Skip to content
Likable Aurora @likable-hair/svelte 5

Chip

Compact label for tags, statuses, filters and selections, with seven color variants (variant) and two sizes (size). With onclick its content becomes a native <button>; with selected as well it is a toggle (aria-pressed) that takes the selected look. closable adds a separate close button that calls onclose. Long text is cut with an ellipsis when the chip has no room, or past --chip-max-width. Its state is exposed as data-variant, data-size, data-selected and data-disabled for app CSS.

import { Chip } from '@likable-hair/svelte';

src/lib/components/simple/navigation/Chip.svelte · Markdown for LLMs

Variants and sizes

Seven colors and two sizes. prependIcon takes an SVG path; prependSnippet takes any content, here a pulsing status dot.

Default VIP Online Paid Pending Expired Pro
10′ 35′ Confirmed Cancelled
Code
<script lang="ts">
	import { mdiCheck, mdiLightningBolt, mdiTagOutline } from '@mdi/js';
	import { Chip } from '@likable-hair/svelte';
</script>

<div class="rows">
	<div class="row">
		<Chip prependIcon={mdiTagOutline}>Default</Chip>
		<Chip variant="primary">VIP</Chip>
		<Chip variant="accent">
			{#snippet prependSnippet()}<span class="dot"></span>{/snippet}
			Online
		</Chip>
		<Chip variant="success" prependIcon={mdiCheck}>Paid</Chip>
		<Chip variant="warning">Pending</Chip>
		<Chip variant="error">Expired</Chip>
		<Chip variant="filled" prependIcon={mdiLightningBolt}>Pro</Chip>
	</div>
	<div class="row">
		<Chip size="sm">10′</Chip>
		<Chip size="sm" variant="primary">35′</Chip>
		<Chip size="sm" variant="success">Confirmed</Chip>
		<Chip size="sm" variant="error">Cancelled</Chip>
	</div>
</div>

<style>
	.rows {
		display: grid;
		gap: 14px;
	}

	.row {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		gap: 8px;
	}

	.dot {
		width: 6px;
		height: 6px;
		border-radius: 50%;
		background: currentColor;
		animation: pulse 1.8s infinite;
	}

	@keyframes pulse {
		from {
			box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent);
		}
		to {
			box-shadow: 0 0 0 8px transparent;
		}
	}

	@media (prefers-reduced-motion: reduce) {
		.dot {
			animation: none;
		}
	}
</style>

Toggle chips

With onclick the chip is a <button>; adding selected makes it a toggle with aria-pressed, and the selected one takes the filled look. The parent keeps the selection.

Selected: color

Code
<script lang="ts">
	import { mdiContentCut, mdiHairDryerOutline, mdiPalette, mdiSpa } from '@mdi/js';
	import { Chip } from '@likable-hair/svelte';

	const services = [
		{ value: 'cut', label: 'Cut', icon: mdiContentCut },
		{ value: 'color', label: 'Color', icon: mdiPalette },
		{ value: 'blow-dry', label: 'Blow-dry', icon: mdiHairDryerOutline },
		{ value: 'treatment', label: 'Treatment', icon: mdiSpa }
	];

	let selected = $state<string[]>(['color']);

	function toggle(value: string) {
		selected = selected.includes(value)
			? selected.filter((v) => v !== value)
			: [...selected, value];
	}
</script>

<div class="toggle">
	<div class="row" role="group" aria-label="Services">
		{#each services as service (service.value)}
			<Chip
				prependIcon={service.icon}
				selected={selected.includes(service.value)}
				onclick={() => toggle(service.value)}
			>
				{service.label}
			</Chip>
		{/each}
	</div>
	<p>Selected: {selected.join(', ') || 'none'}</p>
</div>

<style>
	.toggle {
		display: grid;
		gap: 12px;
	}

	.row {
		display: flex;
		flex-wrap: wrap;
		gap: 8px;
	}

	p {
		margin: 0;
		font-size: 13px;
	}
</style>

Removable chips

closable adds a separate close button named by closeLabel; onclose receives its click. Text that does not fit is cut with an ellipsis: --chip-max-width sets a cap.

Cut Balayage Keratin treatment with deep conditioning mask Blow-dry
Code
<script lang="ts">
	import { Button, Chip } from '@likable-hair/svelte';

	const initial = ['Cut', 'Balayage', 'Keratin treatment with deep conditioning mask', 'Blow-dry'];
	let tags = $state([...initial]);
</script>

<div class="row">
	{#each tags as tag (tag)}
		<Chip
			variant="primary"
			closable
			closeLabel="Remove {tag}"
			title={tag}
			onclose={() => (tags = tags.filter((t) => t !== tag))}
			--chip-max-width="200px"
		>
			{tag}
		</Chip>
	{:else}
		<Button size="sm" variant="secondary" onclick={() => (tags = [...initial])}>Restore</Button>
	{/each}
</div>

<style>
	.row {
		display: flex;
		flex-wrap: wrap;
		gap: 8px;
	}
</style>

Props

NameTypeDefaultDescription
variant 'neutral' | 'primary' | 'accent' | 'success' | 'warning' | 'error' | 'filled''neutral'Color. filled is the strongest, for a highlighted chip.
size 'sm' | 'md''md'Height, padding and text size: sm 22px, md 26px.
selected booleanSelected state of a toggle chip: with onclick it sets aria-pressed. When true the chip takes the selected look, by default the same as filled.
disabled booleanfalseDisables the chip button and the close button.
prependIcon stringSVG path of an icon before the text, for example from @mdi/js.
closable booleanfalseShows a close button after the text, which calls onclose.
closeIcon stringCLOSE_ICONSVG path of the close button icon. Defaults to the MDI close icon.
closeLabel stringAccessible name of the close button. Defaults to "Remove", in the language of locale.
locale stringBCP 47 locale of the texts: it and en are built in, other languages fall back to English. Defaults to the one set with setDefaultLocale, else en.
tabindex numberNative tabindex of the chip button and of the close button: -1 keeps both out of the tab order.
chipElement bindable HTMLSpanElementThe root <span> element.

It also accepts the native attributes and events of <span> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
childrenChip text.
prependSnippetReplaces the icon before the text with any content (a status dot, an avatar).
closeSnippet{ close: (event: MouseEvent) => void; closeLabel: string }Replaces the close button. close calls onclose. Shown even without closable.

Events

NameTypeDescription
onclick(event: MouseEvent) => voidCalled on click. With it the chip content becomes a native <button>.
onclose(event: MouseEvent) => voidCalled on a click on the close button.

CSS variables

For a single instance, pass them as style props: <Chip --chip-background="tomato">. The --chip-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--chip-icon-size
--chip-default-icon-size 15px
--chip-default-sm-icon-size 14px
--chip-max-width
--chip-default-max-width 100%
--chip-height
--chip-default-height 26px
--chip-default-sm-height 22px
--chip-border-color
--chip-default-neutral-border-color var(--global-color-border)
--chip-default-primary-border-color color-mix(in oklab, var(--global-color-primary) 30%, transparent)
--chip-default-accent-border-color color-mix(in oklab, var(--global-color-accent) 30%, transparent)
--chip-default-success-border-color transparent
--chip-default-warning-border-color transparent
--chip-default-error-border-color transparent
--chip-default-filled-border-color transparent
--chip-background
--chip-default-neutral-background var(--global-color-surface-2)
--chip-default-primary-background var(--global-color-primary-soft)
--chip-default-accent-background var(--global-color-accent-soft)
--chip-default-success-background var(--global-color-success-soft)
--chip-default-warning-background var(--global-color-warning-soft)
--chip-default-error-background var(--global-color-error-soft)
--chip-default-filled-background var(--global-fill-gradient)
--chip-color
--chip-default-neutral-color var(--global-color-text)
--chip-default-primary-color var(--global-color-primary)
--chip-default-accent-color var(--global-color-accent)
--chip-default-success-color var(--global-color-success)
--chip-default-warning-color var(--global-color-warning)
--chip-default-error-color var(--global-color-error)
--chip-default-filled-color var(--global-color-on-primary)
--chip-box-shadow
--chip-default-neutral-box-shadow 0 0 #0000
--chip-default-primary-box-shadow 0 0 #0000
--chip-default-accent-box-shadow 0 0 #0000
--chip-default-success-box-shadow 0 0 #0000
--chip-default-warning-box-shadow 0 0 #0000
--chip-default-error-box-shadow 0 0 #0000
--chip-default-filled-box-shadow 0 6px 16px -6px var(--global-color-primary-glow)
--chip-border-width
--chip-default-border-width var(--global-border-width)
--chip-border-radius
--chip-default-border-radius var(--global-radius-sm)
--chip-font-family
--chip-default-font-family inherit
--chip-font-size
--chip-default-font-size 12.5px
--chip-default-sm-font-size 12px
--chip-font-weight
--chip-default-font-weight 500
--chip-selected-border-color
--chip-default-selected-border-color var(--chip-default-filled-border-color)
--chip-selected-hover-border-color
--chip-default-selected-hover-border-color var(--chip-default-filled-hover-border-color)
--chip-selected-background
--chip-default-selected-background var(--chip-default-filled-background)
--chip-selected-color
--chip-default-selected-color var(--chip-default-filled-color)
--chip-selected-box-shadow
--chip-default-selected-box-shadow var(--chip-default-filled-box-shadow)
--chip-gap
--chip-default-gap 6px
--chip-padding
--chip-default-padding 0 10px
--chip-default-sm-padding 0 8px
--chip-close-margin-end
--chip-default-close-margin-end 4px
--chip-close-icon-size
--chip-default-close-icon-size 14px
--chip-close-size
--chip-default-close-size 18px
--chip-close-border-radius
--chip-default-close-border-radius var(--global-radius-full)
--chip-close-color
--chip-default-close-color color-mix(in oklab, currentColor 70%, transparent)
--chip-hover-border-color
--chip-default-neutral-hover-border-color var(--global-color-border-strong)
--chip-default-primary-hover-border-color color-mix(in oklab, var(--global-color-primary) 55%, transparent)
--chip-default-accent-hover-border-color color-mix(in oklab, var(--global-color-accent) 55%, transparent)
--chip-default-success-hover-border-color color-mix(in oklab, var(--global-color-success) 40%, transparent)
--chip-default-warning-hover-border-color color-mix(in oklab, var(--global-color-warning) 40%, transparent)
--chip-default-error-hover-border-color color-mix(in oklab, var(--global-color-error) 40%, transparent)
--chip-default-filled-hover-border-color transparent
--chip-hover-background
--chip-hover-color
--chip-hover-transform
--chip-default-hover-transform translateY(-1px)
--chip-close-hover-background
--chip-default-close-hover-background color-mix(in oklab, currentColor 14%, transparent)
--chip-close-hover-color
--chip-default-close-hover-color currentColor
--chip-focus-ring-width
--chip-default-focus-ring-width var(--global-focus-ring-width)
--chip-focus-ring-color
--chip-default-focus-ring-color var(--global-focus-ring-color)
--chip-focus-ring-offset
--chip-default-focus-ring-offset var(--global-focus-ring-offset)
--chip-close-focus-ring-offset
--chip-default-close-focus-ring-offset 0px
--chip-disabled-opacity
--chip-default-disabled-opacity 0.4