← Components

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.

Brief.pdf
1.2 MB
Moodboard
24 images
Archive
Folder
Example
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.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/item.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy 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:

Imports
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

  1. 1Group · ItemGroup holds the hover pill.
  2. 2Row · --list-item-padding-*, --list-item-corner, --list-item-gap; selected --list-item-selected.
  3. 3Media · --list-item-media-size.
  4. 4Title and description · One or two lines, truncated.
  5. 5Actions · Trailing buttons.

Props

PropTypeDefaultDescription
Item interactiveboolean—Focusable and pressable.
Item selectedboolean—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.

TokenPoints toLightDark
--list-item-padding-xvar(--space-inset-item-x)12pxsame
--list-item-padding-yvar(--space-inset-item-y)8pxsame
--list-item-gapvar(--space-3)12pxsame
--list-item-cornercalc(var(--list-group-corner) - var(--list-group-padding))calc(var(--list-group-corner) - var(--list-group-padding))same
--list-item-media-cornermax(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-hovervar(--color-bg-hover)oklch(0.965 0.005 95)oklch(0.22 0 0)
--list-item-selectedvar(--color-bg-selected)color-mix(in oklch, var(--ref-select) 12%, transparent)color-mix(in oklch, var(--ref-select) 16%, transparent)
--list-item-media-sizevar(--size-control-md)40pxsame

Motion

TriggerWhat happensTokens
HoverOne 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

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 }