ListRow
The height and the shape of one row of a list. What the row does (a button, a link, a menu trigger) comes from render.
import { ListRow } from '@adecore/ui';import { Icon, ListRow } from '@adecore/ui';
import { GitCommitHorizontal } from 'lucide-react';
const COMMITS = [
{ hash: 'a1c9e2f', message: 'Keep a nested dialog above its parent' },
{ hash: '4d02b7a', message: 'Round the spacing unit to a whole pixel' },
{ hash: '9fe13c0', message: 'Let a select align with the end of its trigger' }
];
export default function ListRowDemo() {
return (
<div className="flex w-full max-w-xl gap-4">
<div className="flex w-48 shrink-0 flex-col gap-0.5 rounded-lg border border-border bg-surface p-1">
<ListRow variant="inset" className="bg-surface-active text-sm text-text" render={<button type="button" />}>
Inbox
</ListRow>
<ListRow variant="inset" className="text-sm text-text-muted hover:bg-surface-hover" render={<button type="button" />}>
Archive
</ListRow>
</div>
<div className="min-w-0 grow divide-y divide-border-soft rounded-lg border border-border bg-surface">
{COMMITS.map((commit) => (
<ListRow key={commit.hash} variant="flat" className="gap-2 px-3 text-xs text-text">
<Icon icon={GitCommitHorizontal} size={14} className="text-text-faint" />
<span className="font-mono text-text-muted">{commit.hash}</span>
<span className="truncate">{commit.message}</span>
</ListRow>
))}
</div>
</div>
);
}variant is required. A flat row is 28 pixels tall and square, for a list that reads as a table and fills the width of its panel: commits, processes, branches. It has no padding; pad 12 pixels beside text and 4 beside a button.
An inset row is 32 pixels tall, rounded and padded 8 pixels, for a list a person finds their way through: a sidebar, devices, recent files.
A stacked row has the shape of an inset row and grows with its content. Its children stand in a column, for a row of several lines such as a message with its sender, subject and preview.
selected draws the selected ground and sets aria-current, or aria-selected when the row has role="option". A row with selected={false} draws a hover. Without selected the row draws neither, and the caller adds them.
indent adds steps of 24 pixels to the start padding, for a row nested under another.
import { ListRow } from '@adecore/ui';
import { useState } from 'react';
const FOLDERS = [
{ id: 'all', label: 'All inboxes', indent: 0 },
{ id: 'personal', label: 'Personal', indent: 1 },
{ id: 'work', label: 'Work', indent: 1 }
];
const MESSAGES = [
{
id: 1,
from: 'Sanne de Vries',
time: '09:41',
subject: 'Review requested: new onboarding flow',
preview: 'I left notes on the second and fourth screen. The empty state could use a drawing.'
},
{
id: 2,
from: 'Jan Dekker',
time: 'Tue',
subject: 'Re: Q1 roadmap planning',
preview: 'Sounds good, I will bring the slides. Can we decide on the sync engine before Friday?'
}
];
export default function ListRowStacked() {
const [folder, setFolder] = useState('personal');
const [message, setMessage] = useState(1);
return (
<div className="flex w-full max-w-xl gap-4">
<div className="flex w-44 shrink-0 flex-col gap-0.5 rounded-lg border border-border bg-surface p-1">
{FOLDERS.map((entry) => (
<ListRow
key={entry.id}
variant="inset"
indent={entry.indent}
selected={folder === entry.id}
className="text-sm"
render={<button type="button" onClick={() => setFolder(entry.id)} />}
>
{entry.label}
</ListRow>
))}
</div>
<div className="flex min-w-0 grow flex-col gap-0.5 rounded-lg border border-border bg-surface p-1">
{MESSAGES.map((entry) => (
<ListRow
key={entry.id}
variant="stacked"
selected={message === entry.id}
render={<button type="button" onClick={() => setMessage(entry.id)} />}
>
<span className="flex items-center gap-2 text-xs font-semibold">
<span className="truncate">{entry.from}</span>
<span className="ml-auto font-normal text-text-faint">{entry.time}</span>
</span>
<span className="truncate text-xs">{entry.subject}</span>
<span className="line-clamp-2 text-xs text-text-muted">{entry.preview}</span>
</ListRow>
))}
</div>
</div>
);
}Props
| Prop | Type | Default | |
|---|---|---|---|
variant | 'flat' | 'inset' | 'stacked' | Required. | |
selected | boolean | ||
indent | number | 0 | Steps of 24 pixels. |
render | ReactElement | <div> | What the row is. |
ListRow also takes the props of a <div>. ListRowProps is an exported type.