Color Picker
Used to select colors from a color area or a set of defined swatches
Usage
import { ColorPicker } from "@chakra-ui/react"<ColorPicker.Root>
<ColorPicker.HiddenInput />
<ColorPicker.Label />
<ColorPicker.Control>
<ColorPicker.Input />
<ColorPicker.Trigger />
</ColorPicker.Control>
<ColorPicker.Positioner>
<ColorPicker.Content>
<ColorPicker.Area />
<ColorPicker.EyeDropper />
<ColorPicker.Sliders />
<ColorPicker.SwatchGroup>
<ColorPicker.SwatchTrigger>
<ColorPicker.Swatch />
</ColorPicker.SwatchTrigger>
</ColorPicker.SwatchGroup>
</ColorPicker.Content>
</ColorPicker.Positioner>
</ColorPicker.Root>Shortcuts
ColorPicker.ChannelSlider
This component renders the slider track, thumb and transparency grid.
<ColorPicker.ChannelSlider />is the same as:
<ColorPicker.ChannelSlider>
<ColorPickerTransparencyGrid />
<ColorPickerChannelSliderTrack />
<ColorPickerChannelSliderThumb />
</ColorPicker.ChannelSlider>ColorPicker.Sliders
This is a shortcut component for the hue and alpha sliders:
<Stack>
<ColorPickerChannelSlider channel="hue" />
<ColorPickerChannelSlider channel="alpha" />
</Stack>ColorPicker.Area
This component renders the color area thumb and background.
<ColorPicker.Area>
<ColorPicker.AreaThumb />
<ColorPicker.AreaBackground />
</ColorPicker.Area>is the same as:
<ColorPicker.Area />ColorPicker.EyeDropper
This is a shortcut component for:
<ColorPicker.EyeDropperTrigger asChild>
<IconButton>
<LuPipette />
</IconButton>
</ColorPicker.EyeDropperTrigger>Examples
Sizes
Use the size prop to change the size of the color picker.
Variants
Use the variant prop to change the visual style of the color picker. Values
can be either outline or subtle.
Input Only
Combine the ColorPicker.ValueSwatch and the ColorPicker.EyeDropper on the
InputGroup to render a color picker that contains only an input.
Swatch Only
Use the ColorPicker.SwatchGroup and ColorPicker.SwatchTrigger to render only
the color swatches.
Trigger Only
Compose the color picker to initially show only a trigger using the
ColorPicker.ValueSwatch and ColorPicker.ValueText.
Trigger Inside Input
Compose the color picker to trigger in input using the InputGroup and
ColorPickerInput.
Controlled
Use the value and onValueChange props to control the state of the color
picker.
Store
An alternative way to control the color picker is to use the RootProvider
component and the useColorPicker store hook.
This way you can access the color picker state and methods from outside the color picker.
Change End
Use the onValueChangeEnd to listen to when the user finishes selecting a
color, rather than while they are scrubbing or dragging through the color area.
onChangeEnd: #EB5E41Channel Slider
Combine the ColorPickerChannelSliders and the format prop to add the
different color channels to the color picker.
Hook Form
Here's an example of how to integrate the color picker with react-hook-form.
Inline
Here's an example of how to display an inline version of the color picker.
Disabled
Pass the disabled prop to disable the color picker.
Channel Input
Use the ChannelFormat.Select and ColorPicker.ChannelInput to create a color
picker that allows users to select their preferred channel.
Fit Content
Pass the data-fit-content attribute to the ColorPicker.Trigger to make it
fit the content.
ReadOnly
Use the readOnly prop to make the color picker component read-only.
Save Swatch
Here's an example of how to save a selected color as a swatch.
Swatches
Here's an example of how to combine the color picker with pre-defined swatches.
Swatch and Input
Here's how to compose a swatch with an input.
Swatch and Trigger
Here's how to compose a swatch with a trigger.
Props
Root
| Prop | Default | Type |
|---|---|---|
closeOnSelect | false | booleanWhether to close the color picker when a swatch is selected |
defaultFormat | 'rgba' | ColorFormatThe initial color format when rendered. Use when you don't need to control the color format of the color picker. |
defaultValue | #000000 | ColorThe initial color value when rendered. Use when you don't need to control the color value of the color picker. |
lazyMount | false | booleanWhether to enable lazy mounting |
openAutoFocus | true | booleanWhether to auto focus the color picker when it is opened |
skipAnimationOnMount | false | booleanWhether to allow the initial presence animation. |
unmountOnExit | false | booleanWhether to unmount on exit. |
colorPalette | gray | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'The color palette of the component |
size | md | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl'The size of the component |
variant | outline | 'outline' | 'subtle'The variant of the component |
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | booleanWhether to remove the component's style. | |
defaultOpen | booleanThe initial open state of the color picker when rendered. Use when you don't need to control the open state of the color picker. | |
disabled | booleanWhether the color picker is disabled | |
format | ColorFormatThe controlled color format to use | |
id | stringThe unique identifier of the machine. | |
ids | Partial<{ root: string; control: string; trigger: string; label: string; input: string; hiddenInput: string; content: string; area: string; areaGradient: string; positioner: string; formatSelect: string; areaThumb: string; channelInput: (id: string) => string; channelSliderTrack: (id: ColorChannel) => string; channe...The ids of the elements in the color picker. Useful for composition. | |
immediate | booleanWhether to synchronize the present change immediately or defer it to the next frame | |
initialFocusEl | () => HTMLElement | nullThe initial focus element when the color picker is opened. | |
inline | booleanWhether to render the color picker inline | |
invalid | booleanWhether the color picker is invalid | |
name | stringThe name for the form input | |
onExitComplete | VoidFunctionFunction called when the animation ends in the closed state | |
onFocusOutside | (event: FocusOutsideEvent) => voidFunction called when the focus is moved outside the component | |
onFormatChange | (details: FormatChangeDetails) => voidFunction called when the color format changes | |
onInteractOutside | (event: InteractOutsideEvent) => voidFunction called when an interaction happens outside the component | |
onOpenChange | (details: OpenChangeDetails) => voidHandler that is called when the user opens or closes the color picker. | |
onPointerDownOutside | (event: PointerDownOutsideEvent) => voidFunction called when the pointer is pressed down outside the component | |
onValueChange | (details: ValueChangeDetails) => voidHandler that is called when the value changes, as the user drags. | |
onValueChangeEnd | (details: ValueChangeDetails) => voidHandler that is called when the user stops dragging. | |
open | booleanThe controlled open state of the color picker | |
positioning | PositioningOptionsThe positioning options for the color picker | |
present | booleanWhether the node is present (controlled by the user) | |
readOnly | booleanWhether the color picker is read-only | |
required | booleanWhether the color picker is required | |
value | ColorThe controlled color value of the color picker |
Explorer
Explore the Color Picker component parts interactively. Click on parts in the
sidebar to highlight them in the preview.
Component Anatomy
Hover to highlight, click to select parts
root
label
control
trigger
positioner
content
area
areaThumb
valueText
areaBackground
channelSlider
channelSliderLabel
channelSliderTrack
channelSliderThumb
channelSliderValueText
channelInput
transparencyGrid
swatchGroup
swatchTrigger
swatchIndicator
swatch
eyeDropperTrigger
formatTrigger
formatSelect
view
channelText