Components
Color picker
NativeChoose saturation, brightness, hue and opacity, check contrast, or select a labelled palette swatch.
Your workspace color
A little personality, with contrast you can check.
Left and right change saturation. Up and down change brightness. Hold Shift for steps of ten.
Contrast: 6.16:1 on white ยท 3.41:1 on black (opacity included).
Installation
npx nook-ui@latest add color-pickerPrompt
Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.
Short. For assistants that can run commands in your project.
Add the Nook "Color picker" component to this project, exactly as Nook ships it.
Choose saturation, brightness, hue and opacity, check contrast, or select a labelled palette swatch.
Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add color-picker`. It writes `components/ui/color-picker.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/color-picker.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:
```tsx
"use client";
import * as React from "react";
import { ColorPicker } from "@/components/ui/color-picker";
import { Button } from "@/components/ui/button";
import { Popover, PopoverTrigger, PopoverContent, PopoverTitle } from "@/components/ui/popover";
export default function ColorPickerDefault() {
const [color, setColor] = React.useState("#2952e3");
return <div className="grid w-full max-w-sm gap-5"><div><h3 className="font-semibold">Your workspace color</h3><p className="mt-1 text-xs text-muted-foreground">A little personality, with contrast you can check.</p></div><ColorPicker value={color} onValueChange={setColor} alpha presets={[{ name: "Cobalt", value: "#2952e3" }, { name: "Forest", value: "#247660" }, { name: "Plum", value: "#8053a5" }, { name: "Ink", value: "#24252b" }]} /><Popover><PopoverTrigger render={<Button variant="outline" />}>Open color picker</PopoverTrigger><PopoverContent className="w-72"><PopoverTitle className="mb-3">Choose an accent</PopoverTitle><ColorPicker value={color} onValueChange={setColor} /></PopoverContent></Popover></div>;
}
```
API
- `ColorPicker`: No color dependency. Contrast uses WCAG relative luminance, compositing alpha separately over white and black. The areaโs gradients represent color data, independent of the interface theme.
- `value, defaultValue, onValueChange` (`string, string, (hex: string) => void`): A # followed by six hex digits, or eight including alpha. Supply valid values; invalid external values use the default color for the controls.
- `alpha` (`boolean`, default false): Show the opacity slider. Existing eight-digit values retain alpha.
- `presets` (`PaletteSwatch[]`): Named preset colors with name and value.
- `Palette`: Labelled swatches, each with name and hex text. The ramp variant lays out ten supplied color steps.
- `swatches` (`{ name: string; value: string }[]`): The actual authored colors. Invalid hex swatches are omitted.
- `value, defaultValue, onValueChange` (`string, string, (hex: string) => void`): Selected color and change callback.
- `variant, copyOnPress` (`"grid" | "ramp", boolean`, default grid, false): Choose layout and optionally copy the selected swatch. Clipboard failures are announced.
Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: The color area announces both saturation and brightness; Left/Right change saturation and Up/Down brightness. Shift uses steps of ten. Hue and opacity use native range inputs. The hex field reports invalid input without changing the color, and copy results are announced.
Done when the component renders like the example in light and dark mode and the project type-checks.Usage
"use client";
import * as React from "react";
import { ColorPicker } from "@/components/ui/color-picker";
import { Button } from "@/components/ui/button";
import { Popover, PopoverTrigger, PopoverContent, PopoverTitle } from "@/components/ui/popover";
export default function ColorPickerDefault() {
const [color, setColor] = React.useState("#2952e3");
return <div className="grid w-full max-w-sm gap-5"><div><h3 className="font-semibold">Your workspace color</h3><p className="mt-1 text-xs text-muted-foreground">A little personality, with contrast you can check.</p></div><ColorPicker value={color} onValueChange={setColor} alpha presets={[{ name: "Cobalt", value: "#2952e3" }, { name: "Forest", value: "#247660" }, { name: "Plum", value: "#8053a5" }, { name: "Ink", value: "#24252b" }]} /><Popover><PopoverTrigger render={<Button variant="outline" />}>Open color picker</PopoverTrigger><PopoverContent className="w-72"><PopoverTitle className="mb-3">Choose an accent</PopoverTitle><ColorPicker value={color} onValueChange={setColor} /></PopoverContent></Popover></div>;
}Examples
A ten-step color ramp
Cobalt ramp
Select a step to copy its hex value.
With opacity
Left and right change saturation. Up and down change brightness. Hold Shift for steps of ten.
Contrast: 3.62:1 on white ยท 2.90:1 on black (opacity included).
With brand presets
Left and right change saturation. Up and down change brightness. Hold Shift for steps of ten.
Contrast: 2.54:1 on white ยท 8.28:1 on black.
Live preview
Use onValueChange to preview the color where it will be used.
Left and right change saturation. Up and down change brightness. Hold Shift for steps of ten.
Contrast: 5.70:1 on white ยท 3.69:1 on black.
Your accent on the invoice header
Props
ColorPicker
No color dependency. Contrast uses WCAG relative luminance, compositing alpha separately over white and black. The areaโs gradients represent color data, independent of the interface theme.
| Prop | Type | Default | Description |
|---|---|---|---|
| value, defaultValue, onValueChange | string, string, (hex: string) => void | โ | A # followed by six hex digits, or eight including alpha. Supply valid values; invalid external values use the default color for the controls. |
| alpha | boolean | false | Show the opacity slider. Existing eight-digit values retain alpha. |
| presets | PaletteSwatch[] | โ | Named preset colors with name and value. |
Palette
Labelled swatches, each with name and hex text. The ramp variant lays out ten supplied color steps.
| Prop | Type | Default | Description |
|---|---|---|---|
| swatches | { name: string; value: string }[] | โ | The actual authored colors. Invalid hex swatches are omitted. |
| value, defaultValue, onValueChange | string, string, (hex: string) => void | โ | Selected color and change callback. |
| variant, copyOnPress | "grid" | "ramp", boolean | grid, false | Choose layout and optionally copy the selected swatch. Clipboard failures are announced. |
Accessibility
The color area announces both saturation and brightness; Left/Right change saturation and Up/Down brightness. Shift uses steps of ten. Hue and opacity use native range inputs. The hex field reports invalid input without changing the color, and copy results are announced.
Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.