Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Color Picker

ProNew

A saturation and brightness square, hue and opacity sliders, a hex field, named swatches, an eyedropper where the browser has one, and a contrast reading against another color. Inline, or as a field that opens it.

Installation

pnpm dlx shadcn@latest add @viewport/color-picker

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

<ColorPicker>

PropTypeDefault
value*string

The color as a hex string: "#3b82f6", or "#3b82f680" with transparency.

—
onValueChange*(value: string) => void—
alphaboolean

Add a transparency slider.

false
swatchesSwatch[]

Colors offered below the sliders. Give them names so they can be told apart without seeing them.

[]
contrastWithstring

A color to check against, e.g. the page background. The contrast ratio is shown, with whether text would pass.

—
labelstring

Accessible name of the picker.

"Color"
classNamestring—

<ColorField>

PropTypeDefault
size"sm" | "md""md"
disabledboolean—

Accessibility

  • The square and the sliders are sliders: arrow keys move them, Shift in larger steps.
  • Swatches are named buttons with a pressed state.
  • The contrast reading says in words whether text would pass.
  • The hex field keeps what you type while it is invalid and marks it.