View as Markdown

API reference: @salmonui/inputs/color-picker

ColorPickercomponent

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

Color picker: a trigger button with a swatch preview that opens a popover, or an inline panel. The panel composes the parts: ColorArea, hue and alpha ColorSliders and a ColorField (mode 'area'), or a ColorSwatchPicker (mode 'swatches'), recent colors and Apply / Cancel. The popover is a role="dialog" that takes focus on open and returns it to the trigger on close. A hidden input with name submits the value.

Props: ColorPickerProps

ColorPicker props (42)
NameSignatureDescription
labeloptionalinheritedlabel?: ReactNode;
descriptionoptionalinheriteddescription?: ReactNode;
errorMessageoptionalinheritederrorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) | ReactNode;

Error text (or a function of the errors) shown while the field is invalid.

invalidoptionalinheritedinvalid?: boolean;

Forces the error state.

validationoptionalinheritedvalidation?: FieldValidation;

Rules in the Data Grid vocabulary.

validateOnoptionalinheritedvalidateOn?: ValidateOn;

When errors appear; default the Form's, else 'blur'.

sizeoptionalinheritedsize?: FieldSize;

Metric set. Default 'md'.

valueoptionalreadonly value?: string | null | undefined;

The color in valueFormat, or null for no color.

defaultValueoptionalreadonly defaultValue?: string | null | undefined;

Default '#008000ff'.

onValueChangeoptionalreadonly onValueChange?: ((value: string | null, details: ColorPickerChangeDetails) => void) | undefined;

Every pick, at most once per animation frame while dragging.

onValueCommitoptionalreadonly onValueCommit?: ((value: string | null, details: ColorPickerChangeDetails) => void) | undefined;

A committed value: Apply with commitBehavior: 'confirm', else a drag end, key step, field entry or swatch pick.

valueFormatoptionalreadonly valueFormat?: ColorFormat | undefined;

Default 'hexa'. With 'hex' the alpha slider is hidden.

modeoptionalreadonly mode?: ColorPickerMode | undefined;
defaultModeoptionalreadonly defaultMode?: ColorPickerMode | undefined;

Default 'area'.

onModeChangeoptionalreadonly onModeChange?: ((mode: ColorPickerMode) => void) | undefined;
onBeforeModeChangeoptionalreadonly onBeforeModeChange?: ((event: ColorPickerBeforeModeChangeEvent) => void) | undefined;

Cancellable.

showModeSwitchoptionalreadonly showModeSwitch?: boolean | undefined;

The button that switches between the area and the palette. Default true.

inlineoptionalreadonly inline?: boolean | undefined;

Renders the panel in place, without a trigger or popover.

alphaoptionalreadonly alpha?: boolean | undefined;

The alpha slider and alpha in the hex field. Default true.

clearableoptionalreadonly clearable?: boolean | undefined;

A "no color" swatch (and the field's clear button); value null.

commitBehavioroptionalreadonly commitBehavior?: 'confirm' | 'immediate' | undefined;

'confirm' (default): Apply and Cancel buttons, Cancel or a dismissal discards the picks. 'immediate': every pick commits.

recentColorsoptionalreadonly recentColors?: readonly string[] | undefined;

Recently committed colors, newest first. Shown and tracked when this or defaultRecentColors is set; never stored.

defaultRecentColorsoptionalreadonly defaultRecentColors?: readonly string[] | undefined;
onRecentColorsChangeoptionalreadonly onRecentColorsChange?: ((colors: readonly string[]) => void) | undefined;
maxRecentColorsoptionalreadonly maxRecentColors?: number | undefined;

Default 10.

colorsoptionalreadonly colors?: readonly ColorSwatchItem[] | readonly ColorSwatchGroup[] | undefined;

Palette of the swatches mode; default the ColorSwatchPicker palette.

columnsoptionalreadonly columns?: number | undefined;

Palette columns. Default 10.

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

Replaces each palette swatch.

openoptionalreadonly open?: boolean | undefined;
defaultOpenoptionalreadonly defaultOpen?: boolean | undefined;
onOpenChangeoptionalreadonly onOpenChange?: ((open: boolean, details: ColorPickerOpenChangeDetails) => void) | undefined;
onBeforeOpenChangeoptionalreadonly onBeforeOpenChange?: ((event: ColorPickerBeforeOpenChangeEvent) => void) | undefined;

Cancellable.

nameoptionalreadonly name?: string | undefined;

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

formoptionalreadonly form?: string | undefined;
disabledoptionalreadonly disabled?: boolean | undefined;
requiredoptionalreadonly required?: boolean | undefined;
idoptionalreadonly id?: string | undefined;
aria-labeloptionalreadonly 'aria-label'?: string | undefined;

Accessible name of the trigger without a label.

localeTextoptionalreadonly localeText?: ColorPickerLocaleText | undefined;
classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
refoptionalreadonly ref?: Ref<HTMLElement> | undefined;

The trigger button (the panel group when inline).