HextaUI

Color picker (UI SDK): Presets and channels

ColorPickerSwatches is one tab stop with arrow keys between presets, and a preset stays selected however the value is written. ColorPickerChannelInput edits one channel as a number. The eyedropper hides itself in browsers that can’t pick from the screen.

import {
  ColorPicker,
  ColorPickerChannelInput,
  ColorPickerEyeDropper,
  ColorPickerSwatch,
  ColorPickerSwatches,
  ColorPickerSwatchItem,
} from "@/components/ui/ui-sdk-color-picker"

const presets = [
  "#ef4444",
  "#f97316",
  "#eab308",
  "#22c55e",
  "#0ea5e9",
  "#6366f1",
  "#a855f7",
  "#ec4899",
]

const channels = [
  { channel: "red", label: "R" },
  { channel: "green", label: "G" },
  { channel: "blue", label: "B" },
] as const

function UiSdkColorPickerChannels() {
  return (
    <ColorPicker
      aria-label="Label color"
      space="srgb"
      format="hex"
      defaultValue="#0ea5e9"
    >
      <ColorPickerSwatches aria-label="Presets">
        {presets.map((preset) => (
          <ColorPickerSwatchItem key={preset} value={preset} />
        ))}
      </ColorPickerSwatches>
      <div className="flex items-end gap-2">
        <ColorPickerSwatch />
        {channels.map(({ channel, label }) => (
          <label
            key={channel}
            className="flex min-w-0 flex-1 flex-col gap-1 text-xs text-muted-foreground"
          >
            {label}
            <ColorPickerChannelInput channel={channel} />
          </label>
        ))}
        <ColorPickerEyeDropper aria-label="Pick a color from the screen" />
      </div>
    </ColorPicker>
  )
}

export { UiSdkColorPickerChannels }

This adds the example as components/examples/ui-sdk-color-picker/channels.tsx, together with the Color picker component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/ui-sdk-color-picker-channels.json

To add only the component, follow the Color picker installation.

Props in this example

The Color picker props this example sets, from the API reference.

PropTypeDefault
defaultValue
string"black"
spaceWhich channels the parts edit.
"hsv" | "hsl" | "srgb" | "oklch""hsv"
formatHow the value is written. Hex for hsv, the space’s own CSS syntax otherwise.
ColorFormat–
PropTypeDefault
channelThe channel to edit, in the units people read it in.
ColorChannel–
PropTypeDefault
valueRequired. The preset’s color.
string–

Every prop is in the Color picker API reference.

See them all, with keyboard support and accessibility notes, on the Color picker page.