@bsol-oss/react-datatable5 1.0.36 → 1.0.38
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/README.md +7 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +17 -11
- package/dist/index.mjs +19 -13
- package/dist/types/components/DataTableContext.d.ts +1 -0
- package/dist/types/components/DataTableServer.d.ts +1 -1
- package/dist/types/components/Table.d.ts +3 -1
- package/dist/types/components/useDataTable.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -69,3 +69,10 @@ Example Url generated by the DataTableServer
|
|
|
69
69
|
```
|
|
70
70
|
GET http://localhost:8333/api/v1/gpt/chat/history/all?pagination={"offset":0,"rows":10}&sorting={}&where={}&searching=hello
|
|
71
71
|
```
|
|
72
|
+
|
|
73
|
+
## Development
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
npm install
|
|
77
|
+
npm run storybook
|
|
78
|
+
```
|
package/dist/index.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ declare module "@tanstack/react-table" {
|
|
|
90
90
|
displayName: string;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection,
|
|
93
|
+
declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection, children, }: DataTableServerProps<TData>) => react_jsx_runtime.JSX.Element;
|
|
94
94
|
|
|
95
95
|
declare const DensityToggleButton: () => react_jsx_runtime.JSX.Element;
|
|
96
96
|
|
|
@@ -116,9 +116,11 @@ declare const ResetSelectionButton: () => react_jsx_runtime.JSX.Element;
|
|
|
116
116
|
declare const ResetSortingButton: () => react_jsx_runtime.JSX.Element;
|
|
117
117
|
|
|
118
118
|
interface TableProps {
|
|
119
|
+
showLoading?: boolean;
|
|
120
|
+
loadingComponent?: JSX.Element;
|
|
119
121
|
children: ReactNode;
|
|
120
122
|
}
|
|
121
|
-
declare const Table: ({ children, ...props }: TableProps) => react_jsx_runtime.JSX.Element;
|
|
123
|
+
declare const Table: ({ children, showLoading, loadingComponent, ...props }: TableProps) => react_jsx_runtime.JSX.Element;
|
|
122
124
|
|
|
123
125
|
interface TableBodyProps {
|
|
124
126
|
pinnedBgColor?: {
|
|
@@ -204,6 +206,7 @@ declare const useDataTable: () => {
|
|
|
204
206
|
refreshData: () => void;
|
|
205
207
|
globalFilter: string;
|
|
206
208
|
setGlobalFilter: (filter: string) => void;
|
|
209
|
+
loading: boolean;
|
|
207
210
|
};
|
|
208
211
|
|
|
209
212
|
export { type DataResponse, DataTable, type DataTableProps, DataTableServer, type DataTableServerProps, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, GlobalFilter, PageSizeControl, type PageSizeControlProps, type PaginationProps, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, type Result, Table, TableBody, type TableBodyProps, TableCardContainer, type TableCardContainerProps, TableCards, type TableCardsProps, TableFilter, TableFooter, type TableFooterProps, TableHeader, type TableHeaderProps, TableOrderer, TablePagination, type TableProps, type TableRowSelectorProps, TableSelector, TableSorter, TableViewer, TextCell, type TextCellProps, useDataFromUrl, type useDataFromUrlProps, type useDataFromUrlReturn, useDataTable };
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const TableContext = react.createContext({
|
|
|
17
17
|
refreshData: () => { },
|
|
18
18
|
globalFilter: "",
|
|
19
19
|
setGlobalFilter: () => { },
|
|
20
|
+
loading: false,
|
|
20
21
|
});
|
|
21
22
|
|
|
22
23
|
// Reference: https://tanstack.com/table/latest/docs/framework/react/examples/custom-features
|
|
@@ -165,6 +166,7 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
165
166
|
},
|
|
166
167
|
globalFilter: globalFilter,
|
|
167
168
|
setGlobalFilter: setGlobalFilter,
|
|
169
|
+
loading: false
|
|
168
170
|
}, children: children }));
|
|
169
171
|
};
|
|
170
172
|
|
|
@@ -193,14 +195,14 @@ const useDataFromUrl = ({ url, params = {}, defaultData, }) => {
|
|
|
193
195
|
getData().catch((e) => {
|
|
194
196
|
console.error(e);
|
|
195
197
|
});
|
|
196
|
-
}, []);
|
|
198
|
+
}, [url]);
|
|
197
199
|
return { data, loading, hasError, refreshData };
|
|
198
200
|
};
|
|
199
201
|
|
|
200
202
|
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder: defaultColumnOrder = [], columnFilters: defaultColumnFilter = [], density = "sm", globalFilter: defaultGlobalFilter = "", pagination: defaultPagination = {
|
|
201
203
|
pageIndex: 0, //initial page index
|
|
202
204
|
pageSize: 10, //default page size
|
|
203
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {},
|
|
205
|
+
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, children, }) => {
|
|
204
206
|
const [sorting, setSorting] = react.useState(defaultSorting);
|
|
205
207
|
const [columnFilters, setColumnFilters] = react.useState(defaultColumnFilter); // can set initial column filter state here
|
|
206
208
|
const [pagination, setPagination] = react.useState(defaultPagination);
|
|
@@ -286,12 +288,13 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
286
288
|
react.useEffect(() => {
|
|
287
289
|
onRowSelect(table.getState().rowSelection);
|
|
288
290
|
}, [table.getState().rowSelection]);
|
|
289
|
-
return (jsxRuntime.
|
|
291
|
+
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
290
292
|
table: { ...table },
|
|
291
293
|
refreshData: refreshData,
|
|
292
294
|
globalFilter,
|
|
293
295
|
setGlobalFilter,
|
|
294
|
-
|
|
296
|
+
loading: loading,
|
|
297
|
+
}, children: children }));
|
|
295
298
|
};
|
|
296
299
|
|
|
297
300
|
const DensityToggleButton = () => {
|
|
@@ -309,8 +312,8 @@ const ResetFilteringButton = () => {
|
|
|
309
312
|
};
|
|
310
313
|
|
|
311
314
|
const useDataTable = () => {
|
|
312
|
-
const { table, refreshData, globalFilter, setGlobalFilter } = react.useContext(TableContext);
|
|
313
|
-
return { table, refreshData, globalFilter, setGlobalFilter };
|
|
315
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading } = react.useContext(TableContext);
|
|
316
|
+
return { table, refreshData, globalFilter, setGlobalFilter, loading };
|
|
314
317
|
};
|
|
315
318
|
|
|
316
319
|
const TableFilter = () => {
|
|
@@ -454,9 +457,12 @@ const ResetSelectionButton = () => {
|
|
|
454
457
|
}, children: "Reset Selection" }));
|
|
455
458
|
};
|
|
456
459
|
|
|
457
|
-
const Table = ({ children, ...props }) => {
|
|
458
|
-
const { table } = useDataTable();
|
|
459
|
-
|
|
460
|
+
const Table = ({ children, showLoading = false, loadingComponent = jsxRuntime.jsx(jsxRuntime.Fragment, { children: "Loading..." }), ...props }) => {
|
|
461
|
+
const { table, loading } = useDataTable();
|
|
462
|
+
if (showLoading) {
|
|
463
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [loading && loadingComponent, !loading && (jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflowX: "scroll", ...props, children: children }))] }));
|
|
464
|
+
}
|
|
465
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(react$1.Table, { width: table.getCenterTotalSize(), overflowX: "scroll", ...props, children: children }) }));
|
|
460
466
|
};
|
|
461
467
|
|
|
462
468
|
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
@@ -624,7 +630,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
624
630
|
? null
|
|
625
631
|
: reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react$1.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && (
|
|
626
632
|
// <UpDownIcon />
|
|
627
|
-
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) })] }) }), jsxRuntime.jsx(react$1.Portal, { children: jsxRuntime.jsxs(react$1.MenuList, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(md.MdPushPin, {}), onClick: () => {
|
|
633
|
+
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) }), jsxRuntime.jsx(react$1.Box, { children: header.column.getIsFiltered() && jsxRuntime.jsx(md.MdFilterListAlt, {}) })] }) }), jsxRuntime.jsx(react$1.Portal, { children: jsxRuntime.jsxs(react$1.MenuList, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(md.MdPushPin, {}), onClick: () => {
|
|
628
634
|
header.column.pin("left");
|
|
629
635
|
}, children: "Pin Column" })), header.column.getIsPinned() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(md.MdCancel, {}), onClick: () => {
|
|
630
636
|
header.column.pin(false);
|
|
@@ -632,7 +638,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
632
638
|
header.column.toggleSorting();
|
|
633
639
|
}, children: "Toggle Sorting" }), header.column.getIsSorted() && (jsxRuntime.jsx(react$1.MenuItem, { icon: jsxRuntime.jsx(io.IoMdClose, {}), onClick: () => {
|
|
634
640
|
header.column.clearSorting();
|
|
635
|
-
}, children: "Clear Sorting" }))] }))] }) })] }),
|
|
641
|
+
}, children: "Clear Sorting" }))] }))] }) })] }), canResize && (jsxRuntime.jsx(react$1.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing() ? "gray.700" : "transparent", position: "absolute", right: "0", top: "0", height: "100%", width: "5px", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
636
642
|
borderRightColor: header.column.getIsResizing()
|
|
637
643
|
? "gray.700"
|
|
638
644
|
: "gray.400",
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { jsx,
|
|
1
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { makeStateUpdater, functionalUpdate, useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, flexRender } from '@tanstack/react-table';
|
|
3
3
|
import { createContext, useState, useEffect, useContext } from 'react';
|
|
4
4
|
import { rankItem } from '@tanstack/match-sorter-utils';
|
|
5
5
|
import axios from 'axios';
|
|
6
6
|
import { Tooltip, IconButton, Button, Box, Text, Input, Popover, PopoverTrigger, PopoverContent, PopoverArrow, PopoverBody, Flex, Switch, Menu, MenuButton, MenuList, MenuItem, Table as Table$1, FormLabel, Checkbox, Grid, Card, CardBody, Tfoot, Tr as Tr$1, Th, Thead, Portal, ButtonGroup, Icon } from '@chakra-ui/react';
|
|
7
7
|
import { AiOutlineColumnWidth } from 'react-icons/ai';
|
|
8
|
-
import { MdFilterAlt, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutlineSort, MdPushPin, MdCancel, MdSort,
|
|
8
|
+
import { MdFilterAlt, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutlineSort, MdFilterListAlt, MdPushPin, MdCancel, MdSort, MdFirstPage, MdArrowBack, MdArrowForward, MdLastPage, MdClear, MdOutlineChecklist } from 'react-icons/md';
|
|
9
9
|
import { UpDownIcon, ChevronDownIcon, ChevronUpIcon, CloseIcon } from '@chakra-ui/icons';
|
|
10
10
|
import { IoMdEye, IoMdClose, IoMdCheckbox } from 'react-icons/io';
|
|
11
11
|
import { Tbody, Tr, Td } from '@chakra-ui/table';
|
|
@@ -15,6 +15,7 @@ const TableContext = createContext({
|
|
|
15
15
|
refreshData: () => { },
|
|
16
16
|
globalFilter: "",
|
|
17
17
|
setGlobalFilter: () => { },
|
|
18
|
+
loading: false,
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
// Reference: https://tanstack.com/table/latest/docs/framework/react/examples/custom-features
|
|
@@ -163,6 +164,7 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
163
164
|
},
|
|
164
165
|
globalFilter: globalFilter,
|
|
165
166
|
setGlobalFilter: setGlobalFilter,
|
|
167
|
+
loading: false
|
|
166
168
|
}, children: children }));
|
|
167
169
|
};
|
|
168
170
|
|
|
@@ -191,14 +193,14 @@ const useDataFromUrl = ({ url, params = {}, defaultData, }) => {
|
|
|
191
193
|
getData().catch((e) => {
|
|
192
194
|
console.error(e);
|
|
193
195
|
});
|
|
194
|
-
}, []);
|
|
196
|
+
}, [url]);
|
|
195
197
|
return { data, loading, hasError, refreshData };
|
|
196
198
|
};
|
|
197
199
|
|
|
198
200
|
const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, onRowSelect = () => { }, columnOrder: defaultColumnOrder = [], columnFilters: defaultColumnFilter = [], density = "sm", globalFilter: defaultGlobalFilter = "", pagination: defaultPagination = {
|
|
199
201
|
pageIndex: 0, //initial page index
|
|
200
202
|
pageSize: 10, //default page size
|
|
201
|
-
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {},
|
|
203
|
+
}, sorting: defaultSorting = [], rowSelection: defaultRowSelection = {}, children, }) => {
|
|
202
204
|
const [sorting, setSorting] = useState(defaultSorting);
|
|
203
205
|
const [columnFilters, setColumnFilters] = useState(defaultColumnFilter); // can set initial column filter state here
|
|
204
206
|
const [pagination, setPagination] = useState(defaultPagination);
|
|
@@ -284,12 +286,13 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
|
|
|
284
286
|
useEffect(() => {
|
|
285
287
|
onRowSelect(table.getState().rowSelection);
|
|
286
288
|
}, [table.getState().rowSelection]);
|
|
287
|
-
return (
|
|
289
|
+
return (jsx(TableContext.Provider, { value: {
|
|
288
290
|
table: { ...table },
|
|
289
291
|
refreshData: refreshData,
|
|
290
292
|
globalFilter,
|
|
291
293
|
setGlobalFilter,
|
|
292
|
-
|
|
294
|
+
loading: loading,
|
|
295
|
+
}, children: children }));
|
|
293
296
|
};
|
|
294
297
|
|
|
295
298
|
const DensityToggleButton = () => {
|
|
@@ -307,8 +310,8 @@ const ResetFilteringButton = () => {
|
|
|
307
310
|
};
|
|
308
311
|
|
|
309
312
|
const useDataTable = () => {
|
|
310
|
-
const { table, refreshData, globalFilter, setGlobalFilter } = useContext(TableContext);
|
|
311
|
-
return { table, refreshData, globalFilter, setGlobalFilter };
|
|
313
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading } = useContext(TableContext);
|
|
314
|
+
return { table, refreshData, globalFilter, setGlobalFilter, loading };
|
|
312
315
|
};
|
|
313
316
|
|
|
314
317
|
const TableFilter = () => {
|
|
@@ -452,9 +455,12 @@ const ResetSelectionButton = () => {
|
|
|
452
455
|
}, children: "Reset Selection" }));
|
|
453
456
|
};
|
|
454
457
|
|
|
455
|
-
const Table = ({ children, ...props }) => {
|
|
456
|
-
const { table } = useDataTable();
|
|
457
|
-
|
|
458
|
+
const Table = ({ children, showLoading = false, loadingComponent = jsx(Fragment, { children: "Loading..." }), ...props }) => {
|
|
459
|
+
const { table, loading } = useDataTable();
|
|
460
|
+
if (showLoading) {
|
|
461
|
+
return (jsxs(Fragment, { children: [loading && loadingComponent, !loading && (jsx(Table$1, { width: table.getCenterTotalSize(), overflowX: "scroll", ...props, children: children }))] }));
|
|
462
|
+
}
|
|
463
|
+
return (jsx(Fragment, { children: jsx(Table$1, { width: table.getCenterTotalSize(), overflowX: "scroll", ...props, children: children }) }));
|
|
458
464
|
};
|
|
459
465
|
|
|
460
466
|
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
|
|
@@ -622,7 +628,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
622
628
|
? null
|
|
623
629
|
: flexRender(header.column.columnDef.header, header.getContext()), jsx(Box, { children: header.column.getCanSort() && (jsxs(Fragment, { children: [header.column.getIsSorted() === false && (
|
|
624
630
|
// <UpDownIcon />
|
|
625
|
-
jsx(Fragment, {})), header.column.getIsSorted() === "asc" && (jsx(ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsx(ChevronDownIcon, {}))] })) })] }) }), jsx(Portal, { children: jsxs(MenuList, { children: [!header.column.getIsPinned() && (jsx(MenuItem, { icon: jsx(MdPushPin, {}), onClick: () => {
|
|
631
|
+
jsx(Fragment, {})), header.column.getIsSorted() === "asc" && (jsx(ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsx(ChevronDownIcon, {}))] })) }), jsx(Box, { children: header.column.getIsFiltered() && jsx(MdFilterListAlt, {}) })] }) }), jsx(Portal, { children: jsxs(MenuList, { children: [!header.column.getIsPinned() && (jsx(MenuItem, { icon: jsx(MdPushPin, {}), onClick: () => {
|
|
626
632
|
header.column.pin("left");
|
|
627
633
|
}, children: "Pin Column" })), header.column.getIsPinned() && (jsx(MenuItem, { icon: jsx(MdCancel, {}), onClick: () => {
|
|
628
634
|
header.column.pin(false);
|
|
@@ -630,7 +636,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
630
636
|
header.column.toggleSorting();
|
|
631
637
|
}, children: "Toggle Sorting" }), header.column.getIsSorted() && (jsx(MenuItem, { icon: jsx(IoMdClose, {}), onClick: () => {
|
|
632
638
|
header.column.clearSorting();
|
|
633
|
-
}, children: "Clear Sorting" }))] }))] }) })] }),
|
|
639
|
+
}, children: "Clear Sorting" }))] }))] }) })] }), canResize && (jsx(Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing() ? "gray.700" : "transparent", position: "absolute", right: "0", top: "0", height: "100%", width: "5px", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
634
640
|
borderRightColor: header.column.getIsResizing()
|
|
635
641
|
? "gray.700"
|
|
636
642
|
: "gray.400",
|
|
@@ -34,4 +34,4 @@ declare module "@tanstack/react-table" {
|
|
|
34
34
|
displayName: string;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection,
|
|
37
|
+
export declare const DataTableServer: <TData>({ columns, url, enableRowSelection, enableMultiRowSelection, enableSubRowSelection, onRowSelect, columnOrder: defaultColumnOrder, columnFilters: defaultColumnFilter, density, globalFilter: defaultGlobalFilter, pagination: defaultPagination, sorting: defaultSorting, rowSelection: defaultRowSelection, children, }: DataTableServerProps<TData>) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
2
|
export interface TableProps {
|
|
3
|
+
showLoading?: boolean;
|
|
4
|
+
loadingComponent?: JSX.Element;
|
|
3
5
|
children: ReactNode;
|
|
4
6
|
}
|
|
5
|
-
export declare const Table: ({ children, ...props }: TableProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare const Table: ({ children, showLoading, loadingComponent, ...props }: TableProps) => import("react/jsx-runtime").JSX.Element;
|