ColorPicker

Used for color selection.
Importimport{ ColorPicker }from"antd";
Versionsupported since 5.5.0

When To Use

Used when the user needs to make a customized color selection.

Examples

Basic Usage.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Set the component to controlled mode. Will lock the display color if controlled by onChangeComplete.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
#1677FF
Custom Text (#1677ff)

Renders the default text of the trigger, effective when showText is true. When customizing text, you can use showText as a function to return custom text.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Disabled color alpha.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Triggers for customizing color panels.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
HEX: #1677ff
HSB: hsb(215, 91%, 100%)
RGB: rgb(22, 119, 255)

Encoding formats, support HEX, HSB, RGB.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Add title:
Horizontal layout:

Rendering of the free control panel via panelRender.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
#1677FF
#1677FF
#1677FF

Ant Design supports three trigger sizes: small, default and large.

If a large or small trigger is desired, set the size property to either large or small respectively. Omit the size property for a trigger with the default size.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
rgb(16,142,233) 0%rgb(135,208,104) 100%
rgb(16,142,233) 0%rgb(135,208,104) 100%

Set the color to a single or a gradient color via mode.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
5.20.0
#1677FF

Set to disabled state.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Clear Color.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Triggers event for customizing color panels, provide options click and hover.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Set the presets color of the color picker.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

This component is available since antd@5.5.0.

PropertyDescriptionTypeDefaultVersion
allowClearAllow clearing color selectedbooleanfalse
arrowConfiguration for popup arrowboolean | { pointAtCenter: boolean }true
childrenTrigger of ColorPickerReact.ReactNode-
defaultValueDefault value of colorstring | Color-
defaultFormatDefault format of colorrgb | hex | hsb-5.9.0
disabledDisable ColorPickerboolean-
disabledAlphaDisable Alphaboolean-5.8.0
disabledFormatDisable format of colorboolean-
destroyTooltipOnHideWhether destroy popover when hiddenbooleanfalse5.7.0
formatFormat of colorrgb | hex | hsbhex
modeConfigure single or gradient color'single' | 'gradient' | ('single' | 'gradient')[]single5.20.0
openWhether to show popupboolean-
presetsPreset colors{ label: ReactNode, colors: Array<string | Color>, defaultOpen?: boolean, key?: React.Key }[]-defaultOpen: 5.11.0, key: 5.23.0
placementPlacement of popupThe design of the placement parameter is the same as the Tooltips component.bottomLeft
panelRenderCustom Render Panel(panel: React.ReactNode, extra: { components: { Picker: FC; Presets: FC } }) => React.ReactNode-5.7.0
showTextShow color textboolean | (color: Color) => React.ReactNode-5.7.0
sizeSetting the trigger sizelarge | middle | smallmiddle5.7.0
triggerColorPicker trigger modehover | clickclick
valueValue of colorstring | Color-
onChangeCallback when value is changed(value: Color, css: string) => void-
onChangeCompleteCalled when color pick ends. Will not change the display color when value controlled by onChangeComplete(value: Color) => void-5.7.0
onFormatChangeCallback when format is changed(format: 'hex' | 'rgb' | 'hsb') => void-
onOpenChangeCallback when open is changed(open: boolean) => void-
onClearCalled when clear() => void-5.6.0

Color

PropertyDescriptionTypeVersion
toCssStringConvert to CSS support format() => string5.20.0
toHexConvert to hex format characters, the return type like: 1677ff() => string-
toHexStringConvert to hex format color string, the return type like: #1677ff() => string-
toHsbConvert to hsb object() => ({ h: number, s: number, b: number, a number })-
toHsbStringConvert to hsb format color string, the return type like: hsb(215, 91%, 100%)() => string-
toRgbConvert to rgb object() => ({ r: number, g: number, b: number, a number })-
toRgbStringConvert to rgb format color string, the return type like: rgb(22, 119, 255)() => string-

FAQ

Questions about color assignment

The value of the color selector supports both string color values and selector-generated Color objects. However, since there is a precision error when converting color strings of different formats to each other, it is recommended to use selector-generated Color objects for assignment operations in controlled scenarios, so that the precision problem can be avoided and the values are guaranteed to be accurate and the selector can work as expected.