View as Markdown

API reference: @salmonui/inputs/color-picker

ColorSwatchPickercomponent

import { ColorSwatchPicker } from '@salmonui/inputs/color-picker';
function ColorSwatchPicker(props: ColorSwatchPickerProps): ReactNode;

A palette as an APG listbox laid out as a grid: one tab stop (roving tabindex), arrows move by cell and row (ArrowLeft / ArrowRight mirrored in right-to-left content), Home / End to the row ends, Ctrl+Home / Ctrl+End to the first and last swatch, Enter or Space (or a click) selects. Groups are labelled role="group"s.

Props: ColorSwatchPickerProps

ColorSwatchPicker props (17)
NameSignatureDescription
colorsoptionalreadonly colors?: readonly ColorSwatchItem[] | readonly ColorSwatchGroup[] | undefined;

Flat entries or labelled groups. Default: a 10-column palette of grays and 9 hues in 5 shades.

columnsoptionalreadonly columns?: number | undefined;

Swatches per row. Default 10.

valueoptionalreadonly value?: string | null | undefined;
defaultValueoptionalreadonly defaultValue?: string | null | undefined;
onValueChangeoptionalreadonly onValueChange?: ((value: string | null, details: SwatchChangeDetails) => void) | undefined;
clearableoptionalreadonly clearable?: boolean | undefined;

Adds a "no color" swatch first; picking it sets null.

renderSwatchoptionalreadonly renderSwatch?: ((ctx: SwatchRenderContext) => ReactNode) | undefined;

Replaces the swatch inside each option.

nameoptionalreadonly name?: string | undefined;

Name of a hidden input carrying the value ('' for no color).

formoptionalreadonly form?: string | undefined;
disabledoptionalreadonly disabled?: boolean | undefined;
localeTextoptionalreadonly localeText?: { readonly noColor?: string; readonly colorName?: (color: Color) => string; } | undefined;
classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
idoptionalreadonly id?: string | undefined;
aria-labeloptionalreadonly 'aria-label'?: string | undefined;
aria-labelledbyoptionalreadonly 'aria-labelledby'?: string | undefined;
refoptionalreadonly ref?: Ref<HTMLDivElement> | undefined;

The listbox element.