@ballistix.digital/react-components 1.0.3 → 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.js CHANGED
@@ -1756,11 +1756,11 @@ var isValidState = function (state) {
1756
1756
  };
1757
1757
 
1758
1758
  var TableList2 = function (props) {
1759
- var _a, _b, _c, _d, _e, _f;
1759
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1760
1760
  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;
1761
- var _g = React.useState((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultSorting) !== null && _b !== void 0 ? _b : []), sorting = _g[0], setSorting = _g[1];
1762
- var _h = React.useState({}), columnVisibility = _h[0], setColumnVisibility = _h[1];
1763
- var _j = React.useState([]), columnOrder = _j[0], setColumnOrder = _j[1];
1761
+ var _j = React.useState((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultSorting) !== null && _b !== void 0 ? _b : []), sorting = _j[0], setSorting = _j[1];
1762
+ var _k = React.useState({}), columnVisibility = _k[0], setColumnVisibility = _k[1];
1763
+ var _l = React.useState([]), columnOrder = _l[0], setColumnOrder = _l[1];
1764
1764
  var handleGenerateStyle = function () {
1765
1765
  var result = deepCopyObject(styles$f.base);
1766
1766
  var keys = calculateNestedKeys(styles$f.base);
@@ -1775,6 +1775,32 @@ var TableList2 = function (props) {
1775
1775
  return result;
1776
1776
  };
1777
1777
  var styles = handleGenerateStyle();
1778
+ var initialVisibilityState = React.useMemo(function () {
1779
+ var _a;
1780
+ var columnAccessorKeys = lodash.compact(lodash.map(config.columns, 'accessorKey'));
1781
+ var columnIds = lodash.compact(lodash.map(config.columns, 'id'));
1782
+ var visibilityState = {};
1783
+ if ((_a = config.options) === null || _a === void 0 ? void 0 : _a.defaultVisibility) {
1784
+ lodash.forEach(columnAccessorKeys, function (key) {
1785
+ var _a;
1786
+ var _b;
1787
+ visibilityState = lodash.assign(visibilityState, (_a = {},
1788
+ _a[key] = lodash.includes((_b = config.options) === null || _b === void 0 ? void 0 : _b.defaultVisibility, key),
1789
+ _a));
1790
+ });
1791
+ }
1792
+ else {
1793
+ lodash.forEach(columnAccessorKeys, function (key) {
1794
+ var _a;
1795
+ visibilityState = lodash.assign(visibilityState, (_a = {}, _a[key] = true, _a));
1796
+ });
1797
+ }
1798
+ lodash.forEach(columnIds, function (key) {
1799
+ var _a;
1800
+ visibilityState = lodash.assign(visibilityState, (_a = {}, _a[key] = true, _a));
1801
+ });
1802
+ return visibilityState;
1803
+ }, [config.columns, (_c = config.options) === null || _c === void 0 ? void 0 : _c.defaultVisibility]);
1778
1804
  var table = reactTable.useReactTable({
1779
1805
  getCoreRowModel: reactTable.getCoreRowModel(),
1780
1806
  columns: config.columns,
@@ -1784,6 +1810,10 @@ var TableList2 = function (props) {
1784
1810
  columnVisibility: columnVisibility,
1785
1811
  columnOrder: columnOrder,
1786
1812
  },
1813
+ initialState: {
1814
+ columnVisibility: initialVisibilityState,
1815
+ columnOrder: (_d = config.options) === null || _d === void 0 ? void 0 : _d.defaultOrder,
1816
+ },
1787
1817
  manualPagination: true,
1788
1818
  manualSorting: true,
1789
1819
  onSortingChange: setSorting,
@@ -1832,7 +1862,7 @@ var TableList2 = function (props) {
1832
1862
  }
1833
1863
  setColumnVisibility(visibility_1);
1834
1864
  }
1835
- }, [(_c = config === null || config === void 0 ? void 0 : config.options) === null || _c === void 0 ? void 0 : _c.defaultVisibility, id, table]);
1865
+ }, [(_e = config === null || config === void 0 ? void 0 : config.options) === null || _e === void 0 ? void 0 : _e.defaultVisibility, id, table]);
1836
1866
  React.useEffect(function () {
1837
1867
  var _a, _b, _c;
1838
1868
  var savedOrder = (_a = getTableState(id)) === null || _a === void 0 ? void 0 : _a.columnOrder;
@@ -1845,7 +1875,7 @@ var TableList2 = function (props) {
1845
1875
  else if (lodash.some(config.columns, function (column) { return (column === null || column === void 0 ? void 0 : column.id) || lodash.get(column, 'accessorKey'); })) {
1846
1876
  setColumnOrder(lodash.map(config.columns, function (column) { var _a; return ((_a = column === null || column === void 0 ? void 0 : column.id) !== null && _a !== void 0 ? _a : lodash.get(column, 'accessorKey')); }));
1847
1877
  }
1848
- }, [config.columns, (_d = config === null || config === void 0 ? void 0 : config.options) === null || _d === void 0 ? void 0 : _d.defaultOrder, id]);
1878
+ }, [config.columns, (_f = config === null || config === void 0 ? void 0 : config.options) === null || _f === void 0 ? void 0 : _f.defaultOrder, id]);
1849
1879
  // Write state to local storage when it changes
1850
1880
  React.useEffect(function () {
1851
1881
  if (state) {
@@ -1886,7 +1916,7 @@ var TableList2 = function (props) {
1886
1916
  ((_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 &&
1887
1917
  'border-b border-gray-200'), children: reactTable.flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id));
1888
1918
  }) }, row.id));
1889
- }) }))] }), lodash.isEmpty(table === null || table === void 0 ? void 0 : table.getRowModel().rows) && !isLoading && (jsxRuntime.jsx(jsxRuntime.Fragment, { 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) : (jsxRuntime.jsx("div", { className: "w-full flex justify-center my-2", children: "There is no data to show..." })) })), isLoading && (jsxRuntime.jsx("div", { className: "flex flex-col gap-y-2 w-full pt-5", children: new Array(8).fill(undefined).map(function (index) { return (jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx("div", { className: "w-20 h-12 rounded-md bg-gray-100 animate-pulse" }), jsxRuntime.jsx("div", { className: "w-full h-12 rounded-md bg-gray-100 animate-pulse" })] }, index)); }) }))] }) }) }) }), jsxRuntime.jsx("div", { className: styles.foot, children: foot && foot(state) })] }));
1919
+ }) }))] }), lodash.isEmpty(table === null || table === void 0 ? void 0 : table.getRowModel().rows) && !isLoading && (jsxRuntime.jsx(jsxRuntime.Fragment, { 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) : (jsxRuntime.jsx("div", { className: "w-full flex justify-center my-2", children: "There is no data to show..." })) })), isLoading && (jsxRuntime.jsx("div", { className: "flex flex-col gap-y-2 w-full pt-5", children: new Array(8).fill(undefined).map(function (index) { return (jsxRuntime.jsxs("div", { className: "flex gap-2", children: [jsxRuntime.jsx("div", { className: "w-20 h-12 rounded-md bg-gray-100 animate-pulse" }), jsxRuntime.jsx("div", { className: "w-full h-12 rounded-md bg-gray-100 animate-pulse" })] }, index)); }) }))] }) }) }) }), jsxRuntime.jsx("div", { className: styles.foot, children: foot && foot(state) })] }));
1890
1920
  };
1891
1921
 
1892
1922
  var base$c = {
@@ -2632,7 +2662,7 @@ var TableColumnOptionsCustom = function (props) {
2632
2662
  var styles = handleGenerateStyle();
2633
2663
  return (jsxRuntime.jsxs(react.Popover, { children: [jsxRuntime.jsx(react.Popover.Button, { children: trigger }), jsxRuntime.jsxs(react.Popover.Panel, { className: styles.controls.content, children: [resetConfig && (jsxRuntime.jsxs("div", { className: styles.controls.dropdown.reset, onClick: function () {
2634
2664
  removeTableState(resetConfig.tableId);
2635
- table.resetColumnVisibility(true);
2665
+ table.resetColumnVisibility();
2636
2666
  table.resetColumnOrder();
2637
2667
  resetConfig.onReset && resetConfig.onReset();
2638
2668
  }, children: [jsxRuntime.jsx(IconElement, { accessor: "rotate-left" }), jsxRuntime.jsx("p", { children: (_a = resetConfig.label) !== null && _a !== void 0 ? _a : 'Reset' })] })), table