@carbon/ibm-products 1.2.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. package/css/index-full-carbon.css +662 -313
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +2 -2
  4. package/css/index-without-carbon-released-only.css +156 -81
  5. package/css/index-without-carbon-released-only.css.map +1 -1
  6. package/css/index-without-carbon-released-only.min.css +2 -2
  7. package/css/index-without-carbon.css +393 -81
  8. package/css/index-without-carbon.css.map +1 -1
  9. package/css/index-without-carbon.min.css +2 -2
  10. package/css/index.css +615 -81
  11. package/css/index.css.map +1 -1
  12. package/css/index.min.css +2 -2
  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 +157 -0
  18. package/es/components/AddSelect/index.js +7 -0
  19. package/es/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +19 -15
  20. package/es/components/CancelableTextEdit/CancelableTextEdit.js +245 -0
  21. package/es/components/{CreateTearsheet/constants.js → CancelableTextEdit/index.js} +1 -2
  22. package/es/components/CreateFullPage/CreateFullPage.js +102 -258
  23. package/es/components/CreateFullPage/CreateFullPageStep.js +65 -13
  24. package/es/components/CreateFullPage/index.js +1 -2
  25. package/es/components/CreateInfluencer/CreateInfluencer.js +40 -220
  26. package/es/components/CreateTearsheet/CreateTearsheet.js +95 -146
  27. package/es/components/CreateTearsheet/CreateTearsheetStep.js +70 -20
  28. package/es/components/CreateTearsheet/index.js +0 -1
  29. package/es/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +87 -28
  30. package/es/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  31. package/es/components/ExportModal/ExportModal.js +41 -12
  32. package/es/components/ImportModal/ImportModal.js +2 -1
  33. package/es/components/InlineEdit/InlineEdit.js +224 -0
  34. package/es/components/InlineEdit/index.js +7 -0
  35. package/es/components/MultiAddSelect/MultiAddSelect.js +16 -0
  36. package/es/components/MultiAddSelect/index.js +1 -0
  37. package/es/components/OptionsTile/OptionsTile.js +36 -15
  38. package/es/components/PageHeader/PageHeader.js +54 -33
  39. package/es/components/PageHeader/PageHeaderTitle.js +78 -7
  40. package/es/components/PageHeader/PageHeaderUtils.js +21 -2
  41. package/es/components/RemoveModal/RemoveModal.js +4 -2
  42. package/es/components/SidePanel/SidePanel.js +1 -1
  43. package/es/components/SingleAddSelect/SingleAddSelect.js +15 -0
  44. package/es/components/SingleAddSelect/index.js +1 -0
  45. package/es/components/TagSet/TagSet.js +4 -1
  46. package/es/components/Tearsheet/Tearsheet.js +1 -1
  47. package/es/components/Tearsheet/TearsheetNarrow.js +1 -1
  48. package/es/components/Tearsheet/TearsheetShell.js +1 -1
  49. package/es/components/Toolbar/Toolbar.js +69 -8
  50. package/es/components/index.js +5 -1
  51. package/es/global/js/hooks/index.js +1 -0
  52. package/es/global/js/hooks/useCreateComponentFocus.js +15 -19
  53. package/es/global/js/hooks/useCreateComponentStepChange.js +69 -79
  54. package/es/global/js/hooks/useResetCreateComponent.js +7 -4
  55. package/es/global/js/hooks/useRetrieveStepData.js +51 -0
  56. package/es/global/js/hooks/useValidCreateStepCount.js +4 -7
  57. package/es/global/js/package-settings.js +5 -1
  58. package/es/global/js/utils/lastIndexInArray.js +26 -0
  59. package/es/global/js/utils/story-helper.js +1 -1
  60. package/lib/components/APIKeyModal/APIKeyModal.js +25 -29
  61. package/lib/components/ActionBar/ActionBar.js +4 -1
  62. package/lib/components/ActionSet/ActionSet.js +22 -10
  63. package/lib/components/ActionSet/actions.js +25 -17
  64. package/lib/components/AddSelect/AddSelect.js +178 -0
  65. package/lib/components/AddSelect/index.js +13 -0
  66. package/lib/components/BreadcrumbWithOverflow/BreadcrumbWithOverflow.js +18 -14
  67. package/lib/components/CancelableTextEdit/CancelableTextEdit.js +265 -0
  68. package/lib/components/CancelableTextEdit/index.js +13 -0
  69. package/lib/components/CreateFullPage/CreateFullPage.js +102 -258
  70. package/lib/components/CreateFullPage/CreateFullPageStep.js +68 -13
  71. package/lib/components/CreateFullPage/index.js +1 -9
  72. package/lib/components/CreateInfluencer/CreateInfluencer.js +38 -231
  73. package/lib/components/CreateTearsheet/CreateTearsheet.js +97 -148
  74. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +72 -19
  75. package/lib/components/CreateTearsheet/index.js +0 -8
  76. package/lib/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +86 -34
  77. package/lib/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  78. package/lib/components/ExportModal/ExportModal.js +38 -11
  79. package/lib/components/ImportModal/ImportModal.js +2 -1
  80. package/lib/components/InlineEdit/InlineEdit.js +242 -0
  81. package/lib/components/InlineEdit/index.js +13 -0
  82. package/lib/components/MultiAddSelect/MultiAddSelect.js +37 -0
  83. package/lib/components/MultiAddSelect/index.js +13 -0
  84. package/lib/components/OptionsTile/OptionsTile.js +36 -15
  85. package/lib/components/PageHeader/PageHeader.js +54 -33
  86. package/lib/components/PageHeader/PageHeaderTitle.js +87 -9
  87. package/lib/components/PageHeader/PageHeaderUtils.js +21 -2
  88. package/lib/components/RemoveModal/RemoveModal.js +4 -2
  89. package/lib/components/SidePanel/SidePanel.js +1 -1
  90. package/lib/components/SingleAddSelect/SingleAddSelect.js +36 -0
  91. package/lib/components/SingleAddSelect/index.js +13 -0
  92. package/lib/components/TagSet/TagSet.js +4 -1
  93. package/lib/components/Tearsheet/Tearsheet.js +1 -1
  94. package/lib/components/Tearsheet/TearsheetNarrow.js +1 -1
  95. package/lib/components/Tearsheet/TearsheetShell.js +1 -1
  96. package/lib/components/Toolbar/Toolbar.js +69 -6
  97. package/lib/components/index.js +33 -1
  98. package/lib/global/js/hooks/index.js +8 -0
  99. package/lib/global/js/hooks/useCreateComponentFocus.js +15 -19
  100. package/lib/global/js/hooks/useCreateComponentStepChange.js +69 -79
  101. package/lib/global/js/hooks/useResetCreateComponent.js +7 -4
  102. package/lib/global/js/hooks/useRetrieveStepData.js +62 -0
  103. package/lib/global/js/hooks/useValidCreateStepCount.js +4 -7
  104. package/lib/global/js/package-settings.js +5 -1
  105. package/lib/global/js/utils/lastIndexInArray.js +35 -0
  106. package/lib/global/js/utils/story-helper.js +1 -1
  107. package/package.json +22 -22
  108. package/scss/components/AddSelect/_add-select.scss +84 -0
  109. package/scss/components/AddSelect/_index.scss +10 -0
  110. package/scss/components/AddSelect/_storybook-styles.scss +6 -0
  111. package/scss/components/BreadcrumbWithOverflow/_breadcrumb-with-overflow.scss +19 -15
  112. package/scss/components/CancelableTextEdit/_cancelable-text-edit.scss +211 -0
  113. package/{es/components/CreateFullPage/constants.js → scss/components/CancelableTextEdit/_index.scss} +2 -2
  114. package/scss/components/CancelableTextEdit/_storybook-styles.scss +15 -0
  115. package/scss/components/CreateFullPage/_create-full-page.scss +4 -11
  116. package/scss/components/CreateTearsheet/_create-tearsheet.scss +4 -8
  117. package/scss/components/InlineEdit/_index.scss +8 -0
  118. package/scss/components/InlineEdit/_inline-edit.scss +44 -0
  119. package/scss/components/InlineEdit/_storybook-styles.scss +15 -0
  120. package/scss/components/MultiAddSelect/_index.scss +1 -0
  121. package/scss/components/MultiAddSelect/_multi-add-select.scss +1 -0
  122. package/scss/components/MultiAddSelect/_storybook-styles.scss +6 -0
  123. package/scss/components/PageHeader/_page-header.scss +14 -4
  124. package/scss/components/SingleAddSelect/_index.scss +1 -0
  125. package/scss/components/SingleAddSelect/_single-add-select.scss +1 -0
  126. package/scss/components/SingleAddSelect/_storybook-styles.scss +6 -0
  127. package/scss/components/StatusIcon/_status-icon.scss +2 -0
  128. package/scss/components/_index.scss +4 -0
  129. package/es/components/CreateFullPage/CreateFullPageSection.js +0 -53
  130. package/es/components/CreateTearsheet/CreateTearsheetSection.js +0 -83
  131. package/es/components/CreateTearsheet/preview-components/MultiStepWithSectionsTearsheet.js +0 -327
  132. package/es/global/js/utils/hasValidType.js +0 -94
  133. package/lib/components/CreateFullPage/CreateFullPageSection.js +0 -74
  134. package/lib/components/CreateFullPage/constants.js +0 -16
  135. package/lib/components/CreateTearsheet/CreateTearsheetSection.js +0 -105
  136. package/lib/components/CreateTearsheet/constants.js +0 -17
  137. package/lib/components/CreateTearsheet/preview-components/MultiStepWithSectionsTearsheet.js +0 -354
  138. package/lib/global/js/utils/hasValidType.js +0 -110
@@ -1,273 +1,93 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
-
4
1
  /**
5
- * Copyright IBM Corp. 2021, 2021
2
+ * Copyright IBM Corp. 2021, 2022
6
3
  *
7
4
  * This source code is licensed under the Apache-2.0 license found in the
8
5
  * LICENSE file in the root directory of this source tree.
9
6
  */
10
7
  // Import portions of React that are needed.
11
- import React, { useEffect, useState } from 'react';
8
+ import React from 'react';
12
9
  import PropTypes from 'prop-types';
13
10
  import cx from 'classnames';
14
- import { ProgressIndicator, ProgressStep, Toggle } from 'carbon-components-react';
15
- import { SideNav, SideNavItems, SideNavLink } from 'carbon-components-react/lib/components/UIShell';
16
- import { moderate02 } from '@carbon/motion';
17
- import { getExtractedSteps } from '../../global/js/utils/hasValidType';
11
+ import { ProgressIndicator, ProgressStep } from 'carbon-components-react';
18
12
  import '../../global/js/utils/props-helper';
19
- import { pkg } from '../../settings';
20
- import { CREATE_TEARSHEET_STEP } from '../CreateTearsheet/constants';
21
- import { CREATE_FULL_PAGE_STEP } from '../CreateFullPage/constants';
22
- import { CreateTearsheet } from '../CreateTearsheet'; // The block part of our conventional BEM class names (blockClass__E--M).
13
+ import { pkg } from '../../settings'; // The block part of our conventional BEM class names (blockClass__E--M).
23
14
 
24
15
  var blockClass = "".concat(pkg.prefix, "--create-influencer");
25
16
  var componentName = 'CreateInfluencer';
26
17
  export var CreateInfluencer = function CreateInfluencer(_ref) {
27
- var activeSectionIndex = _ref.activeSectionIndex,
28
- className = _ref.className,
29
- componentBlockClass = _ref.componentBlockClass,
30
- createComponentName = _ref.createComponentName,
31
- createComponents = _ref.createComponents,
18
+ var className = _ref.className,
32
19
  currentStep = _ref.currentStep,
33
- handleToggleState = _ref.handleToggleState,
34
- handleActiveSectionIndex = _ref.handleActiveSectionIndex,
35
- includeViewAllToggle = _ref.includeViewAllToggle,
36
- open = _ref.open,
37
- previousState = _ref.previousState,
38
- sideNavAriaLabel = _ref.sideNavAriaLabel,
39
- toggleState = _ref.toggleState,
40
- viewAllToggleLabelText = _ref.viewAllToggleLabelText,
41
- viewAllToggleOffLabelText = _ref.viewAllToggleOffLabelText,
42
- viewAllToggleOnLabelText = _ref.viewAllToggleOnLabelText;
43
-
44
- var _useState = useState(''),
45
- _useState2 = _slicedToArray(_useState, 2),
46
- progressIndicatorState = _useState2[0],
47
- setProgressIndicatorState = _useState2[1];
48
-
49
- var _useState3 = useState(''),
50
- _useState4 = _slicedToArray(_useState3, 2),
51
- sideNavState = _useState4[0],
52
- setSideNavState = _useState4[1]; // Animating states need to be reset here otherwise things won't render
53
- // the way they should after the component mounts/unmounts
54
-
55
- /* istanbul ignore next */
56
-
57
-
58
- useEffect(function () {
59
- if (!(previousState !== null && previousState !== void 0 && previousState.open) && open) {
60
- setSideNavState('');
61
- setProgressIndicatorState('');
62
- }
63
- }, [open, previousState]);
64
- /* istanbul ignore next */
65
-
66
- var handleViewAllToggle = function handleViewAllToggle(newToggleValue) {
67
- if (newToggleValue) {
68
- setProgressIndicatorState('closing');
69
- setTimeout(function () {
70
- handleToggleState(newToggleValue);
71
- setSideNavState('opening');
72
- }, moderate02);
73
- } else {
74
- setSideNavState('closing');
75
- setTimeout(function () {
76
- handleToggleState(newToggleValue);
77
- setProgressIndicatorState('opening');
78
- }, moderate02);
79
- }
20
+ stepData = _ref.stepData;
80
21
 
81
- handleActiveSectionIndex(0);
82
- var createComponentContainer = document.querySelector(".".concat(componentBlockClass));
22
+ var getNumberOfDynamicStepsBeforeCurrentStep = function getNumberOfDynamicStepsBeforeCurrentStep(array, key) {
23
+ var dynamicSteps = [];
24
+ array.forEach(function (item, index) {
25
+ var _array$index;
83
26
 
84
- if (createComponentContainer) {
85
- createComponentContainer.scrollTop = 0;
86
- }
87
- };
88
-
89
- var renderViewAllToggle = function renderViewAllToggle() {
90
- return /*#__PURE__*/React.createElement(Toggle, {
91
- id: "".concat(blockClass, "__view-all-toggle"),
92
- toggled: toggleState,
93
- labelText: viewAllToggleLabelText,
94
- labelA: viewAllToggleOffLabelText,
95
- labelB: viewAllToggleOnLabelText,
96
- onToggle: function onToggle(value) {
97
- return handleViewAllToggle(value);
98
- },
99
- className: "".concat(blockClass, "__view-all-toggle"),
100
- defaultToggled: false
27
+ if (((_array$index = array[index]) === null || _array$index === void 0 ? void 0 : _array$index[key]) === false && index <= currentStep - 1) {
28
+ dynamicSteps.push(item);
29
+ }
101
30
  });
31
+ return dynamicSteps.length;
102
32
  }; // renders the step progression components in the left influencer area
103
33
 
104
34
 
105
35
  var renderProgressSteps = function renderProgressSteps() {
106
- var _createComponents$ste, _createComponents$ste2, _cx2;
107
-
108
- /* istanbul ignore next */
109
- if (toggleState) {
110
- var _cx, _createComponents$sec;
111
-
112
- return /*#__PURE__*/React.createElement("div", {
113
- className: "".concat(blockClass, "__left-nav")
114
- }, /*#__PURE__*/React.createElement(SideNav, {
115
- expanded: true,
116
- isFixedNav: true,
117
- "aria-label": sideNavAriaLabel,
118
- className: cx((_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__side-nav-opening"), sideNavState === 'opening'), _defineProperty(_cx, "".concat(blockClass, "__side-nav-closing"), sideNavState === 'closing'), _cx))
119
- }, /*#__PURE__*/React.createElement(SideNavItems, null, ((_createComponents$sec = createComponents.sections) === null || _createComponents$sec === void 0 ? void 0 : _createComponents$sec.length) && createComponents.sections.map(function (sectionComponent, sectionIndex) {
120
- var _sectionComponent$pro;
121
-
122
- return /*#__PURE__*/React.createElement(SideNavLink, {
123
- href: "#".concat(sectionComponent === null || sectionComponent === void 0 ? void 0 : (_sectionComponent$pro = sectionComponent.props) === null || _sectionComponent$pro === void 0 ? void 0 : _sectionComponent$pro.id),
124
- key: sectionIndex,
125
- isActive: activeSectionIndex === sectionIndex,
126
- onClick: function onClick(event) {
127
- event.preventDefault();
128
- handleActiveSectionIndex(sectionIndex);
129
-
130
- if (sectionComponent.props.id) {
131
- var _scrollTarget$getBoun;
132
-
133
- var scrollTarget = document.querySelector("#".concat(sectionComponent.props.id));
134
- var scrollContainer = document.querySelector(".".concat(componentBlockClass, "__content"));
135
- var scrollTopValue = createComponentName === 'CreateFullPage' ? (scrollTarget === null || scrollTarget === void 0 ? void 0 : (_scrollTarget$getBoun = scrollTarget.getBoundingClientRect()) === null || _scrollTarget$getBoun === void 0 ? void 0 : _scrollTarget$getBoun.y) + (scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTop) : scrollTarget === null || scrollTarget === void 0 ? void 0 : scrollTarget.offsetTop;
136
- scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
137
- top: scrollTopValue,
138
- behavior: 'smooth'
139
- });
140
- } else {
141
- console.warn("".concat(createComponentName, ": ").concat(createComponentName, "Section component is missing a required prop of 'id'"));
142
- }
143
- }
144
- }, sectionComponent.props.title);
145
- }))));
146
- }
36
+ var _stepData$, _stepData$2;
147
37
 
148
- var extractedSteps = getExtractedSteps(createComponents.steps, createComponentName === CreateTearsheet.displayName ? CREATE_TEARSHEET_STEP : CREATE_FULL_PAGE_STEP);
149
- var stepsWithoutIntroStep = extractedSteps.filter(function (item) {
150
- return !item.props.introStep;
38
+ var extractedSteps = stepData === null || stepData === void 0 ? void 0 : stepData.filter(function (item) {
39
+ return !(item !== null && item !== void 0 && item.introStep);
151
40
  });
152
- var introStepFound = !!createComponents.steps.filter(function (item) {
153
- return item.props.introStep;
154
- }).length;
41
+ var progressSteps = extractedSteps === null || extractedSteps === void 0 ? void 0 : extractedSteps.filter(function (item) {
42
+ return item === null || item === void 0 ? void 0 : item.shouldIncludeStep;
43
+ }); // To get the ProgressIndicator's `currentIndex`, accounting for dynamic steps,
44
+ // we need to subtract the number of !shouldIncludeStep/s before the current step
45
+ // which we get from `getNumberOfDynamicStepsBeforeCurrentStep()`
46
+
47
+ var totalDynamicSteps = getNumberOfDynamicStepsBeforeCurrentStep(stepData, 'shouldIncludeStep') || 0;
155
48
  return /*#__PURE__*/React.createElement("div", {
156
49
  className: "".concat(blockClass, "__left-nav")
157
- }, currentStep === 1 && (_createComponents$ste = createComponents.steps[0]) !== null && _createComponents$ste !== void 0 && (_createComponents$ste2 = _createComponents$ste.props) !== null && _createComponents$ste2 !== void 0 && _createComponents$ste2.introStep ? null : /*#__PURE__*/React.createElement(ProgressIndicator, {
158
- currentIndex: introStepFound ? currentStep - 2 : currentStep - 1,
50
+ }, currentStep === 1 && (_stepData$ = stepData[0]) !== null && _stepData$ !== void 0 && _stepData$.introStep ? null : /*#__PURE__*/React.createElement(ProgressIndicator, {
51
+ currentIndex: (_stepData$2 = stepData[0]) !== null && _stepData$2 !== void 0 && _stepData$2.introStep ? currentStep - totalDynamicSteps - 2 // minus 2 because we need to account for the intro step in addition to `currentIndex` being 0 index based and our steps being 1 index based
52
+ : currentStep - totalDynamicSteps - 1 // minus 1 because ProgressIndicator currentIndex prop is 0 index based, but our steps are 1 index based
53
+ ,
159
54
  spaceEqually: true,
160
55
  vertical: true,
161
- className: cx("".concat(blockClass, "__progress-indicator"), (_cx2 = {}, _defineProperty(_cx2, "".concat(blockClass, "__progress-indicator-opening"), progressIndicatorState === 'opening'), _defineProperty(_cx2, "".concat(blockClass, "__progress-indicator-closing"), progressIndicatorState === 'closing'), _cx2))
162
- }, stepsWithoutIntroStep.map(function (child, stepIndex) {
56
+ className: cx("".concat(blockClass, "__progress-indicator"))
57
+ }, progressSteps.map(function (step, stepIndex) {
163
58
  return /*#__PURE__*/React.createElement(ProgressStep, {
164
- label: child.props.title,
59
+ label: step.title,
165
60
  key: stepIndex,
166
- secondaryLabel: child.props.secondaryLabel
61
+ secondaryLabel: step.secondaryLabel
167
62
  });
168
63
  })));
169
64
  };
170
65
 
171
66
  return /*#__PURE__*/React.createElement("div", {
172
67
  className: cx(blockClass, className)
173
- }, renderProgressSteps(), includeViewAllToggle && renderViewAllToggle());
68
+ }, renderProgressSteps());
174
69
  }; // The display name of the component, used by React. Note that displayName
175
70
  // is used in preference to relying on function.name.
176
71
 
177
72
  CreateInfluencer.displayName = componentName;
178
73
  CreateInfluencer.propTypes = {
179
- /**
180
- * Sets the active side nav item when toggle is on
181
- */
182
- activeSectionIndex: PropTypes.number.isRequired,
183
-
184
74
  /**
185
75
  * Provide an optional class to be applied to the containing node.
186
76
  */
187
77
  className: PropTypes.string,
188
78
 
189
- /**
190
- * The blockClass for the create component (Tearsheet or FullPage)
191
- */
192
- componentBlockClass: PropTypes.string.isRequired,
193
-
194
- /**
195
- * Used to mark the current step on the ProgressIndicator component
196
- */
197
- createComponentName: PropTypes.string.isRequired,
198
-
199
- /**
200
- * An object with section and step components, needed to render the progress steps. This is where the titles are retrieved from.
201
- */
202
- createComponents: PropTypes.shape({
203
- steps: PropTypes.arrayOf(PropTypes.element),
204
- sections: PropTypes.arrayOf(PropTypes.element)
205
- }).isRequired,
206
-
207
79
  /**
208
80
  * Used to mark the current step on the ProgressIndicator component
209
81
  */
210
82
  currentStep: PropTypes.number.isRequired,
211
83
 
212
84
  /**
213
- * Handler used to set the active section index
214
- */
215
- handleActiveSectionIndex: PropTypes.func,
216
-
217
- /**
218
- * Handler used to track the state of the toggle
219
- */
220
- handleToggleState: PropTypes.func,
221
-
222
- /**
223
- * Used to optionally include view all toggle
224
- */
225
- includeViewAllToggle: PropTypes.bool,
226
-
227
- /**
228
- * This is the open state of the CreateComponent in which the CreateInfluencer is used from
229
- */
230
- open: PropTypes.bool,
231
-
232
- /**
233
- * This is the open state of the CreateComponent in which the CreateInfluencer is used from
234
- */
235
- previousState: PropTypes.object,
236
-
237
- /**
238
- * The aria label to be used for the UI Shell SideNav Carbon component
239
- */
240
- sideNavAriaLabel: PropTypes.string.isRequired.if(function (_ref2) {
241
- var includeViewAllToggle = _ref2.includeViewAllToggle;
242
- return includeViewAllToggle;
243
- }),
244
-
245
- /**
246
- * The current toggled state to be provided to the Toggle component
247
- */
248
- toggleState: PropTypes.bool,
249
-
250
- /**
251
- * Sets the label text for the view all toggle component
252
- */
253
- viewAllToggleLabelText: PropTypes.string.isRequired.if(function (_ref3) {
254
- var includeViewAllToggle = _ref3.includeViewAllToggle;
255
- return includeViewAllToggle === true;
256
- }),
257
-
258
- /**
259
- * Sets the label text for the view all toggle `off` text
260
- */
261
- viewAllToggleOffLabelText: PropTypes.string.isRequired.if(function (_ref4) {
262
- var includeViewAllToggle = _ref4.includeViewAllToggle;
263
- return includeViewAllToggle === true;
264
- }),
265
-
266
- /**
267
- * Sets the label text for the view all toggle `on` text
85
+ * The step data that renders the progress items
268
86
  */
269
- viewAllToggleOnLabelText: PropTypes.string.isRequired.if(function (_ref5) {
270
- var includeViewAllToggle = _ref5.includeViewAllToggle;
271
- return includeViewAllToggle === true;
272
- })
87
+ stepData: PropTypes.arrayOf(PropTypes.shape({
88
+ introStep: PropTypes.bool,
89
+ secondaryLabel: PropTypes.string,
90
+ shouldIncludeStep: PropTypes.bool,
91
+ title: PropTypes.node
92
+ }))
273
93
  };
@@ -1,16 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
5
- var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "description", "includeViewAllToggle", "influencerWidth", "initialStep", "label", "nextButtonText", "onClose", "onRequestSubmit", "open", "sideNavAriaLabel", "submitButtonText", "title", "verticalPosition", "viewAllToggleLabelText", "viewAllToggleOffLabelText", "viewAllToggleOnLabelText"];
4
+ var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "description", "influencerWidth", "initialStep", "label", "nextButtonText", "onClose", "onRequestSubmit", "open", "submitButtonText", "title", "verticalPosition"];
6
5
 
7
6
  /**
8
- * Copyright IBM Corp. 2021, 2021
7
+ * Copyright IBM Corp. 2021, 2022
9
8
  *
10
9
  * This source code is licensed under the Apache-2.0 license found in the
11
10
  * LICENSE file in the root directory of this source tree.
12
11
  */
13
- import React, { forwardRef, useCallback, useState, useRef } from 'react';
12
+ import React, { forwardRef, useState, useRef, createContext, useEffect } from 'react';
14
13
  import PropTypes from 'prop-types';
15
14
  import cx from 'classnames';
16
15
  import { Grid, Form } from 'carbon-components-react';
@@ -18,19 +17,24 @@ import wrapFocus from '../../global/js/utils/wrapFocus';
18
17
  import { TearsheetShell } from '../Tearsheet/TearsheetShell';
19
18
  import { CreateInfluencer } from '../CreateInfluencer';
20
19
  import { pkg } from '../../settings';
21
- import { CREATE_TEARSHEET_SECTION, CREATE_TEARSHEET_STEP } from './constants';
22
20
  import { usePreviousValue, useValidCreateStepCount, useResetCreateComponent, useCreateComponentFocus, useCreateComponentStepChange } from '../../global/js/hooks';
23
- import { hasValidChildrenType, hasValidChildType, getExtractedSteps } from '../../global/js/utils/hasValidType';
24
21
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
22
+ import { lastIndexInArray } from '../../global/js/utils/lastIndexInArray';
25
23
  var componentName = 'CreateTearsheet';
26
- var blockClass = "".concat(pkg.prefix, "--tearsheet-create");
24
+ var blockClass = "".concat(pkg.prefix, "--tearsheet-create"); // This is a general context for the steps container
25
+ // containing information about the state of the container
26
+ // and providing some callback methods for steps to use
27
+
28
+ export var StepsContext = /*#__PURE__*/createContext(null); // This is a context supplied separately to each step in the container
29
+ // to let it know what number it is in the sequence of steps
30
+
31
+ export var StepNumberContext = /*#__PURE__*/createContext(-1);
27
32
  export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
28
33
  var backButtonText = _ref.backButtonText,
29
34
  cancelButtonText = _ref.cancelButtonText,
30
35
  children = _ref.children,
31
36
  className = _ref.className,
32
37
  description = _ref.description,
33
- includeViewAllToggle = _ref.includeViewAllToggle,
34
38
  influencerWidth = _ref.influencerWidth,
35
39
  initialStep = _ref.initialStep,
36
40
  label = _ref.label,
@@ -38,13 +42,9 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
38
42
  onClose = _ref.onClose,
39
43
  onRequestSubmit = _ref.onRequestSubmit,
40
44
  open = _ref.open,
41
- sideNavAriaLabel = _ref.sideNavAriaLabel,
42
45
  submitButtonText = _ref.submitButtonText,
43
46
  title = _ref.title,
44
47
  verticalPosition = _ref.verticalPosition,
45
- viewAllToggleLabelText = _ref.viewAllToggleLabelText,
46
- viewAllToggleOffLabelText = _ref.viewAllToggleOffLabelText,
47
- viewAllToggleOnLabelText = _ref.viewAllToggleOnLabelText,
48
48
  rest = _objectWithoutProperties(_ref, _excluded);
49
49
 
50
50
  var _useState = useState([]),
@@ -67,40 +67,83 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
67
67
  isSubmitting = _useState8[0],
68
68
  setIsSubmitting = _useState8[1];
69
69
 
70
- var _useState9 = useState(0),
70
+ var _useState9 = useState(false),
71
71
  _useState10 = _slicedToArray(_useState9, 2),
72
- activeSectionIndex = _useState10[0],
73
- setActiveSectionIndex = _useState10[1];
72
+ isDisabled = _useState10[0],
73
+ setIsDisabled = _useState10[1];
74
+
75
+ var _useState11 = useState(),
76
+ _useState12 = _slicedToArray(_useState11, 2),
77
+ onNext = _useState12[0],
78
+ _setOnNext = _useState12[1];
79
+
80
+ var _useState13 = useState(),
81
+ _useState14 = _slicedToArray(_useState13, 2),
82
+ onMount = _useState14[0],
83
+ _setOnMount = _useState14[1];
84
+
85
+ var _useState15 = useState([]),
86
+ _useState16 = _slicedToArray(_useState15, 2),
87
+ stepData = _useState16[0],
88
+ setStepData = _useState16[1];
89
+
90
+ var _useState17 = useState(1),
91
+ _useState18 = _slicedToArray(_useState17, 2),
92
+ firstIncludedStep = _useState18[0],
93
+ setFirstIncludedStep = _useState18[1];
94
+
95
+ var _useState19 = useState(null),
96
+ _useState20 = _slicedToArray(_useState19, 2),
97
+ lastIncludedStep = _useState20[0],
98
+ setLastIncludedStep = _useState20[1];
74
99
 
75
100
  var previousState = usePreviousValue({
76
101
  currentStep: currentStep,
77
102
  open: open
78
103
  });
79
- var contentRef = useRef(); // returns an array of tearsheet steps
80
-
81
- var getTearsheetSteps = useCallback(function () {
82
- var childrenArray = Array.isArray(children) ? children : [children];
83
- var steps = getExtractedSteps(childrenArray, CREATE_TEARSHEET_STEP);
84
- return steps;
85
- }, [children]);
86
- useCreateComponentFocus(previousState, currentStep, getTearsheetSteps, blockClass);
87
- useValidCreateStepCount(getTearsheetSteps, componentName);
104
+ var contentRef = useRef();
105
+ useEffect(function () {
106
+ var firstItem = stepData.findIndex(function (item) {
107
+ return item === null || item === void 0 ? void 0 : item.shouldIncludeStep;
108
+ }) + 1;
109
+ var lastItem = lastIndexInArray(stepData, 'shouldIncludeStep', true);
110
+
111
+ if (firstItem !== firstIncludedStep) {
112
+ setFirstIncludedStep(firstItem);
113
+ }
114
+
115
+ if (lastItem !== lastIncludedStep) {
116
+ setLastIncludedStep(lastItem);
117
+ }
118
+ }, [stepData, firstIncludedStep, lastIncludedStep]);
119
+ useCreateComponentFocus({
120
+ previousState: previousState,
121
+ currentStep: currentStep,
122
+ blockClass: blockClass,
123
+ onMount: onMount
124
+ });
125
+ useValidCreateStepCount(stepData.length, componentName);
88
126
  useResetCreateComponent({
127
+ firstIncludedStep: firstIncludedStep,
89
128
  previousState: previousState,
90
129
  open: open,
91
130
  setCurrentStep: setCurrentStep,
92
131
  initialStep: initialStep,
93
- totalSteps: getTearsheetSteps().length,
132
+ totalSteps: stepData === null || stepData === void 0 ? void 0 : stepData.length,
94
133
  componentName: componentName
95
134
  });
96
135
  useCreateComponentStepChange({
136
+ firstIncludedStep: firstIncludedStep,
137
+ lastIncludedStep: lastIncludedStep,
138
+ stepData: stepData,
139
+ onNext: onNext,
140
+ isSubmitDisabled: isDisabled,
97
141
  setCurrentStep: setCurrentStep,
98
142
  setIsSubmitting: setIsSubmitting,
99
143
  setShouldViewAll: setShouldViewAll,
100
144
  onClose: onClose,
101
145
  onRequestSubmit: onRequestSubmit,
102
146
  componentName: componentName,
103
- getComponentSteps: getTearsheetSteps,
104
147
  currentStep: currentStep,
105
148
  shouldViewAll: shouldViewAll,
106
149
  backButtonText: backButtonText,
@@ -110,62 +153,10 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
110
153
  isSubmitting: isSubmitting,
111
154
  componentBlockClass: blockClass,
112
155
  setCreateComponentActions: setCreateTearsheetActions
113
- });
114
-
115
- var getTearsheetComponents = function getTearsheetComponents(childrenElements) {
116
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
117
- var tearsheetStepComponents = getExtractedSteps(childrenArray, CREATE_TEARSHEET_STEP);
118
- var tearsheetSectionComponents = [];
119
- tearsheetStepComponents.forEach(function (child) {
120
- var _child$props, _child$props$children;
121
-
122
- // we have received an array of children, lets check to see that each child is
123
- // a CreateTearsheetSection component before adding it to tearsheetSectionComponents
124
- if (shouldViewAll && child !== null && child !== void 0 && (_child$props = child.props) !== null && _child$props !== void 0 && (_child$props$children = _child$props.children) !== null && _child$props$children !== void 0 && _child$props$children.length && typeof child.props.children !== 'string') {
125
- child.props.children.forEach(function (stepChild) {
126
- if (hasValidChildType({
127
- child: stepChild,
128
- type: CREATE_TEARSHEET_SECTION
129
- })) {
130
- tearsheetSectionComponents.push(stepChild);
131
- }
132
- });
133
- } // we have received a single child element, lets check to see that it is
134
- // a CreateTearsheetSection component before adding it to tearsheetSectionComponents
135
-
136
-
137
- if (shouldViewAll && typeof child.props.children !== 'undefined' && !child.props.children.length) {
138
- if (hasValidChildType({
139
- child: child.props.children,
140
- type: CREATE_TEARSHEET_SECTION
141
- })) {
142
- tearsheetSectionComponents.push(child.props.children);
143
- }
144
- }
145
- });
146
- return {
147
- sections: tearsheetSectionComponents,
148
- steps: tearsheetStepComponents
149
- };
150
- }; // renders all children (CreateTearsheetSteps)
151
-
152
-
153
- var renderChildren = function renderChildren(childrenElements) {
154
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
155
- var extractedSteps = getExtractedSteps(childrenArray, CREATE_TEARSHEET_STEP);
156
- return /*#__PURE__*/React.createElement(React.Fragment, null, extractedSteps.map(function (child, stepIndex) {
157
- var _cx;
158
-
159
- return /*#__PURE__*/React.cloneElement(child, {
160
- className: cx(child.props.className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__step--hidden-step"), !shouldViewAll && currentStep !== stepIndex + 1), _defineProperty(_cx, "".concat(blockClass, "__step--visible-step"), currentStep === stepIndex + 1), _cx)),
161
- key: "key_".concat(stepIndex)
162
- });
163
- }));
164
- }; // adds focus trap functionality
156
+ }); // adds focus trap functionality
165
157
 
166
158
  /* istanbul ignore next */
167
159
 
168
-
169
160
  var handleBlur = function handleBlur(_ref2) {
170
161
  var oldActiveNode = _ref2.target,
171
162
  currentActiveNode = _ref2.relatedTarget;
@@ -186,25 +177,8 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
186
177
  description: description,
187
178
  hasCloseIcon: false,
188
179
  influencer: /*#__PURE__*/React.createElement(CreateInfluencer, {
189
- activeSectionIndex: activeSectionIndex,
190
- componentBlockClass: blockClass,
191
- createComponentName: componentName,
192
180
  currentStep: currentStep,
193
- createComponents: getTearsheetComponents(children),
194
- includeViewAllToggle: includeViewAllToggle,
195
- handleToggleState: function handleToggleState(toggleState) {
196
- return setShouldViewAll(toggleState);
197
- },
198
- handleActiveSectionIndex: function handleActiveSectionIndex(index) {
199
- return setActiveSectionIndex(index);
200
- },
201
- open: open,
202
- previousState: previousState,
203
- sideNavAriaLabel: sideNavAriaLabel,
204
- toggleState: shouldViewAll,
205
- viewAllToggleLabelText: viewAllToggleLabelText,
206
- viewAllToggleOffLabelText: viewAllToggleOffLabelText,
207
- viewAllToggleOnLabelText: viewAllToggleOnLabelText
181
+ stepData: stepData
208
182
  }),
209
183
  influencerPosition: "left",
210
184
  influencerWidth: influencerWidth,
@@ -219,7 +193,28 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
219
193
  className: "".concat(blockClass, "__content"),
220
194
  onBlur: handleBlur,
221
195
  ref: contentRef
222
- }, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Form, null, renderChildren(children)))));
196
+ }, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(StepsContext.Provider, {
197
+ value: {
198
+ currentStep: currentStep,
199
+ setIsDisabled: setIsDisabled,
200
+ setOnNext: function setOnNext(fn) {
201
+ return _setOnNext(function () {
202
+ return fn;
203
+ });
204
+ },
205
+ setOnMount: function setOnMount(fn) {
206
+ return _setOnMount(function () {
207
+ return fn;
208
+ });
209
+ },
210
+ setStepData: setStepData,
211
+ stepData: stepData
212
+ }
213
+ }, React.Children.map(children, function (child, index) {
214
+ return /*#__PURE__*/React.createElement(StepNumberContext.Provider, {
215
+ value: index + 1
216
+ }, child);
217
+ }))))));
223
218
  }); // Return a placeholder if not released and not enabled by feature flag
224
219
 
225
220
  CreateTearsheet = pkg.checkComponentEnabled(CreateTearsheet, componentName); // The display name of the component, used by React. Note that displayName
@@ -242,10 +237,7 @@ CreateTearsheet.propTypes = {
242
237
  /**
243
238
  * The main content of the tearsheet
244
239
  */
245
- children: hasValidChildrenType({
246
- componentName: componentName,
247
- childType: CREATE_TEARSHEET_STEP
248
- }),
240
+ children: PropTypes.node,
249
241
 
250
242
  /**
251
243
  * An optional class or classes to be added to the outermost element.
@@ -257,12 +249,6 @@ CreateTearsheet.propTypes = {
257
249
  */
258
250
  description: PropTypes.node,
259
251
 
260
- /**
261
- * @ignore
262
- * Used to optionally include view all toggle
263
- */
264
- includeViewAllToggle: PropTypes.bool,
265
-
266
252
  /**
267
253
  * Used to set the size of the influencer
268
254
  */
@@ -305,15 +291,6 @@ CreateTearsheet.propTypes = {
305
291
  */
306
292
  open: PropTypes.bool,
307
293
 
308
- /**
309
- * @ignore
310
- * The aria label to be used for the UI Shell SideNav Carbon component
311
- */
312
- sideNavAriaLabel: PropTypes.string.isRequired.if(function (_ref3) {
313
- var includeViewAllToggle = _ref3.includeViewAllToggle;
314
- return includeViewAllToggle;
315
- }),
316
-
317
294
  /**
318
295
  * The submit button text
319
296
  */
@@ -331,34 +308,7 @@ CreateTearsheet.propTypes = {
331
308
  * from below. The 'lower' position provides a little extra room at the top
332
309
  * to allow an action bar navigation or breadcrumbs to also show through.
333
310
  */
334
- verticalPosition: PropTypes.oneOf(['normal', 'lower']),
335
-
336
- /**
337
- * @ignore
338
- * Sets the label text for the view all toggle component
339
- */
340
- viewAllToggleLabelText: PropTypes.string.isRequired.if(function (_ref4) {
341
- var includeViewAllToggle = _ref4.includeViewAllToggle;
342
- return includeViewAllToggle === true;
343
- }),
344
-
345
- /**
346
- * @ignore
347
- * Sets the label text for the view all toggle `off` text
348
- */
349
- viewAllToggleOffLabelText: PropTypes.string.isRequired.if(function (_ref5) {
350
- var includeViewAllToggle = _ref5.includeViewAllToggle;
351
- return includeViewAllToggle === true;
352
- }),
353
-
354
- /**
355
- * @ignore
356
- * Sets the label text for the view all toggle `on` text
357
- */
358
- viewAllToggleOnLabelText: PropTypes.string.isRequired.if(function (_ref6) {
359
- var includeViewAllToggle = _ref6.includeViewAllToggle;
360
- return includeViewAllToggle === true;
361
- })
311
+ verticalPosition: PropTypes.oneOf(['normal', 'lower'])
362
312
  }; // Default values for component props. Default values are not required for
363
313
  // props that are required, nor for props where the component can apply
364
314
  // 'undefined' values reasonably. Default values should be provided when the
@@ -366,6 +316,5 @@ CreateTearsheet.propTypes = {
366
316
 
367
317
  CreateTearsheet.defaultProps = {
368
318
  verticalPosition: 'normal',
369
- includeViewAllToggle: false,
370
319
  influencerWidth: 'narrow'
371
320
  };