Reference
Badge
Small status label.
Badge(_ label: String, tone: Enum, pill: Bool)
Before 5.0
label
tone
Billing
Beta 3 overdueExample
Row(gap: .sm, align: .center) {
Heading("Billing").h3
Badge("Beta").info
Badge("3 overdue").danger.pill
}
Every tone
Row(gap: .sm) {
Badge("Default")
Badge("Primary").primary
Badge("Secondary").secondary
Badge("Live").success
Badge("Failed").danger
Badge("Pending").warning
Badge("New").info
}
A pill, as a count
Row(gap: .xs, align: .center) { Text("Inbox") Badge("12").primary.pill }
A tone that follows state
state failing = true
Badge(if failing { "Failing" } else { "Passing" }, tone: if failing { .danger } else { .success })
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | none | The badge's text; unset, its block |
tone: | one of its cases | none: the surface colour with a border | The colour it is filled with, a tone of the theme, its text in the tone's
|
pill: | Bool | false | Fully rounded ends; the full theme already rounds a badge, so it matters with |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
.primary
.secondary
.success
.danger
.warning
.info
.pill
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
It takes no slots.
Renders with the class wf-badge, stable across releases, so a stylesheet may target it.