Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Be a good samaritan and create stories
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Sep 13, 2023
1 parent a142dce commit 2f859f3
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/components/Table/BaseTable.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useRef } from "react";
import { LGColumnDef, useLeafyGreenTable } from "@leafygreen-ui/table/new";
import { CustomStoryObj, CustomMeta } from "test_utils/types";

import { BaseTable } from "./BaseTable";

export default {
component: BaseTable,
} satisfies CustomMeta<typeof BaseTable>;

export const Default: CustomStoryObj<typeof BaseTable> = {
render: (args) => <TemplateComponent {...args} data={fullArray} />,
args: {
shouldAlternateRowColor: true,
darkMode: false,
},
};

export const EmptyState: CustomStoryObj<typeof BaseTable> = {
render: (args) => <TemplateComponent {...args} data={[]} />,
args: {
shouldAlternateRowColor: true,
darkMode: false,
},
};
interface DataShape {
name: string;
column1: string;
column2: string;
}
const fullArray: DataShape[] = Array.from({ length: 100 }, (_, i) => ({
name: `name ${i}`,
column1: `column1 ${i}`,
column2: `column2 ${i}`,
}));
const columns: LGColumnDef<DataShape>[] = [
{
accessorKey: "name",
header: "Name",
size: 60,
enableSorting: true,
},
{
accessorKey: "column1",
header: "Column 1",
size: 60,
enableSorting: true,
},
{
accessorKey: "column2",
header: "Column 2",
size: 60,
enableSorting: true,
},
];

const TemplateComponent: React.FC<
React.ComponentProps<typeof BaseTable> & {
data: DataShape[];
}
> = (args) => {
const { data, ...rest } = args;
const tableContainerRef = useRef<HTMLDivElement>(null);
const table = useLeafyGreenTable<DataShape>({
data,
columns,
containerRef: tableContainerRef,
});

return <BaseTable {...rest} table={table} />;
};

0 comments on commit 2f859f3

Please sign in to comment.