@bsol-oss/react-datatable5 3.4.2 → 4.0.0
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 +1 -1
- package/dist/index.d.ts +13 -16
- package/dist/index.js +268 -124
- package/dist/index.mjs +220 -94
- package/dist/types/components/Controls/EditFilterButton.d.ts +1 -1
- package/dist/types/components/DataTable/DefaultTable.d.ts +3 -1
- package/dist/types/components/DataTable/Table.d.ts +4 -3
- package/dist/types/components/DataTable/TableHeader.d.ts +3 -1
- package/dist/types/components/DataTable/TablePagination.d.ts +1 -3
- package/dist/types/components/DataTable/TextCell.d.ts +2 -3
- package/dist/types/components/Filter/GlobalFilter.d.ts +1 -3
- package/dist/types/components/ui/avatar.d.ts +17 -0
- package/dist/types/components/ui/button.d.ts +10 -0
- package/dist/types/components/ui/checkbox.d.ts +8 -0
- package/dist/types/components/ui/close-button.d.ts +4 -0
- package/dist/types/components/ui/color-mode.d.ts +17 -0
- package/dist/types/components/ui/dialog.d.ts +19 -0
- package/dist/types/components/ui/drawer.d.ts +19 -0
- package/dist/types/components/ui/empty-state.d.ts +8 -0
- package/dist/types/components/ui/field.d.ts +9 -0
- package/dist/types/components/ui/input-group.d.ts +12 -0
- package/dist/types/components/ui/menu.d.ts +24 -0
- package/dist/types/components/ui/popover.d.ts +17 -0
- package/dist/types/components/ui/provider.d.ts +2 -0
- package/dist/types/components/ui/radio.d.ts +8 -0
- package/dist/types/components/ui/select.d.ts +25 -0
- package/dist/types/components/ui/slider.d.ts +11 -0
- package/dist/types/components/ui/switch.d.ts +15 -0
- package/dist/types/components/ui/tag.d.ts +9 -0
- package/dist/types/components/ui/tooltip.d.ts +11 -0
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -4,19 +4,40 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var react = require('@chakra-ui/react');
|
|
5
5
|
var ai = require('react-icons/ai');
|
|
6
6
|
var md = require('react-icons/md');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var lu = require('react-icons/lu');
|
|
7
9
|
var icons = require('@chakra-ui/icons');
|
|
8
|
-
var react$1 = require('react');
|
|
9
10
|
var io = require('react-icons/io');
|
|
10
11
|
var reactTable = require('@tanstack/react-table');
|
|
11
12
|
var matchSorterUtils = require('@tanstack/match-sorter-utils');
|
|
12
|
-
var table = require('@chakra-ui/table');
|
|
13
13
|
var bs = require('react-icons/bs');
|
|
14
14
|
var gr = require('react-icons/gr');
|
|
15
15
|
var io5 = require('react-icons/io5');
|
|
16
|
+
var hi = require('react-icons/hi');
|
|
17
|
+
var cg = require('react-icons/cg');
|
|
16
18
|
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
17
19
|
var fa = require('react-icons/fa');
|
|
18
20
|
var axios = require('axios');
|
|
19
21
|
|
|
22
|
+
function _interopNamespaceDefault(e) {
|
|
23
|
+
var n = Object.create(null);
|
|
24
|
+
if (e) {
|
|
25
|
+
Object.keys(e).forEach(function (k) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return e[k]; }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
n.default = e;
|
|
36
|
+
return Object.freeze(n);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
40
|
+
|
|
20
41
|
const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWidth, {}), }) => {
|
|
21
42
|
const { table } = useDataTableContext();
|
|
22
43
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Toggle Density", icon: icon, onClick: () => {
|
|
@@ -26,17 +47,37 @@ const DensityToggleButton = ({ text, icon = jsxRuntime.jsx(ai.AiOutlineColumnWid
|
|
|
26
47
|
}, children: text }))] }));
|
|
27
48
|
};
|
|
28
49
|
|
|
29
|
-
const
|
|
50
|
+
const CloseButton = React__namespace.forwardRef(function CloseButton(props, ref) {
|
|
51
|
+
return (jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "Close", ref: ref, ...props, children: props.children ?? jsxRuntime.jsx(lu.LuX, {}) }));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const DialogContent = React__namespace.forwardRef(function DialogContent(props, ref) {
|
|
55
|
+
const { children, portalled = true, portalRef, backdrop = true, ...rest } = props;
|
|
56
|
+
return (jsxRuntime.jsxs(react.Portal, { disabled: !portalled, container: portalRef, children: [backdrop && jsxRuntime.jsx(react.Dialog.Backdrop, {}), jsxRuntime.jsx(react.Dialog.Positioner, { children: jsxRuntime.jsx(react.Dialog.Content, { ref: ref, ...rest, asChild: false, children: children }) })] }));
|
|
57
|
+
});
|
|
58
|
+
const DialogCloseTrigger = React__namespace.forwardRef(function DialogCloseTrigger(props, ref) {
|
|
59
|
+
return (jsxRuntime.jsx(react.Dialog.CloseTrigger, { position: "absolute", top: "2", insetEnd: "2", ...props, asChild: true, children: jsxRuntime.jsx(CloseButton, { size: "sm", ref: ref, children: props.children }) }));
|
|
60
|
+
});
|
|
61
|
+
const DialogRoot = react.Dialog.Root;
|
|
62
|
+
const DialogFooter = react.Dialog.Footer;
|
|
63
|
+
const DialogHeader = react.Dialog.Header;
|
|
64
|
+
const DialogBody = react.Dialog.Body;
|
|
65
|
+
react.Dialog.Backdrop;
|
|
66
|
+
const DialogTitle = react.Dialog.Title;
|
|
67
|
+
react.Dialog.Description;
|
|
68
|
+
const DialogTrigger = react.Dialog.Trigger;
|
|
69
|
+
const DialogActionTrigger = react.Dialog.ActionTrigger;
|
|
70
|
+
|
|
71
|
+
const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsxRuntime.jsx(md.MdFilterAlt, {}), }) => {
|
|
30
72
|
const filterModal = react.useDisclosure();
|
|
31
|
-
return (jsxRuntime.
|
|
73
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(DialogRoot, { size: ["full", "full", "md", "md"], children: jsxRuntime.jsxs(DialogRoot, { children: [jsxRuntime.jsx(DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { variant: "outline", children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogHeader, { children: jsxRuntime.jsx(DialogTitle, { children: title }) }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "1rem", children: [jsxRuntime.jsx(TableFilter, {}), jsxRuntime.jsx(ResetFilteringButton, { text: resetText })] }) }), jsxRuntime.jsxs(DialogFooter, { children: [jsxRuntime.jsx(DialogActionTrigger, { asChild: true, children: jsxRuntime.jsx(react.Button, { onClick: filterModal.onClose, children: closeText }) }), jsxRuntime.jsx(react.Button, { children: "Save" })] }), jsxRuntime.jsx(DialogCloseTrigger, {})] })] }) }) }));
|
|
32
74
|
};
|
|
33
75
|
|
|
34
76
|
const EditOrderButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineMoveDown, {}), title = "Change Order", }) => {
|
|
35
|
-
|
|
36
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [!!text === false && (jsxRuntime.jsx(react.IconButton, { icon: icon, variant: "ghost", onClick: orderModal.onOpen, "aria-label": "change order" })), !!text !== false && (jsxRuntime.jsx(react.Button, { leftIcon: icon, variant: "ghost", onClick: orderModal.onOpen, children: text })), jsxRuntime.jsxs(react.Modal, { isOpen: orderModal.isOpen, onClose: orderModal.onClose, size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.ModalOverlay, {}), jsxRuntime.jsxs(react.ModalContent, { padding: "0 0 1rem 0", children: [jsxRuntime.jsx(react.ModalHeader, { children: title }), jsxRuntime.jsx(react.ModalCloseButton, {}), jsxRuntime.jsx(react.ModalBody, { children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) })] })] })] }));
|
|
77
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react.DialogRoot, { size: "cover", children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(react.DialogTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { variant: "ghost", children: [icon, text] }) }), jsxRuntime.jsxs(react.DialogContent, { children: [jsxRuntime.jsx(react.DialogCloseTrigger, {}), jsxRuntime.jsxs(react.DialogHeader, { children: [jsxRuntime.jsx(react.DialogTitle, {}), title] }), jsxRuntime.jsx(react.DialogBody, { children: jsxRuntime.jsx(react.Flex, { flexFlow: "column", gap: "0.25rem", children: jsxRuntime.jsx(TableOrderer, {}) }) }), jsxRuntime.jsx(react.DialogFooter, {})] })] }) }));
|
|
37
78
|
};
|
|
38
79
|
|
|
39
|
-
const TableContext =
|
|
80
|
+
const TableContext = React.createContext({
|
|
40
81
|
table: {},
|
|
41
82
|
refreshData: () => { },
|
|
42
83
|
globalFilter: "",
|
|
@@ -46,7 +87,7 @@ const TableContext = react$1.createContext({
|
|
|
46
87
|
});
|
|
47
88
|
|
|
48
89
|
const useDataTableContext = () => {
|
|
49
|
-
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } =
|
|
90
|
+
const { table, refreshData, globalFilter, setGlobalFilter, loading, hasError, } = React.useContext(TableContext);
|
|
50
91
|
return {
|
|
51
92
|
table,
|
|
52
93
|
refreshData,
|
|
@@ -73,19 +114,50 @@ const TableSorter = () => {
|
|
|
73
114
|
|
|
74
115
|
const EditSortingButton = ({ text, icon = jsxRuntime.jsx(md.MdOutlineSort, {}), title = "Edit Sorting", }) => {
|
|
75
116
|
const sortingModal = react.useDisclosure();
|
|
76
|
-
return (jsxRuntime.
|
|
117
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(DialogRoot, { size: ["full", "full", "md", "md"], children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { children: jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: sortingModal.onOpen, children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsxs(DialogHeader, { children: [jsxRuntime.jsx(DialogTitle, {}), title] }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(TableSorter, {}), jsxRuntime.jsx(ResetSortingButton, {})] }) }), jsxRuntime.jsx(DialogFooter, {})] })] }) }));
|
|
77
118
|
};
|
|
78
119
|
|
|
79
120
|
const EditViewButton = ({ text, icon = jsxRuntime.jsx(io.IoMdEye, {}), title = "Edit View", }) => {
|
|
80
121
|
const viewModel = react.useDisclosure();
|
|
81
|
-
return (jsxRuntime.
|
|
122
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(DialogRoot, { children: [jsxRuntime.jsx(react.DialogBackdrop, {}), jsxRuntime.jsx(DialogTrigger, { children: jsxRuntime.jsxs(react.Button, { variant: "ghost", onClick: viewModel.onOpen, children: [icon, " ", text] }) }), jsxRuntime.jsxs(DialogContent, { children: [jsxRuntime.jsx(DialogCloseTrigger, {}), jsxRuntime.jsxs(DialogHeader, { children: [jsxRuntime.jsx(DialogTitle, {}), title] }), jsxRuntime.jsx(DialogBody, { children: jsxRuntime.jsx(TableViewer, {}) }), jsxRuntime.jsx(DialogFooter, {})] })] }) }));
|
|
82
123
|
};
|
|
83
124
|
|
|
125
|
+
const MenuContent = React__namespace.forwardRef(function MenuContent(props, ref) {
|
|
126
|
+
const { portalled = true, portalRef, ...rest } = props;
|
|
127
|
+
return (jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Menu.Positioner, { children: jsxRuntime.jsx(react.Menu.Content, { ref: ref, ...rest }) }) }));
|
|
128
|
+
});
|
|
129
|
+
React__namespace.forwardRef(function MenuArrow(props, ref) {
|
|
130
|
+
return (jsxRuntime.jsx(react.Menu.Arrow, { ref: ref, ...props, children: jsxRuntime.jsx(react.Menu.ArrowTip, {}) }));
|
|
131
|
+
});
|
|
132
|
+
React__namespace.forwardRef(function MenuCheckboxItem(props, ref) {
|
|
133
|
+
return (jsxRuntime.jsxs(react.Menu.CheckboxItem, { ref: ref, ...props, children: [jsxRuntime.jsx(react.Menu.ItemIndicator, { hidden: false, children: jsxRuntime.jsx(lu.LuCheck, {}) }), props.children] }));
|
|
134
|
+
});
|
|
135
|
+
React__namespace.forwardRef(function MenuRadioItem(props, ref) {
|
|
136
|
+
const { children, ...rest } = props;
|
|
137
|
+
return (jsxRuntime.jsxs(react.Menu.RadioItem, { ps: "8", ref: ref, ...rest, children: [jsxRuntime.jsx(react.AbsoluteCenter, { axis: "horizontal", left: "4", asChild: true, children: jsxRuntime.jsx(react.Menu.ItemIndicator, { children: jsxRuntime.jsx(lu.LuCheck, {}) }) }), jsxRuntime.jsx(react.Menu.ItemText, { children: children })] }));
|
|
138
|
+
});
|
|
139
|
+
React__namespace.forwardRef(function MenuItemGroup(props, ref) {
|
|
140
|
+
const { title, children, ...rest } = props;
|
|
141
|
+
return (jsxRuntime.jsxs(react.Menu.ItemGroup, { ref: ref, ...rest, children: [title && (jsxRuntime.jsx(react.Menu.ItemGroupLabel, { userSelect: "none", children: title })), children] }));
|
|
142
|
+
});
|
|
143
|
+
React__namespace.forwardRef(function MenuTriggerItem(props, ref) {
|
|
144
|
+
const { startIcon, children, ...rest } = props;
|
|
145
|
+
return (jsxRuntime.jsxs(react.Menu.TriggerItem, { ref: ref, ...rest, children: [startIcon, children, jsxRuntime.jsx(lu.LuChevronRight, {})] }));
|
|
146
|
+
});
|
|
147
|
+
react.Menu.RadioItemGroup;
|
|
148
|
+
react.Menu.ContextTrigger;
|
|
149
|
+
const MenuRoot = react.Menu.Root;
|
|
150
|
+
react.Menu.Separator;
|
|
151
|
+
const MenuItem = react.Menu.Item;
|
|
152
|
+
react.Menu.ItemText;
|
|
153
|
+
react.Menu.ItemCommand;
|
|
154
|
+
const MenuTrigger = react.Menu.Trigger;
|
|
155
|
+
|
|
84
156
|
const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
|
|
85
157
|
const { table } = useDataTableContext();
|
|
86
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(
|
|
158
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(MenuRoot, { children: [jsxRuntime.jsx(MenuTrigger, { asChild: true, children: jsxRuntime.jsxs(react.Button, { variant: "ghost", gap: "0.5rem", children: [table.getState().pagination.pageSize, " ", jsxRuntime.jsx(icons.ChevronDownIcon, {})] }) }), jsxRuntime.jsx(MenuContent, { children: pageSizes.map((pageSize) => (jsxRuntime.jsx(MenuItem, { value: `chakra-table-pageSize-${pageSize}`, onClick: () => {
|
|
87
159
|
table.setPageSize(Number(pageSize));
|
|
88
|
-
}, children: pageSize }
|
|
160
|
+
}, children: pageSize }))) })] }) }));
|
|
89
161
|
};
|
|
90
162
|
|
|
91
163
|
const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
|
|
@@ -245,10 +317,10 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
|
|
|
245
317
|
onDensityChange: setDensity,
|
|
246
318
|
onColumnVisibilityChange: setColumnVisibility,
|
|
247
319
|
});
|
|
248
|
-
|
|
320
|
+
React.useEffect(() => {
|
|
249
321
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
250
322
|
}, []);
|
|
251
|
-
|
|
323
|
+
React.useEffect(() => {
|
|
252
324
|
onRowSelect(table.getState().rowSelection, data);
|
|
253
325
|
}, [table.getState().rowSelection]);
|
|
254
326
|
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
@@ -311,13 +383,13 @@ const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
311
383
|
},
|
|
312
384
|
// for tanstack-table ts bug end
|
|
313
385
|
});
|
|
314
|
-
|
|
386
|
+
React.useEffect(() => {
|
|
315
387
|
setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
|
|
316
388
|
}, []);
|
|
317
|
-
|
|
389
|
+
React.useEffect(() => {
|
|
318
390
|
onRowSelect(table.getState().rowSelection, data.results);
|
|
319
391
|
}, [table.getState().rowSelection]);
|
|
320
|
-
|
|
392
|
+
React.useEffect(() => {
|
|
321
393
|
table.resetPagination();
|
|
322
394
|
}, [sorting, columnFilters, globalFilter]);
|
|
323
395
|
return (jsxRuntime.jsx(TableContext.Provider, { value: {
|
|
@@ -330,6 +402,11 @@ const DataTableServer = ({ columns, enableRowSelection = true, enableMultiRowSel
|
|
|
330
402
|
}, children: children }));
|
|
331
403
|
};
|
|
332
404
|
|
|
405
|
+
const Tag = React__namespace.forwardRef(function Tag(props, ref) {
|
|
406
|
+
const { startElement, endElement, onClose, closable = !!onClose, children, ...rest } = props;
|
|
407
|
+
return (jsxRuntime.jsxs(react.Tag.Root, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.Tag.StartElement, { children: startElement })), jsxRuntime.jsx(react.Tag.Label, { children: children }), endElement && (jsxRuntime.jsx(react.Tag.EndElement, { children: endElement })), closable && (jsxRuntime.jsx(react.Tag.EndElement, { children: jsxRuntime.jsx(react.Tag.CloseTrigger, { onClick: onClose }) }))] }));
|
|
408
|
+
});
|
|
409
|
+
|
|
333
410
|
const DefaultCard = ({ row, imageColumnId = undefined, titleColumnId = undefined, tagColumnId = undefined, tagIcon = undefined, showTag = true, }) => {
|
|
334
411
|
if (!!row.original === false) {
|
|
335
412
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
@@ -343,13 +420,18 @@ const DefaultCard = ({ row, imageColumnId = undefined, titleColumnId = undefined
|
|
|
343
420
|
// const tagIdExists = Object.keys(row.original).some((key) => {
|
|
344
421
|
// return key === tagColumnId;
|
|
345
422
|
// });
|
|
346
|
-
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto", gap: "1rem", children: [jsxRuntime.jsx(react.Flex, { justifyContent: "center", alignItems: "center", children: jsxRuntime.jsx(react.Image, { src: row.original[imageColumnId] }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: [jsxRuntime.jsx(react.Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] }), showTag && (jsxRuntime.
|
|
423
|
+
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto", gap: "1rem", children: [jsxRuntime.jsx(react.Flex, { justifyContent: "center", alignItems: "center", children: jsxRuntime.jsx(react.Image, { src: row.original[imageColumnId] }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: [jsxRuntime.jsx(react.Text, { fontWeight: "bold", fontSize: "large", children: row.original[titleColumnId] }), showTag && (jsxRuntime.jsx(Tag, { fontSize: "large", startElement: tagIcon && tagIcon({}), children: row.original[tagColumnId] }))] })] }));
|
|
347
424
|
};
|
|
348
425
|
|
|
426
|
+
const Checkbox = React__namespace.forwardRef(function Checkbox(props, ref) {
|
|
427
|
+
const { icon, children, inputProps, rootRef, ...rest } = props;
|
|
428
|
+
return (jsxRuntime.jsxs(react.Checkbox.Root, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.Checkbox.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.Checkbox.Control, { children: icon || jsxRuntime.jsx(react.Checkbox.Indicator, {}) }), children != null && (jsxRuntime.jsx(react.Checkbox.Label, { children: children }))] }));
|
|
429
|
+
});
|
|
430
|
+
|
|
349
431
|
const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, }) => {
|
|
350
|
-
const { table
|
|
432
|
+
const { table } = React.useContext(TableContext);
|
|
351
433
|
const SELECTION_BOX_WIDTH = 20;
|
|
352
|
-
const [hoveredRow, setHoveredRow] =
|
|
434
|
+
const [hoveredRow, setHoveredRow] = React.useState(-1);
|
|
353
435
|
const handleRowHover = (index) => {
|
|
354
436
|
setHoveredRow(index);
|
|
355
437
|
};
|
|
@@ -357,11 +439,11 @@ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, sho
|
|
|
357
439
|
const tdProps = cell.column.getIsPinned()
|
|
358
440
|
? {
|
|
359
441
|
left: showSelector
|
|
360
|
-
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table
|
|
361
|
-
: `${cell.column.getStart("left")
|
|
442
|
+
? `${cell.column.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
443
|
+
: `${cell.column.getStart("left")}px`,
|
|
362
444
|
background: pinnedBgColor.light,
|
|
363
445
|
position: "sticky",
|
|
364
|
-
zIndex: 1,
|
|
446
|
+
zIndex: -1,
|
|
365
447
|
_dark: {
|
|
366
448
|
backgroundColor: pinnedBgColor.dark,
|
|
367
449
|
},
|
|
@@ -369,16 +451,16 @@ const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, sho
|
|
|
369
451
|
: {};
|
|
370
452
|
return tdProps;
|
|
371
453
|
};
|
|
372
|
-
return (jsxRuntime.jsx(
|
|
373
|
-
return (jsxRuntime.jsxs(
|
|
374
|
-
return (jsxRuntime.jsx(
|
|
454
|
+
return (jsxRuntime.jsx(react.Table.Body, { children: table.getRowModel().rows.map((row, index) => {
|
|
455
|
+
return (jsxRuntime.jsxs(react.Table.Row, { display: "flex", _hover: { backgroundColor: "rgba(178,178,178,0.1)" }, zIndex: 1, onMouseEnter: () => handleRowHover(index), onMouseLeave: () => handleRowHover(-1), children: [showSelector && (jsxRuntime.jsx(TableRowSelector, { index: index, row: row, hoveredRow: hoveredRow, alwaysShowSelector: alwaysShowSelector })), row.getVisibleCells().map((cell, index) => {
|
|
456
|
+
return (jsxRuntime.jsx(react.Table.Cell, { padding: `${table.getDensityValue()}px`,
|
|
375
457
|
// styling resize and pinning start
|
|
376
458
|
maxWidth: `${cell.column.getSize()}px`, width: `${cell.column.getSize()}px`, ...getTdProps(cell), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, `chakra-table-rowcell-${cell.id}-${index}`));
|
|
377
459
|
})] }, `chakra-table-row-${row.id}`));
|
|
378
460
|
}) }));
|
|
379
461
|
};
|
|
380
462
|
const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, alwaysShowSelector = true, }) => {
|
|
381
|
-
const { table
|
|
463
|
+
const { table } = React.useContext(TableContext);
|
|
382
464
|
const SELECTION_BOX_WIDTH = 20;
|
|
383
465
|
const isCheckBoxVisible = (current_index, current_row) => {
|
|
384
466
|
if (alwaysShowSelector) {
|
|
@@ -392,7 +474,7 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
|
|
|
392
474
|
}
|
|
393
475
|
return false;
|
|
394
476
|
};
|
|
395
|
-
return (jsxRuntime.jsxs(
|
|
477
|
+
return (jsxRuntime.jsxs(react.Table.Cell, { padding: `${table.getDensityValue()}px`, ...(table.getIsSomeColumnsPinned("left")
|
|
396
478
|
? {
|
|
397
479
|
left: `0px`,
|
|
398
480
|
backgroundColor: pinnedBgColor.light,
|
|
@@ -402,15 +484,22 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
|
|
|
402
484
|
}
|
|
403
485
|
: {}),
|
|
404
486
|
// styling resize and pinning end
|
|
405
|
-
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.
|
|
487
|
+
display: "grid", children: [!isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` })), isCheckBoxVisible(index, row) && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: row.getIsSelected(),
|
|
406
488
|
disabled: !row.getCanSelect(),
|
|
407
489
|
// indeterminate: row.getIsSomeSelected(),
|
|
408
490
|
onChange: row.getToggleSelectedHandler() }) }))] }));
|
|
409
491
|
};
|
|
410
492
|
|
|
493
|
+
const Tooltip = React__namespace.forwardRef(function Tooltip(props, ref) {
|
|
494
|
+
const { showArrow, children, disabled, portalled, content, contentProps, portalRef, ...rest } = props;
|
|
495
|
+
if (disabled)
|
|
496
|
+
return children;
|
|
497
|
+
return (jsxRuntime.jsxs(react.Tooltip.Root, { ...rest, children: [jsxRuntime.jsx(react.Tooltip.Trigger, { asChild: true, children: children }), jsxRuntime.jsx(react.Portal, { disabled: !portalled, container: portalRef, children: jsxRuntime.jsx(react.Tooltip.Positioner, { children: jsxRuntime.jsxs(react.Tooltip.Content, { ref: ref, ...contentProps, children: [showArrow && (jsxRuntime.jsx(react.Tooltip.Arrow, { children: jsxRuntime.jsx(react.Tooltip.ArrowTip, {}) })), content] }) }) })] }));
|
|
498
|
+
});
|
|
499
|
+
|
|
411
500
|
const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, children = jsxRuntime.jsx(jsxRuntime.Fragment, {}), showFilterName = false, showFilterTags = false, showReload = false, filterOptions = [], extraItems = jsxRuntime.jsx(jsxRuntime.Fragment, {}), }) => {
|
|
412
501
|
const { loading, hasError } = useDataTableContext();
|
|
413
|
-
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", justifySelf: "end", children: [loading && jsxRuntime.jsx(react.Spinner, { size: "sm" }), hasError && (jsxRuntime.jsx(
|
|
502
|
+
return (jsxRuntime.jsxs(react.Grid, { templateRows: "auto auto auto 1fr auto", templateColumns: "1fr 1fr", width: fitTableWidth ? "fit-content" : "100%", height: fitTableHeight ? "fit-content" : "100%", justifySelf: "center", alignSelf: "center", gap: "0.5rem", children: [jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsxRuntime.jsx(react.Box, { children: jsxRuntime.jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsxRuntime.jsx(md.MdOutlineViewColumn, {}) }) }), jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", justifySelf: "end", children: [loading && jsxRuntime.jsx(react.Spinner, { size: "sm" }), hasError && (jsxRuntime.jsx(Tooltip, { content: "An error occurred while fetching data", children: jsxRuntime.jsx(react.Icon, { as: bs.BsExclamationCircleFill, color: "red.400" }) })), showFilter && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(GlobalFilter, {}), jsxRuntime.jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] })), showReload && jsxRuntime.jsx(ReloadButton, {}), extraItems] })] }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
|
|
414
503
|
return (jsxRuntime.jsxs(react.Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxRuntime.jsxs(react.Text, { children: [column, ":"] }), jsxRuntime.jsx(FilterOptions, { column: column })] }, column));
|
|
415
504
|
}) }), jsxRuntime.jsx(react.Flex, { gridColumn: "1 / span 2", children: showFilterTags && jsxRuntime.jsx(TableFilterTags, {}) }), jsxRuntime.jsx(react.Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: children }), jsxRuntime.jsxs(react.Flex, { gap: "1rem", alignItems: "center", children: [jsxRuntime.jsx(PageSizeControl, {}), jsxRuntime.jsxs(react.Flex, { children: [jsxRuntime.jsx(react.Text, { paddingRight: "0.5rem", children: totalText }), jsxRuntime.jsx(RowCountText, {})] })] }), jsxRuntime.jsx(react.Box, { justifySelf: "end", children: jsxRuntime.jsx(TablePagination, {}) })] }));
|
|
416
505
|
};
|
|
@@ -418,7 +507,7 @@ const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth
|
|
|
418
507
|
const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, alwaysShowSelector = true, }) => {
|
|
419
508
|
const table = useDataTableContext().table;
|
|
420
509
|
const SELECTION_BOX_WIDTH = 20;
|
|
421
|
-
const [hoveredCheckBox, setHoveredCheckBox] =
|
|
510
|
+
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
422
511
|
const handleRowHover = (isHovered) => {
|
|
423
512
|
setHoveredCheckBox(isHovered);
|
|
424
513
|
};
|
|
@@ -450,7 +539,7 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
450
539
|
: {};
|
|
451
540
|
return thProps;
|
|
452
541
|
};
|
|
453
|
-
return (jsxRuntime.jsx(react.
|
|
542
|
+
return (jsxRuntime.jsx(react.Table.Footer, { children: table.getFooterGroups().map((footerGroup) => (jsxRuntime.jsxs(react.Table.Row, { display: "flex", children: [showSelector && (jsxRuntime.jsxs(react.Table.Header
|
|
454
543
|
// styling resize and pinning start
|
|
455
544
|
, {
|
|
456
545
|
// styling resize and pinning start
|
|
@@ -464,21 +553,26 @@ const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, s
|
|
|
464
553
|
}
|
|
465
554
|
: {}),
|
|
466
555
|
// styling resize and pinning end
|
|
467
|
-
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.
|
|
556
|
+
onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
468
557
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
469
|
-
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] })), footerGroup.headers.map((header) => (jsxRuntime.jsx(react.
|
|
558
|
+
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] })), footerGroup.headers.map((header) => (jsxRuntime.jsx(react.Table.Header, { padding: "0", columnSpan: `${header.colSpan}`,
|
|
470
559
|
// styling resize and pinning start
|
|
471
|
-
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid", ...getThProps(header), children: jsxRuntime.jsx(react.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
560
|
+
maxWidth: `${header.getSize()}px`, width: `${header.getSize()}px`, display: "grid", ...getThProps(header), children: jsxRuntime.jsx(react.MenuRoot, { children: jsxRuntime.jsx(react.MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Box, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", _hover: { backgroundColor: "gray.100" }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
561
|
+
? null
|
|
562
|
+
: reactTable.flexRender(header.column.columnDef.footer, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && (
|
|
563
|
+
// <UpDownIcon />
|
|
564
|
+
jsxRuntime.jsx(jsxRuntime.Fragment, {})), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) })] }) }) }) }) }, `chakra-table-footer-${footerGroup.id}`)))] }, `chakra-table-footergroup-${footerGroup.id}`))) }));
|
|
476
565
|
};
|
|
477
566
|
|
|
478
|
-
const
|
|
567
|
+
const Button = React__namespace.forwardRef(function Button(props, ref) {
|
|
568
|
+
const { loading, disabled, loadingText, children, ...rest } = props;
|
|
569
|
+
return (jsxRuntime.jsx(react.Button, { disabled: loading || disabled, ref: ref, ...rest, children: loading && !loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.AbsoluteCenter, { display: "inline-flex", children: jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }) }), jsxRuntime.jsx(react.Span, { opacity: 0, children: children })] })) : loading && loadingText ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(react.Spinner, { size: "inherit", color: "inherit" }), loadingText] })) : (children) }));
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gray.700" }, showSelector = false, isSticky = true, alwaysShowSelector = true, tHeadProps = {}, }) => {
|
|
479
573
|
const { table } = useDataTableContext();
|
|
480
574
|
const SELECTION_BOX_WIDTH = 20;
|
|
481
|
-
const [hoveredCheckBox, setHoveredCheckBox] =
|
|
575
|
+
const [hoveredCheckBox, setHoveredCheckBox] = React.useState(false);
|
|
482
576
|
const handleRowHover = (isHovered) => {
|
|
483
577
|
setHoveredCheckBox(isHovered);
|
|
484
578
|
};
|
|
@@ -499,7 +593,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
499
593
|
? {
|
|
500
594
|
left: showSelector
|
|
501
595
|
? `${header.getStart("left") + SELECTION_BOX_WIDTH + table.getDensityValue() * 2}px`
|
|
502
|
-
: `${header.getStart("left")
|
|
596
|
+
: `${header.getStart("left")}px`,
|
|
503
597
|
background: pinnedBgColor.light,
|
|
504
598
|
position: "sticky",
|
|
505
599
|
zIndex: 1,
|
|
@@ -510,14 +604,11 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
510
604
|
: {};
|
|
511
605
|
return thProps;
|
|
512
606
|
};
|
|
513
|
-
const
|
|
607
|
+
const stickyProps = {
|
|
514
608
|
position: "sticky",
|
|
515
|
-
|
|
516
|
-
_dark: {
|
|
517
|
-
backgroundColor: "gray.800",
|
|
518
|
-
},
|
|
609
|
+
top: 0,
|
|
519
610
|
};
|
|
520
|
-
return (jsxRuntime.jsx(react.
|
|
611
|
+
return (jsxRuntime.jsx(react.Table.Header, { ...(isSticky ? stickyProps : {}), ...tHeadProps, children: table.getHeaderGroups().map((headerGroup) => (jsxRuntime.jsxs(react.Table.Row, { display: "flex", children: [showSelector && (jsxRuntime.jsxs(react.Table.ColumnHeader
|
|
521
612
|
// styling resize and pinning start
|
|
522
613
|
, { ...(table.getIsSomeColumnsPinned("left")
|
|
523
614
|
? {
|
|
@@ -529,7 +620,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
529
620
|
}
|
|
530
621
|
: {}),
|
|
531
622
|
// styling resize and pinning end
|
|
532
|
-
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.
|
|
623
|
+
padding: `${table.getDensityValue()}px`, onMouseEnter: () => handleRowHover(true), onMouseLeave: () => handleRowHover(false), display: "grid", children: [isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", children: jsxRuntime.jsx(Checkbox, { width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px`, isChecked: table.getIsAllRowsSelected(),
|
|
533
624
|
// indeterminate: table.getIsSomeRowsSelected(),
|
|
534
625
|
onChange: table.getToggleAllRowsSelectedHandler() }) })), !isCheckBoxVisible() && (jsxRuntime.jsx(react.Box, { as: "span", margin: "0rem", display: "grid", justifyItems: "center", alignItems: "center", width: `${SELECTION_BOX_WIDTH}px`, height: `${SELECTION_BOX_WIDTH}px` }))] })), headerGroup.headers.map((header) => {
|
|
535
626
|
const resizeProps = {
|
|
@@ -537,15 +628,15 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
537
628
|
onTouchStart: header.getResizeHandler(),
|
|
538
629
|
cursor: "col-resize",
|
|
539
630
|
};
|
|
540
|
-
return (jsxRuntime.jsxs(react.
|
|
631
|
+
return (jsxRuntime.jsxs(react.Table.ColumnHeader, { padding: "0rem", columnSpan: `${header.colSpan}`,
|
|
541
632
|
// styling resize and pinning start
|
|
542
|
-
width: `${header.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxRuntime.jsxs(
|
|
543
|
-
|
|
544
|
-
|
|
633
|
+
width: `${header.getSize()}px`, display: "grid", gridTemplateColumns: "1fr auto", zIndex: header.index, ...getThProps(header), children: [jsxRuntime.jsxs(MenuRoot, { children: [jsxRuntime.jsx(MenuTrigger, { asChild: true, children: jsxRuntime.jsx(react.Grid, { padding: `${table.getDensityValue()}px`, display: "flex", alignItems: "center", justifyContent: "start", borderRadius: "0rem", overflow: "auto", _hover: { backgroundColor: "gray.100" }, children: jsxRuntime.jsxs(react.Flex, { gap: "0.5rem", alignItems: "center", children: [header.isPlaceholder
|
|
634
|
+
? null
|
|
635
|
+
: reactTable.flexRender(header.column.columnDef.header, header.getContext()), jsxRuntime.jsx(react.Box, { children: header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [header.column.getIsSorted() === false && jsxRuntime.jsx(jsxRuntime.Fragment, {}), header.column.getIsSorted() === "asc" && (jsxRuntime.jsx(icons.ChevronUpIcon, {})), header.column.getIsSorted() === "desc" && (jsxRuntime.jsx(icons.ChevronDownIcon, {}))] })) }), jsxRuntime.jsx(react.Box, { children: header.column.getIsFiltered() && jsxRuntime.jsx(md.MdFilterListAlt, {}) })] }) }) }), jsxRuntime.jsxs(MenuContent, { children: [!header.column.getIsPinned() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "pin-column", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
545
636
|
header.column.pin("left");
|
|
546
|
-
}, children: "Pin Column" })), header.column.getIsPinned() && (jsxRuntime.jsx(
|
|
637
|
+
}, children: [jsxRuntime.jsx(md.MdPushPin, {}), "Pin Column"] }) })), header.column.getIsPinned() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "cancel-pin", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
547
638
|
header.column.pin(false);
|
|
548
|
-
}, children: "Cancel Pin" })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(
|
|
639
|
+
}, children: [jsxRuntime.jsx(md.MdCancel, {}), "Cancel Pin"] }) })), header.column.getCanSort() && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-ascend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
549
640
|
table.setSorting((state) => {
|
|
550
641
|
return [
|
|
551
642
|
...state.filter((column) => {
|
|
@@ -554,7 +645,7 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
554
645
|
{ id: header.id, desc: false },
|
|
555
646
|
];
|
|
556
647
|
});
|
|
557
|
-
}, children: "Sort Ascending" }), jsxRuntime.jsx(
|
|
648
|
+
}, children: [jsxRuntime.jsx(gr.GrAscend, {}), "Sort Ascending"] }) }), jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
558
649
|
table.setSorting((state) => {
|
|
559
650
|
return [
|
|
560
651
|
...state.filter((column) => {
|
|
@@ -563,9 +654,9 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
563
654
|
{ id: header.id, desc: true },
|
|
564
655
|
];
|
|
565
656
|
});
|
|
566
|
-
}, children: "Sort Descending" }), header.column.getIsSorted() && (jsxRuntime.jsx(
|
|
657
|
+
}, children: [jsxRuntime.jsx(gr.GrDescend, {}), "Sort Descending"] }) }), header.column.getIsSorted() && (jsxRuntime.jsx(MenuItem, { asChild: true, value: "sort-descend", children: jsxRuntime.jsxs(Button, { variant: "ghost", onClick: () => {
|
|
567
658
|
header.column.clearSorting();
|
|
568
|
-
}, children: "Clear Sorting" })
|
|
659
|
+
}, children: [jsxRuntime.jsx(md.MdClear, {}), "Clear Sorting"] }) }))] }))] })] }), canResize && (jsxRuntime.jsx(react.Box, { borderRight: "0.2rem solid", borderRightColor: header.column.getIsResizing() ? "gray.700" : "transparent", position: "relative", right: "0.1rem", width: "2px", height: "100%", userSelect: "none", style: { touchAction: "none" }, _hover: {
|
|
569
660
|
borderRightColor: header.column.getIsResizing()
|
|
570
661
|
? "gray.700"
|
|
571
662
|
: "gray.400",
|
|
@@ -573,28 +664,34 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
|
|
|
573
664
|
})] }, `chakra-table-headergroup-${headerGroup.id}`))) }));
|
|
574
665
|
};
|
|
575
666
|
|
|
576
|
-
const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, filterOptions = [], showFilterTags = false, showFilterName = false, showReload = false, showSelector = false, extraItems = jsxRuntime.jsx(jsxRuntime.Fragment, {}), tableProps = {}, }) => {
|
|
577
|
-
return (jsxRuntime.jsx(TableControls, { totalText: totalText, showFilter: showFilter, fitTableWidth: fitTableWidth, fitTableHeight: fitTableHeight, isMobile: isMobile, filterOptions: filterOptions, showFilterName: showFilterName, showFilterTags: showFilterTags, showReload: showReload, extraItems: extraItems, children: jsxRuntime.jsxs(Table, { ...tableProps, children: [jsxRuntime.jsx(TableHeader, { canResize: true, showSelector: showSelector }), jsxRuntime.jsx(TableBody, { showSelector: showSelector }), showFooter && jsxRuntime.jsx(TableFooter, { showSelector: showSelector })] }) }));
|
|
667
|
+
const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, filterOptions = [], showFilterTags = false, showFilterName = false, showReload = false, showSelector = false, extraItems = jsxRuntime.jsx(jsxRuntime.Fragment, {}), tableProps = {}, tHeadProps = {}, }) => {
|
|
668
|
+
return (jsxRuntime.jsx(TableControls, { totalText: totalText, showFilter: showFilter, fitTableWidth: fitTableWidth, fitTableHeight: fitTableHeight, isMobile: isMobile, filterOptions: filterOptions, showFilterName: showFilterName, showFilterTags: showFilterTags, showReload: showReload, extraItems: extraItems, children: jsxRuntime.jsxs(Table, { ...tableProps, children: [jsxRuntime.jsx(TableHeader, { canResize: true, showSelector: showSelector, tHeadProps: tHeadProps }), jsxRuntime.jsx(TableBody, { showSelector: showSelector }), showFooter && jsxRuntime.jsx(TableFooter, { showSelector: showSelector })] }) }));
|
|
578
669
|
};
|
|
579
670
|
|
|
580
671
|
const ReloadButton = ({ text = "Reload", variant = "icon", }) => {
|
|
581
672
|
const { refreshData } = useDataTableContext();
|
|
582
673
|
if (variant === "icon") {
|
|
583
|
-
return (jsxRuntime.jsx(
|
|
674
|
+
return (jsxRuntime.jsx(Tooltip, { showArrow: true, content: "This is the tooltip content", children: jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => {
|
|
584
675
|
refreshData();
|
|
585
|
-
}, "aria-label": "refresh" }) }));
|
|
676
|
+
}, "aria-label": "refresh", children: jsxRuntime.jsx(io5.IoReload, {}) }) }));
|
|
586
677
|
}
|
|
587
|
-
return (jsxRuntime.jsx(
|
|
678
|
+
return (jsxRuntime.jsx(Button, { variant: "ghost", leftIcon: jsxRuntime.jsx(io5.IoReload, {}), onClick: () => {
|
|
588
679
|
refreshData();
|
|
589
680
|
}, children: text }));
|
|
590
681
|
};
|
|
591
682
|
|
|
592
|
-
const
|
|
593
|
-
const {
|
|
594
|
-
|
|
595
|
-
|
|
683
|
+
const EmptyState = React__namespace.forwardRef(function EmptyState(props, ref) {
|
|
684
|
+
const { title, description, icon, children, ...rest } = props;
|
|
685
|
+
return (jsxRuntime.jsx(react.EmptyState.Root, { ref: ref, ...rest, children: jsxRuntime.jsxs(react.EmptyState.Content, { children: [icon && (jsxRuntime.jsx(react.EmptyState.Indicator, { children: icon })), description ? (jsxRuntime.jsxs(react.VStack, { textAlign: "center", children: [jsxRuntime.jsx(react.EmptyState.Title, { children: title }), jsxRuntime.jsx(react.EmptyState.Description, { children: description })] })) : (jsxRuntime.jsx(react.EmptyState.Title, { children: title })), children] }) }));
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
const EmptyResult = (jsxRuntime.jsx(EmptyState, { icon: jsxRuntime.jsx(hi.HiColorSwatch, {}), title: "No results found", description: "Try adjusting your search", children: jsxRuntime.jsxs(react.List.Root, { variant: "marker", children: [jsxRuntime.jsx(react.List.Item, { children: "Try removing filters" }), jsxRuntime.jsx(react.List.Item, { children: "Try different keywords" })] }) }));
|
|
689
|
+
const Table = ({ children, emptyComponent = EmptyResult, ...props }) => {
|
|
690
|
+
const { table } = useDataTableContext();
|
|
691
|
+
if (table.getRowModel().rows.length <= 0) {
|
|
692
|
+
return emptyComponent;
|
|
596
693
|
}
|
|
597
|
-
return (jsxRuntime.jsx(
|
|
694
|
+
return (jsxRuntime.jsx(react.Table.Root, { stickyHeader: true, variant: "outline", width: table.getCenterTotalSize(), ...props, children: children }));
|
|
598
695
|
};
|
|
599
696
|
|
|
600
697
|
const TableCardContainer = ({ children, ...props }) => {
|
|
@@ -605,13 +702,12 @@ const DefaultCardTitle = () => {
|
|
|
605
702
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
606
703
|
};
|
|
607
704
|
const TableCards = ({ isSelectable = false, showDisplayNameOnly = false, renderTitle = DefaultCardTitle, cardBodyProps = {} }) => {
|
|
608
|
-
const { table } =
|
|
705
|
+
const { table } = React.useContext(TableContext);
|
|
609
706
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getRowModel().rows.map((row) => {
|
|
610
|
-
return (jsxRuntime.jsx(react.Card, { children: jsxRuntime.jsxs(react.
|
|
707
|
+
return (jsxRuntime.jsx(react.Card.Root, { children: jsxRuntime.jsxs(react.Card.Body, { display: "flex", flexFlow: "column", gap: "0.5rem", ...cardBodyProps, children: [isSelectable && (jsxRuntime.jsx(Checkbox, { isChecked: row.getIsSelected(),
|
|
611
708
|
disabled: !row.getCanSelect(),
|
|
612
709
|
// indeterminate: row.getIsSomeSelected(),
|
|
613
710
|
onChange: row.getToggleSelectedHandler() })), renderTitle(row), jsxRuntime.jsx(react.Grid, { templateColumns: "auto 1fr", gap: "1rem", children: row.getVisibleCells().map((cell) => {
|
|
614
|
-
console.log(table.getColumn(cell.column.id), "dko");
|
|
615
711
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(react.Box, { children: [showDisplayNameOnly && (jsxRuntime.jsx(react.Text, { fontWeight: "bold", children: cell.column.columnDef.meta?.displayName ??
|
|
616
712
|
cell.column.id })), !showDisplayNameOnly && (jsxRuntime.jsx(jsxRuntime.Fragment, { children: reactTable.flexRender(cell.column.columnDef.header,
|
|
617
713
|
// @ts-expect-error Assuming the CellContext interface is the same as HeaderContext
|
|
@@ -629,11 +725,39 @@ const TableComponent = ({ render = () => {
|
|
|
629
725
|
|
|
630
726
|
const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
|
|
631
727
|
console.log(startDate, endDate, "dflp");
|
|
632
|
-
return (jsxRuntime.jsx(react.Box, { p:
|
|
728
|
+
return (jsxRuntime.jsx(react.Box, { p: "1rem", children: jsxRuntime.jsxs(react.VStack, { children: [jsxRuntime.jsxs(react.Box, { children: [jsxRuntime.jsx(react.Box, { children: "Start Date" }), jsxRuntime.jsx(react.Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxRuntime.jsxs(react.Box, { children: [jsxRuntime.jsx(react.Box, { children: "End Date" }), jsxRuntime.jsx(react.Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
|
|
633
729
|
};
|
|
634
730
|
|
|
731
|
+
const Slider = React__namespace.forwardRef(function Slider(props, ref) {
|
|
732
|
+
const { marks: marksProp, label, showValue, ...rest } = props;
|
|
733
|
+
const value = props.defaultValue ?? props.value;
|
|
734
|
+
const marks = marksProp?.map((mark) => {
|
|
735
|
+
if (typeof mark === "number")
|
|
736
|
+
return { value: mark, label: undefined };
|
|
737
|
+
return mark;
|
|
738
|
+
});
|
|
739
|
+
const hasMarkLabel = !!marks?.some((mark) => mark.label);
|
|
740
|
+
return (jsxRuntime.jsxs(react.Slider.Root, { ref: ref, thumbAlignment: "center", ...rest, children: [label && !showValue && (jsxRuntime.jsx(react.Slider.Label, { children: label })), label && showValue && (jsxRuntime.jsxs(react.HStack, { justify: "space-between", children: [jsxRuntime.jsx(react.Slider.Label, { children: label }), jsxRuntime.jsx(react.Slider.ValueText, {})] })), jsxRuntime.jsxs(react.Slider.Control, { "data-has-mark-label": hasMarkLabel || undefined, children: [jsxRuntime.jsx(react.Slider.Track, { children: jsxRuntime.jsx(react.Slider.Range, {}) }), jsxRuntime.jsx(SliderThumbs, { value: value }), jsxRuntime.jsx(SliderMarks, { marks: marks })] })] }));
|
|
741
|
+
});
|
|
742
|
+
function SliderThumbs(props) {
|
|
743
|
+
const { value } = props;
|
|
744
|
+
return (jsxRuntime.jsx(react.For, { each: value, children: (_, index) => (jsxRuntime.jsx(react.Slider.Thumb, { index: index, children: jsxRuntime.jsx(react.Slider.HiddenInput, {}) }, index)) }));
|
|
745
|
+
}
|
|
746
|
+
const SliderMarks = React__namespace.forwardRef(function SliderMarks(props, ref) {
|
|
747
|
+
const { marks } = props;
|
|
748
|
+
if (!marks?.length)
|
|
749
|
+
return null;
|
|
750
|
+
return (jsxRuntime.jsx(react.Slider.MarkerGroup, { ref: ref, children: marks.map((mark, index) => {
|
|
751
|
+
const value = typeof mark === "number" ? mark : mark.value;
|
|
752
|
+
const label = typeof mark === "number" ? undefined : mark.label;
|
|
753
|
+
return (jsxRuntime.jsxs(react.Slider.Marker, { value: value, children: [jsxRuntime.jsx(react.Slider.MarkerIndicator, {}), label] }, index));
|
|
754
|
+
}) }));
|
|
755
|
+
});
|
|
756
|
+
|
|
635
757
|
const RangeFilter = ({ range, setRange, defaultValue, min, max, step, }) => {
|
|
636
|
-
return (jsxRuntime.jsx(react.Box, { p: 8, children: jsxRuntime.
|
|
758
|
+
return (jsxRuntime.jsx(react.Box, { p: 8, children: jsxRuntime.jsx(Slider, { width: "full", min: min, max: max, defaultValue: defaultValue, step: step, name: `Selected Range: ${range[0]} - ${range[1]}`,
|
|
759
|
+
// value={field.value}
|
|
760
|
+
onValueChange: (val) => setRange(val.value) }) }));
|
|
637
761
|
};
|
|
638
762
|
|
|
639
763
|
const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
@@ -645,13 +769,22 @@ const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
|
|
|
645
769
|
onTagChange([...selectedTags, tag]);
|
|
646
770
|
}
|
|
647
771
|
};
|
|
648
|
-
return (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsxRuntime.jsx(
|
|
772
|
+
return (jsxRuntime.jsx(react.Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsxRuntime.jsx(Tag, { variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", closable: selectedTags.includes(tag) ? true : undefined, onClick: () => toggleTag(tag), children: tag }))) }));
|
|
649
773
|
};
|
|
650
774
|
|
|
651
|
-
function
|
|
775
|
+
const Radio = React__namespace.forwardRef(function Radio(props, ref) {
|
|
776
|
+
const { children, inputProps, rootRef, ...rest } = props;
|
|
777
|
+
return (jsxRuntime.jsxs(react.RadioGroup.Item, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.RadioGroup.ItemHiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsx(react.RadioGroup.ItemIndicator, {}), children && (jsxRuntime.jsx(react.RadioGroup.ItemText, { children: children }))] }));
|
|
778
|
+
});
|
|
779
|
+
const RadioGroup = react.RadioGroup.Root;
|
|
780
|
+
|
|
781
|
+
const Filter = ({ column }) => {
|
|
652
782
|
const { filterVariant } = column.columnDef.meta ?? {};
|
|
653
783
|
const displayName = column.columnDef.meta?.displayName ?? column.id;
|
|
654
784
|
const filterOptions = column.columnDef.meta?.filterOptions ?? [];
|
|
785
|
+
// const collection = createListCollection({
|
|
786
|
+
// items: filterOptions,
|
|
787
|
+
// });
|
|
655
788
|
if (column.columns.length > 0) {
|
|
656
789
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), column.columns.map((column) => {
|
|
657
790
|
return jsxRuntime.jsx(Filter, { column: column }, column.id);
|
|
@@ -661,11 +794,9 @@ function Filter({ column }) {
|
|
|
661
794
|
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
662
795
|
}
|
|
663
796
|
if (filterVariant === "select") {
|
|
664
|
-
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(
|
|
665
|
-
column.setFilterValue(
|
|
666
|
-
}, children: filterOptions.map((
|
|
667
|
-
return (jsxRuntime.jsx("option", { value: option, children: option }, `${option}`));
|
|
668
|
-
}) })] }, column.id));
|
|
797
|
+
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(RadioGroup, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onValueChange: (details) => {
|
|
798
|
+
column.setFilterValue(details.value);
|
|
799
|
+
}, children: jsxRuntime.jsx(react.Flex, { flexFlow: 'wrap', gap: '0.5rem', children: filterOptions.map((item) => (jsxRuntime.jsx(Radio, { value: item, children: item }, item))) }) })] }, column.id));
|
|
669
800
|
}
|
|
670
801
|
if (filterVariant === "tag") {
|
|
671
802
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
|
|
@@ -725,7 +856,7 @@ function Filter({ column }) {
|
|
|
725
856
|
return (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.25rem", children: [jsxRuntime.jsx(react.Text, { children: displayName }), jsxRuntime.jsx(react.Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
|
|
726
857
|
column.setFilterValue(e.target.value);
|
|
727
858
|
} })] }, column.id));
|
|
728
|
-
}
|
|
859
|
+
};
|
|
729
860
|
const TableFilter = () => {
|
|
730
861
|
const { table } = useDataTableContext();
|
|
731
862
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: table.getAllColumns().map((column) => {
|
|
@@ -736,11 +867,11 @@ const TableFilter = () => {
|
|
|
736
867
|
const TableFilterTags = () => {
|
|
737
868
|
const { table } = useDataTableContext();
|
|
738
869
|
return (jsxRuntime.jsx(react.Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }) => {
|
|
739
|
-
return (jsxRuntime.jsxs(
|
|
870
|
+
return (jsxRuntime.jsxs(Tag, { gap: "0.5rem", children: [`${id}: ${value}`, jsxRuntime.jsx(react.IconButton, { variant: "ghost", "aria-label": "remove filter", onClick: () => {
|
|
740
871
|
table.setColumnFilters(table.getState().columnFilters.filter((filter) => {
|
|
741
872
|
return filter.value != value;
|
|
742
873
|
}));
|
|
743
|
-
},
|
|
874
|
+
}, children: jsxRuntime.jsx(cg.CgClose, {}) })] }, `${id}-${value}`));
|
|
744
875
|
}) }));
|
|
745
876
|
};
|
|
746
877
|
|
|
@@ -750,8 +881,8 @@ const TableLoadingComponent = ({ render, }) => {
|
|
|
750
881
|
};
|
|
751
882
|
|
|
752
883
|
const ColumnOrderChanger = ({ columns }) => {
|
|
753
|
-
const [order, setOrder] =
|
|
754
|
-
const [originalOrder, setOriginalOrder] =
|
|
884
|
+
const [order, setOrder] = React.useState([]);
|
|
885
|
+
const [originalOrder, setOriginalOrder] = React.useState([]);
|
|
755
886
|
const { table } = useDataTableContext();
|
|
756
887
|
const handleChangeOrder = (startIndex, endIndex) => {
|
|
757
888
|
const newOrder = Array.from(order);
|
|
@@ -759,10 +890,10 @@ const ColumnOrderChanger = ({ columns }) => {
|
|
|
759
890
|
newOrder.splice(endIndex, 0, removed);
|
|
760
891
|
setOrder(newOrder);
|
|
761
892
|
};
|
|
762
|
-
|
|
893
|
+
React.useEffect(() => {
|
|
763
894
|
setOrder(columns);
|
|
764
895
|
}, [columns]);
|
|
765
|
-
|
|
896
|
+
React.useEffect(() => {
|
|
766
897
|
if (originalOrder.length > 0) {
|
|
767
898
|
return;
|
|
768
899
|
}
|
|
@@ -802,9 +933,9 @@ const TableOrderer = () => {
|
|
|
802
933
|
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
|
|
803
934
|
};
|
|
804
935
|
|
|
805
|
-
const TablePagination = (
|
|
936
|
+
const TablePagination = () => {
|
|
806
937
|
const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTableContext().table;
|
|
807
|
-
return (jsxRuntime.jsxs(react.
|
|
938
|
+
return (jsxRuntime.jsxs(react.Group, { attached: true, children: [jsxRuntime.jsx(react.IconButton, { onClick: () => firstPage(), disabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost", children: jsxRuntime.jsx(md.MdFirstPage, {}) }), jsxRuntime.jsx(react.IconButton, { onClick: () => previousPage(), disabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowBack, {}) }), jsxRuntime.jsx(Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsxRuntime.jsx(react.IconButton, { onClick: () => nextPage(), disabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsxRuntime.jsx(md.MdArrowForward, {}) }), jsxRuntime.jsx(react.IconButton, { onClick: () => lastPage(), disabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsxRuntime.jsx(md.MdLastPage, {}) })] }));
|
|
808
939
|
};
|
|
809
940
|
|
|
810
941
|
const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineChecklist, {}), clearAllIcon = jsxRuntime.jsx(md.MdClear, {}), selectAllText = "", clearAllText = "", }) => {
|
|
@@ -817,16 +948,21 @@ const SelectAllRowsToggle = ({ selectAllIcon = jsxRuntime.jsx(md.MdOutlineCheckl
|
|
|
817
948
|
};
|
|
818
949
|
|
|
819
950
|
const TableSelector = () => {
|
|
820
|
-
const { table } =
|
|
951
|
+
const { table } = React.useContext(TableContext);
|
|
821
952
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsxs(react.Button, { onClick: () => { }, variant: "ghost", display: "flex", gap: "0.25rem", children: [jsxRuntime.jsx(react.Box, { fontSize: "sm", children: `${table.getSelectedRowModel().rows.length}` }), jsxRuntime.jsx(react.Icon, { as: io.IoMdCheckbox })] })), !table.getIsAllPageRowsSelected() && jsxRuntime.jsx(SelectAllRowsToggle, {}), table.getSelectedRowModel().rows.length > 0 && (jsxRuntime.jsx(react.IconButton, { variant: "ghost", icon: jsxRuntime.jsx(react.Icon, { as: md.MdClear }), onClick: () => {
|
|
822
953
|
table.resetRowSelection();
|
|
823
954
|
}, "aria-label": "reset selection" }))] }));
|
|
824
955
|
};
|
|
825
956
|
|
|
957
|
+
const Switch = React__namespace.forwardRef(function Switch(props, ref) {
|
|
958
|
+
const { inputProps, children, rootRef, trackLabel, thumbLabel, ...rest } = props;
|
|
959
|
+
return (jsxRuntime.jsxs(react.Switch.Root, { ref: rootRef, ...rest, children: [jsxRuntime.jsx(react.Switch.HiddenInput, { ref: ref, ...inputProps }), jsxRuntime.jsxs(react.Switch.Control, { children: [jsxRuntime.jsx(react.Switch.Thumb, { children: thumbLabel && (jsxRuntime.jsx(react.Switch.ThumbIndicator, { fallback: thumbLabel?.off, children: thumbLabel?.on })) }), trackLabel && (jsxRuntime.jsx(react.Switch.Indicator, { fallback: trackLabel.off, children: trackLabel.on }))] }), children != null && (jsxRuntime.jsx(react.Switch.Label, { children: children }))] }));
|
|
960
|
+
});
|
|
961
|
+
|
|
826
962
|
const TableViewer = () => {
|
|
827
963
|
const { table } = useDataTableContext();
|
|
828
964
|
const columns = table.getAllLeafColumns();
|
|
829
|
-
const [columnOrder, setColumnOrder] =
|
|
965
|
+
const [columnOrder, setColumnOrder] = React.useState(columns.map((column) => column.id));
|
|
830
966
|
const handleDragEnd = (result) => {
|
|
831
967
|
if (!result.destination)
|
|
832
968
|
return;
|
|
@@ -838,22 +974,22 @@ const TableViewer = () => {
|
|
|
838
974
|
};
|
|
839
975
|
return (jsxRuntime.jsx(reactBeautifulDnd.DragDropContext, { onDragEnd: handleDragEnd, children: jsxRuntime.jsx(reactBeautifulDnd.Droppable, { droppableId: "columns", children: (provided) => (jsxRuntime.jsxs(react.Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, index) => {
|
|
840
976
|
const displayName = column.columnDef.meta?.displayName || column.id;
|
|
841
|
-
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: index, children: (provided) => (jsxRuntime.jsxs(react.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "0", children: jsxRuntime.jsx(
|
|
977
|
+
return (jsxRuntime.jsx(reactBeautifulDnd.Draggable, { draggableId: column.id, index: index, children: (provided) => (jsxRuntime.jsxs(react.Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsxRuntime.jsx(react.Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "0", children: jsxRuntime.jsx(fa.FaGripLinesVertical, { color: "gray.400" }) }), jsxRuntime.jsxs(react.Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxRuntime.jsx(react.Box, { children: displayName }), jsxRuntime.jsx(Switch, { checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] })) }, column.id));
|
|
842
978
|
}), provided.placeholder] })) }) }));
|
|
843
979
|
};
|
|
844
980
|
|
|
845
|
-
const TextCell = ({ label,
|
|
981
|
+
const TextCell = ({ label, padding = "0rem", children, ...props }) => {
|
|
846
982
|
if (label) {
|
|
847
|
-
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(
|
|
983
|
+
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(Tooltip, { content: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", children: label }), children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", ...props, children: children }) }) }));
|
|
848
984
|
}
|
|
849
|
-
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all",
|
|
985
|
+
return (jsxRuntime.jsx(react.Flex, { alignItems: "center", height: "100%", padding: padding, children: jsxRuntime.jsx(react.Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", ...props, children: children }) }));
|
|
850
986
|
};
|
|
851
987
|
|
|
852
988
|
const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSuccess = () => { }, defaultData, }) => {
|
|
853
|
-
const [loading, setLoading] =
|
|
854
|
-
const [hasError, setHasError] =
|
|
855
|
-
const [data, setData] =
|
|
856
|
-
const [timer, setTimer] =
|
|
989
|
+
const [loading, setLoading] = React.useState(true);
|
|
990
|
+
const [hasError, setHasError] = React.useState(false);
|
|
991
|
+
const [data, setData] = React.useState(defaultData);
|
|
992
|
+
const [timer, setTimer] = React.useState();
|
|
857
993
|
const refreshData = async ({ debounce, delay } = { debounce: false, delay: 1000 }) => {
|
|
858
994
|
if (debounce) {
|
|
859
995
|
await debouncedGetData(delay);
|
|
@@ -885,7 +1021,7 @@ const useDataFromUrl = ({ url, params = {}, disableFirstFetch = false, onFetchSu
|
|
|
885
1021
|
await getData();
|
|
886
1022
|
}, delay));
|
|
887
1023
|
};
|
|
888
|
-
|
|
1024
|
+
React.useEffect(() => {
|
|
889
1025
|
if (disableFirstFetch) {
|
|
890
1026
|
return;
|
|
891
1027
|
}
|
|
@@ -926,14 +1062,14 @@ const useDataTable = ({ default: { sorting: defaultSorting = [], pagination: def
|
|
|
926
1062
|
density: "sm",
|
|
927
1063
|
},
|
|
928
1064
|
}) => {
|
|
929
|
-
const [sorting, setSorting] =
|
|
930
|
-
const [columnFilters, setColumnFilters] =
|
|
931
|
-
const [pagination, setPagination] =
|
|
932
|
-
const [rowSelection, setRowSelection] =
|
|
933
|
-
const [columnOrder, setColumnOrder] =
|
|
934
|
-
const [globalFilter, setGlobalFilter] =
|
|
935
|
-
const [density, setDensity] =
|
|
936
|
-
const [columnVisibility, setColumnVisibility] =
|
|
1065
|
+
const [sorting, setSorting] = React.useState(defaultSorting);
|
|
1066
|
+
const [columnFilters, setColumnFilters] = React.useState(defaultColumnFilters); // can set initial column filter state here
|
|
1067
|
+
const [pagination, setPagination] = React.useState(defaultPagination);
|
|
1068
|
+
const [rowSelection, setRowSelection] = React.useState(defaultRowSelection);
|
|
1069
|
+
const [columnOrder, setColumnOrder] = React.useState(defaultColumnOrder);
|
|
1070
|
+
const [globalFilter, setGlobalFilter] = React.useState(defaultGlobalFilter);
|
|
1071
|
+
const [density, setDensity] = React.useState(defaultDensity);
|
|
1072
|
+
const [columnVisibility, setColumnVisibility] = React.useState(defaultColumnVisibility);
|
|
937
1073
|
return {
|
|
938
1074
|
sorting,
|
|
939
1075
|
setSorting,
|
|
@@ -970,14 +1106,14 @@ const useDataTableServer = ({ url, onFetchSuccess = () => { }, default: { sortin
|
|
|
970
1106
|
globalFilter: "",
|
|
971
1107
|
density: "sm",
|
|
972
1108
|
}, debounce = true, debounceDelay = 1000, }) => {
|
|
973
|
-
const [sorting, setSorting] =
|
|
974
|
-
const [columnFilters, setColumnFilters] =
|
|
975
|
-
const [pagination, setPagination] =
|
|
976
|
-
const [rowSelection, setRowSelection] =
|
|
977
|
-
const [columnOrder, setColumnOrder] =
|
|
978
|
-
const [globalFilter, setGlobalFilter] =
|
|
979
|
-
const [density, setDensity] =
|
|
980
|
-
const [columnVisibility, setColumnVisibility] =
|
|
1109
|
+
const [sorting, setSorting] = React.useState(defaultSorting);
|
|
1110
|
+
const [columnFilters, setColumnFilters] = React.useState(defaultColumnFilters); // can set initial column filter state here
|
|
1111
|
+
const [pagination, setPagination] = React.useState(defaultPagination);
|
|
1112
|
+
const [rowSelection, setRowSelection] = React.useState(defaultRowSelection);
|
|
1113
|
+
const [columnOrder, setColumnOrder] = React.useState(defaultColumnOrder);
|
|
1114
|
+
const [globalFilter, setGlobalFilter] = React.useState(defaultGlobalFilter);
|
|
1115
|
+
const [density, setDensity] = React.useState(defaultDensity);
|
|
1116
|
+
const [columnVisibility, setColumnVisibility] = React.useState(defaultColumnVisibility);
|
|
981
1117
|
const { data, loading, hasError, refreshData } = useDataFromUrl({
|
|
982
1118
|
url: url,
|
|
983
1119
|
defaultData: {
|
|
@@ -1003,7 +1139,7 @@ const useDataTableServer = ({ url, onFetchSuccess = () => { }, default: { sortin
|
|
|
1003
1139
|
disableFirstFetch: true,
|
|
1004
1140
|
onFetchSuccess: onFetchSuccess,
|
|
1005
1141
|
});
|
|
1006
|
-
|
|
1142
|
+
React.useEffect(() => {
|
|
1007
1143
|
refreshData({ debounce, debounceDelay });
|
|
1008
1144
|
}, [pagination, sorting, columnFilters, globalFilter, url]);
|
|
1009
1145
|
return {
|
|
@@ -1050,14 +1186,22 @@ const FilterOptions = ({ column }) => {
|
|
|
1050
1186
|
}) }));
|
|
1051
1187
|
};
|
|
1052
1188
|
|
|
1053
|
-
const
|
|
1189
|
+
const InputGroup = React__namespace.forwardRef(function InputGroup(props, ref) {
|
|
1190
|
+
const { startElement, startElementProps, endElement, endElementProps, children, startOffset = "6px", endOffset = "6px", ...rest } = props;
|
|
1191
|
+
return (jsxRuntime.jsxs(react.Group, { ref: ref, ...rest, children: [startElement && (jsxRuntime.jsx(react.InputElement, { pointerEvents: "none", ...startElementProps, children: startElement })), React__namespace.cloneElement(children, {
|
|
1192
|
+
...(startElement && {
|
|
1193
|
+
ps: `calc(var(--input-height) - ${startOffset})`,
|
|
1194
|
+
}),
|
|
1195
|
+
...(endElement && { pe: `calc(var(--input-height) - ${endOffset})` }),
|
|
1196
|
+
...children.props,
|
|
1197
|
+
}), endElement && (jsxRuntime.jsx(react.InputElement, { placement: "end", ...endElementProps, children: endElement }))] }));
|
|
1198
|
+
});
|
|
1199
|
+
|
|
1200
|
+
const GlobalFilter = () => {
|
|
1054
1201
|
const { table } = useDataTableContext();
|
|
1055
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
table.setGlobalFilter(e.target.value);
|
|
1060
|
-
} })] }) }) }));
|
|
1202
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(InputGroup, { flex: "1", startElement: jsxRuntime.jsx(md.MdSearch, {}), children: jsxRuntime.jsx(react.Input, { placeholder: "Outline", variant: "outline", onChange: (e) => {
|
|
1203
|
+
table.setGlobalFilter(e.target.value);
|
|
1204
|
+
} }) }) }));
|
|
1061
1205
|
};
|
|
1062
1206
|
|
|
1063
1207
|
exports.DataTable = DataTable;
|