import React from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; import { Table } from '../Table/Table'; import { TableBody } from '../TableBody/TableBody'; import { TableHeader } from '../TableHeader/TableHeader'; import { TableHeaderCell } from '../TableHeaderCell/TableHeaderCell'; import { TableRow } from '../TableRow/TableRow'; import type { TableCellType } from '../types'; import { TableCell } from './TableCell'; const typeOptions: Record = { actions: 'actions', attention: 'attention', balance: 'balance', calloutActions: 'calloutActions', datetime: 'datetime', headline: 'headline', image: 'image', imageBig: 'imageBig', large: 'large', massAction: 'massAction', medium: 'medium', number: 'number', preview: 'preview', price: 'price', pricePrimary: 'pricePrimary', small: 'small', stickyEnd: 'stickyEnd', stickyStart: 'stickyStart', summary: 'summary', }; function range(start: number, end: number): Array { return Array.from({ length: end - start }, (_, i) => start + i); } const meta: Meta = { title: 'UI kit/Table/TableCell', component: TableCell, tags: ['autodocs'], argTypes: { type: { control: 'select', options: Object.values(typeOptions).map(type => type), }, }, parameters: { count: 4, }, decorators: [ (Story, { args, parameters: { count } }) => { if (typeof count !== 'number') { throw new TypeError('TableCell stories require "count" parameter to be set to a number.'); } args.colspan = typeof args.colspan === 'number' && args.colspan >= 1 ? args.colspan : undefined; args.rowspan = typeof args.rowspan === 'number' && args.rowspan >= 1 ? args.rowspan : undefined; return ( {range(1, count + 1).map(i => ( {`Header cell ${i}`} ))} {range(2, count + 1).map( i => (!args.colspan || args.colspan < i) && {`Row 1, body cell ${i}`} )} {typeof args.rowspan === 'number' && args.rowspan > 1 && range(1, args.rowspan).map(rowIndex => ( {range(2, count + 1).map( i => (!args.colspan || args.colspan < i) && ( {`Row ${rowIndex + 1}, body cell ${i}`} ) )} ))} {range(1, Math.max(0, 4 - (args.rowspan ?? 1)) + 1).map(rowIndex => ( {range(1, count + 1).map(i => ( {`Row ${rowIndex + (args.rowspan ?? 1)}, body cell ${i}`} ))} ))}
); }, ], }; export default meta; type Story = StoryObj; export const Default: Story = { args: { children: 'Row 1, body cell 1', }, }; export const StickyStart: Story = { args: { type: 'stickyStart', children: 'Sticky start header cell', }, parameters: { count: 48, }, };