

<InteractiveDemo
  name="color-editor"
  controls="[
  {
    type: &#x22;boolean&#x22;,
    name: &#x22;showAlphaChannel&#x22;,
    defaultValue: false,
  },
  {
    type: &#x22;boolean&#x22;,
    name: &#x22;showFormatSelector&#x22;,
    defaultValue: true,
  },
]"
/>

## Installation [#installation]

<InstallPrerequisite>
  Before adding components, init your project with your design system from the [Studio](/studio).
</InstallPrerequisite>

<CodeBlockTabs defaultValue="npm" groupId="package-manager">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/color-editor
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/color-editor
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/color-editor
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bunx shadcn@latest add @dotui/color-editor
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use a color editor to let users adjust a color with a saturation/brightness area, channel sliders, and format-aware fields. Standalone, it manages its own color value; inside a [Color Picker](/docs/components/color-picker), it edits the picker's color instead.

```tsx
import { ColorEditor } from "@/components/ui/color-editor"
```

```tsx
<ColorEditor defaultValue="#5100FF" />
```

## Anatomy [#anatomy]

`ColorEditor` renders a saturation/brightness area with channel sliders, then a row of format-aware fields. Omit children for the default layout, or compose the parts yourself.

```tsx
import {
  ColorEditor,
  ColorEditorArea,
  ColorEditorFields,
} from "@/components/ui/color-editor"
```

```tsx
<ColorEditor>
  <ColorEditorArea showAlphaChannel />
  <ColorEditorFields defaultFormat="rgb" />
</ColorEditor>
```

* `ColorEditorArea` — the color area, hue slider, and optional alpha slider.
* `ColorEditorFields` — channel inputs for the current format, with an optional format selector.

## Composition [#composition]

The default children render an area row and a fields row. Pass your own children to reorder, drop, or extend them — for example, dropping a swatch picker between the two parts.

```tsx
<ColorEditor defaultValue="#f80">
  <ColorEditorArea showAlphaChannel />
  <ColorSwatchPicker>{/* ... */}</ColorSwatchPicker>
  <ColorEditorFields defaultFormat="rgb" showFormatSelector={false} />
</ColorEditor>
```

## Value [#value]

The value is a React Aria `Color`. Use `defaultValue` for uncontrolled state, or `value` with `onChange` to control it. Pass a hex string (including alpha, e.g. `#5100FF80`) or a `Color` from `parseColor`.

```tsx
<ColorEditor defaultValue="#5100FF" onChange={setColor} />
```

<Alert>
  Inside a [Color Picker](/docs/components/color-picker), the editor adopts the
  picker's color — `value`, `defaultValue`, and `onChange` are ignored.
</Alert>

## Color format [#color-format]

`ColorEditorFields` picks its channel inputs from the current format. Set the initial format with `defaultFormat` (`hex`, `rgb`, `hsl`, or `hsb`), or control it with `format` and `onFormatChange`.

```tsx
<ColorEditorFields format={format} onFormatChange={setFormat} />
```

## Examples [#examples]

<Examples className="sm:grid-cols-2">
  <Example name="color-editor/demos/alpha-channel" title="Alpha channel" />

  <Example name="color-editor/demos/with-color-picker" title="In a color picker" />

  <Example name="color-editor/demos/composition" title="Custom composition" />
</Examples>

## API Reference [#api-reference]

### ColorEditor [#coloreditor]

<Reference name="color-editor" />

### ColorEditorArea [#coloreditorarea]

<Reference name="color-editor-area" />

### ColorEditorFields [#coloreditorfields]

<Reference name="color-editor-fields" />
