@carbon/ibm-products 1.27.0 → 1.31.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. package/css/index-full-carbon.css +513 -75
  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 +512 -74
  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 +513 -75
  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/DraggableElement.js +5 -1
  34. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +5 -40
  35. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +35 -10
  36. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +61 -24
  37. package/es/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  38. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +63 -0
  39. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +1 -0
  40. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +459 -0
  41. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +1 -0
  42. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +112 -0
  43. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +27 -0
  44. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +1 -0
  45. package/es/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +31 -0
  46. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +19 -0
  47. package/es/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +197 -0
  48. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  49. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  50. package/es/components/Datagrid/index.js +3 -1
  51. package/es/components/Datagrid/useColumnOrder.js +8 -0
  52. package/es/components/Datagrid/useCustomizeColumns.js +5 -0
  53. package/es/components/Datagrid/useDisableSelectRows.js +6 -2
  54. package/es/components/Datagrid/useInlineEdit.js +71 -0
  55. package/es/components/Datagrid/useRowSize.js +17 -6
  56. package/es/components/Datagrid/useSelectRows.js +12 -2
  57. package/es/components/Datagrid/useStickyColumn.js +11 -0
  58. package/es/components/Datagrid/utils/getInlineEditColumns.js +121 -0
  59. package/es/components/Datagrid/utils/makeData.js +17 -1
  60. package/es/components/ImportModal/ImportModal.js +2 -2
  61. package/es/components/InlineEdit/InlineEdit.js +4 -2
  62. package/es/components/ProductiveCard/ProductiveCard.js +5 -0
  63. package/es/components/index.js +1 -1
  64. package/es/global/js/hooks/useClickOutside.js +1 -1
  65. package/es/global/js/package-settings.js +3 -3
  66. package/es/global/js/utils/rangeWithCallback.js +13 -0
  67. package/es/global/js/utils/uuidv4.spec.js +4 -0
  68. package/lib/components/AddSelect/AddSelect.js +0 -4
  69. package/lib/components/AddSelect/AddSelectBody.js +20 -3
  70. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +14 -3
  71. package/lib/components/AddSelect/AddSelectColumn.js +3 -2
  72. package/lib/components/AddSelect/AddSelectFilter.js +3 -2
  73. package/lib/components/AddSelect/AddSelectList.js +39 -13
  74. package/lib/components/Card/Card.js +16 -6
  75. package/lib/components/Card/CardFooter.js +3 -1
  76. package/lib/components/Card/CardHeader.js +21 -1
  77. package/lib/components/DataSpreadsheet/DataSpreadsheet.js +62 -10
  78. package/lib/components/DataSpreadsheet/DataSpreadsheetHeader.js +7 -0
  79. package/lib/components/DataSpreadsheet/utils/handleCellDeletion.js +42 -0
  80. package/lib/components/DataSpreadsheet/utils/handleMultipleKeys.js +1 -1
  81. package/lib/components/Datagrid/Datagrid/Datagrid.js +12 -45
  82. package/lib/components/Datagrid/Datagrid/DatagridContent.js +138 -0
  83. package/lib/components/Datagrid/Datagrid/DatagridSelectAll.js +12 -3
  84. package/lib/components/Datagrid/Datagrid/DraggableElement.js +5 -1
  85. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Actions.js +12 -41
  86. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/Columns.js +47 -25
  87. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/CustomizeColumnsModal.js +59 -23
  88. package/lib/components/Datagrid/Datagrid/addons/CustomizeColumns/ModalWrapper.js +3 -2
  89. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/InlineEditButton.js +79 -0
  90. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditButton/index.js +13 -0
  91. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/InlineEditCell.js +483 -0
  92. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditCell/index.js +13 -0
  93. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/InlineEditContext.js +129 -0
  94. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/getCellIdAsObject.js +36 -0
  95. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/index.js +19 -0
  96. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/InlineEditContext/returnUpdatedActiveCell.js +42 -0
  97. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridFocus.js +28 -0
  98. package/lib/components/Datagrid/Datagrid/addons/InlineEdit/handleGridKeyPress.js +204 -0
  99. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +6 -5
  100. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +1 -2
  101. package/lib/components/Datagrid/index.js +17 -1
  102. package/lib/components/Datagrid/useColumnOrder.js +17 -0
  103. package/lib/components/Datagrid/useCustomizeColumns.js +5 -0
  104. package/lib/components/Datagrid/useDisableSelectRows.js +6 -2
  105. package/lib/components/Datagrid/useInlineEdit.js +85 -0
  106. package/lib/components/Datagrid/useRowSize.js +18 -13
  107. package/lib/components/Datagrid/useSelectRows.js +12 -2
  108. package/lib/components/Datagrid/useStickyColumn.js +11 -0
  109. package/lib/components/Datagrid/utils/getInlineEditColumns.js +133 -0
  110. package/lib/components/Datagrid/utils/makeData.js +17 -1
  111. package/lib/components/ImportModal/ImportModal.js +2 -2
  112. package/lib/components/InlineEdit/InlineEdit.js +4 -2
  113. package/lib/components/ProductiveCard/ProductiveCard.js +5 -0
  114. package/lib/components/index.js +12 -0
  115. package/lib/global/js/hooks/useClickOutside.js +1 -1
  116. package/lib/global/js/package-settings.js +3 -3
  117. package/lib/global/js/utils/rangeWithCallback.js +22 -0
  118. package/lib/global/js/utils/uuidv4.spec.js +4 -0
  119. package/package.json +13 -13
  120. package/scss/components/AddSelect/_add-select.scss +126 -28
  121. package/scss/components/Card/_card.scss +1 -0
  122. package/scss/components/Cascade/_cascade.scss +1 -1
  123. package/scss/components/CreateTearsheet/_create-tearsheet.scss +1 -0
  124. package/scss/components/DataSpreadsheet/_data-spreadsheet.scss +18 -1
  125. package/scss/components/Datagrid/_storybook-styles.scss +1 -1
  126. package/scss/components/Datagrid/styles/_datagrid.scss +27 -0
  127. package/scss/components/Datagrid/styles/_draggableElement.scss +26 -9
  128. package/scss/components/Datagrid/styles/_index.scss +1 -0
  129. package/scss/components/Datagrid/styles/_useInlineEdit.scss +211 -0
  130. package/scss/components/Datagrid/styles/_useStickyColumn.scss +24 -2
  131. package/scss/components/Datagrid/styles/addons/_CustomizeColumnsModal.scss +44 -6
  132. package/scss/components/NotificationsPanel/_notifications-panel.scss +5 -6
  133. package/scss/components/ProductiveCard/_productive-card.scss +39 -0
  134. package/scss/components/RemoveModal/_remove-modal.scss +0 -4
  135. package/scss/components/SidePanel/_side-panel.scss +4 -6
  136. package/scss/components/_index-released-only.scss +1 -0
@@ -0,0 +1,459 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
+
5
+ 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; }
6
+
7
+ 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; }
8
+
9
+ /**
10
+ * Copyright IBM Corp. 2022, 2022
11
+ *
12
+ * This source code is licensed under the Apache-2.0 license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ */
15
+ import React, { useState, useRef, useEffect, useContext, useCallback } from 'react';
16
+ import PropTypes from 'prop-types';
17
+ import { TextInput, NumberInput, Dropdown, DatePicker, DatePickerInput } from 'carbon-components-react';
18
+ import { Edit16, CaretSort16, ChevronDown16, Calendar16 } from '@carbon/icons-react';
19
+ import { InlineEditButton } from '../InlineEditButton';
20
+ import { pkg } from '../../../../../../settings';
21
+ import cx from 'classnames';
22
+ import { InlineEditContext } from '../InlineEditContext';
23
+ import { usePreviousValue } from '../../../../../../global/js/hooks';
24
+ import { prepareProps } from '../../../../../../global/js/utils/props-helper';
25
+ var blockClass = "".concat(pkg.prefix, "--datagrid");
26
+ export var InlineEditCell = function InlineEditCell(_ref) {
27
+ var _cx3;
28
+
29
+ var cell = _ref.cell,
30
+ config = _ref.config,
31
+ instance = _ref.instance,
32
+ _ref$placeholder = _ref.placeholder,
33
+ placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
34
+ tabIndex = _ref.tabIndex,
35
+ value = _ref.value,
36
+ _ref$label = _ref.label,
37
+ label = _ref$label === void 0 ? 'Inline edit type text label' : _ref$label,
38
+ nonEditCell = _ref.nonEditCell,
39
+ totalInlineEditColumns = _ref.totalInlineEditColumns,
40
+ type = _ref.type;
41
+ var columnId = cell.column.id;
42
+ var columnIndex = instance.columns.findIndex(function (col) {
43
+ return col.id === columnId;
44
+ });
45
+ var cellId = "column-".concat(columnIndex, "-row-").concat(cell.row.index);
46
+ var totalColumns = instance.columns.length;
47
+
48
+ var _useContext = useContext(InlineEditContext),
49
+ state = _useContext.state,
50
+ dispatch = _useContext.dispatch;
51
+
52
+ var _useState = useState(false),
53
+ _useState2 = _slicedToArray(_useState, 2),
54
+ inEditMode = _useState2[0],
55
+ setInEditMode = _useState2[1];
56
+
57
+ var _useState3 = useState(value),
58
+ _useState4 = _slicedToArray(_useState3, 2),
59
+ cellValue = _useState4[0],
60
+ setCellValue = _useState4[1];
61
+
62
+ var _useState5 = useState(),
63
+ _useState6 = _slicedToArray(_useState5, 2),
64
+ initialValue = _useState6[0],
65
+ setInitialValue = _useState6[1];
66
+
67
+ var activeCellId = state.activeCellId,
68
+ editId = state.editId;
69
+ var previousState = usePreviousValue({
70
+ editId: editId,
71
+ activeCellId: activeCellId
72
+ });
73
+
74
+ var _ref2 = config || {},
75
+ inputProps = _ref2.inputProps;
76
+
77
+ var textInputRef = useRef();
78
+ var numberInputRef = useRef();
79
+ var dropdownRef = useRef();
80
+ var datePickerRef = useRef();
81
+ var outerButtonElement = useRef();
82
+ useEffect(function () {
83
+ setInitialValue(value); // eslint-disable-next-line react-hooks/exhaustive-deps
84
+ }, []); // If you are in edit mode and click outside of the cell,
85
+ // this changes the cell back to the InlineEditButton
86
+
87
+ useEffect(function () {
88
+ if (activeCellId !== cellId || !editId) {
89
+ setInEditMode(false);
90
+ }
91
+
92
+ if (activeCellId === cellId && editId === cellId && !nonEditCell) {
93
+ setInEditMode(true);
94
+ saveCellData(cellValue);
95
+ }
96
+ }, [activeCellId, cellId, nonEditCell, editId, cellValue, saveCellData]);
97
+
98
+ var openDropdown = function openDropdown(type) {
99
+ var _datePickerRef$curren;
100
+
101
+ var dropdownTrigger = type === 'selection' ? dropdownRef === null || dropdownRef === void 0 ? void 0 : dropdownRef.current : datePickerRef === null || datePickerRef === void 0 ? void 0 : (_datePickerRef$curren = datePickerRef.current) === null || _datePickerRef$curren === void 0 ? void 0 : _datePickerRef$curren.inputField;
102
+ dropdownTrigger.click();
103
+
104
+ if (type === 'date') {
105
+ // datePickerRef.current.cal.calendarContainer.focus();
106
+ dropdownTrigger === null || dropdownTrigger === void 0 ? void 0 : dropdownTrigger.focus();
107
+ }
108
+ }; // Re-initializes initialValue if clicking outside of a cell that was previously
109
+ // in edit mode, otherwise `initialValue` becomes stale
110
+
111
+
112
+ useEffect(function () {
113
+ if ((previousState === null || previousState === void 0 ? void 0 : previousState.editId) === cellId && (previousState === null || previousState === void 0 ? void 0 : previousState.activeCellId) === cellId && activeCellId !== cellId) {
114
+ setInitialValue(cellValue);
115
+ }
116
+ }, [previousState, cellId, cellValue, activeCellId]);
117
+
118
+ var handleInlineCellClick = function handleInlineCellClick() {
119
+ if (!inEditMode) {
120
+ dispatch({
121
+ type: 'ENTER_EDIT_MODE',
122
+ payload: {
123
+ activeCellId: cellId,
124
+ editId: cellId
125
+ }
126
+ });
127
+ setInEditMode(true);
128
+ setTimeout(function () {
129
+ if (type === 'selection' || type === 'date') {
130
+ openDropdown(type);
131
+ }
132
+ }, 1);
133
+ }
134
+ };
135
+
136
+ var rowSize = instance.rowSize,
137
+ onDataUpdate = instance.onDataUpdate; // Auto focus text input when entering edit mode
138
+
139
+ useEffect(function () {
140
+ if (inEditMode) {
141
+ if (type === 'text') {
142
+ textInputRef.current.focus();
143
+ }
144
+
145
+ if (type === 'number') {
146
+ numberInputRef.current.focus();
147
+ }
148
+ }
149
+ }, [inEditMode, type]); // Initialize cellValue from value prop
150
+
151
+ useEffect(function () {
152
+ setCellValue(value);
153
+ }, [value]); // Saves the new cell data, onDataUpdate is a required function to be
154
+ // passed to useDatagrid when using useInlineEdit
155
+
156
+ var saveCellData = useCallback(function (newValue) {
157
+ var columnId = cell.column.id;
158
+ var rowIndex = cell.row.index;
159
+ onDataUpdate(function (prev) {
160
+ return prev.map(function (row, index) {
161
+ if (index === rowIndex) {
162
+ return _objectSpread(_objectSpread({}, prev[rowIndex]), {}, _defineProperty({}, columnId, newValue));
163
+ }
164
+
165
+ return row;
166
+ });
167
+ });
168
+ }, [cell, onDataUpdate]);
169
+
170
+ var sendFocusBackToGrid = function sendFocusBackToGrid() {
171
+ // Allows the onKeyDown listener to go back to the entire grid area
172
+ var inlineEditArea = document.querySelector("#".concat(instance.tableId, " .").concat(blockClass, "__table-with-inline-edit"));
173
+ inlineEditArea.focus();
174
+ };
175
+
176
+ var getNewCellId = function getNewCellId(key) {
177
+ var totalRows = instance.rows.length;
178
+ var newCellId = key === 'Enter' ? "column-".concat(columnIndex, "-row-").concat(cell.row.index < totalRows - 1 ? cell.row.index + 1 : cell.row.index) : "column-".concat(columnIndex < instance.columns.length - 1 ? columnIndex + 1 : columnIndex, "-row-").concat(cell.row.index);
179
+ return newCellId;
180
+ };
181
+
182
+ var handleKeyDown = function handleKeyDown(event) {
183
+ var key = event.key;
184
+
185
+ switch (key) {
186
+ // Save cell contents to data
187
+ case 'Tab':
188
+ case 'Enter':
189
+ {
190
+ if (inEditMode) {
191
+ // Dropdown saves are handled in the Dropdown's/DatePicker's onChange prop
192
+ if (type === 'selection' || type === 'date') {
193
+ return;
194
+ }
195
+
196
+ var newCellId = getNewCellId(key);
197
+ saveCellData(cellValue);
198
+ setInitialValue(cellValue);
199
+ dispatch({
200
+ type: 'EXIT_EDIT_MODE',
201
+ payload: newCellId
202
+ });
203
+ setInEditMode(false);
204
+ sendFocusBackToGrid();
205
+ }
206
+
207
+ break;
208
+ }
209
+
210
+ case 'Escape':
211
+ {
212
+ if (inEditMode) {
213
+ dispatch({
214
+ type: 'EXIT_EDIT_MODE',
215
+ payload: cellId
216
+ });
217
+ setCellValue(initialValue);
218
+ saveCellData(initialValue);
219
+ setInEditMode(false);
220
+ sendFocusBackToGrid();
221
+ }
222
+
223
+ break;
224
+ }
225
+
226
+ default:
227
+ return;
228
+ }
229
+ };
230
+
231
+ var addActiveState = function addActiveState() {
232
+ dispatch({
233
+ type: 'UPDATE_ACTIVE_CELL_ID',
234
+ payload: cellId
235
+ });
236
+ };
237
+
238
+ var renderDropdownItem = function renderDropdownItem(item) {
239
+ var includesIcon = !!(item !== null && item !== void 0 && item.icon);
240
+ return includesIcon ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(item.icon), /*#__PURE__*/React.createElement("span", {
241
+ className: cx("".concat(blockClass, "__inline-edit--select-item"))
242
+ }, item === null || item === void 0 ? void 0 : item.text)) : item === null || item === void 0 ? void 0 : item.text;
243
+ };
244
+
245
+ var renderSelectCell = function renderSelectCell() {
246
+ var _ref3 = config || {},
247
+ inputProps = _ref3.inputProps;
248
+
249
+ return /*#__PURE__*/React.createElement(Dropdown, _extends({
250
+ id: cellId,
251
+ label: "Dropdown menu options"
252
+ }, inputProps, {
253
+ hideLabel: true,
254
+ style: {
255
+ width: cell.column.totalWidth
256
+ },
257
+ className: cx("".concat(blockClass, "__inline-edit--select"), _defineProperty({}, "".concat(blockClass, "__inline-edit--select-").concat(rowSize), rowSize)),
258
+ items: (inputProps === null || inputProps === void 0 ? void 0 : inputProps.items) || [],
259
+ initialSelectedItem: cell.value,
260
+ itemToElement: function itemToElement(item) {
261
+ return renderDropdownItem(item);
262
+ },
263
+ renderSelectedItem: function renderSelectedItem(item) {
264
+ return renderDropdownItem(item);
265
+ },
266
+ onChange: function onChange(item) {
267
+ var _inputProps$onChange;
268
+
269
+ var newCellId = getNewCellId('Enter');
270
+ saveCellData(item.selectedItem);
271
+ setCellValue(item.selectedItem);
272
+ dispatch({
273
+ type: 'EXIT_EDIT_MODE',
274
+ payload: newCellId
275
+ });
276
+ setInEditMode(false);
277
+ sendFocusBackToGrid();
278
+ inputProps === null || inputProps === void 0 ? void 0 : (_inputProps$onChange = inputProps.onChange) === null || _inputProps$onChange === void 0 ? void 0 : _inputProps$onChange.call(inputProps, item.selectedItem);
279
+ },
280
+ downshiftProps: {
281
+ onStateChange: function onStateChange(downshiftState) {
282
+ var _ref4 = downshiftState || {},
283
+ isOpen = _ref4.isOpen; // !isOpen does not work in this case because a state change occurs on hover of the
284
+ // menu items and isOpen is changed to undefined which causes dispatch to be called unexpectedly
285
+
286
+
287
+ if (isOpen === false) {
288
+ dispatch({
289
+ type: 'EXIT_EDIT_MODE',
290
+ payload: cellId
291
+ });
292
+ setInEditMode(false);
293
+ sendFocusBackToGrid();
294
+ }
295
+ }
296
+ },
297
+ ref: dropdownRef
298
+ }));
299
+ };
300
+
301
+ var setRenderIcon = function setRenderIcon() {
302
+ if (type === 'text') {
303
+ return Edit16;
304
+ }
305
+
306
+ if (type === 'number') {
307
+ return CaretSort16;
308
+ }
309
+
310
+ if (type === 'selection') {
311
+ return ChevronDown16;
312
+ }
313
+
314
+ if (type === 'date') {
315
+ return Calendar16;
316
+ }
317
+ };
318
+
319
+ var renderDateCell = function renderDateCell() {
320
+ var _config$inputProps, _outerButtonElement$c;
321
+
322
+ var datePickerPreparedProps = prepareProps(config.inputProps, ['datePickerInputProps']);
323
+ var datePickerInputProps = config === null || config === void 0 ? void 0 : (_config$inputProps = config.inputProps) === null || _config$inputProps === void 0 ? void 0 : _config$inputProps.datePickerInputProps;
324
+ return /*#__PURE__*/React.createElement(DatePicker, _extends({}, datePickerPreparedProps, {
325
+ appendTo: outerButtonElement === null || outerButtonElement === void 0 ? void 0 : (_outerButtonElement$c = outerButtonElement.current) === null || _outerButtonElement$c === void 0 ? void 0 : _outerButtonElement$c.parentElement,
326
+ ref: datePickerRef,
327
+ style: {
328
+ width: cell.column.totalWidth
329
+ },
330
+ datePickerType: "single",
331
+ className: cx("".concat(blockClass, "__inline-edit--date"), _defineProperty({}, "".concat(blockClass, "__inline-edit--date-").concat(rowSize), rowSize)),
332
+ onChange: function onChange(newDate) {
333
+ var _datePickerPreparedPr;
334
+
335
+ var newDateObj = newDate[0];
336
+ datePickerPreparedProps === null || datePickerPreparedProps === void 0 ? void 0 : (_datePickerPreparedPr = datePickerPreparedProps.onChange) === null || _datePickerPreparedPr === void 0 ? void 0 : _datePickerPreparedPr.call(datePickerPreparedProps, newDateObj, cell);
337
+ var newCellId = getNewCellId('Enter');
338
+ saveCellData(newDateObj);
339
+ setCellValue(newDateObj);
340
+ setInEditMode(false);
341
+ sendFocusBackToGrid();
342
+ dispatch({
343
+ type: 'EXIT_EDIT_MODE',
344
+ payload: newCellId
345
+ });
346
+ },
347
+ value: cell.value
348
+ }), /*#__PURE__*/React.createElement(DatePickerInput, _extends({}, datePickerInputProps, {
349
+ style: {
350
+ position: 'static'
351
+ },
352
+ placeholder: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.placeholder) || 'mm/dd/yyyy',
353
+ labelText: (datePickerInputProps === null || datePickerInputProps === void 0 ? void 0 : datePickerInputProps.labelText) || 'Set date',
354
+ id: datePickerInputProps.id || "".concat(blockClass, "__inline-edit--date-picker--").concat(cell.row.index),
355
+ hideLabel: true
356
+ })));
357
+ }; // Ensures that months and days are all 2 digits, prefixes 0 if `num` is a single digit
358
+
359
+
360
+ var padTo2Digits = function padTo2Digits(num) {
361
+ return num.toString().padStart(2, '0');
362
+ };
363
+
364
+ var buildDate = function buildDate(value) {
365
+ if (value instanceof Date) {
366
+ var _config$dateFormat = config.dateFormat,
367
+ dateFormat = _config$dateFormat === void 0 ? 'm/d/Y' : _config$dateFormat;
368
+ var maskedFullYear = value.getFullYear();
369
+ var maskedMonth = padTo2Digits(value.getMonth() + 1);
370
+ var maskedDay = padTo2Digits(value.getDate());
371
+
372
+ if (dateFormat === 'm/d/Y' || dateFormat === 'm/d/y') {
373
+ return [maskedMonth, maskedDay, maskedFullYear].join('/');
374
+ }
375
+
376
+ if (dateFormat === 'd/m/Y' || dateFormat === 'd/m/y') {
377
+ return [maskedDay, maskedMonth, maskedFullYear].join('/');
378
+ }
379
+ }
380
+
381
+ return null;
382
+ };
383
+
384
+ return (
385
+ /*#__PURE__*/
386
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
387
+ React.createElement("div", {
388
+ ref: outerButtonElement,
389
+ "data-cell-id": cellId,
390
+ "data-column-index": columnIndex,
391
+ "data-row-index": cell.row.index,
392
+ "data-disabled": nonEditCell,
393
+ "data-inline-type": type,
394
+ onClick: !nonEditCell ? handleInlineCellClick : addActiveState,
395
+ onKeyDown: !nonEditCell ? handleKeyDown : null,
396
+ className: cx("".concat(blockClass, "__inline-edit--outer-cell-button"), (_cx3 = {}, _defineProperty(_cx3, "".concat(blockClass, "__inline-edit--outer-cell-button--").concat(rowSize), rowSize), _defineProperty(_cx3, "".concat(blockClass, "__inline-edit--outer-cell-button--lg"), !rowSize), _cx3))
397
+ }, !inEditMode && /*#__PURE__*/React.createElement(InlineEditButton, {
398
+ isActiveCell: cellId === activeCellId,
399
+ renderIcon: setRenderIcon(),
400
+ label: type === 'selection' ? value.text : type === 'date' ? buildDate(value) : value,
401
+ labelIcon: (value === null || value === void 0 ? void 0 : value.icon) || null,
402
+ placeholder: placeholder,
403
+ tabIndex: tabIndex,
404
+ nonEditCell: nonEditCell,
405
+ columnConfig: cell.column,
406
+ totalInlineEditColumns: totalInlineEditColumns,
407
+ totalColumns: totalColumns,
408
+ type: type
409
+ }), !nonEditCell && inEditMode && cellId === activeCellId && /*#__PURE__*/React.createElement(React.Fragment, null, type === 'text' && /*#__PURE__*/React.createElement(TextInput, _extends({
410
+ labelText: label,
411
+ placeholder: placeholder
412
+ }, inputProps, {
413
+ id: cellId,
414
+ hideLabel: true,
415
+ defaultValue: cellValue,
416
+ onChange: function onChange(event) {
417
+ setCellValue(event.target.value);
418
+
419
+ if (inputProps.onChange) {
420
+ inputProps.onChange(event.target.value);
421
+ }
422
+ },
423
+ ref: textInputRef
424
+ })), type === 'number' && /*#__PURE__*/React.createElement(NumberInput, _extends({
425
+ placeholder: placeholder,
426
+ label: label
427
+ }, inputProps, {
428
+ id: cellId,
429
+ hideLabel: true,
430
+ defaultValue: cellValue,
431
+ onChange: function onChange(event) {
432
+ setCellValue(event.imaginaryTarget.value);
433
+
434
+ if (inputProps.onChange) {
435
+ inputProps.onChange(event.imaginaryTarget.value);
436
+ }
437
+ },
438
+ ref: numberInputRef
439
+ })), type === 'selection' && renderSelectCell(), type === 'date' && renderDateCell()))
440
+ );
441
+ };
442
+ InlineEditCell.propTypes = {
443
+ cell: PropTypes.object,
444
+ config: PropTypes.object,
445
+ instance: PropTypes.shape({
446
+ columns: PropTypes.arrayOf(PropTypes.object),
447
+ onDataUpdate: PropTypes.func,
448
+ rows: PropTypes.arrayOf(PropTypes.object),
449
+ rowSize: PropTypes.string,
450
+ tableId: PropTypes.string
451
+ }),
452
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
453
+ nonEditCell: PropTypes.bool,
454
+ placeholder: PropTypes.string,
455
+ tabIndex: PropTypes.number,
456
+ totalInlineEditColumns: PropTypes.number,
457
+ type: PropTypes.oneOf(['text', 'number', 'selection', 'date']),
458
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.node, PropTypes.object])
459
+ };
@@ -0,0 +1 @@
1
+ export { InlineEditCell } from './InlineEditCell';
@@ -0,0 +1,112 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+
4
+ 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; }
5
+
6
+ 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; }
7
+
8
+ /**
9
+ * Copyright IBM Corp. 2022, 2022
10
+ *
11
+ * This source code is licensed under the Apache-2.0 license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ */
14
+ import React, { createContext, useReducer } from 'react';
15
+ import PropTypes from 'prop-types';
16
+ import { returnUpdatedActiveCell } from './returnUpdatedActiveCell';
17
+ import { getCellIdAsObject } from './getCellIdAsObject';
18
+ export var InlineEditContext = /*#__PURE__*/createContext();
19
+
20
+ var inlineEditReducer = function inlineEditReducer(state, action) {
21
+ switch (action.type) {
22
+ case 'ADD_GRID_ACTIVE_FOCUS':
23
+ {
24
+ return _objectSpread(_objectSpread({}, state), {}, {
25
+ gridActive: true,
26
+ activeCellId: action.payload,
27
+ // set default active cell when grid receives focus
28
+ previousActiveCellId: null
29
+ });
30
+ }
31
+
32
+ case 'REMOVE_GRID_ACTIVE_FOCUS':
33
+ {
34
+ return _objectSpread(_objectSpread({}, state), {}, {
35
+ gridActive: false,
36
+ editId: null,
37
+ activeCellId: null,
38
+ previousActiveCellId: action.payload
39
+ });
40
+ }
41
+
42
+ case 'ENTER_EDIT_MODE':
43
+ {
44
+ return _objectSpread(_objectSpread({}, state), {}, {
45
+ activeCellId: action.payload.activeCellId,
46
+ editId: action.payload.editId
47
+ });
48
+ }
49
+
50
+ case 'EXIT_EDIT_MODE':
51
+ {
52
+ return _objectSpread(_objectSpread({}, state), {}, {
53
+ activeCellId: action.payload,
54
+ editId: null
55
+ });
56
+ }
57
+
58
+ case 'UPDATE_ACTIVE_CELL_ID':
59
+ {
60
+ var _action$payload = action.payload,
61
+ direction = _action$payload.direction,
62
+ oldId = _action$payload.oldId,
63
+ instance = _action$payload.instance;
64
+
65
+ if (!action.payload.direction) {
66
+ return _objectSpread(_objectSpread({}, state), {}, {
67
+ activeCellId: action.payload,
68
+ editId: null
69
+ });
70
+ }
71
+
72
+ if (direction && typeof direction === 'string') {
73
+ var activeCellCoords = getCellIdAsObject(oldId);
74
+ var totalVisibleColumns = instance.visibleColumns.filter(function (item) {
75
+ return item.id !== 'spacer';
76
+ });
77
+ return returnUpdatedActiveCell({
78
+ activeCellCoords: activeCellCoords,
79
+ direction: direction,
80
+ totalVisibleColumns: totalVisibleColumns,
81
+ state: state,
82
+ instance: instance
83
+ });
84
+ }
85
+
86
+ break;
87
+ }
88
+
89
+ default:
90
+ return state;
91
+ }
92
+ };
93
+
94
+ export var InlineEditProvider = function InlineEditProvider(_ref) {
95
+ var children = _ref.children;
96
+ var initialState = {};
97
+
98
+ var _useReducer = useReducer(inlineEditReducer, initialState),
99
+ _useReducer2 = _slicedToArray(_useReducer, 2),
100
+ state = _useReducer2[0],
101
+ dispatch = _useReducer2[1];
102
+
103
+ return /*#__PURE__*/React.createElement(InlineEditContext.Provider, {
104
+ value: {
105
+ state: state,
106
+ dispatch: dispatch
107
+ }
108
+ }, children);
109
+ };
110
+ InlineEditProvider.propTypes = {
111
+ children: PropTypes.element
112
+ };
@@ -0,0 +1,27 @@
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
+ // Turns activeCellId into an object to be able to
8
+ // update cell coordinates more easily
9
+ export var getCellIdAsObject = function getCellIdAsObject(oldId) {
10
+ var oldIdArr = oldId.split('-');
11
+ var updatedOldValuesArray = oldIdArr.map(function (item) {
12
+ if (isNaN(item)) {
13
+ return item;
14
+ }
15
+
16
+ return Number(item);
17
+ });
18
+ var indexArray = updatedOldValuesArray.filter(Number.isFinite);
19
+ var keyArray = updatedOldValuesArray.filter(function (item) {
20
+ return typeof item === 'string';
21
+ });
22
+ var activeCellCoords = {};
23
+ keyArray.forEach(function (element, index) {
24
+ activeCellCoords[element] = indexArray[index];
25
+ });
26
+ return activeCellCoords;
27
+ };
@@ -0,0 +1 @@
1
+ export { InlineEditProvider, InlineEditContext } from './InlineEditContext';
@@ -0,0 +1,31 @@
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
+ /**
8
+ * Copyright IBM Corp. 2022, 2022
9
+ *
10
+ * This source code is licensed under the Apache-2.0 license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ // This function returns the state back to the reducer after
14
+ // determining the new active cell value
15
+ export var returnUpdatedActiveCell = function returnUpdatedActiveCell(_ref) {
16
+ var activeCellCoords = _ref.activeCellCoords,
17
+ direction = _ref.direction,
18
+ totalVisibleColumns = _ref.totalVisibleColumns,
19
+ state = _ref.state,
20
+ instance = _ref.instance;
21
+
22
+ var newActiveCoords = _objectSpread(_objectSpread({}, activeCellCoords), {}, {
23
+ column: direction === 'right' ? activeCellCoords.column < totalVisibleColumns.length - 1 ? activeCellCoords.column + 1 : activeCellCoords.column : direction === 'left' ? activeCellCoords.column === 0 ? 0 : activeCellCoords.column - 1 : activeCellCoords.column,
24
+ row: direction === 'up' ? activeCellCoords.row === 0 ? 0 : activeCellCoords.row - 1 : direction === 'down' ? activeCellCoords.row < instance.rows.length - 1 ? activeCellCoords.row + 1 : activeCellCoords.row : activeCellCoords.row
25
+ });
26
+
27
+ var newActiveCellId = "column-".concat(newActiveCoords.column, "-row-").concat(newActiveCoords.row);
28
+ return _objectSpread(_objectSpread({}, state), {}, {
29
+ activeCellId: newActiveCellId
30
+ });
31
+ };
@@ -0,0 +1,19 @@
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
+ export var handleGridFocus = function handleGridFocus(state, dispatch) {
8
+ var gridActive = state.gridActive,
9
+ previousActiveCellId = state.previousActiveCellId;
10
+
11
+ if (!gridActive) {
12
+ // Initialize grid active state
13
+ dispatch({
14
+ type: 'ADD_GRID_ACTIVE_FOCUS',
15
+ payload: previousActiveCellId || 'column-0-row-0' // If there is a previous active cell id that is found use that, otherwise use the first cell in the grid area
16
+
17
+ });
18
+ }
19
+ };