# Chip

A small pill that starts one quiet action, such as View all at the end of a panel header or Edit beside a section title.

Status: Stable. Group: Actions.

## When to use

- The action at the end of a Panel header: View all, Edit, Manage.
- A quiet shortcut that sits next to the content it opens, with the chevron when it goes to another screen.

## When not to use

- It is the main action of the screen. Use Button instead.
- It shows a status or a count and does nothing. Use Badge instead.
- It switches between views of the same content. Use Segmented control instead.

## Scenarios

### View all

A Panel lists three active audits. A Chip with a chevron at the end of its header opens the full list.

### Edit a section

The Brand section of a token page ends its header with an Edit chip that opens the editing drawer.

## Do and avoid

- Do: Name the action in one or two words: View all, Edit.
- Avoid: Write a sentence, or repeat the panel title inside the chip.
- Do: Use one chip per header.
- Avoid: Line up several chips; use a Button group or a menu.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The label. Keep it to one or two words. |
| `chevron` | `boolean` | `false` | Draws a chevron after the label, mirrored in right-to-left text. |
| `href` | `string` |  | Makes the chip a link (an a element) instead of a button. |
| `onClick` | `MouseEventHandler<HTMLElement>` |  | Called on click, for a button or a link. |
| `disabled` | `boolean` | `false` | Dims the label and stops the click; a disabled chip is never a link. |
| `className` | `string` |  | Extra classes on the chip. |

## Anatomy

1. Chip (`data-part="root"`): Full pill, 36 px high, sunken background, label 14/20 at weight 600 in fg.
2. Chevron (`data-part="chevron"`): 16 px stroke chevron after the label, drawn with currentColor.

## Motion

| Interaction | Property | Duration | Easing | From the keyboard |
| --- | --- | --- | --- | --- |
| Hover | background-color and color | quick | out | Same, colour only. |
| Press | scale .97 (pointer only, motion-safe) | quick | out | Enter and Space activate it with no scale. |

## Accessibility

| Keys | Action |
| --- | --- |
| Tab | Moves focus to the chip. |
| Enter, Space | Activates a button chip. Enter follows a link chip. |

- A native button or a native link: no role is added.
- The chevron is aria-hidden, so the name is the label alone. Say where it goes in the label when the panel title does not.
- disabled uses the native disabled attribute.

## Code

### Chip.tsx

```tsx
import type { MouseEventHandler, ReactNode } from 'react'

// Nacre Chip: a small pill that starts one quiet action, such as View all in a panel header. React plus Tailwind
// classes only; needs nacre-theme.css. A link when it has an href, otherwise a button. Motion: colour quick 160 out on
// hover; the press scale comes from the Nacre base (pointer only, motion-safe).

export type ChipProps = {
  children: ReactNode
  /** Shows a chevron after the label, for a chip that goes somewhere. */
  chevron?: boolean
  /** Makes the chip a link. */
  href?: string
  onClick?: MouseEventHandler<HTMLElement>
  disabled?: boolean
  className?: string
}

const base =
  'inline-flex h-9 shrink-0 cursor-pointer items-center gap-1 rounded-full bg-sunken px-3.5 text-body font-[600] whitespace-nowrap text-fg ' +
  'transition-colors duration-(--nx-dur-quick) ease-out hover:bg-[color-mix(in_oklab,var(--nx-fg)_7%,var(--nx-sunken))] hover:text-fg-strong ' +
  'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:cursor-not-allowed disabled:text-fg-disabled'

export function Chip({ children, chevron = false, href, onClick, disabled = false, className = '' }: ChipProps) {
  const content = (
    <>
      {children}
      {chevron && (
        <svg data-part="chevron" aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" className="-me-1 size-4 rtl:scale-x-[-1]">
          <path d="M6.5 4l4 4-4 4" />
        </svg>
      )}
    </>
  )
  if (href && !disabled) {
    return <a href={href} data-part="root" data-press="" onClick={onClick} className={`${base} ${className}`}>{content}</a>
  }
  return <button type="button" data-part="root" disabled={disabled} onClick={onClick} className={`${base} ${className}`}>{content}</button>
}
```

## HTML

The default example as plain HTML, for any stack. Needs nacre-theme.css.

```html
<button type="button" data-part="root" class="inline-flex h-9 shrink-0 cursor-pointer items-center gap-1 rounded-full bg-sunken px-3.5 text-body font-[600] whitespace-nowrap text-fg transition-colors duration-(--nx-dur-quick) ease-out hover:bg-[color-mix(in_oklab,var(--nx-fg)_7%,var(--nx-sunken))] hover:text-fg-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-focus disabled:cursor-not-allowed disabled:text-fg-disabled ">
  View all
  <svg data-part="chevron" aria-hidden="true" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" class="-me-1 size-4 rtl:scale-x-[-1]">
    <path d="M6.5 4l4 4-4 4"></path>
  </svg>
</button>
```

## Related

- [Button](https://enxm.me/services/design-systems/nacre/components/button)
- [Badge](https://enxm.me/services/design-systems/nacre/components/badge)
- [Panel](https://enxm.me/services/design-systems/nacre/components/panel)
