Skip to content

Commit 2faf23b

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

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.changeset/yummy-ends-knock.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@zenml-io/react-component-library": minor
3+
---
4+
5+
port full functionality of DataTable component from pro

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)