@carbon/ibm-products 1.6.1 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/css/index-full-carbon.css +224 -143
  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 +1 -2
  6. package/css/index-without-carbon-released-only.css.map +1 -1
  7. package/css/index-without-carbon-released-only.min.css +1 -1
  8. package/css/index-without-carbon-released-only.min.css.map +1 -1
  9. package/css/index-without-carbon.css +178 -142
  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 +178 -142
  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/APIKeyModal/APIKeyModal.js +10 -13
  18. package/es/components/ActionBar/ActionBar.js +0 -3
  19. package/es/components/ActionBar/ActionBarItem.js +2 -6
  20. package/es/components/ActionSet/ActionSet.js +11 -13
  21. package/es/components/AddSelect/AddSelect.js +121 -25
  22. package/es/components/AddSelect/AddSelectBreadcrumbs.js +5 -5
  23. package/es/components/AddSelect/AddSelectColumn.js +21 -0
  24. package/es/components/AddSelect/AddSelectList.js +68 -9
  25. package/es/components/AddSelect/AddSelectSidebar.js +43 -5
  26. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  27. package/es/components/ButtonMenu/ButtonMenu.js +6 -4
  28. package/es/components/ButtonMenu/ButtonMenuItem.js +1 -2
  29. package/es/components/Card/Card.js +31 -21
  30. package/es/components/Card/CardFooter.js +14 -10
  31. package/es/components/Card/CardHeader.js +8 -6
  32. package/es/components/Cascade/Cascade.js +5 -4
  33. package/es/components/ComboButton/ComboButton.js +0 -4
  34. package/es/components/ComboButton/ComboButtonItem/index.js +0 -5
  35. package/es/components/CreateFullPage/CreateFullPageStep.js +15 -8
  36. package/es/components/CreateModal/CreateModal.js +1 -4
  37. package/es/components/CreateTearsheet/CreateTearsheet.js +10 -11
  38. package/es/components/CreateTearsheet/CreateTearsheetStep.js +18 -14
  39. package/es/components/DataSpreadsheet/DataSpreadsheet.js +454 -0
  40. package/es/components/DataSpreadsheet/DataSpreadsheetBody.js +322 -0
  41. package/es/components/DataSpreadsheet/DataSpreadsheetHeader.js +64 -0
  42. package/es/components/DataSpreadsheet/createActiveCellFn.js +45 -0
  43. package/es/components/DataSpreadsheet/createCellSelectionArea.js +45 -0
  44. package/es/components/DataSpreadsheet/generateData.js +47 -0
  45. package/es/components/DataSpreadsheet/getCellSize.js +30 -0
  46. package/es/components/{CancelableTextEdit → DataSpreadsheet}/index.js +2 -2
  47. package/es/components/EditSidePanel/EditSidePanel.js +9 -10
  48. package/es/components/EmptyStates/EmptyState.js +7 -6
  49. package/es/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +4 -8
  50. package/es/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +4 -8
  51. package/es/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +4 -8
  52. package/es/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +4 -8
  53. package/es/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +4 -8
  54. package/es/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +4 -8
  55. package/es/components/ExampleComponent/ExampleComponent.js +12 -13
  56. package/es/components/ExportModal/ExportModal.js +13 -9
  57. package/es/components/ExpressiveCard/ExpressiveCard.js +0 -8
  58. package/es/components/ImportModal/ImportModal.js +7 -5
  59. package/es/components/InlineEdit/InlineEdit.js +51 -46
  60. package/es/components/LoadingBar/LoadingBar.js +13 -17
  61. package/es/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  62. package/es/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  63. package/es/components/ModifiedTabs/ModifiedTabs.js +24 -18
  64. package/es/components/NotificationsPanel/NotificationsPanel.js +109 -86
  65. package/es/components/OptionsTile/OptionsTile.js +6 -9
  66. package/es/components/PageHeader/PageHeader.js +10 -7
  67. package/es/components/ProductiveCard/ProductiveCard.js +23 -12
  68. package/es/components/RemoveModal/RemoveModal.js +0 -3
  69. package/es/components/SidePanel/SidePanel.js +22 -17
  70. package/es/components/TagSet/TagSet.js +13 -9
  71. package/es/components/TagSet/TagSetModal.js +16 -12
  72. package/es/components/TagSet/TagSetOverflow.js +21 -13
  73. package/es/components/Tearsheet/Tearsheet.js +27 -18
  74. package/es/components/Tearsheet/TearsheetNarrow.js +18 -15
  75. package/es/components/Tearsheet/TearsheetShell.js +3 -4
  76. package/es/components/Toolbar/ToolbarButton.js +0 -3
  77. package/es/components/WebTerminal/WebTerminal.js +17 -18
  78. package/es/components/index.js +2 -2
  79. package/es/global/js/hooks/index.js +1 -0
  80. package/es/global/js/hooks/useActiveElement.js +27 -0
  81. package/es/global/js/package-settings.js +2 -1
  82. package/es/global/js/utils/DisplayBox.js +31 -0
  83. package/es/global/js/utils/Wrap.js +7 -5
  84. package/es/global/js/utils/deepCloneObject.js +26 -0
  85. package/es/global/js/utils/getScrollbarWidth.js +14 -0
  86. package/lib/components/APIKeyModal/APIKeyModal.js +10 -13
  87. package/lib/components/ActionBar/ActionBar.js +0 -3
  88. package/lib/components/ActionBar/ActionBarItem.js +2 -6
  89. package/lib/components/ActionSet/ActionSet.js +11 -13
  90. package/lib/components/AddSelect/AddSelect.js +119 -24
  91. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +3 -4
  92. package/lib/components/AddSelect/AddSelectColumn.js +37 -0
  93. package/lib/components/AddSelect/AddSelectList.js +66 -9
  94. package/lib/components/AddSelect/AddSelectSidebar.js +43 -4
  95. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +0 -3
  96. package/lib/components/ButtonMenu/ButtonMenu.js +6 -4
  97. package/lib/components/ButtonMenu/ButtonMenuItem.js +1 -2
  98. package/lib/components/Card/Card.js +31 -21
  99. package/lib/components/Card/CardFooter.js +14 -10
  100. package/lib/components/Card/CardHeader.js +8 -6
  101. package/lib/components/Cascade/Cascade.js +5 -4
  102. package/lib/components/ComboButton/ComboButton.js +0 -4
  103. package/lib/components/ComboButton/ComboButtonItem/index.js +0 -5
  104. package/lib/components/CreateFullPage/CreateFullPageStep.js +17 -14
  105. package/lib/components/CreateModal/CreateModal.js +1 -4
  106. package/lib/components/CreateTearsheet/CreateTearsheet.js +10 -11
  107. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +20 -20
  108. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +478 -0
  109. package/lib/components/DataSpreadsheet/DataSpreadsheetBody.js +349 -0
  110. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +80 -0
  111. package/lib/components/DataSpreadsheet/createActiveCellFn.js +56 -0
  112. package/lib/components/DataSpreadsheet/createCellSelectionArea.js +56 -0
  113. package/lib/components/DataSpreadsheet/generateData.js +58 -0
  114. package/lib/components/DataSpreadsheet/getCellSize.js +39 -0
  115. package/lib/components/DataSpreadsheet/index.js +13 -0
  116. package/lib/components/EditSidePanel/EditSidePanel.js +9 -10
  117. package/lib/components/EmptyStates/EmptyState.js +9 -8
  118. package/lib/components/EmptyStates/ErrorEmptyState/ErrorEmptyState.js +3 -7
  119. package/lib/components/EmptyStates/NoDataEmptyState/NoDataEmptyState.js +3 -7
  120. package/lib/components/EmptyStates/NoTagsEmptyState/NoTagsEmptyState.js +3 -7
  121. package/lib/components/EmptyStates/NotFoundEmptyState/NotFoundEmptyState.js +3 -7
  122. package/lib/components/EmptyStates/NotificationsEmptyState/NotificationsEmptyState.js +3 -7
  123. package/lib/components/EmptyStates/UnauthorizedEmptyState/UnauthorizedEmptyState.js +3 -7
  124. package/lib/components/ExampleComponent/ExampleComponent.js +12 -13
  125. package/lib/components/ExportModal/ExportModal.js +13 -9
  126. package/lib/components/ExpressiveCard/ExpressiveCard.js +0 -8
  127. package/lib/components/ImportModal/ImportModal.js +7 -5
  128. package/lib/components/InlineEdit/InlineEdit.js +51 -46
  129. package/lib/components/LoadingBar/LoadingBar.js +13 -17
  130. package/lib/components/ModifiedTabs/ModifiedTabLabelNew.js +0 -4
  131. package/lib/components/ModifiedTabs/ModifiedTabLabelWithClose.js +0 -5
  132. package/lib/components/ModifiedTabs/ModifiedTabs.js +24 -18
  133. package/lib/components/NotificationsPanel/NotificationsPanel.js +109 -86
  134. package/lib/components/OptionsTile/OptionsTile.js +6 -9
  135. package/lib/components/PageHeader/PageHeader.js +9 -6
  136. package/lib/components/ProductiveCard/ProductiveCard.js +24 -18
  137. package/lib/components/RemoveModal/RemoveModal.js +0 -3
  138. package/lib/components/SidePanel/SidePanel.js +22 -17
  139. package/lib/components/TagSet/TagSet.js +13 -9
  140. package/lib/components/TagSet/TagSetModal.js +17 -13
  141. package/lib/components/TagSet/TagSetOverflow.js +24 -19
  142. package/lib/components/Tearsheet/Tearsheet.js +26 -17
  143. package/lib/components/Tearsheet/TearsheetNarrow.js +18 -15
  144. package/lib/components/Tearsheet/TearsheetShell.js +2 -3
  145. package/lib/components/Toolbar/ToolbarButton.js +0 -3
  146. package/lib/components/WebTerminal/WebTerminal.js +17 -18
  147. package/lib/components/index.js +8 -8
  148. package/lib/global/js/hooks/index.js +8 -0
  149. package/lib/global/js/hooks/useActiveElement.js +39 -0
  150. package/lib/global/js/package-settings.js +2 -1
  151. package/lib/global/js/utils/DisplayBox.js +46 -0
  152. package/lib/global/js/utils/Wrap.js +7 -5
  153. package/lib/global/js/utils/deepCloneObject.js +37 -0
  154. package/lib/global/js/utils/getScrollbarWidth.js +23 -0
  155. package/package.json +18 -16
  156. package/scss/components/{CancelableTextEdit → ActionBar}/_storybook-styles.scss +2 -2
  157. package/scss/components/ActionSet/_storybook-styles.scss +1 -3
  158. package/scss/components/AddSelect/_add-select.scss +77 -1
  159. package/scss/components/BreadcrumbWithOverflow/_storybook-styles.scss +8 -0
  160. package/scss/components/ButtonSetWithOverflow/_storybook-styles.scss +8 -0
  161. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +120 -0
  162. package/scss/components/{CancelableTextEdit → DataSpreadsheet}/_index.scss +2 -2
  163. package/scss/components/DataSpreadsheet/_storybook-styles.scss +6 -0
  164. package/scss/components/InlineEdit/_inline-edit.scss +22 -8
  165. package/scss/components/InlineEdit/_storybook-styles.scss +1 -0
  166. package/scss/components/TagSet/_storybook-styles.scss +8 -0
  167. package/scss/components/Tearsheet/_tearsheet.scss +1 -2
  168. package/scss/components/_index.scss +1 -1
  169. package/scss/global/styles/_display-box.scss +62 -0
  170. package/es/components/CancelableTextEdit/CancelableTextEdit.js +0 -245
  171. package/lib/components/CancelableTextEdit/CancelableTextEdit.js +0 -265
  172. package/lib/components/CancelableTextEdit/index.js +0 -13
  173. package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +0 -212
@@ -0,0 +1,322 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
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.
9
+ */
10
+ import React, { useRef, useCallback, useEffect } from 'react';
11
+ import PropTypes from 'prop-types';
12
+ import { FixedSizeList } from 'react-window';
13
+ import cx from 'classnames';
14
+ import { pkg } from '../../settings';
15
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
16
+ import uuidv4 from '../../global/js/utils/uuidv4';
17
+ import { createCellSelectionArea } from './createCellSelectionArea';
18
+ var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
19
+ export var DataSpreadsheetBody = function DataSpreadsheetBody(_ref) {
20
+ var defaultColumn = _ref.defaultColumn,
21
+ getTableBodyProps = _ref.getTableBodyProps,
22
+ id = _ref.id,
23
+ prepareRow = _ref.prepareRow,
24
+ rows = _ref.rows,
25
+ setActiveCellCoordinates = _ref.setActiveCellCoordinates,
26
+ selectionAreas = _ref.selectionAreas,
27
+ setContainerHasFocus = _ref.setContainerHasFocus,
28
+ setSelectionAreas = _ref.setSelectionAreas,
29
+ scrollBarSize = _ref.scrollBarSize,
30
+ totalColumnsWidth = _ref.totalColumnsWidth,
31
+ clickAndHoldActive = _ref.clickAndHoldActive,
32
+ setClickAndHoldActive = _ref.setClickAndHoldActive,
33
+ currentMatcher = _ref.currentMatcher,
34
+ setCurrentMatcher = _ref.setCurrentMatcher;
35
+ // Create cell selection areas based on selectionAreas array
36
+ useEffect(function () {
37
+ if (selectionAreas && selectionAreas.length) {
38
+ selectionAreas.map(function (area) {
39
+ if (!area.areaCreated && area.point1 && area.point2 && area.matcher) {
40
+ // Do not create a cell selection area if point1 and point2 have the same values
41
+ // Cell selections must have two distinctly different points for an area to be created
42
+ if (area.point1.row === area.point2.row && area.point1.column === area.point2.column) {
43
+ var selectionAreasClone = deepCloneObject(selectionAreas);
44
+ var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
45
+ return item.matcher === area.matcher;
46
+ });
47
+ selectionAreasClone[indexOfCurrentArea].areaCreated = false;
48
+ selectionAreasClone[indexOfCurrentArea].point2 = null;
49
+ return setSelectionAreas(selectionAreasClone);
50
+ }
51
+
52
+ createCellSelectionArea({
53
+ area: area,
54
+ blockClass: blockClass,
55
+ selectionAreas: selectionAreas,
56
+ setSelectionAreas: setSelectionAreas
57
+ });
58
+ }
59
+
60
+ return;
61
+ });
62
+ }
63
+ }, [selectionAreas, setSelectionAreas]); // Mouse up
64
+
65
+ useEffect(function () {
66
+ var handleMouseUp = function handleMouseUp(event) {
67
+ setClickAndHoldActive(false);
68
+ var cellButton = event.target.closest(".".concat(blockClass, "__body--td"));
69
+
70
+ if (cellButton) {
71
+ var endCellCoordinates = {
72
+ row: Number(cellButton.getAttribute('data-row-index')),
73
+ column: Number(cellButton.getAttribute('data-column-index'))
74
+ };
75
+ setCurrentMatcher(null);
76
+ setSelectionAreas(function (prev) {
77
+ var selectionAreaClone = deepCloneObject(prev);
78
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
79
+ return item.matcher === currentMatcher;
80
+ }); // No items in the array have an object that matches the value of currentMatcher
81
+
82
+ if (indexOfItemToUpdate === -1) {
83
+ return prev;
84
+ }
85
+
86
+ selectionAreaClone[indexOfItemToUpdate].point2 = endCellCoordinates;
87
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
88
+ return selectionAreaClone;
89
+ });
90
+ } else {
91
+ var selectionAreaClone = deepCloneObject(selectionAreas);
92
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
93
+ return item.matcher === currentMatcher;
94
+ });
95
+
96
+ if (indexOfItemToUpdate === -1) {
97
+ return;
98
+ }
99
+
100
+ var newArray = selectionAreaClone.filter(function (item) {
101
+ return item.matcher !== currentMatcher;
102
+ });
103
+ setCurrentMatcher(null);
104
+ setSelectionAreas(newArray);
105
+ }
106
+ };
107
+
108
+ document.addEventListener('mouseup', handleMouseUp);
109
+ return function () {
110
+ document.removeEventListener('mouseup', handleMouseUp);
111
+ };
112
+ }, [selectionAreas, currentMatcher, setSelectionAreas, setClickAndHoldActive, setCurrentMatcher]); // Make sure that if the cellSize prop changes, the active
113
+ // cell also gets updated with the new size
114
+
115
+ useEffect(function () {
116
+ var listContainer = spreadsheetBodyRef === null || spreadsheetBodyRef === void 0 ? void 0 : spreadsheetBodyRef.current;
117
+ var activeCellButton = listContainer.querySelector(".".concat(blockClass, "__active-cell--highlight"));
118
+
119
+ if (activeCellButton) {
120
+ activeCellButton.style.height = "".concat(defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight, "px");
121
+ }
122
+ }, [defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight]); // onClick fn for each cell in the data spreadsheet body,
123
+ // adds the active cell highlight
124
+
125
+ var handleBodyCellClick = useCallback(function (event, cell, columnIndex) {
126
+ var isHoldingCommandKey = event.metaKey || event.ctrlKey;
127
+ setContainerHasFocus(true);
128
+ var activeCoordinates = {
129
+ row: cell.row.index,
130
+ column: columnIndex
131
+ };
132
+ var tempMatcher = uuidv4();
133
+ setActiveCellCoordinates(activeCoordinates); // prevent multiple selections unless cmd key is held
134
+ // meaning that selectionAreas should only have one item by default
135
+
136
+ if (isHoldingCommandKey) {
137
+ setSelectionAreas(function (prev) {
138
+ return [].concat(_toConsumableArray(prev), [{
139
+ point1: activeCoordinates,
140
+ matcher: tempMatcher
141
+ }]);
142
+ });
143
+ } else {
144
+ // remove all previous cell selections
145
+ var cellSelections = spreadsheetBodyRef.current.querySelectorAll(".".concat(blockClass, "__selection-area--element"));
146
+ Array.from(cellSelections).forEach(function (element) {
147
+ return element.remove();
148
+ });
149
+ setSelectionAreas([{
150
+ point1: activeCoordinates,
151
+ matcher: tempMatcher
152
+ }]);
153
+ }
154
+
155
+ setCurrentMatcher(tempMatcher);
156
+ setClickAndHoldActive(true);
157
+ }, [setActiveCellCoordinates, setSelectionAreas, setContainerHasFocus, setClickAndHoldActive, setCurrentMatcher]);
158
+ var handleBodyCellHover = useCallback(function (event, cell, columnIndex) {
159
+ if (clickAndHoldActive) {
160
+ var cellCoordinates = {
161
+ row: cell.row.index,
162
+ column: columnIndex
163
+ };
164
+ setSelectionAreas(function (prev) {
165
+ var _selectionAreaClone$i, _selectionAreaClone$i2;
166
+
167
+ var selectionAreaClone = deepCloneObject(prev);
168
+ var indexOfItemToUpdate = selectionAreaClone.findIndex(function (item) {
169
+ return item.matcher === currentMatcher;
170
+ }); // No items in the array match up with the currentMatcher value
171
+
172
+ if (indexOfItemToUpdate === -1) {
173
+ return prev;
174
+ } // Do not update state if you're still hovering on the same cell
175
+
176
+
177
+ if (((_selectionAreaClone$i = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i === void 0 ? void 0 : _selectionAreaClone$i.row) === cellCoordinates.row && ((_selectionAreaClone$i2 = selectionAreaClone[indexOfItemToUpdate].point2) === null || _selectionAreaClone$i2 === void 0 ? void 0 : _selectionAreaClone$i2.column) === cellCoordinates.column) {
178
+ return prev;
179
+ }
180
+
181
+ selectionAreaClone[indexOfItemToUpdate].point2 = cellCoordinates;
182
+ selectionAreaClone[indexOfItemToUpdate].areaCreated = false;
183
+ return selectionAreaClone;
184
+ });
185
+ }
186
+ }, [clickAndHoldActive, currentMatcher, setSelectionAreas]); // Renders each cell in the spreadsheet body
187
+
188
+ var RenderRow = useCallback(function (_ref2) {
189
+ var index = _ref2.index,
190
+ style = _ref2.style;
191
+ var row = rows[index];
192
+ prepareRow(row);
193
+ return /*#__PURE__*/React.createElement("div", _extends({}, row.getRowProps({
194
+ style: style
195
+ }), {
196
+ className: cx("".concat(blockClass, "__tr")),
197
+ "data-row-index": index
198
+ }), /*#__PURE__*/React.createElement("button", {
199
+ tabIndex: -1,
200
+ "data-row-index": index,
201
+ "data-column-index": "header",
202
+ type: "button",
203
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__td-th"), "".concat(blockClass, "--interactive-cell-element")),
204
+ style: {
205
+ width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth
206
+ }
207
+ }, index + 1), row.cells.map(function (cell, index) {
208
+ return /*#__PURE__*/React.createElement("button", _extends({
209
+ tabIndex: -1,
210
+ "data-row-index": cell.row.index,
211
+ "data-column-index": index
212
+ }, cell.getCellProps(), {
213
+ className: cx("".concat(blockClass, "__td"), "".concat(blockClass, "__body--td"), "".concat(blockClass, "--interactive-cell-element")),
214
+ key: "cell_".concat(index),
215
+ onMouseDown: function onMouseDown(event) {
216
+ return handleBodyCellClick(event, cell, index);
217
+ },
218
+ onMouseOver: function onMouseOver(event) {
219
+ return handleBodyCellHover(event, cell, index);
220
+ },
221
+ onFocus: function onFocus() {},
222
+ type: "button"
223
+ }), cell.render('Cell'));
224
+ }));
225
+ }, [prepareRow, rows, defaultColumn.rowHeaderWidth, handleBodyCellClick, handleBodyCellHover]);
226
+ var spreadsheetBodyRef = useRef();
227
+ return /*#__PURE__*/React.createElement("div", _extends({
228
+ ref: spreadsheetBodyRef,
229
+ className: cx("".concat(blockClass, "__body--container"))
230
+ }, getTableBodyProps()), /*#__PURE__*/React.createElement(FixedSizeList, {
231
+ className: cx("".concat(blockClass, "__list--container"), "".concat(blockClass, "__list--container--").concat(id)),
232
+ height: 400,
233
+ itemCount: rows.length,
234
+ itemSize: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight,
235
+ width: totalColumnsWidth + scrollBarSize
236
+ }, RenderRow));
237
+ };
238
+ DataSpreadsheetBody.propTypes = {
239
+ /**
240
+ * Is the user clicking and holding in the data spreadsheet body
241
+ */
242
+ clickAndHoldActive: PropTypes.bool,
243
+
244
+ /**
245
+ * This represents the id of the current cell selection area
246
+ */
247
+ currentMatcher: PropTypes.string,
248
+
249
+ /**
250
+ * Default spreadsheet sizing values
251
+ */
252
+ defaultColumn: PropTypes.shape({
253
+ rowHeight: PropTypes.number,
254
+ rowHeaderWidth: PropTypes.number,
255
+ width: PropTypes.number
256
+ }),
257
+
258
+ /**
259
+ * Function to set table body prop values
260
+ */
261
+ getTableBodyProps: PropTypes.func,
262
+
263
+ /**
264
+ * The spreadsheet id
265
+ */
266
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
267
+
268
+ /**
269
+ * The event handler that is called when the active cell changes
270
+ */
271
+ onActiveCellChange: PropTypes.func,
272
+
273
+ /**
274
+ * Prepare row function from react-table
275
+ */
276
+ prepareRow: PropTypes.func,
277
+
278
+ /**
279
+ * All of the spreadsheet row data
280
+ */
281
+ rows: PropTypes.arrayOf(PropTypes.object),
282
+
283
+ /**
284
+ * The scrollbar width
285
+ */
286
+ scrollBarSize: PropTypes.number,
287
+
288
+ /**
289
+ * Array of selection areas
290
+ */
291
+ selectionAreas: PropTypes.array,
292
+
293
+ /**
294
+ * Setter fn for activeCellCoordinates state value
295
+ */
296
+ setActiveCellCoordinates: PropTypes.func,
297
+
298
+ /**
299
+ * Setter fn for clickAndHold state value
300
+ */
301
+ setClickAndHoldActive: PropTypes.func,
302
+
303
+ /**
304
+ * Setter fn for containerHasFocus state value
305
+ */
306
+ setContainerHasFocus: PropTypes.func,
307
+
308
+ /**
309
+ * Setter fn for currentMatcher state value
310
+ */
311
+ setCurrentMatcher: PropTypes.func,
312
+
313
+ /**
314
+ * Setter fn for selectionAreas state value
315
+ */
316
+ setSelectionAreas: PropTypes.func,
317
+
318
+ /**
319
+ * The total columns width
320
+ */
321
+ totalColumnsWidth: PropTypes.number
322
+ };
@@ -0,0 +1,64 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+
3
+ /**
4
+ * Copyright IBM Corp. 2022, 2022
5
+ *
6
+ * This source code is licensed under the Apache-2.0 license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import React from 'react';
10
+ import PropTypes from 'prop-types';
11
+ import cx from 'classnames';
12
+ import { pkg } from '../../settings';
13
+ var blockClass = "".concat(pkg.prefix, "--data-spreadsheet");
14
+ export var DataSpreadsheetHeader = function DataSpreadsheetHeader(_ref) {
15
+ var defaultColumn = _ref.defaultColumn,
16
+ headerGroups = _ref.headerGroups;
17
+ return /*#__PURE__*/React.createElement("div", {
18
+ className: cx("".concat(blockClass, "__header--container"))
19
+ }, headerGroups.map(function (headerGroup, index) {
20
+ return /*#__PURE__*/React.createElement("div", _extends({
21
+ key: "header_".concat(index)
22
+ }, headerGroup.getHeaderGroupProps(), {
23
+ className: "".concat(blockClass, "__tr")
24
+ }), /*#__PURE__*/React.createElement("button", {
25
+ "data-row-index": "header",
26
+ "data-column-index": "header",
27
+ type: "button",
28
+ tabIndex: -1,
29
+ className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element")),
30
+ style: {
31
+ width: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeaderWidth,
32
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
33
+ }
34
+ }, "\xA0"), headerGroup.headers.map(function (column, index) {
35
+ return /*#__PURE__*/React.createElement("button", _extends({
36
+ key: "column_".concat(index),
37
+ "data-row-index": "header",
38
+ "data-column-index": index,
39
+ tabIndex: -1,
40
+ style: {
41
+ height: defaultColumn === null || defaultColumn === void 0 ? void 0 : defaultColumn.rowHeight
42
+ }
43
+ }, column.getHeaderProps(), {
44
+ className: cx("".concat(blockClass, "__th"), "".concat(blockClass, "--interactive-cell-element")),
45
+ type: "button"
46
+ }), column.render('Header'));
47
+ }));
48
+ }));
49
+ };
50
+ DataSpreadsheetHeader.propTypes = {
51
+ /**
52
+ * Default spreadsheet sizing values
53
+ */
54
+ defaultColumn: PropTypes.shape({
55
+ rowHeight: PropTypes.number,
56
+ rowHeaderWidth: PropTypes.number,
57
+ width: PropTypes.number
58
+ }),
59
+
60
+ /**
61
+ * Headers provided from useTable hook
62
+ */
63
+ headerGroups: PropTypes.arrayOf(PropTypes.object)
64
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { px } from '@carbon/layout';
8
+ import { pkg } from '../../settings';
9
+ export var createActiveCellFn = function createActiveCellFn(_ref) {
10
+ var placementElement = _ref.placementElement,
11
+ coords = _ref.coords,
12
+ _ref$addToHeader = _ref.addToHeader,
13
+ addToHeader = _ref$addToHeader === void 0 ? false : _ref$addToHeader,
14
+ contextRef = _ref.contextRef,
15
+ _ref$blockClass = _ref.blockClass,
16
+ blockClass = _ref$blockClass === void 0 ? "".concat(pkg.prefix, "--data-spreadsheet") : _ref$blockClass,
17
+ onActiveCellChange = _ref.onActiveCellChange,
18
+ activeCellValue = _ref.activeCellValue;
19
+
20
+ if (!coords) {
21
+ return;
22
+ } // If the active cell is in the column header row (very first), we need to append this element
23
+ // to `.${blockClass}__header--container`, otherwise it should be appended to `.${blockClass}__listContainer` firstElementChild
24
+
25
+
26
+ var activeElementContainer = addToHeader ? contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__header--container")) : contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
27
+ var relativePosition = {
28
+ top: placementElement.getBoundingClientRect().top - activeElementContainer.getBoundingClientRect().top,
29
+ left: placementElement.getBoundingClientRect().left - activeElementContainer.getBoundingClientRect().left
30
+ };
31
+ var activeCellButton = (contextRef === null || contextRef === void 0 ? void 0 : contextRef.current.querySelector(".".concat(blockClass, "__active-cell--highlight"))) || document.createElement('button');
32
+ activeCellButton.classList.add("".concat(blockClass, "__active-cell--highlight"), "".concat(blockClass, "--interactive-cell-element"));
33
+ activeCellButton.style.width = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetWidth);
34
+ activeCellButton.style.height = px(placementElement === null || placementElement === void 0 ? void 0 : placementElement.offsetHeight);
35
+ activeCellButton.style.left = px(relativePosition.left);
36
+ activeCellButton.style.top = px(relativePosition.top);
37
+ activeCellButton.setAttribute('data-active-row-index', typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number' ? coords.row : 'header');
38
+ activeCellButton.setAttribute('data-active-column-index', typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' ? coords.column : 'header');
39
+ activeElementContainer.appendChild(activeCellButton);
40
+ activeCellButton.focus();
41
+
42
+ if (typeof (coords === null || coords === void 0 ? void 0 : coords.column) === 'number' && typeof (coords === null || coords === void 0 ? void 0 : coords.row) === 'number') {
43
+ onActiveCellChange === null || onActiveCellChange === void 0 ? void 0 : onActiveCellChange(activeCellValue);
44
+ }
45
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { px } from '@carbon/layout';
8
+ import { deepCloneObject } from '../../global/js/utils/deepCloneObject';
9
+ export var createCellSelectionArea = function createCellSelectionArea(_ref) {
10
+ var area = _ref.area,
11
+ blockClass = _ref.blockClass,
12
+ selectionAreas = _ref.selectionAreas,
13
+ setSelectionAreas = _ref.setSelectionAreas;
14
+ var greatestRow = Math.max(area.point1.row, area.point2.row);
15
+ var greatestColumn = Math.max(area.point1.column, area.point2.column);
16
+ var lowestRowIndex = Math.min(area.point1.row, area.point2.row);
17
+ var lowestColumnIndex = Math.min(area.point1.column, area.point2.column);
18
+ var point1Element = document.querySelector("[data-row-index=\"".concat(area.point1.row, "\"][data-column-index=\"").concat(area.point1.column, "\"]"));
19
+ var selectionAreaCellWidth = point1Element.offsetWidth;
20
+ var selectionAreaCellHeight = point1Element.offsetHeight;
21
+ var selectionAreaTotalWidth = selectionAreaCellWidth * (greatestColumn - lowestColumnIndex + 1);
22
+ var selectionAreaTotalHeight = selectionAreaCellHeight * (greatestRow - lowestRowIndex + 1);
23
+ var bodyContainer = document.querySelector(".".concat(blockClass, "__list--container")).firstElementChild;
24
+ var placementElement = bodyContainer.querySelector("[data-row-index=\"".concat(lowestRowIndex, "\"][data-column-index=\"").concat(lowestColumnIndex, "\"]"));
25
+ var relativePosition = {
26
+ top: placementElement.getBoundingClientRect().top - bodyContainer.getBoundingClientRect().top,
27
+ left: placementElement.getBoundingClientRect().left - bodyContainer.getBoundingClientRect().left
28
+ };
29
+ var selectionAreaElement = document.querySelector("[data-matcher-id=\"".concat(area.matcher, "\"]")) || document.createElement('div');
30
+ selectionAreaElement.classList.add("".concat(blockClass, "__selection-area--element"));
31
+ selectionAreaElement.setAttribute('data-matcher-id', area.matcher);
32
+ selectionAreaElement.style.width = px(selectionAreaTotalWidth);
33
+ selectionAreaElement.style.height = px(selectionAreaTotalHeight);
34
+ selectionAreaElement.style.left = px(relativePosition.left);
35
+ selectionAreaElement.style.top = px(relativePosition.top);
36
+ bodyContainer.appendChild(selectionAreaElement);
37
+ var selectionAreasClone = deepCloneObject(selectionAreas);
38
+ var indexOfCurrentArea = selectionAreasClone.findIndex(function (item) {
39
+ return item.matcher === area.matcher;
40
+ }); // We need to add another property to the selectionAreas object array to
41
+ // let us know if an area has been created for each item already, ie createdArea: true
42
+
43
+ selectionAreasClone[indexOfCurrentArea].areaCreated = true;
44
+ setSelectionAreas(selectionAreasClone);
45
+ };
@@ -0,0 +1,47 @@
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
+ // cspell:disable
8
+ var pets = ['dog', 'cat', 'bird', 'lizard', 'frog', 'hamster', 'fish', 'rabbit', 'snake'];
9
+ var petNames = ['Bruno', 'Willow', 'Kona', 'Heidi', 'Rusty', 'Bonnie', 'Cash', 'Gucci', 'Brody', 'Emma', 'Loki', 'Angel', 'Astro', 'Sherman', 'Layla', 'Peanut', 'Grace', 'Mickey', 'Sasha', 'Finn', 'Tucker', 'Bear', 'Mocha', 'Roscoe']; // cspell:enable
10
+
11
+ var range = function range(len) {
12
+ var arr = [];
13
+
14
+ for (var i = 0; i < len; i++) {
15
+ arr.push(i);
16
+ }
17
+
18
+ return arr;
19
+ };
20
+
21
+ var newPet = function newPet() {
22
+ return {
23
+ petType: pets[Math.floor(Math.random() * pets.length)],
24
+ firstName: petNames[Math.floor(Math.random() * petNames.length)],
25
+ age: Math.floor(Math.random() * 30),
26
+ visits: Math.floor(Math.random() * 40),
27
+ health: Math.floor(Math.random() * 100)
28
+ };
29
+ };
30
+
31
+ export var generateData = function generateData() {
32
+ for (var _len = arguments.length, lens = new Array(_len), _key = 0; _key < _len; _key++) {
33
+ lens[_key] = arguments[_key];
34
+ }
35
+
36
+ var makeDataLevel = function makeDataLevel() {
37
+ var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
38
+ var len = lens[depth];
39
+ return range(len).map(function () {
40
+ return _objectSpread(_objectSpread({}, newPet()), {}, {
41
+ subRows: lens[depth + 1] ? makeDataLevel(depth + 1) : undefined
42
+ });
43
+ });
44
+ };
45
+
46
+ return makeDataLevel();
47
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright IBM Corp. 2022, 2022
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { baseFontSize, sizeXSmall as compact, sizeSmall as standard, sizeMedium as medium, sizeLarge as large } from '@carbon/layout';
8
+
9
+ var getSizeInPixels = function getSizeInPixels(carbonSize) {
10
+ return Number(carbonSize.replace('rem', '') * baseFontSize);
11
+ };
12
+
13
+ export var getCellSize = function getCellSize(cellSize) {
14
+ switch (cellSize) {
15
+ case 'compact':
16
+ return getSizeInPixels(compact);
17
+
18
+ case 'standard':
19
+ return getSizeInPixels(standard);
20
+
21
+ case 'medium':
22
+ return getSizeInPixels(medium);
23
+
24
+ case 'large':
25
+ return getSizeInPixels(large);
26
+
27
+ default:
28
+ return getSizeInPixels(standard);
29
+ }
30
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Copyright IBM Corp. 2021, 2021
2
+ * Copyright IBM Corp. 2022, 2022
3
3
  *
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export { CancelableTextEdit } from './CancelableTextEdit';
7
+ export { DataSpreadsheet } from './DataSpreadsheet';
@@ -31,7 +31,12 @@ import '../../global/js/utils/props-helper'; // The block part of our convention
31
31
  var blockClass = "".concat(pkg.prefix, "--edit-side-panel");
32
32
  var sidePanelBlockClass = "".concat(pkg.prefix, "--side-panel");
33
33
  var componentName = 'EditSidePanel'; // NOTE: the component SCSS is not imported here: it is rolled up separately.
34
+ // Default values for props
34
35
 
36
+ var defaults = {
37
+ placement: 'right',
38
+ size: 'md'
39
+ };
35
40
  /**
36
41
  * TODO: A description of the component.
37
42
  */
@@ -45,12 +50,14 @@ export var EditSidePanel = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
45
50
  onRequestClose = _ref.onRequestClose,
46
51
  onRequestSubmit = _ref.onRequestSubmit,
47
52
  open = _ref.open,
48
- placement = _ref.placement,
53
+ _ref$placement = _ref.placement,
54
+ placement = _ref$placement === void 0 ? defaults.placement : _ref$placement,
49
55
  primaryButtonText = _ref.primaryButtonText,
50
56
  secondaryButtonText = _ref.secondaryButtonText,
51
57
  selectorPrimaryFocus = _ref.selectorPrimaryFocus,
52
58
  selectorPageContent = _ref.selectorPageContent,
53
- size = _ref.size,
59
+ _ref$size = _ref.size,
60
+ size = _ref$size === void 0 ? defaults.size : _ref$size,
54
61
  slideIn = _ref.slideIn,
55
62
  subtitle = _ref.subtitle,
56
63
  title = _ref.title,
@@ -198,12 +205,4 @@ EditSidePanel.propTypes = {
198
205
  * The title of the CreateSidePanel is usually the product or service name.
199
206
  */
200
207
  title: PropTypes.node.isRequired
201
- }; // Default values for component props. Default values are not required for
202
- // props that are required, nor for props where the component can apply
203
- // 'undefined' values reasonably. Default values should be provided when the
204
- // component needs to make a choice or assumption when a prop is not supplied.
205
-
206
- EditSidePanel.defaultProps = {
207
- placement: 'right',
208
- size: 'md'
209
208
  };
@@ -25,14 +25,19 @@ import { pkg } from '../../settings';
25
25
  import { EmptyStateContent } from './EmptyStateContent'; // The block part of our conventional BEM class names (blockClass__E--M).
26
26
 
27
27
  var blockClass = "".concat(pkg.prefix, "--empty-state");
28
- var componentName = 'EmptyState';
28
+ var componentName = 'EmptyState'; // Default values for props
29
+
30
+ export var defaults = {
31
+ size: 'lg'
32
+ };
29
33
  export var EmptyState = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
30
34
  var action = _ref.action,
31
35
  className = _ref.className,
32
36
  illustration = _ref.illustration,
33
37
  illustrationDescription = _ref.illustrationDescription,
34
38
  link = _ref.link,
35
- size = _ref.size,
39
+ _ref$size = _ref.size,
40
+ size = _ref$size === void 0 ? defaults.size : _ref$size,
36
41
  subtitle = _ref.subtitle,
37
42
  title = _ref.title,
38
43
  rest = _objectWithoutProperties(_ref, _excluded);
@@ -58,9 +63,6 @@ export var EmptyState = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
58
63
  }); // Return a placeholder if not released and not enabled by feature flag
59
64
 
60
65
  EmptyState = pkg.checkComponentEnabled(EmptyState, componentName);
61
- export var EmptyStateDefaultProps = {
62
- size: 'lg'
63
- };
64
66
  EmptyState.propTypes = {
65
67
  /**
66
68
  * Empty state action button
@@ -114,5 +116,4 @@ EmptyState.propTypes = {
114
116
  */
115
117
  title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired
116
118
  };
117
- EmptyState.defaultProps = EmptyStateDefaultProps;
118
119
  EmptyState.displayName = componentName;