@carbon/ibm-products 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/css/index-full-carbon.css +124 -40
  2. package/css/index-full-carbon.css.map +1 -1
  3. package/css/index-full-carbon.min.css +1 -1
  4. package/css/index-without-carbon-released-only.css +124 -40
  5. package/css/index-without-carbon-released-only.css.map +1 -1
  6. package/css/index-without-carbon-released-only.min.css +1 -1
  7. package/css/index-without-carbon.css +124 -40
  8. package/css/index-without-carbon.css.map +1 -1
  9. package/css/index-without-carbon.min.css +1 -1
  10. package/css/index.css +124 -40
  11. package/css/index.css.map +1 -1
  12. package/css/index.min.css +1 -1
  13. package/es/components/ActionSet/ActionSet.js +22 -10
  14. package/es/components/ActionSet/actions.js +25 -17
  15. package/es/components/CreateFullPage/CreateFullPage.js +30 -5
  16. package/es/components/CreateFullPage/CreateFullPageStep.js +40 -32
  17. package/es/components/CreateInfluencer/CreateInfluencer.js +25 -3
  18. package/es/components/CreateTearsheet/CreateTearsheet.js +32 -6
  19. package/es/components/CreateTearsheet/CreateTearsheetStep.js +45 -38
  20. package/es/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +24 -4
  21. package/es/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  22. package/es/components/ExportModal/ExportModal.js +39 -12
  23. package/es/components/SidePanel/SidePanel.js +1 -1
  24. package/es/components/Tearsheet/Tearsheet.js +1 -1
  25. package/es/components/Tearsheet/TearsheetNarrow.js +1 -1
  26. package/es/components/Tearsheet/TearsheetShell.js +1 -1
  27. package/es/global/js/hooks/index.js +1 -0
  28. package/es/global/js/hooks/useCreateComponentStepChange.js +31 -11
  29. package/es/global/js/hooks/useResetCreateComponent.js +7 -4
  30. package/es/global/js/hooks/useRetrieveStepData.js +51 -0
  31. package/es/global/js/utils/lastIndexInArray.js +26 -0
  32. package/lib/components/ActionSet/ActionSet.js +22 -10
  33. package/lib/components/ActionSet/actions.js +25 -17
  34. package/lib/components/CreateFullPage/CreateFullPage.js +29 -4
  35. package/lib/components/CreateFullPage/CreateFullPageStep.js +38 -30
  36. package/lib/components/CreateInfluencer/CreateInfluencer.js +25 -3
  37. package/lib/components/CreateTearsheet/CreateTearsheet.js +31 -5
  38. package/lib/components/CreateTearsheet/CreateTearsheetStep.js +43 -36
  39. package/lib/components/CreateTearsheet/preview-components/MultiStepTearsheet.js +22 -2
  40. package/lib/components/CreateTearsheet/preview-components/MultiStepWithIntro.js +8 -6
  41. package/lib/components/ExportModal/ExportModal.js +36 -11
  42. package/lib/components/SidePanel/SidePanel.js +1 -1
  43. package/lib/components/Tearsheet/Tearsheet.js +1 -1
  44. package/lib/components/Tearsheet/TearsheetNarrow.js +1 -1
  45. package/lib/components/Tearsheet/TearsheetShell.js +1 -1
  46. package/lib/global/js/hooks/index.js +8 -0
  47. package/lib/global/js/hooks/useCreateComponentStepChange.js +31 -11
  48. package/lib/global/js/hooks/useResetCreateComponent.js +7 -4
  49. package/lib/global/js/hooks/useRetrieveStepData.js +62 -0
  50. package/lib/global/js/utils/lastIndexInArray.js +35 -0
  51. package/package.json +15 -15
  52. package/scss/components/StatusIcon/_status-icon.scss +2 -0
@@ -38,7 +38,7 @@ var ActionSetButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
38
38
 
39
39
  return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
40
40
  isExpressive: true,
41
- className: cx(className, ["".concat(blockClass, "__action-button"), _defineProperty({}, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost')]),
41
+ className: cx(className, ["".concat(blockClass, "__action-button"), _defineProperty({}, "".concat(blockClass, "__action-button--ghost"), kind === 'ghost' || kind === 'danger--ghost')]),
42
42
  disabled: disabled || loading || false,
43
43
  kind: kind,
44
44
  onClick: onClick,
@@ -48,7 +48,7 @@ var ActionSetButton = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
48
48
  });
49
49
  ActionSetButton.displayName = 'ActionSetButton';
50
50
  ActionSetButton.propTypes = _objectSpread(_objectSpread({}, Button.PropTypes), {}, {
51
- kind: PropTypes.oneOf(['ghost', 'secondary', 'primary']),
51
+ kind: PropTypes.oneOf(['ghost', 'danger--ghost', 'secondary', 'danger', 'primary']),
52
52
  label: PropTypes.string,
53
53
  loading: PropTypes.bool
54
54
  });
@@ -82,13 +82,24 @@ export var ActionSet = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
82
82
 
83
83
  var buttons = actions && ((_actions$slice = actions.slice) === null || _actions$slice === void 0 ? void 0 : _actions$slice.call(actions, 0)) || []; // We stack the buttons in a xs/sm set, or if there are three or more in a md set.
84
84
 
85
- var stacking = willStack(size, buttons.length); // order the actions with ghost buttons first and primary buttons last
86
- // (and the opposite way if we're stacking)
85
+ var stacking = willStack(size, buttons.length); // Order of button kinds: ghost first, then danger--ghost, then most other types,
86
+ // then danger, and finally primary
87
+
88
+ var buttonOrder = function buttonOrder(kind) {
89
+ var _ghost$dangerGhost$;
90
+
91
+ return (_ghost$dangerGhost$ = {
92
+ ghost: 1,
93
+ 'danger--ghost': 2,
94
+ danger: 4,
95
+ primary: 5
96
+ }[kind]) !== null && _ghost$dangerGhost$ !== void 0 ? _ghost$dangerGhost$ : 3;
97
+ }; // order the actions with ghost/ghost-danger buttons first and primary/danger buttons last
98
+ // (or the opposite way if we're stacking)
99
+
87
100
 
88
101
  buttons.sort(function (action1, action2) {
89
- var kind1 = action1.kind || defaultKind;
90
- var kind2 = action2.kind || defaultKind;
91
- return kind1 === 'ghost' || kind2 === 'primary' ? stacking ? 1 : -1 : kind1 === 'primary' || kind2 === 'ghost' ? stacking ? -1 : 1 : 0;
102
+ return (buttonOrder(action1.kind || defaultKind) - buttonOrder(action2.kind || defaultKind)) * (stacking ? -1 : 1);
92
103
  });
93
104
  return /*#__PURE__*/React.createElement(ButtonSet, _extends({}, rest, {
94
105
  className: cx(blockClass, className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "--row-single"), !stacking && buttons.length === 1), _defineProperty(_cx, "".concat(blockClass, "--row-double"), !stacking && buttons.length === 2), _defineProperty(_cx, "".concat(blockClass, "--row-triple"), !stacking && buttons.length === 3), _defineProperty(_cx, "".concat(blockClass, "--row-quadruple"), !stacking && buttons.length >= 4), _defineProperty(_cx, "".concat(blockClass, "--stacking"), stacking), _cx), "".concat(blockClass, "--").concat(size)),
@@ -137,13 +148,14 @@ ActionSet.validateActions = function (sizeFn) {
137
148
 
138
149
  var primaryActions = countActions('primary');
139
150
  var secondaryActions = countActions('secondary');
140
- var ghostActions = countActions('ghost');
151
+ var dangerActions = countActions('danger');
152
+ var ghostActions = countActions('ghost') + countActions('danger--ghost');
141
153
  stacking && actions > 3 && problems.push("you cannot have more than three actions in this size of ".concat(componentName));
142
154
  actions > 4 && problems.push("you cannot have more than four actions in a ".concat(componentName));
143
155
  primaryActions > 1 && problems.push("you cannot have more than one 'primary' action in a ".concat(componentName));
144
156
  ghostActions > 1 && problems.push("you cannot have more than one 'ghost' action in a ".concat(componentName));
145
157
  stacking && actions > 1 && ghostActions > 0 && problems.push("you cannot have a 'ghost' button in conjunction with other action types in this size of ".concat(componentName));
146
- actions > primaryActions + secondaryActions + ghostActions && problems.push("you can only have 'primary', 'secondary' and 'ghost' buttons in a ".concat(componentName));
158
+ actions > primaryActions + secondaryActions + dangerActions + ghostActions && problems.push("you can only have 'primary', 'danger', 'secondary', 'ghost' and 'danger--ghost' buttons in a ".concat(componentName));
147
159
  }
148
160
 
149
161
  return problems.length > 0 ? new Error("Invalid ".concat(location, " `").concat(name, "` supplied to `").concat(componentName, "`: ").concat(problems.join(', and '), ".")) : null;
@@ -164,7 +176,7 @@ ActionSet.propTypes = {
164
176
  * See https://react.carbondesignsystem.com/?path=/docs/components-button--default#component-api
165
177
  */
166
178
  actions: allPropTypes([ActionSet.validateActions(), PropTypes.arrayOf(PropTypes.shape(_objectSpread(_objectSpread({}, Button.propTypes), {}, {
167
- kind: PropTypes.oneOf(['ghost', 'secondary', 'primary']),
179
+ kind: PropTypes.oneOf(['ghost', 'danger--ghost', 'secondary', 'danger', 'primary']),
168
180
  label: PropTypes.string,
169
181
  loading: PropTypes.bool,
170
182
  // we duplicate this Button prop to improve the DocGen here
@@ -4,19 +4,22 @@
4
4
  * This source code is licensed under the Apache-2.0 license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export var actionsOptions = [0, 1, 2, 3, 4, 5, 6, 7];
7
+ export var actionsOptions = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
8
8
  export var actionsLabels = {
9
9
  0: 'None',
10
10
  1: 'One button',
11
- 2: 'One ghost button',
12
- 3: 'Two buttons',
13
- 4: 'Two buttons including one ghost',
14
- 5: 'Three buttons',
15
- 6: 'Three buttons including one ghost',
16
- 7: 'Four buttons including one ghost'
11
+ 2: 'A danger button',
12
+ 3: 'A ghost button',
13
+ 4: 'Two buttons',
14
+ 5: 'Two buttons with one ghost',
15
+ 6: 'Three buttons',
16
+ 7: 'Three buttons with one ghost',
17
+ 8: 'Three buttons with one danger',
18
+ 9: 'Four buttons with one ghost',
19
+ 10: 'Four buttons with two danger'
17
20
  };
18
21
  export var actionsMapping = function actionsMapping(labels, action) {
19
- var _labels$primary, _labels$secondary, _labels$secondary2, _labels$ghost;
22
+ var _labels$primary, _labels$danger, _labels$secondary, _labels$secondary2, _labels$dangerGhost, _labels$ghost;
20
23
 
21
24
  var act = function act(label, kind, key) {
22
25
  var actionCall = action && action("Click on '".concat(label, "'"));
@@ -32,17 +35,22 @@ export var actionsMapping = function actionsMapping(labels, action) {
32
35
  };
33
36
 
34
37
  var primary = act((_labels$primary = labels === null || labels === void 0 ? void 0 : labels.primary) !== null && _labels$primary !== void 0 ? _labels$primary : 'Primary', 'primary', 1);
35
- var secondary = act((_labels$secondary = labels === null || labels === void 0 ? void 0 : labels.secondary) !== null && _labels$secondary !== void 0 ? _labels$secondary : 'Secondary', 'secondary', 2);
36
- var secondary2 = act((_labels$secondary2 = labels === null || labels === void 0 ? void 0 : labels.secondary2) !== null && _labels$secondary2 !== void 0 ? _labels$secondary2 : 'Secondary', 'secondary', 3);
37
- var ghost = act((_labels$ghost = labels === null || labels === void 0 ? void 0 : labels.ghost) !== null && _labels$ghost !== void 0 ? _labels$ghost : 'Ghost', 'ghost', 4);
38
+ var danger = act((_labels$danger = labels === null || labels === void 0 ? void 0 : labels.danger) !== null && _labels$danger !== void 0 ? _labels$danger : 'Danger', 'danger', 2);
39
+ var secondary = act((_labels$secondary = labels === null || labels === void 0 ? void 0 : labels.secondary) !== null && _labels$secondary !== void 0 ? _labels$secondary : 'Secondary', 'secondary', 3);
40
+ var secondary2 = act((_labels$secondary2 = labels === null || labels === void 0 ? void 0 : labels.secondary2) !== null && _labels$secondary2 !== void 0 ? _labels$secondary2 : 'Secondary', 'secondary', 4);
41
+ var dangerGhost = act((_labels$dangerGhost = labels === null || labels === void 0 ? void 0 : labels.dangerGhost) !== null && _labels$dangerGhost !== void 0 ? _labels$dangerGhost : 'Danger-ghost', 'danger--ghost', 5);
42
+ var ghost = act((_labels$ghost = labels === null || labels === void 0 ? void 0 : labels.ghost) !== null && _labels$ghost !== void 0 ? _labels$ghost : 'Ghost', 'ghost', 6);
38
43
  return {
39
44
  0: [],
40
45
  1: [primary],
41
- 2: [ghost],
42
- 3: [primary, secondary],
43
- 4: [primary, ghost],
44
- 5: [primary, secondary, secondary2],
45
- 6: [primary, secondary, ghost],
46
- 7: [primary, secondary, secondary2, ghost]
46
+ 2: [danger],
47
+ 3: [ghost],
48
+ 4: [primary, secondary],
49
+ 5: [primary, ghost],
50
+ 6: [primary, secondary, secondary2],
51
+ 7: [primary, secondary, ghost],
52
+ 8: [danger, secondary, ghost],
53
+ 9: [primary, secondary, secondary2, ghost],
54
+ 10: [danger, secondary, secondary2, dangerGhost]
47
55
  };
48
56
  };
@@ -10,7 +10,7 @@ var _excluded = ["backButtonText", "cancelButtonText", "children", "className",
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
12
  // Import portions of React that are needed.
13
- import React, { useState, createContext } from 'react'; // Other standard imports.
13
+ import React, { useEffect, useState, createContext } from 'react'; // Other standard imports.
14
14
 
15
15
  import PropTypes from 'prop-types';
16
16
  import cx from 'classnames';
@@ -21,6 +21,7 @@ import { Grid, ModalFooter, ComposedModal, ModalHeader, ModalBody, Button, Form
21
21
  import { CreateInfluencer } from '../CreateInfluencer';
22
22
  import { ActionSet } from '../ActionSet';
23
23
  import { usePreviousValue, useValidCreateStepCount, useCreateComponentFocus, useCreateComponentStepChange } from '../../global/js/hooks';
24
+ import { lastIndexInArray } from '../../global/js/utils/lastIndexInArray';
24
25
  var blockClass = "".concat(pkg.prefix, "--create-full-page");
25
26
  var componentName = 'CreateFullPage'; // This is a general context for the steps container
26
27
  // containing information about the state of the container
@@ -95,7 +96,30 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
95
96
  stepData = _useState18[0],
96
97
  setStepData = _useState18[1];
97
98
 
98
- var totalStepCount = React.Children.count(children);
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];
108
+
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]);
99
123
  useCreateComponentFocus({
100
124
  previousState: previousState,
101
125
  currentStep: currentStep,
@@ -104,7 +128,9 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
104
128
  });
105
129
  useValidCreateStepCount(stepData.length, componentName);
106
130
  useCreateComponentStepChange({
107
- totalStepCount: totalStepCount,
131
+ firstIncludedStep: firstIncludedStep,
132
+ lastIncludedStep: lastIncludedStep,
133
+ stepData: stepData,
108
134
  onNext: onNext,
109
135
  isSubmitDisabled: isDisabled,
110
136
  setCurrentStep: setCurrentStep,
@@ -158,8 +184,7 @@ export var CreateFullPage = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
158
184
  });
159
185
  },
160
186
  setStepData: setStepData,
161
- stepData: stepData,
162
- totalStepCount: totalStepCount
187
+ stepData: stepData
163
188
  }
164
189
  }, React.Children.map(children, function (child, index) {
165
190
  return /*#__PURE__*/React.createElement(StepNumberContext.Provider, {
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
 
4
4
  /**
5
5
  * Copyright IBM Corp. 2021, 2022
@@ -7,13 +7,13 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
7
7
  * This source code is licensed under the Apache-2.0 license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
- import React, { forwardRef, useContext, useEffect } from 'react';
10
+ import React, { forwardRef, useContext, useEffect, useState } from 'react';
11
11
  import PropTypes from 'prop-types';
12
12
  import cx from 'classnames';
13
13
  import { pkg } from '../../settings';
14
14
  import { FormGroup } from 'carbon-components-react';
15
15
  import { StepsContext, StepNumberContext } from './CreateFullPage';
16
- import { usePreviousValue } from '../../global/js/hooks';
16
+ import { usePreviousValue, useRetrieveStepData } from '../../global/js/hooks';
17
17
  import pconsole from '../../global/js/utils/pconsole';
18
18
  var componentName = 'CreateFullPageStep';
19
19
  var blockClass = "".concat(pkg.prefix, "--create-full-page__step");
@@ -25,6 +25,7 @@ export var CreateFullPageStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
25
25
  subtitle = _ref.subtitle,
26
26
  description = _ref.description,
27
27
  disableSubmit = _ref.disableSubmit,
28
+ includeStep = _ref.includeStep,
28
29
  introStep = _ref.introStep,
29
30
  title = _ref.title,
30
31
  hasFieldset = _ref.hasFieldset,
@@ -32,47 +33,45 @@ export var CreateFullPageStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
32
33
  onNext = _ref.onNext,
33
34
  onMount = _ref.onMount,
34
35
  secondaryLabel = _ref.secondaryLabel;
35
- var steps = useContext(StepsContext);
36
+ var stepsContext = useContext(StepsContext);
36
37
  var stepNumber = useContext(StepNumberContext);
38
+
39
+ var _useState = useState(),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ shouldIncludeStep = _useState2[0],
42
+ setShouldIncludeStep = _useState2[1];
43
+
37
44
  var previousState = usePreviousValue({
38
- currentStep: steps === null || steps === void 0 ? void 0 : steps.currentStep
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
39
54
  }); // This useEffect reports back the onNext and onMount values so that they can be used
40
55
  // in the appropriate custom hooks.
41
56
 
42
57
  useEffect(function () {
43
- if (stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep) && (previousState === null || previousState === void 0 ? void 0 : previousState.currentStep) !== (steps === null || steps === void 0 ? void 0 : steps.currentStep)) {
44
- steps === null || steps === void 0 ? void 0 : steps.setOnNext(onNext);
45
- steps === null || steps === void 0 ? void 0 : steps.setOnMount(onMount);
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);
46
61
  }
47
- }, [onMount, onNext, steps, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]); // This useEffect makes sure that every CreateTearsheetStep reports back it's
48
- // title, secondaryLabel, and introStep props so that it can be sent to the CreateInfluencer.
49
-
62
+ }, [onMount, onNext, stepsContext, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]);
50
63
  useEffect(function () {
51
- var _steps$stepData, _steps$stepData2;
52
-
53
- var stepHasReported = steps === null || steps === void 0 ? void 0 : (_steps$stepData = steps.stepData) === null || _steps$stepData === void 0 ? void 0 : _steps$stepData.includes(function (item) {
54
- return item.title === title;
55
- });
56
-
57
- if (!stepHasReported && (steps === null || steps === void 0 ? void 0 : (_steps$stepData2 = steps.stepData) === null || _steps$stepData2 === void 0 ? void 0 : _steps$stepData2.length) < (steps === null || steps === void 0 ? void 0 : steps.totalStepCount)) {
58
- steps === null || steps === void 0 ? void 0 : steps.setStepData(function (prev) {
59
- return [].concat(_toConsumableArray(prev), [{
60
- title: title,
61
- secondaryLabel: secondaryLabel,
62
- introStep: introStep
63
- }]);
64
- });
65
- }
66
- }, [steps, title, secondaryLabel, introStep]); // Whenever we are the current step, supply our disableSubmit value to the
64
+ setShouldIncludeStep(includeStep);
65
+ }, [includeStep, stepsContext, title]); // Whenever we are the current step, supply our disableSubmit value to the
67
66
  // steps container context so that it can manage the 'Next' button appropriately.
68
67
 
69
68
  useEffect(function () {
70
- if (stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep)) {
71
- steps.setIsDisabled(disableSubmit);
69
+ if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
70
+ stepsContext.setIsDisabled(disableSubmit);
72
71
  }
73
- }, [steps, stepNumber, disableSubmit, onNext]);
74
- return steps ? /*#__PURE__*/React.createElement("section", {
75
- className: cx(blockClass, className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__step--hidden-step"), stepNumber !== (steps === null || steps === void 0 ? void 0 : steps.currentStep)), _defineProperty(_cx, "".concat(blockClass, "__step--visible-step"), stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep)), _cx)),
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)),
76
75
  ref: ref
77
76
  }, /*#__PURE__*/React.createElement("h5", {
78
77
  className: "".concat(blockClass, "-title")
@@ -121,6 +120,12 @@ CreateFullPageStep.propTypes = {
121
120
  */
122
121
  hasFieldset: PropTypes.bool,
123
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
+
124
129
  /**
125
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
126
131
  */
@@ -153,4 +158,7 @@ CreateFullPageStep.propTypes = {
153
158
  * Sets the title text for a create full page step
154
159
  */
155
160
  title: PropTypes.node.isRequired
161
+ };
162
+ CreateFullPageStep.defaultProps = {
163
+ includeStep: true
156
164
  };
@@ -19,21 +19,42 @@ export var CreateInfluencer = function CreateInfluencer(_ref) {
19
19
  currentStep = _ref.currentStep,
20
20
  stepData = _ref.stepData;
21
21
 
22
- // renders the step progression components in the left influencer area
22
+ var getNumberOfDynamicStepsBeforeCurrentStep = function getNumberOfDynamicStepsBeforeCurrentStep(array, key) {
23
+ var dynamicSteps = [];
24
+ array.forEach(function (item, index) {
25
+ var _array$index;
26
+
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
+ }
30
+ });
31
+ return dynamicSteps.length;
32
+ }; // renders the step progression components in the left influencer area
33
+
34
+
23
35
  var renderProgressSteps = function renderProgressSteps() {
24
36
  var _stepData$, _stepData$2;
25
37
 
26
38
  var extractedSteps = stepData === null || stepData === void 0 ? void 0 : stepData.filter(function (item) {
27
39
  return !(item !== null && item !== void 0 && item.introStep);
28
40
  });
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;
29
48
  return /*#__PURE__*/React.createElement("div", {
30
49
  className: "".concat(blockClass, "__left-nav")
31
50
  }, currentStep === 1 && (_stepData$ = stepData[0]) !== null && _stepData$ !== void 0 && _stepData$.introStep ? null : /*#__PURE__*/React.createElement(ProgressIndicator, {
32
- currentIndex: (_stepData$2 = stepData[0]) !== null && _stepData$2 !== void 0 && _stepData$2.introStep ? currentStep - 2 : currentStep - 1,
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
+ ,
33
54
  spaceEqually: true,
34
55
  vertical: true,
35
56
  className: cx("".concat(blockClass, "__progress-indicator"))
36
- }, extractedSteps.map(function (step, stepIndex) {
57
+ }, progressSteps.map(function (step, stepIndex) {
37
58
  return /*#__PURE__*/React.createElement(ProgressStep, {
38
59
  label: step.title,
39
60
  key: stepIndex,
@@ -66,6 +87,7 @@ CreateInfluencer.propTypes = {
66
87
  stepData: PropTypes.arrayOf(PropTypes.shape({
67
88
  introStep: PropTypes.bool,
68
89
  secondaryLabel: PropTypes.string,
90
+ shouldIncludeStep: PropTypes.bool,
69
91
  title: PropTypes.node
70
92
  }))
71
93
  };
@@ -9,7 +9,7 @@ var _excluded = ["backButtonText", "cancelButtonText", "children", "className",
9
9
  * This source code is licensed under the Apache-2.0 license found in the
10
10
  * LICENSE file in the root directory of this source tree.
11
11
  */
12
- import React, { forwardRef, useState, useRef, createContext } from 'react';
12
+ import React, { forwardRef, useState, useRef, createContext, useEffect } from 'react';
13
13
  import PropTypes from 'prop-types';
14
14
  import cx from 'classnames';
15
15
  import { Grid, Form } from 'carbon-components-react';
@@ -19,6 +19,7 @@ import { CreateInfluencer } from '../CreateInfluencer';
19
19
  import { pkg } from '../../settings';
20
20
  import { usePreviousValue, useValidCreateStepCount, useResetCreateComponent, useCreateComponentFocus, useCreateComponentStepChange } from '../../global/js/hooks';
21
21
  import { getDevtoolsProps } from '../../global/js/utils/devtools';
22
+ import { lastIndexInArray } from '../../global/js/utils/lastIndexInArray';
22
23
  var componentName = 'CreateTearsheet';
23
24
  var blockClass = "".concat(pkg.prefix, "--tearsheet-create"); // This is a general context for the steps container
24
25
  // containing information about the state of the container
@@ -86,12 +87,35 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
86
87
  stepData = _useState16[0],
87
88
  setStepData = _useState16[1];
88
89
 
89
- var totalStepCount = React.Children.count(children);
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];
99
+
90
100
  var previousState = usePreviousValue({
91
101
  currentStep: currentStep,
92
102
  open: open
93
103
  });
94
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]);
95
119
  useCreateComponentFocus({
96
120
  previousState: previousState,
97
121
  currentStep: currentStep,
@@ -100,15 +124,18 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
100
124
  });
101
125
  useValidCreateStepCount(stepData.length, componentName);
102
126
  useResetCreateComponent({
127
+ firstIncludedStep: firstIncludedStep,
103
128
  previousState: previousState,
104
129
  open: open,
105
130
  setCurrentStep: setCurrentStep,
106
131
  initialStep: initialStep,
107
- totalSteps: totalStepCount,
132
+ totalSteps: stepData === null || stepData === void 0 ? void 0 : stepData.length,
108
133
  componentName: componentName
109
134
  });
110
135
  useCreateComponentStepChange({
111
- totalStepCount: totalStepCount,
136
+ firstIncludedStep: firstIncludedStep,
137
+ lastIncludedStep: lastIncludedStep,
138
+ stepData: stepData,
112
139
  onNext: onNext,
113
140
  isSubmitDisabled: isDisabled,
114
141
  setCurrentStep: setCurrentStep,
@@ -181,8 +208,7 @@ export var CreateTearsheet = /*#__PURE__*/forwardRef(function (_ref, ref) {
181
208
  });
182
209
  },
183
210
  setStepData: setStepData,
184
- stepData: stepData,
185
- totalStepCount: totalStepCount
211
+ stepData: stepData
186
212
  }
187
213
  }, React.Children.map(children, function (child, index) {
188
214
  return /*#__PURE__*/React.createElement(StepNumberContext.Provider, {
@@ -1,20 +1,20 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
 
4
4
  /**
5
- * Copyright IBM Corp. 2021, 2021
5
+ * Copyright IBM Corp. 2021, 2022
6
6
  *
7
7
  * This source code is licensed under the Apache-2.0 license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
9
  */
10
- import React, { forwardRef, useContext, useEffect } from 'react';
10
+ import React, { forwardRef, useContext, useEffect, useState } from 'react';
11
11
  import PropTypes from 'prop-types';
12
12
  import cx from 'classnames';
13
13
  import { Column, FormGroup, Row } from 'carbon-components-react';
14
14
  import { StepsContext, StepNumberContext } from './CreateTearsheet';
15
15
  import { pkg } from '../../settings';
16
16
  import pconsole from '../../global/js/utils/pconsole';
17
- import { usePreviousValue } from '../../global/js/hooks';
17
+ import { usePreviousValue, useRetrieveStepData } from '../../global/js/hooks';
18
18
  var componentName = 'CreateTearsheetStep';
19
19
  var blockClass = "".concat(pkg.prefix, "--tearsheet-create__step");
20
20
  export var CreateTearsheetStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
@@ -22,57 +22,57 @@ export var CreateTearsheetStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
22
22
 
23
23
  var children = _ref.children,
24
24
  className = _ref.className,
25
- subtitle = _ref.subtitle,
26
25
  description = _ref.description,
27
26
  disableSubmit = _ref.disableSubmit,
28
- introStep = _ref.introStep,
29
- title = _ref.title,
30
- hasFieldset = _ref.hasFieldset,
31
27
  fieldsetLegendText = _ref.fieldsetLegendText,
28
+ hasFieldset = _ref.hasFieldset,
29
+ includeStep = _ref.includeStep,
30
+ introStep = _ref.introStep,
32
31
  onNext = _ref.onNext,
33
32
  onMount = _ref.onMount,
34
- secondaryLabel = _ref.secondaryLabel;
35
- var steps = useContext(StepsContext);
33
+ secondaryLabel = _ref.secondaryLabel,
34
+ subtitle = _ref.subtitle,
35
+ title = _ref.title;
36
+ var stepsContext = useContext(StepsContext);
36
37
  var stepNumber = useContext(StepNumberContext);
38
+
39
+ var _useState = useState(),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ shouldIncludeStep = _useState2[0],
42
+ setShouldIncludeStep = _useState2[1];
43
+
37
44
  var previousState = usePreviousValue({
38
- currentStep: steps === null || steps === void 0 ? void 0 : steps.currentStep
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
39
54
  }); // This useEffect reports back the onNext and onMount values so that they can be used
40
55
  // in the appropriate custom hooks.
41
56
 
42
57
  useEffect(function () {
43
- if (stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep) && (previousState === null || previousState === void 0 ? void 0 : previousState.currentStep) !== (steps === null || steps === void 0 ? void 0 : steps.currentStep)) {
44
- steps === null || steps === void 0 ? void 0 : steps.setOnNext(onNext);
45
- steps === null || steps === void 0 ? void 0 : steps.setOnMount(onMount);
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);
46
61
  }
47
- }, [onMount, onNext, steps, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]); // This useEffect makes sure that every CreateTearsheetStep reports back it's
48
- // title, secondaryLabel, and introStep props so that it can be sent to the CreateInfluencer.
62
+ }, [onMount, onNext, stepsContext, stepNumber, previousState === null || previousState === void 0 ? void 0 : previousState.currentStep]); // Used to take the `includeStep` prop and use it as a local state value
49
63
 
50
64
  useEffect(function () {
51
- var _steps$stepData, _steps$stepData2;
52
-
53
- var stepHasReported = steps === null || steps === void 0 ? void 0 : (_steps$stepData = steps.stepData) === null || _steps$stepData === void 0 ? void 0 : _steps$stepData.includes(function (item) {
54
- return item.title === title;
55
- });
56
-
57
- if (!stepHasReported && (steps === null || steps === void 0 ? void 0 : (_steps$stepData2 = steps.stepData) === null || _steps$stepData2 === void 0 ? void 0 : _steps$stepData2.length) < (steps === null || steps === void 0 ? void 0 : steps.totalStepCount)) {
58
- steps === null || steps === void 0 ? void 0 : steps.setStepData(function (prev) {
59
- return [].concat(_toConsumableArray(prev), [{
60
- title: title,
61
- secondaryLabel: secondaryLabel,
62
- introStep: introStep
63
- }]);
64
- });
65
- }
66
- }, [steps, title, secondaryLabel, introStep]); // Whenever we are the current step, supply our disableSubmit value to the
65
+ setShouldIncludeStep(includeStep);
66
+ }, [includeStep, stepsContext, title]); // Whenever we are the current step, supply our disableSubmit value to the
67
67
  // steps container context so that it can manage the 'Next' button appropriately.
68
68
 
69
69
  useEffect(function () {
70
- if (stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep)) {
71
- steps.setIsDisabled(disableSubmit);
70
+ if (stepNumber === (stepsContext === null || stepsContext === void 0 ? void 0 : stepsContext.currentStep)) {
71
+ stepsContext.setIsDisabled(disableSubmit);
72
72
  }
73
- }, [steps, stepNumber, disableSubmit, onNext]);
74
- return steps ? /*#__PURE__*/React.createElement("div", {
75
- className: cx(blockClass, className, (_cx = {}, _defineProperty(_cx, "".concat(blockClass, "__step--hidden-step"), stepNumber !== (steps === null || steps === void 0 ? void 0 : steps.currentStep)), _defineProperty(_cx, "".concat(blockClass, "__step--visible-step"), stepNumber === (steps === null || steps === void 0 ? void 0 : steps.currentStep)), _cx)),
73
+ }, [stepsContext, stepNumber, disableSubmit, onNext]);
74
+ return stepsContext ? /*#__PURE__*/React.createElement("div", {
75
+ 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)),
76
76
  ref: ref
77
77
  }, /*#__PURE__*/React.createElement(Row, null, /*#__PURE__*/React.createElement(Column, {
78
78
  xlg: 12,
@@ -130,6 +130,12 @@ CreateTearsheetStep.propTypes = {
130
130
  */
131
131
  hasFieldset: PropTypes.bool,
132
132
 
133
+ /**
134
+ * 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
135
+ * 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
136
+ */
137
+ includeStep: PropTypes.bool,
138
+
133
139
  /**
134
140
  * This prop can be used on the first step to mark it as an intro step, which will not render the progress indicator steps
135
141
  */
@@ -168,5 +174,6 @@ CreateTearsheetStep.propTypes = {
168
174
  // component needs to make a choice or assumption when a prop is not supplied.
169
175
 
170
176
  CreateTearsheetStep.defaultProps = {
171
- hasFieldset: true
177
+ hasFieldset: true,
178
+ includeStep: true
172
179
  };