Record List
The List view of a table. Each record on the current page is one row: a title, up to four labelled values, choice badges, and row actions. Use it to read and triage records. Use Table to compare values in columns, edit, or select rows in bulk.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/record-list.jsonCopies Record List and the components it uses (Button, Skeleton, and Spinner) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/record-list. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
'use client'; import { useCallback, useId, useImperativeHandle, useLayoutEffect, useRef, useState, type KeyboardEvent, type MouseEvent, type ReactNode, type Ref, } from 'react'; import { cn } from '@/lib/sprout/classes'; import { Button } from '@/components/ui/button'; import { Skeleton, SkeletonGroup } from '@/components/ui/skeleton'; import { StatePanel } from '@/lib/sprout/state-panel-core'; export const recordListStatusNames = ['ready', 'loading', 'error'] as const; export const recordListDensityNames = ['md', 'sm'] as const; export type RecordListStatus = (typeof recordListStatusNames)[number]; export type RecordListDensity = (typeof recordListDensityNames)[number]; export const recordListMaxValues = 4; export interface RecordListItem { id: string; title: string; } export interface RecordListValue { label: string; value: ReactNode; text?: string | undefined; } export interface RecordListHandle { focusFirst: () => void; } export interface RecordListProps<T extends RecordListItem> { items: T[]; label: string; renderTitle?: ((item: T) => ReactNode) | undefined; values?: ((item: T) => RecordListValue[]) | undefined; badges?: ((item: T) => ReactNode) | undefined; renderActions?: ((item: T) => ReactNode) | undefined; onItemOpen?: ((item: T) => void) | undefined; status?: RecordListStatus | undefined; error?: ReactNode; onRetry?: (() => void) | undefined; empty?: ReactNode; footer?: ReactNode; density?: RecordListDensity | undefined; ref?: Ref<RecordListHandle> | undefined; className?: string | undefined; } const SKELETON_ROWS = 5; const ROW = 'data-record-list-row'; const SAVED_TAB = 'data-record-list-tabindex'; const FOCUSABLE = 'a[href], area[href], button, input, select, textarea, iframe, summary, [contenteditable=""], [contenteditable="true"], [tabindex]'; const rowsName = (label: string, count: number) => `${label}, ${count} ${count === 1 ? 'row' : 'rows'}`; const hint = (entry: RecordListValue) => entry.text ?? (typeof entry.value === 'string' || typeof entry.value === 'number' ? String(entry.value) : undefined); function syncTabStops(list: HTMLElement) { for (const row of list.querySelectorAll<HTMLElement>(`[${ROW}]`)) { const active = row.tabIndex === 0; for (const control of row.querySelectorAll<HTMLElement>(FOCUSABLE)) { if (active) { const saved = control.getAttribute(SAVED_TAB); if (saved === null) continue; if (saved === '') control.removeAttribute('tabindex'); else control.setAttribute('tabindex', saved); control.removeAttribute(SAVED_TAB); } else if (!control.hasAttribute(SAVED_TAB) && control.tabIndex >= 0) { control.setAttribute(SAVED_TAB, control.getAttribute('tabindex') ?? ''); control.setAttribute('tabindex', '-1'); } } } } function SkeletonRows() { return ( <SkeletonGroup label="Loading rows" gap="sm" className="sprout-record-list-skeleton" data-slot="record-list-skeleton" > {Array.from({ length: SKELETON_ROWS }, (_, index) => ( <div key={index} className="sprout-record-list-skeleton-row"> <div className="sprout-record-list-skeleton-main"> <Skeleton className="sprout-record-list-skeleton-title" /> <Skeleton className="sprout-record-list-skeleton-values" /> </div> <Skeleton shape="action" /> </div> ))} </SkeletonGroup> ); } export function RecordList<T extends RecordListItem>({ items, label, renderTitle, values, badges, renderActions, onItemOpen, status = 'ready', error, onRetry, empty, footer, density = 'md', ref, className, }: RecordListProps<T>) { const id = useId(); const listRef = useRef<HTMLUListElement>(null); const stateRef = useRef<HTMLDivElement>(null); const pendingFocus = useRef(false); const [activeId, setActiveId] = useState<string | null>(null); const loading = status === 'loading'; const showRows = status !== 'error' && items.length > 0; const current = items.some(item => item.id === activeId) ? activeId : (items[0]?.id ?? null); const rowOf = useCallback( (itemId: string) => [...(listRef.current?.querySelectorAll<HTMLElement>(`[${ROW}]`) ?? [])].find( row => row.dataset.recordListRow === itemId, ), [], ); const flushFocus = useCallback(() => { if (!pendingFocus.current || loading) return; pendingFocus.current = false; if (showRows && items[0]) { setActiveId(items[0].id); rowOf(items[0].id)?.focus(); } else stateRef.current?.focus(); }, [items, loading, rowOf, showRows]); const latestFlush = useRef(flushFocus); useLayoutEffect(() => { latestFlush.current = flushFocus; flushFocus(); }); useImperativeHandle( ref, () => ({ focusFirst() { pendingFocus.current = true; setTimeout(() => latestFlush.current()); }, }), [], ); useLayoutEffect(() => { const list = listRef.current; if (!list) return; syncTabStops(list); const observer = new MutationObserver(() => syncTabStops(list)); observer.observe(list, { childList: true, subtree: true }); return () => observer.disconnect(); }); const move = (event: KeyboardEvent<HTMLUListElement>) => { const row = event.target as HTMLElement; if (!row.hasAttribute(ROW) || event.altKey || event.ctrlKey || event.metaKey) return; const index = items.findIndex(item => item.id === row.dataset.recordListRow); const item = items[index]; if (!item) return; if (event.key === 'Enter') { if (!onItemOpen || event.repeat) return; event.preventDefault(); onItemOpen(item); return; } const target = event.key === 'ArrowDown' ? items[Math.min(index + 1, items.length - 1)] : event.key === 'ArrowUp' ? items[Math.max(index - 1, 0)] : event.key === 'Home' ? items[0] : event.key === 'End' ? items.at(-1) : undefined; if (!target || event.shiftKey) return; event.preventDefault(); setActiveId(target.id); rowOf(target.id)?.focus(); }; const open = (event: MouseEvent<HTMLElement>, item: T) => { const target = event.target as HTMLElement; const row = event.currentTarget; if (!onItemOpen || !row.contains(target)) return; const control = target.closest(FOCUSABLE); if (control && control !== row && row.contains(control)) return; if (target.closest('[data-slot="record-list-actions"]')) return; if (window.getSelection()?.toString()) return; onItemOpen(item); }; const emptyContent = empty === undefined ? ( <StatePanel kind="empty" heading="h3" title="No rows to show" description="Rows show here when they are added or match the search and filters." /> ) : typeof empty === 'string' ? ( <p className="sprout-record-list-empty-text">{empty}</p> ) : ( empty ); return ( <div data-slot="record-list" data-density={density} data-status={status} className={cn('sprout-record-list', className)} > {status === 'error' ? ( <div ref={stateRef} tabIndex={-1} data-slot="record-list-state" className="sprout-record-list-state"> <StatePanel kind="error" heading="h3" title="Rows did not load" description={error ?? 'Something went wrong while loading the rows.'} > {onRetry ? ( <Button variant="outline" onClick={onRetry}> Try again </Button> ) : null} </StatePanel> </div> ) : showRows ? ( <> <ul ref={listRef} aria-label={rowsName(label, items.length)} aria-busy={loading || undefined} data-slot="record-list-items" className="sprout-record-list-items" onKeyDown={move} > {items.map((item, index) => { const shown = values?.(item).slice(0, recordListMaxValues) ?? []; const badgeContent = badges?.(item); const hasBadges = badgeContent != null && badgeContent !== false; const actions = renderActions?.(item); const valuesId = `${id}-${index}-values`; const badgesId = `${id}-${index}-badges`; const described = [shown.length > 0 && valuesId, hasBadges && badgesId].filter(Boolean).join(' '); return ( <li key={item.id} data-record-list-row={item.id} tabIndex={item.id === current ? 0 : -1} aria-label={item.title} aria-describedby={described || undefined} data-slot="record-list-item" data-openable={onItemOpen ? '' : undefined} className="sprout-record-list-item" onFocus={event => { if (event.currentTarget.contains(event.target)) setActiveId(item.id); }} onClick={event => open(event, item)} > <div data-slot="record-list-title" className="sprout-record-list-title" title={item.title}> {renderTitle ? renderTitle(item) : item.title} </div> {shown.length > 0 && ( <dl id={valuesId} data-slot="record-list-values" className="sprout-record-list-values"> {shown.map((entry, position) => ( <div key={`${entry.label}-${position}`} className="sprout-record-list-value"> <dt>{entry.label}</dt> <dd title={hint(entry)}>{entry.value}</dd> </div> ))} </dl> )} {hasBadges && ( <div id={badgesId} data-slot="record-list-badges" className="sprout-record-list-badges"> {badgeContent} </div> )} {actions != null && actions !== false && ( <div data-slot="record-list-actions" className="sprout-record-list-actions"> {actions} </div> )} </li> ); })} </ul> <span role="status" className="sprout-record-list-sr-only"> {loading ? 'Loading rows…' : ''} </span> </> ) : ( <div ref={stateRef} tabIndex={-1} data-slot="record-list-state" className="sprout-record-list-state"> {loading ? <SkeletonRows /> : emptyContent} </div> )} {footer != null && footer !== false && ( <div data-slot="record-list-footer" className="sprout-record-list-footer"> {footer} </div> )} </div> ); }And the files it imports:
lib/sprout/icons/check-icon.tsxlib/sprout/icons/create-icon.tsxlib/sprout/icons/inbox-icon.tsxlib/sprout/icons/warning-icon.tsxlib/sprout/state-panel-core.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-record-list { --sprout-record-list-pad-y: .75rem; --sprout-record-list-pad-x: 1rem; box-sizing: border-box; border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-surface); min-width: 0; color: var(--sprout-text); font-family: var(--sprout-font); font-size: var(--sprout-text-sm); flex-direction: column; line-height: 1.25rem; display: flex; overflow: hidden; container-type: inline-size; } .sprout-record-list[data-density="sm"] { --sprout-record-list-pad-y: .5rem; --sprout-record-list-pad-x: .75rem; } .sprout-record-list-items { margin: 0; padding: 0; list-style: none; } .sprout-record-list-items[aria-busy="true"] { opacity: .55; } .sprout-record-list-item { min-height: 2.75rem; padding: var(--sprout-record-list-pad-y) var(--sprout-record-list-pad-x); border-bottom: 1px solid var(--sprout-line); outline: none; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title badges actions" "values badges actions"; align-items: center; column-gap: .75rem; display: grid; } .sprout-record-list-item:last-child { border-bottom: 0; } .sprout-record-list-item[data-openable] { cursor: pointer; } @media (hover: hover) { .sprout-record-list-item:hover { background-color: var(--sprout-hover); } } .sprout-record-list-item:has([aria-expanded="true"]), .sprout-record-list-item:has(:focus-visible) { background-color: var(--sprout-hover); } .sprout-record-list-item:focus-visible { background-color: var(--sprout-hover); outline: var(--sprout-focus-width) solid var(--sprout-focus-ring); outline-offset: calc(var(--sprout-focus-width) * -1); border-radius: 2px; } .sprout-record-list-title { text-overflow: ellipsis; white-space: nowrap; grid-area: title; min-width: 0; font-weight: 500; overflow: hidden; } .sprout-record-list-values { min-width: 0; font-size: var(--sprout-text-xs); font-variant-numeric: tabular-nums; flex-wrap: wrap; grid-area: values; gap: .25rem 1rem; margin: .25rem 0 0; line-height: 1rem; display: flex; } .sprout-record-list-value { align-items: baseline; gap: .375rem; min-width: 0; max-width: 16rem; display: flex; } .sprout-record-list-value > dt { color: var(--sprout-muted); flex-shrink: 0; } .sprout-record-list-value > dd { min-width: 0; color: var(--sprout-text); text-overflow: ellipsis; white-space: nowrap; margin: 0; font-weight: 500; overflow: hidden; } .sprout-record-list-badges { flex-wrap: wrap; grid-area: badges; justify-content: flex-end; align-items: center; gap: .25rem; min-width: 0; max-width: 18rem; display: flex; } .sprout-record-list-actions { grid-area: actions; align-items: center; gap: .25rem; margin-inline-end: -.25rem; display: flex; } @container (width <= 40rem) { .sprout-record-list-item { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title actions" "values values" "badges badges"; align-items: start; } .sprout-record-list-title { -webkit-line-clamp: 2; white-space: normal; overflow-wrap: anywhere; -webkit-box-orient: vertical; align-self: center; display: -webkit-box; } .sprout-record-list-badges { justify-content: flex-start; max-width: none; margin-top: .5rem; } .sprout-record-list-value { max-width: 100%; } } .sprout-record-list-state { outline: none; min-width: 0; } .sprout-record-list-empty-text { padding: 1.5rem var(--sprout-record-list-pad-x); color: var(--sprout-muted); text-align: center; margin: 0; } .sprout-record-list-skeleton { gap: 0; } .sprout-record-list-skeleton-row { padding: var(--sprout-record-list-pad-y) var(--sprout-record-list-pad-x); border-bottom: 1px solid var(--sprout-line); align-items: center; gap: .75rem; display: flex; } .sprout-record-list-skeleton-row:last-of-type { border-bottom: 0; } .sprout-record-list-skeleton-main { flex: 1; gap: .5rem; min-width: 0; display: grid; } .sprout-record-list .sprout-record-list-skeleton-title { width: min(40%, 16rem); height: 14px; } .sprout-record-list .sprout-record-list-skeleton-values { width: min(70%, 28rem); height: 10px; } .sprout-record-list-footer { min-width: 0; padding: .5rem var(--sprout-record-list-pad-x); border-top: 1px solid var(--sprout-line); justify-content: center; display: flex; } .sprout-record-list-footer > * { margin-inline: 0; } .sprout-record-list-sr-only { clip-path: inset(50%); white-space: nowrap; width: 1px; height: 1px; position: absolute; overflow: hidden; } @media (prefers-reduced-motion: no-preference) { .sprout-record-list-item { transition: background-color var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-record-list-items { transition: opacity var(--sprout-motion-normal) var(--sprout-motion-ease); } .sprout-record-list-state, .sprout-record-list-item { animation: sprout-record-list-in var(--sprout-motion-normal) var(--sprout-motion-ease); } } @keyframes sprout-record-list-in { from { opacity: .4; } } @media (forced-colors: active) { .sprout-record-list, .sprout-record-list-item, .sprout-record-list-footer { border-color: canvastext; } .sprout-record-list-item:focus-visible { outline-color: highlight; } } .sprout-state-panel { font-family: var(--sprout-font); color: var(--sprout-text); overflow-wrap: anywhere; animation: sprout-state-panel-in var(--sprout-motion-normal, .18s) var(--sprout-motion-ease, ease) both; } .sprout-state-panel[data-layout="centered"] { text-align: center; flex-direction: column; align-items: center; gap: 1.5rem; width: 100%; max-width: 28rem; margin-inline: auto; padding: 3rem 1.5rem; display: flex; } .sprout-state-panel-media { border: 1px solid var(--sprout-line); background: var(--sprout-surface); width: 2.5rem; height: 2.5rem; color: var(--sprout-text); box-shadow: var(--sprout-shadow-control); border-radius: .5rem; flex-shrink: 0; justify-content: center; align-items: center; display: flex; } .sprout-state-panel-media > svg { flex-shrink: 0; } .sprout-state-panel-danger { color: var(--sprout-danger); } .sprout-state-panel-text { gap: .5rem; width: 100%; display: grid; } .sprout-state-panel-title { font-size: var(--sprout-text-base); letter-spacing: normal; color: var(--sprout-text); margin: 0; font-weight: 500; line-height: 1.5; } .sprout-state-panel-description { font-size: var(--sprout-text-sm); color: var(--sprout-muted); margin: 0; line-height: 1.5; } .sprout-state-panel-actions { width: 100%; font-size: var(--sprout-text-sm); color: var(--sprout-muted); flex-direction: column; align-items: center; gap: .75rem; display: flex; } .sprout-state-panel-actions:empty { display: none; } .sprout-state-panel[data-layout="sample"] { width: 100%; container-type: inline-size; } .sprout-state-panel-card { border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-surface); box-shadow: var(--sprout-shadow-control); display: grid; overflow: hidden; } .sprout-state-panel-copy { flex-direction: column; justify-content: center; align-items: flex-start; gap: 1.5rem; min-width: 0; padding: 1.5rem; display: flex; } [data-layout="sample"] .sprout-state-panel-text { max-width: 28rem; } [data-layout="sample"] .sprout-state-panel-title { font-size: 1.25rem; line-height: 1.4; } [data-layout="sample"] .sprout-state-panel-description { font-size: var(--sprout-text-base); } [data-layout="sample"] .sprout-state-panel-actions { align-items: stretch; gap: .5rem; } .sprout-state-panel-sample { border-top: 1px solid var(--sprout-line); background: var(--sprout-canvas); min-height: 15rem; display: none; position: relative; overflow: hidden; } .sprout-state-panel-sample-window { border-top: 1px solid var(--sprout-line); border-left: 1px solid var(--sprout-line); border-top-left-radius: var(--sprout-radius-panel); background: var(--sprout-surface); box-shadow: var(--sprout-shadow-panel); position: absolute; inset: 1.5rem 0 0 1.5rem; overflow: hidden; mask-image: linear-gradient(oklch(0% 0 0) 60%, #0000 100%); } @container (width >= 24rem) { [data-layout="sample"] .sprout-state-panel-actions { flex-flow: wrap; align-items: center; width: auto; } } @container (width >= 28rem) { .sprout-state-panel-sample { display: block; } } @container (width >= 32rem) { .sprout-state-panel-copy { padding: 2.5rem; } } @container (width >= 48rem) { .sprout-state-panel-card { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); } .sprout-state-panel-copy { padding-block: 3.5rem; } .sprout-state-panel-sample { border-top: 0; border-left: 1px solid var(--sprout-line); min-height: 22rem; } } @media (prefers-reduced-motion: reduce) { .sprout-state-panel { animation-name: sprout-state-panel-fade; } } @keyframes sprout-state-panel-fade { from { opacity: 0; } } @keyframes sprout-state-panel-in { from { opacity: 0; transform: translateY(4px); } } }Import it from
@/components/ui/record-list. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/record-list.
- TF-101Seed tray leaks onto the potting bench
- Assignee
- Ana Ruiz
- Due
- Oct 01
- Points
- 1
- Requester
- Robin Hale
OpenUrgent - TF-102Order compost for the north beds
- Assignee
- Chen Wei
- Due
- Oct 08
- Points
- 6
- Requester
- Robin Hale
In progressLow - TF-103Fix the greenhouse vent motor that stops halfway open on cold mornings after the frost alert runs
- Due
- Oct 15
- Points
- 11
- Requester
- Greenhouse operations team, north site, weekend shift
- Site
- Packing shed
BlockedHigh - TF-104Frost alert texts arrive late
- Assignee
- Ben Okafor
- Points
- 3
- Requester
- Robin Hale
- Site
- East field
Done - TF-105Label printer jams on seed packets
- Assignee
- Dara Singh
- Due
- Oct 01
- Requester
- Robin Hale
- Site
- North greenhouse
OpenNormal - TF-106Update the spring market price list
- Assignee
- Ana Ruiz
- Due
- Oct 08
- Points
- 13
- Requester
- Robin Hale
In progressUrgent
Click a row, or focus the list and press Enter, to edit it.
Usage
import { Badge } from "@tulipfarm/sprout/badge";
import { RecordList, type RecordListHandle } from "@tulipfarm/sprout/record-list";
const list = useRef<RecordListHandle>(null);
<RecordList
ref={list}
label="Tickets"
items={page.rows}
status={read.loading ? "loading" : read.failed ? "error" : "ready"}
onRetry={read.retry}
values={(ticket) => [
{ label: "Assignee", value: ticket.assignee },
{ label: "Due", value: ticket.due },
]}
badges={(ticket) => <Badge variant="info">{ticket.status}</Badge>}
renderActions={(ticket) => <TicketActions ticket={ticket} />}
onItemOpen={(ticket) => openSheet(ticket)}
footer={<TicketPagination onPageChange={() => list.current?.focusFirst()} />}
/>items:{ id, title }[]plus your own fields, in page order.titleis plain text. Screen readers use it, and it shows in full on hover.labelnames the list. The row count is added, so screen readers hear “Tickets, 6 rows”.renderTitledraws the title, such as a key before the text. Screen readers still usetitle.valuesreturns{ label, value, text? }[]. Only the first four show; the rest are left out. Leave out empty values before you return them. Usetextfor the hover hint whenvalueis not a string or number.badgesreturns choice badges, such as status and priority. Leave out empty choices.renderActionsis a free slot for row actions, such as an Edit icon button and aDropdownMenu. Clicks in it never open the row. Give each action a name that includes the row.onItemOpenruns on a click anywhere else in the row, or on Enter. A click that ends a text selection does not open the row.footersits under the rows inside the panel. Put yourPaginationthere.density="sm"uses 8px by 12px padding instead of 12px by 16px.
States
status is "ready", "loading", or "error". While a page loads and rows are already shown, they stay in place, dimmed, with aria-busy and a “Loading rows…” announcement. With no rows yet, five skeleton rows hold the space.
"error" replaces the rows with an error state. error is its description, andonRetry adds a Try again button. When items is empty and ready, the list showsempty: pass a StatePanel or text. Without it, the list says “No rows to show”.
<RecordList
label="Tickets"
items={[]}
empty={
<StatePanel kind="empty" heading="h3" title="No rows match" description="No tickets match the current filters.">
<Button variant="outline" onClick={clearFilters}>Clear filters</Button>
</StatePanel>
}
/>Layout
Rows sit in one bordered panel, separated by hairlines. The title is on the first line in 14px medium text. Values follow on the second line as muted label and strong value pairs, with tabular numerals, 16px apart, wrapping as needed. Badges and actions sit on the right.
Long titles cut off after one line. Each value cuts off at 16rem. The full text shows on hover and is always read by screen readers. When the list is 640px wide or less, badges move under the values, actions stay at the top right, and titles wrap to two lines.
Keyboard and focus
- The list is one tab stop. Tab lands on the last focused row, or the first row.
- Up and Down move between rows. Home and End go to the first and last row. Enter opens the row.
- Tab from a row reaches that row's actions, then leaves the list. Actions in other rows are out of the tab order until their row is focused. Clicking an action also makes its row the focused row.
- Menus opened from actions work as usual, and focus returns to their trigger when they close. Shift+Tab from an action goes back to its row.
After a page change, call focusFirst() on the ref so focus does not fall to the page. Whilestatus is "loading", it waits for the new rows, so you can call it from the page button's click handler. With no rows, it focuses the empty or error state.
Accessibility
The list is a named list, and each row is a listitem named by its title. The values and badges describe the row, so screen readers read them after the title. Values are a description list of field and value. Rows have a hover color and an inset focus ring. Rows fade in over 180ms and the dim changes smoothly only when reduced motion is not requested. In forced colors mode the lines use the system text color.
Theme tokens
The panel uses --sprout-surface, --sprout-line, and --sprout-radius-panel. Titles and values use --sprout-text, labels use --sprout-muted, and hover uses--sprout-hover. Focus uses --sprout-focus-ring and --sprout-focus-width. Motion uses --sprout-motion-fast, --sprout-motion-normal, and--sprout-motion-ease.