ColorPicker
Native color selection control with token-backed styling.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { ColorPicker } from "@tavojs/ui/color-picker";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/color-picker.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
ColorPicker example
tsximport { createTavo } from "@tavojs/core";
import { ColorPicker } from "@tavojs/ui/color-picker";
import { Text } from "@tavojs/ui";
type State = { color: string; savedColor: string };
export const ColorPickerExample1 = createTavo<Record<string, never>, State>({
model: () => ({ color: "#6633ff", savedColor: "#6633ff" }),
view: ({ state, model }) => (
<>
<ColorPicker
aria-label="Brand color"
value={state.color}
onValueInput={(color) => model.set("color", color)}
onValueChange={(color) => model.patch({ color, savedColor: color })}
/>
<Text>Committed color: {state.savedColor}</Text>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
value | string | — | Controlled color value in `#rrggbb` format. |
defaultValue | string | — | Initial color value for an uncontrolled picker. |
name | string | — | Form field name submitted with the selected color. |
size | Size | — | Control scale: `sm`, `md`, or `lg`. |
format | "hex" | "css" | — | Keeps the backward-compatible native picker or enables CSS-string editing. |
swatches | Array<string | ColorPickerOption> | — | Optional reusable paint choices. |
tokens | ColorPickerOption[] | — | Optional labeled CSS token choices. |
onValueInput | (value: string) => void | — | Runs for transient paint previews. |
Complete TypeScript API
Import from @tavojs/ui/color-picker. Published exports: ColorPicker, ColorPickerOption, ColorPickerProps.
ColorPickerProps
| Property | Type | Required | Description |
|---|---|---|---|
className | string | No | Optional class hook applied to the public root element owned by the component. |
size | Size | No | Control scale: `sm`, `md`, or `lg`. |
format | "hex" | "css" | No | Keeps the backward-compatible native picker or enables CSS-string editing. |
label | Child | No | Inherited label attribute accepted by ColorPicker. |
value | string | No | Controlled color value in `#rrggbb` format. |
defaultValue | string | No | Initial color value for an uncontrolled picker. |
name | string | No | Form field name submitted with the selected color. |
placeholder | string | No | Inherited placeholder attribute accepted by ColorPicker. |
required | boolean | No | Inherited required attribute accepted by ColorPicker. |
type | never | No | Inherited type attribute accepted by ColorPicker. |
swatches | (string | ColorPickerOption)[] | No | Optional reusable paint choices. |
tokens | ColorPickerOption[] | No | Optional labeled CSS token choices. |
onValueInput | (value: string) => void | No | Runs for transient paint previews. |
onValueChange | (value: string) => void | No | Inherited onValueChange attribute accepted by ColorPicker. |
onChange | ValueChangeHandler<HTMLInputElement> | No | Inherited onChange attribute accepted by ColorPicker. |
onInput | ValueChangeHandler<HTMLInputElement> | No | Inherited onInput attribute accepted by ColorPicker. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | Use value to supply rendered state. Update it through the documented callback or native event handler. For browser-owned initial values, use defaultValue instead. |
| DOM target | Native input attributes target the owned form control; wrapper-specific props stay on the documented component root. |
Anatomy and related components
Limitations
Avoid ColorPicker when wrapping controls without labels or accessible names.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
Pair native mode with `Field` or `aria-label`; CSS mode accepts a visible `label` and keeps the solid-color chooser keyboard reachable.
Pair native mode with `Field` or `aria-label`; CSS mode accepts a visible `label` and keeps the solid-color chooser keyboard reachable.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/color-picker |
| Explicit CSS import | @tavojs/ui/css/color-picker |
| Preview | Interactive preview available on this page |