grommet 2.56.0 → 2.56.1

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 (118) hide show
  1. package/COPYRIGHT.md +3 -1
  2. package/components/Calendar/Calendar.js +2 -1
  3. package/components/Cards/Cards.js +1 -2
  4. package/components/DateTimeInput/DateTimeInput.js +1093 -0
  5. package/components/DateTimeInput/README.md +2 -0
  6. package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
  7. package/components/DateTimeInput/index.d.ts +47 -0
  8. package/components/DateTimeInput/index.js +6 -0
  9. package/components/DateTimeInput/propTypes.js +42 -0
  10. package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  11. package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  12. package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  13. package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  14. package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  15. package/components/Form/Form.js +7 -4
  16. package/components/Form/index.d.ts +3 -0
  17. package/components/Form/stories/AggregateValidation.stories.js +6 -8
  18. package/components/FormField/FormField.js +164 -91
  19. package/components/Stepper/StepConnector.js +19 -49
  20. package/components/Stepper/Stepper.js +5 -11
  21. package/components/Stepper/StepperStep.js +14 -4
  22. package/components/Stepper/StyledStepper.js +59 -21
  23. package/components/TimeInput/TimeInput.js +50 -47
  24. package/components/TimeInput/TimeInputPopup.js +172 -76
  25. package/components/TimeInput/index.d.ts +3 -0
  26. package/components/TimeInput/propTypes.js +4 -0
  27. package/components/TimeInput/useSectionedTimeField.js +33 -34
  28. package/components/TimeInput/utils.js +31 -26
  29. package/components/Wizard/StyledWizard.js +16 -0
  30. package/components/Wizard/Wizard.js +770 -0
  31. package/components/Wizard/WizardContent.js +90 -0
  32. package/components/Wizard/WizardContext.js +35 -0
  33. package/components/Wizard/WizardFooter.js +123 -0
  34. package/components/Wizard/WizardHeader.js +63 -0
  35. package/components/Wizard/WizardProgress.js +84 -0
  36. package/components/Wizard/WizardStepHeader.js +55 -0
  37. package/components/Wizard/index.d.ts +171 -0
  38. package/components/Wizard/index.js +19 -0
  39. package/components/Wizard/propTypes.js +56 -0
  40. package/components/Wizard/stories/BasicLinear.stories.js +71 -0
  41. package/components/Wizard/stories/Branching.stories.js +96 -0
  42. package/components/Wizard/stories/Composable.stories.js +75 -0
  43. package/components/Wizard/stories/Controlled.stories.js +136 -0
  44. package/components/Wizard/stories/LongContent.stories.js +118 -0
  45. package/components/Wizard/stories/Modal.stories.js +143 -0
  46. package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
  47. package/components/Wizard/stories/Validation.stories.js +123 -0
  48. package/components/index.d.ts +4 -0
  49. package/components/index.js +12 -0
  50. package/es6/components/Calendar/Calendar.js +2 -0
  51. package/es6/components/Cards/Cards.js +1 -2
  52. package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
  53. package/es6/components/DateTimeInput/README.md +2 -0
  54. package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
  55. package/es6/components/DateTimeInput/index.d.ts +47 -0
  56. package/es6/components/DateTimeInput/index.js +3 -0
  57. package/es6/components/DateTimeInput/propTypes.js +36 -0
  58. package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
  59. package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
  60. package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
  61. package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
  62. package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
  63. package/es6/components/Form/Form.js +7 -3
  64. package/es6/components/Form/index.d.ts +3 -0
  65. package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
  66. package/es6/components/FormField/FormField.js +165 -91
  67. package/es6/components/Stepper/StepConnector.js +18 -48
  68. package/es6/components/Stepper/Stepper.js +5 -10
  69. package/es6/components/Stepper/StepperStep.js +15 -4
  70. package/es6/components/Stepper/StyledStepper.js +57 -21
  71. package/es6/components/TimeInput/TimeInput.js +50 -46
  72. package/es6/components/TimeInput/TimeInputPopup.js +172 -76
  73. package/es6/components/TimeInput/index.d.ts +3 -0
  74. package/es6/components/TimeInput/propTypes.js +3 -0
  75. package/es6/components/TimeInput/useSectionedTimeField.js +34 -35
  76. package/es6/components/TimeInput/utils.js +25 -21
  77. package/es6/components/Wizard/StyledWizard.js +11 -0
  78. package/es6/components/Wizard/Wizard.js +768 -0
  79. package/es6/components/Wizard/WizardContent.js +87 -0
  80. package/es6/components/Wizard/WizardContext.js +31 -0
  81. package/es6/components/Wizard/WizardFooter.js +120 -0
  82. package/es6/components/Wizard/WizardHeader.js +60 -0
  83. package/es6/components/Wizard/WizardProgress.js +80 -0
  84. package/es6/components/Wizard/WizardStepHeader.js +51 -0
  85. package/es6/components/Wizard/index.d.ts +171 -0
  86. package/es6/components/Wizard/index.js +7 -0
  87. package/es6/components/Wizard/propTypes.js +51 -0
  88. package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
  89. package/es6/components/Wizard/stories/Branching.stories.js +93 -0
  90. package/es6/components/Wizard/stories/Composable.stories.js +72 -0
  91. package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
  92. package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
  93. package/es6/components/Wizard/stories/Modal.stories.js +141 -0
  94. package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
  95. package/es6/components/Wizard/stories/Validation.stories.js +118 -0
  96. package/es6/components/index.d.ts +4 -0
  97. package/es6/components/index.js +4 -0
  98. package/es6/index.d.ts +4 -0
  99. package/es6/languages/default.json +28 -0
  100. package/es6/themes/base.d.ts +115 -0
  101. package/es6/themes/base.js +158 -0
  102. package/es6/utils/DOM.js +11 -2
  103. package/es6/utils/dates.js +10 -0
  104. package/es6/utils/sectionHelpers.js +57 -0
  105. package/es6/utils/useSectionedField.js +45 -0
  106. package/grommet.min.js +2 -1
  107. package/grommet.min.js.LICENSE.txt +1 -0
  108. package/grommet.min.js.map +1 -1
  109. package/index.d.ts +4 -0
  110. package/languages/default.json +28 -0
  111. package/package.json +35 -31
  112. package/themes/base.d.ts +115 -0
  113. package/themes/base.js +158 -1
  114. package/tools/license-header.js +2 -0
  115. package/utils/DOM.js +11 -2
  116. package/utils/dates.js +11 -1
  117. package/utils/sectionHelpers.js +61 -0
  118. package/utils/useSectionedField.js +50 -0
@@ -0,0 +1,87 @@
1
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
2
+ 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); }
3
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ import React, { useCallback } from 'react';
6
+ import { Form } from '../Form';
7
+ import { Box } from '../Box';
8
+ import { Notification } from '../Notification';
9
+ import { useThemeValue } from '../../utils/useThemeValue';
10
+ import { useWizard } from './WizardContext';
11
+
12
+ // WizardContent renders the current step body and any wizard-level
13
+ // validation error message.
14
+ export var WizardContent = function WizardContent(_ref) {
15
+ var _theme$wizard;
16
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
17
+ var _useThemeValue = useThemeValue(),
18
+ theme = _useThemeValue.theme;
19
+ var wizard = useWizard();
20
+ var currentStep = wizard.currentStep,
21
+ currentStepIndex = wizard.currentStepIndex,
22
+ currentStepObj = wizard.currentStepObj,
23
+ totalSteps = wizard.totalSteps,
24
+ formValue = wizard.formValue,
25
+ complete = wizard.complete,
26
+ next = wizard.next,
27
+ renderStep = wizard.renderStep,
28
+ setFormValue = wizard.setFormValue,
29
+ validationError = wizard.validationError;
30
+ var contentTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.content;
31
+ var submit = currentStepIndex >= totalSteps - 1 ? complete : next;
32
+ var onValidate = useCallback(function (_ref2) {
33
+ var valid = _ref2.valid,
34
+ errors = _ref2.errors,
35
+ submitting = _ref2.submitting;
36
+ var formElement = document.getElementById(currentStep + "-form");
37
+ if (formElement) {
38
+ formElement.setAttribute('data-form-valid', String(valid));
39
+ }
40
+ if (submitting) {
41
+ // focus the first error field that exists in the DOM
42
+ var names = Object.keys(errors || {});
43
+ var firstInvalid = names.reduce(function (found, name) {
44
+ if (found) return found;
45
+ var matches = document.getElementsByName(name);
46
+ return matches.length > 0 ? matches[0] : null;
47
+ }, null);
48
+ if (firstInvalid) {
49
+ setTimeout(function () {
50
+ return firstInvalid.focus();
51
+ }, 0);
52
+ }
53
+ if (!valid) {
54
+ // Since onSubmit won't get called in this case, go ahead and
55
+ // call submit() to trigger wizard-level state changes. It will
56
+ // get to the runValidation step, see that
57
+ // the form is invalid from the data-form-valid attribute and set
58
+ // the appropriate blocked state.
59
+ // TODO: consider a method on the wizard context to set the
60
+ // blocked state directly instead of calling submit()
61
+ submit();
62
+ }
63
+ }
64
+ }, [currentStep, submit]);
65
+ if (!currentStepObj) return null;
66
+ var stepRender = currentStepObj.render || renderStep;
67
+ var body = stepRender ? stepRender(currentStepObj, wizard) : null;
68
+ return /*#__PURE__*/React.createElement(Form, {
69
+ id: currentStep + "-form",
70
+ value: formValue,
71
+ onChange: setFormValue,
72
+ onSubmit: submit,
73
+ onValidate: onValidate,
74
+ method: "post",
75
+ "data-form-valid": "true",
76
+ style: {
77
+ display: 'flex',
78
+ flex: '1 1 auto'
79
+ }
80
+ }, /*#__PURE__*/React.createElement(Box, _extends({}, contentTheme, {
81
+ flex: "grow"
82
+ }, rest), body, validationError && /*#__PURE__*/React.createElement(Notification, {
83
+ status: "critical",
84
+ message: validationError
85
+ })));
86
+ };
87
+ WizardContent.displayName = 'WizardContent';
@@ -0,0 +1,31 @@
1
+ import React, { useContext } from 'react';
2
+
3
+ // WizardContext exposes wizard state and navigation actions to descendants.
4
+ export var WizardContext = /*#__PURE__*/React.createContext({
5
+ steps: [],
6
+ currentStep: '',
7
+ currentStepIndex: 0,
8
+ currentStepObj: undefined,
9
+ totalSteps: 0,
10
+ stepStates: {},
11
+ formValue: {},
12
+ setFormValue: function setFormValue() {},
13
+ validationError: undefined,
14
+ isValidating: false,
15
+ isBlocked: false,
16
+ isCompleted: false,
17
+ canGoNext: true,
18
+ next: function next() {},
19
+ previous: function previous() {},
20
+ goTo: function goTo() {},
21
+ skip: function skip() {},
22
+ complete: function complete() {},
23
+ cancel: function cancel() {},
24
+ // True when `onCancel` was provided; drives the footer Cancel button.
25
+ hasCancelHandler: false,
26
+ showProgress: false,
27
+ renderStep: undefined
28
+ });
29
+ export var useWizard = function useWizard() {
30
+ return useContext(WizardContext);
31
+ };
@@ -0,0 +1,120 @@
1
+ var _excluded = ["children"];
2
+ 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); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ import React from 'react';
7
+ import { Box } from '../Box';
8
+ import { Button } from '../Button';
9
+ import { MessageContext } from '../../contexts/MessageContext';
10
+ import { ResponsiveContext } from '../../contexts/ResponsiveContext';
11
+ import { useThemeValue } from '../../utils/useThemeValue';
12
+ import { useWizard } from './WizardContext';
13
+
14
+ // WizardFooter renders navigation buttons. Pass `children` to fully
15
+ // replace the default set.
16
+ export var WizardFooter = function WizardFooter(_ref) {
17
+ var _theme$wizard;
18
+ var children = _ref.children,
19
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
20
+ var _useThemeValue = useThemeValue(),
21
+ theme = _useThemeValue.theme;
22
+ var _React$useContext = React.useContext(MessageContext),
23
+ format = _React$useContext.format;
24
+ var _useWizard = useWizard(),
25
+ currentStep = _useWizard.currentStep,
26
+ currentStepObj = _useWizard.currentStepObj,
27
+ currentStepIndex = _useWizard.currentStepIndex,
28
+ totalSteps = _useWizard.totalSteps,
29
+ canGoNext = _useWizard.canGoNext,
30
+ previous = _useWizard.previous,
31
+ skip = _useWizard.skip,
32
+ cancel = _useWizard.cancel,
33
+ hasCancelHandler = _useWizard.hasCancelHandler,
34
+ messages = _useWizard.messages;
35
+ if (!currentStepObj) return null;
36
+ var isFirstStep = currentStepIndex <= 0;
37
+ var isLastStep = currentStepIndex >= totalSteps - 1;
38
+ var canGoPrevious = !isFirstStep;
39
+ var footerTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.footer;
40
+
41
+ // Only build the default buttons when `children` isn't provided; a
42
+ // custom footer replaces them entirely.
43
+ var content = children;
44
+ if (content === undefined) {
45
+ var _footerTheme$button, _footerTheme$button2, _footerTheme$button3, _footerTheme$button4, _footerTheme$button5;
46
+ var label = function label(id) {
47
+ return format({
48
+ id: "wizard." + id,
49
+ messages: messages
50
+ });
51
+ };
52
+ var NextIcon = footerTheme == null || (_footerTheme$button = footerTheme.button) == null || (_footerTheme$button = _footerTheme$button.next) == null ? void 0 : _footerTheme$button.icon;
53
+ var PreviousIcon = footerTheme == null || (_footerTheme$button2 = footerTheme.button) == null || (_footerTheme$button2 = _footerTheme$button2.previous) == null ? void 0 : _footerTheme$button2.icon;
54
+ var SkipIcon = footerTheme == null || (_footerTheme$button3 = footerTheme.button) == null || (_footerTheme$button3 = _footerTheme$button3.skip) == null ? void 0 : _footerTheme$button3.icon;
55
+ var CompleteIcon = footerTheme == null || (_footerTheme$button4 = footerTheme.button) == null || (_footerTheme$button4 = _footerTheme$button4.complete) == null ? void 0 : _footerTheme$button4.icon;
56
+ var CancelIcon = footerTheme == null || (_footerTheme$button5 = footerTheme.button) == null || (_footerTheme$button5 = _footerTheme$button5.cancel) == null ? void 0 : _footerTheme$button5.icon;
57
+ content = [hasCancelHandler && /*#__PURE__*/React.createElement(Button, {
58
+ key: "cancel",
59
+ label: label('cancel'),
60
+ icon: CancelIcon ? /*#__PURE__*/React.createElement(CancelIcon, {
61
+ "aria-hidden": "true"
62
+ }) : undefined,
63
+ onClick: cancel
64
+ }), !isFirstStep && /*#__PURE__*/React.createElement(Button, {
65
+ key: "previous",
66
+ label: label('previous'),
67
+ secondary: true,
68
+ icon: PreviousIcon ? /*#__PURE__*/React.createElement(PreviousIcon, {
69
+ "aria-hidden": "true"
70
+ }) : undefined,
71
+ disabled: !canGoPrevious,
72
+ onClick: previous
73
+ }), currentStepObj.skippable && !isLastStep && /*#__PURE__*/React.createElement(Button, {
74
+ key: "skip",
75
+ label: label('skip'),
76
+ secondary: true,
77
+ icon: SkipIcon ? /*#__PURE__*/React.createElement(SkipIcon, {
78
+ "aria-hidden": "true"
79
+ }) : undefined,
80
+ reverse: true,
81
+ onClick: skip
82
+ }), isLastStep ? /*#__PURE__*/React.createElement(Button, {
83
+ key: "complete",
84
+ label: label('complete'),
85
+ icon: CompleteIcon ? /*#__PURE__*/React.createElement(CompleteIcon, {
86
+ "aria-hidden": "true"
87
+ }) : undefined,
88
+ primary: true,
89
+ disabled: !canGoNext,
90
+ type: "submit",
91
+ form: currentStep + "-form"
92
+ }) : /*#__PURE__*/React.createElement(Button, {
93
+ key: "next",
94
+ label: label('next'),
95
+ primary: true,
96
+ icon: NextIcon ? /*#__PURE__*/React.createElement(NextIcon, {
97
+ "aria-hidden": "true"
98
+ }) : undefined,
99
+ reverse: true,
100
+ disabled: !canGoNext,
101
+ type: "submit",
102
+ form: currentStep + "-form"
103
+ })];
104
+ }
105
+ return /*#__PURE__*/React.createElement(ResponsiveContext.Consumer, null, function (size) {
106
+ var isSmall = size === 'small';
107
+ return /*#__PURE__*/React.createElement(Box, _extends({
108
+ background: footerTheme == null ? void 0 : footerTheme.background,
109
+ border: footerTheme == null ? void 0 : footerTheme.border,
110
+ pad: footerTheme == null ? void 0 : footerTheme.pad,
111
+ gap: footerTheme == null ? void 0 : footerTheme.gap,
112
+ direction: "row",
113
+ justify: footerTheme == null ? void 0 : footerTheme.justify,
114
+ align: "center",
115
+ wrap: isSmall,
116
+ flex: false
117
+ }, rest), content);
118
+ });
119
+ };
120
+ WizardFooter.displayName = 'WizardFooter';
@@ -0,0 +1,60 @@
1
+ var _excluded = ["title", "children"];
2
+ 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); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ import React from 'react';
7
+ import { Box } from '../Box';
8
+ import { Button } from '../Button';
9
+ import { Heading } from '../Heading';
10
+ import { MessageContext } from '../../contexts/MessageContext';
11
+ import { useThemeValue } from '../../utils/useThemeValue';
12
+ import { useWizard } from './WizardContext';
13
+
14
+ // Header above the progress track. Hosts the close (X) button which
15
+ // invokes `cancel` from context.
16
+ export var WizardHeader = function WizardHeader(_ref) {
17
+ var _theme$wizard, _headerTheme$title, _headerTheme$close;
18
+ var title = _ref.title,
19
+ children = _ref.children,
20
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
21
+ var _useThemeValue = useThemeValue(),
22
+ theme = _useThemeValue.theme;
23
+ var _React$useContext = React.useContext(MessageContext),
24
+ format = _React$useContext.format;
25
+ var _useWizard = useWizard(),
26
+ cancel = _useWizard.cancel,
27
+ messages = _useWizard.messages;
28
+ var headerTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.header;
29
+
30
+ // Custom children override the themed title.
31
+ var content = children !== undefined ? children : title && /*#__PURE__*/React.createElement(Heading, {
32
+ level: 1,
33
+ size: headerTheme == null || (_headerTheme$title = headerTheme.title) == null ? void 0 : _headerTheme$title.size,
34
+ margin: "none"
35
+ }, title);
36
+ var CloseIcon = headerTheme == null || (_headerTheme$close = headerTheme.close) == null ? void 0 : _headerTheme$close.icon;
37
+ var closeLabel = format({
38
+ id: 'wizard.close',
39
+ messages: messages
40
+ });
41
+ return /*#__PURE__*/React.createElement(Box, _extends({
42
+ pad: headerTheme == null ? void 0 : headerTheme.pad,
43
+ background: headerTheme == null ? void 0 : headerTheme.background,
44
+ direction: "row",
45
+ align: "center",
46
+ justify: "between",
47
+ flex: false
48
+ }, rest), /*#__PURE__*/React.createElement(Box, {
49
+ direction: "row",
50
+ align: "center",
51
+ flex: true
52
+ }, content), /*#__PURE__*/React.createElement(Button, {
53
+ "aria-label": closeLabel,
54
+ icon: CloseIcon ? /*#__PURE__*/React.createElement(CloseIcon, {
55
+ "aria-hidden": "true"
56
+ }) : undefined,
57
+ onClick: cancel
58
+ }));
59
+ };
60
+ WizardHeader.displayName = 'WizardHeader';
@@ -0,0 +1,80 @@
1
+ var _excluded = ["aria-label", "showDescription"];
2
+ 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); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React from 'react';
5
+ import { Box } from '../Box';
6
+ import { Stepper } from '../Stepper';
7
+ import { useThemeValue } from '../../utils/useThemeValue';
8
+ import { MessageContext } from '../../contexts/MessageContext';
9
+ import { useWizard } from './WizardContext';
10
+
11
+ // WizardProgress delegates step rendering to <Stepper>. Descriptions
12
+ // are hidden by default (WizardStepHeader shows them in the body).
13
+ export var WizardProgress = function WizardProgress(_ref) {
14
+ var _theme$wizard, _theme$wizard2;
15
+ var ariaLabelProp = _ref['aria-label'],
16
+ _ref$showDescription = _ref.showDescription,
17
+ showDescription = _ref$showDescription === void 0 ? false : _ref$showDescription,
18
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded);
19
+ var _useThemeValue = useThemeValue(),
20
+ theme = _useThemeValue.theme;
21
+ var _React$useContext = React.useContext(MessageContext),
22
+ format = _React$useContext.format;
23
+ var _useWizard = useWizard(),
24
+ steps = _useWizard.steps,
25
+ currentStep = _useWizard.currentStep,
26
+ showProgress = _useWizard.showProgress,
27
+ stepStates = _useWizard.stepStates,
28
+ messages = _useWizard.messages;
29
+
30
+ // Opt-in: render nothing when `showProgress` is false.
31
+ if (!showProgress) return null;
32
+ var progressTheme = showProgress === 'vertical' ? (_theme$wizard = theme.wizard) == null || (_theme$wizard = _theme$wizard.progress) == null ? void 0 : _theme$wizard.vertical : (_theme$wizard2 = theme.wizard) == null || (_theme$wizard2 = _theme$wizard2.progress) == null ? void 0 : _theme$wizard2.horizontal;
33
+
34
+ // Map wizard steps (with optional children) into Stepper's step model.
35
+ var stepperSteps = steps.map(function (step) {
36
+ var mapped = {
37
+ id: step.id,
38
+ title: step.title,
39
+ description: step.description,
40
+ status: stepStates[step.id]
41
+ };
42
+ if (step.disabledReason) mapped.disabledReason = step.disabledReason;
43
+ if (step['aria-label']) mapped['aria-label'] = step['aria-label'];
44
+ if (step.children && step.children.length) {
45
+ mapped.children = step.children.map(function (child) {
46
+ return _extends({
47
+ id: child.id,
48
+ title: child.title,
49
+ description: child.description,
50
+ status: stepStates[child.id]
51
+ }, child.disabledReason ? {
52
+ disabledReason: child.disabledReason
53
+ } : {}, child['aria-label'] ? {
54
+ 'aria-label': child['aria-label']
55
+ } : {});
56
+ });
57
+ }
58
+ return mapped;
59
+ });
60
+ var ariaLabel = ariaLabelProp || format({
61
+ id: 'wizard.progress',
62
+ messages: messages
63
+ });
64
+ return /*#__PURE__*/React.createElement(Box, _extends({
65
+ pad: progressTheme == null ? void 0 : progressTheme.pad,
66
+ width: showProgress === 'vertical' ? progressTheme == null ? void 0 : progressTheme.width : undefined,
67
+ flex: false
68
+ // Vertical rail should hug its steps, not stretch to the body height.
69
+ ,
70
+ alignSelf: showProgress === 'vertical' ? 'start' : undefined
71
+ }, rest), /*#__PURE__*/React.createElement(Stepper, {
72
+ steps: stepperSteps,
73
+ currentStep: currentStep,
74
+ direction: showProgress === 'vertical' ? 'vertical' : 'horizontal',
75
+ clickableSteps: false,
76
+ showDescription: showDescription,
77
+ "aria-label": ariaLabel
78
+ }));
79
+ };
80
+ WizardProgress.displayName = 'WizardProgress';
@@ -0,0 +1,51 @@
1
+ function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
2
+ 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); }
3
+ import React from 'react';
4
+ import { Box } from '../Box';
5
+ import { Heading } from '../Heading';
6
+ import { Paragraph } from '../Paragraph';
7
+ import { Text } from '../Text';
8
+ import { MessageContext } from '../../contexts/MessageContext';
9
+ import { useThemeValue } from '../../utils/useThemeValue';
10
+ import { useWizard } from './WizardContext';
11
+ import { StyledWizardFocusAnchor } from './StyledWizard';
12
+
13
+ // Renders the "Step X of Y" counter, title, and description. Wrapped in an
14
+ // `aria-live="polite"` focus anchor (located via `data-g-wizard-focus-anchor`)
15
+ // so Wizard can move focus here on step transitions for screen readers.
16
+ export var WizardStepHeader = function WizardStepHeader(_ref) {
17
+ var _theme$wizard, _theme$wizard2;
18
+ var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
19
+ var _useThemeValue = useThemeValue(),
20
+ theme = _useThemeValue.theme;
21
+ var _React$useContext = React.useContext(MessageContext),
22
+ format = _React$useContext.format;
23
+ var _useWizard = useWizard(),
24
+ currentStepObj = _useWizard.currentStepObj,
25
+ currentStepIndex = _useWizard.currentStepIndex,
26
+ totalSteps = _useWizard.totalSteps,
27
+ messages = _useWizard.messages;
28
+ if (!currentStepObj) return null;
29
+ var stepHeaderTheme = (_theme$wizard = theme.wizard) == null ? void 0 : _theme$wizard.stepHeader;
30
+ var counterTheme = (_theme$wizard2 = theme.wizard) == null || (_theme$wizard2 = _theme$wizard2.stepHeader) == null ? void 0 : _theme$wizard2.counter;
31
+ var counterTemplate = format({
32
+ id: 'wizard.stepHeader.counter',
33
+ values: {
34
+ step: currentStepIndex + 1,
35
+ total: totalSteps
36
+ },
37
+ messages: messages
38
+ });
39
+ return /*#__PURE__*/React.createElement(StyledWizardFocusAnchor, {
40
+ "data-g-wizard-focus-anchor": true,
41
+ tabIndex: -1,
42
+ "aria-live": "polite"
43
+ }, /*#__PURE__*/React.createElement(Box, _extends({
44
+ pad: stepHeaderTheme == null ? void 0 : stepHeaderTheme.pad,
45
+ gap: stepHeaderTheme == null ? void 0 : stepHeaderTheme.gap,
46
+ flex: false
47
+ }, rest), /*#__PURE__*/React.createElement(Text, counterTheme, counterTemplate), /*#__PURE__*/React.createElement(Heading, _extends({
48
+ level: 2
49
+ }, stepHeaderTheme == null ? void 0 : stepHeaderTheme.title), currentStepObj.title), currentStepObj.description && /*#__PURE__*/React.createElement(Paragraph, stepHeaderTheme == null ? void 0 : stepHeaderTheme.description, currentStepObj.description)));
50
+ };
51
+ WizardStepHeader.displayName = 'WizardStepHeader';
@@ -0,0 +1,171 @@
1
+ import * as React from 'react';
2
+ import { BoxExtendedProps } from '../Box';
3
+
4
+ export type WizardShowProgress = 'horizontal' | 'vertical' | false;
5
+
6
+ export type WizardStepStatus = 'pending' | 'completed' | 'error' | 'disabled';
7
+
8
+ export type WizardTrigger =
9
+ | 'next'
10
+ | 'previous'
11
+ | 'goTo'
12
+ | 'skip'
13
+ | 'complete'
14
+ | 'cancel';
15
+
16
+ export type WizardPhase =
17
+ | 'requested'
18
+ | 'validating'
19
+ | 'validated'
20
+ | 'navigated'
21
+ | 'blocked'
22
+ | 'completed'
23
+ | 'cancelled';
24
+
25
+ export interface WizardStep<TValue = Record<string, any>> {
26
+ id: string;
27
+ title: string;
28
+ description?: React.ReactNode;
29
+ render?: (
30
+ step: WizardStep<TValue>,
31
+ api: WizardContextValue<TValue>,
32
+ ) => React.ReactNode;
33
+ validate?: (
34
+ value: TValue,
35
+ ) =>
36
+ | boolean
37
+ | string
38
+ | void
39
+ | { error?: string }
40
+ | Promise<boolean | string | void | { error?: string }>;
41
+ nextStep?: (value: TValue) => string | undefined | null;
42
+ skippable?: boolean;
43
+ disabled?: boolean;
44
+ disabledReason?: string;
45
+ children?: WizardStep<TValue>[];
46
+ 'aria-label'?: string;
47
+ }
48
+
49
+ // Discriminated union for onStepChange events. Consumers can narrow on
50
+ // `trigger` + `phase` to reason about event flow without inspecting DOM.
51
+ export interface NavigationStepChangeEvent {
52
+ trigger: Exclude<WizardTrigger, 'cancel'>;
53
+ phase: Exclude<WizardPhase, 'cancelled'>;
54
+ from?: string;
55
+ to?: string;
56
+ error?: string;
57
+ }
58
+
59
+ export interface TerminalStepChangeEvent {
60
+ trigger: 'cancel' | 'complete';
61
+ phase: 'cancelled' | 'completed';
62
+ from?: string;
63
+ }
64
+
65
+ export type StepChangeEvent =
66
+ | NavigationStepChangeEvent
67
+ | TerminalStepChangeEvent;
68
+
69
+ export interface WizardMessages {
70
+ previous?: string;
71
+ next?: string;
72
+ skip?: string;
73
+ cancel?: string;
74
+ close?: string;
75
+ complete?: string;
76
+ counter?: string;
77
+ progress?: string;
78
+ validationError?: string;
79
+ }
80
+
81
+ export interface WizardProps<TValue = Record<string, any>> {
82
+ steps: WizardStep<TValue>[];
83
+ currentStep?: string;
84
+ defaultStep?: string;
85
+ showProgress?: WizardShowProgress;
86
+ onStepChange?: (event: StepChangeEvent) => void;
87
+ onComplete?: (event: { value: TValue; completedSteps: string[] }) => void;
88
+ onCancel?: (event: { value: TValue; reason: 'user' }) => void;
89
+ renderStep?: (
90
+ step: WizardStep<TValue>,
91
+ api: WizardContextValue<TValue>,
92
+ ) => React.ReactNode;
93
+ title?: string;
94
+ footer?: React.ReactNode;
95
+ scrollToTop?: boolean;
96
+ value?: TValue;
97
+ defaultValue?: TValue;
98
+ onChange?: (event: { value: TValue }) => void;
99
+ id?: string;
100
+ 'aria-label'?: string;
101
+ messages?: WizardMessages;
102
+ children?: React.ReactNode;
103
+ }
104
+
105
+ declare const Wizard: <TValue = Record<string, any>>(
106
+ props: WizardProps<TValue> & { ref?: React.Ref<HTMLDivElement> },
107
+ ) => React.ReactElement;
108
+
109
+ export { Wizard };
110
+
111
+ export interface WizardContextValue<TValue = Record<string, any>> {
112
+ steps: WizardStep<TValue>[];
113
+ currentStep: string;
114
+ currentStepIndex: number;
115
+ currentStepObj?: WizardStep<TValue>;
116
+ totalSteps: number;
117
+ stepStates: Record<string, WizardStepStatus>;
118
+ formValue: TValue;
119
+ setFormValue: (next: TValue | ((prev: TValue) => TValue)) => void;
120
+ validationError?: string;
121
+ isValidating: boolean;
122
+ isBlocked: boolean;
123
+ isCompleted: boolean;
124
+ canGoNext: boolean;
125
+ next: () => void;
126
+ previous: () => void;
127
+ goTo: (stepId: string) => void;
128
+ skip: () => void;
129
+ complete: () => void;
130
+ cancel: () => void;
131
+ showProgress: WizardShowProgress;
132
+ renderStep?: (
133
+ step: WizardStep<TValue>,
134
+ api: WizardContextValue<TValue>,
135
+ ) => React.ReactNode;
136
+ }
137
+
138
+ export const WizardContext: React.Context<WizardContextValue>;
139
+
140
+ export function useWizard<
141
+ TValue = Record<string, any>,
142
+ >(): WizardContextValue<TValue>;
143
+
144
+ export interface WizardHeaderProps extends BoxExtendedProps {
145
+ title?: string;
146
+ children?: React.ReactNode;
147
+ }
148
+
149
+ export const WizardHeader: React.FC<WizardHeaderProps>;
150
+
151
+ export interface WizardProgressProps extends BoxExtendedProps {
152
+ 'aria-label'?: string;
153
+ showDescription?: boolean;
154
+ }
155
+
156
+ export const WizardProgress: React.FC<WizardProgressProps>;
157
+
158
+ export interface WizardStepHeaderProps extends BoxExtendedProps {}
159
+
160
+ export const WizardStepHeader: React.FC<WizardStepHeaderProps>;
161
+
162
+ export interface WizardContentProps<TValue = Record<string, any>>
163
+ extends BoxExtendedProps {}
164
+
165
+ export const WizardContent: <TValue = Record<string, any>>(
166
+ props: WizardContentProps<TValue>,
167
+ ) => React.ReactElement;
168
+
169
+ export interface WizardFooterProps extends BoxExtendedProps {}
170
+
171
+ export const WizardFooter: React.FC<WizardFooterProps>;
@@ -0,0 +1,7 @@
1
+ export { Wizard } from './Wizard';
2
+ export { WizardContext, useWizard } from './WizardContext';
3
+ export { WizardHeader } from './WizardHeader';
4
+ export { WizardProgress } from './WizardProgress';
5
+ export { WizardStepHeader } from './WizardStepHeader';
6
+ export { WizardContent } from './WizardContent';
7
+ export { WizardFooter } from './WizardFooter';
@@ -0,0 +1,51 @@
1
+ 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); }
2
+ import PropTypes from 'prop-types';
3
+ var propType = {};
4
+ if (process.env.NODE_ENV !== 'production') {
5
+ var stepShape = {
6
+ id: PropTypes.string.isRequired,
7
+ title: PropTypes.string.isRequired,
8
+ description: PropTypes.node,
9
+ render: PropTypes.func,
10
+ validate: PropTypes.func,
11
+ nextStep: PropTypes.func,
12
+ skippable: PropTypes.bool,
13
+ disabled: PropTypes.bool,
14
+ disabledReason: PropTypes.string,
15
+ 'aria-label': PropTypes.string
16
+ };
17
+ var nestedStepShape = _extends({}, stepShape, {
18
+ children: PropTypes.array
19
+ });
20
+ propType = {
21
+ steps: PropTypes.arrayOf(PropTypes.shape(nestedStepShape)).isRequired,
22
+ currentStep: PropTypes.string,
23
+ defaultStep: PropTypes.string,
24
+ showProgress: PropTypes.oneOfType([PropTypes.oneOf(['horizontal', 'vertical']), PropTypes.bool]),
25
+ onStepChange: PropTypes.func,
26
+ onComplete: PropTypes.func,
27
+ onCancel: PropTypes.func,
28
+ renderStep: PropTypes.func,
29
+ title: PropTypes.string,
30
+ footer: PropTypes.node,
31
+ scrollToTop: PropTypes.bool,
32
+ value: PropTypes.object,
33
+ defaultValue: PropTypes.object,
34
+ onChange: PropTypes.func,
35
+ id: PropTypes.string,
36
+ 'aria-label': PropTypes.string,
37
+ children: PropTypes.node,
38
+ messages: PropTypes.shape({
39
+ previous: PropTypes.string,
40
+ next: PropTypes.string,
41
+ skip: PropTypes.string,
42
+ cancel: PropTypes.string,
43
+ close: PropTypes.string,
44
+ complete: PropTypes.string,
45
+ counter: PropTypes.string,
46
+ progress: PropTypes.string,
47
+ validationError: PropTypes.string
48
+ })
49
+ };
50
+ }
51
+ export var WizardPropTypes = propType;