@entur/datepicker 0.11.6 → 2.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 +37 -0
- package/dist/{DatePicker.d.ts → DatePicker/DatePicker.d.ts} +54 -10
- package/dist/DatePicker/DatePickerHeader.d.ts +3 -0
- package/dist/DatePicker/DatePickerInput.d.ts +25 -0
- package/dist/DatePicker/index.d.ts +1 -0
- package/dist/TimePicker.d.ts +1 -1
- package/dist/datepicker.cjs.development.js +335 -211
- 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 +336 -212
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/styles.css +119 -1082
- package/package.json +10 -6
package/dist/datepicker.esm.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { useRandomId, useOnMount, warnAboutMissingStyles } from '@entur/utils';
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useState, useRef } from 'react';
|
|
3
3
|
import ReactDatepicker, { registerLocale } from 'react-datepicker';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
import { useInputGroupContext, BaseFormControl, useVariant, isFilled } from '@entur/form';
|
|
6
|
-
import { CalendarIcon, DateIcon, LeftArrowIcon, RightArrowIcon, ClockIcon } from '@entur/icons';
|
|
7
4
|
import { parse, isSameDay, sub, add } from 'date-fns';
|
|
8
5
|
import { nb } from 'date-fns/locale';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { LeftArrowIcon, RightArrowIcon, CalendarIcon, DateIcon, ClockIcon } 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';
|
|
9
11
|
import { Tooltip } from '@entur/tooltip';
|
|
12
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
10
13
|
|
|
11
14
|
function _extends() {
|
|
12
15
|
_extends = Object.assign || function (target) {
|
|
@@ -41,264 +44,385 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
41
44
|
return target;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
name
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
48
|
+
if (!o) return;
|
|
49
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
50
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
51
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
52
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
53
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _arrayLikeToArray(arr, len) {
|
|
57
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
58
|
+
|
|
59
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
60
|
+
|
|
61
|
+
return arr2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
65
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
66
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
67
|
+
|
|
68
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
69
|
+
if (it) o = it;
|
|
70
|
+
var i = 0;
|
|
71
|
+
return function () {
|
|
72
|
+
if (i >= o.length) return {
|
|
73
|
+
done: true
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
done: false,
|
|
77
|
+
value: o[i++]
|
|
78
|
+
};
|
|
79
|
+
};
|
|
52
80
|
}
|
|
53
|
-
|
|
81
|
+
|
|
82
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var DatePickerHeader = function DatePickerHeader(_ref) {
|
|
86
|
+
var _date$getMonth;
|
|
87
|
+
|
|
88
|
+
var date = _ref.date,
|
|
89
|
+
decreaseMonth = _ref.decreaseMonth,
|
|
90
|
+
increaseMonth = _ref.increaseMonth,
|
|
91
|
+
prevMonthButtonDisabled = _ref.prevMonthButtonDisabled,
|
|
92
|
+
nextMonthButtonDisabled = _ref.nextMonthButtonDisabled;
|
|
93
|
+
var monthNames = getMonthList();
|
|
94
|
+
return React.createElement("div", {
|
|
95
|
+
className: "eds-datepicker__calender__header"
|
|
96
|
+
}, React.createElement(IconButton, {
|
|
97
|
+
className: "eds-datepicker__calender__header__month-button--left",
|
|
98
|
+
onClick: decreaseMonth,
|
|
99
|
+
disabled: prevMonthButtonDisabled
|
|
100
|
+
}, React.createElement(LeftArrowIcon, null)), React.createElement(Heading3, {
|
|
101
|
+
className: "eds-datepicker__calender__header__month-text"
|
|
102
|
+
}, monthNames[(_date$getMonth = date == null ? void 0 : date.getMonth()) != null ? _date$getMonth : 0]), React.createElement(Heading3, {
|
|
103
|
+
className: "eds-datepicker__calender__header__month-text"
|
|
104
|
+
}, date == null ? void 0 : date.getFullYear()), React.createElement(IconButton, {
|
|
105
|
+
className: "eds-datepicker__calender__header__month-button--right",
|
|
106
|
+
onClick: increaseMonth,
|
|
107
|
+
disabled: nextMonthButtonDisabled
|
|
108
|
+
}, React.createElement(RightArrowIcon, null)));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
function getMonthList(locale) {
|
|
112
|
+
if (locale === void 0) {
|
|
113
|
+
locale = 'nb';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var year = new Date().getFullYear();
|
|
117
|
+
var monthList = Array(12).keys();
|
|
118
|
+
var formatter = new Intl.DateTimeFormat(locale, {
|
|
119
|
+
month: 'long'
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
var getMonthName = function getMonthName(monthIndex) {
|
|
123
|
+
return formatter.format(new Date(year, monthIndex));
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return Array.from(monthList, getMonthName);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var _excluded$4 = ["style", "label", "inputPlaceholder", "prepend", "feedback", "variant", "disabled", "calendarButtonTooltip", "hideCalendarButton", "disableLabelAnimation", "inputRef", "forwardRef", "toggleCalendarGUI", "onKeyDownInput", "onBlurInput", "selectedDate", "placeholder"];
|
|
130
|
+
var DatePickerInput = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
131
|
+
var style = _ref.style,
|
|
132
|
+
label = _ref.label,
|
|
133
|
+
inputPlaceholder = _ref.inputPlaceholder,
|
|
134
|
+
prepend = _ref.prepend,
|
|
135
|
+
feedback = _ref.feedback,
|
|
136
|
+
variant = _ref.variant,
|
|
137
|
+
disabled = _ref.disabled,
|
|
138
|
+
calendarButtonTooltip = _ref.calendarButtonTooltip,
|
|
139
|
+
hideCalendarButton = _ref.hideCalendarButton,
|
|
140
|
+
disableLabelAnimation = _ref.disableLabelAnimation,
|
|
141
|
+
inputRef = _ref.inputRef,
|
|
142
|
+
forwardRef = _ref.forwardRef,
|
|
143
|
+
toggleCalendarGUI = _ref.toggleCalendarGUI,
|
|
144
|
+
onKeyDownInput = _ref.onKeyDownInput,
|
|
145
|
+
onBlurInput = _ref.onBlurInput,
|
|
146
|
+
selectedDate = _ref.selectedDate,
|
|
147
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
148
|
+
|
|
149
|
+
React.useEffect(function () {
|
|
150
|
+
var _inputRef$current, _inputRef$current2, _inputRef$current3;
|
|
151
|
+
|
|
152
|
+
(_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.addEventListener('keydown', handleOnKeyDown);
|
|
153
|
+
(_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.addEventListener('blur', handleOnBlur);
|
|
154
|
+
(_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.addEventListener('focus', handleOnFocus);
|
|
155
|
+
return function () {
|
|
156
|
+
var _inputRef$current4, _inputRef$current5, _inputRef$current6;
|
|
157
|
+
|
|
158
|
+
(_inputRef$current4 = inputRef.current) == null ? void 0 : _inputRef$current4.removeEventListener('keydown', handleOnKeyDown);
|
|
159
|
+
(_inputRef$current5 = inputRef.current) == null ? void 0 : _inputRef$current5.removeEventListener('blur', handleOnBlur);
|
|
160
|
+
(_inputRef$current6 = inputRef.current) == null ? void 0 : _inputRef$current6.removeEventListener('focus', handleOnFocus);
|
|
161
|
+
};
|
|
162
|
+
}, [inputRef, selectedDate]);
|
|
163
|
+
|
|
164
|
+
function handleOnKeyDown(event) {
|
|
165
|
+
onKeyDownInput(event);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function handleOnBlur(event) {
|
|
169
|
+
onBlurInput(event);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function handleOnFocus() {
|
|
173
|
+
setTimeout(function () {
|
|
174
|
+
var _inputRef$current7;
|
|
175
|
+
|
|
176
|
+
return (_inputRef$current7 = inputRef.current) == null ? void 0 : _inputRef$current7.select();
|
|
177
|
+
}, 5);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return React.createElement(TextField, _extends({
|
|
181
|
+
style: style,
|
|
182
|
+
label: label,
|
|
183
|
+
placeholder: inputPlaceholder,
|
|
184
|
+
prepend: prepend,
|
|
185
|
+
feedback: feedback,
|
|
186
|
+
variant: variant,
|
|
187
|
+
disableLabelAnimation: disableLabelAnimation,
|
|
188
|
+
ref: mergeRefs(ref, inputRef, forwardRef),
|
|
189
|
+
append: !hideCalendarButton && React.createElement(Tooltip, {
|
|
190
|
+
placement: "top",
|
|
191
|
+
content: calendarButtonTooltip,
|
|
192
|
+
disableHoverListener: disabled,
|
|
193
|
+
disableFocusListener: disabled
|
|
194
|
+
}, React.createElement(IconButton, {
|
|
195
|
+
type: "button",
|
|
196
|
+
onClick: toggleCalendarGUI
|
|
197
|
+
}, React.createElement(CalendarIcon, null)))
|
|
198
|
+
}, rest));
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
var mergeRefs = function mergeRefs() {
|
|
202
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
203
|
+
refs[_key] = arguments[_key];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return function (node) {
|
|
207
|
+
for (var _iterator = _createForOfIteratorHelperLoose(refs), _step; !(_step = _iterator()).done;) {
|
|
208
|
+
var ref = _step.value;
|
|
209
|
+
|
|
210
|
+
if (typeof ref === 'function') {
|
|
211
|
+
ref(node);
|
|
212
|
+
} else if (ref) ref.current = node;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
var _excluded$3 = ["style", "className", "selectedDate", "label", "placeholder", "onChange", "onKeyDown", "dateFormats", "minDate", "maxDate", "inline", "disabled", "prepend", "feedback", "variant", "validationFeedback", "validationVariant", "disableLabelAnimation", "calendarButtonTooltip", "hideCalendarButton", "hideCalendar", "hideValidation", "weekLabel", "locale", "open"];
|
|
218
|
+
registerLocale('nb', nb);
|
|
54
219
|
var DatePicker = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
220
|
+
var style = _ref.style,
|
|
221
|
+
className = _ref.className,
|
|
222
|
+
selectedDate = _ref.selectedDate,
|
|
223
|
+
label = _ref.label,
|
|
59
224
|
_ref$placeholder = _ref.placeholder,
|
|
60
225
|
placeholder = _ref$placeholder === void 0 ? 'dd.mm.yyyy' : _ref$placeholder,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
_ref$
|
|
67
|
-
|
|
68
|
-
|
|
226
|
+
onChange = _ref.onChange,
|
|
227
|
+
_ref$onKeyDown = _ref.onKeyDown,
|
|
228
|
+
onKeyDown = _ref$onKeyDown === void 0 ? function () {
|
|
229
|
+
return null;
|
|
230
|
+
} : _ref$onKeyDown,
|
|
231
|
+
_ref$dateFormats = _ref.dateFormats,
|
|
232
|
+
dateFormats = _ref$dateFormats === void 0 ? ['dd.MM.yyyy', 'ddMMyyyy', 'dd/MM/yyyy', 'ddMMyy'] : _ref$dateFormats,
|
|
233
|
+
minDate = _ref.minDate,
|
|
234
|
+
maxDate = _ref.maxDate,
|
|
235
|
+
_ref$inline = _ref.inline,
|
|
236
|
+
inline = _ref$inline === void 0 ? false : _ref$inline,
|
|
69
237
|
disabled = _ref.disabled,
|
|
238
|
+
prepend = _ref.prepend,
|
|
239
|
+
_ref$feedback = _ref.feedback,
|
|
240
|
+
feedback = _ref$feedback === void 0 ? '' : _ref$feedback,
|
|
70
241
|
variant = _ref.variant,
|
|
71
|
-
_ref$validationVarian = _ref.validationVariant,
|
|
72
|
-
validationVariant = _ref$validationVarian === void 0 ? 'error' : _ref$validationVarian,
|
|
73
|
-
feedback = _ref.feedback,
|
|
74
242
|
_ref$validationFeedba = _ref.validationFeedback,
|
|
75
243
|
validationFeedback = _ref$validationFeedba === void 0 ? 'Ugyldig dato' : _ref$validationFeedba,
|
|
76
|
-
|
|
244
|
+
_ref$validationVarian = _ref.validationVariant,
|
|
245
|
+
validationVariant = _ref$validationVarian === void 0 ? 'error' : _ref$validationVarian,
|
|
246
|
+
_ref$disableLabelAnim = _ref.disableLabelAnimation,
|
|
247
|
+
disableLabelAnimation = _ref$disableLabelAnim === void 0 ? false : _ref$disableLabelAnim,
|
|
248
|
+
_ref$calendarButtonTo = _ref.calendarButtonTooltip,
|
|
249
|
+
calendarButtonTooltip = _ref$calendarButtonTo === void 0 ? 'Åpne\xa0kalender' : _ref$calendarButtonTo,
|
|
77
250
|
_ref$hideCalendarButt = _ref.hideCalendarButton,
|
|
78
251
|
hideCalendarButton = _ref$hideCalendarButt === void 0 ? false : _ref$hideCalendarButt,
|
|
79
252
|
_ref$hideCalendar = _ref.hideCalendar,
|
|
80
253
|
hideCalendar = _ref$hideCalendar === void 0 ? false : _ref$hideCalendar,
|
|
81
|
-
_ref$
|
|
82
|
-
|
|
83
|
-
|
|
254
|
+
_ref$hideValidation = _ref.hideValidation,
|
|
255
|
+
hideValidation = _ref$hideValidation === void 0 ? false : _ref$hideValidation,
|
|
256
|
+
_ref$weekLabel = _ref.weekLabel,
|
|
257
|
+
weekLabel = _ref$weekLabel === void 0 ? 'uke' : _ref$weekLabel,
|
|
258
|
+
_ref$locale = _ref.locale,
|
|
259
|
+
locale = _ref$locale === void 0 ? nb : _ref$locale,
|
|
260
|
+
open = _ref.open,
|
|
84
261
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
85
262
|
|
|
263
|
+
var datepickerId = useRandomId('eds-datepicker');
|
|
264
|
+
|
|
86
265
|
var _useState = useState(false),
|
|
87
|
-
|
|
88
|
-
|
|
266
|
+
showValidation = _useState[0],
|
|
267
|
+
setShowValidation = _useState[1];
|
|
89
268
|
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
|
|
269
|
+
var datepickerRef = useRef(null);
|
|
270
|
+
var inputRef = React.useRef(null);
|
|
271
|
+
React.useEffect(function () {
|
|
272
|
+
return validateInput();
|
|
273
|
+
}, [selectedDate]);
|
|
93
274
|
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
setLastValidValue = _useState3[1];
|
|
275
|
+
var handleOnKeyDown = function handleOnKeyDown(event) {
|
|
276
|
+
var _datepickerRef$curren;
|
|
97
277
|
|
|
98
|
-
|
|
278
|
+
var calendarIsClosed = !((_datepickerRef$curren = datepickerRef.current) != null && _datepickerRef$curren.isCalendarOpen());
|
|
279
|
+
setShowValidation(false);
|
|
99
280
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
281
|
+
if (event.key === 'Enter') {
|
|
282
|
+
validateInput();
|
|
283
|
+
focusAndSelectInputField();
|
|
284
|
+
forceUpdateInputFormat();
|
|
285
|
+
} else if (event.key === 'Tab' && calendarIsClosed) {
|
|
286
|
+
validateInput();
|
|
287
|
+
forceUpdateInputFormat();
|
|
288
|
+
}
|
|
103
289
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
handleChange(selectedDate, undefined);
|
|
107
|
-
}, [selectedDate, setFilled, isFilled]);
|
|
290
|
+
onKeyDown(event);
|
|
291
|
+
};
|
|
108
292
|
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
293
|
+
var validateInput = function validateInput() {
|
|
294
|
+
var _inputRef$current;
|
|
295
|
+
|
|
296
|
+
setShowValidation(false);
|
|
297
|
+
var inputValue = (_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.value;
|
|
298
|
+
if (!inputValue) return;
|
|
299
|
+
var inputValueParsedWithAllDateFormats = dateFormats.map(function (format) {
|
|
300
|
+
return parse(inputValue, format, new Date(), {
|
|
301
|
+
locale: locale
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
var parsedDateFromInputIsTheSameAsSelectedDate = selectedDate && inputValueParsedWithAllDateFormats.some(function (dateFormat) {
|
|
305
|
+
return isSameDay(dateFormat, selectedDate);
|
|
118
306
|
});
|
|
119
|
-
setCurrentValue(dateString != null ? dateString : '');
|
|
120
|
-
setLastValidValue(dateString != null ? dateString : '');
|
|
121
307
|
|
|
122
|
-
if (
|
|
123
|
-
|
|
308
|
+
if (parsedDateFromInputIsTheSameAsSelectedDate) {
|
|
309
|
+
// valid date inputted
|
|
310
|
+
setShowValidation(false);
|
|
311
|
+
} else {
|
|
312
|
+
// invalid date inputted
|
|
313
|
+
setShowValidation(true);
|
|
124
314
|
}
|
|
125
315
|
};
|
|
126
316
|
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
317
|
+
var getFeedbackAndVariant = function getFeedbackAndVariant() {
|
|
318
|
+
if (feedback) return {
|
|
319
|
+
feedback: feedback,
|
|
320
|
+
variant: variant
|
|
321
|
+
};
|
|
322
|
+
if (!hideValidation && showValidation) return {
|
|
323
|
+
feedback: validationFeedback,
|
|
324
|
+
variant: validationVariant
|
|
325
|
+
};
|
|
326
|
+
return {
|
|
327
|
+
feedback: '',
|
|
328
|
+
variant: undefined
|
|
329
|
+
};
|
|
132
330
|
};
|
|
133
331
|
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
|
|
332
|
+
var focusAndSelectInputField = function focusAndSelectInputField() {
|
|
333
|
+
return setTimeout(function () {
|
|
334
|
+
var _inputRef$current2;
|
|
137
335
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
validateInput(event.currentTarget.value);
|
|
141
|
-
}
|
|
336
|
+
(_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.select();
|
|
337
|
+
}, 5);
|
|
142
338
|
};
|
|
143
339
|
|
|
144
|
-
var
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!inputValue) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
340
|
+
var forceUpdateInputFormat = function forceUpdateInputFormat() {
|
|
341
|
+
var _datepickerRef$curren2;
|
|
150
342
|
|
|
151
|
-
|
|
152
|
-
|
|
343
|
+
return (_datepickerRef$curren2 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren2.setState({
|
|
344
|
+
inputValue: null
|
|
153
345
|
});
|
|
154
|
-
var selectedDateIsTheSameAsParsedDateFromInput = selectedDate && isSameDay(parsedDate, selectedDate);
|
|
155
|
-
|
|
156
|
-
if (selectedDateIsTheSameAsParsedDateFromInput) {
|
|
157
|
-
setLastValidValue(currentValue);
|
|
158
|
-
} else {
|
|
159
|
-
setShowValidationFeedback(true);
|
|
160
|
-
setCurrentValue(lastValidValue);
|
|
161
|
-
}
|
|
162
346
|
};
|
|
163
347
|
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
if (!hideValidationFeedback && showValidationFeedback) return validationFeedback;
|
|
167
|
-
return '';
|
|
168
|
-
};
|
|
348
|
+
var toggleCalendarGUI = function toggleCalendarGUI() {
|
|
349
|
+
var _datepickerRef$curren3, _datepickerRef$curren4;
|
|
169
350
|
|
|
170
|
-
|
|
171
|
-
if (feedback && variant) return variant;
|
|
172
|
-
if (!hideValidationFeedback && showValidationFeedback) return validationVariant;
|
|
173
|
-
return undefined;
|
|
351
|
+
return (_datepickerRef$curren3 = datepickerRef.current) == null ? void 0 : _datepickerRef$curren3.setOpen(!((_datepickerRef$curren4 = datepickerRef.current) != null && _datepickerRef$curren4.isCalendarOpen()));
|
|
174
352
|
};
|
|
175
353
|
|
|
176
|
-
return React.createElement(ReactDatepicker, _extends({
|
|
177
|
-
className: classNames(className),
|
|
178
|
-
calendarClassName: "eds-datepicker__calender",
|
|
354
|
+
return React.createElement(React.Fragment, null, React.createElement(ReactDatepicker, _extends({
|
|
179
355
|
selected: selectedDate,
|
|
180
|
-
|
|
356
|
+
minDate: minDate,
|
|
357
|
+
maxDate: maxDate,
|
|
358
|
+
dateFormat: dateFormats,
|
|
181
359
|
showWeekNumbers: true,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
readOnly: readOnly,
|
|
360
|
+
weekLabel: weekLabel,
|
|
361
|
+
onChange: onChange,
|
|
362
|
+
onClickOutside: validateInput,
|
|
186
363
|
id: datepickerId,
|
|
187
364
|
ariaLabelledBy: datepickerId,
|
|
188
|
-
|
|
365
|
+
showPopperArrow: false,
|
|
189
366
|
locale: locale,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
367
|
+
inline: inline,
|
|
368
|
+
disabled: disabled,
|
|
369
|
+
preventOpenOnFocus: true,
|
|
370
|
+
open: hideCalendar ? false : open,
|
|
371
|
+
ref: datepickerRef,
|
|
372
|
+
calendarClassName: "eds-datepicker__calender",
|
|
373
|
+
dayClassName: function dayClassName() {
|
|
374
|
+
return 'eds-datepicker__calender__day';
|
|
375
|
+
},
|
|
376
|
+
weekDayClassName: function weekDayClassName() {
|
|
377
|
+
return 'eds-datepicker__calender__day-name';
|
|
378
|
+
},
|
|
379
|
+
className: classNames(className, 'eds-datepicker__input'),
|
|
380
|
+
highlightDates: [{
|
|
381
|
+
'eds-datepicker__calender__day--today': [new Date()]
|
|
382
|
+
}, {
|
|
383
|
+
'eds-datepicker__calender__day--selected': selectedDate ? [selectedDate] : []
|
|
384
|
+
}],
|
|
385
|
+
renderCustomHeader: function renderCustomHeader(_ref2) {
|
|
386
|
+
var date = _ref2.date,
|
|
387
|
+
changeYear = _ref2.changeYear,
|
|
388
|
+
changeMonth = _ref2.changeMonth,
|
|
389
|
+
decreaseMonth = _ref2.decreaseMonth,
|
|
390
|
+
increaseMonth = _ref2.increaseMonth,
|
|
391
|
+
prevMonthButtonDisabled = _ref2.prevMonthButtonDisabled,
|
|
392
|
+
nextMonthButtonDisabled = _ref2.nextMonthButtonDisabled;
|
|
393
|
+
return React.createElement(DatePickerHeader, {
|
|
394
|
+
date: date,
|
|
395
|
+
changeYear: changeYear,
|
|
396
|
+
changeMonth: changeMonth,
|
|
397
|
+
increaseMonth: increaseMonth,
|
|
398
|
+
decreaseMonth: decreaseMonth,
|
|
399
|
+
prevMonthButtonDisabled: prevMonthButtonDisabled,
|
|
400
|
+
nextMonthButtonDisabled: nextMonthButtonDisabled
|
|
401
|
+
});
|
|
195
402
|
},
|
|
196
|
-
value: currentValue,
|
|
197
|
-
open: hideCalendar === true ? false : rest.open
|
|
198
|
-
}, rest, {
|
|
199
403
|
customInput: React.createElement(DatePickerInput, {
|
|
200
404
|
style: style,
|
|
201
|
-
readOnly: readOnly,
|
|
202
|
-
variant: displayedVariant(),
|
|
203
|
-
feedback: displayedFeedback(),
|
|
204
405
|
label: label,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"data-cy": rest['data-cy'],
|
|
208
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
406
|
+
inputPlaceholder: placeholder,
|
|
407
|
+
calendarButtonTooltip: calendarButtonTooltip,
|
|
209
408
|
prepend: prepend,
|
|
409
|
+
feedback: getFeedbackAndVariant().feedback,
|
|
410
|
+
variant: getFeedbackAndVariant().variant,
|
|
411
|
+
inputRef: inputRef,
|
|
412
|
+
forwardRef: ref,
|
|
413
|
+
onKeyDownInput: handleOnKeyDown,
|
|
414
|
+
onBlurInput: function onBlurInput() {
|
|
415
|
+
var _datepickerRef$curren5;
|
|
416
|
+
|
|
417
|
+
return !((_datepickerRef$curren5 = datepickerRef.current) != null && _datepickerRef$curren5.isCalendarOpen()) && validateInput();
|
|
418
|
+
},
|
|
419
|
+
onFocus: undefined,
|
|
420
|
+
toggleCalendarGUI: toggleCalendarGUI,
|
|
421
|
+
disableLabelAnimation: disableLabelAnimation,
|
|
210
422
|
hideCalendarButton: hideCalendarButton,
|
|
211
|
-
|
|
212
|
-
onKeyDownInput: handleKeyDownInput,
|
|
213
|
-
onBlurInput: handleBlur,
|
|
214
|
-
onChangeInput: onChangeInput
|
|
423
|
+
selectedDate: selectedDate
|
|
215
424
|
})
|
|
216
|
-
}));
|
|
217
|
-
}); // Props fra customInput i react-datepicker
|
|
218
|
-
// value: inputValue,
|
|
219
|
-
// onBlur: this.handleBlur,
|
|
220
|
-
// onChange: this.handleChange,
|
|
221
|
-
// onClick: this.onInputClick,
|
|
222
|
-
// onFocus: this.handleFocus,
|
|
223
|
-
// onKeyDown: this.onInputKeyDown,
|
|
224
|
-
// id: this.props.id,
|
|
225
|
-
// name: this.props.name,
|
|
226
|
-
// autoFocus: this.props.autoFocus,
|
|
227
|
-
// placeholder: this.props.placeholderText,
|
|
228
|
-
// disabled: this.props.disabled,
|
|
229
|
-
// autoComplete: this.props.autoComplete,
|
|
230
|
-
// className: classnames(customInput.props.className, className),
|
|
231
|
-
// title: this.props.title,
|
|
232
|
-
// readOnly: this.props.readOnly,
|
|
233
|
-
// required: this.props.required,
|
|
234
|
-
// tabIndex: this.props.tabIndex,
|
|
235
|
-
// "aria-describedby": this.props.ariaDescribedBy,
|
|
236
|
-
// "aria-invalid": this.props.ariaInvalid,
|
|
237
|
-
// "aria-labelledby": this.props.ariaLabelledBy,
|
|
238
|
-
// "aria-required": this.props.ariaRequired,
|
|
239
|
-
|
|
240
|
-
var DatePickerInput = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
|
|
241
|
-
var value = _ref2.value,
|
|
242
|
-
onClick = _ref2.onClick,
|
|
243
|
-
onKeyDown = _ref2.onKeyDown,
|
|
244
|
-
variant = _ref2.variant,
|
|
245
|
-
feedback = _ref2.feedback,
|
|
246
|
-
style = _ref2.style,
|
|
247
|
-
disableLabelAnimation = _ref2.disableLabelAnimation,
|
|
248
|
-
disabled = _ref2.disabled,
|
|
249
|
-
label = _ref2.label,
|
|
250
|
-
readOnly = _ref2.readOnly,
|
|
251
|
-
id = _ref2.id,
|
|
252
|
-
prepend = _ref2.prepend,
|
|
253
|
-
className = _ref2.className,
|
|
254
|
-
hideCalendarButton = _ref2.hideCalendarButton,
|
|
255
|
-
inputId = _ref2.inputId,
|
|
256
|
-
onChangeInput = _ref2.onChangeInput,
|
|
257
|
-
onKeyDownInput = _ref2.onKeyDownInput,
|
|
258
|
-
onBlurInput = _ref2.onBlurInput,
|
|
259
|
-
rest = _objectWithoutPropertiesLoose(_ref2, _excluded2$3);
|
|
260
|
-
|
|
261
|
-
return React.createElement("span", {
|
|
262
|
-
className: className,
|
|
263
|
-
onBlur: onBlurInput
|
|
264
|
-
}, React.createElement(BaseFormControl, {
|
|
265
|
-
style: style,
|
|
266
|
-
className: "eds-datepicker__form-control",
|
|
267
|
-
readOnly: readOnly,
|
|
268
|
-
label: label,
|
|
269
|
-
labelId: id,
|
|
270
|
-
feedback: feedback,
|
|
271
|
-
variant: variant,
|
|
272
|
-
disabled: disabled,
|
|
273
|
-
disableLabelAnimation: disableLabelAnimation,
|
|
274
|
-
isFilled: !!value,
|
|
275
|
-
prepend: prepend
|
|
276
|
-
}, React.createElement("input", _extends({
|
|
277
|
-
value: value,
|
|
278
|
-
onClick: onClick,
|
|
279
|
-
readOnly: readOnly,
|
|
280
|
-
disabled: disabled,
|
|
281
|
-
ref: ref,
|
|
282
|
-
// aria-labelledby={id}
|
|
283
|
-
className: "eds-form-control",
|
|
284
|
-
id: inputId,
|
|
285
|
-
onKeyDown: onKeyDownInput,
|
|
286
|
-
onChange: onChangeInput
|
|
287
|
-
}, rest)), !hideCalendarButton && React.createElement(Tooltip, {
|
|
288
|
-
placement: "top",
|
|
289
|
-
content: "\xC5pne kalender",
|
|
290
|
-
disableHoverListener: disabled,
|
|
291
|
-
disableFocusListener: disabled
|
|
292
|
-
}, React.createElement("button", {
|
|
293
|
-
className: classNames('eds-datepicker__calendar-button', {
|
|
294
|
-
'eds-datepicker__calendar-button--open': true,
|
|
295
|
-
'eds-datepicker__calendar-button--disabled': disabled
|
|
296
|
-
}),
|
|
297
|
-
onKeyDown: onKeyDown,
|
|
298
|
-
onClick: onClick,
|
|
299
|
-
disabled: disabled,
|
|
300
|
-
type: "button"
|
|
301
|
-
}, React.createElement(CalendarIcon, null)))));
|
|
425
|
+
}, rest)));
|
|
302
426
|
});
|
|
303
427
|
|
|
304
428
|
var _excluded$2 = ["className", "style", "label", "onChange", "feedback", "variant", "disableLabelAnimation", "prepend"],
|