import type { Meta, StoryObj } from '@storybook/react-vite'; import { VirtualList } from './virtual-list'; import { Avatar, AvatarFallback } from '../avatar/avatar'; type Row = { id: number; name: string; email: string }; const rows: Row[] = Array.from({ length: 10000 }, (_, index) => ({ id: index, name: `Person ${index + 1}`, email: `person${index + 1}@example.com`, })); const meta = { title: 'Components/VirtualList', parameters: { layout: 'centered', docs: { description: { component: 'Windowed list: only the rows in view are mounted. Reach for it past a few hundred rows, where mounting everything makes scrolling stutter. Below that a plain `map` is simpler and behaves better with find-in-page, which cannot see unmounted rows. Rows must all be the same `itemHeight`.', }, }, }, tags: ['autodocs'], } satisfies Meta; export default meta; type Story = StoryObj; /** Ten thousand rows; the DOM holds roughly a dozen at a time. */ export const TenThousandRows: Story = { render: () => (
{(row) => (
{row.name} #{row.id}
)}
), }; export const RichRows: Story = { render: () => (
{(row) => (
{row.name.slice(7, 9)}
{row.name}
{row.email}
)}
), };