# Color pill

A hex colour inside text, its digits on a mention's ground with a swatch in place of its hash, as the composer draws it.

Live variants: https://design.arcadia.is/components/color-pill

```tsx
import { ColorPill } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import {
  MessageGroup, Bubble, FormattedText, ColorPill, ComposerFrame, IconButton,
  ComposerField,
} from "@arcadia/ui";

function Sent() {
  const [draft, setDraft] = useState("");
  const [sent, setSent] = useState(SENT);
  const send = () => {
    setSent(draft);
    setDraft("");
  };
  return (
    <div {...sx("color-pill-thread", ColorPillPage.thread)}>
      <MessageGroup side="end">
        <Bubble side="end">
          <FormattedText source={sent} ranges={colorRanges(sent).map(({ start, end, value }) => ({ start, length: end - start, node: <ColorPill value={value} /> }))} />
        </Bubble>
      </MessageGroup>
      <ComposerFrame end={<IconButton icon="arrow-up" label="Send" variant="inverse" disabled={!draft.trim()} onClick={send} />}>
        <ComposerField value={draft} onValueChange={setDraft} colors={colorRanges(draft)} minRows={2} placeholder="Try a hex colour" aria-label="Message" />
      </ComposerFrame>
    </div>
  );
}
```

## Accessibility

The pill is its text: a reader hears the colour as written, hash and digits. The swatch is drawn for the eye (`aria-hidden`) and keeps its colour under forced colours, since the colour is what it says.

## API reference

### ColorPill

- `value` (`string`, required): The colour as the text writes it: a hash and 3, 4, 6 or 8 hex digits. Anything else is drawn as plain text.
- `disabled` (`boolean`, default `false`): Its field is turned off: the text takes the disabled ink.
- `inDraft` (`boolean`, default `false`): In a textarea mirror, paint the colour on the edge without adding room to the text.
- `rootStyle` (`RootStyle`): Typed StyleX override: layout.

Rest props go to `HTMLAttributes<HTMLSpanElement>`.
