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.
- package/COPYRIGHT.md +3 -1
- package/components/Calendar/Calendar.js +2 -1
- package/components/Cards/Cards.js +1 -2
- package/components/DateTimeInput/DateTimeInput.js +1093 -0
- package/components/DateTimeInput/README.md +2 -0
- package/components/DateTimeInput/StyledDateTimeInput.js +74 -0
- package/components/DateTimeInput/index.d.ts +47 -0
- package/components/DateTimeInput/index.js +6 -0
- package/components/DateTimeInput/propTypes.js +42 -0
- package/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
- package/components/DateTimeInput/stories/Form.stories.tsx +44 -0
- package/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
- package/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
- package/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
- package/components/Form/Form.js +7 -4
- package/components/Form/index.d.ts +3 -0
- package/components/Form/stories/AggregateValidation.stories.js +6 -8
- package/components/FormField/FormField.js +164 -91
- package/components/Stepper/StepConnector.js +19 -49
- package/components/Stepper/Stepper.js +5 -11
- package/components/Stepper/StepperStep.js +14 -4
- package/components/Stepper/StyledStepper.js +59 -21
- package/components/TimeInput/TimeInput.js +50 -47
- package/components/TimeInput/TimeInputPopup.js +172 -76
- package/components/TimeInput/index.d.ts +3 -0
- package/components/TimeInput/propTypes.js +4 -0
- package/components/TimeInput/useSectionedTimeField.js +33 -34
- package/components/TimeInput/utils.js +31 -26
- package/components/Wizard/StyledWizard.js +16 -0
- package/components/Wizard/Wizard.js +770 -0
- package/components/Wizard/WizardContent.js +90 -0
- package/components/Wizard/WizardContext.js +35 -0
- package/components/Wizard/WizardFooter.js +123 -0
- package/components/Wizard/WizardHeader.js +63 -0
- package/components/Wizard/WizardProgress.js +84 -0
- package/components/Wizard/WizardStepHeader.js +55 -0
- package/components/Wizard/index.d.ts +171 -0
- package/components/Wizard/index.js +19 -0
- package/components/Wizard/propTypes.js +56 -0
- package/components/Wizard/stories/BasicLinear.stories.js +71 -0
- package/components/Wizard/stories/Branching.stories.js +96 -0
- package/components/Wizard/stories/Composable.stories.js +75 -0
- package/components/Wizard/stories/Controlled.stories.js +136 -0
- package/components/Wizard/stories/LongContent.stories.js +118 -0
- package/components/Wizard/stories/Modal.stories.js +143 -0
- package/components/Wizard/stories/NestedSubSteps.stories.js +79 -0
- package/components/Wizard/stories/Validation.stories.js +123 -0
- package/components/index.d.ts +4 -0
- package/components/index.js +12 -0
- package/es6/components/Calendar/Calendar.js +2 -0
- package/es6/components/Cards/Cards.js +1 -2
- package/es6/components/DateTimeInput/DateTimeInput.js +1090 -0
- package/es6/components/DateTimeInput/README.md +2 -0
- package/es6/components/DateTimeInput/StyledDateTimeInput.js +68 -0
- package/es6/components/DateTimeInput/index.d.ts +47 -0
- package/es6/components/DateTimeInput/index.js +3 -0
- package/es6/components/DateTimeInput/propTypes.js +36 -0
- package/es6/components/DateTimeInput/stories/CustomThemed/Custom.stories.tsx +53 -0
- package/es6/components/DateTimeInput/stories/Form.stories.tsx +44 -0
- package/es6/components/DateTimeInput/stories/Inline.stories.tsx +45 -0
- package/es6/components/DateTimeInput/stories/Locale.stories.tsx +59 -0
- package/es6/components/DateTimeInput/stories/Simple.stories.tsx +23 -0
- package/es6/components/Form/Form.js +7 -3
- package/es6/components/Form/index.d.ts +3 -0
- package/es6/components/Form/stories/AggregateValidation.stories.js +6 -9
- package/es6/components/FormField/FormField.js +165 -91
- package/es6/components/Stepper/StepConnector.js +18 -48
- package/es6/components/Stepper/Stepper.js +5 -10
- package/es6/components/Stepper/StepperStep.js +15 -4
- package/es6/components/Stepper/StyledStepper.js +57 -21
- package/es6/components/TimeInput/TimeInput.js +50 -46
- package/es6/components/TimeInput/TimeInputPopup.js +172 -76
- package/es6/components/TimeInput/index.d.ts +3 -0
- package/es6/components/TimeInput/propTypes.js +3 -0
- package/es6/components/TimeInput/useSectionedTimeField.js +34 -35
- package/es6/components/TimeInput/utils.js +25 -21
- package/es6/components/Wizard/StyledWizard.js +11 -0
- package/es6/components/Wizard/Wizard.js +768 -0
- package/es6/components/Wizard/WizardContent.js +87 -0
- package/es6/components/Wizard/WizardContext.js +31 -0
- package/es6/components/Wizard/WizardFooter.js +120 -0
- package/es6/components/Wizard/WizardHeader.js +60 -0
- package/es6/components/Wizard/WizardProgress.js +80 -0
- package/es6/components/Wizard/WizardStepHeader.js +51 -0
- package/es6/components/Wizard/index.d.ts +171 -0
- package/es6/components/Wizard/index.js +7 -0
- package/es6/components/Wizard/propTypes.js +51 -0
- package/es6/components/Wizard/stories/BasicLinear.stories.js +67 -0
- package/es6/components/Wizard/stories/Branching.stories.js +93 -0
- package/es6/components/Wizard/stories/Composable.stories.js +72 -0
- package/es6/components/Wizard/stories/Controlled.stories.js +133 -0
- package/es6/components/Wizard/stories/LongContent.stories.js +115 -0
- package/es6/components/Wizard/stories/Modal.stories.js +141 -0
- package/es6/components/Wizard/stories/NestedSubSteps.stories.js +76 -0
- package/es6/components/Wizard/stories/Validation.stories.js +118 -0
- package/es6/components/index.d.ts +4 -0
- package/es6/components/index.js +4 -0
- package/es6/index.d.ts +4 -0
- package/es6/languages/default.json +28 -0
- package/es6/themes/base.d.ts +115 -0
- package/es6/themes/base.js +158 -0
- package/es6/utils/DOM.js +11 -2
- package/es6/utils/dates.js +10 -0
- package/es6/utils/sectionHelpers.js +57 -0
- package/es6/utils/useSectionedField.js +45 -0
- package/grommet.min.js +2 -1
- package/grommet.min.js.LICENSE.txt +1 -0
- package/grommet.min.js.map +1 -1
- package/index.d.ts +4 -0
- package/languages/default.json +28 -0
- package/package.json +35 -31
- package/themes/base.d.ts +115 -0
- package/themes/base.js +158 -1
- package/tools/license-header.js +2 -0
- package/utils/DOM.js +11 -2
- package/utils/dates.js +11 -1
- package/utils/sectionHelpers.js +61 -0
- package/utils/useSectionedField.js +50 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
1
3
|
import styled, { css } from 'styled-components';
|
|
4
|
+
import isPropValid from '@emotion/is-prop-valid';
|
|
2
5
|
import { focusStyle, normalizeColor, styledComponentsConfig } from '../../utils';
|
|
3
6
|
var getMetricSize = function getMetricSize(theme, size) {
|
|
4
7
|
var _theme$global, _theme$global2;
|
|
@@ -22,39 +25,54 @@ var getConnectorColor = function getConnectorColor(stepStatus, theme) {
|
|
|
22
25
|
var _theme$stepper;
|
|
23
26
|
return normalizeColor(((_theme$stepper = theme.stepper) == null || (_theme$stepper = _theme$stepper[stepStatus]) == null || (_theme$stepper = _theme$stepper.connector) == null ? void 0 : _theme$stepper.color) || 'border', theme);
|
|
24
27
|
};
|
|
25
|
-
var StyledStepItem = styled.li.withConfig(
|
|
28
|
+
var StyledStepItem = styled.li.withConfig({
|
|
29
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
30
|
+
return isPropValid(prop) && prop !== 'direction';
|
|
31
|
+
}
|
|
32
|
+
}).withConfig({
|
|
26
33
|
displayName: "StyledStepper__StyledStepItem",
|
|
27
34
|
componentId: "sc-gmpe0p-0"
|
|
28
35
|
})(["display:flex;position:relative;", ""], function (props) {
|
|
29
36
|
if (props.direction === 'vertical') {
|
|
30
|
-
var
|
|
31
|
-
|
|
37
|
+
var paddingBottom = '0px';
|
|
38
|
+
if (!props.isSubStep && !props.isLast && !props.hasSubSteps) {
|
|
39
|
+
paddingBottom = "" + props.theme.global.edgeSize.medium;
|
|
40
|
+
}
|
|
41
|
+
return css(["flex-direction:column;align-items:flex-start;padding-bottom:", ";"], paddingBottom);
|
|
32
42
|
}
|
|
33
43
|
if (props.isSubStep) {
|
|
34
44
|
// horizontal and sub-steps isn't supported
|
|
35
45
|
return css(["flex-direction:row;align-items:center;flex:none;min-width:0;overflow:hidden;"]);
|
|
36
46
|
}
|
|
37
|
-
return css(["flex-direction:column;align-items:center;flex:1;min-width:0;overflow:
|
|
47
|
+
return css(["flex-direction:column;align-items:center;flex:1;min-width:0;overflow:visible;"]);
|
|
38
48
|
});
|
|
39
|
-
var StyledStepButton = styled.button.withConfig(
|
|
49
|
+
var StyledStepButton = styled.button.withConfig({
|
|
50
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
51
|
+
return isPropValid(prop) && prop !== 'direction';
|
|
52
|
+
}
|
|
53
|
+
}).withConfig({
|
|
40
54
|
displayName: "StyledStepper__StyledStepButton",
|
|
41
55
|
componentId: "sc-gmpe0p-1"
|
|
42
56
|
})(["display:flex;background:none;border:none;padding:", ";cursor:", ";outline:none;", ""], function (props) {
|
|
43
|
-
var _props$theme$
|
|
44
|
-
return (
|
|
57
|
+
var _props$theme$global, _props$theme$stepper;
|
|
58
|
+
return (_props$theme$global = props.theme.global) == null || (_props$theme$global = _props$theme$global.edgeSize) == null ? void 0 : _props$theme$global[((_props$theme$stepper = props.theme.stepper) == null || (_props$theme$stepper = _props$theme$stepper.button) == null ? void 0 : _props$theme$stepper.pad) || 'xxsmall'];
|
|
45
59
|
}, function (props) {
|
|
46
60
|
return props.isClickable ? 'pointer' : 'default';
|
|
47
61
|
}, function (props) {
|
|
48
|
-
var _props$theme$global3, _props$theme$
|
|
49
|
-
return props.direction === 'vertical' ? css(["flex-direction:row;align-items:flex-start;gap:", ";text-align:left;"], (_props$theme$
|
|
62
|
+
var _props$theme$global2, _props$theme$stepper2, _props$theme$global3, _props$theme$stepper3;
|
|
63
|
+
return props.direction === 'vertical' ? css(["flex-direction:row;align-items:flex-start;gap:", ";text-align:left;"], (_props$theme$global2 = props.theme.global) == null || (_props$theme$global2 = _props$theme$global2.edgeSize) == null ? void 0 : _props$theme$global2[((_props$theme$stepper2 = props.theme.stepper) == null || (_props$theme$stepper2 = _props$theme$stepper2.vertical) == null || (_props$theme$stepper2 = _props$theme$stepper2.button) == null ? void 0 : _props$theme$stepper2.gap) || 'small']) : css(["flex-direction:column;align-items:center;gap:", ";text-align:center;width:100%;"], (_props$theme$global3 = props.theme.global) == null || (_props$theme$global3 = _props$theme$global3.edgeSize) == null ? void 0 : _props$theme$global3[((_props$theme$stepper3 = props.theme.stepper) == null || (_props$theme$stepper3 = _props$theme$stepper3.horizontal) == null || (_props$theme$stepper3 = _props$theme$stepper3.button) == null ? void 0 : _props$theme$stepper3.gap) || 'xxsmall']);
|
|
50
64
|
});
|
|
51
|
-
var StyledStepContent = styled.span.withConfig(
|
|
65
|
+
var StyledStepContent = styled.span.withConfig({
|
|
66
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
67
|
+
return isPropValid(prop) && prop !== 'direction';
|
|
68
|
+
}
|
|
69
|
+
}).withConfig({
|
|
52
70
|
displayName: "StyledStepper__StyledStepContent",
|
|
53
71
|
componentId: "sc-gmpe0p-2"
|
|
54
72
|
})(["display:flex;flex-direction:column;", ""], function (props) {
|
|
55
73
|
if (props.direction === 'vertical' && !props.isSubStep && !props.hasDescription) {
|
|
56
|
-
var _props$theme$
|
|
57
|
-
var indicatorSizeToken = ((_props$theme$
|
|
74
|
+
var _props$theme$stepper4;
|
|
75
|
+
var indicatorSizeToken = ((_props$theme$stepper4 = props.theme.stepper) == null || (_props$theme$stepper4 = _props$theme$stepper4.indicator) == null ? void 0 : _props$theme$stepper4.size) || 'medium';
|
|
58
76
|
var indicatorSize = getMetricSize(props.theme, indicatorSizeToken);
|
|
59
77
|
var lineHeight = getTextMetric(props.theme, 'small', 'height');
|
|
60
78
|
return css(["padding-top:calc((", " - ", ") / 2);"], indicatorSize, lineHeight);
|
|
@@ -65,12 +83,12 @@ var StyledIndicator = styled.span.withConfig(styledComponentsConfig).withConfig(
|
|
|
65
83
|
displayName: "StyledStepper__StyledIndicator",
|
|
66
84
|
componentId: "sc-gmpe0p-3"
|
|
67
85
|
})(["display:flex;align-items:center;justify-content:center;border-radius:50%;transition:transform 0.1s ease,background-color 0.15s ease,border-color 0.15s ease,color 0.15s ease;", " ", " ", ":focus-visible &{", "}", ""], function (props) {
|
|
68
|
-
return function (_props$theme$
|
|
69
|
-
var indicatorSizeToken = ((_props$theme$
|
|
86
|
+
return function (_props$theme$stepper5, _props$theme$stepper6, _props$theme$global4) {
|
|
87
|
+
var indicatorSizeToken = ((_props$theme$stepper5 = props.theme.stepper) == null || (_props$theme$stepper5 = _props$theme$stepper5.indicator) == null ? void 0 : _props$theme$stepper5.size) || 'medium';
|
|
70
88
|
var parentSize = getMetricSize(props.theme, indicatorSizeToken);
|
|
71
89
|
var subStepSize = getMetricSize(props.theme, getSubStepSizeToken(indicatorSizeToken));
|
|
72
90
|
var size = props.isSubStep ? subStepSize : parentSize;
|
|
73
|
-
var borderWidth = ((_props$theme$
|
|
91
|
+
var borderWidth = ((_props$theme$stepper6 = props.theme.stepper) == null || (_props$theme$stepper6 = _props$theme$stepper6.indicator) == null || (_props$theme$stepper6 = _props$theme$stepper6.border) == null ? void 0 : _props$theme$stepper6.width) || ((_props$theme$global4 = props.theme.global) == null || (_props$theme$global4 = _props$theme$global4.borderSize) == null ? void 0 : _props$theme$global4.small) || '2px';
|
|
74
92
|
return css(["width:", ";height:", ";min-width:", ";min-height:", ";border:", " solid;"], size, size, size, size, borderWidth);
|
|
75
93
|
}();
|
|
76
94
|
}, function (props) {
|
|
@@ -104,17 +122,35 @@ var StyledConnector = styled.span.withConfig(styledComponentsConfig).withConfig(
|
|
|
104
122
|
displayName: "StyledStepper__StyledConnector",
|
|
105
123
|
componentId: "sc-gmpe0p-4"
|
|
106
124
|
})(["", " position:absolute;background:", ";"], function (props) {
|
|
107
|
-
var _theme$stepper6, _theme$stepper7,
|
|
125
|
+
var _theme$stepper6, _theme$stepper7, _props$theme$global5, _props$theme$stepper7, _theme$stepper8, _theme$global3, _theme$global4, _props$theme$stepper8;
|
|
108
126
|
var theme = props.theme;
|
|
109
127
|
var indicatorSizeToken = ((_theme$stepper6 = theme.stepper) == null || (_theme$stepper6 = _theme$stepper6.indicator) == null ? void 0 : _theme$stepper6.size) || 'medium';
|
|
110
128
|
var parentSize = getMetricSize(theme, indicatorSizeToken);
|
|
111
129
|
var indicatorBorderWidth = getMetricSize(theme, ((_theme$stepper7 = theme.stepper) == null || (_theme$stepper7 = _theme$stepper7.indicator) == null || (_theme$stepper7 = _theme$stepper7.border) == null ? void 0 : _theme$stepper7.width) || '2px');
|
|
112
|
-
var buttonPad = (
|
|
113
|
-
var connectorThickness = ((_theme$stepper8 = theme.stepper) == null || (_theme$stepper8 = _theme$stepper8.connector) == null || (_theme$stepper8 = _theme$stepper8.stroke) == null ? void 0 : _theme$stepper8.width) || ((_theme$
|
|
114
|
-
var connectorRadius = ((_theme$
|
|
130
|
+
var buttonPad = (_props$theme$global5 = props.theme.global) == null || (_props$theme$global5 = _props$theme$global5.edgeSize) == null ? void 0 : _props$theme$global5[((_props$theme$stepper7 = props.theme.stepper) == null || (_props$theme$stepper7 = _props$theme$stepper7.button) == null ? void 0 : _props$theme$stepper7.pad) || 'xxsmall'];
|
|
131
|
+
var connectorThickness = ((_theme$stepper8 = theme.stepper) == null || (_theme$stepper8 = _theme$stepper8.connector) == null || (_theme$stepper8 = _theme$stepper8.stroke) == null ? void 0 : _theme$stepper8.width) || ((_theme$global3 = theme.global) == null || (_theme$global3 = _theme$global3.borderSize) == null ? void 0 : _theme$global3.small) || '2px';
|
|
132
|
+
var connectorRadius = ((_theme$global4 = theme.global) == null || (_theme$global4 = _theme$global4.edgeSize) == null ? void 0 : _theme$global4.xsmall) || '4px';
|
|
115
133
|
var connectorOffset = "calc(" + parentSize + " / 2 + " + buttonPad + ")";
|
|
116
|
-
|
|
134
|
+
var connectorGap = '4px';
|
|
135
|
+
var nonBetweenTop = "calc(" + parentSize + " + " + buttonPad + " +\n (" + indicatorBorderWidth + " * 2) + " + connectorGap + ")";
|
|
136
|
+
return css(["border-radius:", ";", ""], connectorRadius, props.direction === 'horizontal' ? css(["top:", ";left:calc(", "50% + ", ");right:calc(-50% + ", ");height:", ";margin-inline:", ";"], connectorOffset, props.isBetween ? '-' : '', connectorOffset, connectorOffset, connectorThickness, props.theme.global.edgeSize[((_props$theme$stepper8 = props.theme.stepper) == null || (_props$theme$stepper8 = _props$theme$stepper8.horizontal) == null || (_props$theme$stepper8 = _props$theme$stepper8.connector) == null ? void 0 : _props$theme$stepper8.margin) || 'xxsmall']) : css(["left:calc( ", " + ", " - ", " / 2 );top:", ";bottom:0;", " width:", ";margin-block:0;"], connectorOffset, indicatorBorderWidth, connectorThickness, props.isBetween ? 0 : nonBetweenTop, !props.isBetween && css(["min-height:12px;"]), connectorThickness));
|
|
117
137
|
}, function (props) {
|
|
118
138
|
return getConnectorColor(props.status, props.theme);
|
|
119
139
|
});
|
|
120
|
-
|
|
140
|
+
var StyledSubStepsList = styled.ol.withConfig({
|
|
141
|
+
shouldForwardProp: function shouldForwardProp(prop) {
|
|
142
|
+
return isPropValid(prop) && prop !== 'direction';
|
|
143
|
+
}
|
|
144
|
+
}).withConfig({
|
|
145
|
+
displayName: "StyledStepper__StyledSubStepsList",
|
|
146
|
+
componentId: "sc-gmpe0p-5"
|
|
147
|
+
})(["list-style:none;margin:0;padding:0;", ""], function (props) {
|
|
148
|
+
var _props$theme$stepper9, _props$theme$global6, _props$theme$stepper0, _props$theme$global7, _props$theme$stepper1;
|
|
149
|
+
if (props.direction !== 'vertical') return '';
|
|
150
|
+
var indicatorSizeToken = ((_props$theme$stepper9 = props.theme.stepper) == null || (_props$theme$stepper9 = _props$theme$stepper9.indicator) == null ? void 0 : _props$theme$stepper9.size) || 'medium';
|
|
151
|
+
var indicatorSize = getMetricSize(props.theme, indicatorSizeToken);
|
|
152
|
+
var textGap = (_props$theme$global6 = props.theme.global) == null || (_props$theme$global6 = _props$theme$global6.edgeSize) == null ? void 0 : _props$theme$global6[((_props$theme$stepper0 = props.theme.stepper) == null || (_props$theme$stepper0 = _props$theme$stepper0.vertical) == null || (_props$theme$stepper0 = _props$theme$stepper0.button) == null ? void 0 : _props$theme$stepper0.gap) || 'small'];
|
|
153
|
+
var buttonPad = (_props$theme$global7 = props.theme.global) == null || (_props$theme$global7 = _props$theme$global7.edgeSize) == null ? void 0 : _props$theme$global7[((_props$theme$stepper1 = props.theme.stepper) == null || (_props$theme$stepper1 = _props$theme$stepper1.button) == null ? void 0 : _props$theme$stepper1.pad) || 'xxsmall'];
|
|
154
|
+
return css(["padding-inline-start:calc(", " + ", " + ", ");"], indicatorSize, textGap, buttonPad);
|
|
155
|
+
});
|
|
156
|
+
export { StyledStepItem, StyledStepButton, StyledStepContent, StyledIndicator, StyledConnector, StyledSubStepsList };
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
var _excluded = ["defaultValue", "disabled", "format", "id", "messages", "minuteStep", "name", "onChange", "readOnly", "value"],
|
|
1
|
+
var _excluded = ["defaultValue", "disabled", "format", "id", "inline", "messages", "minuteStep", "name", "onChange", "onPartialChange", "readOnly", "showSeconds", "value"],
|
|
2
2
|
_excluded2 = ["plain", "focusIndicator"];
|
|
3
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
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
|
+
// SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
7
|
import React, { forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
8
|
import { Clock as GrommetClockIcon } from 'grommet-icons/icons/Clock';
|
|
7
9
|
import { AnnounceContext } from '../../contexts/AnnounceContext';
|
|
8
10
|
import { MessageContext } from '../../contexts/MessageContext';
|
|
9
11
|
import { useForwardedRef } from '../../utils';
|
|
12
|
+
import { normalizeStep } from '../../utils/dates';
|
|
10
13
|
import { useThemeValue } from '../../utils/useThemeValue';
|
|
14
|
+
import { getSectionKeyFromType, getSectionTokenFromType } from '../../utils/sectionHelpers';
|
|
11
15
|
import { Box } from '../Box';
|
|
12
16
|
import { Button } from '../Button';
|
|
13
17
|
import { FormContext } from '../Form';
|
|
@@ -16,25 +20,7 @@ import { StyledTimeInputDisplay, StyledTimeInputField, StyledTimeInputSegment, S
|
|
|
16
20
|
import { TimeInputPopup } from './TimeInputPopup';
|
|
17
21
|
import { TimeInputPropTypes } from './propTypes';
|
|
18
22
|
import { useSectionedTimeField } from './useSectionedTimeField';
|
|
19
|
-
import { getSectionAriaMeta, getSectionName, pad, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
|
|
20
|
-
var sectionTypeToSection = {
|
|
21
|
-
hours: SECTION_HOUR,
|
|
22
|
-
minutes: SECTION_MINUTE,
|
|
23
|
-
seconds: SECTION_SECOND,
|
|
24
|
-
meridiem: SECTION_PERIOD
|
|
25
|
-
};
|
|
26
|
-
var getSectionKey = function getSectionKey(section) {
|
|
27
|
-
if (section === SECTION_HOUR) return 'hour';
|
|
28
|
-
if (section === SECTION_MINUTE) return 'minute';
|
|
29
|
-
if (section === SECTION_SECOND) return 'second';
|
|
30
|
-
return 'period';
|
|
31
|
-
};
|
|
32
|
-
var getSectionToken = function getSectionToken(section) {
|
|
33
|
-
if (section === SECTION_HOUR) return 'hh';
|
|
34
|
-
if (section === SECTION_MINUTE) return 'mm';
|
|
35
|
-
if (section === SECTION_SECOND) return 'ss';
|
|
36
|
-
return 'aa';
|
|
37
|
-
};
|
|
23
|
+
import { getSectionAriaMeta, getSectionName, pad, sectionTypeFromSection, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
|
|
38
24
|
var getDisplaySectionKey = function getDisplaySectionKey(section) {
|
|
39
25
|
if (section === SECTION_HOUR) return 'hour';
|
|
40
26
|
if (section === SECTION_MINUTE) return 'minute';
|
|
@@ -49,37 +35,27 @@ var getDisplaySectionText = function getDisplaySectionText(_ref) {
|
|
|
49
35
|
var key = _ref.key,
|
|
50
36
|
section = _ref.section,
|
|
51
37
|
sections = _ref.sections;
|
|
52
|
-
if (sections[key] === undefined) return
|
|
38
|
+
if (sections[key] === undefined) return getSectionTokenFromType(sectionTypeFromSection(section));
|
|
53
39
|
if (section === SECTION_PERIOD) return sections[key];
|
|
54
40
|
return pad(sections[key]);
|
|
55
41
|
};
|
|
56
|
-
var getSectionOrder = function getSectionOrder(format,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return sectionTypeToSection[view];
|
|
62
|
-
}).filter(function (section) {
|
|
63
|
-
return section !== undefined;
|
|
64
|
-
});
|
|
42
|
+
var getSectionOrder = function getSectionOrder(format, showSeconds) {
|
|
43
|
+
if (showSeconds === void 0) {
|
|
44
|
+
showSeconds = format === '12';
|
|
45
|
+
}
|
|
46
|
+
var numericSections = showSeconds ? [SECTION_HOUR, SECTION_MINUTE, SECTION_SECOND] : [SECTION_HOUR, SECTION_MINUTE];
|
|
65
47
|
if (format === '12') {
|
|
66
|
-
|
|
67
|
-
if (includePeriod) return [].concat(numericSections, [SECTION_PERIOD]);
|
|
48
|
+
return [].concat(numericSections, [SECTION_PERIOD]);
|
|
68
49
|
}
|
|
69
50
|
return numericSections;
|
|
70
51
|
};
|
|
71
52
|
var buildPlaceholder = function buildPlaceholder(sectionOrder) {
|
|
72
53
|
return sectionOrder.map(function (section, index) {
|
|
73
|
-
var token =
|
|
54
|
+
var token = getSectionTokenFromType(sectionTypeFromSection(section));
|
|
74
55
|
if (index === 0) return token;
|
|
75
56
|
return "" + (section === SECTION_PERIOD ? ' ' : ':') + token;
|
|
76
57
|
}).join('');
|
|
77
58
|
};
|
|
78
|
-
var normalizeStep = function normalizeStep(step) {
|
|
79
|
-
var parsed = Number(step);
|
|
80
|
-
if (!Number.isFinite(parsed) || parsed <= 0) return 1;
|
|
81
|
-
return Math.max(1, Math.floor(parsed));
|
|
82
|
-
};
|
|
83
59
|
|
|
84
60
|
// When `format` isn't explicitly provided, default to the 12/24-hour
|
|
85
61
|
// convention the browser's default locale uses, rather than hardcoding one.
|
|
@@ -102,13 +78,17 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
102
78
|
_ref2$format = _ref2.format,
|
|
103
79
|
format = _ref2$format === void 0 ? DEFAULT_FORMAT : _ref2$format,
|
|
104
80
|
id = _ref2.id,
|
|
81
|
+
_ref2$inline = _ref2.inline,
|
|
82
|
+
inline = _ref2$inline === void 0 ? false : _ref2$inline,
|
|
105
83
|
messages = _ref2.messages,
|
|
106
84
|
_ref2$minuteStep = _ref2.minuteStep,
|
|
107
85
|
minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
|
|
108
86
|
name = _ref2.name,
|
|
109
87
|
onChange = _ref2.onChange,
|
|
88
|
+
onPartialChange = _ref2.onPartialChange,
|
|
110
89
|
_ref2$readOnly = _ref2.readOnly,
|
|
111
90
|
readOnly = _ref2$readOnly === void 0 ? false : _ref2$readOnly,
|
|
91
|
+
showSeconds = _ref2.showSeconds,
|
|
112
92
|
valueArg = _ref2.value,
|
|
113
93
|
rest = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
114
94
|
var _useThemeValue = useThemeValue(),
|
|
@@ -156,6 +136,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
156
136
|
var normalizedMinuteStep = useMemo(function () {
|
|
157
137
|
return normalizeStep(minuteStep);
|
|
158
138
|
}, [minuteStep]);
|
|
139
|
+
var resolvedShowSeconds = showSeconds !== undefined ? showSeconds : format === '12';
|
|
159
140
|
var handleInvalid = useCallback(function () {
|
|
160
141
|
var error = formatMessage({
|
|
161
142
|
id: 'timeInput.invalidTime',
|
|
@@ -178,8 +159,8 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
178
159
|
}), 'polite');
|
|
179
160
|
}, [announce, format, formatMessage, messages]);
|
|
180
161
|
var sectionOrder = useMemo(function () {
|
|
181
|
-
return getSectionOrder(format);
|
|
182
|
-
}, [format]);
|
|
162
|
+
return getSectionOrder(format, resolvedShowSeconds);
|
|
163
|
+
}, [format, resolvedShowSeconds]);
|
|
183
164
|
var firstSection = sectionOrder[0] || SECTION_HOUR;
|
|
184
165
|
var lastSection = sectionOrder[sectionOrder.length - 1] || SECTION_HOUR;
|
|
185
166
|
var _useSectionedTimeFiel = useSectionedTimeField({
|
|
@@ -187,7 +168,10 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
187
168
|
sectionOrder: sectionOrder,
|
|
188
169
|
minuteStep: normalizedMinuteStep,
|
|
189
170
|
value: value,
|
|
190
|
-
onCommit: function onCommit(_nextSections, nextValue) {
|
|
171
|
+
onCommit: function onCommit(_nextSections, nextValue, _changedSection) {
|
|
172
|
+
// Fire partial change on every commit so consumers can update
|
|
173
|
+
// display state even before all sections are filled.
|
|
174
|
+
onPartialChange == null || onPartialChange(_nextSections, _changedSection);
|
|
191
175
|
if (!nextValue) {
|
|
192
176
|
setValue('');
|
|
193
177
|
onChange == null || onChange({
|
|
@@ -241,7 +225,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
241
225
|
}
|
|
242
226
|
});
|
|
243
227
|
}
|
|
244
|
-
var sectionKey =
|
|
228
|
+
var sectionKey = getSectionKeyFromType(sectionTypeFromSection(section));
|
|
245
229
|
var sectionValue = sections[sectionKey];
|
|
246
230
|
if (sectionValue === undefined) {
|
|
247
231
|
return formatMessage({
|
|
@@ -524,10 +508,14 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
524
508
|
event.preventDefault();
|
|
525
509
|
}, [commitSections, handleInvalid, parsePasted, readOnly]);
|
|
526
510
|
var hoursOptions = useMemo(function () {
|
|
527
|
-
return Array.from({
|
|
528
|
-
length:
|
|
511
|
+
return format === '12' ? [12].concat(Array.from({
|
|
512
|
+
length: 11
|
|
529
513
|
}, function (_, index) {
|
|
530
|
-
return
|
|
514
|
+
return index + 1;
|
|
515
|
+
})) : Array.from({
|
|
516
|
+
length: 24
|
|
517
|
+
}, function (_, index) {
|
|
518
|
+
return index;
|
|
531
519
|
});
|
|
532
520
|
}, [format]);
|
|
533
521
|
var minuteOptions = useMemo(function () {
|
|
@@ -547,6 +535,23 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
547
535
|
});
|
|
548
536
|
}, []);
|
|
549
537
|
var showActiveSection = (segmentFocused || open) && !readOnly && !disabled;
|
|
538
|
+
if (inline) {
|
|
539
|
+
return /*#__PURE__*/React.createElement(TimeInputPopup, _extends({
|
|
540
|
+
inline: true,
|
|
541
|
+
activeSection: activeSection,
|
|
542
|
+
format: format,
|
|
543
|
+
formatMessage: formatMessage,
|
|
544
|
+
hoursOptions: hoursOptions,
|
|
545
|
+
incrementSection: incrementSection,
|
|
546
|
+
messages: messages,
|
|
547
|
+
minuteOptions: minuteOptions,
|
|
548
|
+
sectionOrder: sectionOrder,
|
|
549
|
+
secondOptions: secondOptions,
|
|
550
|
+
sections: sections,
|
|
551
|
+
setActiveSection: setActiveSection,
|
|
552
|
+
setSectionValue: setSectionValue
|
|
553
|
+
}, inputRest));
|
|
554
|
+
}
|
|
550
555
|
return /*#__PURE__*/React.createElement(Keyboard, {
|
|
551
556
|
onEsc: open ? closePicker : undefined
|
|
552
557
|
}, /*#__PURE__*/React.createElement(Box, null, /*#__PURE__*/React.createElement(StyledTimeInputContainer, _extends({
|
|
@@ -669,7 +674,6 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
669
674
|
}),
|
|
670
675
|
messages: messages,
|
|
671
676
|
minuteOptions: minuteOptions,
|
|
672
|
-
moveSection: moveSection,
|
|
673
677
|
sectionOrder: sectionOrder,
|
|
674
678
|
onClose: closePicker,
|
|
675
679
|
onFocusLeave: closePicker,
|