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
|
@@ -0,0 +1,1093 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.DateTimeInput = void 0;
|
|
5
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
6
|
+
var _Calendar = require("grommet-icons/icons/Calendar");
|
|
7
|
+
var _AnnounceContext = require("../../contexts/AnnounceContext");
|
|
8
|
+
var _MessageContext = require("../../contexts/MessageContext");
|
|
9
|
+
var _dates = require("../../utils/dates");
|
|
10
|
+
var _utils = require("../../utils");
|
|
11
|
+
var _useSectionedField2 = require("../../utils/useSectionedField");
|
|
12
|
+
var _useThemeValue2 = require("../../utils/useThemeValue");
|
|
13
|
+
var _Box = require("../Box");
|
|
14
|
+
var _Button = require("../Button");
|
|
15
|
+
var _Calendar2 = require("../Calendar");
|
|
16
|
+
var _Drop = require("../Drop");
|
|
17
|
+
var _Form = require("../Form");
|
|
18
|
+
var _Keyboard = require("../Keyboard");
|
|
19
|
+
var _TimeInput = require("../TimeInput");
|
|
20
|
+
var _utils2 = require("../TimeInput/utils");
|
|
21
|
+
var _sectionHelpers = require("../../utils/sectionHelpers");
|
|
22
|
+
var _StyledDateTimeInput = require("./StyledDateTimeInput");
|
|
23
|
+
var _propTypes = require("./propTypes");
|
|
24
|
+
var _excluded = ["defaultValue", "disabled", "format", "id", "inline", "locale", "messages", "minuteStep", "name", "onChange", "plain", "focusIndicator", "readOnly", "showSeconds", "value"];
|
|
25
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
26
|
+
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; }
|
|
27
|
+
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
|
|
28
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
29
|
+
var SECTION_DAY = 0;
|
|
30
|
+
var SECTION_MONTH = 1;
|
|
31
|
+
var SECTION_YEAR = 2;
|
|
32
|
+
var SECTION_HOUR = 3;
|
|
33
|
+
var SECTION_MINUTE = 4;
|
|
34
|
+
var SECTION_SECOND = 5;
|
|
35
|
+
var SECTION_PERIOD = 6;
|
|
36
|
+
var pad4 = function pad4(value) {
|
|
37
|
+
return String(value).padStart(4, '0');
|
|
38
|
+
};
|
|
39
|
+
var getDaysInMonth = function getDaysInMonth(year, month) {
|
|
40
|
+
return new Date(year, month, 0).getDate();
|
|
41
|
+
};
|
|
42
|
+
var sectionTypeFromSection = function sectionTypeFromSection(section) {
|
|
43
|
+
if (section === SECTION_DAY) return 'day';
|
|
44
|
+
if (section === SECTION_MONTH) return 'month';
|
|
45
|
+
if (section === SECTION_YEAR) return 'year';
|
|
46
|
+
if (section === SECTION_HOUR) return 'hours';
|
|
47
|
+
if (section === SECTION_MINUTE) return 'minutes';
|
|
48
|
+
if (section === SECTION_SECOND) return 'seconds';
|
|
49
|
+
return 'meridiem';
|
|
50
|
+
};
|
|
51
|
+
var defaultSections = function defaultSections(format, showSeconds) {
|
|
52
|
+
var base = _extends({
|
|
53
|
+
day: undefined,
|
|
54
|
+
month: undefined,
|
|
55
|
+
year: undefined,
|
|
56
|
+
hour: undefined,
|
|
57
|
+
minute: undefined
|
|
58
|
+
}, showSeconds ? {
|
|
59
|
+
second: undefined
|
|
60
|
+
} : {});
|
|
61
|
+
if (format === '12') {
|
|
62
|
+
return _extends({}, base, {
|
|
63
|
+
period: undefined
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return base;
|
|
67
|
+
};
|
|
68
|
+
var hasAnyValue = function hasAnyValue(sections) {
|
|
69
|
+
return sections.day !== undefined || sections.month !== undefined || sections.year !== undefined || sections.hour !== undefined || sections.minute !== undefined || sections.second !== undefined || sections.period !== undefined;
|
|
70
|
+
};
|
|
71
|
+
var sectionForPart = function sectionForPart(partType) {
|
|
72
|
+
if (partType === 'day') return SECTION_DAY;
|
|
73
|
+
if (partType === 'month') return SECTION_MONTH;
|
|
74
|
+
if (partType === 'year') return SECTION_YEAR;
|
|
75
|
+
if (partType === 'hour') return SECTION_HOUR;
|
|
76
|
+
if (partType === 'minute') return SECTION_MINUTE;
|
|
77
|
+
if (partType === 'second') return SECTION_SECOND;
|
|
78
|
+
if (partType === 'dayPeriod') return SECTION_PERIOD;
|
|
79
|
+
return undefined;
|
|
80
|
+
};
|
|
81
|
+
var getSectionOrder = function getSectionOrder(format, showSeconds) {
|
|
82
|
+
var timeSections = showSeconds ? [SECTION_HOUR, SECTION_MINUTE, SECTION_SECOND] : [SECTION_HOUR, SECTION_MINUTE];
|
|
83
|
+
if (format === '12') {
|
|
84
|
+
return [SECTION_DAY, SECTION_MONTH, SECTION_YEAR].concat(timeSections, [SECTION_PERIOD]);
|
|
85
|
+
}
|
|
86
|
+
return [SECTION_DAY, SECTION_MONTH, SECTION_YEAR].concat(timeSections);
|
|
87
|
+
};
|
|
88
|
+
var separatorBeforeSection = function separatorBeforeSection(section) {
|
|
89
|
+
if (section === SECTION_MONTH || section === SECTION_YEAR) return '/';
|
|
90
|
+
if (section === SECTION_HOUR) return ' ';
|
|
91
|
+
if (section === SECTION_MINUTE || section === SECTION_SECOND) return ':';
|
|
92
|
+
return ' ';
|
|
93
|
+
};
|
|
94
|
+
var getLocaleSectionLayout = function getLocaleSectionLayout(format, showSeconds, locale) {
|
|
95
|
+
var fallbackOrder = getSectionOrder(format, showSeconds);
|
|
96
|
+
var fallbackPrefixes = {};
|
|
97
|
+
fallbackOrder.forEach(function (section, index) {
|
|
98
|
+
fallbackPrefixes[section] = index === 0 ? '' : separatorBeforeSection(section);
|
|
99
|
+
});
|
|
100
|
+
try {
|
|
101
|
+
var formatter = new Intl.DateTimeFormat(locale || undefined, _extends({
|
|
102
|
+
year: 'numeric',
|
|
103
|
+
month: '2-digit',
|
|
104
|
+
day: '2-digit',
|
|
105
|
+
hour: '2-digit',
|
|
106
|
+
minute: '2-digit'
|
|
107
|
+
}, showSeconds ? {
|
|
108
|
+
second: '2-digit'
|
|
109
|
+
} : {}, {
|
|
110
|
+
hour12: format === '12'
|
|
111
|
+
}));
|
|
112
|
+
var parts = formatter.formatToParts(new Date());
|
|
113
|
+
var seen = new Set();
|
|
114
|
+
var sectionOrder = [];
|
|
115
|
+
var separatorMap = {};
|
|
116
|
+
var pendingLiteral = '';
|
|
117
|
+
parts.forEach(function (part) {
|
|
118
|
+
if (part.type === 'literal') {
|
|
119
|
+
pendingLiteral += part.value;
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var section = sectionForPart(part.type);
|
|
123
|
+
if (section === undefined) return;
|
|
124
|
+
if (section === SECTION_PERIOD && format !== '12') return;
|
|
125
|
+
if (section === SECTION_SECOND && !showSeconds) return;
|
|
126
|
+
if (!seen.has(section)) {
|
|
127
|
+
// Normalize the date/time boundary separator: strip commas (e.g. ", "
|
|
128
|
+
// from en-US) so the display matches the design spec (space only).
|
|
129
|
+
var raw = sectionOrder.length === 0 ? '' : pendingLiteral;
|
|
130
|
+
separatorMap[section] = section === SECTION_HOUR ? raw.replace(/,/g, '').trimStart() || ' ' : raw;
|
|
131
|
+
sectionOrder.push(section);
|
|
132
|
+
seen.add(section);
|
|
133
|
+
}
|
|
134
|
+
pendingLiteral = '';
|
|
135
|
+
});
|
|
136
|
+
fallbackOrder.forEach(function (section) {
|
|
137
|
+
if (!seen.has(section)) {
|
|
138
|
+
separatorMap[section] = sectionOrder.length === 0 ? '' : separatorBeforeSection(section);
|
|
139
|
+
sectionOrder.push(section);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
sectionOrder: sectionOrder,
|
|
144
|
+
separatorMap: separatorMap
|
|
145
|
+
};
|
|
146
|
+
} catch (_unused) {
|
|
147
|
+
return {
|
|
148
|
+
sectionOrder: fallbackOrder,
|
|
149
|
+
separatorMap: fallbackPrefixes
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
var getLocaleTimeFormat = function getLocaleTimeFormat(locale) {
|
|
154
|
+
try {
|
|
155
|
+
var _Intl$DateTimeFormat$ = new Intl.DateTimeFormat(locale || undefined, {
|
|
156
|
+
hour: 'numeric'
|
|
157
|
+
}).resolvedOptions(),
|
|
158
|
+
hour12 = _Intl$DateTimeFormat$.hour12;
|
|
159
|
+
return hour12 === false ? '24' : '12';
|
|
160
|
+
} catch (_unused2) {
|
|
161
|
+
return '12';
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
var toLocalSections = function toLocalSections(value, format) {
|
|
165
|
+
if (!value || typeof value !== 'string') return undefined;
|
|
166
|
+
var parsed = new Date(value);
|
|
167
|
+
if (Number.isNaN(parsed.getTime())) return undefined;
|
|
168
|
+
var year = parsed.getFullYear();
|
|
169
|
+
var month = parsed.getMonth() + 1;
|
|
170
|
+
var day = parsed.getDate();
|
|
171
|
+
var hour24 = parsed.getHours();
|
|
172
|
+
var minute = parsed.getMinutes();
|
|
173
|
+
var second = parsed.getSeconds();
|
|
174
|
+
if (format === '12') {
|
|
175
|
+
var period = hour24 < 12 ? 'AM' : 'PM';
|
|
176
|
+
var hour = hour24 % 12 || 12;
|
|
177
|
+
return {
|
|
178
|
+
day: day,
|
|
179
|
+
month: month,
|
|
180
|
+
year: year,
|
|
181
|
+
hour: hour,
|
|
182
|
+
minute: minute,
|
|
183
|
+
second: second,
|
|
184
|
+
period: period
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
day: day,
|
|
189
|
+
month: month,
|
|
190
|
+
year: year,
|
|
191
|
+
hour: hour24,
|
|
192
|
+
minute: minute,
|
|
193
|
+
second: second
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
var toUtcISOString = function toUtcISOString(sections, format, showSeconds) {
|
|
197
|
+
var day = sections.day,
|
|
198
|
+
month = sections.month,
|
|
199
|
+
year = sections.year,
|
|
200
|
+
hour = sections.hour,
|
|
201
|
+
minute = sections.minute,
|
|
202
|
+
second = sections.second,
|
|
203
|
+
_sections$period = sections.period,
|
|
204
|
+
period = _sections$period === void 0 ? 'AM' : _sections$period;
|
|
205
|
+
if (day === undefined || month === undefined || year === undefined || hour === undefined || minute === undefined || showSeconds && second === undefined) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
var hour24 = hour;
|
|
209
|
+
if (format === '12') {
|
|
210
|
+
hour24 = hour % 12;
|
|
211
|
+
if (period === 'PM') hour24 += 12;
|
|
212
|
+
}
|
|
213
|
+
var daysInMonth = getDaysInMonth(year, month);
|
|
214
|
+
if (day < 1 || day > daysInMonth) return undefined;
|
|
215
|
+
var resolvedSecond = showSeconds ? second : second != null ? second : 0;
|
|
216
|
+
var candidate = new Date(year, month - 1, day, hour24, minute, resolvedSecond, 0);
|
|
217
|
+
if (candidate.getFullYear() !== year || candidate.getMonth() + 1 !== month || candidate.getDate() !== day) {
|
|
218
|
+
return undefined;
|
|
219
|
+
}
|
|
220
|
+
return candidate.toISOString();
|
|
221
|
+
};
|
|
222
|
+
var getCalendarDate = function getCalendarDate(sections) {
|
|
223
|
+
var day = sections.day,
|
|
224
|
+
month = sections.month,
|
|
225
|
+
year = sections.year;
|
|
226
|
+
if (day === undefined || month === undefined || year === undefined) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
var daysInMonth = getDaysInMonth(year, month);
|
|
230
|
+
if (day < 1 || day > daysInMonth) return undefined;
|
|
231
|
+
|
|
232
|
+
// Calendar selection should persist even before time sections are complete.
|
|
233
|
+
return pad4(year) + "-" + (0, _dates.pad)(month) + "-" + (0, _dates.pad)(day);
|
|
234
|
+
};
|
|
235
|
+
var parseCalendarSelection = function parseCalendarSelection(nextValue) {
|
|
236
|
+
if (!nextValue) return undefined;
|
|
237
|
+
var nextDate = Array.isArray(nextValue) ? nextValue[0] : nextValue;
|
|
238
|
+
if (!nextDate || typeof nextDate !== 'string') return undefined;
|
|
239
|
+
var match = /^(\d{4})-(\d{2})-(\d{2})/.exec(nextDate);
|
|
240
|
+
if (match) {
|
|
241
|
+
return {
|
|
242
|
+
year: Number(match[1]),
|
|
243
|
+
month: Number(match[2]),
|
|
244
|
+
day: Number(match[3])
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
var parsed = new Date(nextDate);
|
|
248
|
+
if (Number.isNaN(parsed.getTime())) return undefined;
|
|
249
|
+
return {
|
|
250
|
+
year: parsed.getFullYear(),
|
|
251
|
+
month: parsed.getMonth() + 1,
|
|
252
|
+
day: parsed.getDate()
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
var getSeededTimeSections = function getSeededTimeSections(sections, format, showSeconds) {
|
|
256
|
+
var _sections$hour, _sections$minute, _sections$second, _sections$period2;
|
|
257
|
+
var hourMin = (0, _utils2.defaultHourForFormat)(format);
|
|
258
|
+
return _extends({
|
|
259
|
+
hour: (_sections$hour = sections.hour) != null ? _sections$hour : hourMin,
|
|
260
|
+
minute: (_sections$minute = sections.minute) != null ? _sections$minute : 0
|
|
261
|
+
}, showSeconds ? {
|
|
262
|
+
second: (_sections$second = sections.second) != null ? _sections$second : 0
|
|
263
|
+
} : {}, format === '12' ? {
|
|
264
|
+
period: (_sections$period2 = sections.period) != null ? _sections$period2 : 'AM'
|
|
265
|
+
} : {});
|
|
266
|
+
};
|
|
267
|
+
var hasCompleteDateSections = function hasCompleteDateSections(sections) {
|
|
268
|
+
return sections.day !== undefined && sections.month !== undefined && sections.year !== undefined;
|
|
269
|
+
};
|
|
270
|
+
var getSeededDateSections = function getSeededDateSections(sections) {
|
|
271
|
+
if (hasCompleteDateSections(sections)) {
|
|
272
|
+
return {
|
|
273
|
+
day: sections.day,
|
|
274
|
+
month: sections.month,
|
|
275
|
+
year: sections.year
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
var today = new Date();
|
|
279
|
+
return {
|
|
280
|
+
day: today.getDate(),
|
|
281
|
+
month: today.getMonth() + 1,
|
|
282
|
+
year: today.getFullYear()
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
var getSectionName = function getSectionName(section, formatMessage, messages) {
|
|
286
|
+
var sectionType = sectionTypeFromSection(section);
|
|
287
|
+
return (0, _sectionHelpers.getSectionNameFromType)({
|
|
288
|
+
sectionType: sectionType,
|
|
289
|
+
messagePrefix: 'dateTimeInput',
|
|
290
|
+
formatMessage: formatMessage,
|
|
291
|
+
messages: messages
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
var getSectionLimits = function getSectionLimits(section, format, sections) {
|
|
295
|
+
if (section === SECTION_DAY) {
|
|
296
|
+
var year = sections.year || new Date().getFullYear();
|
|
297
|
+
var month = sections.month || 1;
|
|
298
|
+
return {
|
|
299
|
+
min: 1,
|
|
300
|
+
max: getDaysInMonth(year, month)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (section === SECTION_MONTH) return {
|
|
304
|
+
min: 1,
|
|
305
|
+
max: 12
|
|
306
|
+
};
|
|
307
|
+
if (section === SECTION_YEAR) return {
|
|
308
|
+
min: 1,
|
|
309
|
+
max: 9999
|
|
310
|
+
};
|
|
311
|
+
if (section === SECTION_HOUR) return {
|
|
312
|
+
min: format === '12' ? 1 : 0,
|
|
313
|
+
max: format === '12' ? 12 : 23
|
|
314
|
+
};
|
|
315
|
+
if (section === SECTION_PERIOD) return {
|
|
316
|
+
min: 0,
|
|
317
|
+
max: 1
|
|
318
|
+
};
|
|
319
|
+
return {
|
|
320
|
+
min: 0,
|
|
321
|
+
max: 59
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
var digitsPerSection = function digitsPerSection(section) {
|
|
325
|
+
if (section === SECTION_YEAR) return 4;
|
|
326
|
+
if (section === SECTION_PERIOD) return 0;
|
|
327
|
+
return 2;
|
|
328
|
+
};
|
|
329
|
+
var formatSectionText = function formatSectionText(section, value) {
|
|
330
|
+
if (value === undefined || value === '') return (0, _sectionHelpers.getSectionTokenFromType)(sectionTypeFromSection(section));
|
|
331
|
+
if (section === SECTION_YEAR) return pad4(value);
|
|
332
|
+
if (section === SECTION_PERIOD) return value;
|
|
333
|
+
return (0, _dates.pad)(value);
|
|
334
|
+
};
|
|
335
|
+
var DateTimeInput = exports.DateTimeInput = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, refArg) {
|
|
336
|
+
var _theme$dateTimeInput, _theme$global$edgeSiz, _theme$global$edgeSiz2, _theme$dateTimeInput2, _theme$dateTimeInput3, _theme$dateTimeInput4, _theme$dateTimeInput5, _theme$dateTimeInput6, _theme$dateTimeInput7, _theme$dateTimeInput8;
|
|
337
|
+
var defaultValue = _ref.defaultValue,
|
|
338
|
+
disabled = _ref.disabled,
|
|
339
|
+
format = _ref.format,
|
|
340
|
+
id = _ref.id,
|
|
341
|
+
_ref$inline = _ref.inline,
|
|
342
|
+
inline = _ref$inline === void 0 ? false : _ref$inline,
|
|
343
|
+
locale = _ref.locale,
|
|
344
|
+
messages = _ref.messages,
|
|
345
|
+
_ref$minuteStep = _ref.minuteStep,
|
|
346
|
+
minuteStep = _ref$minuteStep === void 0 ? 1 : _ref$minuteStep,
|
|
347
|
+
name = _ref.name,
|
|
348
|
+
onChange = _ref.onChange,
|
|
349
|
+
plainProp = _ref.plain,
|
|
350
|
+
focusIndicatorProp = _ref.focusIndicator,
|
|
351
|
+
_ref$readOnly = _ref.readOnly,
|
|
352
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
353
|
+
_ref$showSeconds = _ref.showSeconds,
|
|
354
|
+
showSeconds = _ref$showSeconds === void 0 ? false : _ref$showSeconds,
|
|
355
|
+
valueArg = _ref.value,
|
|
356
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
357
|
+
var _useThemeValue = (0, _useThemeValue2.useThemeValue)(),
|
|
358
|
+
theme = _useThemeValue.theme,
|
|
359
|
+
passThemeFlag = _useThemeValue.passThemeFlag;
|
|
360
|
+
var announce = (0, _react.useContext)(_AnnounceContext.AnnounceContext);
|
|
361
|
+
var _useContext = (0, _react.useContext)(_MessageContext.MessageContext),
|
|
362
|
+
formatMessage = _useContext.format;
|
|
363
|
+
var formContext = (0, _react.useContext)(_Form.FormContext);
|
|
364
|
+
var useFormInput = formContext.useFormInput;
|
|
365
|
+
var resolvedFormat = (0, _react.useMemo)(function () {
|
|
366
|
+
return format || getLocaleTimeFormat(locale);
|
|
367
|
+
}, [format, locale]);
|
|
368
|
+
var separatorPadToken = (_theme$dateTimeInput = theme.dateTimeInput) == null || (_theme$dateTimeInput = _theme$dateTimeInput.separator) == null ? void 0 : _theme$dateTimeInput.pad;
|
|
369
|
+
var dateTimeSeparatorPadding = ((_theme$global$edgeSiz = theme.global.edgeSize) == null ? void 0 : _theme$global$edgeSiz[separatorPadToken]) || separatorPadToken || ((_theme$global$edgeSiz2 = theme.global.edgeSize) == null ? void 0 : _theme$global$edgeSiz2.xxsmall);
|
|
370
|
+
var inputRef = (0, _utils.useForwardedRef)(refArg);
|
|
371
|
+
var containerRef = (0, _react.useRef)();
|
|
372
|
+
var triggerRef = (0, _react.useRef)();
|
|
373
|
+
var segmentRefs = (0, _react.useRef)({});
|
|
374
|
+
var activeSectionRef = (0, _react.useRef)(SECTION_DAY);
|
|
375
|
+
var suppressSegmentFocusRef = (0, _react.useRef)(false);
|
|
376
|
+
var suppressTimePartialSyncRef = (0, _react.useRef)(false);
|
|
377
|
+
var editStateRef = (0, _react.useRef)({
|
|
378
|
+
section: SECTION_DAY,
|
|
379
|
+
buffer: ''
|
|
380
|
+
});
|
|
381
|
+
var _useFormInput = useFormInput({
|
|
382
|
+
name: name,
|
|
383
|
+
value: valueArg,
|
|
384
|
+
initialValue: defaultValue || ''
|
|
385
|
+
}),
|
|
386
|
+
value = _useFormInput[0],
|
|
387
|
+
setValue = _useFormInput[1];
|
|
388
|
+
(0, _react.useEffect)(function () {
|
|
389
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
390
|
+
console.warn('Warning: DateTimeInput is currently in beta. The API is subject ' + 'to change in future releases.');
|
|
391
|
+
}
|
|
392
|
+
}, []);
|
|
393
|
+
var _useMemo = (0, _react.useMemo)(function () {
|
|
394
|
+
return getLocaleSectionLayout(resolvedFormat, showSeconds, locale);
|
|
395
|
+
}, [resolvedFormat, showSeconds, locale]),
|
|
396
|
+
sectionOrder = _useMemo.sectionOrder,
|
|
397
|
+
separatorMap = _useMemo.separatorMap;
|
|
398
|
+
var firstSection = sectionOrder[0] || SECTION_DAY;
|
|
399
|
+
var lastSection = sectionOrder[sectionOrder.length - 1] || SECTION_SECOND;
|
|
400
|
+
var parseValue = (0, _react.useCallback)(function (nextValue) {
|
|
401
|
+
return toLocalSections(nextValue, resolvedFormat);
|
|
402
|
+
}, [resolvedFormat]);
|
|
403
|
+
var getDefaultValue = (0, _react.useCallback)(function () {
|
|
404
|
+
return defaultSections(resolvedFormat, showSeconds);
|
|
405
|
+
}, [resolvedFormat, showSeconds]);
|
|
406
|
+
var _useSectionedField = (0, _useSectionedField2.useSectionedField)({
|
|
407
|
+
value: value,
|
|
408
|
+
parseValue: parseValue,
|
|
409
|
+
defaultValue: getDefaultValue,
|
|
410
|
+
sectionOrder: sectionOrder
|
|
411
|
+
}),
|
|
412
|
+
activeSection = _useSectionedField.activeSection,
|
|
413
|
+
pendingDigits = _useSectionedField.pendingDigits,
|
|
414
|
+
preserveIncompleteSectionsRef = _useSectionedField.preserveIncompleteSectionsRef,
|
|
415
|
+
sections = _useSectionedField.sections,
|
|
416
|
+
setActiveSection = _useSectionedField.setActiveSection,
|
|
417
|
+
setPendingDigits = _useSectionedField.setPendingDigits,
|
|
418
|
+
setSections = _useSectionedField.setSections;
|
|
419
|
+
var _useState = (0, _react.useState)(false),
|
|
420
|
+
segmentFocused = _useState[0],
|
|
421
|
+
setSegmentFocused = _useState[1];
|
|
422
|
+
var _useState2 = (0, _react.useState)(false),
|
|
423
|
+
open = _useState2[0],
|
|
424
|
+
setOpen = _useState2[1];
|
|
425
|
+
var normalizedMinuteStep = (0, _react.useMemo)(function () {
|
|
426
|
+
return (0, _dates.normalizeStep)(minuteStep);
|
|
427
|
+
}, [minuteStep]);
|
|
428
|
+
(0, _react.useEffect)(function () {
|
|
429
|
+
activeSectionRef.current = activeSection;
|
|
430
|
+
}, [activeSection]);
|
|
431
|
+
var commitSections = (0, _react.useCallback)(function (nextSections) {
|
|
432
|
+
setSections(nextSections);
|
|
433
|
+
var complete = sectionOrder.every(function (section) {
|
|
434
|
+
return nextSections[(0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section))] !== undefined;
|
|
435
|
+
});
|
|
436
|
+
var anyValue = hasAnyValue(nextSections);
|
|
437
|
+
var nextValue = complete ? toUtcISOString(nextSections, resolvedFormat, showSeconds) : undefined;
|
|
438
|
+
preserveIncompleteSectionsRef.current = (!nextValue || !complete) && anyValue;
|
|
439
|
+
|
|
440
|
+
// Structured input contract: emit only valid committed values.
|
|
441
|
+
// Emit undefined only when user fully clears the component.
|
|
442
|
+
if (nextValue) {
|
|
443
|
+
setValue(nextValue);
|
|
444
|
+
onChange == null || onChange({
|
|
445
|
+
value: nextValue
|
|
446
|
+
});
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!anyValue) {
|
|
450
|
+
setValue(undefined);
|
|
451
|
+
onChange == null || onChange({
|
|
452
|
+
value: undefined
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}, [onChange, preserveIncompleteSectionsRef, resolvedFormat, sectionOrder, setSections, setValue, showSeconds]);
|
|
456
|
+
var setSectionValue = (0, _react.useCallback)(function (section, rawValue) {
|
|
457
|
+
var _extends2;
|
|
458
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
459
|
+
var nextSections = _extends({}, sections, (_extends2 = {}, _extends2[key] = rawValue, _extends2));
|
|
460
|
+
if (section === SECTION_MONTH || section === SECTION_YEAR) {
|
|
461
|
+
var dayLimit = getSectionLimits(SECTION_DAY, resolvedFormat, nextSections).max;
|
|
462
|
+
if (nextSections.day !== undefined && nextSections.day > dayLimit) {
|
|
463
|
+
nextSections.day = dayLimit;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
commitSections(nextSections);
|
|
467
|
+
}, [commitSections, resolvedFormat, sections]);
|
|
468
|
+
var moveSection = (0, _react.useCallback)(function (direction) {
|
|
469
|
+
var activeIndex = Math.max(0, sectionOrder.indexOf(activeSection));
|
|
470
|
+
var count = sectionOrder.length;
|
|
471
|
+
var nextIndex = (activeIndex + direction + count) % count;
|
|
472
|
+
var nextSection = sectionOrder[nextIndex];
|
|
473
|
+
setActiveSection(nextSection);
|
|
474
|
+
return nextSection;
|
|
475
|
+
}, [activeSection, sectionOrder, setActiveSection]);
|
|
476
|
+
var focusSection = (0, _react.useCallback)(function (section) {
|
|
477
|
+
var target = segmentRefs.current[section];
|
|
478
|
+
if (target) target.focus();
|
|
479
|
+
}, []);
|
|
480
|
+
var incrementSection = (0, _react.useCallback)(function (section, delta) {
|
|
481
|
+
if (section === SECTION_PERIOD) {
|
|
482
|
+
setSectionValue(section, sections.period === 'AM' ? 'PM' : 'AM');
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// When year is empty, seed it to the current year first to avoid
|
|
487
|
+
// wrapping to 0001/9999 on the initial arrow interaction.
|
|
488
|
+
if (section === SECTION_YEAR && sections.year === undefined) {
|
|
489
|
+
setSectionValue(SECTION_YEAR, new Date().getFullYear());
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
var _getSectionLimits = getSectionLimits(section, resolvedFormat, sections),
|
|
493
|
+
min = _getSectionLimits.min,
|
|
494
|
+
max = _getSectionLimits.max;
|
|
495
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
496
|
+
var current = sections[key] === undefined ? min : sections[key];
|
|
497
|
+
var step = section === SECTION_MINUTE ? normalizedMinuteStep : 1;
|
|
498
|
+
var next;
|
|
499
|
+
if (section === SECTION_MINUTE && step > 1) {
|
|
500
|
+
var options = Array.from({
|
|
501
|
+
length: Math.ceil((max - min + 1) / step)
|
|
502
|
+
}, function (_, index) {
|
|
503
|
+
return min + index * step;
|
|
504
|
+
}).filter(function (valueAtIndex) {
|
|
505
|
+
return valueAtIndex <= max;
|
|
506
|
+
});
|
|
507
|
+
var currentIndex = options.indexOf(current);
|
|
508
|
+
if (currentIndex !== -1) {
|
|
509
|
+
var wrappedIndex = ((currentIndex + delta) % options.length + options.length) % options.length;
|
|
510
|
+
next = options[wrappedIndex];
|
|
511
|
+
} else if (delta > 0) {
|
|
512
|
+
var _options$find;
|
|
513
|
+
next = (_options$find = options.find(function (option) {
|
|
514
|
+
return option > current;
|
|
515
|
+
})) != null ? _options$find : options[0];
|
|
516
|
+
} else {
|
|
517
|
+
var _descending$find;
|
|
518
|
+
var descending = [].concat(options).reverse();
|
|
519
|
+
next = (_descending$find = descending.find(function (option) {
|
|
520
|
+
return option < current;
|
|
521
|
+
})) != null ? _descending$find : options[options.length - 1];
|
|
522
|
+
}
|
|
523
|
+
} else {
|
|
524
|
+
next = current + delta * step;
|
|
525
|
+
if (next > max) next = min;
|
|
526
|
+
if (next < min) next = max;
|
|
527
|
+
}
|
|
528
|
+
setSectionValue(section, next);
|
|
529
|
+
}, [normalizedMinuteStep, resolvedFormat, sections, setSectionValue]);
|
|
530
|
+
var commitPendingBuffer = (0, _react.useCallback)(function () {
|
|
531
|
+
var _editStateRef$current = editStateRef.current,
|
|
532
|
+
section = _editStateRef$current.section,
|
|
533
|
+
buffer = _editStateRef$current.buffer;
|
|
534
|
+
if (!buffer) return;
|
|
535
|
+
var numeric = Number(buffer);
|
|
536
|
+
var _getSectionLimits2 = getSectionLimits(section, resolvedFormat, sections),
|
|
537
|
+
min = _getSectionLimits2.min,
|
|
538
|
+
max = _getSectionLimits2.max;
|
|
539
|
+
if (!Number.isNaN(numeric) && numeric >= min && numeric <= max) {
|
|
540
|
+
setSectionValue(section, numeric);
|
|
541
|
+
}
|
|
542
|
+
editStateRef.current = {
|
|
543
|
+
section: section,
|
|
544
|
+
buffer: ''
|
|
545
|
+
};
|
|
546
|
+
setPendingDigits({});
|
|
547
|
+
}, [resolvedFormat, sections, setPendingDigits, setSectionValue]);
|
|
548
|
+
var applyDigit = (0, _react.useCallback)(function (digit) {
|
|
549
|
+
if (activeSection === SECTION_PERIOD) return activeSection;
|
|
550
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(activeSection));
|
|
551
|
+
var needed = digitsPerSection(activeSection);
|
|
552
|
+
var sameSection = editStateRef.current.section === activeSection;
|
|
553
|
+
if (!sameSection) commitPendingBuffer();
|
|
554
|
+
var currentBuffer = sameSection ? editStateRef.current.buffer : '';
|
|
555
|
+
var nextBuffer = "" + currentBuffer + digit;
|
|
556
|
+
editStateRef.current = {
|
|
557
|
+
section: activeSection,
|
|
558
|
+
buffer: nextBuffer
|
|
559
|
+
};
|
|
560
|
+
if (nextBuffer.length < needed) {
|
|
561
|
+
var _getSectionLimits3 = getSectionLimits(activeSection, resolvedFormat, sections),
|
|
562
|
+
_max = _getSectionLimits3.max;
|
|
563
|
+
if (Number(nextBuffer) * 10 <= _max) {
|
|
564
|
+
var _setPendingDigits;
|
|
565
|
+
setPendingDigits((_setPendingDigits = {}, _setPendingDigits[key] = nextBuffer, _setPendingDigits));
|
|
566
|
+
return activeSection;
|
|
567
|
+
}
|
|
568
|
+
// first digit * 10 exceeds max — commit it directly
|
|
569
|
+
}
|
|
570
|
+
var numeric = Number(nextBuffer);
|
|
571
|
+
var _getSectionLimits4 = getSectionLimits(activeSection, resolvedFormat, sections),
|
|
572
|
+
min = _getSectionLimits4.min,
|
|
573
|
+
max = _getSectionLimits4.max;
|
|
574
|
+
if (Number.isNaN(numeric) || numeric < min || numeric > max) {
|
|
575
|
+
announce(formatMessage({
|
|
576
|
+
id: 'dateTimeInput.invalidDateTime',
|
|
577
|
+
messages: messages
|
|
578
|
+
}), 'assertive');
|
|
579
|
+
editStateRef.current = {
|
|
580
|
+
section: activeSection,
|
|
581
|
+
buffer: ''
|
|
582
|
+
};
|
|
583
|
+
setPendingDigits({});
|
|
584
|
+
return activeSection;
|
|
585
|
+
}
|
|
586
|
+
setPendingDigits({});
|
|
587
|
+
editStateRef.current = {
|
|
588
|
+
section: activeSection,
|
|
589
|
+
buffer: ''
|
|
590
|
+
};
|
|
591
|
+
setSectionValue(activeSection, numeric);
|
|
592
|
+
var sectionIndex = sectionOrder.indexOf(activeSection);
|
|
593
|
+
var isLastSection = sectionIndex === sectionOrder.length - 1;
|
|
594
|
+
if (!isLastSection) return moveSection(1);
|
|
595
|
+
return activeSection;
|
|
596
|
+
}, [activeSection, announce, commitPendingBuffer, formatMessage, messages, moveSection, resolvedFormat, sectionOrder, sections, setPendingDigits, setSectionValue]);
|
|
597
|
+
var clearActiveSection = (0, _react.useCallback)(function () {
|
|
598
|
+
setPendingDigits({});
|
|
599
|
+
editStateRef.current = {
|
|
600
|
+
section: activeSection,
|
|
601
|
+
buffer: ''
|
|
602
|
+
};
|
|
603
|
+
setSectionValue(activeSection, undefined);
|
|
604
|
+
}, [activeSection, setPendingDigits, setSectionValue]);
|
|
605
|
+
var getDisplayText = (0, _react.useCallback)(function (section) {
|
|
606
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
607
|
+
var pending = pendingDigits[key];
|
|
608
|
+
if (pending !== undefined) {
|
|
609
|
+
if (section === SECTION_YEAR) return pending.padEnd(4, 'y');
|
|
610
|
+
if (section === SECTION_PERIOD) return pending;
|
|
611
|
+
return pending.padStart(2, '0');
|
|
612
|
+
}
|
|
613
|
+
return formatSectionText(section, sections[key]);
|
|
614
|
+
}, [pendingDigits, sections]);
|
|
615
|
+
var displaySections = (0, _react.useMemo)(function () {
|
|
616
|
+
return sectionOrder.map(function (section, index) {
|
|
617
|
+
var _separatorMap$section;
|
|
618
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
619
|
+
return {
|
|
620
|
+
section: section,
|
|
621
|
+
prefix: index === 0 ? '' : (_separatorMap$section = separatorMap[section]) != null ? _separatorMap$section : separatorBeforeSection(section),
|
|
622
|
+
text: getDisplayText(section),
|
|
623
|
+
filled: sections[key] !== undefined || pendingDigits[key] !== undefined
|
|
624
|
+
};
|
|
625
|
+
});
|
|
626
|
+
}, [getDisplayText, pendingDigits, sectionOrder, sections, separatorMap]);
|
|
627
|
+
var placeholder = (0, _react.useMemo)(function () {
|
|
628
|
+
return sectionOrder.map(function (section, index) {
|
|
629
|
+
var _separatorMap$section2;
|
|
630
|
+
var token = (0, _sectionHelpers.getSectionTokenFromType)(sectionTypeFromSection(section));
|
|
631
|
+
if (index === 0) return token;
|
|
632
|
+
var prefix = (_separatorMap$section2 = separatorMap[section]) != null ? _separatorMap$section2 : separatorBeforeSection(section);
|
|
633
|
+
return "" + prefix + token;
|
|
634
|
+
}).join('');
|
|
635
|
+
}, [sectionOrder, separatorMap]);
|
|
636
|
+
var hasDisplayValue = hasAnyValue(sections) || Object.keys(pendingDigits).length > 0;
|
|
637
|
+
var inputValue = hasDisplayValue ? displaySections.map(function (_ref2) {
|
|
638
|
+
var prefix = _ref2.prefix,
|
|
639
|
+
text = _ref2.text;
|
|
640
|
+
return "" + prefix + text;
|
|
641
|
+
}).join('') : placeholder;
|
|
642
|
+
var sectionValueAnnouncement = (0, _react.useCallback)(function (section) {
|
|
643
|
+
var nameText = getSectionName(section, formatMessage, messages);
|
|
644
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
645
|
+
var raw = sections[key];
|
|
646
|
+
if (raw === undefined) {
|
|
647
|
+
return formatMessage({
|
|
648
|
+
id: 'dateTimeInput.activeSection',
|
|
649
|
+
messages: messages,
|
|
650
|
+
values: {
|
|
651
|
+
section: nameText
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
return formatMessage({
|
|
656
|
+
id: 'dateTimeInput.activeSectionValue',
|
|
657
|
+
messages: messages,
|
|
658
|
+
values: {
|
|
659
|
+
value: raw
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
}, [formatMessage, messages, sections]);
|
|
663
|
+
var openPicker = (0, _react.useCallback)(function () {
|
|
664
|
+
if (disabled || readOnly) return;
|
|
665
|
+
if (!segmentFocused) {
|
|
666
|
+
activeSectionRef.current = firstSection;
|
|
667
|
+
setActiveSection(firstSection);
|
|
668
|
+
}
|
|
669
|
+
setOpen(true);
|
|
670
|
+
announce(formatMessage({
|
|
671
|
+
id: 'dateTimeInput.openDrop',
|
|
672
|
+
messages: messages
|
|
673
|
+
}));
|
|
674
|
+
}, [announce, disabled, firstSection, formatMessage, messages, readOnly, segmentFocused, setActiveSection]);
|
|
675
|
+
var closePicker = (0, _react.useCallback)(function () {
|
|
676
|
+
setSegmentFocused(false);
|
|
677
|
+
suppressSegmentFocusRef.current = true;
|
|
678
|
+
setOpen(false);
|
|
679
|
+
requestAnimationFrame(function () {
|
|
680
|
+
if (inline) {
|
|
681
|
+
var _triggerRef$current;
|
|
682
|
+
(_triggerRef$current = triggerRef.current) == null || _triggerRef$current.focus();
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
focusSection(activeSectionRef.current);
|
|
686
|
+
});
|
|
687
|
+
}, [focusSection, inline]);
|
|
688
|
+
var onDisplaySectionMouseDown = (0, _react.useCallback)(function (section, event) {
|
|
689
|
+
if (readOnly || disabled) return;
|
|
690
|
+
if (event.button !== 0 || event.defaultPrevented) return;
|
|
691
|
+
event.preventDefault();
|
|
692
|
+
event.stopPropagation();
|
|
693
|
+
commitPendingBuffer();
|
|
694
|
+
setSegmentFocused(true);
|
|
695
|
+
setActiveSection(section);
|
|
696
|
+
focusSection(section);
|
|
697
|
+
}, [commitPendingBuffer, disabled, focusSection, readOnly, setActiveSection]);
|
|
698
|
+
var onDisplayMouseDown = (0, _react.useCallback)(function (event) {
|
|
699
|
+
var _sectionNode$dataset;
|
|
700
|
+
if (readOnly || event.button !== 0 || event.defaultPrevented) return;
|
|
701
|
+
var sectionNode = event.target.closest == null ? void 0 : event.target.closest('[data-section]');
|
|
702
|
+
if ((sectionNode == null || (_sectionNode$dataset = sectionNode.dataset) == null ? void 0 : _sectionNode$dataset.section) !== undefined) {
|
|
703
|
+
var section = Number(sectionNode.dataset.section);
|
|
704
|
+
if (!Number.isNaN(section)) {
|
|
705
|
+
onDisplaySectionMouseDown(section, event);
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
event.preventDefault();
|
|
710
|
+
commitPendingBuffer();
|
|
711
|
+
setSegmentFocused(true);
|
|
712
|
+
setActiveSection(firstSection);
|
|
713
|
+
focusSection(firstSection);
|
|
714
|
+
}, [commitPendingBuffer, firstSection, focusSection, onDisplaySectionMouseDown, readOnly, setActiveSection]);
|
|
715
|
+
var onSegmentFocus = (0, _react.useCallback)(function (section) {
|
|
716
|
+
if (suppressSegmentFocusRef.current) {
|
|
717
|
+
suppressSegmentFocusRef.current = false;
|
|
718
|
+
} else {
|
|
719
|
+
setSegmentFocused(true);
|
|
720
|
+
}
|
|
721
|
+
if (readOnly || disabled) return;
|
|
722
|
+
setActiveSection(section);
|
|
723
|
+
}, [disabled, readOnly, setActiveSection]);
|
|
724
|
+
var onSegmentBlur = (0, _react.useCallback)(function () {
|
|
725
|
+
requestAnimationFrame(function () {
|
|
726
|
+
var _document = document,
|
|
727
|
+
activeElement = _document.activeElement;
|
|
728
|
+
var isSegmentActive = Object.values(segmentRefs.current).includes(activeElement);
|
|
729
|
+
if (!isSegmentActive && activeElement === document.body && !readOnly && !disabled) {
|
|
730
|
+
focusSection(activeSection);
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
if (!isSegmentActive) {
|
|
734
|
+
setSegmentFocused(false);
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}, [activeSection, disabled, focusSection, readOnly]);
|
|
738
|
+
var onSegmentKeyDown = (0, _react.useCallback)(function (section, event) {
|
|
739
|
+
if (readOnly || disabled) return;
|
|
740
|
+
if (!segmentFocused) setSegmentFocused(true);
|
|
741
|
+
var key = event.key;
|
|
742
|
+
if (activeSection !== section) setActiveSection(section);
|
|
743
|
+
if (key === 'ArrowRight') {
|
|
744
|
+
event.preventDefault();
|
|
745
|
+
commitPendingBuffer();
|
|
746
|
+
var next = moveSection(1);
|
|
747
|
+
focusSection(next);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (key === 'ArrowLeft') {
|
|
751
|
+
event.preventDefault();
|
|
752
|
+
commitPendingBuffer();
|
|
753
|
+
var _next = moveSection(-1);
|
|
754
|
+
focusSection(_next);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
if (key === 'Home') {
|
|
758
|
+
event.preventDefault();
|
|
759
|
+
commitPendingBuffer();
|
|
760
|
+
setActiveSection(firstSection);
|
|
761
|
+
focusSection(firstSection);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
if (key === 'End') {
|
|
765
|
+
event.preventDefault();
|
|
766
|
+
commitPendingBuffer();
|
|
767
|
+
setActiveSection(lastSection);
|
|
768
|
+
focusSection(lastSection);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
if (key === 'ArrowUp') {
|
|
772
|
+
event.preventDefault();
|
|
773
|
+
incrementSection(section, open ? -1 : 1);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (key === 'ArrowDown') {
|
|
777
|
+
if (event.altKey) {
|
|
778
|
+
event.preventDefault();
|
|
779
|
+
openPicker();
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
event.preventDefault();
|
|
783
|
+
incrementSection(section, open ? 1 : -1);
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (key === 'Delete' || key === 'Backspace') {
|
|
787
|
+
event.preventDefault();
|
|
788
|
+
clearActiveSection();
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (key === 'Enter') {
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
if (open) closePicker();
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
if (key === 'Escape' && open) {
|
|
797
|
+
event.preventDefault();
|
|
798
|
+
closePicker();
|
|
799
|
+
return;
|
|
800
|
+
}
|
|
801
|
+
if (key === ' ' || key === 'Spacebar') {
|
|
802
|
+
event.preventDefault();
|
|
803
|
+
openPicker();
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (resolvedFormat === '12' && section === SECTION_PERIOD) {
|
|
807
|
+
var lower = key.toLowerCase();
|
|
808
|
+
if (lower === 'a') {
|
|
809
|
+
event.preventDefault();
|
|
810
|
+
setSectionValue(SECTION_PERIOD, 'AM');
|
|
811
|
+
} else if (lower === 'p') {
|
|
812
|
+
event.preventDefault();
|
|
813
|
+
setSectionValue(SECTION_PERIOD, 'PM');
|
|
814
|
+
}
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (/^\d$/.test(key)) {
|
|
818
|
+
event.preventDefault();
|
|
819
|
+
var _next2 = applyDigit(Number(key));
|
|
820
|
+
if (_next2 !== section) {
|
|
821
|
+
focusSection(_next2);
|
|
822
|
+
} else {
|
|
823
|
+
event.currentTarget.focus();
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}, [activeSection, applyDigit, clearActiveSection, closePicker, commitPendingBuffer, disabled, firstSection, focusSection, incrementSection, lastSection, moveSection, open, openPicker, readOnly, resolvedFormat, segmentFocused, setActiveSection, setSectionValue]);
|
|
827
|
+
(0, _react.useEffect)(function () {
|
|
828
|
+
if (!segmentFocused || readOnly || disabled) return;
|
|
829
|
+
var activeSegment = segmentRefs.current[activeSection];
|
|
830
|
+
if (activeSegment && document.activeElement !== activeSegment) {
|
|
831
|
+
activeSegment.focus();
|
|
832
|
+
}
|
|
833
|
+
}, [activeSection, disabled, readOnly, segmentFocused]);
|
|
834
|
+
var handleCalendarSelect = (0, _react.useCallback)(function (nextDateValue) {
|
|
835
|
+
var parsed = parseCalendarSelection(nextDateValue);
|
|
836
|
+
if (!parsed) return;
|
|
837
|
+
var seededTimeSections = getSeededTimeSections(sections, resolvedFormat, showSeconds);
|
|
838
|
+
var nextSections = _extends({}, sections, {
|
|
839
|
+
day: parsed.day,
|
|
840
|
+
month: parsed.month,
|
|
841
|
+
year: parsed.year
|
|
842
|
+
}, seededTimeSections);
|
|
843
|
+
var isSameSelection = nextSections.day === sections.day && nextSections.month === sections.month && nextSections.year === sections.year && nextSections.hour === sections.hour && nextSections.minute === sections.minute && nextSections.second === sections.second && nextSections.period === sections.period;
|
|
844
|
+
if (isSameSelection) return;
|
|
845
|
+
suppressTimePartialSyncRef.current = true;
|
|
846
|
+
setPendingDigits({});
|
|
847
|
+
editStateRef.current = {
|
|
848
|
+
section: activeSection,
|
|
849
|
+
buffer: ''
|
|
850
|
+
};
|
|
851
|
+
activeSectionRef.current = SECTION_HOUR;
|
|
852
|
+
setActiveSection(SECTION_HOUR);
|
|
853
|
+
commitSections(nextSections);
|
|
854
|
+
}, [activeSection, commitSections, resolvedFormat, sections, setActiveSection, setPendingDigits, showSeconds]);
|
|
855
|
+
var handleTimeSelect = (0, _react.useCallback)(function (_ref3) {
|
|
856
|
+
var nextTime = _ref3.value;
|
|
857
|
+
setPendingDigits({});
|
|
858
|
+
editStateRef.current = {
|
|
859
|
+
section: activeSection,
|
|
860
|
+
buffer: ''
|
|
861
|
+
};
|
|
862
|
+
if (!nextTime) {
|
|
863
|
+
// Incomplete picker selection — preserve existing sections.
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
var match = /^(\d{2}):(\d{2}):(\d{2})$/.exec(nextTime);
|
|
867
|
+
if (!match) return;
|
|
868
|
+
var hour24 = Number(match[1]);
|
|
869
|
+
var minute = Number(match[2]);
|
|
870
|
+
var second = Number(match[3]);
|
|
871
|
+
var nextHour;
|
|
872
|
+
var nextPeriod;
|
|
873
|
+
if (resolvedFormat === '12') {
|
|
874
|
+
nextPeriod = hour24 < 12 ? 'AM' : 'PM';
|
|
875
|
+
nextHour = hour24 % 12 || 12;
|
|
876
|
+
} else {
|
|
877
|
+
nextHour = hour24;
|
|
878
|
+
nextPeriod = undefined;
|
|
879
|
+
}
|
|
880
|
+
commitSections(_extends({}, sections, getSeededDateSections(sections), {
|
|
881
|
+
hour: nextHour,
|
|
882
|
+
minute: minute,
|
|
883
|
+
second: second,
|
|
884
|
+
period: nextPeriod
|
|
885
|
+
}));
|
|
886
|
+
}, [activeSection, commitSections, resolvedFormat, sections, setPendingDigits]);
|
|
887
|
+
|
|
888
|
+
// TimeInput section constants (0–3) → DateTimeInput section constants (3–6)
|
|
889
|
+
var TIME_TO_DT_SECTION = (0, _react.useMemo)(function () {
|
|
890
|
+
return [SECTION_HOUR, SECTION_MINUTE, SECTION_SECOND, SECTION_PERIOD];
|
|
891
|
+
}, []);
|
|
892
|
+
var handleTimePartialChange = (0, _react.useCallback)(function (timeSections, changedTimeSectionIndex) {
|
|
893
|
+
if (suppressTimePartialSyncRef.current) {
|
|
894
|
+
suppressTimePartialSyncRef.current = false;
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// Sync the active spinbutton segment to the column being edited
|
|
899
|
+
var dtSection = TIME_TO_DT_SECTION[changedTimeSectionIndex];
|
|
900
|
+
if (dtSection !== undefined) setActiveSection(dtSection);
|
|
901
|
+
|
|
902
|
+
// Update display state with partial time fields immediately so the
|
|
903
|
+
// input shows values as each column is selected, not only on
|
|
904
|
+
// completion.
|
|
905
|
+
setSections(function (prev) {
|
|
906
|
+
var _timeSections$hour, _timeSections$minute, _timeSections$second, _timeSections$period;
|
|
907
|
+
var mergedTimeSections = _extends({}, prev, {
|
|
908
|
+
hour: (_timeSections$hour = timeSections.hour) != null ? _timeSections$hour : prev.hour,
|
|
909
|
+
minute: (_timeSections$minute = timeSections.minute) != null ? _timeSections$minute : prev.minute
|
|
910
|
+
}, showSeconds ? {
|
|
911
|
+
second: (_timeSections$second = timeSections.second) != null ? _timeSections$second : prev.second
|
|
912
|
+
} : {}, resolvedFormat === '12' ? {
|
|
913
|
+
period: (_timeSections$period = timeSections.period) != null ? _timeSections$period : prev.period
|
|
914
|
+
} : {});
|
|
915
|
+
return _extends({}, prev, getSeededDateSections(prev), getSeededTimeSections(mergedTimeSections, resolvedFormat, showSeconds));
|
|
916
|
+
});
|
|
917
|
+
}, [resolvedFormat, setActiveSection, setSections, showSeconds, TIME_TO_DT_SECTION]);
|
|
918
|
+
var timeValue = (0, _react.useMemo)(function () {
|
|
919
|
+
var _sections$minute2, _sections$second2;
|
|
920
|
+
if (sections.hour === undefined) {
|
|
921
|
+
return undefined;
|
|
922
|
+
}
|
|
923
|
+
if (showSeconds && sections.second === undefined) return undefined;
|
|
924
|
+
var minute = (_sections$minute2 = sections.minute) != null ? _sections$minute2 : 0;
|
|
925
|
+
var resolvedSecond = (_sections$second2 = sections.second) != null ? _sections$second2 : 0;
|
|
926
|
+
if (resolvedFormat === '12') {
|
|
927
|
+
var hour24 = sections.hour % 12;
|
|
928
|
+
if ((sections.period || 'AM') === 'PM') hour24 += 12;
|
|
929
|
+
return (0, _dates.pad)(hour24) + ":" + (0, _dates.pad)(minute) + ":" + (0, _dates.pad)(resolvedSecond);
|
|
930
|
+
}
|
|
931
|
+
return (0, _dates.pad)(sections.hour) + ":" + (0, _dates.pad)(minute) + ":" + (0, _dates.pad)(resolvedSecond);
|
|
932
|
+
}, [resolvedFormat, sections, showSeconds]);
|
|
933
|
+
var showActiveSection = (segmentFocused || open) && !readOnly && !disabled;
|
|
934
|
+
var _formContext$useFormF = formContext.useFormField({}),
|
|
935
|
+
inForm = _formContext$useFormF.inForm;
|
|
936
|
+
var formFieldLabelId = inForm && id ? "grommet-" + id + "__label" : undefined;
|
|
937
|
+
var groupLabel = formFieldLabelId ? undefined : formatMessage({
|
|
938
|
+
id: 'dateTimeInput.inputLabel',
|
|
939
|
+
messages: messages
|
|
940
|
+
});
|
|
941
|
+
var CalendarIcon = ((_theme$dateTimeInput2 = theme.dateTimeInput) == null || (_theme$dateTimeInput2 = _theme$dateTimeInput2.icon) == null ? void 0 : _theme$dateTimeInput2.calendar) || _Calendar.Calendar;
|
|
942
|
+
var dropTarget = inline ? triggerRef.current : containerRef.current;
|
|
943
|
+
var generatedId = (0, _react.useId)();
|
|
944
|
+
var dropId = (id || generatedId) + "__drop";
|
|
945
|
+
return /*#__PURE__*/_react["default"].createElement(_Keyboard.Keyboard, {
|
|
946
|
+
onEsc: open ? closePicker : undefined
|
|
947
|
+
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, null, inline ? /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
948
|
+
direction: "row",
|
|
949
|
+
align: "center"
|
|
950
|
+
}, /*#__PURE__*/_react["default"].createElement(_Button.Button, {
|
|
951
|
+
ref: triggerRef,
|
|
952
|
+
icon: /*#__PURE__*/_react["default"].createElement(CalendarIcon, null),
|
|
953
|
+
plain: true,
|
|
954
|
+
disabled: disabled || readOnly,
|
|
955
|
+
"aria-label": formatMessage({
|
|
956
|
+
id: 'dateTimeInput.chooseDateTime',
|
|
957
|
+
messages: messages
|
|
958
|
+
}),
|
|
959
|
+
"aria-haspopup": "dialog",
|
|
960
|
+
"aria-expanded": open,
|
|
961
|
+
"aria-controls": dropId,
|
|
962
|
+
onClick: open ? closePicker : openPicker
|
|
963
|
+
})) : /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInputContainer, _extends({
|
|
964
|
+
ref: containerRef,
|
|
965
|
+
direction: "row",
|
|
966
|
+
border: !plainProp,
|
|
967
|
+
fill: true,
|
|
968
|
+
round: (_theme$dateTimeInput3 = theme.dateTimeInput) == null || (_theme$dateTimeInput3 = _theme$dateTimeInput3.container) == null ? void 0 : _theme$dateTimeInput3.round,
|
|
969
|
+
disabled: disabled,
|
|
970
|
+
readOnlyProp: readOnly,
|
|
971
|
+
focusIndicator: focusIndicatorProp != null ? focusIndicatorProp : true
|
|
972
|
+
}, passThemeFlag), /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInputField, passThemeFlag, /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInputDisplay, _extends({
|
|
973
|
+
role: "group",
|
|
974
|
+
"aria-label": groupLabel,
|
|
975
|
+
"aria-labelledby": formFieldLabelId,
|
|
976
|
+
onMouseDown: onDisplayMouseDown
|
|
977
|
+
}, passThemeFlag), displaySections.map(function (_ref4) {
|
|
978
|
+
var section = _ref4.section,
|
|
979
|
+
prefix = _ref4.prefix,
|
|
980
|
+
text = _ref4.text,
|
|
981
|
+
filled = _ref4.filled;
|
|
982
|
+
var sectionLimits = getSectionLimits(section, resolvedFormat, sections);
|
|
983
|
+
var key = (0, _sectionHelpers.getSectionKeyFromType)(sectionTypeFromSection(section));
|
|
984
|
+
var numericValue;
|
|
985
|
+
if (section === SECTION_PERIOD) {
|
|
986
|
+
numericValue = sections[key] === 'PM' ? 1 : 0;
|
|
987
|
+
} else {
|
|
988
|
+
var _sections$key;
|
|
989
|
+
numericValue = (_sections$key = sections[key]) != null ? _sections$key : sectionLimits.min;
|
|
990
|
+
}
|
|
991
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
|
|
992
|
+
key: section
|
|
993
|
+
}, !!prefix && /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInputSeparator, _extends({
|
|
994
|
+
$filled: hasDisplayValue,
|
|
995
|
+
$paddingInline: dateTimeSeparatorPadding
|
|
996
|
+
}, passThemeFlag), prefix), /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInputSegment, _extends({
|
|
997
|
+
ref: function ref(segmentNode) {
|
|
998
|
+
segmentRefs.current[section] = segmentNode;
|
|
999
|
+
},
|
|
1000
|
+
tabIndex: !readOnly && !disabled && activeSection === section ? 0 : -1,
|
|
1001
|
+
$active: showActiveSection && activeSection === section,
|
|
1002
|
+
$filled: filled,
|
|
1003
|
+
onFocus: function onFocus() {
|
|
1004
|
+
return onSegmentFocus(section);
|
|
1005
|
+
},
|
|
1006
|
+
onBlur: onSegmentBlur,
|
|
1007
|
+
onKeyDown: function onKeyDown(event) {
|
|
1008
|
+
return onSegmentKeyDown(section, event);
|
|
1009
|
+
},
|
|
1010
|
+
"data-section": section,
|
|
1011
|
+
role: "spinbutton",
|
|
1012
|
+
"aria-label": getSectionName(section, formatMessage, messages),
|
|
1013
|
+
"aria-disabled": disabled || undefined,
|
|
1014
|
+
"aria-readonly": readOnly || undefined,
|
|
1015
|
+
"aria-valuenow": numericValue,
|
|
1016
|
+
"aria-valuemin": sectionLimits.min,
|
|
1017
|
+
"aria-valuemax": sectionLimits.max,
|
|
1018
|
+
"aria-valuetext": sectionValueAnnouncement(section)
|
|
1019
|
+
}, passThemeFlag), text));
|
|
1020
|
+
})), /*#__PURE__*/_react["default"].createElement(_StyledDateTimeInput.StyledDateTimeInput, _extends({
|
|
1021
|
+
tabIndex: -1
|
|
1022
|
+
}, rest, {
|
|
1023
|
+
id: id,
|
|
1024
|
+
ref: inputRef,
|
|
1025
|
+
value: inputValue,
|
|
1026
|
+
"aria-hidden": "true",
|
|
1027
|
+
disabled: disabled,
|
|
1028
|
+
readOnly: true,
|
|
1029
|
+
focusIndicator: false,
|
|
1030
|
+
plain: true
|
|
1031
|
+
}))), !readOnly && /*#__PURE__*/_react["default"].createElement(_Button.Button, {
|
|
1032
|
+
ref: triggerRef,
|
|
1033
|
+
icon: /*#__PURE__*/_react["default"].createElement(CalendarIcon, null),
|
|
1034
|
+
plain: true,
|
|
1035
|
+
disabled: disabled,
|
|
1036
|
+
margin: (_theme$dateTimeInput4 = theme.dateTimeInput) == null || (_theme$dateTimeInput4 = _theme$dateTimeInput4.button) == null ? void 0 : _theme$dateTimeInput4.margin,
|
|
1037
|
+
"aria-label": formatMessage({
|
|
1038
|
+
id: 'dateTimeInput.chooseDateTime',
|
|
1039
|
+
messages: messages
|
|
1040
|
+
}),
|
|
1041
|
+
"aria-haspopup": "dialog",
|
|
1042
|
+
"aria-expanded": open,
|
|
1043
|
+
"aria-controls": dropId,
|
|
1044
|
+
onClick: open ? closePicker : openPicker
|
|
1045
|
+
})), name && /*#__PURE__*/_react["default"].createElement("input", {
|
|
1046
|
+
"aria-hidden": "true",
|
|
1047
|
+
name: name,
|
|
1048
|
+
readOnly: true,
|
|
1049
|
+
tabIndex: -1,
|
|
1050
|
+
type: "hidden",
|
|
1051
|
+
value: value || ''
|
|
1052
|
+
}), open && /*#__PURE__*/_react["default"].createElement(_Drop.Drop, {
|
|
1053
|
+
id: dropId,
|
|
1054
|
+
target: dropTarget,
|
|
1055
|
+
align: {
|
|
1056
|
+
top: 'bottom',
|
|
1057
|
+
left: 'left'
|
|
1058
|
+
},
|
|
1059
|
+
onEsc: closePicker,
|
|
1060
|
+
onClickOutside: closePicker
|
|
1061
|
+
}, /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
1062
|
+
direction: "row",
|
|
1063
|
+
pad: (_theme$dateTimeInput5 = theme.dateTimeInput) == null || (_theme$dateTimeInput5 = _theme$dateTimeInput5.drop) == null ? void 0 : _theme$dateTimeInput5.pad,
|
|
1064
|
+
gap: (_theme$dateTimeInput6 = theme.dateTimeInput) == null || (_theme$dateTimeInput6 = _theme$dateTimeInput6.drop) == null ? void 0 : _theme$dateTimeInput6.gap
|
|
1065
|
+
}, /*#__PURE__*/_react["default"].createElement(_Calendar2.Calendar, {
|
|
1066
|
+
date: getCalendarDate(sections),
|
|
1067
|
+
initialFocus: "days",
|
|
1068
|
+
onSelect: handleCalendarSelect
|
|
1069
|
+
}), /*#__PURE__*/_react["default"].createElement(_Box.Box, {
|
|
1070
|
+
alignSelf: "stretch",
|
|
1071
|
+
flex: false,
|
|
1072
|
+
border: {
|
|
1073
|
+
side: 'start',
|
|
1074
|
+
color: (_theme$dateTimeInput7 = theme.dateTimeInput) == null || (_theme$dateTimeInput7 = _theme$dateTimeInput7.drop) == null || (_theme$dateTimeInput7 = _theme$dateTimeInput7.border) == null ? void 0 : _theme$dateTimeInput7.color,
|
|
1075
|
+
size: (_theme$dateTimeInput8 = theme.dateTimeInput) == null || (_theme$dateTimeInput8 = _theme$dateTimeInput8.drop) == null || (_theme$dateTimeInput8 = _theme$dateTimeInput8.border) == null ? void 0 : _theme$dateTimeInput8.size
|
|
1076
|
+
}
|
|
1077
|
+
}), /*#__PURE__*/_react["default"].createElement(_TimeInput.TimeInput, {
|
|
1078
|
+
inline: true,
|
|
1079
|
+
format: resolvedFormat,
|
|
1080
|
+
value: timeValue,
|
|
1081
|
+
showSeconds: showSeconds,
|
|
1082
|
+
messages: messages,
|
|
1083
|
+
minuteStep: normalizedMinuteStep,
|
|
1084
|
+
disabled: disabled,
|
|
1085
|
+
readOnly: readOnly,
|
|
1086
|
+
onChange: handleTimeSelect,
|
|
1087
|
+
onPartialChange: handleTimePartialChange
|
|
1088
|
+
})))));
|
|
1089
|
+
});
|
|
1090
|
+
DateTimeInput.displayName = 'DateTimeInput';
|
|
1091
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1092
|
+
DateTimeInput.propTypes = _propTypes.DateTimeInputPropTypes;
|
|
1093
|
+
}
|