@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,37 +1,41 @@
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", "includeViewAllToggle", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "sideNavAriaLabel", "submitButtonText", "viewAllToggleLabelText", "viewAllToggleOffLabelText", "viewAllToggleOnLabelText"];
4
+ var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "submitButtonText"];
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
12
  // Import portions of React that are needed.
14
- import React, { useEffect, useCallback, useState } from 'react'; // Other standard imports.
13
+ import React, { useEffect, useState, createContext } from 'react'; // Other standard imports.
15
14
 
16
15
  import PropTypes from 'prop-types';
17
16
  import cx from 'classnames';
18
17
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
19
- import { pkg } from '../../settings';
20
- import { CREATE_FULL_PAGE_SECTION, CREATE_FULL_PAGE_STEP } from './constants'; // Carbon and package components we use.
18
+ import { pkg } from '../../settings'; // Carbon and package components we use.
21
19
 
22
20
  import { Grid, ModalFooter, ComposedModal, ModalHeader, ModalBody, Button, Form } from 'carbon-components-react';
23
21
  import { CreateInfluencer } from '../CreateInfluencer';
24
22
  import { ActionSet } from '../ActionSet';
25
23
  import { usePreviousValue, useValidCreateStepCount, useCreateComponentFocus, useCreateComponentStepChange } from '../../global/js/hooks';
26
- import { hasValidChildrenType } from '../../global/js/utils/hasValidType';
24
+ import { lastIndexInArray } from '../../global/js/utils/lastIndexInArray';
27
25
  var blockClass = "".concat(pkg.prefix, "--create-full-page");
28
- var componentName = 'CreateFullPage';
26
+ var componentName = 'CreateFullPage'; // This is a general context for the steps container
27
+ // containing information about the state of the container
28
+ // and providing some callback methods for steps to use
29
+
30
+ export var StepsContext = /*#__PURE__*/createContext(null); // This is a context supplied separately to each step in the container
31
+ // to let it know what number it is in the sequence of steps
32
+
33
+ export var StepNumberContext = /*#__PURE__*/createContext(-1);
29
34
  export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
30
35
  var backButtonText = _ref.backButtonText,
31
36
  cancelButtonText = _ref.cancelButtonText,
32
37
  children = _ref.children,
33
38
  className = _ref.className,
34
- includeViewAllToggle = _ref.includeViewAllToggle,
35
39
  modalDangerButtonText = _ref.modalDangerButtonText,
36
40
  modalDescription = _ref.modalDescription,
37
41
  modalSecondaryButtonText = _ref.modalSecondaryButtonText,
@@ -39,11 +43,7 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
39
43
  nextButtonText = _ref.nextButtonText,
40
44
  onClose = _ref.onClose,
41
45
  onRequestSubmit = _ref.onRequestSubmit,
42
- sideNavAriaLabel = _ref.sideNavAriaLabel,
43
46
  submitButtonText = _ref.submitButtonText,
44
- viewAllToggleLabelText = _ref.viewAllToggleLabelText,
45
- viewAllToggleOffLabelText = _ref.viewAllToggleOffLabelText,
46
- viewAllToggleOnLabelText = _ref.viewAllToggleOnLabelText,
47
47
  rest = _objectWithoutProperties(_ref, _excluded);
48
48
 
49
49
  var _useState = useState([]),
@@ -61,49 +61,84 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
61
61
  currentStep = _useState6[0],
62
62
  setCurrentStep = _useState6[1];
63
63
 
64
- var _useState7 = useState(0),
64
+ var _useState7 = useState(false),
65
65
  _useState8 = _slicedToArray(_useState7, 2),
66
- activeSectionIndex = _useState8[0],
67
- setActiveSectionIndex = _useState8[1];
66
+ isSubmitting = _useState8[0],
67
+ setIsSubmitting = _useState8[1];
68
68
 
69
69
  var _useState9 = useState(false),
70
70
  _useState10 = _slicedToArray(_useState9, 2),
71
- isSubmitting = _useState10[0],
72
- setIsSubmitting = _useState10[1];
71
+ modalIsOpen = _useState10[0],
72
+ setModalIsOpen = _useState10[1];
73
+
74
+ var previousState = usePreviousValue({
75
+ currentStep: currentStep,
76
+ open: open
77
+ });
73
78
 
74
79
  var _useState11 = useState(false),
75
80
  _useState12 = _slicedToArray(_useState11, 2),
76
- modalIsOpen = _useState12[0],
77
- setModalIsOpen = _useState12[1];
81
+ isDisabled = _useState12[0],
82
+ setIsDisabled = _useState12[1];
83
+
84
+ var _useState13 = useState(),
85
+ _useState14 = _slicedToArray(_useState13, 2),
86
+ onNext = _useState14[0],
87
+ _setOnNext = _useState14[1];
88
+
89
+ var _useState15 = useState(),
90
+ _useState16 = _slicedToArray(_useState15, 2),
91
+ onMount = _useState16[0],
92
+ _setOnMount = _useState16[1];
93
+
94
+ var _useState17 = useState([]),
95
+ _useState18 = _slicedToArray(_useState17, 2),
96
+ stepData = _useState18[0],
97
+ setStepData = _useState18[1];
98
+
99
+ var _useState19 = useState(1),
100
+ _useState20 = _slicedToArray(_useState19, 2),
101
+ firstIncludedStep = _useState20[0],
102
+ setFirstIncludedStep = _useState20[1];
103
+
104
+ var _useState21 = useState(null),
105
+ _useState22 = _slicedToArray(_useState21, 2),
106
+ lastIncludedStep = _useState22[0],
107
+ setLastIncludedStep = _useState22[1];
78
108
 
79
- var previousState = usePreviousValue({
109
+ useEffect(function () {
110
+ var firstItem = stepData.findIndex(function (item) {
111
+ return item === null || item === void 0 ? void 0 : item.shouldIncludeStep;
112
+ }) + 1;
113
+ var lastItem = lastIndexInArray(stepData, 'shouldIncludeStep', true);
114
+
115
+ if (firstItem !== firstIncludedStep) {
116
+ setFirstIncludedStep(firstItem);
117
+ }
118
+
119
+ if (lastItem !== lastIncludedStep) {
120
+ setLastIncludedStep(lastItem);
121
+ }
122
+ }, [stepData, firstIncludedStep, lastIncludedStep]);
123
+ useCreateComponentFocus({
124
+ previousState: previousState,
80
125
  currentStep: currentStep,
81
- open: open
82
- }); // returns an array of full page steps
83
-
84
- var getFullPageSteps = useCallback(function () {
85
- var _childrenArray$;
86
-
87
- var steps = [];
88
- var childrenArray = Array.isArray(children) ? children : [children];
89
- var extractedChildren = childrenArray && ((_childrenArray$ = childrenArray[0]) === null || _childrenArray$ === void 0 ? void 0 : _childrenArray$.type) === React.Fragment ? childrenArray[0].props.children : childrenArray;
90
- extractedChildren.forEach(function (child) {
91
- if (isFullPageStep(child)) {
92
- steps.push(child);
93
- }
94
- });
95
- return steps;
96
- }, [children]);
97
- useCreateComponentFocus(previousState, currentStep, getFullPageSteps, blockClass);
98
- useValidCreateStepCount(getFullPageSteps, componentName);
126
+ blockClass: blockClass,
127
+ onMount: onMount
128
+ });
129
+ useValidCreateStepCount(stepData.length, componentName);
99
130
  useCreateComponentStepChange({
131
+ firstIncludedStep: firstIncludedStep,
132
+ lastIncludedStep: lastIncludedStep,
133
+ stepData: stepData,
134
+ onNext: onNext,
135
+ isSubmitDisabled: isDisabled,
100
136
  setCurrentStep: setCurrentStep,
101
137
  setIsSubmitting: setIsSubmitting,
102
138
  setShouldViewAll: setShouldViewAll,
103
139
  onClose: onClose,
104
140
  onRequestSubmit: onRequestSubmit,
105
141
  componentName: componentName,
106
- getComponentSteps: getFullPageSteps,
107
142
  currentStep: currentStep,
108
143
  shouldViewAll: shouldViewAll,
109
144
  backButtonText: backButtonText,
@@ -114,200 +149,18 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
114
149
  componentBlockClass: blockClass,
115
150
  setCreateComponentActions: setCreateFullPageActions,
116
151
  setModalIsOpen: setModalIsOpen
117
- }); // Log a warning to the console in the event there are no CreateFullPageSection components
118
- // inside of the CreateFullPageSteps when the viewAll toggle is provided and turned on.
119
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
152
+ }); // currently, we are not supporting the use of 'view all' toggle state
120
153
 
121
154
  /* istanbul ignore next */
122
155
 
123
- useEffect(function () {
124
- if (includeViewAllToggle && shouldViewAll) {
125
- var childrenArray = Array.isArray(children) ? children : [children];
126
- var fullPageStepComponents = childrenArray.filter(function (child) {
127
- return isFullPageStep(child);
128
- });
129
- var fullPageSectionComponents = [];
130
- fullPageStepComponents.forEach(function (child, index) {
131
- // We have received children for a FullPageStep
132
- if (shouldViewAll && typeof child.props.children !== 'undefined') {
133
- // Only a string was provided as children of CreateFullPageStep, this is not permitted when using view all toggle
134
- if (typeof child.props.children === 'string') {
135
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
136
- } else {
137
- // The FullPageStep has an array of children, lets check each one to see if it is a FullPageSection
138
- if (child.props.children.length) {
139
- child.props.children.forEach(function (stepChild) {
140
- if (isFullPageSection(stepChild)) {
141
- fullPageSectionComponents.push(stepChild);
142
- }
143
- });
144
- } else {
145
- // The FullPageStep only has a single React element as a child, lets check to see if it is a FullPageSection
146
- if (isFullPageSection(child.props.children)) {
147
- fullPageSectionComponents.push(child.props.children);
148
- }
149
- }
150
- }
151
- } // If there are fewer CreateFullPageSection components than CreateFullPageStep components
152
- // it means that each CreateFullPageStep does not have at least one CreateFullPageSection
153
- // this is not permitted when using view all toggle
154
-
155
-
156
- if (fullPageSectionComponents.length < fullPageStepComponents.length && index === fullPageStepComponents.length - 1 // wait until we've finished checking each FullPageStep before giving a warning
157
- ) {
158
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
159
- } // We have received a single child element, lets check to see that it is
160
- // a CreateFullPageSection component, if it is not we should add a console
161
- // warning, as each CreateFullPageStep required at least one CreateFullPageSection,
162
- // when using the view all toggle
163
-
164
-
165
- if (shouldViewAll && typeof child.props.children !== 'undefined' && !child.props.children.length) {
166
- if (!isFullPageSection(child.props.children)) {
167
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
168
- }
169
- }
170
- });
171
- }
172
- }, [includeViewAllToggle, shouldViewAll, children]); // check if child is a full page step component
173
-
174
- var isFullPageStep = function isFullPageStep(child) {
175
- if (child && child.props && child.props.type === CREATE_FULL_PAGE_STEP) {
176
- return true;
177
- }
178
-
179
- return false;
180
- }; // check if child is a full page section component
181
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
182
-
183
- /* istanbul ignore next */
184
-
185
-
186
- var isFullPageSection = function isFullPageSection(child) {
187
- if (child && child.props && child.props.type === CREATE_FULL_PAGE_SECTION) {
188
- return true;
189
- }
190
-
191
- return false;
192
- }; // renders the step progression components in the left influencer area
193
-
194
-
195
- var getFullPageComponents = function getFullPageComponents(childrenElements) {
196
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
197
- var fullPageStepComponents = childrenArray.filter(function (child) {
198
- return isFullPageStep(child);
199
- });
200
- var sectionChildElements = [];
201
- fullPageStepComponents.forEach(function (child) {
202
- // we have received an array of children, lets check to see that each child is
203
- // a FullPageSection component before adding it to sectionChildElements
204
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
205
-
206
- /* istanbul ignore next */
207
- if (shouldViewAll && child.props.children.length) {
208
- child.props.children.forEach(function (stepChild) {
209
- if (isFullPageSection(stepChild)) {
210
- sectionChildElements.push(stepChild);
211
- }
212
- });
213
- } // we have received a single child element, lets check to see that it is
214
- // a CreateFullPageSection component before adding it to sectionChildElements
215
-
216
-
217
- if (shouldViewAll && typeof child.props.children !== 'undefined' && !child.props.children.length) {
218
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
219
-
220
- /* istanbul ignore next */
221
- if (isFullPageSection(child.props.children)) {
222
- sectionChildElements.push(child.props.children);
223
- }
224
- }
225
- });
226
- return {
227
- sections: sectionChildElements,
228
- steps: fullPageStepComponents
229
- };
230
- }; // renders all children (CreateFullPageSteps and regular children elements)
231
-
232
-
233
- var renderChildren = function renderChildren(childrenElements) {
234
- var step = 0;
235
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
236
- var indexOfLastFullPageStep = childrenArray.map(function (el) {
237
- var _el$props;
238
-
239
- return el === null || el === void 0 ? void 0 : (_el$props = el.props) === null || _el$props === void 0 ? void 0 : _el$props.type;
240
- }).lastIndexOf(CREATE_FULL_PAGE_STEP);
241
- return /*#__PURE__*/React.createElement(React.Fragment, null, childrenArray.map(function (child, stepIndex) {
242
- var _cx;
243
-
244
- if (!isFullPageStep(child)) {
245
- return child;
246
- }
247
-
248
- step++;
249
- return /*#__PURE__*/React.cloneElement(child, {
250
- className: cx(child.props.className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__step--hidden-step"), !shouldViewAll && currentStep !== step), _defineProperty(_cx, "".concat(blockClass, "__step--visible-step"), currentStep === step), _cx)),
251
- key: "key_".concat(stepIndex)
252
- }, /*#__PURE__*/React.createElement(React.Fragment, null, renderStepChildren(child.props.children, indexOfLastFullPageStep === step - 1)));
253
- }));
254
- };
255
-
256
- var renderStepChildren = function renderStepChildren(fullPageStepComponent, isLastFullPageStep) {
257
- var fullPageStepComponents = Array.isArray(fullPageStepComponent) ? fullPageStepComponent : [fullPageStepComponent];
258
- return /*#__PURE__*/React.createElement(React.Fragment, null, fullPageStepComponents.map(function (child, index) {
259
- var _cx2;
260
-
261
- if (!isFullPageSection(child)) {
262
- return child;
263
- } // Needed to be able to not render the divider
264
- // line on the last section of the last step
265
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
266
-
267
- /* istanbul ignore next */
268
-
269
-
270
- var isLastSectionOfLastStep = isLastFullPageStep && fullPageStepComponents.length - 1 === index;
271
- /* istanbul ignore next */
272
-
273
- return /*#__PURE__*/React.cloneElement(child, {
274
- className: cx(child.props.className, (_cx2 = {}, _defineProperty(_cx2, "".concat(blockClass, "__step--hidden-section"), child.props.viewAllOnly && !shouldViewAll), _defineProperty(_cx2, "".concat(blockClass, "__step--visible-section"), !child.props.viewAllOnly || child.props.viewAllOnly && shouldViewAll), _cx2)),
275
- key: "key_".concat(index)
276
- }, /*#__PURE__*/React.createElement(React.Fragment, null, shouldViewAll && /*#__PURE__*/React.createElement("h4", {
277
- className: "".concat(blockClass, "__step-title")
278
- }, child.props.title), child, shouldViewAll && !isLastSectionOfLastStep && /*#__PURE__*/React.createElement("span", {
279
- className: "".concat(blockClass, "__section-divider")
280
- })));
281
- }));
282
- }; // currently, we are not supporting the use of 'view all' toggle state or CreateFullPageSection -- this may be a future feature
283
-
284
- /* istanbul ignore next */
285
-
286
-
287
156
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
288
157
  ref: ref,
289
158
  className: cx(blockClass, className)
290
159
  }, getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement("div", {
291
160
  className: "".concat(blockClass, "__influencer")
292
161
  }, /*#__PURE__*/React.createElement(CreateInfluencer, {
293
- activeSectionIndex: activeSectionIndex,
294
- componentBlockClass: blockClass,
295
- createComponentName: componentName,
296
- currentStep: currentStep,
297
- createComponents: getFullPageComponents(children),
298
- includeViewAllToggle: includeViewAllToggle,
299
- handleToggleState: function handleToggleState(toggleState) {
300
- return setShouldViewAll(toggleState);
301
- },
302
- handleActiveSectionIndex: function handleActiveSectionIndex(index) {
303
- return setActiveSectionIndex(index);
304
- },
305
- previousState: previousState,
306
- sideNavAriaLabel: sideNavAriaLabel,
307
- toggleState: shouldViewAll,
308
- viewAllToggleLabelText: viewAllToggleLabelText,
309
- viewAllToggleOffLabelText: viewAllToggleOffLabelText,
310
- viewAllToggleOnLabelText: viewAllToggleOnLabelText
162
+ stepData: stepData,
163
+ currentStep: currentStep
311
164
  })), /*#__PURE__*/React.createElement("div", {
312
165
  className: "".concat(blockClass, "__body")
313
166
  }, /*#__PURE__*/React.createElement("div", {
@@ -316,7 +169,28 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
316
169
  className: "".concat(blockClass, "__content")
317
170
  }, /*#__PURE__*/React.createElement(Grid, null, /*#__PURE__*/React.createElement(Form, {
318
171
  className: "".concat(blockClass, "__form")
319
- }, renderChildren(children)))), /*#__PURE__*/React.createElement(ActionSet, {
172
+ }, /*#__PURE__*/React.createElement(StepsContext.Provider, {
173
+ value: {
174
+ currentStep: currentStep,
175
+ setIsDisabled: setIsDisabled,
176
+ setOnNext: function setOnNext(fn) {
177
+ return _setOnNext(function () {
178
+ return fn;
179
+ });
180
+ },
181
+ setOnMount: function setOnMount(fn) {
182
+ return _setOnMount(function () {
183
+ return fn;
184
+ });
185
+ },
186
+ setStepData: setStepData,
187
+ stepData: stepData
188
+ }
189
+ }, React.Children.map(children, function (child, index) {
190
+ return /*#__PURE__*/React.createElement(StepNumberContext.Provider, {
191
+ value: index + 1
192
+ }, child);
193
+ }))))), /*#__PURE__*/React.createElement(ActionSet, {
320
194
  className: "".concat(blockClass, "__buttons"),
321
195
  actions: createFullPageActions,
322
196
  size: "max"
@@ -361,22 +235,13 @@ CreateFullPage.propTypes = {
361
235
  /**
362
236
  * The main content of the full page
363
237
  */
364
- children: hasValidChildrenType({
365
- componentName: componentName,
366
- childType: CREATE_FULL_PAGE_STEP
367
- }),
238
+ children: PropTypes.node,
368
239
 
369
240
  /**
370
241
  * Provide an optional class to be applied to the containing node.
371
242
  */
372
243
  className: PropTypes.string,
373
244
 
374
- /**
375
- * @ignore
376
- * An optional prop that provides a toggle element in the left side influencer panel
377
- */
378
- includeViewAllToggle: PropTypes.bool,
379
-
380
245
  /**
381
246
  * The primary 'danger' button text in the modal
382
247
  */
@@ -429,26 +294,5 @@ CreateFullPage.propTypes = {
429
294
  /**
430
295
  * The main title of the full page, displayed in the header area.
431
296
  */
432
- title: PropTypes.node,
433
-
434
- /**
435
- * @ignore
436
- * Sets the label text for the view all toggle component
437
- */
438
- viewAllToggleLabelText: PropTypes.string,
439
-
440
- /**
441
- * @ignore
442
- * Sets the label text for the view all toggle `off` text
443
- */
444
- viewAllToggleOffLabelText: PropTypes.string,
445
-
446
- /**
447
- * @ignore
448
- * Sets the label text for the view all toggle `on` text
449
- */
450
- viewAllToggleOnLabelText: PropTypes.string
451
- };
452
- CreateFullPage.defaultProps = {
453
- includeViewAllToggle: false
297
+ title: PropTypes.node
454
298
  };
@@ -1,27 +1,77 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+
1
4
  /**
2
- * Copyright IBM Corp. 2021, 2021
5
+ * Copyright IBM Corp. 2021, 2022
3
6
  *
4
7
  * This source code is licensed under the Apache-2.0 license found in the
5
8
  * LICENSE file in the root directory of this source tree.
6
9
  */
7
- import React, { forwardRef } from 'react';
10
+ import React, { forwardRef, useContext, useEffect, useState } from 'react';
8
11
  import PropTypes from 'prop-types';
9
12
  import cx from 'classnames';
10
13
  import { pkg } from '../../settings';
11
- import { CREATE_FULL_PAGE_STEP } from './constants.js';
12
14
  import { FormGroup } from 'carbon-components-react';
15
+ import { StepsContext, StepNumberContext } from './CreateFullPage';
16
+ import { usePreviousValue, useRetrieveStepData } from '../../global/js/hooks';
17
+ import pconsole from '../../global/js/utils/pconsole';
13
18
  var componentName = 'CreateFullPageStep';
14
19
  var blockClass = "".concat(pkg.prefix, "--create-full-page__step");
15
20
  export var CreateFullPageStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
21
+ var _cx;
22
+
16
23
  var children = _ref.children,
17
24
  className = _ref.className,
18
25
  subtitle = _ref.subtitle,
19
26
  description = _ref.description,
27
+ disableSubmit = _ref.disableSubmit,
28
+ includeStep = _ref.includeStep,
29
+ introStep = _ref.introStep,
20
30
  title = _ref.title,
21
31
  hasFieldset = _ref.hasFieldset,
22
- fieldsetLegendText = _ref.fieldsetLegendText;
23
- return /*#__PURE__*/React.createElement("section", {
24
- className: cx(blockClass, className),
32
+ fieldsetLegendText = _ref.fieldsetLegendText,
33
+ onNext = _ref.onNext,
34
+ onMount = _ref.onMount,
35
+ secondaryLabel = _ref.secondaryLabel;
36
+ var stepsContext = useContext(StepsContext);
37
+ var stepNumber = useContext(StepNumberContext);
38
+
39
+ var _useState = useState(),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ shouldIncludeStep = _useState2[0],
42
+ setShouldIncludeStep = _useState2[1];
43
+
44
+ var previousState = usePreviousValue({
45
+ currentStep: stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep
46
+ });
47
+ useRetrieveStepData({
48
+ stepsContext: stepsContext,
49
+ stepNumber: stepNumber,
50
+ introStep: introStep,
51
+ shouldIncludeStep: shouldIncludeStep,
52
+ secondaryLabel: secondaryLabel,
53
+ title: title
54
+ }); // This useEffect reports back the onNext and onMount values so that they can be used
55
+ // in the appropriate custom hooks.
56
+
57
+ useEffect(function () {
58
+ if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep) && (previousState === null || previousState === void 0 ? void 0 : previousState.currentStep) !== (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
59
+ stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnNext(onNext);
60
+ stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnMount(onMount);
61
+ }
62
+ }, [onMount, onNext, stepsContext, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]);
63
+ useEffect(function () {
64
+ setShouldIncludeStep(includeStep);
65
+ }, [includeStep, stepsContext, title]); // Whenever we are the current step, supply our disableSubmit value to the
66
+ // steps container context so that it can manage the 'Next' button appropriately.
67
+
68
+ useEffect(function () {
69
+ if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
70
+ stepsContext.setIsDisabled(disableSubmit);
71
+ }
72
+ }, [stepsContext, stepNumber, disableSubmit, onNext]);
73
+ return stepsContext ? /*#__PURE__*/React.createElement("section", {
74
+ className: cx(blockClass, className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__step--hidden-step"), stepNumber !== (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)), _defineProperty(_cx, "".concat(blockClass, "__step--visible-step"), stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)), _cx)),
25
75
  ref: ref
26
76
  }, /*#__PURE__*/React.createElement("h5", {
27
77
  className: "".concat(blockClass, "-title")
@@ -32,7 +82,7 @@ export var CreateFullPageStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
32
82
  }, description), hasFieldset ? /*#__PURE__*/React.createElement(FormGroup, {
33
83
  legendText: fieldsetLegendText,
34
84
  className: "".concat(blockClass, "-fieldset")
35
- }, children) : children);
85
+ }, children) : children) : pconsole.warn("You have tried using a ".concat(componentName, " component outside of a CreateFullPage. This is not allowed. ").concat(componentName, "s should always be children of the CreateFullPage"));
36
86
  }); // Return a placeholder if not released and not enabled by feature flag
37
87
 
38
88
  CreateFullPageStep = pkg.checkComponentEnabled(CreateFullPageStep, componentName);
@@ -70,6 +120,12 @@ CreateFullPageStep.propTypes = {
70
120
  */
71
121
  hasFieldset: PropTypes.bool,
72
122
 
123
+ /**
124
+ * This prop is used to help track dynamic steps. If this value is `false` then the step is not included in the visible steps or the ProgressIndicator
125
+ * steps. If this value is `true` then the step will be included in the list of visible steps, as well as being included in the ProgressIndicator step list
126
+ */
127
+ includeStep: PropTypes.bool,
128
+
73
129
  /**
74
130
  * This prop can be used on the first step to mark it as an intro step, which will not render the progress indicator steps
75
131
  */
@@ -102,11 +158,7 @@ CreateFullPageStep.propTypes = {
102
158
  * Sets the title text for a create full page step
103
159
  */
104
160
  title: PropTypes.node.isRequired
105
- }; // Default values for component props. Default values are not required for
106
- // props that are required, nor for props where the component can apply
107
- // 'undefined' values reasonably. Default values should be provided when the
108
- // component needs to make a choice or assumption when a prop is not supplied.
109
-
161
+ };
110
162
  CreateFullPageStep.defaultProps = {
111
- type: CREATE_FULL_PAGE_STEP
163
+ includeStep: true
112
164
  };
@@ -5,5 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export { CreateFullPage } from './CreateFullPage';
8
- export { CreateFullPageStep } from './CreateFullPageStep';
9
- export { CreateFullPageSection } from './CreateFullPageSection';
8
+ export { CreateFullPageStep } from './CreateFullPageStep';