List
FreeNewRows of records with leading, title, description and trailing slots, clickable across the row, in divided or card style with sticky group headings.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above.
import { Ellipsis } from "lucide-react";
import { Avatar } from "@/components/viewport/avatar";
import { Badge } from "@/components/viewport/badge";
import { List, ListGroup, ListItem } from "@/components/viewport/list";
const groups = [
{ letter: "C", people: [{ name: "Inés Carvalho", role: "Account Executive, Globex", tag: "Customer" }] },
{ letter: "L", people: [{ name: "Mara Lindqvist", role: "Head of Revenue, Northwind", tag: "Champion" }] },
{
letter: "O",
people: [
{ name: "Theo Okafor", role: "Procurement Lead, Initech", tag: "Lead" },
{ name: "Adaeze Okonkwo", role: "CFO, Umbrella Health", tag: "Customer" },
],
},
{ letter: "R", people: [{ name: "Priya Raman", role: "VP Operations, Hooli", tag: "Lead" }] },
{ letter: "W", people: [{ name: "Kenji Watanabe", role: "IT Director, Northgate Foods", tag: "Customer" }] },
];
export default function ListDemo() {
return (
<div className="h-80 w-full max-w-md overflow-y-auto rounded-2xl border border-border bg-card [--list-heading:var(--card)]">
{groups.map((group) => (
<ListGroup key={group.letter} title={group.letter} trailing={<span className="tabular-nums">{group.people.length}</span>}>
<List>
{group.people.map((person) => (
<ListItem
key={person.name}
href={`#${person.name.toLowerCase().replace(/\s+/g, "-")}`}
leading={<Avatar name={person.name} size="sm" />}
title={person.name}
description={person.role}
trailing={
<>
<Badge size="sm" tone={person.tag === "Champion" ? "success" : person.tag === "Lead" ? "info" : "neutral"}>
{person.tag}
</Badge>
<button
type="button"
aria-label={`More actions for ${person.name}`}
className="grid size-7 cursor-pointer place-items-center rounded-md outline-none transition-colors hover:bg-foreground/[0.08] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
>
<Ellipsis className="size-4" aria-hidden />
</button>
</>
}
/>
))}
</List>
</ListGroup>
))}
</div>
);
}Props
<List>
| Prop | Type | Default |
|---|---|---|
| variant | "divided" | "separated" | "plain"`divided` draws hairlines between rows; `separated` gives each row its own card; `plain` draws nothing. | "divided" |
<ListItem>
| Prop | Type | Default |
|---|---|---|
| leading | React.ReactNodeAn avatar, an icon or a checkbox at the start of the row. | — |
| title* | React.ReactNode | — |
| description | React.ReactNodeA second, muted line. | — |
| trailing | React.ReactNodeA value, a badge or buttons at the end of the row. | — |
| href | stringMakes the row a link. The link is the title, stretched over the row. | — |
| onClick | () => voidMakes the row a button. | — |
| current | booleanMarks the row as the one currently open, e.g. in a master-detail layout. | — |
<ListGroup>
| Prop | Type | Default |
|---|---|---|
| title* | React.ReactNodeThe group's heading, e.g. a letter or a date. | — |
| sticky | booleanKeep the heading in view while its rows scroll past. | true |
| trailing | React.ReactNodeA count or an action at the end of the heading. | — |
Accessibility
- The row's link is its title, stretched over the row, so it has one clear name.
- Controls in the trailing slot stay separately focusable and clickable.
- Groups are sections with real headings.
- Server component with no client JavaScript.