# Color picker (UI SDK): Controlled

> `onValueChange` runs on every step of a drag, and `onValueCommit` once when it ends, so save there. A controller from `createColorPickerController()` sets the color from anywhere.

Canonical: https://hextaui.com/docs/ui-sdk-color-picker/examples/controlled

Component docs: https://hextaui.com/docs/ui-sdk-color-picker

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/ui-sdk-color-picker-controlled.json
```

This adds `components/examples/ui-sdk-color-picker/controlled.tsx` with the Color picker component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/ui-sdk-color-picker/controlled.tsx"
"use client"

import * as React from "react"

import { Button } from "@/components/ui/button"
import {
  ColorPicker,
  ColorPickerArea,
  ColorPickerInput,
  ColorPickerSlider,
  createColorPickerController,
} from "@/components/ui/ui-sdk-color-picker"

function UiSdkColorPickerControlled() {
  const [picker] = React.useState(() => createColorPickerController())
  const [value, setValue] = React.useState("#0ea5e9")
  const [saved, setSaved] = React.useState("#0ea5e9")

  return (
    <div className="flex w-full max-w-64 flex-col gap-3">
      <ColorPicker
        aria-label="Theme color"
        value={value}
        onValueChange={setValue}
        onValueCommit={setSaved}
        controller={picker}
      >
        <ColorPickerArea />
        <ColorPickerSlider channel="hue" />
        <ColorPickerInput aria-label="Hex" />
      </ColorPicker>
      <div className="flex items-center justify-between gap-2 text-sm">
        <p className="text-muted-foreground">
          Saved <span className="font-mono text-foreground">{saved}</span>
        </p>
        <Button
          variant="outline"
          size="sm"
          onClick={() => picker.setValue("#663399")}
        >
          Use purple
        </Button>
      </div>
    </div>
  )
}

export { UiSdkColorPickerControlled }
```

## Props in this example

### ColorPicker

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | – |  |
| `onValueChange` | `(value: string, details: ChangeDetails) => void` | – | Runs on every step of a drag, a key press, a typed color or a preset. |
| `onValueCommit` | `(value: string, details: ChangeDetails) => void` | – | Runs once when a drag, key or typed color ends. |
| `controller` | `ColorPickerController` | – | From createColorPickerController(). |

### ColorPickerSlider

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `channel` | `ColorChannel` | – | Hue, or blue in sRGB, by default. |

## More Color picker examples

- [Inline](https://hextaui.com/docs/ui-sdk-color-picker/examples/inline)
- [Alpha](https://hextaui.com/docs/ui-sdk-color-picker/examples/alpha)
- [OKLCH](https://hextaui.com/docs/ui-sdk-color-picker/examples/oklch)
- [Presets and channels](https://hextaui.com/docs/ui-sdk-color-picker/examples/channels)
- [Vertical sliders](https://hextaui.com/docs/ui-sdk-color-picker/examples/vertical)
- [Form](https://hextaui.com/docs/ui-sdk-color-picker/examples/form)
- [Disabled](https://hextaui.com/docs/ui-sdk-color-picker/examples/disabled)
- [Read-only](https://hextaui.com/docs/ui-sdk-color-picker/examples/read-only)
- [Right to left](https://hextaui.com/docs/ui-sdk-color-picker/examples/rtl)
