# Chip

A monospace chip for a code value in text or a table.

A monospace chip for a code value in prose or a table: a field name, a command, a version. Monospace token chip for code values like `updated_at`. Inline: it sits on the text baseline, and a long value wraps with the sentence instead of overflowing.

Kind: component · Category: Display · Status: stable · Targets: React, Vue, Svelte

## Add

```bash
npx fndn add chip
```

It writes the folder `chip/` into the project's ui folder (`index.ts`, `chip.tsx`, `Chip.vue`, `Chip.svelte`, `chip.recipe.ts`). First time: [Installation](/installation.md).

## Usage

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

```vue
import { Chip } from "@/components/ui/chip";
```

```svelte
import { Chip } from "$lib/components/ui/chip";
```

## Parts

In the DOM the root carries `data-slot="chip"` and each part `data-slot="chip-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `code` | `chip` |  |  |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tone` | `"neutral" \| "accent" \| "green" \| "orange" \| "red"` | `"neutral"` |  |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Slots

| Slot | Content |
| --- | --- |
| `default` | Value |

## Keyboard and accessibility

Notes:

- Rendered as <code>, so it is announced as code. Tone is decoration; never the only carrier of meaning.

## Tokens

`color.inset`, `color.ink-2`, `color.accent-tint`, `color.accent-ink`, `color.green`, `color.green-tint`, `color.orange`, `color.orange-tint`, `color.red`, `color.red-tint`, `radius.chip`, `font.mono`, `text.xs`

## Examples

### Missing environment variable

React · `missing-env-var.tsx`

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

export default function MissingEnvVar() {
  return (
    <p className="max-w-[300px] text-md text-ink">
      The build of web-app stopped: <Chip>DATABASE_URL</Chip> is not set in Production. Add it in Settings, then run <Chip>pnpm build</Chip> again.
    </p>
  );
}
```

Vue · `missing-env-var.vue`

```vue
<script setup lang="ts">
import { Chip } from "@/components/ui/chip";
</script>

<template>
  <p class="max-w-[300px] text-md text-ink">
    The build of web-app stopped: <Chip>DATABASE_URL</Chip> is not set in Production. Add it in Settings, then run <Chip>pnpm build</Chip> again.
  </p>
</template>
```

Svelte · `missing-env-var.svelte`

```svelte
<script lang="ts">
  import { Chip } from "$lib/components/ui/chip";
</script>

<p class="max-w-[300px] text-md text-ink">
  The build of web-app stopped: <Chip>DATABASE_URL</Chip> is not set in Production. Add it in Settings, then run <Chip>pnpm build</Chip> again.
</p>
```

### Fields of a webhook payload

React · `webhook-payload.tsx`

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

const fields = [
  { name: "deploy.id", about: "The deploy, like dpl_7f3a9c." },
  { name: "deploy.state", about: "One of ready, error or canceled." },
  { name: "created_at", about: "When the event happened, in UTC." },
];

export default function WebhookPayload() {
  return (
    <dl className="grid w-80 grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-2 text-sm">
      {fields.map((field) => (
        <div key={field.name} className="contents">
          <dt><Chip>{field.name}</Chip></dt>
          <dd className="text-ink-2">{field.about}</dd>
        </div>
      ))}
    </dl>
  );
}
```

Vue · `webhook-payload.vue`

```vue
<script setup lang="ts">
import { Chip } from "@/components/ui/chip";

const fields = [
  { name: "deploy.id", about: "The deploy, like dpl_7f3a9c." },
  { name: "deploy.state", about: "One of ready, error or canceled." },
  { name: "created_at", about: "When the event happened, in UTC." },
];
</script>

<template>
  <dl class="grid w-80 grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-2 text-sm">
    <div v-for="field in fields" :key="field.name" class="contents">
      <dt><Chip>{{ field.name }}</Chip></dt>
      <dd class="text-ink-2">{{ field.about }}</dd>
    </div>
  </dl>
</template>
```

Svelte · `webhook-payload.svelte`

```svelte
<script lang="ts">
  import { Chip } from "$lib/components/ui/chip";

  const fields = [
    { name: "deploy.id", about: "The deploy, like dpl_7f3a9c." },
    { name: "deploy.state", about: "One of ready, error or canceled." },
    { name: "created_at", about: "When the event happened, in UTC." },
  ];
</script>

<dl class="grid w-80 grid-cols-[auto_1fr] items-baseline gap-x-3 gap-y-2 text-sm">
  {#each fields as field (field.name)}
    <div class="contents">
      <dt><Chip>{field.name}</Chip></dt>
      <dd class="text-ink-2">{field.about}</dd>
    </div>
  {/each}
</dl>
```

### Schema changes in a migration

React · `migration-summary.tsx`

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

/* green added, orange changed, red removed */
export default function MigrationSummary() {
  return (
    <p className="max-w-[300px] text-md text-ink">
      This migration adds <Chip tone="green">retry_count</Chip>, renames <Chip tone="orange">sent_at</Chip> to <Chip tone="orange">delivered_at</Chip> and drops <Chip tone="red">legacy_status</Chip> from <Chip>webhooks</Chip>.
    </p>
  );
}
```

Vue · `migration-summary.vue`

```vue
<script setup lang="ts">
import { Chip } from "@/components/ui/chip";
</script>

<!-- green added, orange changed, red removed -->
<template>
  <p class="max-w-[300px] text-md text-ink">
    This migration adds <Chip tone="green">retry_count</Chip>, renames <Chip tone="orange">sent_at</Chip> to <Chip tone="orange">delivered_at</Chip> and drops <Chip tone="red">legacy_status</Chip> from <Chip>webhooks</Chip>.
  </p>
</template>
```

Svelte · `migration-summary.svelte`

```svelte
<script lang="ts">
  import { Chip } from "$lib/components/ui/chip";
</script>

<!-- green added, orange changed, red removed -->
<p class="max-w-[300px] text-md text-ink">
  This migration adds <Chip tone="green">retry_count</Chip>, renames <Chip tone="orange">sent_at</Chip> to <Chip tone="orange">delivered_at</Chip> and drops <Chip tone="red">legacy_status</Chip> from <Chip>webhooks</Chip>.
</p>
```

### Active query in a list

React · `active-query.tsx`

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

export default function ActiveQuery() {
  return (
    <p className="max-w-[300px] text-sm text-ink-2">
      Showing 14 deploys where <Chip tone="accent">state = error</Chip> and <Chip tone="accent">branch = main</Chip>, newest first.
    </p>
  );
}
```

Vue · `active-query.vue`

```vue
<script setup lang="ts">
import { Chip } from "@/components/ui/chip";
</script>

<template>
  <p class="max-w-[300px] text-sm text-ink-2">
    Showing 14 deploys where <Chip tone="accent">state = error</Chip> and <Chip tone="accent">branch = main</Chip>, newest first.
  </p>
</template>
```

Svelte · `active-query.svelte`

```svelte
<script lang="ts">
  import { Chip } from "$lib/components/ui/chip";
</script>

<p class="max-w-[300px] text-sm text-ink-2">
  Showing 14 deploys where <Chip tone="accent">state = error</Chip> and <Chip tone="accent">branch = main</Chip>, newest first.
</p>
```

## Recipe

`chip.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";

/* chip — monospace token chip for code values like `updated_at`.
 * Inline, sits in running text on the sentence's baseline; a long value wraps instead of
 * overflowing, and each line fragment keeps its own padding and radius (box-decoration clone).
 * One element, so the recipe is `base` only. No motion. */

export const chip = tv({
  base: "inline py-0.5 px-1.5 rounded-chip font-mono text-xs leading-none align-baseline [overflow-wrap:anywhere] box-decoration-clone",
  variants: {
    tone: {
      neutral: "bg-inset text-ink-2",
      accent: "bg-accent-tint text-accent-ink",
      green: "bg-green-tint text-green",
      orange: "bg-orange-tint text-orange",
      red: "bg-red-tint text-red",
    },
  },
  defaultVariants: { tone: "neutral" },
});

export type ChipRecipeProps = VariantProps<typeof chip>;
```
