@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
@@ -7,12 +7,10 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.CreateFullPage = void 0;
10
+ exports.StepsContext = exports.StepNumberContext = exports.CreateFullPage = void 0;
11
11
 
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
13
 
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
-
16
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
17
15
 
18
16
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
@@ -27,8 +25,6 @@ var _devtools = require("../../global/js/utils/devtools");
27
25
 
28
26
  var _settings = require("../../settings");
29
27
 
30
- var _constants = require("./constants");
31
-
32
28
  var _carbonComponentsReact = require("carbon-components-react");
33
29
 
34
30
  var _CreateInfluencer = require("../CreateInfluencer");
@@ -37,23 +33,31 @@ var _ActionSet = require("../ActionSet");
37
33
 
38
34
  var _hooks = require("../../global/js/hooks");
39
35
 
40
- var _hasValidType = require("../../global/js/utils/hasValidType");
36
+ var _lastIndexInArray = require("../../global/js/utils/lastIndexInArray");
41
37
 
42
- var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "includeViewAllToggle", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "sideNavAriaLabel", "submitButtonText", "viewAllToggleLabelText", "viewAllToggleOffLabelText", "viewAllToggleOnLabelText"];
38
+ var _excluded = ["backButtonText", "cancelButtonText", "children", "className", "modalDangerButtonText", "modalDescription", "modalSecondaryButtonText", "modalTitle", "nextButtonText", "onClose", "onRequestSubmit", "submitButtonText"];
43
39
 
44
40
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
45
41
 
46
42
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
47
43
 
48
44
  var blockClass = "".concat(_settings.pkg.prefix, "--create-full-page");
49
- var componentName = 'CreateFullPage';
45
+ var componentName = 'CreateFullPage'; // This is a general context for the steps container
46
+ // containing information about the state of the container
47
+ // and providing some callback methods for steps to use
48
+
49
+ var StepsContext = /*#__PURE__*/(0, _react.createContext)(null); // This is a context supplied separately to each step in the container
50
+ // to let it know what number it is in the sequence of steps
51
+
52
+ exports.StepsContext = StepsContext;
53
+ var StepNumberContext = /*#__PURE__*/(0, _react.createContext)(-1);
54
+ exports.StepNumberContext = StepNumberContext;
50
55
 
51
56
  var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
52
57
  var backButtonText = _ref.backButtonText,
53
58
  cancelButtonText = _ref.cancelButtonText,
54
59
  children = _ref.children,
55
60
  className = _ref.className,
56
- includeViewAllToggle = _ref.includeViewAllToggle,
57
61
  modalDangerButtonText = _ref.modalDangerButtonText,
58
62
  modalDescription = _ref.modalDescription,
59
63
  modalSecondaryButtonText = _ref.modalSecondaryButtonText,
@@ -61,11 +65,7 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
61
65
  nextButtonText = _ref.nextButtonText,
62
66
  onClose = _ref.onClose,
63
67
  onRequestSubmit = _ref.onRequestSubmit,
64
- sideNavAriaLabel = _ref.sideNavAriaLabel,
65
68
  submitButtonText = _ref.submitButtonText,
66
- viewAllToggleLabelText = _ref.viewAllToggleLabelText,
67
- viewAllToggleOffLabelText = _ref.viewAllToggleOffLabelText,
68
- viewAllToggleOnLabelText = _ref.viewAllToggleOnLabelText,
69
69
  rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
70
70
 
71
71
  var _useState = (0, _react.useState)([]),
@@ -83,49 +83,84 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
83
83
  currentStep = _useState6[0],
84
84
  setCurrentStep = _useState6[1];
85
85
 
86
- var _useState7 = (0, _react.useState)(0),
86
+ var _useState7 = (0, _react.useState)(false),
87
87
  _useState8 = (0, _slicedToArray2.default)(_useState7, 2),
88
- activeSectionIndex = _useState8[0],
89
- setActiveSectionIndex = _useState8[1];
88
+ isSubmitting = _useState8[0],
89
+ setIsSubmitting = _useState8[1];
90
90
 
91
91
  var _useState9 = (0, _react.useState)(false),
92
92
  _useState10 = (0, _slicedToArray2.default)(_useState9, 2),
93
- isSubmitting = _useState10[0],
94
- setIsSubmitting = _useState10[1];
93
+ modalIsOpen = _useState10[0],
94
+ setModalIsOpen = _useState10[1];
95
+
96
+ var previousState = (0, _hooks.usePreviousValue)({
97
+ currentStep: currentStep,
98
+ open: open
99
+ });
95
100
 
96
101
  var _useState11 = (0, _react.useState)(false),
97
102
  _useState12 = (0, _slicedToArray2.default)(_useState11, 2),
98
- modalIsOpen = _useState12[0],
99
- setModalIsOpen = _useState12[1];
103
+ isDisabled = _useState12[0],
104
+ setIsDisabled = _useState12[1];
105
+
106
+ var _useState13 = (0, _react.useState)(),
107
+ _useState14 = (0, _slicedToArray2.default)(_useState13, 2),
108
+ onNext = _useState14[0],
109
+ _setOnNext = _useState14[1];
110
+
111
+ var _useState15 = (0, _react.useState)(),
112
+ _useState16 = (0, _slicedToArray2.default)(_useState15, 2),
113
+ onMount = _useState16[0],
114
+ _setOnMount = _useState16[1];
115
+
116
+ var _useState17 = (0, _react.useState)([]),
117
+ _useState18 = (0, _slicedToArray2.default)(_useState17, 2),
118
+ stepData = _useState18[0],
119
+ setStepData = _useState18[1];
120
+
121
+ var _useState19 = (0, _react.useState)(1),
122
+ _useState20 = (0, _slicedToArray2.default)(_useState19, 2),
123
+ firstIncludedStep = _useState20[0],
124
+ setFirstIncludedStep = _useState20[1];
125
+
126
+ var _useState21 = (0, _react.useState)(null),
127
+ _useState22 = (0, _slicedToArray2.default)(_useState21, 2),
128
+ lastIncludedStep = _useState22[0],
129
+ setLastIncludedStep = _useState22[1];
100
130
 
101
- var previousState = (0, _hooks.usePreviousValue)({
131
+ (0, _react.useEffect)(function () {
132
+ var firstItem = stepData.findIndex(function (item) {
133
+ return item === null || item === void 0 ? void 0 : item.shouldIncludeStep;
134
+ }) + 1;
135
+ var lastItem = (0, _lastIndexInArray.lastIndexInArray)(stepData, 'shouldIncludeStep', true);
136
+
137
+ if (firstItem !== firstIncludedStep) {
138
+ setFirstIncludedStep(firstItem);
139
+ }
140
+
141
+ if (lastItem !== lastIncludedStep) {
142
+ setLastIncludedStep(lastItem);
143
+ }
144
+ }, [stepData, firstIncludedStep, lastIncludedStep]);
145
+ (0, _hooks.useCreateComponentFocus)({
146
+ previousState: previousState,
102
147
  currentStep: currentStep,
103
- open: open
104
- }); // returns an array of full page steps
105
-
106
- var getFullPageSteps = (0, _react.useCallback)(function () {
107
- var _childrenArray$;
108
-
109
- var steps = [];
110
- var childrenArray = Array.isArray(children) ? children : [children];
111
- var extractedChildren = childrenArray && ((_childrenArray$ = childrenArray[0]) === null || _childrenArray$ === void 0 ? void 0 : _childrenArray$.type) === _react.default.Fragment ? childrenArray[0].props.children : childrenArray;
112
- extractedChildren.forEach(function (child) {
113
- if (isFullPageStep(child)) {
114
- steps.push(child);
115
- }
116
- });
117
- return steps;
118
- }, [children]);
119
- (0, _hooks.useCreateComponentFocus)(previousState, currentStep, getFullPageSteps, blockClass);
120
- (0, _hooks.useValidCreateStepCount)(getFullPageSteps, componentName);
148
+ blockClass: blockClass,
149
+ onMount: onMount
150
+ });
151
+ (0, _hooks.useValidCreateStepCount)(stepData.length, componentName);
121
152
  (0, _hooks.useCreateComponentStepChange)({
153
+ firstIncludedStep: firstIncludedStep,
154
+ lastIncludedStep: lastIncludedStep,
155
+ stepData: stepData,
156
+ onNext: onNext,
157
+ isSubmitDisabled: isDisabled,
122
158
  setCurrentStep: setCurrentStep,
123
159
  setIsSubmitting: setIsSubmitting,
124
160
  setShouldViewAll: setShouldViewAll,
125
161
  onClose: onClose,
126
162
  onRequestSubmit: onRequestSubmit,
127
163
  componentName: componentName,
128
- getComponentSteps: getFullPageSteps,
129
164
  currentStep: currentStep,
130
165
  shouldViewAll: shouldViewAll,
131
166
  backButtonText: backButtonText,
@@ -136,200 +171,18 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
136
171
  componentBlockClass: blockClass,
137
172
  setCreateComponentActions: setCreateFullPageActions,
138
173
  setModalIsOpen: setModalIsOpen
139
- }); // Log a warning to the console in the event there are no CreateFullPageSection components
140
- // inside of the CreateFullPageSteps when the viewAll toggle is provided and turned on.
141
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
142
-
143
- /* istanbul ignore next */
144
-
145
- (0, _react.useEffect)(function () {
146
- if (includeViewAllToggle && shouldViewAll) {
147
- var childrenArray = Array.isArray(children) ? children : [children];
148
- var fullPageStepComponents = childrenArray.filter(function (child) {
149
- return isFullPageStep(child);
150
- });
151
- var fullPageSectionComponents = [];
152
- fullPageStepComponents.forEach(function (child, index) {
153
- // We have received children for a FullPageStep
154
- if (shouldViewAll && typeof child.props.children !== 'undefined') {
155
- // Only a string was provided as children of CreateFullPageStep, this is not permitted when using view all toggle
156
- if (typeof child.props.children === 'string') {
157
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
158
- } else {
159
- // The FullPageStep has an array of children, lets check each one to see if it is a FullPageSection
160
- if (child.props.children.length) {
161
- child.props.children.forEach(function (stepChild) {
162
- if (isFullPageSection(stepChild)) {
163
- fullPageSectionComponents.push(stepChild);
164
- }
165
- });
166
- } else {
167
- // The FullPageStep only has a single React element as a child, lets check to see if it is a FullPageSection
168
- if (isFullPageSection(child.props.children)) {
169
- fullPageSectionComponents.push(child.props.children);
170
- }
171
- }
172
- }
173
- } // If there are fewer CreateFullPageSection components than CreateFullPageStep components
174
- // it means that each CreateFullPageStep does not have at least one CreateFullPageSection
175
- // this is not permitted when using view all toggle
176
-
177
-
178
- if (fullPageSectionComponents.length < fullPageStepComponents.length && index === fullPageStepComponents.length - 1 // wait until we've finished checking each FullPageStep before giving a warning
179
- ) {
180
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
181
- } // We have received a single child element, lets check to see that it is
182
- // a CreateFullPageSection component, if it is not we should add a console
183
- // warning, as each CreateFullPageStep required at least one CreateFullPageSection,
184
- // when using the view all toggle
185
-
186
-
187
- if (shouldViewAll && typeof child.props.children !== 'undefined' && !child.props.children.length) {
188
- if (!isFullPageSection(child.props.children)) {
189
- console.warn("".concat(componentName, ": You must have at least one CreateFullPageSection component in a CreateFullPageStep when using the 'includeViewAllToggle' prop."));
190
- }
191
- }
192
- });
193
- }
194
- }, [includeViewAllToggle, shouldViewAll, children]); // check if child is a full page step component
195
-
196
- var isFullPageStep = function isFullPageStep(child) {
197
- if (child && child.props && child.props.type === _constants.CREATE_FULL_PAGE_STEP) {
198
- return true;
199
- }
200
-
201
- return false;
202
- }; // check if child is a full page section component
203
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
174
+ }); // currently, we are not supporting the use of 'view all' toggle state
204
175
 
205
176
  /* istanbul ignore next */
206
177
 
207
-
208
- var isFullPageSection = function isFullPageSection(child) {
209
- if (child && child.props && child.props.type === _constants.CREATE_FULL_PAGE_SECTION) {
210
- return true;
211
- }
212
-
213
- return false;
214
- }; // renders the step progression components in the left influencer area
215
-
216
-
217
- var getFullPageComponents = function getFullPageComponents(childrenElements) {
218
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
219
- var fullPageStepComponents = childrenArray.filter(function (child) {
220
- return isFullPageStep(child);
221
- });
222
- var sectionChildElements = [];
223
- fullPageStepComponents.forEach(function (child) {
224
- // we have received an array of children, lets check to see that each child is
225
- // a FullPageSection component before adding it to sectionChildElements
226
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
227
-
228
- /* istanbul ignore next */
229
- if (shouldViewAll && child.props.children.length) {
230
- child.props.children.forEach(function (stepChild) {
231
- if (isFullPageSection(stepChild)) {
232
- sectionChildElements.push(stepChild);
233
- }
234
- });
235
- } // we have received a single child element, lets check to see that it is
236
- // a CreateFullPageSection component before adding it to sectionChildElements
237
-
238
-
239
- if (shouldViewAll && typeof child.props.children !== 'undefined' && !child.props.children.length) {
240
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
241
-
242
- /* istanbul ignore next */
243
- if (isFullPageSection(child.props.children)) {
244
- sectionChildElements.push(child.props.children);
245
- }
246
- }
247
- });
248
- return {
249
- sections: sectionChildElements,
250
- steps: fullPageStepComponents
251
- };
252
- }; // renders all children (CreateFullPageSteps and regular children elements)
253
-
254
-
255
- var renderChildren = function renderChildren(childrenElements) {
256
- var step = 0;
257
- var childrenArray = Array.isArray(childrenElements) ? childrenElements : [childrenElements];
258
- var indexOfLastFullPageStep = childrenArray.map(function (el) {
259
- var _el$props;
260
-
261
- return el === null || el === void 0 ? void 0 : (_el$props = el.props) === null || _el$props === void 0 ? void 0 : _el$props.type;
262
- }).lastIndexOf(_constants.CREATE_FULL_PAGE_STEP);
263
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, childrenArray.map(function (child, stepIndex) {
264
- var _cx;
265
-
266
- if (!isFullPageStep(child)) {
267
- return child;
268
- }
269
-
270
- step++;
271
- return /*#__PURE__*/_react.default.cloneElement(child, {
272
- className: (0, _classnames.default)(child.props.className, (_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__step--hidden-step"), !shouldViewAll && currentStep !== step), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__step--visible-step"), currentStep === step), _cx)),
273
- key: "key_".concat(stepIndex)
274
- }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderStepChildren(child.props.children, indexOfLastFullPageStep === step - 1)));
275
- }));
276
- };
277
-
278
- var renderStepChildren = function renderStepChildren(fullPageStepComponent, isLastFullPageStep) {
279
- var fullPageStepComponents = Array.isArray(fullPageStepComponent) ? fullPageStepComponent : [fullPageStepComponent];
280
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, fullPageStepComponents.map(function (child, index) {
281
- var _cx2;
282
-
283
- if (!isFullPageSection(child)) {
284
- return child;
285
- } // Needed to be able to not render the divider
286
- // line on the last section of the last step
287
- // currently, we are not supporting the use of FullPageSections -- this may be a future feature
288
-
289
- /* istanbul ignore next */
290
-
291
-
292
- var isLastSectionOfLastStep = isLastFullPageStep && fullPageStepComponents.length - 1 === index;
293
- /* istanbul ignore next */
294
-
295
- return /*#__PURE__*/_react.default.cloneElement(child, {
296
- className: (0, _classnames.default)(child.props.className, (_cx2 = {}, (0, _defineProperty2.default)(_cx2, "".concat(blockClass, "__step--hidden-section"), child.props.viewAllOnly && !shouldViewAll), (0, _defineProperty2.default)(_cx2, "".concat(blockClass, "__step--visible-section"), !child.props.viewAllOnly || child.props.viewAllOnly && shouldViewAll), _cx2)),
297
- key: "key_".concat(index)
298
- }, /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, shouldViewAll && /*#__PURE__*/_react.default.createElement("h4", {
299
- className: "".concat(blockClass, "__step-title")
300
- }, child.props.title), child, shouldViewAll && !isLastSectionOfLastStep && /*#__PURE__*/_react.default.createElement("span", {
301
- className: "".concat(blockClass, "__section-divider")
302
- })));
303
- }));
304
- }; // currently, we are not supporting the use of 'view all' toggle state or CreateFullPageSection -- this may be a future feature
305
-
306
- /* istanbul ignore next */
307
-
308
-
309
178
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, rest, {
310
179
  ref: ref,
311
180
  className: (0, _classnames.default)(blockClass, className)
312
181
  }, (0, _devtools.getDevtoolsProps)(componentName)), /*#__PURE__*/_react.default.createElement("div", {
313
182
  className: "".concat(blockClass, "__influencer")
314
183
  }, /*#__PURE__*/_react.default.createElement(_CreateInfluencer.CreateInfluencer, {
315
- activeSectionIndex: activeSectionIndex,
316
- componentBlockClass: blockClass,
317
- createComponentName: componentName,
318
- currentStep: currentStep,
319
- createComponents: getFullPageComponents(children),
320
- includeViewAllToggle: includeViewAllToggle,
321
- handleToggleState: function handleToggleState(toggleState) {
322
- return setShouldViewAll(toggleState);
323
- },
324
- handleActiveSectionIndex: function handleActiveSectionIndex(index) {
325
- return setActiveSectionIndex(index);
326
- },
327
- previousState: previousState,
328
- sideNavAriaLabel: sideNavAriaLabel,
329
- toggleState: shouldViewAll,
330
- viewAllToggleLabelText: viewAllToggleLabelText,
331
- viewAllToggleOffLabelText: viewAllToggleOffLabelText,
332
- viewAllToggleOnLabelText: viewAllToggleOnLabelText
184
+ stepData: stepData,
185
+ currentStep: currentStep
333
186
  })), /*#__PURE__*/_react.default.createElement("div", {
334
187
  className: "".concat(blockClass, "__body")
335
188
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -338,7 +191,28 @@ var CreateFullPage = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref)
338
191
  className: "".concat(blockClass, "__content")
339
192
  }, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Grid, null, /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.Form, {
340
193
  className: "".concat(blockClass, "__form")
341
- }, renderChildren(children)))), /*#__PURE__*/_react.default.createElement(_ActionSet.ActionSet, {
194
+ }, /*#__PURE__*/_react.default.createElement(StepsContext.Provider, {
195
+ value: {
196
+ currentStep: currentStep,
197
+ setIsDisabled: setIsDisabled,
198
+ setOnNext: function setOnNext(fn) {
199
+ return _setOnNext(function () {
200
+ return fn;
201
+ });
202
+ },
203
+ setOnMount: function setOnMount(fn) {
204
+ return _setOnMount(function () {
205
+ return fn;
206
+ });
207
+ },
208
+ setStepData: setStepData,
209
+ stepData: stepData
210
+ }
211
+ }, _react.default.Children.map(children, function (child, index) {
212
+ return /*#__PURE__*/_react.default.createElement(StepNumberContext.Provider, {
213
+ value: index + 1
214
+ }, child);
215
+ }))))), /*#__PURE__*/_react.default.createElement(_ActionSet.ActionSet, {
342
216
  className: "".concat(blockClass, "__buttons"),
343
217
  actions: createFullPageActions,
344
218
  size: "max"
@@ -385,22 +259,13 @@ CreateFullPage.propTypes = {
385
259
  /**
386
260
  * The main content of the full page
387
261
  */
388
- children: (0, _hasValidType.hasValidChildrenType)({
389
- componentName: componentName,
390
- childType: _constants.CREATE_FULL_PAGE_STEP
391
- }),
262
+ children: _propTypes.default.node,
392
263
 
393
264
  /**
394
265
  * Provide an optional class to be applied to the containing node.
395
266
  */
396
267
  className: _propTypes.default.string,
397
268
 
398
- /**
399
- * @ignore
400
- * An optional prop that provides a toggle element in the left side influencer panel
401
- */
402
- includeViewAllToggle: _propTypes.default.bool,
403
-
404
269
  /**
405
270
  * The primary 'danger' button text in the modal
406
271
  */
@@ -453,26 +318,5 @@ CreateFullPage.propTypes = {
453
318
  /**
454
319
  * The main title of the full page, displayed in the header area.
455
320
  */
456
- title: _propTypes.default.node,
457
-
458
- /**
459
- * @ignore
460
- * Sets the label text for the view all toggle component
461
- */
462
- viewAllToggleLabelText: _propTypes.default.string,
463
-
464
- /**
465
- * @ignore
466
- * Sets the label text for the view all toggle `off` text
467
- */
468
- viewAllToggleOffLabelText: _propTypes.default.string,
469
-
470
- /**
471
- * @ignore
472
- * Sets the label text for the view all toggle `on` text
473
- */
474
- viewAllToggleOnLabelText: _propTypes.default.string
475
- };
476
- CreateFullPage.defaultProps = {
477
- includeViewAllToggle: false
321
+ title: _propTypes.default.node
478
322
  };
@@ -9,6 +9,10 @@ Object.defineProperty(exports, "__esModule", {
9
9
  });
10
10
  exports.CreateFullPageStep = void 0;
11
11
 
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
+
12
16
  var _react = _interopRequireWildcard(require("react"));
13
17
 
14
18
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -17,16 +21,20 @@ var _classnames = _interopRequireDefault(require("classnames"));
17
21
 
18
22
  var _settings = require("../../settings");
19
23
 
20
- var _constants = require("./constants.js");
21
-
22
24
  var _carbonComponentsReact = require("carbon-components-react");
23
25
 
26
+ var _CreateFullPage = require("./CreateFullPage");
27
+
28
+ var _hooks = require("../../global/js/hooks");
29
+
30
+ var _pconsole = _interopRequireDefault(require("../../global/js/utils/pconsole"));
31
+
24
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
33
 
26
34
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
35
 
28
36
  /**
29
- * Copyright IBM Corp. 2021, 2021
37
+ * Copyright IBM Corp. 2021, 2022
30
38
  *
31
39
  * This source code is licensed under the Apache-2.0 license found in the
32
40
  * LICENSE file in the root directory of this source tree.
@@ -34,15 +42,60 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
34
42
  var componentName = 'CreateFullPageStep';
35
43
  var blockClass = "".concat(_settings.pkg.prefix, "--create-full-page__step");
36
44
  var CreateFullPageStep = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
45
+ var _cx;
46
+
37
47
  var children = _ref.children,
38
48
  className = _ref.className,
39
49
  subtitle = _ref.subtitle,
40
50
  description = _ref.description,
51
+ disableSubmit = _ref.disableSubmit,
52
+ includeStep = _ref.includeStep,
53
+ introStep = _ref.introStep,
41
54
  title = _ref.title,
42
55
  hasFieldset = _ref.hasFieldset,
43
- fieldsetLegendText = _ref.fieldsetLegendText;
44
- return /*#__PURE__*/_react.default.createElement("section", {
45
- className: (0, _classnames.default)(blockClass, className),
56
+ fieldsetLegendText = _ref.fieldsetLegendText,
57
+ onNext = _ref.onNext,
58
+ onMount = _ref.onMount,
59
+ secondaryLabel = _ref.secondaryLabel;
60
+ var stepsContext = (0, _react.useContext)(_CreateFullPage.StepsContext);
61
+ var stepNumber = (0, _react.useContext)(_CreateFullPage.StepNumberContext);
62
+
63
+ var _useState = (0, _react.useState)(),
64
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
65
+ shouldIncludeStep = _useState2[0],
66
+ setShouldIncludeStep = _useState2[1];
67
+
68
+ var previousState = (0, _hooks.usePreviousValue)({
69
+ currentStep: stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep
70
+ });
71
+ (0, _hooks.useRetrieveStepData)({
72
+ stepsContext: stepsContext,
73
+ stepNumber: stepNumber,
74
+ introStep: introStep,
75
+ shouldIncludeStep: shouldIncludeStep,
76
+ secondaryLabel: secondaryLabel,
77
+ title: title
78
+ }); // This useEffect reports back the onNext and onMount values so that they can be used
79
+ // in the appropriate custom hooks.
80
+
81
+ (0, _react.useEffect)(function () {
82
+ 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)) {
83
+ stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnNext(onNext);
84
+ stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.setOnMount(onMount);
85
+ }
86
+ }, [onMount, onNext, stepsContext, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]);
87
+ (0, _react.useEffect)(function () {
88
+ setShouldIncludeStep(includeStep);
89
+ }, [includeStep, stepsContext, title]); // Whenever we are the current step, supply our disableSubmit value to the
90
+ // steps container context so that it can manage the 'Next' button appropriately.
91
+
92
+ (0, _react.useEffect)(function () {
93
+ if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
94
+ stepsContext.setIsDisabled(disableSubmit);
95
+ }
96
+ }, [stepsContext, stepNumber, disableSubmit, onNext]);
97
+ return stepsContext ? /*#__PURE__*/_react.default.createElement("section", {
98
+ className: (0, _classnames.default)(blockClass, className, (_cx = {}, (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__step--hidden-step"), stepNumber !== (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)), (0, _defineProperty2.default)(_cx, "".concat(blockClass, "__step--visible-step"), stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)), _cx)),
46
99
  ref: ref
47
100
  }, /*#__PURE__*/_react.default.createElement("h5", {
48
101
  className: "".concat(blockClass, "-title")
@@ -53,7 +106,7 @@ var CreateFullPageStep = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref
53
106
  }, description), hasFieldset ? /*#__PURE__*/_react.default.createElement(_carbonComponentsReact.FormGroup, {
54
107
  legendText: fieldsetLegendText,
55
108
  className: "".concat(blockClass, "-fieldset")
56
- }, children) : children);
109
+ }, children) : children) : _pconsole.default.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"));
57
110
  }); // Return a placeholder if not released and not enabled by feature flag
58
111
 
59
112
  exports.CreateFullPageStep = CreateFullPageStep;
@@ -92,6 +145,12 @@ CreateFullPageStep.propTypes = {
92
145
  */
93
146
  hasFieldset: _propTypes.default.bool,
94
147
 
148
+ /**
149
+ * 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
150
+ * 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
151
+ */
152
+ includeStep: _propTypes.default.bool,
153
+
95
154
  /**
96
155
  * This prop can be used on the first step to mark it as an intro step, which will not render the progress indicator steps
97
156
  */
@@ -124,11 +183,7 @@ CreateFullPageStep.propTypes = {
124
183
  * Sets the title text for a create full page step
125
184
  */
126
185
  title: _propTypes.default.node.isRequired
127
- }; // Default values for component props. Default values are not required for
128
- // props that are required, nor for props where the component can apply
129
- // 'undefined' values reasonably. Default values should be provided when the
130
- // component needs to make a choice or assumption when a prop is not supplied.
131
-
186
+ };
132
187
  CreateFullPageStep.defaultProps = {
133
- type: _constants.CREATE_FULL_PAGE_STEP
188
+ includeStep: true
134
189
  };
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "CreateFullPage", {
9
9
  return _CreateFullPage.CreateFullPage;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "CreateFullPageSection", {
13
- enumerable: true,
14
- get: function get() {
15
- return _CreateFullPageSection.CreateFullPageSection;
16
- }
17
- });
18
12
  Object.defineProperty(exports, "CreateFullPageStep", {
19
13
  enumerable: true,
20
14
  get: function get() {
@@ -24,6 +18,4 @@ Object.defineProperty(exports, "CreateFullPageStep", {
24
18
 
25
19
  var _CreateFullPage = require("./CreateFullPage");
26
20
 
27
- var _CreateFullPageStep = require("./CreateFullPageStep");
28
-
29
- var _CreateFullPageSection = require("./CreateFullPageSection");
21
+ var _CreateFullPageStep = require("./CreateFullPageStep");