carbon-addons-iot-react 2.154.0-next.2 → 2.154.0-next.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.154.0-next.3](https://github.com/carbon-design-system/carbon-addons-iot-react/compare/v2.154.0-next.2...v2.154.0-next.3) (2023-10-18)
7
+
8
+
9
+ ### Features
10
+
11
+ * **table:** enable percentage-based column width for the table header ([#3831](https://github.com/carbon-design-system/carbon-addons-iot-react/issues/3831)) ([6dd5d97](https://github.com/carbon-design-system/carbon-addons-iot-react/commit/6dd5d97af83286a7d42a8f60d3ded51727c7c89e))
12
+
13
+
14
+
15
+
16
+
6
17
  # [2.154.0-next.2](https://github.com/carbon-design-system/carbon-addons-iot-react/compare/v2.154.0-next.1...v2.154.0-next.2) (2023-10-13)
7
18
 
8
19
 
@@ -688,7 +688,8 @@ var defaultProps = function defaultProps(baseProps) {
688
688
  error: null,
689
689
  // TODO: set default in v3. Leaving null for backwards compat. to match 'id' which was
690
690
  // previously used as testId.
691
- testId: null
691
+ testId: null,
692
+ enablePercentageColumnWidth: false
692
693
  };
693
694
  };
694
695
 
@@ -698,6 +699,7 @@ var Table = function Table(props) {
698
699
  var _merge2 = merge({}, defaultProps(props), props),
699
700
  id = _merge2.id,
700
701
  columns = _merge2.columns,
702
+ enablePercentageColumnWidth = _merge2.enablePercentageColumnWidth,
701
703
  columnGroups = _merge2.columnGroups,
702
704
  data = _merge2.data,
703
705
  expandedData = _merge2.expandedData,
@@ -716,7 +718,7 @@ var Table = function Table(props) {
716
718
  testId = _merge2.testId,
717
719
  size = _merge2.size,
718
720
  zIndex = _merge2.zIndex,
719
- others = _objectWithoutProperties(_merge2, ["id", "columns", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
721
+ others = _objectWithoutProperties(_merge2, ["id", "columns", "enablePercentageColumnWidth", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
720
722
  // so we need to track that for the save view functionality.
721
723
 
722
724
 
@@ -1034,6 +1036,7 @@ var Table = function Table(props) {
1034
1036
  truncateCellText: useCellTextTruncate
1035
1037
  }),
1036
1038
  columns: columns,
1039
+ enablePercentageColumnWidth: enablePercentageColumnWidth,
1037
1040
  columnGroups: columnGroups,
1038
1041
  filters: view.filters,
1039
1042
  actions: _objectSpread(_objectSpread(_objectSpread({}, pick(actions.toolbar, 'onApplyFilter')), pick(actions.table, 'onSelectAll', 'onChangeSort', 'onChangeOrdering', 'onColumnSelectionConfig', 'onOverflowItemClicked', 'onFilterRowIconClick')), {}, {
@@ -1,7 +1,7 @@
1
- import 'core-js/modules/es.object.keys.js';
2
1
  import 'core-js/modules/es.symbol.js';
3
2
  import 'core-js/modules/es.object.get-own-property-descriptor.js';
4
3
  import 'core-js/modules/es.object.get-own-property-descriptors.js';
4
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
5
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
6
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
7
7
  import debounce from '../../../node_modules/lodash-es/debounce.js';
@@ -15,8 +15,10 @@ import 'core-js/modules/es.array.map.js';
15
15
  import 'core-js/modules/web.dom-collections.for-each.js';
16
16
  import 'core-js/modules/es.object.entries.js';
17
17
  import 'core-js/modules/es.array.filter.js';
18
- import 'core-js/modules/es.array.slice.js';
18
+ import 'core-js/modules/es.object.keys.js';
19
+ import 'core-js/modules/es.string.includes.js';
19
20
  import 'core-js/modules/es.array.find.js';
21
+ import 'core-js/modules/es.array.slice.js';
20
22
  import 'core-js/modules/es.array.find-index.js';
21
23
  import 'core-js/modules/es.function.name.js';
22
24
  import React__default, { createRef, useState, useCallback, useLayoutEffect, useEffect } from 'react';
@@ -80,6 +82,7 @@ var propTypes = {
80
82
 
81
83
  /** List of columns */
82
84
  columns: TableColumnsPropTypes.isRequired,
85
+ enablePercentageColumnWidth: PropTypes.bool,
83
86
 
84
87
  /** Specify the properties of each column group in the table. Defaults to empty column. */
85
88
  columnGroups: TableColumnGroupPropType,
@@ -164,6 +167,7 @@ var defaultProps = {
164
167
  closeMenuText: 'Close menu',
165
168
  i18n: _objectSpread({}, defaultI18NPropTypes),
166
169
  hasFastFilter: true,
170
+ enablePercentageColumnWidth: false,
167
171
  testId: '',
168
172
  showExpanderColumn: false,
169
173
  size: undefined,
@@ -236,6 +240,7 @@ var TableHead = function TableHead(_ref) {
236
240
  hasFastFilter = _ref.hasFastFilter,
237
241
  showExpanderColumn = _ref.showExpanderColumn,
238
242
  size = _ref.size,
243
+ enablePercentageColumnWidth = _ref.enablePercentageColumnWidth,
239
244
  filterRowIcon = _ref.filterRowIcon,
240
245
  filterRowIconDescription = _ref.filterRowIconDescription;
241
246
  var filterBarActive = activeBar === 'filter';
@@ -248,6 +253,11 @@ var TableHead = function TableHead(_ref) {
248
253
  currentColumnWidths = _useState2[0],
249
254
  setCurrentColumnWidths = _useState2[1];
250
255
 
256
+ var _useState3 = useState(enablePercentageColumnWidth),
257
+ _useState4 = _slicedToArray(_useState3, 2),
258
+ percentageMode = _useState4[0],
259
+ setPercentageMode = _useState4[1];
260
+
251
261
  if (isEmpty(currentColumnWidths)) {
252
262
  columns.forEach(function (col) {
253
263
  initialColumnWidths[col.id] = col.width;
@@ -291,8 +301,28 @@ var TableHead = function TableHead(_ref) {
291
301
  };
292
302
 
293
303
  var onManualColumnResize = function onManualColumnResize(modifiedColumnWidths) {
294
- var newColumnWidths = createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
295
- updateColumnWidths(newColumnWidths);
304
+ if (percentageMode) {
305
+ var modifiedColumns = _toConsumableArray(columns);
306
+
307
+ Object.keys(modifiedColumns).forEach(function (key) {
308
+ if (modifiedColumns[key].hasOwnProperty('width')) {
309
+ delete modifiedColumns[key].width;
310
+ }
311
+ }); // while Resizing setting all column width to default DEFAULT_COLUMN_WIDTH 150px
312
+
313
+ var columnPropInlcudingWidths = addMissingColumnWidths({
314
+ ordering: ordering,
315
+ columns: modifiedColumns,
316
+ currentColumnWidths: {}
317
+ });
318
+ var newColumnWidths = createNewWidthsMap(ordering, columnPropInlcudingWidths);
319
+ setCurrentColumnWidths(newColumnWidths);
320
+ setPercentageMode(false);
321
+ } else {
322
+ var _newColumnWidths = createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
323
+
324
+ updateColumnWidths(_newColumnWidths);
325
+ }
296
326
  };
297
327
 
298
328
  var onColumnToggle = function onColumnToggle(columnId, newOrdering) {
@@ -309,14 +339,14 @@ var TableHead = function TableHead(_ref) {
309
339
  updateColumnWidths(newColumnWidths);
310
340
  }
311
341
  } else {
312
- var _newColumnWidths = calculateWidthsOnToggle({
342
+ var _newColumnWidths2 = calculateWidthsOnToggle({
313
343
  currentColumnWidths: currentColumnWidths,
314
344
  newOrdering: newOrdering,
315
345
  columnId: columnId,
316
346
  columns: columns
317
347
  });
318
348
 
319
- updateColumnWidths(_newColumnWidths);
349
+ updateColumnWidths(_newColumnWidths2);
320
350
  }
321
351
  }
322
352
 
@@ -369,7 +399,13 @@ var TableHead = function TableHead(_ref) {
369
399
  // if the widths of the column prop are externally updated or if columns are added/removed.
370
400
  var externallyModified = !isEqual(columns, previousColumns) || !isEqual(ordering, previousOrdering);
371
401
 
372
- if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified) {
402
+ if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified && !percentageMode) {
403
+ /* eslint-disable no-param-reassign */
404
+ Object.keys(columns).forEach(function (key) {
405
+ if (columns[key].width && columns[key].width.includes('%')) {
406
+ delete columns[key].width;
407
+ }
408
+ });
373
409
  checkColumnWidthFormat(columns); // PRESERVE WIDTHS
374
410
  // Preserve column when possible widths when columns are externally modified
375
411
 
@@ -413,7 +449,53 @@ var TableHead = function TableHead(_ref) {
413
449
  // since it would be directly overridden by the column props. This effect can be removed
414
450
  // with issue https://github.com/IBM/carbon-addons-iot-react/issues/1224
415
451
  // eslint-disable-next-line react-hooks/exhaustive-deps
416
- [hasResize, columns, ordering, previousColumns]);
452
+ [hasResize, columns, ordering, previousColumns, percentageMode]);
453
+ useEffect(function () {
454
+ var tableWidth;
455
+ var columnWidth;
456
+ var filteredColumns = columns.filter(function (colOrder) {
457
+ var hiddenCol = ordering.find(function (col) {
458
+ return col.columnId === colOrder.id;
459
+ });
460
+ return !hiddenCol || !hiddenCol.isHidden;
461
+ });
462
+ var hasOverflowMenu = filteredColumns.some(function (column) {
463
+ return column.overflowMenuItems && column.overflowMenuItems.length > 0;
464
+ });
465
+ var totalColumns = filteredColumns.length;
466
+
467
+ if (enablePercentageColumnWidth && filteredColumns.length && percentageMode && !hasOverflowMenu) {
468
+ if (hasRowSelection === 'multi' && !(hasRowExpansion || hasRowNesting)) {
469
+ tableWidth = "calc(100% - 54px)";
470
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
471
+ } else if ((hasRowExpansion || hasRowNesting) && !(hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
472
+ tableWidth = "calc(100% - 40px)";
473
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
474
+ } else if ((hasRowExpansion || hasRowNesting) && (hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
475
+ tableWidth = "calc(100% - 94px)";
476
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
477
+ } else {
478
+ columnWidth = "".concat(parseInt(100 / filteredColumns.length, 10), "%");
479
+ }
480
+
481
+ var updatedColumns = filteredColumns.map(function (col) {
482
+ var updatedCol = _objectSpread({}, col);
483
+
484
+ updatedCol.width = columnWidth;
485
+ return updatedCol;
486
+ });
487
+ var columnPropIncludingWidths = addMissingColumnWidths({
488
+ ordering: ordering,
489
+ columns: updatedColumns,
490
+ currentColumnWidths: currentColumnWidths
491
+ });
492
+ var newColumnWidths = createNewWidthsMap(ordering, columnPropIncludingWidths);
493
+
494
+ if (!isEqual(currentColumnWidths, newColumnWidths)) {
495
+ setCurrentColumnWidths(newColumnWidths);
496
+ }
497
+ }
498
+ }, [columns, ordering, hasRowExpansion, hasRowNesting, hasRowSelection, useRadioButtonSingleSelect, currentColumnWidths, enablePercentageColumnWidth, percentageMode]);
417
499
  var visibleColumns = ordering.filter(function (col) {
418
500
  return !col.isHidden;
419
501
  });
@@ -882,6 +964,17 @@ TableHead.__docgenInfo = {
882
964
  "required": false,
883
965
  "description": "should we filter on each keypress"
884
966
  },
967
+ "enablePercentageColumnWidth": {
968
+ "defaultValue": {
969
+ "value": "false",
970
+ "computed": false
971
+ },
972
+ "type": {
973
+ "name": "bool"
974
+ },
975
+ "required": false,
976
+ "description": ""
977
+ },
885
978
  "testId": {
886
979
  "defaultValue": {
887
980
  "value": "''",
@@ -8,10 +8,12 @@ import cloneDeep from '../../../node_modules/lodash-es/cloneDeep.js';
8
8
  import 'core-js/modules/es.array.find.js';
9
9
  import 'core-js/modules/es.array.reduce.js';
10
10
  import 'core-js/modules/web.dom-collections.for-each.js';
11
- import 'core-js/modules/es.array.filter.js';
12
- import 'core-js/modules/es.object.values.js';
13
11
  import 'core-js/modules/es.array.includes.js';
14
12
  import 'core-js/modules/es.string.includes.js';
13
+ import 'core-js/modules/es.object.to-string.js';
14
+ import 'core-js/modules/es.regexp.to-string.js';
15
+ import 'core-js/modules/es.array.filter.js';
16
+ import 'core-js/modules/es.object.values.js';
15
17
  import 'core-js/modules/es.array.map.js';
16
18
  import 'core-js/modules/es.string.ends-with.js';
17
19
  import 'core-js/modules/es.number.is-nan.js';
@@ -51,7 +53,7 @@ function createWidthsMap(ordering, columnWidths, adjustedCols) {
51
53
  return col.id === orderedColumn.columnId;
52
54
  }) : columnWidths[orderedColumn.columnId];
53
55
  newColumnWidths[orderedColumn.columnId] = {
54
- width: current && current.width !== undefined ? parseInt(current.width, 10) : undefined,
56
+ width: current !== null && current !== void 0 && current.width ? current.width.toString().includes('%') ? current.width : parseInt(current.width, 10) : undefined,
55
57
  id: orderedColumn.columnId
56
58
  };
57
59
  });
@@ -705,7 +705,8 @@ var defaultProps = function defaultProps(baseProps) {
705
705
  error: null,
706
706
  // TODO: set default in v3. Leaving null for backwards compat. to match 'id' which was
707
707
  // previously used as testId.
708
- testId: null
708
+ testId: null,
709
+ enablePercentageColumnWidth: false
709
710
  };
710
711
  };
711
712
 
@@ -715,6 +716,7 @@ var Table = function Table(props) {
715
716
  var _merge2 = merge({}, defaultProps(props), props),
716
717
  id = _merge2.id,
717
718
  columns = _merge2.columns,
719
+ enablePercentageColumnWidth = _merge2.enablePercentageColumnWidth,
718
720
  columnGroups = _merge2.columnGroups,
719
721
  data = _merge2.data,
720
722
  expandedData = _merge2.expandedData,
@@ -733,7 +735,7 @@ var Table = function Table(props) {
733
735
  testId = _merge2.testId,
734
736
  size = _merge2.size,
735
737
  zIndex = _merge2.zIndex,
736
- others = _objectWithoutProperties__default['default'](_merge2, ["id", "columns", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
738
+ others = _objectWithoutProperties__default['default'](_merge2, ["id", "columns", "enablePercentageColumnWidth", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
737
739
  // so we need to track that for the save view functionality.
738
740
 
739
741
 
@@ -1051,6 +1053,7 @@ var Table = function Table(props) {
1051
1053
  truncateCellText: useCellTextTruncate
1052
1054
  }),
1053
1055
  columns: columns,
1056
+ enablePercentageColumnWidth: enablePercentageColumnWidth,
1054
1057
  columnGroups: columnGroups,
1055
1058
  filters: view.filters,
1056
1059
  actions: _objectSpread(_objectSpread(_objectSpread({}, pick(actions.toolbar, 'onApplyFilter')), pick(actions.table, 'onSelectAll', 'onChangeSort', 'onChangeOrdering', 'onColumnSelectionConfig', 'onOverflowItemClicked', 'onFilterRowIconClick')), {}, {
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
- require('core-js/modules/es.object.keys.js');
4
3
  require('core-js/modules/es.symbol.js');
5
4
  require('core-js/modules/es.object.get-own-property-descriptor.js');
6
5
  require('core-js/modules/es.object.get-own-property-descriptors.js');
6
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
7
7
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
8
8
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
9
9
  var debounce = require('../../../node_modules/lodash-es/debounce.js');
@@ -17,8 +17,10 @@ require('core-js/modules/es.array.map.js');
17
17
  require('core-js/modules/web.dom-collections.for-each.js');
18
18
  require('core-js/modules/es.object.entries.js');
19
19
  require('core-js/modules/es.array.filter.js');
20
- require('core-js/modules/es.array.slice.js');
20
+ require('core-js/modules/es.object.keys.js');
21
+ require('core-js/modules/es.string.includes.js');
21
22
  require('core-js/modules/es.array.find.js');
23
+ require('core-js/modules/es.array.slice.js');
22
24
  require('core-js/modules/es.array.find-index.js');
23
25
  require('core-js/modules/es.function.name.js');
24
26
  var React = require('react');
@@ -46,6 +48,7 @@ var ColumnGrouping = require('./ColumnGrouping/ColumnGrouping.js');
46
48
 
47
49
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
48
50
 
51
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
49
52
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
50
53
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
51
54
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
@@ -91,6 +94,7 @@ var propTypes = {
91
94
 
92
95
  /** List of columns */
93
96
  columns: TablePropTypes.TableColumnsPropTypes.isRequired,
97
+ enablePercentageColumnWidth: PropTypes__default['default'].bool,
94
98
 
95
99
  /** Specify the properties of each column group in the table. Defaults to empty column. */
96
100
  columnGroups: TablePropTypes.TableColumnGroupPropType,
@@ -175,6 +179,7 @@ var defaultProps = {
175
179
  closeMenuText: 'Close menu',
176
180
  i18n: _objectSpread({}, TablePropTypes.defaultI18NPropTypes),
177
181
  hasFastFilter: true,
182
+ enablePercentageColumnWidth: false,
178
183
  testId: '',
179
184
  showExpanderColumn: false,
180
185
  size: undefined,
@@ -247,6 +252,7 @@ var TableHead = function TableHead(_ref) {
247
252
  hasFastFilter = _ref.hasFastFilter,
248
253
  showExpanderColumn = _ref.showExpanderColumn,
249
254
  size = _ref.size,
255
+ enablePercentageColumnWidth = _ref.enablePercentageColumnWidth,
250
256
  filterRowIcon = _ref.filterRowIcon,
251
257
  filterRowIconDescription = _ref.filterRowIconDescription;
252
258
  var filterBarActive = activeBar === 'filter';
@@ -259,6 +265,11 @@ var TableHead = function TableHead(_ref) {
259
265
  currentColumnWidths = _useState2[0],
260
266
  setCurrentColumnWidths = _useState2[1];
261
267
 
268
+ var _useState3 = React.useState(enablePercentageColumnWidth),
269
+ _useState4 = _slicedToArray__default['default'](_useState3, 2),
270
+ percentageMode = _useState4[0],
271
+ setPercentageMode = _useState4[1];
272
+
262
273
  if (isEmpty(currentColumnWidths)) {
263
274
  columns.forEach(function (col) {
264
275
  initialColumnWidths[col.id] = col.width;
@@ -302,8 +313,28 @@ var TableHead = function TableHead(_ref) {
302
313
  };
303
314
 
304
315
  var onManualColumnResize = function onManualColumnResize(modifiedColumnWidths) {
305
- var newColumnWidths = columnWidthUtilityFunctions.createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
306
- updateColumnWidths(newColumnWidths);
316
+ if (percentageMode) {
317
+ var modifiedColumns = _toConsumableArray__default['default'](columns);
318
+
319
+ Object.keys(modifiedColumns).forEach(function (key) {
320
+ if (modifiedColumns[key].hasOwnProperty('width')) {
321
+ delete modifiedColumns[key].width;
322
+ }
323
+ }); // while Resizing setting all column width to default DEFAULT_COLUMN_WIDTH 150px
324
+
325
+ var columnPropInlcudingWidths = columnWidthUtilityFunctions.addMissingColumnWidths({
326
+ ordering: ordering,
327
+ columns: modifiedColumns,
328
+ currentColumnWidths: {}
329
+ });
330
+ var newColumnWidths = columnWidthUtilityFunctions.createNewWidthsMap(ordering, columnPropInlcudingWidths);
331
+ setCurrentColumnWidths(newColumnWidths);
332
+ setPercentageMode(false);
333
+ } else {
334
+ var _newColumnWidths = columnWidthUtilityFunctions.createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
335
+
336
+ updateColumnWidths(_newColumnWidths);
337
+ }
307
338
  };
308
339
 
309
340
  var onColumnToggle = function onColumnToggle(columnId, newOrdering) {
@@ -320,14 +351,14 @@ var TableHead = function TableHead(_ref) {
320
351
  updateColumnWidths(newColumnWidths);
321
352
  }
322
353
  } else {
323
- var _newColumnWidths = columnWidthUtilityFunctions.calculateWidthsOnToggle({
354
+ var _newColumnWidths2 = columnWidthUtilityFunctions.calculateWidthsOnToggle({
324
355
  currentColumnWidths: currentColumnWidths,
325
356
  newOrdering: newOrdering,
326
357
  columnId: columnId,
327
358
  columns: columns
328
359
  });
329
360
 
330
- updateColumnWidths(_newColumnWidths);
361
+ updateColumnWidths(_newColumnWidths2);
331
362
  }
332
363
  }
333
364
 
@@ -380,7 +411,13 @@ var TableHead = function TableHead(_ref) {
380
411
  // if the widths of the column prop are externally updated or if columns are added/removed.
381
412
  var externallyModified = !isEqual(columns, previousColumns) || !isEqual(ordering, previousOrdering);
382
413
 
383
- if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified) {
414
+ if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified && !percentageMode) {
415
+ /* eslint-disable no-param-reassign */
416
+ Object.keys(columns).forEach(function (key) {
417
+ if (columns[key].width && columns[key].width.includes('%')) {
418
+ delete columns[key].width;
419
+ }
420
+ });
384
421
  columnWidthUtilityFunctions.checkColumnWidthFormat(columns); // PRESERVE WIDTHS
385
422
  // Preserve column when possible widths when columns are externally modified
386
423
 
@@ -424,7 +461,53 @@ var TableHead = function TableHead(_ref) {
424
461
  // since it would be directly overridden by the column props. This effect can be removed
425
462
  // with issue https://github.com/IBM/carbon-addons-iot-react/issues/1224
426
463
  // eslint-disable-next-line react-hooks/exhaustive-deps
427
- [hasResize, columns, ordering, previousColumns]);
464
+ [hasResize, columns, ordering, previousColumns, percentageMode]);
465
+ React.useEffect(function () {
466
+ var tableWidth;
467
+ var columnWidth;
468
+ var filteredColumns = columns.filter(function (colOrder) {
469
+ var hiddenCol = ordering.find(function (col) {
470
+ return col.columnId === colOrder.id;
471
+ });
472
+ return !hiddenCol || !hiddenCol.isHidden;
473
+ });
474
+ var hasOverflowMenu = filteredColumns.some(function (column) {
475
+ return column.overflowMenuItems && column.overflowMenuItems.length > 0;
476
+ });
477
+ var totalColumns = filteredColumns.length;
478
+
479
+ if (enablePercentageColumnWidth && filteredColumns.length && percentageMode && !hasOverflowMenu) {
480
+ if (hasRowSelection === 'multi' && !(hasRowExpansion || hasRowNesting)) {
481
+ tableWidth = "calc(100% - 54px)";
482
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
483
+ } else if ((hasRowExpansion || hasRowNesting) && !(hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
484
+ tableWidth = "calc(100% - 40px)";
485
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
486
+ } else if ((hasRowExpansion || hasRowNesting) && (hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
487
+ tableWidth = "calc(100% - 94px)";
488
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
489
+ } else {
490
+ columnWidth = "".concat(parseInt(100 / filteredColumns.length, 10), "%");
491
+ }
492
+
493
+ var updatedColumns = filteredColumns.map(function (col) {
494
+ var updatedCol = _objectSpread({}, col);
495
+
496
+ updatedCol.width = columnWidth;
497
+ return updatedCol;
498
+ });
499
+ var columnPropIncludingWidths = columnWidthUtilityFunctions.addMissingColumnWidths({
500
+ ordering: ordering,
501
+ columns: updatedColumns,
502
+ currentColumnWidths: currentColumnWidths
503
+ });
504
+ var newColumnWidths = columnWidthUtilityFunctions.createNewWidthsMap(ordering, columnPropIncludingWidths);
505
+
506
+ if (!isEqual(currentColumnWidths, newColumnWidths)) {
507
+ setCurrentColumnWidths(newColumnWidths);
508
+ }
509
+ }
510
+ }, [columns, ordering, hasRowExpansion, hasRowNesting, hasRowSelection, useRadioButtonSingleSelect, currentColumnWidths, enablePercentageColumnWidth, percentageMode]);
428
511
  var visibleColumns = ordering.filter(function (col) {
429
512
  return !col.isHidden;
430
513
  });
@@ -893,6 +976,17 @@ TableHead.__docgenInfo = {
893
976
  "required": false,
894
977
  "description": "should we filter on each keypress"
895
978
  },
979
+ "enablePercentageColumnWidth": {
980
+ "defaultValue": {
981
+ "value": "false",
982
+ "computed": false
983
+ },
984
+ "type": {
985
+ "name": "bool"
986
+ },
987
+ "required": false,
988
+ "description": ""
989
+ },
896
990
  "testId": {
897
991
  "defaultValue": {
898
992
  "value": "''",
@@ -12,10 +12,12 @@ var cloneDeep = require('../../../node_modules/lodash-es/cloneDeep.js');
12
12
  require('core-js/modules/es.array.find.js');
13
13
  require('core-js/modules/es.array.reduce.js');
14
14
  require('core-js/modules/web.dom-collections.for-each.js');
15
- require('core-js/modules/es.array.filter.js');
16
- require('core-js/modules/es.object.values.js');
17
15
  require('core-js/modules/es.array.includes.js');
18
16
  require('core-js/modules/es.string.includes.js');
17
+ require('core-js/modules/es.object.to-string.js');
18
+ require('core-js/modules/es.regexp.to-string.js');
19
+ require('core-js/modules/es.array.filter.js');
20
+ require('core-js/modules/es.object.values.js');
19
21
  require('core-js/modules/es.array.map.js');
20
22
  require('core-js/modules/es.string.ends-with.js');
21
23
  require('core-js/modules/es.number.is-nan.js');
@@ -61,7 +63,7 @@ function createWidthsMap(ordering, columnWidths, adjustedCols) {
61
63
  return col.id === orderedColumn.columnId;
62
64
  }) : columnWidths[orderedColumn.columnId];
63
65
  newColumnWidths[orderedColumn.columnId] = {
64
- width: current && current.width !== undefined ? parseInt(current.width, 10) : undefined,
66
+ width: current !== null && current !== void 0 && current.width ? current.width.toString().includes('%') ? current.width : parseInt(current.width, 10) : undefined,
65
67
  id: orderedColumn.columnId
66
68
  };
67
69
  });
package/package.json CHANGED
@@ -336,11 +336,11 @@
336
336
  "whatwg-fetch": "^3.0.0"
337
337
  },
338
338
  "sideEffects": false,
339
- "version": "2.154.0-next.2",
339
+ "version": "2.154.0-next.3",
340
340
  "resolutions": {
341
341
  "chokidar": "3.3.1",
342
342
  "react-grid-layout": "1.2.2",
343
343
  "got": "11.8.5"
344
344
  },
345
- "gitHead": "956af8cbb5c4e33cfafe0e44cf7e245825c74ac5"
345
+ "gitHead": "11d3d2c6ea05a1355e9a345ce1dd08343f5b993d"
346
346
  }
@@ -35824,7 +35824,7 @@
35824
35824
  return col.id === orderedColumn.columnId;
35825
35825
  }) : columnWidths[orderedColumn.columnId];
35826
35826
  newColumnWidths[orderedColumn.columnId] = {
35827
- width: current && current.width !== undefined ? parseInt(current.width, 10) : undefined,
35827
+ width: current !== null && current !== void 0 && current.width ? current.width.toString().includes('%') ? current.width : parseInt(current.width, 10) : undefined,
35828
35828
  id: orderedColumn.columnId
35829
35829
  };
35830
35830
  });
@@ -36809,6 +36809,7 @@
36809
36809
 
36810
36810
  /** List of columns */
36811
36811
  columns: TableColumnsPropTypes.isRequired,
36812
+ enablePercentageColumnWidth: PropTypes__default['default'].bool,
36812
36813
 
36813
36814
  /** Specify the properties of each column group in the table. Defaults to empty column. */
36814
36815
  columnGroups: TableColumnGroupPropType,
@@ -36893,6 +36894,7 @@
36893
36894
  closeMenuText: 'Close menu',
36894
36895
  i18n: _objectSpread$26({}, defaultI18NPropTypes),
36895
36896
  hasFastFilter: true,
36897
+ enablePercentageColumnWidth: false,
36896
36898
  testId: '',
36897
36899
  showExpanderColumn: false,
36898
36900
  size: undefined,
@@ -36965,6 +36967,7 @@
36965
36967
  hasFastFilter = _ref.hasFastFilter,
36966
36968
  showExpanderColumn = _ref.showExpanderColumn,
36967
36969
  size = _ref.size,
36970
+ enablePercentageColumnWidth = _ref.enablePercentageColumnWidth,
36968
36971
  filterRowIcon = _ref.filterRowIcon,
36969
36972
  filterRowIconDescription = _ref.filterRowIconDescription;
36970
36973
  var filterBarActive = activeBar === 'filter';
@@ -36977,6 +36980,11 @@
36977
36980
  currentColumnWidths = _useState2[0],
36978
36981
  setCurrentColumnWidths = _useState2[1];
36979
36982
 
36983
+ var _useState3 = React$1.useState(enablePercentageColumnWidth),
36984
+ _useState4 = slicedToArray$2(_useState3, 2),
36985
+ percentageMode = _useState4[0],
36986
+ setPercentageMode = _useState4[1];
36987
+
36980
36988
  if (isEmpty(currentColumnWidths)) {
36981
36989
  columns.forEach(function (col) {
36982
36990
  initialColumnWidths[col.id] = col.width;
@@ -37020,8 +37028,28 @@
37020
37028
  };
37021
37029
 
37022
37030
  var onManualColumnResize = function onManualColumnResize(modifiedColumnWidths) {
37023
- var newColumnWidths = createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
37024
- updateColumnWidths(newColumnWidths);
37031
+ if (percentageMode) {
37032
+ var modifiedColumns = toConsumableArray(columns);
37033
+
37034
+ Object.keys(modifiedColumns).forEach(function (key) {
37035
+ if (modifiedColumns[key].hasOwnProperty('width')) {
37036
+ delete modifiedColumns[key].width;
37037
+ }
37038
+ }); // while Resizing setting all column width to default DEFAULT_COLUMN_WIDTH 150px
37039
+
37040
+ var columnPropInlcudingWidths = addMissingColumnWidths({
37041
+ ordering: ordering,
37042
+ columns: modifiedColumns,
37043
+ currentColumnWidths: {}
37044
+ });
37045
+ var newColumnWidths = createNewWidthsMap(ordering, columnPropInlcudingWidths);
37046
+ setCurrentColumnWidths(newColumnWidths);
37047
+ setPercentageMode(false);
37048
+ } else {
37049
+ var _newColumnWidths = createNewWidthsMap(ordering, currentColumnWidths, modifiedColumnWidths);
37050
+
37051
+ updateColumnWidths(_newColumnWidths);
37052
+ }
37025
37053
  };
37026
37054
 
37027
37055
  var onColumnToggle = function onColumnToggle(columnId, newOrdering) {
@@ -37038,14 +37066,14 @@
37038
37066
  updateColumnWidths(newColumnWidths);
37039
37067
  }
37040
37068
  } else {
37041
- var _newColumnWidths = calculateWidthsOnToggle({
37069
+ var _newColumnWidths2 = calculateWidthsOnToggle({
37042
37070
  currentColumnWidths: currentColumnWidths,
37043
37071
  newOrdering: newOrdering,
37044
37072
  columnId: columnId,
37045
37073
  columns: columns
37046
37074
  });
37047
37075
 
37048
- updateColumnWidths(_newColumnWidths);
37076
+ updateColumnWidths(_newColumnWidths2);
37049
37077
  }
37050
37078
  }
37051
37079
 
@@ -37098,7 +37126,13 @@
37098
37126
  // if the widths of the column prop are externally updated or if columns are added/removed.
37099
37127
  var externallyModified = !isEqual$1(columns, previousColumns) || !isEqual$1(ordering, previousOrdering);
37100
37128
 
37101
- if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified) {
37129
+ if (hasResize && columns.length && !isEmpty(currentColumnWidths) && externallyModified && !percentageMode) {
37130
+ /* eslint-disable no-param-reassign */
37131
+ Object.keys(columns).forEach(function (key) {
37132
+ if (columns[key].width && columns[key].width.includes('%')) {
37133
+ delete columns[key].width;
37134
+ }
37135
+ });
37102
37136
  checkColumnWidthFormat(columns); // PRESERVE WIDTHS
37103
37137
  // Preserve column when possible widths when columns are externally modified
37104
37138
 
@@ -37142,7 +37176,53 @@
37142
37176
  // since it would be directly overridden by the column props. This effect can be removed
37143
37177
  // with issue https://github.com/IBM/carbon-addons-iot-react/issues/1224
37144
37178
  // eslint-disable-next-line react-hooks/exhaustive-deps
37145
- [hasResize, columns, ordering, previousColumns]);
37179
+ [hasResize, columns, ordering, previousColumns, percentageMode]);
37180
+ React$1.useEffect(function () {
37181
+ var tableWidth;
37182
+ var columnWidth;
37183
+ var filteredColumns = columns.filter(function (colOrder) {
37184
+ var hiddenCol = ordering.find(function (col) {
37185
+ return col.columnId === colOrder.id;
37186
+ });
37187
+ return !hiddenCol || !hiddenCol.isHidden;
37188
+ });
37189
+ var hasOverflowMenu = filteredColumns.some(function (column) {
37190
+ return column.overflowMenuItems && column.overflowMenuItems.length > 0;
37191
+ });
37192
+ var totalColumns = filteredColumns.length;
37193
+
37194
+ if (enablePercentageColumnWidth && filteredColumns.length && percentageMode && !hasOverflowMenu) {
37195
+ if (hasRowSelection === 'multi' && !(hasRowExpansion || hasRowNesting)) {
37196
+ tableWidth = "calc(100% - 54px)";
37197
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
37198
+ } else if ((hasRowExpansion || hasRowNesting) && !(hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
37199
+ tableWidth = "calc(100% - 40px)";
37200
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
37201
+ } else if ((hasRowExpansion || hasRowNesting) && (hasRowSelection === 'multi' || useRadioButtonSingleSelect && hasRowSelection === 'single')) {
37202
+ tableWidth = "calc(100% - 94px)";
37203
+ columnWidth = "calc(".concat(tableWidth, " / ").concat(totalColumns, ")");
37204
+ } else {
37205
+ columnWidth = "".concat(parseInt(100 / filteredColumns.length, 10), "%");
37206
+ }
37207
+
37208
+ var updatedColumns = filteredColumns.map(function (col) {
37209
+ var updatedCol = _objectSpread$26({}, col);
37210
+
37211
+ updatedCol.width = columnWidth;
37212
+ return updatedCol;
37213
+ });
37214
+ var columnPropIncludingWidths = addMissingColumnWidths({
37215
+ ordering: ordering,
37216
+ columns: updatedColumns,
37217
+ currentColumnWidths: currentColumnWidths
37218
+ });
37219
+ var newColumnWidths = createNewWidthsMap(ordering, columnPropIncludingWidths);
37220
+
37221
+ if (!isEqual$1(currentColumnWidths, newColumnWidths)) {
37222
+ setCurrentColumnWidths(newColumnWidths);
37223
+ }
37224
+ }
37225
+ }, [columns, ordering, hasRowExpansion, hasRowNesting, hasRowSelection, useRadioButtonSingleSelect, currentColumnWidths, enablePercentageColumnWidth, percentageMode]);
37146
37226
  var visibleColumns = ordering.filter(function (col) {
37147
37227
  return !col.isHidden;
37148
37228
  });
@@ -37611,6 +37691,17 @@
37611
37691
  "required": false,
37612
37692
  "description": "should we filter on each keypress"
37613
37693
  },
37694
+ "enablePercentageColumnWidth": {
37695
+ "defaultValue": {
37696
+ "value": "false",
37697
+ "computed": false
37698
+ },
37699
+ "type": {
37700
+ "name": "bool"
37701
+ },
37702
+ "required": false,
37703
+ "description": ""
37704
+ },
37614
37705
  "testId": {
37615
37706
  "defaultValue": {
37616
37707
  "value": "''",
@@ -48573,7 +48664,8 @@
48573
48664
  error: null,
48574
48665
  // TODO: set default in v3. Leaving null for backwards compat. to match 'id' which was
48575
48666
  // previously used as testId.
48576
- testId: null
48667
+ testId: null,
48668
+ enablePercentageColumnWidth: false
48577
48669
  };
48578
48670
  };
48579
48671
 
@@ -48583,6 +48675,7 @@
48583
48675
  var _merge2 = merge$1({}, defaultProps$29(props), props),
48584
48676
  id = _merge2.id,
48585
48677
  columns = _merge2.columns,
48678
+ enablePercentageColumnWidth = _merge2.enablePercentageColumnWidth,
48586
48679
  columnGroups = _merge2.columnGroups,
48587
48680
  data = _merge2.data,
48588
48681
  expandedData = _merge2.expandedData,
@@ -48601,7 +48694,7 @@
48601
48694
  testId = _merge2.testId,
48602
48695
  size = _merge2.size,
48603
48696
  zIndex = _merge2.zIndex,
48604
- others = objectWithoutProperties$1(_merge2, ["id", "columns", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
48697
+ others = objectWithoutProperties$1(_merge2, ["id", "columns", "enablePercentageColumnWidth", "columnGroups", "data", "expandedData", "locale", "view", "actions", "actions", "options", "lightweight", "className", "style", "i18n", "secondaryTitle", "tooltip", "error", "testId", "size", "zIndex"]); // There is no way to access the current search value in the Table
48605
48698
  // so we need to track that for the save view functionality.
48606
48699
 
48607
48700
 
@@ -48919,6 +49012,7 @@
48919
49012
  truncateCellText: useCellTextTruncate
48920
49013
  }),
48921
49014
  columns: columns,
49015
+ enablePercentageColumnWidth: enablePercentageColumnWidth,
48922
49016
  columnGroups: columnGroups,
48923
49017
  filters: view.filters,
48924
49018
  actions: _objectSpread$1Y(_objectSpread$1Y(_objectSpread$1Y({}, pick(actions.toolbar, 'onApplyFilter')), pick(actions.table, 'onSelectAll', 'onChangeSort', 'onChangeOrdering', 'onColumnSelectionConfig', 'onOverflowItemClicked', 'onFilterRowIconClick')), {}, {