grommet 2.55.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/Button/Button.js +7 -4
- package/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +86 -0
- 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/Grommet/index.d.ts +21 -0
- package/components/Grommet/propTypes.js +26 -0
- package/components/Stepper/StepConnector.js +38 -0
- package/components/Stepper/Stepper.js +303 -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 +137 -0
- package/components/Stepper/StyledStepper.js +162 -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 +692 -0
- package/components/TimeInput/TimeInputPopup.js +489 -0
- package/components/TimeInput/index.d.ts +44 -0
- package/components/TimeInput/index.js +6 -0
- package/components/TimeInput/propTypes.js +39 -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 +358 -0
- package/components/TimeInput/utils.js +192 -0
- 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 +6 -0
- package/components/index.js +24 -0
- package/es6/components/Button/Button.js +7 -4
- package/es6/components/Button/stories/CustomThemed/ChildrenPlainOption.stories.js +81 -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/Grommet/index.d.ts +21 -0
- package/es6/components/Grommet/propTypes.js +26 -0
- package/es6/components/Stepper/StepConnector.js +33 -0
- package/es6/components/Stepper/Stepper.js +301 -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 +133 -0
- package/es6/components/Stepper/StyledStepper.js +156 -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 +689 -0
- package/es6/components/TimeInput/TimeInputPopup.js +485 -0
- package/es6/components/TimeInput/index.d.ts +44 -0
- package/es6/components/TimeInput/index.js +1 -0
- package/es6/components/TimeInput/propTypes.js +33 -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 +355 -0
- package/es6/components/TimeInput/utils.js +187 -0
- 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 +6 -0
- package/es6/components/index.js +6 -0
- package/es6/index.d.ts +6 -0
- package/es6/languages/default.json +48 -0
- package/es6/themes/base.d.ts +223 -0
- package/es6/themes/base.js +366 -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 +6 -0
- package/languages/default.json +48 -0
- package/package.json +57 -52
- package/themes/base.d.ts +223 -0
- package/themes/base.js +366 -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
- 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,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box, TimeInput } from 'grommet';
|
|
4
|
+
|
|
5
|
+
export const ReadOnly = () => (
|
|
6
|
+
<Box pad="large" width="medium" gap="small">
|
|
7
|
+
<TimeInput format="12" defaultValue="09:45:10" readOnly />
|
|
8
|
+
</Box>
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Input/TimeInput/ReadOnly',
|
|
13
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box, TimeInput } from 'grommet';
|
|
4
|
+
|
|
5
|
+
export const Simple = () => {
|
|
6
|
+
const onChange = ({ value }: { value?: string }) => {
|
|
7
|
+
console.log('onChange iso time:', value);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Box pad="large" width="medium">
|
|
12
|
+
<TimeInput format="12" onChange={onChange} />
|
|
13
|
+
</Box>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
title: 'Input/TimeInput/Simple',
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box, Text, TimeInput } from 'grommet';
|
|
4
|
+
|
|
5
|
+
export const Step = () => (
|
|
6
|
+
<Box pad="large" width="medium" gap="small">
|
|
7
|
+
<Text size="small">Minute options increment by 15 (00, 15, 30, 45).</Text>
|
|
8
|
+
<TimeInput format="24" defaultValue="10:30:00" minuteStep={15} />
|
|
9
|
+
</Box>
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
title: 'Input/TimeInput/Step',
|
|
14
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box, Heading, ThemeContext, TimeInput } from 'grommet';
|
|
4
|
+
|
|
5
|
+
export const ThemingLightDark = () => (
|
|
6
|
+
<Box gap="xlarge">
|
|
7
|
+
<Box pad="xlarge" background="background-front">
|
|
8
|
+
<Heading level={3}>Light Theme</Heading>
|
|
9
|
+
<TimeInput format="12" defaultValue="12:34:56" />
|
|
10
|
+
</Box>
|
|
11
|
+
<ThemeContext.Extend value={{ dark: true }}>
|
|
12
|
+
<Box pad="xlarge" background="background-front">
|
|
13
|
+
<Heading level={3}>Dark Theme</Heading>
|
|
14
|
+
<TimeInput format="12" defaultValue="12:34:56" />
|
|
15
|
+
</Box>
|
|
16
|
+
</ThemeContext.Extend>
|
|
17
|
+
</Box>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
title: 'Input/TimeInput/Theming Light Dark',
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Box, Text, TimeInput } from 'grommet';
|
|
4
|
+
|
|
5
|
+
export const Uncontrolled = () => {
|
|
6
|
+
const onChange = ({ value }: { value?: string }) => {
|
|
7
|
+
console.log('onChange iso time:', value);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Box pad="large" width="medium" gap="small">
|
|
12
|
+
<Text size="small">
|
|
13
|
+
Uncontrolled input (manages its own internal state).
|
|
14
|
+
</Text>
|
|
15
|
+
<TimeInput format="12" defaultValue="12:34:56" onChange={onChange} />
|
|
16
|
+
</Box>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default {
|
|
21
|
+
title: 'Input/TimeInput/Uncontrolled',
|
|
22
|
+
};
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.useSectionedTimeField = void 0;
|
|
5
|
+
var _react = require("react");
|
|
6
|
+
var _useSectionedField2 = require("../../utils/useSectionedField");
|
|
7
|
+
var _utils = require("./utils");
|
|
8
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } // SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
/* eslint-disable no-nested-ternary */
|
|
11
|
+
var separatorBeforeSection = function separatorBeforeSection(section) {
|
|
12
|
+
return section === _utils.SECTION_PERIOD ? ' ' : ':';
|
|
13
|
+
};
|
|
14
|
+
var sectionToken = function sectionToken(section) {
|
|
15
|
+
if (section === _utils.SECTION_HOUR) return 'hh';
|
|
16
|
+
if (section === _utils.SECTION_MINUTE) return 'mm';
|
|
17
|
+
if (section === _utils.SECTION_SECOND) return 'ss';
|
|
18
|
+
return 'aa';
|
|
19
|
+
};
|
|
20
|
+
var sectionPattern = function sectionPattern(section) {
|
|
21
|
+
if (section === _utils.SECTION_PERIOD) return '(AM|PM)';
|
|
22
|
+
return '(\\d{1,2})';
|
|
23
|
+
};
|
|
24
|
+
var isNumericSection = function isNumericSection(section) {
|
|
25
|
+
return section !== _utils.SECTION_PERIOD;
|
|
26
|
+
};
|
|
27
|
+
var parseSectionsValue = function parseSectionsValue(value, format, sectionOrder) {
|
|
28
|
+
if (!value || typeof value !== 'string') return undefined;
|
|
29
|
+
var normalized = value.trim().toUpperCase();
|
|
30
|
+
if (!normalized || !sectionOrder.length) return undefined;
|
|
31
|
+
var pattern = sectionOrder.map(function (section, index) {
|
|
32
|
+
var sectionRegex = sectionPattern(section);
|
|
33
|
+
if (index === 0) return sectionRegex;
|
|
34
|
+
return separatorBeforeSection(section) + "\\s*" + sectionRegex;
|
|
35
|
+
}).join('');
|
|
36
|
+
var regex = new RegExp("^" + pattern + "$");
|
|
37
|
+
var match = normalized.match(regex);
|
|
38
|
+
if (!match) return undefined;
|
|
39
|
+
var parsed = (0, _utils.defaultSections)(format);
|
|
40
|
+
sectionOrder.forEach(function (section, index) {
|
|
41
|
+
var key = (0, _utils.sectionKey)(section);
|
|
42
|
+
var captured = match[index + 1];
|
|
43
|
+
if (section === _utils.SECTION_PERIOD) {
|
|
44
|
+
parsed[key] = captured;
|
|
45
|
+
} else {
|
|
46
|
+
var next = Number(captured);
|
|
47
|
+
if (!Number.isNaN(next)) parsed[key] = next;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
for (var i = 0; i < sectionOrder.length; i += 1) {
|
|
51
|
+
var section = sectionOrder[i];
|
|
52
|
+
if (isNumericSection(section)) {
|
|
53
|
+
var key = (0, _utils.sectionKey)(section);
|
|
54
|
+
var next = parsed[key];
|
|
55
|
+
if (next === undefined || next < (0, _utils.sectionMin)(section, format) || next > (0, _utils.sectionMax)(section, format)) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return parsed;
|
|
61
|
+
};
|
|
62
|
+
var formatSectionsValue = function formatSectionsValue(_ref) {
|
|
63
|
+
var sections = _ref.sections,
|
|
64
|
+
sectionOrder = _ref.sectionOrder,
|
|
65
|
+
_ref$includeTokens = _ref.includeTokens,
|
|
66
|
+
includeTokens = _ref$includeTokens === void 0 ? false : _ref$includeTokens;
|
|
67
|
+
return sectionOrder.map(function (section, index) {
|
|
68
|
+
var key = (0, _utils.sectionKey)(section);
|
|
69
|
+
var rawValue = sections[key];
|
|
70
|
+
var rendered = rawValue === undefined ? includeTokens ? sectionToken(section) : '' : section === _utils.SECTION_PERIOD ? rawValue : (0, _utils.pad)(rawValue);
|
|
71
|
+
if (index === 0) return rendered;
|
|
72
|
+
return "" + separatorBeforeSection(section) + rendered;
|
|
73
|
+
}).join('');
|
|
74
|
+
};
|
|
75
|
+
var useSectionedTimeField = exports.useSectionedTimeField = function useSectionedTimeField(_ref2) {
|
|
76
|
+
var format = _ref2.format,
|
|
77
|
+
sectionOrder = _ref2.sectionOrder,
|
|
78
|
+
_ref2$minuteStep = _ref2.minuteStep,
|
|
79
|
+
minuteStep = _ref2$minuteStep === void 0 ? 1 : _ref2$minuteStep,
|
|
80
|
+
value = _ref2.value,
|
|
81
|
+
onCommit = _ref2.onCommit,
|
|
82
|
+
onInvalid = _ref2.onInvalid;
|
|
83
|
+
var editStateRef = (0, _react.useRef)({
|
|
84
|
+
section: _utils.SECTION_HOUR,
|
|
85
|
+
digits: 0,
|
|
86
|
+
previousValue: undefined,
|
|
87
|
+
firstDigit: undefined
|
|
88
|
+
});
|
|
89
|
+
var parseValue = (0, _react.useCallback)(function (nextValue) {
|
|
90
|
+
return (0, _utils.isoTimeToSections)((0, _utils.normalizeToIsoTime)(nextValue), format);
|
|
91
|
+
}, [format]);
|
|
92
|
+
var getDefaultValue = (0, _react.useCallback)(function () {
|
|
93
|
+
return (0, _utils.defaultSections)(format);
|
|
94
|
+
}, [format]);
|
|
95
|
+
var _useSectionedField = (0, _useSectionedField2.useSectionedField)({
|
|
96
|
+
value: value,
|
|
97
|
+
parseValue: parseValue,
|
|
98
|
+
defaultValue: getDefaultValue,
|
|
99
|
+
sectionOrder: sectionOrder
|
|
100
|
+
}),
|
|
101
|
+
activeSection = _useSectionedField.activeSection,
|
|
102
|
+
pendingDigits = _useSectionedField.pendingDigits,
|
|
103
|
+
preserveIncompleteSectionsRef = _useSectionedField.preserveIncompleteSectionsRef,
|
|
104
|
+
sections = _useSectionedField.sections,
|
|
105
|
+
setActiveSection = _useSectionedField.setActiveSection,
|
|
106
|
+
setPendingDigits = _useSectionedField.setPendingDigits,
|
|
107
|
+
setSections = _useSectionedField.setSections;
|
|
108
|
+
var displayValue = (0, _react.useMemo)(function () {
|
|
109
|
+
if (!(0, _utils.hasAnyValue)(sections)) return '';
|
|
110
|
+
|
|
111
|
+
// Create a copy of sections with pending digits overlaid for display
|
|
112
|
+
var displaySections = _extends({}, sections);
|
|
113
|
+
var pendingSection = Object.keys(pendingDigits)[0];
|
|
114
|
+
if (pendingSection && pendingDigits[pendingSection] !== undefined) {
|
|
115
|
+
displaySections[pendingSection] = pendingDigits[pendingSection];
|
|
116
|
+
}
|
|
117
|
+
return formatSectionsValue({
|
|
118
|
+
sections: displaySections,
|
|
119
|
+
sectionOrder: sectionOrder,
|
|
120
|
+
includeTokens: true
|
|
121
|
+
});
|
|
122
|
+
}, [sectionOrder, sections, pendingDigits]);
|
|
123
|
+
var commitSections = (0, _react.useCallback)(function (nextSections, changedSection) {
|
|
124
|
+
var _nextSections$second;
|
|
125
|
+
setSections(nextSections);
|
|
126
|
+
var complete = sectionOrder.every(function (section) {
|
|
127
|
+
return nextSections[(0, _utils.sectionKey)(section)] !== undefined;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Check if all numeric sections are valid
|
|
131
|
+
var allValid = sectionOrder.every(function (section) {
|
|
132
|
+
if (!isNumericSection(section)) return true; // skip period
|
|
133
|
+
var key = (0, _utils.sectionKey)(section);
|
|
134
|
+
var sectionValue = nextSections[key];
|
|
135
|
+
var min = (0, _utils.sectionMin)(section, format);
|
|
136
|
+
var max = (0, _utils.sectionMax)(section, format);
|
|
137
|
+
return sectionValue >= min && sectionValue <= max;
|
|
138
|
+
});
|
|
139
|
+
var nextValue = complete && sectionOrder.length && allValid ? (0, _utils.sectionsToIsoTime)(_extends({}, nextSections, {
|
|
140
|
+
second: (_nextSections$second = nextSections.second) != null ? _nextSections$second : 0
|
|
141
|
+
}), format) : undefined;
|
|
142
|
+
|
|
143
|
+
// Mark as incomplete if: sections incomplete OR some invalid
|
|
144
|
+
var hasIncompleteSections = !complete || !allValid;
|
|
145
|
+
preserveIncompleteSectionsRef.current = hasIncompleteSections && (0, _utils.hasAnyValue)(nextSections);
|
|
146
|
+
onCommit(nextSections, nextValue, changedSection);
|
|
147
|
+
}, [format, onCommit, preserveIncompleteSectionsRef, sectionOrder, setSections]);
|
|
148
|
+
var setSectionValue = (0, _react.useCallback)(function (section, rawValue) {
|
|
149
|
+
var _extends2;
|
|
150
|
+
var key = (0, _utils.sectionKey)(section);
|
|
151
|
+
var next = _extends({}, sections, (_extends2 = {}, _extends2[key] = rawValue, _extends2));
|
|
152
|
+
commitSections(next, section);
|
|
153
|
+
// Clear any pending first-digit overlay, since it's now stale
|
|
154
|
+
// relative to the section value we just committed.
|
|
155
|
+
setPendingDigits({});
|
|
156
|
+
}, [commitSections, sections, setPendingDigits]);
|
|
157
|
+
var moveSection = (0, _react.useCallback)(function (direction) {
|
|
158
|
+
if (!sectionOrder.length) return activeSection;
|
|
159
|
+
var activeIndex = Math.max(0, sectionOrder.indexOf(activeSection));
|
|
160
|
+
var count = sectionOrder.length;
|
|
161
|
+
var nextIndex = (activeIndex + direction + count) % count;
|
|
162
|
+
var nextSection = sectionOrder[nextIndex];
|
|
163
|
+
setActiveSection(nextSection);
|
|
164
|
+
return nextSection;
|
|
165
|
+
}, [activeSection, sectionOrder, setActiveSection]);
|
|
166
|
+
var incrementSection = (0, _react.useCallback)(function (section, delta) {
|
|
167
|
+
if (section === _utils.SECTION_PERIOD) {
|
|
168
|
+
setSectionValue(section, sections.period === 'AM' ? 'PM' : 'AM');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
var minValue = (0, _utils.sectionMin)(section, format);
|
|
172
|
+
var maxValue = (0, _utils.sectionMax)(section, format);
|
|
173
|
+
var key = (0, _utils.sectionKey)(section);
|
|
174
|
+
var current = sections[key];
|
|
175
|
+
var step = section === _utils.SECTION_MINUTE ? minuteStep : section === _utils.SECTION_SECOND ? 1 : 1;
|
|
176
|
+
var next;
|
|
177
|
+
if (step > 1 && (section === _utils.SECTION_MINUTE || section === _utils.SECTION_SECOND)) {
|
|
178
|
+
var options = Array.from({
|
|
179
|
+
length: Math.ceil((maxValue - minValue + 1) / step)
|
|
180
|
+
}, function (_, index) {
|
|
181
|
+
return minValue + index * step;
|
|
182
|
+
}).filter(function (valueAtIndex) {
|
|
183
|
+
return valueAtIndex <= maxValue;
|
|
184
|
+
});
|
|
185
|
+
var currentIndex = options.indexOf(current);
|
|
186
|
+
if (currentIndex !== -1) {
|
|
187
|
+
var wrappedIndex = ((currentIndex + delta) % options.length + options.length) % options.length;
|
|
188
|
+
next = options[wrappedIndex];
|
|
189
|
+
} else if (delta > 0) {
|
|
190
|
+
var _options$find;
|
|
191
|
+
next = (_options$find = options.find(function (option) {
|
|
192
|
+
return option > (current != null ? current : minValue - 1);
|
|
193
|
+
})) != null ? _options$find : options[0];
|
|
194
|
+
} else {
|
|
195
|
+
var _descending$find;
|
|
196
|
+
var descending = [].concat(options).reverse();
|
|
197
|
+
next = (_descending$find = descending.find(function (option) {
|
|
198
|
+
return option < (current != null ? current : maxValue + 1);
|
|
199
|
+
})) != null ? _descending$find : options[options.length - 1];
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
var base = current === undefined ? section === _utils.SECTION_HOUR ? (0, _utils.defaultHourForFormat)(format) : minValue : current;
|
|
203
|
+
next = base + delta;
|
|
204
|
+
if (next > maxValue) next = minValue;
|
|
205
|
+
if (next < minValue) next = maxValue;
|
|
206
|
+
}
|
|
207
|
+
setSectionValue(section, next);
|
|
208
|
+
}, [format, minuteStep, sections, setSectionValue]);
|
|
209
|
+
var applyDigit = (0, _react.useCallback)(function (digit) {
|
|
210
|
+
if (activeSection === _utils.SECTION_PERIOD) return undefined;
|
|
211
|
+
var minValue = (0, _utils.sectionMin)(activeSection, format);
|
|
212
|
+
var maxValue = (0, _utils.sectionMax)(activeSection, format);
|
|
213
|
+
var key = (0, _utils.sectionKey)(activeSection);
|
|
214
|
+
var isSameSection = editStateRef.current.section === activeSection;
|
|
215
|
+
var isSecondDigit = isSameSection && editStateRef.current.digits === 1;
|
|
216
|
+
var currentRaw = sections[key] === undefined ? 0 : sections[key];
|
|
217
|
+
var nextValue;
|
|
218
|
+
if (isSecondDigit) {
|
|
219
|
+
var _editStateRef$current;
|
|
220
|
+
// Use the stored first digit from editState
|
|
221
|
+
var firstDigit = (_editStateRef$current = editStateRef.current.firstDigit) != null ? _editStateRef$current : currentRaw % 10;
|
|
222
|
+
nextValue = firstDigit * 10 + digit;
|
|
223
|
+
editStateRef.current = {
|
|
224
|
+
section: activeSection,
|
|
225
|
+
digits: 0,
|
|
226
|
+
previousValue: editStateRef.current.previousValue,
|
|
227
|
+
firstDigit: undefined
|
|
228
|
+
};
|
|
229
|
+
// Clear pending digits since we're committing now
|
|
230
|
+
setPendingDigits({});
|
|
231
|
+
} else {
|
|
232
|
+
var _setPendingDigits;
|
|
233
|
+
// First digit: store in pending for display only
|
|
234
|
+
nextValue = digit;
|
|
235
|
+
editStateRef.current = {
|
|
236
|
+
section: activeSection,
|
|
237
|
+
digits: 1,
|
|
238
|
+
previousValue: sections[key],
|
|
239
|
+
firstDigit: digit
|
|
240
|
+
};
|
|
241
|
+
// Show the first digit in pending state
|
|
242
|
+
setPendingDigits((_setPendingDigits = {}, _setPendingDigits[key] = digit, _setPendingDigits));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// For 2nd digit: validate combined value, but allow invalid 1st digit
|
|
246
|
+
// (allows "0X" patterns in formats where single "0" is invalid)
|
|
247
|
+
if (isSecondDigit && (nextValue < minValue || nextValue > maxValue)) {
|
|
248
|
+
var _editStateRef$current2;
|
|
249
|
+
// Combined value invalid. Try to use first digit for current section
|
|
250
|
+
// and apply second digit to next section (MUI behavior)
|
|
251
|
+
var _firstDigit = (_editStateRef$current2 = editStateRef.current.firstDigit) != null ? _editStateRef$current2 : currentRaw % 10;
|
|
252
|
+
if (_firstDigit >= minValue && _firstDigit <= maxValue) {
|
|
253
|
+
setSectionValue(activeSection, _firstDigit);
|
|
254
|
+
|
|
255
|
+
// Get next section and check if second digit is valid there
|
|
256
|
+
var currentSectionIndex = sectionOrder.indexOf(activeSection);
|
|
257
|
+
var nextSection = sectionOrder[currentSectionIndex + 1];
|
|
258
|
+
if (nextSection && isNumericSection(nextSection)) {
|
|
259
|
+
var nextMinValue = (0, _utils.sectionMin)(nextSection, format);
|
|
260
|
+
var nextMaxValue = (0, _utils.sectionMax)(nextSection, format);
|
|
261
|
+
|
|
262
|
+
// If second digit is valid for next section, apply it there
|
|
263
|
+
if (digit >= nextMinValue && digit <= nextMaxValue) {
|
|
264
|
+
setSectionValue(nextSection, digit);
|
|
265
|
+
// Now move to section after that
|
|
266
|
+
return moveSection(2);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// If second digit not valid for next section, just move to next
|
|
271
|
+
return moveSection(1);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// If even first digit alone is invalid, reject the entry
|
|
275
|
+
onInvalid == null || onInvalid();
|
|
276
|
+
setPendingDigits({});
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// MUI Pattern: Determine if we should commit and move to next section
|
|
281
|
+
// shouldGoToNextSection = nextValue * 10 > max || digitCount === 2
|
|
282
|
+
var shouldMoveToNextSection = nextValue * 10 > maxValue || isSecondDigit;
|
|
283
|
+
setSectionValue(activeSection, nextValue);
|
|
284
|
+
if (shouldMoveToNextSection) {
|
|
285
|
+
// Don't move past the last section during digit entry
|
|
286
|
+
// (Tab navigation can still wrap, but digit entry stops at last
|
|
287
|
+
// section)
|
|
288
|
+
var currentIndex = sectionOrder.indexOf(activeSection);
|
|
289
|
+
var isLastSection = currentIndex === sectionOrder.length - 1;
|
|
290
|
+
if (!isLastSection) {
|
|
291
|
+
return moveSection(1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return activeSection;
|
|
295
|
+
}, [activeSection, format, moveSection, onInvalid, sections, setSectionValue, setPendingDigits, sectionOrder]);
|
|
296
|
+
var clearActiveSection = (0, _react.useCallback)(function () {
|
|
297
|
+
setSectionValue(activeSection, undefined);
|
|
298
|
+
}, [activeSection, setSectionValue]);
|
|
299
|
+
var parsePasted = (0, _react.useCallback)(function (pasted) {
|
|
300
|
+
var parsed = parseSectionsValue(pasted, format, sectionOrder);
|
|
301
|
+
if (parsed) {
|
|
302
|
+
return parsed;
|
|
303
|
+
}
|
|
304
|
+
var digits = pasted.replace(/\D/g, '');
|
|
305
|
+
var numericSections = sectionOrder.filter(function (section) {
|
|
306
|
+
return section !== _utils.SECTION_PERIOD;
|
|
307
|
+
});
|
|
308
|
+
var hasExplicitPeriod = /\b(AM|PM)\b/i.test(pasted);
|
|
309
|
+
var shouldInferPeriod = format === '12' && sectionOrder.includes(_utils.SECTION_PERIOD) && !hasExplicitPeriod;
|
|
310
|
+
if (digits.length >= numericSections.length * 2 && numericSections.length) {
|
|
311
|
+
var next = _extends({}, sections);
|
|
312
|
+
for (var i = 0; i < numericSections.length; i += 1) {
|
|
313
|
+
var section = numericSections[i];
|
|
314
|
+
var parsedNumber = Number(digits.slice(i * 2, i * 2 + 2));
|
|
315
|
+
var minValue = section === _utils.SECTION_HOUR && shouldInferPeriod ? 0 : (0, _utils.sectionMin)(section, format);
|
|
316
|
+
var maxValue = section === _utils.SECTION_HOUR && shouldInferPeriod ? 23 : (0, _utils.sectionMax)(section, format);
|
|
317
|
+
if (Number.isNaN(parsedNumber) || parsedNumber < minValue || parsedNumber > maxValue) {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
next[(0, _utils.sectionKey)(section)] = parsedNumber;
|
|
321
|
+
}
|
|
322
|
+
if (sectionOrder.includes(_utils.SECTION_PERIOD)) {
|
|
323
|
+
if (hasExplicitPeriod) {
|
|
324
|
+
next.period = /\bPM\b/i.test(pasted) ? 'PM' : 'AM';
|
|
325
|
+
} else if (shouldInferPeriod) {
|
|
326
|
+
var normalizedHour = next.hour;
|
|
327
|
+
if (normalizedHour === 0) {
|
|
328
|
+
next.hour = 12;
|
|
329
|
+
next.period = 'AM';
|
|
330
|
+
} else if (normalizedHour === 12) {
|
|
331
|
+
next.period = 'PM';
|
|
332
|
+
} else if (normalizedHour > 12) {
|
|
333
|
+
next.hour = normalizedHour - 12;
|
|
334
|
+
next.period = 'PM';
|
|
335
|
+
} else {
|
|
336
|
+
next.period = 'AM';
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return next;
|
|
341
|
+
}
|
|
342
|
+
return undefined;
|
|
343
|
+
}, [format, sectionOrder, sections]);
|
|
344
|
+
return {
|
|
345
|
+
activeSection: activeSection,
|
|
346
|
+
clearActiveSection: clearActiveSection,
|
|
347
|
+
displayValue: displayValue,
|
|
348
|
+
incrementSection: incrementSection,
|
|
349
|
+
moveSection: moveSection,
|
|
350
|
+
parsePasted: parsePasted,
|
|
351
|
+
sections: sections,
|
|
352
|
+
setActiveSection: setActiveSection,
|
|
353
|
+
setSectionValue: setSectionValue,
|
|
354
|
+
applyDigit: applyDigit,
|
|
355
|
+
commitSections: commitSections,
|
|
356
|
+
pendingDigits: pendingDigits
|
|
357
|
+
};
|
|
358
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.sectionsToIsoTime = exports.sectionTypeFromSection = exports.sectionMin = exports.sectionMax = exports.sectionKey = exports.parseTime = exports.normalizeToIsoTime = exports.isoTimeToSections = exports.hasAnyValue = exports.getSectionName = exports.getSectionAriaMeta = exports.getRanges = exports.getActiveSectionAriaMeta = exports.formatTime = exports.defaultSections = exports.defaultHourForFormat = exports.SECTION_SECOND = exports.SECTION_PERIOD = exports.SECTION_MINUTE = exports.SECTION_HOUR = exports.ISO_TIME_REGEX = void 0;
|
|
5
|
+
var _sectionHelpers = require("../../utils/sectionHelpers");
|
|
6
|
+
var _dates = require("../../utils/dates");
|
|
7
|
+
exports.pad = _dates.pad;
|
|
8
|
+
// SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
var SECTION_HOUR = exports.SECTION_HOUR = 0;
|
|
12
|
+
var SECTION_MINUTE = exports.SECTION_MINUTE = 1;
|
|
13
|
+
var SECTION_SECOND = exports.SECTION_SECOND = 2;
|
|
14
|
+
var SECTION_PERIOD = exports.SECTION_PERIOD = 3;
|
|
15
|
+
var sectionTypeFromSection = exports.sectionTypeFromSection = function sectionTypeFromSection(section) {
|
|
16
|
+
if (section === SECTION_HOUR) return 'hours';
|
|
17
|
+
if (section === SECTION_MINUTE) return 'minutes';
|
|
18
|
+
if (section === SECTION_SECOND) return 'seconds';
|
|
19
|
+
return 'meridiem';
|
|
20
|
+
};
|
|
21
|
+
var getSectionName = exports.getSectionName = function getSectionName(section, format, formatMessage, messages) {
|
|
22
|
+
var sectionType = sectionTypeFromSection(section);
|
|
23
|
+
var sectionName = (0, _sectionHelpers.getSectionNameFromType)({
|
|
24
|
+
sectionType: sectionType,
|
|
25
|
+
messagePrefix: 'timeInput',
|
|
26
|
+
formatMessage: formatMessage,
|
|
27
|
+
messages: messages
|
|
28
|
+
});
|
|
29
|
+
if (format !== '12' && sectionType === 'meridiem') return undefined;
|
|
30
|
+
return sectionName;
|
|
31
|
+
};
|
|
32
|
+
var getRanges = exports.getRanges = function getRanges(format) {
|
|
33
|
+
if (format === '12') {
|
|
34
|
+
return [[0, 2], [3, 5], [6, 8], [9, 11]];
|
|
35
|
+
}
|
|
36
|
+
return [[0, 2], [3, 5], [6, 8]];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// TimeInput always transacts (value/defaultValue/onChange) in a canonical
|
|
40
|
+
// 24-hour ISO time string ("HH:MM:SS"), regardless of the display `format`
|
|
41
|
+
// prop.
|
|
42
|
+
var ISO_TIME_REGEX = exports.ISO_TIME_REGEX = /^([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/;
|
|
43
|
+
var normalizeToIsoTime = exports.normalizeToIsoTime = function normalizeToIsoTime(value) {
|
|
44
|
+
if (typeof value !== 'string' || !value.trim()) return undefined;
|
|
45
|
+
var trimmed = value.trim();
|
|
46
|
+
if (ISO_TIME_REGEX.test(trimmed)) return trimmed;
|
|
47
|
+
var parsed = new Date(trimmed);
|
|
48
|
+
if (Number.isNaN(parsed.getTime())) return undefined;
|
|
49
|
+
return (0, _dates.pad)(parsed.getHours()) + ":" + (0, _dates.pad)(parsed.getMinutes()) + ":" + (0, _dates.pad)(parsed.getSeconds());
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Converts a canonical 24-hour ISO time string into the section shape the
|
|
53
|
+
// sectioned editor uses for display, deriving 12-hour + period fields when
|
|
54
|
+
// needed.
|
|
55
|
+
var isoTimeToSections = exports.isoTimeToSections = function isoTimeToSections(isoTime, format) {
|
|
56
|
+
if (typeof isoTime !== 'string') return undefined;
|
|
57
|
+
var match = isoTime.match(ISO_TIME_REGEX);
|
|
58
|
+
if (!match) return undefined;
|
|
59
|
+
var hour24 = Number(match[1]);
|
|
60
|
+
var minute = Number(match[2]);
|
|
61
|
+
var second = Number(match[3]);
|
|
62
|
+
if (format === '12') {
|
|
63
|
+
var period = hour24 < 12 ? 'AM' : 'PM';
|
|
64
|
+
var hour = hour24 % 12 || 12;
|
|
65
|
+
return {
|
|
66
|
+
hour: hour,
|
|
67
|
+
minute: minute,
|
|
68
|
+
second: second,
|
|
69
|
+
period: period
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
hour: hour24,
|
|
74
|
+
minute: minute,
|
|
75
|
+
second: second
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
var sectionsToIsoTime = exports.sectionsToIsoTime = function sectionsToIsoTime(sections, format) {
|
|
79
|
+
if (sections.hour === undefined || sections.minute === undefined || sections.second === undefined) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
var hour24 = sections.hour;
|
|
83
|
+
if (format === '12') {
|
|
84
|
+
var period = sections.period || 'AM';
|
|
85
|
+
hour24 = sections.hour % 12;
|
|
86
|
+
if (period === 'PM') hour24 += 12;
|
|
87
|
+
}
|
|
88
|
+
return (0, _dates.pad)(hour24) + ":" + (0, _dates.pad)(sections.minute) + ":" + (0, _dates.pad)(sections.second);
|
|
89
|
+
};
|
|
90
|
+
var parseTime = exports.parseTime = function parseTime(value, format) {
|
|
91
|
+
if (!value || typeof value !== 'string') return undefined;
|
|
92
|
+
var trimmed = value.trim().toUpperCase();
|
|
93
|
+
if (format === '12') {
|
|
94
|
+
var _match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})\s*(AM|PM)$/);
|
|
95
|
+
if (!_match) return undefined;
|
|
96
|
+
var _hour = Number(_match[1]);
|
|
97
|
+
var _minute = Number(_match[2]);
|
|
98
|
+
var _second = Number(_match[3]);
|
|
99
|
+
var period = _match[4];
|
|
100
|
+
if (Number.isNaN(_hour) || Number.isNaN(_minute) || Number.isNaN(_second) || _hour < 1 || _hour > 12 || _minute < 0 || _minute > 59 || _second < 0 || _second > 59) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
hour: _hour,
|
|
105
|
+
minute: _minute,
|
|
106
|
+
second: _second,
|
|
107
|
+
period: period
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
var match = trimmed.match(/^(\d{1,2}):(\d{2}):(\d{2})$/);
|
|
111
|
+
if (!match) return undefined;
|
|
112
|
+
var hour = Number(match[1]);
|
|
113
|
+
var minute = Number(match[2]);
|
|
114
|
+
var second = Number(match[3]);
|
|
115
|
+
if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || hour < 0 || hour > 23 || minute < 0 || minute > 59 || second < 0 || second > 59) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
hour: hour,
|
|
120
|
+
minute: minute,
|
|
121
|
+
second: second
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
var formatTime = exports.formatTime = function formatTime(time, format) {
|
|
125
|
+
if (!time) return undefined;
|
|
126
|
+
if (format === '12') {
|
|
127
|
+
return (0, _dates.pad)(time.hour) + ":" + (0, _dates.pad)(time.minute) + ":" + (0, _dates.pad)(time.second) + " " + (time.period || 'AM');
|
|
128
|
+
}
|
|
129
|
+
return (0, _dates.pad)(time.hour) + ":" + (0, _dates.pad)(time.minute) + ":" + (0, _dates.pad)(time.second);
|
|
130
|
+
};
|
|
131
|
+
var defaultSections = exports.defaultSections = function defaultSections(format) {
|
|
132
|
+
return format === '12' ? {
|
|
133
|
+
hour: undefined,
|
|
134
|
+
minute: undefined,
|
|
135
|
+
second: undefined,
|
|
136
|
+
period: undefined
|
|
137
|
+
} : {
|
|
138
|
+
hour: undefined,
|
|
139
|
+
minute: undefined,
|
|
140
|
+
second: undefined
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
var hasAnyValue = exports.hasAnyValue = function hasAnyValue(sections) {
|
|
144
|
+
return sections.hour !== undefined || sections.minute !== undefined || sections.second !== undefined || sections.period !== undefined;
|
|
145
|
+
};
|
|
146
|
+
var sectionMax = exports.sectionMax = function sectionMax(section, format) {
|
|
147
|
+
if (section === SECTION_HOUR) return format === '12' ? 12 : 23;
|
|
148
|
+
return 59;
|
|
149
|
+
};
|
|
150
|
+
var sectionMin = exports.sectionMin = function sectionMin(section, format) {
|
|
151
|
+
if (section === SECTION_HOUR) return format === '12' ? 1 : 0;
|
|
152
|
+
return 0;
|
|
153
|
+
};
|
|
154
|
+
var defaultHourForFormat = exports.defaultHourForFormat = function defaultHourForFormat(format) {
|
|
155
|
+
return format === '12' ? 12 : 0;
|
|
156
|
+
};
|
|
157
|
+
var sectionKey = exports.sectionKey = function sectionKey(section) {
|
|
158
|
+
var sectionType = sectionTypeFromSection(section);
|
|
159
|
+
return (0, _sectionHelpers.getSectionKeyFromType)(sectionType);
|
|
160
|
+
};
|
|
161
|
+
var getSectionAriaMeta = exports.getSectionAriaMeta = function getSectionAriaMeta(_ref) {
|
|
162
|
+
var _sections$key;
|
|
163
|
+
var section = _ref.section,
|
|
164
|
+
format = _ref.format,
|
|
165
|
+
sections = _ref.sections;
|
|
166
|
+
if (section === SECTION_PERIOD) {
|
|
167
|
+
return {
|
|
168
|
+
now: sections.period === 'PM' ? 1 : 0,
|
|
169
|
+
min: 0,
|
|
170
|
+
max: 1
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var key = sectionKey(section);
|
|
174
|
+
var min = sectionMin(section, format);
|
|
175
|
+
var max = sectionMax(section, format);
|
|
176
|
+
var now = (_sections$key = sections[key]) != null ? _sections$key : section === SECTION_HOUR ? defaultHourForFormat(format) : min;
|
|
177
|
+
return {
|
|
178
|
+
now: now,
|
|
179
|
+
min: min,
|
|
180
|
+
max: max
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
var getActiveSectionAriaMeta = exports.getActiveSectionAriaMeta = function getActiveSectionAriaMeta(_ref2) {
|
|
184
|
+
var activeSection = _ref2.activeSection,
|
|
185
|
+
format = _ref2.format,
|
|
186
|
+
sections = _ref2.sections;
|
|
187
|
+
return getSectionAriaMeta({
|
|
188
|
+
section: activeSection,
|
|
189
|
+
format: format,
|
|
190
|
+
sections: sections
|
|
191
|
+
});
|
|
192
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.StyledWizardFocusAnchor = void 0;
|
|
5
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
6
|
+
var _utils = require("../../utils");
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
8
|
+
// SPDX-FileCopyrightText: © Hewlett Packard Enterprise Development LP
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
// Programmatic focus target for step transitions (tabIndex={-1}); no visible
|
|
12
|
+
// focus indication — screen readers announce via aria-live on this element.
|
|
13
|
+
var StyledWizardFocusAnchor = exports.StyledWizardFocusAnchor = _styledComponents["default"].div.withConfig(_utils.styledComponentsConfig).withConfig({
|
|
14
|
+
displayName: "StyledWizard__StyledWizardFocusAnchor",
|
|
15
|
+
componentId: "sc-1o4qqu4-0"
|
|
16
|
+
})(["outline:none;"]);
|