@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.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 = {
@@ -2630,7 +2660,7 @@ var TableColumnOptionsCustom = function (props) {
2630
2660
  var styles = handleGenerateStyle();
2631
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 () {
2632
2662
  removeTableState(resetConfig.tableId);
2633
- table.resetColumnVisibility(true);
2663
+ table.resetColumnVisibility();
2634
2664
  table.resetColumnOrder();
2635
2665
  resetConfig.onReset && resetConfig.onReset();
2636
2666
  }, children: [jsx(IconElement, { accessor: "rotate-left" }), jsx("p", { children: (_a = resetConfig.label) !== null && _a !== void 0 ? _a : 'Reset' })] })), table