# Colour field

- **[Atoms](/components/)**

A brand colour: a hex field, the browser's own picker and up to eight swatches. It sends a normalised #rrggbb only, and a line under it says what the colour did or why it was refused.

## Preview

color-field.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { ColorField } from '@/components/klarhimmel/ui/theme-parts';

export default function Example() {
  return (
    <Theme theme="brand">
      <ColorField label="Brand colour" value="#1d4ed8" onChange={(hex) => console.log(hex)} swatches={['#1d4ed8', '#b45309', '#0f766e']} />
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/theme-parts
  ```
- **Import**

  ```
  import { ColorField } from '@/components/klarhimmel/ui/theme-parts';
  ```

- **Files**: theme-parts.tsx, in components/klarhimmel/ui/. With it: input, theme, utils.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Props

- **label**: The field's words.
- **description**: The field's words.
- **value**: The colour as hex.
- **onChange**: Gets a normalised #rrggbb; a bad hex is held and marked, never sent.
- **swatches**: Up to eight colours to pick from.
- **notes**: A calm line on what the colour did, or a refusal in the danger tone.
- **problem**: A calm line on what the colour did, or a refusal in the danger tone.
- **pickerLabel**
- **invalidLabel**
- **disabled**
- **className**: Extra classes, merged after the component's own.

[Previous](/components/preset-tile)

[Next](/components/tabs)
