Skip to content

ColorMode ​

ewColorPickerColorMode provides Hex / RGB / HSL input modes. Switching rebuilds the channel input group.

ItemValue
Package@ew-color-picker/color-mode
pluginNameewColorPickerColorMode
applyOrderPost
Mount pointpanelContainer
Instancecore.plugins.ewColorPickerColorMode

Options ​

OptionTypeDefaultDescription
defaultMode'hex' | 'rgb' | 'hsl''rgb' with Alpha, else 'hex'Initial mode
showColorModebooleantrueHide the switcher
ewColorPickerColorModeboolean | objecttruefalse disables; object merges
changeMode(mode, picker) => void—Mode change callback

Methods ​

Method / propertySignatureDescription
getCurrentMode() => 'hex' | 'rgb' | 'hsl'Read mode
setMode(mode) => voidSwitch (100ms debounce)
switchToNextMode() => voidhex → rgb → hsl → hex
switchToPreviousMode() => voidReverse
onModeChange(mode) => voidMain handler
updateOptions() => voidRe-read config and redraw
updateInputStructure() => voidRebuild inputs
updateInputValues(color: string) => voidSync inputs
updateColorFromRgbInputs / updateColorFromHslInputs() => voidCompose color (debounced)
restoreDefaultInput() => voidRestore Input plugin field
currentMode'hex' | 'rgb' | 'hsl'Current mode

Switch flow ​

text
Arrow click
  → debounce(100ms) onModeChange(mode)
  → update label (HEX / RGB / HSL)
  → updateInputStructure()
  → non-hex: updateInputValues(current color)
  → options.changeMode?.(mode, picker)
  → trigger('mode-change', mode)

Hex mode never calls setColor again, preventing hex text from being overwritten by rgba().

Arrows respect options.disabled.

Events & callbacks ​

ts
picker.on('mode-change', (mode) => console.log(mode))

DOM ​

html
<div class="ew-color-picker-mode-container">
  <button class="ew-color-picker-mode-up-btn" type="button"></button>
  <div class="ew-color-picker-mode-text">HEX</div>
  <button class="ew-color-picker-mode-down-btn" type="button"></button>
</div>

<div class="ew-color-picker-inputs-group">
  <div class="ew-color-picker-inputs-col">
    <label class="ew-color-picker-input-label">R</label>
    <div class="ew-input-number">…</div>
  </div>
</div>

Example ​

ts
const picker = new ewColorPicker({
  el: '#app',
  defaultColor: '#ec4899',
  defaultMode: 'hex',
  changeMode: (mode, instance) => console.log(mode, instance.getColor()),
})

picker.plugins.ewColorPickerColorMode.setMode('hsl')