@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.
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
@@ -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 var Button = React.forwardRef(function (_a, ref) {
6
- var value = _a.value, locale = _a.locale, onClick = _a.onClick;
7
- var buttonLabel = validateDate(value)
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
- var calendarMonthIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Ik0yMTIuMzA5LTEwMC4wMDFxLTMwLjMwOCAwLTUxLjMwOC0yMXQtMjEtNTEuMzA4di01MzUuMzgycTAtMzAuMzA4IDIxLTUxLjMwOHQ1MS4zMDgtMjFoNTUuMzg1di01My44NDdxMC0xMy4xNTMgOC44MDgtMjEuOTYxIDguODA3LTguODA3IDIxLjk2MS04LjgwNyAxMy4xNTMgMCAyMS45NjEgOC44MDcgOC44MDcgOC44MDggOC44MDcgMjEuOTYxdjUzLjg0N2gzMDMuMDc2di01NC42MTZxMC0xMi43NjkgOC42MTUtMjEuMzg0dDIxLjM4NC04LjYxNXExMi43NjkgMCAyMS4zODQgOC42MTUgOC42MTYgOC42MTUgOC42MTYgMjEuMzg0djU0LjYxNmg1NS4zODVxMzAuMzA4IDAgNTEuMzA4IDIxdDIxIDUxLjMwOHY1MzUuMzgycTAgMzAuMzA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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
  });
@@ -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
- var Calendar = /** @class */ (function (_super) {
24
- __extends(Calendar, _super);
25
- function Calendar(props) {
26
- var _this = _super.call(this, props) || this;
27
- _this.clickableDateRef = React.createRef();
28
- _this.prevMonthButtonElementRef = React.createRef();
29
- _this.nextMonthButtonElementRef = React.createRef();
30
- _this.monthSelectRef = React.createRef();
31
- _this.yearSelectRef = React.createRef();
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
- var activeElement = document.activeElement;
17
+ const activeElement = document.activeElement;
35
18
  if (event.key === 'Tab') {
36
19
  event.preventDefault();
37
- var dropdownCaption = _this.props.dropdownCaption;
20
+ const { dropdownCaption } = this.props;
38
21
  if (event.shiftKey) {
39
- if (activeElement === _this.clickableDateRef.current) {
40
- (_a = _this.nextMonthButtonElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
41
- _this.setState({ isFocusingHeader: true });
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 === _this.nextMonthButtonElementRef.current) {
26
+ else if (activeElement === this.nextMonthButtonElementRef.current) {
44
27
  if (dropdownCaption) {
45
- (_b = _this.yearSelectRef.current) === null || _b === void 0 ? void 0 : _b.focus();
28
+ (_b = this.yearSelectRef.current) === null || _b === void 0 ? void 0 : _b.focus();
46
29
  }
47
30
  else {
48
- (_c = _this.prevMonthButtonElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
31
+ (_c = this.prevMonthButtonElementRef.current) === null || _c === void 0 ? void 0 : _c.focus();
49
32
  }
50
33
  }
51
- else if (dropdownCaption && activeElement === _this.yearSelectRef.current) {
52
- (_d = _this.monthSelectRef.current) === null || _d === void 0 ? void 0 : _d.focus();
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 === _this.monthSelectRef.current) {
55
- (_e = _this.prevMonthButtonElementRef.current) === null || _e === void 0 ? void 0 : _e.focus();
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 === _this.prevMonthButtonElementRef.current) {
58
- (_f = _this.clickableDateRef.current) === null || _f === void 0 ? void 0 : _f.focus();
59
- _this.setState({ isFocusingHeader: false });
60
- _this.forceUpdate();
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 === _this.clickableDateRef.current) {
65
- (_g = _this.prevMonthButtonElementRef.current) === null || _g === void 0 ? void 0 : _g.focus();
66
- _this.setState({ isFocusingHeader: true });
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 === _this.prevMonthButtonElementRef.current) {
51
+ else if (activeElement === this.prevMonthButtonElementRef.current) {
69
52
  if (dropdownCaption) {
70
- (_h = _this.monthSelectRef.current) === null || _h === void 0 ? void 0 : _h.focus();
53
+ (_h = this.monthSelectRef.current) === null || _h === void 0 ? void 0 : _h.focus();
71
54
  }
72
55
  else {
73
- (_j = _this.nextMonthButtonElementRef.current) === null || _j === void 0 ? void 0 : _j.focus();
56
+ (_j = this.nextMonthButtonElementRef.current) === null || _j === void 0 ? void 0 : _j.focus();
74
57
  }
75
58
  }
76
- else if (dropdownCaption && activeElement === _this.monthSelectRef.current) {
77
- (_k = _this.yearSelectRef.current) === null || _k === void 0 ? void 0 : _k.focus();
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 === _this.yearSelectRef.current) {
80
- (_l = _this.nextMonthButtonElementRef.current) === null || _l === void 0 ? void 0 : _l.focus();
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 === _this.nextMonthButtonElementRef.current) {
83
- (_m = _this.clickableDateRef.current) === null || _m === void 0 ? void 0 : _m.focus();
84
- _this.setState({ isFocusingHeader: false });
85
- _this.forceUpdate();
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
- _this.state = {
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
- _this.datepickerId = "ffe-calendar-".concat(uuid());
95
- _this.keyDown = _this.keyDown.bind(_this);
96
- _this.mouseClick = _this.mouseClick.bind(_this);
97
- _this.nextMonth = _this.nextMonth.bind(_this);
98
- _this.previousMonth = _this.previousMonth.bind(_this);
99
- _this.navigateToMonthYear = _this.navigateToMonthYear.bind(_this);
100
- _this.renderDate = _this.renderDate.bind(_this);
101
- _this.renderWeek = _this.renderWeek.bind(_this);
102
- _this.renderDay = _this.renderDay.bind(_this);
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
- Calendar.prototype.componentDidUpdate = function (prevProps) {
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
- Calendar.prototype.shouldComponentUpdate = function (nextProps) {
94
+ }
95
+ shouldComponentUpdate(nextProps) {
114
96
  return nextProps.selectedDate !== this.props.selectedDate;
115
- };
116
- Calendar.prototype.keyDown = function (event) {
97
+ }
98
+ keyDown(event) {
117
99
  var _a, _b, _c;
118
- var calendar = this.state.calendar;
119
- var scrollableEvents = [
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
- Calendar.prototype.mouseClick = function (date) {
186
- var pickedDate = getSimpleDateFromTimestamp(date.timestamp);
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
- Calendar.prototype.nextMonth = function (evt) {
174
+ }
175
+ nextMonth(evt) {
194
176
  evt.preventDefault();
195
177
  this.state.calendar.nextMonth();
196
178
  this.forceUpdate();
197
- };
198
- Calendar.prototype.previousMonth = function (evt) {
179
+ }
180
+ previousMonth(evt) {
199
181
  evt.preventDefault();
200
182
  this.state.calendar.previousMonth();
201
183
  this.forceUpdate();
202
- };
203
- Calendar.prototype.renderDate = function (calendarButtonState, index) {
204
- var calendar = this.state.calendar;
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: "header__".concat(this.datepickerId, "__").concat(index), key: calendarButtonState.timestamp, onClick: this.mouseClick, locale: this.props.locale, dateButtonRef: calendarButtonState.isFocus
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
- Calendar.prototype.renderWeek = function (week) {
213
- return (React.createElement("tr", { key: "week-".concat(week.number), role: "presentation" }, week.dates.map(this.renderDate)));
214
- };
215
- Calendar.prototype.renderDay = function (day, index) {
216
- return (React.createElement("th", { "aria-label": day.name, className: "ffe-calendar__weekday", id: "header__".concat(this.datepickerId, "__").concat(index), key: day.name },
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
- Calendar.prototype.navigateToMonthYear = function (month, year) {
223
- var calendar = this.state.calendar;
224
- var currentMonth = calendar.focusedDate.month + 1; // 1-indexed month
225
- var currentYear = calendar.focusedYear;
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
- var monthsDiff = (year - currentYear) * 12 + (month - currentMonth);
209
+ const monthsDiff = (year - currentYear) * 12 + (month - currentMonth);
228
210
  if (monthsDiff < 0) {
229
211
  // Go backward
230
- for (var i = 0; i > monthsDiff; i--) {
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 (var i = 0; i < monthsDiff; i++) {
218
+ for (let i = 0; i < monthsDiff; i++) {
237
219
  calendar.nextMonth();
238
220
  }
239
221
  }
240
222
  this.forceUpdate();
241
- };
242
- Calendar.prototype.render = function () {
243
- var _this = this;
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": "".concat(this.datepickerId, "-title"), className: "ffe-default-mode" },
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: function (month, year) {
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
- return Calendar;
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
- var ClickableDate = /** @class */ (function (_super) {
19
- __extends(ClickableDate, _super);
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
- ClickableDate.prototype.componentDidUpdate = function () {
8
+ }
9
+ componentDidUpdate() {
29
10
  this.focusIfNeeded();
30
- };
31
- ClickableDate.prototype.focusIfNeeded = function () {
11
+ }
12
+ focusIfNeeded() {
32
13
  var _a;
33
- var _b = this.props, calendarButtonState = _b.calendarButtonState, isFocusingHeader = _b.isFocusingHeader, dateButtonRef = _b.dateButtonRef;
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
- ClickableDate.prototype.dateClassName = function () {
39
- var _a = this.props, calendarButtonState = _a.calendarButtonState, isFocusingHeader = _a.isFocusingHeader;
40
- var isEnabled = calendarButtonState.isEnabled, isFocus = calendarButtonState.isFocus, isSelected = calendarButtonState.isSelected, isToday = calendarButtonState.isToday;
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
- ClickableDate.prototype.tabIndex = function () {
30
+ }
31
+ tabIndex() {
51
32
  return this.props.calendarButtonState.isFocus ? 0 : -1;
52
- };
53
- ClickableDate.prototype.render = function () {
54
- 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;
55
- var monthName = locale === 'en' ? month : month.toLowerCase();
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": "".concat(calendarButtonState.dayInMonth, ". ").concat(monthName, " ").concat(year), tabIndex: this.tabIndex(), onClick: function () { return onClick(calendarButtonState); } },
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
- return ClickableDate;
60
- }(Component));
61
- export { ClickableDate };
39
+ }
40
+ }
@@ -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 var Header = function (_a) {
6
- 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;
7
- var arrowBackIosIcon = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgLTk2MCA5NjAgOTYwIiB3aWR0aD0iMjQiPjxwYXRoIGQ9Im0zNjcuMzg0LTQ4MCAzMDEuMzA4IDMwMS4zMDhxMTEuOTIzIDExLjkyMyAxMS42MTUgMjguMDc3LS4zMDggMTYuMTUzLTEyLjIzMSAyOC4wNzZxLTExLjkyMiAxMS45MjMtMjguMDc2IDExLjkyM3QtMjguMDc2LTExLjkyM0wzMDUuMDc4LTQyOC43N3EtMTAuODQ3LTEwLjg0Ni0xNi4wNzctMjQuMzA3LTUuMjMxLTEzLjQ2Mi01LjIzMS0yNi45MjMgMC0xMy40NjEgNS4yMzEtMjYuOTIzIDUuMjMtMTMuNDYxIDE2LjA3Ny0yNC4zMDdsMzA2Ljg0Ni0zMDYuODQ2cTExLjkyMi0xMS45MjMgMjguMzg0LTExLjYxNiAxNi40NjEuMzA4IDI4LjM4NCAxMi4yMzEgMTEuOTIzIDExLjkyMyAxMS45MjMgMjguMDc2IDAgMTYuMTU0LTExLjkyMyAyOC4wNzdMMzY3LjM4NC00ODBaIi8+PC9zdmc+';
8
- var monthOptions = getMonthOptions(locale);
9
- var yearOptions = getYearOptions(minDate, maxDate);
10
- var handleMonthChange = function (e) {
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
- var handleYearChange = function (e) {
15
- var selectedYear = parseInt(e.target.value, 10);
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
- var handleDropdownClick = function (e) {
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
- var handleDropdownFocus = function (e) {
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: "".concat(datepickerId, "-title") }, dropdownCaption ? (React.createElement("div", { className: "ffe-calendar__dropdown-container" },
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: "".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.createElement("option", { key: option.value, value: option.value }, option.label)); }))),
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: "".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.createElement("option", { key: option.value, value: option.value }, option.label)); }))))) : (React.createElement("div", { id: "".concat(datepickerId, "__month-label"), "data-testid": "".concat(datepickerId, "__month-label") },
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 var NonClickableDate = function (_a) {
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
  };