Badge
Visual indicators for numeric values such as tallies and scores.
Import
tsx
import { Badge } from "@kobalte/pigment";
tsx
import { Badge } from "@kobalte/pigment";
Basic usage
v1.0.0
tsx
<Badge>v1.0.0</Badge>
tsx
<Badge>v1.0.0</Badge>
Customization
Variants
The Badge component comes in four variants: solid
, soft
(default), inverted
and dot
.
SolidSoftDot
tsx
<Badge variant="solid">Solid</Badge><Badge variant="soft">Soft</Badge><Badge variant="dot">Dot</Badge>
tsx
<Badge variant="solid">Solid</Badge><Badge variant="soft">Soft</Badge><Badge variant="dot">Dot</Badge>
The inverted
variant can be used to create a high contrast badge on a vibrant surface of the same color|status
.
tsx
<Buttonvariant="solid"color="primary"leadingIcon={<TablerTagIcon />}trailingIcon={<Badge variant="inverted" color="primary" class="flex">12</Badge>}>Labels</Button>
tsx
<Buttonvariant="solid"color="primary"leadingIcon={<TablerTagIcon />}trailingIcon={<Badge variant="inverted" color="primary" class="flex">12</Badge>}>Labels</Button>
Colors
Badges supports all Pigment semantic colors: primary
, success
, info
(default), warning
, danger
and discovery
.
primarysuccessinfowarningdangerdiscovery
primarysuccessinfowarningdangerdiscovery
primarysuccessinfowarningdangerdiscovery
primarysuccessinfowarningdangerdiscovery
tsx
<For each={["solid", "soft", "inverted", "dot"]}>{variant => (<div class="flex items-center gap-3"><For each={["primary", "success", "info", "warning", "danger", "discovery"]}>{color => (<Badge variant={variant} color={color} class="capitalize">{color}</Badge>)}</For></div>)}</For>
tsx
<For each={["solid", "soft", "inverted", "dot"]}>{variant => (<div class="flex items-center gap-3"><For each={["primary", "success", "info", "warning", "danger", "discovery"]}>{color => (<Badge variant={variant} color={color} class="capitalize">{color}</Badge>)}</For></div>)}</For>
Sizes
The Badge component comes in two sizes: md
(default) and lg
.
MediumLarge
tsx
<Badge size="md">Medium</Badge><Badge size="lg">Large</Badge>
tsx
<Badge size="md">Medium</Badge><Badge size="lg">Large</Badge>
Shapes
Badges supports three different shapes: rounded
(default), pill
and circle
.
+100121
tsx
<Badge shape="rounded">+100</Badge><Badge shape="pill">12</Badge><Badge shape="circle">1</Badge>
tsx
<Badge shape="rounded">+100</Badge><Badge shape="pill">12</Badge><Badge shape="circle">1</Badge>
API Reference
Component identifier
The name Badge
can be used when providing default props and slot classes in the theme.
Props
Prop | Description |
---|---|
variant | "solid" | "soft" | "inverted" | "dot" default: "solid" The visual style of the badge. |
color | "primary" | "success" | "info" | "warning" | "danger" | "discovery" default: "primary" The color of the badge. |
size | "md" | "lg" default: "md" The size of the badge. |
shape | "rounded" | "pill" | "circle" default: "rounded" The shape of the badge. |
slotClasses | Partial<Record<BadgeSlots, string>> Addiitonal CSS classes to be passed to the component slots. |
Slots
Name | CSS selector | Rendered element | Description |
---|---|---|---|
root | .pg-badge-root | span | Root element |