ColorPicker

Picks a color with the system color well or swatches.

  • Native host
  • New in 0.1
import { ColorPicker, colorPickerPrimitive } from "nitro-ui-sdk/color-picker";
HeroUI Native
No counterpart
Expo UI
ColorPicker
  • ColorPicker example screen, light appearance
    Light
  • ColorPicker example screen, dark appearance
    Dark
On this page

Picks a color as a normalized hex string (#RRGGBB or #RRGGBBAA when supportsAlpha is enabled). On iOS 14+ it pairs a native UIColorWell (which opens the system color picker sheet) with a composed ColorPicker.Swatches preset grid. On Android it renders the preset ColorPicker.Swatches grid only. Use ColorPicker for theme accents, label colors, or drawing tools.

Anatomy

<ColorPicker.Root
  label="Accent color"
  defaultValue="#CC4A0F"
  swatches={[
    { value: "#CC4A0F", label: "Ember" },
    { value: "#15803D", label: "Forest" },
    { value: "#2563EB", label: "Cobalt" },
  ]}
>
  <ColorPicker.Label />
  <ColorPicker.Hint />
  <ColorPicker.Value />
  <ColorPicker.Well />
  <ColorPicker.Swatches />
</ColorPicker.Root>
Part Description
ColorPicker.Root Manages normalized hex state, controller attachment, agent registration, and container layout.
ColorPicker.Label Visible label (hidden from duplicate screen-reader focus).
ColorPicker.Hint Optional helper text and accessibility hint.
ColorPicker.Value Displays the current uppercase hex string (#RRGGBB or #RRGGBBAA).
ColorPicker.Well Native iOS UIColorWell button opening the system color picker (returns null on Android).
ColorPicker.Swatches Composed wrapping grid of preset color discs, each with a selected focus ring and role="radio".

Usage

import { ColorPicker } from "nitro-ui-sdk/color-picker";

const swatches = [
  { value: "#CC4A0F", label: "Ember" },
  { value: "#15803D", label: "Forest" },
  { value: "#2563EB", label: "Cobalt" },
];

<ColorPicker.Root label="Badge color" defaultValue="#CC4A0F" swatches={swatches} />;

Variants and sizes

variant selects "default" (transparent container) or "outlined" (card surface with border). size supports "sm", "md" (default), and "lg", scaling the swatch circle diameters while keeping every swatch touch target at least 44 pt. Pass supportsAlpha to allow #RRGGBBAA hex values with transparency in both UIColorWell and swatches.

<ColorPicker.Root label="Highlight" variant="outlined" size="sm" supportsAlpha defaultValue="#CC4A0F80" />

States

Pass disabled on ColorPicker.Root to lock both the native color well and all swatches, or disabled: true on an individual swatch entry to keep that preset unselectable.

<ColorPicker.Root
  label="Locked palette"
  defaultValue="#CC4A0F"
  disabled
  swatches={[{ value: "#CC4A0F", label: "Ember" }]}
/>

Controlled

Provide value and onValueChange to control the selected hex string. Invalid hex inputs are refused; calling details.preventDefault() declines a change and reconciles the native UIColorWell back to the committed color.

import { useState } from "react";
import { ColorPicker } from "nitro-ui-sdk/color-picker";

const [color, setColor] = useState("#CC4A0F");

<ColorPicker.Root label="Theme accent" value={color} onValueChange={setColor} />;

Props

ColorPicker.Root

Prop Type Default Description
label string — Required visible and accessible name.
title string label Title shown in the iOS system color picker sheet.
hint string undefined Optional helper text and accessibility hint.
swatches readonly ColorSwatch[] [] Named preset swatches ({ value, label, disabled? }).
supportsAlpha boolean false Enables #RRGGBBAA alpha selection in the picker and normalization.
value string undefined Controlled hex color (#RRGGBB or #RRGGBBAA).
defaultValue string First enabled swatch or "#CC4A0F" Initial uncontrolled hex color.
onValueChange (hex: string, details: ActionDetails) => void undefined Called before the color changes.
variant "default" | "outlined" "default" Container styling.
size "sm" | "md" | "lg" "md" Swatch disc and target sizing.
disabled boolean false Disables the well and all swatches.
styles PartStyles<ColorPickerPart, ColorPickerVariant, ColorPickerSize, ColorPickerState> undefined Per-part style overrides.
api Controller<ColorPickerActions> undefined Imperative controller created with colorPickerPrimitive.createApi().
agentId string undefined Stable agent identity when rendered in recyclable rows.
layout SharedViewProps["layout"] undefined Additional layout props merged onto the root container.
children ReactNode Default header + well + swatches Custom part composition.

ColorPicker.Swatches

Prop Type Default Description
swatches readonly ColorSwatch[] Root swatches Optional per-part swatch override.
part ColorPickerPart "swatches" Overrides the style slot resolved from styles.

Controller API

import { ColorPicker, colorPickerPrimitive } from "nitro-ui-sdk/color-picker";

const api = colorPickerPrimitive.createApi();
<ColorPicker.Root label="Accent" api={api} />;
api.current?.setColor("#15803D");
Action Signature Result
setColor (hex: string, source?: ActionSource) => ChangeStatus Normalizes and applies a valid hex color, returning "refused" on invalid hex strings or "disabled" when disabled.

Styles

Style resolvers receive { tokens, variant, size, state } where state is { disabled: boolean; value: string; supportsAlpha: boolean }.

<ColorPicker.Root
  label="Accent"
  styles={{
    value: ({ tokens }) => ({ text: { color: tokens.colors.foreground, fontWeight: "semibold" } }),
  }}
/>

Accessibility

ColorPicker.Well hosts iOS UIColorWell with accessibilityLabel, accessibilityHint, and sheet title. ColorPicker.Swatches wraps its grid in Semantics role="group" and exposes each swatch as a named role="radio" option with label, hex value, selected, and disabled states. Touch selection triggers selectionChanged() haptics; agent and API actions never vibrate.

Agent API

Action Arguments Notes
setColor string (hex #RGB, #RRGGBB, or #RRGGBBAA) Sets a normalized hex color and settles controlled updates. Exported options list enabled swatches.

Platform notes

iOS Android
Implementation Native UIColorWell host (iOS 14+) with sRGB hex conversion plus composed ColorPicker.Swatches. Swatches only (ColorPicker.Well renders null on Android because Android has no equivalent system color well); compile-only HybridNativeColorWell.kt stub included.
Verification Unit, type, iOS harness, and simulator screenshot verified. Composed swatches share the verified TS model; Android native build not run locally (no Android NDK on this machine).