Color Picker

Pick a color from a square and sliders, as hex, RGB or HSL, with the eyedropper, swatches and tokens.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/color-picker

Usage

import { ColorPicker } from "./ui/uicontext/components/canvas/ColorPicker.ts"
const Message = UiSchema.TaggedEnum({ RequestedFill: { color: Schema.String, live: Schema.Boolean } })export const Fill = (h: Html.H<typeof Message.Type>, color: string) =>	ColorPicker(h, {		props: { value: color },		onEmit: {			RequestedColor: ({ color: next, live }) => Message.RequestedFill({ color: next, live }),			RequestedToken: ({ color: next }) => Message.RequestedFill({ color: next, live: false }),		},	})

API reference

Props

ColorPicker props
NameTypeDefaultDescription
valuerequiredstring——
tokenstring | null—The token the value comes from, if any: its swatch shows picked
swatchesColorSwatch[]—Colors already in the document
tokensColorSwatch[]—Design tokens, by name
alphabooleanonShow the alpha slider and field; on by default

Events

ColorPicker events
EventPayloadDescription
RequestedColor{ color: string; live: boolean }—
RequestedToken{ token: string; color: string }A token was picked: store its name with the color

Source