Skip to content

CopyColor ​

ewColorPickerCopyColor renders a round copy button in its own toolbar row above the value input. Its background shows the current color, and clicking it writes the current color value to the clipboard and shows a short success toast.

ItemValue
Package@ew-color-picker/copy-color
pluginNameewColorPickerCopyColor
applyOrderPost
Mount pointpanelContainer → .ew-color-picker-extra-row (toolbar row above the input row)
Instancecore.plugins.ewColorPickerCopyColor

Options ​

OptionTypeDefaultDescription
showCopyColorbooleantrueSet false to hide the copy button
copyColorTextstring'复制颜色到剪贴板'Button title / aria-label
copiedTextstring'已复制'Text of the success toast shown for 1.5s
onCopyColor(color: string) => void—Called with the copied color value
ts
import ewColorPicker from '@ew-color-picker/core'
import CopyColor from '@ew-color-picker/copy-color'

ewColorPicker.use(CopyColor)

new ewColorPicker({
  el: '#app',
  copyColorText: 'Copy color',
  copiedText: 'Copied',
  onCopyColor: (color) => console.log('copied', color),
})

Click behaviour ​

  1. Read the current value from core.getColor(); an empty value does nothing;
  2. Prefer navigator.clipboard.writeText();
  3. Fall back to a temporary <textarea> + document.execCommand('copy') when the Clipboard API is unavailable (for example on plain HTTP pages);
  4. On success, show a toast bubble next to the button with copiedText for 1.5s, then call options.onCopyColor?.(color);
  5. On failure, print a console.warn and keep the current color unchanged.

The copied string is the exact value returned by core.getColor() — a hex string in hex mode, rgba() / hsla() when alpha is enabled.

DOM ​

html
<div class="ew-color-picker-copy-group">
  <button type="button" class="ew-color-picker-copy-btn" title="复制颜色到剪贴板" aria-label="复制颜色到剪贴板">
    <svg class="ew-color-picker-icon" viewBox="0 0 24 24">…</svg>
  </button>
  <div class="ew-color-picker-copy-tip" role="status" aria-live="polite">已复制</div>
</div>

The button background follows change, and the icon switches between dark and light based on the background luminance. The toast is a self-contained element styled by the package itself, so no extra message library or global styles are required.

Methods ​

Method / propertySignatureDescription
run() => voidRemove the old node, render and bind
updateOptions() => voidRe-read options and re-render
destroy() => voidUnbind events and remove the node
container / button / tipHTMLElement | nullCurrent DOM references