@pdg/react-table 1.0.28 → 1.0.30

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.
@@ -16,6 +16,13 @@ export interface TableColumn<T = TableItem> {
16
16
  ellipsis?: boolean;
17
17
  dateFormat?: string;
18
18
  tooltipProps?: Omit<TooltipProps, 'children' | 'title'>;
19
+ display?: {
20
+ xs?: boolean;
21
+ sm?: boolean;
22
+ md?: boolean;
23
+ lg?: boolean;
24
+ xl?: boolean;
25
+ };
19
26
  head?: {
20
27
  className?: CommonSxProps['className'];
21
28
  style?: CommonSxProps['style'];
@@ -48,6 +55,7 @@ export interface TableColumn<T = TableItem> {
48
55
  onInitChecked?(item: T): boolean;
49
56
  onCheckDisabled?(item: T): boolean;
50
57
  onCheckChange?(item: T, checked: boolean): void;
58
+ onCheckDisabledChange?(item: T, checkDisabled: boolean): void;
51
59
  }
52
60
  export interface TableProps<T = TableItem> extends CommonSxProps {
53
61
  columns?: (TableColumn<T> | false | undefined | null)[];
@@ -1,7 +1,7 @@
1
1
  import { TableColumn, TableItem, TableProps } from '../Table/Table.types';
2
2
  export interface TableBodyCellCommands {
3
- setCheckDisabled(disabled: boolean): void;
4
3
  setChecked(checked: boolean): void;
4
+ setCheckDisabled(disabled: boolean): void;
5
5
  }
6
6
  export interface TableBodyCellProps {
7
7
  index: number;
@@ -1,6 +1,7 @@
1
1
  import { TableColumn, TableProps } from '../Table/Table.types';
2
2
  export interface TableHeadCellCommands {
3
3
  setChecked(checked: boolean): void;
4
+ setCheckDisabled(checkDisabled: boolean): void;
4
5
  }
5
6
  export interface TableHeadCellProps {
6
7
  column: TableColumn;
package/dist/index.esm.js CHANGED
@@ -8420,6 +8420,7 @@ var TableCommonCell = function (_a) {
8420
8420
  var _a, _b, _c, _d, _e, _f;
8421
8421
  var sx;
8422
8422
  var getSx;
8423
+ var displaySx;
8423
8424
  switch (type) {
8424
8425
  case 'head':
8425
8426
  sx = (_a = column.head) === null || _a === void 0 ? void 0 : _a.sx;
@@ -8436,6 +8437,20 @@ var TableCommonCell = function (_a) {
8436
8437
  getSx = ((_e = column.footer) === null || _e === void 0 ? void 0 : _e.onGetSx) ? (_f = column.footer) === null || _f === void 0 ? void 0 : _f.onGetSx() : undefined;
8437
8438
  break;
8438
8439
  }
8440
+ if (column.display) {
8441
+ var display = {};
8442
+ if (column.display.xs !== undefined)
8443
+ display.xs = column.display.xs ? 'table-cell' : 'none';
8444
+ if (column.display.sm !== undefined)
8445
+ display.sm = column.display.sm ? 'table-cell' : 'none';
8446
+ if (column.display.md !== undefined)
8447
+ display.md = column.display.md ? 'table-cell' : 'none';
8448
+ if (column.display.lg !== undefined)
8449
+ display.lg = column.display.lg ? 'table-cell' : 'none';
8450
+ if (column.display.xl !== undefined)
8451
+ display.xl = column.display.xl ? 'table-cell' : 'none';
8452
+ displaySx = { display: display };
8453
+ }
8439
8454
  var sxList = [];
8440
8455
  if (getSx)
8441
8456
  sxList.push(getSx);
@@ -8443,6 +8458,8 @@ var TableCommonCell = function (_a) {
8443
8458
  sxList.push(sx);
8444
8459
  if (initSx)
8445
8460
  sxList.push(initSx);
8461
+ if (displaySx)
8462
+ sxList.push(displaySx);
8446
8463
  if (sxList.length > 0) {
8447
8464
  if (sxList.length === 1) {
8448
8465
  return sxList[0];
@@ -8515,9 +8532,17 @@ var TableBodyCell = function (_a) {
8515
8532
  }
8516
8533
  // eslint-disable-next-line react-hooks/exhaustive-deps
8517
8534
  }, [checked]);
8535
+ useEffect(function () {
8536
+ if (column.type === 'check') {
8537
+ setItemColumnChecked(item, column, checked);
8538
+ column.onCheckChange && column.onCheckChange(item, checked);
8539
+ }
8540
+ // eslint-disable-next-line react-hooks/exhaustive-deps
8541
+ }, [checked]);
8518
8542
  useEffect(function () {
8519
8543
  if (column.type === 'check') {
8520
8544
  setItemColumnCheckDisabled(item, column, checkDisabled);
8545
+ column.onCheckDisabledChange && column.onCheckDisabledChange(item, checkDisabled);
8521
8546
  }
8522
8547
  // eslint-disable-next-line react-hooks/exhaustive-deps
8523
8548
  }, [checkDisabled]);
@@ -8652,6 +8677,7 @@ TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableHeadCell = functio
8652
8677
  var _b = useTableState(), setHeadColumnChecked = _b.setHeadColumnChecked, setHeadColumnCommands = _b.setHeadColumnCommands;
8653
8678
  // State -------------------------------------------------------------------------------------------------------------
8654
8679
  var _c = useState(false), checked = _c[0], setChecked = _c[1];
8680
+ var _d = useState(false), checkDisabled = _d[0], setCheckDisabled = _d[1];
8655
8681
  // Effect ------------------------------------------------------------------------------------------------------------
8656
8682
  useEffect(function () {
8657
8683
  if (column.type === 'check') {
@@ -8665,13 +8691,18 @@ TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableHeadCell = functio
8665
8691
  setChecked(checked);
8666
8692
  }
8667
8693
  },
8694
+ setCheckDisabled: function (checkDisabled) {
8695
+ if (column.type === 'check') {
8696
+ setCheckDisabled(checkDisabled);
8697
+ }
8698
+ },
8668
8699
  });
8669
8700
  }, [setHeadColumnCommands, column]);
8670
8701
  // Memo --------------------------------------------------------------------------------------------------------------
8671
8702
  var data = useMemo(function () {
8672
8703
  var _a, _b;
8673
8704
  if (column.type === 'check') {
8674
- return (React__default.createElement(Checkbox, { checked: checked, onChange: function (e, newChecked) {
8705
+ return (React__default.createElement(Checkbox, { checked: checked, disabled: checkDisabled, onChange: function (e, newChecked) {
8675
8706
  setChecked(newChecked);
8676
8707
  onCheckChange && onCheckChange(column, newChecked);
8677
8708
  } }));
@@ -8684,7 +8715,7 @@ TableBodyRow.defaultProps = TableBodyRowDefaultProps;var TableHeadCell = functio
8684
8715
  return column.label;
8685
8716
  }
8686
8717
  }
8687
- }, [checked, column, onCheckChange]);
8718
+ }, [checkDisabled, checked, column, onCheckChange]);
8688
8719
  // Render ------------------------------------------------------------------------------------------------------------
8689
8720
  return (React__default.createElement(TableCommonCell, { type: 'head', className: 'TableHeadCell', column: column, defaultAlign: defaultAlign }, data));
8690
8721
  };var TableFooterCell = function (_a) {
@@ -8944,17 +8975,27 @@ var Table = React__default.forwardRef(function (_a, ref) {
8944
8975
  var headColumnData = localHeaderDataRef.current[column.id];
8945
8976
  if (headColumnData) {
8946
8977
  updateHeadCheckTimer.current = setTimeout(function () {
8947
- var _a;
8978
+ var _a, _b;
8948
8979
  updateHeadCheckTimer.current = undefined;
8949
- var allChecked = !Object.keys(localBodyDataRef.current).find(function (key) {
8980
+ var enabledCheckExists = !!Object.keys(localBodyDataRef.current).find(function (key) {
8950
8981
  var columnData = localBodyDataRef.current[key].columns[column.id];
8951
8982
  if (columnData) {
8952
8983
  if (!columnData.checkDisabled) {
8953
- return !columnData.checked;
8984
+ return true;
8954
8985
  }
8955
8986
  }
8956
8987
  });
8957
- (_a = headColumnData.commands) === null || _a === void 0 ? void 0 : _a.setChecked(allChecked);
8988
+ var allChecked = enabledCheckExists &&
8989
+ !Object.keys(localBodyDataRef.current).find(function (key) {
8990
+ var columnData = localBodyDataRef.current[key].columns[column.id];
8991
+ if (columnData) {
8992
+ if (!columnData.checkDisabled) {
8993
+ return !columnData.checked;
8994
+ }
8995
+ }
8996
+ });
8997
+ (_a = headColumnData.commands) === null || _a === void 0 ? void 0 : _a.setCheckDisabled(!enabledCheckExists);
8998
+ (_b = headColumnData.commands) === null || _b === void 0 ? void 0 : _b.setChecked(allChecked);
8958
8999
  }, 100);
8959
9000
  }
8960
9001
  }, []);
@@ -9176,8 +9217,9 @@ var Table = React__default.forwardRef(function (_a, ref) {
9176
9217
  var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[column.id];
9177
9218
  if (data) {
9178
9219
  data.checkDisabled = disabled;
9220
+ updateHeadCheck(column);
9179
9221
  }
9180
- }, []);
9222
+ }, [updateHeadCheck]);
9181
9223
  var TableContextSetItemColumnCommands = useCallback(function (item, column, commands) {
9182
9224
  var _a;
9183
9225
  var data = (_a = localBodyDataRef.current[item.id]) === null || _a === void 0 ? void 0 : _a.columns[column.id];