import type { Meta, StoryObj } from '@storybook/react' import { useState } from 'react' import { Button, Typography } from '../../components' import { usePlaceholderRows } from './usePlaceholderRows' const meta: Meta = { title: 'Hooks/usePlaceholderRows', } export default meta type MockData = { id: number; name: string } const mockData: MockData[] = [ { id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, { id: 3, name: 'Item 3' }, ] export const Default: StoryObj = { render: function PlaceholderRowsDemo() { const [isLoading, setIsLoading] = useState(true) const tableData = usePlaceholderRows({ data: mockData, isLoading, pageSize: 5, }) return (
usePlaceholderRows Demo Toggle loading state to see placeholder rows vs actual data.
{tableData.data.map((row, index) => ( ))}
ID Name
{tableData.isLoading ? (
) : ( (row as MockData).id )}
{tableData.isLoading ? (
) : ( (row as MockData).name )}
Rows: {tableData.data.length} | Loading: {String(tableData.isLoading)}
) }, } export const WithCustomCount: StoryObj = { render: function CustomPlaceholderCount() { const [isLoading, setIsLoading] = useState(true) const tableData = usePlaceholderRows({ data: [] as MockData[], isLoading, placeholderCount: 3, }) return (
Custom Placeholder Count Using placeholderCount to override the default behavior.
{tableData.data.map((_, index) => (
))}
Always shows exactly 3 placeholder rows when loading.
) }, }