English | ç®€ä½“ä¸æ–‡
- Supports controlled and uncontrolled color values.
- Accepts string, number, RGB, RGBA, HSB, HSBA, and
Colorinputs. - Provides hue and alpha controls with change and drag-complete callbacks.
- Exposes
Colorhelpers for hex, RGB, and HSB conversions. - Exposes keyboard-operable, screen-reader-labelled controls with overridable strings.
npm install @rc-component/color-pickerimport ColorPicker from '@rc-component/color-picker';
import '@rc-component/color-picker/assets/index.css';
export default function App() {
return (
<ColorPicker
defaultValue="#1677ff"
onChange={(color, info) => {
console.log(color.toHexString(), info?.type);
}}
/>
);
}Run the local dumi site:
npm install
npm startThen open http://localhost:8000.
| Property | Description | Type | Default |
|---|---|---|---|
| defaultValue | Default color value | ColorGenInput |
- |
| disabled | Whether the color picker is disabled | boolean | false |
| disabledAlpha | Whether to hide the alpha slider | boolean | false |
| locale | Accessible labels for the picker and sliders | Locale |
- |
| panelRender | Custom panel renderer | (panel: React.ReactElement) => React.ReactElement |
- |
| prefixCls | Component class name prefix | string | rc-color-picker |
| value | Current color value | ColorGenInput |
- |
| onChange | Callback when color changes | (color: Color, info?: { type?: 'hue' | 'alpha'; value?: number }) => void |
- |
| onChangeComplete | Callback when a drag operation finishes | (color: Color, info?: { type?: 'hue' | 'alpha'; value?: number }) => void |
- |
Overrides the accessible names the controls expose to assistive technology. Every key is optional and falls back to its default, so pass only the strings you need to translate.
| Property | Description | Type | Default |
|---|---|---|---|
| alpha | aria-label of the alpha slider |
string | Alpha |
| brightness | Channel name in the brightness axis aria-valuetext |
string | Brightness |
| hue | aria-label of the hue slider |
string | Hue |
| picker | aria-label of both saturation and brightness axes |
string | Color picker |
| pickerDescription | aria-roledescription of both saturation and brightness axes |
string | 2D slider |
| saturation | Channel name in the saturation axis aria-valuetext |
string | Saturation |
<ColorPicker
locale={{
picker: 'Sélecteur de couleur',
pickerDescription: 'Curseur 2D',
hue: 'Teinte',
alpha: 'Transparence',
saturation: 'Saturation',
brightness: 'Luminosité',
}}
/>The 2-D area renders one range input per axis. Both share the picker name and the pickerDescription role description, while each announces its own channel through aria-valuetext — Saturation: 91% and Brightness: 100% — so saturation and brightness are channel names rather than whole labels.
| Method | Description | Type |
|---|---|---|
| toHexString | Convert to hex color string | () => string |
| toHsb | Convert to HSB object | () => { h: number; s: number; b: number; a: number } |
| toHsbString | Convert to HSB color string | () => string |
| toRgb | Convert to RGB object | () => { r: number; g: number; b: number; a: number } |
| toRgbString | Convert to RGB color string | () => string |
A standalone swatch, exported for building custom triggers and panels.
import { ColorBlock } from '@rc-component/color-picker';
<ColorBlock
color="#1677ff"
prefixCls="rc-color-picker"
title="Current color"
onClick={handleClick}
/>;| Property | Description | Type | Default |
|---|---|---|---|
| color | Color used to fill the swatch | string | - |
| prefixCls | Component class name prefix | string | - |
| className | Class name of the outer element | string | - |
| style | Style of the outer element | React.CSSProperties |
- |
| ...rest | Forwarded to the outer element | React.HTMLAttributes<HTMLDivElement | HTMLButtonElement> |
- |
ColorBlockProps extends React.HTMLAttributes<HTMLDivElement | HTMLButtonElement>, so standard attributes and event handlers reach the outer element. innerClassName and innerStyle are internal to antd's semantic structure; treat them as private.
Passing onClick renders a native <button type="button"> with an aria-label defaulting to color. Enter and Space activation is handled by the browser. Your own role, tabIndex, aria-label and onKeyDown are forwarded. Without onClick, the swatch stays a plain div.
npm install
npm startThe dumi site runs at http://localhost:8000 by default.
npm test
npm run tsc
npm run lint
npm run compile
npm run buildnpm run prepublishOnlyThe release flow is handled by @rc-component/np through the rc-np command after the package build.
@rc-component/color-picker is released under the MIT license.