# Color picker

Choose an opaque hex color with pointer selection, keyboard controls or text entry.

## Web 0.2.0

### Usage

Supply a six-digit hex value and onChange, or defaultValue for local state. Text commits on blur or Enter. A name submits the committed value.

### Accessibility

Provide a visible label. Tab reaches saturation, hue and text entry. Arrow keys adjust selection. Invalid text restores the selected color on blur.

### When to use

Use for an opaque color chosen visually or by hex code. Alpha channels and eyedropper controls are outside this contract.

### Install

Add this registry to your project's components.json once, before the first install. Keep your existing settings and other registries.

```json
{
  "registries": {
    "@maeso": "http://127.0.0.1:4321/r/{name}.json"
  }
}
```

Then install the registry's default theme once, and import its sheet in the CSS entry that imports Tailwind. It paints every item from this registry.

```sh
npx shadcn@latest add @maeso/maeso
```

```css
@import "./styles/theme.web.css";
```

```sh
npx shadcn@latest add @maeso/color-picker
```

### Props

#### ColorPicker

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| label | string | yes |  |
| defaultValue | string \| undefined | no |  |
| disabled | boolean \| undefined | no |  |
| error | string \| undefined | no |  |
| hint | string \| undefined | no |  |
| name | string \| undefined | no |  |
| onChange | ((value: string) => void) \| undefined | no |  |
| required | boolean \| undefined | no |  |
| value | string \| undefined | no |  |

### Proof

#### Contrast

measured on 0.2.0

| State | Foreground | Background | Ratio | Floor |
| --- | --- | --- | --- | --- |
| default | rgb(67 77 86) | rgb(248 245 240) | 7.93 | AA 4.5 |
| default (dark) | rgb(181 182 182) | rgb(7 21 34) | 9.07 | AA 4.5 |

#### Keyboard

measured on 0.2.0

| Key | Action |
| --- | --- |
| ArrowRight | Increase hue |
| ArrowLeft | Decrease hue |
| ArrowUp | Increase hue |
| ArrowDown | Decrease hue |
| End | Set hue to the maximum |
| Home | Set hue to the minimum |
| Tab | Move focus from hue to hex input |
| Shift+Tab | Move focus from hex input to hue |
| ControlOrMeta+A | Select hex text for replacement |
| #00ff00 | Type a hex color draft |
| Enter | Commit the hex color |

#### Size

23007 gzip bytes · measured on 0.2.0

### Example

```tsx
import { ColorPicker } from "@/components/ui/_kit/forms/color-picker/ColorPicker";

const Example = () => (
		<div className="w-full max-w-105">
			<ColorPicker
				label="Brand color"
				defaultValue="#2563eb"
				name="brand"
				hint="Choose a color or enter its six-digit hex code."
			/>
		</div>
	);
export default Example;
```

### Preview · 0.2.0

not on native yet
