A list with filters
Records in a table, each opening beside the list
This recipe draws ListPage arrangement="filtered"; the others (agent/layout-chooser.md) take the same slots. Your page fits another? Change the one prop:
plain(fields: few):filtersa few, in the header line;collectionrows or a feed.views-column(views: saved):viewsthe saved views, a column beside the list.centred(fields: few; Trail draws it asplain):collectionrows read as items.
Copy the file below whole (src/screens/issues.tsx, say) beside frame.tsx (docs/screen-frame.md) and swap the sample rows and columns for your records; keep the parts and their props. ListPage: its heading, a filter row of a search and a status filter (a Select, "Status: All 4", whose options each count the rows they would show, the count at the option's end and in its name: its words stay whole on a phone, where a SegmentedControl cuts five counted options to "To…", "P…"; a SegmentedControl is for a view or a mode in a few short words, Tabs for views with panels), the table at the panel's full width; a row opens its record in a RecordPeek beside the list, kept in the URL (?peek=<id>; your router: useRecordPeek({ adapter })). The row's main item, its title, is a TableCellLabel with primary, in the weight and ink of the person beside it. A status column is a StatusMark (a stock level is the same column with your own status, { name: 'Low', icon: 'alert-triangle', variant: 'warning' }: docs/status.md); a number edited in its row (an estimate, a quantity) is a NumberInput with stepper straight in its cell, named by its row; the row's actions are a dots IconButton's DropdownMenu in the last column, align="end". Light, dark, phone (the filters stack, the narrow columns leave) and desktop are the parts' own: add no class for them. Your own columns: the title, the status and the one figure a person reads first (an amount) keep plain tracks; mark every other { track, hide: 'narrow' }, as these are, so a 375 px phone shows those three whole. Its empty row is the filtered state; rows loading, a failed load and a first run: docs/screen-states.md.
Show the code294 lines
// src/screens/issues.tsx: the list page, a row opening beside it
import { useState } from 'react';
import { ListPage } from '@/components/goop/patterns/list-page';
import {
RecordPeekBody,
RecordPeekHeader,
RecordPeekItem,
RecordPeekPanel,
RecordPeekTrigger,
useRecordPeek,
} from '@/components/goop/patterns/record-peek';
import { CommandShortcut } from '@/components/ui/goop/command';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/goop/dropdown-menu';
import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from '@/components/ui/goop/empty';
import { IconButton, IconButtonIcon } from '@/components/ui/goop/icon-button';
import { MetaFacts, MetaFactsItem, MetaFactsLabel, MetaFactsValue } from '@/components/ui/goop/meta-facts';
import { NumberInput } from '@/components/ui/goop/number-input';
import { PageHeader, PageHeaderTitle } from '@/components/ui/goop/page-header';
import { PriorityMark } from '@/components/ui/goop/priority-mark';
import { Prose } from '@/components/ui/goop/prose';
import { SearchInput } from '@/components/ui/goop/search-input';
import {
Select,
SelectContent,
SelectIcon,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/goop/select';
import { StatusMark } from '@/components/ui/goop/status-mark';
import { Table, TableBody, TableHead, TableHeader, TableRow } from '@/components/ui/goop/table';
import { TableCell, TableCellLabel, TableCellPerson } from '@/components/ui/goop/table-cell';
import { ScreenFrame, ScreenTopBar } from './frame';
import { hrefOf } from './router';
// ---- the sample data: swap it for yours
type Status = 'todo' | 'in-progress' | 'in-review' | 'done';
const STATUS_WORDS: Record<Status, string> = {
todo: 'To do',
'in-progress': 'In progress',
'in-review': 'In review',
done: 'Done',
};
const STATUSES = Object.keys(STATUS_WORDS) as Status[];
interface Issue {
id: string;
title: string;
status: Status;
priority: 'urgent' | 'high' | 'medium' | 'low';
assignee: string;
/** Points; null for not estimated. */
estimate: number | null;
}
const ME = 'Teodora Valk';
const ISSUES: Issue[] = [
{
id: 'FW-121',
title: 'Tags vanish on sync',
status: 'in-review',
priority: 'urgent',
assignee: 'Bilal Rashed',
estimate: 3,
},
{
id: 'FW-117',
title: 'Recruit 8 participants',
status: 'todo',
priority: 'high',
assignee: 'Dagny Holm',
estimate: 5,
},
{
id: 'FW-110',
title: 'Help page on tags',
status: 'in-progress',
priority: 'low',
assignee: 'Teodora Valk',
estimate: 1,
},
{
id: 'FW-108',
title: 'Waveform stutters',
status: 'done',
priority: 'medium',
assignee: 'Ngozi Ilori',
estimate: 2,
},
];
const ANY = 'any';
const counted = (n: number) => `${n} ${n === 1 ? 'issue' : 'issues'}`;
export default function IssuesScreen() {
const [issues, setIssues] = useState(ISSUES);
const [query, setQuery] = useState('');
const [status, setStatus] = useState<string>(ANY);
const peek = useRecordPeek();
// what the search leaves: each status option counts its own share of it
const found = issues.filter((issue) =>
`${issue.id} ${issue.title}`.toLowerCase().includes(query.trim().toLowerCase()),
);
const shown = found.filter((issue) => status === ANY || issue.status === status);
const countOf = (value: string) => (value === ANY ? found : found.filter((issue) => issue.status === value)).length;
const statusWords = (value: string) => (value === ANY ? 'All' : STATUS_WORDS[value as Status]);
const open = issues.find((issue) => issue.id === peek.id);
const change = (id: string, next: Partial<Issue>) =>
setIssues((all) => all.map((issue) => (issue.id === id ? { ...issue, ...next } : issue)));
return (
<ScreenFrame current="/issues">
<ListPage
arrangement="filtered"
header={<ScreenTopBar title="Issues" />}
heading={
<PageHeader>
<PageHeaderTitle asChild>
<h1>Issues</h1>
</PageHeaderTitle>
</PageHeader>
}
filters={
<>
<SearchInput
label="Search issues"
placeholder="Search issues"
value={query}
onChange={(event) => setQuery(event.currentTarget.value)}
/>
<Select value={status} onValueChange={setStatus}>
<SelectTrigger aria-label={`Status: ${statusWords(status)}, ${counted(countOf(status))}`}>
<SelectValue>{`Status: ${statusWords(status)} ${countOf(status)}`}</SelectValue>
<SelectIcon />
</SelectTrigger>
<SelectContent aria-label="Status" search={false}>
{[ANY, ...STATUSES].map((value) => (
<SelectItem
key={value}
value={value}
aria-label={`${statusWords(value)}, ${counted(countOf(value))}`}
>
{statusWords(value)}
<CommandShortcut>{countOf(value)}</CommandShortcut>
</SelectItem>
))}
</SelectContent>
</Select>
</>
}
collection={
shown.length === 0 ? (
<Empty variant="outline">
<EmptyHeader>
<EmptyTitle>No issue matches the search and the status.</EmptyTitle>
<EmptyDescription>Try other words, or all statuses.</EmptyDescription>
</EmptyHeader>
</Empty>
) : (
<Table
aria-label="Issues"
gutter="page"
columns={[
'minmax(160px, 1fr)',
'128px',
{ track: '96px', hide: 'narrow' },
{ track: '176px', hide: 'narrow' },
{ track: '120px', hide: 'narrow' },
'40px',
]}
>
<TableHeader>
<TableRow>
<TableHead>
<TableCellLabel>Issue</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Status</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Priority</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Assignee</TableCellLabel>
</TableHead>
<TableHead>
<TableCellLabel>Estimate</TableCellLabel>
</TableHead>
<TableHead align="end" aria-label="Actions" />
</TableRow>
</TableHeader>
<TableBody>
{shown.map((issue) => (
<RecordPeekItem key={issue.id} value={issue.id} asChild>
<TableRow>
<TableCell>
<RecordPeekTrigger>
<TableCellLabel primary>{issue.title}</TableCellLabel>
</RecordPeekTrigger>
</TableCell>
<TableCell>
<StatusMark status={issue.status} label={STATUS_WORDS[issue.status]} />
</TableCell>
<TableCell>
<PriorityMark priority={issue.priority} label />
</TableCell>
<TableCell>
<TableCellPerson name={issue.assignee} />
</TableCell>
<TableCell>
<NumberInput
aria-label={`Estimate of ${issue.title}`}
stepper
min={0}
max={13}
value={issue.estimate}
onValueChange={(estimate) => change(issue.id, { estimate })}
/>
</TableCell>
<TableCell align="end">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<IconButton variant="ghost" size="sm" aria-label={`Actions for ${issue.id}`}>
<IconButtonIcon icon="dots" />
</IconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" aria-label={`Actions for ${issue.id}`}>
<DropdownMenuItem
disabled={issue.assignee === ME}
onSelect={() => change(issue.id, { assignee: ME })}
>
Assign to me
</DropdownMenuItem>
<DropdownMenuItem
disabled={issue.status === 'done'}
onSelect={() => change(issue.id, { status: 'done' })}
>
Mark as done
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>
</TableRow>
</RecordPeekItem>
))}
</TableBody>
</Table>
)
}
peek={{
open: open !== undefined,
onOpenChange: (next) => {
if (!next) peek.close();
},
records: shown.map((issue) => issue.id),
value: peek.id,
onValueChange: peek.step,
onOpenRecord: peek.open,
href: open ? hrefOf(`/issues/${open.id}`) : undefined,
storageKey: 'issues:peek',
}}
record={
<RecordPeekPanel>
<RecordPeekHeader title={open?.title ?? ''} />
<RecordPeekBody>
{open ? (
<>
<MetaFacts aria-label="Issue details">
<MetaFactsItem>
<MetaFactsLabel>Issue</MetaFactsLabel>
<MetaFactsValue>{open.id}</MetaFactsValue>
</MetaFactsItem>
<MetaFactsItem>
<MetaFactsLabel>Status</MetaFactsLabel>
<MetaFactsValue>
<StatusMark status={open.status} label={STATUS_WORDS[open.status]} />
</MetaFactsValue>
</MetaFactsItem>
<MetaFactsItem>
<MetaFactsLabel>Assignee</MetaFactsLabel>
<MetaFactsValue>{open.assignee}</MetaFactsValue>
</MetaFactsItem>
</MetaFacts>
<Prose>{`${open.assignee} has this one. Open the full page for its history.`}</Prose>
</>
) : null}
</RecordPeekBody>
</RecordPeekPanel>
}
/>
</ScreenFrame>
);
}Options: rows in groups, a Display menu, a pinned foot; a timeline, a tree, budgets
The file above is the default. Three named options change how the table works, each a whole file in a doc of its own (docs/recipe-list-grouped.md, docs/recipe-list-display.md, docs/recipe-list-foot.md), copied instead of it (same path, same frame). Each is written short: it keeps the search and the row's menu, and leaves out the status filter, the stepper and the peek — put back any of them exactly as the default writes them. Three more draw records that are not rows, each a page of its own beside the list (its own path and route, a row in the frame's pages): dated records on a timeline (docs/recipe-list-timeline.md, a Gantt), records inside records in a tree (docs/recipe-list-tree.md, a TreeView) and budgets held to a limit (docs/recipe-list-budgets.md, a Meter a card).
Which one:
| The list in your product | Copy | | --- | --- | | A few dozen records a person scans and opens one by one (contacts, files, a tracker's own list) | the default | | Records read by one key, the groups done with folded away (issues by status, orders by stage, tickets by assignee) | grouped | | A working list each person shapes: which columns show, the grouping, the order, how dense the rows are | display | | Records with figures to add up, or more than fit one screen (invoices, hours, stock, payments) | foot | | Records with a start and an end date a team plans by (projects, phases, releases): a page of its own | timeline | | Records kept inside one another (pages under pages, folders and files, categories): a page of its own | tree | | Money held to a limit a period, the limit changed in place (a household's or a team's budgets): a page of its own | budgets |