dentil

Color Picker

ColorPicker reads and writes a 6-digit hex with no leading #. Type it, or open the swatch for a saturation and hue picker. The first field starts on a random color. The second turns invalid until the value is six digits.

@dentil/color-picker
On this page
#
Result: —
#
Result: —

Installation

pnpm dlx shadcn@latest add @dentil/color-picker
npx shadcn@latest add @dentil/color-picker
yarn dlx shadcn@latest add @dentil/color-picker
bunx --bun shadcn@latest add @dentil/color-picker

Files land in components/dentil/color-picker/. Uses the stock shadcn input-group, button and popover, and react-colorful for the saturation and hue picker.

API reference

ColorPicker

PropTypeDefaultDescription
valuestring | null | undefined—6-digit hex without a leading #, e.g. ed5656. A leading # is ignored. Until the value is six digits, the picker opens on a random color.
onChange(value: string) => void—Called on every change with the hex and no #, including a partial value such as ed56. Characters other than 0–9 and a–f are removed.
placeholderstring'ed5656'Shown while the field is empty.
classNamestring—Applied to the root, around the field and the swatch.
…propsComponentProps<'input'>—Other props (id, aria-invalid, aria-describedby, name…) are passed to the input. Pass aria-invalid while the value is not six hex digits.