Skip to content

Commit

Permalink
feat: documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kostasdano committed Apr 29, 2024
1 parent 7e20426 commit eb90b19
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/Table/Table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ This type includes all the configuration for the columns
### Sorting

<Canvas of={TableStories.Sorting} />

### Sticky Header

<Tip>
In order to create a table with sticky header, use the hasStickyHeader prop and also pass a
max-height for the tbody though the sx prop
</Tip>

<Canvas of={TableStories.StickyHeader} />
29 changes: 28 additions & 1 deletion src/components/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState } from 'react';
import Table from './Table';
import { SimpleData, simpleColumns, simpleData } from './constants';
import { SimpleData, moreData, simpleColumns, simpleData } from './constants';
import Typography from 'components/Typography';
import { SortingState } from '@tanstack/react-table';
import { concat } from 'lodash';

export default {
title: 'Updated Components/Table/Table',
Expand All @@ -11,6 +12,7 @@ export default {
args: {
rowSize: 'sm',
isMultiSortable: false,
maxHeight: 280,
},

argTypes: {
Expand All @@ -20,6 +22,7 @@ export default {
ageWidth: { control: 'number', name: 'Age Width' },
jobWidth: { control: 'number', name: 'Job Width' },
rowSize: { name: 'Row Size' },
maxHeight: { name: 'Tbody Max height' },
},
};

Expand Down Expand Up @@ -180,3 +183,27 @@ export const Sorting = {
},
},
};

export const StickyHeader = {
render: (args) => {
const { rowSize, maxHeight } = args;

return (
<Table<SimpleData>
data={concat(simpleData, moreData)}
columns={simpleColumns}
rowSize={rowSize}
hasStickyHeader
sx={{ tbody: { maxHeight: `${maxHeight}px` } }}
/>
);
},

name: 'Sticky Header',

parameters: {
controls: {
include: ['Row Size', 'Tbody Max height'],
},
},
};
75 changes: 75 additions & 0 deletions src/components/Table/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,78 @@ export const simpleData = [
},
},
];

export const moreData = [
{
cells: {
firstName: 'Gunther',
lastName: 'N/A',
age: '35',
job: 'Central Perk Manager',
},
},
{
cells: {
firstName: 'Janice',
lastName: 'Litman-Foralnik',
age: '35',
job: 'Personal Shopper',
},
},
{
cells: {
firstName: 'Richard',
lastName: 'Burke',
age: '50',
job: 'Ophthalmologist',
},
},
{
cells: {
firstName: 'Estelle',
lastName: 'Leonard',
age: 'N/A',
job: 'Talent Agent',
},
},
{
cells: {
firstName: 'Mike',
lastName: 'Hannigan',
age: '31',
job: 'N/A',
},
},
{
cells: {
firstName: 'Charlie',
lastName: 'Wheeler',
age: '28',
job: 'Paleontologist',
},
},
{
cells: {
firstName: 'Emily',
lastName: 'Waltham',
age: '28',
job: 'N/A',
},
},
{
cells: {
firstName: 'Carol',
lastName: 'Willick',
age: '35',
job: 'N/A',
},
},
{
cells: {
firstName: 'Frank',
lastName: 'Buffay Jr.',
age: '29',
job: 'N/A',
},
},
];

0 comments on commit eb90b19

Please sign in to comment.