Skip to content

Commit

Permalink
feat: documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasdano committed May 14, 2024
1 parent b3b6d0a commit fa668a1
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
1 change: 1 addition & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const preview: SBPreview = {
chromatic: { delay: 2000 },
viewMode: 'docs',
docs: {
source: { type: 'code' },
story: {
inline: true,
},
Expand Down
23 changes: 22 additions & 1 deletion src/components/Table/Table.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Meta, Canvas, ArgTypes } from '@storybook/blocks';
import Table from './Table';
import * as TableStories from './Table.stories';
import { DisplayColumnStory, ColumnsConfigStory } from './utils/TableStoryComponents';
import {
DisplayColumnStory,
ColumnsConfigStory,
RowsConfigStory,
} from './utils/TableStoryComponents';

<Meta of={TableStories} />

Expand Down Expand Up @@ -33,6 +37,12 @@ This type includes all the configuration for the columns

<ArgTypes of={ColumnsConfigStory} />

## RowsConfig Type

This type includes all the configuration for the rows

<ArgTypes of={RowsConfigStory} />

<SubsectionHeader title="Variants" />

### Column and Row Sizing
Expand Down Expand Up @@ -62,3 +72,14 @@ This type includes all the configuration for the columns
</Tip>

<Canvas of={TableStories.StickyHeader} />

### Row Selection

In order to enable row Selection, do the following steps:

- Use prop `type` = `interactive`.
- Use the `rowsConfig` object prop and more specificaly `rowSelection` and `setRowSelection` keys. The `rowSelection` is an object where the key is the row index (from 0 to rows.length - 1) and value is a boolean indicating if the row is selected. Check the implementation below for more clientInformation.

You can also pass a `defaultAction` and/or `bulkActions` inside the `rowsConfig`, which are visible once at least 1 row is selected.

<Canvas of={TableStories.RowSelection} />
57 changes: 57 additions & 0 deletions src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SimpleData, moreData, simpleColumns, simpleData } from './constants';
import Typography from 'components/Typography';
import { SortingState } from '@tanstack/react-table';
import { concat } from 'lodash';
import Button from 'components/Button';
import DropdownButton from 'components/DropdownButton';

export default {
title: 'Updated Components/Table/Table',
Expand Down Expand Up @@ -211,3 +213,58 @@ export const StickyHeader = {
},
},
};

export const RowSelection = {
render: (args) => {
const { rowSize } = args;

const [rowSelection, setRowSelection] = useState<Record<number, boolean>>({
1: true,
5: true,
7: true,
});

return (
<Table<SimpleData>
data={concat(simpleData, moreData)}
columns={simpleColumns}
rowSize={rowSize}
type="interactive"
rowsConfig={{
rowSelection,
setRowSelection,
defaultAction: <Button size="compact">Default Action</Button>,
bulkActions: (
<div
css={{
display: 'flex',
alignContent: 'center',
justifyContent: 'center',
gap: '8px',
}}
>
<Button size="compact">Bulk 1</Button>
<Button size="compact">Bulk 2</Button>
<DropdownButton
size="compact"
items={['Bulk 4', 'Bulk 5', 'Bulk 6']}
onButtonClick={() => console.log('click')}
onOptionSelect={() => console.log('option')}
>
Bulk 3
</DropdownButton>
</div>
),
}}
/>
);
},

name: 'Row Selection',

parameters: {
controls: {
include: ['Row Size'],
},
},
};
5 changes: 4 additions & 1 deletion src/components/Table/utils/TableStoryComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type React from 'react';

import type { ColumnsConfig, DisplayColumn, GroupColumn, TableData } from '../types';
import type { ColumnsConfig, DisplayColumn, GroupColumn, TableData, RowsConfig } from '../types';

/** This is just a dummy component to be used in Storybook for showing the Row type on props */
export const ColumnsConfigStory: React.FC<ColumnsConfig> = () => null;
Expand All @@ -11,5 +11,8 @@ export const GroupColumnStory: React.FC<GroupColumn> = () => null;
/** This is just a dummy component to be used in Storybook for showing the Row type on props */
export const DisplayColumnStory: React.FC<DisplayColumn> = () => null;

/** This is just a dummy component to be used in Storybook for showing the Row type on props */
export const RowsConfigStory: React.FC<RowsConfig> = () => null;

/** This is just a dummy component to be used in Storybook for showing the Cell type on props */
export const TableDataStory: React.FC<TableData<any>> = () => null;

0 comments on commit fa668a1

Please sign in to comment.