import React from 'react' import { action } from '@storybook/addon-actions' import { type Meta, type StoryObj } from '@storybook/react' import { Checkbox } from '~components/Checkbox' import { Divider } from '~components/Divider' import { Icon } from '~components/Icon' import { Text } from '~components/Text' import { TableCard, TableContainer, TableHeader, TableHeaderRowCell, TableRow, TableRowCell, type TableCardProps, type TableContainerProps, type TableHeaderRowCellProps, type TableRowCellProps, type TableRowProps, } from '../index' export type TableStoryProps = { container?: TableContainerProps row?: TableRowProps rowCells: TableRowCellProps[] headerRowCells: TableHeaderRowCellProps[] tableCards: TableCardProps[] } const TableTemplate: StoryObj = { render: ({ container, headerRowCells, tableCards, row, rowCells }) => ( {headerRowCells.map((headerRowCellProps, index) => ( ))} {tableCards.map((tableCardProps, index) => ( {rowCells.map(({ children, ...otherProps }, rowCellIndex) => ( {children} ))} {tableCardProps.expanded && ( <> Overall progress )} ))} ), } export default { ...TableTemplate, title: 'Components/Table', parameters: { chromatic: { disable: false }, docs: { source: { type: 'dynamic' }, }, a11y: { config: { rules: [ { // Fixing this in a rebuild id: 'nested-interactive', enabled: false, }, { // Fixing this in a rebuild id: 'aria-required-children', enabled: false, }, { // Fixing this in a rebuild id: 'aria-required-parent', enabled: false, }, ], }, }, }, args: { tableCards: [ { expanded: false, }, { expanded: false, }, ], headerRowCells: [ { labelText: 'Resource name', width: 3 / 12, }, { labelText: 'Supplementary information', width: 3 / 12, }, { labelText: 'Date', width: 3 / 12, }, { labelText: 'Price', width: 3 / 12, }, ], rowCells: [ { width: 3 / 12, children: 'Resource', }, { width: 3 / 12, children: 'Supplementary', }, { width: 3 / 12, children: 'Today', }, { width: 3 / 12, children: '100', }, ], }, decorators: [ (Story) => (
), ], } satisfies Meta export const Playground: StoryObj = { ...TableTemplate, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const Sorting: StoryObj = { ...TableTemplate, parameters: { docs: { source: { type: 'dynamic' }, }, }, args: { headerRowCells: [ { labelText: 'Resource name', sorting: 'ascending', onClick: action('Sort Resource name'), width: 3 / 12, }, { labelText: 'Supplementary information', sorting: 'descending', onClick: action('Sort Supplementary information'), width: 3 / 12, }, { labelText: 'Date', width: 3 / 12, }, { labelText: 'Price', width: 3 / 12, }, ], }, } export const Data: StoryObj = { ...TableTemplate, args: { container: { variant: 'data' } }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const Reversed: StoryObj = { ...TableTemplate, args: { headerRowCells: [ { labelText: 'Resource name', sorting: 'ascending', onClick: action('Sort Resource name by ascending'), width: 3 / 12, reversed: true, }, { labelText: 'Supplementary information', width: 3 / 12, reversed: true, }, { labelText: 'Date', width: 3 / 12, reversed: true, }, { labelText: 'Price', width: 3 / 12, reversed: true, }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, decorators: [ (Story) => (
), ], } export const Compact: StoryObj = { ...TableTemplate, args: { container: { variant: 'compact' } }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const Default: StoryObj = { ...TableTemplate, args: { container: { variant: 'default' } }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const CheckboxVariant: StoryObj = { ...TableTemplate, args: { headerRowCells: [ { checkable: true, onCheck: action('onCheck header-1'), checkboxLabel: 'Select all Employees', labelText: 'Employee', width: 5 / 12, }, { labelText: 'Job title', width: 3 / 12, }, { labelText: 'Date', width: 2 / 12, }, { labelText: 'Score', width: 2 / 12, }, ], rowCells: [ { width: 5 / 12, children: ( Employee name ), }, { width: 3 / 12, children: 'Engineer', }, { width: 2 / 12, children: 'Today', }, { width: 2 / 12, children: '100', }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const LinkVariant: StoryObj = { ...TableTemplate, args: { tableCards: [{ href: '#?foo=bar' }, { href: '#?bar=foo' }] }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const IconVariant: StoryObj = { ...TableTemplate, args: { headerRowCells: [ { icon: , labelText: 'Resource name', width: 3 / 12, }, { icon: , labelText: 'Supplementary information', width: 3 / 12, }, { labelText: 'Date', width: 3 / 12, }, { labelText: 'Price', width: 3 / 12, }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const Expandable: StoryObj = { ...TableTemplate, args: { tableCards: [ { expanded: true, expandedStyle: 'popout', onClick: action('Set expanded to false'), }, { expanded: false, }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const HeaderAlignmentAndWrapping: StoryObj = { ...TableTemplate, args: { headerRowCells: [ { labelText: 'Header align start with wrapping', wrapping: 'wrap', align: 'start', }, { labelText: 'Default alignment', width: 3 / 12, }, { labelText: 'Header center', align: 'center', width: 3 / 12, }, { labelText: 'Header align with end with wrapping', wrapping: 'wrap', align: 'end', width: 3 / 12, }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, } export const Tooltip: StoryObj = { ...TableTemplate, args: { headerRowCells: [ { labelText: 'Resource name', tooltipInfo: 'Sort this by ascending', sorting: 'ascending', onClick: action('Sort Resource name by ascending'), width: 3 / 12, }, { labelText: 'Supplementary information', width: 3 / 12, }, { labelText: 'Date', width: 3 / 12, }, { labelText: 'Price', width: 3 / 12, }, ], }, parameters: { docs: { source: { type: 'dynamic' }, }, }, }