@ballistix.digital/react-components 1.0.2 → 1.1.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/dist/index.d.ts CHANGED
@@ -843,10 +843,33 @@ type TProps$2 = {
843
843
  };
844
844
  declare const SlideOverOverlay: FC<TProps$2>;
845
845
 
846
+ declare const styles: {
847
+ controls: {
848
+ container: string;
849
+ content: string;
850
+ head: string;
851
+ body: string;
852
+ dropdown: {
853
+ reset: string;
854
+ container: string;
855
+ input: string;
856
+ label: string;
857
+ actions: string;
858
+ upIcon: string;
859
+ downIcon: string;
860
+ };
861
+ };
862
+ label: string;
863
+ icon: string;
864
+ };
865
+
866
+ type TTableColumnOptionsStyles = DeepPartialType$1<typeof styles>;
867
+
846
868
  type TProps$1 = {
847
869
  table: Table<any>;
848
870
  setColumnOrder: Dispatch<SetStateAction<ColumnOrderState>>;
849
871
  trigger: ReactNode;
872
+ styles?: TTableColumnOptionsStyles;
850
873
  resetConfig?: {
851
874
  tableId: string;
852
875
  label?: string;
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
2
  import { ArrowPathIcon, ChevronDownIcon, EllipsisVerticalIcon, ExclamationCircleIcon, ChevronDoubleLeftIcon, ChevronLeftIcon, ChevronRightIcon, ChevronDoubleRightIcon, ChevronUpIcon, ChevronUpDownIcon, HomeIcon, ArrowLongLeftIcon, ArrowLongRightIcon } from '@heroicons/react/20/solid';
3
- import { isArray, map, set, get, noop as noop$1, indexOf, toSafeInteger, pick, isEmpty, some, forEach, assign, intersection, trim, lastIndexOf } from 'lodash';
3
+ import { isArray, map, set, get, noop as noop$1, indexOf, toSafeInteger, pick, isEmpty, some, compact as compact$1, forEach, assign, includes, intersection, trim, lastIndexOf } from 'lodash';
4
4
  import get$1 from 'lodash/get';
5
5
  import React, { useState, useMemo, Children, Fragment, useEffect, useCallback, useRef, forwardRef, useImperativeHandle, useReducer, createElement, PureComponent, Component } from 'react';
6
6
  import { library } from '@fortawesome/fontawesome-svg-core';
@@ -1754,11 +1754,11 @@ var isValidState = function (state) {
1754
1754
  };
1755
1755
 
1756
1756
  var TableList2 = function (props) {
1757
- var _a, _b, _c, _d, _e, _f;
1757
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1758
1758
  var id = props.id, config = props.table, head = props.head, foot = props.foot, isLoading = props.isLoading, onRowClick = props.onRowClick, onChange = props.onChange, stylesOverrides = props.styles;
1759
- var _g = useState((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultSorting) !== null && _b !== void 0 ? _b : []), sorting = _g[0], setSorting = _g[1];
1760
- var _h = useState({}), columnVisibility = _h[0], setColumnVisibility = _h[1];
1761
- var _j = useState([]), columnOrder = _j[0], setColumnOrder = _j[1];
1759
+ var _j = useState((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultSorting) !== null && _b !== void 0 ? _b : []), sorting = _j[0], setSorting = _j[1];
1760
+ var _k = useState({}), columnVisibility = _k[0], setColumnVisibility = _k[1];
1761
+ var _l = useState([]), columnOrder = _l[0], setColumnOrder = _l[1];
1762
1762
  var handleGenerateStyle = function () {
1763
1763
  var result = deepCopyObject(styles$f.base);
1764
1764
  var keys = calculateNestedKeys(styles$f.base);
@@ -1773,6 +1773,32 @@ var TableList2 = function (props) {
1773
1773
  return result;
1774
1774
  };
1775
1775
  var styles = handleGenerateStyle();
1776
+ var initialVisibilityState = useMemo(function () {
1777
+ var _a;
1778
+ var columnAccessorKeys = compact$1(map(config.columns, 'accessorKey'));
1779
+ var columnIds = compact$1(map(config.columns, 'id'));
1780
+ var visibilityState = {};
1781
+ if ((_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultVisibility) {
1782
+ forEach(columnAccessorKeys, function (key) {
1783
+ var _a;
1784
+ var _b;
1785
+ visibilityState = assign(visibilityState, (_a = {},
1786
+ _a[key] = includes((_b = config.options) === null || _b === void 0 ? void 0 : _b.defaultVisibility, key),
1787
+ _a));
1788
+ });
1789
+ }
1790
+ else {
1791
+ forEach(columnAccessorKeys, function (key) {
1792
+ var _a;
1793
+ visibilityState = assign(visibilityState, (_a = {}, _a[key] = true, _a));
1794
+ });
1795
+ }
1796
+ forEach(columnIds, function (key) {
1797
+ var _a;
1798
+ visibilityState = assign(visibilityState, (_a = {}, _a[key] = true, _a));
1799
+ });
1800
+ return visibilityState;
1801
+ }, [config.columns, (_c = config.options) === null || _c === void 0 ? void 0 : _c.defaultVisibility]);
1776
1802
  var table = useReactTable({
1777
1803
  getCoreRowModel: getCoreRowModel(),
1778
1804
  columns: config.columns,
@@ -1782,6 +1808,10 @@ var TableList2 = function (props) {
1782
1808
  columnVisibility: columnVisibility,
1783
1809
  columnOrder: columnOrder,
1784
1810
  },
1811
+ initialState: {
1812
+ columnVisibility: initialVisibilityState,
1813
+ columnOrder: (_d = config.options) === null || _d === void 0 ? void 0 : _d.defaultOrder,
1814
+ },
1785
1815
  manualPagination: true,
1786
1816
  manualSorting: true,
1787
1817
  onSortingChange: setSorting,
@@ -1830,7 +1860,7 @@ var TableList2 = function (props) {
1830
1860
  }
1831
1861
  setColumnVisibility(visibility_1);
1832
1862
  }
1833
- }, [(_c = config === null || config === void 0 ? void 0 : config.options) === null || _c === void 0 ? void 0 : _c.defaultVisibility, id, table]);
1863
+ }, [(_e = config === null || config === void 0 ? void 0 : config.options) === null || _e === void 0 ? void 0 : _e.defaultVisibility, id, table]);
1834
1864
  useEffect(function () {
1835
1865
  var _a, _b, _c;
1836
1866
  var savedOrder = (_a = getTableState(id)) === null || _a === void 0 ? void 0 : _a.columnOrder;
@@ -1843,7 +1873,7 @@ var TableList2 = function (props) {
1843
1873
  else if (some(config.columns, function (column) { return (column === null || column === void 0 ? void 0 : column.id) || get(column, 'accessorKey'); })) {
1844
1874
  setColumnOrder(map(config.columns, function (column) { var _a; return ((_a = column === null || column === void 0 ? void 0 : column.id) !== null && _a !== void 0 ? _a : get(column, 'accessorKey')); }));
1845
1875
  }
1846
- }, [config.columns, (_d = config === null || config === void 0 ? void 0 : config.options) === null || _d === void 0 ? void 0 : _d.defaultOrder, id]);
1876
+ }, [config.columns, (_f = config === null || config === void 0 ? void 0 : config.options) === null || _f === void 0 ? void 0 : _f.defaultOrder, id]);
1847
1877
  // Write state to local storage when it changes
1848
1878
  useEffect(function () {
1849
1879
  if (state) {
@@ -1884,7 +1914,7 @@ var TableList2 = function (props) {
1884
1914
  ((_c = (_b = table === null || table === void 0 ? void 0 : table.getState()) === null || _b === void 0 ? void 0 : _b.pagination) === null || _c === void 0 ? void 0 : _c.pageSize) - 1 &&
1885
1915
  'border-b border-gray-200'), children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
1886
1916
  }) }, row.id));
1887
- }) }))] }), isEmpty(table === null || table === void 0 ? void 0 : table.getRowModel().rows) && !isLoading && (jsx(Fragment$1, { children: ((_e = config === null || config === void 0 ? void 0 : config.options) === null || _e === void 0 ? void 0 : _e.emptyComponent) ? ((_f = config === null || config === void 0 ? void 0 : config.options) === null || _f === void 0 ? void 0 : _f.emptyComponent) : (jsx("div", { className: "w-full flex justify-center my-2", children: "There is no data to show..." })) })), isLoading && (jsx("div", { className: "flex flex-col gap-y-2 w-full pt-5", children: new Array(8).fill(undefined).map(function (index) { return (jsxs("div", { className: "flex gap-2", children: [jsx("div", { className: "w-20 h-12 rounded-md bg-gray-100 animate-pulse" }), jsx("div", { className: "w-full h-12 rounded-md bg-gray-100 animate-pulse" })] }, index)); }) }))] }) }) }) }), jsx("div", { className: styles.foot, children: foot && foot(state) })] }));
1917
+ }) }))] }), isEmpty(table === null || table === void 0 ? void 0 : table.getRowModel().rows) && !isLoading && (jsx(Fragment$1, { children: ((_g = config === null || config === void 0 ? void 0 : config.options) === null || _g === void 0 ? void 0 : _g.emptyComponent) ? ((_h = config === null || config === void 0 ? void 0 : config.options) === null || _h === void 0 ? void 0 : _h.emptyComponent) : (jsx("div", { className: "w-full flex justify-center my-2", children: "There is no data to show..." })) })), isLoading && (jsx("div", { className: "flex flex-col gap-y-2 w-full pt-5", children: new Array(8).fill(undefined).map(function (index) { return (jsxs("div", { className: "flex gap-2", children: [jsx("div", { className: "w-20 h-12 rounded-md bg-gray-100 animate-pulse" }), jsx("div", { className: "w-full h-12 rounded-md bg-gray-100 animate-pulse" })] }, index)); }) }))] }) }) }) }), jsx("div", { className: styles.foot, children: foot && foot(state) })] }));
1888
1918
  };
1889
1919
 
1890
1920
  var base$c = {
@@ -2607,7 +2637,7 @@ var styles$8 = {
2607
2637
 
2608
2638
  var TableColumnOptionsCustom = function (props) {
2609
2639
  var _a;
2610
- var table = props.table, trigger = props.trigger, setColumnOrder = props.setColumnOrder, resetConfig = props.resetConfig;
2640
+ var table = props.table, trigger = props.trigger, setColumnOrder = props.setColumnOrder, stylesOverrides = props.styles, resetConfig = props.resetConfig;
2611
2641
  var handleUpdateColumnOrder = useCallback(function (table, column, location, setColumnOrder) {
2612
2642
  var _a;
2613
2643
  var ids = (_a = table
@@ -2619,18 +2649,27 @@ var TableColumnOptionsCustom = function (props) {
2619
2649
  ids.splice(location, 0, column.id);
2620
2650
  setColumnOrder(ids);
2621
2651
  }, []);
2622
- return (jsxs(Popover, { children: [jsx(Popover.Button, { children: trigger }), jsxs(Popover.Panel, { className: styles$7.controls.content, children: [resetConfig && (jsxs("div", { className: styles$7.controls.dropdown.reset, onClick: function () {
2652
+ var handleGenerateStyle = function () {
2653
+ var result = deepCopyObject(styles$7);
2654
+ var keys = calculateNestedKeys(styles$7);
2655
+ keys.forEach(function (key) {
2656
+ set(result, key, toClassName(get(styles$7, key), get(stylesOverrides, key)));
2657
+ });
2658
+ return result;
2659
+ };
2660
+ var styles = handleGenerateStyle();
2661
+ return (jsxs(Popover, { children: [jsx(Popover.Button, { children: trigger }), jsxs(Popover.Panel, { className: styles.controls.content, children: [resetConfig && (jsxs("div", { className: styles.controls.dropdown.reset, onClick: function () {
2623
2662
  removeTableState(resetConfig.tableId);
2624
- table.resetColumnVisibility(true);
2663
+ table.resetColumnVisibility();
2625
2664
  table.resetColumnOrder();
2626
2665
  resetConfig.onReset && resetConfig.onReset();
2627
2666
  }, children: [jsx(IconElement, { accessor: "rotate-left" }), jsx("p", { children: (_a = resetConfig.label) !== null && _a !== void 0 ? _a : 'Reset' })] })), table
2628
2667
  .getAllLeafColumns()
2629
2668
  .map(function (column, index) {
2630
2669
  var isAccessorColumn = !!(column === null || column === void 0 ? void 0 : column.accessorFn);
2631
- return (jsxs("div", { className: toClassName(styles$7.controls.dropdown.container, !isAccessorColumn && 'hidden'), children: [jsx("input", { className: styles$7.controls.dropdown.input, type: "checkbox", checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }), jsx("label", { className: styles$7.controls.dropdown.label, children: column.columnDef.header }), jsxs("div", { className: styles$7.controls.dropdown.actions, children: [jsx(ChevronDownIcon$1, { className: styles$7.controls.dropdown.upIcon, onClick: function () {
2670
+ return (jsxs("div", { className: toClassName(styles.controls.dropdown.container, !isAccessorColumn && 'hidden'), children: [jsx("input", { className: styles.controls.dropdown.input, type: "checkbox", checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }), jsx("label", { className: styles.controls.dropdown.label, children: column.columnDef.header }), jsxs("div", { className: styles.controls.dropdown.actions, children: [jsx(ChevronDownIcon$1, { className: styles.controls.dropdown.upIcon, onClick: function () {
2632
2671
  return handleUpdateColumnOrder(table, column, index - 1, setColumnOrder);
2633
- } }), jsx(ChevronDownIcon$1, { className: styles$7.controls.dropdown.downIcon, onClick: function () {
2672
+ } }), jsx(ChevronDownIcon$1, { className: styles.controls.dropdown.downIcon, onClick: function () {
2634
2673
  return handleUpdateColumnOrder(table, column, index + 1, setColumnOrder);
2635
2674
  } })] })] }, column.id));
2636
2675
  })] })] }));