JGuang

ColorPicker

ColorPicker · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

ColorPicker

Used for color selection.

When To Use

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

Examples

  • Basic Usage · base

  • Trigger size · size

  • controlled mode · controlled

  • Line Gradient · line-gradient

  • Rendering Trigger Text · text-render

  • Disable · disabled

  • Disabled Alpha · disabled-alpha

  • Clear Color · allowClear

  • Custom Trigger · trigger

  • Custom Trigger Event · trigger-event

  • Color Format · format

  • Preset Colors · presets

  • Custom Render Panel · panel-render

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

This component is available since antd@5.5.0.

PropertyDescriptionTypeDefaultVersionGlobal Config
allowClearAllow clearing color selectedbooleanfalse×
arrowConfiguration for popup arrowboolean | { pointAtCenter: boolean }true6.3.0
childrenTrigger of ColorPickerReact.ReactNode-×
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>-6.0.0
defaultValueDefault value of colorColorType-×
defaultFormatDefault format of colorrgb | hex | hsbhex5.9.0×
disabledDisable ColorPickerboolean-×
disabledAlphaDisable Alphaboolean-5.8.0×
disabledFormatDisable format of colorboolean-5.22.0×
destroyTooltipOnHideWhether destroy dom when closebooleanfalse5.7.0×
destroyOnHiddenWhether destroy dom when closebooleanfalse5.25.0×
formatFormat of colorrgb | hex | hsb-×
modeConfigure single or gradient color'single' | 'gradient' | ('single' | 'gradient')[]single5.20.0×
openWhether to show popupboolean-×
presetsPreset colorsPresetColorType-×
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 | medium | smallmedium5.7.0×
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-6.0.0
triggerColorPicker trigger modehover | clickclick×
valueValue of colorColorType-×
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×

ColorType

type ColorType =
  | string
  | Color
  | {
      color: string;
      percent: number;
    }[];

PresetColorType

type PresetColorType = {
  label: React.ReactNode;
  defaultOpen?: boolean;
  key?: React.Key;
  colors: ColorType[];
};

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-

Semantic DOM

Semantic nodeNative descriptionVersion
rootTrigger container with border styles, transition animations, size controls, displaying color block and text content—
bodyColor block container with background color, border styles—
contentColor block element with actual selected color styles—
descriptionDescription text content with font styles and color—
popup.rootPopup panel root container with background color, shadow effects, color selection panel, slider controls and preset colors—

Semantic description source: vendor/components/color-picker/demo/_semantic.tsx

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.

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/color-picker/ColorPicker.tsx
  • vendor/components/color-picker/ColorPickerPanel.tsx
  • vendor/components/color-picker/color.ts
  • vendor/components/color-picker/components/ColorAlphaInput.tsx
  • vendor/components/color-picker/components/ColorClear.tsx
  • vendor/components/color-picker/components/ColorHexInput.tsx
  • vendor/components/color-picker/components/ColorHsbInput.tsx
  • vendor/components/color-picker/components/ColorInput.tsx
  • vendor/components/color-picker/components/ColorPresets.tsx
  • vendor/components/color-picker/components/ColorRgbInput.tsx
  • vendor/components/color-picker/components/ColorSlider.tsx
  • vendor/components/color-picker/components/ColorSteppers.tsx
  • vendor/components/color-picker/components/ColorTrigger.tsx
  • vendor/components/color-picker/components/PanelPicker/GradientColorBar.tsx
  • vendor/components/color-picker/components/PanelPicker/index.tsx
  • vendor/components/color-picker/context.ts
  • vendor/components/color-picker/hooks/useModeColor.ts
  • vendor/components/color-picker/interface.ts
  • vendor/components/color-picker/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.