All Projects → web-padawan → Vanilla Colorful

web-padawan / Vanilla Colorful

Licence: mit
A tiny color picker custom element for modern web apps (2.7 KB) 🎨

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Vanilla Colorful

Vanilla Hamburger
Animated hamburger menu icons for modern web apps (1.8 KB) 🍔
Stars: ✭ 110 (-76.45%)
Mutual labels:  web-components, webcomponents, custom-elements, vanilla
symbiote.js
Simple, light and very powerful library to create embedded components for any purpose, with a data flow management included.
Stars: ✭ 40 (-91.43%)
Mutual labels:  webcomponents, web-components, custom-elements
smart-webcomponents-community
Material & Bootstrap Web Components built with Smart
Stars: ✭ 30 (-93.58%)
Mutual labels:  webcomponents, web-components, custom-elements
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (-85.22%)
Mutual labels:  webcomponents, web-components, custom-elements
Colorpicker
jQuery UI widget for color picking (similar to the one in Microsoft Office 2010).
Stars: ✭ 271 (-41.97%)
Mutual labels:  color, color-picker, colorpicker
React Colorpickr
A themeable colorpicker with HSL and RGB support for React
Stars: ✭ 180 (-61.46%)
Mutual labels:  color, color-picker, colorpicker
Pickr
🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
Stars: ✭ 3,759 (+704.93%)
Mutual labels:  color, color-picker, colorpicker
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+2502.36%)
Mutual labels:  web-components, webcomponents, custom-elements
global-color-picker
start the script and click anywhere to get rgb value at the cursor location
Stars: ✭ 31 (-93.36%)
Mutual labels:  color, color-picker, colorpicker
ColorPickView
🐾一个自定义的颜色选择view
Stars: ✭ 19 (-95.93%)
Mutual labels:  color, color-picker, colorpicker
toggle-icon
toggle-icon is a custom element created with Polymer. It provides an extremely powerful and customizable switch that looks like a paper-icon-button.
Stars: ✭ 21 (-95.5%)
Mutual labels:  webcomponents, web-components, custom-elements
Bootstrap Colorpicker
Bootstrap Colorpicker is a modular color picker plugin for Bootstrap.
Stars: ✭ 1,351 (+189.29%)
Mutual labels:  color, color-picker, colorpicker
Kallewheel
A custom color wheel extension for Adobe Photoshop
Stars: ✭ 16 (-96.57%)
Mutual labels:  color, color-picker, colorpicker
web-components
A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
Stars: ✭ 322 (-31.05%)
Mutual labels:  webcomponents, web-components, custom-elements
Colorpicker
A mininal but complete colorpicker desktop app
Stars: ✭ 766 (+64.03%)
Mutual labels:  color, color-picker, colorpicker
modulor-html
Missing template engine for Web Components
Stars: ✭ 36 (-92.29%)
Mutual labels:  webcomponents, web-components, custom-elements
custom-elements-manifest
Custom Elements Manifest is a file format that describes custom elements in your project.
Stars: ✭ 81 (-82.66%)
Mutual labels:  webcomponents, web-components, custom-elements
Nutmeg
Build, test, and publish vanilla Web Components with a little spice
Stars: ✭ 111 (-76.23%)
Mutual labels:  web-components, webcomponents, custom-elements
lit-components
Moved to https://github.com/vaadin/component-mixins
Stars: ✭ 59 (-87.37%)
Mutual labels:  webcomponents, web-components, custom-elements
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: ✭ 27 (-94.22%)
Mutual labels:  webcomponents, web-components, custom-elements
vanilla-colorful is a port of react-colorful to vanilla Custom Elements.

Features

  • Small: Just 2,7 KB (minified and gzipped). Size Limit controls the size.
  • Fast: Built with standards based Custom Elements.
  • Bulletproof: Written in strict TypeScript and covered by 100+ tests.
  • Simple: The interface is straight forward and easy to use.
  • Accessible: Follows the WAI-ARIA guidelines to support users of assistive technologies.
  • Mobile-friendly: Works well on mobile devices and touch screens.
  • Framework-agnostic: Can be used with any framework.
  • No dependencies

Live demo

Install

npm install vanilla-colorful --save

Or use one of the following content delivery networks:

unpkg.com CDN:

<script type="module" src="https://unpkg.com/vanilla-colorful?module"></script>

Skypack CDN:

<script type="module" src="https://cdn.skypack.dev/vanilla-colorful"></script>

Usage

<hex-color-picker color="#1e88e5"></hex-color-picker>
<script type="module">
  import 'vanilla-colorful';

  const picker = document.querySelector('hex-color-picker');
  picker.addEventListener('color-changed', (event) => {
    // get updated color value
    const newColor = event.detail.value;
  });

  // get current color value
  console.log(picker.color);
</script>

ES modules

vanilla-colorful is authored using ES modules which are natively supported by modern browsers. However, it also uses "bare module imports" which are not yet standardized and require a small transform.

We recommend the following tools for the ES modules based development:

None of these tools are needed when importing the component from CDN.

Supported color models

The default vanilla-colorful's input/output format is a HEX string (like #ffffff). In case if you need another color model, we provide 12 additional color picker bundles.

How to use another color model

Available pickers

File to import HTML element Value example
"hex-color-picker.js" <hex-color-picker> "#ffffff"
"hsl-color-picker.js" <hsl-color-picker> { h: 0, s: 0, l: 100 }
"hsl-string-color-picker.js" <hsl-string-color-picker> "hsl(0, 0%, 100%)"
"hsla-color-picker.js" <hsla-color-picker> { h: 0, s: 0, l: 100, a: 1 }
"hsla-string-color-picker.js" <hsla-string-color-picker> "hsla(0, 0%, 100%, 1)"
"hsv-color-picker.js" <hsv-color-picker> { h: 0, s: 0, v: 100 }
"hsv-string-color-picker.js" <hsv-string-color-picker> "hsv(0, 0%, 100%)"
"hsva-color-picker.js" <hsva-color-picker> { h: 0, s: 0, v: 100, a: 1 }
"hsva-string-color-picker.js" <hsva-string-color-picker> "hsva(0, 0%, 100%, 1)"
"rgb-color-picker.js" <rgb-color-picker> { r: 255, g: 255, b: 255 }
"rgba-color-picker.js" <rgba-color-picker> { r: 255, g: 255, b: 255, a: 1 }
"rgb-string-color-picker.js" <rgb-string-color-picker> "rgb(255, 255, 255)"
"rgba-string-color-picker.js" <rgba-string-color-picker> "rgba(255, 255, 255, 1)"

Code example

<rgba-color-picker></rgba-color-picker>
<script type="module">
  import 'vanilla-colorful/rgba-color-picker.js';

  const picker = document.querySelector('rgba-color-picker');
  picker.color = { r: 50, g: 100, b: 150, a: 1 };
</script>

Overriding styles

vanilla-colorful exposes CSS Shadow Parts allowing to override the default styles:

hex-color-picker {
  height: 250px;
}

hex-color-picker::part(saturation) {
  bottom: 30px;
  border-radius: 3px 3px 0 0;
}

hex-color-picker::part(hue) {
  height: 30px;
  border-radius: 0 0 3px 3px;
}

hex-color-picker::part(saturation-pointer) {
  border-radius: 5px;
}

hex-color-picker::part(hue-pointer) {
  border-radius: 2px;
  width: 15px;
  height: inherit;
}

HEX input

vanilla-colorful provides an additional <hex-input> element that can be used to type a color:

<hex-input color="#1e88e5"></hex-input>
<script type="module">
  import 'vanilla-colorful/hex-input.js';

  const input = document.querySelector('hex-input');
  input.addEventListener('color-changed', (event) => {
    const newColor = event.detail.value;
  });
</script>

<hex-input> renders an unstyled <input> element inside a slot and exposes it for styling using part. You can also pass your own <input> element as a child if you want to fully configure it.

Base classes

vanilla-colorful provides a set of base classes that can be imported without registering custom elements. This is useful if you want to create your own color picker with a different tag name.

import { RgbBase } from 'vanilla-colorful/lib/entrypoints/rgb.js';

customElements.define('custom-color-picker', class extends RgbBase {});

TypeScript support

vanilla-colorful supports TypeScript and ships with types in the library itself; no need for any other install.

How you can get the most from our TypeScript support

While not only typing its own class methods and variables, it can also help you type yours. Depending on the element you are using, you can also import the type that is associated with the element. For example, if you are using our <hsl-color-picker> element, you can also import the HslColor type.

import type { HslColor } from 'vanilla-colorful/hsl-color-picker';

const myHslValue: HslColor = { h: 0, s: 0, l: 0 };

All the included custom elements are compatible with lit-analyzer and lit-plugin extension for Visual Studio Code, so you can benefit from type checking in lit-html templates.

Browser support

vanilla-colorful uses Custom Elements and Shadow DOM, and does not support IE11 or legacy Edge.

Why vanilla-colorful?

vanilla-colorful has all the benefits of react-colorful with one important difference.

While react-colorful claims to have zero dependencies, it still expects you to use React or Preact. This means that Angular, Vue, Svelte or vanilla JS users would have an extra dependency in their apps.

Now when all the evergreen browsers support standards based Custom Elements, it's perfect time to build such tiny and lightweight UI controls as web components rather than framework components.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].