# Color swatch

One named color tile with a faint inset edge, so light colors show on light grounds.

- Family: color
- Import: `import { ColorSwatch } from "@senvenli/react/color";`
- Page: https://design.senvenli.com/docs/components/color-swatch
- JSON: https://design.senvenli.com/docs/components/color-swatch.json

## Example: A named color

The name is the swatch's accessible label.

```tsx
import { ColorSwatch } from "@senvenli/react/color";

export default function Example() {
  return <ColorSwatch color="#1E63D0" name="Ocean" />;
}
```

## Examples

### Beside its value

A small palette, each color with its name and hex.

```tsx
import { ColorSwatch } from "@senvenli/react/color";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";

const PALETTE = [
  { name: "Ocean", value: "#1E63D0" },
  { name: "Pine", value: "#0F766E" },
  { name: "Plum", value: "#7C3AED" },
  { name: "Chalk", value: "#F4F4F2" },
];

export default function Example() {
  return (
    <Stack direction="horizontal" space="space-300">
      {PALETTE.map((color) => (
        <Stack direction="horizontal" key={color.value} space="space-100">
          <ColorSwatch color={color.value} name={color.name} />
          <Stack>
            <Text size="body-small">{color.name}</Text>
            <Text size="code" tone="subtle">{color.value}</Text>
          </Stack>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Showing a color next to its name or value.

### Use something else when

- [color-swatch-picker](https://design.senvenli.com/docs/components/color-swatch-picker.md): People pick one of the colors.
- [badge](https://design.senvenli.com/docs/components/badge.md): The color marks a status that also needs words.

## Accessibility

Built in:

- The name is the accessible label; without one, the color is described.

You provide:

- A name when the color carries meaning.

## API reference

### ColorSwatch

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| color | `string` |  | yes | The color shown ("#1E63D0"). |
| name | `string` |  | no | Its name ("Ocean"): the accessible label. |
| className | `string` |  | no |  |

### Tokens it reads

`--ds-background-neutral-pressed`, `--ds-border`, `--ds-border-focused`, `--ds-radius-full`, `--ds-radius-large`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-shadow-raised`, `--ds-space-050`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-400`, `--ds-surface-raised`, `--font-ds-mono`

## Related

- [color-swatch-picker](https://design.senvenli.com/docs/components/color-swatch-picker.md)
