Skip to content

Plugin Overview ​

The core (@ew-color-picker/core) only does three things: keep color state, dispatch events, and manage mount points. All visible UI is rendered by plugins, so you can compose very different pickers.

How a plugin works ​

MemberTypeRequired
static pluginNamestringYes
static applyOrderApplyOrderNo (Pre first, unset in registration order, Post last)
constructor(core)—Yes
destroy()() => voidNo
ts
import ewColorPicker from '@ew-color-picker/core'
import MyPlugin from './my-plugin'

ewColorPicker.use(MyPlugin)
new ewColorPicker({ el: '#app' })

use() is idempotent. Plugin instances live at core.plugins[pluginName].

Execution order (applyOrder) ​

applyOrder controls the order in which plugin constructors run. Values come from the ApplyOrder enum exported by @ew-color-picker/utils (a regular runtime enum):

ValueWeightMeaning
ApplyOrder.Pre-1Constructed first — create shared nodes or state other plugins rely on
unset0Registration order, between Pre and Post
ApplyOrder.Post1Constructed last — read DOM rendered by other plugins

Plugins with the same weight run in use() registration order. The aggregator registers Console → Box → Panel → …, and most built-in UI plugins use Post.

ts
import { ApplyOrder } from '@ew-color-picker/utils'

export default class MyPlugin {
  static pluginName = 'myPlugin'
  static applyOrder = ApplyOrder.Post
  // ...
}

TIP

applyOrder only affects construction order, not the order of event callbacks. Plugins that only listen to change can omit it.

Built-in plugins ​

Registration order in @ew-color-picker/ew-color-picker:

#PluginpluginNamePackageRole
1ConsoleewColorPickerConsoleutilsPrints the version banner once
2BoxewColorPickerBoxboxTrigger swatch
3PanelewColorPickerPanelpanelSaturation/value panel
4HueewColorPickerHuehueHue slider
5AlphaewColorPickerAlphaalphaAlpha slider
6InputewColorPickerInputinputText color input
7InputNumberewColorPickerInputNumberinput-numberNumeric inputs
8ButtonewColorPickerButtonbuttonClear / Sure
9PredefineewColorPickerPredefinepredefineSwatches
10ColorModeewColorPickerColorModecolor-modeHex / RGB / HSL
11——styleCSS artifacts (not a plugin)

Mount points ​

Mount pointAccessContents
rootcore.getMountPoint('root').ew-color-picker, hosts Box
panelContainercore.getMountPoint('panelContainer').ew-color-picker-panel-container, hosts everything else

The panel container carries ew-color-picker-panel-container-hidden while closed.

Collaboration ​

text
User action (Box / Panel / Hue / Alpha / Input / Predefine / Button)
        │
        ▼
   core.setColor(color)   ← the only color entry
        │
        ├─► emit('change', color)
        │     ├─ Panel / Hue / Alpha / Input / ColorMode / Box sync
        │
        └─► options.changeColor(color)

Rules:

  • Only core.setColor() changes color.
  • Subscribe to change; don't poll currentColor.
  • Read other plugin state via core.plugins.xxx.
  • Use core.updateOptions() to refresh configuration.

Trimming the UI ​

All plugins are registered by the bundle; disable via options instead of unregistering:

ts
new ewColorPicker({
  el: '#app',
  hasPanel: false,
  hue: false,
  alpha: false,
  hasInput: false,
  hasClear: false,
  hasSure: false,
  showColorMode: false,
  size: 'large',
})

Smaller bundle

Register plugins manually — see Installation.

Next steps ​