Badge
A small dot or a short count or label, placed on an anchor with BadgedBox.
import { Badge, BadgedBox } from '@windmorph/react';Props
Badge 8 props
A count or a short label (large badge); leave it out for the small dot. Numbers are formatted for the locale and capped at
max("999+"). M3 allows four characters, including the "+"; text badges stop at 34px wide and truncate longer text.The highest count shown; larger counts show as
max+ "+".What assistive tech reads instead of the visible content, e.g. "3 unread messages". Without it, a large badge reads its content and a small one
labels.newNotification.Ref to the root element.
Text
Words the badge announces, with English defaults. A
LabelsProvidersets them for the whole app.
Classes for each part, by slot.
classNames.rootis merged withclassName.Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
BadgedBox 6 props
The badge, a
Badge.The anchor, usually an icon.
Ref to the root element.
Classes for each part, by slot.
classNames.rootis merged withclassName.Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Tokens
M3's component tokens as CSS variables. Each is unset until you set it, on :root, a theme or any ancestor, and falls back to the default shown. The root carries data-variant (and data-size where it has sizes), which picks the variables that apply. See Component tokens in the Customisation guide.
| Variable | Default | Paints | Compose |
|---|---|---|---|
| Small (size) | |||
--md-comp-badge-color | var(--md-sys-color-error) | The small badge, a dot. | BadgeTokens.Color |
| Large (size) | |||
--md-comp-badge-large-color | var(--md-sys-color-error) | The large badge, holding a count or short text. | BadgeTokens.LargeColor |
--md-comp-badge-large-label-text-color | var(--md-sys-color-on-error) | The large badge's label. | BadgeTokens.LargeLabelTextColor |
Spec status
Built to the M3 Expressive badge spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.
| Item | Status | Details |
|---|---|---|
| Small badge | Built | Variant · Basic, Navigation |
| Large badge | Built | Variant · Basic, Navigation |
| Large badge with maximum characters | Built | Configuration · Basic, Navigation |
| On navigation items | Built | Use case · Navigation |
| On icons | Built | Use case · Basic |
| Count cap | Extension | max sets the highest count shown (999 by default, "999+"), and text longer than four characters stops at 34px and truncates. |
Small badge
BuiltVariant · Basic, Navigation
Large badge
BuiltVariant · Basic, Navigation
Large badge with maximum characters
BuiltConfiguration · Basic, Navigation
On navigation items
BuiltUse case · Navigation
On icons
BuiltUse case · Basic
Count cap
Extensionmaxsets the highest count shown (999 by default, "999+"), and text longer than four characters stops at 34px and truncates.
Bundle size
Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.
Badge,BadgedBox: 7.7 kB
M3 Expressive specs
- Sizes
small, large- Shape
rounded-corner-full
Spec values
- No children is the small 6px dot; children give the large badge (16px tall, at least 16px wide, with text over four characters cut at 34px, full corners, 4px side padding,
label-small), both inerror/on-error. Its height and width limits grow with a larger text size, so a single digit stays a circle. BadgedBoxplaces the badge like Compose: a small badge 6px inside the anchor's end at the top, a large one 12px inside the end hanging 2px above and past it.- Positioning uses a shared grid cell and a zero-size box, so the badge overflows without changing the anchor's size and mirrors in RTL; Compose's badge rulers (clamping to an outer bound) aren't ported.