Zum Hauptinhalt springen

Badge

Every example on this page is live, drawn by the library's Storybook, where you can also change its props and see the result.

An inline label in solid or outline style.

Import​

import { Badge } from "~lib/data-display/badge";

Props​

NameTypeRequiredDefaultDescription
childrenReactNodeNoN/ABadge content
variant"solid" | "outline"No"solid"Visual style
size"xs" | "sm" | "md" | "lg"No"md"Badge size
shape"pill" | "circle"No"pill"Badge shape
iconIconNameNoN/AAn icon before the text, as tall as the text

A badge keeps its own width: in a flex row it never shrinks or wraps its text, so beside a paragraph that truncates, the paragraph is what gives way.

Examples​

Solid​

Solid in Storybook öffnen

Outline​

Outline in Storybook öffnen

Small​

Small in Storybook öffnen

Extra Small​

size="xs" is exactly as tall as a line of xs text, so a badge in an xs row, such as a status on a line-status board, keeps the row the same height as the rows without one.

Extra Small in Storybook öffnen
In An Extra Small Row in Storybook öffnen

With an Icon​

icon draws any Icon name before the text, as tall as the text and in its color, on either variant and at every size. A change pill carries its trend glyph this way rather than nesting an Icon of its own. An icon with no text in a shape="circle" badge draws a round mark, such as a tick.

<Badge variant="outline" icon={trendIconName(change)}>
+2.4%
</Badge>
With Icon in Storybook öffnen
Icon At Every Size in Storybook öffnen

In a Flex Row​

Beside a paragraph that truncates, the badge keeps its width and its one line, and the paragraph ends in "…".

In A Flex Row in Storybook öffnen

Circle​

shape="circle" keeps the badge round at every size, so one or two digits sit in a circle rather than a pill.

Circle in Storybook öffnen

Day Numbers​

Mark today's date with a solid circle and the other days with an outline, the way a calendar does.

Day Numbers in Storybook öffnen

See Also​