@ballistix.digital/react-components 0.4.3 → 0.4.4

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
@@ -2,7 +2,7 @@ import React, { FC, ReactNode, RefObject, ReactElement, HTMLInputTypeAttribute,
2
2
  import { DeepPartial as DeepPartial$1 } from 'types/DeepPartial';
3
3
  import { Menu } from '@headlessui/react';
4
4
  import { IconName } from '@fortawesome/fontawesome-svg-core';
5
- import { ColumnDef } from '@tanstack/react-table';
5
+ import { ColumnDef, SortingState, ColumnOrderState } from '@tanstack/react-table';
6
6
  import { TButtonElementStyles as TButtonElementStyles$1 } from 'components/Element/Button';
7
7
  import { TDropdownElementStyles as TDropdownElementStyles$1 } from 'components/Element/Dropdown';
8
8
  import { TPagePaginationNavigationStyles as TPagePaginationNavigationStyles$1 } from 'components/Navigation/PagePagination';
@@ -297,6 +297,9 @@ declare const base$7: {
297
297
  type TTableListStyles = DeepPartial$1<typeof base$7>;
298
298
 
299
299
  type TData = any;
300
+ type VisibilityState = {
301
+ [key: string]: boolean;
302
+ };
300
303
  type TProps$6<TData> = {
301
304
  id: string;
302
305
  columns: ColumnDef<TData>[];
@@ -304,6 +307,7 @@ type TProps$6<TData> = {
304
307
  page: {
305
308
  total: number;
306
309
  };
310
+ defaultOrder?: string[];
307
311
  children: ({ min, max, current, }: {
308
312
  min: number;
309
313
  max: number;
@@ -321,6 +325,11 @@ type TProps$6<TData> = {
321
325
  panelPaginationNavigation: TPagePaginationNavigationStyles$1;
322
326
  };
323
327
  };
328
+ onChange?: ({ sorting, visibility, order, }: {
329
+ sorting: SortingState;
330
+ visibility: VisibilityState;
331
+ order: ColumnOrderState;
332
+ }) => void;
324
333
  };
325
334
  declare const TableList: FC<TProps$6<TData>>;
326
335
 
package/dist/index.esm.js CHANGED
@@ -328,7 +328,7 @@ var ButtonElement = function (props) {
328
328
  return result;
329
329
  };
330
330
  var styles = handleGenerateStyle();
331
- return (jsxs("button", __assign({ type: htmlType, className: styles.container, disabled: isDisabled || status !== 'idle', onClick: onClick, ref: innerRef }, { children: [status === 'idle' && children, status === 'loading' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(ArrowPathIcon, { className: styles.spinner }), jsx("p", { children: children })] }))), status === 'error' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(ExclamationCircleIcon, { className: styles.icon }), jsx("p", { children: children })] }))), status === 'success' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(CheckIcon, { className: styles.icon }), jsx("p", { children: children })] })))] })));
331
+ return (jsxs("button", __assign({ type: htmlType, className: styles.container, disabled: isDisabled || status !== 'idle', onClick: onClick, ref: innerRef }, { children: [status === 'idle' && children, status === 'loading' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(ArrowPathIcon, { className: styles.spinner }), jsx("div", { children: children })] }))), status === 'error' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(ExclamationCircleIcon, { className: styles.icon }), jsx("div", { children: children })] }))), status === 'success' && (jsxs("div", __assign({ className: styles.content }, { children: [jsx(CheckIcon, { className: styles.icon }), jsx("div", { children: children })] })))] })));
332
332
  };
333
333
 
334
334
  var base$g = {
@@ -16868,7 +16868,7 @@ var PanelPaginationNavigation = function (props) {
16868
16868
  component = (jsxs(Fragment$1, { children: [jsx("button", __assign({ className: toClassName(styles.button.default, current === min && styles.button.active), onClick: function () { return handleChangeCurrent(min); } }, { children: min })), jsx("button", __assign({ className: toClassName(styles.button.default, current === min + 1 && styles.button.active), onClick: function () { return handleChangeCurrent(min + 1); } }, { children: min + 1 })), jsx("button", __assign({ className: toClassName(styles.button.default, current === min + 2 && styles.button.active), onClick: function () { return handleChangeCurrent(min + 2); } }, { children: min + 2 }))] }));
16869
16869
  break;
16870
16870
  }
16871
- return (jsxs("div", __assign({ className: styles.container }, { children: [jsxs("div", __assign({ className: "flex flex-1 justify-between sm:hidden" }, { children: [jsx("button", __assign({ className: toClassName(styles.mobile.button, current === min && styles.button.disabled), disabled: current === min, onClick: function () { return handleChangeCurrent(current - 1); } }, { children: "Previous" })), jsx("button", __assign({ className: toClassName(styles.mobile.button, current === max && styles.button.disabled), disabled: current === max, onClick: function () { return handleChangeCurrent(current + 1); } }, { children: "Next" }))] })), jsxs("div", __assign({ className: styles.desktop.container }, { children: [jsx("div", { children: jsx("p", __assign({ className: "text-sm text-gray-700" }, { children: children({ min: min, max: max, current: current }) })) }), jsx("div", { children: jsxs("nav", __assign({ className: styles.desktop.navigation, "aria-label": "Pagination" }, { children: [jsxs("button", __assign({ className: toClassName(styles.desktop.leftButton, current === min && styles.button.disabled), disabled: current === min, onClick: function () { return handleChangeCurrent(current - 1); } }, { children: [jsx("span", __assign({ className: styles.label }, { children: "Previous" })), jsx(ChevronLeftIcon, { className: styles.icon, "aria-hidden": "true" })] })), component, jsxs("button", __assign({ className: toClassName(styles.desktop.rightButton, current === max && styles.button.disabled), disabled: current === max, onClick: function () { return handleChangeCurrent(current + 1); } }, { children: [jsx("span", __assign({ className: styles.label }, { children: "Next" })), jsx(ChevronRightIcon, { className: styles.icon, "aria-hidden": "true" })] }))] })) })] }))] })));
16871
+ return (jsxs("div", __assign({ className: styles.container }, { children: [jsxs("div", __assign({ className: "flex flex-1 justify-between sm:hidden" }, { children: [jsx("button", __assign({ className: toClassName(styles.mobile.button, current === min && styles.button.disabled), disabled: current === min, onClick: function () { return handleChangeCurrent(current - 1); } }, { children: "Previous" })), jsx("button", __assign({ className: toClassName(styles.mobile.button, current === max && styles.button.disabled), disabled: current === max, onClick: function () { return handleChangeCurrent(current + 1); } }, { children: "Next" }))] })), jsxs("div", __assign({ className: styles.desktop.container }, { children: [jsx("div", { children: jsx("div", __assign({ className: "text-sm text-gray-700" }, { children: children({ min: min, max: max, current: current }) })) }), jsx("div", { children: jsxs("nav", __assign({ className: styles.desktop.navigation, "aria-label": "Pagination" }, { children: [jsxs("button", __assign({ className: toClassName(styles.desktop.leftButton, current === min && styles.button.disabled), disabled: current === min, onClick: function () { return handleChangeCurrent(current - 1); } }, { children: [jsx("span", __assign({ className: styles.label }, { children: "Previous" })), jsx(ChevronLeftIcon, { className: styles.icon, "aria-hidden": "true" })] })), component, jsxs("button", __assign({ className: toClassName(styles.desktop.rightButton, current === max && styles.button.disabled), disabled: current === max, onClick: function () { return handleChangeCurrent(current + 1); } }, { children: [jsx("span", __assign({ className: styles.label }, { children: "Next" })), jsx(ChevronRightIcon, { className: styles.icon, "aria-hidden": "true" })] }))] })) })] }))] })));
16872
16872
  };
16873
16873
 
16874
16874
  var base$7 = {
@@ -16897,7 +16897,7 @@ var styles$8 = {
16897
16897
  };
16898
16898
 
16899
16899
  var TableList = function (props) {
16900
- var id = props.id, columns = props.columns, data = props.data, page = props.page, children = props.children, _a = props.type, type = _a === void 0 ? 'normal' : _a, _b = props.isStriped, isStriped = _b === void 0 ? false : _b, _c = props.hasStickyHeader, hasStickyHeader = _c === void 0 ? false : _c, _d = props.hasVerticalSeparators, hasVerticalSeparators = _d === void 0 ? false : _d, _e = props.areControlsVisible, areControlsVisible = _e === void 0 ? true : _e, stylesOverrides = props.styles;
16900
+ var id = props.id, columns = props.columns, data = props.data, page = props.page, children = props.children, defaultOrder = props.defaultOrder, _a = props.type, type = _a === void 0 ? 'normal' : _a, _b = props.isStriped, isStriped = _b === void 0 ? false : _b, _c = props.hasStickyHeader, hasStickyHeader = _c === void 0 ? false : _c, _d = props.hasVerticalSeparators, hasVerticalSeparators = _d === void 0 ? false : _d, _e = props.areControlsVisible, areControlsVisible = _e === void 0 ? true : _e, stylesOverrides = props.styles, onChange = props.onChange;
16901
16901
  var write = useExcel().write;
16902
16902
  var handleGenerateStyle = function () {
16903
16903
  var result = deepCopyObject(styles$7.base);
@@ -16926,6 +16926,12 @@ var TableList = function (props) {
16926
16926
  onColumnVisibilityChange: setVisibility,
16927
16927
  onColumnOrderChange: setOrder,
16928
16928
  });
16929
+ useEffect(function () {
16930
+ if (sorting || visibility || order) {
16931
+ onChange && onChange({ sorting: sorting, visibility: visibility, order: order });
16932
+ }
16933
+ // eslint-disable-next-line react-hooks/exhaustive-deps
16934
+ }, [sorting || visibility || order]);
16929
16935
  var handleCalculateExcelTypeFromValue = function (value) {
16930
16936
  var _a;
16931
16937
  var result = 'string';
@@ -16972,8 +16978,7 @@ var TableList = function (props) {
16972
16978
  var handleUpdateColumnOrder = useCallback(function (column, location) {
16973
16979
  var _a;
16974
16980
  var ids = (_a = table
16975
- .getAllLeafColumns()
16976
- .filter(function (column) { return column === null || column === void 0 ? void 0 : column.getCanSort(); })) === null || _a === void 0 ? void 0 : _a.map(function (column) { return column.id; });
16981
+ .getAllLeafColumns()) === null || _a === void 0 ? void 0 : _a.map(function (column) { return column.id; });
16977
16982
  var currentIndexOfId = ids.findIndex(function (id) { return id === column.id; });
16978
16983
  // Remove id from array.
16979
16984
  ids.splice(currentIndexOfId, 1);
@@ -16986,6 +16991,9 @@ var TableList = function (props) {
16986
16991
  var _a;
16987
16992
  var state = window === null || window === void 0 ? void 0 : window.localStorage.getItem("TableList.".concat(id, ".state"));
16988
16993
  if (!state) {
16994
+ if (defaultOrder && (defaultOrder === null || defaultOrder === void 0 ? void 0 : defaultOrder.length) > 0) {
16995
+ return setOrder(defaultOrder);
16996
+ }
16989
16997
  return setOrder(columns.map(function (column) { var _a; return (_a = column === null || column === void 0 ? void 0 : column.id) !== null && _a !== void 0 ? _a : ''; }));
16990
16998
  }
16991
16999
  var savedColumnOrder = (_a = state === null || state === void 0 ? void 0 : state.split(',').map(function (id) { return id.replace('-', ''); })) !== null && _a !== void 0 ? _a : [];
@@ -16995,7 +17003,7 @@ var TableList = function (props) {
16995
17003
  });
16996
17004
  setOrder(savedColumnOrder);
16997
17005
  setVisibility(savedColumnVisibility);
16998
- }, [columns, id]);
17006
+ }, [columns, defaultOrder, id]);
16999
17007
  // Save state to local storage when column visibility or order updates.
17000
17008
  useEffect(function () {
17001
17009
  var _a;
@@ -17003,8 +17011,7 @@ var TableList = function (props) {
17003
17011
  var isMounted = order.length > 0;
17004
17012
  if (isMounted && (order || visibility)) {
17005
17013
  var ids = (_a = table
17006
- .getAllLeafColumns()
17007
- .filter(function (column) { return column === null || column === void 0 ? void 0 : column.getCanSort(); })) === null || _a === void 0 ? void 0 : _a.map(function (column) { return column.id; });
17014
+ .getAllLeafColumns()) === null || _a === void 0 ? void 0 : _a.map(function (column) { return column.id; });
17008
17015
  var idsWithVisibilityIndicator = ids.map(function (id) {
17009
17016
  // Hardcoding `false` here since `undefined` is allowed.
17010
17017
  if (visibility[id] === false) {
@@ -17017,9 +17024,10 @@ var TableList = function (props) {
17017
17024
  }, [id, table, order, visibility]);
17018
17025
  return (jsx(Fragment$1, { children: jsxs("div", __assign({ className: styles.container }, { children: [jsxs("div", __assign({ className: styles.controls.container }, { children: [jsx(DropdownElement.Container, __assign({ styles: stylesOverrides === null || stylesOverrides === void 0 ? void 0 : stylesOverrides.components.dropdownElement, label: jsx(ViewColumnsIcon, { className: "w-6 h-6" }) }, { children: jsx("div", __assign({ className: styles.controls.content }, { children: table
17019
17026
  .getAllLeafColumns()
17020
- .filter(function (column) { return column === null || column === void 0 ? void 0 : column.getCanSort(); })
17027
+ // .filter((column) => column?.getCanSort())
17021
17028
  .map(function (column, index) {
17022
- return (jsx(DropdownElement.Item, { children: function () { return (jsxs("div", __assign({ className: styles.controls.dropdown.container }, { children: [jsx("input", { className: styles.controls.dropdown.input, type: "checkbox", checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }), jsx("label", __assign({ className: styles.controls.dropdown.label }, { children: column.columnDef.header })), jsxs("div", __assign({ className: styles.controls.dropdown.actions }, { children: [jsx(ChevronDownIcon$1, { className: styles.controls.dropdown.upIcon, onClick: function () {
17029
+ var canSort = column === null || column === void 0 ? void 0 : column.getCanSort();
17030
+ return (jsx(DropdownElement.Item, { children: function () { return (jsxs("div", __assign({ className: toClassName(styles.controls.dropdown.container, !canSort && 'hidden') }, { children: [jsx("input", { className: styles.controls.dropdown.input, type: "checkbox", checked: column.getIsVisible(), onChange: column.getToggleVisibilityHandler() }), jsx("label", __assign({ className: styles.controls.dropdown.label }, { children: column.columnDef.header })), jsxs("div", __assign({ className: styles.controls.dropdown.actions }, { children: [jsx(ChevronDownIcon$1, { className: styles.controls.dropdown.upIcon, onClick: function () {
17023
17031
  return handleUpdateColumnOrder(column, index - 1);
17024
17032
  } }), jsx(ChevronDownIcon$1, { className: styles.controls.dropdown.downIcon, onClick: function () {
17025
17033
  return handleUpdateColumnOrder(column, index + 1);