ColorPicker
Pick colors in hex(a), rgb(a), hsl(a) and hsv(a) formats
Source
LLM docs
Docs
PackageIcon
Usage
rgba(47, 119, 150, 0.7)
Controlled
The ColorPicker value must be a string; other types are not supported.
The onChange function is called with a string value as a single argument.
Uncontrolled
ColorPicker can be used with uncontrolled forms the same way as a native input element.
Set the name attribute to include color picker value in FormData object on form submission.
To control the initial value in uncontrolled forms, use the defaultValue prop.
Example usage of uncontrolled ColorPicker with FormData:
Color format
ColorPicker supports hex, hexa, rgb, rgba, hsl and hsla color formats.
The slider to change opacity and color preview are displayed only for hexa, rgba and hsla formats:
#C5D899
With swatches
You can add predefined color swatches with the swatches prop:
By default, ColorPicker will display 7 swatches per row. You can configure it with the swatchesPerRow prop:
To display swatches without picker, set withPicker={false} and fullWidth props:
#fff
Size
ColorPicker has 5 predefined sizes: xs, sm, md, lg and xl:
fullWidth
Set the fullWidth prop to stretch the component to 100% of parent width. In this case the picker will not
have a fixed width, but you can still use the size prop to control the sizes of sliders.
Styles API
ColorPicker supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Accessibility
The ColorPicker component is accessible by default:
- Saturation, hue and alpha sliders are focusable
- When the mouse is used to interact with the slider, focus is moved to the slider
- All values can be changed with arrows
To make the component accessible for screen readers, set saturationLabel, hueLabel and alphaLabel: