Badges are used to inform the user of the status of specific data. Perfect for notifications, labels, and status indicators.
Basic Usage
Badges with different colors and variants.
await import('/components/data-display/badge.js');
const { tags, $ } = Lightview;
const { div, Badge } = tags;
const badges = div({ style: 'display: flex; flex-direction: column; gap: 1rem;' },
// Colors
div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Badge({}, 'Default'),
Badge({ color: 'primary' }, 'Primary'),
Badge({ color: 'secondary' }, 'Secondary'),
Badge({ color: 'accent' }, 'Accent'),
Badge({ color: 'info' }, 'Info'),
Badge({ color: 'success' }, 'Success'),
Badge({ color: 'warning' }, 'Warning'),
Badge({ color: 'error' }, 'Error')
),
// Variants
div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Badge({ variant: 'outline' }, 'Outline'),
Badge({ variant: 'soft', color: 'primary' }, 'Soft'),
Badge({ variant: 'dash', color: 'secondary' }, 'Dash')
)
);
$('#example').content(badges);
Notification Counter
Reactive badge showing notification count.
await import('/components/data-display/badge.js');
await import('/components/actions/button.js');
const { signal, tags, $ } = Lightview;
const { div, Badge, Button } = tags;
const count = signal(5);
const demo = div({ style: 'display: flex; flex-direction: row; gap: 0.5rem;' },
Button({
size: 'sm',
color: 'primary',
onclick: () => { count.value++; }
}, '+ Add Message'),
Button({},
'Inbox',
Badge({
color: 'secondary',
style: 'margin-left: 0.5rem;'
}, () => count.value > 99 ? '99+' : count.value)
),
Button({
size: 'sm',
onclick: () => { count.value = 0; }
}, 'Clear')
);
$('#example').content(demo);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
color |
string | - | 'primary' | 'secondary' | 'accent' | 'success' | 'warning' | 'info' | 'error' | 'ghost' | 'neutral' |
size |
string | 'md' | 'xs' | 'sm' | 'md' | 'lg' |
variant |
string | - | 'outline' | 'soft' | 'dash' |
Colors
Default
Neutral
Primary
Secondary
Accent
Ghost
Info
Success
Warning
Error
Variants
Outline
Soft
Dash
Sizes
xs
sm
md
lg
In Button
Custom Element Gallery
Live examples using <lv-badge> custom elements with various options.