@carbon/ibm-products 1.35.1 → 1.36.0

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