# Color Picker

Choose solid colors with an HSV area, hue and alpha controls, channel fields, presets, and composable popover support.

Color Picker provides the complete solid-color workflow in one panel. It keeps HSV as its working model while exposing HEX, RGB, and HSL fields, so switching the visible format never changes the selected color.

```tsx
import { ColorPicker, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function ColorPickerExample() {
  const [color, setColor] = useState("#d31510");

  return (
    <Stack gap="3" align="center">
      <ColorPicker value={color} onValueChange={setColor} />
      <Text type="code" size="s" color="subtle">
        {color}
      </Text>
    </Stack>
  );
}
```

## Import

```tsx
import { ColorPicker } from "@zentara-co/zenos-ui";
```

## Controlled value

Use `value` and `onValueChange` when another owner needs the selected color. Values are normalized to six-digit HEX while opaque and eight-digit HEX when alpha is below 100%.

```tsx
const [color, setColor] = useState("#d31510");

<ColorPicker value={color} onValueChange={setColor} />;
```

Use `defaultValue` for an uncontrolled picker. Three- and four-digit HEX inputs are accepted and normalized.

## Formats

The format switcher changes only the visible channel fields. `onValueChange` always receives HEX, regardless of whether the person edits HEX, RGB, or HSL. Control the switcher with `format` and `onFormatChange`, or seed it with `defaultFormat`.

## Sizes and surface

`md` is the complete 324px panel. `sm` is a compact 216px panel and omits the channel field row because it does not fit comfortably at that width. Use `variant="plain"` when the picker already sits inside a card, dialog, or settings surface.

```tsx
import { ColorPicker, Stack } from "@zentara-co/zenos-ui";

function ColorPickerSizesExample() {
  return (
    <Stack direction="row" gap="6" wrap="wrap" align="start" justify="center">
      <ColorPicker defaultValue="#0ea5e9" size="sm" />
      <ColorPicker defaultValue="#a855f7cc" size="md" />
    </Stack>
  );
}
```

## Alpha and presets

Alpha and preset colors are enabled by default. Set `showAlpha={false}` for opaque-only selection, `showPresets={false}` to remove the palette, or pass `presets` with application-owned HEX colors.

```tsx
<ColorPicker showAlpha={false} presets={["#d31510", "#0f0f0f", "#f9f9f9"]} />
```

## Composition

Passing children replaces the default layout. Every functional part remains connected to the root state, so parts can be dropped, reordered, or wrapped without adding visibility flags.

```tsx
import { ColorPicker } from "@zentara-co/zenos-ui";

function ColorPickerCompositionExample() {
  return (
    <ColorPicker defaultValue="#22c55e" variant="plain" showAlpha={false}>
      <ColorPicker.Area />
      <ColorPicker.Controls>
        <ColorPicker.HueSlider />
      </ColorPicker.Controls>
      <ColorPicker.Swatches label="Brand palette" />
    </ColorPicker>
  );
}
```

## Popover

The popover parts reuse Zenos Popover positioning, focus management, collision handling, and motion. The picker owns its card surface, so `ColorPicker.Content` adds positioning without drawing a second frame.

```tsx
import { ColorPicker } from "@zentara-co/zenos-ui";
import { useState } from "react";

function ColorPickerPopoverExample() {
  const [color, setColor] = useState("#6366f1");

  return (
    <ColorPicker.Popover>
      <ColorPicker.Trigger render={<ColorPicker.TriggerSwatch value={color} />} />
      <ColorPicker.Content align="start">
        <ColorPicker value={color} onValueChange={setColor} />
      </ColorPicker.Content>
    </ColorPicker.Popover>
  );
}
```

## Color utilities

The package exports `normalizeColorHex`, `hexToHsva`, `hsvaToHex`, `hsvaToRgba`, `rgbaToHsva`, `hsvaToHsla`, and `hslaToHsva` for applications that need the same conversion model outside the component.

## Variants

card, plain

## Sizes

sm, md

## Anatomy

```text
ColorPicker.Root
ColorPicker.Format
ColorPicker.Preview
ColorPicker.Area
ColorPicker.Controls
ColorPicker.HueSlider
ColorPicker.AlphaSlider
ColorPicker.Fields
ColorPicker.Swatches
ColorPicker.Popover
ColorPicker.Trigger
ColorPicker.Content
ColorPicker.TriggerSwatch
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| value | string | — | Controlled HEX color. |
| defaultValue | string | #d31510 | Initial uncontrolled HEX color. |
| onValueChange | (value: string) => void | — | Receives normalized six- or eight-digit HEX. |
| format / defaultFormat | hex \| hsl \| rgb | hex | Controlled or initial channel-field format. |
| onFormatChange | (format: ColorPickerFormat) => void | — | Runs when the visible channel format changes. |
| size | sm \| md | md | 216px compact panel or 324px complete panel. |
| variant | card \| plain | card | Draws the panel surface or inherits its surrounding surface. |
| showAlpha / showInput / showPresets | boolean | true | Includes each optional part in the default composition. |
| presets | readonly string[] | — | Application-owned HEX colors shown by the default swatch grid. |
| disabled | boolean | false | Disables the area, rails, fields, format buttons, and presets. |
| children | ReactNode | — | Replaces the default layout with a custom composition of picker parts. |
| Swatches.label | ReactNode | Colors | Renames or removes the preset section label. |
| Content side / align / offsets | Popover placement props | — | Positions the popover picker through the shared Popover behavior. |
| native props | React.HTMLAttributes<HTMLDivElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

The saturation and brightness area supports arrow keys, with Shift increasing the step. Hue and alpha use native range controls. Format and preset choices expose pressed state, every channel has an accessible name, and disabled state reaches every default interaction. Color is always returned as text rather than communicated by the swatch alone.

Source: https://zenos-ui.pages.dev/components/color-picker/