@entur/datepicker 11.2.1-beta.9 → 11.2.2
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/dist/DatePicker/Calendar.d.ts +1 -2
- package/dist/DatePicker/CalendarCell.d.ts +1 -1
- package/dist/DatePicker/CalendarGrid.d.ts +1 -1
- package/dist/DatePicker/DateField.d.ts +4 -5
- package/dist/DatePicker/DatePicker.d.ts +1 -2
- package/dist/DatePicker/NativeDatePicker.d.ts +2 -2
- package/dist/TimePicker/NativeTimePicker.d.ts +2 -3
- package/dist/TimePicker/SimpleTimePicker.d.ts +4 -5
- package/dist/TimePicker/TimePicker.d.ts +4 -5
- package/dist/TimePicker/TimePickerArrowButton.d.ts +1 -1
- package/dist/datepicker.cjs.js +1243 -0
- package/dist/datepicker.cjs.js.map +1 -0
- package/dist/datepicker.esm.js +1046 -1047
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/shared/CalendarButton.d.ts +1 -1
- package/dist/shared/FieldSegment.d.ts +1 -2
- package/dist/shared/utils.d.ts +1 -2
- package/dist/styles.css +64 -78
- package/package.json +39 -29
- package/dist/datepicker.cjs.development.js +0 -1269
- package/dist/datepicker.cjs.development.js.map +0 -1
- package/dist/datepicker.cjs.production.min.js +0 -2
- package/dist/datepicker.cjs.production.min.js.map +0 -1
- package/dist/index.js +0 -8
package/dist/datepicker.esm.js
CHANGED
|
@@ -1,780 +1,759 @@
|
|
|
1
|
-
import { useRandomId, ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { useRandomId, ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from "@entur/utils";
|
|
2
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { useRef, useEffect, useState } from "react";
|
|
4
|
+
import { useDateFieldState, useDatePickerState, useTimeFieldState } from "@react-stately/datepicker";
|
|
5
|
+
import { useDateSegment, useDateField, useDatePicker, useTimeField } from "@react-aria/datepicker";
|
|
6
|
+
import { useLocale, I18nProvider } from "@react-aria/i18n";
|
|
7
|
+
import classNames from "classnames";
|
|
8
|
+
import { BaseFormControl, useVariant, useInputGroupContext, isFilled, TextField } from "@entur/form";
|
|
9
|
+
import { toCalendarDateTime, CalendarDate, Time, getLocalTimeZone, GregorianCalendar, toTime, now, toZoned, today, toCalendarDate, startOfWeek, startOfYear, ZonedDateTime, parseAbsolute, CalendarDateTime, isEqualDay, getWeeksInMonth, parseTime } from "@internationalized/date";
|
|
10
|
+
import { CalendarDate as CalendarDate2, CalendarDateTime as CalendarDateTime2, Time as Time2, ZonedDateTime as ZonedDateTime2 } from "@internationalized/date";
|
|
11
|
+
import { useCalendarCell, useCalendarGrid, useCalendar } from "@react-aria/calendar";
|
|
12
|
+
import { useCalendarState } from "@react-stately/calendar";
|
|
13
|
+
import { LeftArrowIcon, RightArrowIcon, CalendarIcon, DateIcon, ClockIcon } from "@entur/icons";
|
|
14
|
+
import { useButton } from "@react-aria/button";
|
|
15
|
+
import { IconButton } from "@entur/button";
|
|
16
|
+
import { VisuallyHidden } from "@entur/a11y";
|
|
17
|
+
import { useFloating, offset, flip, shift, autoUpdate } from "@floating-ui/react-dom";
|
|
18
|
+
import FocusLock from "react-focus-lock";
|
|
19
|
+
import { space, zIndexes } from "@entur/tokens";
|
|
20
|
+
import { Modal } from "@entur/modal";
|
|
21
|
+
const FieldSegment = ({ segment, state, ...rest }) => {
|
|
22
|
+
const ref = useRef(null);
|
|
23
|
+
const { segmentProps } = useDateSegment(segment, state, ref);
|
|
24
|
+
return /* @__PURE__ */ jsx(
|
|
25
|
+
"div",
|
|
26
|
+
{
|
|
27
|
+
...segmentProps,
|
|
28
|
+
ref,
|
|
29
|
+
className: classNames("eds-date-and-time-field__segment", {
|
|
30
|
+
"eds-date-and-time-field__segment--placeholder": segment.isPlaceholder,
|
|
31
|
+
"eds-date-and-time-field__segment--dot-separator": segment.text === "." || segment.text === ":"
|
|
32
|
+
}),
|
|
33
|
+
tabIndex: state.isDisabled ? -1 : segmentProps.tabIndex,
|
|
34
|
+
...rest,
|
|
35
|
+
children: segment.text
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
}, _extends.apply(null, arguments);
|
|
29
|
-
}
|
|
30
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
31
|
-
if (null == r) return {};
|
|
32
|
-
var t = {};
|
|
33
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
34
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
35
|
-
t[n] = r[n];
|
|
36
|
-
}
|
|
37
|
-
return t;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var _excluded$b = ["segment", "state"];
|
|
41
|
-
var FieldSegment = function FieldSegment(_ref) {
|
|
42
|
-
var segment = _ref.segment,
|
|
43
|
-
state = _ref.state,
|
|
44
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$b);
|
|
45
|
-
var ref = useRef(null);
|
|
46
|
-
var _useDateSegment = useDateSegment(segment, state, ref),
|
|
47
|
-
segmentProps = _useDateSegment.segmentProps;
|
|
48
|
-
return React.createElement("div", _extends({}, segmentProps, {
|
|
49
|
-
ref: ref,
|
|
50
|
-
className: classNames('eds-date-and-time-field__segment', {
|
|
51
|
-
'eds-date-and-time-field__segment--placeholder': segment.isPlaceholder,
|
|
52
|
-
'eds-date-and-time-field__segment--dot-separator': segment.text === '.' || segment.text === ':'
|
|
53
|
-
}),
|
|
54
|
-
tabIndex: state.isDisabled ? -1 : segmentProps.tabIndex
|
|
55
|
-
}, rest), segment.text);
|
|
37
|
+
);
|
|
56
38
|
};
|
|
57
|
-
|
|
58
|
-
var nativeDateToDateTime = function nativeDateToDateTime(date, timeZone, offset) {
|
|
39
|
+
const nativeDateToDateTime = (date, timeZone, offset2) => {
|
|
59
40
|
if (timeZone) {
|
|
60
|
-
if (
|
|
61
|
-
return new ZonedDateTime(
|
|
41
|
+
if (offset2) {
|
|
42
|
+
return new ZonedDateTime(
|
|
43
|
+
date.getFullYear(),
|
|
44
|
+
date.getMonth() + 1,
|
|
45
|
+
date.getDate(),
|
|
46
|
+
timeZone,
|
|
47
|
+
offset2,
|
|
48
|
+
date.getHours(),
|
|
49
|
+
date.getMinutes(),
|
|
50
|
+
date.getSeconds(),
|
|
51
|
+
date.getMilliseconds()
|
|
52
|
+
);
|
|
62
53
|
}
|
|
63
54
|
return parseAbsolute(date.toISOString(), timeZone);
|
|
64
55
|
}
|
|
65
|
-
return new CalendarDateTime(
|
|
56
|
+
return new CalendarDateTime(
|
|
57
|
+
date.getFullYear(),
|
|
58
|
+
date.getMonth() + 1,
|
|
59
|
+
date.getDate(),
|
|
60
|
+
date.getHours(),
|
|
61
|
+
date.getMinutes(),
|
|
62
|
+
date.getSeconds(),
|
|
63
|
+
date.getMilliseconds()
|
|
64
|
+
);
|
|
66
65
|
};
|
|
67
|
-
|
|
68
|
-
* Tar inn et JS Date-objekt og returnerer et av DateValue-objektene fra @internationalized/date-pakken
|
|
69
|
-
* @param {Date | null} date JS Date-objekt som ønskes konvertert til et DateValue-objekt
|
|
70
|
-
* @param {boolean} noTimeOnlyDate Hvis tidspunktet er irrelevant kan denne settes til true, da får man et CalendarDate-objekt uten tidspunkt tilbake
|
|
71
|
-
* @param {string} timeZone Tidssonen på IANA-formatet som tidpunktet skal konverteres til. Utelates denne får man et tidspunkt uten tidssone. Kan brukes med og uten en UTC-offset Vær obs på annen oppførsel med offset, les mer på beskrivelsen av offset
|
|
72
|
-
* @param {number} offset UTC-offset i millisekunder, må brukes med en tidssone. Ved å legge på en offset lager du en variant av en tidssone. Det betyr at tidspunktet ikke endres (time, minutt, sekund uendret), men tidssonen, med tilhørende offset, tidspunktet er i endres.
|
|
73
|
-
* @returns {CalendarDateTime | ZonedDateTime | CalendarDate | null} et av DateValue-objektene med verdier fra date eller null
|
|
74
|
-
*/
|
|
75
|
-
function nativeDateToDateValue(date, noTimeOnlyDate, timeZone, offset) {
|
|
76
|
-
if (noTimeOnlyDate === void 0) {
|
|
77
|
-
noTimeOnlyDate = false;
|
|
78
|
-
}
|
|
66
|
+
function nativeDateToDateValue(date, noTimeOnlyDate = false, timeZone, offset2) {
|
|
79
67
|
if (date === null) return null;
|
|
80
|
-
if (noTimeOnlyDate)
|
|
81
|
-
|
|
68
|
+
if (noTimeOnlyDate)
|
|
69
|
+
return new CalendarDate(
|
|
70
|
+
date.getFullYear(),
|
|
71
|
+
date.getMonth() + 1,
|
|
72
|
+
date.getDate()
|
|
73
|
+
);
|
|
74
|
+
return nativeDateToDateTime(date, timeZone, offset2);
|
|
82
75
|
}
|
|
83
|
-
|
|
84
|
-
* Tar inn et JS Date-objekt og returnerer et av TimeValue-objektene fra @internationalized/date-pakken
|
|
85
|
-
* @param {Date | null} date JS Date-objekt som ønskes konvertert til et TimeValue-objekt
|
|
86
|
-
* @param {boolean} noDateOnlyTime Hvis datoen er irrelevant kan denne settes til true, da får man et Time-objekt uten dato tilbake
|
|
87
|
-
* @param {string} timeZone Tidssonen på IANA-formatet som tidpunktet skal konverteres til. Utelates denne får man et tidspunkt uten tidssone. Kan brukes med og uten en UTC-offset Vær obs på annen oppførsel med offset, les mer på beskrivelsen av offset
|
|
88
|
-
* @param {number} offset UTC-offset i millisekunder, må brukes med en tidssone. Ved å legge på en offset lager du en variant av en tidssone. Det betyr at tidspunktet ikke endres (time, minutt, sekund uendret), men tidssonen, med tilhørende offset, tidspunktet er i endres.
|
|
89
|
-
* @returns {Time | CalendarDateTime | ZonedDateTime | null} et av TimeValue-objektene med verdier fra date eller null
|
|
90
|
-
*/
|
|
91
|
-
function nativeDateToTimeValue(date, noDateOnlyTime, timeZone, offset) {
|
|
92
|
-
if (noDateOnlyTime === void 0) {
|
|
93
|
-
noDateOnlyTime = false;
|
|
94
|
-
}
|
|
76
|
+
function nativeDateToTimeValue(date, noDateOnlyTime = false, timeZone, offset2) {
|
|
95
77
|
if (date === null) return null;
|
|
96
|
-
if (noDateOnlyTime)
|
|
97
|
-
|
|
78
|
+
if (noDateOnlyTime)
|
|
79
|
+
return new Time(
|
|
80
|
+
date.getHours(),
|
|
81
|
+
date.getMinutes(),
|
|
82
|
+
date.getSeconds(),
|
|
83
|
+
date.getMilliseconds()
|
|
84
|
+
);
|
|
85
|
+
return nativeDateToDateTime(date, timeZone, offset2);
|
|
98
86
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Tar inn et av Date- eller TimeValue-objektene fra \@internationalized/date-pakken og returnerer et JS Date-objekt
|
|
101
|
-
* @param {DateValue | TimeValue | null} value En dato eller et tidspunkt på Date- eller TimeValue-formatet som ønskes konvertert til et JS Date-objekt
|
|
102
|
-
* @param {string} timeZoneForCalendarDateTime Tidssonen value er i. Fungerer kun med typen er CalendarDateTime
|
|
103
|
-
* @returns {Date | null} et Date-objekt med verdier fra time eller null
|
|
104
|
-
*/
|
|
105
87
|
function timeOrDateValueToNativeDate(value, timeZoneForCalendarDateTime) {
|
|
106
88
|
if (value === null) return null;
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var date = new Date();
|
|
89
|
+
if (!("day" in value)) {
|
|
90
|
+
const date = /* @__PURE__ */ new Date();
|
|
110
91
|
date.setHours(value.hour);
|
|
111
92
|
date.setMinutes(value.minute);
|
|
112
93
|
date.setSeconds(value.second);
|
|
113
94
|
date.setMilliseconds(value.millisecond);
|
|
114
95
|
return date;
|
|
115
96
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return value.toDate(timeZoneForCalendarDateTime != null ? timeZoneForCalendarDateTime : getLocalTimeZone());
|
|
97
|
+
if (!("hour" in value)) {
|
|
98
|
+
return value.toDate(timeZoneForCalendarDateTime ?? getLocalTimeZone());
|
|
119
99
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
100
|
+
if (!("timeZone" in value)) {
|
|
101
|
+
if (timeZoneForCalendarDateTime)
|
|
102
|
+
return value.toDate(timeZoneForCalendarDateTime);
|
|
123
103
|
return value.toDate(getLocalTimeZone());
|
|
124
104
|
}
|
|
125
|
-
// type is ZonedDateTime
|
|
126
105
|
return value.toDate();
|
|
127
106
|
}
|
|
128
|
-
|
|
129
|
-
if (identifier === void 0) {
|
|
130
|
-
identifier = 'gregory';
|
|
131
|
-
}
|
|
107
|
+
const createCalendar = (identifier = "gregory") => {
|
|
132
108
|
switch (identifier) {
|
|
133
|
-
case
|
|
109
|
+
case "gregory":
|
|
134
110
|
return new GregorianCalendar();
|
|
135
111
|
default:
|
|
136
|
-
throw new Error(
|
|
112
|
+
throw new Error(`Unsupported calendar ${identifier}`);
|
|
137
113
|
}
|
|
138
114
|
};
|
|
139
|
-
|
|
140
|
-
if (locale.toLowerCase() !==
|
|
115
|
+
const ariaLabelIfNorwegian = (norwegianAriaLabel, locale, propsCollection) => {
|
|
116
|
+
if (locale.toLowerCase() !== "no-no") return propsCollection["aria-label"];
|
|
141
117
|
return norwegianAriaLabel;
|
|
142
118
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
var value = _ref.value,
|
|
152
|
-
type = _ref.type,
|
|
153
|
-
_ref$timezone = _ref.timezone,
|
|
154
|
-
timezone = _ref$timezone === void 0 ? 'Europe/Oslo' : _ref$timezone;
|
|
119
|
+
const lastMillisecondOfDay = (dateValue) => toCalendarDateTime(dateValue.add({ days: 1 })).add({
|
|
120
|
+
milliseconds: -1
|
|
121
|
+
});
|
|
122
|
+
const convertValueToType = ({
|
|
123
|
+
value,
|
|
124
|
+
type,
|
|
125
|
+
timezone = "Europe/Oslo"
|
|
126
|
+
}) => {
|
|
155
127
|
if (value === null) return null;
|
|
156
128
|
switch (type) {
|
|
157
|
-
case
|
|
158
|
-
if (!(
|
|
129
|
+
case "CalendarDate":
|
|
130
|
+
if (!("day" in value)) return today(timezone);
|
|
159
131
|
return toCalendarDate(value);
|
|
160
|
-
case
|
|
161
|
-
if (!(
|
|
132
|
+
case "CalendarDateTime":
|
|
133
|
+
if (!("day" in value)) return toCalendarDateTime(today(timezone), value);
|
|
162
134
|
return toCalendarDateTime(value);
|
|
163
|
-
case
|
|
164
|
-
if (!(
|
|
135
|
+
case "ZonedDateTime":
|
|
136
|
+
if (!("day" in value))
|
|
137
|
+
return toZoned(toCalendarDateTime(today(timezone), value), timezone);
|
|
165
138
|
return toZoned(value, timezone);
|
|
166
|
-
case
|
|
167
|
-
if (!(
|
|
168
|
-
if (!(
|
|
139
|
+
case "Time":
|
|
140
|
+
if (!("hour" in value)) return toTime(now(timezone));
|
|
141
|
+
if (!("day" in value)) return value;
|
|
169
142
|
return toTime(value);
|
|
170
143
|
default:
|
|
171
144
|
return value;
|
|
172
145
|
}
|
|
173
146
|
};
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
var focusSegment = function focusSegment(ref, segment) {
|
|
147
|
+
const modulo = (a, b) => (a % b + b) % b;
|
|
148
|
+
const focusSegment = (ref, segment) => {
|
|
178
149
|
if (ref.current) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
150
|
+
const segments = ref.current.querySelectorAll(
|
|
151
|
+
".eds-date-and-time-field__segment"
|
|
152
|
+
);
|
|
153
|
+
const firstSegment = segments[0];
|
|
154
|
+
const lastSegment = segments[segments.length - 1];
|
|
182
155
|
switch (segment) {
|
|
183
|
-
case
|
|
156
|
+
case "first":
|
|
184
157
|
return firstSegment.focus();
|
|
185
|
-
case
|
|
158
|
+
case "last":
|
|
186
159
|
return lastSegment.focus();
|
|
187
160
|
}
|
|
188
161
|
}
|
|
189
162
|
};
|
|
190
|
-
/** Based on code from https://stackoverflow.com/questions/6117814/get-week-of-year-in-javascript-like-in-php */
|
|
191
163
|
function getWeekNumberForDate(date) {
|
|
192
164
|
if (date === null) return -1;
|
|
193
|
-
|
|
165
|
+
const calendarDate = convertValueToType({
|
|
194
166
|
value: date,
|
|
195
|
-
type:
|
|
196
|
-
});
|
|
197
|
-
var firstDayOfWeek = startOfWeek(calendarDate, 'no-NO');
|
|
198
|
-
var thursdayOfWeek = firstDayOfWeek.add({
|
|
199
|
-
days: 3
|
|
167
|
+
type: "CalendarDate"
|
|
200
168
|
});
|
|
201
|
-
|
|
202
|
-
|
|
169
|
+
const firstDayOfWeek = startOfWeek(calendarDate, "no-NO");
|
|
170
|
+
const thursdayOfWeek = firstDayOfWeek.add({ days: 3 });
|
|
171
|
+
const firstDayOfYearForThursday = startOfYear(thursdayOfWeek);
|
|
172
|
+
const weekNumber = Math.ceil(
|
|
173
|
+
(thursdayOfWeek.compare(firstDayOfYearForThursday) + 1) / 7
|
|
174
|
+
);
|
|
203
175
|
return weekNumber;
|
|
204
176
|
}
|
|
205
|
-
function handleOnChange(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
177
|
+
function handleOnChange({
|
|
178
|
+
value,
|
|
179
|
+
selectedDate,
|
|
180
|
+
forcedReturnType,
|
|
181
|
+
onChange
|
|
182
|
+
}) {
|
|
183
|
+
if (forcedReturnType !== void 0 || !selectedDate) {
|
|
184
|
+
return onChange?.(
|
|
185
|
+
convertValueToType({
|
|
186
|
+
value,
|
|
187
|
+
type: forcedReturnType ?? "ZonedDateTime",
|
|
188
|
+
timezone: value !== null && "timezone" in value ? value.timezone : void 0
|
|
189
|
+
})
|
|
190
|
+
);
|
|
216
191
|
}
|
|
217
|
-
onChange
|
|
192
|
+
onChange?.(value);
|
|
218
193
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var _props = _extends({}, rest, {
|
|
254
|
-
label: label,
|
|
255
|
-
locale: customLocale != null ? customLocale : locale,
|
|
256
|
-
createCalendar: createCalendar,
|
|
194
|
+
const DateField = ({
|
|
195
|
+
selectedDate,
|
|
196
|
+
onChange,
|
|
197
|
+
label,
|
|
198
|
+
locale: customLocale,
|
|
199
|
+
showTimeZone,
|
|
200
|
+
showTime,
|
|
201
|
+
granularity = showTime ? "minute" : "day",
|
|
202
|
+
disabled,
|
|
203
|
+
readOnly,
|
|
204
|
+
isDisabled,
|
|
205
|
+
variant,
|
|
206
|
+
feedback,
|
|
207
|
+
validationVariant = "negative",
|
|
208
|
+
validationFeedback = "Ugyldig dato",
|
|
209
|
+
labelTooltip,
|
|
210
|
+
minDate,
|
|
211
|
+
maxDate,
|
|
212
|
+
forcedReturnType,
|
|
213
|
+
style,
|
|
214
|
+
className,
|
|
215
|
+
labelProps: parentLabelProps,
|
|
216
|
+
append,
|
|
217
|
+
prepend,
|
|
218
|
+
onValidate,
|
|
219
|
+
dateFieldRef: ref,
|
|
220
|
+
...rest
|
|
221
|
+
}) => {
|
|
222
|
+
const { locale } = useLocale();
|
|
223
|
+
const _props = {
|
|
224
|
+
...rest,
|
|
225
|
+
label,
|
|
226
|
+
locale: customLocale ?? locale,
|
|
227
|
+
createCalendar,
|
|
257
228
|
value: selectedDate,
|
|
258
|
-
onChange:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
265
|
-
},
|
|
229
|
+
onChange: (value) => handleOnChange({
|
|
230
|
+
value,
|
|
231
|
+
selectedDate,
|
|
232
|
+
forcedReturnType,
|
|
233
|
+
onChange
|
|
234
|
+
}),
|
|
266
235
|
hideTimeZone: !showTimeZone,
|
|
267
|
-
granularity
|
|
236
|
+
granularity,
|
|
268
237
|
minValue: minDate,
|
|
269
238
|
// this weird logic makes sure the entire day is included if no time is provided in maxDate
|
|
270
|
-
maxValue:
|
|
239
|
+
maxValue: "hour" in (maxDate ?? {}) ? maxDate : maxDate !== void 0 ? lastMillisecondOfDay(maxDate) : void 0,
|
|
271
240
|
isDisabled: isDisabled || disabled || readOnly,
|
|
272
241
|
shouldForceLeadingZeros: true
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
242
|
+
};
|
|
243
|
+
const state = useDateFieldState(_props);
|
|
244
|
+
const dateFieldRef = useRef(null);
|
|
245
|
+
const { labelProps, fieldProps } = useDateField(_props, state, dateFieldRef);
|
|
246
|
+
useEffect(() => onValidate?.(!state.isInvalid), [state.isInvalid]);
|
|
247
|
+
const id = useRandomId("datefield");
|
|
248
|
+
return /* @__PURE__ */ jsx(
|
|
249
|
+
ConditionalWrapper,
|
|
250
|
+
{
|
|
251
|
+
condition: customLocale !== void 0,
|
|
252
|
+
wrapper: (child) => /* @__PURE__ */ jsx(I18nProvider, { locale: customLocale, children: child }),
|
|
253
|
+
children: /* @__PURE__ */ jsx(
|
|
254
|
+
BaseFormControl,
|
|
255
|
+
{
|
|
256
|
+
append,
|
|
257
|
+
ariaAlertOnFeedback: true,
|
|
258
|
+
className: classNames("eds-datefield", className, {
|
|
259
|
+
"eds-datefield--has-tooltip": labelTooltip !== void 0
|
|
260
|
+
}),
|
|
261
|
+
disabled: isDisabled || disabled,
|
|
262
|
+
readOnly,
|
|
263
|
+
disableLabelAnimation: true,
|
|
264
|
+
feedback: feedback ?? (state.validationState === "invalid" ? validationFeedback : void 0),
|
|
265
|
+
label,
|
|
266
|
+
labelId: id,
|
|
267
|
+
labelProps: parentLabelProps ?? labelProps,
|
|
268
|
+
labelTooltip,
|
|
269
|
+
prepend,
|
|
270
|
+
ref: mergeRefs(ref, dateFieldRef),
|
|
271
|
+
style,
|
|
272
|
+
variant: variant ?? (state.isInvalid ? validationVariant : void 0),
|
|
273
|
+
...fieldProps,
|
|
274
|
+
children: state.segments.map((segment, i) => /* @__PURE__ */ jsx(FieldSegment, { segment, state }, i))
|
|
275
|
+
}
|
|
276
|
+
)
|
|
289
277
|
}
|
|
290
|
-
|
|
291
|
-
append: append,
|
|
292
|
-
ariaAlertOnFeedback: true,
|
|
293
|
-
className: classNames('eds-datefield', className, {
|
|
294
|
-
'eds-datefield--has-tooltip': labelTooltip !== undefined
|
|
295
|
-
}),
|
|
296
|
-
disabled: isDisabled || disabled,
|
|
297
|
-
readOnly: readOnly,
|
|
298
|
-
disableLabelAnimation: true,
|
|
299
|
-
feedback: feedback != null ? feedback : state.validationState === 'invalid' ? validationFeedback : undefined,
|
|
300
|
-
label: label,
|
|
301
|
-
labelId: id,
|
|
302
|
-
labelProps: parentLabelProps != null ? parentLabelProps : labelProps,
|
|
303
|
-
labelTooltip: labelTooltip,
|
|
304
|
-
prepend: prepend,
|
|
305
|
-
ref: mergeRefs(ref, dateFieldRef),
|
|
306
|
-
style: style,
|
|
307
|
-
variant: variant != null ? variant : state.isInvalid ? validationVariant : undefined
|
|
308
|
-
}, fieldProps), state.segments.map(function (segment, i) {
|
|
309
|
-
return React.createElement(FieldSegment, {
|
|
310
|
-
segment: segment,
|
|
311
|
-
state: state,
|
|
312
|
-
key: i
|
|
313
|
-
});
|
|
314
|
-
})));
|
|
278
|
+
);
|
|
315
279
|
};
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
buttonProps = _useButton.buttonProps;
|
|
326
|
-
return React.createElement(IconButton, _extends({}, buttonProps, {
|
|
327
|
-
ref: ref,
|
|
328
|
-
className: className,
|
|
329
|
-
style: style
|
|
330
|
-
}), children);
|
|
280
|
+
const CalendarButton = ({
|
|
281
|
+
children,
|
|
282
|
+
className,
|
|
283
|
+
style,
|
|
284
|
+
...props
|
|
285
|
+
}) => {
|
|
286
|
+
const ref = useRef(null);
|
|
287
|
+
const { buttonProps } = useButton(props, ref);
|
|
288
|
+
return /* @__PURE__ */ jsx(IconButton, { ...buttonProps, ref, className, style, children });
|
|
331
289
|
};
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
buttonProps.onKeyUp && buttonProps.onKeyUp(e);
|
|
380
|
-
if (e.key === 'Enter') {
|
|
381
|
-
// Used to force close calendar on select
|
|
290
|
+
const CalendarCell = ({
|
|
291
|
+
state,
|
|
292
|
+
date,
|
|
293
|
+
onSelectedCellClick = () => {
|
|
294
|
+
return;
|
|
295
|
+
},
|
|
296
|
+
onCellClick = () => {
|
|
297
|
+
return;
|
|
298
|
+
},
|
|
299
|
+
weekNumberString,
|
|
300
|
+
classNameForDate,
|
|
301
|
+
ariaLabelForDate,
|
|
302
|
+
...rest
|
|
303
|
+
}) => {
|
|
304
|
+
const cellRef = useRef(null);
|
|
305
|
+
const {
|
|
306
|
+
cellProps,
|
|
307
|
+
buttonProps,
|
|
308
|
+
isSelected,
|
|
309
|
+
isOutsideVisibleRange,
|
|
310
|
+
isDisabled,
|
|
311
|
+
isUnavailable,
|
|
312
|
+
formattedDate
|
|
313
|
+
} = useCalendarCell({ date }, state, cellRef);
|
|
314
|
+
const ariaLabel = `${buttonProps["aria-label"]}${weekNumberString} ${ariaLabelForDate?.(date) ?? ""}`;
|
|
315
|
+
const cellCanBeSelected = !(isOutsideVisibleRange || isDisabled || isUnavailable);
|
|
316
|
+
return /* @__PURE__ */ jsx("td", { ...cellProps, className: "eds-datepicker__calendar__grid__cell__td", children: /* @__PURE__ */ jsx(
|
|
317
|
+
"div",
|
|
318
|
+
{
|
|
319
|
+
...buttonProps,
|
|
320
|
+
"aria-label": ariaLabel,
|
|
321
|
+
"aria-hidden": isOutsideVisibleRange,
|
|
322
|
+
ref: cellRef,
|
|
323
|
+
hidden: isOutsideVisibleRange,
|
|
324
|
+
className: classNames("eds-datepicker__calendar__grid__cell", {
|
|
325
|
+
[classNameForDate?.(date) ?? ""]: !isOutsideVisibleRange,
|
|
326
|
+
"eds-datepicker__calendar__grid__cell--selected": isSelected,
|
|
327
|
+
"eds-datepicker__calendar__grid__cell--disabled": isDisabled || isUnavailable,
|
|
328
|
+
"eds-datepicker__calendar__grid__cell--outside-month": isOutsideVisibleRange,
|
|
329
|
+
"eds-datepicker__calendar__grid__cell--today": isEqualDay(
|
|
330
|
+
date,
|
|
331
|
+
now(state.timeZone ?? getLocalTimeZone())
|
|
332
|
+
)
|
|
333
|
+
}),
|
|
334
|
+
...rest,
|
|
335
|
+
onClick: (e) => {
|
|
336
|
+
buttonProps.onClick && buttonProps.onClick(e);
|
|
382
337
|
isSelected && onSelectedCellClick();
|
|
383
338
|
cellCanBeSelected && onCellClick();
|
|
384
|
-
}
|
|
339
|
+
},
|
|
340
|
+
onKeyUp: (e) => {
|
|
341
|
+
buttonProps.onKeyUp && buttonProps.onKeyUp(e);
|
|
342
|
+
if (e.key === "Enter") {
|
|
343
|
+
isSelected && onSelectedCellClick();
|
|
344
|
+
cellCanBeSelected && onCellClick();
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
children: formattedDate
|
|
385
348
|
}
|
|
386
|
-
|
|
349
|
+
) });
|
|
387
350
|
};
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (locale.toLowerCase().includes('no')) return ['ma', 'ti', 'on', 'to', 'fr', 'lø', 'sø'];
|
|
417
|
-
if (locale.toLowerCase().includes('en')) {
|
|
418
|
-
if (weekDays[0] === 'M') return ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
|
|
419
|
-
if (weekDays[0] === 'S') return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
351
|
+
const CalendarGrid = ({
|
|
352
|
+
state,
|
|
353
|
+
navigationDescription,
|
|
354
|
+
onSelectedCellClick = () => {
|
|
355
|
+
return;
|
|
356
|
+
},
|
|
357
|
+
onCellClick = () => {
|
|
358
|
+
return;
|
|
359
|
+
},
|
|
360
|
+
showWeekNumbers,
|
|
361
|
+
weekNumberHeader,
|
|
362
|
+
classNameForDate,
|
|
363
|
+
ariaLabelForDate,
|
|
364
|
+
...rest
|
|
365
|
+
}) => {
|
|
366
|
+
const calendarGridId = useRandomId("eds-calendar");
|
|
367
|
+
const { locale } = useLocale();
|
|
368
|
+
const { gridProps, headerProps, weekDays } = useCalendarGrid(rest, state);
|
|
369
|
+
const weeksInMonth = getWeeksInMonth(state.visibleRange.start, locale);
|
|
370
|
+
const weeksArray = Array.from(Array(weeksInMonth).keys());
|
|
371
|
+
const weekDaysMapped = () => {
|
|
372
|
+
if (locale.toLowerCase().includes("no"))
|
|
373
|
+
return ["ma", "ti", "on", "to", "fr", "lø", "sø"];
|
|
374
|
+
if (locale.toLowerCase().includes("en")) {
|
|
375
|
+
if (weekDays[0] === "M")
|
|
376
|
+
return ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"];
|
|
377
|
+
if (weekDays[0] === "S")
|
|
378
|
+
return ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
|
|
420
379
|
}
|
|
421
|
-
return weekDays.map(
|
|
422
|
-
return day.toLowerCase();
|
|
423
|
-
});
|
|
380
|
+
return weekDays.map((day) => day.toLowerCase());
|
|
424
381
|
};
|
|
425
|
-
|
|
382
|
+
const getNavigationDescription = () => {
|
|
426
383
|
if (navigationDescription) return navigationDescription;
|
|
427
|
-
if (locale.toLowerCase().includes(
|
|
428
|
-
|
|
384
|
+
if (locale.toLowerCase().includes("en"))
|
|
385
|
+
return "Use the arrow keys to navigate between dates";
|
|
386
|
+
return "Bruk piltastene til å navigere mellom datoer";
|
|
429
387
|
};
|
|
430
|
-
return
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
388
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
389
|
+
/* @__PURE__ */ jsxs(
|
|
390
|
+
"table",
|
|
391
|
+
{
|
|
392
|
+
...gridProps,
|
|
393
|
+
cellSpacing: "0",
|
|
394
|
+
className: "eds-datepicker__calendar__grid",
|
|
395
|
+
children: [
|
|
396
|
+
/* @__PURE__ */ jsx("thead", { ...headerProps, children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
397
|
+
showWeekNumbers && /* @__PURE__ */ jsx("th", { className: "eds-datepicker__calendar__grid__weeknumber-header", children: weekNumberHeader }),
|
|
398
|
+
weekDaysMapped().map((day) => /* @__PURE__ */ jsx("th", { children: day }, day))
|
|
399
|
+
] }) }),
|
|
400
|
+
/* @__PURE__ */ jsx("tbody", { children: weeksArray.map((weekIndex) => {
|
|
401
|
+
const weekNumber = getWeekNumberForDate(
|
|
402
|
+
state.getDatesInWeek(weekIndex)[0]
|
|
403
|
+
);
|
|
404
|
+
return /* @__PURE__ */ jsxs("tr", { children: [
|
|
405
|
+
showWeekNumbers && /* @__PURE__ */ jsx(
|
|
406
|
+
"th",
|
|
407
|
+
{
|
|
408
|
+
"aria-hidden": true,
|
|
409
|
+
className: "eds-datepicker__calendar__grid__weeknumber",
|
|
410
|
+
children: weekNumber
|
|
411
|
+
}
|
|
412
|
+
),
|
|
413
|
+
state.getDatesInWeek(weekIndex).map(
|
|
414
|
+
(date, i) => date ? /* @__PURE__ */ jsx(
|
|
415
|
+
CalendarCell,
|
|
416
|
+
{
|
|
417
|
+
state,
|
|
418
|
+
date,
|
|
419
|
+
"aria-describedby": calendarGridId + "description",
|
|
420
|
+
weekNumberString: showWeekNumbers ? `, ${weekNumberHeader} ${weekNumber},` : "",
|
|
421
|
+
onSelectedCellClick,
|
|
422
|
+
onCellClick,
|
|
423
|
+
classNameForDate,
|
|
424
|
+
ariaLabelForDate
|
|
425
|
+
},
|
|
426
|
+
`${date.month}.${date.day}`
|
|
427
|
+
) : /* @__PURE__ */ jsx("td", {}, i)
|
|
428
|
+
)
|
|
429
|
+
] }, weekIndex);
|
|
430
|
+
}) })
|
|
431
|
+
]
|
|
432
|
+
}
|
|
433
|
+
),
|
|
434
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { id: calendarGridId + "description", children: getNavigationDescription() })
|
|
435
|
+
] });
|
|
464
436
|
};
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
isDisabled: rest.disabled
|
|
473
|
-
}, rest);
|
|
474
|
-
var _useLocale = useLocale(),
|
|
475
|
-
locale = _useLocale.locale;
|
|
476
|
-
return React.createElement(I18nProvider, {
|
|
477
|
-
locale: localOverride != null ? localOverride : locale
|
|
478
|
-
}, React.createElement(CalendarBase, _extends({}, props)));
|
|
437
|
+
const Calendar = ({
|
|
438
|
+
locale: localOverride,
|
|
439
|
+
...rest
|
|
440
|
+
}) => {
|
|
441
|
+
const props = { isDisabled: rest.disabled, ...rest };
|
|
442
|
+
const { locale } = useLocale();
|
|
443
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale: localOverride ?? locale, children: /* @__PURE__ */ jsx(CalendarBase, { ...props }) });
|
|
479
444
|
};
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
rest
|
|
505
|
-
var _useLocale2 = useLocale(),
|
|
506
|
-
locale = _useLocale2.locale;
|
|
507
|
-
var _props = _extends({}, rest, {
|
|
445
|
+
const CalendarBase = ({
|
|
446
|
+
selectedDate,
|
|
447
|
+
onChange,
|
|
448
|
+
minDate,
|
|
449
|
+
maxDate,
|
|
450
|
+
showWeekNumbers = false,
|
|
451
|
+
weekNumberHeader = "uke",
|
|
452
|
+
forcedReturnType,
|
|
453
|
+
style,
|
|
454
|
+
className,
|
|
455
|
+
navigationDescription,
|
|
456
|
+
onSelectedCellClick = () => {
|
|
457
|
+
return;
|
|
458
|
+
},
|
|
459
|
+
onCellClick = () => {
|
|
460
|
+
return;
|
|
461
|
+
},
|
|
462
|
+
classNameForDate,
|
|
463
|
+
ariaLabelForDate,
|
|
464
|
+
calendarRef,
|
|
465
|
+
...rest
|
|
466
|
+
}) => {
|
|
467
|
+
const { locale } = useLocale();
|
|
468
|
+
const _props = {
|
|
469
|
+
...rest,
|
|
508
470
|
value: selectedDate,
|
|
509
|
-
onChange:
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
locale: locale,
|
|
518
|
-
createCalendar: createCalendar,
|
|
471
|
+
onChange: (value) => handleOnChange({
|
|
472
|
+
value,
|
|
473
|
+
selectedDate,
|
|
474
|
+
forcedReturnType,
|
|
475
|
+
onChange
|
|
476
|
+
}),
|
|
477
|
+
locale,
|
|
478
|
+
createCalendar,
|
|
519
479
|
minValue: minDate,
|
|
520
480
|
maxValue: maxDate
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
481
|
+
};
|
|
482
|
+
const state = useCalendarState(_props);
|
|
483
|
+
const { calendarProps, prevButtonProps, nextButtonProps, title } = useCalendar(_props, state);
|
|
484
|
+
useEffect(
|
|
485
|
+
() => rest.onValidate?.(!state.isValueInvalid),
|
|
486
|
+
[state.isValueInvalid]
|
|
487
|
+
);
|
|
488
|
+
return /* @__PURE__ */ jsxs(
|
|
489
|
+
"div",
|
|
490
|
+
{
|
|
491
|
+
...calendarProps,
|
|
492
|
+
ref: calendarRef,
|
|
493
|
+
className: classNames("eds-datepicker__calendar", className),
|
|
494
|
+
style,
|
|
495
|
+
children: [
|
|
496
|
+
/* @__PURE__ */ jsxs("div", { className: "eds-datepicker__calendar__header", children: [
|
|
497
|
+
/* @__PURE__ */ jsx(
|
|
498
|
+
CalendarButton,
|
|
499
|
+
{
|
|
500
|
+
...prevButtonProps,
|
|
501
|
+
"aria-label": ariaLabelIfNorwegian(
|
|
502
|
+
"Forrige måned",
|
|
503
|
+
locale,
|
|
504
|
+
prevButtonProps
|
|
505
|
+
),
|
|
506
|
+
children: /* @__PURE__ */ jsx(LeftArrowIcon, { size: 20 })
|
|
507
|
+
}
|
|
508
|
+
),
|
|
509
|
+
/* @__PURE__ */ jsx("h2", { children: title }),
|
|
510
|
+
/* @__PURE__ */ jsx(
|
|
511
|
+
CalendarButton,
|
|
512
|
+
{
|
|
513
|
+
...nextButtonProps,
|
|
514
|
+
"aria-label": ariaLabelIfNorwegian(
|
|
515
|
+
"Neste måned",
|
|
516
|
+
locale,
|
|
517
|
+
nextButtonProps
|
|
518
|
+
),
|
|
519
|
+
children: /* @__PURE__ */ jsx(RightArrowIcon, { size: 20 })
|
|
520
|
+
}
|
|
521
|
+
)
|
|
522
|
+
] }),
|
|
523
|
+
/* @__PURE__ */ jsx(
|
|
524
|
+
CalendarGrid,
|
|
525
|
+
{
|
|
526
|
+
...rest,
|
|
527
|
+
state,
|
|
528
|
+
navigationDescription,
|
|
529
|
+
onSelectedCellClick,
|
|
530
|
+
onCellClick,
|
|
531
|
+
classNameForDate,
|
|
532
|
+
ariaLabelForDate,
|
|
533
|
+
showWeekNumbers,
|
|
534
|
+
weekNumberHeader
|
|
535
|
+
}
|
|
536
|
+
)
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
);
|
|
555
540
|
};
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return handleOnChange({
|
|
596
|
-
value: value,
|
|
597
|
-
selectedDate: selectedDate,
|
|
598
|
-
forcedReturnType: rest.forcedReturnType,
|
|
599
|
-
onChange: rest.onChange
|
|
600
|
-
});
|
|
601
|
-
},
|
|
541
|
+
const DatePicker = ({
|
|
542
|
+
selectedDate,
|
|
543
|
+
locale,
|
|
544
|
+
disabled,
|
|
545
|
+
readOnly,
|
|
546
|
+
showTime,
|
|
547
|
+
showTimeZone = false,
|
|
548
|
+
classNameForDate,
|
|
549
|
+
className,
|
|
550
|
+
variant,
|
|
551
|
+
feedback,
|
|
552
|
+
validationVariant,
|
|
553
|
+
validationFeedback,
|
|
554
|
+
showWeekNumbers,
|
|
555
|
+
weekNumberHeader,
|
|
556
|
+
disableModal = false,
|
|
557
|
+
labelTooltip,
|
|
558
|
+
navigationDescription,
|
|
559
|
+
minDate,
|
|
560
|
+
maxDate,
|
|
561
|
+
modalTreshold = 1e3,
|
|
562
|
+
ariaLabelForDate,
|
|
563
|
+
append,
|
|
564
|
+
prepend,
|
|
565
|
+
granularity = showTime ? "minute" : "day",
|
|
566
|
+
...rest
|
|
567
|
+
}) => {
|
|
568
|
+
const CALENDAR_MODAL_MAX_SCREEN_WIDTH = modalTreshold;
|
|
569
|
+
const datePickerRef = useRef(null);
|
|
570
|
+
const calendarRef = useRef(null);
|
|
571
|
+
const { width } = useWindowDimensions();
|
|
572
|
+
const _props = {
|
|
573
|
+
...rest,
|
|
574
|
+
onChange: (value) => handleOnChange({
|
|
575
|
+
value,
|
|
576
|
+
selectedDate,
|
|
577
|
+
forcedReturnType: rest.forcedReturnType,
|
|
578
|
+
onChange: rest.onChange
|
|
579
|
+
}),
|
|
602
580
|
minValue: minDate,
|
|
603
581
|
// this weird logic makes sure the entire day is included if no time is provided in maxDate
|
|
604
|
-
maxValue:
|
|
582
|
+
maxValue: "hour" in (maxDate ?? {}) ? maxDate : maxDate !== void 0 ? lastMillisecondOfDay(maxDate) : void 0,
|
|
605
583
|
value: selectedDate,
|
|
606
|
-
granularity
|
|
584
|
+
granularity,
|
|
607
585
|
isDisabled: disabled || readOnly
|
|
586
|
+
};
|
|
587
|
+
const state = useDatePickerState(_props);
|
|
588
|
+
const {
|
|
589
|
+
groupProps,
|
|
590
|
+
labelProps,
|
|
591
|
+
fieldProps,
|
|
592
|
+
buttonProps,
|
|
593
|
+
dialogProps,
|
|
594
|
+
calendarProps
|
|
595
|
+
} = useDatePicker(_props, state, datePickerRef);
|
|
596
|
+
const { refs, floatingStyles, update } = useFloating({
|
|
597
|
+
whileElementsMounted: (ref, float, update2) => autoUpdate(ref, float, update2, { elementResize: false }),
|
|
598
|
+
placement: "bottom-start",
|
|
599
|
+
middleware: [
|
|
600
|
+
offset(space.extraSmall2),
|
|
601
|
+
flip(),
|
|
602
|
+
shift({ padding: space.extraSmall })
|
|
603
|
+
]
|
|
608
604
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
buttonProps = _useDatePicker.buttonProps,
|
|
615
|
-
dialogProps = _useDatePicker.dialogProps,
|
|
616
|
-
calendarProps = _useDatePicker.calendarProps;
|
|
617
|
-
// calculations for floating-UI popover position
|
|
618
|
-
var _useFloating = useFloating({
|
|
619
|
-
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
620
|
-
return autoUpdate(ref, _float, update, {
|
|
621
|
-
elementResize: false
|
|
622
|
-
});
|
|
623
|
-
},
|
|
624
|
-
placement: 'bottom-start',
|
|
625
|
-
middleware: [offset(space.extraSmall2), flip(), shift({
|
|
626
|
-
padding: space.extraSmall
|
|
627
|
-
})]
|
|
628
|
-
}),
|
|
629
|
-
refs = _useFloating.refs,
|
|
630
|
-
floatingStyles = _useFloating.floatingStyles,
|
|
631
|
-
update = _useFloating.update;
|
|
632
|
-
useOnClickOutside([calendarRef], function () {
|
|
633
|
-
return state.setOpen(false);
|
|
634
|
-
});
|
|
635
|
-
useOnEscape(calendarRef, function () {
|
|
636
|
-
return state.setOpen(false);
|
|
637
|
-
});
|
|
638
|
-
var calendarSharedProps = _extends({}, dialogProps, calendarProps, {
|
|
605
|
+
useOnClickOutside([calendarRef], () => state.setOpen(false));
|
|
606
|
+
useOnEscape(calendarRef, () => state.setOpen(false));
|
|
607
|
+
const calendarSharedProps = {
|
|
608
|
+
...dialogProps,
|
|
609
|
+
...calendarProps,
|
|
639
610
|
// We don't use handleOnChange here since it's handled internally by Calendar
|
|
640
611
|
onChange: rest.onChange,
|
|
641
612
|
forcedReturnType: rest.forcedReturnType,
|
|
642
|
-
disabled
|
|
643
|
-
navigationDescription
|
|
644
|
-
onSelectedCellClick:
|
|
645
|
-
return state.setOpen(false);
|
|
646
|
-
},
|
|
613
|
+
disabled,
|
|
614
|
+
navigationDescription,
|
|
615
|
+
onSelectedCellClick: () => state.setOpen(false),
|
|
647
616
|
// onCellClick is a temporary fix solving an issue where the
|
|
648
617
|
// calendar sometimes doesn't close on date selection
|
|
649
|
-
onCellClick:
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
ref: refs.setFloating
|
|
667
|
-
}, React.createElement(FocusLock, {
|
|
668
|
-
disabled: !state.isOpen || isModal,
|
|
669
|
-
returnFocus: true
|
|
670
|
-
}, state.isOpen && React.createElement(Calendar, _extends({}, calendarSharedProps))));
|
|
671
|
-
var modalCalendar = React.createElement(Modal, {
|
|
672
|
-
size: "small",
|
|
673
|
-
title: "",
|
|
674
|
-
open: state.isOpen,
|
|
675
|
-
onDismiss: function onDismiss() {
|
|
676
|
-
return state.setOpen(false);
|
|
677
|
-
},
|
|
678
|
-
className: "eds-datepicker__calendar-modal"
|
|
679
|
-
}, React.createElement(Calendar, _extends({}, calendarSharedProps)));
|
|
680
|
-
return React.createElement(ConditionalWrapper, {
|
|
681
|
-
condition: locale !== undefined,
|
|
682
|
-
wrapper: function wrapper(child) {
|
|
683
|
-
return React.createElement(I18nProvider, {
|
|
684
|
-
locale: locale
|
|
685
|
-
}, child);
|
|
618
|
+
onCellClick: () => state.setOpen(false),
|
|
619
|
+
selectedDate,
|
|
620
|
+
minDate,
|
|
621
|
+
maxDate,
|
|
622
|
+
calendarRef,
|
|
623
|
+
classNameForDate,
|
|
624
|
+
ariaLabelForDate,
|
|
625
|
+
showWeekNumbers,
|
|
626
|
+
weekNumberHeader
|
|
627
|
+
};
|
|
628
|
+
const isModal = typeof width !== "undefined" && width <= CALENDAR_MODAL_MAX_SCREEN_WIDTH && !disableModal;
|
|
629
|
+
const popoverCalendar = /* @__PURE__ */ jsx(
|
|
630
|
+
"div",
|
|
631
|
+
{
|
|
632
|
+
style: { ...floatingStyles, zIndex: zIndexes.popover },
|
|
633
|
+
ref: refs.setFloating,
|
|
634
|
+
children: /* @__PURE__ */ jsx(FocusLock, { disabled: !state.isOpen || isModal, returnFocus: true, children: state.isOpen && /* @__PURE__ */ jsx(Calendar, { ...calendarSharedProps }) })
|
|
686
635
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
636
|
+
);
|
|
637
|
+
const modalCalendar = /* @__PURE__ */ jsx(
|
|
638
|
+
Modal,
|
|
639
|
+
{
|
|
640
|
+
size: "small",
|
|
641
|
+
title: "",
|
|
642
|
+
open: state.isOpen,
|
|
643
|
+
onDismiss: () => state.setOpen(false),
|
|
644
|
+
className: "eds-datepicker__calendar-modal",
|
|
645
|
+
children: /* @__PURE__ */ jsx(Calendar, { ...calendarSharedProps })
|
|
646
|
+
}
|
|
647
|
+
);
|
|
648
|
+
return /* @__PURE__ */ jsxs(
|
|
649
|
+
ConditionalWrapper,
|
|
650
|
+
{
|
|
651
|
+
condition: locale !== void 0,
|
|
652
|
+
wrapper: (child) => /* @__PURE__ */ jsx(I18nProvider, { locale, children: child }),
|
|
653
|
+
children: [
|
|
654
|
+
/* @__PURE__ */ jsx(
|
|
655
|
+
DateField,
|
|
656
|
+
{
|
|
657
|
+
...groupProps,
|
|
658
|
+
...fieldProps,
|
|
659
|
+
...rest,
|
|
660
|
+
append: !disabled && !readOnly && /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
|
|
661
|
+
append,
|
|
662
|
+
/* @__PURE__ */ jsx(
|
|
663
|
+
CalendarButton,
|
|
664
|
+
{
|
|
665
|
+
...buttonProps,
|
|
666
|
+
onPress: () => {
|
|
667
|
+
state.setOpen(!state.isOpen);
|
|
668
|
+
update();
|
|
669
|
+
},
|
|
670
|
+
className: "eds-datepicker__open-calendar-button",
|
|
671
|
+
children: /* @__PURE__ */ jsx(CalendarIcon, {})
|
|
672
|
+
}
|
|
673
|
+
)
|
|
674
|
+
] }),
|
|
675
|
+
prepend,
|
|
676
|
+
className: classNames("eds-datepicker", className, {
|
|
677
|
+
"eds-datepicker--disabled": disabled
|
|
678
|
+
}),
|
|
679
|
+
disabled,
|
|
680
|
+
readOnly,
|
|
681
|
+
feedback,
|
|
682
|
+
labelProps,
|
|
683
|
+
labelTooltip,
|
|
684
|
+
maxDate,
|
|
685
|
+
minDate,
|
|
686
|
+
dateFieldRef: (node) => {
|
|
687
|
+
refs.setReference(node);
|
|
688
|
+
datePickerRef.current = node;
|
|
689
|
+
},
|
|
690
|
+
selectedDate,
|
|
691
|
+
showTime,
|
|
692
|
+
showTimeZone,
|
|
693
|
+
validationFeedback,
|
|
694
|
+
validationVariant,
|
|
695
|
+
variant
|
|
696
|
+
}
|
|
697
|
+
),
|
|
698
|
+
isModal ? modalCalendar : popoverCalendar
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
);
|
|
722
702
|
};
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
useOnMount(function () {
|
|
703
|
+
const NativeDatePicker = React.forwardRef(
|
|
704
|
+
({
|
|
705
|
+
className,
|
|
706
|
+
style,
|
|
707
|
+
label,
|
|
708
|
+
onChange,
|
|
709
|
+
feedback,
|
|
710
|
+
variant,
|
|
711
|
+
disableLabelAnimation,
|
|
712
|
+
prepend = /* @__PURE__ */ jsx(DateIcon, { inline: true }),
|
|
713
|
+
...rest
|
|
714
|
+
}, ref) => {
|
|
715
|
+
const nativedatepickerId = useRandomId("eds-nativetimepicker");
|
|
716
|
+
return /* @__PURE__ */ jsx(
|
|
717
|
+
BaseFormControl,
|
|
718
|
+
{
|
|
719
|
+
style,
|
|
720
|
+
className,
|
|
721
|
+
prepend,
|
|
722
|
+
label,
|
|
723
|
+
feedback,
|
|
724
|
+
variant,
|
|
725
|
+
labelId: nativedatepickerId,
|
|
726
|
+
disableLabelAnimation,
|
|
727
|
+
isFilled: true,
|
|
728
|
+
children: /* @__PURE__ */ jsx(
|
|
729
|
+
NativeDatePickerBase,
|
|
730
|
+
{
|
|
731
|
+
onChange,
|
|
732
|
+
"aria-labelledby": nativedatepickerId,
|
|
733
|
+
ref,
|
|
734
|
+
variant,
|
|
735
|
+
...rest
|
|
736
|
+
}
|
|
737
|
+
)
|
|
738
|
+
}
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
const NativeDatePickerBase = React.forwardRef(({ onChange, variant, value, ...rest }, ref) => {
|
|
743
|
+
const contextVariant = useVariant();
|
|
744
|
+
const currentVariant = variant || contextVariant;
|
|
745
|
+
const { isFilled: isDatepickerFilled, setFilled: setFiller } = useInputGroupContext();
|
|
746
|
+
useOnMount(() => {
|
|
768
747
|
setFiller && !isDatepickerFilled && setFiller(true);
|
|
769
748
|
});
|
|
770
|
-
React.useEffect(
|
|
749
|
+
React.useEffect(() => {
|
|
771
750
|
if (value) {
|
|
772
751
|
setFiller && !isDatepickerFilled && setFiller(true);
|
|
773
752
|
} else {
|
|
774
753
|
setFiller && isDatepickerFilled && setFiller(false);
|
|
775
754
|
}
|
|
776
755
|
}, [value, setFiller, isDatepickerFilled]);
|
|
777
|
-
|
|
756
|
+
const handleChange = (event) => {
|
|
778
757
|
if (isFilled(event.target)) {
|
|
779
758
|
setFiller && !isDatepickerFilled && setFiller(true);
|
|
780
759
|
} else {
|
|
@@ -784,236 +763,243 @@ var NativeDatePickerBase = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
784
763
|
onChange(event);
|
|
785
764
|
}
|
|
786
765
|
};
|
|
787
|
-
return
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
766
|
+
return /* @__PURE__ */ jsx(
|
|
767
|
+
"input",
|
|
768
|
+
{
|
|
769
|
+
ref,
|
|
770
|
+
"aria-invalid": currentVariant === "error",
|
|
771
|
+
type: "date",
|
|
772
|
+
className: "eds-form-control eds-native-date-picker",
|
|
773
|
+
onChange: handleChange,
|
|
774
|
+
value,
|
|
775
|
+
...rest
|
|
776
|
+
}
|
|
777
|
+
);
|
|
795
778
|
});
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
return
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
779
|
+
const TimePickerArrowButton = ({
|
|
780
|
+
direction,
|
|
781
|
+
onClick,
|
|
782
|
+
disabled,
|
|
783
|
+
readonly,
|
|
784
|
+
"aria-label": ariaLabel,
|
|
785
|
+
...rest
|
|
786
|
+
}) => {
|
|
787
|
+
return /* @__PURE__ */ jsx(
|
|
788
|
+
IconButton,
|
|
789
|
+
{
|
|
790
|
+
className: classNames(
|
|
791
|
+
"eds-timepicker__arrowbutton",
|
|
792
|
+
`eds-timepicker__arrowbutton--${direction}`,
|
|
793
|
+
{ "eds-timepicker__arrowbutton--disabled": disabled }
|
|
794
|
+
),
|
|
795
|
+
type: "button",
|
|
796
|
+
tabIndex: -1,
|
|
797
|
+
onClick,
|
|
798
|
+
"aria-label": ariaLabel,
|
|
799
|
+
disabled,
|
|
800
|
+
...rest,
|
|
801
|
+
children: direction === "left" ? /* @__PURE__ */ jsx(LeftArrowIcon, {}) : /* @__PURE__ */ jsx(RightArrowIcon, {})
|
|
802
|
+
}
|
|
803
|
+
);
|
|
814
804
|
};
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
forcedTimeZone = _ref.forcedTimeZone,
|
|
842
|
-
append = _ref.append,
|
|
843
|
-
prepend = _ref.prepend,
|
|
844
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
845
|
-
var _useLocale = useLocale(),
|
|
846
|
-
locale = _useLocale.locale;
|
|
805
|
+
const TimePicker = ({
|
|
806
|
+
selectedTime,
|
|
807
|
+
onChange,
|
|
808
|
+
disabled,
|
|
809
|
+
readOnly,
|
|
810
|
+
className,
|
|
811
|
+
style,
|
|
812
|
+
label,
|
|
813
|
+
labelTooltip,
|
|
814
|
+
feedback,
|
|
815
|
+
granularity,
|
|
816
|
+
variant,
|
|
817
|
+
locale: customLocale,
|
|
818
|
+
showTimeZone,
|
|
819
|
+
showSeconds = false,
|
|
820
|
+
minuteIncrementForArrowButtons = 30,
|
|
821
|
+
leftArrowButtonAriaLabel = `Trekk fra ${minuteIncrementForArrowButtons} minutter`,
|
|
822
|
+
rightArrowButtonAriaLabel = `Legg til ${minuteIncrementForArrowButtons} minutter`,
|
|
823
|
+
inputRef,
|
|
824
|
+
forcedReturnType,
|
|
825
|
+
forcedTimeZone,
|
|
826
|
+
append,
|
|
827
|
+
prepend,
|
|
828
|
+
...rest
|
|
829
|
+
}) => {
|
|
830
|
+
let { locale } = useLocale();
|
|
847
831
|
if (customLocale) locale = customLocale;
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
if (forcedReturnType !==
|
|
852
|
-
return onChange(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
832
|
+
const timePickerId = useRandomId("eds-timepicker");
|
|
833
|
+
const timeZone = forcedTimeZone ?? (selectedTime !== null && "timezone" in selectedTime ? selectedTime.timezone : "Europe/Oslo");
|
|
834
|
+
const handleOnChange2 = (value) => {
|
|
835
|
+
if (forcedReturnType !== void 0 || !selectedTime) {
|
|
836
|
+
return onChange(
|
|
837
|
+
convertValueToType({
|
|
838
|
+
value,
|
|
839
|
+
type: forcedReturnType ?? "ZonedDateTime",
|
|
840
|
+
timezone: timeZone
|
|
841
|
+
})
|
|
842
|
+
);
|
|
857
843
|
}
|
|
858
844
|
onChange(value);
|
|
859
845
|
};
|
|
860
|
-
|
|
861
|
-
onChange:
|
|
862
|
-
label
|
|
863
|
-
locale
|
|
846
|
+
const state = useTimeFieldState({
|
|
847
|
+
onChange: handleOnChange2,
|
|
848
|
+
label,
|
|
849
|
+
locale,
|
|
864
850
|
value: selectedTime,
|
|
865
|
-
granularity:
|
|
851
|
+
granularity: granularity ?? showSeconds ? "second" : "minute",
|
|
866
852
|
hideTimeZone: !showTimeZone,
|
|
867
853
|
isDisabled: disabled || readOnly,
|
|
868
|
-
shouldForceLeadingZeros: true
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
854
|
+
shouldForceLeadingZeros: true,
|
|
855
|
+
...rest
|
|
856
|
+
});
|
|
857
|
+
const timeFieldRef = useRef(null);
|
|
858
|
+
const { labelProps, fieldProps } = useTimeField(
|
|
859
|
+
{ ...rest, label },
|
|
860
|
+
state,
|
|
861
|
+
timeFieldRef
|
|
862
|
+
);
|
|
863
|
+
const id = useRandomId("timepicker");
|
|
864
|
+
const getCurrentTime = () => {
|
|
865
|
+
const getCurrentTimeWithCorrectType = convertValueToType({
|
|
879
866
|
value: now(timeZone),
|
|
880
|
-
type: forcedReturnType
|
|
867
|
+
type: forcedReturnType ?? "ZonedDateTime"
|
|
881
868
|
});
|
|
882
869
|
return getCurrentTimeWithCorrectType;
|
|
883
870
|
};
|
|
884
|
-
|
|
885
|
-
if (selectedTime === null) return
|
|
871
|
+
const handleOnClickArrowButton = (operation) => {
|
|
872
|
+
if (selectedTime === null) return handleOnChange2(getCurrentTime());
|
|
886
873
|
switch (operation) {
|
|
887
|
-
case
|
|
888
|
-
return
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
874
|
+
case "add":
|
|
875
|
+
return handleOnChange2(
|
|
876
|
+
selectedTime.add({
|
|
877
|
+
minutes: minuteIncrementForArrowButtons - modulo(selectedTime.minute, minuteIncrementForArrowButtons)
|
|
878
|
+
})
|
|
879
|
+
);
|
|
880
|
+
case "subtract":
|
|
881
|
+
return handleOnChange2(
|
|
882
|
+
selectedTime.subtract({
|
|
883
|
+
minutes: modulo(selectedTime.minute - 1, minuteIncrementForArrowButtons) + 1
|
|
884
|
+
})
|
|
885
|
+
);
|
|
895
886
|
}
|
|
896
887
|
};
|
|
897
|
-
return
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
labelProps: _extends({}, labelProps, {
|
|
930
|
-
'aria-describedby': timePickerId + 'description'
|
|
931
|
-
}),
|
|
932
|
-
labelTooltip: labelTooltip,
|
|
933
|
-
prepend: React.createElement("div", {
|
|
934
|
-
style: {
|
|
935
|
-
display: 'flex',
|
|
936
|
-
alignItems: 'center'
|
|
937
|
-
}
|
|
938
|
-
}, React.createElement(TimePickerArrowButton, {
|
|
939
|
-
direction: "left",
|
|
940
|
-
disabled: disabled || readOnly,
|
|
941
|
-
"aria-label": leftArrowButtonAriaLabel,
|
|
942
|
-
onClick: function onClick() {
|
|
943
|
-
return handleOnClickArrowButton('subtract');
|
|
888
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale, children: /* @__PURE__ */ jsxs(
|
|
889
|
+
BaseFormControl,
|
|
890
|
+
{
|
|
891
|
+
append: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
|
|
892
|
+
append,
|
|
893
|
+
/* @__PURE__ */ jsx(
|
|
894
|
+
TimePickerArrowButton,
|
|
895
|
+
{
|
|
896
|
+
direction: "right",
|
|
897
|
+
disabled: disabled || readOnly,
|
|
898
|
+
"aria-label": rightArrowButtonAriaLabel,
|
|
899
|
+
onClick: () => handleOnClickArrowButton("add"),
|
|
900
|
+
onFocus: () => focusSegment(timeFieldRef, "last")
|
|
901
|
+
}
|
|
902
|
+
)
|
|
903
|
+
] }),
|
|
904
|
+
ariaAlertOnFeedback: true,
|
|
905
|
+
"aria-describedby": timePickerId + "description",
|
|
906
|
+
className: classNames("eds-timepicker", className, {
|
|
907
|
+
"eds-timepicker--disabled": disabled,
|
|
908
|
+
"eds-timepicker--has-tooltip": labelTooltip !== void 0,
|
|
909
|
+
"eds-timepicker--readonly": readOnly
|
|
910
|
+
}),
|
|
911
|
+
disabled,
|
|
912
|
+
readOnly,
|
|
913
|
+
disableLabelAnimation: true,
|
|
914
|
+
feedback,
|
|
915
|
+
label,
|
|
916
|
+
labelId: id,
|
|
917
|
+
labelProps: {
|
|
918
|
+
...labelProps,
|
|
919
|
+
"aria-describedby": timePickerId + "description"
|
|
944
920
|
},
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
921
|
+
labelTooltip,
|
|
922
|
+
prepend: /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center" }, children: [
|
|
923
|
+
/* @__PURE__ */ jsx(
|
|
924
|
+
TimePickerArrowButton,
|
|
925
|
+
{
|
|
926
|
+
direction: "left",
|
|
927
|
+
disabled: disabled || readOnly,
|
|
928
|
+
"aria-label": leftArrowButtonAriaLabel,
|
|
929
|
+
onClick: () => handleOnClickArrowButton("subtract"),
|
|
930
|
+
onFocus: () => focusSegment(timeFieldRef, "first")
|
|
931
|
+
}
|
|
932
|
+
),
|
|
933
|
+
prepend
|
|
934
|
+
] }),
|
|
935
|
+
ref: inputRef,
|
|
936
|
+
style,
|
|
937
|
+
variant,
|
|
938
|
+
children: [
|
|
939
|
+
/* @__PURE__ */ jsx(
|
|
940
|
+
"span",
|
|
941
|
+
{
|
|
942
|
+
ref: timeFieldRef,
|
|
943
|
+
...fieldProps,
|
|
944
|
+
style: { display: "contents" },
|
|
945
|
+
children: state.segments.map((segment, i) => /* @__PURE__ */ jsx(
|
|
946
|
+
FieldSegment,
|
|
947
|
+
{
|
|
948
|
+
segment,
|
|
949
|
+
state,
|
|
950
|
+
"aria-describedby": timePickerId + "description"
|
|
951
|
+
},
|
|
952
|
+
i
|
|
953
|
+
))
|
|
954
|
+
}
|
|
955
|
+
),
|
|
956
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { id: timePickerId + "description", children: selectedTime !== null ? "valgt tid: " + selectedTime.hour.toString().padStart(2, "0") + ":" + selectedTime.minute.toString().padStart(2, "0") + (showSeconds ? ":" + selectedTime.second.toString().padStart(2, "0") : "") : "" })
|
|
957
|
+
]
|
|
957
958
|
}
|
|
958
|
-
|
|
959
|
-
return React.createElement(FieldSegment, {
|
|
960
|
-
segment: segment,
|
|
961
|
-
state: state,
|
|
962
|
-
key: i,
|
|
963
|
-
"aria-describedby": timePickerId + 'description'
|
|
964
|
-
});
|
|
965
|
-
})), React.createElement(VisuallyHidden, {
|
|
966
|
-
id: timePickerId + 'description'
|
|
967
|
-
}, selectedTime !== null ? 'valgt tid: ' + selectedTime.hour.toString().padStart(2, '0') + ':' + selectedTime.minute.toString().padStart(2, '0') + (showSeconds ? ':' + selectedTime.second.toString().padStart(2, '0') : '') : '')));
|
|
959
|
+
) });
|
|
968
960
|
};
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
})
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
var contextVariant = useVariant();
|
|
1002
|
-
var currentVariant = rest.variant || contextVariant;
|
|
1003
|
-
var _useInputGroupContext = useInputGroupContext(),
|
|
1004
|
-
isTimepickerFilled = _useInputGroupContext.isFilled,
|
|
1005
|
-
setFiller = _useInputGroupContext.setFilled;
|
|
1006
|
-
useOnMount(function () {
|
|
961
|
+
const NativeTimePicker = React.forwardRef(
|
|
962
|
+
({ className, style, onChange, label, feedback, variant, prepend, ...rest }, ref) => {
|
|
963
|
+
const nativetimepickerId = useRandomId("eds-native-timepicker");
|
|
964
|
+
return /* @__PURE__ */ jsx(
|
|
965
|
+
BaseFormControl,
|
|
966
|
+
{
|
|
967
|
+
style,
|
|
968
|
+
className: classNames(className, "eds-native-timepicker"),
|
|
969
|
+
prepend,
|
|
970
|
+
label,
|
|
971
|
+
feedback,
|
|
972
|
+
variant,
|
|
973
|
+
labelId: nativetimepickerId,
|
|
974
|
+
disableLabelAnimation: true,
|
|
975
|
+
children: /* @__PURE__ */ jsx(
|
|
976
|
+
NativeTimePickerBase,
|
|
977
|
+
{
|
|
978
|
+
onChange,
|
|
979
|
+
"aria-labelledby": nativetimepickerId,
|
|
980
|
+
ref,
|
|
981
|
+
...rest
|
|
982
|
+
}
|
|
983
|
+
)
|
|
984
|
+
}
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
);
|
|
988
|
+
const NativeTimePickerBase = React.forwardRef(({ onChange, value, ...rest }, ref) => {
|
|
989
|
+
const contextVariant = useVariant();
|
|
990
|
+
const currentVariant = rest.variant || contextVariant;
|
|
991
|
+
const { isFilled: isTimepickerFilled, setFilled: setFiller } = useInputGroupContext();
|
|
992
|
+
useOnMount(() => {
|
|
1007
993
|
setFiller && !isTimepickerFilled && setFiller(true);
|
|
1008
994
|
});
|
|
1009
|
-
React.useEffect(
|
|
995
|
+
React.useEffect(() => {
|
|
1010
996
|
if (value) {
|
|
1011
997
|
setFiller && !isTimepickerFilled && setFiller(true);
|
|
1012
998
|
} else {
|
|
1013
999
|
setFiller && isTimepickerFilled && setFiller(false);
|
|
1014
1000
|
}
|
|
1015
1001
|
}, [value, setFiller, isTimepickerFilled]);
|
|
1016
|
-
|
|
1002
|
+
const handleChange = (event) => {
|
|
1017
1003
|
if (isFilled(event.target)) {
|
|
1018
1004
|
setFiller && !isTimepickerFilled && setFiller(true);
|
|
1019
1005
|
} else {
|
|
@@ -1023,211 +1009,224 @@ var NativeTimePickerBase = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
1023
1009
|
onChange(event);
|
|
1024
1010
|
}
|
|
1025
1011
|
};
|
|
1026
|
-
return
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1012
|
+
return /* @__PURE__ */ jsx(
|
|
1013
|
+
"input",
|
|
1014
|
+
{
|
|
1015
|
+
ref,
|
|
1016
|
+
"aria-invalid": currentVariant === "error",
|
|
1017
|
+
type: "time",
|
|
1018
|
+
className: "eds-form-control",
|
|
1019
|
+
onChange: handleChange,
|
|
1020
|
+
value,
|
|
1021
|
+
...rest
|
|
1022
|
+
}
|
|
1023
|
+
);
|
|
1034
1024
|
});
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
var _useState = useState(''),
|
|
1063
|
-
inputText = _useState[0],
|
|
1064
|
-
setInputText = _useState[1];
|
|
1065
|
-
var timeFieldRef = useRef(null);
|
|
1066
|
-
var _useState2 = useState(null),
|
|
1067
|
-
lastValidSelectedTime = _useState2[0],
|
|
1068
|
-
setLastValidSelectedTime = _useState2[1];
|
|
1069
|
-
var _useLocale = useLocale(),
|
|
1070
|
-
locale = _useLocale.locale;
|
|
1071
|
-
var state = useTimeFieldState(_extends({
|
|
1072
|
-
onChange: onChange,
|
|
1073
|
-
label: label,
|
|
1074
|
-
locale: locale,
|
|
1025
|
+
const SimpleTimePicker = ({
|
|
1026
|
+
append,
|
|
1027
|
+
className,
|
|
1028
|
+
disabled,
|
|
1029
|
+
feedback,
|
|
1030
|
+
showClockIcon = "right",
|
|
1031
|
+
inputRef,
|
|
1032
|
+
label,
|
|
1033
|
+
labelTooltip,
|
|
1034
|
+
onChange,
|
|
1035
|
+
padding = "default",
|
|
1036
|
+
prepend,
|
|
1037
|
+
readOnly,
|
|
1038
|
+
selectedTime,
|
|
1039
|
+
showSeconds,
|
|
1040
|
+
style,
|
|
1041
|
+
variant,
|
|
1042
|
+
...rest
|
|
1043
|
+
}) => {
|
|
1044
|
+
const [inputText, setInputText] = useState("");
|
|
1045
|
+
const timeFieldRef = useRef(null);
|
|
1046
|
+
const [lastValidSelectedTime, setLastValidSelectedTime] = useState(null);
|
|
1047
|
+
const { locale } = useLocale();
|
|
1048
|
+
const state = useTimeFieldState({
|
|
1049
|
+
onChange,
|
|
1050
|
+
label,
|
|
1051
|
+
locale,
|
|
1075
1052
|
value: selectedTime,
|
|
1076
1053
|
hideTimeZone: true,
|
|
1077
1054
|
isDisabled: disabled,
|
|
1078
|
-
isReadOnly: readOnly
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1055
|
+
isReadOnly: readOnly,
|
|
1056
|
+
...rest
|
|
1057
|
+
});
|
|
1058
|
+
const { labelProps, fieldProps } = useTimeField(
|
|
1059
|
+
{ ...rest, label },
|
|
1060
|
+
state,
|
|
1061
|
+
timeFieldRef
|
|
1062
|
+
);
|
|
1063
|
+
useEffect(() => {
|
|
1086
1064
|
updateInputWithSelectedTime();
|
|
1087
|
-
// @ts-expect-error TimeType and MappedTimeValue<TimeType> is actually the same
|
|
1088
1065
|
if (selectedTime !== null) setLastValidSelectedTime(selectedTime);
|
|
1089
|
-
}, [selectedTime
|
|
1090
|
-
|
|
1091
|
-
|
|
1066
|
+
}, [selectedTime?.toString()]);
|
|
1067
|
+
const updateInputWithSelectedTime = () => {
|
|
1068
|
+
const selectedTimeString = getStringFromTimeValue(selectedTime);
|
|
1092
1069
|
setInputText(selectedTimeString);
|
|
1093
|
-
|
|
1094
|
-
if (selectedTimeString ===
|
|
1070
|
+
const timeFieldIsFocused = document.activeElement === timeFieldRef?.current;
|
|
1071
|
+
if (selectedTimeString === "" && !timeFieldIsFocused)
|
|
1072
|
+
addPlaceholderToInput();
|
|
1095
1073
|
};
|
|
1096
|
-
|
|
1097
|
-
if (timeValue === null) return
|
|
1098
|
-
|
|
1074
|
+
const getStringFromTimeValue = (timeValue) => {
|
|
1075
|
+
if (timeValue === null) return "";
|
|
1076
|
+
const timeObject = "day" in timeValue ? toTime(timeValue) : timeValue;
|
|
1099
1077
|
if (showSeconds) return timeObject.toString().slice(0, 8);
|
|
1100
1078
|
return timeObject.toString().slice(0, 5);
|
|
1101
1079
|
};
|
|
1102
|
-
|
|
1103
|
-
if (showSeconds) setInputText(
|
|
1080
|
+
const addPlaceholderToInput = () => {
|
|
1081
|
+
if (showSeconds) setInputText("–– : –– : ––");
|
|
1082
|
+
else setInputText("–– : ––");
|
|
1104
1083
|
};
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
if (newTime ===
|
|
1084
|
+
const handleChangeTime = () => {
|
|
1085
|
+
const newTime = getValueForOnChangeFromInput();
|
|
1086
|
+
if (newTime === 1) {
|
|
1108
1087
|
return updateInputWithSelectedTime();
|
|
1109
1088
|
}
|
|
1110
|
-
if (
|
|
1089
|
+
if (newTime?.toString() !== selectedTime?.toString()) onChange?.(newTime);
|
|
1111
1090
|
};
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
if (newTimeObject ===
|
|
1116
|
-
return
|
|
1091
|
+
const getValueForOnChangeFromInput = () => {
|
|
1092
|
+
const formatedTimeString = formatTimeString(inputText);
|
|
1093
|
+
const newTimeObject = formatedTimeStringToTimeObject(formatedTimeString);
|
|
1094
|
+
if (newTimeObject === 1) {
|
|
1095
|
+
return 1;
|
|
1117
1096
|
}
|
|
1118
|
-
if (newTimeObject ===
|
|
1097
|
+
if (newTimeObject === 0) {
|
|
1119
1098
|
return null;
|
|
1120
1099
|
}
|
|
1121
|
-
|
|
1100
|
+
const updatedSelectedTime = getSelectedTimeWithTimeFromObject(newTimeObject);
|
|
1122
1101
|
return updatedSelectedTime;
|
|
1123
1102
|
};
|
|
1124
|
-
|
|
1125
|
-
if (timeString.length === 0) return
|
|
1126
|
-
if (timeString.length < 3 || timeString.length > 8)
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1103
|
+
const formatTimeString = (timeString) => {
|
|
1104
|
+
if (timeString.length === 0) return 0;
|
|
1105
|
+
if (timeString.length < 3 || timeString.length > 8)
|
|
1106
|
+
return 1;
|
|
1107
|
+
const numberOfColons = (timeString.match(new RegExp(":", "g")) || []).length;
|
|
1108
|
+
const stringLength = timeString.length;
|
|
1130
1109
|
if (numberOfColons === 2 && stringLength >= 7) {
|
|
1131
|
-
return timeString.padStart(8,
|
|
1110
|
+
return timeString.padStart(8, "0");
|
|
1132
1111
|
}
|
|
1133
|
-
// targets 'd:dd' and 'dd:dd'
|
|
1134
1112
|
if (numberOfColons === 1) {
|
|
1135
|
-
return timeString.padStart(5,
|
|
1113
|
+
return timeString.padStart(5, "0");
|
|
1136
1114
|
}
|
|
1137
|
-
if (stringLength > 6) return
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
if (stringSlice ===
|
|
1115
|
+
if (stringLength > 6) return 1;
|
|
1116
|
+
const stringLengthIsEven = stringLength % 2 == 0;
|
|
1117
|
+
const hourString = stringLengthIsEven ? timeString.slice(0, 2) : timeString.slice(0, 1);
|
|
1118
|
+
const minuteString = stringLengthIsEven ? timeString.slice(2, 4) : timeString.slice(1, 3);
|
|
1119
|
+
const secondString = (() => {
|
|
1120
|
+
const stringSlice = stringLengthIsEven ? timeString.slice(4, 6) : timeString.slice(3, 5);
|
|
1121
|
+
if (stringSlice === "") return "00";
|
|
1144
1122
|
return stringSlice;
|
|
1145
|
-
}();
|
|
1146
|
-
|
|
1123
|
+
})();
|
|
1124
|
+
const timeStringWithColon = hourString.padStart(2, "0") + ":" + minuteString + (showSeconds ? ":" + secondString : "");
|
|
1147
1125
|
return timeStringWithColon;
|
|
1148
1126
|
};
|
|
1149
|
-
|
|
1150
|
-
if (formatedTimeString ===
|
|
1151
|
-
if (formatedTimeString ===
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1127
|
+
const formatedTimeStringToTimeObject = (formatedTimeString) => {
|
|
1128
|
+
if (formatedTimeString === 1) return 1;
|
|
1129
|
+
if (formatedTimeString === 0)
|
|
1130
|
+
return 0;
|
|
1131
|
+
const isNumberTest = /^\d+$/;
|
|
1132
|
+
const hourString = formatedTimeString.slice(0, 2);
|
|
1133
|
+
const minuteString = formatedTimeString.slice(3, 5);
|
|
1134
|
+
const secondString = formatedTimeString.slice(6, 8);
|
|
1135
|
+
if (hourString.match(isNumberTest) && minuteString.match(isNumberTest) && (secondString === "" || secondString.match(isNumberTest))) {
|
|
1157
1136
|
try {
|
|
1158
|
-
|
|
1137
|
+
const timeObject = parseTime(formatedTimeString);
|
|
1159
1138
|
return timeObject;
|
|
1160
1139
|
} catch (e) {
|
|
1161
|
-
return
|
|
1140
|
+
return 1;
|
|
1162
1141
|
}
|
|
1163
1142
|
}
|
|
1164
|
-
return
|
|
1143
|
+
return 1;
|
|
1165
1144
|
};
|
|
1166
|
-
|
|
1167
|
-
|
|
1145
|
+
const getSelectedTimeWithTimeFromObject = (newTime) => {
|
|
1146
|
+
const selectedTimeWithUpdateTime = (lastValidSelectedTime ?? new Time()).set({
|
|
1168
1147
|
hour: newTime.hour,
|
|
1169
1148
|
minute: newTime.minute,
|
|
1170
1149
|
second: newTime.second
|
|
1171
1150
|
});
|
|
1172
1151
|
return selectedTimeWithUpdateTime;
|
|
1173
1152
|
};
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1153
|
+
const {
|
|
1154
|
+
onBlur,
|
|
1155
|
+
onClick,
|
|
1156
|
+
onDragStart,
|
|
1157
|
+
onFocus,
|
|
1158
|
+
onKeyDown,
|
|
1159
|
+
onKeyUp,
|
|
1160
|
+
onMouseDown,
|
|
1161
|
+
onPointerDown,
|
|
1162
|
+
onPointerUp,
|
|
1163
|
+
...usedFieldProps
|
|
1164
|
+
} = fieldProps;
|
|
1165
|
+
return /* @__PURE__ */ jsx(I18nProvider, { locale, children: /* @__PURE__ */ jsx(
|
|
1166
|
+
TextField,
|
|
1167
|
+
{
|
|
1168
|
+
append: append || (showClockIcon === true || showClockIcon === "right" ? /* @__PURE__ */ jsx(ClockIcon, { onClick: () => timeFieldRef?.current?.focus(), inline: true }) : void 0),
|
|
1169
|
+
className: classNames("eds-simple-timepicker", {
|
|
1170
|
+
"eds-simple-timepicker--padding-large": padding === "large",
|
|
1171
|
+
"eds-simple-timepicker--show-seconds": showSeconds,
|
|
1172
|
+
"eds-simple-timepicker--hide-clock": !showClockIcon,
|
|
1173
|
+
"eds-simple-timepicker--has-tooltip": labelTooltip !== void 0
|
|
1174
|
+
}),
|
|
1175
|
+
disabled,
|
|
1176
|
+
disableLabelAnimation: true,
|
|
1177
|
+
feedback,
|
|
1178
|
+
label,
|
|
1179
|
+
labelProps,
|
|
1180
|
+
labelTooltip,
|
|
1181
|
+
onBlur: () => {
|
|
1182
|
+
handleChangeTime();
|
|
1183
|
+
if (selectedTime === null) {
|
|
1184
|
+
addPlaceholderToInput();
|
|
1185
|
+
}
|
|
1182
1186
|
},
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
}, usedFieldProps)));
|
|
1187
|
+
onChange: (e) => setInputText(e.target.value),
|
|
1188
|
+
onFocus: () => {
|
|
1189
|
+
if (selectedTime === null) {
|
|
1190
|
+
setInputText("");
|
|
1191
|
+
}
|
|
1192
|
+
},
|
|
1193
|
+
onKeyDown: ({ key }) => {
|
|
1194
|
+
if (key === "Enter") handleChangeTime();
|
|
1195
|
+
},
|
|
1196
|
+
placeholder: showSeconds ? "–– : –– : ––" : "–– : ––",
|
|
1197
|
+
prepend: prepend || (showClockIcon === "left" ? /* @__PURE__ */ jsx(ClockIcon, { onClick: () => timeFieldRef?.current?.focus() }) : void 0),
|
|
1198
|
+
readOnly,
|
|
1199
|
+
ref: mergeRefs(timeFieldRef, inputRef),
|
|
1200
|
+
style,
|
|
1201
|
+
value: inputText,
|
|
1202
|
+
variant,
|
|
1203
|
+
...usedFieldProps
|
|
1204
|
+
}
|
|
1205
|
+
) });
|
|
1206
|
+
};
|
|
1207
|
+
warnAboutMissingStyles("datepicker", "form", "icons");
|
|
1208
|
+
export {
|
|
1209
|
+
Calendar,
|
|
1210
|
+
CalendarDate2 as CalendarDate,
|
|
1211
|
+
CalendarDateTime2 as CalendarDateTime,
|
|
1212
|
+
DateField,
|
|
1213
|
+
DatePicker,
|
|
1214
|
+
NativeDatePicker,
|
|
1215
|
+
NativeTimePicker,
|
|
1216
|
+
SimpleTimePicker,
|
|
1217
|
+
Time2 as Time,
|
|
1218
|
+
TimePicker,
|
|
1219
|
+
ZonedDateTime2 as ZonedDateTime,
|
|
1220
|
+
ariaLabelIfNorwegian,
|
|
1221
|
+
convertValueToType,
|
|
1222
|
+
createCalendar,
|
|
1223
|
+
focusSegment,
|
|
1224
|
+
getWeekNumberForDate,
|
|
1225
|
+
handleOnChange,
|
|
1226
|
+
lastMillisecondOfDay,
|
|
1227
|
+
modulo,
|
|
1228
|
+
nativeDateToDateValue,
|
|
1229
|
+
nativeDateToTimeValue,
|
|
1230
|
+
timeOrDateValueToNativeDate
|
|
1228
1231
|
};
|
|
1229
|
-
|
|
1230
|
-
warnAboutMissingStyles('datepicker', 'form', 'icons');
|
|
1231
|
-
|
|
1232
|
-
export { Calendar, DateField, DatePicker, NativeDatePicker, NativeTimePicker, SimpleTimePicker, TimePicker, ariaLabelIfNorwegian, convertValueToType, createCalendar, focusSegment, getWeekNumberForDate, handleOnChange, lastMillisecondOfDay, modulo, nativeDateToDateValue, nativeDateToTimeValue, timeOrDateValueToNativeDate };
|
|
1233
1232
|
//# sourceMappingURL=datepicker.esm.js.map
|