@bsol-oss/react-datatable5 1.0.60 → 1.0.62

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.
Files changed (51) hide show
  1. package/dist/index.d.ts +39 -6
  2. package/dist/index.js +319 -195
  3. package/dist/index.mjs +320 -200
  4. package/dist/types/components/Controls/DensityFeature.d.ts +23 -0
  5. package/dist/types/components/Controls/DensityToggleButton.d.ts +6 -0
  6. package/dist/types/components/Controls/EditFilterButton.d.ts +9 -0
  7. package/dist/types/components/Controls/EditOrderButton.d.ts +7 -0
  8. package/dist/types/components/Controls/EditSortingButton.d.ts +7 -0
  9. package/dist/types/components/Controls/EditViewButton.d.ts +7 -0
  10. package/dist/types/components/Controls/PageSizeControl.d.ts +4 -0
  11. package/dist/types/components/Controls/ResetFilteringButton.d.ts +4 -0
  12. package/dist/types/components/Controls/ResetSelectionButton.d.ts +4 -0
  13. package/dist/types/components/Controls/ResetSortingButton.d.ts +4 -0
  14. package/dist/types/components/Controls/RowCountText.d.ts +1 -0
  15. package/dist/types/components/Controls/SelectAllRowsToggle.d.ts +8 -0
  16. package/dist/types/components/DataTable/DataTable.d.ts +33 -0
  17. package/dist/types/components/DataTable/DataTableContext.d.ts +10 -0
  18. package/dist/types/components/DataTable/DataTableServer.d.ts +38 -0
  19. package/dist/types/components/DataTable/DefaultTable.d.ts +5 -0
  20. package/dist/types/components/DataTable/Table.d.ts +8 -0
  21. package/dist/types/components/DataTable/TableBody.d.ts +17 -0
  22. package/dist/types/components/DataTable/TableCardContainer.d.ts +6 -0
  23. package/dist/types/components/DataTable/TableCards.d.ts +4 -0
  24. package/dist/types/components/DataTable/TableComponent.d.ts +6 -0
  25. package/dist/types/components/DataTable/TableControls.d.ts +13 -0
  26. package/dist/types/components/DataTable/TableFilter.d.ts +19 -0
  27. package/dist/types/components/DataTable/TableFilterTags.d.ts +1 -0
  28. package/dist/types/components/DataTable/TableFooter.d.ts +7 -0
  29. package/dist/types/components/DataTable/TableHeader.d.ts +8 -0
  30. package/dist/types/components/DataTable/TableLoadingComponent.d.ts +5 -0
  31. package/dist/types/components/DataTable/TableOrderer.d.ts +1 -0
  32. package/dist/types/components/DataTable/TablePagination.d.ts +3 -0
  33. package/dist/types/components/DataTable/TableReloadButton.d.ts +4 -0
  34. package/dist/types/components/DataTable/TableSelector.d.ts +1 -0
  35. package/dist/types/components/DataTable/TableSorter.d.ts +1 -0
  36. package/dist/types/components/DataTable/TableViewer.d.ts +1 -0
  37. package/dist/types/components/DataTable/TextCell.d.ts +10 -0
  38. package/dist/types/components/DataTable/useDataFromUrl.d.ts +14 -0
  39. package/dist/types/components/DataTable/useDataTable.d.ts +7 -0
  40. package/dist/types/components/DefaultTable.d.ts +3 -7
  41. package/dist/types/components/Filter/DateRangeFilter.d.ts +9 -0
  42. package/dist/types/components/Filter/FilterOptions.d.ts +4 -0
  43. package/dist/types/components/Filter/GlobalFilter.d.ts +3 -0
  44. package/dist/types/components/Filter/RangeFilter.d.ts +11 -0
  45. package/dist/types/components/Filter/TagFilter.d.ts +8 -0
  46. package/dist/types/components/FilterOptions.d.ts +4 -0
  47. package/dist/types/components/TableControls.d.ts +13 -0
  48. package/dist/types/components/TableLoadingComponent.d.ts +5 -0
  49. package/dist/types/components/TableReloadButton.d.ts +4 -0
  50. package/dist/types/index.d.ts +35 -31
  51. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,16 +1,18 @@
1
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
1
+ import { jsx, jsxs, Fragment } 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
- import { Button, Flex, Text, Select, Input, useDisclosure, IconButton, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, Grid, Icon, Box, Switch, InputGroup, InputLeftElement, Menu, MenuButton, MenuList, MenuItem, Table as Table$1, FormLabel, Checkbox, Tag, Tfoot, Tr as Tr$1, Th, Thead, Portal, ButtonGroup, Card, CardBody, Tooltip } from '@chakra-ui/react';
7
- import { MdFilterAlt, MdSearch, MdFilterListAlt, MdPushPin, MdCancel, MdSort, MdFirstPage, MdArrowBack, MdArrowForward, MdLastPage, MdOutlineViewColumn, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutlineSort, MdOutlineChecklist, MdClear } from 'react-icons/md';
8
- import { IoMdEye, IoMdClose, IoMdCheckbox } from 'react-icons/io';
9
- import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
10
- import { FaGripLinesVertical } from 'react-icons/fa';
11
- import { ChevronDownIcon, CloseIcon, ChevronUpIcon, UpDownIcon } from '@chakra-ui/icons';
6
+ import { Box, FormLabel, Checkbox, Grid, Flex, Text, Tfoot, Tr as Tr$1, Th, Menu, MenuButton, Thead, Portal, MenuList, MenuItem, IconButton, Button, useDisclosure, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, InputGroup, InputLeftElement, Icon, Input, Table as Table$1, Card, CardBody, VStack, FormControl, RangeSlider, RangeSliderTrack, RangeSliderFilledTrack, RangeSliderThumb, WrapItem, Tag, TagLabel, TagCloseButton, Select, ButtonGroup, Switch, Tooltip } from '@chakra-ui/react';
12
7
  import { Tbody, Tr, Td } from '@chakra-ui/table';
8
+ import { MdOutlineViewColumn, MdFilterListAlt, MdPushPin, MdCancel, MdClear, MdFilterAlt, MdOutlineMoveDown, MdOutlineSort, MdClose, MdSearch, MdArrowUpward, MdArrowDownward, MdFirstPage, MdArrowBack, MdArrowForward, MdLastPage, MdOutlineChecklist } from 'react-icons/md';
9
+ import { ChevronUpIcon, ChevronDownIcon, UpDownIcon, CloseIcon } from '@chakra-ui/icons';
10
+ import { GrAscend, GrDescend } from 'react-icons/gr';
13
11
  import { AiOutlineColumnWidth } from 'react-icons/ai';
12
+ import { IoMdEye, IoMdCheckbox } from 'react-icons/io';
13
+ import { IoReload } from 'react-icons/io5';
14
+ import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
15
+ import { FaGripLinesVertical } from 'react-icons/fa';
14
16
 
15
17
  const TableContext = createContext({
16
18
  table: {},
@@ -308,120 +310,6 @@ const DataTableServer = ({ columns, url, enableRowSelection = true, enableMultiR
308
310
  }, children: children }));
309
311
  };
310
312
 
311
- const useDataTable = () => {
312
- const { table, refreshData, globalFilter, setGlobalFilter, loading } = useContext(TableContext);
313
- return { table, refreshData, globalFilter, setGlobalFilter, loading };
314
- };
315
-
316
- const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
317
- const { table } = useDataTable();
318
- return (jsx(Button, { onClick: () => {
319
- table.resetColumnFilters();
320
- }, children: text }));
321
- };
322
-
323
- function Filter({ column }) {
324
- const { filterVariant } = column.columnDef.meta ?? {};
325
- const displayName = column.columnDef.meta?.displayName ?? column.id;
326
- const filterOptions = column.columnDef.meta?.filterOptions ?? [];
327
- if (column.columns.length > 0) {
328
- return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), column.columns.map((column) => {
329
- return jsx(Filter, { column: column }, column.id);
330
- })] }, column.id));
331
- }
332
- if (!column.getCanFilter()) {
333
- return jsx(Fragment, {});
334
- }
335
- if (filterVariant === "select") {
336
- return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(Select, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", placeholder: "Select option", onChange: (e) => {
337
- column.setFilterValue(e.target.value);
338
- }, children: filterOptions.map((option) => {
339
- return (jsx("option", { value: option, children: option }, `${option}`));
340
- }) })] }, column.id));
341
- }
342
- if (filterVariant === "range") {
343
- const filterValue = column.getFilterValue() ?? [
344
- undefined,
345
- undefined,
346
- ];
347
- const [min, max] = filterValue;
348
- return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsxs(Flex, { gap: "0.5rem", children: [jsx(Input, { type: "number", placeholder: "min", value: min, onChange: (e) => {
349
- column.setFilterValue([Number(e.target.value), max]);
350
- } }), jsx(Input, { type: "number", placeholder: "max", value: max, onChange: (e) => {
351
- column.setFilterValue([min, Number(e.target.value)]);
352
- } })] })] }, column.id));
353
- }
354
- return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
355
- column.setFilterValue(e.target.value);
356
- } })] }, column.id));
357
- }
358
- const TableFilter = () => {
359
- const { table } = useDataTable();
360
- return (jsx(Fragment, { children: table.getAllColumns().map((column) => {
361
- return jsx(Filter, { column: column }, column.id);
362
- }) }));
363
- };
364
-
365
- const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsx(MdFilterAlt, {}), ...props }) => {
366
- const filterModal = useDisclosure();
367
- return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxs(Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsxs(Flex, { flexFlow: "column", gap: "1rem", children: [jsx(TableFilter, {}), jsx(ResetFilteringButton, { text: resetText })] }) }), jsx(ModalFooter, { children: jsx(Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
368
- };
369
-
370
- const TableViewer = () => {
371
- const { table } = useDataTable();
372
- const columns = table.getAllLeafColumns();
373
- const [columnOrder, setColumnOrder] = useState(columns.map((column, index) => {
374
- return column.id;
375
- }));
376
- const handleDragEnd = (result) => {
377
- if (!result.destination)
378
- return;
379
- const newColumnOrder = Array.from(columnOrder);
380
- const [removed] = newColumnOrder.splice(result.source.index, 1);
381
- newColumnOrder.splice(result.destination.index, 0, removed);
382
- setColumnOrder(newColumnOrder);
383
- table.setColumnOrder(newColumnOrder);
384
- };
385
- return (jsx(Fragment, { children: jsx(DragDropContext, { onDragEnd: handleDragEnd, children: jsx(Droppable, { droppableId: "columns", children: (provided) => (jsxs(Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, i) => {
386
- const displayName = column.columnDef.meta === undefined
387
- ? column.id
388
- : column.columnDef.meta.displayName;
389
- return (jsx(Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxs(Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsx(Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsx(Icon, { as: FaGripLinesVertical, color: "gray.400" }) }), jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxs(Box, { children: [" ", displayName] }), jsx(Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
390
- }), provided.placeholder] })) }) }) }));
391
- };
392
-
393
- const EditViewButton = ({ text, icon = jsx(IoMdEye, {}), title = "Edit View", }) => {
394
- const viewModel = useDisclosure();
395
- return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxs(Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { padding: "0 0 1rem 0", children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsx(TableViewer, {}) })] })] })] }));
396
- };
397
-
398
- const GlobalFilter = ({ icon = MdSearch }) => {
399
- const { globalFilter, setGlobalFilter } = useDataTable();
400
- return (jsx(Fragment, { children: jsx(Box, { children: jsxs(InputGroup, { children: [jsx(InputLeftElement, { pointerEvents: "none", children: jsx(Icon, { as: icon, color: "gray.300" }) }), jsx(Input, { value: globalFilter, onChange: (e) => {
401
- setGlobalFilter(e.target.value);
402
- } })] }) }) }));
403
- };
404
-
405
- const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
406
- const { table } = useDataTable();
407
- return (jsx(Fragment, { children: jsxs(Menu, { children: [jsx(MenuButton, { as: Button, variant: "ghost", rightIcon: jsx(ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsx(MenuList, { children: pageSizes.map((pageSize) => (jsx(MenuItem, { onClick: () => {
408
- table.setPageSize(Number(pageSize));
409
- }, children: pageSize }, crypto.randomUUID()))) })] }) }));
410
- };
411
-
412
- const RowCountText = () => {
413
- const { table } = useContext(TableContext);
414
- return jsx(Text, { children: table.getRowCount() });
415
- };
416
-
417
- const Table = ({ children, showLoading = false, loadingComponent = jsx(Fragment, { children: "Loading..." }), ...props }) => {
418
- const { table, loading } = useDataTable();
419
- if (showLoading) {
420
- return (jsxs(Fragment, { children: [loading && loadingComponent, !loading && (jsx(Table$1, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
421
- }
422
- return (jsx(Fragment, { children: jsx(Table$1, { width: table.getCenterTotalSize(), overflowX: "auto", ...props, children: children }) }));
423
- };
424
-
425
313
  const TableBody = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
426
314
  const { table } = useContext(TableContext);
427
315
  const SELECTION_BOX_WIDTH = 20;
@@ -471,15 +359,15 @@ const TableRowSelector = ({ index, row, hoveredRow, pinnedBgColor = { light: "gr
471
359
  onChange: row.getToggleSelectedHandler() }) }))] }));
472
360
  };
473
361
 
474
- const TableFilterTags = () => {
475
- const { table } = useDataTable();
476
- return (jsx(Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }, index) => {
477
- return (jsxs(Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsx(Text, { children: `${id}: ${value}` }), jsx(IconButton, { size: "xs", variant: "ghost", icon: jsx(CloseIcon, {}), onClick: () => {
478
- table.setColumnFilters(table.getState().columnFilters.filter((value, curIndex) => {
479
- return curIndex != index;
480
- }));
481
- }, "aria-label": "remove filter" })] }, `${id}-${value}`));
482
- }) }));
362
+ const TableControls = ({ totalText = "Total:", showFilter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, children = jsx(Fragment, {}), showFilterName = false, showFilterTags = false, filterOptions = [], }) => {
363
+ return (jsxs(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: [jsxs(Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsx(Box, { children: jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsx(MdOutlineViewColumn, {}) }) }), jsx(Flex, { gap: "1rem", justifySelf: "end", children: showFilter && (jsxs(Fragment, { children: [jsx(GlobalFilter, {}), jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] })) })] }), jsx(Flex, { gridColumn: "1 / span 2", flexFlow: "column", gap: "0.5rem", children: filterOptions.map((column) => {
364
+ return (jsxs(Flex, { alignItems: "center", flexFlow: "wrap", gap: "0.5rem", children: [showFilterName && jsxs(Text, { children: [column, ":"] }), jsx(FilterOptions, { column: column })] }));
365
+ }) }), jsx(Flex, { gridColumn: "1 / span 2", children: showFilterTags && jsx(TableFilterTags, {}) }), jsx(Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: children }), jsxs(Flex, { gap: "1rem", alignItems: "center", children: [jsx(PageSizeControl, {}), jsxs(Flex, { children: [jsx(Text, { paddingRight: "0.5rem", children: totalText }), jsx(RowCountText, {})] })] }), jsx(Box, { justifySelf: "end", children: jsx(TablePagination, {}) })] }));
366
+ };
367
+
368
+ const useDataTable = () => {
369
+ const { table, refreshData, globalFilter, setGlobalFilter, loading } = useContext(TableContext);
370
+ return { table, refreshData, globalFilter, setGlobalFilter, loading };
483
371
  };
484
372
 
485
373
  const TableFooter = ({ pinnedBgColor = { light: "gray.50", dark: "gray.700" }, }) => {
@@ -584,9 +472,25 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
584
472
  header.column.pin("left");
585
473
  }, children: "Pin Column" })), header.column.getIsPinned() && (jsx(MenuItem, { icon: jsx(MdCancel, {}), onClick: () => {
586
474
  header.column.pin(false);
587
- }, children: "Cancel Pin" })), header.column.getCanSort() && (jsxs(Fragment, { children: [jsx(MenuItem, { icon: jsx(MdSort, {}), onClick: () => {
588
- header.column.toggleSorting();
589
- }, children: "Toggle Sorting" }), header.column.getIsSorted() && (jsx(MenuItem, { icon: jsx(IoMdClose, {}), onClick: () => {
475
+ }, children: "Cancel Pin" })), header.column.getCanSort() && (jsxs(Fragment, { children: [jsx(MenuItem, { icon: jsx(GrAscend, {}), onClick: () => {
476
+ table.setSorting((state) => {
477
+ return [
478
+ ...state.filter((column) => {
479
+ return column.id !== header.id;
480
+ }),
481
+ { id: header.id, desc: false },
482
+ ];
483
+ });
484
+ }, children: "Sort Ascending" }), jsx(MenuItem, { icon: jsx(GrDescend, {}), onClick: () => {
485
+ table.setSorting((state) => {
486
+ return [
487
+ ...state.filter((column) => {
488
+ return column.id !== header.id;
489
+ }),
490
+ { id: header.id, desc: true },
491
+ ];
492
+ });
493
+ }, children: "Sort Descending" }), header.column.getIsSorted() && (jsx(MenuItem, { icon: jsx(MdClear, {}), onClick: () => {
590
494
  header.column.clearSorting();
591
495
  }, 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: {
592
496
  borderRightColor: header.column.getIsResizing()
@@ -596,13 +500,8 @@ const TableHeader = ({ canResize, pinnedBgColor = { light: "gray.50", dark: "gra
596
500
  })] }, crypto.randomUUID()))) }));
597
501
  };
598
502
 
599
- const TablePagination = ({}) => {
600
- const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTable().table;
601
- return (jsxs(ButtonGroup, { isAttached: true, children: [jsx(IconButton, { icon: jsx(MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsx(IconButton, { icon: jsx(MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsx(Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsx(IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsx(MdArrowForward, {}) }), jsx(IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsx(MdLastPage, {}) })] }));
602
- };
603
-
604
- const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, }) => {
605
- return (jsxs(Grid, { templateRows: "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: [jsxs(Flex, { justifyContent: "space-between", gridColumn: "1 / span 2", children: [jsx(Box, { children: jsx(EditViewButton, { text: isMobile ? undefined : "View", icon: jsx(MdOutlineViewColumn, {}) }) }), jsx(Flex, { gap: "1rem", justifySelf: "end", children: showFilter && (jsxs(Fragment, { children: [jsx(GlobalFilter, {}), jsx(EditFilterButton, { text: isMobile ? undefined : "Advanced Filter" })] })) })] }), jsx(Flex, { gridColumn: "1 / span 2", children: jsx(TableFilterTags, {}) }), jsx(Box, { overflow: "auto", gridColumn: "1 / span 2", width: "100%", height: "100%", children: jsxs(Table, { variant: "striped", children: [jsx(TableHeader, { canResize: true }), jsx(TableBody, {}), showFooter && jsx(TableFooter, {})] }) }), jsxs(Flex, { gap: "1rem", alignItems: "center", children: [jsx(PageSizeControl, {}), jsxs(Flex, { children: [jsx(Text, { paddingRight: "0.5rem", children: totalText }), jsx(RowCountText, {})] })] }), jsx(Box, { justifySelf: "end", children: jsx(TablePagination, {}) })] }));
503
+ const DefaultTable = ({ totalText = "Total:", showFilter = false, showFooter = false, fitTableWidth = false, fitTableHeight = false, isMobile = false, filterOptions = [], showFilterTags = false, showFilterName = false, }) => {
504
+ return (jsx(TableControls, { totalText: totalText, showFilter: showFilter, fitTableWidth: fitTableWidth, fitTableHeight: fitTableHeight, isMobile: isMobile, filterOptions: filterOptions, showFilterName: showFilterName, showFilterTags: showFilterTags, children: jsxs(Table, { variant: "striped", children: [jsx(TableHeader, { canResize: true }), jsx(TableBody, {}), showFooter && jsx(TableFooter, {})] }) }));
606
505
  };
607
506
 
608
507
  const DensityToggleButton = ({ text, icon = jsx(AiOutlineColumnWidth, {}), }) => {
@@ -614,57 +513,9 @@ const DensityToggleButton = ({ text, icon = jsx(AiOutlineColumnWidth, {}), }) =>
614
513
  }, children: text }))] }));
615
514
  };
616
515
 
617
- const ColumnOrderChanger = ({ columns }) => {
618
- const [order, setOrder] = useState([]);
619
- const [originalOrder, setOriginalOrder] = useState([]);
620
- const { table } = useDataTable();
621
- const handleChangeOrder = (startIndex, endIndex) => {
622
- const newOrder = Array.from(order);
623
- const [removed] = newOrder.splice(startIndex, 1);
624
- newOrder.splice(endIndex, 0, removed);
625
- setOrder(newOrder);
626
- };
627
- useEffect(() => {
628
- setOrder(columns);
629
- }, [columns]);
630
- useEffect(() => {
631
- if (originalOrder.length > 0) {
632
- return;
633
- }
634
- if (columns.length <= 0) {
635
- return;
636
- }
637
- setOriginalOrder(columns);
638
- }, [columns]);
639
- return (jsxs(Flex, { gap: "0.5rem", flexFlow: "column", children: [jsx(Flex, { gap: "0.5rem", flexFlow: "column", children: order.map((columnId, index) => (jsxs(Flex, { gap: "0.5rem", alignItems: "center", justifyContent: "space-between", children: [jsx(IconButton, { onClick: () => {
640
- const prevIndex = index - 1;
641
- if (prevIndex >= 0) {
642
- handleChangeOrder(index, prevIndex);
643
- }
644
- }, disabled: index === 0, "aria-label": "", children: jsx(MdArrowUpward, {}) }), table
645
- .getAllFlatColumns()
646
- .filter((column) => {
647
- return column.id === columnId;
648
- })
649
- .map((column) => {
650
- const displayName = column.columnDef.meta === undefined
651
- ? column.id
652
- : column.columnDef.meta.displayName;
653
- return jsx("span", { children: displayName }, column.id);
654
- }), jsx(IconButton, { onClick: () => {
655
- const nextIndex = index + 1;
656
- if (nextIndex < order.length) {
657
- handleChangeOrder(index, nextIndex);
658
- }
659
- }, disabled: index === order.length - 1, "aria-label": "", children: jsx(MdArrowDownward, {}) })] }, columnId))) }), jsxs(Flex, { gap: "0.25rem", children: [jsx(Button, { onClick: () => {
660
- table.setColumnOrder(order);
661
- }, children: "Apply" }), jsx(Button, { onClick: () => {
662
- table.setColumnOrder(originalOrder);
663
- }, children: "Reset" })] })] }));
664
- };
665
- const TableOrderer = () => {
666
- const { table } = useDataTable();
667
- return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
516
+ const EditFilterButton = ({ text, title = "Edit Filter", closeText = "Close", resetText = "Reset", icon = jsx(MdFilterAlt, {}), ...props }) => {
517
+ const filterModal = useDisclosure();
518
+ return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: filterModal.onOpen, "aria-label": "filter", ...props })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: filterModal.onOpen, ...props, children: text })), jsxs(Modal, { isOpen: filterModal.isOpen, onClose: filterModal.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsxs(Flex, { flexFlow: "column", gap: "1rem", children: [jsx(TableFilter, {}), jsx(ResetFilteringButton, { text: resetText })] }) }), jsx(ModalFooter, { children: jsx(Button, { onClick: filterModal.onClose, children: closeText }) })] })] })] }));
668
519
  };
669
520
 
670
521
  const EditOrderButton = ({ text, icon = jsx(MdOutlineMoveDown, {}), title = "Change Order", }) => {
@@ -672,13 +523,6 @@ const EditOrderButton = ({ text, icon = jsx(MdOutlineMoveDown, {}), title = "Cha
672
523
  return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: orderModal.onOpen, "aria-label": "change order" })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: orderModal.onOpen, children: text })), jsxs(Modal, { isOpen: orderModal.isOpen, onClose: orderModal.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { padding: "0 0 1rem 0", children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsx(Flex, { flexFlow: "column", gap: "0.25rem", children: jsx(TableOrderer, {}) }) })] })] })] }));
673
524
  };
674
525
 
675
- const ResetSortingButton = ({ text = "Reset Sorting", }) => {
676
- const { table } = useDataTable();
677
- return (jsx(Button, { onClick: () => {
678
- table.resetSorting();
679
- }, children: text }));
680
- };
681
-
682
526
  const TableSorter = () => {
683
527
  const { table } = useDataTable();
684
528
  return (jsx(Fragment, { children: table.getHeaderGroups().map((headerGroup) => (jsx(Fragment, { children: headerGroup.headers.map((header) => {
@@ -704,6 +548,52 @@ const EditSortingButton = ({ text, icon = jsx(MdOutlineSort, {}), title = "Edit
704
548
  return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: sortingModal.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: sortingModal.onOpen, children: text })), jsxs(Modal, { isOpen: sortingModal.isOpen, onClose: sortingModal.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { padding: "0 0 1rem 0", children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(TableSorter, {}), jsx(ResetSortingButton, {})] }) })] })] })] }));
705
549
  };
706
550
 
551
+ const EditViewButton = ({ text, icon = jsx(IoMdEye, {}), title = "Edit View", }) => {
552
+ const viewModel = useDisclosure();
553
+ return (jsxs(Fragment, { children: [!!text === false && (jsx(IconButton, { icon: icon, variant: "ghost", onClick: viewModel.onOpen, "aria-label": "change sorting" })), !!text !== false && (jsx(Button, { leftIcon: icon, variant: "ghost", onClick: viewModel.onOpen, children: text })), jsxs(Modal, { isOpen: viewModel.isOpen, onClose: viewModel.onClose, size: ["full", "full", "md", "md"], children: [jsx(ModalOverlay, {}), jsxs(ModalContent, { padding: "0 0 1rem 0", children: [jsx(ModalHeader, { children: title }), jsx(ModalCloseButton, {}), jsx(ModalBody, { children: jsx(TableViewer, {}) })] })] })] }));
554
+ };
555
+
556
+ const FilterOptions = ({ column }) => {
557
+ const { table } = useDataTable();
558
+ const tableColumn = table.getColumn(column);
559
+ const options = tableColumn?.columnDef.meta?.filterOptions ?? [];
560
+ return (jsx(Fragment, { children: options.map((option) => {
561
+ const selected = table.getColumn(column)?.getFilterValue() === option;
562
+ return (jsxs(Button, { size: "sm", onClick: () => {
563
+ if (selected) {
564
+ table.setColumnFilters((state) => {
565
+ return state.filter((filter) => {
566
+ return filter.id !== column;
567
+ });
568
+ });
569
+ return;
570
+ }
571
+ table.getColumn(column)?.setFilterValue(option);
572
+ }, variant: selected ? "solid" : "outline", display: "flex", gap: "0.25rem", children: [option, selected && jsx(MdClose, {})] }, option));
573
+ }) }));
574
+ };
575
+
576
+ const GlobalFilter = ({ icon = MdSearch }) => {
577
+ const { globalFilter, setGlobalFilter } = useDataTable();
578
+ return (jsx(Fragment, { children: jsx(Box, { children: jsxs(InputGroup, { children: [jsx(InputLeftElement, { pointerEvents: "none", children: jsx(Icon, { as: icon, color: "gray.300" }) }), jsx(Input, { value: globalFilter, onChange: (e) => {
579
+ setGlobalFilter(e.target.value);
580
+ } })] }) }) }));
581
+ };
582
+
583
+ const PageSizeControl = ({ pageSizes = [10, 20, 30, 40, 50], }) => {
584
+ const { table } = useDataTable();
585
+ return (jsx(Fragment, { children: jsxs(Menu, { children: [jsx(MenuButton, { as: Button, variant: "ghost", rightIcon: jsx(ChevronDownIcon, {}), gap: "0.5rem", children: table.getState().pagination.pageSize }), jsx(MenuList, { children: pageSizes.map((pageSize) => (jsx(MenuItem, { onClick: () => {
586
+ table.setPageSize(Number(pageSize));
587
+ }, children: pageSize }, crypto.randomUUID()))) })] }) }));
588
+ };
589
+
590
+ const ResetFilteringButton = ({ text = "Reset Filtering", }) => {
591
+ const { table } = useDataTable();
592
+ return (jsx(Button, { onClick: () => {
593
+ table.resetColumnFilters();
594
+ }, children: text }));
595
+ };
596
+
707
597
  const ResetSelectionButton = ({ text = "Reset Selection", }) => {
708
598
  const { table } = useDataTable();
709
599
  return (jsx(Button, { onClick: () => {
@@ -711,6 +601,26 @@ const ResetSelectionButton = ({ text = "Reset Selection", }) => {
711
601
  }, children: text }));
712
602
  };
713
603
 
604
+ const ResetSortingButton = ({ text = "Reset Sorting", }) => {
605
+ const { table } = useDataTable();
606
+ return (jsx(Button, { onClick: () => {
607
+ table.resetSorting();
608
+ }, children: text }));
609
+ };
610
+
611
+ const RowCountText = () => {
612
+ const { table } = useDataTable();
613
+ return jsx(Text, { children: table.getRowCount() });
614
+ };
615
+
616
+ const Table = ({ children, showLoading = false, loadingComponent = jsx(Fragment, { children: "Loading..." }), ...props }) => {
617
+ const { table, loading } = useDataTable();
618
+ if (showLoading) {
619
+ return (jsxs(Fragment, { children: [loading && loadingComponent, !loading && (jsx(Table$1, { width: table.getCenterTotalSize(), overflow: "auto", ...props, children: children }))] }));
620
+ }
621
+ return (jsx(Fragment, { children: jsx(Table$1, { width: table.getCenterTotalSize(), overflowX: "auto", ...props, children: children }) }));
622
+ };
623
+
714
624
  const TableCardContainer = ({ children, ...props }) => {
715
625
  return (jsx(Grid, { gridTemplateColumns: ["1fr", "1fr 1fr", "1fr 1fr 1fr"], gap: "0.5rem", ...props, children: children }));
716
626
  };
@@ -734,8 +644,195 @@ const TableComponent = ({ render = () => {
734
644
  return render(table);
735
645
  };
736
646
 
647
+ const DateRangeFilter = ({ startDate, endDate, setStartDate, setEndDate, }) => {
648
+ console.log(startDate, endDate, "dflp");
649
+ return (jsx(Box, { p: '1rem', children: jsxs(VStack, { spacing: 4, children: [jsxs(FormControl, { children: [jsx(FormLabel, { htmlFor: "start-date", children: "Start Date" }), jsx(Input, { id: "start-date", type: "date", value: startDate, onChange: (e) => setStartDate(e.target.value) })] }), jsxs(FormControl, { children: [jsx(FormLabel, { htmlFor: "end-date", children: "End Date" }), jsx(Input, { id: "end-date", type: "date", value: endDate, onChange: (e) => setEndDate(e.target.value) })] })] }) }));
650
+ };
651
+
652
+ const RangeFilter = ({ range, setRange, defaultValue, min, max, step, }) => {
653
+ return (jsx(Box, { p: 8, children: jsxs(VStack, { spacing: 4, children: [jsxs(Text, { children: ["Selected Range: ", range[0], " - ", range[1]] }), jsxs(RangeSlider, { "aria-label": ["min", "max"], defaultValue: defaultValue, min: min, max: max, step: step, onChangeEnd: (val) => setRange(val), children: [jsx(RangeSliderTrack, { children: jsx(RangeSliderFilledTrack, {}) }), jsx(RangeSliderThumb, { index: 0 }), jsx(RangeSliderThumb, { index: 1 })] })] }) }));
654
+ };
655
+
656
+ const TagFilter = ({ availableTags, selectedTags, onTagChange, }) => {
657
+ const toggleTag = (tag) => {
658
+ if (selectedTags.includes(tag)) {
659
+ onTagChange(selectedTags.filter((t) => t !== tag));
660
+ }
661
+ else {
662
+ onTagChange([...selectedTags, tag]);
663
+ }
664
+ };
665
+ return (jsx(Flex, { flexFlow: "wrap", p: "0.5rem", gap: "0.5rem", children: availableTags.map((tag) => (jsx(WrapItem, { children: jsxs(Tag, { size: "lg", variant: selectedTags.includes(tag) ? "solid" : "outline", cursor: "pointer", onClick: () => toggleTag(tag), children: [jsx(TagLabel, { children: tag }), selectedTags.includes(tag) && jsx(TagCloseButton, {})] }) }, tag))) }));
666
+ };
667
+
668
+ function Filter({ column }) {
669
+ const { filterVariant } = column.columnDef.meta ?? {};
670
+ const displayName = column.columnDef.meta?.displayName ?? column.id;
671
+ const filterOptions = column.columnDef.meta?.filterOptions ?? [];
672
+ if (column.columns.length > 0) {
673
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), column.columns.map((column) => {
674
+ return jsx(Filter, { column: column }, column.id);
675
+ })] }, column.id));
676
+ }
677
+ if (!column.getCanFilter()) {
678
+ return jsx(Fragment, {});
679
+ }
680
+ if (filterVariant === "select") {
681
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(Select, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", placeholder: "Select option", onChange: (e) => {
682
+ column.setFilterValue(e.target.value);
683
+ }, children: filterOptions.map((option) => {
684
+ return (jsx("option", { value: option, children: option }, `${option}`));
685
+ }) })] }, column.id));
686
+ }
687
+ if (filterVariant === "tag") {
688
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(TagFilter, { availableTags: filterOptions, selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
689
+ if (tags.length === 0) {
690
+ return column.setFilterValue(undefined);
691
+ }
692
+ column.setFilterValue(tags);
693
+ } })] }, column.id));
694
+ }
695
+ if (filterVariant === "boolean") {
696
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(TagFilter, { availableTags: ["true", "false"], selectedTags: (column.getFilterValue() ?? []), onTagChange: (tags) => {
697
+ if (tags.length === 0) {
698
+ return column.setFilterValue(undefined);
699
+ }
700
+ column.setFilterValue(tags);
701
+ } })] }, column.id));
702
+ }
703
+ if (filterVariant === "range") {
704
+ const filterValue = column.getFilterValue() ?? [
705
+ undefined,
706
+ undefined,
707
+ ];
708
+ const { min, max, step, defaultValue } = column.columnDef.meta
709
+ ?.filterRangeConfig ?? {
710
+ min: 0,
711
+ max: 100,
712
+ step: 1,
713
+ defaultValue: [4, 50],
714
+ };
715
+ return (jsx(RangeFilter, { range: filterValue, setRange: function (value) {
716
+ // throw new Error("Function not implemented.");
717
+ column.setFilterValue(value);
718
+ }, defaultValue: defaultValue, min: min, max: max, step: step }));
719
+ }
720
+ if (filterVariant === "dateRange") {
721
+ const [start, end] = column.getFilterValue() ?? [
722
+ "",
723
+ "",
724
+ ];
725
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(DateRangeFilter, { startDate: start, endDate: end, setStartDate: function (value) {
726
+ column.setFilterValue((state) => {
727
+ return [value, (state ?? ["", ""])[1]];
728
+ });
729
+ }, setEndDate: function (value) {
730
+ column.setFilterValue((state) => {
731
+ return [(state ?? ["", ""])[0], value];
732
+ });
733
+ } })] }, column.id));
734
+ }
735
+ if (filterVariant === "custom") {
736
+ const renderFilter = column.columnDef.meta?.renderFilter;
737
+ if (renderFilter === undefined) {
738
+ throw new Error("renderFilter is undefined");
739
+ }
740
+ return jsx(Fragment, { children: renderFilter(column) });
741
+ }
742
+ return (jsxs(Flex, { flexFlow: "column", gap: "0.25rem", children: [jsx(Text, { children: displayName }), jsx(Input, { value: column.getFilterValue() ? String(column.getFilterValue()) : "", onChange: (e) => {
743
+ column.setFilterValue(e.target.value);
744
+ } })] }, column.id));
745
+ }
746
+ const TableFilter = () => {
747
+ const { table } = useDataTable();
748
+ return (jsx(Fragment, { children: table.getAllColumns().map((column) => {
749
+ return jsx(Filter, { column: column }, column.id);
750
+ }) }));
751
+ };
752
+
753
+ const TableFilterTags = () => {
754
+ const { table } = useDataTable();
755
+ return (jsx(Flex, { gap: "0.5rem", flexFlow: "wrap", children: table.getState().columnFilters.map(({ id, value }, index) => {
756
+ return (jsxs(Tag, { display: "flex", gap: "0.5rem", alignItems: "center", children: [jsx(Text, { children: `${id}: ${value}` }), jsx(IconButton, { size: "xs", variant: "ghost", icon: jsx(CloseIcon, {}), onClick: () => {
757
+ table.setColumnFilters(table.getState().columnFilters.filter((value, curIndex) => {
758
+ return curIndex != index;
759
+ }));
760
+ }, "aria-label": "remove filter" })] }, `${id}-${value}`));
761
+ }) }));
762
+ };
763
+
764
+ const TableLoadingComponent = ({ render, }) => {
765
+ const { loading } = useDataTable();
766
+ return jsx(Fragment, { children: render(loading) });
767
+ };
768
+
769
+ const ColumnOrderChanger = ({ columns }) => {
770
+ const [order, setOrder] = useState([]);
771
+ const [originalOrder, setOriginalOrder] = useState([]);
772
+ const { table } = useDataTable();
773
+ const handleChangeOrder = (startIndex, endIndex) => {
774
+ const newOrder = Array.from(order);
775
+ const [removed] = newOrder.splice(startIndex, 1);
776
+ newOrder.splice(endIndex, 0, removed);
777
+ setOrder(newOrder);
778
+ };
779
+ useEffect(() => {
780
+ setOrder(columns);
781
+ }, [columns]);
782
+ useEffect(() => {
783
+ if (originalOrder.length > 0) {
784
+ return;
785
+ }
786
+ if (columns.length <= 0) {
787
+ return;
788
+ }
789
+ setOriginalOrder(columns);
790
+ }, [columns]);
791
+ return (jsxs(Flex, { gap: "0.5rem", flexFlow: "column", children: [jsx(Flex, { gap: "0.5rem", flexFlow: "column", children: order.map((columnId, index) => (jsxs(Flex, { gap: "0.5rem", alignItems: "center", justifyContent: "space-between", children: [jsx(IconButton, { onClick: () => {
792
+ const prevIndex = index - 1;
793
+ if (prevIndex >= 0) {
794
+ handleChangeOrder(index, prevIndex);
795
+ }
796
+ }, disabled: index === 0, "aria-label": "", children: jsx(MdArrowUpward, {}) }), table
797
+ .getAllFlatColumns()
798
+ .filter((column) => {
799
+ return column.id === columnId;
800
+ })
801
+ .map((column) => {
802
+ const displayName = column.columnDef.meta === undefined
803
+ ? column.id
804
+ : column.columnDef.meta.displayName;
805
+ return jsx("span", { children: displayName }, column.id);
806
+ }), jsx(IconButton, { onClick: () => {
807
+ const nextIndex = index + 1;
808
+ if (nextIndex < order.length) {
809
+ handleChangeOrder(index, nextIndex);
810
+ }
811
+ }, disabled: index === order.length - 1, "aria-label": "", children: jsx(MdArrowDownward, {}) })] }, columnId))) }), jsxs(Flex, { gap: "0.25rem", children: [jsx(Button, { onClick: () => {
812
+ table.setColumnOrder(order);
813
+ }, children: "Apply" }), jsx(Button, { onClick: () => {
814
+ table.setColumnOrder(originalOrder);
815
+ }, children: "Reset" })] })] }));
816
+ };
817
+ const TableOrderer = () => {
818
+ const { table } = useDataTable();
819
+ return (jsx(Fragment, { children: jsx(ColumnOrderChanger, { columns: table.getState().columnOrder }) }));
820
+ };
821
+
822
+ const TablePagination = ({}) => {
823
+ const { firstPage, getCanPreviousPage, previousPage, getState, nextPage, getCanNextPage, lastPage, } = useDataTable().table;
824
+ return (jsxs(ButtonGroup, { isAttached: true, children: [jsx(IconButton, { icon: jsx(MdFirstPage, {}), onClick: () => firstPage(), isDisabled: !getCanPreviousPage(), "aria-label": "first-page", variant: "ghost" }), jsx(IconButton, { icon: jsx(MdArrowBack, {}), onClick: () => previousPage(), isDisabled: !getCanPreviousPage(), "aria-label": "previous-page", variant: "ghost" }), jsx(Button, { variant: "ghost", onClick: () => { }, disabled: !getCanPreviousPage(), children: getState().pagination.pageIndex + 1 }), jsx(IconButton, { onClick: () => nextPage(), isDisabled: !getCanNextPage(), "aria-label": "next-page", variant: "ghost", children: jsx(MdArrowForward, {}) }), jsx(IconButton, { onClick: () => lastPage(), isDisabled: !getCanNextPage(), "aria-label": "last-page", variant: "ghost", children: jsx(MdLastPage, {}) })] }));
825
+ };
826
+
827
+ const ReloadButton = ({ text = "Reload" }) => {
828
+ const { refreshData } = useDataTable();
829
+ return (jsx(Button, { leftIcon: jsx(IoReload, {}), onClick: () => {
830
+ refreshData();
831
+ }, children: text }));
832
+ };
833
+
737
834
  const SelectAllRowsToggle = ({ selectAllIcon = jsx(MdOutlineChecklist, {}), clearAllIcon = jsx(MdClear, {}), selectAllText, clearAllText, }) => {
738
- const { table } = useContext(TableContext);
835
+ const { table } = useDataTable();
739
836
  return (jsxs(Fragment, { children: [!!selectAllText === false && (jsx(IconButton, { icon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", "aria-label": table.getIsAllRowsSelected() ? clearAllText : selectAllText, onClick: (event) => {
740
837
  table.getToggleAllRowsSelectedHandler()(event);
741
838
  } })), !!selectAllText !== false && (jsx(Button, { leftIcon: table.getIsAllRowsSelected() ? clearAllIcon : selectAllIcon, variant: "ghost", onClick: (event) => {
@@ -750,6 +847,29 @@ const TableSelector = () => {
750
847
  }, "aria-label": "reset selection" }))] }));
751
848
  };
752
849
 
850
+ const TableViewer = () => {
851
+ const { table } = useDataTable();
852
+ const columns = table.getAllLeafColumns();
853
+ const [columnOrder, setColumnOrder] = useState(columns.map((column, index) => {
854
+ return column.id;
855
+ }));
856
+ const handleDragEnd = (result) => {
857
+ if (!result.destination)
858
+ return;
859
+ const newColumnOrder = Array.from(columnOrder);
860
+ const [removed] = newColumnOrder.splice(result.source.index, 1);
861
+ newColumnOrder.splice(result.destination.index, 0, removed);
862
+ setColumnOrder(newColumnOrder);
863
+ table.setColumnOrder(newColumnOrder);
864
+ };
865
+ return (jsx(Fragment, { children: jsx(DragDropContext, { onDragEnd: handleDragEnd, children: jsx(Droppable, { droppableId: "columns", children: (provided) => (jsxs(Flex, { flexFlow: "column", gap: "0.5rem", ref: provided.innerRef, ...provided.droppableProps, children: [columns.map((column, i) => {
866
+ const displayName = column.columnDef.meta === undefined
867
+ ? column.id
868
+ : column.columnDef.meta.displayName;
869
+ return (jsx(Draggable, { draggableId: column.id, index: i, children: (provided) => (jsxs(Grid, { ref: provided.innerRef, ...provided.draggableProps, templateColumns: "auto 1fr", gap: "0.5rem", alignItems: "center", children: [jsx(Flex, { ...provided.dragHandleProps, alignItems: "center", padding: "auto 0 auto 0", children: jsx(Icon, { as: FaGripLinesVertical, color: "gray.400" }) }), jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [jsxs(Box, { children: [" ", displayName] }), jsx(Switch, { isChecked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() })] })] }, column.id)) }, column.id));
870
+ }), provided.placeholder] })) }) }) }));
871
+ };
872
+
753
873
  const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipProps, ...props }) => {
754
874
  if (label) {
755
875
  return (jsx(Flex, { alignItems: "center", height: "100%", padding: padding, children: jsx(Tooltip, { label: jsx(Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", noOfLines: [5], children: label }), placement: "auto", ...tooltipProps, children: jsx(Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }) }));
@@ -757,4 +877,4 @@ const TextCell = ({ label, noOfLines = [1], padding = "0rem", children, tooltipP
757
877
  return (jsx(Flex, { alignItems: "center", height: "100%", padding: padding, children: jsx(Text, { as: "span", overflow: "hidden", textOverflow: "ellipsis", wordBreak: "break-all", noOfLines: noOfLines, ...props, children: children }) }));
758
878
  };
759
879
 
760
- export { DataTable, DataTableServer, DefaultTable, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, GlobalFilter, PageSizeControl, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableFilter, TableFilterTags, TableFooter, TableHeader, TableOrderer, TablePagination, TableSelector, TableSorter, TableViewer, TextCell, useDataFromUrl, useDataTable };
880
+ export { DataTable, DataTableServer, DefaultTable, DensityToggleButton, EditFilterButton, EditOrderButton, EditSortingButton, EditViewButton, FilterOptions, GlobalFilter, PageSizeControl, ReloadButton, ResetFilteringButton, ResetSelectionButton, ResetSortingButton, RowCountText, Table, TableBody, TableCardContainer, TableCards, TableComponent, TableControls, TableFilter, TableFilterTags, TableFooter, TableHeader, TableLoadingComponent, TableOrderer, TablePagination, TableSelector, TableSorter, TableViewer, TextCell, useDataFromUrl, useDataTable };