# Recent colors

> Each pick is saved to a Recent row once a drag is released, not on every move.

A shadcn/ui block from the [@reui](https://reui.io) registry, listed on [shadcn.exchange](https://shadcn.exchange/r/reui/c-color-picker-9).

- Page, with a live preview: https://shadcn.exchange/r/reui/c-color-picker-9
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/reui/c-color-picker-9-light-b37135dde7fd4575.png
- Registry item: https://reui.io/r/new-york-v4/c-color-picker-9.json
- Listed: 2026-10-13, source last changed 2026-10-13

## Install

```bash
npx shadcn@latest add https://reui.io/r/new-york-v4/c-color-picker-9.json
```

Run it in a project that has shadcn/ui set up. It adds the files below and installs what they depend on.

## Dependencies

- Registry items: `@reui/color-picker`, `field`

## Files

### `c-color-picker-9.tsx`

```tsx
"use client"

import { useState } from "react"
import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerContent,
  ColorPickerEyeDropper,
  ColorPickerFields,
  ColorPickerPanel,
  ColorPickerSlider,
  ColorPickerSwatches,
  ColorPickerTrigger,
} from "@/components/reui/color-picker"

import {
  Field,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field"

export function Pattern() {
  const [color, setColor] = useState<string | null>("#2563eb")
  const [recent, setRecent] = useState([
    "#0f172a",
    "#e11d48",
    "#f59e0b",
    "#10b981",
  ])

  return (
    <div className="w-full max-w-xs">
      <Field>
        <FieldLabel id="brush-color-label" htmlFor="brush-color">
          Brush color
        </FieldLabel>
        {/* `onValueCommit` fires once per pick, when a drag is released, so
            dragging across the area adds one recent color, not hundreds. */}
        <ColorPicker
          id="brush-color"
          value={color}
          onValueChange={setColor}
          onValueCommit={(next) => {
            if (!next) return
            setRecent((list) =>
              [next, ...list.filter((item) => item !== next)].slice(0, 8)
            )
          }}
          aria-labelledby="brush-color-label"
          aria-describedby="brush-color-description"
        >
          <ColorPickerTrigger />
          <ColorPickerContent>
            <ColorPickerPanel>
              <ColorPickerArea />
              <div className="flex items-center gap-3">
                <ColorPickerEyeDropper />
                <ColorPickerSlider channel="hue" />
              </div>
              <ColorPickerFields />
              <div className="flex flex-col gap-2">
                <span
                  id="brush-recent-label"
                  className="text-muted-foreground text-xs font-medium"
                >
                  Recent
                </span>
                <ColorPickerSwatches
                  colors={recent}
                  aria-labelledby="brush-recent-label"
                />
              </div>
            </ColorPickerPanel>
          </ColorPickerContent>
        </ColorPicker>
        <FieldDescription id="brush-color-description">
          Colors you pick are kept under Recent.
        </FieldDescription>
      </Field>
    </div>
  )
}
```
