Skip to content

components/SwatchPicker

import { … } from 'zidane-ui'ui/src/components/SwatchPicker.tsx

Components#

SwatchPickerComponent#

Renders swatches as a radio group, with a caption that names the swatch in view.

TypeScript
function SwatchPicker<T extends string>(props: SwatchPickerProps<T>): Element
Type parameters
NameTypeDescription
Textends string
Parameters
NameTypeDescription
propsSwatchPickerProps<T>

Component props.

Element
SwatchPicker props
NameTypeDefaultDescription
ariaLabelstring

Accessible name of the radio group.

caption?(option: Swatch<T>) => ReactNode

Formats the caption of a swatch. Defaults to its label.

className?string

Extra classes on the picker.

columns?4 | 5 | 65

Tiles per row, for tile.

note?ReactNode

A muted line under the caption, such as where the pick shows.

onChange(value: T) => void

Called with the value of the swatch picked by click or keyboard.

optionsreadonly Swatch<T>[]

The swatches, in order.

shape?'dot' | 'tile''dot'

dot: 28px circles in a row, for colors. tile: square tiles in a grid, for images.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

valueT | undefined

The value of the picked swatch. undefined: none is picked.

ui/src/components/SwatchPicker.tsx:62

Interfaces#

SwatchInterface#

One swatch of a SwatchPicker.

TypeScript
interface Swatch<T extends string>
Swatch type parameters
NameTypeDescription
Textends string
Swatch properties
NameTypeDescription
labelstring

Name of the swatch: the caption and the accessible name.

swatchReactNode

What the swatch shows: a color that fills the dot, or an image for a tile.

valueT

The value reported to onChange when the swatch is picked. Unique among the swatches.

ui/src/components/SwatchPicker.tsx:11

SwatchPickerPropsInterface#

Props for SwatchPicker.

TypeScript
interface SwatchPickerProps<T extends string>
SwatchPickerProps type parameters
NameTypeDescription
Textends string
SwatchPickerProps properties
NameTypeDefaultDescription
ariaLabelstring

Accessible name of the radio group.

caption?(option: Swatch<T>) => ReactNode

Formats the caption of a swatch. Defaults to its label.

className?string

Extra classes on the picker.

columns?4 | 5 | 65

Tiles per row, for tile.

note?ReactNode

A muted line under the caption, such as where the pick shows.

onChange(value: T) => void

Called with the value of the swatch picked by click or keyboard.

optionsreadonly Swatch<T>[]

The swatches, in order.

shape?'dot' | 'tile''dot'

dot: 28px circles in a row, for colors. tile: square tiles in a grid, for images.

style?CSSProperties

Inline styles on the root element, merged after the component's own.

valueT | undefined

The value of the picked swatch. undefined: none is picked.

ui/src/components/SwatchPicker.tsx:28