@carbon/ibm-products 1.35.1 → 1.35.2

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 (50) hide show
  1. package/css/index-full-carbon.css +257 -237
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +2 -2
  4. package/css/index-full-carbon.min.css.map +1 -1
  5. package/css/index-without-carbon-released-only.css.map +1 -1
  6. package/css/index-without-carbon-released-only.min.css.map +1 -1
  7. package/css/index-without-carbon.css +257 -237
  8. package/css/index-without-carbon.css.map +1 -1
  9. package/css/index-without-carbon.min.css +2 -2
  10. package/css/index-without-carbon.min.css.map +1 -1
  11. package/css/index.css +257 -237
  12. package/css/index.css.map +1 -1
  13. package/css/index.min.css +2 -2
  14. package/css/index.min.css.map +1 -1
  15. package/es/components/Datagrid/Datagrid/DatagridContent.js +1 -1
  16. package/es/components/Datagrid/Datagrid/DatagridRow.js +3 -3
  17. package/es/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  18. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +1 -1
  19. package/es/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +4 -3
  20. package/es/components/Datagrid/useRowExpander.js +13 -1
  21. package/es/components/InlineEdit/InlineEdit.js +22 -385
  22. package/es/components/InlineEditV1/InlineEditV1.js +406 -0
  23. package/es/components/InlineEditV1/index.js +8 -0
  24. package/es/components/InlineEditV2/InlineEditV2.js +48 -21
  25. package/es/components/InlineEditV2/index.js +7 -0
  26. package/es/components/index.js +1 -1
  27. package/es/global/js/package-settings.js +1 -0
  28. package/lib/components/Datagrid/Datagrid/DatagridContent.js +1 -1
  29. package/lib/components/Datagrid/Datagrid/DatagridRow.js +3 -3
  30. package/lib/components/Datagrid/Datagrid/DatagridToolbar.js +4 -2
  31. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeDropdown.js +1 -1
  32. package/lib/components/Datagrid/Datagrid/addons/RowSize/RowSizeRadioGroup.js +4 -3
  33. package/lib/components/Datagrid/useColumnOrder.js +2 -1
  34. package/lib/components/Datagrid/useRowExpander.js +13 -1
  35. package/lib/components/InlineEdit/InlineEdit.js +22 -379
  36. package/lib/components/InlineEditV1/InlineEditV1.js +403 -0
  37. package/lib/components/InlineEditV1/index.js +12 -0
  38. package/lib/components/InlineEditV2/InlineEditV2.js +38 -20
  39. package/lib/components/index.js +1 -1
  40. package/lib/global/js/package-settings.js +1 -0
  41. package/package.json +10 -10
  42. package/scss/components/Datagrid/styles/_useExpandedRow.scss +18 -0
  43. package/scss/components/{InlineEdit → InlineEditV1}/_index.scss +1 -1
  44. package/scss/components/{InlineEdit/_inline-edit.scss → InlineEditV1/_inline-edit-v1.scss} +0 -0
  45. package/scss/components/{InlineEdit → InlineEditV1}/_storybook-styles.scss +0 -0
  46. package/scss/components/InlineEditV2/_index.scss +1 -1
  47. package/scss/components/InlineEditV2/_inline-edit-v2.scss +5 -1
  48. package/scss/components/InlineEditV2/_storybook-styles.scss +6 -0
  49. package/scss/components/_index-released-only.scss +1 -1
  50. package/scss/components/_index.scss +2 -1
@@ -1,9 +1,8 @@
1
- import _extends from "@babel/runtime/helpers/extends";
2
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _typeof from "@babel/runtime/helpers/typeof";
4
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
6
- var _excluded = ["buttonTooltipAlignment", "buttonTooltipPosition", "cancelDescription", "className", "disabled", "editAlwaysVisible", "editDescription", "id", "invalid", "invalidText", "labelText", "light", "onCancel", "onSave", "onChange", "placeholder", "saveDescription", "size", "value"];
3
+ var _excluded = ["v2"];
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
+ 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
6
  /**
8
7
  * Copyright IBM Corp. 2022, 2022
9
8
  *
@@ -11,395 +10,33 @@ var _excluded = ["buttonTooltipAlignment", "buttonTooltipPosition", "cancelDescr
11
10
  * LICENSE file in the root directory of this source tree.
12
11
  */
13
12
 
14
- // Import portions of React that are needed.
15
- import React, { useRef, useState } from 'react';
16
-
17
- // Other standard imports.
13
+ import React, { forwardRef } from 'react';
18
14
  import PropTypes from 'prop-types';
19
- import cx from 'classnames';
20
- import { getDevtoolsProps } from '../../global/js/utils/devtools';
21
- import { pkg, carbon } from '../../settings';
22
-
23
- // Carbon and package components we use.
24
- /* TODO: @import(s) of carbon components and other package components. */
25
- import { Button } from 'carbon-components-react';
26
- import { Close16, Edit16, EditOff16, Checkmark16, WarningFilled16 } from '@carbon/icons-react';
27
-
28
- // The block part of our conventional BEM class names (blockClass__E--M).
29
- var blockClass = "".concat(pkg.prefix, "--inline-edit");
30
- var componentName = 'InlineEdit';
31
- // NOTE: the component SCSS is not imported here: it is rolled up separately.
32
-
33
- var defaults = {
34
- buttonTooltipAlignment: 'center',
35
- buttonTooltipPosition: 'top',
36
- light: true,
37
- // defaults to true to reflect design
38
- size: 'md'
39
- };
40
- var buttons = ['cancel', 'edit', 'save'];
15
+ import { pkg } from '../../settings';
16
+ import { InlineEditV1 } from '../InlineEditV1';
17
+ import { InlineEditV2 } from '../InlineEditV2';
41
18
 
42
19
  /**
43
- * TODO: A description of the component.
20
+ * this is a wrapper component that will allow us to support v1 and v2 versions of InlineEdit
21
+ * if the user passes in the v2 feature flag the v2 version of the component will be rendered
22
+ * since this is a temporary solution the named export should just remain InlineEdit unlike how
23
+ * Card works as a base layer for Productive and Expressive cards.
44
24
  */
45
- export var InlineEdit = /*#__PURE__*/React.forwardRef(function (_ref, refIn) {
46
- var _cx, _refInput$current, _refInput$current$tex, _cx3;
47
- var buttonTooltipAlignment = _ref.buttonTooltipAlignment,
48
- buttonTooltipPosition = _ref.buttonTooltipPosition,
49
- cancelDescription = _ref.cancelDescription,
50
- className = _ref.className,
51
- disabled = _ref.disabled,
52
- editAlwaysVisible = _ref.editAlwaysVisible,
53
- editDescription = _ref.editDescription,
54
- id = _ref.id,
55
- invalid = _ref.invalid,
56
- invalidText = _ref.invalidText,
57
- labelText = _ref.labelText,
58
- _ref$light = _ref.light,
59
- light = _ref$light === void 0 ? defaults.light : _ref$light,
60
- onCancel = _ref.onCancel,
61
- onSave = _ref.onSave,
62
- onChange = _ref.onChange,
63
- placeholder = _ref.placeholder,
64
- saveDescription = _ref.saveDescription,
65
- _ref$size = _ref.size,
66
- size = _ref$size === void 0 ? defaults.size : _ref$size,
67
- value = _ref.value,
25
+
26
+ var componentName = 'InlineEdit';
27
+ export var InlineEdit = /*#__PURE__*/forwardRef(function (_ref, ref) {
28
+ var v2 = _ref.v2,
68
29
  rest = _objectWithoutProperties(_ref, _excluded);
69
- var refInput = useRef({
70
- textContent: value
30
+ var props = _objectSpread(_objectSpread({}, rest), {}, {
31
+ ref: ref
71
32
  });
72
- var localRef = useRef(null);
73
- var ref = refIn || localRef;
74
- var _useState = useState(false),
75
- _useState2 = _slicedToArray(_useState, 2),
76
- editing = _useState2[0],
77
- setEditing = _useState2[1];
78
- var _useState3 = useState(value),
79
- _useState4 = _slicedToArray(_useState3, 2),
80
- internalValue = _useState4[0],
81
- setInternalValue = _useState4[1];
82
- var showValidation = invalid; // || warn;
83
- var validationText = invalidText; // || warnText;
84
- var validationIcon = showValidation ? /*#__PURE__*/React.createElement(WarningFilled16, null) : null;
85
-
86
- // sanitize the tooltip values
87
- var alignIsObject = _typeof(buttonTooltipAlignment) === 'object';
88
- var directionIsObject = _typeof(buttonTooltipPosition) === 'object';
89
- var tipPositions = buttons.reduce(function (acc, button) {
90
- var _ref2, _ref3;
91
- var tooltipAlignment = (_ref2 = alignIsObject ? buttonTooltipAlignment[button] : buttonTooltipAlignment) !== null && _ref2 !== void 0 ? _ref2 : defaults.buttonTooltipAlignment;
92
- var tooltipPosition = (_ref3 = directionIsObject ? buttonTooltipPosition[button] : buttonTooltipPosition) !== null && _ref3 !== void 0 ? _ref3 : defaults.buttonTooltipPosition;
93
- acc[button] = {
94
- tooltipAlignment: tooltipAlignment,
95
- tooltipPosition: tooltipPosition
96
- };
97
- return acc;
98
- }, {});
99
- var doSetEditing = function doSetEditing(value) {
100
- if (value === false) {
101
- // move scroll to start
102
- refInput.current.scrollLeft = 0;
103
- }
104
- setEditing(!disabled && value);
105
- };
106
- var handleEdit = function handleEdit(ev) {
107
- /* istanbul ignore else */
108
- if (!disabled) {
109
- var rightOfInput = ev.currentTarget.classList.contains("".concat(blockClass, "__edit")) || ev.target.classList.contains("".concat(blockClass, "__after-input-elements"));
110
- var leftOfInput = ev.currentTarget = ev.target.classList.contains("".concat(blockClass));
111
-
112
- // clicking on the content editable element should not set either of these to true
113
- if (rightOfInput || leftOfInput) {
114
- doSetEditing(true);
115
- setTimeout(function () {
116
- refInput.current.focus();
117
- // select all the content
118
- document.getSelection().selectAllChildren(refInput.current);
119
- if (rightOfInput) {
120
- document.getSelection().collapseToEnd();
121
- refInput.current.scrollLeft = 9999; // never going to get there but ensures at end.
122
- } else {
123
- document.getSelection().collapseToStart();
124
- refInput.current.scrollLeft = 0; // scroll to start
125
- }
126
- }, 0);
127
- }
128
- }
129
- };
130
- var handleFocus = function handleFocus(ev) {
131
- ev.preventDefault();
132
- if (!editing && ev.target.classList.contains("".concat(blockClass, "__input"))) {
133
- doSetEditing(true);
134
- }
135
- };
136
- var handleSave = function handleSave() {
137
- doSetEditing(false);
138
- document.getSelection().removeAllRanges();
139
- if (onSave) {
140
- onSave(refInput.current.textContent);
141
- }
142
- };
143
- var handleInput = function handleInput() {
144
- setInternalValue(refInput.current.textContent);
145
- if (onChange) {
146
- onChange(refInput.current.textContent);
147
- }
148
- };
149
-
150
- // pasting into contentEditable not supported by userEvent
151
- var handlePaste = /* istanbul ignore next */function handlePaste(ev) {
152
- ev.preventDefault();
153
-
154
- // Get clipboard as plain text
155
- var text = (ev.clipboardData || window.clipboardData).getData('text/plain');
156
-
157
- // remove \n
158
- var sanitizedText = text.replaceAll(/\n/g, '') // remove carriage returns
159
- .replaceAll(/\t/g, ' '); // replace tab with two spaces
160
-
161
- if (document.queryCommandSupported('insertText')) {
162
- document.execCommand('insertText', false, sanitizedText);
163
- } else {
164
- // Insert text at the current position of caret
165
- var range = document.getSelection().getRangeAt(0);
166
- range.deleteContents();
167
- var textNode = document.createTextNode(sanitizedText);
168
- range.insertNode(textNode);
169
- // move selection end of textNode
170
- range.selectNodeContents(textNode);
171
- range.collapse(false);
172
-
173
- // remove existing range
174
- var selection = document.getSelection();
175
- selection.removeAllRanges();
176
-
177
- // set the new range
178
- selection.addRange(range);
179
- }
180
- };
181
- var handleCancel = function handleCancel() {
182
- refInput.current.textContent = value;
183
- handleInput(value);
184
- doSetEditing(false);
185
- document.getSelection().removeAllRanges();
186
- if (onCancel) {
187
- onCancel(value);
188
- }
189
- };
190
- var handleBlur = function handleBlur(ev) {
191
- if (!ref.current.contains(ev.relatedTarget)) {
192
- handleSave();
193
- }
194
- };
195
- var handleKeyDown = function handleKeyDown(ev) {
196
- switch (ev.key) {
197
- case 'Enter':
198
- ev.preventDefault();
199
- refInput.current.blur(); // will cause save
200
- break;
201
- case 'Escape':
202
- handleCancel();
203
- break;
204
- }
205
- };
206
-
207
- /*
208
- The HTML is structured as follows:
209
- <container>
210
- <!-- margin left of input to match Carbon -->
211
- <content-editable>
212
- <-- margin right of input space for after-input-elements -->
213
- <after-input-elements>
214
- </container>
215
- NOTE:
216
- - An input is not used as this would not permit a heading tag e.g. <h2>.
217
- - Some padding is added to the left 16px standard for a Carbon text input
218
- - The after-input-elements are position absolute with a margin to on the input to reserve space. Using inline-flex
219
- - does not measure space properly for the input otherwise.
220
- - The content editable is not expected to change size when buttons are added, to ensure the text does not move space
221
- is reserved up front for buttons and invalid icon. Mostly this is only noticed if the width of the component is not 100%.
222
- which can be shown by setting inlineEditFullWidth to false in storybook.
223
- In making content-editable behave like an input of type text we have to account for.
224
- - Enforcing a single line
225
- - Pasting of non-text e.g. html or text with carriage returns
226
- - The padding and border not hiding typed in text.
227
- - Placing the cursor at the start or end depending on area clicked (before for left-padding)
228
- */
229
-
230
- var toolbarAnimation = true;
231
- return (
232
- /*#__PURE__*/
233
- // eslint-disable-next-line
234
- React.createElement("div", {
235
- className: cx(blockClass,
236
- // Apply the block class to the main HTML element
237
- className, // Apply any supplied class names to the main HTML element.
238
- "".concat(blockClass, "--").concat(size), (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "--disabled"), disabled), _defineProperty(_cx, "".concat(blockClass, "--editing"), editing), _defineProperty(_cx, "".concat(blockClass, "--invalid"), invalid), _defineProperty(_cx, "".concat(blockClass, "--light"), light), _defineProperty(_cx, "".concat(blockClass, "--overflows"), refInput.current && refInput.current.scrollWidth > refInput.current.offsetWidth), _cx)),
239
- onClick: handleEdit // disabled eslint for click handler
240
- ,
241
- onBlur: handleBlur,
242
- ref: ref
243
- }, /*#__PURE__*/React.createElement("div", _extends({}, rest, getDevtoolsProps(componentName), {
244
- id: id,
245
- size: size,
246
- className: cx("".concat(blockClass, "__input"), _defineProperty({}, "".concat(blockClass, "__input--empty"), ((_refInput$current = refInput.current) === null || _refInput$current === void 0 ? void 0 : (_refInput$current$tex = _refInput$current.textContent) === null || _refInput$current$tex === void 0 ? void 0 : _refInput$current$tex.length) === 0)),
247
- contentEditable: true,
248
- "aria-label": labelText,
249
- role: "textbox",
250
- tabIndex: disabled ? -1 : 0,
251
- onFocus: handleFocus,
252
- onInput: handleInput,
253
- onKeyDown: handleKeyDown,
254
- onPaste: handlePaste,
255
- suppressContentEditableWarning: true,
256
- ref: refInput,
257
- "data-placeholder": placeholder
258
- }), value), /*#__PURE__*/React.createElement("div", {
259
- className: cx("".concat(blockClass, "__after-input-elements"))
260
- // tabindex -1 fixes blur target test when clicking on after-input-elements background
261
- ,
262
- tabIndex: "-1"
263
- }, /*#__PURE__*/React.createElement("div", {
264
- className: "".concat(blockClass, "__ellipsis"),
265
- "aria-hidden": !editing
266
- }, "\u2026"), /*#__PURE__*/React.createElement("div", {
267
- className: cx("".concat(blockClass, "__toolbar"), (_cx3 = {}, _defineProperty(_cx3, "".concat(blockClass, "__toolbar--animation"), toolbarAnimation), _defineProperty(_cx3, "".concat(blockClass, "__toolbar--saveable"), refInput.current && value !== internalValue), _cx3))
268
- }, showValidation && /*#__PURE__*/React.createElement("div", {
269
- className: "".concat(blockClass, "__validation-icon")
270
- }, validationIcon), editing ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
271
- className: "".concat(blockClass, "__cancel"),
272
- kind: "ghost",
273
- hasIconOnly: true,
274
- iconDescription: cancelDescription,
275
- onClick: handleCancel,
276
- renderIcon: Close16
277
- }, tipPositions.cancel)), /*#__PURE__*/React.createElement(Button, _extends({
278
- className: "".concat(blockClass, "__save"),
279
- kind: "ghost",
280
- hasIconOnly: true,
281
- iconDescription: saveDescription,
282
- onClick: handleSave,
283
- renderIcon: Checkmark16,
284
- disabled: value === internalValue
285
- }, tipPositions.save))) : /*#__PURE__*/React.createElement(Button, _extends({
286
- className: cx("".concat(blockClass, "__edit"), _defineProperty({}, "".concat(blockClass, "__edit--always-visible"), editAlwaysVisible)),
287
- kind: "ghost",
288
- hasIconOnly: true,
289
- iconDescription: editDescription,
290
- onClick: handleEdit,
291
- renderIcon: disabled ? EditOff16 : Edit16,
292
- disabled: disabled,
293
- tabIndex: -1
294
- }, tipPositions.edit)))), /*#__PURE__*/React.createElement("div", {
295
- className: cx("".concat(blockClass, "__disabled-cover"))
296
- }), showValidation && validationText && validationText.length > 0 && /*#__PURE__*/React.createElement("div", {
297
- className: "".concat(blockClass, "__validation-text ").concat(carbon.prefix, "--form-requirement")
298
- }, validationText))
299
- );
33
+ if (v2 === true) {
34
+ return /*#__PURE__*/React.createElement(InlineEditV2, props);
35
+ }
36
+ return /*#__PURE__*/React.createElement(InlineEditV1, props);
300
37
  });
301
-
302
- // Return a placeholder if not released and not enabled by feature flag
303
38
  InlineEdit = pkg.checkComponentEnabled(InlineEdit, componentName);
304
-
305
- // The display name of the component, used by React. Note that displayName
306
- // is used in preference to relying on function.name.
307
39
  InlineEdit.displayName = componentName;
308
-
309
- // The types and DocGen commentary for the component props,
310
- // in alphabetical order (for consistency).
311
- // See https://www.npmjs.com/package/prop-types#usage.
312
40
  InlineEdit.propTypes = {
313
- /**
314
- * buttonTooltipAlignment from the standard tooltip. Default center.
315
- *
316
- * Can be passed either as one of tooltip options or as an object specifying cancel, edit and save separately
317
- */
318
- buttonTooltipAlignment: PropTypes.oneOfType([PropTypes.oneOf(['start', 'center', 'end']), PropTypes.shape({
319
- cancel: PropTypes.oneOf(['start', 'center', 'end']),
320
- edit: PropTypes.oneOf(['start', 'center', 'end']),
321
- save: PropTypes.oneOf(['start', 'center', 'end'])
322
- })]),
323
- /**
324
- * buttonTooltipPosition from the standard tooltip
325
- *
326
- * Can be passed either as one of tooltip options or as an object specifying cancel, edit and save separately
327
- */
328
- buttonTooltipPosition: PropTypes.oneOfType([PropTypes.oneOf(['top', 'right', 'bottom', 'left']), PropTypes.shape({
329
- cancel: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
330
- edit: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
331
- save: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
332
- })]),
333
- /**
334
- * label for cancel button
335
- */
336
- cancelDescription: PropTypes.string.isRequired,
337
- /**
338
- * Provide an optional class to be applied to the containing node.
339
- */
340
- className: PropTypes.string,
341
- /**
342
- * disable edit
343
- */
344
- disabled: PropTypes.bool,
345
- /**
346
- * By default the edit icon is shown on hover only.
347
- */
348
- editAlwaysVisible: PropTypes.bool,
349
- /**
350
- * Label for the edit button
351
- */
352
- editDescription: PropTypes.string.isRequired,
353
- /**
354
- * ID for inline edit
355
- */
356
- id: PropTypes.string,
357
- /**
358
- * set invalid state for input
359
- */
360
- invalid: PropTypes.bool,
361
- /**
362
- * text shown when invalid is true
363
- */
364
- invalidText: PropTypes.string,
365
- /**
366
- * label for text input
367
- */
368
- labelText: PropTypes.string,
369
- /**
370
- * change background to light version (mimic React TextInput)
371
- */
372
- light: PropTypes.bool,
373
- /**
374
- * method called on cancel event
375
- */
376
- onCancel: PropTypes.func,
377
- /**
378
- * method called on input event (it's a React thing onChange behaves like on input).
379
- *
380
- * NOTE: caller to handle invalid states and associated text
381
- */
382
- onChange: PropTypes.func,
383
- /**
384
- * method called on change event
385
- *
386
- * NOTE: caller to handle invalid states and associated text
387
- */
388
- onSave: PropTypes.func,
389
- /**
390
- * placeholder for text input
391
- */
392
- placeholder: PropTypes.string,
393
- /**
394
- * label for save button
395
- */
396
- saveDescription: PropTypes.string.isRequired,
397
- /**
398
- * vertical size of control
399
- */
400
- size: PropTypes.oneOf(['sm', 'md', 'lg']),
401
- /**
402
- * initial/unedited value
403
- */
404
- value: PropTypes.string
41
+ v2: PropTypes.bool
405
42
  };