Communication
Badge
Badge — a status pill, or the count that rides on an icon.
import { Badge } from 'omaris' Examples
Status and counts
A status pill on a row, or a count on its own. max caps it — 100 becomes 99+, because past that the number stops mattering.
<script lang="ts"> import { Badge } from 'omaris';</script><Badge tone="success" variant="tonal">Live</Badge><Badge tone="warning" variant="tonal">Building</Badge><Badge tone="destructive" variant="tonal">Failed</Badge><Badge value={7} /><Badge value={128} /><Badge value={128} max={999} /> Anchored
anchor pins it to the corner of a relative parent — unread on a bell; dot drops the number when "something is new" is all that matters.
<script lang="ts"> import { Badge, IconButton } from 'omaris';</script>{#snippet bell()} ...{/snippet}<span class="relative inline-flex"> <IconButton aria-label="Notifications">{@render bell()}</IconButton> <Badge anchor="top-end" value={4} tone="destructive" label="4 unread" /></span><span class="relative inline-flex"> <IconButton aria-label="Notifications">{@render bell()}</IconButton> <Badge anchor="top-end" dot tone="success" label="Something new" /></span> When to use it
Use it for
- A count on an icon: unread on a bell, items in a cart.
valuewithanchor="top-end"on arelativeparent, andmaxso 100 reads "99+". - "Something new" with no number.
doton a Navigation Bar item or an Icon Button. - A read-only status on a row or a card: "Paid", "Draft", "Beta". A labelled pill,
tonaloroutlined, withtonecarrying the meaning. - A coloured word in a table cell.
variant="text"when a pill in every row is too loud.
Do
- Give a count or a dot a
label: "3 unread", not "3", so a screen reader says what the number is. - Put
relativeon the parent before youanchor. The badge is positioned absolutely and needs a box to pin to. - Keep one tone per meaning across the app:
successpaid,warningpending,destructivefailed. - Clear the dot as soon as the thing has been seen. A dot that never goes away means nothing.
Don't
- Use
filledfor status pills in a table. A column of solid capsules fights the data; usetonaloroutlined. - Show a zero. No
value, no badge. - Anchor a count to something nobody will act on. "99+" on a log tab is noise.
Quick reference
tone primary(default)secondarytertiarydestructivesuccesswarninginfo
variant filled(default)tonaloutlinedtext
size smmd(default)lg
anchor none(default)top-endtop-start
Pins the badge to the corner of a relative parent — a sibling of what it counts, not a wrapper around it. Without a positioned ancestor the badge's containing block is the page, and it lands in the top corner of the screen rather than of the bell.
API
Badge
Badge — a status pill, or the count that rides on an icon.
Same two axes as the button: variant is the fill style and tone the color role, resolved through the shared --btn-* properties. dot and count are MD3's small and large notification badges; both take anchor to pin themselves to the corner of a relative parent.
import { Badge } from 'omaris' Props
variant Defaults to 'filled'
BadgeVariant filledtonaloutlinedtext- Ghosted — the label carries the color, nothing else.
tone Defaults to 'primary'
BadgeTone primarysecondarytertiarydestructivesuccesswarninginfo
size Defaults to 'md'
BadgeSize smmdlg
dot Defaults to false
boolean Renders the 6dp dot instead of a label.
value number A number badge. Values above max render as "99+", and the pill stays a circle until two digits force it wider.
The number is the content: a badge given a value draws it and nothing else, so anything passed as children is dropped. Put the thing being counted beside the badge, inside a relative box.
max Defaults to 99
number Cap for value.
anchor Defaults to 'none'
BadgeAnchor Corner of the relative parent to pin to.
nonetop-endtop-start
label string Screen-reader text — "3 unread", not "3".
class string children Snippet