@bsol-oss/react-datatable5 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -3
- package/dist/types/components/DataTable.d.ts +17 -0
- package/dist/types/components/DataTableContext.d.ts +8 -0
- package/dist/types/components/EditFilterButton.d.ts +2 -0
- package/dist/types/components/EditSortingButton.d.ts +2 -0
- package/dist/types/components/EditViewButton.d.ts +2 -0
- package/dist/types/components/PageSizeControl.d.ts +5 -0
- package/dist/types/components/ResetFilteringButton.d.ts +2 -0
- package/dist/types/components/ResetSortingButton.d.ts +2 -0
- package/dist/types/components/Table.d.ts +6 -0
- package/dist/types/components/TableBody.d.ts +2 -0
- package/dist/types/components/TableCardContainer.d.ts +6 -0
- package/dist/types/components/TableCards.d.ts +2 -0
- package/dist/types/components/TableFilter.d.ts +2 -0
- package/dist/types/components/TableFooter.d.ts +2 -0
- package/dist/types/components/TableHeader.d.ts +5 -0
- package/dist/types/components/TablePagination.d.ts +4 -0
- package/dist/types/components/TableSorter.d.ts +2 -0
- package/dist/types/components/TextCell.d.ts +2 -0
- package/dist/types/components/useDataFromUrl.d.ts +13 -0
- package/dist/types/components/useDataTable.d.ts +4 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/stories/CardViewShowcase.d.ts +2 -0
- package/dist/types/stories/DataTable.stories.d.ts +13 -0
- package/dist/types/stories/TableViewShowcase.d.ts +2 -0
- package/package.json +8 -1
- package/src/components/DataTable.tsx +23 -8
- package/src/components/DataTableContext.tsx +2 -3
- package/src/components/Table.tsx +1 -1
- package/src/components/TableHeader.tsx +1 -1
- package/src/components/TablePagination.tsx +3 -2
- package/src/stories/DataTable.stories.tsx +14 -41
- package/tsconfig.json +3 -2
- package/src/components/ChakraDataTable.tsx +0 -279
- package/src/stories/Button.stories.ts +0 -52
- package/src/stories/Button.tsx +0 -52
- package/src/stories/Configure.mdx +0 -369
- package/src/stories/DataTable-test.stories.tsx +0 -83
- package/src/stories/DefaultDataTable.tsx +0 -141
- package/src/stories/Header.stories.ts +0 -33
- package/src/stories/Header.tsx +0 -71
- package/src/stories/Page.stories.ts +0 -32
- package/src/stories/Page.tsx +0 -91
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -5
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -15
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -3
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -12
- package/src/stories/assets/youtube.svg +0 -4
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/page.css +0 -69
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Box,
|
|
3
|
-
Button,
|
|
4
|
-
Checkbox,
|
|
5
|
-
Flex,
|
|
6
|
-
FormControl,
|
|
7
|
-
Grid,
|
|
8
|
-
Popover,
|
|
9
|
-
PopoverArrow,
|
|
10
|
-
PopoverBody,
|
|
11
|
-
PopoverContent,
|
|
12
|
-
PopoverTrigger,
|
|
13
|
-
Table,
|
|
14
|
-
Tbody,
|
|
15
|
-
Td,
|
|
16
|
-
Tfoot,
|
|
17
|
-
Th,
|
|
18
|
-
Thead,
|
|
19
|
-
Tr,
|
|
20
|
-
Text,
|
|
21
|
-
Input,
|
|
22
|
-
} from "@chakra-ui/react";
|
|
23
|
-
import { Table as ITable, flexRender } from "@tanstack/react-table";
|
|
24
|
-
// import React, { useRef } from "react";
|
|
25
|
-
import React, { CSSProperties } from "react";
|
|
26
|
-
import {
|
|
27
|
-
Column,
|
|
28
|
-
ColumnDef,
|
|
29
|
-
getCoreRowModel,
|
|
30
|
-
useReactTable,
|
|
31
|
-
} from "@tanstack/react-table";
|
|
32
|
-
|
|
33
|
-
interface ChakraDataTable<T> {
|
|
34
|
-
table: ITable<T>;
|
|
35
|
-
hasFooter: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const getCommonPinningStyles = (column: Column<any>): CSSProperties => {
|
|
39
|
-
const isPinned = column.getIsPinned();
|
|
40
|
-
const isLastLeftPinnedColumn =
|
|
41
|
-
isPinned === "left" && column.getIsLastColumn("left");
|
|
42
|
-
const isFirstRightPinnedColumn =
|
|
43
|
-
isPinned === "right" && column.getIsFirstColumn("right");
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
boxShadow: isLastLeftPinnedColumn
|
|
47
|
-
? "-4px 0 4px -4px gray inset"
|
|
48
|
-
: isFirstRightPinnedColumn
|
|
49
|
-
? "4px 0 4px -4px gray inset"
|
|
50
|
-
: undefined,
|
|
51
|
-
left: isPinned === "left" ? `${column.getStart("left")}px` : undefined,
|
|
52
|
-
right: isPinned === "right" ? `${column.getAfter("right")}px` : undefined,
|
|
53
|
-
opacity: isPinned ? 0.95 : 1,
|
|
54
|
-
position: isPinned ? "sticky" : "relative",
|
|
55
|
-
width: column.getSize(),
|
|
56
|
-
zIndex: isPinned ? 1 : 0,
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const ChakraDataTable = <T,>({
|
|
61
|
-
table,
|
|
62
|
-
hasFooter,
|
|
63
|
-
refreshData,
|
|
64
|
-
}: ChakraDataTable<T>) => {
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<Flex justifyContent={"flex-end"}>
|
|
68
|
-
{JSON.stringify(table.getState().sorting)}
|
|
69
|
-
<Button
|
|
70
|
-
onClick={() => {
|
|
71
|
-
table.resetSorting();
|
|
72
|
-
}}
|
|
73
|
-
>
|
|
74
|
-
Reset Sorting
|
|
75
|
-
</Button>
|
|
76
|
-
<Popover placement="bottom-end">
|
|
77
|
-
<PopoverTrigger>
|
|
78
|
-
<Button>Edit View</Button>
|
|
79
|
-
</PopoverTrigger>
|
|
80
|
-
<PopoverContent width={"auto"}>
|
|
81
|
-
<PopoverArrow />
|
|
82
|
-
<PopoverBody>
|
|
83
|
-
<Flex flexFlow={"column"} gap={"1rem"}>
|
|
84
|
-
{table.getAllLeafColumns().map((column) => {
|
|
85
|
-
return (
|
|
86
|
-
<FormControl key={crypto.randomUUID()} width={"auto"}>
|
|
87
|
-
<Checkbox
|
|
88
|
-
isChecked={column.getIsVisible()}
|
|
89
|
-
onChange={column.getToggleVisibilityHandler()}
|
|
90
|
-
>
|
|
91
|
-
{column.id}
|
|
92
|
-
</Checkbox>
|
|
93
|
-
</FormControl>
|
|
94
|
-
);
|
|
95
|
-
})}
|
|
96
|
-
</Flex>
|
|
97
|
-
</PopoverBody>
|
|
98
|
-
</PopoverContent>
|
|
99
|
-
</Popover>
|
|
100
|
-
</Flex>
|
|
101
|
-
{table.getLeafHeaders().map((header) => {
|
|
102
|
-
return (
|
|
103
|
-
<>
|
|
104
|
-
{header.column.getCanFilter() && (
|
|
105
|
-
<>
|
|
106
|
-
<Text>{header.column.id}</Text>
|
|
107
|
-
<Input
|
|
108
|
-
value={header.column.getFilterValue()}
|
|
109
|
-
onChange={(e) => {
|
|
110
|
-
header.column.setFilterValue(e.target.value);
|
|
111
|
-
}}
|
|
112
|
-
/>
|
|
113
|
-
<Button
|
|
114
|
-
onClick={() => {
|
|
115
|
-
refreshData();
|
|
116
|
-
}}
|
|
117
|
-
>
|
|
118
|
-
Filter
|
|
119
|
-
</Button>
|
|
120
|
-
</>
|
|
121
|
-
)}
|
|
122
|
-
</>
|
|
123
|
-
);
|
|
124
|
-
})}
|
|
125
|
-
|
|
126
|
-
<Grid overflowX={"scroll"} overflowY={"auto"}>
|
|
127
|
-
<Table variant="simple">
|
|
128
|
-
<Thead>
|
|
129
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
130
|
-
<Tr key={crypto.randomUUID()} style={{ columnSpan: "all" }}>
|
|
131
|
-
{headerGroup.headers.map((header) => {
|
|
132
|
-
return (
|
|
133
|
-
<Th
|
|
134
|
-
key={crypto.randomUUID()}
|
|
135
|
-
colSpan={header.colSpan}
|
|
136
|
-
width={`${header.getSize()}px`}
|
|
137
|
-
style={{ ...getCommonPinningStyles(header.column) }}
|
|
138
|
-
>
|
|
139
|
-
{header.isPlaceholder
|
|
140
|
-
? null
|
|
141
|
-
: flexRender(
|
|
142
|
-
header.column.columnDef.header,
|
|
143
|
-
header.getContext(),
|
|
144
|
-
)}
|
|
145
|
-
{header.column.getCanSort() && (
|
|
146
|
-
<>
|
|
147
|
-
<Button
|
|
148
|
-
onClick={(e) => {
|
|
149
|
-
const func =
|
|
150
|
-
header.column.getToggleSortingHandler();
|
|
151
|
-
if (func === undefined) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
func(e);
|
|
155
|
-
}}
|
|
156
|
-
>
|
|
157
|
-
Toggle Sort
|
|
158
|
-
</Button>
|
|
159
|
-
<Text>
|
|
160
|
-
{header.column.getIsSorted()
|
|
161
|
-
? "Sorted"
|
|
162
|
-
: "Not Sort"}
|
|
163
|
-
</Text>
|
|
164
|
-
{header.column.getNextSortingOrder() === false && (
|
|
165
|
-
<Text>To No sort</Text>
|
|
166
|
-
)}
|
|
167
|
-
{header.column.getNextSortingOrder() === "asc" && (
|
|
168
|
-
<Text>To asc</Text>
|
|
169
|
-
)}
|
|
170
|
-
{header.column.getNextSortingOrder() === "desc" && (
|
|
171
|
-
<Text>To desc</Text>
|
|
172
|
-
)}
|
|
173
|
-
</>
|
|
174
|
-
)}
|
|
175
|
-
|
|
176
|
-
{header.column.getIsFiltered() ? (
|
|
177
|
-
<Text>Filtered</Text>
|
|
178
|
-
) : (
|
|
179
|
-
<Text>Not Filtered</Text>
|
|
180
|
-
)}
|
|
181
|
-
<Box
|
|
182
|
-
padding={"1rem 0"}
|
|
183
|
-
borderRight={
|
|
184
|
-
header.column.getIsResizing()
|
|
185
|
-
? "1rem solid black"
|
|
186
|
-
: "0.5rem solid grey"
|
|
187
|
-
}
|
|
188
|
-
{...{
|
|
189
|
-
onDoubleClick: () => header.column.resetSize(),
|
|
190
|
-
onMouseDown: header.getResizeHandler(),
|
|
191
|
-
onTouchStart: header.getResizeHandler(),
|
|
192
|
-
}}
|
|
193
|
-
/>
|
|
194
|
-
{}
|
|
195
|
-
</Th>
|
|
196
|
-
);
|
|
197
|
-
})}
|
|
198
|
-
</Tr>
|
|
199
|
-
))}
|
|
200
|
-
</Thead>
|
|
201
|
-
<Tbody>
|
|
202
|
-
{table.getRowModel().rows.map((row) => (
|
|
203
|
-
<Tr key={crypto.randomUUID()}>
|
|
204
|
-
{row.getVisibleCells().map((cell) => (
|
|
205
|
-
<Td
|
|
206
|
-
key={crypto.randomUUID()}
|
|
207
|
-
width={`${cell.column.getSize()}px`}
|
|
208
|
-
>
|
|
209
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
210
|
-
</Td>
|
|
211
|
-
))}
|
|
212
|
-
</Tr>
|
|
213
|
-
))}
|
|
214
|
-
</Tbody>
|
|
215
|
-
{hasFooter && (
|
|
216
|
-
<Tfoot>
|
|
217
|
-
{table.getFooterGroups().map((footerGroup) => (
|
|
218
|
-
<Tr key={crypto.randomUUID()}>
|
|
219
|
-
{footerGroup.headers.map((header) => (
|
|
220
|
-
<Th key={crypto.randomUUID()} colSpan={header.colSpan}>
|
|
221
|
-
{header.isPlaceholder
|
|
222
|
-
? null
|
|
223
|
-
: flexRender(
|
|
224
|
-
header.column.columnDef.footer,
|
|
225
|
-
header.getContext(),
|
|
226
|
-
)}
|
|
227
|
-
</Th>
|
|
228
|
-
))}
|
|
229
|
-
</Tr>
|
|
230
|
-
))}
|
|
231
|
-
</Tfoot>
|
|
232
|
-
)}
|
|
233
|
-
</Table>
|
|
234
|
-
</Grid>
|
|
235
|
-
<Flex>
|
|
236
|
-
<Button
|
|
237
|
-
onClick={() => table.firstPage()}
|
|
238
|
-
disabled={!table.getCanPreviousPage()}
|
|
239
|
-
>
|
|
240
|
-
{"<<"}
|
|
241
|
-
</Button>
|
|
242
|
-
<Button
|
|
243
|
-
onClick={() => table.previousPage()}
|
|
244
|
-
disabled={!table.getCanPreviousPage()}
|
|
245
|
-
>
|
|
246
|
-
{"<"}
|
|
247
|
-
</Button>
|
|
248
|
-
<Text>{table.getState().pagination.pageIndex + 1}</Text>
|
|
249
|
-
|
|
250
|
-
<Button
|
|
251
|
-
onClick={() => table.nextPage()}
|
|
252
|
-
disabled={!table.getCanNextPage()}
|
|
253
|
-
>
|
|
254
|
-
{">"}
|
|
255
|
-
</Button>
|
|
256
|
-
<Button
|
|
257
|
-
onClick={() => table.lastPage()}
|
|
258
|
-
disabled={!table.getCanNextPage()}
|
|
259
|
-
>
|
|
260
|
-
{">>"}
|
|
261
|
-
</Button>
|
|
262
|
-
<select
|
|
263
|
-
value={table.getState().pagination.pageSize}
|
|
264
|
-
onChange={(e) => {
|
|
265
|
-
table.setPageSize(Number(e.target.value));
|
|
266
|
-
}}
|
|
267
|
-
>
|
|
268
|
-
{[10, 20, 30, 40, 50].map((pageSize) => (
|
|
269
|
-
<option key={pageSize} value={pageSize}>
|
|
270
|
-
{pageSize}
|
|
271
|
-
</option>
|
|
272
|
-
))}
|
|
273
|
-
</select>
|
|
274
|
-
</Flex>
|
|
275
|
-
</>
|
|
276
|
-
);
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
export default ChakraDataTable;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
-
import { fn } from "@storybook/test";
|
|
3
|
-
import { Button } from "./Button";
|
|
4
|
-
|
|
5
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
6
|
-
const meta = {
|
|
7
|
-
title: "Example/Button",
|
|
8
|
-
component: Button,
|
|
9
|
-
parameters: {
|
|
10
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
11
|
-
layout: "centered",
|
|
12
|
-
},
|
|
13
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
14
|
-
tags: ["autodocs"],
|
|
15
|
-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
16
|
-
argTypes: {
|
|
17
|
-
backgroundColor: { control: "color" },
|
|
18
|
-
},
|
|
19
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
20
|
-
args: { onClick: fn() },
|
|
21
|
-
} satisfies Meta<typeof Button>;
|
|
22
|
-
|
|
23
|
-
export default meta;
|
|
24
|
-
type Story = StoryObj<typeof meta>;
|
|
25
|
-
|
|
26
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
27
|
-
export const Primary: Story = {
|
|
28
|
-
args: {
|
|
29
|
-
primary: true,
|
|
30
|
-
label: "Button",
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const Secondary: Story = {
|
|
35
|
-
args: {
|
|
36
|
-
label: "Button",
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Large: Story = {
|
|
41
|
-
args: {
|
|
42
|
-
size: "large",
|
|
43
|
-
label: "Button",
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const Small: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
size: "small",
|
|
50
|
-
label: "Button",
|
|
51
|
-
},
|
|
52
|
-
};
|
package/src/stories/Button.tsx
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import "./button.css";
|
|
3
|
-
|
|
4
|
-
interface ButtonProps {
|
|
5
|
-
/**
|
|
6
|
-
* Is this the principal call to action on the page?
|
|
7
|
-
*/
|
|
8
|
-
primary?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* What background color to use
|
|
11
|
-
*/
|
|
12
|
-
backgroundColor?: string;
|
|
13
|
-
/**
|
|
14
|
-
* How large should the button be?
|
|
15
|
-
*/
|
|
16
|
-
size?: "small" | "medium" | "large";
|
|
17
|
-
/**
|
|
18
|
-
* Button contents
|
|
19
|
-
*/
|
|
20
|
-
label: string;
|
|
21
|
-
/**
|
|
22
|
-
* Optional click handler
|
|
23
|
-
*/
|
|
24
|
-
onClick?: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Primary UI component for user interaction
|
|
29
|
-
*/
|
|
30
|
-
export const Button = ({
|
|
31
|
-
primary = false,
|
|
32
|
-
size = "medium",
|
|
33
|
-
backgroundColor,
|
|
34
|
-
label,
|
|
35
|
-
...props
|
|
36
|
-
}: ButtonProps) => {
|
|
37
|
-
const mode = primary
|
|
38
|
-
? "storybook-button--primary"
|
|
39
|
-
: "storybook-button--secondary";
|
|
40
|
-
return (
|
|
41
|
-
<button
|
|
42
|
-
type="button"
|
|
43
|
-
className={["storybook-button", `storybook-button--${size}`, mode].join(
|
|
44
|
-
" ",
|
|
45
|
-
)}
|
|
46
|
-
style={{ backgroundColor }}
|
|
47
|
-
{...props}
|
|
48
|
-
>
|
|
49
|
-
{label}
|
|
50
|
-
</button>
|
|
51
|
-
);
|
|
52
|
-
};
|