Skip to content

Options ​

Every option below can be passed to the constructor. Defaults come from defaultConfig in the core.

Overview ​

GroupOptions
Coreel, disabled, defaultColor, size, predefineColor, isClickOutside
LayouthueDirection, alphaDirection, autoPanelPosition, panelPlacement, appendTo, prefix
LabelsclearText, sureText
AnimationtogglePickerAnimation, pickerAnimationTime
Plugin switcheshasBox, hasPanel, hasInput, hasClear, hasSure, hue, alpha, showButton, showColorMode, showInputNumber
Plugin config objectsewColorPickerPanel, ewColorPickerColorMode
Box extrasboxNoColorIcon, boxHasColorIcon, readonly, className, style
CallbackschangeColor, sure, clear, togglePicker
Color modedefaultMode, changeMode

Core options ​

el ​

TypeDefaultDescription
string | HTMLElementdocument.bodyMount container. A selector or element. Providing it auto-mounts.
ts
new ewColorPicker({ el: '#app' })
new ewColorPicker(document.getElementById('app')!)

disabled ​

TypeDefaultDescription
booleanfalseDisables the box, panel drag, hue/alpha sliders, inputs and buttons.
ts
new ewColorPicker({ el: '#app', disabled: true })

defaultColor ​

TypeDefaultDescription
string''Initial color; also the color restored by the Clear button.
  • With the Alpha plugin registered, a hex value is converted to rgba().
  • Without Alpha, a rgba() value is converted to hex.
  • Invalid values produce a warning and keep the current color when passed to updateOptions.

size ​

TypeDefaultDescription
'mini' | 'small' | 'normal' | 'medium' | 'large' | number | { width, height } | string'normal'Box size
PresetSizeIcon
mini20px12px
small24px14px
normal32px16px
medium36px18px
large40px20px

Numbers are treated as pixels; objects accept width/height; CSS strings are used verbatim.

predefineColor ​

OptionTypeDefaultDescription
predefineColor(string | { color: string; disabled?: boolean })[][]Predefined swatches. Empty array renders nothing. Clicking a swatch calls the top-level changeColor callback.
ts
predefineColor: ['#ef4444', '#22c55e', { color: '#0f172a', disabled: true }]

isClickOutside ​

TypeDefaultDescription
booleantrueClicking outside the picker closes the panel.

Layout options ​

hueDirection / alphaDirection ​

TypeDefault
'horizontal' | 'vertical''vertical'

Controls slider orientation. When both are horizontal, the panel width becomes 320px.

autoPanelPosition ​

TypeDefaultDescription
booleanfalsePosition the panel relative to the box automatically. Requires the Box plugin with hasBox: true.

appendTo ​

TypeDefaultDescription
string | HTMLElementundefinedMount the panel container into an external container (e.g. document.body) so it is not clipped by overflow of dialogs or scroll containers. The panel switches to viewport-relative (position: fixed) placement, still follows panelPlacement, and re-positions on scroll or resize.
ts
new ewColorPicker({
  el: '#picker',
  appendTo: document.body,
  panelPlacement: 'bottom',
})

prefix ​

TypeDefaultDescription
string'ew-'Prefix of every generated CSS class name. Override it when embedding the picker in another library to avoid style collisions.
ts
new ewColorPicker({ el: '#picker', prefix: 'my-' })

The JS option must match the prefix used when compiling the styles, otherwise the class names won't line up and CSS won't apply.

When compiling the SCSS sources yourself, override $prefix:

scss
@use "@ew-color-picker/style/src/index.scss" with (
  $prefix: "my-"
);

The prebuilt dist/index.css always uses the ew- prefix; keep the default prefix option when using it.

panelPlacement ​

TypeDefaultValues
string'bottom'top-start top top-end left-start left left-end right-start right right-end bottom-start bottom bottom-end

Gap is 5px; out-of-viewport positions are adjusted automatically.

Labels ​

OptionTypeDefault
clearTextstring'清空'
sureTextstring'确定'

Change them for i18n:

ts
new ewColorPicker({ clearText: 'Reset', sureText: 'Apply' })

Animation ​

togglePickerAnimation ​

TypeDefaultValues
string'default''default', 'height', 'opacity'

Only height and opacity are animated; default toggles instantly.

pickerAnimationTime ​

TypeDefaultRange
number2000–10000 (ms)

Values above 10000 are clamped.

Plugin switches ​

OptionTypeDefaultEffect
hasBoxbooleantrueHide the trigger swatch
hasPanelbooleantrueHide the 2D panel
hasInputbooleantrueHide the text input
hasClearbooleantrueHide the Clear button
hasSurebooleantrueHide the Sure button
huebooleantrueHide the hue slider
alphabooleantrueHide the alpha slider
showButtonbooleantrueHide clear + sure buttons at once
showColorModebooleantrueHide the Hex/RGB/HSL switcher
showInputNumberbooleantrueSkip the InputNumber plugin's own numeric input; ColorMode channel inputs are unaffected
ts
new ewColorPicker({
  el: '#app',
  hasPanel: false,
  hue: false,
  alpha: false,
  hasInput: false,
  hasClear: false,
  hasSure: false,
})

Plugin config objects ​

OptionTypeNotes
ewColorPickerPanelbooleanfalse disables the panel (same as hasPanel: false)
ewColorPickerColorModeboolean | objectfalse disables mode switching; object merges color-mode options

Box extras ​

OptionTypeDefaultDescription
boxNoColorIconstring''Custom HTML for the "no color" icon
boxHasColorIconstring''Custom HTML for the "has color" icon
readonlybooleanfalsePrevents clicking the box
classNamestring''Extra class on .ew-color-picker-box
stylestring | Record<string,string>''Inline styles for the box

Color mode ​

OptionTypeDefaultDescription
defaultMode'hex' | 'rgb' | 'hsl''rgb' with Alpha, otherwise 'hex'Initial mode
changeMode(mode, picker) => void—Mode change callback

Callbacks ​

CallbackSignatureWhen
changeColor(color: string) => voidColor changed
sure(color: string, picker) => voidSure button clicked
clear(picker) => voidClear button clicked
togglePicker(isOpen: boolean) => voidPanel toggled

Complete example ​

ts
const picker = new ewColorPicker({
  el: '#app',
  defaultColor: 'rgba(99, 102, 241, 0.8)',
  size: 'large',
  predefineColor: ['#ef4444', '#22c55e', '#3b82f6', { color: '#0f172a', disabled: true }],
  hueDirection: 'horizontal',
  alphaDirection: 'horizontal',
  clearText: 'Reset',
  sureText: 'Apply',
  togglePickerAnimation: 'height',
  pickerAnimationTime: 250,
  autoPanelPosition: true,
  panelPlacement: 'bottom-start',
  defaultMode: 'rgb',
  changeColor: (color) => console.log(color),
  sure: (color) => console.log('sure', color),
})

Next steps ​