Beta Preview

ColorSwatchPicker

A ColorSwatchPicker displays a list of color swatches and allows a user to select one of them.

layout 
Example
ColorSwatchPicker.tsx
ColorSwatchPicker.css
import {ColorSwatchPicker, ColorSwatchPickerItem} from './ColorSwatchPicker';

<ColorSwatchPicker aria-label="Background color">
  <ColorSwatchPickerItem color="#A00" />
  <ColorSwatchPickerItem color="#f80" />
  <ColorSwatchPickerItem color="#080" />
  <ColorSwatchPickerItem color="#08f" />
  <ColorSwatchPickerItem color="#088" />
  <ColorSwatchPickerItem color="#008" />
</ColorSwatchPicker>

Value

Use the value or defaultValue prop to set the selected color, and onChange to handle selection changes. The value may be a string or object, parsed using the function.

Selected color: rgb(170, 0, 0)
import {ColorSwatchPicker, ColorSwatchPickerItem} from './ColorSwatchPicker';
import {parseColor} from 'react-aria-components';
import {useState} from 'react';

function Example() {
  let [value, setValue] = useState(parseColor('#A00'));

  return (
    <>
      <ColorSwatchPicker value={value} onChange={setValue}>
        <ColorSwatchPickerItem color="#A00" />
        <ColorSwatchPickerItem color="#f80" />
        <ColorSwatchPickerItem color="#080" />
        <ColorSwatchPickerItem color="#08f" />
        <ColorSwatchPickerItem color="#088" />
        <ColorSwatchPickerItem color="#008" />
      </ColorSwatchPicker>
      <pre style={{fontSize: 12}}>Selected color: {value.toString('rgb')}</pre>
    </>
  );
}

API

<ColorSwatchPicker>
  <ColorSwatchPickerItem>
    <ColorSwatch />
  </ColorSwatchPickerItem>
</ColorSwatchPicker>

ColorSwatchPicker

NameTypeDefault
childrenReactNodeDefault:
The children of the ColorSwatchPicker.
layout'grid''stack'Default: 'grid'
Whether the items are arranged in a stack or grid.
valuestringDefault:
The current value (controlled).
defaultValuestringDefault:
The default value (uncontrolled).
onChange(value: ) => voidDefault:
Handler that is called when the value changes.

Default className: react-aria-ColorSwatchPicker

Render PropCSS Selector
isEmptyCSS Selector: [data-empty]
Whether the listbox has no items and should display its empty state.
isFocusedCSS Selector: [data-focused]
Whether the listbox is currently focused.
isFocusVisibleCSS Selector: [data-focus-visible]
Whether the listbox is currently keyboard focused.
layoutCSS Selector: [data-layout="stack | grid"]
Whether the items are arranged in a stack or grid.
stateCSS Selector:
State of the listbox.

ColorSwatchPickerItem

NameType
colorstring
The color of the swatch.
isDisabledboolean
Whether the color swatch is disabled.
children<>
The children of the component. A function may be provided to alter the children based on component state.

Default className: react-aria-ColorSwatchPickerItem

Render PropCSS Selector
colorCSS Selector:
The color of the swatch.
isHoveredCSS Selector: [data-hovered]
Whether the item is currently hovered with a mouse.
isPressedCSS Selector: [data-pressed]
Whether the item is currently in a pressed state.
isSelectedCSS Selector: [data-selected]
Whether the item is currently selected.
isFocusedCSS Selector: [data-focused]
Whether the item is currently focused.
isFocusVisibleCSS Selector: [data-focus-visible]
Whether the item is currently keyboard focused.
isDisabledCSS Selector: [data-disabled]
Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may not be focused. Dependent on disabledKeys and disabledBehavior.