Reference

Badge

Small status label.

Badge(_ label: String, tone: Enum, pill: Bool)

Before 5.0

label

tone

Billing

Beta 3 overdue

Example

wf

Row(gap: .sm, align: .center) { Heading("Billing").h3 Badge("Beta").info Badge("3 overdue").danger.pill }

Every tone

wf

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

wf

Row(gap: .xs, align: .center) { Text("Inbox") Badge("12").primary.pill }

A tone that follows state

wf

state failing = true Badge(if failing { "Failing" } else { "Passing" }, tone: if failing { .danger } else { .success })

Props

Props of Badge
PropTypeUnsetMeaning

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 color-on-*. Written as a flag, .primary, or by name, tone: .primary.

  • .primary: The theme's primary colour
  • .secondary: The theme's secondary colour
  • .success: Green: done, healthy
  • .danger: Red: failed, destructive
  • .warning: Amber: needs attention
  • .info: Blue: a neutral notice

pill:

Bool

false

Fully rounded ends; the full theme already rounds a badge, so it matters with theme.builtin: "structural". Written as a flag, .pill, or pill: true.

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.