ColorPicker 是基于 react-colorful 的颜色选择组件,支持视觉选择或通过 RGB(A)、HSL(A) 和 Hex(8) 值操作颜色。它适用于 WordPress 开发中的颜色设置场景。
import { useState } from 'react';
import { ColorPicker } from '@wordpress/components';
function Example() {
const [color, setColor] = useState();
return (
<ColorPicker
color={color}
onChange={setColor}
enableAlpha
defaultValue="#000"
/>
);
}ColorPicker is a color picking component based on react-colorful. It lets you pick a color visually or by manipulating the individual RGB(A), HSL(A) and Hex(8) color values.
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: stringThe current color value to display in the picker. Must be a hex or hex8 string.
onChange: (hex8Color: string) => voidFired when the color changes. Always passes a hex or hex8 color string.
enableAlpha: booleanWhen true the color picker will display the alpha channel both in the bottom inputs as well as in the color picker itself.
falsedefaultValue: string | undefinedAn optional default value to use for the color picker.
'#fff'copyFormat: 'hex' | 'hsl' | 'rgb' | undefinedThe format to copy when clicking the displayed color format.