Components

List component

The kit:list and kit:list-item components render structured vertical lists. Items are interactive automatically when onclick is attached or href is set.

list.svelte
<script lang="ts">
	import { Inbox, Send, Archive, Trash2, Star } from 'lucide-svelte';

	const items = [
		{ icon: Inbox, label: 'Inbox', count: 12 },
		{ icon: Star, label: 'Starred', count: 3 },
		{ icon: Send, label: 'Sent' },
		{ icon: Archive, label: 'Archive' },
		{ icon: Trash2, label: 'Trash' }
	];

	let active = $state('Inbox');
</script>

<kit:list style="max-width: 240px;">
	{#each items as item (item.icon)}
		<kit:list-item is="button" active={active === item.label} onclick={() => (active = item.label)}>
			{#snippet prepend()}
				{@const Icon = item.icon}
				<kit:icon><Icon /></kit:icon>
			{/snippet}
			{item.label}
			{#if item.count}
				{#snippet append()}
					<kit:chip variant="filled" size="xs" labelStyle>{item.count}</kit:chip>
				{/snippet}
			{/if}
		</kit:list-item>
	{/each}
</kit:list>

kit:list is a layout container that sets size tokens consumed by its kit:list-item children. kit:list-item detects its tag automatically: it renders as <a> when href is set, <button> when an onclick is attached, or <div> otherwise.

Examples of list

Variants

The variant and the color of the list apply to all its items. A kit:list-item can override the color with its own color.

  • filled (default): surface background (--kit-color-surface-2), or the color with a contrasted text.

  • tonal: light tint of the color, text in the color.

  • outline: transparent background with a border on each item.

  • surface: very light tint of the color with a soft border.

  • text: transparent background, text in the color.

  • plain: like text, but hover and pressed only change the text color, never the background.

  • variant: 'filled' | 'tonal' | 'outline' | 'surface' | 'text' | 'plain' = 'filled'

  • color: string | false = undefined

list.svelte
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;">
	{#each ['filled', 'tonal', 'outline', 'surface', 'text', 'plain'] as variant (variant)}
		<kit:list {variant} color="accent">
			<kit:list-item is="button">{variant}</kit:list-item>
			<kit:list-item is="button" active>Item two</kit:list-item>
			<kit:list-item is="button">Item three</kit:list-item>
		</kit:list>
	{/each}
</div>

prepend and append

kit:list-item supports prepend and append snippets for icons, avatars, badges, or any inline content.

  • prepend: Snippet | undefined = undefined
  • append: Snippet | undefined = undefined
list.svelte
<script lang="ts">
	import { User, Mail, Phone, ChevronRight } from 'lucide-svelte';
</script>

<kit:list style="max-width: 280px;">
	<kit:list-item is="button">
		{#snippet prepend()}<kit:icon><User /></kit:icon>{/snippet}
		Profile
		{#snippet append()}<kit:icon size="sm"><ChevronRight /></kit:icon>{/snippet}
	</kit:list-item>
	<kit:list-item is="button">
		{#snippet prepend()}<kit:icon><Mail /></kit:icon>{/snippet}
		Email
		{#snippet append()}<kit:icon size="sm"><ChevronRight /></kit:icon>{/snippet}
	</kit:list-item>
	<kit:list-item is="button">
		{#snippet prepend()}<kit:icon><Phone /></kit:icon>{/snippet}
		Phone
		{#snippet append()}<kit:icon size="sm"><ChevronRight /></kit:icon>{/snippet}
	</kit:list-item>
</kit:list>

Add nav to kit:list (and is="nav") for a navigation list. This increases padding and sets role="navigation" on the container.

  • nav: boolean = false
list.svelte
<kit:list is="nav" nav style="max-width: 200px;">
	<kit:list-item href="/docs">Documentation</kit:list-item>
	<kit:list-item href="/docs/components" active>Components</kit:list-item>
	<kit:list-item href="/docs/hooks">Hooks</kit:list-item>
	<kit:list-item href="/docs/hooks" disabled>Changelog</kit:list-item>
</kit:list>

Without preprocess Lapikit

If you aren’t using the Lapikit preprocessor in svelte.config.js, import the components directly:

import { List, ListItem } from 'lapikit/components';

API Reference

kit:list

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''nav''ul'HTML element to render.'div'
classstring | array | objectClasses of the list, with the rules of Svelte (clsx).
stylestringInline style of the list.
s-classstring | array | objectClasses of the list, merged with class.
s-styleobjectInline style as an object of property / value pairs.
variantenum'filled''tonal''outline''surface''text''plain'Visual style of the items.'filled'
sizeenum'xs''sm''md''lg''xl'Item height, padding, gap and font size (in rem).'md'
densityenum'dense''compact''default''comfortable''spacious'Item height and padding, from -4px to +4px.'default'
roundedenum0'xs''sm''md''lg''xl''full'Border radius on list items children.'md'
navbooleanNavigation mode more padding, role="navigation".false
colorstring | falseColor of all the items, its use depends on the variant.
childrenSnippetList items.

kit:list-item

propstypedescriptiondefault
ref $bindableHTMLElementBindable reference to the rendered DOM element.null
isenum'div''a''button''li'HTML element. Overridden by href or onclick.'div'
classstring | array | objectClasses of the item, with the rules of Svelte (clsx).
stylestringInline style of the item.
s-classstring | array | objectClasses of the item, merged with class.
s-styleobjectInline style as an object of property / value pairs.
hrefstringRenders as <a>. Cleared when disabled.
activebooleanApplies the active color.false
disabledbooleanDims and blocks interaction.false
noRipplebooleanDisables the ripple animation.false
interactiveboolean | undefinedundefined detects (<a>, <button>, onclick), true forces, false disables the visual feedback.undefined
colorstring | false | { base?, active? }Color of the item, overrides the color of the list.
prependSnippetContent before the label.
appendSnippetContent after the label.
childrenSnippetItem label.

A well-structured kit:list can easily be enriched with Separators or elements in a Card.