@entur/datepicker 4.0.0-beta.5 → 4.0.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/CHANGELOG.md +56 -0
- package/LICENSE.md +0 -71
- package/dist/DatePicker/{beta/Calendar.d.ts → Calendar.d.ts} +1 -0
- package/dist/DatePicker/{beta/CalendarCell.d.ts → CalendarCell.d.ts} +2 -1
- package/dist/DatePicker/{beta/CalendarGrid.d.ts → CalendarGrid.d.ts} +2 -1
- package/dist/DatePicker/{beta/DateField.d.ts → DateField.d.ts} +2 -3
- package/dist/DatePicker/DatePicker.d.ts +48 -175
- package/dist/{NativeDatePicker.d.ts → DatePicker/NativeDatePicker.d.ts} +0 -0
- package/dist/DatePicker/index.d.ts +3 -1
- package/dist/TimePicker/TimePicker.d.ts +3 -3
- package/dist/datepicker.cjs.development.js +91 -517
- package/dist/datepicker.cjs.development.js.map +1 -1
- package/dist/datepicker.cjs.production.min.js +1 -1
- package/dist/datepicker.cjs.production.min.js.map +1 -1
- package/dist/datepicker.esm.js +91 -515
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/styles.css +100 -206
- package/package.json +21 -22
- package/dist/DatePicker/DatePickerHeader.d.ts +0 -9
- package/dist/DatePicker/DatePickerInput.d.ts +0 -31
- package/dist/DatePicker/beta/DatePicker.d.ts +0 -62
- package/dist/DatePicker/beta/index.d.ts +0 -3
package/dist/datepicker.esm.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { useRef
|
|
3
|
-
import ReactDatepicker, { registerLocale } from 'react-datepicker';
|
|
4
|
-
import { parse, isSameDay } from 'date-fns';
|
|
5
|
-
import { nb } from 'date-fns/locale';
|
|
6
|
-
import classNames from 'classnames';
|
|
7
|
-
import { LeftArrowIcon, RightArrowIcon, CalendarIcon, DateIcon } from '@entur/icons';
|
|
8
|
-
import { Heading3 } from '@entur/typography';
|
|
9
|
-
import { IconButton } from '@entur/button';
|
|
10
|
-
import { TextField, BaseFormControl, useVariant, useInputGroupContext, isFilled } from '@entur/form';
|
|
11
|
-
import { Tooltip } from '@entur/tooltip';
|
|
12
|
-
import 'react-datepicker/dist/react-datepicker.css';
|
|
1
|
+
import { useRandomId, ConditionalWrapper, mergeRefs, useWindowDimensions, useOnClickOutside, useOnEscape, useOnMount, warnAboutMissingStyles } from '@entur/utils';
|
|
2
|
+
import React, { useRef } from 'react';
|
|
13
3
|
import { useDateFieldState, useDatePickerState, useTimeFieldState } from '@react-stately/datepicker';
|
|
14
4
|
import { useDateSegment, useDateField, useDatePicker, useTimeField } from '@react-aria/datepicker';
|
|
15
5
|
import { useLocale, I18nProvider } from '@react-aria/i18n';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { BaseFormControl, useVariant, useInputGroupContext, isFilled } from '@entur/form';
|
|
16
8
|
import { ZonedDateTime, parseAbsolute, Time, CalendarDate, CalendarDateTime, getLocalTimeZone, GregorianCalendar, isEqualDay, now, getWeeksInMonth } from '@internationalized/date';
|
|
17
9
|
import { useCalendarCell, useCalendarGrid, useCalendar } from '@react-aria/calendar';
|
|
18
10
|
import { useCalendarState } from '@react-stately/calendar';
|
|
11
|
+
import { LeftArrowIcon, RightArrowIcon, CalendarIcon, DateIcon } from '@entur/icons';
|
|
19
12
|
import { useButton } from '@react-aria/button';
|
|
13
|
+
import { IconButton } from '@entur/button';
|
|
20
14
|
import { VisuallyHidden } from '@entur/a11y';
|
|
21
|
-
import { useFloating, offset, flip, shift } from '@floating-ui/react-dom';
|
|
15
|
+
import { useFloating, autoUpdate, offset, flip, shift } from '@floating-ui/react-dom';
|
|
22
16
|
import FocusLock from 'react-focus-lock';
|
|
23
17
|
import { space, zIndexes } from '@entur/tokens';
|
|
24
18
|
import { Modal } from '@entur/modal';
|
|
@@ -56,433 +50,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
56
50
|
return target;
|
|
57
51
|
}
|
|
58
52
|
|
|
59
|
-
var DatePickerHeader = function DatePickerHeader(_ref) {
|
|
60
|
-
var _date$getMonth;
|
|
61
|
-
|
|
62
|
-
var date = _ref.date,
|
|
63
|
-
decreaseMonth = _ref.decreaseMonth,
|
|
64
|
-
increaseMonth = _ref.increaseMonth,
|
|
65
|
-
prevMonthButtonDisabled = _ref.prevMonthButtonDisabled,
|
|
66
|
-
nextMonthButtonDisabled = _ref.nextMonthButtonDisabled,
|
|
67
|
-
nextMonthAriaLabel = _ref.nextMonthAriaLabel,
|
|
68
|
-
previousMonthAriaLabel = _ref.previousMonthAriaLabel,
|
|
69
|
-
locale = _ref.locale;
|
|
70
|
-
var currentMonthIndex = (_date$getMonth = date == null ? void 0 : date.getMonth()) != null ? _date$getMonth : 0;
|
|
71
|
-
return React.createElement("div", {
|
|
72
|
-
className: "eds-datepicker__calender__header"
|
|
73
|
-
}, React.createElement(IconButton, {
|
|
74
|
-
type: "button",
|
|
75
|
-
className: "eds-datepicker__calender__header__month-button--left",
|
|
76
|
-
onClick: decreaseMonth,
|
|
77
|
-
disabled: prevMonthButtonDisabled,
|
|
78
|
-
"aria-label": previousMonthAriaLabel + " (" + getMonthName(currentMonthIndex - 1, locale) + ")"
|
|
79
|
-
}, React.createElement(LeftArrowIcon, null)), React.createElement(Heading3, {
|
|
80
|
-
className: "eds-datepicker__calender__header__month-text"
|
|
81
|
-
}, getMonthName(currentMonthIndex, locale)), React.createElement(Heading3, {
|
|
82
|
-
className: "eds-datepicker__calender__header__month-text"
|
|
83
|
-
}, date == null ? void 0 : date.getFullYear()), React.createElement(IconButton, {
|
|
84
|
-
type: "button",
|
|
85
|
-
className: "eds-datepicker__calender__header__month-button--right",
|
|
86
|
-
onClick: increaseMonth,
|
|
87
|
-
disabled: nextMonthButtonDisabled,
|
|
88
|
-
"aria-label": nextMonthAriaLabel + " (" + getMonthName(currentMonthIndex + 1, locale) + ")"
|
|
89
|
-
}, React.createElement(RightArrowIcon, null)));
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
function getMonthName(monthIndex, locale) {
|
|
93
|
-
var year = new Date().getFullYear();
|
|
94
|
-
var formatter = new Intl.DateTimeFormat(locale.code, {
|
|
95
|
-
month: 'long'
|
|
96
|
-
});
|
|
97
|
-
return formatter.format(new Date(year, monthIndex));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
var _excluded$a = ["style", "label", "inputPlaceholder", "prepend", "feedback", "variant", "disabled", "calendarButtonTooltipOpen", "calendarButtonTooltipClose", "hideCalendarButton", "disableLabelAnimation", "inputRef", "calendarButtonId", "forwardRef", "toggleCalendarGUI", "onKeyDownInput", "onBlurInput", "selectedDate", "setFocusToCalendarGUI", "setShouldFocusOnCalendarButtonAfterSelect", "calendarGUIIsOpen", "placeholder", "onClick", "aria-labelledby"];
|
|
101
|
-
var DatePickerInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
102
|
-
var style = _ref.style,
|
|
103
|
-
label = _ref.label,
|
|
104
|
-
inputPlaceholder = _ref.inputPlaceholder,
|
|
105
|
-
prepend = _ref.prepend,
|
|
106
|
-
feedback = _ref.feedback,
|
|
107
|
-
variant = _ref.variant,
|
|
108
|
-
disabled = _ref.disabled,
|
|
109
|
-
calendarButtonTooltipOpen = _ref.calendarButtonTooltipOpen,
|
|
110
|
-
calendarButtonTooltipClose = _ref.calendarButtonTooltipClose,
|
|
111
|
-
hideCalendarButton = _ref.hideCalendarButton,
|
|
112
|
-
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
113
|
-
inputRef = _ref.inputRef,
|
|
114
|
-
calendarButtonId = _ref.calendarButtonId,
|
|
115
|
-
forwardRef = _ref.forwardRef,
|
|
116
|
-
toggleCalendarGUI = _ref.toggleCalendarGUI,
|
|
117
|
-
onKeyDownInput = _ref.onKeyDownInput,
|
|
118
|
-
onBlurInput = _ref.onBlurInput,
|
|
119
|
-
selectedDate = _ref.selectedDate,
|
|
120
|
-
setFocusToCalendarGUI = _ref.setFocusToCalendarGUI,
|
|
121
|
-
setShouldFocusOnCalendarButtonAfterSelect = _ref.setShouldFocusOnCalendarButtonAfterSelect,
|
|
122
|
-
calendarGUIIsOpen = _ref.calendarGUIIsOpen,
|
|
123
|
-
onClick = _ref.onClick,
|
|
124
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$a);
|
|
125
|
-
|
|
126
|
-
React.useEffect(function () {
|
|
127
|
-
var _inputRef$current, _inputRef$current2, _inputRef$current3;
|
|
128
|
-
|
|
129
|
-
(_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.addEventListener('keydown', handleOnKeyDown);
|
|
130
|
-
(_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.addEventListener('blur', handleOnBlur);
|
|
131
|
-
(_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.addEventListener('focus', handleOnFocus);
|
|
132
|
-
return function () {
|
|
133
|
-
var _inputRef$current4, _inputRef$current5, _inputRef$current6;
|
|
134
|
-
|
|
135
|
-
(_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.removeEventListener('keydown', handleOnKeyDown);
|
|
136
|
-
(_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.removeEventListener('blur', handleOnBlur);
|
|
137
|
-
(_inputRef$current6 = inputRef.current) == null ? void 0 : _inputRef$current6.removeEventListener('focus', handleOnFocus);
|
|
138
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
139
|
-
}, [inputRef, selectedDate]);
|
|
140
|
-
|
|
141
|
-
function handleOnKeyDown(event) {
|
|
142
|
-
onKeyDownInput(event);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function handleOnBlur(event) {
|
|
146
|
-
onBlurInput(event);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
var handleOnFocus = function handleOnFocus() {
|
|
150
|
-
return requestAnimationFrame(function () {
|
|
151
|
-
var _inputRef$current7;
|
|
152
|
-
|
|
153
|
-
return (_inputRef$current7 = inputRef.current) == null ? void 0 : _inputRef$current7.select();
|
|
154
|
-
});
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
var handleOnClickInputField = function handleOnClickInputField(event) {
|
|
158
|
-
setShouldFocusOnCalendarButtonAfterSelect(false);
|
|
159
|
-
onClick && onClick(event);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
var handleOnClickCalendarButton = function handleOnClickCalendarButton() {
|
|
163
|
-
toggleCalendarGUI();
|
|
164
|
-
setFocusToCalendarGUI();
|
|
165
|
-
setShouldFocusOnCalendarButtonAfterSelect(true);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
var calendarButtonAriaLabel = function calendarButtonAriaLabel() {
|
|
169
|
-
var _inputRef$current8;
|
|
170
|
-
|
|
171
|
-
var buttonStateText = calendarGUIIsOpen() ? calendarButtonTooltipClose : calendarButtonTooltipOpen;
|
|
172
|
-
var currentSelectionText = selectedDate ? ((_inputRef$current8 = inputRef.current) == null ? void 0 : _inputRef$current8.value) + " valgt" : 'Ingen dato valgt';
|
|
173
|
-
return buttonStateText + ", " + currentSelectionText;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
return React.createElement(TextField, _extends({
|
|
177
|
-
style: style,
|
|
178
|
-
label: label,
|
|
179
|
-
placeholder: inputPlaceholder,
|
|
180
|
-
prepend: prepend,
|
|
181
|
-
feedback: feedback,
|
|
182
|
-
variant: variant,
|
|
183
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
184
|
-
ref: mergeRefs(ref, inputRef, forwardRef),
|
|
185
|
-
onClick: handleOnClickInputField,
|
|
186
|
-
ariaAlertOnFeedback: true,
|
|
187
|
-
append: !hideCalendarButton && React.createElement(Tooltip, {
|
|
188
|
-
placement: "top",
|
|
189
|
-
content: calendarGUIIsOpen() ? calendarButtonTooltipClose : calendarButtonTooltipOpen,
|
|
190
|
-
disableHoverListener: disabled,
|
|
191
|
-
disableFocusListener: disabled
|
|
192
|
-
}, React.createElement(IconButton, {
|
|
193
|
-
id: calendarButtonId,
|
|
194
|
-
type: "button",
|
|
195
|
-
onClick: handleOnClickCalendarButton,
|
|
196
|
-
tabIndex: calendarGUIIsOpen() ? -1 : 0,
|
|
197
|
-
"aria-label": calendarButtonAriaLabel()
|
|
198
|
-
}, React.createElement(CalendarIcon, null)))
|
|
199
|
-
}, rest));
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
var _excluded$9 = ["style", "className", "selectedDate", "label", "placeholder", "onChange", "onKeyDown", "dateFormats", "minDate", "maxDate", "inline", "disabled", "prepend", "feedback", "variant", "validationFeedback", "validationVariant", "disableLabelAnimation", "calendarButtonTooltipOpen", "calendarButtonTooltipClose", "hideCalendarButton", "hideCalendar", "hideValidation", "weekLabel", "chooseDayAriaLabelPrefix", "previousMonthAriaLabel", "nextMonthAriaLabel", "locale", "open"];
|
|
203
|
-
registerLocale('nb', nb);
|
|
204
|
-
var DatePicker = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
205
|
-
var style = _ref.style,
|
|
206
|
-
className = _ref.className,
|
|
207
|
-
selectedDate = _ref.selectedDate,
|
|
208
|
-
label = _ref.label,
|
|
209
|
-
_ref$placeholder = _ref.placeholder,
|
|
210
|
-
placeholder = _ref$placeholder === void 0 ? 'dd.mm.yyyy' : _ref$placeholder,
|
|
211
|
-
onChange = _ref.onChange,
|
|
212
|
-
_ref$onKeyDown = _ref.onKeyDown,
|
|
213
|
-
onKeyDown = _ref$onKeyDown === void 0 ? function () {
|
|
214
|
-
return null;
|
|
215
|
-
} : _ref$onKeyDown,
|
|
216
|
-
_ref$dateFormats = _ref.dateFormats,
|
|
217
|
-
dateFormats = _ref$dateFormats === void 0 ? ['dd.MM.yyyy', 'ddMMyyyy', 'dd/MM/yyyy', 'ddMMyy'] : _ref$dateFormats,
|
|
218
|
-
minDate = _ref.minDate,
|
|
219
|
-
maxDate = _ref.maxDate,
|
|
220
|
-
_ref$inline = _ref.inline,
|
|
221
|
-
inline = _ref$inline === void 0 ? false : _ref$inline,
|
|
222
|
-
disabled = _ref.disabled,
|
|
223
|
-
prepend = _ref.prepend,
|
|
224
|
-
_ref$feedback = _ref.feedback,
|
|
225
|
-
feedback = _ref$feedback === void 0 ? '' : _ref$feedback,
|
|
226
|
-
variant = _ref.variant,
|
|
227
|
-
_ref$validationFeedba = _ref.validationFeedback,
|
|
228
|
-
validationFeedback = _ref$validationFeedba === void 0 ? 'Ugyldig dato' : _ref$validationFeedba,
|
|
229
|
-
_ref$validationVarian = _ref.validationVariant,
|
|
230
|
-
validationVariant = _ref$validationVarian === void 0 ? 'error' : _ref$validationVarian,
|
|
231
|
-
_ref$disableLabelAnim = _ref.disableLabelAnimation,
|
|
232
|
-
disableLabelAnimation = _ref$disableLabelAnim === void 0 ? false : _ref$disableLabelAnim,
|
|
233
|
-
_ref$calendarButtonTo = _ref.calendarButtonTooltipOpen,
|
|
234
|
-
calendarButtonTooltipOpen = _ref$calendarButtonTo === void 0 ? 'Åpne\xa0kalender' : _ref$calendarButtonTo,
|
|
235
|
-
_ref$calendarButtonTo2 = _ref.calendarButtonTooltipClose,
|
|
236
|
-
calendarButtonTooltipClose = _ref$calendarButtonTo2 === void 0 ? 'Lukk\xa0kalender' : _ref$calendarButtonTo2,
|
|
237
|
-
_ref$hideCalendarButt = _ref.hideCalendarButton,
|
|
238
|
-
hideCalendarButton = _ref$hideCalendarButt === void 0 ? false : _ref$hideCalendarButt,
|
|
239
|
-
_ref$hideCalendar = _ref.hideCalendar,
|
|
240
|
-
hideCalendar = _ref$hideCalendar === void 0 ? false : _ref$hideCalendar,
|
|
241
|
-
_ref$hideValidation = _ref.hideValidation,
|
|
242
|
-
hideValidation = _ref$hideValidation === void 0 ? false : _ref$hideValidation,
|
|
243
|
-
_ref$weekLabel = _ref.weekLabel,
|
|
244
|
-
weekLabel = _ref$weekLabel === void 0 ? 'uke' : _ref$weekLabel,
|
|
245
|
-
_ref$chooseDayAriaLab = _ref.chooseDayAriaLabelPrefix,
|
|
246
|
-
chooseDayAriaLabelPrefix = _ref$chooseDayAriaLab === void 0 ? 'Velg' : _ref$chooseDayAriaLab,
|
|
247
|
-
_ref$previousMonthAri = _ref.previousMonthAriaLabel,
|
|
248
|
-
previousMonthAriaLabel = _ref$previousMonthAri === void 0 ? 'Forrige måned' : _ref$previousMonthAri,
|
|
249
|
-
_ref$nextMonthAriaLab = _ref.nextMonthAriaLabel,
|
|
250
|
-
nextMonthAriaLabel = _ref$nextMonthAriaLab === void 0 ? 'Neste måned' : _ref$nextMonthAriaLab,
|
|
251
|
-
_ref$locale = _ref.locale,
|
|
252
|
-
locale = _ref$locale === void 0 ? nb : _ref$locale,
|
|
253
|
-
open = _ref.open,
|
|
254
|
-
rest = _objectWithoutPropertiesLoose(_ref, _excluded$9);
|
|
255
|
-
|
|
256
|
-
var datepickerId = useRandomId('eds-datepicker');
|
|
257
|
-
var datepickerRef = useRef(null);
|
|
258
|
-
var inputRef = React.useRef(null);
|
|
259
|
-
var calendarButton = document.getElementById(datepickerId + '-button');
|
|
260
|
-
|
|
261
|
-
var _useState = useState(false),
|
|
262
|
-
showValidation = _useState[0],
|
|
263
|
-
setShowValidation = _useState[1];
|
|
264
|
-
|
|
265
|
-
var _useState2 = useState(false),
|
|
266
|
-
shouldFocusOnCalendarButtonAfterSelect = _useState2[0],
|
|
267
|
-
setShouldFocusOnCalendarButtonAfterSelect = _useState2[1]; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
React.useEffect(function () {
|
|
271
|
-
return validateInput();
|
|
272
|
-
}, [selectedDate]);
|
|
273
|
-
|
|
274
|
-
var handleOnChange = function handleOnChange(date, event) {
|
|
275
|
-
var _inputRef$current;
|
|
276
|
-
|
|
277
|
-
if (shouldFocusOnCalendarButtonAfterSelect && !hideCalendarButton) {
|
|
278
|
-
calendarButton == null ? void 0 : calendarButton.focus();
|
|
279
|
-
setShouldFocusOnCalendarButtonAfterSelect(false);
|
|
280
|
-
} else (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.focus();
|
|
281
|
-
|
|
282
|
-
onChange(date, event);
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
286
|
-
setShowValidation(false);
|
|
287
|
-
|
|
288
|
-
if (event.key === 'Enter') {
|
|
289
|
-
if (!datePickerGUIIsOpen()) {
|
|
290
|
-
// onBlurInput will validate if calendar is open
|
|
291
|
-
validateInput();
|
|
292
|
-
forceUpdateInputFormat();
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
focusAndSelectInputField();
|
|
296
|
-
} else if (event.key === 'Tab' && datePickerGUIIsOpen()) {
|
|
297
|
-
forceUpdateInputFormat();
|
|
298
|
-
} else if (event.key === 'Escape') {
|
|
299
|
-
forceUpdateInputFormat();
|
|
300
|
-
focusAndSelectInputField();
|
|
301
|
-
if (datePickerGUIIsOpen()) toggleCalendarGUI();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
onKeyDown(event);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
var handleOnClickOutside = function handleOnClickOutside() {
|
|
308
|
-
return setShouldFocusOnCalendarButtonAfterSelect(false);
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
var handleOnBlurInput = function handleOnBlurInput() {
|
|
312
|
-
if (datePickerGUIIsOpen()) return;
|
|
313
|
-
validateInput();
|
|
314
|
-
forceUpdateInputFormat();
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
var validateInput = function validateInput() {
|
|
318
|
-
var _inputRef$current2;
|
|
319
|
-
|
|
320
|
-
setShowValidation(false);
|
|
321
|
-
var inputValue = (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.value;
|
|
322
|
-
if (!inputValue) return;
|
|
323
|
-
var inputValueParsedWithAllDateFormats = dateFormats.map(function (format) {
|
|
324
|
-
return parse(inputValue, format, new Date(), {
|
|
325
|
-
locale: locale
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
var parsedDateFromInputIsTheSameAsSelectedDate = selectedDate && inputValueParsedWithAllDateFormats.some(function (dateFormat) {
|
|
329
|
-
return isSameDay(dateFormat, selectedDate);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
if (parsedDateFromInputIsTheSameAsSelectedDate) {
|
|
333
|
-
// valid date inputted
|
|
334
|
-
setShowValidation(false);
|
|
335
|
-
} else {
|
|
336
|
-
// invalid date inputted
|
|
337
|
-
setShowValidation(true);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
var getFeedbackAndVariant = function getFeedbackAndVariant() {
|
|
342
|
-
if (feedback) return {
|
|
343
|
-
feedback: feedback,
|
|
344
|
-
variant: variant
|
|
345
|
-
};
|
|
346
|
-
if (!hideValidation && showValidation) return {
|
|
347
|
-
feedback: validationFeedback,
|
|
348
|
-
variant: validationVariant
|
|
349
|
-
};
|
|
350
|
-
return {
|
|
351
|
-
feedback: '',
|
|
352
|
-
variant: undefined
|
|
353
|
-
};
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
var focusAndSelectInputField = function focusAndSelectInputField() {
|
|
357
|
-
return requestAnimationFrame(function () {
|
|
358
|
-
var _inputRef$current3;
|
|
359
|
-
|
|
360
|
-
return (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.select();
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
var forceUpdateInputFormat = function forceUpdateInputFormat() {
|
|
365
|
-
var _datepickerRef$curren;
|
|
366
|
-
|
|
367
|
-
return (_datepickerRef$curren = datepickerRef.current) == null ? void 0 : _datepickerRef$curren.setState({
|
|
368
|
-
inputValue: null
|
|
369
|
-
});
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
var toggleCalendarGUI = function toggleCalendarGUI() {
|
|
373
|
-
var _datepickerRef$curren2;
|
|
374
|
-
|
|
375
|
-
return (_datepickerRef$curren2 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren2.setOpen(!datePickerGUIIsOpen());
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
var setFocusToCalendarGUI = function setFocusToCalendarGUI() {
|
|
379
|
-
if (inline || hideCalendar || datePickerGUIIsOpen()) return; // 1 frame delay to allow calendar to spawn
|
|
380
|
-
|
|
381
|
-
requestAnimationFrame(function () {
|
|
382
|
-
var _datepickerRef$curren3;
|
|
383
|
-
|
|
384
|
-
var datepickerGUIWrapper = // @ts-expect-error .calendar does actually exist in ReactDatePicker ref
|
|
385
|
-
(_datepickerRef$curren3 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren3.calendar.componentNode;
|
|
386
|
-
var dateToSetFocusTo = selectedDate ? datepickerGUIWrapper.querySelector('.eds-datepicker__calender__day[tabindex="0"]') : datepickerGUIWrapper.querySelector('.eds-datepicker__calender__day[aria-current="date"]');
|
|
387
|
-
|
|
388
|
-
if (dateToSetFocusTo !== null) {
|
|
389
|
-
var _datepickerRef$curren4;
|
|
390
|
-
|
|
391
|
-
(_datepickerRef$curren4 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren4.setBlur();
|
|
392
|
-
dateToSetFocusTo.focus({
|
|
393
|
-
preventScroll: true
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
setShouldFocusOnCalendarButtonAfterSelect(true);
|
|
398
|
-
setShowValidation(false);
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
var datePickerGUIIsOpen = function datePickerGUIIsOpen() {
|
|
402
|
-
var _datepickerRef$curren5;
|
|
403
|
-
|
|
404
|
-
return (_datepickerRef$curren5 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren5.isCalendarOpen();
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
return React.createElement(React.Fragment, null, React.createElement(ReactDatepicker, _extends({
|
|
408
|
-
selected: selectedDate,
|
|
409
|
-
minDate: minDate,
|
|
410
|
-
maxDate: maxDate,
|
|
411
|
-
dateFormat: dateFormats,
|
|
412
|
-
showWeekNumbers: true,
|
|
413
|
-
weekLabel: weekLabel,
|
|
414
|
-
onChange: handleOnChange,
|
|
415
|
-
onClickOutside: handleOnClickOutside,
|
|
416
|
-
id: datepickerId,
|
|
417
|
-
ariaLabelledBy: datepickerId,
|
|
418
|
-
showPopperArrow: false,
|
|
419
|
-
locale: locale,
|
|
420
|
-
inline: inline,
|
|
421
|
-
disabled: disabled,
|
|
422
|
-
preventOpenOnFocus: true,
|
|
423
|
-
chooseDayAriaLabelPrefix: chooseDayAriaLabelPrefix,
|
|
424
|
-
open: hideCalendar ? false : open,
|
|
425
|
-
ref: datepickerRef,
|
|
426
|
-
calendarClassName: "eds-datepicker__calender",
|
|
427
|
-
dayClassName: function dayClassName() {
|
|
428
|
-
return 'eds-datepicker__calender__day';
|
|
429
|
-
},
|
|
430
|
-
weekDayClassName: function weekDayClassName() {
|
|
431
|
-
return 'eds-datepicker__calender__day-name';
|
|
432
|
-
},
|
|
433
|
-
className: classNames(className, 'eds-datepicker__input'),
|
|
434
|
-
highlightDates: [{
|
|
435
|
-
'eds-datepicker__calender__day--today': [new Date()]
|
|
436
|
-
}, {
|
|
437
|
-
'eds-datepicker__calender__day--selected': selectedDate ? [selectedDate] : []
|
|
438
|
-
}],
|
|
439
|
-
renderCustomHeader: function renderCustomHeader(_ref2) {
|
|
440
|
-
var date = _ref2.date,
|
|
441
|
-
changeYear = _ref2.changeYear,
|
|
442
|
-
changeMonth = _ref2.changeMonth,
|
|
443
|
-
decreaseMonth = _ref2.decreaseMonth,
|
|
444
|
-
increaseMonth = _ref2.increaseMonth,
|
|
445
|
-
prevMonthButtonDisabled = _ref2.prevMonthButtonDisabled,
|
|
446
|
-
nextMonthButtonDisabled = _ref2.nextMonthButtonDisabled;
|
|
447
|
-
return React.createElement(DatePickerHeader, {
|
|
448
|
-
date: date,
|
|
449
|
-
changeYear: changeYear,
|
|
450
|
-
changeMonth: changeMonth,
|
|
451
|
-
increaseMonth: increaseMonth,
|
|
452
|
-
decreaseMonth: decreaseMonth,
|
|
453
|
-
prevMonthButtonDisabled: prevMonthButtonDisabled,
|
|
454
|
-
nextMonthButtonDisabled: nextMonthButtonDisabled,
|
|
455
|
-
previousMonthAriaLabel: previousMonthAriaLabel,
|
|
456
|
-
nextMonthAriaLabel: nextMonthAriaLabel,
|
|
457
|
-
locale: locale
|
|
458
|
-
});
|
|
459
|
-
},
|
|
460
|
-
customInput: React.createElement(DatePickerInput, {
|
|
461
|
-
style: style,
|
|
462
|
-
label: label,
|
|
463
|
-
inputPlaceholder: placeholder,
|
|
464
|
-
calendarButtonTooltipOpen: calendarButtonTooltipOpen,
|
|
465
|
-
calendarButtonTooltipClose: calendarButtonTooltipClose,
|
|
466
|
-
prepend: prepend,
|
|
467
|
-
feedback: getFeedbackAndVariant().feedback,
|
|
468
|
-
variant: getFeedbackAndVariant().variant,
|
|
469
|
-
inputRef: inputRef,
|
|
470
|
-
calendarButtonId: datepickerId + '-button',
|
|
471
|
-
forwardRef: ref,
|
|
472
|
-
onKeyDownInput: handleOnKeyDown,
|
|
473
|
-
onBlurInput: handleOnBlurInput,
|
|
474
|
-
onFocus: undefined,
|
|
475
|
-
toggleCalendarGUI: toggleCalendarGUI,
|
|
476
|
-
setFocusToCalendarGUI: setFocusToCalendarGUI,
|
|
477
|
-
setShouldFocusOnCalendarButtonAfterSelect: setShouldFocusOnCalendarButtonAfterSelect,
|
|
478
|
-
calendarGUIIsOpen: datePickerGUIIsOpen,
|
|
479
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
480
|
-
hideCalendarButton: hideCalendarButton,
|
|
481
|
-
selectedDate: selectedDate
|
|
482
|
-
})
|
|
483
|
-
}, rest)));
|
|
484
|
-
});
|
|
485
|
-
|
|
486
53
|
var FieldSegment = function FieldSegment(_ref) {
|
|
487
54
|
var segment = _ref.segment,
|
|
488
55
|
state = _ref.state;
|
|
@@ -607,7 +174,7 @@ var ariaLabelIfNorwegian = function ariaLabelIfNorwegian(norwegianAriaLabel, loc
|
|
|
607
174
|
return norwegianAriaLabel;
|
|
608
175
|
};
|
|
609
176
|
|
|
610
|
-
var _excluded$8 = ["selectedDate", "label", "locale", "showTimeZone", "showTime", "granularity", "disabled", "variant", "feedback", "validationVariant", "validationFeedback", "labelTooltip", "style", "className", "labelProps", "append"];
|
|
177
|
+
var _excluded$8 = ["selectedDate", "label", "locale", "showTimeZone", "showTime", "granularity", "disabled", "variant", "feedback", "validationVariant", "validationFeedback", "labelTooltip", "minDate", "maxDate", "style", "className", "labelProps", "append"];
|
|
611
178
|
var DateField = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
612
179
|
var value = _ref.selectedDate,
|
|
613
180
|
label = _ref.label,
|
|
@@ -624,6 +191,8 @@ var DateField = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
624
191
|
_ref$validationFeedba = _ref.validationFeedback,
|
|
625
192
|
validationFeedback = _ref$validationFeedba === void 0 ? 'Ugyldig dato' : _ref$validationFeedba,
|
|
626
193
|
labelTooltip = _ref.labelTooltip,
|
|
194
|
+
minValue = _ref.minDate,
|
|
195
|
+
maxValue = _ref.maxDate,
|
|
627
196
|
style = _ref.style,
|
|
628
197
|
className = _ref.className,
|
|
629
198
|
parentLabelProps = _ref.labelProps,
|
|
@@ -638,7 +207,9 @@ var DateField = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
638
207
|
createCalendar: createCalendar,
|
|
639
208
|
value: value === null ? undefined : value,
|
|
640
209
|
hideTimeZone: !showTimeZone,
|
|
641
|
-
granularity: showTime ? 'minute' : granularity
|
|
210
|
+
granularity: showTime ? 'minute' : granularity,
|
|
211
|
+
minValue: minValue,
|
|
212
|
+
maxValue: maxValue
|
|
642
213
|
}));
|
|
643
214
|
var dateFieldRef = useRef(null);
|
|
644
215
|
|
|
@@ -700,12 +271,16 @@ var CalendarButton = function CalendarButton(_ref) {
|
|
|
700
271
|
}), children);
|
|
701
272
|
};
|
|
702
273
|
|
|
703
|
-
var _excluded$6 = ["state", "date"];
|
|
274
|
+
var _excluded$6 = ["state", "date", "onSelectedCellClick"];
|
|
704
275
|
var CalendarCell = function CalendarCell(_ref) {
|
|
705
276
|
var _state$timeZone;
|
|
706
277
|
|
|
707
278
|
var state = _ref.state,
|
|
708
279
|
date = _ref.date,
|
|
280
|
+
_ref$onSelectedCellCl = _ref.onSelectedCellClick,
|
|
281
|
+
onSelectedCellClick = _ref$onSelectedCellCl === void 0 ? function () {
|
|
282
|
+
return;
|
|
283
|
+
} : _ref$onSelectedCellCl,
|
|
709
284
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$6);
|
|
710
285
|
|
|
711
286
|
var cellRef = useRef(null);
|
|
@@ -732,13 +307,26 @@ var CalendarCell = function CalendarCell(_ref) {
|
|
|
732
307
|
'eds-datepicker__calendar__grid__cell--outside-month': isOutsideVisibleRange,
|
|
733
308
|
'eds-datepicker__calendar__grid__cell--today': isEqualDay(date, now((_state$timeZone = state.timeZone) != null ? _state$timeZone : getLocalTimeZone()))
|
|
734
309
|
})
|
|
735
|
-
}, rest
|
|
310
|
+
}, rest, {
|
|
311
|
+
onClick: function onClick(e) {
|
|
312
|
+
buttonProps.onClick && buttonProps.onClick(e);
|
|
313
|
+
isSelected && onSelectedCellClick();
|
|
314
|
+
},
|
|
315
|
+
onKeyDown: function onKeyDown(e) {
|
|
316
|
+
buttonProps.onKeyDown && buttonProps.onKeyDown(e);
|
|
317
|
+
if (e.key === 'Enter' || e.key === ' ') isSelected && onSelectedCellClick();
|
|
318
|
+
}
|
|
319
|
+
}), formattedDate));
|
|
736
320
|
};
|
|
737
321
|
|
|
738
|
-
var _excluded$5 = ["state", "navigationDescription"];
|
|
322
|
+
var _excluded$5 = ["state", "navigationDescription", "onSelectedCellClick"];
|
|
739
323
|
var CalendarGrid = function CalendarGrid(_ref) {
|
|
740
324
|
var state = _ref.state,
|
|
741
325
|
navigationDescription = _ref.navigationDescription,
|
|
326
|
+
_ref$onSelectedCellCl = _ref.onSelectedCellClick,
|
|
327
|
+
onSelectedCellClick = _ref$onSelectedCellCl === void 0 ? function () {
|
|
328
|
+
return;
|
|
329
|
+
} : _ref$onSelectedCellCl,
|
|
742
330
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
743
331
|
|
|
744
332
|
var calendarGridId = useRandomId('eds-calendar');
|
|
@@ -755,8 +343,13 @@ var CalendarGrid = function CalendarGrid(_ref) {
|
|
|
755
343
|
var weeksArray = Array.from(Array(weeksInMonth).keys());
|
|
756
344
|
|
|
757
345
|
var weekDaysMapped = function weekDaysMapped() {
|
|
758
|
-
if (locale.toLowerCase()
|
|
759
|
-
|
|
346
|
+
if (locale.toLowerCase().includes('no')) return ['ma', 'ti', 'on', 'to', 'fr', 'lø', 'sø'];
|
|
347
|
+
|
|
348
|
+
if (locale.toLowerCase().includes('en')) {
|
|
349
|
+
if (weekDays[0] === 'M') return ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
|
|
350
|
+
if (weekDays[0] === 'S') return ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
|
|
351
|
+
}
|
|
352
|
+
|
|
760
353
|
return weekDays.map(function (day) {
|
|
761
354
|
return day.toLowerCase();
|
|
762
355
|
});
|
|
@@ -783,7 +376,8 @@ var CalendarGrid = function CalendarGrid(_ref) {
|
|
|
783
376
|
key: i,
|
|
784
377
|
state: state,
|
|
785
378
|
date: date,
|
|
786
|
-
"aria-describedby": calendarGridId + 'description'
|
|
379
|
+
"aria-describedby": calendarGridId + 'description',
|
|
380
|
+
onSelectedCellClick: onSelectedCellClick
|
|
787
381
|
}) : React.createElement("td", {
|
|
788
382
|
key: i
|
|
789
383
|
});
|
|
@@ -793,12 +387,16 @@ var CalendarGrid = function CalendarGrid(_ref) {
|
|
|
793
387
|
}, getNavigationDescription()));
|
|
794
388
|
};
|
|
795
389
|
|
|
796
|
-
var _excluded$4 = ["selectedDate", "onChange", "locale", "style", "children", "navigationDescription"];
|
|
390
|
+
var _excluded$4 = ["selectedDate", "onChange", "locale", "style", "children", "navigationDescription", "onSelectedCellClick"];
|
|
797
391
|
var Calendar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
798
392
|
var onChange = _ref.onChange,
|
|
799
393
|
customLocale = _ref.locale,
|
|
800
394
|
style = _ref.style,
|
|
801
395
|
navigationDescription = _ref.navigationDescription,
|
|
396
|
+
_ref$onSelectedCellCl = _ref.onSelectedCellClick,
|
|
397
|
+
onSelectedCellClick = _ref$onSelectedCellCl === void 0 ? function () {
|
|
398
|
+
return;
|
|
399
|
+
} : _ref$onSelectedCellCl,
|
|
802
400
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
803
401
|
|
|
804
402
|
var _useLocale = useLocale(),
|
|
@@ -839,14 +437,15 @@ var Calendar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
839
437
|
size: 20
|
|
840
438
|
}))), React.createElement(CalendarGrid, {
|
|
841
439
|
state: state,
|
|
842
|
-
navigationDescription: navigationDescription
|
|
440
|
+
navigationDescription: navigationDescription,
|
|
441
|
+
onSelectedCellClick: onSelectedCellClick
|
|
843
442
|
})));
|
|
844
443
|
});
|
|
845
444
|
|
|
846
|
-
var _excluded$3 = ["selectedDate", "onChange", "locale", "disabled", "showTime", "showTimeZone", "className", "style", "variant", "feedback", "validationVariant", "validationFeedback", "disableModal", "labelTooltip", "navigationDescription", "minDate", "maxDate"];
|
|
847
|
-
var
|
|
445
|
+
var _excluded$3 = ["selectedDate", "onChange", "locale", "disabled", "showTime", "showTimeZone", "className", "style", "variant", "feedback", "validationVariant", "validationFeedback", "disableModal", "labelTooltip", "navigationDescription", "minDate", "maxDate", "modalTreshold"];
|
|
446
|
+
var DatePicker = function DatePicker(_ref) {
|
|
848
447
|
var value = _ref.selectedDate,
|
|
849
|
-
|
|
448
|
+
onChange = _ref.onChange,
|
|
850
449
|
locale = _ref.locale,
|
|
851
450
|
isDisabled = _ref.disabled,
|
|
852
451
|
showTime = _ref.showTime,
|
|
@@ -863,9 +462,11 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
863
462
|
navigationDescription = _ref.navigationDescription,
|
|
864
463
|
minValue = _ref.minDate,
|
|
865
464
|
maxValue = _ref.maxDate,
|
|
465
|
+
_ref$modalTreshold = _ref.modalTreshold,
|
|
466
|
+
modalTreshold = _ref$modalTreshold === void 0 ? 1000 : _ref$modalTreshold,
|
|
866
467
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
867
468
|
|
|
868
|
-
var CALENDAR_MODAL_MAX_SCREEN_WIDTH =
|
|
469
|
+
var CALENDAR_MODAL_MAX_SCREEN_WIDTH = modalTreshold;
|
|
869
470
|
var datePickerRef = useRef(null);
|
|
870
471
|
var calendarRef = useRef(null);
|
|
871
472
|
var dateFieldRef = useRef(null);
|
|
@@ -877,7 +478,7 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
877
478
|
minValue: minValue,
|
|
878
479
|
maxValue: maxValue,
|
|
879
480
|
value: value,
|
|
880
|
-
onChange:
|
|
481
|
+
onChange: onChange
|
|
881
482
|
}));
|
|
882
483
|
|
|
883
484
|
var _useDatePicker = useDatePicker(_extends({
|
|
@@ -890,24 +491,11 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
890
491
|
fieldProps = _useDatePicker.fieldProps,
|
|
891
492
|
buttonProps = _useDatePicker.buttonProps,
|
|
892
493
|
dialogProps = _useDatePicker.dialogProps,
|
|
893
|
-
calendarProps = _useDatePicker.calendarProps;
|
|
894
|
-
|
|
895
|
-
useEffect(function () {
|
|
896
|
-
var _calendarRef$current;
|
|
897
|
-
|
|
898
|
-
var keyDownHandler = function keyDownHandler(event) {
|
|
899
|
-
if (event.key === 'Escape') state.setOpen(false);
|
|
900
|
-
};
|
|
494
|
+
calendarProps = _useDatePicker.calendarProps; // calculations for floating-UI popover position
|
|
901
495
|
|
|
902
|
-
(_calendarRef$current = calendarRef.current) == null ? void 0 : _calendarRef$current.addEventListener('keydown', keyDownHandler);
|
|
903
|
-
return function () {
|
|
904
|
-
var _calendarRef$current2;
|
|
905
|
-
|
|
906
|
-
return (_calendarRef$current2 = calendarRef.current) == null ? void 0 : _calendarRef$current2.removeEventListener('keydown', keyDownHandler);
|
|
907
|
-
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
908
|
-
}, []); // calculations for floating-UI popover position
|
|
909
496
|
|
|
910
497
|
var _useFloating = useFloating({
|
|
498
|
+
whileElementsMounted: autoUpdate,
|
|
911
499
|
placement: 'bottom-start',
|
|
912
500
|
middleware: [offset(space.extraSmall), flip(), shift({
|
|
913
501
|
padding: space.extraSmall
|
|
@@ -919,53 +507,49 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
919
507
|
floating = _useFloating.floating,
|
|
920
508
|
strategy = _useFloating.strategy;
|
|
921
509
|
|
|
510
|
+
var onChangeCalendar = function onChangeCalendar(newSelectedDate) {
|
|
511
|
+
// Necessary to avoid state update on unmounted component
|
|
512
|
+
requestAnimationFrame(function () {
|
|
513
|
+
calendarProps.onChange && calendarProps.onChange(newSelectedDate);
|
|
514
|
+
});
|
|
515
|
+
};
|
|
516
|
+
|
|
922
517
|
useOnClickOutside([calendarRef], function () {
|
|
923
518
|
state.setOpen(false);
|
|
924
519
|
});
|
|
520
|
+
useOnEscape(calendarRef, function () {
|
|
521
|
+
state.setOpen(false);
|
|
522
|
+
});
|
|
925
523
|
|
|
926
|
-
var
|
|
927
|
-
if (!calendarIsOpen) {
|
|
928
|
-
state.setOpen(true);
|
|
929
|
-
setFocusToRelevantDate();
|
|
930
|
-
} else {
|
|
931
|
-
state.setOpen(false);
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
var setFocusToRelevantDate = function setFocusToRelevantDate() {
|
|
936
|
-
var _calendarRef$current3, _calendarRef$current4;
|
|
937
|
-
|
|
938
|
-
var gridCellPrefix = 'eds-datepicker__calendar__grid__cell';
|
|
939
|
-
var selectedCell = (_calendarRef$current3 = calendarRef.current) == null ? void 0 : _calendarRef$current3.getElementsByClassName(gridCellPrefix + '--selected')[0];
|
|
940
|
-
var todayCell = (_calendarRef$current4 = calendarRef.current) == null ? void 0 : _calendarRef$current4.getElementsByClassName(gridCellPrefix + '--today')[0];
|
|
941
|
-
if (selectedCell) selectedCell.focus();else if (todayCell) todayCell.focus();
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
var popoverCalendar = React.createElement(React.Fragment, null, state.isOpen && React.createElement(FocusLock, {
|
|
945
|
-
disabled: !state.isOpen,
|
|
946
|
-
returnFocus: true
|
|
947
|
-
}, React.createElement(Calendar, _extends({}, dialogProps, calendarProps, {
|
|
948
|
-
onChange: function onChange(dateValue) {
|
|
949
|
-
_onChange(dateValue);
|
|
950
|
-
|
|
951
|
-
state.setOpen(false);
|
|
952
|
-
},
|
|
524
|
+
var calendarSharedProps = _extends({}, dialogProps, calendarProps, {
|
|
953
525
|
disabled: calendarProps.isDisabled,
|
|
954
|
-
ref: function ref(node) {
|
|
955
|
-
calendarRef.current = node;
|
|
956
|
-
floating(node);
|
|
957
|
-
},
|
|
958
526
|
navigationDescription: navigationDescription,
|
|
527
|
+
onSelectedCellClick: function onSelectedCellClick() {
|
|
528
|
+
return state.setOpen(false);
|
|
529
|
+
},
|
|
530
|
+
onChange: onChangeCalendar
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
var useModal = width <= CALENDAR_MODAL_MAX_SCREEN_WIDTH && !disableModal;
|
|
534
|
+
var popoverCalendar = React.createElement("div", {
|
|
959
535
|
// styling for floating-UI popover
|
|
960
536
|
style: {
|
|
961
537
|
position: strategy,
|
|
962
538
|
top: y != null ? y : 0,
|
|
963
539
|
left: x != null ? x : 0,
|
|
964
540
|
zIndex: zIndexes.popover
|
|
541
|
+
},
|
|
542
|
+
ref: function ref(node) {
|
|
543
|
+
floating(node);
|
|
965
544
|
}
|
|
545
|
+
}, React.createElement(FocusLock, {
|
|
546
|
+
disabled: !state.isOpen || useModal,
|
|
547
|
+
returnFocus: true
|
|
548
|
+
}, state.isOpen && React.createElement(Calendar, _extends({}, calendarSharedProps, {
|
|
549
|
+
ref: calendarRef
|
|
966
550
|
}))));
|
|
967
551
|
var modalCalendar = React.createElement(Modal, {
|
|
968
|
-
size:
|
|
552
|
+
size: "small",
|
|
969
553
|
title: "",
|
|
970
554
|
open: state.isOpen,
|
|
971
555
|
onDismiss: function onDismiss() {
|
|
@@ -973,16 +557,7 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
973
557
|
},
|
|
974
558
|
closeOnClickOutside: true,
|
|
975
559
|
className: "eds-datepicker__calendar-modal"
|
|
976
|
-
}, React.createElement(Calendar, _extends({},
|
|
977
|
-
onChange: function onChange(dateValue) {
|
|
978
|
-
_onChange(dateValue);
|
|
979
|
-
|
|
980
|
-
state.setOpen(false);
|
|
981
|
-
},
|
|
982
|
-
disabled: calendarProps.isDisabled,
|
|
983
|
-
ref: calendarRef,
|
|
984
|
-
navigationDescription: navigationDescription
|
|
985
|
-
})));
|
|
560
|
+
}, React.createElement(Calendar, _extends({}, calendarSharedProps)));
|
|
986
561
|
return React.createElement(ConditionalWrapper, {
|
|
987
562
|
condition: locale !== undefined,
|
|
988
563
|
wrapper: function wrapper(child) {
|
|
@@ -997,6 +572,7 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
997
572
|
datePickerRef.current = node;
|
|
998
573
|
reference(node);
|
|
999
574
|
},
|
|
575
|
+
id: undefined,
|
|
1000
576
|
className: "eds-datepicker__datefield__wrapper"
|
|
1001
577
|
}), React.createElement(DateField, _extends({}, fieldProps, {
|
|
1002
578
|
selectedDate: state.value,
|
|
@@ -1015,10 +591,10 @@ var DatePickerBeta = function DatePickerBeta(_ref) {
|
|
|
1015
591
|
})
|
|
1016
592
|
})), !fieldProps.isDisabled && React.createElement(CalendarButton, _extends({}, buttonProps, {
|
|
1017
593
|
onPress: function onPress() {
|
|
1018
|
-
return
|
|
594
|
+
return state.setOpen(!state.isOpen);
|
|
1019
595
|
},
|
|
1020
596
|
className: "eds-datepicker__open-calendar-button"
|
|
1021
|
-
}), React.createElement(CalendarIcon, null)),
|
|
597
|
+
}), React.createElement(CalendarIcon, null)), useModal ? modalCalendar : popoverCalendar)));
|
|
1022
598
|
};
|
|
1023
599
|
|
|
1024
600
|
var _excluded$2 = ["className", "style", "label", "onChange", "feedback", "variant", "disableLabelAnimation", "prepend"],
|
|
@@ -1305,5 +881,5 @@ var NativeTimePickerBase = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
1305
881
|
|
|
1306
882
|
warnAboutMissingStyles('datepicker', 'form', 'icons');
|
|
1307
883
|
|
|
1308
|
-
export { Calendar, DateField, DatePicker,
|
|
884
|
+
export { Calendar, DateField, DatePicker, NativeDatePicker, NativeTimePicker, TimePicker, ariaLabelIfNorwegian, createCalendar, nativeDateToTimeOrDateValue, timeOrDateValueToNativeDate };
|
|
1309
885
|
//# sourceMappingURL=datepicker.esm.js.map
|