@entur/datepicker 4.0.0-RC.0 → 4.0.0-RC.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 +4 -0
- package/dist/DatePicker/{beta/Calendar.d.ts → Calendar.d.ts} +0 -0
- package/dist/DatePicker/{beta/CalendarCell.d.ts → CalendarCell.d.ts} +0 -0
- package/dist/DatePicker/{beta/CalendarGrid.d.ts → CalendarGrid.d.ts} +0 -0
- package/dist/DatePicker/{beta/DateField.d.ts → DateField.d.ts} +0 -0
- package/dist/DatePicker/DatePicker.d.ts +49 -175
- package/dist/DatePicker/index.d.ts +2 -1
- package/dist/datepicker.cjs.development.js +9 -444
- 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 +8 -441
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/styles.css +38 -159
- package/package.json +7 -7
- package/dist/DatePicker/DatePickerHeader.d.ts +0 -9
- package/dist/DatePicker/DatePickerInput.d.ts +0 -31
- package/dist/DatePicker/beta/DatePicker.d.ts +0 -66
- package/dist/DatePicker/beta/index.d.ts +0 -3
package/dist/datepicker.esm.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
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
15
|
import { useFloating, autoUpdate, offset, flip, shift } from '@floating-ui/react-dom';
|
|
22
16
|
import FocusLock from 'react-focus-lock';
|
|
@@ -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;
|
|
@@ -863,7 +430,7 @@ var Calendar = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
|
863
430
|
});
|
|
864
431
|
|
|
865
432
|
var _excluded$3 = ["selectedDate", "onChange", "locale", "disabled", "showTime", "showTimeZone", "className", "style", "variant", "feedback", "validationVariant", "validationFeedback", "disableModal", "labelTooltip", "navigationDescription", "minDate", "maxDate", "modalTreshold"];
|
|
866
|
-
var
|
|
433
|
+
var DatePicker = function DatePicker(_ref) {
|
|
867
434
|
var value = _ref.selectedDate,
|
|
868
435
|
onChange = _ref.onChange,
|
|
869
436
|
locale = _ref.locale,
|
|
@@ -1302,5 +869,5 @@ var NativeTimePickerBase = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
|
1302
869
|
|
|
1303
870
|
warnAboutMissingStyles('datepicker', 'form', 'icons');
|
|
1304
871
|
|
|
1305
|
-
export { Calendar, DateField, DatePicker,
|
|
872
|
+
export { Calendar, DateField, DatePicker, NativeDatePicker, NativeTimePicker, TimePicker, ariaLabelIfNorwegian, createCalendar, nativeDateToTimeOrDateValue, timeOrDateValueToNativeDate };
|
|
1306
873
|
//# sourceMappingURL=datepicker.esm.js.map
|