Skip to content
iv-ui v0.3.0

Badge

since 0.2.0

A compact label for status, counts, or categories.

import { Badge } from '@elluzion/iv-ui';

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>
  • variant colors the label; neutral stays monochrome.
  • dismissible adds a remove button wired to ondismiss.
  • Badges are not buttons; use Toggle for pressable chips.

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>
import { Badge } from '@elluzion/iv-ui';

Props

4 props · 1 events · 1 snippets
PropTypeDefaultDescription
variant 'neutral' | 'success' | 'error' | 'accent' | 'info''neutral'Status color. neutral is the default.
size 'sm' | 'md''md'Badge size.
dismissible booleanfalseShows a remove button.
className string''Extra classes merged onto the root element.

Events

EventHandler typeDescription
ondismiss() => voidCalled when the remove button is pressed.

The legacy on:name form is accepted for every event.

Snippets

SnippetTypeDescription
childrenSnippetBadge text.
  • 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.
Class hooks
.iv-accent.iv-badge.iv-badge-content.iv-badge-dismiss.iv-dismissible.iv-error.iv-info.iv-sm.iv-success
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records