grommet 2.57.0 → 2.58.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 (124) hide show
  1. package/components/Box/StyledBox.js +1 -1
  2. package/components/Box/stories/ColorContrast.stories.js +36 -0
  3. package/components/Button/BusyAnimation.js +7 -1
  4. package/components/Button/Button.js +12 -3
  5. package/components/DataTable/StyledDataTable.js +1 -1
  6. package/components/DateInput/DateInput.js +3 -3
  7. package/components/DateTimeInput/DateTimeInput.js +17 -11
  8. package/components/FocusedContainer.js +2 -1
  9. package/components/FormField/FormField.js +31 -10
  10. package/components/FormField/FormFieldContext.js +12 -0
  11. package/components/Grommet/Grommet.js +4 -1
  12. package/components/Grommet/StyledGrommet.js +3 -3
  13. package/components/Grommet/index.d.ts +6 -0
  14. package/components/Grommet/propTypes.js +2 -0
  15. package/components/Menu/Menu.js +1 -1
  16. package/components/Select/SelectContainer.js +2 -2
  17. package/components/Select/StyledSelect.js +3 -1
  18. package/components/TextArea/StyledTextArea.js +3 -1
  19. package/components/TextInput/CopyButton.js +23 -6
  20. package/components/TextInput/StyledTextInput.js +19 -25
  21. package/components/TextInput/TextInput.js +75 -28
  22. package/components/TextInput/index.d.ts +12 -3
  23. package/components/TextInput/propTypes.js +2 -0
  24. package/components/TextInput/stories/Copy.stories.tsx +42 -0
  25. package/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  26. package/components/TimeInput/README.md +24 -1
  27. package/components/TimeInput/StyledTimeInput.js +91 -27
  28. package/components/TimeInput/TimeInput.js +185 -120
  29. package/components/TimeInput/TimeInputPopup.js +114 -117
  30. package/components/TimeInput/index.d.ts +2 -0
  31. package/components/TimeInput/propTypes.js +2 -0
  32. package/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  33. package/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  34. package/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  35. package/components/TimeInput/stories/Form.stories.tsx +1 -0
  36. package/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  37. package/components/TimeInput/useSectionedTimeField.js +2 -2
  38. package/components/TimeInput/utils.js +13 -62
  39. package/components/Wizard/Wizard.js +396 -210
  40. package/components/Wizard/WizardContent.js +61 -35
  41. package/components/Wizard/WizardContext.js +3 -0
  42. package/components/Wizard/WizardFooter.js +14 -15
  43. package/components/Wizard/WizardHeader.js +12 -7
  44. package/components/Wizard/WizardProgress.js +27 -2
  45. package/components/Wizard/index.d.ts +35 -4
  46. package/components/Wizard/propTypes.js +6 -1
  47. package/components/Wizard/stories/BasicLinear.stories.js +12 -10
  48. package/components/Wizard/stories/ClickableSteps.stories.js +104 -0
  49. package/components/Wizard/stories/ExternalForm.stories.js +114 -0
  50. package/components/Wizard/stories/NonClosableHeader.stories.js +68 -0
  51. package/components/Wizard/stories/Validation.stories.js +18 -8
  52. package/es6/components/Box/StyledBox.js +1 -1
  53. package/es6/components/Box/stories/ColorContrast.stories.js +31 -0
  54. package/es6/components/Button/BusyAnimation.js +7 -1
  55. package/es6/components/Button/Button.js +12 -3
  56. package/es6/components/DataTable/StyledDataTable.js +2 -2
  57. package/es6/components/DateInput/DateInput.js +3 -3
  58. package/es6/components/DateTimeInput/DateTimeInput.js +17 -11
  59. package/es6/components/FocusedContainer.js +2 -1
  60. package/es6/components/FormField/FormField.js +31 -10
  61. package/es6/components/FormField/FormFieldContext.js +7 -0
  62. package/es6/components/Grommet/Grommet.js +4 -1
  63. package/es6/components/Grommet/StyledGrommet.js +4 -4
  64. package/es6/components/Grommet/index.d.ts +6 -0
  65. package/es6/components/Grommet/propTypes.js +2 -0
  66. package/es6/components/Menu/Menu.js +1 -1
  67. package/es6/components/Select/SelectContainer.js +2 -2
  68. package/es6/components/Select/StyledSelect.js +4 -2
  69. package/es6/components/TextArea/StyledTextArea.js +4 -2
  70. package/es6/components/TextInput/CopyButton.js +22 -6
  71. package/es6/components/TextInput/StyledTextInput.js +20 -26
  72. package/es6/components/TextInput/TextInput.js +76 -29
  73. package/es6/components/TextInput/index.d.ts +12 -3
  74. package/es6/components/TextInput/propTypes.js +2 -0
  75. package/es6/components/TextInput/stories/Copy.stories.tsx +42 -0
  76. package/es6/components/TextInput/stories/CopySecret.stories.tsx +44 -0
  77. package/es6/components/TimeInput/README.md +24 -1
  78. package/es6/components/TimeInput/StyledTimeInput.js +92 -28
  79. package/es6/components/TimeInput/TimeInput.js +187 -122
  80. package/es6/components/TimeInput/TimeInputPopup.js +115 -118
  81. package/es6/components/TimeInput/index.d.ts +2 -0
  82. package/es6/components/TimeInput/propTypes.js +2 -0
  83. package/es6/components/TimeInput/stories/Controlled.stories.tsx +2 -2
  84. package/es6/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
  85. package/es6/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
  86. package/es6/components/TimeInput/stories/Form.stories.tsx +1 -0
  87. package/es6/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
  88. package/es6/components/TimeInput/useSectionedTimeField.js +2 -2
  89. package/es6/components/TimeInput/utils.js +12 -61
  90. package/es6/components/Wizard/Wizard.js +397 -211
  91. package/es6/components/Wizard/WizardContent.js +62 -36
  92. package/es6/components/Wizard/WizardContext.js +3 -0
  93. package/es6/components/Wizard/WizardFooter.js +14 -15
  94. package/es6/components/Wizard/WizardHeader.js +12 -7
  95. package/es6/components/Wizard/WizardProgress.js +27 -2
  96. package/es6/components/Wizard/index.d.ts +35 -4
  97. package/es6/components/Wizard/propTypes.js +6 -1
  98. package/es6/components/Wizard/stories/BasicLinear.stories.js +11 -11
  99. package/es6/components/Wizard/stories/ClickableSteps.stories.js +99 -0
  100. package/es6/components/Wizard/stories/ExternalForm.stories.js +111 -0
  101. package/es6/components/Wizard/stories/NonClosableHeader.stories.js +63 -0
  102. package/es6/components/Wizard/stories/Validation.stories.js +18 -9
  103. package/es6/languages/default.json +2 -0
  104. package/es6/themes/base.d.ts +79 -59
  105. package/es6/themes/base.js +65 -34
  106. package/es6/utils/DOM.js +10 -7
  107. package/es6/utils/background.js +9 -7
  108. package/es6/utils/colors.js +84 -12
  109. package/es6/utils/legacyColorIsDark.js +17 -0
  110. package/es6/utils/styles.js +13 -5
  111. package/grommet.min.js +1 -1
  112. package/grommet.min.js.map +1 -1
  113. package/languages/default.json +2 -0
  114. package/package.json +3 -3
  115. package/themes/base.d.ts +79 -59
  116. package/themes/base.js +65 -34
  117. package/tools/draft-release-version-pr.js +1 -0
  118. package/tools/generate-release-notes.js +1 -1
  119. package/tools/release-notes-utils.js +1 -0
  120. package/utils/DOM.js +10 -7
  121. package/utils/background.js +9 -7
  122. package/utils/colors.js +84 -12
  123. package/utils/legacyColorIsDark.js +21 -0
  124. package/utils/styles.js +14 -6
@@ -7,6 +7,7 @@ var _Form = require("../Form");
7
7
  var _Box = require("../Box");
8
8
  var _Notification = require("../Notification");
9
9
  var _useThemeValue2 = require("../../utils/useThemeValue");
10
+ var _useIsomorphicLayoutEffect = require("../../utils/use-isomorphic-layout-effect");
10
11
  var _WizardContext = require("./WizardContext");
11
12
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
12
13
  function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
@@ -15,76 +16,101 @@ function _extends() { return _extends = Object.assign ? Object.assign.bind() : f
15
16
  // WizardContent renders the current step body and any wizard-level
16
17
  // validation error message.
17
18
  var WizardContent = exports.WizardContent = function WizardContent(_ref) {
18
- var _theme$wizard;
19
+ var _theme$wizard, _stepValidation$curre;
19
20
  var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
20
21
  var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
21
22
  theme = _useThemeValue.theme;
22
23
  var wizard = (0, _WizardContext.useWizard)();
23
24
  var currentStep = wizard.currentStep,
24
- currentStepIndex = wizard.currentStepIndex,
25
25
  currentStepObj = wizard.currentStepObj,
26
- totalSteps = wizard.totalSteps,
26
+ form = wizard.form,
27
27
  formValue = wizard.formValue,
28
- complete = wizard.complete,
29
- next = wizard.next,
30
28
  renderStep = wizard.renderStep,
31
29
  setFormValue = wizard.setFormValue,
32
- validationError = wizard.validationError;
30
+ validationError = wizard.validationError,
31
+ stepValidation = wizard.stepValidation,
32
+ updateValidation = wizard.updateValidation,
33
+ registerForm = wizard.registerForm;
34
+ var formRef = (0, _react.useRef)(null);
35
+ var pendingSubmission = (0, _react.useRef)();
33
36
  var contentTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.content;
34
- var submit = currentStepIndex >= totalSteps - 1 ? complete : next;
37
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(function () {
38
+ if (!form || !formRef.current) return undefined;
39
+ var unregister = registerForm(currentStep, function () {
40
+ return new Promise(function (resolve) {
41
+ pendingSubmission.current = {
42
+ stepId: currentStep,
43
+ resolve: resolve
44
+ };
45
+ formRef.current.requestSubmit();
46
+ });
47
+ });
48
+ return function () {
49
+ var _pendingSubmission$cu;
50
+ unregister();
51
+ if (((_pendingSubmission$cu = pendingSubmission.current) == null ? void 0 : _pendingSubmission$cu.stepId) === currentStep) {
52
+ pendingSubmission.current.resolve({
53
+ cancelled: true
54
+ });
55
+ pendingSubmission.current = undefined;
56
+ }
57
+ };
58
+ }, [currentStep, form, registerForm]);
35
59
  var onValidate = (0, _react.useCallback)(function (_ref2) {
36
60
  var valid = _ref2.valid,
37
61
  errors = _ref2.errors,
38
62
  submitting = _ref2.submitting;
39
- var formElement = document.getElementById(currentStep + "-form");
40
- if (formElement) {
41
- formElement.setAttribute('data-form-valid', String(valid));
42
- }
43
- if (submitting) {
63
+ var formElement = formRef.current;
64
+ var result = {
65
+ ok: valid,
66
+ errors: _extends({}, errors)
67
+ };
68
+ Promise.resolve().then(function () {
69
+ var _pendingSubmission$cu2;
70
+ updateValidation(currentStep, 'form', result);
71
+ if (submitting && ((_pendingSubmission$cu2 = pendingSubmission.current) == null ? void 0 : _pendingSubmission$cu2.stepId) === currentStep) {
72
+ pendingSubmission.current.resolve(result);
73
+ pendingSubmission.current = undefined;
74
+ }
75
+ });
76
+ if (submitting && !valid) {
44
77
  // focus the first error field that exists in the DOM
45
78
  var names = Object.keys(errors || {});
46
79
  var firstInvalid = names.reduce(function (found, name) {
47
80
  if (found) return found;
48
- var matches = document.getElementsByName(name);
49
- return matches.length > 0 ? matches[0] : null;
81
+ var matches = formElement == null ? void 0 : formElement.elements.namedItem(name);
82
+ return matches != null && matches.focus ? matches : (matches == null ? void 0 : matches[0]) || null;
50
83
  }, null);
51
84
  if (firstInvalid) {
52
85
  setTimeout(function () {
53
- return firstInvalid.focus();
86
+ if (formElement != null && formElement.isConnected && formRef.current === formElement) firstInvalid.focus();
54
87
  }, 0);
55
88
  }
56
- if (!valid) {
57
- // Since onSubmit won't get called in this case, go ahead and
58
- // call submit() to trigger wizard-level state changes. It will
59
- // get to the runValidation step, see that
60
- // the form is invalid from the data-form-valid attribute and set
61
- // the appropriate blocked state.
62
- // TODO: consider a method on the wizard context to set the
63
- // blocked state directly instead of calling submit()
64
- submit();
65
- }
66
89
  }
67
- }, [currentStep, submit]);
90
+ }, [currentStep, updateValidation]);
68
91
  if (!currentStepObj) return null;
69
92
  var stepRender = currentStepObj.render || renderStep;
70
93
  var body = stepRender ? stepRender(currentStepObj, wizard) : null;
71
- return /*#__PURE__*/_react["default"].createElement(_Form.Form, {
94
+ var content = /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({}, contentTheme, {
95
+ flex: "grow"
96
+ }, rest), body, validationError && /*#__PURE__*/_react["default"].createElement(_Notification.Notification, {
97
+ status: "critical",
98
+ message: validationError
99
+ }));
100
+ return form ? /*#__PURE__*/_react["default"].createElement(_Form.Form, {
101
+ key: currentStep,
72
102
  id: currentStep + "-form",
103
+ ref: formRef,
73
104
  value: formValue,
74
105
  onChange: setFormValue,
75
- onSubmit: submit,
76
106
  onValidate: onValidate,
107
+ errors: (_stepValidation$curre = stepValidation[currentStep]) == null || (_stepValidation$curre = _stepValidation$curre.form) == null ? void 0 : _stepValidation$curre.errors,
77
108
  method: "post",
78
- "data-form-valid": "true",
109
+ noValidate: true,
79
110
  style: {
80
111
  display: 'flex',
81
112
  flex: '1 1 auto'
82
113
  }
83
- }, /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({}, contentTheme, {
84
- flex: "grow"
85
- }, rest), body, validationError && /*#__PURE__*/_react["default"].createElement(_Notification.Notification, {
86
- status: "critical",
87
- message: validationError
88
- })));
114
+ }, content) : content;
89
115
  };
90
116
  WizardContent.displayName = 'WizardContent';
@@ -10,11 +10,14 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
10
10
  // WizardContext exposes wizard state and navigation actions to descendants.
11
11
  var WizardContext = exports.WizardContext = /*#__PURE__*/_react["default"].createContext({
12
12
  steps: [],
13
+ clickableSteps: false,
14
+ closable: true,
13
15
  currentStep: '',
14
16
  currentStepIndex: 0,
15
17
  currentStepObj: undefined,
16
18
  totalSteps: 0,
17
19
  stepStates: {},
20
+ form: true,
18
21
  formValue: {},
19
22
  setFormValue: function setFormValue() {},
20
23
  validationError: undefined,
@@ -25,11 +25,12 @@ var WizardFooter = exports.WizardFooter = function WizardFooter(_ref) {
25
25
  var _React$useContext = _react["default"].useContext(_MessageContext.MessageContext),
26
26
  format = _React$useContext.format;
27
27
  var _useWizard = (0, _WizardContext.useWizard)(),
28
- currentStep = _useWizard.currentStep,
29
28
  currentStepObj = _useWizard.currentStepObj,
30
29
  currentStepIndex = _useWizard.currentStepIndex,
31
30
  totalSteps = _useWizard.totalSteps,
32
31
  canGoNext = _useWizard.canGoNext,
32
+ complete = _useWizard.complete,
33
+ next = _useWizard.next,
33
34
  previous = _useWizard.previous,
34
35
  skip = _useWizard.skip,
35
36
  cancel = _useWizard.cancel,
@@ -57,6 +58,12 @@ var WizardFooter = exports.WizardFooter = function WizardFooter(_ref) {
57
58
  var SkipIcon = footerTheme == null || (_footerTheme$button3 = footerTheme.button) == null || (_footerTheme$button3 = _footerTheme$button3.skip) == null ? void 0 : _footerTheme$button3.icon;
58
59
  var CompleteIcon = footerTheme == null || (_footerTheme$button4 = footerTheme.button) == null || (_footerTheme$button4 = _footerTheme$button4.complete) == null ? void 0 : _footerTheme$button4.icon;
59
60
  var CancelIcon = footerTheme == null || (_footerTheme$button5 = footerTheme.button) == null || (_footerTheme$button5 = _footerTheme$button5.cancel) == null ? void 0 : _footerTheme$button5.icon;
61
+ var submitProps = {
62
+ primary: true,
63
+ disabled: !canGoNext,
64
+ type: 'button',
65
+ onClick: isLastStep ? complete : next
66
+ };
60
67
  content = [hasCancelHandler && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
61
68
  key: "cancel",
62
69
  label: label('cancel'),
@@ -73,7 +80,7 @@ var WizardFooter = exports.WizardFooter = function WizardFooter(_ref) {
73
80
  }) : undefined,
74
81
  disabled: !canGoPrevious,
75
82
  onClick: previous
76
- }), currentStepObj.skippable && !isLastStep && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
83
+ }), currentStepObj.skippable && !currentStepObj.disabled && !isLastStep && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
77
84
  key: "skip",
78
85
  label: label('skip'),
79
86
  secondary: true,
@@ -82,28 +89,20 @@ var WizardFooter = exports.WizardFooter = function WizardFooter(_ref) {
82
89
  }) : undefined,
83
90
  reverse: true,
84
91
  onClick: skip
85
- }), isLastStep ? /*#__PURE__*/_react["default"].createElement(_Button.Button, {
92
+ }), isLastStep ? /*#__PURE__*/_react["default"].createElement(_Button.Button, _extends({
86
93
  key: "complete",
87
94
  label: label('complete'),
88
95
  icon: CompleteIcon ? /*#__PURE__*/_react["default"].createElement(CompleteIcon, {
89
96
  "aria-hidden": "true"
90
- }) : undefined,
91
- primary: true,
92
- disabled: !canGoNext,
93
- type: "submit",
94
- form: currentStep + "-form"
95
- }) : /*#__PURE__*/_react["default"].createElement(_Button.Button, {
97
+ }) : undefined
98
+ }, submitProps)) : /*#__PURE__*/_react["default"].createElement(_Button.Button, _extends({
96
99
  key: "next",
97
100
  label: label('next'),
98
- primary: true,
99
101
  icon: NextIcon ? /*#__PURE__*/_react["default"].createElement(NextIcon, {
100
102
  "aria-hidden": "true"
101
103
  }) : undefined,
102
- reverse: true,
103
- disabled: !canGoNext,
104
- type: "submit",
105
- form: currentStep + "-form"
106
- })];
104
+ reverse: true
105
+ }, submitProps))];
107
106
  }
108
107
  return /*#__PURE__*/_react["default"].createElement(_ResponsiveContext.ResponsiveContext.Consumer, null, function (size) {
109
108
  var isSmall = size === 'small';
@@ -17,7 +17,7 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
17
17
  // Header above the progress track. Hosts the close (X) button which
18
18
  // invokes `cancel` from context.
19
19
  var WizardHeader = exports.WizardHeader = function WizardHeader(_ref) {
20
- var _theme$wizard, _headerTheme$title, _headerTheme$close;
20
+ var _theme$wizard, _headerTheme$close;
21
21
  var title = _ref.title,
22
22
  children = _ref.children,
23
23
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -27,15 +27,20 @@ var WizardHeader = exports.WizardHeader = function WizardHeader(_ref) {
27
27
  format = _React$useContext.format;
28
28
  var _useWizard = (0, _WizardContext.useWizard)(),
29
29
  cancel = _useWizard.cancel,
30
+ closable = _useWizard.closable,
30
31
  messages = _useWizard.messages;
31
32
  var headerTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.header;
32
33
 
33
34
  // Custom children override the themed title.
34
- var content = children !== undefined ? children : title && /*#__PURE__*/_react["default"].createElement(_Heading.Heading, {
35
- level: 1,
36
- size: headerTheme == null || (_headerTheme$title = headerTheme.title) == null ? void 0 : _headerTheme$title.size,
37
- margin: "none"
38
- }, title);
35
+ var content = children;
36
+ if (children === undefined) {
37
+ var _headerTheme$title;
38
+ content = typeof title === 'string' && title ? /*#__PURE__*/_react["default"].createElement(_Heading.Heading, {
39
+ level: 1,
40
+ size: headerTheme == null || (_headerTheme$title = headerTheme.title) == null ? void 0 : _headerTheme$title.size,
41
+ margin: "none"
42
+ }, title) : title;
43
+ }
39
44
  var CloseIcon = headerTheme == null || (_headerTheme$close = headerTheme.close) == null ? void 0 : _headerTheme$close.icon;
40
45
  var closeLabel = format({
41
46
  id: 'wizard.close',
@@ -52,7 +57,7 @@ var WizardHeader = exports.WizardHeader = function WizardHeader(_ref) {
52
57
  direction: "row",
53
58
  align: "center",
54
59
  flex: true
55
- }, content), /*#__PURE__*/_react["default"].createElement(_Button.Button, {
60
+ }, content), closable && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
56
61
  "aria-label": closeLabel,
57
62
  icon: CloseIcon ? /*#__PURE__*/_react["default"].createElement(CloseIcon, {
58
63
  "aria-hidden": "true"
@@ -27,9 +27,12 @@ var WizardProgress = exports.WizardProgress = function WizardProgress(_ref) {
27
27
  format = _React$useContext.format;
28
28
  var _useWizard = (0, _WizardContext.useWizard)(),
29
29
  steps = _useWizard.steps,
30
+ clickableSteps = _useWizard.clickableSteps,
30
31
  currentStep = _useWizard.currentStep,
32
+ goTo = _useWizard.goTo,
31
33
  showProgress = _useWizard.showProgress,
32
34
  stepStates = _useWizard.stepStates,
35
+ stepErrorMessages = _useWizard.stepErrorMessages,
33
36
  messages = _useWizard.messages;
34
37
 
35
38
  // Opt-in: render nothing when `showProgress` is false.
@@ -46,6 +49,7 @@ var WizardProgress = exports.WizardProgress = function WizardProgress(_ref) {
46
49
  };
47
50
  if (step.disabledReason) mapped.disabledReason = step.disabledReason;
48
51
  if (step['aria-label']) mapped['aria-label'] = step['aria-label'];
52
+ mapped.errorMessage = stepErrorMessages[step.id];
49
53
  if (step.children && step.children.length) {
50
54
  mapped.children = step.children.map(function (child) {
51
55
  return _extends({
@@ -57,7 +61,9 @@ var WizardProgress = exports.WizardProgress = function WizardProgress(_ref) {
57
61
  disabledReason: child.disabledReason
58
62
  } : {}, child['aria-label'] ? {
59
63
  'aria-label': child['aria-label']
60
- } : {});
64
+ } : {}, {
65
+ errorMessage: stepErrorMessages[child.id]
66
+ });
61
67
  });
62
68
  }
63
69
  return mapped;
@@ -66,6 +72,24 @@ var WizardProgress = exports.WizardProgress = function WizardProgress(_ref) {
66
72
  id: 'wizard.progress',
67
73
  messages: messages
68
74
  });
75
+ var onStepClick = clickableSteps ? function (stepId) {
76
+ var _step$children;
77
+ // if forward and form need to do form validation
78
+ var step = steps.find(function (s) {
79
+ return s.id === stepId;
80
+ });
81
+ if (step != null && (_step$children = step.children) != null && _step$children.length) {
82
+ // find the first child we are allowed to go to
83
+ var firstAllowedChild = step.children.find(function (child) {
84
+ return !child.disabled;
85
+ });
86
+ if (firstAllowedChild) {
87
+ goTo(firstAllowedChild.id);
88
+ }
89
+ } else {
90
+ goTo(stepId);
91
+ }
92
+ } : undefined;
69
93
  return /*#__PURE__*/_react["default"].createElement(_Box.Box, _extends({
70
94
  pad: progressTheme == null ? void 0 : progressTheme.pad,
71
95
  width: showProgress === 'vertical' ? progressTheme == null ? void 0 : progressTheme.width : undefined,
@@ -77,7 +101,8 @@ var WizardProgress = exports.WizardProgress = function WizardProgress(_ref) {
77
101
  steps: stepperSteps,
78
102
  currentStep: currentStep,
79
103
  direction: showProgress === 'vertical' ? 'vertical' : 'horizontal',
80
- clickableSteps: false,
104
+ clickableSteps: clickableSteps,
105
+ onStepClick: onStepClick,
81
106
  showDescription: showDescription,
82
107
  "aria-label": ariaLabel
83
108
  }));
@@ -41,13 +41,27 @@ export interface WizardStep<TValue = Record<string, any>> {
41
41
  | { error?: string }
42
42
  | Promise<boolean | string | void | { error?: string }>;
43
43
  nextStep?: (value: TValue) => string | undefined | null;
44
+ /** Allows goTo(), skip(), and completion after failed validation without
45
+ * marking this step completed. next() still requires a valid step. */
44
46
  skippable?: boolean;
47
+ /** Overrides the displayed status, not validation or completion results.
48
+ * An explicit error status also blocks next(). disabled: true takes
49
+ * precedence. */
50
+ status?: WizardStepStatus;
45
51
  disabled?: boolean;
46
52
  disabledReason?: string;
53
+ /** Overrides the stepper's validation message. An empty string suppresses
54
+ * generated text. Form failures do not generate a stepper message. */
55
+ errorMessage?: string;
47
56
  children?: WizardStep<TValue>[];
48
57
  'aria-label'?: string;
49
58
  }
50
59
 
60
+ export type WizardStepResult<TValue = Record<string, any>> = Omit<
61
+ WizardStep<TValue>,
62
+ 'children' | 'status'
63
+ > & { status: WizardStepStatus };
64
+
51
65
  // Discriminated union for onStepChange events. Consumers can narrow on
52
66
  // `trigger` + `phase` to reason about event flow without inspecting DOM.
53
67
  export interface NavigationStepChangeEvent {
@@ -82,17 +96,28 @@ export interface WizardMessages {
82
96
 
83
97
  export interface WizardProps<TValue = Record<string, any>> {
84
98
  steps: WizardStep<TValue>[];
99
+ clickableSteps?: boolean;
100
+ closable?: boolean;
85
101
  currentStep?: string;
86
102
  defaultStep?: string;
103
+ form?: boolean;
87
104
  showProgress?: WizardShowProgress;
88
105
  onStepChange?: (event: StepChangeEvent) => void;
89
- onComplete?: (event: { value: TValue; completedSteps: string[] }) => void;
106
+ /** completedSteps excludes failed and skipped steps. Completion validates
107
+ * the current step, not every earlier step. steps includes parent groups
108
+ * and children in depth-first order, without children arrays, with resolved
109
+ * statuses and error messages including the final validation result. */
110
+ onComplete?: (event: {
111
+ value: TValue;
112
+ completedSteps: string[];
113
+ steps: WizardStepResult<TValue>[];
114
+ }) => void;
90
115
  onCancel?: (event: { value: TValue; reason: 'user' }) => void;
91
116
  renderStep?: (
92
117
  step: WizardStep<TValue>,
93
118
  api: WizardContextValue<TValue>,
94
119
  ) => React.ReactNode;
95
- title?: string;
120
+ title?: React.ReactNode;
96
121
  footer?: React.ReactNode;
97
122
  scrollToTop?: boolean;
98
123
  value?: TValue;
@@ -117,6 +142,10 @@ export interface WizardContextValue<TValue = Record<string, any>> {
117
142
  currentStepObj?: WizardStep<TValue>;
118
143
  totalSteps: number;
119
144
  stepStates: Record<string, WizardStepStatus>;
145
+ /** Resolved stepper messages, including developer overrides, for steps
146
+ * whose resolved status is error. */
147
+ stepErrorMessages: Record<string, string | undefined>;
148
+ form: boolean;
120
149
  formValue: TValue;
121
150
  setFormValue: (next: TValue | ((prev: TValue) => TValue)) => void;
122
151
  validationError?: string;
@@ -130,6 +159,8 @@ export interface WizardContextValue<TValue = Record<string, any>> {
130
159
  skip: () => void;
131
160
  complete: () => void;
132
161
  cancel: () => void;
162
+ clickableSteps: boolean;
163
+ closable: boolean;
133
164
  showProgress: WizardShowProgress;
134
165
  renderStep?: (
135
166
  step: WizardStep<TValue>,
@@ -143,8 +174,8 @@ export function useWizard<
143
174
  TValue = Record<string, any>,
144
175
  >(): WizardContextValue<TValue>;
145
176
 
146
- export interface WizardHeaderProps extends BoxExtendedProps {
147
- title?: string;
177
+ export interface WizardHeaderProps extends Omit<BoxExtendedProps, 'title'> {
178
+ title?: React.ReactNode;
148
179
  children?: React.ReactNode;
149
180
  }
150
181
 
@@ -12,10 +12,12 @@ if (process.env.NODE_ENV !== 'production') {
12
12
  id: _propTypes["default"].string.isRequired,
13
13
  title: _propTypes["default"].string.isRequired,
14
14
  description: _propTypes["default"].node,
15
+ errorMessage: _propTypes["default"].string,
15
16
  render: _propTypes["default"].func,
16
17
  validate: _propTypes["default"].func,
17
18
  nextStep: _propTypes["default"].func,
18
19
  skippable: _propTypes["default"].bool,
20
+ status: _propTypes["default"].oneOf(['pending', 'completed', 'error', 'disabled']),
19
21
  disabled: _propTypes["default"].bool,
20
22
  disabledReason: _propTypes["default"].string,
21
23
  'aria-label': _propTypes["default"].string
@@ -25,14 +27,17 @@ if (process.env.NODE_ENV !== 'production') {
25
27
  });
26
28
  propType = {
27
29
  steps: _propTypes["default"].arrayOf(_propTypes["default"].shape(nestedStepShape)).isRequired,
30
+ clickableSteps: _propTypes["default"].bool,
31
+ closable: _propTypes["default"].bool,
28
32
  currentStep: _propTypes["default"].string,
29
33
  defaultStep: _propTypes["default"].string,
34
+ form: _propTypes["default"].bool,
30
35
  showProgress: _propTypes["default"].oneOfType([_propTypes["default"].oneOf(['horizontal', 'vertical']), _propTypes["default"].bool]),
31
36
  onStepChange: _propTypes["default"].func,
32
37
  onComplete: _propTypes["default"].func,
33
38
  onCancel: _propTypes["default"].func,
34
39
  renderStep: _propTypes["default"].func,
35
- title: _propTypes["default"].string,
40
+ title: _propTypes["default"].node,
36
41
  footer: _propTypes["default"].node,
37
42
  scrollToTop: _propTypes["default"].bool,
38
43
  value: _propTypes["default"].object,
@@ -6,24 +6,26 @@ var _react = _interopRequireWildcard(require("react"));
6
6
  var _grommet = require("grommet");
7
7
  var _Wizard = require("../Wizard");
8
8
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
9
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
9
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
10
10
  // SPDX-License-Identifier: Apache-2.0
11
+
11
12
  var steps = [{
12
13
  id: 'account',
13
14
  title: 'Account',
14
15
  description: 'Tell us about your account.',
15
- render: function render(step, api) {
16
+ render: function render() {
16
17
  return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
17
18
  gap: "small"
18
- }, /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Enter an email to continue."), /*#__PURE__*/_react["default"].createElement(_grommet.TextInput, {
19
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Enter an email to continue."), /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
20
+ label: "Email",
21
+ name: "email",
22
+ htmlFor: "email-field",
23
+ required: true
24
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.TextInput, {
25
+ id: "email-field",
19
26
  placeholder: "you@example.com",
20
- value: api.formValue.email || '',
21
- onChange: function onChange(event) {
22
- return api.setFormValue(_extends({}, api.formValue, {
23
- email: event.target.value
24
- }));
25
- }
26
- }));
27
+ name: "email"
28
+ })));
27
29
  }
28
30
  }, {
29
31
  id: 'profile',
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports["default"] = exports.ClickableSteps = void 0;
5
+ var _react = _interopRequireWildcard(require("react"));
6
+ var _grommet = require("grommet");
7
+ var _Wizard = require("../Wizard");
8
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
9
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
10
+ // SPDX-License-Identifier: Apache-2.0
11
+
12
+ var ClickableSteps = exports.ClickableSteps = function ClickableSteps() {
13
+ var _useState = (0, _react.useState)(false),
14
+ complete = _useState[0],
15
+ setComplete = _useState[1];
16
+ var _useState2 = (0, _react.useState)({
17
+ advanced: false
18
+ }),
19
+ value = _useState2[0],
20
+ setValue = _useState2[1];
21
+ var steps = [{
22
+ id: 'details',
23
+ title: 'Details',
24
+ description: 'Provide the resource details.',
25
+ render: function render(/* step, api */
26
+ ) {
27
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
28
+ gap: "small"
29
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Describe the resource to create."), /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
30
+ htmlFor: "resource-name",
31
+ label: "Resource name",
32
+ name: "name",
33
+ required: true
34
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.TextInput, {
35
+ id: "resource-name",
36
+ name: "name"
37
+ })), /*#__PURE__*/_react["default"].createElement(_grommet.FormField, {
38
+ name: "advanced"
39
+ }, /*#__PURE__*/_react["default"].createElement(_grommet.CheckBox, {
40
+ name: "advanced",
41
+ label: "Enable advanced options"
42
+ })));
43
+ }
44
+ }, {
45
+ id: 'configure',
46
+ title: 'Configure',
47
+ description: 'Choose configuration options.',
48
+ status: 'error',
49
+ errorMessage: 'Configuration requires attention.',
50
+ skippable: true,
51
+ render: function render() {
52
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Configure the resource options.");
53
+ }
54
+ }, {
55
+ id: 'advanced',
56
+ title: 'Advanced',
57
+ description: 'Configure advanced resource options.',
58
+ disabled: !value.advanced,
59
+ disabledReason: 'Enable advanced options to configure this step.',
60
+ render: function render() {
61
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Configure advanced resource options.");
62
+ }
63
+ }, {
64
+ id: 'review',
65
+ title: 'Review',
66
+ description: 'Review before creating the resource.',
67
+ render: function render(step, api) {
68
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Paragraph, null, "Review the configuration for ", api.formValue.name || 'your resource', ".");
69
+ }
70
+ }];
71
+ return /*#__PURE__*/_react["default"].createElement(_grommet.Box, {
72
+ fill: true
73
+ }, /*#__PURE__*/_react["default"].createElement(_Wizard.Wizard, {
74
+ "aria-label": "Create resource",
75
+ clickableSteps: true,
76
+ title: "Create resource",
77
+ showProgress: "vertical",
78
+ steps: steps,
79
+ value: value,
80
+ onChange: function onChange(_ref) {
81
+ var nextValue = _ref.value;
82
+ return setValue(nextValue);
83
+ },
84
+ onComplete: function onComplete(results) {
85
+ console.log('Wizard complete with results:', results);
86
+ setComplete(true);
87
+ }
88
+ }), complete && /*#__PURE__*/_react["default"].createElement(_grommet.Notification, {
89
+ toast: {
90
+ position: 'top'
91
+ },
92
+ status: "normal",
93
+ title: "Wizard complete",
94
+ onClose: function onClose() {
95
+ return setComplete(false);
96
+ }
97
+ }));
98
+ };
99
+ ClickableSteps.args = {
100
+ full: true
101
+ };
102
+ var _default = exports["default"] = {
103
+ title: 'Layout/Wizard/Clickable Steps'
104
+ };