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

BoxList

Grid of cards, each with an icon, a label and a description, usually the entry points of a section (settings, reports, tools). A box with href is a link, one without is a button when it has its own onclick or onboxClick is set, and a plain card otherwise; onboxClick is called for links too. The grid fills the width with as many columns as fit (--box-list-min-width each, one column on a phone). color gives a box a different icon tone. Its state is exposed as data-color and data-interactive on each box for app CSS.

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

src/lib/components/simple/lists/BoxList.svelte · Markdown for LLMs

Sections

Entry points of a settings page: each box is a link with an icon, a label and a description. The grid puts as many columns as fit and becomes one column on a phone.

Code
<script lang="ts">
	import { BoxList, type BoxListItem } from '@likable-hair/svelte';
	import { mdiAccountGroupOutline, mdiBellOutline, mdiCreditCardOutline, mdiShieldLockOutline } from '@mdi/js';

	const boxes: BoxListItem[] = [
		{ name: 'team', label: 'Team', description: 'Members, roles and invitations', icon: mdiAccountGroupOutline, href: '#team' },
		{ name: 'billing', label: 'Billing', description: 'Plan, invoices and payment method', icon: mdiCreditCardOutline, href: '#billing' },
		{ name: 'notifications', label: 'Notifications', description: 'Emails and push messages', icon: mdiBellOutline, href: '#notifications' },
		{ name: 'security', label: 'Security', description: 'Password, two-factor login and sessions', icon: mdiShieldLockOutline, href: '#security' }
	];
</script>

<div class="demo">
	<BoxList {boxes} aria-label="Settings" />
</div>

<style>
	.demo {
		width: min(100%, 760px);
	}
</style>

Icon tones

color gives each box its own icon tone: primary (the default) or one of the six data colors of the theme.

Code
<script lang="ts">
	import { BoxList, type BoxListItem } from '@likable-hair/svelte';
	import { mdiChartBar, mdiContentCut, mdiPaletteOutline, mdiSpaOutline, mdiStorefrontOutline, mdiTagOutline } from '@mdi/js';

	const boxes: BoxListItem[] = [
		{ name: 'cut', label: 'Haircut', description: '45 min · € 38', icon: mdiContentCut, href: '#cut' },
		{ name: 'color', label: 'Full color', description: '90 min · € 65', icon: mdiPaletteOutline, color: 2, href: '#color' },
		{ name: 'treatment', label: 'Repair treatment', description: '30 min · € 25', icon: mdiSpaOutline, color: 3, href: '#treatment' },
		{ name: 'shop', label: 'Products', description: '128 items in stock', icon: mdiStorefrontOutline, color: 4, href: '#shop' },
		{ name: 'offers', label: 'Offers', description: '3 active promotions', icon: mdiTagOutline, color: 5, href: '#offers' },
		{ name: 'reports', label: 'Reports', description: 'Revenue and visits', icon: mdiChartBar, color: 6, href: '#reports' }
	];
</script>

<div class="demo">
	<BoxList {boxes} aria-label="Salon" />
</div>

<style>
	.demo {
		width: min(100%, 760px);
	}
</style>

Buttons

Without href and with onboxClick each box is a button; onboxClick receives the box and the event, and is called for links too. A box can also have its own onclick, which makes it a button without onboxClick. disabled turns a box off. Without onboxClick and href a box is a plain card.

Last clicked: none

Code
<script lang="ts">
	import { BoxList, type BoxListItem } from '@likable-hair/svelte';
	import { mdiDatabaseExportOutline, mdiDatabaseImportOutline, mdiDeleteSweepOutline } from '@mdi/js';

	const boxes: BoxListItem[] = [
		{ name: 'import', label: 'Import clients', description: 'From a CSV or Excel file', icon: mdiDatabaseImportOutline },
		{ name: 'export', label: 'Export clients', description: 'Download every client as CSV', icon: mdiDatabaseExportOutline, color: 4 },
		{ name: 'purge', label: 'Delete inactive clients', description: 'Only for administrators', icon: mdiDeleteSweepOutline, color: 6, disabled: true }
	];

	let last = $state('none');
</script>

<div class="demo">
	<BoxList {boxes} aria-label="Data tools" onboxClick={({ box }) => (last = box.label)} />
	<p>Last clicked: {last}</p>
</div>

<style>
	.demo {
		display: grid;
		gap: 12px;
		width: min(100%, 760px);
	}

	p {
		margin: 0;
	}
</style>

Snippets

appendSnippet adds content at the end of each box, such as an arrow; prependSnippet adds content at the start, such as an avatar; descriptionSnippet renders a richer description.

Code
<script lang="ts">
	import { Avatar, BoxList, Icon, type BoxListItem } from '@likable-hair/svelte';
	import { mdiChevronRight } from '@mdi/js';

	const people: BoxListItem<{ visits: number }>[] = [
		{ name: 'giulia', label: 'Giulia Marini', href: '#giulia', data: { visits: 12 } },
		{ name: 'luca', label: 'Luca Rossi', href: '#luca', data: { visits: 3 } },
		{ name: 'sara', label: 'Sara Bianchi', href: '#sara', data: { visits: 27 } }
	];
</script>

<div class="demo">
	<BoxList boxes={people} aria-label="Clients">
		{#snippet prependSnippet({ box })}
			<Avatar name={box.label} alt="" />
		{/snippet}
		{#snippet descriptionSnippet({ box })}
			<strong>{box.data?.visits}</strong> visits this year
		{/snippet}
		{#snippet appendSnippet()}
			<Icon path={mdiChevronRight} />
		{/snippet}
	</BoxList>
</div>

<style>
	.demo {
		width: min(100%, 760px);
	}
</style>

Compact grid

Boxes without icon or description make a list of quick links; --box-list-min-width sets the width of the columns and --box-list-gap the space between the boxes.

Code
<script lang="ts">
	import { BoxList, Icon, type BoxListItem } from '@likable-hair/svelte';
	import { mdiArrowRight } from '@mdi/js';

	const boxes: BoxListItem[] = [
		{ name: 'today', label: 'Today', href: '#today' },
		{ name: 'week', label: 'This week', href: '#week' },
		{ name: 'month', label: 'This month', href: '#month' },
		{ name: 'year', label: 'This year', href: '#year' }
	];
</script>

<div class="demo">
	<BoxList {boxes} aria-label="Agenda" --box-list-min-width="150px" --box-list-gap="8px">
		{#snippet appendSnippet()}
			<Icon path={mdiArrowRight} />
		{/snippet}
	</BoxList>
</div>

<style>
	.demo {
		width: min(100%, 760px);
	}
</style>

Props

NameTypeDefaultDescription
boxes requiredBoxListItem<Data>[]The boxes, shown in this order.
class string''Extra classes on the list.
boxListElement bindable HTMLUListElementThe <ul> element.

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

Snippets

NameParametersDescription
boxSnippet{ box: BoxListItem<Data>; index: number }Replaces the whole content of each box (icon, label, description, prepend and append), inside the link or button of the library.
iconSnippet{ box: BoxListItem<Data> }Replaces the icon tile, also in the boxes without icon.
labelSnippet{ box: BoxListItem<Data> }Replaces the label.
descriptionSnippet{ box: BoxListItem<Data> }Replaces the description, for example to render rich text; shown in every box.
prependSnippet{ box: BoxListItem<Data>; index: number }Content before the icon and the texts, on the start side of the box, such as an avatar.
appendSnippet{ box: BoxListItem<Data>; index: number }Content after the texts, on the end side of the box, such as an arrow or a badge.

Events

NameTypeDescription
onboxClick(args: { box: BoxListItem<Data>; event: MouseEvent }) => voidCalled when a box is clicked, links included (before the navigation), after the onclick of the box. Without it, the boxes without href or onclick are plain cards.

Types

Exported by the package: import type { BoxListItem } from '@likable-hair/svelte';

BoxListItem

One card of a BoxList.

interface BoxListItem<Data = unknown>

NameTypeDescription
name requiredstringUnique key of the box in the list, passed back to onboxClick.
label requiredstringMain text of the box, also its accessible name.
description stringSecondary text under the label, always visible. Screen readers read it as the description of the box.
icon stringSVG path of the icon shown in a tile above the label.
color 'primary' | 1 | 2 | 3 | 4 | 5 | 6Tone of the icon tile: primary (the default) or one of the six data colors of the theme.
href stringMakes the box a link to this URL.
onclick (event: MouseEvent) => voidCalled when this box is clicked, before onboxClick. A box without href becomes a button.
disabled booleanDisables the box: a button gets disabled, a link loses its href and gets aria-disabled; onclick and onboxClick are not called.
class stringExtra classes on the box element.
data DataAny app data, passed back to the snippets and to onboxClick.

CSS variables

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

Per-instance variableDefault
--box-list-min-width
--box-list-default-min-width 240px
--box-list-gap
--box-list-default-gap 12px
--box-list-box-gap
--box-list-default-box-gap 12px
--box-list-box-padding-y
--box-list-default-box-padding-y 12px
--box-list-box-padding-x
--box-list-default-box-padding-x 14px
--box-list-box-border-width
--box-list-default-box-border-width 1px
--box-list-box-border-color
--box-list-default-box-border-color var(--global-color-border)
--box-list-box-border-radius
--box-list-default-box-border-radius var(--global-radius-lg)
--box-list-box-background
--box-list-default-box-background var(--global-color-surface-solid)
--box-list-box-shadow
--box-list-default-box-shadow none
--box-list-box-color
--box-list-default-box-color var(--global-color-text)
--box-list-icon-color
--box-list-default-icon-color var(--global-color-primary)
--box-list-glow
--box-list-box-hover-lift
--box-list-default-box-hover-lift 2px
--box-list-box-hover-border-color
--box-list-box-hover-background
--box-list-default-box-hover-background var(--global-color-surface-solid)
--box-list-box-hover-shadow
--box-list-icon-hover-shadow
--box-list-disabled-opacity
--box-list-default-disabled-opacity 0.5
--box-list-text-gap
--box-list-default-text-gap 2px
--box-list-icon-tile-size
--box-list-default-icon-tile-size 34px
--box-list-icon-gap
--box-list-default-icon-gap 10px
--box-list-icon-tile-border-radius
--box-list-default-icon-tile-border-radius var(--global-radius-md)
--box-list-icon-background
--box-list-default-icon-background var(--global-color-primary-soft)
--box-list-icon-size
--box-list-default-icon-size 19px
--box-list-label-color
--box-list-default-label-color var(--global-color-text)
--box-list-label-font-size
--box-list-default-label-font-size 14px
--box-list-label-font-weight
--box-list-default-label-font-weight 600
--box-list-description-color
--box-list-default-description-color var(--global-color-text-3)
--box-list-description-font-size
--box-list-default-description-font-size 12.5px
--box-list-append-color
--box-list-default-append-color var(--global-color-text-3)

Other defaults

VariableValue
--box-list-default-box-hover-border-tint45%
--box-list-default-box-hover-shadow-shape0 18px 36px -22px
--box-list-default-box-hover-shadow-tint70%
--box-list-default-glow-tint12%
--box-list-default-glow-size140% 110%
--box-list-default-glow-reach60%
--box-list-default-icon-hover-shadow-shape0 6px 18px -4px
--box-list-default-icon-hover-shadow-tint60%
--box-list-default-icon-color-1var(--global-color-data-1)
--box-list-default-icon-color-2var(--global-color-data-2)
--box-list-default-icon-color-3var(--global-color-data-3)
--box-list-default-icon-color-4var(--global-color-data-4)
--box-list-default-icon-color-5var(--global-color-data-5)
--box-list-default-icon-color-6var(--global-color-data-6)
--box-list-default-icon-background-1light-dark(color-mix(in oklab, var(--global-color-data-1) 10%, transparent), color-mix(in oklab, var(--global-color-data-1) 14%, transparent))
--box-list-default-icon-background-2light-dark(color-mix(in oklab, var(--global-color-data-2) 10%, transparent), color-mix(in oklab, var(--global-color-data-2) 14%, transparent))
--box-list-default-icon-background-3light-dark(color-mix(in oklab, var(--global-color-data-3) 10%, transparent), color-mix(in oklab, var(--global-color-data-3) 14%, transparent))
--box-list-default-icon-background-4light-dark(color-mix(in oklab, var(--global-color-data-4) 10%, transparent), color-mix(in oklab, var(--global-color-data-4) 14%, transparent))
--box-list-default-icon-background-5light-dark(color-mix(in oklab, var(--global-color-data-5) 10%, transparent), color-mix(in oklab, var(--global-color-data-5) 14%, transparent))
--box-list-default-icon-background-6light-dark(color-mix(in oklab, var(--global-color-data-6) 10%, transparent), color-mix(in oklab, var(--global-color-data-6) 14%, transparent))