Content
Badge
A small pill of words that states a status or a count, such as "Done" or "1 h 32 late"; people read it, they do not press it.
In kanso-ui as Badge
Web and native
Web
Native
Badge in kanso-ui 0.59.0, for React.
import { Badge } from '@kanso-labs/kanso-ui'A small mark on the corner of what it wraps, usually an icon, that flags something new there: a 6dp dot, or with count a 16dp badge holding a number.
It follows Material Design's badges page: both sizes use the error colour pair on a full corner, and the count is set in label small with tabular figures.
What you provide
children: the element the mark sits on, usually a 24dp icon. Leave it out to draw the mark alone in the line.- The mark is hidden from assistive technology, so put what it says in the name of the control it sits on:
aria-label="Notifications, 3 new".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
count | number | — | The number to show, which draws Kanso's count. Left out, the badge is the 6px dot, which flags without counting. A count of 0 still draws, so leave the badge out when there is nothing to count. |
label | string | — | What a screen reader hears in the mark's place, which stays hidden: the count with the words that say what it counts, "3 left". It is drawn nowhere. Give it to a badge standing in a line of text, after the title it counts for. On a control's icon leave it out, and put the count in the control's own name instead, "Notifications, 3 new", so the name a speech-input user says is the name the control has. |
max | number | 999 | The largest count drawn as itself. Above it the badge reads `max` and a plus, 999+ at the default. |
Also takes the props of RenderComponentProps<'span'>.
Example
import { Badge, IconButton } from '@kanso-labs/kanso-ui'
<IconButton aria-label="Notifications, 3 new">
<Badge count={3}>
<BellIcon />
</Badge>
</IconButton>The design’s classes
k-badge with k-badge--accent, k-badge--accent-soft, k-badge--positive, k-badge--caution, k-badge--negative, k-badge--critical or k-badge--count.
Maps to Badge in kanso-ui and react-native-kanso-ui.