ColorPicker 是一个基于 react-colorful 的颜色拾取组件。它允许您通过视觉方式或操作单独的 RGB(A)、HSL(A) 和 Hex(8) 颜色值来选择颜色。

用法

import { useState } from 'react';
import { ColorPicker } from '@wordpress/components';

function Example() {
    const [color, setColor] = useState();
    return (
        <ColorPicker
            color={color}
            onChange={setColor}
            enableAlpha
            defaultValue="#000"
        />
    );
}

属性

color: string

要在拾色器中显示的当前颜色值。必须是 hex 或 hex8 字符串。

  • 必需:否

onChange: (hex8Color: string) => void

当颜色更改时触发。始终传递 hex 或 hex8 颜色字符串。

  • 必需:否

enableAlpha: boolean

当 true 时,颜色拾色器将在底部输入框以及颜色拾色器本身中显示 alpha 通道。

  • 必需:否
  • 默认值:false

defaultValue: string | undefined

用于颜色拾色器的可选默认值。

  • 必需:否
  • 默认值:'#fff'

copyFormat: ‘hex’ | ‘hsl’ | ‘rgb’ | undefined

点击显示的颜色格式时要复制的格式。

  • 必需:否