# Badge

A small status or category label in 12 colors and 6 styles.

- Category: Core Elements
- Page: https://wunderui.com/components/badge
- Tier: Free

## Install

```bash
npx wunderui-cli add badge
```

## Import

```tsx
import { Badge, BadgeCell, BadgeColor, BadgeCounter, BadgeCounterTone, BadgeIndicator, BadgeIndicatorKind, BadgeProcessing, BadgeProcessingState, BadgeStyle, Chip, EntityChip, TokenChip } from "@/components/ui/badge"
```

## Minimal usage

Then use it:

```tsx
import { Badge } from "@/components/ui/badge"

export function Status() {
  return (
    <Badge color="green" badgeStyle="light" shape="pill">
      Approved
    </Badge>
  )
}
```

Expected result: You should see one small green pill with the word Approved.

## Usage

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="green" badgeStyle="light" shape="pill">
      Approved
    </Badge>
  )
}
```

## When to use

### Use Badge for

- A short status or category on a row, a card or a heading, such as Paid, Draft or Beta
- A count next to a navigation label or on the corner of an icon button
- A running operation and its result, such as Syncing, Synced and Failed
- Chips that filter or select, a person as a chip, and the entries of a multi-value field

### Use something else

- [Alert](https://wunderui.com/components/alert) for a message people need to read, with a title and an action
- [Trend Chip](https://wunderui.com/components/trend-chip) for the change in a number, with its direction
- [Avatar](https://wunderui.com/components/avatar) for presence on a person: the avatar draws its own status mark
- [Segment](https://wunderui.com/components/segment) for switching between two or more views, with one always selected

## Keyboard

A badge is a span and takes no focus. Only what does something is a control: the remove button, a badge rendered as a button or link, and the chips.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the next or previous control: a remove button, a chip, a badge rendered as a link or button. |
| `Enter` or `Space` | Runs the focused control: removes the tag, toggles the chip, opens the list of a dropdown chip. |

## Behavior

What the badge does itself, and what it leaves to the page.

- **Static by default:** A badge is a plain span: no role, no focus, no pointer. It reads as part of the text around it, so the label has to make sense there.
- **Color and style:** Tinted looks use the tint tokens of the hue, so they follow light and dark mode. Every color and style pair is measured for AA contrast; the solid style uses white or the darkest step of the hue.
- **A badge that does something:** As a button or link, the badge shows a ring in its own color on hover, scales down on press and gets the focus ring. The remove button is left out then, so two controls never nest.
- **Remove:** A remove handler draws the remove button and calls your function. The badge does not hide itself: take the tag out of your list, and move focus to the next tag or the field.
- **Counter:** A count above 99 reads 99+. An overlay counter hides at zero unless you keep it and needs a relative parent, and an inline counter shows 0 in tertiary text.
- **Indicator:** The indicator is an image with an accessible name from its label, or a default for its kind. An overlay needs a relative parent, and its ring uses the card color so it stays readable on any surface.
- **Processing:** The processing badge is a status region, marked busy while pending, and swaps the spinner for a check or a warning sign when the work ends. The text always names the state.
- **Chips:** A chip keeps no state of its own: pass selected and open, and change them in the click handler. They set the matching aria-pressed, aria-checked or aria-expanded.
- **Motion:** Color and ring changes use the fast duration. A pressed badge scales to 95 %, the remove button to 90 %, and the processing spinner turns until the work ends.
- **Reduced motion:** With reduced motion on, the processing spinner is a still icon and the remove button no longer scales on press. The state is still named in text.

## Anatomy

- `Badge`: A short label in a rounded box, in 12 colors, 6 styles, two sizes (20 or 24 px) and a rounded or pill shape. As a button or link it gains hover, focus and press states.
- `Leading mark`: A Lucide icon as a child, or a dot. The icon is 12 px on a small badge and 14 px on a medium one, follows the label color, and sits 4 or 6 px before it.
- `Label`: One short line, 12 px semibold on a small badge and 14 px on a medium one. It never wraps and clips what does not fit, so keep the label to a word or two.
- `Remove button`: A 16 px round button with an X, drawn when a remove handler is set. It is a separate button with its own name and the badge itself stays inert; it is left out when the badge is a button or link.
- `BadgeCell`: A Badge for a table cell, made from a label string, with the light border style by default.
- `BadgeCounter`: A count next to a label, or on the corner of an icon button, in neutral, brand or danger tones. Counts above 99 read 99+, and an overlay counter hides itself at zero.
- `BadgeIndicator`: A small signal: unread, presence (online, away, busy, offline) or a symbol (check, warning, lock). Each kind has its own shape, not only its own color, and carries an accessible name.
- `BadgeProcessing`: A running operation and its result: pending (a turning spinner), success or error. The label always names the state.
- `Chip`: An interactive pill that filters, selects or opens a list. Selection shows as the indigo tint and a mark, never as color alone.
- `EntityChip`: A person, team or workspace as a pill: a 24 px mark (an avatar, an image, a flag) before the name, and an optional remove button. Written `<Chip variant="entity">`; EntityChip is a deprecated alias.
- `TokenChip`: One entry inside a multi-value field, such as an email address. An invalid token gets a warning icon and the red tint; the field names the error. Written `<Chip variant="token">`; TokenChip is a deprecated alias.
- `Dot`
- `Chip`
- `Chip Main`
- `Token Chip`
- `Entity Chip`

## Best practices

### When to use

- Use a Badge for a short status or category on a row, card or heading: Paid, Draft, Beta. For the change in a number use Trend Chip, and for a message people have to read use Alert.

### Do

- Give each status one color and keep it wherever that status appears. Write the status in the label as well, so color is never the only cue.
- Use the light or light border style in tables and lists, and keep the solid style for the one badge that should stand out.
- Render the badge as a button when it does something. Only a button or link gets the pointer cursor, the hover ring and the focus ring.
- Put an overlay counter on the corner of a relatively positioned button and name the count in the button, like Notifications, 3 unread. The counter itself stays decorative.
- Use Chip for a filter or a choice. It announces its selected state and shows a mark as well as the tint.

### Don't

- Don't use a Badge as a selection control. A removable tag takes a remove handler; anything that selects or opens a list is a Chip.
- Don't recolor a badge with classes or hex values. Every color and style pair is measured for AA contrast in light and dark mode.
- Don't put two badges on one heading, or a badge on every row of a list. A badge that is everywhere says nothing.

## API reference

### Badge

| Prop | Type | Default | Description |
|---|---|---|---|
| badgeStyle | "plain" \| "light" \| "light_border" \| "border_color" \| "border_grey" \| "ghost" | "plain" | The look: `plain` is a solid fill, `light` a tinted surface, `light_border` a tint with a rim, `border_color` and `border_grey` a white surface with a rim, and `ghost` text only. In Figma they are Solid, Subtle, Outline and Plain. |
| color | "blue" \| "green" \| "red" \| "yellow" \| "purple" \| "indigo" \| "pink" \| "orange" \| "alternative" \| "grey" \| "black" \| "white" | "blue" | The hue of the badge. The status tones are `grey` (neutral), `indigo` (brand), `blue` (info), `green` (success), `yellow` (warning) and `red` (danger); the others label categories. |
| dot | boolean |  | Draws a 6 px dot in the color of the label before it. |
| onRemove | () => void |  | Draws a remove button after the label and calls this function when it is pressed. Ignored when the badge is rendered through `render`. |
| removeLabel | string | "Remove" | The accessible name of the remove button. Name the tag in it: `Remove Marketing`. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| shape | "rounded" \| "pill" | "rounded" | `rounded` has an 8 px radius, `pill` is fully round. |
| size | "sm" \| "md" | "sm" | `sm` is 20 px high with 12 px text, `md` is 24 px high with 14 px text. |

Also accepts React.HTMLAttributes attributes.

### BadgeCell

| Prop | Type | Default | Description |
|---|---|---|---|
| label* | string |  | The text of the badge. |
| badgeStyle | "plain" \| "light" \| "light_border" \| "border_color" \| "border_grey" \| "ghost" | "light_border" | The look of the badge. Defaults to `light_border`, the style of a status in a table. |
| color | "blue" \| "green" \| "red" \| "yellow" \| "purple" \| "indigo" \| "pink" \| "orange" \| "alternative" \| "grey" \| "black" \| "white" | "blue" | The hue of the badge. |

### BadgeCounter

| Prop | Type | Default | Description |
|---|---|---|---|
| count* | number |  | The number to show. Negative values and fractions are treated as 0 and cut to a whole number. |
| hideZero | boolean |  | Hides the counter at zero. Defaults to `true` for an overlay and `false` for an inline counter. |
| max | number | 99 | The largest number shown. Above it the counter reads `99+`, or `{max}+` for another value. |
| overlay | boolean | false | Positions the counter on the top right corner of its `relative` parent and gives it a ring in the card color. An overlay counter is hidden at zero. |
| tone | "neutral" \| "brand" \| "danger" | "neutral" | `neutral` is a grey pill, `brand` the primary color and `danger` red. |

Also accepts React.HTMLAttributes attributes.

### BadgeIndicator

| Prop | Type | Default | Description |
|---|---|---|---|
| kind* | "unread" \| "online" \| "away" \| "busy" \| "offline" \| "check" \| "warning" \| "lock" |  | What the indicator stands for. Each kind has its own shape: a dot, a ring, a moon, a bar, a check, a triangle or a lock. |
| label | string |  | The accessible name. Defaults to the name of the kind, such as `Online` or `Locked`; give it more detail when it helps, such as `New event`. |
| overlay | boolean | false | Positions the indicator on the top right corner of its `relative` parent, with a ring in the card color. |
| size | "sm" \| "md" | "sm" | `sm` is 8 px for a dot and 16 px for a symbol; `md` is 10 px and 20 px. |

Also accepts React.HTMLAttributes attributes.

### BadgeProcessing

| Prop | Type | Default | Description |
|---|---|---|---|
| state* | "pending" \| "success" \| "error" |  | `pending` shows a turning spinner on a blue tint, `success` a check on green and `error` a warning sign on red. |
| removeLabel | string |  |  No effect in this version. The processing badge has no remove button. |
| render | React.ReactElement \| ComponentRenderFn<RenderFunctionProps, State> |  | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
| size | "sm" \| "md" |  | `sm` is 20 px high, `md` is 24 px high. The badge is always a pill with the `light` style. |

Also accepts React.HTMLAttributes attributes.

### Chip

| Prop | Type | Default | Description |
|---|---|---|---|
| children* | React.ReactNode |  | The label of the chip. |
| className | string |  | Extra classes for the chip, merged with its own. |
| leading | React.ReactNode |  | Variant `entity` only. The mark before the name, 24 px: an `Avatar`, an image, a flag. |
| mark | "none" \| "check" \| "radio" \| "checkbox" \| "suggest" |  | The mark before the label: a check when selected, a radio or a checkbox, or a dashed circle for a suggestion. |
| onClick | () => void |  | Called when the chip is pressed. The chip keeps no state: change `selected` or `open` here. |
| onRemove | () => void |  | Called when the remove button of a chip with `trailing="remove"` is pressed. |
| open | boolean |  | Shows a chip with a chevron as open: the tint, and the chevron points up. It also sets `aria-expanded`. |
| removeLabel | string |  | The accessible name of the remove button. Name the filter in it: `Remove filter Owner: Nora`. |
| role | "radio" \| "checkbox" |  | Use `radio` for one choice out of a group and `checkbox` for a multi-select. It sets `aria-checked` from `selected`. |
| selected | boolean |  | Shows the chip as selected: the indigo tint and rim. With `mark="check"` a check appears before the label. |
| state | "default" \| "focused" \| "invalid" \| "removing" |  | Variant `token` only. `invalid` adds a warning icon and the red tint, `focused` shows the focus ring of the field, `removing` fills the remove button while it is pressed. |
| trailing | "none" \| "chevron" \| "remove" |  | What follows the label: nothing, a chevron for a chip that opens a list, or a remove button for an applied filter. |
| variant | "filter" |  | `filter` (default) is the filter chip: a pill that selects, filters or opens a list. `entity` is a rounded pill with a mark in `leading` and a name, for a person, team or workspace. `token` is an input token with a `state`, for an entry inside a multi-value field. EntityChip and TokenChip are deprecated aliases of the last two. |

### EntityChip

| Prop | Type | Default | Description |
|---|---|---|---|
| children* | React.ReactNode |  | The name of the person, team or workspace. |
| leading* | React.ReactNode |  | The mark before the name, 24 px: an `Avatar`, an image, a flag. |
| onRemove | () => void |  | Draws a remove button after the name and calls this function when it is pressed. |
| removeLabel | string |  | The accessible name of the remove button. Name the entity in it: `Remove Nora Lindgren`. |

### TokenChip

| Prop | Type | Default | Description |
|---|---|---|---|
| children* | React.ReactNode |  | The entry, such as an email address. |
| onRemove | () => void |  | Draws a remove button after the entry and calls this function when it is pressed. |
| removeLabel | string |  | The accessible name of the remove button. Name the entry in it: `Remove info@wunderui.com`. |
| state | "default" \| "focused" \| "invalid" \| "removing" |  | `invalid` adds a warning icon and the red tint, `focused` shows the focus ring of the field, `removing` fills the remove button while it is pressed. |

## Examples

### Style: subtle, solid, outline and plain

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="green" badgeStyle="light" shape="pill">
      Active
    </Badge>
  )
}
```

### Color: purple, pink, orange, alternative, black and white

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="purple" badgeStyle="light" shape="pill">
      Design
    </Badge>
  )
}
```

### Shape: pill and rounded

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="indigo" badgeStyle="light" shape="pill">
      Beta
    </Badge>
  )
}
```

### Size: small and medium

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="indigo" badgeStyle="light" shape="pill" size="sm">
      Beta
    </Badge>
  )
}
```

### Content: text, icon, dot and remove button

```tsx
import { Badge } from "@/components/ui/badge"

export function Example() {
  return (
    <Badge color="green" badgeStyle="light" shape="pill">
      Approved
    </Badge>
  )
}
```

### Counter: inline and overlay, in three tones

```tsx
import { BadgeCounter } from "@/components/ui/badge"

export function Example() {
  return (
    <span className="inline-flex items-center gap-2 text-sm font-medium">
      Inbox
      <BadgeCounter count={3} tone="neutral" />
    </span>
  )
}
```

### Indicator: activity, presence and symbols

```tsx
import { BadgeIndicator } from "@/components/ui/badge"

export function Example() {
  return (
    <span className="inline-flex items-center gap-2 text-sm font-medium">
      <BadgeIndicator kind="online" size="md" />
      Online
    </span>
  )
}
```

### Processing: syncing, synced and failed

```tsx
import { BadgeProcessing } from "@/components/ui/badge"

export function Example() {
  return <BadgeProcessing state="pending">Syncing</BadgeProcessing>
}
```

### Chip: filter, multi-select, applied, dropdown and suggestion

```tsx
import { useState } from "react"
import { Chip } from "@/components/ui/badge"

export function Example() {
  const [selected, setSelected] = useState(false)

  return (
    <Chip mark="check" selected={selected} onClick={() => setSelected(!selected)}>
      Assigned to me
    </Chip>
  )
}
```

### Entity chip: read-only and removable

```tsx
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Chip } from "@/components/ui/badge"

export function Example() {
  return (
    <Chip
      variant="entity"
      leading={
        <Avatar size="sm" color="purple">
          <AvatarFallback>NL</AvatarFallback>
        </Avatar>
      }
    >
      Nora Lindgren
    </Chip>
  )
}
```

### Input token: default, focused, invalid and removing

```tsx
import { Chip } from "@/components/ui/badge"

export function Example({ onRemove }: { onRemove: () => void }) {
  return (
    <Chip variant="token" state="default" onRemove={onRemove} removeLabel="Remove info@wunderui.com">
      info@wunderui.com
    </Chip>
  )
}
```

## In context

### Invoices: status in a table

Every row has a subtle badge with a dot and a word. The word carries the status, the colour supports it.

```tsx
import { Badge } from "@/components/ui/badge"
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"

const INVOICES = [
  { id: "INV-2048", customer: "Nora Lindgren", amount: "$1,842.00", status: "Paid", color: "green" },
  { id: "INV-2049", customer: "Daniel Okafor", amount: "$69.98", status: "Pending", color: "yellow" },
  { id: "INV-2050", customer: "Priya Raman", amount: "$249.00", status: "Overdue", color: "red" },
  { id: "INV-2051", customer: "Tomás Ferreira", amount: "$1,120.50", status: "Draft", color: "grey" },
] as const

export function Example() {
  return (
    <Table aria-label="Invoices">
      <TableHeader>
        <TableRow>
          <TableHead>Invoice</TableHead>
          <TableHead>Customer</TableHead>
          <TableHead>Status</TableHead>
          <TableHead className="text-right">Amount</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        {INVOICES.map((row) => (
          <TableRow key={row.id}>
            <TableCell>{row.id}</TableCell>
            <TableCell>{row.customer}</TableCell>
            <TableCell>
              <Badge color={row.color} badgeStyle="light" shape="pill" dot>
                {row.status}
              </Badge>
            </TableCell>
            <TableCell className="text-right tabular-nums">{row.amount}</TableCell>
          </TableRow>
        ))}
      </TableBody>
    </Table>
  )
}
```

### Filter bar: toggle, choice and multi-select chips

A toggle chip, one choice out of three and several teams at once. Clear all resets every group.

```tsx
import { useState } from "react"
import { Button } from "@/components/ui/button"
import { Chip } from "@/components/ui/badge"

const PERIODS = ["Daily", "Weekly", "Monthly"]
const TEAMS = ["Design", "Product", "Marketing"]

export function Example() {
  const [mine, setMine] = useState(true)
  const [period, setPeriod] = useState("Weekly")
  const [teams, setTeams] = useState<string[]>(["Design", "Product"])

  const clear = () => {
    setMine(false)
    setPeriod("")
    setTeams([])
  }

  return (
    <div className="flex flex-col gap-4">
      <div className="flex flex-wrap items-center gap-2">
        <Chip mark="check" selected={mine} onClick={() => setMine(!mine)}>
          Assigned to me
        </Chip>
      </div>
      <div role="radiogroup" aria-label="Period" className="flex flex-wrap items-center gap-2">
        {PERIODS.map((item) => (
          <Chip
            key={item}
            role="radio"
            mark="radio"
            selected={period === item}
            onClick={() => setPeriod(item)}
          >
            {item}
          </Chip>
        ))}
      </div>
      <div role="group" aria-label="Teams" className="flex flex-wrap items-center gap-2">
        {TEAMS.map((item) => (
          <Chip
            key={item}
            role="checkbox"
            mark="checkbox"
            selected={teams.includes(item)}
            onClick={() =>
              setTeams((list) => (list.includes(item) ? list.filter((team) => team !== item) : [...list, item]))
            }
          >
            {item}
          </Chip>
        ))}
      </div>
      <Button variant="plain" size="sm" className="self-start" onClick={clear}>
        Clear all
      </Button>
    </div>
  )
}
```

### Navigation: a count beside the label

Unread or total counts beside a navigation label. Archive has no count, so it shows none.

```tsx
import { useState } from "react"
import { BadgeCounter } from "@/components/ui/badge"

const ITEMS = [
  { id: "inbox", label: "Inbox", count: 12, tone: "brand" },
  { id: "mentions", label: "Mentions", count: 3, tone: "danger" },
  { id: "drafts", label: "Drafts", count: 5, tone: "neutral" },
  { id: "archive", label: "Archive", count: 0, tone: "neutral" },
] as const

export function Example() {
  const [active, setActive] = useState("inbox")

  return (
    <nav aria-label="Mail" className="flex flex-col gap-0.5 rounded-xl border border-border bg-card p-2">
      {ITEMS.map((item) => (
        <button
          key={item.id}
          type="button"
          aria-current={active === item.id ? "page" : undefined}
          onClick={() => setActive(item.id)}
          className="flex h-9 cursor-pointer items-center justify-between rounded-md px-3 text-sm font-medium transition-colors duration-fast ease-move hover:bg-bg-page aria-[current=page]:bg-bg-subtle motion-reduce:transition-none"
        >
          {item.label}
          {item.count > 0 && <BadgeCounter count={item.count} tone={item.tone} />}
        </button>
      ))}
    </nav>
  )
}
```

### Notifications: a count and a dot on the corner

The count belongs to the bell button and is part of its name. The dot only says something is new.

```tsx
import { useState } from "react"
import { Bell, CalendarDays } from "lucide-react"
import { Button } from "@/components/ui/button"
import { BadgeCounter, BadgeIndicator } from "@/components/ui/badge"
import { IconButton } from "@/components/ui/icon-button"

export function Example() {
  const [unread, setUnread] = useState(3)
  const [newEvent, setNewEvent] = useState(true)

  return (
    <div className="flex flex-col items-center gap-4">
      <div className="flex items-center gap-6">
        <span className="relative inline-flex">
          <IconButton variant="plain" size="lg" aria-label={`Notifications, ${unread} unread`}>
            <Bell strokeWidth={1.5} />
          </IconButton>
          <BadgeCounter overlay count={unread} tone="danger" aria-hidden />
        </span>
        <span className="relative inline-flex">
          <IconButton variant="plain" size="lg" aria-label={newEvent ? "Calendar, new event" : "Calendar"}>
            <CalendarDays strokeWidth={1.5} />
          </IconButton>
          {newEvent && <BadgeIndicator overlay kind="unread" label="New event" />}
        </span>
      </div>
      <Button
        variant="plain"
        size="sm"
        onClick={() => {
          setUnread(0)
          setNewEvent(false)
        }}
      >
        Mark all as read
      </Button>
    </div>
  )
}
```

### Integrations: sync status with a retry

Syncing turns into Synced, or into Failed with the reason. Retry starts the run again.

```tsx
import { useEffect, useRef, useState } from "react"
import { Button } from "@/components/ui/button"
import { BadgeProcessing } from "@/components/ui/badge"

type Phase = "pending" | "success" | "error"

const SYSTEMS = [
  { name: "Salesforce", phase: "success" },
  { name: "Stripe", phase: "error" },
  { name: "HubSpot", phase: "pending" },
] as const

const NOTES: Record<Phase, string> = { pending: "In progress", success: "Up to date", error: "Token expired" }

export function Example() {
  const [phases, setPhases] = useState<Record<string, Phase>>(
    Object.fromEntries(SYSTEMS.map((item) => [item.name, item.phase]))
  )
  const timers = useRef<number[]>([])

  // clear the timers if the component unmounts while a sync is running
  useEffect(() => () => timers.current.forEach((timer) => window.clearTimeout(timer)), [])

  const retry = (name: string) => {
    setPhases((current) => ({ ...current, [name]: "pending" }))
    timers.current.push(
      window.setTimeout(() => setPhases((current) => ({ ...current, [name]: "success" })), 1400)
    )
  }

  return (
    <ul className="flex flex-col divide-y divide-border rounded-xl border border-border bg-card">
      {SYSTEMS.map((item) => (
        <li key={item.name} className="flex items-center gap-3 px-4 py-3 text-sm">
          <span className="flex-1 font-medium">{item.name}</span>
          <BadgeProcessing state={phases[item.name]}>
            {phases[item.name] === "pending" ? "Syncing" : phases[item.name] === "success" ? "Synced" : "Failed"}
          </BadgeProcessing>
          <span className="text-text-secondary">{NOTES[phases[item.name]]}</span>
          {phases[item.name] === "error" && (
            <Button variant="plain" size="sm" onClick={() => retry(item.name)}>
              Retry
            </Button>
          )}
        </li>
      ))}
    </ul>
  )
}
```

### Invite: tokens in a field

Each address is a token with its own remove button. An invalid address is marked and named below the field.

```tsx
import { useState } from "react"
import { Chip } from "@/components/ui/badge"

const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/

export function Example() {
  const [tokens, setTokens] = useState(["info@wunderui.com", "priya@wunderui"])
  const [draft, setDraft] = useState("")

  const add = () => {
    const value = draft.trim()
    if (value && !tokens.includes(value)) setTokens([...tokens, value])
    setDraft("")
  }

  return (
    <div className="flex flex-col gap-2">
      <div className="flex flex-wrap items-center gap-1.5 rounded-xl border border-border-control bg-card p-2">
        {tokens.map((token) => (
          <Chip
            variant="token"
            key={token}
            state={EMAIL.test(token) ? "default" : "invalid"}
            onRemove={() => setTokens(tokens.filter((item) => item !== token))}
            removeLabel={`Remove ${token}`}
          >
            {token}
          </Chip>
        ))}
        <input
          value={draft}
          onChange={(event) => setDraft(event.target.value)}
          onKeyDown={(event) => {
            if (event.key === "Enter" || event.key === ",") {
              event.preventDefault()
              add()
            }
          }}
          aria-label="Add an email address"
          placeholder="Add an email"
          className="h-6 min-w-32 flex-1 bg-transparent text-sm outline-none"
        />
      </div>
      {tokens.some((token) => !EMAIL.test(token)) && (
        <p role="alert" className="text-xs text-text-error">
          Some addresses are not valid. Fix or remove them before you send the invite.
        </p>
      )}
    </div>
  )
}
```

## For AI agents

`get_component("badge")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
