grommet 2.55.0 → 2.56.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.
- package/components/Button/Button.js +7 -4
- package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
- package/components/FormField/FormField.js +1 -1
- package/components/Grommet/index.d.ts +21 -0
- package/components/Grommet/propTypes.js +26 -0
- package/components/Stepper/StepConnector.js +68 -0
- package/components/Stepper/Stepper.js +309 -0
- package/components/Stepper/StepperContext.js +43 -0
- package/components/Stepper/StepperDescription.js +26 -0
- package/components/Stepper/StepperHelperText.js +44 -0
- package/components/Stepper/StepperIndicator.js +74 -0
- package/components/Stepper/StepperLabel.js +41 -0
- package/components/Stepper/StepperStep.js +127 -0
- package/components/Stepper/StyledStepper.js +124 -0
- package/components/Stepper/index.d.ts +80 -0
- package/components/Stepper/index.js +18 -0
- package/components/Stepper/propTypes.js +35 -0
- package/components/Stepper/stories/DisabledSteps.stories.js +45 -0
- package/components/Stepper/stories/ErrorStates.stories.js +45 -0
- package/components/Stepper/stories/HorizontalSteps.stories.js +50 -0
- package/components/Stepper/stories/Interactive.stories.js +60 -0
- package/components/Stepper/stories/KeyboardNavigation.stories.js +64 -0
- package/components/Stepper/stories/NestedSubSteps.stories.js +70 -0
- package/components/Stepper/stories/ReadOnly.stories.js +43 -0
- package/components/Stepper/stories/ThemingLightDark.stories.js +58 -0
- package/components/Stepper/stories/VerticalSteps.stories.js +67 -0
- package/components/Tab/Tab.js +19 -6
- package/components/Tabs/Tabs.js +156 -22
- package/components/TimeInput/README.md +2 -0
- package/components/TimeInput/StyledTimeInput.js +73 -0
- package/components/TimeInput/TimeInput.js +689 -0
- package/components/TimeInput/TimeInputPopup.js +393 -0
- package/components/TimeInput/index.d.ts +41 -0
- package/components/TimeInput/index.js +6 -0
- package/components/TimeInput/propTypes.js +35 -0
- package/components/TimeInput/stories/Controlled.stories.tsx +29 -0
- package/components/TimeInput/stories/Disabled.stories.tsx +13 -0
- package/components/TimeInput/stories/Form.stories.tsx +38 -0
- package/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
- package/components/TimeInput/stories/Simple.stories.tsx +19 -0
- package/components/TimeInput/stories/Step.stories.tsx +14 -0
- package/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
- package/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
- package/components/TimeInput/useSectionedTimeField.js +359 -0
- package/components/TimeInput/utils.js +187 -0
- package/components/index.d.ts +2 -0
- package/components/index.js +12 -0
- package/es6/components/Button/Button.js +7 -4
- package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -0
- package/es6/components/FormField/FormField.js +1 -1
- package/es6/components/Grommet/index.d.ts +21 -0
- package/es6/components/Grommet/propTypes.js +26 -0
- package/es6/components/Stepper/StepConnector.js +63 -0
- package/es6/components/Stepper/Stepper.js +306 -0
- package/es6/components/Stepper/StepperContext.js +39 -0
- package/es6/components/Stepper/StepperDescription.js +21 -0
- package/es6/components/Stepper/StepperHelperText.js +39 -0
- package/es6/components/Stepper/StepperIndicator.js +69 -0
- package/es6/components/Stepper/StepperLabel.js +36 -0
- package/es6/components/Stepper/StepperStep.js +122 -0
- package/es6/components/Stepper/StyledStepper.js +120 -0
- package/es6/components/Stepper/index.d.ts +80 -0
- package/es6/components/Stepper/index.js +6 -0
- package/es6/components/Stepper/propTypes.js +30 -0
- package/es6/components/Stepper/stories/DisabledSteps.stories.js +41 -0
- package/es6/components/Stepper/stories/ErrorStates.stories.js +41 -0
- package/es6/components/Stepper/stories/HorizontalSteps.stories.js +46 -0
- package/es6/components/Stepper/stories/Interactive.stories.js +56 -0
- package/es6/components/Stepper/stories/KeyboardNavigation.stories.js +60 -0
- package/es6/components/Stepper/stories/NestedSubSteps.stories.js +66 -0
- package/es6/components/Stepper/stories/ReadOnly.stories.js +39 -0
- package/es6/components/Stepper/stories/ThemingLightDark.stories.js +54 -0
- package/es6/components/Stepper/stories/VerticalSteps.stories.js +63 -0
- package/es6/components/Tab/Tab.js +19 -6
- package/es6/components/Tabs/Tabs.js +157 -23
- package/es6/components/TimeInput/README.md +2 -0
- package/es6/components/TimeInput/StyledTimeInput.js +68 -0
- package/es6/components/TimeInput/TimeInput.js +685 -0
- package/es6/components/TimeInput/TimeInputPopup.js +389 -0
- package/es6/components/TimeInput/index.d.ts +41 -0
- package/es6/components/TimeInput/index.js +1 -0
- package/es6/components/TimeInput/propTypes.js +30 -0
- package/es6/components/TimeInput/stories/Controlled.stories.tsx +29 -0
- package/es6/components/TimeInput/stories/Disabled.stories.tsx +13 -0
- package/es6/components/TimeInput/stories/Form.stories.tsx +38 -0
- package/es6/components/TimeInput/stories/ReadOnly.stories.tsx +13 -0
- package/es6/components/TimeInput/stories/Simple.stories.tsx +19 -0
- package/es6/components/TimeInput/stories/Step.stories.tsx +14 -0
- package/es6/components/TimeInput/stories/ThemingLightDark.stories.tsx +22 -0
- package/es6/components/TimeInput/stories/Uncontrolled.stories.tsx +22 -0
- package/es6/components/TimeInput/useSectionedTimeField.js +356 -0
- package/es6/components/TimeInput/utils.js +183 -0
- package/es6/components/index.d.ts +2 -0
- package/es6/components/index.js +2 -0
- package/es6/index.d.ts +2 -0
- package/es6/languages/default.json +20 -0
- package/es6/themes/base.d.ts +108 -0
- package/es6/themes/base.js +208 -0
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/index.d.ts +2 -0
- package/languages/default.json +20 -0
- package/package.json +41 -40
- package/themes/base.d.ts +108 -0
- package/themes/base.js +208 -0
- package/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
- package/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -79
- package/es6/components/TextInput/stories/CustomThemed/CustomSuggestions.stories.tsx +0 -180
- package/es6/components/TextInput/stories/CustomThemed/Themed.stories.js +0 -74
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Add } from "grommet-icons/es6/icons/Add";
|
|
3
|
+
import { Box, Button, Grommet, Text } from 'grommet';
|
|
4
|
+
export var ChildrenPlainOption = function ChildrenPlainOption() {
|
|
5
|
+
return /*#__PURE__*/React.createElement(Box, {
|
|
6
|
+
pad: "large",
|
|
7
|
+
gap: "large"
|
|
8
|
+
}, /*#__PURE__*/React.createElement(Grommet, {
|
|
9
|
+
options: {
|
|
10
|
+
button: {
|
|
11
|
+
childrenPlain: false
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
15
|
+
align: "center",
|
|
16
|
+
gap: "small"
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
18
|
+
size: "small",
|
|
19
|
+
color: "text-weak"
|
|
20
|
+
}, "options.button.childrenPlain defaults to true. Setting it to false stops automatically forcing plain when Button has children."), /*#__PURE__*/React.createElement(Button, {
|
|
21
|
+
hoverIndicator: "light-1",
|
|
22
|
+
onClick: function onClick() {}
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
24
|
+
pad: "small",
|
|
25
|
+
direction: "row",
|
|
26
|
+
align: "center",
|
|
27
|
+
gap: "small"
|
|
28
|
+
}, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Option false"))), /*#__PURE__*/React.createElement(Button, {
|
|
29
|
+
hoverIndicator: "light-1",
|
|
30
|
+
plain: true,
|
|
31
|
+
onClick: function onClick() {}
|
|
32
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
33
|
+
pad: "small",
|
|
34
|
+
direction: "row",
|
|
35
|
+
align: "center",
|
|
36
|
+
gap: "small"
|
|
37
|
+
}, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Explicit plain"))))), /*#__PURE__*/React.createElement(Grommet, {
|
|
38
|
+
options: {
|
|
39
|
+
button: {
|
|
40
|
+
childrenPlain: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
theme: {
|
|
44
|
+
global: {
|
|
45
|
+
font: {
|
|
46
|
+
family: "-apple-system, BlinkMacSystemFont"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
button: {
|
|
50
|
+
"default": {}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
54
|
+
align: "center",
|
|
55
|
+
gap: "small"
|
|
56
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
57
|
+
size: "small",
|
|
58
|
+
color: "text-weak"
|
|
59
|
+
}, "Same behavior applies for kind buttons."), /*#__PURE__*/React.createElement(Button, {
|
|
60
|
+
hoverIndicator: "light-1",
|
|
61
|
+
onClick: function onClick() {}
|
|
62
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
63
|
+
pad: "small",
|
|
64
|
+
direction: "row",
|
|
65
|
+
align: "center",
|
|
66
|
+
gap: "small"
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Kind option false"))), /*#__PURE__*/React.createElement(Button, {
|
|
68
|
+
hoverIndicator: "light-1",
|
|
69
|
+
plain: true,
|
|
70
|
+
onClick: function onClick() {}
|
|
71
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
72
|
+
pad: "small",
|
|
73
|
+
direction: "row",
|
|
74
|
+
align: "center",
|
|
75
|
+
gap: "small"
|
|
76
|
+
}, /*#__PURE__*/React.createElement(Add, null), /*#__PURE__*/React.createElement(Text, null, "Kind explicit plain"))))));
|
|
77
|
+
};
|
|
78
|
+
ChildrenPlainOption.storyName = 'Children Plain Option';
|
|
79
|
+
export default {
|
|
80
|
+
title: 'Controls/Button/Custom Themed/Children Plain Option'
|
|
81
|
+
};
|
|
@@ -21,7 +21,7 @@ import { FormFieldPropTypes } from './propTypes';
|
|
|
21
21
|
import { useThemeValue } from '../../utils/useThemeValue';
|
|
22
22
|
import { AnnounceContext } from '../../contexts/AnnounceContext';
|
|
23
23
|
var grommetInputFocusNames = ['CheckBox', 'CheckBoxGroup', 'RadioButton', 'RadioButtonGroup', 'RangeInput', 'RangeSelector', 'StarRating', 'ThumbsRating'];
|
|
24
|
-
var grommetInputNames = ['CheckBox', 'CheckBoxGroup', 'TextInput', 'Select', 'MaskedInput', 'SelectMultiple', 'TextArea', 'DateInput', 'FileInput', 'RadioButton', 'RadioButtonGroup', 'RangeInput', 'RangeSelector', 'StarRating', 'ThumbsRating'];
|
|
24
|
+
var grommetInputNames = ['CheckBox', 'CheckBoxGroup', 'TextInput', 'Select', 'MaskedInput', 'SelectMultiple', 'TextArea', 'DateInput', 'TimeInput', 'FileInput', 'RadioButton', 'RadioButtonGroup', 'RangeInput', 'RangeSelector', 'StarRating', 'ThumbsRating'];
|
|
25
25
|
var grommetInputPadNames = ['CheckBox', 'CheckBoxGroup', 'RadioButton', 'RadioButtonGroup', 'RangeInput', 'RangeSelector'];
|
|
26
26
|
var isGrommetInput = function isGrommetInput(comp) {
|
|
27
27
|
return comp && (grommetInputNames.indexOf(comp.displayName) !== -1 || grommetInputPadNames.indexOf(comp.displayName) !== -1);
|
|
@@ -9,6 +9,7 @@ export interface GrommetProps {
|
|
|
9
9
|
dir?: 'rtl';
|
|
10
10
|
full?: boolean | 'min';
|
|
11
11
|
options?: {
|
|
12
|
+
button?: { childrenPlain?: boolean };
|
|
12
13
|
box?: {
|
|
13
14
|
cssGap?: boolean;
|
|
14
15
|
};
|
|
@@ -219,9 +220,29 @@ export interface GrommetProps {
|
|
|
219
220
|
skipLinks?: {
|
|
220
221
|
skipTo?: string;
|
|
221
222
|
};
|
|
223
|
+
stepper?: {
|
|
224
|
+
progress?: string;
|
|
225
|
+
step?: string;
|
|
226
|
+
};
|
|
222
227
|
tabs?: {
|
|
228
|
+
nextTab?: string;
|
|
229
|
+
previousTab?: string;
|
|
223
230
|
tabContents?: string;
|
|
224
231
|
};
|
|
232
|
+
timeInput?: {
|
|
233
|
+
activePeriodValue?: string;
|
|
234
|
+
activeSection?: string;
|
|
235
|
+
activeSectionValue?: string;
|
|
236
|
+
chooseTime?: string;
|
|
237
|
+
currentValue?: string;
|
|
238
|
+
inputLabel?: string;
|
|
239
|
+
invalidTime?: string;
|
|
240
|
+
openDrop?: string;
|
|
241
|
+
sectionHours?: string;
|
|
242
|
+
sectionMeridiem?: string;
|
|
243
|
+
sectionMinutes?: string;
|
|
244
|
+
sectionSeconds?: string;
|
|
245
|
+
};
|
|
225
246
|
textInput?: {
|
|
226
247
|
enterSelect?: string;
|
|
227
248
|
suggestionsCount?: string;
|
|
@@ -7,6 +7,12 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
7
7
|
dir: PropTypes.oneOf(['rtl']),
|
|
8
8
|
full: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['min'])]),
|
|
9
9
|
options: PropTypes.shape({
|
|
10
|
+
box: PropTypes.shape({
|
|
11
|
+
cssGap: PropTypes.bool
|
|
12
|
+
}),
|
|
13
|
+
button: PropTypes.shape({
|
|
14
|
+
childrenPlain: PropTypes.bool
|
|
15
|
+
}),
|
|
10
16
|
layer: PropTypes.shape({
|
|
11
17
|
singleId: PropTypes.bool
|
|
12
18
|
}),
|
|
@@ -215,7 +221,13 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
215
221
|
skipLinks: PropTypes.shape({
|
|
216
222
|
skipTo: PropTypes.string
|
|
217
223
|
}),
|
|
224
|
+
stepper: PropTypes.shape({
|
|
225
|
+
progress: PropTypes.string,
|
|
226
|
+
step: PropTypes.string
|
|
227
|
+
}),
|
|
218
228
|
tabs: PropTypes.shape({
|
|
229
|
+
nextTab: PropTypes.string,
|
|
230
|
+
previousTab: PropTypes.string,
|
|
219
231
|
tabContents: PropTypes.string
|
|
220
232
|
}),
|
|
221
233
|
tag: PropTypes.shape({
|
|
@@ -230,6 +242,20 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
230
242
|
suggestionsExist: PropTypes.string,
|
|
231
243
|
suggestionIsOpen: PropTypes.string
|
|
232
244
|
}),
|
|
245
|
+
timeInput: PropTypes.shape({
|
|
246
|
+
activePeriodValue: PropTypes.string,
|
|
247
|
+
activeSection: PropTypes.string,
|
|
248
|
+
activeSectionValue: PropTypes.string,
|
|
249
|
+
chooseTime: PropTypes.string,
|
|
250
|
+
currentValue: PropTypes.string,
|
|
251
|
+
inputLabel: PropTypes.string,
|
|
252
|
+
invalidTime: PropTypes.string,
|
|
253
|
+
openDrop: PropTypes.string,
|
|
254
|
+
sectionHours: PropTypes.string,
|
|
255
|
+
sectionMeridiem: PropTypes.string,
|
|
256
|
+
sectionMinutes: PropTypes.string,
|
|
257
|
+
sectionSeconds: PropTypes.string
|
|
258
|
+
}),
|
|
233
259
|
video: PropTypes.shape({
|
|
234
260
|
audioDescriptions: PropTypes.string,
|
|
235
261
|
captions: PropTypes.string,
|
|
@@ -0,0 +1,63 @@
|
|
|
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 React from 'react';
|
|
3
|
+
import { useThemeValue } from '../../utils/useThemeValue';
|
|
4
|
+
import { StyledConnector } from './StyledStepper';
|
|
5
|
+
export var StepConnector = function StepConnector(_ref) {
|
|
6
|
+
var _theme$stepper, _theme$global, _theme$global2, _theme$global3, _theme$global4, _theme$global5;
|
|
7
|
+
var step = _ref.step,
|
|
8
|
+
direction = _ref.direction,
|
|
9
|
+
children = _ref.children;
|
|
10
|
+
var _useThemeValue = useThemeValue(),
|
|
11
|
+
theme = _useThemeValue.theme,
|
|
12
|
+
passThemeFlag = _useThemeValue.passThemeFlag;
|
|
13
|
+
var indicatorSize = (_theme$stepper = theme.stepper) != null && (_theme$stepper = _theme$stepper.indicator) != null && _theme$stepper.size && (_theme$global = theme.global) != null && (_theme$global = _theme$global.edgeSize) != null && _theme$global[theme.stepper.indicator.size] ? theme.global.edgeSize[theme.stepper.indicator.size] : ((_theme$global2 = theme.global) == null || (_theme$global2 = _theme$global2.edgeSize) == null ? void 0 : _theme$global2.medium) || '24px';
|
|
14
|
+
var childGap = ((_theme$global3 = theme.global) == null || (_theme$global3 = _theme$global3.edgeSize) == null ? void 0 : _theme$global3.xsmall) || '8px';
|
|
15
|
+
var childPadTop = ((_theme$global4 = theme.global) == null || (_theme$global4 = _theme$global4.edgeSize) == null ? void 0 : _theme$global4.medium) || '24px';
|
|
16
|
+
var minConnectorInlineSize = ((_theme$global5 = theme.global) == null || (_theme$global5 = _theme$global5.edgeSize) == null ? void 0 : _theme$global5.small) || '12px';
|
|
17
|
+
var directionStyle = direction === 'horizontal' ? {
|
|
18
|
+
alignItems: 'center',
|
|
19
|
+
minWidth: minConnectorInlineSize
|
|
20
|
+
} : {
|
|
21
|
+
justifyContent: 'flex-start',
|
|
22
|
+
minHeight: minConnectorInlineSize
|
|
23
|
+
};
|
|
24
|
+
var renderChildren = function renderChildren() {
|
|
25
|
+
var _theme$global6;
|
|
26
|
+
if (!children) return null;
|
|
27
|
+
var childIndent = "calc(" + indicatorSize + " + " + (((_theme$global6 = theme.global) == null || (_theme$global6 = _theme$global6.edgeSize) == null ? void 0 : _theme$global6.small) || '12px') + ")";
|
|
28
|
+
return direction === 'horizontal' ? /*#__PURE__*/React.createElement("span", {
|
|
29
|
+
style: {
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: 'row',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
gap: childGap,
|
|
34
|
+
paddingTop: childPadTop,
|
|
35
|
+
maxWidth: '100%',
|
|
36
|
+
flexWrap: 'wrap',
|
|
37
|
+
justifyContent: 'center'
|
|
38
|
+
}
|
|
39
|
+
}, children) : /*#__PURE__*/React.createElement("ol", {
|
|
40
|
+
style: {
|
|
41
|
+
listStyle: 'none',
|
|
42
|
+
padding: "0 0 0 " + childIndent,
|
|
43
|
+
margin: 0
|
|
44
|
+
}
|
|
45
|
+
}, children);
|
|
46
|
+
};
|
|
47
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
48
|
+
role: "presentation",
|
|
49
|
+
"aria-hidden": children ? undefined : 'true',
|
|
50
|
+
style: _extends({
|
|
51
|
+
display: 'flex',
|
|
52
|
+
flexDirection: 'column',
|
|
53
|
+
position: 'relative',
|
|
54
|
+
flex: 1,
|
|
55
|
+
overflow: 'visible'
|
|
56
|
+
}, directionStyle)
|
|
57
|
+
}, /*#__PURE__*/React.createElement(StyledConnector, _extends({
|
|
58
|
+
direction: direction,
|
|
59
|
+
status: step.status,
|
|
60
|
+
"aria-hidden": "true",
|
|
61
|
+
isBetween: true
|
|
62
|
+
}, passThemeFlag)), renderChildren());
|
|
63
|
+
};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
var _excluded = ["steps", "currentStep", "direction", "clickableSteps", "showDescription", "onStepClick", "aria-label", "children", "id"];
|
|
2
|
+
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; }
|
|
3
|
+
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); }
|
|
4
|
+
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
import { Box } from '../Box';
|
|
6
|
+
import { MessageContext } from '../../contexts/MessageContext';
|
|
7
|
+
import { Keyboard } from '../Keyboard';
|
|
8
|
+
import { StepConnector } from './StepConnector';
|
|
9
|
+
import { StepperContext } from './StepperContext';
|
|
10
|
+
import { StepperStep } from './StepperStep';
|
|
11
|
+
import { StepperPropTypes } from './propTypes';
|
|
12
|
+
|
|
13
|
+
// Flattens steps with parent/child relationships into a linear list
|
|
14
|
+
// for keyboard navigation and index-based tracking.
|
|
15
|
+
var flattenSteps = function flattenSteps(steps) {
|
|
16
|
+
var flat = [];
|
|
17
|
+
var hasSubSubSteps = false;
|
|
18
|
+
steps.forEach(function (step, parentIdx) {
|
|
19
|
+
var hasChildren = step.children && step.children.length > 0;
|
|
20
|
+
var isLastParent = parentIdx === steps.length - 1;
|
|
21
|
+
flat.push(_extends({}, step, {
|
|
22
|
+
isSubStep: false,
|
|
23
|
+
showConnector: !isLastParent,
|
|
24
|
+
childIds: hasChildren ? step.children.map(function (c) {
|
|
25
|
+
return c.id;
|
|
26
|
+
}) : []
|
|
27
|
+
}));
|
|
28
|
+
if (hasChildren) {
|
|
29
|
+
step.children.forEach(function (child) {
|
|
30
|
+
flat.push(_extends({}, child, {
|
|
31
|
+
isSubStep: true,
|
|
32
|
+
showConnector: false,
|
|
33
|
+
parentId: step.id,
|
|
34
|
+
childIds: []
|
|
35
|
+
}));
|
|
36
|
+
if (child.children && child.children.length > 0) {
|
|
37
|
+
hasSubSubSteps = true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (process.env.NODE_ENV !== 'production' && hasSubSubSteps) {
|
|
43
|
+
console.warn('Stepper: sub-steps with their own children are not supported.');
|
|
44
|
+
}
|
|
45
|
+
return flat;
|
|
46
|
+
};
|
|
47
|
+
var Stepper = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
48
|
+
var _ref$steps = _ref.steps,
|
|
49
|
+
steps = _ref$steps === void 0 ? [] : _ref$steps,
|
|
50
|
+
currentStep = _ref.currentStep,
|
|
51
|
+
_ref$direction = _ref.direction,
|
|
52
|
+
directionProp = _ref$direction === void 0 ? 'horizontal' : _ref$direction,
|
|
53
|
+
_ref$clickableSteps = _ref.clickableSteps,
|
|
54
|
+
clickableSteps = _ref$clickableSteps === void 0 ? true : _ref$clickableSteps,
|
|
55
|
+
_ref$showDescription = _ref.showDescription,
|
|
56
|
+
showDescription = _ref$showDescription === void 0 ? true : _ref$showDescription,
|
|
57
|
+
onStepClick = _ref.onStepClick,
|
|
58
|
+
ariaLabel = _ref['aria-label'],
|
|
59
|
+
children = _ref.children,
|
|
60
|
+
id = _ref.id,
|
|
61
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
62
|
+
var _useContext = useContext(MessageContext),
|
|
63
|
+
format = _useContext.format;
|
|
64
|
+
var stepRefs = useRef(new Map());
|
|
65
|
+
var flatSteps = useMemo(function () {
|
|
66
|
+
return flattenSteps(steps);
|
|
67
|
+
}, [steps]);
|
|
68
|
+
var stepsRef = useRef(flatSteps);
|
|
69
|
+
stepsRef.current = flatSteps;
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
72
|
+
console.warn('Warning: Stepper is currently in beta. The API is subject ' + 'to change in future releases.');
|
|
73
|
+
}
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
// Force vertical if steps have children
|
|
77
|
+
// (horizontal substeps not supported)
|
|
78
|
+
var hasSubSteps = steps.some(function (step) {
|
|
79
|
+
return step.children && step.children.length > 0;
|
|
80
|
+
});
|
|
81
|
+
var direction = hasSubSteps && directionProp === 'horizontal' ? 'vertical' : directionProp;
|
|
82
|
+
|
|
83
|
+
// Warn in dev about invalid state
|
|
84
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
85
|
+
if (hasSubSteps && directionProp === 'horizontal') {
|
|
86
|
+
console.warn('Stepper: horizontal direction with sub-steps is not supported. ' + 'Falling back to vertical.');
|
|
87
|
+
}
|
|
88
|
+
if (currentStep) {
|
|
89
|
+
var currentStepObj = flatSteps.find(function (s) {
|
|
90
|
+
return s.id === currentStep;
|
|
91
|
+
});
|
|
92
|
+
if (!currentStepObj) {
|
|
93
|
+
console.warn('Stepper: currentStep "' + (currentStep + "\" does not match any ") + 'step id. Falling back to the ' + 'first non-disabled step.');
|
|
94
|
+
} else if (currentStepObj.status === 'disabled') {
|
|
95
|
+
console.warn("Stepper: currentStep \"" + currentStep + "\" matches a disabled step. " + "This is an invalid state. The step will render as disabled.");
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Determine effective current step (fallback to first non-disabled)
|
|
101
|
+
var effectiveCurrentStep = useMemo(function () {
|
|
102
|
+
var _flatSteps$;
|
|
103
|
+
var match = flatSteps.find(function (s) {
|
|
104
|
+
return s.id === currentStep;
|
|
105
|
+
});
|
|
106
|
+
if (match && match.status !== 'disabled') return currentStep;
|
|
107
|
+
var fallback = flatSteps.find(function (s) {
|
|
108
|
+
return s.status !== 'disabled';
|
|
109
|
+
});
|
|
110
|
+
return fallback ? fallback.id : ((_flatSteps$ = flatSteps[0]) == null ? void 0 : _flatSteps$.id) || '';
|
|
111
|
+
}, [currentStep, flatSteps]);
|
|
112
|
+
|
|
113
|
+
// Roving tabindex: only the focused step has tabIndex=0,
|
|
114
|
+
// all others have tabIndex=-1. A ref keeps the index synchronous
|
|
115
|
+
// for keyboard handlers that fire before React re-renders.
|
|
116
|
+
var currentIndex = flatSteps.findIndex(function (s) {
|
|
117
|
+
return s.id === effectiveCurrentStep;
|
|
118
|
+
});
|
|
119
|
+
var flatStepsLength = flatSteps.length;
|
|
120
|
+
var _useState = useState(currentIndex >= 0 ? currentIndex : 0),
|
|
121
|
+
focusedIndex = _useState[0],
|
|
122
|
+
setFocusedIndex = _useState[1];
|
|
123
|
+
var focusedIndexRef = useRef(focusedIndex);
|
|
124
|
+
var updateFocusedIndex = useCallback(function (idx) {
|
|
125
|
+
focusedIndexRef.current = idx;
|
|
126
|
+
setFocusedIndex(idx);
|
|
127
|
+
}, []);
|
|
128
|
+
var stepIndex = useCallback(function (stepId) {
|
|
129
|
+
return flatSteps.findIndex(function (s) {
|
|
130
|
+
return s.id === stepId;
|
|
131
|
+
});
|
|
132
|
+
}, [flatSteps]);
|
|
133
|
+
var isPriorStep = useCallback(function (stepId) {
|
|
134
|
+
var idx = stepIndex(stepId);
|
|
135
|
+
var curIdx = stepIndex(effectiveCurrentStep);
|
|
136
|
+
return idx < curIdx;
|
|
137
|
+
}, [stepIndex, effectiveCurrentStep]);
|
|
138
|
+
var isAfterStep = useCallback(function (stepId) {
|
|
139
|
+
var idx = stepIndex(stepId);
|
|
140
|
+
var curIdx = stepIndex(effectiveCurrentStep);
|
|
141
|
+
return idx > curIdx;
|
|
142
|
+
}, [stepIndex, effectiveCurrentStep]);
|
|
143
|
+
var isCurrentStep = useCallback(function (stepId) {
|
|
144
|
+
return stepId === effectiveCurrentStep;
|
|
145
|
+
}, [effectiveCurrentStep]);
|
|
146
|
+
var canNavigateTo = useCallback(function (stepId) {
|
|
147
|
+
var step = flatSteps.find(function (s) {
|
|
148
|
+
return s.id === stepId;
|
|
149
|
+
});
|
|
150
|
+
return clickableSteps && step && step.status !== 'disabled';
|
|
151
|
+
}, [flatSteps, clickableSteps]);
|
|
152
|
+
var contextValue = useMemo(function () {
|
|
153
|
+
return {
|
|
154
|
+
currentStep: effectiveCurrentStep,
|
|
155
|
+
steps: flatSteps,
|
|
156
|
+
direction: direction,
|
|
157
|
+
clickableSteps: clickableSteps,
|
|
158
|
+
onStepClick: onStepClick,
|
|
159
|
+
showDescription: showDescription,
|
|
160
|
+
stepIndex: stepIndex,
|
|
161
|
+
isPriorStep: isPriorStep,
|
|
162
|
+
isAfterStep: isAfterStep,
|
|
163
|
+
isCurrentStep: isCurrentStep,
|
|
164
|
+
canNavigateTo: canNavigateTo
|
|
165
|
+
};
|
|
166
|
+
}, [effectiveCurrentStep, flatSteps, direction, clickableSteps, onStepClick, showDescription, stepIndex, isPriorStep, isAfterStep, isCurrentStep, canNavigateTo]);
|
|
167
|
+
|
|
168
|
+
// Wraps around the step list to find the next step
|
|
169
|
+
// in the given direction (+1 forward, -1 backward).
|
|
170
|
+
var findNextEnabledIndex = useCallback(function (startIndex, delta) {
|
|
171
|
+
return (startIndex + delta + flatStepsLength) % flatStepsLength;
|
|
172
|
+
}, [flatStepsLength]);
|
|
173
|
+
var findFirstEnabledIndex = useCallback(function () {
|
|
174
|
+
return 0;
|
|
175
|
+
}, []);
|
|
176
|
+
var findLastEnabledIndex = useCallback(function () {
|
|
177
|
+
return flatStepsLength - 1;
|
|
178
|
+
}, [flatStepsLength]);
|
|
179
|
+
var moveFocus = useCallback(function (nextIndex) {
|
|
180
|
+
if (nextIndex !== undefined && nextIndex !== focusedIndexRef.current) {
|
|
181
|
+
updateFocusedIndex(nextIndex);
|
|
182
|
+
var nextButton = stepRefs.current.get(nextIndex);
|
|
183
|
+
if (nextButton) {
|
|
184
|
+
nextButton.focus();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}, [updateFocusedIndex]);
|
|
188
|
+
var onNext = useCallback(function () {
|
|
189
|
+
moveFocus(findNextEnabledIndex(focusedIndexRef.current, 1));
|
|
190
|
+
}, [findNextEnabledIndex, moveFocus]);
|
|
191
|
+
var onPrevious = useCallback(function () {
|
|
192
|
+
moveFocus(findNextEnabledIndex(focusedIndexRef.current, -1));
|
|
193
|
+
}, [findNextEnabledIndex, moveFocus]);
|
|
194
|
+
var handleKeyDown = useCallback(function (event) {
|
|
195
|
+
var isHorizontal = direction === 'horizontal';
|
|
196
|
+
switch (event.key) {
|
|
197
|
+
case 'ArrowRight':
|
|
198
|
+
if (isHorizontal) {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
onNext();
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
case 'ArrowLeft':
|
|
204
|
+
if (isHorizontal) {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
onPrevious();
|
|
207
|
+
}
|
|
208
|
+
break;
|
|
209
|
+
case 'ArrowDown':
|
|
210
|
+
if (!isHorizontal) {
|
|
211
|
+
event.preventDefault();
|
|
212
|
+
onNext();
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case 'ArrowUp':
|
|
216
|
+
if (!isHorizontal) {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
onPrevious();
|
|
219
|
+
}
|
|
220
|
+
break;
|
|
221
|
+
case 'Home':
|
|
222
|
+
event.preventDefault();
|
|
223
|
+
moveFocus(findFirstEnabledIndex());
|
|
224
|
+
break;
|
|
225
|
+
case 'End':
|
|
226
|
+
event.preventDefault();
|
|
227
|
+
moveFocus(findLastEnabledIndex());
|
|
228
|
+
break;
|
|
229
|
+
default:
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}, [direction, onNext, onPrevious, findFirstEnabledIndex, findLastEnabledIndex, moveFocus]);
|
|
233
|
+
var renderDefaultSteps = function renderDefaultSteps() {
|
|
234
|
+
var flatIndex = 0;
|
|
235
|
+
var elements = [];
|
|
236
|
+
steps.forEach(function (step, parentIdx) {
|
|
237
|
+
var parentFlatIndex = flatIndex;
|
|
238
|
+
flatIndex += 1;
|
|
239
|
+
var childElements = step.children ? step.children.map(function (child) {
|
|
240
|
+
var childFlatIndex = flatIndex;
|
|
241
|
+
flatIndex += 1;
|
|
242
|
+
return /*#__PURE__*/React.createElement(StepperStep, {
|
|
243
|
+
key: child.id,
|
|
244
|
+
step: child,
|
|
245
|
+
stepNumber: childFlatIndex + 1,
|
|
246
|
+
isLast: false,
|
|
247
|
+
showConnector: false,
|
|
248
|
+
direction: direction,
|
|
249
|
+
focusedIndex: focusedIndex,
|
|
250
|
+
index: childFlatIndex,
|
|
251
|
+
isSubStep: true,
|
|
252
|
+
onFocusStep: updateFocusedIndex,
|
|
253
|
+
stepsRef: stepsRef,
|
|
254
|
+
stepRefs: stepRefs
|
|
255
|
+
});
|
|
256
|
+
}) : null;
|
|
257
|
+
var isLastParent = parentIdx === steps.length - 1;
|
|
258
|
+
elements.push(/*#__PURE__*/React.createElement(StepperStep, {
|
|
259
|
+
key: step.id,
|
|
260
|
+
step: step,
|
|
261
|
+
stepNumber: parentFlatIndex + 1,
|
|
262
|
+
isLast: isLastParent,
|
|
263
|
+
showConnector: direction === 'horizontal' ? false : !isLastParent || !!childElements,
|
|
264
|
+
direction: direction,
|
|
265
|
+
focusedIndex: focusedIndex,
|
|
266
|
+
index: parentFlatIndex,
|
|
267
|
+
isSubStep: false,
|
|
268
|
+
onFocusStep: updateFocusedIndex,
|
|
269
|
+
stepsRef: stepsRef,
|
|
270
|
+
stepRefs: stepRefs
|
|
271
|
+
}));
|
|
272
|
+
if (!isLastParent || childElements && direction === 'vertical') {
|
|
273
|
+
elements.push(/*#__PURE__*/React.createElement(StepConnector, {
|
|
274
|
+
key: step.id + "-connector",
|
|
275
|
+
step: step,
|
|
276
|
+
direction: direction
|
|
277
|
+
}, childElements));
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return elements;
|
|
281
|
+
};
|
|
282
|
+
var stepperContent = /*#__PURE__*/React.createElement(Box, _extends({
|
|
283
|
+
ref: ref,
|
|
284
|
+
as: "ol",
|
|
285
|
+
"aria-label": ariaLabel || format({
|
|
286
|
+
id: 'stepper.progress'
|
|
287
|
+
}),
|
|
288
|
+
direction: direction === 'horizontal' ? 'row' : 'column',
|
|
289
|
+
fill: direction,
|
|
290
|
+
id: id,
|
|
291
|
+
overflow: "hidden",
|
|
292
|
+
pad: "none",
|
|
293
|
+
margin: "none",
|
|
294
|
+
style: {
|
|
295
|
+
listStyle: 'none'
|
|
296
|
+
}
|
|
297
|
+
}, rest), children || renderDefaultSteps());
|
|
298
|
+
return /*#__PURE__*/React.createElement(StepperContext.Provider, {
|
|
299
|
+
value: contextValue
|
|
300
|
+
}, clickableSteps ? /*#__PURE__*/React.createElement(Keyboard, {
|
|
301
|
+
onKeyDown: handleKeyDown
|
|
302
|
+
}, stepperContent) : stepperContent);
|
|
303
|
+
});
|
|
304
|
+
Stepper.displayName = 'Stepper';
|
|
305
|
+
Stepper.propTypes = StepperPropTypes;
|
|
306
|
+
export { Stepper };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export var StepperContext = /*#__PURE__*/createContext({
|
|
3
|
+
currentStep: '',
|
|
4
|
+
steps: [],
|
|
5
|
+
direction: 'horizontal',
|
|
6
|
+
clickableSteps: true,
|
|
7
|
+
onStepClick: undefined,
|
|
8
|
+
showDescription: true,
|
|
9
|
+
stepIndex: function stepIndex() {
|
|
10
|
+
return -1;
|
|
11
|
+
},
|
|
12
|
+
isPriorStep: function isPriorStep() {
|
|
13
|
+
return false;
|
|
14
|
+
},
|
|
15
|
+
isAfterStep: function isAfterStep() {
|
|
16
|
+
return false;
|
|
17
|
+
},
|
|
18
|
+
isCurrentStep: function isCurrentStep() {
|
|
19
|
+
return false;
|
|
20
|
+
},
|
|
21
|
+
canNavigateTo: function canNavigateTo() {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Step-level context: provides the current step's data to subcomponents
|
|
27
|
+
export var StepItemContext = /*#__PURE__*/createContext({
|
|
28
|
+
step: null,
|
|
29
|
+
index: 0,
|
|
30
|
+
isLast: false,
|
|
31
|
+
isLabelRevealed: false,
|
|
32
|
+
isSubStep: false
|
|
33
|
+
});
|
|
34
|
+
export var useStepper = function useStepper() {
|
|
35
|
+
return useContext(StepperContext);
|
|
36
|
+
};
|
|
37
|
+
export var useStepItem = function useStepItem() {
|
|
38
|
+
return useContext(StepItemContext);
|
|
39
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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 { Text } from '../Text';
|
|
5
|
+
import { useStepper, useStepItem } from './StepperContext';
|
|
6
|
+
import { useThemeValue } from '../../utils/useThemeValue';
|
|
7
|
+
export var StepperDescription = function StepperDescription(_ref) {
|
|
8
|
+
var _theme$stepper;
|
|
9
|
+
var rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
10
|
+
var _useStepper = useStepper(),
|
|
11
|
+
direction = _useStepper.direction;
|
|
12
|
+
var _useThemeValue = useThemeValue(),
|
|
13
|
+
theme = _useThemeValue.theme;
|
|
14
|
+
var _useStepItem = useStepItem(),
|
|
15
|
+
step = _useStepItem.step;
|
|
16
|
+
if (!step || !step.description) return null;
|
|
17
|
+
var descriptionProps = (_theme$stepper = theme.stepper) == null ? void 0 : _theme$stepper.description;
|
|
18
|
+
return /*#__PURE__*/React.createElement(Text, _extends({}, descriptionProps, {
|
|
19
|
+
truncate: direction === 'horizontal'
|
|
20
|
+
}, rest), step.description);
|
|
21
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var _excluded = ["variant"];
|
|
2
|
+
function _objectDestructuringEmpty(t) { if (null == t) throw new TypeError("Cannot destructure " + t); }
|
|
3
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { Text } from '../Text';
|
|
7
|
+
import { useStepItem } from './StepperContext';
|
|
8
|
+
import { useThemeValue } from '../../utils/useThemeValue';
|
|
9
|
+
var StepperHelperText = function StepperHelperText(_ref) {
|
|
10
|
+
var _theme$stepper, _theme$stepper2;
|
|
11
|
+
var variant = _ref.variant,
|
|
12
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
13
|
+
var _useThemeValue = useThemeValue(),
|
|
14
|
+
theme = _useThemeValue.theme;
|
|
15
|
+
var helperTextProps = (_theme$stepper = theme.stepper) == null ? void 0 : _theme$stepper.helperText;
|
|
16
|
+
var variantProps = variant ? ((_theme$stepper2 = theme.stepper) == null || (_theme$stepper2 = _theme$stepper2[variant]) == null ? void 0 : _theme$stepper2.helperText) || {} : {};
|
|
17
|
+
return /*#__PURE__*/React.createElement(Text, _extends({}, helperTextProps, variantProps, rest));
|
|
18
|
+
};
|
|
19
|
+
export var StepperError = function StepperError(_ref2) {
|
|
20
|
+
var rest = _extends({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
21
|
+
var _useStepItem = useStepItem(),
|
|
22
|
+
step = _useStepItem.step;
|
|
23
|
+
if (!step || step.status !== 'error' || !step.errorMessage) return null;
|
|
24
|
+
return /*#__PURE__*/React.createElement(StepperHelperText, _extends({
|
|
25
|
+
id: "stepper-error-" + step.id,
|
|
26
|
+
role: "alert",
|
|
27
|
+
variant: "error"
|
|
28
|
+
}, rest), step.errorMessage);
|
|
29
|
+
};
|
|
30
|
+
export var StepperDisabledReason = function StepperDisabledReason(_ref3) {
|
|
31
|
+
var rest = _extends({}, (_objectDestructuringEmpty(_ref3), _ref3));
|
|
32
|
+
var _useStepItem2 = useStepItem(),
|
|
33
|
+
step = _useStepItem2.step;
|
|
34
|
+
if (!step || step.status !== 'disabled' || !step.disabledReason) return null;
|
|
35
|
+
return /*#__PURE__*/React.createElement(StepperHelperText, _extends({
|
|
36
|
+
id: "stepper-reason-" + step.id,
|
|
37
|
+
variant: "disabled"
|
|
38
|
+
}, rest), step.disabledReason);
|
|
39
|
+
};
|