@sb1/ffe-datepicker-react 100.12.3 → 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
package/es/button/Button.js
CHANGED
|
@@ -2,12 +2,11 @@ import React from 'react';
|
|
|
2
2
|
import { Icon } from '@sb1/ffe-icons-react';
|
|
3
3
|
import { validateDate } from '../util/dateUtil';
|
|
4
4
|
import i18n from '../i18n/i18n';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
? "".concat(i18n[locale].CHANGE_DATE, ", ").concat(i18n[locale].CHOSEN_DATE, " ").concat(value)
|
|
5
|
+
export const Button = React.forwardRef(({ value, locale, onClick }, ref) => {
|
|
6
|
+
const buttonLabel = validateDate(value)
|
|
7
|
+
? `${i18n[locale].CHANGE_DATE}, ${i18n[locale].CHOSEN_DATE} ${value}`
|
|
9
8
|
: i18n[locale].CHOOSE_DATE;
|
|
10
|
-
|
|
9
|
+
const calendarMonthIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik0yMTIuMzA5LTEwMC4wMDFxLTMwLjMwOCAwLTUxLjMwOC0yMXQtMjEtNTEuMzA4di01MzUuMzgycTAtMzAuMzA4IDIxLTUxLjMwOHQ1MS4zMDgtMjFoNTUuMzg1di01My44NDdxMC0xMy4xNTMgOC44MDgtMjEuOTYxIDguODA3LTguODA3IDIxLjk2MS04LjgwNyAxMy4xNTMgMCAyMS45NjEgOC44MDcgOC44MDcgOC44MDggOC44MDcgMjEuOTYxdjUzLjg0N2gzMDMuMDc2di01NC42MTZxMC0xMi43NjkgOC42MTUtMjEuMzg0dDIxLjM4NC04LjYxNXExMi43NjkgMCAyMS4zODQgOC42MTUgOC42MTYgOC42MTUgOC42MTYgMjEuMzg0djU0LjYxNmg1NS4zODVxMzAuMzA4IDAgNTEuMzA4IDIxdDIxIDUxLjMwOHY1MzUuMzgycTAgMzAuMzA4LTIxIDUxLjMwOHQtNTEuMzA4IDIxSDIxMi4zMDlabTAtNTkuOTk5aDUzNS4zODJxNC42MTYgMCA4LjQ2My0zLjg0NiAzLjg0Ni0zLjg0NyAzLjg0Ni04LjQ2M3YtMzc1LjM4MkgyMDB2Mzc1LjM4MnEwIDQuNjE2IDMuODQ2IDguNDYzIDMuODQ3IDMuODQ2IDguNDYzIDMuODQ2Wk0yMDAtNjA3LjY5aDU2MHYtMTAwLjAwMXEwLTQuNjE2LTMuODQ2LTguNDYzLTMuODQ3LTMuODQ2LTguNDYzLTMuODQ2SDIxMi4zMDlxLTQuNjE2IDAtOC40NjMgMy44NDYtMy44NDYgMy44NDctMy44NDYgOC40NjN2MTAwLjAwMVptMCAwVi03MjB2MTEyLjMxWm0yODAgMjEwLjc2N3EtMTQuNjkyIDAtMjUuMDM4LTEwLjM0NnQtMTAuMzQ2LTI1LjAzOHEwLTE0LjY5MiAxMC4zNDYtMjUuMDM4VDQ4MC00NjcuNjkxcTE0LjY5MiAwIDI1LjAzOCAxMC4zNDZ0MTAuMzQ2IDI1LjAzOHEwIDE0LjY5Mi0xMC4zNDYgMjUuMDM4VDQ4MC0zOTYuOTIzWm0tMTYwIDBxLTE0LjY5MiAwLTI1LjAzOC0xMC4zNDZ0LTEwLjM0Ni0yNS4wMzhxMC0xNC42OTIgMTAuMzQ2LTI1LjAzOFQzMjAtNDY3LjY5MXExNC42OTIgMCAyNS4wMzggMTAuMzQ2dDEwLjM0NiAyNS4wMzhxMCAxNC42OTItMTAuMzQ2IDI1LjAzOFQzMjAtMzk2LjkyM1ptMzIwIDBxLTE0LjY5MiAwLTI1LjAzOC0xMC4zNDZ0LTEwLjM0Ni0yNS4wMzhxMC0xNC42OTIgMTAuMzQ2LTI1LjAzOFQ2NDAtNDY3LjY5MXExNC42OTIgMCAyNS4wMzggMTAuMzQ2dDEwLjM0NiAyNS4wMzhxMCAxNC42OTItMTAuMzQ2IDI1LjAzOFQ2NDAtMzk2LjkyM1pNNDgwLTI0MHEtMTQuNjkyIDAtMjUuMDM4LTEwLjM0NnQtMTAuMzQ2LTI1LjAzOHEwLTE0LjY5MiAxMC4zNDYtMjUuMDM4IDEwLjM0Ni0xMC4zNDcgMjUuMDM4LTEwLjM0N3QyNS4wMzggMTAuMzQ3cTEwLjM0NiAxMC4zNDYgMTAuMzQ2IDI1LjAzOHQtMTAuMzQ2IDI1LjAzOFE0OTQuNjkyLTI0MCA0ODAtMjQwWm0tMTYwIDBxLTE0LjY5MiAwLTI1LjAzOC0xMC4zNDZ0LTEwLjM0Ni0yNS4wMzhxMC0xNC42OTIgMTAuMzQ2LTI1LjAzOCAxMC4zNDYtMTAuMzQ3IDI1LjAzOC0xMC4zNDd0MjUuMDM4IDEwLjM0N3ExMC4zNDYgMTAuMzQ2IDEwLjM0NiAyNS4wMzh0LTEwLjM0NiAyNS4wMzhRMzM0LjY5Mi0yNDAgMzIwLTI0MFptMzIwIDBxLTE0LjY5MiAwLTI1LjAzOC0xMC4zNDZ0LTEwLjM0Ni0yNS4wMzhxMC0xNC42OTIgMTAuMzQ2LTI1LjAzOCAxMC4zNDYtMTAuMzQ3IDI1LjAzOC0xMC4zNDd0MjUuMDM4IDEwLjM0N3ExMC4zNDYgMTAuMzQ2IDEwLjM0NiAyNS4wMzh0LTEwLjM0NiAyNS4wMzhRNjU0LjY5Mi0yNDAgNjQwLTI0MFoiLz48L3N2Zz4=';
|
|
11
10
|
return (React.createElement("button", { "data-testid": "datepicker-open", ref: ref, onClick: onClick, className: "ffe-datepicker__button", "aria-label": buttonLabel, type: "button" },
|
|
12
11
|
React.createElement(Icon, { ariaLabel: i18n[locale].CALENDAR_LABEL, fileUrl: calendarMonthIcon, size: "md", className: "ffe-datepicker__icon" })));
|
|
13
12
|
});
|
package/es/calendar/Calendar.js
CHANGED
|
@@ -1,122 +1,104 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
import React, { Component } from 'react';
|
|
17
|
-
import { v4 as uuid } from 'uuid';
|
|
18
2
|
import { ClickableDate } from './ClickableDate';
|
|
19
3
|
import { NonClickableDate } from './NonClickableDate';
|
|
20
4
|
import { Header } from './Header';
|
|
21
5
|
import { getSimpleDateFromString, getSimpleDateFromTimestamp, } from '../datelogic/simpledate';
|
|
22
6
|
import { SimpleCalendar } from '../datelogic/simplecalendar';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_this.focusTrap = function (event) {
|
|
7
|
+
export class Calendar extends Component {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.clickableDateRef = React.createRef();
|
|
11
|
+
this.prevMonthButtonElementRef = React.createRef();
|
|
12
|
+
this.nextMonthButtonElementRef = React.createRef();
|
|
13
|
+
this.monthSelectRef = React.createRef();
|
|
14
|
+
this.yearSelectRef = React.createRef();
|
|
15
|
+
this.focusTrap = (event) => {
|
|
33
16
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
34
|
-
|
|
17
|
+
const activeElement = document.activeElement;
|
|
35
18
|
if (event.key === 'Tab') {
|
|
36
19
|
event.preventDefault();
|
|
37
|
-
|
|
20
|
+
const { dropdownCaption } = this.props;
|
|
38
21
|
if (event.shiftKey) {
|
|
39
|
-
if (activeElement ===
|
|
40
|
-
(_a =
|
|
41
|
-
|
|
22
|
+
if (activeElement === this.clickableDateRef.current) {
|
|
23
|
+
(_a = this.nextMonthButtonElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
24
|
+
this.setState({ isFocusingHeader: true });
|
|
42
25
|
}
|
|
43
|
-
else if (activeElement ===
|
|
26
|
+
else if (activeElement === this.nextMonthButtonElementRef.current) {
|
|
44
27
|
if (dropdownCaption) {
|
|
45
|
-
(_b =
|
|
28
|
+
(_b = this.yearSelectRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
46
29
|
}
|
|
47
30
|
else {
|
|
48
|
-
(_c =
|
|
31
|
+
(_c = this.prevMonthButtonElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
49
32
|
}
|
|
50
33
|
}
|
|
51
|
-
else if (dropdownCaption && activeElement ===
|
|
52
|
-
(_d =
|
|
34
|
+
else if (dropdownCaption && activeElement === this.yearSelectRef.current) {
|
|
35
|
+
(_d = this.monthSelectRef.current) === null || _d === void 0 ? void 0 : _d.focus();
|
|
53
36
|
}
|
|
54
|
-
else if (dropdownCaption && activeElement ===
|
|
55
|
-
(_e =
|
|
37
|
+
else if (dropdownCaption && activeElement === this.monthSelectRef.current) {
|
|
38
|
+
(_e = this.prevMonthButtonElementRef.current) === null || _e === void 0 ? void 0 : _e.focus();
|
|
56
39
|
}
|
|
57
|
-
else if (activeElement ===
|
|
58
|
-
(_f =
|
|
59
|
-
|
|
60
|
-
|
|
40
|
+
else if (activeElement === this.prevMonthButtonElementRef.current) {
|
|
41
|
+
(_f = this.clickableDateRef.current) === null || _f === void 0 ? void 0 : _f.focus();
|
|
42
|
+
this.setState({ isFocusingHeader: false });
|
|
43
|
+
this.forceUpdate();
|
|
61
44
|
}
|
|
62
45
|
}
|
|
63
46
|
else {
|
|
64
|
-
if (activeElement ===
|
|
65
|
-
(_g =
|
|
66
|
-
|
|
47
|
+
if (activeElement === this.clickableDateRef.current) {
|
|
48
|
+
(_g = this.prevMonthButtonElementRef.current) === null || _g === void 0 ? void 0 : _g.focus();
|
|
49
|
+
this.setState({ isFocusingHeader: true });
|
|
67
50
|
}
|
|
68
|
-
else if (activeElement ===
|
|
51
|
+
else if (activeElement === this.prevMonthButtonElementRef.current) {
|
|
69
52
|
if (dropdownCaption) {
|
|
70
|
-
(_h =
|
|
53
|
+
(_h = this.monthSelectRef.current) === null || _h === void 0 ? void 0 : _h.focus();
|
|
71
54
|
}
|
|
72
55
|
else {
|
|
73
|
-
(_j =
|
|
56
|
+
(_j = this.nextMonthButtonElementRef.current) === null || _j === void 0 ? void 0 : _j.focus();
|
|
74
57
|
}
|
|
75
58
|
}
|
|
76
|
-
else if (dropdownCaption && activeElement ===
|
|
77
|
-
(_k =
|
|
59
|
+
else if (dropdownCaption && activeElement === this.monthSelectRef.current) {
|
|
60
|
+
(_k = this.yearSelectRef.current) === null || _k === void 0 ? void 0 : _k.focus();
|
|
78
61
|
}
|
|
79
|
-
else if (dropdownCaption && activeElement ===
|
|
80
|
-
(_l =
|
|
62
|
+
else if (dropdownCaption && activeElement === this.yearSelectRef.current) {
|
|
63
|
+
(_l = this.nextMonthButtonElementRef.current) === null || _l === void 0 ? void 0 : _l.focus();
|
|
81
64
|
}
|
|
82
|
-
else if (activeElement ===
|
|
83
|
-
(_m =
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
else if (activeElement === this.nextMonthButtonElementRef.current) {
|
|
66
|
+
(_m = this.clickableDateRef.current) === null || _m === void 0 ? void 0 : _m.focus();
|
|
67
|
+
this.setState({ isFocusingHeader: false });
|
|
68
|
+
this.forceUpdate();
|
|
86
69
|
}
|
|
87
70
|
}
|
|
88
71
|
}
|
|
89
72
|
};
|
|
90
|
-
|
|
73
|
+
this.state = {
|
|
91
74
|
calendar: new SimpleCalendar(getSimpleDateFromString(props === null || props === void 0 ? void 0 : props.selectedDate), props.minDate, props.maxDate, props.disabledDates, props.locale),
|
|
92
75
|
isFocusingHeader: false,
|
|
93
76
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return _this;
|
|
77
|
+
this.datepickerId = `ffe-calendar-${Math.random().toString(36).slice(2)}`;
|
|
78
|
+
this.keyDown = this.keyDown.bind(this);
|
|
79
|
+
this.mouseClick = this.mouseClick.bind(this);
|
|
80
|
+
this.nextMonth = this.nextMonth.bind(this);
|
|
81
|
+
this.previousMonth = this.previousMonth.bind(this);
|
|
82
|
+
this.navigateToMonthYear = this.navigateToMonthYear.bind(this);
|
|
83
|
+
this.renderDate = this.renderDate.bind(this);
|
|
84
|
+
this.renderWeek = this.renderWeek.bind(this);
|
|
85
|
+
this.renderDay = this.renderDay.bind(this);
|
|
104
86
|
}
|
|
105
87
|
/* eslint-disable react/no-did-update-set-state */
|
|
106
|
-
|
|
88
|
+
componentDidUpdate(prevProps) {
|
|
107
89
|
if (prevProps.selectedDate !== this.props.selectedDate) {
|
|
108
90
|
this.setState({
|
|
109
91
|
calendar: new SimpleCalendar(getSimpleDateFromString(this.props.selectedDate), this.props.minDate, this.props.maxDate, this.props.disabledDates, this.props.locale),
|
|
110
92
|
}, this.forceUpdate);
|
|
111
93
|
}
|
|
112
|
-
}
|
|
113
|
-
|
|
94
|
+
}
|
|
95
|
+
shouldComponentUpdate(nextProps) {
|
|
114
96
|
return nextProps.selectedDate !== this.props.selectedDate;
|
|
115
|
-
}
|
|
116
|
-
|
|
97
|
+
}
|
|
98
|
+
keyDown(event) {
|
|
117
99
|
var _a, _b, _c;
|
|
118
|
-
|
|
119
|
-
|
|
100
|
+
const calendar = this.state.calendar;
|
|
101
|
+
const scrollableEvents = [
|
|
120
102
|
'PageUp',
|
|
121
103
|
'PageDown',
|
|
122
104
|
'End',
|
|
@@ -181,79 +163,74 @@ var Calendar = /** @class */ (function (_super) {
|
|
|
181
163
|
return;
|
|
182
164
|
}
|
|
183
165
|
this.forceUpdate();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
|
|
166
|
+
}
|
|
167
|
+
mouseClick(date) {
|
|
168
|
+
const pickedDate = getSimpleDateFromTimestamp(date.timestamp);
|
|
187
169
|
if (this.state.calendar.isDateWithinDateRange(pickedDate) &&
|
|
188
170
|
date.isEnabled) {
|
|
189
171
|
this.state.calendar.selectTimestamp(date.timestamp);
|
|
190
172
|
this.props.onDatePicked(this.state.calendar.selected());
|
|
191
173
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
174
|
+
}
|
|
175
|
+
nextMonth(evt) {
|
|
194
176
|
evt.preventDefault();
|
|
195
177
|
this.state.calendar.nextMonth();
|
|
196
178
|
this.forceUpdate();
|
|
197
|
-
}
|
|
198
|
-
|
|
179
|
+
}
|
|
180
|
+
previousMonth(evt) {
|
|
199
181
|
evt.preventDefault();
|
|
200
182
|
this.state.calendar.previousMonth();
|
|
201
183
|
this.forceUpdate();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
184
|
+
}
|
|
185
|
+
renderDate(calendarButtonState, index) {
|
|
186
|
+
const { calendar } = this.state;
|
|
205
187
|
if (calendarButtonState.isNonClickableDate) {
|
|
206
188
|
return (React.createElement(NonClickableDate, { key: calendarButtonState.dayInMonth, date: { timestamp: calendarButtonState.timestamp } }));
|
|
207
189
|
}
|
|
208
|
-
return (React.createElement(ClickableDate, { calendarButtonState: calendarButtonState, month: calendar.focusedMonth, year: calendar.focusedYear, headers:
|
|
190
|
+
return (React.createElement(ClickableDate, { calendarButtonState: calendarButtonState, month: calendar.focusedMonth, year: calendar.focusedYear, headers: `header__${this.datepickerId}__${index}`, key: calendarButtonState.timestamp, onClick: this.mouseClick, locale: this.props.locale, dateButtonRef: calendarButtonState.isFocus
|
|
209
191
|
? this.clickableDateRef
|
|
210
192
|
: undefined, isFocusingHeader: this.state.isFocusingHeader, focusOnMount: this.props.focusOnMount }));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return (React.createElement("tr", { key:
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return (React.createElement("th", { "aria-label": day.name, className: "ffe-calendar__weekday", id:
|
|
193
|
+
}
|
|
194
|
+
renderWeek(week) {
|
|
195
|
+
return (React.createElement("tr", { key: `week-${week.number}`, role: "presentation" }, week.dates.map(this.renderDate)));
|
|
196
|
+
}
|
|
197
|
+
renderDay(day, index) {
|
|
198
|
+
return (React.createElement("th", { "aria-label": day.name, className: "ffe-calendar__weekday", id: `header__${this.datepickerId}__${index}`, key: day.name },
|
|
217
199
|
React.createElement("span", { title: day.name }, day.shortName)));
|
|
218
|
-
}
|
|
200
|
+
}
|
|
219
201
|
/**
|
|
220
202
|
* Navigate to a specific month and year
|
|
221
203
|
*/
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
204
|
+
navigateToMonthYear(month, year) {
|
|
205
|
+
const { calendar } = this.state;
|
|
206
|
+
let currentMonth = calendar.focusedDate.month + 1; // 1-indexed month
|
|
207
|
+
let currentYear = calendar.focusedYear;
|
|
226
208
|
// Calculate how many months to move based on current and target date
|
|
227
|
-
|
|
209
|
+
const monthsDiff = (year - currentYear) * 12 + (month - currentMonth);
|
|
228
210
|
if (monthsDiff < 0) {
|
|
229
211
|
// Go backward
|
|
230
|
-
for (
|
|
212
|
+
for (let i = 0; i > monthsDiff; i--) {
|
|
231
213
|
calendar.previousMonth();
|
|
232
214
|
}
|
|
233
215
|
}
|
|
234
216
|
else if (monthsDiff > 0) {
|
|
235
217
|
// Go forward
|
|
236
|
-
for (
|
|
218
|
+
for (let i = 0; i < monthsDiff; i++) {
|
|
237
219
|
calendar.nextMonth();
|
|
238
220
|
}
|
|
239
221
|
}
|
|
240
222
|
this.forceUpdate();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var calendar = this.state.calendar;
|
|
223
|
+
}
|
|
224
|
+
render() {
|
|
225
|
+
const { calendar } = this.state;
|
|
245
226
|
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
|
|
246
|
-
return (React.createElement("div", { role: "dialog", "aria-modal": true, "aria-labelledby":
|
|
227
|
+
return (React.createElement("div", { role: "dialog", "aria-modal": true, "aria-labelledby": `${this.datepickerId}-title`, className: "ffe-default-mode" },
|
|
247
228
|
React.createElement("div", { className: this.props.calendarClassName || 'ffe-calendar', role: "application", onKeyDown: this.focusTrap },
|
|
248
|
-
React.createElement(Header, { datepickerId: this.datepickerId, month: calendar.focusedMonth, nextMonthHandler: this.nextMonth, nextMonthLabel: calendar.nextName, previousMonthHandler: this.previousMonth, previousMonthLabel: calendar.previousName, year: calendar.focusedYear, prevMonthButtonElement: this.prevMonthButtonElementRef, nextMonthButtonElement: this.nextMonthButtonElementRef, monthNumber: calendar.focusedDate.month + 1, locale: this.props.locale, dropdownCaption: this.props.dropdownCaption, onMonthYearChange:
|
|
249
|
-
return _this.navigateToMonthYear(month, year);
|
|
250
|
-
}, minDate: this.props.minDate, maxDate: this.props.maxDate, monthSelectRef: this.monthSelectRef, yearSelectRef: this.yearSelectRef }),
|
|
229
|
+
React.createElement(Header, { datepickerId: this.datepickerId, month: calendar.focusedMonth, nextMonthHandler: this.nextMonth, nextMonthLabel: calendar.nextName, previousMonthHandler: this.previousMonth, previousMonthLabel: calendar.previousName, year: calendar.focusedYear, prevMonthButtonElement: this.prevMonthButtonElementRef, nextMonthButtonElement: this.nextMonthButtonElementRef, monthNumber: calendar.focusedDate.month + 1, locale: this.props.locale, dropdownCaption: this.props.dropdownCaption, onMonthYearChange: (month, year) => this.navigateToMonthYear(month, year), minDate: this.props.minDate, maxDate: this.props.maxDate, monthSelectRef: this.monthSelectRef, yearSelectRef: this.yearSelectRef }),
|
|
251
230
|
React.createElement("table", { className: "ffe-calendar__grid", onKeyDown: this.keyDown, role: "presentation" },
|
|
252
231
|
React.createElement("thead", null,
|
|
253
232
|
React.createElement("tr", null, calendar.dayNames.map(this.renderDay))),
|
|
254
233
|
React.createElement("tbody", null, calendar.visibleDates.map(this.renderWeek))))));
|
|
255
234
|
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
}(Component));
|
|
259
|
-
export { Calendar };
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
var __extends = (this && this.__extends) || (function () {
|
|
2
|
-
var extendStatics = function (d, b) {
|
|
3
|
-
extendStatics = Object.setPrototypeOf ||
|
|
4
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
5
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
6
|
-
return extendStatics(d, b);
|
|
7
|
-
};
|
|
8
|
-
return function (d, b) {
|
|
9
|
-
if (typeof b !== "function" && b !== null)
|
|
10
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
11
|
-
extendStatics(d, b);
|
|
12
|
-
function __() { this.constructor = d; }
|
|
13
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
14
|
-
};
|
|
15
|
-
})();
|
|
16
1
|
import React, { Component } from 'react';
|
|
17
2
|
import classNames from 'classnames';
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function ClickableDate() {
|
|
21
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
22
|
-
}
|
|
23
|
-
ClickableDate.prototype.componentDidMount = function () {
|
|
3
|
+
export class ClickableDate extends Component {
|
|
4
|
+
componentDidMount() {
|
|
24
5
|
if (this.props.focusOnMount) {
|
|
25
6
|
this.focusIfNeeded();
|
|
26
7
|
}
|
|
27
|
-
}
|
|
28
|
-
|
|
8
|
+
}
|
|
9
|
+
componentDidUpdate() {
|
|
29
10
|
this.focusIfNeeded();
|
|
30
|
-
}
|
|
31
|
-
|
|
11
|
+
}
|
|
12
|
+
focusIfNeeded() {
|
|
32
13
|
var _a;
|
|
33
|
-
|
|
14
|
+
const { calendarButtonState, isFocusingHeader, dateButtonRef } = this.props;
|
|
34
15
|
if (calendarButtonState.isFocus && !isFocusingHeader) {
|
|
35
16
|
(_a = dateButtonRef === null || dateButtonRef === void 0 ? void 0 : dateButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
36
17
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
}
|
|
19
|
+
dateClassName() {
|
|
20
|
+
const { calendarButtonState, isFocusingHeader } = this.props;
|
|
21
|
+
const { isEnabled, isFocus, isSelected, isToday } = calendarButtonState;
|
|
41
22
|
return classNames({
|
|
42
23
|
'ffe-calendar__date': true,
|
|
43
24
|
'ffe-calendar__date--today': isToday,
|
|
@@ -46,16 +27,14 @@ var ClickableDate = /** @class */ (function (_super) {
|
|
|
46
27
|
'ffe-calendar__date--selected': isSelected,
|
|
47
28
|
'ffe-calendar__date--disabled-focus': !isEnabled && isFocus,
|
|
48
29
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
30
|
+
}
|
|
31
|
+
tabIndex() {
|
|
51
32
|
return this.props.calendarButtonState.isFocus ? 0 : -1;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return (React.createElement("td", { className: "ffe-calendar__day", headers: headers, role: "button", ref: dateButtonRef, "aria-disabled": !calendarButtonState.isEnabled, "aria-current": calendarButtonState.isSelected, "aria-label":
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
const { calendarButtonState, headers, onClick, locale, dateButtonRef, month, year, } = this.props;
|
|
36
|
+
const monthName = locale === 'en' ? month : month.toLowerCase();
|
|
37
|
+
return (React.createElement("td", { className: "ffe-calendar__day", headers: headers, role: "button", ref: dateButtonRef, "aria-disabled": !calendarButtonState.isEnabled, "aria-current": calendarButtonState.isSelected, "aria-label": `${calendarButtonState.dayInMonth}. ${monthName} ${year}`, tabIndex: this.tabIndex(), onClick: () => onClick(calendarButtonState) },
|
|
57
38
|
React.createElement("span", { className: this.dateClassName(), "aria-hidden": "true" }, calendarButtonState.dayInMonth)));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
}(Component));
|
|
61
|
-
export { ClickableDate };
|
|
39
|
+
}
|
|
40
|
+
}
|
package/es/calendar/Header.js
CHANGED
|
@@ -2,38 +2,37 @@ import React from 'react';
|
|
|
2
2
|
import { Icon } from '@sb1/ffe-icons-react';
|
|
3
3
|
import { Dropdown } from '@sb1/ffe-dropdown-react';
|
|
4
4
|
import { getMonthOptions, getYearOptions } from '../util/dateRangeUtils';
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var selectedMonth = parseInt(e.target.value, 10);
|
|
5
|
+
export const Header = ({ datepickerId, month, nextMonthHandler, nextMonthLabel, previousMonthHandler, previousMonthLabel, year, prevMonthButtonElement, nextMonthButtonElement, monthNumber, dropdownCaption = false, locale, onMonthYearChange, minDate, maxDate, monthSelectRef, yearSelectRef, }) => {
|
|
6
|
+
const arrowBackIosIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Im0zNjcuMzg0LTQ4MCAzMDEuMzA4IDMwMS4zMDhxMTEuOTIzIDExLjkyMyAxMS42MTUgMjguMDc3LS4zMDggMTYuMTUzLTEyLjIzMSAyOC4wNzZxLTExLjkyMiAxMS45MjMtMjguMDc2IDExLjkyM3QtMjguMDc2LTExLjkyM0wzMDUuMDc4LTQyOC43N3EtMTAuODQ3LTEwLjg0Ni0xNi4wNzctMjQuMzA3LTUuMjMxLTEzLjQ2Mi01LjIzMS0yNi45MjMgMC0xMy40NjEgNS4yMzEtMjYuOTIzIDUuMjMtMTMuNDYxIDE2LjA3Ny0yNC4zMDdsMzA2Ljg0Ni0zMDYuODQ2cTExLjkyMi0xMS45MjMgMjguMzg0LTExLjYxNiAxNi40NjEuMzA4IDI4LjM4NCAxMi4yMzEgMTEuOTIzIDExLjkyMyAxMS45MjMgMjguMDc2IDAgMTYuMTU0LTExLjkyMyAyOC4wNzdMMzY3LjM4NC00ODBaIi8+PC9zdmc+';
|
|
7
|
+
const monthOptions = getMonthOptions(locale);
|
|
8
|
+
const yearOptions = getYearOptions(minDate, maxDate);
|
|
9
|
+
const handleMonthChange = (e) => {
|
|
10
|
+
const selectedMonth = parseInt(e.target.value, 10);
|
|
12
11
|
onMonthYearChange === null || onMonthYearChange === void 0 ? void 0 : onMonthYearChange(selectedMonth, year);
|
|
13
12
|
};
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const handleYearChange = (e) => {
|
|
14
|
+
const selectedYear = parseInt(e.target.value, 10);
|
|
16
15
|
onMonthYearChange === null || onMonthYearChange === void 0 ? void 0 : onMonthYearChange(monthNumber, selectedYear);
|
|
17
16
|
};
|
|
18
17
|
// Prevent event propagation when interacting with dropdowns to avoid
|
|
19
18
|
// closing the calendar when selecting from dropdowns
|
|
20
|
-
|
|
19
|
+
const handleDropdownClick = (e) => {
|
|
21
20
|
// Add datepickerId flag to prevent calendar from closing
|
|
22
21
|
e.nativeEvent.__datepickerID = datepickerId;
|
|
23
22
|
e.stopPropagation();
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
const handleDropdownFocus = (e) => {
|
|
26
25
|
e.stopPropagation();
|
|
27
26
|
};
|
|
28
27
|
return (React.createElement("div", { className: "ffe-calendar__header" },
|
|
29
28
|
React.createElement("div", { className: "ffe-calendar__header-inner-wrapper" },
|
|
30
29
|
React.createElement("button", { className: "ffe-calendar__month-nav ffe-calendar__previous", onClick: previousMonthHandler, "aria-label": previousMonthLabel, type: "button", ref: prevMonthButtonElement, tabIndex: -1 },
|
|
31
30
|
React.createElement(Icon, { fileUrl: arrowBackIosIcon, size: "md", className: "ffe-calendar__icon-prev" })),
|
|
32
|
-
React.createElement("header", { "aria-live": "polite", className: "ffe-calendar__title", id:
|
|
31
|
+
React.createElement("header", { "aria-live": "polite", className: "ffe-calendar__title", id: `${datepickerId}-title` }, dropdownCaption ? (React.createElement("div", { className: "ffe-calendar__dropdown-container" },
|
|
33
32
|
React.createElement("div", { className: "ffe-calendar__dropdown ffe-calendar__month-dropdown" },
|
|
34
|
-
React.createElement(Dropdown, { id:
|
|
33
|
+
React.createElement(Dropdown, { id: `${datepickerId}__month-select`, className: "ffe-calendar__month-select", value: monthNumber, onChange: handleMonthChange, "aria-label": `${month} ${year}`, onClick: handleDropdownClick, onFocus: handleDropdownFocus, ref: monthSelectRef }, monthOptions.map(option => (React.createElement("option", { key: option.value, value: option.value }, option.label))))),
|
|
35
34
|
React.createElement("div", { className: "ffe-calendar__dropdown ffe-calendar__year-dropdown" },
|
|
36
|
-
React.createElement(Dropdown, { id:
|
|
35
|
+
React.createElement(Dropdown, { id: `${datepickerId}__year-select`, className: "ffe-calendar__year-select", value: year, onChange: handleYearChange, "aria-label": `${year}`, onClick: handleDropdownClick, onFocus: handleDropdownFocus, ref: yearSelectRef }, yearOptions.map(option => (React.createElement("option", { key: option.value, value: option.value }, option.label))))))) : (React.createElement("div", { id: `${datepickerId}__month-label`, "data-testid": `${datepickerId}__month-label` },
|
|
37
36
|
React.createElement("span", { className: "ffe-calendar__month" }, month),
|
|
38
37
|
React.createElement("span", { className: "ffe-calendar__year" }, year)))),
|
|
39
38
|
React.createElement("button", { className: "ffe-calendar__month-nav ffe-calendar__next", onClick: nextMonthHandler, "aria-label": nextMonthLabel, type: "button", ref: nextMonthButtonElement, tabIndex: -1 },
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export
|
|
3
|
-
var date = _a.date;
|
|
2
|
+
export const NonClickableDate = ({ date }) => {
|
|
4
3
|
return (React.createElement("td", { "aria-hidden": true, className: "ffe-calendar__day", key: date.timestamp, role: "button" }));
|
|
5
4
|
};
|