Badge
A short static label or count, such as a status on a row or the number of unread messages. tone is neutral, the default, one of the four status tones info, success, warning and critical, or one of the eight category tones category-1 to category-8. Each tone reads its colors through the badge.<tone> contract tokens: the status tones from color.status.<tone> and the category tones from color.category.<n>.
On this page
import { Badge, CATEGORY_TONES } from '@tounsoo/todae/badge';
import { Stack } from '@tounsoo/todae/stack';
const CATEGORIES = ['Bug', 'Design', 'Docs', 'Tokens', 'Research', 'Mobile', 'Web', 'Infra'];
export default function BadgeTones() {
return (
<Stack.Root>
<Stack.Root direction="row" style={{ flexWrap: 'wrap' }}>
<Badge.Root>Draft</Badge.Root>
<Badge.Root tone="info">Beta</Badge.Root>
<Badge.Root tone="success">Paid</Badge.Root>
<Badge.Root tone="warning">Due soon</Badge.Root>
<Badge.Root tone="critical">Overdue</Badge.Root>
</Stack.Root>
<Stack.Root direction="row" style={{ flexWrap: 'wrap' }}>
{CATEGORY_TONES.map((tone, i) => (
<Badge.Root key={tone} tone={tone}>
{CATEGORIES[i]}
</Badge.Root>
))}
</Stack.Root>
</Stack.Root>
);
}
Server Components can import it from @tounsoo/todae/badge. That entry has no 'use client' and no hooks; the main @tounsoo/todae entry is a client module.
Badge.Root is a span with no role, so a screen reader reads it as part of the text around it. A bare number has no meaning on its own: add the rest in visually hidden text.
import { Badge } from '@tounsoo/todae/badge';
import { Text } from '@tounsoo/todae/text';
import { VisuallyHidden } from '@tounsoo/todae/visually-hidden';
export default function BadgeCount() {
return (
<Text.Root>
Inbox{' '}
<Badge.Root>
3<VisuallyHidden.Root> unread</VisuallyHidden.Root>
</Badge.Root>
</Text.Root>
);
}
Inbox 3 unread
Accessible composition
Todae handles: Color only. Badge.Root is a span with no role and no ARIA, and tone sets data-tone, which nothing announces. A screen reader reads the badge in line with the text around it.
You supply: Text that makes sense when read in that line. For a count, add the noun in a VisuallyHidden, as above. When the tone carries meaning, such as overdue against paid, put that meaning in the words too.
Watch for: A badge made clickable with onClick: a span takes no focus and has no role, so use a Button or a link. A count that changes while the user waits, such as new messages: the badge does not announce it, so use useAnnouncer or another live region. A badge inside a button or link becomes part of its name, so the whole name has to read well.
When to use
When: A status or count that labels something next to it: a paid invoice, a beta feature, unread messages.
When not: A label the user can remove → Chip. A message about the page or a task → Alert. Something the user clicks → Button.Root. A change you need announced → a live region, which a badge is not.
Props
| Name | Type | Description |
|---|---|---|
tone | "neutral"| "info"| "success"| "warning"| "critical"| "category-1"| "category-2"| "category-3"| "category-4"| "category-5"| "category-6"| "category-7"| "category-8" | Colors from the badge.<tone> contract tokens. Default: "neutral" |
children | React.ReactNode | Label text or a number. |