@ballistix.digital/react-components 1.0.3 → 2.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/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';
@@ -1194,6 +1194,79 @@ var useExcel = function () {
1194
1194
  };
1195
1195
  };
1196
1196
 
1197
+ var SelectMenuForm = function (props) {
1198
+ var _a;
1199
+ var _b = props.name, name = _b === void 0 ? 'select-menu-form' : _b, label = props.label, description = props.description, placeholder = props.placeholder, options = props.options, required = props.required, value = props.value, error = props.error, _c = props.isRequired, isRequired = _c === void 0 ? false : _c, isLoading = props.isLoading, _d = props.isTouched, isTouched = _d === void 0 ? false : _d, isDisabled = props.isDisabled, _e = props.isClearable, isClearable = _e === void 0 ? true : _e, _f = props.isMultiple, isMultiple = _f === void 0 ? false : _f, _g = props.isSearchable, isSearchable = _g === void 0 ? true : _g, _h = props.isSolo, isSolo = _h === void 0 ? false : _h, onChange = props.onChange, onSearchInputChange = props.onSearchInputChange, onClear = props.onClear, onBlur = props.onBlur, stylesOverrides = props.styles;
1200
+ var _j = useState(true), isFocus = _j[0], setIsFocus = _j[1];
1201
+ var _k = useState(value !== null && value !== void 0 ? value : null), state = _k[0], setState = _k[1];
1202
+ var isValid = error === undefined;
1203
+ var selectDataCy = "form-select-".concat(name);
1204
+ var errorDataCy = "form-select-error-".concat(name);
1205
+ var handleGenerateStyle = function () {
1206
+ var result = deepCopyObject(styles$i.base);
1207
+ var keys = calculateNestedKeys(styles$i.base);
1208
+ keys.forEach(function (key) {
1209
+ set(result, key, toClassName(get(styles$i.base, key), get(styles$i['normal'], key), isTouched === true && !isValid && get(styles$i.invalid, key), isDisabled && get(styles$i.disabled, key), get(stylesOverrides, key)));
1210
+ });
1211
+ return result;
1212
+ };
1213
+ var handleChange = function (selectValue) {
1214
+ setState(selectValue);
1215
+ onChange && onChange(selectValue);
1216
+ setIsFocus(false);
1217
+ };
1218
+ var styles = handleGenerateStyle();
1219
+ // Simulate onClear event.
1220
+ useEffect(function () {
1221
+ if (state === null && !isFocus) {
1222
+ onClear && onClear(name);
1223
+ }
1224
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1225
+ }, [state]);
1226
+ // Simulate onBlur event.
1227
+ useEffect(function () {
1228
+ if (!isFocus) {
1229
+ onBlur && onBlur();
1230
+ }
1231
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1232
+ }, [isFocus]);
1233
+ // listen to value changes.
1234
+ useEffect(function () {
1235
+ setState(value);
1236
+ }, [value]);
1237
+ return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", { className: styles.container, children: [jsx("div", { "data-cy": selectDataCy, children: jsx(Select, { primaryColor: "primary",
1238
+ //
1239
+ placeholder: placeholder === null || placeholder === void 0 ? void 0 : placeholder.select, noOptionsMessage: (jsx("p", { className: styles.emptyState, children: (_a = placeholder === null || placeholder === void 0 ? void 0 : placeholder.emptyState) !== null && _a !== void 0 ? _a : 'No results found' })), searchInputPlaceholder: placeholder === null || placeholder === void 0 ? void 0 : placeholder.searchInput,
1240
+ //
1241
+ loading: isLoading, isDisabled: isDisabled, isClearable: isClearable, isMultiple: isMultiple, isSearchable: isSearchable,
1242
+ //
1243
+ options: options,
1244
+ //
1245
+ value: state, onChange: handleChange, onSearchInputChange: onSearchInputChange,
1246
+ //
1247
+ classNames: {
1248
+ menuButton: function () {
1249
+ return toClassName(styles.input, state === null && '[&>*]:!text-gray-300 ', state === null &&
1250
+ !isValid &&
1251
+ isTouched &&
1252
+ '[&>*]:!text-red-300');
1253
+ },
1254
+ menu: styles.menu,
1255
+ tagItem: function () { return styles.tagItem; },
1256
+ tagItemText: styles.tagItemText,
1257
+ tagItemIconContainer: styles.tagItemIconContainer,
1258
+ tagItemIcon: styles.tagItemIcon,
1259
+ list: styles.list,
1260
+ listItem: function () { return styles.listItem; },
1261
+ listDisabledItem: styles.listDisabledItem,
1262
+ listGroupLabel: styles.listGroupLabel,
1263
+ searchContainer: styles.searchContainer,
1264
+ searchBox: styles.searchBox,
1265
+ searchIcon: styles.searchIcon,
1266
+ closeIcon: styles.closeIcon,
1267
+ } }) }), !isSolo && (jsxs("div", { className: styles.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles.description, children: description })), error && isTouched && (jsx("p", { className: styles.error, "data-cy": errorDataCy, children: JSON.stringify(error).replaceAll('"', '') }))] }))] })] }));
1268
+ };
1269
+
1197
1270
  var base$f = {
1198
1271
  container: '',
1199
1272
  head: 'flex justify-between',
@@ -1285,79 +1358,6 @@ var styles$i = {
1285
1358
  disabled: disabled$6,
1286
1359
  };
1287
1360
 
1288
- var SelectMenuForm = function (props) {
1289
- var _a;
1290
- var _b = props.name, name = _b === void 0 ? 'select-menu-form' : _b, label = props.label, description = props.description, placeholder = props.placeholder, options = props.options, required = props.required, value = props.value, error = props.error, _c = props.isRequired, isRequired = _c === void 0 ? false : _c, isLoading = props.isLoading, _d = props.isTouched, isTouched = _d === void 0 ? false : _d, isDisabled = props.isDisabled, _e = props.isClearable, isClearable = _e === void 0 ? true : _e, _f = props.isMultiple, isMultiple = _f === void 0 ? false : _f, _g = props.isSearchable, isSearchable = _g === void 0 ? true : _g, _h = props.isSolo, isSolo = _h === void 0 ? false : _h, onChange = props.onChange, onSearchInputChange = props.onSearchInputChange, onClear = props.onClear, onBlur = props.onBlur, stylesOverrides = props.styles;
1291
- var _j = useState(true), isFocus = _j[0], setIsFocus = _j[1];
1292
- var _k = useState(value !== null && value !== void 0 ? value : null), state = _k[0], setState = _k[1];
1293
- var isValid = error === undefined;
1294
- var selectDataCy = "form-select-".concat(name);
1295
- var errorDataCy = "form-select-error-".concat(name);
1296
- var handleGenerateStyle = function () {
1297
- var result = deepCopyObject(styles$i.base);
1298
- var keys = calculateNestedKeys(styles$i.base);
1299
- keys.forEach(function (key) {
1300
- set(result, key, toClassName(get(styles$i.base, key), get(styles$i['normal'], key), isTouched === true && !isValid && get(styles$i.invalid, key), isDisabled && get(styles$i.disabled, key), get(stylesOverrides, key)));
1301
- });
1302
- return result;
1303
- };
1304
- var handleChange = function (selectValue) {
1305
- setState(selectValue);
1306
- onChange && onChange(selectValue);
1307
- setIsFocus(false);
1308
- };
1309
- var styles = handleGenerateStyle();
1310
- // Simulate onClear event.
1311
- useEffect(function () {
1312
- if (state === null && !isFocus) {
1313
- onClear && onClear(name);
1314
- }
1315
- // eslint-disable-next-line react-hooks/exhaustive-deps
1316
- }, [state]);
1317
- // Simulate onBlur event.
1318
- useEffect(function () {
1319
- if (!isFocus) {
1320
- onBlur && onBlur();
1321
- }
1322
- // eslint-disable-next-line react-hooks/exhaustive-deps
1323
- }, [isFocus]);
1324
- // listen to value changes.
1325
- useEffect(function () {
1326
- setState(value);
1327
- }, [value]);
1328
- return (jsxs("div", { className: styles.container, children: [jsxs("div", { className: styles.head, children: [label && (jsx("label", { htmlFor: name, className: styles.label, children: label })), !required && !isRequired && typeof label === 'string' && (jsx("span", { className: styles.hint, children: "Optional" })), required && required({ isRequired: isRequired })] }), jsxs("div", { className: styles.container, children: [jsx("div", { "data-cy": selectDataCy, children: jsx(Select, { primaryColor: "primary",
1329
- //
1330
- placeholder: placeholder === null || placeholder === void 0 ? void 0 : placeholder.select, noOptionsMessage: (jsx("p", { className: styles.emptyState, children: (_a = placeholder === null || placeholder === void 0 ? void 0 : placeholder.emptyState) !== null && _a !== void 0 ? _a : 'No results found' })), searchInputPlaceholder: placeholder === null || placeholder === void 0 ? void 0 : placeholder.searchInput,
1331
- //
1332
- loading: isLoading, isDisabled: isDisabled, isClearable: isClearable, isMultiple: isMultiple, isSearchable: isSearchable,
1333
- //
1334
- options: options,
1335
- //
1336
- value: state, onChange: handleChange, onSearchInputChange: onSearchInputChange,
1337
- //
1338
- classNames: {
1339
- menuButton: function () {
1340
- return toClassName(styles.input, state === null && '[&>*]:!text-gray-300 ', state === null &&
1341
- !isValid &&
1342
- isTouched &&
1343
- '[&>*]:!text-red-300');
1344
- },
1345
- menu: styles.menu,
1346
- tagItem: function () { return styles.tagItem; },
1347
- tagItemText: styles.tagItemText,
1348
- tagItemIconContainer: styles.tagItemIconContainer,
1349
- tagItemIcon: styles.tagItemIcon,
1350
- list: styles.list,
1351
- listItem: function () { return styles.listItem; },
1352
- listDisabledItem: styles.listDisabledItem,
1353
- listGroupLabel: styles.listGroupLabel,
1354
- searchContainer: styles.searchContainer,
1355
- searchBox: styles.searchBox,
1356
- searchIcon: styles.searchIcon,
1357
- closeIcon: styles.closeIcon,
1358
- } }) }), !isSolo && (jsxs("div", { className: styles.foot, children: [description && !(error && isTouched) && (jsx("p", { className: styles.description, children: description })), error && isTouched && (jsx("p", { className: styles.error, "data-cy": errorDataCy, children: JSON.stringify(error).replaceAll('"', '') }))] }))] })] }));
1359
- };
1360
-
1361
1361
  var PanelPaginationNavigation = function (props) {
1362
1362
  var defaultValue = props.current, _a = props.min, min = _a === void 0 ? 1 : _a, _b = props.max, max = _b === void 0 ? 20 : _b, stylesOverrides = props.styles, pageSizeOptions = props.pageSizeOptions, defaultPageSize = props.defaultPageSize, _c = props.onChangePageSize, onChangePageSize = _c === void 0 ? noop$1 : _c, children = props.children, onChange = props.onChange;
1363
1363
  var _d = useState(1), current = _d[0], setCurrent = _d[1];
@@ -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
@@ -2891,9 +2921,7 @@ var CheckboxInputForm = function (props) {
2891
2921
  var result = deepCopyObject(styles$4.base);
2892
2922
  var keys = calculateNestedKeys(styles$4.base);
2893
2923
  keys.forEach(function (key) {
2894
- set(result, key, toClassName(get(styles$4.base, key),
2895
- // isTouched === true && !isValid && get(defaultStyles.invalid, key),
2896
- isDisabled && get(styles$4.disabled, key), get(stylesOverrides, key)));
2924
+ set(result, key, toClassName(get(styles$4.base, key), isDisabled && get(styles$4.disabled, key), get(stylesOverrides, key)));
2897
2925
  });
2898
2926
  return result;
2899
2927
  };
@@ -2922,7 +2950,7 @@ var CheckboxInputForm = function (props) {
2922
2950
  inputRef.current.indeterminate = value === null;
2923
2951
  }
2924
2952
  }, [isIndeterminable, value]);
2925
- return (jsxs("div", { className: styles.container, children: [jsx("div", { className: styles.head, children: jsx("input", { ref: inputRef, name: name, "data-cy": "form-".concat(name, "-checkbox"), "aria-describedby": "".concat(name, "-description"), type: "checkbox", checked: !!value, className: styles.input, disabled: isDisabled, onChange: handleToggle }) }), jsxs("div", { className: styles.body, children: [jsx("label", { htmlFor: "comments", className: styles.label, children: title }), description && (jsx("p", { id: "comments-description", className: styles.description, children: description }))] })] }));
2953
+ return (jsxs("div", { className: styles.container, children: [jsx("div", { className: styles.head, children: jsx("input", { ref: inputRef, name: name, "data-cy": "form-".concat(name, "-checkbox"), "aria-describedby": "".concat(name, "-description"), type: "checkbox", checked: !!value, className: styles.input, disabled: isDisabled, onChange: handleToggle }) }), jsxs("div", { className: styles.body, children: [jsx("label", { htmlFor: name, className: styles.label, children: title }), description && (jsx("p", { id: "".concat(name, "-description"), className: styles.description, children: description }))] })] }));
2926
2954
  };
2927
2955
 
2928
2956
  var base$3 = {