Color Picker

Swatch trigger with hex trailing, hover border, and channel editors.

Also known as: colour picker, swatch picker, hex picker, color swatch

Installation

Install with the CLI, or copy the component source into your project.

Add color-picker (npm)

npx --yes -p @default-file/ui df-ui add color-picker

With hex

Pill trigger shows the hex value. The whole pill opens the picker.

With clear

Replace the hex with an X. The pill still opens the picker; X fires onClear.

Hover border

Inherits the theme hover border on pill triggers. Override with hoverBorderColor, or set hoverBorder false.

Properties

Pill swatch trigger with optional hex or clear trailing, hover border controls, and channel editors in a popover.

ColorPicker

PropTypeDefaultNotes
valuestring-Current color as a hex string (required).
onChange(hex: string) => void-Called when the color changes (required).
labelstring"Pick color"Accessible name for the swatch trigger.
trailing"hex" | "clear"-Optional trailing control: show hex text, or a clear action. Pill triggers use the hover border contract.
onClear() => void-Required when trailing is "clear".
clearLabelstring"Remove color"Accessible label for the clear control.
hoverBorderboolean-Instance hover border on pill triggers (hex or clear). Omit to inherit the theme. Set false to keep the resting border. Set true to force the hover border on. Dot only triggers do not use this contract.
hoverBorderColorstring-Hover border color when hover is active. Prefer tokens such as var(--foreground). Sets --df-color-picker-hover-border.
classNamestring-Additional styles on the pill trigger or swatch root.

Parts

DOM structure markers for styling and tests. These are not component props. data-df="color-picker-trigger": Pill shell for trailing hex or clear. Owns layout, start padding, resting border, and hover border chrome. data-trailing: hex or clear on the pill trigger. data-df="color-picker-open": Inner swatch control on the clear pill. data-hover-border: true or false when hoverBorder is set; omit to inherit the host theme.

Layout & appearance

Popover editors (internal UI): Opened panel supports hex, rgb, hsl, and hsb channel modes (not separate props). Placement flips when there is not enough space.

Tokens

Theme defaults live on :root. Override these globally or on a local host.

TokenTypeDefaultNotes
--df-color-picker-widthCSS length300pxPopover panel width.
--df-color-picker-heightCSS length220pxPopover panel height.
--df-color-picker-hex-widthCSS length7chFixed width for the hex label on the pill trigger so it does not reflow while dragging.
--df-color-picker-trigger-heightCSS lengthcalc(8 * var(--spacing-unit))Pill trigger height.
--df-color-picker-trigger-pad-startCSS lengthcalc(1.5 * var(--spacing-unit))Inset from the start edge of the pill to the swatch.
--df-color-picker-trigger-pad-endCSS lengthcalc(2.5 * var(--spacing-unit))Inset from the end edge of the hex pill.
--df-color-picker-trigger-gapCSS lengthcalc(1.5 * var(--spacing-unit))Space between the swatch and the hex label.
--df-color-picker-trigger-pad-end-clearCSS lengthcalc(0.5 * var(--spacing-unit))Inset from the end edge of the clear pill.
--df-color-picker-trigger-gap-clearCSS lengthcalc(1 * var(--spacing-unit))Space between the swatch and the clear control.
--df-color-picker-borderCSS colorvar(--input)Resting border on the pill trigger.
--df-hover-borderCSS keywordonTheme field hover border. on paints the ink hover border; off keeps the resting border. Runtime gating uses data-df-hover-border on html. Set with df-ui init --hover-border. Default on.
--df-color-picker-hover-borderCSS colorvar(--foreground)Hover border when the theme or instance enables hover. Defaults to the ink foreground. Override with hoverBorderColor.
--df-color-picker-bgCSS colorvar(--muted)Pill trigger fill.
--df-shadow-picker-thumbCSS shadow0 0 0 1px rgb(0 0 0 / 0.45)Ring around the channel thumb.
--df-corner-shapeCSS corner-shapevar(--df-corner-shape-round)Theme corner curve for all kit chrome. round = circular arcs; smooth = continuous squircle. Set with df-ui init --corner-shape, or override on :root. Default round.