WBadge
Inline status or label pill. Composes a pill-shaped WDiv (rounded-full) around a WText (text-xs). All visual styling is className-driven: the caller supplies tone via bg-* and text-* tokens (with dark: pairs); no colours are baked in.
On this page
Basic Usage#
widgets/w_badge_basic
A live demo of this example follows.
w_badge_basic.dart
View source
Open demo
WBadge(
'Active',
className: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100',
)
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
label |
String |
Required | The text displayed inside the badge. |
className |
String? |
null |
Caller-supplied utility classes appended after the default layout classes (inline-flex items-center rounded-full px-2 py-0.5). Use this to supply bg-*, text-*, and their dark: pairs. |
Constructor#
const WBadge(
String label, {
Key? key,
String? className,
})
label is a required positional parameter.
Styling Examples#
Status Tones#
Supply tone through bg-* + text-* + their dark: pairs. The default layout provides no background or text colour:
// Success
WBadge('Paid', className: 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-100')
// Warning
WBadge('Pending', className: 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-100')
// Danger
WBadge('Error', className: 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-100')
// Neutral
WBadge('Draft', className: 'bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300')
Inline Beside Text#
The default classes include inline-flex, but Wind treats it as an inert token (it has no inline display), so the badge sits beside other widgets because of the parent flex flex-row container:
WDiv(
className: 'flex flex-row items-center gap-2',
children: [
WText('Invoice #1042', className: 'text-base font-medium text-gray-900 dark:text-white'),
WBadge('Paid', className: 'bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-200'),
],
)
With a WindRecipe#
Use WindRecipe to drive tone from a variant axis instead of repeating className strings:
final badge = WindRecipe(
base: 'items-center rounded-full px-2.5 py-0.5 text-xs font-medium',
variants: {
'tone': {
'success': 'bg-green-100 dark:bg-green-900 text-green-800 dark:text-green-200',
'warning': 'bg-yellow-100 dark:bg-yellow-900 text-yellow-800 dark:text-yellow-200',
},
},
defaultVariants: {'tone': 'success'},
);
WBadge('Deployed', className: badge(variants: {'tone': 'success'}))
WBadge('Pending', className: badge(variants: {'tone': 'warning'}))
Related Documentation#
- WDiv: the pill container
WBadgedelegates to internally. - WText: the label renderer inside the badge.
- WindRecipe: compose badge tone variants without repeating className strings.