grommet 2.57.0 → 2.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/Box/StyledBox.js +1 -1
- package/components/Box/stories/ColorContrast.stories.js +36 -0
- package/components/Button/BusyAnimation.js +7 -1
- package/components/Button/Button.js +12 -3
- package/components/DataTable/StyledDataTable.js +1 -1
- package/components/DateInput/DateInput.js +3 -3
- package/components/DateTimeInput/DateTimeInput.js +17 -11
- package/components/FocusedContainer.js +2 -1
- package/components/FormField/FormField.js +31 -10
- package/components/FormField/FormFieldContext.js +12 -0
- package/components/Grommet/Grommet.js +4 -1
- package/components/Grommet/StyledGrommet.js +3 -3
- package/components/Grommet/index.d.ts +6 -0
- package/components/Grommet/propTypes.js +2 -0
- package/components/Menu/Menu.js +1 -1
- package/components/Select/SelectContainer.js +2 -2
- package/components/Select/StyledSelect.js +3 -1
- package/components/TextArea/StyledTextArea.js +3 -1
- package/components/TextInput/CopyButton.js +23 -6
- package/components/TextInput/StyledTextInput.js +19 -25
- package/components/TextInput/TextInput.js +75 -28
- package/components/TextInput/index.d.ts +12 -3
- package/components/TextInput/propTypes.js +2 -0
- package/components/TextInput/stories/Copy.stories.tsx +42 -0
- package/components/TextInput/stories/CopySecret.stories.tsx +44 -0
- package/components/TimeInput/README.md +24 -1
- package/components/TimeInput/StyledTimeInput.js +91 -27
- package/components/TimeInput/TimeInput.js +185 -120
- package/components/TimeInput/TimeInputPopup.js +114 -117
- package/components/TimeInput/index.d.ts +2 -0
- package/components/TimeInput/propTypes.js +2 -0
- package/components/TimeInput/stories/Controlled.stories.tsx +2 -2
- package/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
- package/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
- package/components/TimeInput/stories/Form.stories.tsx +1 -0
- package/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
- package/components/TimeInput/useSectionedTimeField.js +2 -2
- package/components/TimeInput/utils.js +13 -62
- package/components/Wizard/Wizard.js +396 -210
- package/components/Wizard/WizardContent.js +61 -35
- package/components/Wizard/WizardContext.js +3 -0
- package/components/Wizard/WizardFooter.js +14 -15
- package/components/Wizard/WizardHeader.js +12 -7
- package/components/Wizard/WizardProgress.js +27 -2
- package/components/Wizard/index.d.ts +35 -4
- package/components/Wizard/propTypes.js +6 -1
- package/components/Wizard/stories/BasicLinear.stories.js +12 -10
- package/components/Wizard/stories/ClickableSteps.stories.js +104 -0
- package/components/Wizard/stories/ExternalForm.stories.js +114 -0
- package/components/Wizard/stories/NonClosableHeader.stories.js +68 -0
- package/components/Wizard/stories/Validation.stories.js +18 -8
- package/es6/components/Box/StyledBox.js +1 -1
- package/es6/components/Box/stories/ColorContrast.stories.js +31 -0
- package/es6/components/Button/BusyAnimation.js +7 -1
- package/es6/components/Button/Button.js +12 -3
- package/es6/components/DataTable/StyledDataTable.js +2 -2
- package/es6/components/DateInput/DateInput.js +3 -3
- package/es6/components/DateTimeInput/DateTimeInput.js +17 -11
- package/es6/components/FocusedContainer.js +2 -1
- package/es6/components/FormField/FormField.js +31 -10
- package/es6/components/FormField/FormFieldContext.js +7 -0
- package/es6/components/Grommet/Grommet.js +4 -1
- package/es6/components/Grommet/StyledGrommet.js +4 -4
- package/es6/components/Grommet/index.d.ts +6 -0
- package/es6/components/Grommet/propTypes.js +2 -0
- package/es6/components/Menu/Menu.js +1 -1
- package/es6/components/Select/SelectContainer.js +2 -2
- package/es6/components/Select/StyledSelect.js +4 -2
- package/es6/components/TextArea/StyledTextArea.js +4 -2
- package/es6/components/TextInput/CopyButton.js +22 -6
- package/es6/components/TextInput/StyledTextInput.js +20 -26
- package/es6/components/TextInput/TextInput.js +76 -29
- package/es6/components/TextInput/index.d.ts +12 -3
- package/es6/components/TextInput/propTypes.js +2 -0
- package/es6/components/TextInput/stories/Copy.stories.tsx +42 -0
- package/es6/components/TextInput/stories/CopySecret.stories.tsx +44 -0
- package/es6/components/TimeInput/README.md +24 -1
- package/es6/components/TimeInput/StyledTimeInput.js +92 -28
- package/es6/components/TimeInput/TimeInput.js +187 -122
- package/es6/components/TimeInput/TimeInputPopup.js +115 -118
- package/es6/components/TimeInput/index.d.ts +2 -0
- package/es6/components/TimeInput/propTypes.js +2 -0
- package/es6/components/TimeInput/stories/Controlled.stories.tsx +2 -2
- package/es6/components/TimeInput/stories/CustomThemed.stories.tsx +79 -0
- package/es6/components/TimeInput/stories/CustomThemedHpe.stories.tsx +115 -0
- package/es6/components/TimeInput/stories/Form.stories.tsx +1 -0
- package/es6/components/TimeInput/stories/ShowSeconds.stories.tsx +28 -0
- package/es6/components/TimeInput/useSectionedTimeField.js +2 -2
- package/es6/components/TimeInput/utils.js +12 -61
- package/es6/components/Wizard/Wizard.js +397 -211
- package/es6/components/Wizard/WizardContent.js +62 -36
- package/es6/components/Wizard/WizardContext.js +3 -0
- package/es6/components/Wizard/WizardFooter.js +14 -15
- package/es6/components/Wizard/WizardHeader.js +12 -7
- package/es6/components/Wizard/WizardProgress.js +27 -2
- package/es6/components/Wizard/index.d.ts +35 -4
- package/es6/components/Wizard/propTypes.js +6 -1
- package/es6/components/Wizard/stories/BasicLinear.stories.js +11 -11
- package/es6/components/Wizard/stories/ClickableSteps.stories.js +99 -0
- package/es6/components/Wizard/stories/ExternalForm.stories.js +111 -0
- package/es6/components/Wizard/stories/NonClosableHeader.stories.js +63 -0
- package/es6/components/Wizard/stories/Validation.stories.js +18 -9
- package/es6/languages/default.json +2 -0
- package/es6/themes/base.d.ts +79 -59
- package/es6/themes/base.js +65 -34
- package/es6/utils/DOM.js +10 -7
- package/es6/utils/background.js +9 -7
- package/es6/utils/colors.js +84 -12
- package/es6/utils/legacyColorIsDark.js +17 -0
- package/es6/utils/styles.js +13 -5
- package/grommet.min.js +1 -1
- package/grommet.min.js.map +1 -1
- package/languages/default.json +2 -0
- package/package.json +3 -3
- package/themes/base.d.ts +79 -59
- package/themes/base.js +65 -34
- package/tools/draft-release-version-pr.js +1 -0
- package/tools/generate-release-notes.js +1 -1
- package/tools/release-notes-utils.js +1 -0
- package/utils/DOM.js +10 -7
- package/utils/background.js +9 -7
- package/utils/colors.js +84 -12
- package/utils/legacyColorIsDark.js +21 -0
- package/utils/styles.js +14 -6
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var _excluded = ["defaultValue", "disabled", "focusOnOpen", "format", "id", "inline", "messages", "minuteStep", "name", "onChange", "onPartialChange", "readOnly", "showSeconds", "value"],
|
|
2
|
-
_excluded2 = ["plain", "focusIndicator"]
|
|
2
|
+
_excluded2 = ["plain", "focusIndicator", "aria-describedby", "aria-invalid"],
|
|
3
|
+
_excluded3 = ["icon", "kind"];
|
|
3
4
|
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
5
|
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
6
|
// SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
@@ -11,49 +12,55 @@ import { MessageContext } from '../../contexts/MessageContext';
|
|
|
11
12
|
import { useForwardedRef } from '../../utils';
|
|
12
13
|
import { normalizeStep } from '../../utils/dates';
|
|
13
14
|
import { useThemeValue } from '../../utils/useThemeValue';
|
|
14
|
-
import {
|
|
15
|
+
import { getSectionTokenFromType } from '../../utils/sectionHelpers';
|
|
15
16
|
import { Box } from '../Box';
|
|
16
17
|
import { Button } from '../Button';
|
|
17
18
|
import { FormContext } from '../Form';
|
|
19
|
+
import { FormFieldContext } from '../FormField/FormFieldContext';
|
|
18
20
|
import { Keyboard } from '../Keyboard';
|
|
19
21
|
import { StyledTimeInputDisplay, StyledTimeInputField, StyledTimeInputSegment, StyledTimeInputSeparator, StyledTimeInputContainer, StyledTimeInput } from './StyledTimeInput';
|
|
20
22
|
import { TimeInputPopup } from './TimeInputPopup';
|
|
21
23
|
import { TimeInputPropTypes } from './propTypes';
|
|
22
24
|
import { useSectionedTimeField } from './useSectionedTimeField';
|
|
23
|
-
import { getSectionAriaMeta, getSectionName, pad, sectionTypeFromSection, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
|
|
24
|
-
var getDisplaySectionKey = function getDisplaySectionKey(section) {
|
|
25
|
-
if (section === SECTION_HOUR) return 'hour';
|
|
26
|
-
if (section === SECTION_MINUTE) return 'minute';
|
|
27
|
-
if (section === SECTION_SECOND) return 'second';
|
|
28
|
-
return 'period';
|
|
29
|
-
};
|
|
25
|
+
import { getSectionAriaMeta, getSectionName, pad, sectionTypeFromSection, sectionKey, SECTION_HOUR, SECTION_MINUTE, SECTION_PERIOD, SECTION_SECOND } from './utils';
|
|
30
26
|
var getDisplaySectionPrefix = function getDisplaySectionPrefix(section, index) {
|
|
31
27
|
if (index === 0) return '';
|
|
32
28
|
return section === SECTION_PERIOD ? ' ' : ':';
|
|
33
29
|
};
|
|
34
|
-
var getDisplaySectionText = function getDisplaySectionText(_ref) {
|
|
35
|
-
var key = _ref.key,
|
|
36
|
-
section = _ref.section,
|
|
37
|
-
sections = _ref.sections;
|
|
38
|
-
if (sections[key] === undefined) return getSectionTokenFromType(sectionTypeFromSection(section));
|
|
39
|
-
if (section === SECTION_PERIOD) return sections[key];
|
|
40
|
-
return pad(sections[key]);
|
|
41
|
-
};
|
|
42
30
|
var getSectionOrder = function getSectionOrder(format, showSeconds) {
|
|
43
|
-
if (showSeconds === void 0) {
|
|
44
|
-
showSeconds = format === '12';
|
|
45
|
-
}
|
|
46
31
|
var numericSections = showSeconds ? [SECTION_HOUR, SECTION_MINUTE, SECTION_SECOND] : [SECTION_HOUR, SECTION_MINUTE];
|
|
47
32
|
if (format === '12') {
|
|
48
33
|
return [].concat(numericSections, [SECTION_PERIOD]);
|
|
49
34
|
}
|
|
50
35
|
return numericSections;
|
|
51
36
|
};
|
|
37
|
+
var getContainerFill = function getContainerFill(container) {
|
|
38
|
+
if (container === void 0) {
|
|
39
|
+
container = {};
|
|
40
|
+
}
|
|
41
|
+
var fillWidth = container.width === undefined;
|
|
42
|
+
var fillHeight = container.height === undefined;
|
|
43
|
+
if (fillWidth && fillHeight) return true;
|
|
44
|
+
if (fillWidth) return 'horizontal';
|
|
45
|
+
if (fillHeight) return 'vertical';
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
var resolveDropButtonIcon = function resolveDropButtonIcon(icon) {
|
|
49
|
+
if (/*#__PURE__*/React.isValidElement(icon)) {
|
|
50
|
+
var _icon$props$ariaHidd;
|
|
51
|
+
return /*#__PURE__*/React.cloneElement(icon, {
|
|
52
|
+
'aria-hidden': (_icon$props$ariaHidd = icon.props['aria-hidden']) != null ? _icon$props$ariaHidd : true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (typeof icon === 'function' || icon != null && icon.$$typeof) return /*#__PURE__*/React.createElement(icon, {
|
|
56
|
+
'aria-hidden': true
|
|
57
|
+
});
|
|
58
|
+
return icon;
|
|
59
|
+
};
|
|
52
60
|
var buildPlaceholder = function buildPlaceholder(sectionOrder) {
|
|
53
61
|
return sectionOrder.map(function (section, index) {
|
|
54
62
|
var token = getSectionTokenFromType(sectionTypeFromSection(section));
|
|
55
|
-
|
|
56
|
-
return "" + (section === SECTION_PERIOD ? ' ' : ':') + token;
|
|
63
|
+
return "" + getDisplaySectionPrefix(section, index) + token;
|
|
57
64
|
}).join('');
|
|
58
65
|
};
|
|
59
66
|
|
|
@@ -71,28 +78,29 @@ var getDefaultFormat = function getDefaultFormat() {
|
|
|
71
78
|
}
|
|
72
79
|
};
|
|
73
80
|
var DEFAULT_FORMAT = getDefaultFormat();
|
|
74
|
-
var TimeInput = /*#__PURE__*/forwardRef(function (
|
|
75
|
-
var _theme$timeInput, _theme$global, _theme$
|
|
76
|
-
var defaultValue =
|
|
77
|
-
disabled =
|
|
78
|
-
|
|
79
|
-
focusOnOpen =
|
|
80
|
-
|
|
81
|
-
format =
|
|
82
|
-
id =
|
|
83
|
-
|
|
84
|
-
inline =
|
|
85
|
-
messages =
|
|
86
|
-
|
|
87
|
-
minuteStep =
|
|
88
|
-
name =
|
|
89
|
-
onChange =
|
|
90
|
-
onPartialChange =
|
|
91
|
-
|
|
92
|
-
readOnly =
|
|
93
|
-
showSeconds =
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
var TimeInput = /*#__PURE__*/forwardRef(function (_ref, refArg) {
|
|
82
|
+
var _theme$timeInput, _theme$timeInput2, _theme$timeInput$cont, _theme$timeInput3, _theme$global, _theme$timeInput4;
|
|
83
|
+
var defaultValue = _ref.defaultValue,
|
|
84
|
+
disabled = _ref.disabled,
|
|
85
|
+
_ref$focusOnOpen = _ref.focusOnOpen,
|
|
86
|
+
focusOnOpen = _ref$focusOnOpen === void 0 ? true : _ref$focusOnOpen,
|
|
87
|
+
_ref$format = _ref.format,
|
|
88
|
+
format = _ref$format === void 0 ? DEFAULT_FORMAT : _ref$format,
|
|
89
|
+
id = _ref.id,
|
|
90
|
+
_ref$inline = _ref.inline,
|
|
91
|
+
inline = _ref$inline === void 0 ? false : _ref$inline,
|
|
92
|
+
messages = _ref.messages,
|
|
93
|
+
_ref$minuteStep = _ref.minuteStep,
|
|
94
|
+
minuteStep = _ref$minuteStep === void 0 ? 1 : _ref$minuteStep,
|
|
95
|
+
name = _ref.name,
|
|
96
|
+
onChange = _ref.onChange,
|
|
97
|
+
onPartialChange = _ref.onPartialChange,
|
|
98
|
+
_ref$readOnly = _ref.readOnly,
|
|
99
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
100
|
+
_ref$showSeconds = _ref.showSeconds,
|
|
101
|
+
showSeconds = _ref$showSeconds === void 0 ? false : _ref$showSeconds,
|
|
102
|
+
valueArg = _ref.value,
|
|
103
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
96
104
|
var _useThemeValue = useThemeValue(),
|
|
97
105
|
theme = _useThemeValue.theme,
|
|
98
106
|
passThemeFlag = _useThemeValue.passThemeFlag;
|
|
@@ -100,6 +108,8 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
100
108
|
var _useContext = useContext(MessageContext),
|
|
101
109
|
formatMessage = _useContext.format;
|
|
102
110
|
var formContext = useContext(FormContext);
|
|
111
|
+
var _useContext2 = useContext(FormFieldContext),
|
|
112
|
+
setFieldFocusIndicator = _useContext2.setFocusIndicator;
|
|
103
113
|
var useFormInput = formContext.useFormInput;
|
|
104
114
|
var inputRef = useForwardedRef(refArg);
|
|
105
115
|
var containerRef = useRef();
|
|
@@ -110,11 +120,9 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
110
120
|
}),
|
|
111
121
|
value = _useFormInput[0],
|
|
112
122
|
setValue = _useFormInput[1];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
}, []);
|
|
123
|
+
if (inline && (disabled || readOnly)) {
|
|
124
|
+
console.warn('TimeInput is rendered inline and is either disabled or read-only. ' + 'TimeInput ignores disabled and readOnly props when rendered inline.');
|
|
125
|
+
}
|
|
118
126
|
var _formContext$useFormF = formContext.useFormField({}),
|
|
119
127
|
inForm = _formContext$useFormF.inForm;
|
|
120
128
|
var formFieldLabelId = inForm && id ? "grommet-" + id + "__label" : undefined;
|
|
@@ -134,11 +142,23 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
134
142
|
var segmentRefs = useRef({});
|
|
135
143
|
var plainProp = rest.plain,
|
|
136
144
|
focusIndicatorProp = rest.focusIndicator,
|
|
145
|
+
ariaDescribedBy = rest['aria-describedby'],
|
|
146
|
+
ariaInvalid = rest['aria-invalid'],
|
|
137
147
|
inputRest = _objectWithoutPropertiesLoose(rest, _excluded2);
|
|
148
|
+
|
|
149
|
+
// FormField merges its generated error id into aria-describedby
|
|
150
|
+
// alongside any id the consumer already had on the child. Split those
|
|
151
|
+
// back apart so a pre-existing description stays on every segment,
|
|
152
|
+
// while the error id itself is only added to the segment(s) it's about.
|
|
153
|
+
var errorId = id ? "grommet-" + id + "__error" : undefined;
|
|
154
|
+
var describedByTokens = ariaDescribedBy ? ariaDescribedBy.split(' ').filter(Boolean) : [];
|
|
155
|
+
var hasErrorDescribedBy = !!errorId && describedByTokens.includes(errorId);
|
|
156
|
+
var consumerDescribedBy = describedByTokens.filter(function (token) {
|
|
157
|
+
return token !== errorId;
|
|
158
|
+
}).join(' ') || undefined;
|
|
138
159
|
var normalizedMinuteStep = useMemo(function () {
|
|
139
160
|
return normalizeStep(minuteStep);
|
|
140
161
|
}, [minuteStep]);
|
|
141
|
-
var resolvedShowSeconds = showSeconds !== undefined ? showSeconds : format === '12';
|
|
142
162
|
var handleInvalid = useCallback(function () {
|
|
143
163
|
var error = formatMessage({
|
|
144
164
|
id: 'timeInput.invalidTime',
|
|
@@ -147,22 +167,25 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
147
167
|
announce(error, 'assertive');
|
|
148
168
|
}, [announce, formatMessage, messages]);
|
|
149
169
|
var announceCurrentValue = useCallback(function (nextSections) {
|
|
150
|
-
if (nextSections.hour === undefined || nextSections.minute === undefined || nextSections.second === undefined) return;
|
|
170
|
+
if (nextSections.hour === undefined || nextSections.minute === undefined || showSeconds && nextSections.second === undefined) return;
|
|
151
171
|
var period = format === '12' ? " " + (nextSections.period || 'AM') : '';
|
|
172
|
+
var messageId = showSeconds ? 'timeInput.currentValue' : 'timeInput.currentValueWithoutSeconds';
|
|
152
173
|
announce(formatMessage({
|
|
153
|
-
id:
|
|
174
|
+
id: messageId,
|
|
154
175
|
messages: messages,
|
|
155
|
-
values: {
|
|
176
|
+
values: _extends({
|
|
156
177
|
hour: nextSections.hour,
|
|
157
|
-
minute: nextSections.minute
|
|
158
|
-
|
|
178
|
+
minute: nextSections.minute
|
|
179
|
+
}, showSeconds ? {
|
|
180
|
+
second: nextSections.second
|
|
181
|
+
} : {}, {
|
|
159
182
|
period: period
|
|
160
|
-
}
|
|
183
|
+
})
|
|
161
184
|
}), 'polite');
|
|
162
|
-
}, [announce, format, formatMessage, messages]);
|
|
185
|
+
}, [announce, format, formatMessage, messages, showSeconds]);
|
|
163
186
|
var sectionOrder = useMemo(function () {
|
|
164
|
-
return getSectionOrder(format,
|
|
165
|
-
}, [format,
|
|
187
|
+
return getSectionOrder(format, showSeconds);
|
|
188
|
+
}, [format, showSeconds]);
|
|
166
189
|
var firstSection = sectionOrder[0] || SECTION_HOUR;
|
|
167
190
|
var lastSection = sectionOrder[sectionOrder.length - 1] || SECTION_HOUR;
|
|
168
191
|
var _useSectionedTimeFiel = useSectionedTimeField({
|
|
@@ -227,8 +250,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
227
250
|
}
|
|
228
251
|
});
|
|
229
252
|
}
|
|
230
|
-
var
|
|
231
|
-
var sectionValue = sections[sectionKey];
|
|
253
|
+
var sectionValue = sections[sectionKey(section)];
|
|
232
254
|
if (sectionValue === undefined) {
|
|
233
255
|
return formatMessage({
|
|
234
256
|
id: 'timeInput.activeSection',
|
|
@@ -266,19 +288,36 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
266
288
|
displaySectionsData[pendingSection] = pendingDigits[pendingSection];
|
|
267
289
|
}
|
|
268
290
|
return sectionOrder.map(function (section, index) {
|
|
269
|
-
var key =
|
|
291
|
+
var key = sectionKey(section);
|
|
292
|
+
var sectionValue = displaySectionsData[key];
|
|
293
|
+
var text;
|
|
294
|
+
if (sectionValue === undefined) {
|
|
295
|
+
text = getSectionTokenFromType(sectionTypeFromSection(section));
|
|
296
|
+
} else if (section === SECTION_PERIOD) {
|
|
297
|
+
text = sectionValue;
|
|
298
|
+
} else {
|
|
299
|
+
text = pad(sectionValue);
|
|
300
|
+
}
|
|
270
301
|
return {
|
|
271
|
-
|
|
272
|
-
prefix: getDisplaySectionPrefix(section, index),
|
|
273
|
-
text: getDisplaySectionText({
|
|
274
|
-
key: key,
|
|
302
|
+
ariaMeta: getSectionAriaMeta({
|
|
275
303
|
section: section,
|
|
276
|
-
|
|
304
|
+
format: format,
|
|
305
|
+
sections: sections
|
|
277
306
|
}),
|
|
278
|
-
|
|
307
|
+
section: section,
|
|
308
|
+
prefix: getDisplaySectionPrefix(section, index),
|
|
309
|
+
text: text,
|
|
310
|
+
filled: sectionValue !== undefined
|
|
279
311
|
};
|
|
280
312
|
});
|
|
281
|
-
}, [sectionOrder, sections
|
|
313
|
+
}, [format, pendingDigits, sectionOrder, sections]);
|
|
314
|
+
|
|
315
|
+
// A required-field error is caused by whichever section(s) are still
|
|
316
|
+
// empty, so only announce it there; once every section has a value the
|
|
317
|
+
// error must be about the value as a whole, so announce it everywhere.
|
|
318
|
+
var allSectionsFilled = displaySections.every(function (entry) {
|
|
319
|
+
return entry.filled;
|
|
320
|
+
});
|
|
282
321
|
var onDisplaySectionMouseDown = useCallback(function (section, event) {
|
|
283
322
|
if (readOnly) return;
|
|
284
323
|
if (disabled) return;
|
|
@@ -315,8 +354,8 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
315
354
|
}).sort(function (a, b) {
|
|
316
355
|
return a.rect.left - b.rect.left;
|
|
317
356
|
});
|
|
318
|
-
var sectionFromBounds = sectionsWithRects.find(function (
|
|
319
|
-
var rect =
|
|
357
|
+
var sectionFromBounds = sectionsWithRects.find(function (_ref2) {
|
|
358
|
+
var rect = _ref2.rect;
|
|
320
359
|
return x >= rect.left && x <= rect.right;
|
|
321
360
|
});
|
|
322
361
|
if ((sectionFromBounds == null || (_sectionFromBounds$no = sectionFromBounds.node) == null || (_sectionFromBounds$no = _sectionFromBounds$no.dataset) == null ? void 0 : _sectionFromBounds$no.section) !== undefined) {
|
|
@@ -326,8 +365,8 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
326
365
|
return;
|
|
327
366
|
}
|
|
328
367
|
}
|
|
329
|
-
var zones = sectionsWithRects.map(function (
|
|
330
|
-
var rect =
|
|
368
|
+
var zones = sectionsWithRects.map(function (_ref3, index) {
|
|
369
|
+
var rect = _ref3.rect;
|
|
331
370
|
var prev = sectionsWithRects[index - 1];
|
|
332
371
|
var next = sectionsWithRects[index + 1];
|
|
333
372
|
var start = prev !== undefined ? (prev.rect.right + rect.left) / 2 : Number.NEGATIVE_INFINITY;
|
|
@@ -338,9 +377,9 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
338
377
|
end: end
|
|
339
378
|
};
|
|
340
379
|
});
|
|
341
|
-
var zone = zones.find(function (
|
|
342
|
-
var start =
|
|
343
|
-
end =
|
|
380
|
+
var zone = zones.find(function (_ref4) {
|
|
381
|
+
var start = _ref4.start,
|
|
382
|
+
end = _ref4.end;
|
|
344
383
|
return x >= start && x <= end;
|
|
345
384
|
}) || zones[0] || null;
|
|
346
385
|
if (zone) {
|
|
@@ -372,6 +411,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
372
411
|
}, 0);
|
|
373
412
|
}, [activeSection, focusSection]);
|
|
374
413
|
var onSegmentFocus = useCallback(function (section) {
|
|
414
|
+
setFieldFocusIndicator == null || setFieldFocusIndicator(true);
|
|
375
415
|
if (!segmentFocused && !readOnly && !disabled && !open) {
|
|
376
416
|
announce(formatMessage({
|
|
377
417
|
id: 'timeInput.openDrop',
|
|
@@ -381,24 +421,26 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
381
421
|
setSegmentFocused(true);
|
|
382
422
|
if (readOnly || disabled) return;
|
|
383
423
|
setActiveSection(section);
|
|
384
|
-
}, [announce, disabled, formatMessage, messages, open, readOnly, segmentFocused, setActiveSection]);
|
|
424
|
+
}, [announce, disabled, formatMessage, messages, open, readOnly, segmentFocused, setFieldFocusIndicator, setActiveSection]);
|
|
385
425
|
var onSegmentBlur = useCallback(function () {
|
|
386
426
|
requestAnimationFrame(function () {
|
|
427
|
+
var _containerRef$current;
|
|
387
428
|
var _document = document,
|
|
388
429
|
activeElement = _document.activeElement;
|
|
389
430
|
var isSegmentFocused = Object.values(segmentRefs.current).includes(activeElement);
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return;
|
|
393
|
-
}
|
|
394
|
-
if (!isSegmentFocused) {
|
|
431
|
+
var isInsideTimeInput = (_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.contains(activeElement);
|
|
432
|
+
if (!isSegmentFocused || !isInsideTimeInput) {
|
|
395
433
|
setSegmentFocused(false);
|
|
396
434
|
}
|
|
397
435
|
});
|
|
398
|
-
}, [
|
|
436
|
+
}, []);
|
|
399
437
|
var onSegmentKeyDown = useCallback(function (section, event) {
|
|
400
438
|
if (readOnly || disabled) return;
|
|
401
|
-
var key = event.key
|
|
439
|
+
var key = event.key,
|
|
440
|
+
ctrlKey = event.ctrlKey,
|
|
441
|
+
metaKey = event.metaKey,
|
|
442
|
+
altKey = event.altKey;
|
|
443
|
+
if (ctrlKey || metaKey || altKey && key !== 'ArrowDown') return;
|
|
402
444
|
if (activeSection !== section) {
|
|
403
445
|
setActiveSection(section);
|
|
404
446
|
}
|
|
@@ -407,10 +449,12 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
407
449
|
var next = moveSection(1);
|
|
408
450
|
setActiveSection(next);
|
|
409
451
|
focusSection(next);
|
|
452
|
+
event.stopPropagation();
|
|
410
453
|
return;
|
|
411
454
|
}
|
|
412
455
|
if (key === 'ArrowLeft') {
|
|
413
456
|
event.preventDefault();
|
|
457
|
+
event.stopPropagation();
|
|
414
458
|
var _next = moveSection(-1);
|
|
415
459
|
setActiveSection(_next);
|
|
416
460
|
focusSection(_next);
|
|
@@ -418,48 +462,51 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
418
462
|
}
|
|
419
463
|
if (key === 'Home') {
|
|
420
464
|
event.preventDefault();
|
|
465
|
+
event.stopPropagation();
|
|
421
466
|
setActiveSection(firstSection);
|
|
422
467
|
focusSection(firstSection);
|
|
423
468
|
return;
|
|
424
469
|
}
|
|
425
470
|
if (key === 'End') {
|
|
426
471
|
event.preventDefault();
|
|
472
|
+
event.stopPropagation();
|
|
427
473
|
setActiveSection(lastSection);
|
|
428
474
|
focusSection(lastSection);
|
|
429
475
|
return;
|
|
430
476
|
}
|
|
431
477
|
if (key === 'ArrowUp') {
|
|
432
478
|
event.preventDefault();
|
|
479
|
+
event.stopPropagation();
|
|
433
480
|
incrementSection(section, open ? -1 : 1);
|
|
434
481
|
return;
|
|
435
482
|
}
|
|
436
483
|
if (key === 'ArrowDown') {
|
|
437
|
-
if (
|
|
484
|
+
if (altKey) {
|
|
438
485
|
event.preventDefault();
|
|
486
|
+
event.stopPropagation();
|
|
439
487
|
openPicker();
|
|
440
488
|
return;
|
|
441
489
|
}
|
|
442
490
|
event.preventDefault();
|
|
491
|
+
event.stopPropagation();
|
|
443
492
|
incrementSection(section, open ? 1 : -1);
|
|
444
493
|
return;
|
|
445
494
|
}
|
|
446
495
|
if (key === 'Delete' || key === 'Backspace') {
|
|
447
496
|
event.preventDefault();
|
|
497
|
+
event.stopPropagation();
|
|
448
498
|
clearActiveSection();
|
|
449
499
|
return;
|
|
450
500
|
}
|
|
451
|
-
if (key === 'Enter') {
|
|
452
|
-
event.preventDefault();
|
|
453
|
-
if (open) closePicker();
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
if (key === 'Escape' && open) {
|
|
501
|
+
if ((key === 'Enter' || key === 'Escape') && open) {
|
|
457
502
|
event.preventDefault();
|
|
503
|
+
event.stopPropagation();
|
|
458
504
|
closePicker();
|
|
459
505
|
return;
|
|
460
506
|
}
|
|
461
507
|
if (key === ' ' || key === 'Spacebar') {
|
|
462
508
|
event.preventDefault();
|
|
509
|
+
event.stopPropagation();
|
|
463
510
|
openPicker();
|
|
464
511
|
return;
|
|
465
512
|
}
|
|
@@ -467,21 +514,23 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
467
514
|
var lower = key.toLowerCase();
|
|
468
515
|
if (lower === 'a') {
|
|
469
516
|
event.preventDefault();
|
|
517
|
+
event.stopPropagation();
|
|
470
518
|
setSectionValue(SECTION_PERIOD, 'AM');
|
|
471
519
|
} else if (lower === 'p') {
|
|
472
520
|
event.preventDefault();
|
|
521
|
+
event.stopPropagation();
|
|
473
522
|
setSectionValue(SECTION_PERIOD, 'PM');
|
|
474
523
|
}
|
|
475
524
|
return;
|
|
476
525
|
}
|
|
477
526
|
if (/^\d$/.test(key)) {
|
|
478
527
|
event.preventDefault();
|
|
528
|
+
event.stopPropagation();
|
|
479
529
|
var _next2 = applyDigit(Number(key));
|
|
480
530
|
var targetSection = _next2 != null ? _next2 : section;
|
|
481
531
|
setActiveSection(targetSection);
|
|
482
|
-
if (targetSection
|
|
483
|
-
|
|
484
|
-
} else {
|
|
532
|
+
if (targetSection !== section) {
|
|
533
|
+
// moving to a different section focus for digit',
|
|
485
534
|
focusSection(targetSection);
|
|
486
535
|
}
|
|
487
536
|
}
|
|
@@ -537,13 +586,33 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
537
586
|
});
|
|
538
587
|
}, []);
|
|
539
588
|
var showActiveSection = (segmentFocused || open) && !readOnly && !disabled;
|
|
589
|
+
var containerTheme = (_theme$timeInput = theme.timeInput) == null ? void 0 : _theme$timeInput.container;
|
|
590
|
+
var dropButtonTheme = (_theme$timeInput2 = theme.timeInput) == null ? void 0 : _theme$timeInput2.dropButton;
|
|
591
|
+
var dropButtonKind = 'toolbar';
|
|
592
|
+
var dropButtonIcon = /*#__PURE__*/React.createElement(GrommetClockIcon, {
|
|
593
|
+
"aria-hidden": "true"
|
|
594
|
+
});
|
|
595
|
+
if (typeof dropButtonTheme === 'string') {
|
|
596
|
+
dropButtonKind = dropButtonTheme;
|
|
597
|
+
} else if (dropButtonTheme && typeof dropButtonTheme === 'object' && ! /*#__PURE__*/React.isValidElement(dropButtonTheme) && !dropButtonTheme.$$typeof) {
|
|
598
|
+
var icon = dropButtonTheme.icon,
|
|
599
|
+
kind = dropButtonTheme.kind,
|
|
600
|
+
buttonTheme = _objectWithoutPropertiesLoose(dropButtonTheme, _excluded3);
|
|
601
|
+
dropButtonIcon = resolveDropButtonIcon(icon != null ? icon : dropButtonIcon);
|
|
602
|
+
if (kind) {
|
|
603
|
+
dropButtonKind = kind;
|
|
604
|
+
} else {
|
|
605
|
+
var hasButtonTheme = Object.keys(buttonTheme).length > 0;
|
|
606
|
+
dropButtonKind = hasButtonTheme ? buttonTheme : 'toolbar';
|
|
607
|
+
}
|
|
608
|
+
}
|
|
540
609
|
if (inline) {
|
|
541
610
|
return /*#__PURE__*/React.createElement(TimeInputPopup, _extends({
|
|
542
611
|
inline: true,
|
|
543
612
|
activeSection: activeSection,
|
|
544
613
|
format: format,
|
|
545
614
|
formatMessage: formatMessage,
|
|
546
|
-
focusOnOpen: focusOnOpen,
|
|
615
|
+
focusOnOpen: inline ? false : focusOnOpen,
|
|
547
616
|
hoursOptions: hoursOptions,
|
|
548
617
|
incrementSection: incrementSection,
|
|
549
618
|
messages: messages,
|
|
@@ -561,21 +630,27 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
561
630
|
ref: containerRef,
|
|
562
631
|
direction: "row",
|
|
563
632
|
border: !plainProp,
|
|
564
|
-
fill:
|
|
565
|
-
|
|
633
|
+
fill: getContainerFill(containerTheme)
|
|
634
|
+
}, containerTheme, {
|
|
635
|
+
round: (_theme$timeInput$cont = (_theme$timeInput3 = theme.timeInput) == null || (_theme$timeInput3 = _theme$timeInput3.container) == null ? void 0 : _theme$timeInput3.round) != null ? _theme$timeInput$cont : (_theme$global = theme.global) == null || (_theme$global = _theme$global.control) == null || (_theme$global = _theme$global.border) == null ? void 0 : _theme$global.radius,
|
|
566
636
|
disabled: disabled,
|
|
567
637
|
readOnlyProp: readOnly,
|
|
568
638
|
focusIndicator: (focusIndicatorProp != null ? focusIndicatorProp : true) && !iconFocused
|
|
569
|
-
}, passThemeFlag), /*#__PURE__*/React.createElement(StyledTimeInputField, passThemeFlag, /*#__PURE__*/React.createElement(StyledTimeInputDisplay, _extends({
|
|
639
|
+
}, passThemeFlag), /*#__PURE__*/React.createElement(StyledTimeInputField, passThemeFlag, /*#__PURE__*/React.createElement(StyledTimeInputDisplay, _extends({}, (_theme$timeInput4 = theme.timeInput) == null ? void 0 : _theme$timeInput4.value, {
|
|
640
|
+
align: "center",
|
|
641
|
+
direction: "row",
|
|
642
|
+
overflow: "hidden",
|
|
570
643
|
role: "group",
|
|
571
644
|
"aria-label": groupLabel,
|
|
572
645
|
"aria-labelledby": formFieldLabelId,
|
|
573
646
|
onMouseDown: onDisplayMouseDown
|
|
574
|
-
}, passThemeFlag), displaySections.map(function (
|
|
575
|
-
var
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
647
|
+
}, passThemeFlag), displaySections.map(function (_ref5) {
|
|
648
|
+
var ariaMeta = _ref5.ariaMeta,
|
|
649
|
+
section = _ref5.section,
|
|
650
|
+
prefix = _ref5.prefix,
|
|
651
|
+
text = _ref5.text,
|
|
652
|
+
filled = _ref5.filled;
|
|
653
|
+
var describeSegment = !filled || allSectionsFilled;
|
|
579
654
|
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
580
655
|
key: section
|
|
581
656
|
}, !!prefix && /*#__PURE__*/React.createElement(StyledTimeInputSeparator, _extends({
|
|
@@ -584,6 +659,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
584
659
|
ref: function ref(segmentNode) {
|
|
585
660
|
segmentRefs.current[section] = segmentNode;
|
|
586
661
|
},
|
|
662
|
+
responsive: false,
|
|
587
663
|
tabIndex: !readOnly && !disabled && activeSection === section ? 0 : -1,
|
|
588
664
|
$active: showActiveSection && activeSection === section,
|
|
589
665
|
$filled: filled,
|
|
@@ -596,28 +672,17 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
596
672
|
},
|
|
597
673
|
onPaste: onSegmentPaste,
|
|
598
674
|
"data-active": showActiveSection && activeSection === section,
|
|
599
|
-
"data-testid": showActiveSection && activeSection === section ? 'time-input-active-section' : undefined,
|
|
600
675
|
"data-section": section
|
|
601
676
|
}, passThemeFlag, {
|
|
602
677
|
"aria-label": getSectionName(section, format, formatMessage, messages),
|
|
603
678
|
role: "spinbutton",
|
|
604
679
|
"aria-disabled": disabled || undefined,
|
|
605
680
|
"aria-readonly": readOnly || undefined,
|
|
606
|
-
"aria-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
"aria-valuemin": getSectionAriaMeta({
|
|
612
|
-
section: section,
|
|
613
|
-
format: format,
|
|
614
|
-
sections: sections
|
|
615
|
-
}).min,
|
|
616
|
-
"aria-valuemax": getSectionAriaMeta({
|
|
617
|
-
section: section,
|
|
618
|
-
format: format,
|
|
619
|
-
sections: sections
|
|
620
|
-
}).max,
|
|
681
|
+
"aria-invalid": ariaInvalid && describeSegment || undefined,
|
|
682
|
+
"aria-describedby": [consumerDescribedBy, describeSegment && hasErrorDescribedBy ? errorId : undefined].filter(Boolean).join(' ') || undefined,
|
|
683
|
+
"aria-valuenow": ariaMeta.now,
|
|
684
|
+
"aria-valuemin": ariaMeta.min,
|
|
685
|
+
"aria-valuemax": ariaMeta.max,
|
|
621
686
|
"aria-valuetext": getSectionValueAnnouncement(section)
|
|
622
687
|
}), text));
|
|
623
688
|
})), /*#__PURE__*/React.createElement(StyledTimeInput, _extends({
|
|
@@ -639,10 +704,9 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
639
704
|
type: "hidden",
|
|
640
705
|
value: value || ''
|
|
641
706
|
}), !readOnly && /*#__PURE__*/React.createElement(Button, {
|
|
642
|
-
|
|
643
|
-
|
|
707
|
+
kind: dropButtonKind,
|
|
708
|
+
icon: dropButtonIcon,
|
|
644
709
|
disabled: disabled,
|
|
645
|
-
margin: (_theme$timeInput2 = theme.timeInput) == null || (_theme$timeInput2 = _theme$timeInput2.button) == null ? void 0 : _theme$timeInput2.margin,
|
|
646
710
|
"aria-label": formatMessage({
|
|
647
711
|
id: 'timeInput.chooseTime',
|
|
648
712
|
messages: messages
|
|
@@ -652,6 +716,7 @@ var TimeInput = /*#__PURE__*/forwardRef(function (_ref2, refArg) {
|
|
|
652
716
|
"aria-controls": id ? id + "__drop" : undefined,
|
|
653
717
|
onFocus: function onFocus() {
|
|
654
718
|
setIconFocused(true);
|
|
719
|
+
setFieldFocusIndicator == null || setFieldFocusIndicator(false);
|
|
655
720
|
},
|
|
656
721
|
onBlur: function onBlur() {
|
|
657
722
|
setIconFocused(false);
|