# DashboardShaper

Grid of widgets for a dashboard: `columns` equal columns, rows `--dashboard-shaper-row-height` tall, each widget placed by its `left`, `top`, `width` and `height` (the same shape saved by v4) and drawn by `widgetSnippet`. Read-only by default, it shows only the rows in use. With `editing` the user arranges it: the empty spaces become dashed "Add widget" buttons that open the catalog (a dialog, a bottom sheet on screens up to 1024px) with the widgets of `catalog` and the sizes that fit there. From 6 widgets the catalog has a search field (`searchable`), which matches title and description ignoring case and accents and takes the focus when the catalog opens from the keyboard or the mouse; with two or more `category` values it has filter chips, each with the number of matching widgets (none selected shows them all, several show their union). The catalog keeps the height it opens with, up to `--dashboard-shaper-catalog-height`, and only its list scrolls; widgets get a remove button and a handle in their top right corner, shown on hover, on keyboard focus and always on touch screens, and while they show the content of the widget is blurred and faded (`--dashboard-shaper-content-controls-filter` and `-opacity`), so that it does not clash with them; widgets can be dragged to free cells (onto a widget of the same size they swap places, the others never move on their own; on touch screens after holding them for a moment, so that the page still scrolls, or at once from their handle) and resized with the handle in their corner among the `sizes` of their catalog entry; `movable` and `resizable` turn those two off. From the keyboard the handle next to the remove button moves the widget with the arrow keys, resizes it with Shift and the arrow keys and removes it with Delete. While editing, a free band as tall as the tallest size of the catalog stays below the widgets, up to `rows` when set. Every change updates `widgets` and calls `onchange`; `hasEmptySlots` tells whether the rows in use have holes. Narrower than `stackBelow` (640px of the component) the widgets go in one column, in reading order and with their height; while editing there the dashboard shows the real grid in small, each widget as a block with its icon, title and size: tapping a block selects it: then it drags at once and shows its remove button and the handle to resize it; any block also drags after a hold. `preview` draws plain blocks instead of the widgets, for thumbnails, and keeps the grid at every width. The root has `data-editing`, `data-stacked` and `data-preview`; a widget being dragged or resized has `data-dragging` or `data-resizing`.

```ts
import { DashboardShaper } from '@likable-hair/svelte';
```

Category: composed. Source: `src/lib/components/composed/dashboard/DashboardShaper.svelte`.

## Examples

### Basic

A read-only dashboard: each widget is placed by `left`, `top`, `width` and `height` (columns and rows from 1) and drawn by `widgetSnippet`, which picks the content by `name`. Only the rows in use are shown.

```svelte
<script lang="ts">
	import { BarChart, DashboardShaper, type DashboardWidget } from '@likable-hair/svelte';

	type Name = 'revenue' | 'clients' | 'noShow' | 'rating' | 'monthly';

	const widgets: DashboardWidget<unknown, Name>[] = [
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 2 },
		{ id: 2, name: 'clients', left: 3, top: 1, width: 2, height: 1 },
		{ id: 3, name: 'noShow', left: 3, top: 2, width: 1, height: 1 },
		{ id: 4, name: 'rating', left: 4, top: 2, width: 1, height: 1 },
		{ id: 5, name: 'monthly', left: 1, top: 3, width: 4, height: 2 }
	];

	const monthly = {
		labels: ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'],
		datasets: [{ label: 'Revenue', data: [24600, 28900, 31200, 26400, 17800, 29600] }]
	};
</script>

<DashboardShaper {widgets} columns={4} --dashboard-shaper-row-height="110px">
	{#snippet widgetSnippet({ widget })}
		{#if widget.name === 'revenue'}
			<div class="card hero"><small>Revenue today</small><b class="big">€ 1,842</b></div>
		{:else if widget.name === 'clients'}
			<div class="card"><small>Clients today</small><b>18</b></div>
		{:else if widget.name === 'noShow'}
			<div class="card"><small>No-show</small><b class="error">2</b></div>
		{:else if widget.name === 'rating'}
			<div class="card"><small>Rating</small><b>4.9 ★</b></div>
		{:else}
			<div class="card">
				<small>Revenue per month</small>
				<div class="chart">
					<BarChart data={monthly} label="Revenue per month" format={{ style: 'currency', currency: 'EUR', maximumFractionDigits: 0 }} --bar-chart-height="100%" />
				</div>
			</div>
		{/if}
	{/snippet}
</DashboardShaper>

<style>
	.card {
		display: flex;
		height: 100%;
		box-sizing: border-box;
		flex-direction: column;
		justify-content: space-between;
		gap: 8px;
		padding: 14px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
	}

	.hero {
		border: 0;
		background: var(--global-gradient);
		color: var(--global-color-on-primary);
	}

	small {
		color: var(--global-color-text-3);
		font-size: 12px;
	}

	.hero small {
		color: inherit;
		opacity: 0.8;
	}

	b {
		font-family: var(--global-font-family-display);
		font-size: 26px;
		letter-spacing: -0.03em;
	}

	.big {
		font-size: 38px;
	}

	.error {
		color: var(--global-color-error);
	}

	.chart {
		min-height: 0;
		flex: 1;
	}
</style>
```

### Arrange

With `editing` the empty spaces become "Add widget" buttons that open the catalog with the sizes that fit there; widgets are dragged to free cells (onto one of the same size they swap places), resized with the handle in their corner among their `sizes`, removed with the X. From the keyboard, the handle next to the remove button moves with the arrow keys, resizes with Shift and the arrow keys, removes with Delete. `onchange` reports each change; `hasEmptySlots` is used here to save only dashboards without holes.

```svelte
<script lang="ts">
	import {
		mdiAccountGroupOutline,
		mdiCalendarCheckOutline,
		mdiCashMultiple,
		mdiChartBar,
		mdiStarOutline
	} from '@mdi/js';
	import { Button, DashboardShaper, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	type Name = 'revenue' | 'clients' | 'appointments' | 'rating' | 'monthly';

	const catalog: DashboardCatalogItem<Name>[] = [
		{
			name: 'revenue',
			title: 'Revenue',
			description: 'Takings of the day',
			icon: mdiCashMultiple,
			sizes: [
				{ width: 1, height: 1 },
				{ width: 2, height: 1 },
				{ width: 2, height: 2 }
			]
		},
		{
			name: 'clients',
			title: 'Clients',
			description: 'Clients seen today',
			icon: mdiAccountGroupOutline,
			sizes: [
				{ width: 1, height: 1 },
				{ width: 2, height: 1 }
			]
		},
		{
			name: 'appointments',
			title: 'Appointments',
			description: 'Booked for the rest of the day',
			icon: mdiCalendarCheckOutline,
			sizes: [{ width: 1, height: 1 }]
		},
		{
			name: 'rating',
			title: 'Rating',
			description: 'Average of the reviews',
			icon: mdiStarOutline,
			sizes: [{ width: 1, height: 1 }]
		},
		{
			name: 'monthly',
			title: 'Revenue per month',
			description: 'Last twelve months',
			icon: mdiChartBar,
			sizes: [
				{ width: 2, height: 2 },
				{ width: 4, height: 2 }
			]
		}
	];

	let widgets = $state<DashboardWidget<unknown, Name>[]>([
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 1 },
		{ id: 2, name: 'clients', left: 3, top: 1, width: 1, height: 1 },
		{ id: 3, name: 'monthly', left: 1, top: 2, width: 2, height: 2 },
		{ id: 4, name: 'rating', left: 4, top: 2, width: 1, height: 1 }
	]);
	let editing = $state(true);
	let hasEmptySlots = $state(false);
	let last = $state('No changes yet');
</script>

<div class="stack">
	<div class="toolbar">
		<Button variant={editing ? 'primary' : 'secondary'} size="sm" onclick={() => (editing = !editing)}>
			{editing ? 'Done' : 'Edit layout'}
		</Button>
		<Button buttonType="text" size="sm" disabled={hasEmptySlots || !widgets.length}>Save</Button>
		<span class="note">{hasEmptySlots ? 'Fill the holes to save' : 'Ready to save'}</span>
	</div>

	<DashboardShaper
		bind:widgets
		bind:editing
		bind:hasEmptySlots
		{catalog}
		columns={4}
		onchange={({ added, removed, changed }) =>
			(last = `${added.length} added, ${removed.length} removed, ${changed.length} moved or resized`)}
		--dashboard-shaper-row-height="96px"
	>
		{#snippet widgetSnippet({ item })}
			<div class="card"><small>{item?.title}</small><b>—</b></div>
		{/snippet}
	</DashboardShaper>

	<code>{last}</code>
</div>

<style>
	.stack {
		display: flex;
		width: 100%;
		flex-direction: column;
		gap: 12px;
	}

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

	.note {
		color: var(--global-color-text-3);
		font-size: 13px;
	}

	.card {
		display: flex;
		height: 100%;
		box-sizing: border-box;
		flex-direction: column;
		justify-content: space-between;
		padding: 14px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
	}

	small {
		color: var(--global-color-text-3);
		font-size: 12px;
	}

	b {
		font-family: var(--global-font-family-display);
		font-size: 24px;
	}
</style>
```

### Add and remove only

`movable={false}` and `resizable={false}` keep the v4 behaviour: while editing, widgets are only added (with the size chosen in the catalog) and removed. Here the layout has at most `rows={2}`, so the free band below the widgets stops there.

```svelte
<script lang="ts">
	import { mdiAccountGroupOutline, mdiCashMultiple, mdiStarOutline } from '@mdi/js';
	import { DashboardShaper, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', icon: mdiCashMultiple, sizes: [{ width: 2, height: 1 }] },
		{ name: 'clients', title: 'Clients', icon: mdiAccountGroupOutline, sizes: [{ width: 1, height: 1 }] },
		{ name: 'rating', title: 'Rating', icon: mdiStarOutline, sizes: [{ width: 1, height: 1 }] }
	];

	let widgets = $state<DashboardWidget[]>([
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 1 },
		{ id: 2, name: 'clients', left: 3, top: 1, width: 1, height: 1 }
	]);
</script>

<DashboardShaper
	bind:widgets
	{catalog}
	columns={4}
	rows={2}
	editing
	movable={false}
	resizable={false}
	--dashboard-shaper-row-height="88px"
/>
```

### Catalog with groups

With two or more `category` values the catalog shows a filter chip for each, with the number of widgets in it: no chip selected shows them all, several show their union. A `unique` widget disappears from the catalog while it is on the dashboard (here "Revenue"), for backends that keep one widget per type. The default content of a widget is its title.

```svelte
<script lang="ts">
	import {
		mdiAccountGroupOutline,
		mdiCashMultiple,
		mdiChartBar,
		mdiChartDonut,
		mdiFormatListBulleted,
		mdiStarOutline
	} from '@mdi/js';
	import { DashboardShaper, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', icon: mdiCashMultiple, category: 'Numbers', unique: true, sizes: [{ width: 2, height: 1 }] },
		{ name: 'clients', title: 'Clients', icon: mdiAccountGroupOutline, category: 'Numbers', sizes: [{ width: 1, height: 1 }] },
		{ name: 'rating', title: 'Rating', icon: mdiStarOutline, category: 'Numbers', sizes: [{ width: 1, height: 1 }] },
		{ name: 'monthly', title: 'Revenue per month', icon: mdiChartBar, category: 'Charts', sizes: [{ width: 2, height: 2 }] },
		{ name: 'services', title: 'Services', icon: mdiChartDonut, category: 'Charts', sizes: [{ width: 2, height: 2 }] },
		{ name: 'latest', title: 'Latest bookings', icon: mdiFormatListBulleted, category: 'Lists', sizes: [{ width: 2, height: 2 }] }
	];

	let widgets = $state<DashboardWidget[]>([{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 1 }]);
</script>

<DashboardShaper bind:widgets {catalog} columns={4} editing --dashboard-shaper-row-height="88px" />
```

### Thumbnails

`preview` draws a plain block for each widget: with a small row height it becomes a thumbnail of a saved layout, for example in the list of the dashboards of a user.

```svelte
<script lang="ts">
	import { DashboardShaper, type DashboardWidget } from '@likable-hair/svelte';

	const layouts: { name: string; widgets: DashboardWidget[] }[] = [
		{
			name: 'Front desk',
			widgets: [
				{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 2 },
				{ id: 2, name: 'clients', left: 3, top: 1, width: 2, height: 1 },
				{ id: 3, name: 'rating', left: 3, top: 2, width: 1, height: 1 },
				{ id: 4, name: 'noShow', left: 4, top: 2, width: 1, height: 1 },
				{ id: 5, name: 'monthly', left: 1, top: 3, width: 4, height: 2 }
			]
		},
		{
			name: 'Owner',
			widgets: [
				{ id: 1, name: 'monthly', left: 1, top: 1, width: 4, height: 2 },
				{ id: 2, name: 'services', left: 1, top: 3, width: 2, height: 2 },
				{ id: 3, name: 'latest', left: 3, top: 3, width: 2, height: 2 }
			]
		}
	];
</script>

<div class="list">
	{#each layouts as layout (layout.name)}
		<figure>
			<DashboardShaper widgets={layout.widgets} columns={4} preview --dashboard-shaper-row-height="22px" --dashboard-shaper-gap="4px" />
			<figcaption>{layout.name}</figcaption>
		</figure>
	{/each}
</div>

<style>
	.list {
		display: flex;
		flex-wrap: wrap;
		gap: 16px;
	}

	figure {
		width: 180px;
		margin: 0;
		padding: 10px;
		border: 1px solid var(--global-color-border);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
	}

	figcaption {
		margin-top: 8px;
		color: var(--global-color-text-2);
		font-size: 13px;
	}
</style>
```

### Narrow

Narrower than `stackBelow` (640px of the component by default) the widgets go in one column to be read, in reading order and each as tall as its rows (left). While editing (right) the dashboard shows the real grid in small: each widget is a block with its icon, title and size, the empty spaces add widgets there; a tapped block is selected and then drags at once, resizes from its corner or is removed with its X, and any block drags after a hold.

```svelte
<script lang="ts">
	import { mdiAccountGroupOutline, mdiCashMultiple, mdiChartBar, mdiStarOutline } from '@mdi/js';
	import { DashboardShaper, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', icon: mdiCashMultiple, sizes: [{ width: 2, height: 1 }, { width: 2, height: 2 }] },
		{ name: 'clients', title: 'Clients', icon: mdiAccountGroupOutline, sizes: [{ width: 1, height: 1 }, { width: 2, height: 1 }] },
		{ name: 'rating', title: 'Rating', icon: mdiStarOutline, sizes: [{ width: 1, height: 1 }] },
		{ name: 'monthly', title: 'Revenue per month', icon: mdiChartBar, sizes: [{ width: 4, height: 2 }] }
	];

	let widgets = $state<DashboardWidget[]>([
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 2 },
		{ id: 2, name: 'clients', left: 3, top: 1, width: 2, height: 1 },
		{ id: 3, name: 'rating', left: 3, top: 2, width: 1, height: 1 },
		{ id: 4, name: 'monthly', left: 1, top: 3, width: 4, height: 2 }
	]);
</script>

<div class="phones">
	<div class="phone">
		<DashboardShaper {widgets} {catalog} columns={4} --dashboard-shaper-row-height="64px" />
	</div>
	<div class="phone">
		<DashboardShaper bind:widgets {catalog} columns={4} editing />
	</div>
</div>

<style>
	.phones {
		display: flex;
		flex-wrap: wrap;
		align-items: flex-start;
		gap: 24px;
	}

	.phone {
		width: 340px;
		max-width: 100%;
	}
</style>
```

### Custom parts

`widgetSnippet` draws each widget and gets its catalog entry and `editing` (while editing, the content is inert: the dashboard handles the pointer and the keyboard); `slotSnippet` replaces the "Add widget" buttons of the empty spaces and gets their size and `add`, which opens the catalog for that space.

```svelte
<script lang="ts">
	import { mdiCashMultiple, mdiPlusCircleOutline, mdiStarOutline } from '@mdi/js';
	import { DashboardShaper, Icon, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', icon: mdiCashMultiple, sizes: [{ width: 1, height: 1 }, { width: 2, height: 1 }] },
		{ name: 'rating', title: 'Rating', icon: mdiStarOutline, sizes: [{ width: 1, height: 1 }] }
	];

	let widgets = $state<DashboardWidget[]>([
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 1 },
		{ id: 2, name: 'rating', left: 1, top: 2, width: 1, height: 1 }
	]);
</script>

<DashboardShaper bind:widgets {catalog} columns={3} rows={2} editing movable={false} --dashboard-shaper-row-height="96px">
	{#snippet widgetSnippet({ item, widget, editing })}
		<div class="card">
			<span class="title">{item?.title}</span>
			<span class="size">{editing ? `${widget.width} × ${widget.height}` : '€ 1,842'}</span>
		</div>
	{/snippet}
	{#snippet slotSnippet({ width, height, add })}
		<button type="button" class="slot" onclick={add}>
			<Icon path={mdiPlusCircleOutline} />
			{width} × {height} free
		</button>
	{/snippet}
</DashboardShaper>

<style>
	.card {
		display: flex;
		height: 100%;
		box-sizing: border-box;
		flex-direction: column;
		align-items: flex-start;
		gap: 4px;
		padding: 12px;
		border: 1px solid var(--global-color-border);
		border-left: 4px solid var(--global-color-accent);
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-solid);
	}

	.title {
		font-weight: 600;
	}

	.size {
		color: var(--global-color-text-3);
		font-size: 12px;
	}

	.slot {
		display: flex;
		width: 100%;
		height: 100%;
		align-items: center;
		justify-content: center;
		gap: 6px;
		border: 0;
		border-radius: var(--global-radius-lg);
		background: var(--global-color-surface-2);
		color: var(--global-color-text-2);
		font: inherit;
		cursor: pointer;
	}
</style>
```

### Large catalog

18 widgets in 4 categories: the catalog gets a search field, which matches title and description and takes the focus when the catalog opens from the keyboard or the mouse, and filter chips that can be combined. The dialog keeps the height it opens with, so the list scrolls under the search and the chips, and the widgets fade and slide as the filters change.

```svelte
<script lang="ts">
	import {
		mdiAccountClockOutline,
		mdiAccountGroupOutline,
		mdiAccountPlusOutline,
		mdiAccountStarOutline,
		mdiCalendarCheckOutline,
		mdiCalendarClockOutline,
		mdiCalendarRemoveOutline,
		mdiCashMultiple,
		mdiChartBar,
		mdiChartDonut,
		mdiChartLine,
		mdiFormatListBulleted,
		mdiPackageVariantClosed,
		mdiReceiptTextOutline,
		mdiStarOutline,
		mdiTagOutline,
		mdiTruckDeliveryOutline,
		mdiWarehouse
	} from '@mdi/js';
	import { DashboardShaper, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const small = [{ width: 1, height: 1 }, { width: 2, height: 1 }];
	const chart = [{ width: 2, height: 2 }, { width: 3, height: 2 }];

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', description: 'Total of the invoices in the period', icon: mdiCashMultiple, category: 'Sales', sizes: small },
		{ name: 'invoices', title: 'Invoices', description: 'Issued, paid and overdue', icon: mdiReceiptTextOutline, category: 'Sales', sizes: small },
		{ name: 'monthly', title: 'Revenue per month', description: 'Bars of the last twelve months', icon: mdiChartBar, category: 'Sales', sizes: chart },
		{ name: 'trend', title: 'Revenue trend', description: 'Line against the previous year', icon: mdiChartLine, category: 'Sales', sizes: chart },
		{ name: 'discounts', title: 'Discounts', description: 'Coupons and promotions used', icon: mdiTagOutline, category: 'Sales', sizes: small },
		{ name: 'clients', title: 'Clients', description: 'Active clients in the period', icon: mdiAccountGroupOutline, category: 'Clients', sizes: small },
		{ name: 'new-clients', title: 'New clients', description: 'First booking in the period', icon: mdiAccountPlusOutline, category: 'Clients', sizes: small },
		{ name: 'loyal', title: 'Loyal clients', description: 'Five visits or more', icon: mdiAccountStarOutline, category: 'Clients', sizes: small },
		{ name: 'rating', title: 'Rating', description: 'Average of the reviews', icon: mdiStarOutline, category: 'Clients', sizes: small },
		{ name: 'waiting', title: 'Waiting time', description: 'Minutes between arrival and service', icon: mdiAccountClockOutline, category: 'Clients', sizes: small },
		{ name: 'bookings', title: 'Bookings', description: 'Appointments of today', icon: mdiCalendarCheckOutline, category: 'Agenda', sizes: small },
		{ name: 'upcoming', title: 'Upcoming bookings', description: 'List of the next appointments', icon: mdiFormatListBulleted, category: 'Agenda', sizes: chart },
		{ name: 'cancelled', title: 'Cancellations', description: 'Cancelled and missed appointments', icon: mdiCalendarRemoveOutline, category: 'Agenda', sizes: small },
		{ name: 'occupancy', title: 'Occupancy', description: 'Share of the booked hours', icon: mdiCalendarClockOutline, category: 'Agenda', sizes: small },
		{ name: 'services', title: 'Services', description: 'Share of each service', icon: mdiChartDonut, category: 'Agenda', sizes: chart },
		{ name: 'stock', title: 'Stock', description: 'Pieces in the warehouse', icon: mdiWarehouse, category: 'Warehouse', sizes: small },
		{ name: 'low-stock', title: 'Low stock', description: 'Products under the minimum', icon: mdiPackageVariantClosed, category: 'Warehouse', sizes: chart },
		{ name: 'deliveries', title: 'Deliveries', description: 'Orders to the suppliers on the way', icon: mdiTruckDeliveryOutline, category: 'Warehouse', sizes: small }
	];

	let widgets = $state<DashboardWidget[]>([
		{ id: 1, name: 'revenue', left: 1, top: 1, width: 2, height: 1 },
		{ id: 2, name: 'clients', left: 3, top: 1, width: 1, height: 1 }
	]);
</script>

<DashboardShaper bind:widgets {catalog} columns={4} editing --dashboard-shaper-row-height="88px" />
```

### Custom catalog entries

`catalogItemSnippet` redraws each entry of the catalog and gets `sizeButtons`, the default size buttons with their shapes, so the app changes the layout without losing them. `DashboardWidgetShape` draws a single shape where the app needs one.

```svelte
<script lang="ts">
	import { mdiCashMultiple, mdiChartBar, mdiStarOutline } from '@mdi/js';
	import { DashboardShaper, DashboardWidgetShape, Icon, type DashboardCatalogItem, type DashboardWidget } from '@likable-hair/svelte';

	const catalog: DashboardCatalogItem[] = [
		{ name: 'revenue', title: 'Revenue', description: 'Total of the invoices', icon: mdiCashMultiple, sizes: [{ width: 1, height: 1 }, { width: 2, height: 1 }] },
		{ name: 'rating', title: 'Rating', description: 'Average of the reviews', icon: mdiStarOutline, sizes: [{ width: 1, height: 1 }] },
		{ name: 'monthly', title: 'Revenue per month', description: 'Bars of the last twelve months', icon: mdiChartBar, sizes: [{ width: 2, height: 2 }] }
	];

	let widgets = $state<DashboardWidget[]>([{ id: 1, name: 'rating', left: 1, top: 1, width: 1, height: 1 }]);
</script>

<DashboardShaper bind:widgets {catalog} columns={3} editing --dashboard-shaper-row-height="88px">
	{#snippet catalogItemSnippet({ item, sizes, sizeButtons })}
		<div class="entry">
			{#if item.icon}<Icon path={item.icon} />{/if}
			<strong>{item.title}</strong>
			<span class="largest">
				<DashboardWidgetShape width={sizes.at(-1)!.width} height={sizes.at(-1)!.height} />
				up to {sizes.at(-1)!.width} × {sizes.at(-1)!.height}
			</span>
		</div>
		{@render sizeButtons()}
	{/snippet}
</DashboardShaper>

<style>
	.entry {
		display: flex;
		grid-column: 1 / -1;
		align-items: center;
		gap: 8px;
		color: var(--global-color-text);
	}

	.largest {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		margin-inline-start: auto;
		color: var(--global-color-text-3);
		font-size: 12px;
	}
</style>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `widgets` (bindable) | `DashboardWidget<Data, Name>[]` |  | The widgets on the dashboard, each with its `name`, its place (`left`, `top`, from 1) and its size (`width`, `height`). Updated by every change the user makes. |
| `catalog` | `DashboardCatalogItem<Name>[]` | `[]` | Types of widget the user can add, with the sizes each comes in. Also gives the title of each widget and the sizes it can be resized to. |
| `columns` | `number` | `6` | Number of columns. |
| `rows` | `number` |  | Maximum number of rows. Without it the dashboard grows downwards as needed. |
| `editing` (bindable) | `boolean` |  | Lets the user arrange the dashboard: add, remove, move and resize widgets. |
| `movable` | `boolean` | `true` | While editing, widgets can be moved. Turn it off to only add and remove them, as in v4. |
| `resizable` | `boolean` | `true` | While editing, widgets with more than one size in `catalog` can be resized. |
| `preview` | `boolean` | `false` | Draws a plain block for each widget, for a small thumbnail of the layout. |
| `hasEmptySlots` (bindable) | `boolean` |  | Whether some cell is empty in the rows in use, for example to save only complete dashboards. Read it with `bind:hasEmptySlots`. |
| `searchable` | `boolean` |  | Shows the search field at the top of the catalog. Defaults to on when the catalog offers 6 widgets or more. |
| `stackBelow` | `number \| false` | `640` | Width of the component, in pixels, under which the widgets go in one column. `false` keeps the grid at every width. |
| `locale` | `string` |  | BCP 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`. |
| `labels` | `{ add?: string; catalog?: string; all?: string; noFit?: string; search?: string; categories?: string; noResults?: string; clearFilters?: string; results?: string; result?: string; size?: string; addSize?: string; widget?: string; move?: string; moveHint?: string; resizeHint?: string; removeHint?: string; resize?: string; remove?: string; schemaHint?: string; close?: string; moved?: string; resized?: string; removed?: string; added?: string; }` |  | Texts to change, on top of those of `locale`. `{title}`, `{width}`, `{height}`, `{row}` and `{column}` are replaced by the title of a widget, its size and its place, `{count}` by the number of widgets found. `all` is no longer shown. |
| `class` | `{ container?: string; widget?: string; slot?: string; catalog?: string; }` | `{}` | Extra classes for each part: `container` the grid, `widget` the box of each widget, `slot` the empty spaces, `catalog` the dialog or sheet of the catalog. |

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

## Snippets

| Name | Parameters | Description |
| --- | --- | --- |
| `widgetSnippet` | `{ widget: DashboardWidget<Data, Name>; item: DashboardCatalogItem<Name> \| undefined; editing: boolean; controls: boolean; remove: () => void; }` | Content of a widget. `item` is its entry in `catalog`, `editing` is true while the dashboard is being arranged (the content is then inert), `controls` is true while the remove button and the handle show on the widget (hover, keyboard focus, drag, touch screens), for an effect of the app on top of the default blur, and `remove` takes the widget away. Defaults to the title of the widget. |
| `slotSnippet` | `{ width: number; height: number; add: () => void }` | Replaces the "Add widget" button of an empty space, `width` columns by `height` rows; `add` opens the catalog for that space. |
| `catalogHeaderSnippet` |  | Replaces the title of the catalog. |
| `catalogItemSnippet` | `{ item: DashboardCatalogItem<Name>; sizes: DashboardWidgetSize[]; add: (size: DashboardWidgetSize) => void; sizeButtons: Snippet; }` | Content of a widget type in the catalog, instead of its icon, title, description and size buttons; `sizes` are the ones that fit, `add(size)` adds the widget and `sizeButtons` draws the default size buttons, with their shapes. `DashboardWidgetShape` draws a single shape. |
| `catalogBodySnippet` | `{ entries: DashboardCatalogEntry<Name>[]; add: (item: DashboardCatalogItem<Name>, size: DashboardWidgetSize) => void; close: () => void; }` | Whole body of the catalog, instead of the search field, the chips and the list. `entries` are the widgets that fit the chosen space, each with its sizes that fit, `add(item, size)` adds a widget and closes the catalog, `close` closes it. The dialog or sheet and its title stay. |

## Events

| Name | Type | Description |
| --- | --- | --- |
| `onchange` | `(event: DashboardChange<Data, Name>) => void` | Called after every change made by the user, with all the widgets and the ones added, removed, moved or resized. |

## Types

Exported by the package: `import type { DashboardWidget, DashboardCatalogItem, DashboardWidgetSize, DashboardCatalogEntry, DashboardChange } from '@likable-hair/svelte';`

### DashboardWidget

A widget placed on a `DashboardShaper`: its type, where it starts and how many cells it takes. The same shape as v4, so layouts saved by the backends keep working.

`interface DashboardWidget<Data = unknown, Name extends string = string>`

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string \| number` | Unique id of the widget. Widgets added by the user get a random string id; the backend can replace it with its own when it saves. |
| `name` (required) | `Name` | Type of the widget: the `name` of its entry in `catalog`. |
| `width` (required) | `number` | Width in columns. |
| `height` (required) | `number` | Height in rows. |
| `left` (required) | `number` | First column, counted from 1. |
| `top` (required) | `number` | First row, counted from 1. |
| `data` | `Data` | Anything the app needs to draw the widget, such as its settings or its title. The dashboard only passes it to `widgetSnippet`. |

### DashboardCatalogItem

A type of widget the user can add to a `DashboardShaper`, and the sizes it comes in.

`interface DashboardCatalogItem<Name extends string = string>`

| Name | Type | Description |
| --- | --- | --- |
| `name` (required) | `Name` | Type of the widget, saved in the `name` of every widget of this type. |
| `title` (required) | `string` | Name shown in the catalog and to screen readers. |
| `description` | `string` | Line under the title in the catalog. |
| `icon` | `string` | SVG path of the icon shown in the catalog, for example one from `@mdi/js`. |
| `sizes` (required) | `DashboardWidgetSize[]` | Sizes the widget comes in: the catalog offers the ones that fit the chosen space, and resizing moves between them. One size means the widget cannot be resized. |
| `category` | `string` | Group of the widget in the catalog: with two or more groups the catalog shows a filter chip for each; no chip selected shows every group, several show all of theirs. |
| `unique` | `boolean` | The widget can be on the dashboard only once: the catalog hides it while it is there. |

### DashboardWidgetSize

A size a widget can take, in columns and rows.

`interface DashboardWidgetSize`

| Name | Type | Description |
| --- | --- | --- |
| `width` (required) | `number` | Width in columns. |
| `height` (required) | `number` | Height in rows. |

### DashboardCatalogEntry

A widget type as the catalog of a `DashboardShaper` offers it for the chosen space: its entry and the sizes that fit there.

`interface DashboardCatalogEntry<Name extends string = string>`

| Name | Type | Description |
| --- | --- | --- |
| `item` (required) | `DashboardCatalogItem<Name>` | The entry of `catalog`. |
| `sizes` (required) | `DashboardWidgetSize[]` | The sizes of the entry whose cells are free at the chosen space. |

### DashboardChange

What changed on a `DashboardShaper`, passed to its `onchange`.

`interface DashboardChange<Data = unknown, Name extends string = string>`

| Name | Type | Description |
| --- | --- | --- |
| `widgets` (required) | `DashboardWidget<Data, Name>[]` | All the widgets after the change. |
| `added` (required) | `DashboardWidget<Data, Name>[]` | The widget added from the catalog, if any. |
| `removed` (required) | `DashboardWidget<Data, Name>[]` | The widget removed, if any. |
| `changed` (required) | `DashboardWidget<Data, Name>[]` | Widgets moved or resized: one, or two when two widgets swapped places. |

## CSS variables

For a single instance, pass them as style props: `<DashboardShaper --dashboard-shaper-focus-ring-color="tomato">`. The `--dashboard-shaper-default-*` defaults apply to the whole app: override them in `:root` or in a theme.

| Per-instance variable | Default |
| --- | --- |
| `--dashboard-shaper-row-height` | `--dashboard-shaper-default-row-height`: `200px` |
| `--dashboard-shaper-gap` | `--dashboard-shaper-default-gap`: `10px` |
| `--dashboard-shaper-widget-border-radius` | `--dashboard-shaper-default-widget-border-radius`: `var(--global-radius-lg)` |
| `--dashboard-shaper-focus-ring-width` | `--dashboard-shaper-default-focus-ring-width`: `var(--global-focus-ring-width)` |
| `--dashboard-shaper-focus-ring-color` | `--dashboard-shaper-default-focus-ring-color`: `var(--global-focus-ring-color)` |
| `--dashboard-shaper-focus-ring-offset` | `--dashboard-shaper-default-focus-ring-offset`: `var(--global-focus-ring-offset)` |
| `--dashboard-shaper-schema-row-height` | `--dashboard-shaper-default-schema-row-height`: `56px` |
| `--dashboard-shaper-schema-gap` | `--dashboard-shaper-default-schema-gap`: `6px` |
| `--dashboard-shaper-min-height` | `--dashboard-shaper-default-min-height`: `0` |
| `--dashboard-shaper-content-controls-opacity` | `--dashboard-shaper-default-content-controls-opacity`: `0.55` |
| `--dashboard-shaper-content-controls-filter` | `--dashboard-shaper-default-content-controls-filter`: `blur(3px)` |
| `--dashboard-shaper-name-color` | `--dashboard-shaper-default-name-color`: `var(--global-color-text-3)` |
| `--dashboard-shaper-name-font-size` | `--dashboard-shaper-default-name-font-size`: `13px` |
| `--dashboard-shaper-preview-border-radius` | `--dashboard-shaper-default-preview-border-radius`: `var(--global-radius-sm)` |
| `--dashboard-shaper-preview-background` | `--dashboard-shaper-default-preview-background`: `color-mix(in srgb, var(--global-color-primary) 45%, transparent)` |
| `--dashboard-shaper-hover-outline-color` | `--dashboard-shaper-default-hover-outline-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-hover-ring-color` | `--dashboard-shaper-default-hover-ring-color`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-dragging-opacity` | `--dashboard-shaper-default-dragging-opacity`: `0.88` |
| `--dashboard-shaper-dragging-box-shadow` | `--dashboard-shaper-default-dragging-box-shadow`: `var(--global-shadow-lg)` |
| `--dashboard-shaper-control-icon-size` | `--dashboard-shaper-default-control-icon-size`: `16px` |
| `--dashboard-shaper-control-size` | `--dashboard-shaper-default-control-size`: `26px` |
| `--dashboard-shaper-control-border-radius` | `--dashboard-shaper-default-control-border-radius`: `var(--global-radius-xs)` |
| `--dashboard-shaper-grip-background` | `--dashboard-shaper-default-grip-background`: `var(--global-color-surface-pop)` |
| `--dashboard-shaper-grip-color` | `--dashboard-shaper-default-grip-color`: `var(--global-color-text-2)` |
| `--dashboard-shaper-remove-background` | `--dashboard-shaper-default-remove-background`: `var(--global-color-error-soft)` |
| `--dashboard-shaper-remove-color` | `--dashboard-shaper-default-remove-color`: `var(--global-color-error)` |
| `--dashboard-shaper-resize-size` | `--dashboard-shaper-default-resize-size`: `20px` |
| `--dashboard-shaper-resize-color` | `--dashboard-shaper-default-resize-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-slot-border-width` | `--dashboard-shaper-default-slot-border-width`: `1.5px` |
| `--dashboard-shaper-slot-border-color` | `--dashboard-shaper-default-slot-border-color`: `var(--global-color-border-strong)` |
| `--dashboard-shaper-slot-background` | `--dashboard-shaper-default-slot-background`: `transparent` |
| `--dashboard-shaper-slot-color` | `--dashboard-shaper-default-slot-color`: `var(--global-color-text-3)` |
| `--dashboard-shaper-slot-font-size` | `--dashboard-shaper-default-slot-font-size`: `13px` |
| `--dashboard-shaper-slot-font-weight` | `--dashboard-shaper-default-slot-font-weight`: `500` |
| `--dashboard-shaper-slot-hover-border-color` | `--dashboard-shaper-default-slot-hover-border-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-slot-hover-background` | `--dashboard-shaper-default-slot-hover-background`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-slot-hover-color` | `--dashboard-shaper-default-slot-hover-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-target-border-color` | `--dashboard-shaper-default-target-border-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-target-background` | `--dashboard-shaper-default-target-background`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-invalid-target-border-color` | `--dashboard-shaper-default-invalid-target-border-color`: `var(--global-color-error)` |
| `--dashboard-shaper-invalid-target-background` | `--dashboard-shaper-default-invalid-target-background`: `var(--global-color-error-soft)` |
| `--dashboard-shaper-block-border-color` | `--dashboard-shaper-default-block-border-color`: `var(--global-color-border-strong)` |
| `--dashboard-shaper-block-background` | `--dashboard-shaper-default-block-background`: `var(--global-color-surface-solid)` |
| `--dashboard-shaper-block-color` | `--dashboard-shaper-default-block-color`: `var(--global-color-text)` |
| `--dashboard-shaper-block-selected-border-color` | `--dashboard-shaper-default-block-selected-border-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-block-selected-background` | `--dashboard-shaper-default-block-selected-background`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-block-icon-color` | `--dashboard-shaper-default-block-icon-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-block-font-size` | `--dashboard-shaper-default-block-font-size`: `12.5px` |
| `--dashboard-shaper-block-size-color` | `--dashboard-shaper-default-block-size-color`: `var(--global-color-text-3)` |
| `--dashboard-shaper-hint-color` | `--dashboard-shaper-default-hint-color`: `var(--global-color-text-3)` |
| `--dashboard-shaper-block-remove-background` | `--dashboard-shaper-default-block-remove-background`: `var(--global-color-error)` |
| `--dashboard-shaper-block-remove-color` | `--dashboard-shaper-default-block-remove-color`: `var(--global-color-on-error)` |
| `--dashboard-shaper-catalog-width` | `--dashboard-shaper-default-catalog-width`: `640px` |
| `--dashboard-shaper-catalog-height` | `--dashboard-shaper-default-catalog-height`: `min(40rem, 85dvh)` |
| `--dashboard-shaper-catalog-filters-gap` | `--dashboard-shaper-default-catalog-filters-gap`: `10px` |
| `--dashboard-shaper-catalog-chips-gap` | `--dashboard-shaper-default-catalog-chips-gap`: `6px` |
| `--dashboard-shaper-item-gap` | `--dashboard-shaper-default-item-gap`: `14px` |
| `--dashboard-shaper-item-padding` | `--dashboard-shaper-default-item-padding`: `14px` |
| `--dashboard-shaper-item-border-color` | `--dashboard-shaper-default-item-border-color`: `var(--global-color-border)` |
| `--dashboard-shaper-item-border-radius` | `--dashboard-shaper-default-item-border-radius`: `var(--global-radius-lg)` |
| `--dashboard-shaper-item-background` | `--dashboard-shaper-default-item-background`: `var(--global-color-surface)` |
| `--dashboard-shaper-item-enter-scale` | `--dashboard-shaper-default-item-enter-scale`: `0.96` |
| `--dashboard-shaper-item-icon-size` | `--dashboard-shaper-default-item-icon-size`: `40px` |
| `--dashboard-shaper-item-icon-background` | `--dashboard-shaper-default-item-icon-background`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-item-icon-color` | `--dashboard-shaper-default-item-icon-color`: `var(--global-color-primary)` |
| `--dashboard-shaper-item-title-color` | `--dashboard-shaper-default-item-title-color`: `var(--global-color-text)` |
| `--dashboard-shaper-item-title-font-size` | `--dashboard-shaper-default-item-title-font-size`: `14px` |
| `--dashboard-shaper-item-title-font-weight` | `--dashboard-shaper-default-item-title-font-weight`: `600` |
| `--dashboard-shaper-item-description-color` | `--dashboard-shaper-default-item-description-color`: `var(--global-color-text-3)` |
| `--dashboard-shaper-item-description-font-size` | `--dashboard-shaper-default-item-description-font-size`: `12.5px` |
| `--dashboard-shaper-size-border-radius` | `--dashboard-shaper-default-size-border-radius`: `var(--global-radius-sm)` |
| `--dashboard-shaper-size-background` | `--dashboard-shaper-default-size-background`: `var(--global-color-surface-2)` |
| `--dashboard-shaper-size-color` | `--dashboard-shaper-default-size-color`: `var(--global-color-text-2)` |
| `--dashboard-shaper-size-font-size` | `--dashboard-shaper-default-size-font-size`: `12px` |
| `--dashboard-shaper-size-hover-background` | `--dashboard-shaper-default-size-hover-background`: `var(--global-color-primary-soft)` |
| `--dashboard-shaper-size-hover-color` | `--dashboard-shaper-default-size-hover-color`: `var(--global-color-primary)` |
