Skip to content

Color Picker ​

Pick a colour with a saturation / brightness area, hue and alpha sliders, a validated input and preset swatches. SColorPanel is the inline panel; SColorPicker opens it from a trigger in a popover, or in a bottom sheet on compact touch screens.

Usage ​

Approximate web preview — the HarmonyOS rendering is the reference.

Picker in a form ​

The trigger is an outline button with the colour chip and value; triggerWidth: '100%' fills the field.

Approximate web preview — the HarmonyOS rendering is the reference.

Alpha & formats ​

alpha adds an opacity slider; format sets the value format (hex, rgb, hsl, oklch) and formatToggle lets the input show any of them.

Approximate web preview — the HarmonyOS rendering is the reference.

Swatches ​

swatches replaces the default palette ([] hides it); recent lists recently committed colours.

Approximate web preview — the HarmonyOS rendering is the reference.

Controlled ​

onValueChange fires live while dragging; onValueCommit once on release and when the popover closes.

Approximate web preview — the HarmonyOS rendering is the reference.

API ​

Extracted from the @Param / @Event / @BuilderParam declarations in the library sources.

SColorPanel ​

Inline colour panel: a saturation / brightness area, a hue slider, an optional alpha slider (over a checkerboard), a preview swatch, a colour input, optional format toggle, preset swatches and recent colours. The body of {@link SColorPicker}'s popover; usable on its own.

  • value / $value / defaultValue: a colour string in the format of the panel ('hex' default → #rrggbb, #rrggbbaa with alpha when translucent; 'rgb' | 'hsl' | 'oklch' → CSS functions). Any CSS colour SparkColor understands is accepted as input. Hex is CSS order: use SparkColor.parse(v).value (or sparkColorValueToArgb) for an ArkUI #AARRGGBB colour.
  • onValueChange fires live while dragging; onValueCommit once per interaction (release, tap, key, swatch, Enter / blur of the input).
  • The input accepts #RGB / #RRGGBB / #RRGGBBAA (and the other CSS forms); invalid text shows the error look and is reverted on blur. formatToggle adds a HEX / RGB / HSL / OKLCH button that only changes what the input displays.
  • swatches (default: a shadcn-like palette; [] hides them), recent (recently committed colours, shared app-wide, see SparkColorRecents).
  • Keyboard: arrows move the area thumb (saturation ←→, brightness ↑↓) and step the hue / alpha sliders.
  • The trailing closure renders below the panel (e.g. actions).
PropTypeDefaultDescription
value!!string | undefinedundefinedControlled value (use with !!). Leave undefined for uncontrolled.
defaultValuestring'#000000'Uncontrolled initial value.
formatColorPickerFormat
ColorPickerFormat = 'hex' | 'rgb' | 'hsl' | 'oklch'
'hex'Format of emitted values.
alphabooleanfalseShow the alpha slider and keep alpha in values.
disabledbooleanfalse
sizingInputSize
InputSize = 'sm' | 'default' | 'lg'
'default'Size of the colour input / format button.
showInputbooleantrueShow the colour input row.
formatTogglebooleanfalseHEX / RGB / HSL / OKLCH button that cycles the input's display format.
swatchesstring[]SPARK_DEFAULT_SWATCHESPreset swatches (any CSS colours); [] hides the row.
recentbooleanfalseShow recently committed colours (shared by all panels).
panelWidthLength | undefinedundefinedPanel width; undefined → --color-picker-width / 240vp. Pass '100%' to fill.
labelstring | undefinedundefinedAccessible name prefix of the panel's controls.
tokensColorPickerTokens{}Per-instance token overrides (instance → theme --color-picker-* → recipe), see {@link ColorPickerTokens}.
EventTypeDefaultDescription
onValueChange(v: string) => void() => { }Live, while dragging.
onValueCommit(v: string) => void() => { }Once an interaction ends (release, tap, key, swatch, input Enter / blur).

Slots: children (trailing closure)

SColorPicker ​

Colour picker: an outline-button trigger showing the colour chip and value (or only the chip with iconOnly) that opens an {@link SColorPanel} in a popover anchored below the trigger, or in a bottom sheet on compact touch windows (adaptive: 'auto').

Values follow {@link SColorPanel}: a colour string in format ('hex' default), onValueChange live while dragging, onValueCommit when an interaction ends and once more on close if the last value was not committed yet. The trailing closure renders at the bottom of the panel. tokens restyle the panel (--color-picker-*); surfaceTokens the popover surface (--popover-*).

PropTypeDefaultDescription
value!!string | undefinedundefinedControlled value (use with !!). Leave undefined for uncontrolled.
defaultValuestring'#000000'
formatColorPickerFormat
ColorPickerFormat = 'hex' | 'rgb' | 'hsl' | 'oklch'
'hex'Format of emitted values and of the trigger text.
alphabooleanfalse
disabledbooleanfalse
sizingInputSize
InputSize = 'sm' | 'default' | 'lg'
'default'Trigger (and panel input) size.
iconOnlybooleanfalseSquare trigger showing only the colour chip.
triggerWidthLength | undefinedundefinedTrigger width; undefined → fits its content.
formatTogglebooleanfalse
showInputbooleantrue
swatchesstring[]SPARK_DEFAULT_SWATCHES
recentbooleanfalse
labelstring | undefinedundefinedAccessible name of the trigger (default "Pick a color").
adaptiveSparkAdaptive
SparkAdaptive = 'auto' | 'pointer' | 'touch'
'auto'
tokensColorPickerTokens{}Panel tokens (instance → --color-picker-* → recipe).
surfaceTokensSparkSurfaceTokens{}Popover surface tokens (instance → --popover-* → recipe).
EventTypeDefaultDescription
onValueChange(v: string) => void() => { }
onValueCommit(v: string) => void() => { }
onOpenChange(open: boolean) => void() => { }

Slots: children (trailing closure)

MIT Licensed