# List page

A toolbar with search and filters over a list and detail split.

Section: Blocks / Layouts
Page: https://ui.heyramzi.com/components/list-page
Import path: `@heyramzi/ui/components/list-page`

## Import

```ts
import { DetailHeader, DetailPanel, DetailRow, DetailStack, EmptyState, FilterItem, FilterPopover, filterSectionClass, ListPageShell, MasterDetail, RailBody, RailHead, RailRow, ToolbarSearch, } from "@heyramzi/ui/components/list-page";
import { SegmentedFilter } from "@heyramzi/ui/components/segmented";
import { Button } from "@heyramzi/ui/shadcn/button";
```

## Usage

```svelte
<ListPageShell>
  {#snippet content()}
    <MasterDetail>
      {#snippet rail()}
        <RailBody>
          {#each quotes as quote (quote.id)}
            <RailRow title={quote.client} onclick={() => (selectedId = quote.id)} />
          {/each}
        </RailBody>
      {/snippet}
      {#snippet detail()}
        <DetailHeader title={selected.client} />
      {/snippet}
    </MasterDetail>
  {/snippet}
</ListPageShell>
```

## Demo

```svelte
<script lang="ts">
	import {
		DetailHeader,
		DetailPanel,
		DetailRow,
		DetailStack,
		EmptyState,
		FilterItem,
		FilterPopover,
		filterSectionClass,
		ListPageShell,
		MasterDetail,
		RailBody,
		RailHead,
		RailRow,
		ToolbarSearch,
	} from "@heyramzi/ui/components/list-page";
	import { SegmentedFilter } from "@heyramzi/ui/components/segmented";
	import { Button } from "@heyramzi/ui/shadcn/button";
	import { Funnel, MagnifyingGlass, Plus, SlidersHorizontal, Tray } from "phosphor-svelte";

	type Quote = {
		id: string;
		client: string;
		title: string;
		status: "draft" | "sent" | "won";
		total: string;
		owner: string;
		lines: [string, string][];
	};

	const quotes: Quote[] = [
		{
			id: "q-2041",
			client: "Brightwell Legal",
			title: "Contract workflow",
			status: "sent",
			total: "€9,000",
			owner: "Ramzi",
			lines: [
				["Audit and scoping", "€1,800"],
				["Build the first module", "€6,000"],
				["Handover", "€1,200"],
			],
		},
		{
			id: "q-2040",
			client: "Acme Freight",
			title: "Onboarding automation",
			status: "draft",
			total: "€4,200",
			owner: "Camille",
			lines: [
				["Intake form", "€1,400"],
				["Welcome sequence", "€2,800"],
			],
		},
		{
			id: "q-2037",
			client: "Atelier Morel",
			title: "Studio bookings",
			status: "won",
			total: "€12,600",
			owner: "Ramzi",
			lines: [
				["Calendar sync", "€3,600"],
				["Deposit payments", "€5,400"],
				["Reminders", "€3,600"],
			],
		},
		{
			id: "q-2033",
			client: "Harbor Dental",
			title: "Recall campaign",
			status: "sent",
			total: "€2,950",
			owner: "Camille",
			lines: [
				["Patient list cleanup", "€950"],
				["Recall emails", "€2,000"],
			],
		},
	];

	let query = $state("");
	let status = $state("all");
	let owner = $state("all");
	let order = $state<"newest" | "total">("newest");
	let selectedId = $state(quotes[0].id);

	const amount = (q: Quote) => Number(q.total.replace(/\D/g, ""));
	let visible = $derived(
		quotes
			.filter(
				(q) =>
					(status === "all" || q.status === status) &&
					(owner === "all" || q.owner === owner) &&
					`${q.client} ${q.title}`.toLowerCase().includes(query.trim().toLowerCase()),
			)
			.sort((a, b) => (order === "total" ? amount(b) - amount(a) : 0)),
	);
	let selected = $derived(visible.find((q) => q.id === selectedId) ?? visible[0]);
</script>

<div class="flex w-full max-w-4xl flex-col gap-4">
	<div class="w-full overflow-hidden rounded-xl border border-border bg-background">
		<ListPageShell
			maxWidth={false}
			isEmpty={visible.length === 0}
			emptyState={{
				title: "No quote matches",
				description: "Try another name or clear the filter.",
				actionLabel: "Clear filter",
				onAction: () => {
					query = "";
					status = "all";
					owner = "all";
				},
			}}
		>
			{#snippet search()}
				<ToolbarSearch bind:value={query} placeholder="Search quotes" class="w-56 max-w-full" />
			{/snippet}
			{#snippet filters()}
				<FilterPopover
					label="Filter"
					icon={Funnel}
					count={owner === "all" ? 0 : 1}
					onClear={() => (owner = "all")}
					clearLabel="Clear all"
				>
					<p class={filterSectionClass()}>Owner</p>
					{#each ["all", "Ramzi", "Camille"] as value (value)}
						<FilterItem variant="radio" checked={owner === value} onclick={() => (owner = value)}>
							{value === "all" ? "Anyone" : value}
						</FilterItem>
					{/each}
				</FilterPopover>
			{/snippet}
			{#snippet tabs()}
				<SegmentedFilter
					options={[
						{ value: "all", label: "All" },
						{ value: "draft", label: "Draft" },
						{ value: "sent", label: "Sent" },
						{ value: "won", label: "Won" },
					]}
					bind:value={status}
					ariaLabel="Status"
					block={false}
				/>
			{/snippet}
			{#snippet rightActions()}
				<FilterPopover label="Display" icon={SlidersHorizontal} align="end">
					<p class={filterSectionClass()}>Order</p>
					{#each ["newest", "total"] as const as value (value)}
						<FilterItem variant="radio" checked={order === value} onclick={() => (order = value)}>
							{value === "newest" ? "Newest first" : "Largest total"}
						</FilterItem>
					{/each}
				</FilterPopover>
				<Button
					size="sm"
					class="group-data-[fold=3]/toolbar:aspect-square group-data-[fold=3]/toolbar:px-0"
				>
					<Plus aria-hidden="true" class="size-4" weight="bold" />
					<span class="group-data-[fold=3]/toolbar:sr-only">New quote</span>
				</Button>
			{/snippet}
			{#snippet content()}
				<div class="h-[26rem]">
					<MasterDetail pad={false} railWidth="minmax(220px, 280px)">
						{#snippet rail()}
							<div
								class="flex h-full flex-col overflow-hidden rounded-xl border border-border bg-card"
							>
								<RailHead label="{visible.length} quotes" />
								<RailBody>
									{#each visible as q (q.id)}
										<RailRow
											title={q.client}
											selected={q.id === selected?.id}
											onclick={() => (selectedId = q.id)}
											preview={q.title}
											meta={[q.status, q.total]}
										/>
									{/each}
								</RailBody>
							</div>
						{/snippet}
						{#snippet detail()}
							{#if selected}
								<DetailStack>
									<DetailHeader
										title={selected.client}
										meta={[selected.title, selected.id, selected.owner]}
									/>
									<DetailPanel label="Lines" pad={false}>
										{#each selected.lines as [item, amount] (item)}
											<DetailRow class="flex gap-4">
												<span>{item}</span>
												<span class="ms-auto tabular-nums">{amount}</span>
											</DetailRow>
										{/each}
										<DetailRow muted class="flex gap-4">
											<span>Total</span>
											<span class="ms-auto tabular-nums">{selected.total}</span>
										</DetailRow>
									</DetailPanel>
								</DetailStack>
							{/if}
						{/snippet}
					</MasterDetail>
				</div>
			{/snippet}
		</ListPageShell>
	</div>
	<div class="grid gap-4 sm:grid-cols-3">
		<div class="rounded-xl border border-border bg-muted/40 p-2">
			<EmptyState
				surface="card"
				icon={Tray}
				title="Pick a quote"
				description="Its lines and total open here."
			/>
		</div>
		<div class="rounded-xl border border-border bg-card">
			<EmptyState
				size="sm"
				icon={MagnifyingGlass}
				title="No quote matches"
				description="Clear the filter to see every quote."
			/>
		</div>
		<EmptyState surface="dashed" icon={Tray} title="No quotes yet">
			{#snippet actions()}
				<Button size="sm"><Plus aria-hidden="true" class="size-4" weight="bold" />New quote</Button>
				<Button size="sm" variant="outline">Import</Button>
			{/snippet}
		</EmptyState>
	</div>
</div>
```

## API

### ListPageShell

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `isEmpty` | `boolean` | `false` |  |
| `emptyState` | `EmptyConfig` |  |  |
| `hideToolbarWhenEmpty` | `boolean` | `false` |  |
| `maxWidth` | `string \| false` | `"1600px"` |  |
| `fillHeight` | `boolean` | `false` |  |
| `containerClass` | `string` |  |  |
| `toolbarClass` | `string` |  |  |
| `tabs` | `Snippet` |  |  |
| `search` | `Snippet` |  |  |
| `filters` | `Snippet` |  |  |
| `rightActions` | `Snippet` |  |  |
| `summary` | `Snippet` |  |  |
| `content` | `Snippet` |  |  |
| `empty` | `Snippet` |  |  |
| `extra` | `Snippet` |  |  |
| `searchLabel` | `string` | `"Search"` | The folded search icon's name, on a toolbar too narrow for the field. Translate at the call site. |
| `closeSearchLabel` | `string` | `"Close search"` | The close button's name once the folded search is open. |

### ToolbarSearch

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `value` | `string` | `""` | bindable |
| `placeholder` | `string` | `"Search..."` |  |
| `label` | `string` | `"Search"` | The box's accessible name. A placeholder isn't one, and it goes away once you type. |
| `size` | `"sm" \| "default"` | `"default"` |  |
| `class` | `string` |  |  |

### FilterPopover

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `label` | `string` |  | required |
| `icon` | `PhosphorIcon` | `DefaultFunnelIcon` |  |
| `count` | `number` | `0` |  |
| `active` | `boolean` |  |  |
| `onClear` | `() => void` |  |  |
| `align` | `"start" \| "center" \| "end"` | `"start"` |  |
| `width` | ``w-${string}`` | `"w-52"` |  |
| `open` | `boolean` | `false` | bindable |
| `clearLabel` | `string` | `"Clear"` |  |
| `triggerClass` | `string` |  |  |
| `contentClass` | `string` |  |  |
| `children` | `Snippet` |  | required |
| `trailing` | `Snippet` |  |  |

### FilterItem

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `checked` | `boolean` |  | required |
| `onclick` | `() => void` |  | required |
| `variant` | `"checkbox" \| "radio"` | `"checkbox"` |  |
| `children` | `Snippet` |  | required |

### MasterDetail

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `rail` | `Snippet` |  | required |
| `detail` | `Snippet` |  | required |
| `banner` | `Snippet` |  |  |
| `railWidth` | `string` | `"minmax(260px, 320px)"` |  |
| `stackBelow` | `"lg"` \| `"xl"` | `"lg"` |  |
| `backLabel` | `string` | `"Back to the list"` |  |
| `pane` | `"rail" \| "detail"` | `"rail"` | bindable |
| `gap` | `boolean` | `true` |  |
| `pad` | `boolean` | `true` |  |
| `railClass` | `string` |  |  |
| `detailClass` | `string` |  |  |
| `class` | `string` |  |  |

### RailHead

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `label` | `string` |  |  |
| `action` | `Snippet` |  |  |
| `children` | `Snippet` |  |  |
| `class` | `string` |  |  |

### RailBody

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `children` | `Snippet` |  | required |
| `class` | `string` |  |  |

### RailRow

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `title` | `string` |  | required |
| `selected` | `boolean` | `false` |  |
| `onclick` | `() => void` |  | required |
| `leading` | `Snippet` |  |  |
| `trailing` | `Snippet` |  |  |
| `preview` | `string \| null` |  |  |
| `meta` | `Array<string \| null \| undefined \| false>` |  |  |
| `metaTruncate` | `"first" \| "last"` | `"first"` |  |
| `metaTrail` | `Snippet` |  |  |
| `actions` | `Snippet` |  |  |
| `titleLines` | `1 \| 2` | `1` |  |
| `class` | `string` |  |  |

### DetailStack

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `fill` | `boolean` | `false` |  |
| `children` | `Snippet` |  | required |
| `class` | `string` |  |  |

### DetailHeader

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `title` | `string` |  | required |
| `badge` | `Snippet` |  |  |
| `leading` | `Snippet` |  |  |
| `meta` | `Array<string \| null \| undefined \| false>` |  |  |
| `note` | `string \| null` |  |  |
| `actions` | `Snippet` |  |  |
| `corner` | `Snippet` |  |  |
| `children` | `Snippet` |  |  |
| `class` | `string` |  |  |

### DetailPanel

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `label` | `string` |  | What this panel is, drawn as the app's one panel label. No label, no actions: no header. |
| `labelIcon` | `PhosphorIcon` |  |  |
| `labelLead` | `Snippet` |  | A mark the icon set lacks (a platform logo), drawn ahead of the label at the same size. |
| `sublabel` | `string` |  | A line under the label, for the scope a number was measured over. |
| `hint` | `string` |  | A row count, total or freshness stamp. A prop, not an action, because hand-placed hints ended up at three type sizes on one screen. |
| `actions` | `Snippet` |  | Controls that act on this panel. Pinned right, after the hint. |
| `pad` | `boolean` | `true` | Off for a body that supplies its own padding: a table, a media grid, a full-bleed list. |
| `scroll` | `boolean` | `false` | The body scrolls sideways rather than squeezing, for a table wider than the window. |
| `grow` | `boolean` | `false` | Takes the height the panels above it left, inside a `fill` stack. One per stack. |
| `children` | `Snippet` |  | required |
| `class` | `string` |  |  |
| `bodyClass` | `string` |  |  |

### DetailRow

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `muted` | `boolean` | `false` |  |
| `children` | `Snippet` |  | required |
| `class` | `string` |  |  |

### EmptyState

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `icon` | `PhosphorIcon` |  |  |
| `iconWeight` | `"bold"` \| `"duotone"` \| `"fill"` \| `"light"` \| `"thin"` \| `"regular"` |  |  |
| `iconClass` | `string` |  | Replaces the muted colour of a bare icon. Ignored by the tile, which stays foreground. |
| `title` | `string` |  | required |
| `description` | `string` |  |  |
| `actionLabel` | `string` |  |  |
| `actionHref` | `string` |  |  |
| `onAction` | `() => void` |  |  |
| `actions` | `Snippet` |  | Several ways out, drawn in one row after the single action. |
| `surface` | `"plain" \| "card" \| "dashed"` | `"plain"` | `card` fills the white panel; `dashed` frames a whole dashboard section. |
| `size` | `"default" \| "sm"` | `"default"` | `sm` fits a 280px rail: a bare icon and one line of small type. |
| `class` | `string` |  |  |

### PrevNext

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ids` | `readonly string[]` |  | required. Ids in the order the list shows them. |
| `current` | `string \| null \| undefined` |  | required |
| `onSelect` | `(id: string) => void` |  | required |
| `previousLabel` | `string` | `"Previous"` |  |
| `nextLabel` | `string` | `"Next"` |  |
| `keys` | `boolean` | `true` | Off when two steppers share a page, so one key press moves one list. |
| `class` | `string` |  |  |

### NoticeBar

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `tone` | `Tone` | `"destructive"` |  |
| `icon` | `PhosphorIcon` |  |  |
| `actions` | `Snippet` |  |  |
| `children` | `Snippet` |  | required |
| `class` | `string` |  |  |

### GroupedList

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `groups` | `TGroup[]` |  | required |
| `getKey` | `(group: TGroup) => string` |  | required |
| `defaultCollapsed` | `string[]` | `[]` |  |
| `onCollapsedChange` | `(keys: string[]) => void` |  | WHY: a page that drives its own keyboard cursor has to know which rows are on screen, and the collapsed set is the only thing that says so. |
| `header` | `Snippet<[TGroup, { collapsed: boolean }]>` |  | required |
| `actions` | `Snippet<[TGroup]>` |  | Controls beside the header, outside its toggle button so a click on one doesn't collapse the group. Shown on hover of the header row. |
| `rows` | `Snippet<[TGroup]>` |  | required |
| `getCount` | `(group: TGroup) => number` |  | A count beside the header, in a small pill. Leave it out when the header draws its own. |
| `onAdd` | `(group: TGroup) => void` |  | Shows an add button at the end of the header row. |
| `addLabel` | `string` | `"Add"` | The add button's accessible name. |
| `class` | `string` |  |  |
| `onGroupDragOver` | `(e: DragEvent, group: TGroup) => void` |  |  |
| `onGroupDragLeave` | `(e: DragEvent) => void` |  |  |
| `onGroupDrop` | `(e: DragEvent, group: TGroup) => void` |  |  |
