View as Markdown

API reference: @salmonui/inputs/color-picker

ColorPickerPropsinterface

import type { ColorPickerProps } from '@salmonui/inputs/color-picker';
interface ColorPickerProps extends FieldCommonProps {
    readonly value?: string | null | undefined;
    readonly defaultValue?: string | null | undefined;
    readonly onValueChange?: ((value: string | null, details: ColorPickerChangeDetails) => void) | undefined;
    readonly onValueCommit?: ((value: string | null, details: ColorPickerChangeDetails) => void) | undefined;
    readonly valueFormat?: ColorFormat | undefined;
    readonly mode?: ColorPickerMode | undefined;
    readonly defaultMode?: ColorPickerMode | undefined;
    readonly onModeChange?: ((mode: ColorPickerMode) => void) | undefined;
    readonly onBeforeModeChange?: ((event: ColorPickerBeforeModeChangeEvent) => void) | undefined;
    readonly showModeSwitch?: boolean | undefined;
    readonly inline?: boolean | undefined;
    readonly alpha?: boolean | undefined;
    readonly clearable?: boolean | undefined;
    readonly commitBehavior?: 'confirm' | 'immediate' | undefined;
    readonly recentColors?: readonly string[] | undefined;
    readonly defaultRecentColors?: readonly string[] | undefined;
    readonly onRecentColorsChange?: ((colors: readonly string[]) => void) | undefined;
    readonly maxRecentColors?: number | undefined;
    readonly colors?: readonly ColorSwatchItem[] | readonly ColorSwatchGroup[] | undefined;
    readonly columns?: number | undefined;
    readonly renderSwatch?: ((ctx: SwatchRenderContext) => ReactNode) | undefined;
    readonly open?: boolean | undefined;
    readonly defaultOpen?: boolean | undefined;
    readonly onOpenChange?: ((open: boolean, details: ColorPickerOpenChangeDetails) => void) | undefined;
    readonly onBeforeOpenChange?: ((event: ColorPickerBeforeOpenChangeEvent) => void) | undefined;
    readonly name?: string | undefined;
    readonly form?: string | undefined;
    readonly disabled?: boolean | undefined;
    readonly required?: boolean | undefined;
    readonly id?: string | undefined;
    readonly 'aria-label'?: string | undefined;
    readonly localeText?: ColorPickerLocaleText | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly ref?: Ref<HTMLElement> | undefined;
}
ColorPickerProps members (42, 7 inherited)
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).