@sb1/ffe-datepicker-react 100.12.4 → 101.0.0
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/es/button/Button.js +4 -5
- package/es/calendar/Calendar.js +88 -111
- package/es/calendar/ClickableDate.js +20 -41
- package/es/calendar/Header.js +13 -14
- package/es/calendar/NonClickableDate.js +1 -2
- package/es/datelogic/simplecalendar.js +97 -124
- package/es/datelogic/simpledate.js +66 -96
- package/es/datepicker/Datepicker.js +2 -25
- package/es/datepicker/DatepickerComp.js +61 -64
- package/es/datepicker/DatepickerContext.js +33 -36
- package/es/datepicker/SpinButton.js +8 -32
- package/es/datepicker/padZero.js +2 -2
- package/es/datepicker/testHelper.js +72 -143
- package/es/datepicker/toNumber.js +4 -6
- package/es/i18n/i18n.js +3 -3
- package/es/input/DateInput.js +3 -26
- package/es/types.js +1 -1
- package/es/util/dateRangeUtils.js +12 -12
- package/es/util/dateUtil.js +2 -2
- package/es/util/isIOSSafari.js +4 -4
- package/lib/button/Button.js +8 -9
- package/lib/calendar/Calendar.js +94 -116
- package/lib/calendar/ClickableDate.js +22 -42
- package/lib/calendar/Header.js +17 -18
- package/lib/calendar/NonClickableDate.js +2 -3
- package/lib/datelogic/simplecalendar.js +99 -125
- package/lib/datelogic/simpledate.js +67 -96
- package/lib/datepicker/Datepicker.js +5 -28
- package/lib/datepicker/DatepickerComp.js +74 -77
- package/lib/datepicker/DatepickerContext.js +36 -39
- package/lib/datepicker/SpinButton.js +10 -34
- package/lib/datepicker/padZero.js +2 -2
- package/lib/datepicker/testHelper.js +73 -177
- package/lib/datepicker/toNumber.js +4 -6
- package/lib/i18n/i18n.js +3 -3
- package/lib/input/DateInput.js +7 -30
- package/lib/types.js +1 -1
- package/lib/util/dateRangeUtils.js +14 -14
- package/lib/util/dateUtil.js +3 -3
- package/lib/util/isIOSSafari.js +4 -4
- package/package.json +13 -14
|
@@ -11,53 +11,52 @@ import { getSimpleDateFromString } from '../datelogic/simpledate';
|
|
|
11
11
|
import { ErrorFieldMessage } from '@sb1/ffe-form-react';
|
|
12
12
|
import i18n from '../i18n/i18n';
|
|
13
13
|
import { isMonth } from '../types';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var formatDate = useCallback(function () {
|
|
14
|
+
export const DatepickerComp = ({ ariaInvalid: ariaInvalidState, 'aria-invalid': ariaInvalidProp, ariaDescribedby: ariaDescribedbyState, 'aria-describedby': ariaDescribedbyProp, onBlur, calendarAbove, id, maxDate: maxDateProp, minDate: minDateProp, onChange, fullWidth, fieldMessage, labelId, dropdownCaption, disabledDates, }) => {
|
|
15
|
+
const { day, setDay, year, setYear, month, setMonth, locale, calendarActiveDate, setCalendarActiveDate, setLastChangedValue, } = useContext(DatepickerContext);
|
|
16
|
+
const formatDate = useCallback(() => {
|
|
18
17
|
return getPaddedDateString(day, month, year);
|
|
19
18
|
}, [day, month, year]);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return fieldMessage ?
|
|
19
|
+
const [displayDatePicker, setDisplayDatePicker] = useState(false);
|
|
20
|
+
const [minDate, setMinDate] = useState(minDateProp);
|
|
21
|
+
const [maxDate, setMaxDate] = useState(maxDateProp);
|
|
22
|
+
const [lastValidDate, setLastValidDate] = useState(formatDate());
|
|
23
|
+
const datepickerId = useId();
|
|
24
|
+
const buttonRef = useRef(null);
|
|
25
|
+
const dayRef = useRef(null);
|
|
26
|
+
const monthRef = useRef(null);
|
|
27
|
+
const yearRef = useRef(null);
|
|
28
|
+
const getFieldMessageId = () => {
|
|
29
|
+
return fieldMessage ? `${datepickerId}-fieldmessage` : undefined;
|
|
31
30
|
};
|
|
32
|
-
|
|
31
|
+
const _onChange = useCallback((date) => {
|
|
33
32
|
setLastChangedValue(date);
|
|
34
33
|
onChange(date);
|
|
35
34
|
}, [onChange, setLastChangedValue]);
|
|
36
|
-
|
|
35
|
+
const fieldMessageId = getFieldMessageId();
|
|
37
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
38
|
-
|
|
37
|
+
const debounceCalendar = useCallback(debounce((newValue) => {
|
|
39
38
|
if (newValue !== lastValidDate && validateDate(newValue)) {
|
|
40
39
|
setCalendarActiveDate(newValue);
|
|
41
40
|
setLastValidDate(newValue);
|
|
42
41
|
}
|
|
43
42
|
}, 250), [lastValidDate]);
|
|
44
|
-
|
|
45
|
-
useEffect(
|
|
46
|
-
return
|
|
43
|
+
const hasMessage = !!fieldMessage;
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
return () => {
|
|
47
46
|
debounceCalendar.cancel();
|
|
48
47
|
};
|
|
49
48
|
}, [debounceCalendar]);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
getSimpleDateFromString(dateString,
|
|
53
|
-
|
|
49
|
+
const validateDateIntervals = useCallback(() => {
|
|
50
|
+
const dateString = formatDate();
|
|
51
|
+
getSimpleDateFromString(dateString, date => {
|
|
52
|
+
const maxDateValidated = maxDateProp
|
|
54
53
|
? getSimpleDateFromString(maxDateProp)
|
|
55
54
|
: null;
|
|
56
55
|
if ((maxDateValidated === null || maxDateValidated === void 0 ? void 0 : maxDateValidated.isBefore(date)) &&
|
|
57
56
|
isDateInputWithTwoDigitYear(dateString)) {
|
|
58
57
|
date.adjust({ period: 'Y', offset: -100 });
|
|
59
58
|
}
|
|
60
|
-
|
|
59
|
+
const formattedDate = date.format();
|
|
61
60
|
if (formattedDate !== dateString) {
|
|
62
61
|
setDay([date.date]);
|
|
63
62
|
setMonth([date.month + 1]);
|
|
@@ -66,7 +65,7 @@ export var DatepickerComp = function (_a) {
|
|
|
66
65
|
setLastValidDate(formattedDate);
|
|
67
66
|
});
|
|
68
67
|
}, [formatDate, maxDateProp, setDay, setMonth, setYear]);
|
|
69
|
-
useEffect(
|
|
68
|
+
useEffect(() => {
|
|
70
69
|
if (minDateProp !== minDate || maxDateProp !== maxDate) {
|
|
71
70
|
setMinDate(minDateProp);
|
|
72
71
|
setMaxDate(maxDateProp);
|
|
@@ -82,43 +81,43 @@ export var DatepickerComp = function (_a) {
|
|
|
82
81
|
maxDate,
|
|
83
82
|
validateDateIntervals,
|
|
84
83
|
]);
|
|
85
|
-
|
|
84
|
+
const closeCalendarSetInputFocus = () => {
|
|
86
85
|
var _a;
|
|
87
86
|
setDisplayDatePicker(false);
|
|
88
87
|
(_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
89
88
|
validateDateIntervals();
|
|
90
89
|
};
|
|
91
|
-
|
|
90
|
+
const escKeyHandler = (evt) => {
|
|
92
91
|
if (evt.key === 'Escape') {
|
|
93
92
|
closeCalendarSetInputFocus();
|
|
94
93
|
}
|
|
95
94
|
};
|
|
96
|
-
|
|
95
|
+
const globalClickHandler = (evt) => {
|
|
97
96
|
if (displayDatePicker && evt.__datepickerID !== datepickerId) {
|
|
98
97
|
closeCalendarSetInputFocus();
|
|
99
98
|
}
|
|
100
99
|
};
|
|
101
|
-
|
|
100
|
+
const addGlobalEventListeners = () => {
|
|
102
101
|
window.addEventListener('click', globalClickHandler);
|
|
103
102
|
window.addEventListener('keyup', escKeyHandler);
|
|
104
103
|
};
|
|
105
|
-
|
|
104
|
+
const removeGlobalEventListeners = () => {
|
|
106
105
|
window.removeEventListener('click', globalClickHandler);
|
|
107
106
|
window.removeEventListener('keyup', escKeyHandler);
|
|
108
107
|
};
|
|
109
|
-
useEffect(
|
|
108
|
+
useEffect(() => {
|
|
110
109
|
if (displayDatePicker) {
|
|
111
110
|
addGlobalEventListeners();
|
|
112
111
|
}
|
|
113
112
|
else {
|
|
114
113
|
removeGlobalEventListeners();
|
|
115
114
|
}
|
|
116
|
-
return
|
|
115
|
+
return () => {
|
|
117
116
|
removeGlobalEventListeners();
|
|
118
117
|
};
|
|
119
118
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
120
119
|
}, [displayDatePicker]);
|
|
121
|
-
|
|
120
|
+
const calendarButtonClickHandler = () => {
|
|
122
121
|
validateDateIntervals();
|
|
123
122
|
setDisplayDatePicker(!displayDatePicker);
|
|
124
123
|
};
|
|
@@ -126,11 +125,11 @@ export var DatepickerComp = function (_a) {
|
|
|
126
125
|
* Adds a flag on the click event so that the globalClickHandler()
|
|
127
126
|
* can determine whether the ID matches. Makes it so that only one datepicker can be open at the same time
|
|
128
127
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
const addFlagOnClickEventClickHandler = (evt) => {
|
|
129
|
+
const nativeEvent = evt.nativeEvent;
|
|
131
130
|
nativeEvent.__datepickerID = datepickerId;
|
|
132
131
|
};
|
|
133
|
-
|
|
132
|
+
const focusSpinButton = (evt) => {
|
|
134
133
|
var _a;
|
|
135
134
|
if (evt.target !== yearRef.current &&
|
|
136
135
|
evt.target !== buttonRef.current &&
|
|
@@ -139,9 +138,9 @@ export var DatepickerComp = function (_a) {
|
|
|
139
138
|
(_a = dayRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
140
139
|
}
|
|
141
140
|
};
|
|
142
|
-
|
|
141
|
+
const datePickedHandler = (date) => {
|
|
143
142
|
var _a;
|
|
144
|
-
|
|
143
|
+
const simpleDate = getSimpleDateFromString(date);
|
|
145
144
|
if (simpleDate) {
|
|
146
145
|
setDay([simpleDate.date]);
|
|
147
146
|
setMonth([simpleDate.month + 1]);
|
|
@@ -151,34 +150,34 @@ export var DatepickerComp = function (_a) {
|
|
|
151
150
|
(_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
152
151
|
}
|
|
153
152
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
const ariaInvalid = () => {
|
|
154
|
+
const ariaInvalidTotal = ariaInvalidProp === 'true' || ariaInvalidState;
|
|
155
|
+
const isAriaInvalid = ariaInvalidTotal === 'true' || ariaInvalidTotal === true
|
|
157
156
|
? 'true'
|
|
158
157
|
: undefined;
|
|
159
158
|
return isAriaInvalid;
|
|
160
159
|
};
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
const ariaDescribedby = () => {
|
|
161
|
+
const ariaDescribedbyTotal = ariaDescribedbyProp !== null && ariaDescribedbyProp !== void 0 ? ariaDescribedbyProp : ariaDescribedbyState;
|
|
163
162
|
return ariaDescribedbyTotal;
|
|
164
163
|
};
|
|
165
|
-
|
|
164
|
+
const handlePaste = (evt) => {
|
|
166
165
|
evt.preventDefault();
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
const paste = (evt.clipboardData || window.Clipboard).getData('text');
|
|
167
|
+
const date = getSimpleDateFromString(paste);
|
|
169
168
|
if (date) {
|
|
170
169
|
setDay([date.date]);
|
|
171
170
|
setMonth([date.month + 1]);
|
|
172
171
|
setYear([date.year]);
|
|
173
172
|
}
|
|
174
173
|
};
|
|
175
|
-
|
|
176
|
-
useEffect(
|
|
174
|
+
const [init, setInit] = useState(true);
|
|
175
|
+
useEffect(() => {
|
|
177
176
|
if (init) {
|
|
178
177
|
setInit(false);
|
|
179
178
|
return;
|
|
180
179
|
}
|
|
181
|
-
|
|
180
|
+
const [day, month, year] = lastValidDate.split('.').map(Number);
|
|
182
181
|
if (day * month * year > 0) {
|
|
183
182
|
_onChange(lastValidDate);
|
|
184
183
|
return;
|
|
@@ -191,12 +190,12 @@ export var DatepickerComp = function (_a) {
|
|
|
191
190
|
'ffe-datepicker--full-width': fullWidth,
|
|
192
191
|
'ffe-input-group--message': hasMessage,
|
|
193
192
|
'ffe-datepicker--invalid': ariaInvalid(),
|
|
194
|
-
}), "data-testid": "date-picker", onClick:
|
|
193
|
+
}), "data-testid": "date-picker", onClick: e => {
|
|
195
194
|
addFlagOnClickEventClickHandler(e);
|
|
196
195
|
focusSpinButton(e);
|
|
197
196
|
}, role: 'group', id: id },
|
|
198
|
-
React.createElement("div", { className: classNames('ffe-dateinput'), onBlur:
|
|
199
|
-
|
|
197
|
+
React.createElement("div", { className: classNames('ffe-dateinput'), onBlur: evt => {
|
|
198
|
+
const elementReceivingFocus = evt.relatedTarget;
|
|
200
199
|
if (elementReceivingFocus !== yearRef.current &&
|
|
201
200
|
elementReceivingFocus !== dayRef.current &&
|
|
202
201
|
elementReceivingFocus !== monthRef.current) {
|
|
@@ -204,22 +203,20 @@ export var DatepickerComp = function (_a) {
|
|
|
204
203
|
validateDateIntervals();
|
|
205
204
|
}
|
|
206
205
|
} },
|
|
207
|
-
React.createElement(SpinButton, { ref: dayRef, value: day !== null && day !== void 0 ? day : undefined, min: 1, max: 31, onPaste: handlePaste, onSpinButtonChange:
|
|
208
|
-
if (allowFocusNext === void 0) { allowFocusNext = true; }
|
|
206
|
+
React.createElement(SpinButton, { ref: dayRef, value: day !== null && day !== void 0 ? day : undefined, min: 1, max: 31, onPaste: handlePaste, onSpinButtonChange: (newValue, allowFocusNext = true) => {
|
|
209
207
|
return allowFocusNext
|
|
210
|
-
? setDay(newValue,
|
|
208
|
+
? setDay(newValue, () => {
|
|
211
209
|
var _a;
|
|
212
210
|
return (_a = monthRef.current) === null || _a === void 0 ? void 0 : _a.focus({
|
|
213
211
|
preventScroll: true,
|
|
214
212
|
});
|
|
215
213
|
})
|
|
216
214
|
: setDay(newValue);
|
|
217
|
-
}, nextSpinButton: monthRef, maxLength: 2, "aria-invalid": ariaInvalid(), "aria-valuenow": typeof day === 'number' ? day : undefined, "aria-valuetext":
|
|
215
|
+
}, nextSpinButton: monthRef, maxLength: 2, "aria-invalid": ariaInvalid(), "aria-valuenow": typeof day === 'number' ? day : undefined, "aria-valuetext": `${day}`, "aria-label": i18n[locale].DAY, "aria-describedby": ariaDescribedby(), "aria-labelledby": labelId }, day ? padZero(day) : 'dd'),
|
|
218
216
|
".",
|
|
219
|
-
React.createElement(SpinButton, { ref: monthRef, value: month !== null && month !== void 0 ? month : undefined, min: 1, max: 12, onPaste: handlePaste, onSpinButtonChange:
|
|
220
|
-
if (allowFocusNext === void 0) { allowFocusNext = true; }
|
|
217
|
+
React.createElement(SpinButton, { ref: monthRef, value: month !== null && month !== void 0 ? month : undefined, min: 1, max: 12, onPaste: handlePaste, onSpinButtonChange: (newValue, allowFocusNext = true) => {
|
|
221
218
|
return allowFocusNext
|
|
222
|
-
? setMonth(newValue,
|
|
219
|
+
? setMonth(newValue, () => {
|
|
223
220
|
var _a;
|
|
224
221
|
return (_a = yearRef.current) === null || _a === void 0 ? void 0 : _a.focus({
|
|
225
222
|
preventScroll: true,
|
|
@@ -227,12 +224,12 @@ export var DatepickerComp = function (_a) {
|
|
|
227
224
|
})
|
|
228
225
|
: setMonth(newValue);
|
|
229
226
|
}, nextSpinButton: yearRef, prevSpinButton: dayRef, maxLength: 2, "aria-invalid": ariaInvalid(), "aria-valuenow": typeof month === 'number' ? month : undefined, "aria-valuetext": isMonth(month)
|
|
230
|
-
?
|
|
227
|
+
? `${month} - ${i18n[locale][`MONTH_${month}`]}`
|
|
231
228
|
: undefined, "aria-label": i18n[locale].MONTH, "aria-describedby": ariaDescribedby(), "aria-labelledby": labelId }, month ? padZero(month) : 'mm'),
|
|
232
229
|
".",
|
|
233
|
-
React.createElement(SpinButton, { ref: yearRef, className: 'ffe-dateinput__field-year', value: year !== null && year !== void 0 ? year : undefined, min: 1, max: 9999, onPaste: handlePaste, onSpinButtonChange:
|
|
230
|
+
React.createElement(SpinButton, { ref: yearRef, className: 'ffe-dateinput__field-year', value: year !== null && year !== void 0 ? year : undefined, min: 1, max: 9999, onPaste: handlePaste, onSpinButtonChange: newValue => {
|
|
234
231
|
setYear(newValue);
|
|
235
|
-
}, prevSpinButton: monthRef, maxLength: 4, "aria-invalid": ariaInvalid(), "aria-valuetext":
|
|
232
|
+
}, prevSpinButton: monthRef, maxLength: 4, "aria-invalid": ariaInvalid(), "aria-valuetext": `${year}`, "aria-valuenow": typeof year === 'number' ? year : undefined, "aria-label": i18n[locale].YEAR, "aria-describedby": ariaDescribedby(), "aria-labelledby": labelId }, year ? year : 'yyyy')),
|
|
236
233
|
React.createElement(Button, { onClick: calendarButtonClickHandler, locale: locale, value: calendarActiveDate || '', ref: buttonRef }),
|
|
237
234
|
displayDatePicker && (React.createElement(Calendar, { calendarClassName: classNames('ffe-calendar ffe-calendar--datepicker', { 'ffe-calendar--datepicker--above': calendarAbove }), locale: locale, onDatePicked: datePickedHandler, selectedDate: calendarActiveDate, focusOnMount: true, dropdownCaption: dropdownCaption, minDate: minDate, maxDate: maxDate, disabledDates: disabledDates })),
|
|
238
235
|
!!fieldMessage && (React.createElement(ErrorFieldMessage, { as: "p", id: fieldMessageId }, fieldMessage))));
|
|
@@ -2,30 +2,29 @@ import React, { createContext, useEffect, useState } from 'react';
|
|
|
2
2
|
import { getSimpleDateFromString } from '../datelogic/simpledate';
|
|
3
3
|
import { validateDate } from '../util/dateUtil';
|
|
4
4
|
import { toNumber } from './toNumber';
|
|
5
|
-
export
|
|
5
|
+
export const DatepickerContext = createContext({
|
|
6
6
|
day: null,
|
|
7
7
|
month: null,
|
|
8
8
|
year: null,
|
|
9
|
-
setDay:
|
|
10
|
-
setMonth:
|
|
11
|
-
setYear:
|
|
9
|
+
setDay: () => null,
|
|
10
|
+
setMonth: () => null,
|
|
11
|
+
setYear: () => null,
|
|
12
12
|
locale: 'nb',
|
|
13
13
|
calendarActiveDate: '',
|
|
14
|
-
setCalendarActiveDate:
|
|
15
|
-
setLastChangedValue:
|
|
14
|
+
setCalendarActiveDate: () => null,
|
|
15
|
+
setLastChangedValue: () => null,
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
useEffect(function () {
|
|
17
|
+
const MONTHS_PER_YEAR = 12;
|
|
18
|
+
const MAX_DAYS = 31;
|
|
19
|
+
export const DatepickerProvider = ({ children, value = '', locale, }) => {
|
|
20
|
+
var _a;
|
|
21
|
+
const newDate = validateDate(value) ? getSimpleDateFromString(value) : '';
|
|
22
|
+
const [day, setDay] = useState(newDate ? newDate.date : null);
|
|
23
|
+
const [month, setMonth] = useState(newDate ? newDate.month + 1 : null);
|
|
24
|
+
const [year, setYear] = useState(newDate ? newDate.year : null);
|
|
25
|
+
const [calendarActiveDate, setCalendarActiveDate] = useState((_a = newDate === null || newDate === void 0 ? void 0 : newDate.toString()) !== null && _a !== void 0 ? _a : '');
|
|
26
|
+
const [lastChangedValue, setLastChangedValue] = useState(value !== null && value !== void 0 ? value : '');
|
|
27
|
+
useEffect(() => {
|
|
29
28
|
var _a;
|
|
30
29
|
if (value !== lastChangedValue) {
|
|
31
30
|
setDay(newDate ? newDate.date : null);
|
|
@@ -36,14 +35,13 @@ export var DatepickerProvider = function (_a) {
|
|
|
36
35
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
36
|
}, [value]);
|
|
38
37
|
return (React.createElement(DatepickerContext.Provider, { value: {
|
|
39
|
-
day
|
|
40
|
-
month
|
|
41
|
-
year
|
|
42
|
-
setDay:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var total = toNumber(numbers);
|
|
38
|
+
day,
|
|
39
|
+
month,
|
|
40
|
+
year,
|
|
41
|
+
setDay: (newValue, focusNext = undefined) => {
|
|
42
|
+
const numbers = newValue.slice(-2);
|
|
43
|
+
const [first, second] = numbers;
|
|
44
|
+
const total = toNumber(numbers);
|
|
47
45
|
if (total > MAX_DAYS) {
|
|
48
46
|
focusNext === null || focusNext === void 0 ? void 0 : focusNext();
|
|
49
47
|
}
|
|
@@ -58,11 +56,10 @@ export var DatepickerProvider = function (_a) {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
},
|
|
61
|
-
setMonth:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
var total = toNumber(numbers);
|
|
59
|
+
setMonth: (newValue, focusNext = undefined) => {
|
|
60
|
+
const numbers = newValue.slice(-2);
|
|
61
|
+
const [first, second] = numbers;
|
|
62
|
+
const total = toNumber(numbers);
|
|
66
63
|
if (total > MONTHS_PER_YEAR) {
|
|
67
64
|
focusNext === null || focusNext === void 0 ? void 0 : focusNext();
|
|
68
65
|
}
|
|
@@ -77,15 +74,15 @@ export var DatepickerProvider = function (_a) {
|
|
|
77
74
|
}
|
|
78
75
|
}
|
|
79
76
|
},
|
|
80
|
-
setYear:
|
|
77
|
+
setYear: newValue => {
|
|
81
78
|
setYear(toNumber(newValue.slice(-4)));
|
|
82
79
|
},
|
|
83
|
-
calendarActiveDate
|
|
84
|
-
setCalendarActiveDate:
|
|
80
|
+
calendarActiveDate,
|
|
81
|
+
setCalendarActiveDate: date => {
|
|
85
82
|
setCalendarActiveDate(date);
|
|
86
83
|
},
|
|
87
|
-
locale
|
|
88
|
-
setLastChangedValue:
|
|
84
|
+
locale,
|
|
85
|
+
setLastChangedValue: val => {
|
|
89
86
|
setLastChangedValue(val);
|
|
90
87
|
},
|
|
91
88
|
} }, children));
|
|
@@ -1,33 +1,9 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
1
|
import React, { useRef } from 'react';
|
|
24
2
|
import classNames from 'classnames';
|
|
25
|
-
export
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var handleKeyDown = function (evt) {
|
|
3
|
+
export const SpinButton = React.forwardRef(({ className, onSpinButtonChange, maxLength, min, max, value, nextSpinButton, prevSpinButton, children, ...rest }, ref) => {
|
|
4
|
+
const history = useRef([]);
|
|
5
|
+
const handleKeyDown = (evt) => {
|
|
29
6
|
var _a, _b, _c;
|
|
30
|
-
evt.stopPropagation();
|
|
31
7
|
if (/\d/.test(evt.key)) {
|
|
32
8
|
history.current =
|
|
33
9
|
history.current.length === maxLength
|
|
@@ -41,7 +17,7 @@ export var SpinButton = React.forwardRef(function (_a, ref) {
|
|
|
41
17
|
(_a = prevSpinButton === null || prevSpinButton === void 0 ? void 0 : prevSpinButton.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
42
18
|
return;
|
|
43
19
|
}
|
|
44
|
-
|
|
20
|
+
const newValue = value === null || value === void 0 ? void 0 : value.toString().slice(0, -1);
|
|
45
21
|
history.current = newValue
|
|
46
22
|
? newValue.split('').map(Number)
|
|
47
23
|
: [];
|
|
@@ -49,7 +25,7 @@ export var SpinButton = React.forwardRef(function (_a, ref) {
|
|
|
49
25
|
}
|
|
50
26
|
else if (evt.key === 'ArrowUp') {
|
|
51
27
|
evt.preventDefault();
|
|
52
|
-
|
|
28
|
+
let newValue = (value !== null && value !== void 0 ? value : 0) + 1;
|
|
53
29
|
if (newValue && newValue !== null && newValue > max) {
|
|
54
30
|
newValue = min;
|
|
55
31
|
}
|
|
@@ -57,7 +33,7 @@ export var SpinButton = React.forwardRef(function (_a, ref) {
|
|
|
57
33
|
}
|
|
58
34
|
else if (evt.key === 'ArrowDown') {
|
|
59
35
|
evt.preventDefault();
|
|
60
|
-
|
|
36
|
+
let newValue = (value !== null && value !== void 0 ? value : 0) - 1;
|
|
61
37
|
if (newValue < min) {
|
|
62
38
|
newValue = max;
|
|
63
39
|
}
|
|
@@ -72,7 +48,7 @@ export var SpinButton = React.forwardRef(function (_a, ref) {
|
|
|
72
48
|
(_c = nextSpinButton === null || nextSpinButton === void 0 ? void 0 : nextSpinButton.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
73
49
|
}
|
|
74
50
|
};
|
|
75
|
-
return (React.createElement("span",
|
|
51
|
+
return (React.createElement("span", { role: 'spinbutton', inputMode: 'numeric', className: classNames(className, 'ffe-dateinput__field'), tabIndex: 0, onFocus: () => {
|
|
76
52
|
history.current = [];
|
|
77
|
-
}, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": value, ref: ref, onKeyDown: handleKeyDown
|
|
53
|
+
}, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": value, ref: ref, onKeyDown: handleKeyDown, ...rest }, children));
|
|
78
54
|
});
|
package/es/datepicker/padZero.js
CHANGED