vanilla-colorful is a lightweight, framework-agnostic color picker library implemented as W3C standards-based Custom Elements. It serves as a vanilla JavaScript port of the popular `react-colorful` library, offering the same core functionality in a dependency-free, highly optimized package. The current stable version is 0.7.2, released in November 2022, and while no explicit release cadence is stated, it appears to be actively maintained. Key differentiators include its extremely small bundle size (just 2.7 KB minified and gzipped), 100% test coverage, full TypeScript typings, and comprehensive accessibility (WAI-ARIA) and mobile support. It provides various color picker types (HEX, RGB, HSL, HSV) directly usable as HTML custom elements, making integration into any web application or framework straightforward.
npm install vanilla-colorfulVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate and interact with `hex-color-picker` using standard Custom Elements. It registers the component, initializes its value, listens for `color-changed` events, and updates an output element. It also shows programmatic color setting.
If you need to react to programmatic color changes, implement separate logic or directly call your update function after setting the property. The `color-changed` event is strictly for user interactions.
Review your custom implementations that extend `vanilla-colorful`'s base classes or rely on internal element structure and update them according to the latest API. Refer to the GitHub changelog for specific changes.
To style the `hex-input` (or other elements within Shadow DOM), use CSS custom properties (variables) exposed by the component, or the `::part()` pseudo-element if parts are exposed. Direct global CSS selectors will not penetrate the Shadow DOM boundary.
For development without a bundler, ensure your HTML script tags use `type="module"` and either configure import maps or use a CDN URL that provides module resolution: `<script type="module" src="https://unpkg.com/vanilla-colorful?module"></script>`.
Ensure your target browsers have native Web Components support or include appropriate polyfills if wider browser compatibility is required. The library is designed for evergreen browsers.
Always use `addEventListener('color-changed', ...)` in vanilla JS. When integrating with frameworks, use their specific event binding syntax (e.g., `(color-changed)="handler"` in Angular/Lit, or consider solutions like `@lit/react` for React). Avoid assuming `onChange` or other framework-specific event names.Add `type="module"` to your script tag: `<script type="module" src="./main.js"></script>` or use a bundler/CDN with module resolution.
Ensure `import 'vanilla-colorful';` is at the top of your module, or `import { HexColorPicker } from 'vanilla-colorful';` if you're directly using the class.Ensure the `import 'vanilla-colorful';` statement runs only once. This can happen if you include the script multiple times, or if a build process duplicates module imports. Remove redundant imports.
No dependency data recorded yet.