Badge
A compact label for status, counts, or categories.
import { Badge } from '@elluzion/iv-ui'; 01 Preview
Variants
Neutral, success, error, accent, and info.
neutral success error accent info
Source· svelte Show Hide
<script lang="ts">
import { Badge } from '@elluzion/iv-ui';
</script>
<div class="row">
<Badge>neutral</Badge>
<Badge variant="success">success</Badge>
<Badge variant="error">error</Badge>
<Badge variant="accent">accent</Badge>
<Badge variant="info">info</Badge>
</div>
<style>
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--iv_spacing-sm);
}
</style>02 Usage
variantcolors the label;neutralstays monochrome.dismissibleadds a remove button wired toondismiss.- Badges are not buttons; use
Togglefor pressable chips.
03 Examples
Sizes
sm and md label heights.
stable stable beta beta
Source· svelte Show Hide
<script lang="ts">
import { Badge } from '@elluzion/iv-ui';
</script>
<div class="row">
<Badge size="sm" variant="success">stable</Badge>
<Badge variant="success">stable</Badge>
<Badge size="sm" variant="accent">beta</Badge>
<Badge variant="accent">beta</Badge>
</div>
<style>
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--iv_spacing-sm);
}
</style>Dismissible
A trailing remove button calls ondismiss.
edge cache read-only
Source· svelte Show Hide
<script lang="ts">
import { Badge, Button } from '@elluzion/iv-ui';
let tags = $state(['edge', 'cache', 'read-only']);
function remove(tag: string) {
tags = tags.filter((value) => value !== tag);
}
</script>
<div class="stack">
<div class="row">
{#each tags as tag (tag)}
<Badge variant="neutral" dismissible ondismiss={() => remove(tag)}>{tag}</Badge>
{/each}
{#if tags.length === 0}<span class="empty">no tags</span>{/if}
</div>
{#if tags.length < 3}
<Button size="sm" variant="ghost" onclick={() => (tags = ['edge', 'cache', 'read-only'])}>
Restore
</Button>
{/if}
</div>
<style>
.stack {
display: flex;
flex-direction: column;
align-items: start;
gap: var(--iv_spacing-sm);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--iv_spacing-sm);
}
.empty {
font-family: var(--iv_font-mono);
font-size: var(--iv_text-sm);
color: var(--iv_foreground-dim);
}
</style>04 API
import { Badge } from '@elluzion/iv-ui';Props
4 props · 1 events · 1 snippets| Prop | Type | Default | Description |
|---|---|---|---|
| variant | 'neutral' | 'success' | 'error' | 'accent' | 'info' | 'neutral' | Status color. neutral is the default. |
| size | 'sm' | 'md' | 'md' | Badge size. |
| dismissible | boolean | false | Shows a remove button. |
| className | string | '' | Extra classes merged onto the root element. |
Events
| Event | Handler type | Description |
|---|---|---|
| ondismiss | () => void | Called when the remove button is pressed. |
The legacy on:name form is accepted for every event.
Snippets
| Snippet | Type | Description |
|---|---|---|
| children | Snippet | Badge text. |
05 Accessibility
- Color is not the only signal; the text carries the meaning.
- The dismiss control is a button with an accessible name.
- Keep labels short; the badge truncates instead of wrapping.
06 Tokens & CSS hooks
Tokens used
--iv_accent --iv_badge-h-md --iv_badge-h-sm --iv_badge-pad-x-md --iv_badge-pad-x-sm --iv_border --iv_error --iv_font-mono --iv_foreground --iv_foreground-dim --iv_info --iv_outline-offset --iv_outline-width --iv_radius-sm --iv_spacing-sm --iv_spacing-xs --iv_success --iv_surface-elevated --iv_surface-overlay --iv_text-chips --iv_text-xs --iv_weight-semibold
Class hooks
.iv-accent.iv-badge.iv-badge-content.iv-badge-dismiss.iv-dismissible.iv-error.iv-info.iv-sm.iv-success