import React from 'react' import { Story, Meta } from '@storybook/react' import { Table, TableProps } from './Table' import { Icon } from '../../Icons' import { Button } from '../Button' const Link = (props: any) => { return ( {props.children} ) } const columns = [ { id: 'Name', label: 'Name', cellWrapper: Link, }, { id: 'Address', label: 'Address', cellWrapper: Link, }, { id: 'Price', label: KA, textAlign: 'center', size: 'w-1/6', cellWrapper: Link, }, { id: 'Count', label: 'Count', size: 'w-1/6', cellWrapper: Link, }, { id: 'Active', label: 'Active', size: 'w-1/6', textAlign: 'center', }, { id: 'Actions', label: 'Actions', size: 'w-16', textAlign: 'center', }, ] const rows = [ { id: 1, Name: 'Example Test', Address: 'Street of Test', Count: 245, Price: (
$ 2399.00
$ 2299.00
), Active: , Actions:
, cellWrapperProps: { page: 'admin/settings/view', params: { file_name: 1 } }, }, { id: 2, Name: 'Last Test', Address: 'LongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLong Text', Price: ( 24
), Active: , Actions:
, bgColor: 'danger-light', cellWrapperProps: { page: 'admin/settings/view', params: { file_name: 2 } }, }, { id: 3, Name: 'Example Test', Address: 'Street of Test', Count: 245, Price: (
$ 2399.00
), Active: , Actions:
, cellWrapperProps: { page: 'admin/settings/view', params: { file_name: 3 } }, }, { id: 4, Name: 'Last Test', Address: 'Just a big street', Price: ( 24
), Active: , Actions:
, bgColor: 'success-light', cellWrapperProps: { page: 'admin/settings/view', params: { file_name: 4 } }, }, ] export default { title: 'Components/Table', component: Table, args: { columns: columns, rows: rows, selectable: false, onChange: (selectedData: number[]) => { console.log('Selected rows data: ', selectedData) }, }, argTypes: { emptyText: { control: { type: 'text' }, }, }, parameters: { layout: 'padded', }, } as Meta const Template: Story = (args) => export const Default = Template.bind({}) export const Loading = Template.bind({}) Loading.args = { isLoading: true, } export const Empty = Template.bind({}) Empty.args = { rows: undefined, } export const Selectable = Template.bind({}) Selectable.args = { selectable: true, onChange: (selectedRows) => { console.log(selectedRows) }, } const CustomStateTemplate: Story = (args) => { const [selectedData, setSelectedData] = React.useState( args.selectedData || [] ) React.useEffect(() => { setSelectedData(args.selectedData || []) }, []) return (
Selected rows: {JSON.stringify(selectedData)}
{ const mapped = selectedRows.map((element) => element.index) setSelectedData(mapped) }} >
) } export const SelectedData = CustomStateTemplate.bind({}) SelectedData.args = { selectable: true, disabledRows: [0], selectedData: [1], }