Skip to content

Introduction ​

ew-color-picker is a modern color picker built around two ideas:

  1. Event-driven — every action becomes an event (change, sure, clear, toggle, mode-change, options-update, destroy).
  2. Plugin-based — the core owns color state and mount points; every piece of UI is a plugin.
text
Core (@ew-color-picker/core)
├─ color state: currentColor + hsvaColor
├─ event bus: on / once / off / trigger / emit
├─ mount points: root + panelContainer
└─ plugins: can be registered, replaced, or extended

Why a plugin architecture? ​

BenefitWhat it means
Small bundlesInstall only the plugins you use
Replaceable UISwap the panel, input, or buttons for your own implementation
TestableEach plugin can be tested in isolation
ExtensibleAdd features without touching the core

The 14 packages ​

PackageResponsibility
@ew-color-picker/coreColor state, event bus, mount points, plugin registry
@ew-color-picker/utilsDOM/color/animation helpers, EventEmitter, Console plugin
@ew-color-picker/styleCSS (index.css + input-number.css)
@ew-color-picker/ew-color-pickerAll-in-one bundle: registers all plugins and re-exports the core
ew-color-pickerUnscoped compat entry for v1 users; forwards the aggregate package and styles
@ew-color-picker/boxTrigger swatch that opens/closes the panel
@ew-color-picker/panelSaturation/value 2D panel
@ew-color-picker/hueHue slider (0–360°)
@ew-color-picker/alphaAlpha slider (0–1)
@ew-color-picker/inputText color input with validation
@ew-color-picker/input-numberNumeric input component + plugin
@ew-color-picker/buttonClear / Sure buttons
@ew-color-picker/predefinePredefined color swatches
@ew-color-picker/color-modeHex / RGB / HSL mode switching

Data flow ​

text
User interaction (Box / Panel / Hue / Alpha / Input / Predefine / Button)
        │
        ▼
   core.setColor(color)        ← the only way to change color
        │
        ├─► emit('change', color)
        │     ├─ Panel   sync background + cursor
        │     ├─ Hue     sync thumb
        │     ├─ Alpha   sync thumb
        │     ├─ Input   sync text
        │     ├─ ColorMode sync R/G/B or H/S/L inputs
        │     └─ Box     sync background + icon color
        │
        └─► options.changeColor(color)

Design principles ​

PrincipleDetail
Single source of truthOnly core.setColor() changes color; plugins never call each other directly
Instance isolationEach instance has its own event bus, DOM and plugin instances
No global pollutionCSS is scoped by class names; the only global is the UMD window.ewColorPicker
Progressive disclosureDefaults work out of the box; every plugin exposes options and methods when you need them

Next steps ​