@carbon/ibm-products 1.25.1 → 1.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. package/css/index-full-carbon.css +562 -88
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css +942 -23
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +3 -3
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +561 -87
  10. package/css/index-without-carbon.css.map +1 -1
  11. package/css/index-without-carbon.min.css +3 -3
  12. package/css/index-without-carbon.min.css.map +1 -1
  13. package/css/index.css +562 -88
  14. package/css/index.css.map +1 -1
  15. package/css/index.min.css +3 -3
  16. package/css/index.min.css.map +1 -1
  17. package/es/components/AddSelect/AddSelect.js +0 -3
  18. package/es/components/AddSelect/AddSelectBody.js +20 -3
  19. package/es/components/AddSelect/AddSelectBreadcrumbs.js +11 -3
  20. package/es/components/AddSelect/AddSelectColumn.js +4 -3
  21. package/es/components/AddSelect/AddSelectFilter.js +4 -3
  22. package/es/components/AddSelect/AddSelectList.js +40 -14
  23. package/es/components/Card/Card.js +16 -6
  24. package/es/components/Card/CardFooter.js +3 -1
  25. package/es/components/Card/CardHeader.js +20 -1
  26. package/es/components/DataSpreadsheet/DataSpreadsheet.js +62 -11
  27. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +7 -0
  28. package/es/components/DataSpreadsheet/utils/handleCellDeletion.js +31 -0
  29. package/es/components/DataSpreadsheet/utils/handleMultipleKeys.js +1 -1
  30. package/es/components/Datagrid/Datagrid/Datagrid.js +10 -38
  31. package/es/components/Datagrid/Datagrid/DatagridContent.js +106 -0
  32. package/es/components/Datagrid/Datagrid/DatagridSelectAll.js +10 -3
  33. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +139 -11
  34. package/es/components/Datagrid/Datagrid/DraggableElement.js +5 -1
  35. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +5 -40
  36. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +35 -10
  37. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +61 -24
  38. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  39. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +63 -0
  40. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +1 -0
  41. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +459 -0
  42. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +1 -0
  43. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +112 -0
  44. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +27 -0
  45. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +1 -0
  46. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +31 -0
  47. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +19 -0
  48. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +197 -0
  49. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  50. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  51. package/es/components/Datagrid/index.js +3 -1
  52. package/es/components/Datagrid/useActionsColumn.js +31 -6
  53. package/es/components/Datagrid/useColumnOrder.js +8 -0
  54. package/es/components/Datagrid/useCustomizeColumns.js +5 -0
  55. package/es/components/Datagrid/useDefaultStringRenderer.js +4 -1
  56. package/es/components/Datagrid/useDisableSelectRows.js +6 -2
  57. package/es/components/Datagrid/useInlineEdit.js +71 -0
  58. package/es/components/Datagrid/useRowSize.js +17 -6
  59. package/es/components/Datagrid/useSelectRows.js +14 -4
  60. package/es/components/Datagrid/useStickyColumn.js +14 -0
  61. package/es/components/Datagrid/utils/getInlineEditColumns.js +121 -0
  62. package/es/components/Datagrid/utils/makeData.js +18 -2
  63. package/es/components/ImportModal/ImportModal.js +2 -2
  64. package/es/components/InlineEdit/InlineEdit.js +4 -2
  65. package/es/components/ProductiveCard/ProductiveCard.js +5 -0
  66. package/es/components/WebTerminal/WebTerminal.js +1 -1
  67. package/es/components/WebTerminal/WebTerminalContentWrapper.js +1 -1
  68. package/es/components/WebTerminal/hooks/index.js +6 -0
  69. package/es/components/WebTerminal/index.js +6 -0
  70. package/es/components/WebTerminal/preview-components/Navigation.js +6 -0
  71. package/es/components/WebTerminal/preview-components/documentationLinks.js +6 -0
  72. package/es/components/WebTerminal/preview-components/index.js +7 -0
  73. package/es/components/index.js +1 -1
  74. package/es/global/js/hooks/useClickOutside.js +1 -1
  75. package/es/global/js/package-settings.js +3 -3
  76. package/es/global/js/utils/rangeWithCallback.js +13 -0
  77. package/es/global/js/utils/uuidv4.spec.js +4 -0
  78. package/lib/components/AddSelect/AddSelect.js +0 -4
  79. package/lib/components/AddSelect/AddSelectBody.js +20 -3
  80. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +14 -3
  81. package/lib/components/AddSelect/AddSelectColumn.js +3 -2
  82. package/lib/components/AddSelect/AddSelectFilter.js +3 -2
  83. package/lib/components/AddSelect/AddSelectList.js +39 -13
  84. package/lib/components/Card/Card.js +16 -6
  85. package/lib/components/Card/CardFooter.js +3 -1
  86. package/lib/components/Card/CardHeader.js +21 -1
  87. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +62 -10
  88. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +7 -0
  89. package/lib/components/DataSpreadsheet/utils/handleCellDeletion.js +42 -0
  90. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +1 -1
  91. package/lib/components/Datagrid/Datagrid/Datagrid.js +12 -45
  92. package/lib/components/Datagrid/Datagrid/DatagridContent.js +138 -0
  93. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +12 -3
  94. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +148 -9
  95. package/lib/components/Datagrid/Datagrid/DraggableElement.js +5 -1
  96. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +12 -41
  97. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +47 -25
  98. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +59 -23
  99. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  100. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +79 -0
  101. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +13 -0
  102. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +483 -0
  103. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +13 -0
  104. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +129 -0
  105. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +36 -0
  106. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +19 -0
  107. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +42 -0
  108. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +28 -0
  109. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +204 -0
  110. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  111. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  112. package/lib/components/Datagrid/index.js +17 -1
  113. package/lib/components/Datagrid/useActionsColumn.js +31 -6
  114. package/lib/components/Datagrid/useColumnOrder.js +17 -0
  115. package/lib/components/Datagrid/useCustomizeColumns.js +5 -0
  116. package/lib/components/Datagrid/useDefaultStringRenderer.js +5 -1
  117. package/lib/components/Datagrid/useDisableSelectRows.js +6 -2
  118. package/lib/components/Datagrid/useInlineEdit.js +85 -0
  119. package/lib/components/Datagrid/useRowSize.js +18 -13
  120. package/lib/components/Datagrid/useSelectRows.js +13 -3
  121. package/lib/components/Datagrid/useStickyColumn.js +14 -0
  122. package/lib/components/Datagrid/utils/getInlineEditColumns.js +133 -0
  123. package/lib/components/Datagrid/utils/makeData.js +18 -2
  124. package/lib/components/ImportModal/ImportModal.js +2 -2
  125. package/lib/components/InlineEdit/InlineEdit.js +4 -2
  126. package/lib/components/ProductiveCard/ProductiveCard.js +5 -0
  127. package/lib/components/WebTerminal/hooks/index.js +6 -0
  128. package/lib/components/WebTerminal/preview-components/Navigation.js +6 -0
  129. package/lib/components/WebTerminal/preview-components/documentationLinks.js +6 -0
  130. package/lib/components/index.js +12 -0
  131. package/lib/global/js/hooks/useClickOutside.js +1 -1
  132. package/lib/global/js/package-settings.js +3 -3
  133. package/lib/global/js/utils/rangeWithCallback.js +22 -0
  134. package/lib/global/js/utils/uuidv4.spec.js +4 -0
  135. package/package.json +13 -13
  136. package/scss/components/AddSelect/_add-select.scss +126 -28
  137. package/scss/components/Card/_card.scss +1 -0
  138. package/scss/components/Cascade/_cascade.scss +1 -1
  139. package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
  140. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +18 -1
  141. package/scss/components/Datagrid/_datagrid.scss +5 -0
  142. package/scss/components/Datagrid/_storybook-styles.scss +1 -1
  143. package/scss/components/Datagrid/styles/_datagrid.scss +81 -12
  144. package/scss/components/Datagrid/styles/_draggableElement.scss +26 -9
  145. package/scss/components/Datagrid/styles/_index.scss +1 -0
  146. package/scss/components/Datagrid/styles/_useInlineEdit.scss +211 -0
  147. package/scss/components/Datagrid/styles/_useStickyColumn.scss +24 -2
  148. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsModal.scss +44 -6
  149. package/scss/components/InlineEdit/_inline-edit.scss +1 -1
  150. package/scss/components/NotificationsPanel/_notifications-panel.scss +5 -6
  151. package/scss/components/ProductiveCard/_productive-card.scss +39 -0
  152. package/scss/components/RemoveModal/_remove-modal.scss +0 -4
  153. package/scss/components/SidePanel/_side-panel.scss +4 -6
  154. package/scss/components/WebTerminal/_index.scss +7 -0
  155. package/scss/components/WebTerminal/_storybook-styles.scss +7 -0
  156. package/scss/components/WebTerminal/_web-terminal.scss +13 -0
  157. package/scss/components/_index-released-only.scss +1 -0
@@ -0,0 +1,106 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import React, { useContext, useRef } from 'react';
4
+ import cx from 'classnames';
5
+ import PropTypes from 'prop-types';
6
+ import { DataTable } from 'carbon-components-react';
7
+ import DatagridHead from './DatagridHead';
8
+ import DatagridBody from './DatagridBody';
9
+ import DatagridToolbar from './DatagridToolbar';
10
+ import { handleGridKeyPress } from './addons/InlineEdit/handleGridKeyPress';
11
+ import { pkg } from '../../../settings';
12
+ import { InlineEditContext } from './addons/InlineEdit/InlineEditContext';
13
+ import { handleGridFocus } from './addons/InlineEdit/handleGridFocus';
14
+ import { useClickOutside } from '../../../global/js/hooks';
15
+ var TableContainer = DataTable.TableContainer,
16
+ Table = DataTable.Table;
17
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
18
+ export var DatagridContent = function DatagridContent(_ref) {
19
+ var _getTableProps;
20
+
21
+ var datagridState = _ref.datagridState;
22
+
23
+ var _useContext = useContext(InlineEditContext),
24
+ state = _useContext.state,
25
+ dispatch = _useContext.dispatch;
26
+
27
+ var activeCellId = state.activeCellId;
28
+ var _datagridState$getTab = datagridState.getTableProps,
29
+ getTableProps = _datagridState$getTab === void 0 ? function () {} : _datagridState$getTab,
30
+ withVirtualScroll = datagridState.withVirtualScroll,
31
+ DatagridPagination = datagridState.DatagridPagination,
32
+ isFetching = datagridState.isFetching,
33
+ CustomizeColumnsModal = datagridState.CustomizeColumnsModal,
34
+ leftPanel = datagridState.leftPanel,
35
+ fullHeightDatagrid = datagridState.fullHeightDatagrid,
36
+ _datagridState$vertic = datagridState.verticalAlign,
37
+ verticalAlign = _datagridState$vertic === void 0 ? 'center' : _datagridState$vertic,
38
+ variableRowHeight = datagridState.variableRowHeight,
39
+ gridTitle = datagridState.gridTitle,
40
+ gridDescription = datagridState.gridDescription,
41
+ useDenseHeader = datagridState.useDenseHeader,
42
+ withInlineEdit = datagridState.withInlineEdit;
43
+ var rows = DatagridPagination && datagridState.page || datagridState.rows;
44
+ var gridActive = state.gridActive;
45
+ var gridAreaRef = useRef();
46
+ useClickOutside(gridAreaRef, function (target) {
47
+ if (!withInlineEdit) {
48
+ return;
49
+ } // We return from here if we find a parent element with the selector below
50
+ // because that element was initially part of the grid area but was removed
51
+ // and swapped out with an input, i.e. text, number, selection, or date picker
52
+
53
+
54
+ if (target.closest(".".concat(blockClass, "__inline-edit-button")) || target.closest(".".concat(blockClass, "__inline-edit--select"))) {
55
+ return;
56
+ }
57
+
58
+ dispatch({
59
+ type: 'REMOVE_GRID_ACTIVE_FOCUS',
60
+ payload: activeCellId
61
+ });
62
+ });
63
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TableContainer, {
64
+ className: cx("".concat(blockClass, "__grid-container"), withVirtualScroll || fullHeightDatagrid ? "".concat(blockClass, "__full-height") : '', DatagridPagination ? "".concat(blockClass, "__with-pagination") : '', useDenseHeader ? "".concat(blockClass, "__dense-header") : ''),
65
+ title: gridTitle,
66
+ description: gridDescription
67
+ }, /*#__PURE__*/React.createElement(DatagridToolbar, datagridState), /*#__PURE__*/React.createElement("div", {
68
+ className: "".concat(blockClass, "__table-container"),
69
+ ref: gridAreaRef
70
+ }, leftPanel && leftPanel.isOpen && /*#__PURE__*/React.createElement("div", {
71
+ className: "".concat(blockClass, "__datagridLeftPanel")
72
+ }, leftPanel.panelContent), /*#__PURE__*/React.createElement(Table, _extends({}, getTableProps(), {
73
+ className: cx(withVirtualScroll ? '' : "".concat(blockClass, "__table-simple"), "".concat(blockClass, "__vertical-align-").concat(verticalAlign), _defineProperty({}, "".concat(blockClass, "__variable-row-height"), variableRowHeight), _defineProperty({}, "".concat(blockClass, "__table-with-inline-edit"), withInlineEdit), _defineProperty({}, "".concat(blockClass, "__table-grid-active"), gridActive), (_getTableProps = getTableProps()) === null || _getTableProps === void 0 ? void 0 : _getTableProps.className),
74
+ role: withInlineEdit && 'grid',
75
+ tabIndex: withInlineEdit && 0,
76
+ onKeyDown: withInlineEdit ? function (event) {
77
+ return handleGridKeyPress(event, dispatch, state, datagridState);
78
+ } : null,
79
+ onFocus: withInlineEdit ? function () {
80
+ return handleGridFocus(state, dispatch);
81
+ } : null
82
+ }), /*#__PURE__*/React.createElement(DatagridHead, datagridState), /*#__PURE__*/React.createElement(DatagridBody, _extends({}, datagridState, {
83
+ rows: rows
84
+ }))))), (rows === null || rows === void 0 ? void 0 : rows.length) > 0 && !isFetching && DatagridPagination && DatagridPagination(datagridState), CustomizeColumnsModal && /*#__PURE__*/React.createElement(CustomizeColumnsModal, {
85
+ instance: datagridState
86
+ }));
87
+ };
88
+ DatagridContent.propTypes = {
89
+ datagridState: PropTypes.shape({
90
+ getTableProps: PropTypes.func,
91
+ withVirtualScroll: PropTypes.bool,
92
+ DatagridPagination: PropTypes.element,
93
+ CustomizeColumnsModal: PropTypes.element,
94
+ isFetching: PropTypes.bool,
95
+ leftPanel: PropTypes.object,
96
+ fullHeightDatagrid: PropTypes.bool,
97
+ variableRowHeight: PropTypes.bool,
98
+ useDenseHeader: PropTypes.bool,
99
+ withInlineEdit: PropTypes.bool,
100
+ verticalAlign: PropTypes.string,
101
+ gridTitle: PropTypes.node,
102
+ gridDescription: PropTypes.node,
103
+ page: PropTypes.arrayOf(PropTypes.object),
104
+ rows: PropTypes.arrayOf(PropTypes.object)
105
+ })
106
+ };
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
4
  var _excluded = ["onChange"];
4
5
 
5
6
  /*
@@ -12,21 +13,27 @@ var _excluded = ["onChange"];
12
13
  // @flow
13
14
  import React from 'react';
14
15
  import { DataTable } from 'carbon-components-react';
16
+ import cx from 'classnames';
15
17
  import { pkg } from '../../../settings';
16
18
  var blockClass = "".concat(pkg.prefix, "--datagrid");
17
19
 
18
20
  var SelectAll = function SelectAll(datagridState) {
21
+ var _columns$;
22
+
19
23
  var isFetching = datagridState.isFetching,
20
24
  getToggleAllRowsSelectedProps = datagridState.getToggleAllRowsSelectedProps,
21
25
  getToggleAllPageRowsSelectedProps = datagridState.getToggleAllPageRowsSelectedProps,
22
26
  tableId = datagridState.tableId,
23
27
  hideSelectAll = datagridState.hideSelectAll,
24
28
  DatagridPagination = datagridState.DatagridPagination,
25
- radio = datagridState.radio;
29
+ radio = datagridState.radio,
30
+ columns = datagridState.columns,
31
+ withStickyColumn = datagridState.withStickyColumn;
32
+ var isFirstColumnStickyLeft = ((_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.sticky) === 'left' && withStickyColumn;
26
33
 
27
34
  if (hideSelectAll || radio) {
28
35
  return /*#__PURE__*/React.createElement("div", {
29
- className: "".concat(blockClass, "__head-hidden-select-all")
36
+ className: cx("".concat(blockClass, "__head-hidden-select-all"), _defineProperty({}, "".concat(blockClass, "__select-all-sticky-left"), isFirstColumnStickyLeft))
30
37
  });
31
38
  }
32
39
 
@@ -37,7 +44,7 @@ var SelectAll = function SelectAll(datagridState) {
37
44
  selectProps = _objectWithoutProperties(_getProps, _excluded);
38
45
 
39
46
  return /*#__PURE__*/React.createElement("div", {
40
- className: "".concat(blockClass, "__head-select-all ").concat(blockClass, "__checkbox-cell")
47
+ className: cx("".concat(blockClass, "__head-select-all"), "".concat(blockClass, "__checkbox-cell"), _defineProperty({}, "".concat(blockClass, "__checkbox-cell-sticky-left"), isFirstColumnStickyLeft))
41
48
  }, /*#__PURE__*/React.createElement(TableSelectAll, _extends({}, selectProps, {
42
49
  name: "".concat(tableId, "-select-all-checkbox-name"),
43
50
  onSelect: onChange,
@@ -1,20 +1,148 @@
1
- /*
2
- * Licensed Materials - Property of IBM
3
- * 5724-Q36
4
- * (c) Copyright IBM Corp. 2020
5
- * US Government Users Restricted Rights - Use, duplication or disclosure
6
- * restricted by GSA ADP Schedule Contract with IBM Corp.
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+
4
+ /**
5
+ * Copyright IBM Corp. 2022, 2022
6
+ *
7
+ * This source code is licensed under the Apache-2.0 license found in the
8
+ * LICENSE file in the root directory of this source tree.
7
9
  */
8
- import React from 'react';
9
- import { DataTable } from 'carbon-components-react';
10
- import { pkg } from '../../../settings';
10
+ import React, { useEffect, useState } from 'react';
11
+ import { Add16, OverflowMenuVertical16 } from '@carbon/icons-react';
12
+ import { DataTable, TableBatchActions, TableBatchAction } from 'carbon-components-react';
13
+ import { useResizeDetector } from 'react-resize-detector';
14
+ import { ButtonMenu, ButtonMenuItem } from '../../ButtonMenu';
15
+ import { pkg, carbon } from '../../../settings';
16
+ import cx from 'classnames';
11
17
  var blockClass = "".concat(pkg.prefix, "--datagrid");
12
18
  var TableToolbar = DataTable.TableToolbar;
13
19
 
20
+ var DatagridBatchActionsToolbar = function DatagridBatchActionsToolbar(datagridState, width, ref) {
21
+ var _useState = useState(false),
22
+ _useState2 = _slicedToArray(_useState, 2),
23
+ displayAllInMenu = _useState2[0],
24
+ setDisplayAllInMenu = _useState2[1];
25
+
26
+ var _useState3 = useState(null),
27
+ _useState4 = _slicedToArray(_useState3, 2),
28
+ initialListWidth = _useState4[0],
29
+ setInitialListWidth = _useState4[1];
30
+
31
+ var _useState5 = useState(false),
32
+ _useState6 = _slicedToArray(_useState5, 2),
33
+ receivedInitialWidth = _useState6[0],
34
+ setReceivedInitialWidth = _useState6[1];
35
+
36
+ var selectedFlatRows = datagridState.selectedFlatRows,
37
+ toggleAllRowsSelected = datagridState.toggleAllRowsSelected,
38
+ toolbarBatchActions = datagridState.toolbarBatchActions;
39
+ var totalSelected = selectedFlatRows && selectedFlatRows.length; // Get initial width of batch actions container,
40
+ // used to measure when all items are put inside
41
+ // the ButtonMenu
42
+
43
+ useEffect(function () {
44
+ if (totalSelected === 1 && !receivedInitialWidth) {
45
+ var batchActionListWidth = ref.current.querySelector(".".concat(carbon.prefix, "--action-list")).offsetWidth;
46
+ setInitialListWidth(batchActionListWidth);
47
+ setReceivedInitialWidth(true);
48
+ }
49
+ }, [totalSelected, receivedInitialWidth, ref]);
50
+ useEffect(function () {
51
+ var summaryWidth = ref.current.querySelector(".".concat(carbon.prefix, "--batch-summary")).offsetWidth;
52
+
53
+ if (width < summaryWidth + initialListWidth + 32) {
54
+ setDisplayAllInMenu(true);
55
+ } else {
56
+ setDisplayAllInMenu(false);
57
+ }
58
+ }, [width, ref, initialListWidth]); // Render batch actions in ButtonMenu
59
+
60
+ var renderBatchActionOverflow = function renderBatchActionOverflow() {
61
+ var minWidthBeforeOverflowIcon = 380; // Do not render ButtonMenu when there are 3 or less items
62
+ // and if there is enough available space to render all the items
63
+
64
+ if ((toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.length) <= 3 && !displayAllInMenu) {
65
+ return null;
66
+ }
67
+
68
+ return /*#__PURE__*/React.createElement(ButtonMenu, {
69
+ label: width > minWidthBeforeOverflowIcon ? 'More' : null,
70
+ renderIcon: width > minWidthBeforeOverflowIcon ? Add16 : OverflowMenuVertical16,
71
+ className: cx("".concat(blockClass, "__button-menu"), _defineProperty({}, "".concat(blockClass, "__button-menu--icon-only"), width <= minWidthBeforeOverflowIcon)),
72
+ menuOptionsClass: "".concat(blockClass, "__button-menu-options"),
73
+ flipped: true
74
+ }, toolbarBatchActions && toolbarBatchActions.map(function (batchAction, index) {
75
+ if (index < 2) {
76
+ if (displayAllInMenu) {
77
+ return /*#__PURE__*/React.createElement(ButtonMenuItem, {
78
+ key: "".concat(batchAction.label, "-").concat(index),
79
+ itemText: batchAction.label,
80
+ onClick: function onClick() {
81
+ batchAction.onClick();
82
+
83
+ if (batchAction.type === 'select_all') {
84
+ toggleAllRowsSelected(true);
85
+ }
86
+ }
87
+ });
88
+ }
89
+
90
+ return null;
91
+ }
92
+
93
+ return /*#__PURE__*/React.createElement(ButtonMenuItem, {
94
+ key: "".concat(batchAction.label, "-").concat(index),
95
+ itemText: batchAction.label,
96
+ onClick: function onClick() {
97
+ batchAction.onClick();
98
+
99
+ if (batchAction.type === 'select_all') {
100
+ toggleAllRowsSelected(true);
101
+ }
102
+ }
103
+ });
104
+ }));
105
+ }; // Only display the first two batch actions, the rest are
106
+ // displayed inside of the ButtonMenu if there are more than
107
+ // 3 batch actions
108
+
109
+
110
+ return /*#__PURE__*/React.createElement(TableBatchActions, {
111
+ shouldShowBatchActions: totalSelected > 0,
112
+ totalSelected: totalSelected,
113
+ onCancel: function onCancel() {
114
+ return toggleAllRowsSelected(false);
115
+ }
116
+ }, !displayAllInMenu && toolbarBatchActions && (toolbarBatchActions === null || toolbarBatchActions === void 0 ? void 0 : toolbarBatchActions.map(function (batchAction, index) {
117
+ if (index < 2 && toolbarBatchActions.length > 3 || index < 3 && toolbarBatchActions.length === 3) {
118
+ return /*#__PURE__*/React.createElement(TableBatchAction, {
119
+ key: "".concat(batchAction.label, "-").concat(index),
120
+ renderIcon: batchAction.renderIcon,
121
+ onClick: function onClick() {
122
+ batchAction.onClick();
123
+
124
+ if (batchAction.type === 'select_all') {
125
+ toggleAllRowsSelected(true);
126
+ }
127
+ },
128
+ iconDescription: batchAction.label
129
+ }, batchAction.label);
130
+ }
131
+ })), renderBatchActionOverflow());
132
+ };
133
+
14
134
  var DatagridToolbar = function DatagridToolbar(datagridState) {
135
+ var _useResizeDetector = useResizeDetector(),
136
+ width = _useResizeDetector.width,
137
+ ref = _useResizeDetector.ref;
138
+
15
139
  var DatagridActions = datagridState.DatagridActions,
16
- DatagridBatchActions = datagridState.DatagridBatchActions;
17
- return DatagridActions || DatagridBatchActions ? /*#__PURE__*/React.createElement("div", {
140
+ DatagridBatchActions = datagridState.DatagridBatchActions,
141
+ batchActions = datagridState.batchActions;
142
+ return batchActions && DatagridActions ? /*#__PURE__*/React.createElement("div", {
143
+ ref: ref,
144
+ className: "".concat(blockClass, "__table-toolbar")
145
+ }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActionsToolbar && DatagridBatchActionsToolbar(datagridState, width, ref))) : DatagridActions ? /*#__PURE__*/React.createElement("div", {
18
146
  className: "".concat(blockClass, "__table-toolbar")
19
147
  }, /*#__PURE__*/React.createElement(TableToolbar, null, DatagridActions && DatagridActions(datagridState), DatagridBatchActions && DatagridBatchActions(datagridState))) : null;
20
148
  };
@@ -22,6 +22,8 @@ var blockClass = "".concat(pkg.prefix, "--datagrid");
22
22
  var DRAG_TYPE = "".concat(blockClass, "__shared-ui-draggable-element");
23
23
 
24
24
  var DraggableElement = function DraggableElement(_ref) {
25
+ var _cx;
26
+
25
27
  var id = _ref.id,
26
28
  index = _ref.index,
27
29
  listData = _ref.listData,
@@ -33,6 +35,7 @@ var DraggableElement = function DraggableElement(_ref) {
33
35
  onArrowKeyDown = _ref.onArrowKeyDown,
34
36
  isFocused = _ref.isFocused,
35
37
  moveElement = _ref.moveElement,
38
+ selected = _ref.selected,
36
39
  _ref$positionLabel = _ref.positionLabel,
37
40
  positionLabel = _ref$positionLabel === void 0 ? 'Current position {index} of {total}' : _ref$positionLabel,
38
41
  _ref$grabbedLabel = _ref.grabbedLabel,
@@ -119,7 +122,7 @@ var DraggableElement = function DraggableElement(_ref) {
119
122
  }, "".concat(blockClass, "__draggable-handleStyle"))
120
123
  }, /*#__PURE__*/React.createElement(Draggable16, null)), children);
121
124
  return /*#__PURE__*/React.createElement("li", {
122
- className: cx(_defineProperty({}, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty({}, "".concat(blockClass, "__wkc-draggable-handleHolder--grabbed"), isGrabbed), "".concat(blockClass, "__draggable-handleHolder")),
125
+ className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-isOver"), isOver && !disabled), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-grabbed"), isGrabbed), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder-selected"), selected), _defineProperty(_cx, "".concat(blockClass, "__draggable-handleHolder"), !selected), _cx)),
123
126
  ref: ref,
124
127
  "aria-selected": isFocused,
125
128
  role: "option",
@@ -173,6 +176,7 @@ DraggableElement.propTypes = {
173
176
  onArrowKeyDown: PropTypes.func.isRequired,
174
177
  onGrab: PropTypes.func.isRequired,
175
178
  positionLabel: PropTypes.string,
179
+ selected: PropTypes.bool,
176
180
  type: PropTypes.string.isRequired
177
181
  };
178
182
  export default DraggableElement;
@@ -1,9 +1,3 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
-
7
1
  // @flow
8
2
 
9
3
  /*
@@ -13,28 +7,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
13
7
  * US Government Users Restricted Rights - Use, duplication or disclosure
14
8
  * restricted by GSA ADP Schedule Contract with IBM Corp.
15
9
  */
16
- import { Reset16 } from '@carbon/icons-react';
17
10
  import PropTypes from 'prop-types';
18
- import { Button, Search } from 'carbon-components-react';
11
+ import { Search } from 'carbon-components-react';
19
12
  import * as React from 'react';
20
- import keyBy from 'lodash/keyBy';
21
13
  import { pkg } from '../../../../../settings';
22
- import { isColumnVisible } from './common';
23
14
  var blockClass = "".concat(pkg.prefix, "--datagrid");
24
15
 
25
16
  var Actions = function Actions(_ref) {
26
17
  var searchText = _ref.searchText,
27
- columns = _ref.columns,
28
- originalColumnDefinitions = _ref.originalColumnDefinitions,
29
- setColumnsObject = _ref.setColumnsObject,
30
18
  setSearchText = _ref.setSearchText,
31
- _ref$findColumnPlaceh = _ref.findColumnPlaceholderLabel,
32
- findColumnPlaceholderLabel = _ref$findColumnPlaceh === void 0 ? 'Find column' : _ref$findColumnPlaceh,
33
- _ref$resetToDefaultLa = _ref.resetToDefaultLabel,
34
- resetToDefaultLabel = _ref$resetToDefaultLa === void 0 ? 'Reset to default' : _ref$resetToDefaultLa;
19
+ findColumnPlaceholderLabel = _ref.findColumnPlaceholderLabel;
35
20
  return /*#__PURE__*/React.createElement("div", {
36
- className: "".concat(blockClass, "__customize-columns-modal--actions"),
37
- "test-id": "".concat(blockClass, "__customize-columns-modal--actions")
21
+ className: "".concat(blockClass, "__customize-columns-modal--actions")
38
22
  }, /*#__PURE__*/React.createElement(Search, {
39
23
  placeholder: findColumnPlaceholderLabel,
40
24
  value: searchText,
@@ -43,27 +27,8 @@ var Actions = function Actions(_ref) {
43
27
  onChange: function onChange(e) {
44
28
  // TODO: is it performant?
45
29
  setSearchText(e.target.value);
46
- },
47
- "test-id": "".concat(blockClass, "__customize-columns-modal--search")
48
- }), /*#__PURE__*/React.createElement(Button, {
49
- onClick: function onClick() {
50
- var reset = resetToOriginal(columns, originalColumnDefinitions);
51
- setColumnsObject(reset);
52
- },
53
- size: "sm",
54
- kind: "ghost",
55
- renderIcon: Reset16,
56
- "test-id": "".concat(blockClass, "__customize-columns-modal--reset")
57
- }, resetToDefaultLabel));
58
- };
59
-
60
- var resetToOriginal = function resetToOriginal(columnDefinitions, originalColumnDefinitions) {
61
- var keyedDefs = keyBy(columnDefinitions, 'id');
62
- return originalColumnDefinitions.map(function (colDef) {
63
- return _objectSpread(_objectSpread({}, keyedDefs[colDef.id]), {}, {
64
- isVisible: isColumnVisible(colDef)
65
- });
66
- });
30
+ }
31
+ }));
67
32
  };
68
33
 
69
34
  Actions.propTypes = {
@@ -1,3 +1,4 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  // @flow
3
4
 
@@ -8,7 +9,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
8
9
  * US Government Users Restricted Rights - Use, duplication or disclosure
9
10
  * restricted by GSA ADP Schedule Contract with IBM Corp.
10
11
  */
11
- import * as React from 'react';
12
+ import React from 'react';
12
13
  import PropTypes from 'prop-types';
13
14
  import { DndProvider } from 'react-dnd';
14
15
  import { HTML5Backend } from 'react-dnd-html5-backend';
@@ -17,6 +18,7 @@ import update from 'immutability-helper';
17
18
  import { pkg } from '../../../../../settings';
18
19
  import DraggableElement from '../../DraggableElement';
19
20
  import { isColumnVisible } from './common';
21
+ import classNames from 'classnames';
20
22
  var blockClass = "".concat(pkg.prefix, "--datagrid");
21
23
 
22
24
  var getNextIndex = function getNextIndex(array, currentIndex, key) {
@@ -34,14 +36,16 @@ var getNextIndex = function getNextIndex(array, currentIndex, key) {
34
36
  };
35
37
 
36
38
  var Columns = function Columns(_ref) {
37
- var filterString = _ref.filterString,
39
+ var _classNames;
40
+
41
+ var getVisibleColumnsCount = _ref.getVisibleColumnsCount,
42
+ filterString = _ref.filterString,
38
43
  columns = _ref.columns,
39
44
  setColumnsObject = _ref.setColumnsObject,
40
45
  onSelectColumn = _ref.onSelectColumn,
41
- _ref$instructionsLabe = _ref.instructionsLabel,
42
- instructionsLabel = _ref$instructionsLabe === void 0 ? 'Press space bar to toggle drag drop mode, use arrow keys to move selected elements.' : _ref$instructionsLabe,
43
- _ref$disabledInstruct = _ref.disabledInstructionsLabel,
44
- disabledInstructionsLabel = _ref$disabledInstruct === void 0 ? 'Reordering columns are disabled because they are filtered currently.' : _ref$disabledInstruct;
46
+ assistiveTextInstructionsLabel = _ref.assistiveTextInstructionsLabel,
47
+ assistiveTextDisabledInstructionsLabel = _ref.assistiveTextDisabledInstructionsLabel,
48
+ selectAllLabel = _ref.selectAllLabel;
45
49
 
46
50
  var _React$useState = React.useState(''),
47
51
  _React$useState2 = _slicedToArray(_React$useState, 2),
@@ -88,7 +92,21 @@ var Columns = function Columns(_ref) {
88
92
  }, ariaRegionText), /*#__PURE__*/React.createElement("span", {
89
93
  id: "".concat(blockClass, "__customize-columns--instructions"),
90
94
  className: "".concat(blockClass, "__shared-ui--assistive-text")
91
- }, filterString.length === 0 ? instructionsLabel : disabledInstructionsLabel), columns.filter(function (colDef) {
95
+ }, filterString.length === 0 ? assistiveTextInstructionsLabel : assistiveTextDisabledInstructionsLabel), /*#__PURE__*/React.createElement("div", {
96
+ id: "".concat(blockClass, "__customize-columns-select-all"),
97
+ className: classNames((_classNames = {}, _defineProperty(_classNames, "".concat(blockClass, "__customize-columns-select-all"), getVisibleColumnsCount() === 0), _defineProperty(_classNames, "".concat(blockClass, "__customize-columns-select-all-selected"), getVisibleColumnsCount() > 0), _classNames)),
98
+ selected: getVisibleColumnsCount() > 0
99
+ }, /*#__PURE__*/React.createElement(Checkbox, {
100
+ wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox-wrapper"),
101
+ checked: getVisibleColumnsCount() === columns.length,
102
+ empty: !!getVisibleColumnsCount() === 0,
103
+ indeterminate: getVisibleColumnsCount() < columns.length && getVisibleColumnsCount() > 0,
104
+ onChange: function onChange() {
105
+ onSelectColumn(columns, getVisibleColumnsCount() !== columns.length);
106
+ },
107
+ id: "".concat(blockClass, "__customization-column-select-all"),
108
+ labelText: selectAllLabel
109
+ })), columns.filter(function (colDef) {
92
110
  return filterString.length === 0 || colDef.Header.props.title.toLowerCase().includes(filterString);
93
111
  }).map(function (colDef, i) {
94
112
  return /*#__PURE__*/React.createElement(DraggableElement, {
@@ -117,24 +135,31 @@ var Columns = function Columns(_ref) {
117
135
  });
118
136
  }
119
137
  }
120
- }
138
+ },
139
+ selected: isColumnVisible(colDef)
121
140
  }, /*#__PURE__*/React.createElement(Checkbox, {
122
- wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox"),
141
+ wrapperClassName: "".concat(blockClass, "__customize-columns-checkbox-wrapper"),
123
142
  checked: isColumnVisible(colDef),
124
143
  onChange: onSelectColumn.bind(null, colDef),
125
144
  id: "".concat(blockClass, "__customization-column-").concat(colDef.id),
126
145
  labelText: colDef.Header.props.title,
127
- title: colDef.Header.props.title
146
+ title: colDef.Header.props.title,
147
+ className: "".concat(blockClass, "__customize-columns-checkbox")
128
148
  }));
129
149
  }))));
130
150
  };
131
151
 
132
152
  Columns.propTypes = {
153
+ assistiveTextDisabledInstructionsLabel: PropTypes.string,
154
+ assistiveTextInstructionsLabel: PropTypes.string,
133
155
  columns: PropTypes.array.isRequired,
134
156
  disabledInstructionsLabel: PropTypes.string,
135
157
  filterString: PropTypes.string.isRequired,
158
+ getVisibleColumnsCount: PropTypes.func.isRequired,
136
159
  instructionsLabel: PropTypes.string,
137
160
  onSelectColumn: PropTypes.func.isRequired,
161
+ selectAllLabel: PropTypes.string,
162
+ setColumnStatus: PropTypes.func,
138
163
  setColumnsObject: PropTypes.func.isRequired
139
164
  };
140
165
  export default Columns;