# Chip (/components/chip)

<ReferenceLinks
  links={[
    { label: "Source", href: meta.links.source, iconName: "code" },
    { label: "Stories", href: meta.links.stories },
  ]}
/>

<Stage code={"<Chip color=\"blue\">Person</Chip>\n<Chip color=\"green\" variant=\"soft\" shape=\"round\">\n  Published\n</Chip>\n<Chip color=\"purple\" variant=\"outline\">\n  v2.4\n</Chip>\n<Chip size=\"lg\" color=\"orange\">\n  Draft\n</Chip>"}>
  <Chip color="blue">Person</Chip>
  <Chip color="green" variant="soft" shape="round">
    Published
  </Chip>
  <Chip color="purple" variant="outline">
    v2.4
  </Chip>
  <Chip size="lg" color="orange">
    Draft
  </Chip>
</Stage>

## Installation [#installation]

1. Install the package.

```sh
npm install @hashintel/ds-components
```

2. Import the component.

```tsx
import { Chip } from "@hashintel/ds-components";

export const EntityTypeChip = () => (
  <Chip color="blue" variant="defined">
    Person
  </Chip>
);
```

### When to use [#when-to-use]

<DoList
  items={[
    "Use Chip to label an object with compact metadata: an entity's type, a property value, a status, a version.",
    <Fragment key="0">
      Use <code>onClick</code> when the token itself opens something, such as a
      filter chip that opens its editor.
    </Fragment>,
    "Use color to tell categories apart at a glance, keeping each color's meaning consistent across a view.",
  ]}
/>

### When not to use [#when-not-to-use]

<DontList
  items={[
    "Don't use chips for actions or navigation — a chip's primary purpose is to label something. Prefer a Button or Link.",
    "Don't use chips for counts that annotate another element, like an unread count on an icon — use Badge.",
    "Don't use chips to pick one value from a visible set — use SegmentedControl, or RadioGroup in forms.",
  ]}
/>

## Examples [#examples]

### Basic [#basic]

The default chip is `defined`, `grey`, and `md`-sized.

<Stage code={"<Chip>Entity type</Chip>"}>
  <Chip>Entity type</Chip>
</Stage>

### Variants [#variants]

Variants set emphasis. `defined` (default) has a solid border for standalone labels, `soft` and `outline` sit quieter inside busy UI, and `ghost` shows no fill or border until hovered or focused — for metadata that shouldn't compete with content.

<Stage code={"<Chip variant=\"defined\">Defined</Chip>\n<Chip variant=\"soft\">Soft</Chip>\n<Chip variant=\"outline\">Outline</Chip>\n<Chip variant=\"ghost\">Ghost</Chip>"}>
  <Chip variant="defined">Defined</Chip>
  <Chip variant="soft">Soft</Chip>
  <Chip variant="outline">Outline</Chip>
  <Chip variant="ghost">Ghost</Chip>
</Stage>

### Colors [#colors]

Color categorizes: give each category one color and keep the mapping stable across the product. `grey` is the default. The label must still carry the meaning — never rely on color alone.

<Stage code={"<Chip color=\"grey\">Grey</Chip>\n<Chip color=\"red\">Red</Chip>\n<Chip color=\"blue\">Blue</Chip>\n<Chip color=\"green\">Green</Chip>\n<Chip color=\"orange\">Orange</Chip>\n<Chip color=\"yellow\">Yellow</Chip>\n<Chip color=\"purple\">Purple</Chip>\n<Chip color=\"pink\">Pink</Chip>"}>
  <Chip color="grey">Grey</Chip>
  <Chip color="red">Red</Chip>
  <Chip color="blue">Blue</Chip>
  <Chip color="green">Green</Chip>
  <Chip color="orange">Orange</Chip>
  <Chip color="yellow">Yellow</Chip>
  <Chip color="purple">Purple</Chip>
  <Chip color="pink">Pink</Chip>
</Stage>

### Sizes [#sizes]

`md` is the default. Use `xxs`-`sm` inside dense tables and metadata rows, and `lg`/`xl` next to headings. Icons, dots, and spinners inside the chip scale with it.

<Stage code={"<Chip size=\"xxs\">xxs</Chip>\n<Chip size=\"xs\">xs</Chip>\n<Chip size=\"sm\">sm</Chip>\n<Chip size=\"md\">md</Chip>\n<Chip size=\"lg\">lg</Chip>\n<Chip size=\"xl\">xl</Chip>"}>
  <Chip size="xxs">xxs</Chip>
  <Chip size="xs">xs</Chip>
  <Chip size="sm">sm</Chip>
  <Chip size="md">md</Chip>
  <Chip size="lg">lg</Chip>
  <Chip size="xl">xl</Chip>
</Stage>

### Round shape [#round-shape]

`shape="round"` renders a pill. Use it for status chips, and keep one shape per chip group — mixing shapes reads as a difference in meaning.

<Stage code={"<Chip shape=\"default\">Default</Chip>\n<Chip shape=\"round\" color=\"green\">\n  Round\n</Chip>"}>
  <Chip shape="default">Default</Chip>
  <Chip shape="round" color="green">
    Round
  </Chip>
</Stage>

### Prefix and suffix [#prefix-and-suffix]

`prefix` and `suffix` add a slot on either side of the label. A slot's content is an `iconName`, a status `dot`, a `loading` spinner, or arbitrary `children` such as a count or version.

<Stage code={"<Chip color=\"blue\" prefix={{ iconName: \"cube\" }}>\n  Person\n</Chip>\n<Chip color=\"green\" suffix={{ iconName: \"check\" }}>\n  Validated\n</Chip>\n<Chip color=\"purple\" suffix={{ children: \"v2\" }}>\n  Company\n</Chip>"}>
  <Chip color="blue" prefix={{ iconName: "cube" }}>
    Person
  </Chip>
  <Chip color="green" suffix={{ iconName: "check" }}>
    Validated
  </Chip>
  <Chip color="purple" suffix={{ children: "v2" }}>
    Company
  </Chip>
</Stage>

### Status dot [#status-dot]

A `dot` prefix draws a small circle in the chip's text color, with three fill states — `filled`, `partiallyFilled`, `empty` — for lifecycle or progress readings. The dot is hidden from assistive technology, so the label must state the status.

<Stage code={"<Chip color=\"green\" shape=\"round\" prefix={{ dot: \"filled\" }}>\n  Running\n</Chip>\n<Chip color=\"orange\" shape=\"round\" prefix={{ dot: \"partiallyFilled\" }}>\n  Partially synced\n</Chip>\n<Chip shape=\"round\" prefix={{ dot: \"empty\" }}>\n  Not started\n</Chip>"}>
  <Chip color="green" shape="round" prefix={{ dot: "filled" }}>
    Running
  </Chip>
  <Chip color="orange" shape="round" prefix={{ dot: "partiallyFilled" }}>
    Partially synced
  </Chip>
  <Chip shape="round" prefix={{ dot: "empty" }}>
    Not started
  </Chip>
</Stage>

### Loading [#loading]

A `loading: true` affix shows a spinner. Swapping the affix to a success mark when work completes can help communicate finished progress.

<Stage code={"<Chip color=\"blue\" prefix={{ loading: true }}>\n  Syncing entities\n</Chip>\n<Chip color=\"blue\" prefix={{ iconName: \"check\" }}>\n  Synced\n</Chip>"}>
  <Chip color="blue" prefix={{ loading: true }}>
    Syncing entities
  </Chip>
  <Chip color="blue" prefix={{ iconName: "check" }}>
    Synced
  </Chip>
</Stage>

### Affix styles [#affix-styles]

An affix's `variant` shapes its edge treatment: `straight` (default) draws a divider between slot and label, `naked` drops the divider, `badge` fills the slot and bleeds to the chip's edge, and `angle` slants the boundary.

<Stage code={"<Chip color=\"blue\" prefix={{ iconName: \"cube\", variant: \"straight\" }}>\n  Straight\n</Chip>\n<Chip color=\"blue\" prefix={{ iconName: \"cube\", variant: \"naked\" }}>\n  Naked\n</Chip>\n<Chip color=\"blue\" suffix={{ children: \"12\", variant: \"badge\" }}>\n  Badge\n</Chip>\n<Chip color=\"blue\" prefix={{ children: \"beta\", variant: \"angle\" }}>\n  Angle\n</Chip>"}>
  <Chip color="blue" prefix={{ iconName: "cube", variant: "straight" }}>
    Straight
  </Chip>
  <Chip color="blue" prefix={{ iconName: "cube", variant: "naked" }}>
    Naked
  </Chip>
  <Chip color="blue" suffix={{ children: "12", variant: "badge" }}>
    Badge
  </Chip>
  <Chip color="blue" prefix={{ children: "beta", variant: "angle" }}>
    Angle
  </Chip>
</Stage>

### Clickable [#clickable]

`onClick` turns the whole chip into a real `<button>` with hover and focus styles. Reserve it for token-level interactions such as opening a filter's editor. Consider promoting anything that reads as an action to Button. An affix with its own `onClick` becomes a separate button beside the clickable centre (`aria-label` required).

<Stage code={"<Chip color=\"blue\" prefix={{ iconName: \"filter\" }} onClick={() => {}}>\n  Type: Person\n</Chip>\n<Chip\n  color=\"purple\"\n  onClick={() => {}}\n  prefix={{\n    iconName: \"sparkles\",\n    variant: \"badge\",\n    onClick: () => {},\n    \"aria-label\": \"Accept suggestion\",\n  }}\n  removeable={{ onRemove: () => {}, \"aria-label\": \"Dismiss suggestion\" }}\n>\n  Works at Acme Corp\n</Chip>"}>
  <Chip color="blue" prefix={{ iconName: "filter" }} onClick={noop}>
    Type: Person
  </Chip>
  <Chip
    color="purple"
    onClick={noop}
    prefix={{
      iconName: "sparkles",
      variant: "badge",
      onClick: noop,
      "aria-label": "Accept suggestion",
    }}
    removeable={{ onRemove: noop, "aria-label": "Dismiss suggestion" }}
  >
    Works at Acme Corp
  </Chip>
</Stage>

### Removeable [#removeable]

`removeable` appends a close button that calls `onRemove`. Name each removal through its `aria-label` — the default name is just "Remove". `removeable` and `suffix` are mutually exclusive.

<Stage code={"<Chip\n  color=\"blue\"\n  removeable={{ onRemove: () => {}, \"aria-label\": \"Remove Person filter\" }}\n>\n  Person\n</Chip>\n<Chip\n  color=\"blue\"\n  removeable={{ onRemove: () => {}, \"aria-label\": \"Remove Company filter\" }}\n>\n  Company\n</Chip>"}>
  <Chip
    color="blue"
    removeable={{ onRemove: noop, "aria-label": "Remove Person filter" }}
  >
    Person
  </Chip>
  <Chip
    color="blue"
    removeable={{ onRemove: noop, "aria-label": "Remove Company filter" }}
  >
    Company
  </Chip>
</Stage>

## Behavior [#behavior]

- A static chip renders as a `<div>`, `onClick` alone renders one `<button>`, and `onClick` combined with an interactive affix or `removeable` renders a `<div>` containing a separate button per segment.
- Labels never wrap. Under a width constraint the label truncates with an ellipsis. Wrap the chip in Tooltip when the full value matters.

## Content [#content]

- Write labels as nouns or values, 1–3 words, sentence case: "Person", "Draft", "3 properties". Prefer labels under 20 characters.
- Keep affix text to a short token: a count ("12"), a version ("v2"), a stage ("beta").

## Accessibility [#accessibility]

Clickable chips, interactive affixes, and the remove control implement the [WAI-ARIA button pattern](https://www.w3.org/WAI/ARIA/apg/patterns/button/).

- Status dots are `aria-hidden`, so they never produce an unlabeled announcement.
- Chips pass through `aria-*` attributes for contextual labelling.

### What you must do [#what-you-must-do]

- The default aria label for the remove button is "Remove". Generally you should re-label the action with the chip contents through `removeable.aria-label`, for ex: "Remove 'Ready Status'", so that buttons are distinguishable in a list.
- Move focus to a sensible neighbour after removing a chip; the component doesn't manage focus for you.
- State status in the label text — dots and colors are invisible to assistive technology.

## API reference [#api-reference]

### Chip [#chip]

<PropsTable
  of={Chip}
  defaults={{
    size: '"md"',
    shape: '"default"',
    color: '"grey"',
    variant: '"defined"',
  }}
/>

### PrefixOrSuffix [#prefixorsuffix]

The object shape `prefix` and `suffix` take.

<PropsTable of={ChipAffixSlot} defaults={{ variant: '"straight"' }} />
