@carbon/ibm-products 1.2.5 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. package/css/index-full-carbon.css +1028 -517
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +3 -3
  4. package/css/index-without-carbon-released-only.css +187 -108
  5. package/css/index-without-carbon-released-only.css.map +1 -1
  6. package/css/index-without-carbon-released-only.min.css +3 -3
  7. package/css/index-without-carbon.css +580 -114
  8. package/css/index-without-carbon.css.map +1 -1
  9. package/css/index-without-carbon.min.css +3 -3
  10. package/css/index.css +804 -116
  11. package/css/index.css.map +1 -1
  12. package/css/index.min.css +3 -3
  13. package/es/components/APIKeyModal/APIKeyModal.js +25 -29
  14. package/es/components/ActionBar/ActionBar.js +4 -1
  15. package/es/components/ActionSet/ActionSet.js +22 -10
  16. package/es/components/ActionSet/actions.js +25 -17
  17. package/es/components/AddSelect/AddSelect.js +198 -0
  18. package/es/components/AddSelect/AddSelectBreadcrumbs.js +56 -0
  19. package/es/components/AddSelect/AddSelectList.js +94 -0
  20. package/es/components/AddSelect/AddSelectSidebar.js +46 -0
  21. package/es/components/AddSelect/index.js +7 -0
  22. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +24 -17
  23. package/es/components/CancelableTextEdit/CancelableTextEdit.js +245 -0
  24. package/es/components/{CreateTearsheet/constants.js → CancelableTextEdit/index.js} +1 -2
  25. package/es/components/Card/Card.js +6 -4
  26. package/es/components/CreateFullPage/CreateFullPage.js +102 -258
  27. package/es/components/CreateFullPage/CreateFullPageStep.js +65 -13
  28. package/es/components/CreateFullPage/index.js +1 -2
  29. package/es/components/CreateInfluencer/CreateInfluencer.js +40 -220
  30. package/es/components/CreateTearsheet/CreateTearsheet.js +95 -146
  31. package/es/components/CreateTearsheet/CreateTearsheetStep.js +70 -20
  32. package/es/components/CreateTearsheet/index.js +0 -1
  33. package/es/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +87 -28
  34. package/es/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  35. package/es/components/ExportModal/ExportModal.js +41 -12
  36. package/es/components/ImportModal/ImportModal.js +2 -1
  37. package/es/components/InlineEdit/InlineEdit.js +373 -0
  38. package/es/components/InlineEdit/index.js +7 -0
  39. package/es/components/MultiAddSelect/MultiAddSelect.js +16 -0
  40. package/es/components/MultiAddSelect/index.js +1 -0
  41. package/es/components/NotificationsPanel/NotificationsPanel.js +16 -3
  42. package/es/components/OptionsTile/OptionsTile.js +36 -15
  43. package/es/components/PageHeader/PageHeader.js +59 -35
  44. package/es/components/PageHeader/PageHeaderTitle.js +82 -7
  45. package/es/components/PageHeader/PageHeaderUtils.js +21 -2
  46. package/es/components/RemoveModal/RemoveModal.js +4 -2
  47. package/es/components/SidePanel/SidePanel.js +33 -16
  48. package/es/components/SingleAddSelect/SingleAddSelect.js +15 -0
  49. package/es/components/SingleAddSelect/index.js +1 -0
  50. package/es/components/TagSet/TagSet.js +4 -1
  51. package/es/components/Tearsheet/Tearsheet.js +1 -1
  52. package/es/components/Tearsheet/TearsheetNarrow.js +1 -1
  53. package/es/components/Tearsheet/TearsheetShell.js +1 -1
  54. package/es/components/Toolbar/Toolbar.js +69 -8
  55. package/es/components/WebTerminal/WebTerminal.js +1 -1
  56. package/es/components/index.js +5 -1
  57. package/es/global/js/hooks/index.js +1 -0
  58. package/es/global/js/hooks/useCreateComponentFocus.js +15 -19
  59. package/es/global/js/hooks/useCreateComponentStepChange.js +69 -79
  60. package/es/global/js/hooks/useResetCreateComponent.js +7 -4
  61. package/es/global/js/hooks/useRetrieveStepData.js +51 -0
  62. package/es/global/js/hooks/useValidCreateStepCount.js +4 -7
  63. package/es/global/js/package-settings.js +5 -1
  64. package/es/global/js/utils/lastIndexInArray.js +26 -0
  65. package/es/settings.js +0 -5
  66. package/lib/components/APIKeyModal/APIKeyModal.js +25 -29
  67. package/lib/components/ActionBar/ActionBar.js +4 -1
  68. package/lib/components/ActionSet/ActionSet.js +22 -10
  69. package/lib/components/ActionSet/actions.js +25 -17
  70. package/lib/components/AddSelect/AddSelect.js +223 -0
  71. package/lib/components/AddSelect/AddSelectBreadcrumbs.js +71 -0
  72. package/lib/components/AddSelect/AddSelectList.js +112 -0
  73. package/lib/components/AddSelect/AddSelectSidebar.js +63 -0
  74. package/lib/components/AddSelect/index.js +13 -0
  75. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +23 -16
  76. package/lib/components/CancelableTextEdit/CancelableTextEdit.js +265 -0
  77. package/lib/components/CancelableTextEdit/index.js +13 -0
  78. package/lib/components/Card/Card.js +6 -4
  79. package/lib/components/CreateFullPage/CreateFullPage.js +102 -258
  80. package/lib/components/CreateFullPage/CreateFullPageStep.js +68 -13
  81. package/lib/components/CreateFullPage/index.js +1 -9
  82. package/lib/components/CreateInfluencer/CreateInfluencer.js +38 -231
  83. package/lib/components/CreateTearsheet/CreateTearsheet.js +97 -148
  84. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +72 -19
  85. package/lib/components/CreateTearsheet/index.js +0 -8
  86. package/lib/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +86 -34
  87. package/lib/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  88. package/lib/components/ExportModal/ExportModal.js +38 -11
  89. package/lib/components/ImportModal/ImportModal.js +2 -1
  90. package/lib/components/InlineEdit/InlineEdit.js +389 -0
  91. package/lib/components/InlineEdit/index.js +13 -0
  92. package/lib/components/MultiAddSelect/MultiAddSelect.js +37 -0
  93. package/lib/components/MultiAddSelect/index.js +13 -0
  94. package/lib/components/NotificationsPanel/NotificationsPanel.js +13 -1
  95. package/lib/components/OptionsTile/OptionsTile.js +36 -15
  96. package/lib/components/PageHeader/PageHeader.js +59 -35
  97. package/lib/components/PageHeader/PageHeaderTitle.js +91 -9
  98. package/lib/components/PageHeader/PageHeaderUtils.js +21 -2
  99. package/lib/components/RemoveModal/RemoveModal.js +4 -2
  100. package/lib/components/SidePanel/SidePanel.js +33 -16
  101. package/lib/components/SingleAddSelect/SingleAddSelect.js +36 -0
  102. package/lib/components/SingleAddSelect/index.js +13 -0
  103. package/lib/components/TagSet/TagSet.js +4 -1
  104. package/lib/components/Tearsheet/Tearsheet.js +1 -1
  105. package/lib/components/Tearsheet/TearsheetNarrow.js +1 -1
  106. package/lib/components/Tearsheet/TearsheetShell.js +1 -1
  107. package/lib/components/Toolbar/Toolbar.js +69 -6
  108. package/lib/components/WebTerminal/WebTerminal.js +1 -1
  109. package/lib/components/index.js +33 -1
  110. package/lib/global/js/hooks/index.js +8 -0
  111. package/lib/global/js/hooks/useCreateComponentFocus.js +15 -19
  112. package/lib/global/js/hooks/useCreateComponentStepChange.js +69 -79
  113. package/lib/global/js/hooks/useResetCreateComponent.js +7 -4
  114. package/lib/global/js/hooks/useRetrieveStepData.js +62 -0
  115. package/lib/global/js/hooks/useValidCreateStepCount.js +4 -7
  116. package/lib/global/js/package-settings.js +5 -1
  117. package/lib/global/js/utils/lastIndexInArray.js +35 -0
  118. package/lib/settings.js +0 -6
  119. package/package.json +19 -19
  120. package/scss/components/AddSelect/_add-select.scss +108 -0
  121. package/scss/components/AddSelect/_index.scss +10 -0
  122. package/scss/components/AddSelect/_storybook-styles.scss +6 -0
  123. package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +19 -15
  124. package/scss/components/BreadcrumbWithOverflow/_index.scss +1 -1
  125. package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +212 -0
  126. package/{es/components/CreateFullPage/constants.js → scss/components/CancelableTextEdit/_index.scss} +2 -2
  127. package/scss/components/CancelableTextEdit/_storybook-styles.scss +15 -0
  128. package/scss/components/CreateFullPage/_create-full-page.scss +4 -11
  129. package/scss/components/CreateInfluencer/_create-influencer.scss +4 -4
  130. package/scss/components/CreateTearsheet/_create-tearsheet.scss +6 -10
  131. package/scss/components/InlineEdit/_index.scss +8 -0
  132. package/scss/components/InlineEdit/_inline-edit.scss +245 -0
  133. package/scss/components/InlineEdit/_storybook-styles.scss +28 -0
  134. package/scss/components/MultiAddSelect/_index.scss +1 -0
  135. package/scss/components/MultiAddSelect/_multi-add-select.scss +1 -0
  136. package/scss/components/MultiAddSelect/_storybook-styles.scss +6 -0
  137. package/scss/components/NotificationsPanel/_notifications-panel.scss +2 -2
  138. package/scss/components/PageHeader/_index.scss +1 -1
  139. package/scss/components/PageHeader/_page-header.scss +15 -5
  140. package/scss/components/ProductiveCard/_productive-card.scss +0 -4
  141. package/scss/components/SidePanel/_side-panel.scss +15 -6
  142. package/scss/components/SingleAddSelect/_index.scss +1 -0
  143. package/scss/components/SingleAddSelect/_single-add-select.scss +1 -0
  144. package/scss/components/SingleAddSelect/_storybook-styles.scss +6 -0
  145. package/scss/components/StatusIcon/_index.scss +1 -1
  146. package/scss/components/StatusIcon/_status-icon.scss +2 -0
  147. package/scss/components/TagSet/_index.scss +1 -1
  148. package/scss/components/UserProfileImage/_index.scss +1 -1
  149. package/scss/components/WebTerminal/_web-terminal.scss +2 -2
  150. package/scss/components/_index.scss +4 -0
  151. package/scss/global/styles/_project-settings.scss +5 -1
  152. package/es/components/CreateFullPage/CreateFullPageSection.js +0 -53
  153. package/es/components/CreateTearsheet/CreateTearsheetSection.js +0 -83
  154. package/es/components/CreateTearsheet/preview-components/MultiStepWithSectionsTearsheet.js +0 -327
  155. package/es/generated/feature-flags/feature-flags.js +0 -15
  156. package/es/global/js/utils/hasValidType.js +0 -94
  157. package/lib/components/CreateFullPage/CreateFullPageSection.js +0 -74
  158. package/lib/components/CreateFullPage/constants.js +0 -16
  159. package/lib/components/CreateTearsheet/CreateTearsheetSection.js +0 -105
  160. package/lib/components/CreateTearsheet/constants.js +0 -17
  161. package/lib/components/CreateTearsheet/preview-components/MultiStepWithSectionsTearsheet.js +0 -354
  162. package/lib/generated/feature-flags/feature-flags.js +0 -22
  163. package/lib/global/js/utils/hasValidType.js +0 -110
  164. package/scss/generated/feature-flags/_feature-flags.scss +0 -19
@@ -87,7 +87,6 @@ export var APIKeyModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
87
87
  currentStep = _useState6[0],
88
88
  setCurrentStep = _useState6[1];
89
89
 
90
- var inputRef = useRef();
91
90
  var copyRef = useRef();
92
91
  var apiKeyInputId = useRef(uuidv4());
93
92
  var nameInputId = useRef(uuidv4());
@@ -101,11 +100,6 @@ export var APIKeyModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
101
100
  ref: copyRef
102
101
  };
103
102
  var blockClass = "".concat(pkg.prefix, "--apikey-modal");
104
- useEffect(function () {
105
- if (inputRef.current && open) {
106
- inputRef.current.focus();
107
- }
108
- }, [open]);
109
103
  useEffect(function () {
110
104
  if (copyRef.current && open && apiKeyLoaded) {
111
105
  copyRef.current.focus();
@@ -179,70 +173,72 @@ export var APIKeyModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
179
173
  };
180
174
 
181
175
  var submitHandler = /*#__PURE__*/function () {
182
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
176
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(e) {
183
177
  return _regeneratorRuntime.wrap(function _callee$(_context) {
184
178
  while (1) {
185
179
  switch (_context.prev = _context.next) {
186
180
  case 0:
181
+ e.preventDefault();
182
+
187
183
  if (!hasNextStep) {
188
- _context.next = 4;
184
+ _context.next = 5;
189
185
  break;
190
186
  }
191
187
 
192
188
  setCurrentStep(currentStep + 1);
193
- _context.next = 21;
189
+ _context.next = 22;
194
190
  break;
195
191
 
196
- case 4:
192
+ case 5:
197
193
  if (!apiKeyLoaded) {
198
- _context.next = 20;
194
+ _context.next = 21;
199
195
  break;
200
196
  }
201
197
 
202
198
  if (!onCopy) {
203
- _context.next = 9;
199
+ _context.next = 10;
204
200
  break;
205
201
  }
206
202
 
207
203
  onCopy(apiKey);
208
- _context.next = 18;
204
+ _context.next = 19;
209
205
  break;
210
206
 
211
- case 9:
212
- _context.prev = 9;
213
- _context.next = 12;
207
+ case 10:
208
+ _context.prev = 10;
209
+ _context.next = 13;
214
210
  return navigator.clipboard.writeText(apiKey);
215
211
 
216
- case 12:
217
- _context.next = 18;
212
+ case 13:
213
+ _context.next = 19;
218
214
  break;
219
215
 
220
- case 14:
221
- _context.prev = 14;
222
- _context.t0 = _context["catch"](9);
216
+ case 15:
217
+ _context.prev = 15;
218
+ _context.t0 = _context["catch"](10);
223
219
  console.error(_context.t0);
224
220
  setCopyError(true);
225
221
 
226
- case 18:
227
- _context.next = 21;
222
+ case 19:
223
+ _context.next = 22;
228
224
  break;
229
225
 
230
- case 20:
226
+ case 21:
231
227
  if (editing) {
232
228
  onRequestEdit(name);
233
229
  } else {
234
230
  onRequestGenerate(name);
235
231
  }
236
232
 
237
- case 21:
233
+ case 22:
238
234
  case "end":
239
235
  return _context.stop();
240
236
  }
241
237
  }
242
- }, _callee, null, [[9, 14]]);
238
+ }, _callee, null, [[10, 15]]);
243
239
  }));
244
240
 
245
- return function submitHandler() {
241
+ return function submitHandler(_x) {
246
242
  return _ref2.apply(this, arguments);
247
243
  };
248
244
  }();
@@ -293,8 +289,8 @@ export var APIKeyModal = /*#__PURE__*/forwardRef(function (_ref, ref) {
293
289
  value: name,
294
290
  id: nameInputId.current,
295
291
  disabled: loading,
296
- ref: inputRef,
297
- required: nameRequired
292
+ required: nameRequired,
293
+ "data-modal-primary-focus": true
298
294
  })), loading && /*#__PURE__*/React.createElement(InlineLoading, {
299
295
  description: loadingText,
300
296
  className: "".concat(blockClass, "__loader")
@@ -3,7 +3,7 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
5
  var _excluded = ["actions", "className", "maxVisible", "menuOptionsClass", "onWidthChange", "overflowAriaLabel", "rightAlign"],
6
- _excluded2 = ["key"],
6
+ _excluded2 = ["key", "id"],
7
7
  _excluded3 = ["key"];
8
8
 
9
9
  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; }
@@ -80,9 +80,12 @@ export var ActionBar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
80
80
  key: "hidden-overflow-menu"
81
81
  }), actions.map(function (_ref2) {
82
82
  var key = _ref2.key,
83
+ id = _ref2.id,
83
84
  rest = _objectWithoutProperties(_ref2, _excluded2);
84
85
 
85
86
  return /*#__PURE__*/React.createElement(ActionBarItem, _extends({}, rest, {
87
+ // ensure id is not duplicated
88
+ "data-original-id": id,
86
89
  key: "hidden-item-".concat(key),
87
90
  className: "".concat(blockClass, "__hidden-sizing-item")
88
91
  }));
@@ -38,7 +38,7 @@ var ActionSetButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
38
38
 
39
39
  return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
40
40
  isExpressive: true,
41
- className: cx(className, ["".concat(blockClass, "__action-button"), _defineProperty({}, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost')]),
41
+ className: cx(className, ["".concat(blockClass, "__action-button"), _defineProperty({}, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost' || kind === 'danger--ghost')]),
42
42
  disabled: disabled || loading || false,
43
43
  kind: kind,
44
44
  onClick: onClick,
@@ -48,7 +48,7 @@ var ActionSetButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
48
48
  });
49
49
  ActionSetButton.displayName = 'ActionSetButton';
50
50
  ActionSetButton.propTypes = _objectSpread(_objectSpread({}, Button.PropTypes), {}, {
51
- kind: PropTypes.oneOf(['ghost', 'secondary', 'primary']),
51
+ kind: PropTypes.oneOf(['ghost', 'danger--ghost', 'secondary', 'danger', 'primary']),
52
52
  label: PropTypes.string,
53
53
  loading: PropTypes.bool
54
54
  });
@@ -82,13 +82,24 @@ export var ActionSet = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
82
82
 
83
83
  var buttons = actions && ((_actions$slice = actions.slice) === null || _actions$slice === void 0 ? void 0 : _actions$slice.call(actions, 0)) || []; // We stack the buttons in a xs/sm set, or if there are three or more in a md set.
84
84
 
85
- var stacking = willStack(size, buttons.length); // order the actions with ghost buttons first and primary buttons last
86
- // (and the opposite way if we're stacking)
85
+ var stacking = willStack(size, buttons.length); // Order of button kinds: ghost first, then danger--ghost, then most other types,
86
+ // then danger, and finally primary
87
+
88
+ var buttonOrder = function buttonOrder(kind) {
89
+ var _ghost$dangerGhost$;
90
+
91
+ return (_ghost$dangerGhost$ = {
92
+ ghost: 1,
93
+ 'danger--ghost': 2,
94
+ danger: 4,
95
+ primary: 5
96
+ }[kind]) !== null && _ghost$dangerGhost$ !== void 0 ? _ghost$dangerGhost$ : 3;
97
+ }; // order the actions with ghost/ghost-danger buttons first and primary/danger buttons last
98
+ // (or the opposite way if we're stacking)
99
+
87
100
 
88
101
  buttons.sort(function (action1, action2) {
89
- var kind1 = action1.kind || defaultKind;
90
- var kind2 = action2.kind || defaultKind;
91
- return kind1 === 'ghost' || kind2 === 'primary' ? stacking ? 1 : -1 : kind1 === 'primary' || kind2 === 'ghost' ? stacking ? -1 : 1 : 0;
102
+ return (buttonOrder(action1.kind || defaultKind) - buttonOrder(action2.kind || defaultKind)) * (stacking ? -1 : 1);
92
103
  });
93
104
  return /*#__PURE__*/React.createElement(ButtonSet, _extends({}, rest, {
94
105
  className: cx(blockClass, className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "--row-single"), !stacking && buttons.length === 1), _defineProperty(_cx, "".concat(blockClass, "--row-double"), !stacking && buttons.length === 2), _defineProperty(_cx, "".concat(blockClass, "--row-triple"), !stacking && buttons.length === 3), _defineProperty(_cx, "".concat(blockClass, "--row-quadruple"), !stacking && buttons.length >= 4), _defineProperty(_cx, "".concat(blockClass, "--stacking"), stacking), _cx), "".concat(blockClass, "--").concat(size)),
@@ -137,13 +148,14 @@ ActionSet.validateActions = function (sizeFn) {
137
148
 
138
149
  var primaryActions = countActions('primary');
139
150
  var secondaryActions = countActions('secondary');
140
- var ghostActions = countActions('ghost');
151
+ var dangerActions = countActions('danger');
152
+ var ghostActions = countActions('ghost') + countActions('danger--ghost');
141
153
  stacking && actions > 3 && problems.push("you cannot have more than three actions in this size of ".concat(componentName));
142
154
  actions > 4 && problems.push("you cannot have more than four actions in a ".concat(componentName));
143
155
  primaryActions > 1 && problems.push("you cannot have more than one 'primary' action in a ".concat(componentName));
144
156
  ghostActions > 1 && problems.push("you cannot have more than one 'ghost' action in a ".concat(componentName));
145
157
  stacking && actions > 1 && ghostActions > 0 && problems.push("you cannot have a 'ghost' button in conjunction with other action types in this size of ".concat(componentName));
146
- actions > primaryActions + secondaryActions + ghostActions && problems.push("you can only have 'primary', 'secondary' and 'ghost' buttons in a ".concat(componentName));
158
+ actions > primaryActions + secondaryActions + dangerActions + ghostActions && problems.push("you can only have 'primary', 'danger', 'secondary', 'ghost' and 'danger--ghost' buttons in a ".concat(componentName));
147
159
  }
148
160
 
149
161
  return problems.length > 0 ? new Error("Invalid ".concat(location, " `").concat(name, "` supplied to `").concat(componentName, "`: ").concat(problems.join(', and '), ".")) : null;
@@ -164,7 +176,7 @@ ActionSet.propTypes = {
164
176
  * See https://react.carbondesignsystem.com/?path=/docs/components-button--default#component-api
165
177
  */
166
178
  actions: allPropTypes([ActionSet.validateActions(), PropTypes.arrayOf(PropTypes.shape(_objectSpread(_objectSpread({}, Button.propTypes), {}, {
167
- kind: PropTypes.oneOf(['ghost', 'secondary', 'primary']),
179
+ kind: PropTypes.oneOf(['ghost', 'danger--ghost', 'secondary', 'danger', 'primary']),
168
180
  label: PropTypes.string,
169
181
  loading: PropTypes.bool,
170
182
  // we duplicate this Button prop to improve the DocGen here
@@ -4,19 +4,22 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export var actionsOptions = [0, 1, 2, 3, 4, 5, 6, 7];
7
+ export var actionsOptions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
8
8
  export var actionsLabels = {
9
9
  0: 'None',
10
10
  1: 'One button',
11
- 2: 'One ghost button',
12
- 3: 'Two buttons',
13
- 4: 'Two buttons including one ghost',
14
- 5: 'Three buttons',
15
- 6: 'Three buttons including one ghost',
16
- 7: 'Four buttons including one ghost'
11
+ 2: 'A danger button',
12
+ 3: 'A ghost button',
13
+ 4: 'Two buttons',
14
+ 5: 'Two buttons with one ghost',
15
+ 6: 'Three buttons',
16
+ 7: 'Three buttons with one ghost',
17
+ 8: 'Three buttons with one danger',
18
+ 9: 'Four buttons with one ghost',
19
+ 10: 'Four buttons with two danger'
17
20
  };
18
21
  export var actionsMapping = function actionsMapping(labels, action) {
19
- var _labels$primary, _labels$secondary, _labels$secondary2, _labels$ghost;
22
+ var _labels$primary, _labels$danger, _labels$secondary, _labels$secondary2, _labels$dangerGhost, _labels$ghost;
20
23
 
21
24
  var act = function act(label, kind, key) {
22
25
  var actionCall = action && action("Click on '".concat(label, "'"));
@@ -32,17 +35,22 @@ export var actionsMapping = function actionsMapping(labels, action) {
32
35
  };
33
36
 
34
37
  var primary = act((_labels$primary = labels === null || labels === void 0 ? void 0 : labels.primary) !== null && _labels$primary !== void 0 ? _labels$primary : 'Primary', 'primary', 1);
35
- var secondary = act((_labels$secondary = labels === null || labels === void 0 ? void 0 : labels.secondary) !== null && _labels$secondary !== void 0 ? _labels$secondary : 'Secondary', 'secondary', 2);
36
- var secondary2 = act((_labels$secondary2 = labels === null || labels === void 0 ? void 0 : labels.secondary2) !== null && _labels$secondary2 !== void 0 ? _labels$secondary2 : 'Secondary', 'secondary', 3);
37
- var ghost = act((_labels$ghost = labels === null || labels === void 0 ? void 0 : labels.ghost) !== null && _labels$ghost !== void 0 ? _labels$ghost : 'Ghost', 'ghost', 4);
38
+ var danger = act((_labels$danger = labels === null || labels === void 0 ? void 0 : labels.danger) !== null && _labels$danger !== void 0 ? _labels$danger : 'Danger', 'danger', 2);
39
+ var secondary = act((_labels$secondary = labels === null || labels === void 0 ? void 0 : labels.secondary) !== null && _labels$secondary !== void 0 ? _labels$secondary : 'Secondary', 'secondary', 3);
40
+ var secondary2 = act((_labels$secondary2 = labels === null || labels === void 0 ? void 0 : labels.secondary2) !== null && _labels$secondary2 !== void 0 ? _labels$secondary2 : 'Secondary', 'secondary', 4);
41
+ var dangerGhost = act((_labels$dangerGhost = labels === null || labels === void 0 ? void 0 : labels.dangerGhost) !== null && _labels$dangerGhost !== void 0 ? _labels$dangerGhost : 'Danger-ghost', 'danger--ghost', 5);
42
+ var ghost = act((_labels$ghost = labels === null || labels === void 0 ? void 0 : labels.ghost) !== null && _labels$ghost !== void 0 ? _labels$ghost : 'Ghost', 'ghost', 6);
38
43
  return {
39
44
  0: [],
40
45
  1: [primary],
41
- 2: [ghost],
42
- 3: [primary, secondary],
43
- 4: [primary, ghost],
44
- 5: [primary, secondary, secondary2],
45
- 6: [primary, secondary, ghost],
46
- 7: [primary, secondary, secondary2, ghost]
46
+ 2: [danger],
47
+ 3: [ghost],
48
+ 4: [primary, secondary],
49
+ 5: [primary, ghost],
50
+ 6: [primary, secondary, secondary2],
51
+ 7: [primary, secondary, ghost],
52
+ 8: [danger, secondary, ghost],
53
+ 9: [primary, secondary, secondary2, ghost],
54
+ 10: [danger, secondary, secondary2, dangerGhost]
47
55
  };
48
56
  };
@@ -0,0 +1,198 @@
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
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
+ var _excluded = ["className", "description", "influencerTitle", "inputPlaceholder", "items", "itemsLabel", "multi", "noResultsDescription", "noResultsTitle", "noSelectionDescription", "noSelectionTitle", "onClose", "onCloseButtonText", "onSearchFilter", "onSubmit", "onSubmitButtonText", "open", "title"];
6
+ //
7
+ // Copyright IBM Corp. 2022
8
+ //
9
+ // This source code is licensed under the Apache-2.0 license found in the
10
+ // LICENSE file in the root directory of this source tree.
11
+ //
12
+ import React, { forwardRef, useState } from 'react';
13
+ import PropTypes from 'prop-types';
14
+ import cx from 'classnames';
15
+ import { TextInput, Tag } from 'carbon-components-react';
16
+ import { Tearsheet, TearsheetNarrow } from '../../components/Tearsheet';
17
+ import { NoDataEmptyState } from '../../components/EmptyStates/NoDataEmptyState';
18
+ import { pkg } from '../../settings';
19
+ import { AddSelectSidebar } from './AddSelectSidebar';
20
+ import { AddSelectBreadcrumbs } from './AddSelectBreadcrumbs';
21
+ import { AddSelectList } from './AddSelectList';
22
+ var componentName = 'AddSelect';
23
+ export var AddSelect = /*#__PURE__*/forwardRef(function (_ref, ref) {
24
+ var _cx;
25
+
26
+ var className = _ref.className,
27
+ description = _ref.description,
28
+ influencerTitle = _ref.influencerTitle,
29
+ inputPlaceholder = _ref.inputPlaceholder,
30
+ items = _ref.items,
31
+ itemsLabel = _ref.itemsLabel,
32
+ multi = _ref.multi,
33
+ noResultsDescription = _ref.noResultsDescription,
34
+ noResultsTitle = _ref.noResultsTitle,
35
+ noSelectionDescription = _ref.noSelectionDescription,
36
+ noSelectionTitle = _ref.noSelectionTitle,
37
+ onClose = _ref.onClose,
38
+ onCloseButtonText = _ref.onCloseButtonText,
39
+ onSearchFilter = _ref.onSearchFilter,
40
+ onSubmit = _ref.onSubmit,
41
+ onSubmitButtonText = _ref.onSubmitButtonText,
42
+ open = _ref.open,
43
+ title = _ref.title,
44
+ rest = _objectWithoutProperties(_ref, _excluded);
45
+
46
+ var blockClass = "".concat(pkg.prefix, "--add-select"); // hooks
47
+
48
+ var _useState = useState([]),
49
+ _useState2 = _slicedToArray(_useState, 2),
50
+ path = _useState2[0],
51
+ setPath = _useState2[1];
52
+
53
+ var _useState3 = useState(''),
54
+ _useState4 = _slicedToArray(_useState3, 2),
55
+ singleSelection = _useState4[0],
56
+ setSingleSelection = _useState4[1];
57
+
58
+ var _useState5 = useState([]),
59
+ _useState6 = _slicedToArray(_useState5, 2),
60
+ multiSelection = _useState6[0],
61
+ setMultiSelection = _useState6[1];
62
+
63
+ var _useState7 = useState(''),
64
+ _useState8 = _slicedToArray(_useState7, 2),
65
+ searchTerm = _useState8[0],
66
+ setSearchTerm = _useState8[1]; // handlers
67
+
68
+
69
+ var handleSearch = function handleSearch(e) {
70
+ setSearchTerm(e.target.value);
71
+ }; // item filtering
72
+
73
+
74
+ var getFilteredItems = function getFilteredItems() {
75
+ var hasPath = path.length > 0;
76
+ /**
77
+ * how to traverse the levels of items-
78
+ * the path represents the ids of each level / item / breadcrumb
79
+ * using this path we can drill down into the items until we get to the last one the user selected
80
+ */
81
+
82
+ var itemsToFilter = hasPath ? path.reduce(function (prev, cur) {
83
+ return prev.find(function (item) {
84
+ return item.id === cur.id;
85
+ }).children;
86
+ }, items) : items;
87
+ var results = itemsToFilter.filter(function (item) {
88
+ if (!searchTerm) {
89
+ return item;
90
+ } // if user provides their own filter function use that
91
+
92
+
93
+ if (onSearchFilter) {
94
+ return onSearchFilter(item, searchTerm);
95
+ } // otherwise use the default label filter
96
+
97
+
98
+ return item.label.toLowerCase().includes(searchTerm);
99
+ });
100
+ return results;
101
+ };
102
+
103
+ var filteredItems = getFilteredItems(); // main content
104
+
105
+ var body = /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
106
+ className: "".concat(blockClass, "__header")
107
+ }, /*#__PURE__*/React.createElement(TextInput, {
108
+ id: "temp-id",
109
+ labelText: "temp label",
110
+ placeholder: inputPlaceholder,
111
+ value: searchTerm,
112
+ onChange: handleSearch
113
+ }), /*#__PURE__*/React.createElement("div", {
114
+ className: "".concat(blockClass, "__items-label-container")
115
+ }, path.length ? /*#__PURE__*/React.createElement(AddSelectBreadcrumbs, {
116
+ itemsLabel: itemsLabel,
117
+ path: path,
118
+ setPath: setPath
119
+ }) : /*#__PURE__*/React.createElement("p", {
120
+ className: "".concat(blockClass, "__items-label")
121
+ }, itemsLabel), /*#__PURE__*/React.createElement(Tag, {
122
+ type: "gray",
123
+ size: "sm",
124
+ className: "".concat(blockClass, "__items-label-tag")
125
+ }, filteredItems.length))), filteredItems.length > 0 ? /*#__PURE__*/React.createElement(AddSelectList, {
126
+ filteredItems: filteredItems,
127
+ multi: multi,
128
+ multiSelection: multiSelection,
129
+ path: path,
130
+ setMultiSelection: setMultiSelection,
131
+ setPath: setPath,
132
+ setSingleSelection: setSingleSelection,
133
+ singleSelection: singleSelection
134
+ }) : /*#__PURE__*/React.createElement("div", {
135
+ className: "".concat(blockClass, "__body")
136
+ }, /*#__PURE__*/React.createElement(NoDataEmptyState, {
137
+ subtitle: noResultsDescription,
138
+ title: noResultsTitle
139
+ })));
140
+ var commonTearsheetProps = {
141
+ open: open,
142
+ title: title,
143
+ description: description,
144
+ closeIconDescription: 'temp description',
145
+ actions: [{
146
+ label: onCloseButtonText,
147
+ kind: 'secondary',
148
+ onClick: onClose
149
+ }, {
150
+ label: onSubmitButtonText,
151
+ kind: 'primary',
152
+ onClick: onSubmit,
153
+ disabled: multi ? multiSelection.length === 0 : !singleSelection
154
+ }]
155
+ };
156
+ var sidebarProps = {
157
+ influencerTitle: influencerTitle,
158
+ multiSelection: multiSelection,
159
+ noSelectionDescription: noSelectionDescription,
160
+ noSelectionTitle: noSelectionTitle
161
+ };
162
+ var classNames = cx(className, blockClass, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__single"), !multi), _defineProperty(_cx, "".concat(blockClass, "__multi"), multi), _cx));
163
+ return /*#__PURE__*/React.createElement("div", _extends({
164
+ ref: ref,
165
+ className: classNames
166
+ }, rest), multi ? /*#__PURE__*/React.createElement(Tearsheet, _extends({}, commonTearsheetProps, {
167
+ influencer: multi && /*#__PURE__*/React.createElement(AddSelectSidebar, sidebarProps),
168
+ influencerPosition: "right"
169
+ }), body) : /*#__PURE__*/React.createElement(TearsheetNarrow, commonTearsheetProps, body));
170
+ });
171
+ AddSelect.propTypes = {
172
+ className: PropTypes.string,
173
+ description: PropTypes.string,
174
+ influencerTitle: PropTypes.string,
175
+ inputPlaceholder: PropTypes.string,
176
+ items: PropTypes.arrayOf(PropTypes.shape({
177
+ id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
178
+ label: PropTypes.string,
179
+ value: PropTypes.string
180
+ })),
181
+ itemsLabel: PropTypes.string,
182
+ multi: PropTypes.bool,
183
+ noResultsDescription: PropTypes.string,
184
+ noResultsTitle: PropTypes.string,
185
+ noSelectionDescription: PropTypes.string,
186
+ noSelectionTitle: PropTypes.string,
187
+ onClose: PropTypes.func,
188
+ onCloseButtonText: PropTypes.string,
189
+ onSearchFilter: PropTypes.func,
190
+ onSubmit: PropTypes.func,
191
+ onSubmitButtonText: PropTypes.string,
192
+ open: PropTypes.bool,
193
+ title: PropTypes.string
194
+ };
195
+ AddSelect.defaultProps = {
196
+ items: []
197
+ };
198
+ AddSelect.displayName = componentName;
@@ -0,0 +1,56 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ //
3
+ // Copyright IBM Corp. 2022
4
+ //
5
+ // This source code is licensed under the Apache-2.0 license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+ import React from 'react';
9
+ import { Breadcrumb, BreadcrumbItem } from 'carbon-components-react';
10
+ import PropTypes from 'prop-types';
11
+ var componentName = 'AddSelectBreadcrumbs';
12
+ export var AddSelectBreadcrumbs = function AddSelectBreadcrumbs(_ref) {
13
+ var itemsLabel = _ref.itemsLabel,
14
+ path = _ref.path,
15
+ setPath = _ref.setPath;
16
+
17
+ var clickHandler = function clickHandler(id) {
18
+ var newPath = _toConsumableArray(path);
19
+
20
+ var pathIdx = newPath.findIndex(function (entry) {
21
+ return entry.id === id;
22
+ });
23
+ var finalPath = newPath.splice(0, pathIdx + 1);
24
+ setPath(finalPath);
25
+ };
26
+
27
+ var resetPath = function resetPath() {
28
+ setPath([]);
29
+ };
30
+
31
+ return /*#__PURE__*/React.createElement(Breadcrumb, {
32
+ noTrailingSlash: true
33
+ }, /*#__PURE__*/React.createElement(BreadcrumbItem, {
34
+ onClick: resetPath
35
+ }, itemsLabel), path.map(function (entry, idx, arr) {
36
+ var isCurrentPage = idx === arr.length - 1;
37
+
38
+ var crumbHandler = function crumbHandler() {
39
+ if (!isCurrentPage) {
40
+ clickHandler(entry.id);
41
+ }
42
+ };
43
+
44
+ return /*#__PURE__*/React.createElement(BreadcrumbItem, {
45
+ key: entry.id,
46
+ isCurrentPage: isCurrentPage,
47
+ onClick: crumbHandler
48
+ }, entry.label);
49
+ }));
50
+ };
51
+ AddSelectBreadcrumbs.propTypes = {
52
+ itemsLabel: PropTypes.string,
53
+ path: PropTypes.array,
54
+ setPath: PropTypes.func
55
+ };
56
+ AddSelectBreadcrumbs.displayName = componentName;
@@ -0,0 +1,94 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ //
3
+ // Copyright IBM Corp. 2022
4
+ //
5
+ // This source code is licensed under the Apache-2.0 license found in the
6
+ // LICENSE file in the root directory of this source tree.
7
+ //
8
+ import React from 'react';
9
+ import { Checkbox, RadioButton, StructuredListRow, StructuredListWrapper, StructuredListBody, StructuredListCell } from 'carbon-components-react';
10
+ import { ChevronRight16 } from '@carbon/icons-react';
11
+ import PropTypes from 'prop-types';
12
+ import { pkg } from '../../settings';
13
+ var componentName = 'AddSelectList';
14
+ export var AddSelectList = function AddSelectList(_ref) {
15
+ var filteredItems = _ref.filteredItems,
16
+ multi = _ref.multi,
17
+ multiSelection = _ref.multiSelection,
18
+ path = _ref.path,
19
+ setMultiSelection = _ref.setMultiSelection,
20
+ setPath = _ref.setPath,
21
+ setSingleSelection = _ref.setSingleSelection,
22
+ singleSelection = _ref.singleSelection;
23
+ var blockClass = "".concat(pkg.prefix, "--add-select__selections");
24
+
25
+ var handleSingleSelection = function handleSingleSelection(value) {
26
+ setSingleSelection(value);
27
+ };
28
+
29
+ var handleMultiSelection = function handleMultiSelection(value, checked) {
30
+ if (checked) {
31
+ var newValues = [].concat(_toConsumableArray(multiSelection), [value]);
32
+ setMultiSelection(newValues);
33
+ } else {
34
+ var _newValues = multiSelection.filter(function (v) {
35
+ return v !== value;
36
+ });
37
+
38
+ setMultiSelection(_newValues);
39
+ }
40
+ };
41
+
42
+ var onNavigateItem = function onNavigateItem(_ref2) {
43
+ var id = _ref2.id,
44
+ label = _ref2.label;
45
+ setPath([].concat(_toConsumableArray(path), [{
46
+ id: id,
47
+ label: label
48
+ }]));
49
+ };
50
+
51
+ return /*#__PURE__*/React.createElement("div", {
52
+ className: "".concat(blockClass, "-wrapper")
53
+ }, /*#__PURE__*/React.createElement(StructuredListWrapper, {
54
+ selection: true,
55
+ className: "".concat(blockClass)
56
+ }, /*#__PURE__*/React.createElement(StructuredListBody, null, filteredItems.map(function (item) {
57
+ return /*#__PURE__*/React.createElement(StructuredListRow, {
58
+ key: item.id
59
+ }, /*#__PURE__*/React.createElement(StructuredListCell, null, /*#__PURE__*/React.createElement("div", {
60
+ className: "".concat(blockClass, "-cell-wrapper")
61
+ }, multi ? /*#__PURE__*/React.createElement(Checkbox, {
62
+ className: "".concat(blockClass, "-checkbox"),
63
+ onChange: function onChange(value) {
64
+ return handleMultiSelection(item.value, value);
65
+ },
66
+ labelText: item.label,
67
+ id: item.id,
68
+ checked: multiSelection.includes(item.value)
69
+ }) : /*#__PURE__*/React.createElement(RadioButton, {
70
+ className: "".concat(blockClass, "-radio"),
71
+ name: "add-select-selections",
72
+ id: item.id,
73
+ value: item.value,
74
+ labelText: item.label,
75
+ onChange: handleSingleSelection,
76
+ selected: item.value === singleSelection
77
+ }), item.children && /*#__PURE__*/React.createElement(ChevronRight16, {
78
+ onClick: function onClick() {
79
+ return onNavigateItem(item);
80
+ }
81
+ }))));
82
+ }))));
83
+ };
84
+ AddSelectList.propTypes = {
85
+ filteredItems: PropTypes.array,
86
+ multi: PropTypes.bool,
87
+ multiSelection: PropTypes.array,
88
+ path: PropTypes.array,
89
+ setMultiSelection: PropTypes.func,
90
+ setPath: PropTypes.func,
91
+ setSingleSelection: PropTypes.func,
92
+ singleSelection: PropTypes.string
93
+ };
94
+ AddSelectList.displayName = componentName;