Skip to content

Commit 1b28f7f

Browse files
committed
showcase sorting & custom icon injection
1 parent 1694673 commit 1b28f7f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/components/Table/DataTable.stories.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Meta } from "@storybook/react";
22
import { StoryObj } from "@storybook/react";
33
import React, { useState } from "react";
4-
import { DataTable } from "./index";
5-
import { ColumnDef, RowSelectionState } from "@tanstack/react-table";
4+
import { DataTable, injectSortingArrowIcons } from "./index";
5+
import { ColumnDef, RowSelectionState, SortingState } from "@tanstack/react-table";
66
import { Checkbox } from "../Checkbox";
77

88
type DummyData = {
@@ -92,8 +92,23 @@ export const CustomizedVariant: Story = {
9292
}
9393
};
9494

95+
injectSortingArrowIcons({
96+
ArrowUp: () => <div></div>,
97+
ArrowDown: () => <div></div>
98+
});
99+
95100
const CustomizedDataTable = () => {
96101
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
102+
const [sorting, setSorting] = useState<SortingState>([
103+
{
104+
id: "name",
105+
desc: true
106+
},
107+
{
108+
id: "age",
109+
desc: false
110+
}
111+
]);
97112

98113
return (
99114
<div>
@@ -103,6 +118,8 @@ const CustomizedDataTable = () => {
103118
getRowId={(x) => x.id.toString()}
104119
rowSelection={rowSelection}
105120
onRowSelectionChange={setRowSelection}
121+
sorting={sorting}
122+
onSortingChange={setSorting}
106123
/>
107124

108125
<div className="mt-4">
@@ -146,11 +163,13 @@ const colsCustomized: ColumnDef<DummyData, unknown>[] = [
146163
{
147164
id: "name",
148165
header: "Name",
149-
accessorKey: "name"
166+
accessorKey: "name",
167+
enableSorting: true
150168
},
151169
{
152170
id: "age",
153171
header: "Age",
154-
accessorKey: "age"
172+
accessorKey: "age",
173+
enableSorting: true
155174
}
156175
];

0 commit comments

Comments
 (0)