Color Picker
A tool that allows users to select colors visually, often used for customizing designs or selecting background/foreground colors.
Usage
Basic usage example to quickly see how the ColorPicker
works.
Properties
Interactive configurator to explore customization options for the ColorPicker
component.
Size
Round
Swatch per row
Notes
withClipboard
prop only available in certain formats"hexa"
||"rgba"
||"hsla"
.
API References
Styles API
type ColorPickerTrees = "saturation" | "body" | "slider" | "root" | "sliders" | "sliderOverlay" | "thumb" | "saturationOverlay" | "swatches" | "swatch" | "preview" | "alphaOverlay" | "shadowOverlay" | "colorOverlay" | "childrenOverlay";
Styles API | Type | Default | Annotation |
---|---|---|---|
unstyled? | Partial<Record<ColorPickerTrees, boolean>> | false | if true , all default styles will be removed |
classNames? | Partial<Record<ColorPickerTrees, string>> | undefined | Set className for ColorPickerTrees |
styles? | Partial<Record<ColorPickerTrees, CSSProperties>> | undefined | Set style for ColorPickerTrees |
Props API
type ColorFormat = "hex" | "hexa" | "rgba" | "rgb" | "hsl" | "hsla";
const withAlpha = format === "hexa" || format === "rgba" || format === "hsla";
Props API | Type | Default | Annotation |
---|---|---|---|
defaultValue? | string | undefined | Uncontrolled component default value |
value? | string | undefined | Controlled component value |
format? | ColorFormat | hex | Color format |
withPicker? | boolean | true | Determines whether the color picker should be displayed |
swatches? | string[] | undefined | An array of colors in one of the supported formats. Used to render swatches list below the color picker. |
swatchPerRow? | number | 7 | Number of swatches per row |
focusable? | boolean | true | Determines whether interactive elements (sliders thumbs and swatches) should be focusable |
size? | string | number | Controls size of hue, alpha and saturation sliders | |
alphaLabel? | string | Alpha slider aria-label prop | |
hueLabel? | string | Hue slider aria-label prop | |
saturationLabel? | string | Saturation slider aria-label prop | |
withShadow? | boolean | true | Add style shadow for swatches |
withClipboard? | boolean | false | When to copy color values (only available in certain formats / withAlpha ) |
onChange? | (value: string) => void | undefined | Called when value changes |
onChangeEnd? | (value: string) => void | undefined | Called when the user stops dragging one of the sliders or changes the value with arrow keys |
onColorSwatchClick? | (color: string) => void | undefined | Called when one of the color swatches is clicked |
Source Codes
Full working code example, including necessary markup and styles. You can copy and paste this code directly to start using the component immediately.