Badge
A short label in a colour: a state, a category, a count.
Installation
pnpm dlx @human-kit/design add badgenpx @human-kit/design add badgeyarn dlx @human-kit/design add badgebunx @human-kit/design add badgeThe command copies the files to src/lib/components/ui/badge. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Badge from '$lib/components/ui/badge';
</script>
<Badge.Root tone="green">Approved</Badge.Root> Examples
Tones
Ten tones, with no meaning of their own: one app’s "Pending" is orange, another’s amber. Map each state to a tone once, in the app, and every badge of that state follows. Blue when none is given, gray for a label that should stay quiet. badgeTones lists them.
Sizes
Three sizes, 16, 19 and 22px tall: the type, the padding and the dot step together, in every look.
Guidelines
- Use a badge for a short state or a tag, one or two words, never for an action: it does not press.
- Use
default, the tone as a muted tint with no edge, where a badge stands alone or in a few rows. Its hue is the avatar’s, so a badge and an avatar of one tone read as one family. - Use
outlinein a column where many badges sit together: the words in ink and the tone in a dot are calmer than a column of tinted chips. Without the dot it is a plain label. - Use
text, the dot and the words with no chip, inside something that already is a box, such as a card’s header. - Use
smwhere the room is tight, in a dense table, andlgbeside a heading or in a roomy card. Each size steps the type, the padding and the height: 16, 19 and 22px.
Accessibility
- It renders a
<span>with no role: its words are read as part of the text around it. - The dot is hidden from screen readers. The words say the state, so the colour is never the only sign.
- Each tone’s words are checked at 4.5:1 or more against its tint, the contrast of body text: 6.8:1 or more in light and dark.
- When the badge alone says something the row does not, such as a count, give the row an
aria-labelthat says it whole.
API reference
| Prop | Type | Default |
|---|---|---|
variant | 'default' | 'outline' | 'text' A muted tint of the tone, a white chip with a dot, or the dot and the words alone. | 'default' |
tone | 'gray' | 'blue' | 'cyan' | 'teal' | 'green' | 'amber' | 'orange' | 'red' | 'pink' | 'violet' The colour. Its meaning is the app’s to give. | 'blue' |
size | 'sm' | 'default' | 'lg' The type, the padding and the height: 16, 19 or 22px. | 'default' |
dot | boolean The tone’s dot before the words. | true |
Plus every attribute of a <span>.