Containment · Material 3: Lists
List
Rows with media, title, description and actions. One hover pill glides down the list.
Examples and variants
Interactive
Hover down the rows; click to select.
function ListInteractive() {
const [selected, setSelected] = useState("Brief.pdf")
const rows = [
{ name: "Brief.pdf", meta: "1.2 MB", icon: <FileTextIcon /> },
{ name: "Moodboard", meta: "24 images", icon: <ImageIcon /> },
{ name: "Archive", meta: "Folder", icon: <FolderIcon /> },
]
return (
<ItemGroup className="w-full max-w-sm rounded-(--list-group-corner) bg-canvas p-(--list-group-padding) shadow-1">
{rows.map((row) => (
<Item key={row.name} interactive selected={selected === row.name} onClick={() => setSelected(row.name)}>
<ItemMedia>{row.icon}</ItemMedia>
<ItemContent>
<ItemTitle>{row.name}</ItemTitle>
<ItemDescription>{row.meta}</ItemDescription>
</ItemContent>
<ItemActions>
<Button size="icon-sm" variant="ghost" aria-label={`More for ${row.name}`}>
<MoreHorizontalIcon />
</Button>
</ItemActions>
</Item>
))}
</ItemGroup>
)
}Spec drawing
Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.
Install
With the CLI
The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/item.jsonBy hand
No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.
Install the packages it uses.
Terminalnpm install cnCopy this file to the same paths in your project. Imports use the
@/alias for your project root.components/ui/item.tsxitem
components/ui/item.tsx"use client" import * as React from "react" import { cn } from "cn" import { layoutTop } from "@/lib/motion/layout-offset" /* Item: a row with media, title, description and actions (files, people, settings rows). Inside an ItemGroup, one hover pill glides down the list instead of each row lighting up on its own. Selected rows keep a tint. */ function ItemGroup({ className, children, ...props }: React.ComponentProps<"div">) { const ref = React.useRef<HTMLDivElement>(null) const [pill, setPill] = React.useState<{ top: number; height: number } | null>(null) function track(event: React.PointerEvent<HTMLDivElement>) { const root = ref.current const row = (event.target as HTMLElement).closest<HTMLElement>("[data-slot=item][data-interactive]") if (!root || !row || !root.contains(row)) return setPill({ top: layoutTop(row, root), height: row.offsetHeight }) } return ( <div ref={ref} role="list" data-slot="item-group" className={cn("relative flex flex-col", className)} onPointerOver={track} onFocus={(event) => track(event as unknown as React.PointerEvent<HTMLDivElement>)} onPointerLeave={() => setPill(null)} {...props} > <span aria-hidden data-visible={pill ? "" : undefined} className="item-pill pointer-events-none absolute inset-x-0 rounded-(--list-item-corner) bg-(--list-item-hover)" style={pill ? { top: pill.top, height: pill.height } : undefined} /> {children} </div> ) } function Item({ className, interactive = false, selected = false, ...props }: React.ComponentProps<"div"> & { interactive?: boolean; selected?: boolean }) { return ( <div role="listitem" data-slot="item" data-interactive={interactive || undefined} data-selected={selected || undefined} tabIndex={interactive ? 0 : undefined} className={cn( "relative z-[1] flex items-center gap-(--list-item-gap) rounded-(--list-item-corner) px-(--list-item-padding-x) py-(--list-item-padding-y) outline-none", interactive && "liquid-press cursor-pointer focus-visible:shadow-(--focus-ring)", selected && "bg-(--color-bg-selected)", className )} {...props} /> ) } function ItemMedia({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="item-media" className={cn("flex size-(--list-item-media-size) shrink-0 items-center justify-center rounded-(--list-item-media-corner) bg-surface-sunken text-muted-foreground [&_svg]:size-icon-md", className)} {...props} /> ) } function ItemContent({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="item-content" className={cn("flex min-w-0 flex-1 flex-col gap-0.5", className)} {...props} /> } function ItemTitle({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="item-title" className={cn("truncate text-sm font-medium", className)} {...props} /> } function ItemDescription({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="item-description" className={cn("truncate text-sm text-muted-foreground", className)} {...props} /> } function ItemActions({ className, ...props }: React.ComponentProps<"div">) { return <div data-slot="item-actions" className={cn("flex shrink-0 items-center gap-inline-xs", className)} {...props} /> } export { ItemGroup, Item, ItemMedia, ItemContent, ItemTitle, ItemDescription, ItemActions }
Imports
What the examples on this page import:
import { FileTextIcon, FolderIcon, ImageIcon, MoreHorizontalIcon } from "lucide-react"
import { Button } from "@/components/ui/button"
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemMedia, ItemTitle } from "@/components/ui/item"Anatomy
- 1Group · ItemGroup holds the hover pill.
- 2Row · --list-item-padding-*, --list-item-corner, --list-item-gap; selected --list-item-selected.
- 3Media · --list-item-media-size.
- 4Title and description · One or two lines, truncated.
- 5Actions · Trailing buttons.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
Item interactive | boolean | — | Focusable and pressable. |
Item selected | boolean | — | Keeps the selected tint. |
Tokens
Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.
| Token | Points to | Light | Dark |
|---|---|---|---|
--list-item-padding-x | var(--space-inset-item-x) | 12px | same |
--list-item-padding-y | var(--space-inset-item-y) | 8px | same |
--list-item-gap | var(--space-3) | 12px | same |
--list-item-corner | calc(var(--list-group-corner) - var(--list-group-padding)) | calc(var(--list-group-corner) - var(--list-group-padding)) | same |
--list-item-media-corner | max(var(--radius-min), calc(var(--list-item-corner) - var(--list-item-padding-y))) | max(var(--radius-min), calc(var(--list-item-corner) - var(--list-item-padding-y))) | same |
--list-item-hover | var(--color-bg-hover) | oklch(0.965 0.005 95) | oklch(0.22 0 0) |
--list-item-selected | var(--color-bg-selected) | color-mix(in oklch, var(--ref-select) 12%, transparent) | color-mix(in oklch, var(--ref-select) 16%, transparent) |
--list-item-media-size | var(--size-control-md) | 40px | same |
Motion
| Trigger | What happens | Tokens |
|---|---|---|
| Hover | One pill glides to the hovered row on a spring. | --spring-snappy |
Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.
Accessibility
- List and listitem roles.
- Actions inside rows are reachable with Tab.
Usage
Do
- Use for files, people, settings rows.
Don’t
- Don't use for data with columns (use Table).
Code
"use client"
import * as React from "react"
import { cn } from "cn"
import { layoutTop } from "@/lib/motion/layout-offset"
/*
Item: a row with media, title, description and actions (files, people,
settings rows). Inside an ItemGroup, one hover pill glides down the list
instead of each row lighting up on its own. Selected rows keep a tint.
*/
function ItemGroup({ className, children, ...props }: React.ComponentProps<"div">) {
const ref = React.useRef<HTMLDivElement>(null)
const [pill, setPill] = React.useState<{ top: number; height: number } | null>(null)
function track(event: React.PointerEvent<HTMLDivElement>) {
const root = ref.current
const row = (event.target as HTMLElement).closest<HTMLElement>("[data-slot=item][data-interactive]")
if (!root || !row || !root.contains(row)) return
setPill({ top: layoutTop(row, root), height: row.offsetHeight })
}
return (
<div
ref={ref}
role="list"
data-slot="item-group"
className={cn("relative flex flex-col", className)}
onPointerOver={track}
onFocus={(event) => track(event as unknown as React.PointerEvent<HTMLDivElement>)}
onPointerLeave={() => setPill(null)}
{...props}
>
<span
aria-hidden
data-visible={pill ? "" : undefined}
className="item-pill pointer-events-none absolute inset-x-0 rounded-(--list-item-corner) bg-(--list-item-hover)"
style={pill ? { top: pill.top, height: pill.height } : undefined}
/>
{children}
</div>
)
}
function Item({
className,
interactive = false,
selected = false,
...props
}: React.ComponentProps<"div"> & { interactive?: boolean; selected?: boolean }) {
return (
<div
role="listitem"
data-slot="item"
data-interactive={interactive || undefined}
data-selected={selected || undefined}
tabIndex={interactive ? 0 : undefined}
className={cn(
"relative z-[1] flex items-center gap-(--list-item-gap) rounded-(--list-item-corner) px-(--list-item-padding-x) py-(--list-item-padding-y) outline-none",
interactive && "liquid-press cursor-pointer focus-visible:shadow-(--focus-ring)",
selected && "bg-(--color-bg-selected)",
className
)}
{...props}
/>
)
}
function ItemMedia({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="item-media"
className={cn("flex size-(--list-item-media-size) shrink-0 items-center justify-center rounded-(--list-item-media-corner) bg-surface-sunken text-muted-foreground [&_svg]:size-icon-md", className)}
{...props}
/>
)
}
function ItemContent({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="item-content" className={cn("flex min-w-0 flex-1 flex-col gap-0.5", className)} {...props} />
}
function ItemTitle({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="item-title" className={cn("truncate text-sm font-medium", className)} {...props} />
}
function ItemDescription({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="item-description" className={cn("truncate text-sm text-muted-foreground", className)} {...props} />
}
function ItemActions({ className, ...props }: React.ComponentProps<"div">) {
return <div data-slot="item-actions" className={cn("flex shrink-0 items-center gap-inline-xs", className)} {...props} />
}
export { ItemGroup, Item, ItemMedia, ItemContent, ItemTitle, ItemDescription, ItemActions }