@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.
Files changed (41) hide show
  1. package/es/button/Button.js +4 -5
  2. package/es/calendar/Calendar.js +88 -111
  3. package/es/calendar/ClickableDate.js +20 -41
  4. package/es/calendar/Header.js +13 -14
  5. package/es/calendar/NonClickableDate.js +1 -2
  6. package/es/datelogic/simplecalendar.js +97 -124
  7. package/es/datelogic/simpledate.js +66 -96
  8. package/es/datepicker/Datepicker.js +2 -25
  9. package/es/datepicker/DatepickerComp.js +61 -64
  10. package/es/datepicker/DatepickerContext.js +33 -36
  11. package/es/datepicker/SpinButton.js +8 -32
  12. package/es/datepicker/padZero.js +2 -2
  13. package/es/datepicker/testHelper.js +72 -143
  14. package/es/datepicker/toNumber.js +4 -6
  15. package/es/i18n/i18n.js +3 -3
  16. package/es/input/DateInput.js +3 -26
  17. package/es/types.js +1 -1
  18. package/es/util/dateRangeUtils.js +12 -12
  19. package/es/util/dateUtil.js +2 -2
  20. package/es/util/isIOSSafari.js +4 -4
  21. package/lib/button/Button.js +8 -9
  22. package/lib/calendar/Calendar.js +94 -116
  23. package/lib/calendar/ClickableDate.js +22 -42
  24. package/lib/calendar/Header.js +17 -18
  25. package/lib/calendar/NonClickableDate.js +2 -3
  26. package/lib/datelogic/simplecalendar.js +99 -125
  27. package/lib/datelogic/simpledate.js +67 -96
  28. package/lib/datepicker/Datepicker.js +5 -28
  29. package/lib/datepicker/DatepickerComp.js +74 -77
  30. package/lib/datepicker/DatepickerContext.js +36 -39
  31. package/lib/datepicker/SpinButton.js +10 -34
  32. package/lib/datepicker/padZero.js +2 -2
  33. package/lib/datepicker/testHelper.js +73 -177
  34. package/lib/datepicker/toNumber.js +4 -6
  35. package/lib/i18n/i18n.js +3 -3
  36. package/lib/input/DateInput.js +7 -30
  37. package/lib/types.js +1 -1
  38. package/lib/util/dateRangeUtils.js +14 -14
  39. package/lib/util/dateUtil.js +3 -3
  40. package/lib/util/isIOSSafari.js +4 -4
  41. package/package.json +13 -14
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
3
  if (k2 === undefined) k2 = k;
19
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -49,110 +34,107 @@ var __importStar = (this && this.__importStar) || (function () {
49
34
  })();
50
35
  Object.defineProperty(exports, "__esModule", { value: true });
51
36
  exports.Calendar = void 0;
52
- var react_1 = __importStar(require("react"));
53
- var uuid_1 = require("uuid");
54
- var ClickableDate_1 = require("./ClickableDate");
55
- var NonClickableDate_1 = require("./NonClickableDate");
56
- var Header_1 = require("./Header");
57
- var simpledate_1 = require("../datelogic/simpledate");
58
- var simplecalendar_1 = require("../datelogic/simplecalendar");
59
- var Calendar = /** @class */ (function (_super) {
60
- __extends(Calendar, _super);
61
- function Calendar(props) {
62
- var _this = _super.call(this, props) || this;
63
- _this.clickableDateRef = react_1.default.createRef();
64
- _this.prevMonthButtonElementRef = react_1.default.createRef();
65
- _this.nextMonthButtonElementRef = react_1.default.createRef();
66
- _this.monthSelectRef = react_1.default.createRef();
67
- _this.yearSelectRef = react_1.default.createRef();
68
- _this.focusTrap = function (event) {
37
+ const react_1 = __importStar(require("react"));
38
+ const ClickableDate_1 = require("./ClickableDate");
39
+ const NonClickableDate_1 = require("./NonClickableDate");
40
+ const Header_1 = require("./Header");
41
+ const simpledate_1 = require("../datelogic/simpledate");
42
+ const simplecalendar_1 = require("../datelogic/simplecalendar");
43
+ class Calendar extends react_1.Component {
44
+ constructor(props) {
45
+ super(props);
46
+ this.clickableDateRef = react_1.default.createRef();
47
+ this.prevMonthButtonElementRef = react_1.default.createRef();
48
+ this.nextMonthButtonElementRef = react_1.default.createRef();
49
+ this.monthSelectRef = react_1.default.createRef();
50
+ this.yearSelectRef = react_1.default.createRef();
51
+ this.focusTrap = (event) => {
69
52
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
70
- var activeElement = document.activeElement;
53
+ const activeElement = document.activeElement;
71
54
  if (event.key === 'Tab') {
72
55
  event.preventDefault();
73
- var dropdownCaption = _this.props.dropdownCaption;
56
+ const { dropdownCaption } = this.props;
74
57
  if (event.shiftKey) {
75
- if (activeElement === _this.clickableDateRef.current) {
76
- (_a = _this.nextMonthButtonElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
77
- _this.setState({ isFocusingHeader: true });
58
+ if (activeElement === this.clickableDateRef.current) {
59
+ (_a = this.nextMonthButtonElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
60
+ this.setState({ isFocusingHeader: true });
78
61
  }
79
- else if (activeElement === _this.nextMonthButtonElementRef.current) {
62
+ else if (activeElement === this.nextMonthButtonElementRef.current) {
80
63
  if (dropdownCaption) {
81
- (_b = _this.yearSelectRef.current) === null || _b === void 0 ? void 0 : _b.focus();
64
+ (_b = this.yearSelectRef.current) === null || _b === void 0 ? void 0 : _b.focus();
82
65
  }
83
66
  else {
84
- (_c = _this.prevMonthButtonElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
67
+ (_c = this.prevMonthButtonElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
85
68
  }
86
69
  }
87
- else if (dropdownCaption && activeElement === _this.yearSelectRef.current) {
88
- (_d = _this.monthSelectRef.current) === null || _d === void 0 ? void 0 : _d.focus();
70
+ else if (dropdownCaption && activeElement === this.yearSelectRef.current) {
71
+ (_d = this.monthSelectRef.current) === null || _d === void 0 ? void 0 : _d.focus();
89
72
  }
90
- else if (dropdownCaption && activeElement === _this.monthSelectRef.current) {
91
- (_e = _this.prevMonthButtonElementRef.current) === null || _e === void 0 ? void 0 : _e.focus();
73
+ else if (dropdownCaption && activeElement === this.monthSelectRef.current) {
74
+ (_e = this.prevMonthButtonElementRef.current) === null || _e === void 0 ? void 0 : _e.focus();
92
75
  }
93
- else if (activeElement === _this.prevMonthButtonElementRef.current) {
94
- (_f = _this.clickableDateRef.current) === null || _f === void 0 ? void 0 : _f.focus();
95
- _this.setState({ isFocusingHeader: false });
96
- _this.forceUpdate();
76
+ else if (activeElement === this.prevMonthButtonElementRef.current) {
77
+ (_f = this.clickableDateRef.current) === null || _f === void 0 ? void 0 : _f.focus();
78
+ this.setState({ isFocusingHeader: false });
79
+ this.forceUpdate();
97
80
  }
98
81
  }
99
82
  else {
100
- if (activeElement === _this.clickableDateRef.current) {
101
- (_g = _this.prevMonthButtonElementRef.current) === null || _g === void 0 ? void 0 : _g.focus();
102
- _this.setState({ isFocusingHeader: true });
83
+ if (activeElement === this.clickableDateRef.current) {
84
+ (_g = this.prevMonthButtonElementRef.current) === null || _g === void 0 ? void 0 : _g.focus();
85
+ this.setState({ isFocusingHeader: true });
103
86
  }
104
- else if (activeElement === _this.prevMonthButtonElementRef.current) {
87
+ else if (activeElement === this.prevMonthButtonElementRef.current) {
105
88
  if (dropdownCaption) {
106
- (_h = _this.monthSelectRef.current) === null || _h === void 0 ? void 0 : _h.focus();
89
+ (_h = this.monthSelectRef.current) === null || _h === void 0 ? void 0 : _h.focus();
107
90
  }
108
91
  else {
109
- (_j = _this.nextMonthButtonElementRef.current) === null || _j === void 0 ? void 0 : _j.focus();
92
+ (_j = this.nextMonthButtonElementRef.current) === null || _j === void 0 ? void 0 : _j.focus();
110
93
  }
111
94
  }
112
- else if (dropdownCaption && activeElement === _this.monthSelectRef.current) {
113
- (_k = _this.yearSelectRef.current) === null || _k === void 0 ? void 0 : _k.focus();
95
+ else if (dropdownCaption && activeElement === this.monthSelectRef.current) {
96
+ (_k = this.yearSelectRef.current) === null || _k === void 0 ? void 0 : _k.focus();
114
97
  }
115
- else if (dropdownCaption && activeElement === _this.yearSelectRef.current) {
116
- (_l = _this.nextMonthButtonElementRef.current) === null || _l === void 0 ? void 0 : _l.focus();
98
+ else if (dropdownCaption && activeElement === this.yearSelectRef.current) {
99
+ (_l = this.nextMonthButtonElementRef.current) === null || _l === void 0 ? void 0 : _l.focus();
117
100
  }
118
- else if (activeElement === _this.nextMonthButtonElementRef.current) {
119
- (_m = _this.clickableDateRef.current) === null || _m === void 0 ? void 0 : _m.focus();
120
- _this.setState({ isFocusingHeader: false });
121
- _this.forceUpdate();
101
+ else if (activeElement === this.nextMonthButtonElementRef.current) {
102
+ (_m = this.clickableDateRef.current) === null || _m === void 0 ? void 0 : _m.focus();
103
+ this.setState({ isFocusingHeader: false });
104
+ this.forceUpdate();
122
105
  }
123
106
  }
124
107
  }
125
108
  };
126
- _this.state = {
109
+ this.state = {
127
110
  calendar: new simplecalendar_1.SimpleCalendar((0, simpledate_1.getSimpleDateFromString)(props === null || props === void 0 ? void 0 : props.selectedDate), props.minDate, props.maxDate, props.disabledDates, props.locale),
128
111
  isFocusingHeader: false,
129
112
  };
130
- _this.datepickerId = "ffe-calendar-".concat((0, uuid_1.v4)());
131
- _this.keyDown = _this.keyDown.bind(_this);
132
- _this.mouseClick = _this.mouseClick.bind(_this);
133
- _this.nextMonth = _this.nextMonth.bind(_this);
134
- _this.previousMonth = _this.previousMonth.bind(_this);
135
- _this.navigateToMonthYear = _this.navigateToMonthYear.bind(_this);
136
- _this.renderDate = _this.renderDate.bind(_this);
137
- _this.renderWeek = _this.renderWeek.bind(_this);
138
- _this.renderDay = _this.renderDay.bind(_this);
139
- return _this;
113
+ this.datepickerId = `ffe-calendar-${Math.random().toString(36).slice(2)}`;
114
+ this.keyDown = this.keyDown.bind(this);
115
+ this.mouseClick = this.mouseClick.bind(this);
116
+ this.nextMonth = this.nextMonth.bind(this);
117
+ this.previousMonth = this.previousMonth.bind(this);
118
+ this.navigateToMonthYear = this.navigateToMonthYear.bind(this);
119
+ this.renderDate = this.renderDate.bind(this);
120
+ this.renderWeek = this.renderWeek.bind(this);
121
+ this.renderDay = this.renderDay.bind(this);
140
122
  }
141
123
  /* eslint-disable react/no-did-update-set-state */
142
- Calendar.prototype.componentDidUpdate = function (prevProps) {
124
+ componentDidUpdate(prevProps) {
143
125
  if (prevProps.selectedDate !== this.props.selectedDate) {
144
126
  this.setState({
145
127
  calendar: new simplecalendar_1.SimpleCalendar((0, simpledate_1.getSimpleDateFromString)(this.props.selectedDate), this.props.minDate, this.props.maxDate, this.props.disabledDates, this.props.locale),
146
128
  }, this.forceUpdate);
147
129
  }
148
- };
149
- Calendar.prototype.shouldComponentUpdate = function (nextProps) {
130
+ }
131
+ shouldComponentUpdate(nextProps) {
150
132
  return nextProps.selectedDate !== this.props.selectedDate;
151
- };
152
- Calendar.prototype.keyDown = function (event) {
133
+ }
134
+ keyDown(event) {
153
135
  var _a, _b, _c;
154
- var calendar = this.state.calendar;
155
- var scrollableEvents = [
136
+ const calendar = this.state.calendar;
137
+ const scrollableEvents = [
156
138
  'PageUp',
157
139
  'PageDown',
158
140
  'End',
@@ -217,79 +199,75 @@ var Calendar = /** @class */ (function (_super) {
217
199
  return;
218
200
  }
219
201
  this.forceUpdate();
220
- };
221
- Calendar.prototype.mouseClick = function (date) {
222
- var pickedDate = (0, simpledate_1.getSimpleDateFromTimestamp)(date.timestamp);
202
+ }
203
+ mouseClick(date) {
204
+ const pickedDate = (0, simpledate_1.getSimpleDateFromTimestamp)(date.timestamp);
223
205
  if (this.state.calendar.isDateWithinDateRange(pickedDate) &&
224
206
  date.isEnabled) {
225
207
  this.state.calendar.selectTimestamp(date.timestamp);
226
208
  this.props.onDatePicked(this.state.calendar.selected());
227
209
  }
228
- };
229
- Calendar.prototype.nextMonth = function (evt) {
210
+ }
211
+ nextMonth(evt) {
230
212
  evt.preventDefault();
231
213
  this.state.calendar.nextMonth();
232
214
  this.forceUpdate();
233
- };
234
- Calendar.prototype.previousMonth = function (evt) {
215
+ }
216
+ previousMonth(evt) {
235
217
  evt.preventDefault();
236
218
  this.state.calendar.previousMonth();
237
219
  this.forceUpdate();
238
- };
239
- Calendar.prototype.renderDate = function (calendarButtonState, index) {
240
- var calendar = this.state.calendar;
220
+ }
221
+ renderDate(calendarButtonState, index) {
222
+ const { calendar } = this.state;
241
223
  if (calendarButtonState.isNonClickableDate) {
242
224
  return (react_1.default.createElement(NonClickableDate_1.NonClickableDate, { key: calendarButtonState.dayInMonth, date: { timestamp: calendarButtonState.timestamp } }));
243
225
  }
244
- return (react_1.default.createElement(ClickableDate_1.ClickableDate, { calendarButtonState: calendarButtonState, month: calendar.focusedMonth, year: calendar.focusedYear, headers: "header__".concat(this.datepickerId, "__").concat(index), key: calendarButtonState.timestamp, onClick: this.mouseClick, locale: this.props.locale, dateButtonRef: calendarButtonState.isFocus
226
+ return (react_1.default.createElement(ClickableDate_1.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
245
227
  ? this.clickableDateRef
246
228
  : undefined, isFocusingHeader: this.state.isFocusingHeader, focusOnMount: this.props.focusOnMount }));
247
- };
248
- Calendar.prototype.renderWeek = function (week) {
249
- return (react_1.default.createElement("tr", { key: "week-".concat(week.number), role: "presentation" }, week.dates.map(this.renderDate)));
250
- };
251
- Calendar.prototype.renderDay = function (day, index) {
252
- return (react_1.default.createElement("th", { "aria-label": day.name, className: "ffe-calendar__weekday", id: "header__".concat(this.datepickerId, "__").concat(index), key: day.name },
229
+ }
230
+ renderWeek(week) {
231
+ return (react_1.default.createElement("tr", { key: `week-${week.number}`, role: "presentation" }, week.dates.map(this.renderDate)));
232
+ }
233
+ renderDay(day, index) {
234
+ return (react_1.default.createElement("th", { "aria-label": day.name, className: "ffe-calendar__weekday", id: `header__${this.datepickerId}__${index}`, key: day.name },
253
235
  react_1.default.createElement("span", { title: day.name }, day.shortName)));
254
- };
236
+ }
255
237
  /**
256
238
  * Navigate to a specific month and year
257
239
  */
258
- Calendar.prototype.navigateToMonthYear = function (month, year) {
259
- var calendar = this.state.calendar;
260
- var currentMonth = calendar.focusedDate.month + 1; // 1-indexed month
261
- var currentYear = calendar.focusedYear;
240
+ navigateToMonthYear(month, year) {
241
+ const { calendar } = this.state;
242
+ let currentMonth = calendar.focusedDate.month + 1; // 1-indexed month
243
+ let currentYear = calendar.focusedYear;
262
244
  // Calculate how many months to move based on current and target date
263
- var monthsDiff = (year - currentYear) * 12 + (month - currentMonth);
245
+ const monthsDiff = (year - currentYear) * 12 + (month - currentMonth);
264
246
  if (monthsDiff < 0) {
265
247
  // Go backward
266
- for (var i = 0; i > monthsDiff; i--) {
248
+ for (let i = 0; i > monthsDiff; i--) {
267
249
  calendar.previousMonth();
268
250
  }
269
251
  }
270
252
  else if (monthsDiff > 0) {
271
253
  // Go forward
272
- for (var i = 0; i < monthsDiff; i++) {
254
+ for (let i = 0; i < monthsDiff; i++) {
273
255
  calendar.nextMonth();
274
256
  }
275
257
  }
276
258
  this.forceUpdate();
277
- };
278
- Calendar.prototype.render = function () {
279
- var _this = this;
280
- var calendar = this.state.calendar;
259
+ }
260
+ render() {
261
+ const { calendar } = this.state;
281
262
  /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
282
- return (react_1.default.createElement("div", { role: "dialog", "aria-modal": true, "aria-labelledby": "".concat(this.datepickerId, "-title"), className: "ffe-default-mode" },
263
+ return (react_1.default.createElement("div", { role: "dialog", "aria-modal": true, "aria-labelledby": `${this.datepickerId}-title`, className: "ffe-default-mode" },
283
264
  react_1.default.createElement("div", { className: this.props.calendarClassName || 'ffe-calendar', role: "application", onKeyDown: this.focusTrap },
284
- react_1.default.createElement(Header_1.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: function (month, year) {
285
- return _this.navigateToMonthYear(month, year);
286
- }, minDate: this.props.minDate, maxDate: this.props.maxDate, monthSelectRef: this.monthSelectRef, yearSelectRef: this.yearSelectRef }),
265
+ react_1.default.createElement(Header_1.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 }),
287
266
  react_1.default.createElement("table", { className: "ffe-calendar__grid", onKeyDown: this.keyDown, role: "presentation" },
288
267
  react_1.default.createElement("thead", null,
289
268
  react_1.default.createElement("tr", null, calendar.dayNames.map(this.renderDay))),
290
269
  react_1.default.createElement("tbody", null, calendar.visibleDates.map(this.renderWeek))))));
291
270
  /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */
292
- };
293
- return Calendar;
294
- }(react_1.Component));
271
+ }
272
+ }
295
273
  exports.Calendar = Calendar;
@@ -1,19 +1,4 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
3
  if (k2 === undefined) k2 = k;
19
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -52,31 +37,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
52
37
  };
53
38
  Object.defineProperty(exports, "__esModule", { value: true });
54
39
  exports.ClickableDate = void 0;
55
- var react_1 = __importStar(require("react"));
56
- var classnames_1 = __importDefault(require("classnames"));
57
- var ClickableDate = /** @class */ (function (_super) {
58
- __extends(ClickableDate, _super);
59
- function ClickableDate() {
60
- return _super !== null && _super.apply(this, arguments) || this;
61
- }
62
- ClickableDate.prototype.componentDidMount = function () {
40
+ const react_1 = __importStar(require("react"));
41
+ const classnames_1 = __importDefault(require("classnames"));
42
+ class ClickableDate extends react_1.Component {
43
+ componentDidMount() {
63
44
  if (this.props.focusOnMount) {
64
45
  this.focusIfNeeded();
65
46
  }
66
- };
67
- ClickableDate.prototype.componentDidUpdate = function () {
47
+ }
48
+ componentDidUpdate() {
68
49
  this.focusIfNeeded();
69
- };
70
- ClickableDate.prototype.focusIfNeeded = function () {
50
+ }
51
+ focusIfNeeded() {
71
52
  var _a;
72
- var _b = this.props, calendarButtonState = _b.calendarButtonState, isFocusingHeader = _b.isFocusingHeader, dateButtonRef = _b.dateButtonRef;
53
+ const { calendarButtonState, isFocusingHeader, dateButtonRef } = this.props;
73
54
  if (calendarButtonState.isFocus && !isFocusingHeader) {
74
55
  (_a = dateButtonRef === null || dateButtonRef === void 0 ? void 0 : dateButtonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
75
56
  }
76
- };
77
- ClickableDate.prototype.dateClassName = function () {
78
- var _a = this.props, calendarButtonState = _a.calendarButtonState, isFocusingHeader = _a.isFocusingHeader;
79
- var isEnabled = calendarButtonState.isEnabled, isFocus = calendarButtonState.isFocus, isSelected = calendarButtonState.isSelected, isToday = calendarButtonState.isToday;
57
+ }
58
+ dateClassName() {
59
+ const { calendarButtonState, isFocusingHeader } = this.props;
60
+ const { isEnabled, isFocus, isSelected, isToday } = calendarButtonState;
80
61
  return (0, classnames_1.default)({
81
62
  'ffe-calendar__date': true,
82
63
  'ffe-calendar__date--today': isToday,
@@ -85,16 +66,15 @@ var ClickableDate = /** @class */ (function (_super) {
85
66
  'ffe-calendar__date--selected': isSelected,
86
67
  'ffe-calendar__date--disabled-focus': !isEnabled && isFocus,
87
68
  });
88
- };
89
- ClickableDate.prototype.tabIndex = function () {
69
+ }
70
+ tabIndex() {
90
71
  return this.props.calendarButtonState.isFocus ? 0 : -1;
91
- };
92
- ClickableDate.prototype.render = function () {
93
- var _a = this.props, calendarButtonState = _a.calendarButtonState, headers = _a.headers, onClick = _a.onClick, locale = _a.locale, dateButtonRef = _a.dateButtonRef, month = _a.month, year = _a.year;
94
- var monthName = locale === 'en' ? month : month.toLowerCase();
95
- return (react_1.default.createElement("td", { className: "ffe-calendar__day", headers: headers, role: "button", ref: dateButtonRef, "aria-disabled": !calendarButtonState.isEnabled, "aria-current": calendarButtonState.isSelected, "aria-label": "".concat(calendarButtonState.dayInMonth, ". ").concat(monthName, " ").concat(year), tabIndex: this.tabIndex(), onClick: function () { return onClick(calendarButtonState); } },
72
+ }
73
+ render() {
74
+ const { calendarButtonState, headers, onClick, locale, dateButtonRef, month, year, } = this.props;
75
+ const monthName = locale === 'en' ? month : month.toLowerCase();
76
+ return (react_1.default.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) },
96
77
  react_1.default.createElement("span", { className: this.dateClassName(), "aria-hidden": "true" }, calendarButtonState.dayInMonth)));
97
- };
98
- return ClickableDate;
99
- }(react_1.Component));
78
+ }
79
+ }
100
80
  exports.ClickableDate = ClickableDate;
@@ -4,42 +4,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Header = void 0;
7
- var react_1 = __importDefault(require("react"));
8
- var ffe_icons_react_1 = require("@sb1/ffe-icons-react");
9
- var ffe_dropdown_react_1 = require("@sb1/ffe-dropdown-react");
10
- var dateRangeUtils_1 = require("../util/dateRangeUtils");
11
- var Header = function (_a) {
12
- var datepickerId = _a.datepickerId, month = _a.month, nextMonthHandler = _a.nextMonthHandler, nextMonthLabel = _a.nextMonthLabel, previousMonthHandler = _a.previousMonthHandler, previousMonthLabel = _a.previousMonthLabel, year = _a.year, prevMonthButtonElement = _a.prevMonthButtonElement, nextMonthButtonElement = _a.nextMonthButtonElement, monthNumber = _a.monthNumber, _b = _a.dropdownCaption, dropdownCaption = _b === void 0 ? false : _b, locale = _a.locale, onMonthYearChange = _a.onMonthYearChange, minDate = _a.minDate, maxDate = _a.maxDate, monthSelectRef = _a.monthSelectRef, yearSelectRef = _a.yearSelectRef;
13
- var arrowBackIosIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Im0zNjcuMzg0LTQ4MCAzMDEuMzA4IDMwMS4zMDhxMTEuOTIzIDExLjkyMyAxMS42MTUgMjguMDc3LS4zMDggMTYuMTUzLTEyLjIzMSAyOC4wNzZxLTExLjkyMiAxMS45MjMtMjguMDc2IDExLjkyM3QtMjguMDc2LTExLjkyM0wzMDUuMDc4LTQyOC43N3EtMTAuODQ3LTEwLjg0Ni0xNi4wNzctMjQuMzA3LTUuMjMxLTEzLjQ2Mi01LjIzMS0yNi45MjMgMC0xMy40NjEgNS4yMzEtMjYuOTIzIDUuMjMtMTMuNDYxIDE2LjA3Ny0yNC4zMDdsMzA2Ljg0Ni0zMDYuODQ2cTExLjkyMi0xMS45MjMgMjguMzg0LTExLjYxNiAxNi40NjEuMzA4IDI4LjM4NCAxMi4yMzEgMTEuOTIzIDExLjkyMyAxMS45MjMgMjguMDc2IDAgMTYuMTU0LTExLjkyMyAyOC4wNzdMMzY3LjM4NC00ODBaIi8+PC9zdmc+';
14
- var monthOptions = (0, dateRangeUtils_1.getMonthOptions)(locale);
15
- var yearOptions = (0, dateRangeUtils_1.getYearOptions)(minDate, maxDate);
16
- var handleMonthChange = function (e) {
17
- var selectedMonth = parseInt(e.target.value, 10);
7
+ const react_1 = __importDefault(require("react"));
8
+ const ffe_icons_react_1 = require("@sb1/ffe-icons-react");
9
+ const ffe_dropdown_react_1 = require("@sb1/ffe-dropdown-react");
10
+ const dateRangeUtils_1 = require("../util/dateRangeUtils");
11
+ const Header = ({ datepickerId, month, nextMonthHandler, nextMonthLabel, previousMonthHandler, previousMonthLabel, year, prevMonthButtonElement, nextMonthButtonElement, monthNumber, dropdownCaption = false, locale, onMonthYearChange, minDate, maxDate, monthSelectRef, yearSelectRef, }) => {
12
+ const arrowBackIosIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Im0zNjcuMzg0LTQ4MCAzMDEuMzA4IDMwMS4zMDhxMTEuOTIzIDExLjkyMyAxMS42MTUgMjguMDc3LS4zMDggMTYuMTUzLTEyLjIzMSAyOC4wNzZxLTExLjkyMiAxMS45MjMtMjguMDc2IDExLjkyM3QtMjguMDc2LTExLjkyM0wzMDUuMDc4LTQyOC43N3EtMTAuODQ3LTEwLjg0Ni0xNi4wNzctMjQuMzA3LTUuMjMxLTEzLjQ2Mi01LjIzMS0yNi45MjMgMC0xMy40NjEgNS4yMzEtMjYuOTIzIDUuMjMtMTMuNDYxIDE2LjA3Ny0yNC4zMDdsMzA2Ljg0Ni0zMDYuODQ2cTExLjkyMi0xMS45MjMgMjguMzg0LTExLjYxNiAxNi40NjEuMzA4IDI4LjM4NCAxMi4yMzEgMTEuOTIzIDExLjkyMyAxMS45MjMgMjguMDc2IDAgMTYuMTU0LTExLjkyMyAyOC4wNzdMMzY3LjM4NC00ODBaIi8+PC9zdmc+';
13
+ const monthOptions = (0, dateRangeUtils_1.getMonthOptions)(locale);
14
+ const yearOptions = (0, dateRangeUtils_1.getYearOptions)(minDate, maxDate);
15
+ const handleMonthChange = (e) => {
16
+ const selectedMonth = parseInt(e.target.value, 10);
18
17
  onMonthYearChange === null || onMonthYearChange === void 0 ? void 0 : onMonthYearChange(selectedMonth, year);
19
18
  };
20
- var handleYearChange = function (e) {
21
- var selectedYear = parseInt(e.target.value, 10);
19
+ const handleYearChange = (e) => {
20
+ const selectedYear = parseInt(e.target.value, 10);
22
21
  onMonthYearChange === null || onMonthYearChange === void 0 ? void 0 : onMonthYearChange(monthNumber, selectedYear);
23
22
  };
24
23
  // Prevent event propagation when interacting with dropdowns to avoid
25
24
  // closing the calendar when selecting from dropdowns
26
- var handleDropdownClick = function (e) {
25
+ const handleDropdownClick = (e) => {
27
26
  // Add datepickerId flag to prevent calendar from closing
28
27
  e.nativeEvent.__datepickerID = datepickerId;
29
28
  e.stopPropagation();
30
29
  };
31
- var handleDropdownFocus = function (e) {
30
+ const handleDropdownFocus = (e) => {
32
31
  e.stopPropagation();
33
32
  };
34
33
  return (react_1.default.createElement("div", { className: "ffe-calendar__header" },
35
34
  react_1.default.createElement("div", { className: "ffe-calendar__header-inner-wrapper" },
36
35
  react_1.default.createElement("button", { className: "ffe-calendar__month-nav ffe-calendar__previous", onClick: previousMonthHandler, "aria-label": previousMonthLabel, type: "button", ref: prevMonthButtonElement, tabIndex: -1 },
37
36
  react_1.default.createElement(ffe_icons_react_1.Icon, { fileUrl: arrowBackIosIcon, size: "md", className: "ffe-calendar__icon-prev" })),
38
- react_1.default.createElement("header", { "aria-live": "polite", className: "ffe-calendar__title", id: "".concat(datepickerId, "-title") }, dropdownCaption ? (react_1.default.createElement("div", { className: "ffe-calendar__dropdown-container" },
37
+ react_1.default.createElement("header", { "aria-live": "polite", className: "ffe-calendar__title", id: `${datepickerId}-title` }, dropdownCaption ? (react_1.default.createElement("div", { className: "ffe-calendar__dropdown-container" },
39
38
  react_1.default.createElement("div", { className: "ffe-calendar__dropdown ffe-calendar__month-dropdown" },
40
- react_1.default.createElement(ffe_dropdown_react_1.Dropdown, { id: "".concat(datepickerId, "__month-select"), className: "ffe-calendar__month-select", value: monthNumber, onChange: handleMonthChange, "aria-label": "".concat(month, " ").concat(year), onClick: handleDropdownClick, onFocus: handleDropdownFocus, ref: monthSelectRef }, monthOptions.map(function (option) { return (react_1.default.createElement("option", { key: option.value, value: option.value }, option.label)); }))),
39
+ react_1.default.createElement(ffe_dropdown_react_1.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_1.default.createElement("option", { key: option.value, value: option.value }, option.label))))),
41
40
  react_1.default.createElement("div", { className: "ffe-calendar__dropdown ffe-calendar__year-dropdown" },
42
- react_1.default.createElement(ffe_dropdown_react_1.Dropdown, { id: "".concat(datepickerId, "__year-select"), className: "ffe-calendar__year-select", value: year, onChange: handleYearChange, "aria-label": "".concat(year), onClick: handleDropdownClick, onFocus: handleDropdownFocus, ref: yearSelectRef }, yearOptions.map(function (option) { return (react_1.default.createElement("option", { key: option.value, value: option.value }, option.label)); }))))) : (react_1.default.createElement("div", { id: "".concat(datepickerId, "__month-label"), "data-testid": "".concat(datepickerId, "__month-label") },
41
+ react_1.default.createElement(ffe_dropdown_react_1.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_1.default.createElement("option", { key: option.value, value: option.value }, option.label))))))) : (react_1.default.createElement("div", { id: `${datepickerId}__month-label`, "data-testid": `${datepickerId}__month-label` },
43
42
  react_1.default.createElement("span", { className: "ffe-calendar__month" }, month),
44
43
  react_1.default.createElement("span", { className: "ffe-calendar__year" }, year)))),
45
44
  react_1.default.createElement("button", { className: "ffe-calendar__month-nav ffe-calendar__next", onClick: nextMonthHandler, "aria-label": nextMonthLabel, type: "button", ref: nextMonthButtonElement, tabIndex: -1 },
@@ -4,9 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.NonClickableDate = void 0;
7
- var react_1 = __importDefault(require("react"));
8
- var NonClickableDate = function (_a) {
9
- var date = _a.date;
7
+ const react_1 = __importDefault(require("react"));
8
+ const NonClickableDate = ({ date }) => {
10
9
  return (react_1.default.createElement("td", { "aria-hidden": true, className: "ffe-calendar__day", key: date.timestamp, role: "button" }));
11
10
  };
12
11
  exports.NonClickableDate = NonClickableDate;