Skip to content

Box ​

ewColorPickerBox is the square trigger showing the current color.

ItemValue
Package@ew-color-picker/box
pluginNameewColorPickerBox
applyOrdernot declared
Mount pointroot
Instancecore.plugins.ewColorPickerBox

Options ​

OptionTypeDefaultDescription
defaultColorstring''Initial color / clear target
sizestring, number, object'normal'Swatch size
disabledbooleanfalseBlocks clicks
readonlybooleanfalseBlocks clicks, keeps styles
hasBoxbooleantrueHide the swatch
boxNoColorIconstring''Custom "no color" icon HTML
boxHasColorIconstring''Custom "has color" icon HTML
classNamestring''Extra class
stylestring | object''Inline styles
onClick(box) => void—Click callback
onMouseEnter / onMouseLeave(box) => void—Hover callbacks

size ​

FormResult
mini / small / normal / medium / large20 / 24 / 32 / 36 / 40px
4848px
{ width: '60px', height: '36px' }custom
'5rem'verbatim

Icon sizes: mini 12px, small 14px, normal 16px, medium 18px, large 20px; numbers/objects use 50% of the shorter side.

Icon contrast ​

  • Luminance > 0.5 → #333333
  • otherwise → #ffffff
  • translucent colors are blended over white first

Methods ​

MethodSignatureDescription
enableBox(enable = true) => voidShow/hide
update(keys?: string[]) => voidRefresh selected keys
updateChildren() => voidRecompute icon
setBoxSize() => voidReapply size
setBoxBgColor(color?: string) => voidSet background
clearBoxBgColor() => voidReset background
setBoxState() => voidSync state classes
setDisabled(disabled: boolean) => voidToggle disabled
bindMouseEvents(onEnter?, onLeave?) => voidBind hover
unbindHandler() => voidUnbind DOM events
destroy() => voidRemove

Properties: hasBox (getter/setter), box (HTMLElement | null).

Behaviour ​

Clicking calls showPanel() or hidePanel() with togglePickerAnimation / pickerAnimationTime, then onClick(boxPlugin). With disabled or readonly, the click is prevented.

ts
picker.on('toggle', (open) => console.log(open))
picker.on('change', (color) => console.log(color))

DOM ​

html
<div class="ew-color-picker-box">
  <span class="ew-color-picker-box-arrow-icon"></span>
</div>
ClassMeaning
.ew-color-picker-boxRoot
.ew-color-picker-box-arrow-iconHas-color icon
.ew-color-picker-box-close-iconNo-color icon
.is-disabled / .is-readonlyStates

Example ​

ts
new ewColorPicker({
  el: '#app',
  defaultColor: '#6366f1',
  size: 'large',
  onClick: (box) => console.log('clicked', box.hasBox),
})