# Chip

> Compact token for tags, attributes, or other discrete entities inline with text. Defaults to secondary appearance, outline variant, and rounded shape.

Source: https://vaneui.com/docs/basic-components/chip

Import: `import { Chip, Card, Col, IconButton, Row, Text, ThemeProvider, Title } from "@vaneui/ui"`

Chip is for values a reader scans as a group, such as the tags on an article or the filters applied to a list. It renders a `<span>`, or an `<a>` when `href` is set, and its label does not wrap. For a count or status indicator, use a [Badge](/docs/basic-components/badge). When clicking the token should run an action rather than follow a link, use a [Button](/docs/basic-components/button), which renders a native `<button>`.

## Basic usage

Chip is a compact token for tags or attributes, and each `appearance` prop maps to a semantic color from the active theme.

```tsx demo
<Row flexWrap>
  <Chip primary>primary</Chip>
  <Chip accent>accent</Chip>
  <Chip>secondary</Chip>
  <Chip tertiary>tertiary</Chip>
  <Chip success>success</Chip>
  <Chip danger>danger</Chip>
  <Chip warning>warning</Chip>
  <Chip info>info</Chip>
  <Chip inheritAppearance>inheritAppearance</Chip>
</Row>
```

## Sizes

Chips come in five sizes: `xs`, `sm`, `md` (default), `lg`, `xl`. Size drives font-size, padding, gap, and border-radius simultaneously via CSS variables. At every size the text is centered by the height of its capital letters. It sits in a `<span class="vane-text-run">`, which [How Button centers its label](/docs/basic-components/button#how-button-centers-its-label) explains.

```tsx demo
<Row flexWrap>
  <Chip xs>xs</Chip>
  <Chip sm>sm</Chip>
  <Chip>md</Chip>
  <Chip lg>lg</Chip>
  <Chip xl>xl</Chip>
</Row>
```

## Variants

Chips can be styled as `filled`, `outline` (default), or `ghost`.

```tsx demo
<Col>
  <Row flexWrap>
    <Chip filled primary>primary</Chip>
    <Chip filled accent>accent</Chip>
    <Chip filled>secondary</Chip>
  </Row>
  <Row flexWrap>
    <Chip primary>primary</Chip>
    <Chip accent>accent</Chip>
    <Chip>secondary</Chip>
  </Row>
  <Row flexWrap>
    <Chip ghost primary>primary</Chip>
    <Chip ghost accent>accent</Chip>
    <Chip ghost>secondary</Chip>
  </Row>
</Col>
```

## Shapes

Chips support three border-radius styles: `rounded` (default), `pill`, and `sharp`.

```tsx demo
<Row flexWrap>
  <Chip>rounded</Chip>
  <Chip pill>pill</Chip>
  <Chip sharp>sharp</Chip>
</Row>
```

## Font family

Chips default to `fontSans`. Override with `fontMono` for code-adjacent tokens or `fontSerif` when the surrounding copy calls for it.

```tsx demo
<Row flexWrap>
  <Chip fontMono>v1.4.2</Chip>
  <Chip>Active user</Chip>
  <Chip fontSerif>Editorial</Chip>
</Row>
```

## With icon

Drop an icon directly inside the chip. `gap` is on by default, so spacing is automatic.

```tsx demo
<Row flexWrap>
  <Chip info><Heart/> Favorite</Chip>
  <Chip success><CheckSquare/> Verified</Chip>
  <Chip danger><X/> Blocked</Chip>
</Row>
```

## Tag lists

The canonical chip pattern: a wrapping row of tokens that label or categorize content. Chip is presentational, so for clickable tags give it an `href` (see As Link) or wire your own `onClick` (see Clickable chips).

```tsx demo
<Card>
  <Title>Article tags</Title>
  <Row flexWrap>
    <Chip>typescript</Chip>
    <Chip>react</Chip>
    <Chip>tailwind</Chip>
    <Chip>design-systems</Chip>
    <Chip>accessibility</Chip>
  </Row>
</Card>
```

## Removable chips

Chip is presentational, so wire removal yourself: compose an `IconButton` as the close control and drop the tag from your own state. The trailing `IconButton` owns the click target and carries an accessible label, and adds no height to the chip.

```tsx demo
const [tags, setTags] = React.useState(['typescript', 'react', 'tailwind']);
return (
  <Row flexWrap>
    {tags.map(tag => (
      <Chip key={tag}>
        {tag}
        <IconButton xs ghost aria-label={`Remove ${tag}`} onClick={() => setTags(tags.filter(t => t !== tag))}>
          <X/>
        </IconButton>
      </Chip>
    ))}
    {tags.length === 0 && <Text secondary>All tags removed.</Text>}
  </Row>
);
```

## As Link

Pass `href` to render the chip as an `<a>`, useful for clickable tag listings. When `href` is set, the chip gains a keyboard focus-visible outline by default, and so does a chip with `onClick` or `tag="button"`. Opt out with `noFocusVisible`. A linked chip tints on hover.

```tsx demo
<Row flexWrap>
  <Chip href="#">typescript</Chip>
  <Chip href="#" info>react</Chip>
  <Chip href="#" accent>tailwind</Chip>
</Row>
```

## Clickable chips

A Chip with `onClick` and no `href` stays a `<span>` but gets `role="button"`, a tab stop, and activation with Enter and Space. A `disabled` one stays focusable with `aria-disabled` and does nothing when activated. A `role` or `tabIndex` you pass wins. This needs `@vaneui/ui` 1.5.0 or later.

```tsx demo
const [selected, setSelected] = useState(['react']);
const toggle = (tag: string) =>
  setSelected(selected.includes(tag) ? selected.filter(t => t !== tag) : [...selected, tag]);

return (
  <Row flexWrap>
    {['typescript', 'react', 'tailwind'].map(tag => (
      <Chip
        key={tag}
        filled={selected.includes(tag)}
        aria-pressed={selected.includes(tag)}
        onClick={() => toggle(tag)}
      >
        {tag}
      </Chip>
    ))}
    <Chip disabled onClick={() => {}}>archived</Chip>
  </Row>
);
```

## Customizing

Set app-wide Chip defaults with `ThemeProvider`'s `themeDefaults`:

```tsx demo
<ThemeProvider themeDefaults={{
  chip: { info: true, filled: true, pill: true },
}}>
  <Chip>v2.0</Chip>
</ThemeProvider>
```

Add prop-conditional classes with `extraClasses`, applied whenever the matching boolean prop is active:

```tsx demo
<ThemeProvider extraClasses={{
  chip: {
    danger: 'animate-pulse',
    success: 'shadow-sm',
  },
}}>
  <Chip danger>blocked</Chip>
</ThemeProvider>
```

## Frequently asked questions

### Why is a Chip gray instead of primary?

Chip defaults to the `secondary` appearance, while Button, Card and the form controls default to `primary`. A bare Chip is a neutral token, and an appearance prop such as `primary`, `info` or `success` colors the ones that should stand out. To change the default for a whole app, set it once on `ThemeProvider`, as [Customizing](#customizing) shows: `themeDefaults={{ chip: { primary: true } }}`.

### Why does removing a Chip submit my form?

The remove control in [removable chips](#removable-chips) is an `IconButton`, and IconButton sets no `type`. Inside a `<form>`, the browser treats a button with no `type` as a submit button, so a click on it submits the form. Pass `type="button"` to the IconButton. A Chip with `tag="button"` also renders a `<button>` with no `type` and needs the same fix.

### How do I let a long Chip label wrap?

Pass `whitespaceNormal`. Chip defaults to `whitespaceNowrap`, so its label stays on one line and a long one widens the chip instead of wrapping. With `whitespaceNormal`, the text wraps once the chip runs out of room in its parent. `Badge` has the same default and takes the same prop.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance | yes | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `disabled` | Disabled |  | Disable the component — reduces opacity, changes cursor to not-allowed, and prevents interaction |
| `flex1` | Flex |  | Take up remaining space (= `flex-1`, i.e. `flex: 1 1 0%`) |
| `flexAuto` | Flex |  | Grow but respect intrinsic size (= `flex-auto`, i.e. `flex: 1 1 auto`) |
| `flexNone` | Flex |  | Don't grow and don't shrink (= `flex-none`, i.e. `flex: none`) |
| `fontSans` | Font Family | yes | Sans-serif font family (default) — emits font-sans |
| `fontSerif` | Font Family |  | Serif font family — emits font-serif |
| `fontMono` | Font Family |  | Monospace font family — emits font-mono |
| `fontHeading` | Font Family |  | Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading |
| `italic` | Font Style |  | Italic font style |
| `notItalic` | Font Style |  | Not italic (normal) font style |
| `fontThin` | Font Weight |  | Thin font weight (100) — emits font-thin |
| `fontExtralight` | Font Weight |  | Extra light font weight (200) — emits font-extralight |
| `fontLight` | Font Weight |  | Light font weight (300) — emits font-light |
| `fontNormal` | Font Weight | yes | Normal font weight (400) — emits font-normal |
| `fontMedium` | Font Weight |  | Medium font weight (500) — emits font-medium |
| `fontSemibold` | Font Weight |  | Semibold font weight (600) — emits font-semibold |
| `fontBold` | Font Weight |  | Bold font weight (700) — emits font-bold |
| `fontExtrabold` | Font Weight |  | Extra bold font weight (800) — emits font-extrabold |
| `fontBlack` | Font Weight |  | Black font weight (900) — emits font-black |
| `inheritSize` | Inherit Size |  | Inherit font-size and line-height from the nearest parent typography element |
| `noInheritSize` | Inherit Size |  | Keep own font-size; do not inherit from parent |
| `padding` | Padding | yes | Enable internal padding |
| `paddingX` | Padding |  | Enable only horizontal padding |
| `paddingY` | Padding |  | Enable only vertical padding |
| `noPadding` | Padding |  | Disable internal padding |
| `pill` | Shape |  | Fully rounded corners (circular) |
| `sharp` | Shape |  | No rounded corners (square) |
| `rounded` | Shape | yes | Medium rounded corners (default) |
| `noShrink` | Shrink |  | Prevent the flex item from shrinking below its content size (= `shrink-0`) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `underline` | Text Decoration |  | Add underline decoration below text |
| `lineThrough` | Text Decoration |  | Add strikethrough/line-through decoration across text |
| `noUnderline` | Text Decoration |  | Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none) |
| `overline` | Text Decoration |  | Add overline decoration above text |
| `uppercase` | Text Transform |  | Transform text to uppercase |
| `lowercase` | Text Transform |  | Transform text to lowercase |
| `capitalize` | Text Transform |  | Capitalize first letter of each word |
| `normalCase` | Text Transform |  | Normal text case (no transformation) |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |
| `breakNormal` | Word Break |  | Reset breaking - overflow-wrap and word-break normal |
| `breakWords` | Word Break |  | Break long words to prevent overflow - overflow-wrap: break-word |
| `breakAll` | Word Break |  | Break between any two characters - word-break: break-all |
| `breakKeep` | Word Break |  | Do not break CJK text - word-break: keep-all |

Layout and utility props (Border, Cursor, Display, Flex Direction, Focus Visible, Gap, Height, Hide, Items, Justify, Overflow, Position, Responsive Sizing, Responsive Width, Ring, Shadow, Show, Transition, Transparent, Whitespace, Width, Wrap) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
