Skip to content

ColorSwatchPicker

A controlled swatch picker for choosing one named theme color.

Office colorChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="blue"
/>
Office colorChoose the named theme color used for this office.
Office colorChoose the named theme color used for this office.
Office colorChoose the named theme color used for this office.
function SizesStory(args: ColorSwatchPickerProps): React.JSX.Element {
const [value, setValue] = useState(args.value);
return (
<div style={{display: 'grid', gap: 16, justifyItems: 'start'}}>
<ColorSwatchPicker
{...args}
onChange={setValue}
size="sm"
value={value}
/>
<ColorSwatchPicker
{...args}
onChange={setValue}
size="md"
value={value}
/>
<ColorSwatchPicker
{...args}
onChange={setValue}
size="lg"
value={value}
/>
</div>
);
}
<SizesStory {...args} />
Office colorChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="green"
colors={['red', 'orange', 'green', 'blue', 'purple']}
/>
Office colorHover a swatch to see the grow effect.
<ColorSwatchPicker
label="Office color"
description="Hover a swatch to see the grow effect."
size="md"
value="purple"
/>
Office colorChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="blue"
isDisabled
/>
Office colorChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="blue"
status={{message: 'Choose an office color.', type: 'error'}}
/>
Office colorRequiredChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="blue"
isRequired
/>
Office colorChoose the named theme color used for this office.
North officeNorth office
function DrivesOtherComponentsStory(
args: ColorSwatchPickerProps,
): React.JSX.Element {
const [value, setValue] = useState<ColorName>(args.value);
return (
<div style={{display: 'grid', gap: 16, justifyItems: 'start'}}>
<ColorSwatchPicker {...args} onChange={setValue} value={value} />
<div style={{display: 'flex', gap: 8}}>
<Tag color={value} label="North office" />
<Badge color={value} label="North office" />
</div>
</div>
);
}
<DrivesOtherComponentsStory {...args} />
Office colorChoose the named theme color used for this office.
<ColorSwatchPicker
label="Office color"
description="Choose the named theme color used for this office."
size="md"
value="blue"
isReadOnly
/>

A controlled swatch picker for choosing one named theme color.

When isOptional: false, isRequired: false

PropTypeDefaultDescription
classNamestringAdditional CSS class names applied to the field root.
colorsReadonlyArray<ColorName>COLOR_NAMESPalette colors to render, in display order.
data-testidstringTest ID applied to the field root.
descriptionReactNodeSupporting text displayed below the label.
isDisabledbooleanfalseWhether all swatches are disabled.
isReadOnlybooleanfalseWhether the selected color is displayed without allowing interaction.
isLabelHiddenbooleanfalseWhether to visually hide the label.
label*stringLabel text for the swatch picker.
labelTooltipReactNodeTooltip content shown next to the label.
onChange*(value: ColorName) => voidCallback fired when the selected color changes.
refRef<HTMLDivElement>Ref forwarded to the field root.
size"sm" | "md" | "lg"'md'Size of the swatches.
statusInputStatusValidation status displayed below the picker.
styleCSSPropertiesInline styles applied to the field root.
value*"red" | "orange" | "yellow" | "green" | "teal" | "cyan" | "blue" | "purple" | "pink" | "gray"The currently selected color.
isOptionalfalse
isRequiredfalse

When isOptional: true, isRequired: false

PropTypeDefaultDescription
classNamestringAdditional CSS class names applied to the field root.
colorsReadonlyArray<ColorName>COLOR_NAMESPalette colors to render, in display order.
data-testidstringTest ID applied to the field root.
descriptionReactNodeSupporting text displayed below the label.
isDisabledbooleanfalseWhether all swatches are disabled.
isReadOnlybooleanfalseWhether the selected color is displayed without allowing interaction.
isLabelHiddenbooleanfalseWhether to visually hide the label.
label*stringLabel text for the swatch picker.
labelTooltipReactNodeTooltip content shown next to the label.
onChange*(value: ColorName) => voidCallback fired when the selected color changes.
refRef<HTMLDivElement>Ref forwarded to the field root.
size"sm" | "md" | "lg"'md'Size of the swatches.
statusInputStatusValidation status displayed below the picker.
styleCSSPropertiesInline styles applied to the field root.
value*"red" | "orange" | "yellow" | "green" | "teal" | "cyan" | "blue" | "purple" | "pink" | "gray"The currently selected color.
isOptional*true
isRequiredfalse

When isOptional: false, isRequired: true

PropTypeDefaultDescription
classNamestringAdditional CSS class names applied to the field root.
colorsReadonlyArray<ColorName>COLOR_NAMESPalette colors to render, in display order.
data-testidstringTest ID applied to the field root.
descriptionReactNodeSupporting text displayed below the label.
isDisabledbooleanfalseWhether all swatches are disabled.
isReadOnlybooleanfalseWhether the selected color is displayed without allowing interaction.
isLabelHiddenbooleanfalseWhether to visually hide the label.
label*stringLabel text for the swatch picker.
labelTooltipReactNodeTooltip content shown next to the label.
onChange*(value: ColorName) => voidCallback fired when the selected color changes.
refRef<HTMLDivElement>Ref forwarded to the field root.
size"sm" | "md" | "lg"'md'Size of the swatches.
statusInputStatusValidation status displayed below the picker.
styleCSSPropertiesInline styles applied to the field root.
value*"red" | "orange" | "yellow" | "green" | "teal" | "cyan" | "blue" | "purple" | "pink" | "gray"The currently selected color.
isOptionalfalse
isRequired*true