# Format converter

> One color as HEX, RGB, HSL, HSB and OKLCH, each with a copy button.

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

- Page, with a live preview: https://shadcn.exchange/r/reui/c-color-picker-7
- Screenshot: https://abzjhwgwpdpz7ua5.public.blob.vercel-storage.com/shots/reui/c-color-picker-7-light-bfd8bb904ce8ce82.png
- Registry item: https://reui.io/r/new-york-v4/c-color-picker-7.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-7.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: `card`, `@reui/color-picker`

## Files

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

```tsx
"use client"

import { useState } from "react"
import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerCopy,
  ColorPickerSlider,
  formatColor,
  useColorPicker,
} from "@/components/reui/color-picker"
import type { ColorPickerFormat } from "@/components/reui/color-picker"

import { Card, CardContent } from "@/components/ui/card"

const FORMATS: Array<{ format: ColorPickerFormat; label: string }> = [
  { format: "hex", label: "HEX" },
  { format: "rgb", label: "RGB" },
  { format: "hsl", label: "HSL" },
  { format: "hsb", label: "HSB" },
  { format: "oklch", label: "OKLCH" },
]

/* Reads the picker through its hook, so it needs no value of its own. */
function FormatList() {
  const { color } = useColorPicker()
  return (
    <ul className="divide-y">
      {FORMATS.map(({ format, label }) => (
        <li
          key={format}
          className="flex items-center gap-3 py-2 first:pt-0 last:pb-0"
        >
          <span className="text-muted-foreground w-12 shrink-0 text-xs font-medium">
            {label}
          </span>
          <code className="min-w-0 flex-1 truncate font-mono text-sm">
            {color ? formatColor(color, format) : "None"}
          </code>
          <ColorPickerCopy
            format={format}
            size="icon-xs"
            aria-label={`Copy ${label}`}
          />
        </li>
      ))}
    </ul>
  )
}

export function Pattern() {
  const [value, setValue] = useState<string | null>("#14b8a6")

  return (
    <Card className="w-full">
      <CardContent>
        <ColorPicker
          value={value}
          onValueChange={setValue}
          alpha
          aria-label="Color to convert"
        >
          {/* Side by side once the card itself has room for the longest value
              (a container query, not the viewport); minmax(0, 1fr) columns
              truncate a value rather than push the copy buttons out. */}
          <div className="@container">
            <div className="grid grid-cols-1 gap-6 @xl:grid-cols-[13rem_minmax(0,1fr)] @xl:items-center">
              <div className="flex flex-col gap-3">
                <ColorPickerArea className="h-36" />
                <ColorPickerSlider channel="hue" />
                <ColorPickerSlider channel="alpha" />
              </div>
              <FormatList />
            </div>
          </div>
        </ColorPicker>
      </CardContent>
    </Card>
  )
}
```
