Badge
A small red count.
Overview
A count of unread or pending things that sits on an icon button.
On icon
Do
import { IconButton } from "@hackcove/ui";
<IconButton label="Alerts" badge={3}>
<svg viewBox="0 0 20 20" width="20" height="20" fill="currentColor" aria-hidden="true">
<path
d="M10 2a5 5 0 0 0-5 5v2.6c0 .5-.2 1-.5 1.4L3.3 12.5a.75.75 0 0 0 .55 1.25
h12.3a.75.75 0 0 0 .55-1.25L15.5 11a2 2 0 0 1-.5-1.4V7a5 5 0 0 0-5-5Z
m-1.9 13.5a2 2 0 0 0 3.8 0H8.1Z"
/>
</svg>
</IconButton>badge on an IconButton pins the count to the corner and adds it to the button's name ("Alerts, 3").Don't
3
import { Cluster, IconButton, Pill } from "@hackcove/ui";
<Cluster>
<IconButton label="Alerts">
<svg viewBox="0 0 20 20" width="20" height="20" fill="currentColor" aria-hidden="true">
<path
d="M10 2a5 5 0 0 0-5 5v2.6c0 .5-.2 1-.5 1.4L3.3 12.5a.75.75 0 0 0 .55 1.25
h12.3a.75.75 0 0 0 .55-1.25L15.5 11a2 2 0 0 1-.5-1.4V7a5 5 0 0 0-5-5Z
m-1.9 13.5a2 2 0 0 0 3.8 0H8.1Z"
/>
</svg>
</IconButton>
<Pill tone="red" round>
3
</Pill>
</Cluster>badge.Count
Do
799+
import { Badge, Cluster } from "@hackcove/ui";
<Cluster>
<Badge count={7} />
<Badge count={120} />
</Cluster>99+.Usage
- On an icon, give the
IconButtonabadgecount; it pins the Badge to the corner and puts the count in the button's name. - A
countabove 99 reads99+. - Show a Badge only when there is something to count: a
countof 0 still draws a0, so leave it out instead. - A tinted label with words in it is a
Pill, not a Badge.
Accessibility
- A Badge is a
<span>with the number as its text. - Inside an
IconButton, the Badge isaria-hiddenand the count is part of the button'saria-labelandtitle("Alerts, 3"), so it is announced once. cornerpins the Badge to its nearest positioned parent;IconButtonalready provides one.
API
Badge
A small red count, 10px, for sitting on an icon. corner pins it to the top-right corner of its relative parent (wrap the icon button and the badge in a relative inline-flex element); a count above 99 reads 99+. Name the control it sits on (aria-label on the button) for a screen reader. An IconButton takes badge itself and does all of this.
corner- Type
boolean- Default
false
count required- Type
number