@transferwise/components 0.0.0-experimental-fc2bb05 → 0.0.0-experimental-c6fb370
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/build/Calendar/Calendar.js +17 -121
- package/build/Calendar/Calendar.js.map +1 -1
- package/build/Calendar/Calendar.messages.js +0 -12
- package/build/Calendar/Calendar.messages.js.map +1 -1
- package/build/Calendar/Calendar.messages.mjs +0 -12
- package/build/Calendar/Calendar.messages.mjs.map +1 -1
- package/build/Calendar/Calendar.mjs +18 -122
- package/build/Calendar/Calendar.mjs.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.js +1 -5
- package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.mjs +1 -5
- package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.js +2 -20
- package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.mjs +2 -20
- package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +19 -60
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +19 -60
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.js +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.js +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.mjs +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
- package/build/Calendar/tableLink/TableLink.js +61 -0
- package/build/Calendar/tableLink/TableLink.js.map +1 -0
- package/build/Calendar/tableLink/TableLink.mjs +57 -0
- package/build/Calendar/tableLink/TableLink.mjs.map +1 -0
- package/build/DateLookup/DateLookup.js +9 -20
- package/build/DateLookup/DateLookup.js.map +1 -1
- package/build/DateLookup/DateLookup.mjs +9 -20
- package/build/DateLookup/DateLookup.mjs.map +1 -1
- package/build/i18n/en.json +0 -4
- package/build/i18n/en.json.js +0 -4
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -4
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +2 -2
- package/build/index.mjs +1 -1
- package/build/main.css +43 -123
- package/build/styles/Calendar/Calendar.css +37 -112
- package/build/styles/main.css +43 -123
- package/build/types/Calendar/Calendar.d.ts +3 -16
- package/build/types/Calendar/Calendar.d.ts.map +1 -1
- package/build/types/Calendar/Calendar.messages.d.ts +0 -20
- package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
- package/build/types/Calendar/DateHeader/DateHeader.d.ts +0 -2
- package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +1 -7
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +0 -6
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +0 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +1 -2
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +1 -2
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +0 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
- package/build/types/Calendar/index.d.ts +0 -1
- package/build/types/Calendar/index.d.ts.map +1 -1
- package/build/types/Calendar/{TableLink → tableLink}/TableLink.d.ts +1 -5
- package/build/types/Calendar/tableLink/TableLink.d.ts.map +1 -0
- package/build/types/Calendar/tableLink/index.d.ts.map +1 -0
- package/build/types/DateLookup/DateLookup.d.ts +5 -24
- package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/DateLookup/index.d.ts +0 -1
- package/build/types/DateLookup/index.d.ts.map +1 -1
- package/build/types/index.d.ts +2 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -8
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Calendar/Calendar.css +37 -112
- package/src/Calendar/Calendar.less +35 -5
- package/src/Calendar/Calendar.messages.ts +0 -21
- package/src/Calendar/Calendar.test.tsx +32 -342
- package/src/Calendar/Calendar.tsx +19 -169
- package/src/Calendar/DateHeader/DateHeader.tsx +0 -6
- package/src/Calendar/DayCalendar/DayCalendar.tsx +1 -39
- package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +27 -67
- package/src/Calendar/MonthCalendar/MonthCalendar.tsx +0 -8
- package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/YearCalendar.tsx +0 -9
- package/src/Calendar/_stories/Calendar.story.tsx +4 -144
- package/src/Calendar/index.ts +0 -7
- package/src/Calendar/tableLink/TableLink.tsx +77 -0
- package/src/DateLookup/DateLookup.test.tsx +37 -34
- package/src/DateLookup/DateLookup.tsx +13 -37
- package/src/DateLookup/_stories/DateLookup.story.tsx +2 -126
- package/src/DateLookup/index.ts +0 -6
- package/src/i18n/en.json +0 -4
- package/src/index.ts +2 -3
- package/src/main.css +43 -123
- package/build/Calendar/Calendar.constants.js +0 -10
- package/build/Calendar/Calendar.constants.js.map +0 -1
- package/build/Calendar/Calendar.constants.mjs +0 -8
- package/build/Calendar/Calendar.constants.mjs.map +0 -1
- package/build/Calendar/TableLink/TableLink.js +0 -95
- package/build/Calendar/TableLink/TableLink.js.map +0 -1
- package/build/Calendar/TableLink/TableLink.mjs +0 -91
- package/build/Calendar/TableLink/TableLink.mjs.map +0 -1
- package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js +0 -24
- package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js.map +0 -1
- package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs +0 -22
- package/build/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs.map +0 -1
- package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +0 -33
- package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +0 -1
- package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +0 -31
- package/build/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +0 -1
- package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js +0 -40
- package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.js.map +0 -1
- package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs +0 -38
- package/build/Calendar/_helpers/isDateDisabled/isDateDisabled.mjs.map +0 -1
- package/build/styles/Calendar/TableLink/TableLink.css +0 -115
- package/build/types/Calendar/Calendar.constants.d.ts +0 -2
- package/build/types/Calendar/Calendar.constants.d.ts.map +0 -1
- package/build/types/Calendar/Calendar.types.d.ts +0 -32
- package/build/types/Calendar/Calendar.types.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/TableLink.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/index.d.ts.map +0 -1
- package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts +0 -8
- package/build/types/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.d.ts.map +0 -1
- package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +0 -3
- package/build/types/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +0 -1
- package/build/types/Calendar/_helpers/index.d.ts +0 -4
- package/build/types/Calendar/_helpers/index.d.ts.map +0 -1
- package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts +0 -3
- package/build/types/Calendar/_helpers/isDateDisabled/isDateDisabled.d.ts.map +0 -1
- package/src/Calendar/Calendar.constants.ts +0 -5
- package/src/Calendar/Calendar.disabledDates.test.tsx +0 -610
- package/src/Calendar/Calendar.types.ts +0 -35
- package/src/Calendar/TableLink/TableLink.css +0 -115
- package/src/Calendar/TableLink/TableLink.less +0 -68
- package/src/Calendar/TableLink/TableLink.tsx +0 -117
- package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.test.ts +0 -90
- package/src/Calendar/_helpers/clampToDayViewBoundary/clampToDayViewBoundary.ts +0 -25
- package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +0 -98
- package/src/Calendar/_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +0 -45
- package/src/Calendar/_helpers/index.ts +0 -3
- package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.test.ts +0 -169
- package/src/Calendar/_helpers/isDateDisabled/isDateDisabled.ts +0 -59
- package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +0 -118
- package/src/Calendar/_stories/Calendar.test.story.tsx +0 -114
- package/src/DateLookup/DateLookup.disabledDates.test.tsx +0 -312
- package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +0 -108
- /package/build/types/Calendar/{TableLink → tableLink}/index.d.ts +0 -0
- /package/src/Calendar/{TableLink → tableLink}/index.ts +0 -0
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var reactIntl = require('react-intl');
|
|
7
|
-
var formatting = require('@transferwise/formatting');
|
|
8
6
|
require('../common/theme.js');
|
|
9
7
|
require('../common/direction.js');
|
|
10
8
|
require('@transferwise/neptune-tokens');
|
|
@@ -24,66 +22,37 @@ require('../common/PropsValues/variant.js');
|
|
|
24
22
|
require('../common/PropsValues/scroll.js');
|
|
25
23
|
require('../common/PropsValues/markdownNodeType.js');
|
|
26
24
|
require('../common/fileType.js');
|
|
25
|
+
require('@transferwise/formatting');
|
|
27
26
|
require('@transferwise/icons');
|
|
28
27
|
require('clsx');
|
|
28
|
+
require('react-intl');
|
|
29
29
|
require('../common/CloseButton/CloseButton.messages.js');
|
|
30
30
|
var jsxRuntime = require('react/jsx-runtime');
|
|
31
31
|
var moveToWithinRange = require('../common/DateUtils/moveToWithinRange/moveToWithinRange.js');
|
|
32
32
|
var isWithinRange = require('../common/DateUtils/isWithinRange/isWithinRange.js');
|
|
33
33
|
var getDateView = require('../common/DateUtils/getDateView/getDateView.js');
|
|
34
|
-
var clampToDayViewBoundary = require('./_helpers/clampToDayViewBoundary/clampToDayViewBoundary.js');
|
|
35
|
-
var isDateDisabled = require('./_helpers/isDateDisabled/isDateDisabled.js');
|
|
36
|
-
var hasDisabledDatesInMonth = require('./_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js');
|
|
37
|
-
var Calendar_constants = require('./Calendar.constants.js');
|
|
38
|
-
var InlinePrompt = require('../Prompt/InlinePrompt/InlinePrompt.js');
|
|
39
34
|
var DayCalendar = require('./DayCalendar/DayCalendar.js');
|
|
40
35
|
var GetStartOfDay = require('./GetStartOfDay/GetStartOfDay.js');
|
|
41
|
-
var Calendar_messages = require('./Calendar.messages.js');
|
|
42
36
|
var MonthCalendar = require('./MonthCalendar/MonthCalendar.js');
|
|
43
37
|
var YearCalendar = require('./YearCalendar/YearCalendar.js');
|
|
44
38
|
|
|
45
|
-
/**
|
|
46
|
-
* Inline calendar for selecting a single date. Powers [DateLookup](?path=/docs/forms-datelookup--docs).
|
|
47
|
-
*/
|
|
48
39
|
const Calendar = ({
|
|
49
40
|
value,
|
|
50
41
|
min: minProp = null,
|
|
51
42
|
max: maxProp = null,
|
|
52
43
|
monthFormat: monthFormat$1 = monthFormat.MonthFormat.LONG,
|
|
53
44
|
placeholder,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
onChange
|
|
45
|
+
onChange,
|
|
46
|
+
onSelect
|
|
57
47
|
}) => {
|
|
58
|
-
const intl = reactIntl.useIntl();
|
|
59
48
|
const selectedDate = GetStartOfDay.getStartOfDay(value);
|
|
60
49
|
const min = GetStartOfDay.getStartOfDay(minProp);
|
|
61
50
|
const max = GetStartOfDay.getStartOfDay(maxProp);
|
|
62
|
-
const disabledReasonId = React.useId();
|
|
63
|
-
const disabledRulesRef = React.useRef(disabledRules);
|
|
64
|
-
React.useEffect(() => {
|
|
65
|
-
disabledRulesRef.current = disabledRules;
|
|
66
|
-
});
|
|
67
|
-
const [hasInteracted, setHasInteracted] = React.useState(false);
|
|
68
|
-
const [focusedDate, setFocusedDate] = React.useState(selectedDate);
|
|
69
|
-
React.useEffect(() => {
|
|
70
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
71
|
-
setFocusedDate(selectedDate);
|
|
72
|
-
}, [selectedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
73
|
-
const checkIsEnabled = date => {
|
|
74
|
-
if (!date) return true;
|
|
75
|
-
return isWithinRange.isWithinRange(date, min, max) && !isDateDisabled.isDateDisabled(date, disabledRulesRef.current);
|
|
76
|
-
};
|
|
77
|
-
const focusedDateDisabled = focusedDate ? !isWithinRange.isWithinRange(focusedDate, min, max) || isDateDisabled.isDateDisabled(focusedDate, disabledRules) : false;
|
|
78
51
|
React.useEffect(() => {
|
|
79
52
|
if (selectedDate && !isWithinRange.isWithinRange(selectedDate, min, max)) {
|
|
80
|
-
|
|
81
|
-
setFocusedDate(clamped); // eslint-disable-line react-hooks/set-state-in-effect
|
|
82
|
-
onDateFocus?.(clamped, {
|
|
83
|
-
isEnabled: checkIsEnabled(clamped)
|
|
84
|
-
});
|
|
53
|
+
onChange(moveToWithinRange.moveToWithinRange(selectedDate, min, max));
|
|
85
54
|
}
|
|
86
|
-
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(),
|
|
55
|
+
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onChange]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
87
56
|
const dateView = getDateView.returnDateView(selectedDate, min, max);
|
|
88
57
|
const [viewMonth, setViewMonth] = React.useState(dateView.getMonth());
|
|
89
58
|
const [viewYear, setViewYear] = React.useState(dateView.getFullYear());
|
|
@@ -94,13 +63,6 @@ const Calendar = ({
|
|
|
94
63
|
setViewMonth(view.getMonth());
|
|
95
64
|
setViewYear(view.getFullYear());
|
|
96
65
|
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
97
|
-
React.useEffect(() => {
|
|
98
|
-
if (focusedDate) {
|
|
99
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
100
|
-
setViewMonth(focusedDate.getMonth());
|
|
101
|
-
setViewYear(focusedDate.getFullYear());
|
|
102
|
-
}
|
|
103
|
-
}, [focusedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
104
66
|
const handleViewDateUpdate = React.useCallback(
|
|
105
67
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization
|
|
106
68
|
({
|
|
@@ -109,56 +71,29 @@ const Calendar = ({
|
|
|
109
71
|
}) => {
|
|
110
72
|
if (month !== undefined) setViewMonth(month);
|
|
111
73
|
if (year !== undefined) setViewYear(year);
|
|
112
|
-
setHasInteracted(false);
|
|
113
74
|
}, []);
|
|
114
75
|
const switchToDays = React.useCallback(() => setMode('day'), []);
|
|
115
76
|
const switchToMonths = React.useCallback(() => setMode('month'), []);
|
|
116
77
|
const switchToYears = React.useCallback(() => setMode('year'), []);
|
|
117
78
|
const handleSelectedDateUpdate = React.useCallback(date => {
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
onDateFocus?.(date, {
|
|
122
|
-
isEnabled
|
|
123
|
-
});
|
|
124
|
-
if (isEnabled && onChange) {
|
|
79
|
+
if (onSelect) {
|
|
80
|
+
onSelect(date);
|
|
81
|
+
} else {
|
|
125
82
|
onChange(date);
|
|
126
83
|
}
|
|
127
|
-
}, [
|
|
84
|
+
}, [onChange, onSelect]);
|
|
128
85
|
const adjustDate = React.useCallback((daysToAdd, monthsToAdd, yearsToAdd) => {
|
|
129
|
-
const base = focusedDate ?? selectedDate;
|
|
130
86
|
let date;
|
|
131
|
-
if (
|
|
132
|
-
date = new Date(mode === 'year' ?
|
|
87
|
+
if (selectedDate) {
|
|
88
|
+
date = new Date(mode === 'year' ? selectedDate.getFullYear() + yearsToAdd : selectedDate.getFullYear(), mode === 'month' ? selectedDate.getMonth() + monthsToAdd : selectedDate.getMonth(), mode === 'day' ? selectedDate.getDate() + daysToAdd : selectedDate.getDate());
|
|
133
89
|
} else {
|
|
134
90
|
date = GetStartOfDay.getStartOfDay(new Date());
|
|
135
91
|
}
|
|
136
|
-
date &&=
|
|
137
|
-
if (date?.getTime() !==
|
|
138
|
-
|
|
139
|
-
setFocusedDate(date);
|
|
140
|
-
if (date) {
|
|
141
|
-
setViewMonth(date.getMonth());
|
|
142
|
-
setViewYear(date.getFullYear());
|
|
143
|
-
}
|
|
144
|
-
if (monthChanged) {
|
|
145
|
-
setHasInteracted(false);
|
|
146
|
-
} else if (!hasInteracted) {
|
|
147
|
-
setHasInteracted(true);
|
|
148
|
-
}
|
|
149
|
-
onDateFocus?.(date, {
|
|
150
|
-
isEnabled: checkIsEnabled(date)
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}, [focusedDate, selectedDate, min, max, mode, onDateFocus]);
|
|
154
|
-
const handleDayFocus = React.useCallback(date => {
|
|
155
|
-
if (date.getTime() !== focusedDate?.getTime()) {
|
|
156
|
-
setFocusedDate(date);
|
|
157
|
-
onDateFocus?.(date, {
|
|
158
|
-
isEnabled: checkIsEnabled(date)
|
|
159
|
-
});
|
|
92
|
+
date &&= moveToWithinRange.moveToWithinRange(date, min, max);
|
|
93
|
+
if (date?.getTime() !== selectedDate?.getTime()) {
|
|
94
|
+
onChange(date);
|
|
160
95
|
}
|
|
161
|
-
}, [
|
|
96
|
+
}, [selectedDate, min, max, mode, onChange]);
|
|
162
97
|
const handleKeyDown = React.useCallback(event => {
|
|
163
98
|
switch (event.key) {
|
|
164
99
|
case 'ArrowLeft':
|
|
@@ -177,34 +112,8 @@ const Calendar = ({
|
|
|
177
112
|
adjustDate(7, 4, 4);
|
|
178
113
|
event.preventDefault();
|
|
179
114
|
break;
|
|
180
|
-
case 'Enter':
|
|
181
|
-
case ' ':
|
|
182
|
-
if (mode === 'day' && focusedDate && event.target.hasAttribute('data-calendar-cell')) {
|
|
183
|
-
handleSelectedDateUpdate(focusedDate);
|
|
184
|
-
event.preventDefault();
|
|
185
|
-
}
|
|
186
|
-
break;
|
|
187
115
|
}
|
|
188
|
-
}, [adjustDate
|
|
189
|
-
const focusedDateOutOfRange = focusedDate ? !isWithinRange.isWithinRange(focusedDate, min, max) : false;
|
|
190
|
-
const formatDateForPrompt = date => formatting.formatDate(date, intl.locale, Calendar_constants.LONG_DAY_FORMAT);
|
|
191
|
-
const outOfRangePromptText = min && max ? intl.formatMessage(Calendar_messages.default.outOfRangeBetween, {
|
|
192
|
-
min: formatDateForPrompt(min),
|
|
193
|
-
max: formatDateForPrompt(max)
|
|
194
|
-
}) : min ? intl.formatMessage(Calendar_messages.default.outOfRangeAfter, {
|
|
195
|
-
min: formatDateForPrompt(min)
|
|
196
|
-
}) : max ? intl.formatMessage(Calendar_messages.default.outOfRangeBefore, {
|
|
197
|
-
max: formatDateForPrompt(max)
|
|
198
|
-
}) : '';
|
|
199
|
-
const hasOutOfRangeDates = mode === 'day' && !!(min || max);
|
|
200
|
-
const showRulesPrompt = mode === 'day' && !!disabledRules && hasDisabledDatesInMonth.hasDisabledDatesInMonth(viewMonth, viewYear, disabledRules, min, max);
|
|
201
|
-
const showOutOfRangePrompt = mode === 'day' && focusedDateOutOfRange;
|
|
202
|
-
const showPrompt = hasOutOfRangeDates || showRulesPrompt;
|
|
203
|
-
const promptText = showOutOfRangePrompt ? outOfRangePromptText : disabledRules?.reason ?? outOfRangePromptText;
|
|
204
|
-
const promptSentiment = showOutOfRangePrompt || focusedDateDisabled ? 'negative' : 'neutral';
|
|
205
|
-
// Visible when there's an actionable message; sr-only when only hasOutOfRangeDates is true
|
|
206
|
-
// (prompt exists for aria-describedby but no visual cue needed until an out-of-range date is focused)
|
|
207
|
-
const promptClassName = showOutOfRangePrompt || showRulesPrompt ? 'm-t-1' : 'sr-only';
|
|
116
|
+
}, [adjustDate]);
|
|
208
117
|
return (
|
|
209
118
|
/*#__PURE__*/
|
|
210
119
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -212,22 +121,16 @@ const Calendar = ({
|
|
|
212
121
|
onKeyDown: handleKeyDown,
|
|
213
122
|
children: [mode === 'day' && /*#__PURE__*/jsxRuntime.jsx(DayCalendar.default, {
|
|
214
123
|
selectedDate: selectedDate,
|
|
215
|
-
focusedDate: focusedDate,
|
|
216
124
|
min: min,
|
|
217
125
|
max: max,
|
|
218
126
|
viewMonth: viewMonth,
|
|
219
127
|
viewYear: viewYear,
|
|
220
128
|
monthFormat: monthFormat$1,
|
|
221
|
-
disabledRules: disabledRules,
|
|
222
|
-
disabledReasonId: showPrompt ? disabledReasonId : undefined,
|
|
223
|
-
announceReasonOnFocus: !hasInteracted,
|
|
224
129
|
onSelect: handleSelectedDateUpdate,
|
|
225
|
-
onDayFocus: handleDayFocus,
|
|
226
130
|
onLabelClick: switchToYears,
|
|
227
131
|
onViewDateUpdate: handleViewDateUpdate
|
|
228
132
|
}), mode === 'month' && /*#__PURE__*/jsxRuntime.jsx(MonthCalendar.default, {
|
|
229
133
|
selectedDate: selectedDate,
|
|
230
|
-
focusedDate: focusedDate,
|
|
231
134
|
min: min,
|
|
232
135
|
max: max,
|
|
233
136
|
viewYear: viewYear,
|
|
@@ -239,7 +142,6 @@ const Calendar = ({
|
|
|
239
142
|
onViewDateUpdate: handleViewDateUpdate
|
|
240
143
|
}), mode === 'year' && /*#__PURE__*/jsxRuntime.jsx(YearCalendar.default, {
|
|
241
144
|
selectedDate: selectedDate,
|
|
242
|
-
focusedDate: focusedDate,
|
|
243
145
|
min: min,
|
|
244
146
|
max: max,
|
|
245
147
|
viewYear: viewYear,
|
|
@@ -248,12 +150,6 @@ const Calendar = ({
|
|
|
248
150
|
}),
|
|
249
151
|
onSelect: switchToMonths,
|
|
250
152
|
onViewDateUpdate: handleViewDateUpdate
|
|
251
|
-
}), showPrompt && /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
|
|
252
|
-
sentiment: promptSentiment,
|
|
253
|
-
width: "full",
|
|
254
|
-
id: disabledReasonId,
|
|
255
|
-
className: promptClassName,
|
|
256
|
-
children: promptText
|
|
257
153
|
})]
|
|
258
154
|
})
|
|
259
155
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.js","sources":["../../src/Calendar/Calendar.tsx"],"sourcesContent":["import { useState, useCallback, useEffect, useId, useRef, KeyboardEvent } from 'react';\nimport { useIntl } from 'react-intl';\nimport { formatDate } from '@transferwise/formatting';\n\nimport { MonthFormat } from '../common';\nimport { isWithinRange, moveToWithinRange, returnDateView } from '../common/DateUtils';\nimport { clampToDayViewBoundary, isDateDisabled, hasDisabledDatesInMonth } from './_helpers';\nimport { LONG_DAY_FORMAT } from './Calendar.constants';\nimport { InlinePrompt } from '../Prompt/InlinePrompt';\nimport type { DateChangeMeta, DisabledRules } from './Calendar.types';\nimport DayCalendar from './DayCalendar';\nimport { getStartOfDay } from './GetStartOfDay';\nimport messages from './Calendar.messages';\nimport MonthCalendar from './MonthCalendar';\nimport YearCalendar from './YearCalendar';\n\nexport interface CalendarProps {\n /** The currently selected date, or `null` for no selection. */\n value: Date | null;\n /** Earliest selectable date (inclusive). Dates before this are interactive but not selectable, and show a boundary prompt. */\n min?: Date | null;\n /** Latest selectable date (inclusive). Dates after this are interactive but not selectable, and show a boundary prompt. */\n max?: Date | null;\n /** Month name format in the header. Defaults to `'long'` (e.g. \"January\"). */\n monthFormat?: `${MonthFormat}`;\n /** Placeholder text shown in the month/year cells when no date is selected. */\n placeholder?: string;\n /** Rules for disabling specific weekdays, individual dates, or date ranges. The required `reason` is shown in an inline prompt and linked to disabled cells via `aria-describedby` for screen reader accessibility. */\n disabledRules?: DisabledRules;\n /** Called whenever the focused date changes — including disabled and out-of-range dates. `meta.isEnabled` is `false` when the date is not selectable. */\n onDateFocus?: (date: Date | null, meta: DateChangeMeta) => void;\n /** Called when a date is confirmed (click or Enter). Only fires for enabled dates. */\n onChange?: (date: Date | null) => void;\n}\n\n/**\n * Temporary toggle — set `true` to restore strict min/max keyboard clamping.\n * @see https://transferwise.atlassian.net/browse/DS-8518\n */\nconst STRICT_KEYBOARD_CLAMPING = false;\n\n/**\n * Inline calendar for selecting a single date. Powers [DateLookup](?path=/docs/forms-datelookup--docs).\n */\nconst Calendar = ({\n value,\n min: minProp = null,\n max: maxProp = null,\n monthFormat = MonthFormat.LONG,\n placeholder,\n disabledRules,\n onDateFocus,\n onChange,\n}: CalendarProps) => {\n const intl = useIntl();\n const selectedDate = getStartOfDay(value);\n const min = getStartOfDay(minProp);\n const max = getStartOfDay(maxProp);\n const disabledReasonId = useId();\n const disabledRulesRef = useRef(disabledRules);\n useEffect(() => {\n disabledRulesRef.current = disabledRules;\n });\n\n const [hasInteracted, setHasInteracted] = useState(false);\n const [focusedDate, setFocusedDate] = useState<Date | null>(selectedDate);\n\n useEffect(() => {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocusedDate(selectedDate);\n }, [selectedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const checkIsEnabled = (date: Date | null) => {\n if (!date) return true;\n return isWithinRange(date, min, max) && !isDateDisabled(date, disabledRulesRef.current);\n };\n\n const focusedDateDisabled = focusedDate\n ? !isWithinRange(focusedDate, min, max) || isDateDisabled(focusedDate, disabledRules)\n : false;\n\n useEffect(() => {\n if (selectedDate && !isWithinRange(selectedDate, min, max)) {\n const clamped = moveToWithinRange(selectedDate, min, max);\n setFocusedDate(clamped); // eslint-disable-line react-hooks/set-state-in-effect\n onDateFocus?.(clamped, { isEnabled: checkIsEnabled(clamped) });\n }\n }, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onDateFocus]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const dateView = returnDateView(selectedDate, min, max);\n const [viewMonth, setViewMonth] = useState(dateView.getMonth());\n const [viewYear, setViewYear] = useState(dateView.getFullYear());\n const [mode, setMode] = useState<'day' | 'month' | 'year'>('day');\n\n useEffect(() => {\n const view = returnDateView(selectedDate, min, max);\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setViewMonth(view.getMonth());\n\n setViewYear(view.getFullYear());\n }, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps\n\n useEffect(() => {\n if (focusedDate) {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setViewMonth(focusedDate.getMonth());\n setViewYear(focusedDate.getFullYear());\n }\n }, [focusedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleViewDateUpdate = useCallback(\n // eslint-disable-next-line react-hooks/preserve-manual-memoization\n ({ month, year }: { month?: number; year?: number }) => {\n if (month !== undefined) setViewMonth(month);\n if (year !== undefined) setViewYear(year);\n setHasInteracted(false);\n },\n [],\n );\n\n const switchToDays = useCallback(() => setMode('day'), []);\n const switchToMonths = useCallback(() => setMode('month'), []);\n const switchToYears = useCallback(() => setMode('year'), []);\n\n const handleSelectedDateUpdate = useCallback(\n (date: Date) => {\n if (!hasInteracted) setHasInteracted(true);\n const isEnabled = checkIsEnabled(date);\n setFocusedDate(date);\n onDateFocus?.(date, { isEnabled });\n if (isEnabled && onChange) {\n onChange(date);\n }\n },\n [onDateFocus, onChange], // eslint-disable-line react-hooks/exhaustive-deps\n );\n\n const adjustDate = useCallback(\n (daysToAdd: number, monthsToAdd: number, yearsToAdd: number) => {\n const base = focusedDate ?? selectedDate;\n let date: Date | null;\n if (base) {\n date = new Date(\n mode === 'year' ? base.getFullYear() + yearsToAdd : base.getFullYear(),\n mode === 'month' ? base.getMonth() + monthsToAdd : base.getMonth(),\n mode === 'day' ? base.getDate() + daysToAdd : base.getDate(),\n );\n } else {\n date = getStartOfDay(new Date());\n }\n date &&=\n STRICT_KEYBOARD_CLAMPING || mode !== 'day'\n ? moveToWithinRange(date, min, max)\n : clampToDayViewBoundary(date, min, max);\n if (date?.getTime() !== focusedDate?.getTime()) {\n const monthChanged = date\n ? date.getMonth() !== focusedDate?.getMonth() ||\n date.getFullYear() !== focusedDate?.getFullYear()\n : false;\n setFocusedDate(date);\n if (date) {\n setViewMonth(date.getMonth());\n setViewYear(date.getFullYear());\n }\n if (monthChanged) {\n setHasInteracted(false);\n } else if (!hasInteracted) {\n setHasInteracted(true);\n }\n onDateFocus?.(date, { isEnabled: checkIsEnabled(date) });\n }\n },\n [focusedDate, selectedDate, min, max, mode, onDateFocus], // eslint-disable-line react-hooks/exhaustive-deps\n );\n\n const handleDayFocus = useCallback(\n (date: Date) => {\n if (date.getTime() !== focusedDate?.getTime()) {\n setFocusedDate(date);\n onDateFocus?.(date, { isEnabled: checkIsEnabled(date) });\n }\n },\n [focusedDate, onDateFocus], // eslint-disable-line react-hooks/exhaustive-deps\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n switch (event.key) {\n case 'ArrowLeft':\n adjustDate(-1, -1, -1);\n event.preventDefault();\n break;\n case 'ArrowUp':\n adjustDate(-7, -4, -4);\n event.preventDefault();\n break;\n case 'ArrowRight':\n adjustDate(1, 1, 1);\n event.preventDefault();\n break;\n case 'ArrowDown':\n adjustDate(7, 4, 4);\n event.preventDefault();\n break;\n case 'Enter':\n case ' ':\n if (\n mode === 'day' &&\n focusedDate &&\n (event.target as HTMLElement).hasAttribute('data-calendar-cell')\n ) {\n handleSelectedDateUpdate(focusedDate);\n event.preventDefault();\n }\n break;\n default:\n break;\n }\n },\n [adjustDate, focusedDate, mode, handleSelectedDateUpdate],\n );\n\n const focusedDateOutOfRange = focusedDate ? !isWithinRange(focusedDate, min, max) : false;\n\n const formatDateForPrompt = (date: Date) => formatDate(date, intl.locale, LONG_DAY_FORMAT);\n\n const outOfRangePromptText =\n min && max\n ? intl.formatMessage(messages.outOfRangeBetween, {\n min: formatDateForPrompt(min),\n max: formatDateForPrompt(max),\n })\n : min\n ? intl.formatMessage(messages.outOfRangeAfter, { min: formatDateForPrompt(min) })\n : max\n ? intl.formatMessage(messages.outOfRangeBefore, { max: formatDateForPrompt(max) })\n : '';\n\n const hasOutOfRangeDates = mode === 'day' && !!(min || max);\n const showRulesPrompt =\n mode === 'day' &&\n !!disabledRules &&\n hasDisabledDatesInMonth(viewMonth, viewYear, disabledRules, min, max);\n const showOutOfRangePrompt = mode === 'day' && focusedDateOutOfRange;\n const showPrompt = hasOutOfRangeDates || showRulesPrompt;\n\n const promptText = showOutOfRangePrompt\n ? outOfRangePromptText\n : (disabledRules?.reason ?? outOfRangePromptText);\n const promptSentiment = showOutOfRangePrompt || focusedDateDisabled ? 'negative' : 'neutral';\n // Visible when there's an actionable message; sr-only when only hasOutOfRangeDates is true\n // (prompt exists for aria-describedby but no visual cue needed until an out-of-range date is focused)\n const promptClassName = showOutOfRangePrompt || showRulesPrompt ? 'm-t-1' : 'sr-only';\n\n return (\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div onKeyDown={handleKeyDown}>\n {mode === 'day' && (\n <DayCalendar\n selectedDate={selectedDate}\n focusedDate={focusedDate}\n min={min}\n max={max}\n viewMonth={viewMonth}\n viewYear={viewYear}\n monthFormat={monthFormat}\n disabledRules={disabledRules}\n disabledReasonId={showPrompt ? disabledReasonId : undefined}\n announceReasonOnFocus={!hasInteracted}\n onSelect={handleSelectedDateUpdate}\n onDayFocus={handleDayFocus}\n onLabelClick={switchToYears}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n {mode === 'month' && (\n <MonthCalendar\n selectedDate={selectedDate}\n focusedDate={focusedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n {...(placeholder != null && { placeholder })}\n onSelect={switchToDays}\n onLabelClick={switchToYears}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n {mode === 'year' && (\n <YearCalendar\n selectedDate={selectedDate}\n focusedDate={focusedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n {...(placeholder != null && { placeholder })}\n onSelect={switchToMonths}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n {showPrompt && (\n <InlinePrompt\n sentiment={promptSentiment}\n width=\"full\"\n id={disabledReasonId}\n className={promptClassName}\n >\n {promptText}\n </InlinePrompt>\n )}\n </div>\n );\n};\n\nexport default Calendar;\n"],"names":["Calendar","value","min","minProp","max","maxProp","monthFormat","MonthFormat","LONG","placeholder","disabledRules","onDateFocus","onChange","intl","useIntl","selectedDate","getStartOfDay","disabledReasonId","useId","disabledRulesRef","useRef","useEffect","current","hasInteracted","setHasInteracted","useState","focusedDate","setFocusedDate","getTime","checkIsEnabled","date","isWithinRange","isDateDisabled","focusedDateDisabled","clamped","moveToWithinRange","isEnabled","dateView","returnDateView","viewMonth","setViewMonth","getMonth","viewYear","setViewYear","getFullYear","mode","setMode","view","handleViewDateUpdate","useCallback","month","year","undefined","switchToDays","switchToMonths","switchToYears","handleSelectedDateUpdate","adjustDate","daysToAdd","monthsToAdd","yearsToAdd","base","Date","getDate","clampToDayViewBoundary","monthChanged","handleDayFocus","handleKeyDown","event","key","preventDefault","target","hasAttribute","focusedDateOutOfRange","formatDateForPrompt","formatDate","locale","LONG_DAY_FORMAT","outOfRangePromptText","formatMessage","messages","outOfRangeBetween","outOfRangeAfter","outOfRangeBefore","hasOutOfRangeDates","showRulesPrompt","hasDisabledDatesInMonth","showOutOfRangePrompt","showPrompt","promptText","reason","promptSentiment","promptClassName","_jsxs","onKeyDown","children","_jsx","DayCalendar","announceReasonOnFocus","onSelect","onDayFocus","onLabelClick","onViewDateUpdate","MonthCalendar","YearCalendar","InlinePrompt","sentiment","width","id","className"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA;;AAEG;AACH,MAAMA,QAAQ,GAAGA,CAAC;EAChBC,KAAK;EACLC,GAAG,EAAEC,OAAO,GAAG,IAAI;EACnBC,GAAG,EAAEC,OAAO,GAAG,IAAI;eACnBC,aAAW,GAAGC,uBAAW,CAACC,IAAI;EAC9BC,WAAW;EACXC,aAAa;EACbC,WAAW;AACXC,EAAAA;AAAQ,CACM,KAAI;AAClB,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;AACtB,EAAA,MAAMC,YAAY,GAAGC,2BAAa,CAACf,KAAK,CAAC;AACzC,EAAA,MAAMC,GAAG,GAAGc,2BAAa,CAACb,OAAO,CAAC;AAClC,EAAA,MAAMC,GAAG,GAAGY,2BAAa,CAACX,OAAO,CA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AAA,GAAG,EAAEA,GAAI;AACTsC,QAAAA,QAAQ,EAAEA,QAAS;QAAA,IACdjC,WAAW,IAAI,IAAI,IAAI;AAAEA,UAAAA;SAAa,CAAA;AAC3C0F,QAAAA,QAAQ,EAAE9C,YAAa;AACvBgD,QAAAA,YAAY,EAAE9C,aAAc;AAC5B+C,QAAAA,gBAAgB,EAAEtD;OAAqB,CAE1C,EACAH,IAAI,KAAK,MAAM,iBACdmD,cAAA,CAACQ,oBAAY,EAAA;AACXzF,QAAAA,YAAY,EAAEA,YAAa;AAC3BW,QAAAA,WAAW,EAAEA,WAAY;AACzBxB,QAAAA,GAAG,EAAEA,GAAI;AACTE,QAAAA,GAAG,EAAEA,GAAI;AACTsC,QAAAA,QAAQ,EAAEA,QAAS;QAAA,IACdjC,WAAW,IAAI,IAAI,IAAI;AAAEA,UAAAA;SAAa,CAAA;AAC3C0F,QAAAA,QAAQ,EAAE7C,cAAe;AACzBgD,QAAAA,gBAAgB,EAAEtD;AAAqB,OAAA,CAE1C,EACAwC,UAAU,iBACTQ,cAAA,CAACS,yBAAY,EAAA;AACXC,QAAAA,SAAS,EAAEf,eAAgB;AAC3BgB,QAAAA,KAAK,EAAC,MAAM;AACZC,QAAAA,EAAE,EAAE3F,gBAAiB;AACrB4F,QAAAA,SAAS,EAAEjB,eAAgB;AAAAG,QAAAA,QAAA,EAE1BN;AAAU,OACC,CACf;KACE;AAAC;AAEV;;;;"}
|
|
1
|
+
{"version":3,"file":"Calendar.js","sources":["../../src/Calendar/Calendar.tsx"],"sourcesContent":["import { useState, useCallback, useEffect, KeyboardEvent } from 'react';\n\nimport { MonthFormat } from '../common';\nimport { isWithinRange, moveToWithinRange, returnDateView } from '../common/DateUtils';\nimport DayCalendar from './DayCalendar';\nimport { getStartOfDay } from './GetStartOfDay';\nimport MonthCalendar from './MonthCalendar';\nimport YearCalendar from './YearCalendar';\n\nexport interface CalendarProps {\n value: Date | null;\n min?: Date | null;\n max?: Date | null;\n monthFormat?: `${MonthFormat}`;\n placeholder?: string;\n onChange: (date: Date | null) => void;\n onSelect?: (date: Date) => void;\n}\n\nconst Calendar = ({\n value,\n min: minProp = null,\n max: maxProp = null,\n monthFormat = MonthFormat.LONG,\n placeholder,\n onChange,\n onSelect,\n}: CalendarProps) => {\n const selectedDate = getStartOfDay(value);\n const min = getStartOfDay(minProp);\n const max = getStartOfDay(maxProp);\n\n useEffect(() => {\n if (selectedDate && !isWithinRange(selectedDate, min, max)) {\n onChange(moveToWithinRange(selectedDate, min, max));\n }\n }, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onChange]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const dateView = returnDateView(selectedDate, min, max);\n const [viewMonth, setViewMonth] = useState(dateView.getMonth());\n const [viewYear, setViewYear] = useState(dateView.getFullYear());\n const [mode, setMode] = useState<'day' | 'month' | 'year'>('day');\n\n useEffect(() => {\n const view = returnDateView(selectedDate, min, max);\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setViewMonth(view.getMonth());\n\n setViewYear(view.getFullYear());\n }, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps\n\n const handleViewDateUpdate = useCallback(\n // eslint-disable-next-line react-hooks/preserve-manual-memoization\n ({ month, year }: { month?: number; year?: number }) => {\n if (month !== undefined) setViewMonth(month);\n if (year !== undefined) setViewYear(year);\n },\n [],\n );\n\n const switchToDays = useCallback(() => setMode('day'), []);\n const switchToMonths = useCallback(() => setMode('month'), []);\n const switchToYears = useCallback(() => setMode('year'), []);\n\n const handleSelectedDateUpdate = useCallback(\n (date: Date) => {\n if (onSelect) {\n onSelect(date);\n } else {\n onChange(date);\n }\n },\n [onChange, onSelect],\n );\n\n const adjustDate = useCallback(\n (daysToAdd: number, monthsToAdd: number, yearsToAdd: number) => {\n let date: Date | null;\n if (selectedDate) {\n date = new Date(\n mode === 'year' ? selectedDate.getFullYear() + yearsToAdd : selectedDate.getFullYear(),\n mode === 'month' ? selectedDate.getMonth() + monthsToAdd : selectedDate.getMonth(),\n mode === 'day' ? selectedDate.getDate() + daysToAdd : selectedDate.getDate(),\n );\n } else {\n date = getStartOfDay(new Date());\n }\n date &&= moveToWithinRange(date, min, max);\n if (date?.getTime() !== selectedDate?.getTime()) {\n onChange(date);\n }\n },\n [selectedDate, min, max, mode, onChange],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>) => {\n switch (event.key) {\n case 'ArrowLeft':\n adjustDate(-1, -1, -1);\n event.preventDefault();\n break;\n case 'ArrowUp':\n adjustDate(-7, -4, -4);\n event.preventDefault();\n break;\n case 'ArrowRight':\n adjustDate(1, 1, 1);\n event.preventDefault();\n break;\n case 'ArrowDown':\n adjustDate(7, 4, 4);\n event.preventDefault();\n break;\n default:\n break;\n }\n },\n [adjustDate],\n );\n\n return (\n // eslint-disable-next-line jsx-a11y/no-static-element-interactions\n <div onKeyDown={handleKeyDown}>\n {mode === 'day' && (\n <DayCalendar\n selectedDate={selectedDate}\n min={min}\n max={max}\n viewMonth={viewMonth}\n viewYear={viewYear}\n monthFormat={monthFormat}\n onSelect={handleSelectedDateUpdate}\n onLabelClick={switchToYears}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n {mode === 'month' && (\n <MonthCalendar\n selectedDate={selectedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n {...(placeholder != null && { placeholder })}\n onSelect={switchToDays}\n onLabelClick={switchToYears}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n {mode === 'year' && (\n <YearCalendar\n selectedDate={selectedDate}\n min={min}\n max={max}\n viewYear={viewYear}\n {...(placeholder != null && { placeholder })}\n onSelect={switchToMonths}\n onViewDateUpdate={handleViewDateUpdate}\n />\n )}\n </div>\n );\n};\n\nexport default Calendar;\n"],"names":["Calendar","value","min","minProp","max","maxProp","monthFormat","MonthFormat","LONG","placeholder","onChange","onSelect","selectedDate","getStartOfDay","useEffect","isWithinRange","moveToWithinRange","getTime","dateView","returnDateView","viewMonth","setViewMonth","useState","getMonth","viewYear","setViewYear","getFullYear","mode","setMode","view","handleViewDateUpdate","useCallback","month","year","undefined","switchToDays","switchToMonths","switchToYears","handleSelectedDateUpdate","date","adjustDate","daysToAdd","monthsToAdd","yearsToAdd","Date","getDate","handleKeyDown","event","key","preventDefault","_jsxs","onKeyDown","children","_jsx","DayCalendar","onLabelClick","onViewDateUpdate","MonthCalendar","YearCalendar"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAMA,QAAQ,GAAGA,CAAC;EAChBC,KAAK;EACLC,GAAG,EAAEC,OAAO,GAAG,IAAI;EACnBC,GAAG,EAAEC,OAAO,GAAG,IAAI;eACnBC,aAAW,GAAGC,uBAAW,CAACC,IAAI;EAC9BC,WAAW;EACXC,QAAQ;AACRC,EAAAA;AAAQ,CACM,KAAI;AAClB,EAAA,MAAMC,YAAY,GAAGC,2BAAa,CAACZ,KAAK,CAAC;AACzC,EAAA,MAAMC,GAAG,GAAGW,2BAAa,CAACV,OAAO,CAAC;AAClC,EAAA,MAAMC,GAAG,GAAGS,2BAAa,CAACR,OAAO,CAAC;AAElCS,EAAAA,eAAS,CAAC,MAAK;IACb,IAAIF,YAAY,IAAI,CAACG,2BAAa,CAACH,YAAY,EAAEV,GAAG,EAAEE,GAAG,CAAC,EAAE;MAC1DM,QAAQ,CAACM,mCAAiB,CAACJ,YAAY,EAAEV,GAAG,EAAEE,GAAG,CAAC,CAAC;AACrD,IAAA;EACF,CAAC,EAAE,CAACQ,YAAY,EAAEK,OAAO,EAAE,EAAEf,GAAG,EAAEe,OAAO,EAAE,EAAEb,GAAG,EAAEa,OAAO,EAAE,EAAEP,QAAQ,CAAC,CAAC,CAAC;EAExE,MAAMQ,QAAQ,GAAGC,0BAAc,CAACP,YAAY,EAAEV,GAAG,EAAEE,GAAG,CAAC;AACvD,EAAA,MAAM,CAACgB,SAAS,EAAEC,YAAY,CAAC,GAAGC,cAAQ,CAACJ,QAAQ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AAA,QAAQ,EAAEwB,YAAa;AACvBoB,QAAAA,YAAY,EAAElB,aAAc;AAC5BmB,QAAAA,gBAAgB,EAAE1B;OAAqB,CAE1C,EACAH,IAAI,KAAK,MAAM,iBACd0B,cAAA,CAACK,oBAAY,EAAA;AACX9C,QAAAA,YAAY,EAAEA,YAAa;AAC3BV,QAAAA,GAAG,EAAEA,GAAI;AACTE,QAAAA,GAAG,EAAEA,GAAI;AACToB,QAAAA,QAAQ,EAAEA,QAAS;QAAA,IACdf,WAAW,IAAI,IAAI,IAAI;AAAEA,UAAAA;SAAa,CAAA;AAC3CE,QAAAA,QAAQ,EAAEyB,cAAe;AACzBoB,QAAAA,gBAAgB,EAAE1B;AAAqB,OAAA,CAE1C;KACE;AAAC;AAEV;;;;"}
|
|
@@ -26,20 +26,8 @@ var messages = reactIntl.defineMessages({
|
|
|
26
26
|
selected: {
|
|
27
27
|
id: "neptune.DateLookup.selected"
|
|
28
28
|
},
|
|
29
|
-
notAvailable: {
|
|
30
|
-
id: "neptune.DateLookup.notAvailable"
|
|
31
|
-
},
|
|
32
29
|
goTo20YearView: {
|
|
33
30
|
id: "neptune.DateLookup.goTo20YearView"
|
|
34
|
-
},
|
|
35
|
-
outOfRangeBetween: {
|
|
36
|
-
id: "neptune.DateLookup.outOfRangeBetween"
|
|
37
|
-
},
|
|
38
|
-
outOfRangeAfter: {
|
|
39
|
-
id: "neptune.DateLookup.outOfRangeAfter"
|
|
40
|
-
},
|
|
41
|
-
outOfRangeBefore: {
|
|
42
|
-
id: "neptune.DateLookup.outOfRangeBefore"
|
|
43
31
|
}
|
|
44
32
|
});
|
|
45
33
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.messages.js","sources":["../../src/Calendar/Calendar.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n next: {\n id: 'neptune.DateLookup.next',\n defaultMessage: 'next',\n description: 'Description of next button',\n },\n previous: {\n id: 'neptune.DateLookup.previous',\n defaultMessage: 'previous',\n description: 'Description of previous button',\n },\n day: {\n id: 'neptune.DateLookup.day',\n defaultMessage: 'day',\n description: 'Description of next/previous/selected day button',\n },\n month: {\n id: 'neptune.DateLookup.month',\n defaultMessage: 'month',\n description: 'Description of next/previous/selected month button',\n },\n year: {\n id: 'neptune.DateLookup.year',\n defaultMessage: 'year',\n description: 'Description of next/previous/selected year button',\n },\n twentyYears: {\n id: 'neptune.DateLookup.twentyYears',\n defaultMessage: '20 years',\n description: 'Description of next/previous 20 years button',\n },\n selected: {\n id: 'neptune.DateLookup.selected',\n defaultMessage: 'selected',\n description: 'Description of the selected day/month/year',\n },\n
|
|
1
|
+
{"version":3,"file":"Calendar.messages.js","sources":["../../src/Calendar/Calendar.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n next: {\n id: 'neptune.DateLookup.next',\n defaultMessage: 'next',\n description: 'Description of next button',\n },\n previous: {\n id: 'neptune.DateLookup.previous',\n defaultMessage: 'previous',\n description: 'Description of previous button',\n },\n day: {\n id: 'neptune.DateLookup.day',\n defaultMessage: 'day',\n description: 'Description of next/previous/selected day button',\n },\n month: {\n id: 'neptune.DateLookup.month',\n defaultMessage: 'month',\n description: 'Description of next/previous/selected month button',\n },\n year: {\n id: 'neptune.DateLookup.year',\n defaultMessage: 'year',\n description: 'Description of next/previous/selected year button',\n },\n twentyYears: {\n id: 'neptune.DateLookup.twentyYears',\n defaultMessage: '20 years',\n description: 'Description of next/previous 20 years button',\n },\n selected: {\n id: 'neptune.DateLookup.selected',\n defaultMessage: 'selected',\n description: 'Description of the selected day/month/year',\n },\n goTo20YearView: {\n id: 'neptune.DateLookup.goTo20YearView',\n defaultMessage: 'Go to 20 year view',\n description: 'Description of the button to go to 20 year view',\n },\n});\n"],"names":["defineMessages","next","id","previous","day","month","year","twentyYears","selected","goTo20YearView"],"mappings":";;;;;;AAEA,eAAeA,wBAAc,CAAC;AAC5BC,EAAAA,IAAI,EAAE;IACJC,EAAE,EAAA;GAGH;AACDC,EAAAA,QAAQ,EAAE;IACRD,EAAE,EAAA;GAGH;AACDE,EAAAA,GAAG,EAAE;IACHF,EAAE,EAAA;GAGH;AACDG,EAAAA,KAAK,EAAE;IACLH,EAAE,EAAA;GAGH;AACDI,EAAAA,IAAI,EAAE;IACJJ,EAAE,EAAA;GAGH;AACDK,EAAAA,WAAW,EAAE;IACXL,EAAE,EAAA;GAGH;AACDM,EAAAA,QAAQ,EAAE;IACRN,EAAE,EAAA;GAGH;AACDO,EAAAA,cAAc,EAAE;IACdP,EAAE,EAAA;AAGH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -22,20 +22,8 @@ var messages = defineMessages({
|
|
|
22
22
|
selected: {
|
|
23
23
|
id: "neptune.DateLookup.selected"
|
|
24
24
|
},
|
|
25
|
-
notAvailable: {
|
|
26
|
-
id: "neptune.DateLookup.notAvailable"
|
|
27
|
-
},
|
|
28
25
|
goTo20YearView: {
|
|
29
26
|
id: "neptune.DateLookup.goTo20YearView"
|
|
30
|
-
},
|
|
31
|
-
outOfRangeBetween: {
|
|
32
|
-
id: "neptune.DateLookup.outOfRangeBetween"
|
|
33
|
-
},
|
|
34
|
-
outOfRangeAfter: {
|
|
35
|
-
id: "neptune.DateLookup.outOfRangeAfter"
|
|
36
|
-
},
|
|
37
|
-
outOfRangeBefore: {
|
|
38
|
-
id: "neptune.DateLookup.outOfRangeBefore"
|
|
39
27
|
}
|
|
40
28
|
});
|
|
41
29
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Calendar.messages.mjs","sources":["../../src/Calendar/Calendar.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n next: {\n id: 'neptune.DateLookup.next',\n defaultMessage: 'next',\n description: 'Description of next button',\n },\n previous: {\n id: 'neptune.DateLookup.previous',\n defaultMessage: 'previous',\n description: 'Description of previous button',\n },\n day: {\n id: 'neptune.DateLookup.day',\n defaultMessage: 'day',\n description: 'Description of next/previous/selected day button',\n },\n month: {\n id: 'neptune.DateLookup.month',\n defaultMessage: 'month',\n description: 'Description of next/previous/selected month button',\n },\n year: {\n id: 'neptune.DateLookup.year',\n defaultMessage: 'year',\n description: 'Description of next/previous/selected year button',\n },\n twentyYears: {\n id: 'neptune.DateLookup.twentyYears',\n defaultMessage: '20 years',\n description: 'Description of next/previous 20 years button',\n },\n selected: {\n id: 'neptune.DateLookup.selected',\n defaultMessage: 'selected',\n description: 'Description of the selected day/month/year',\n },\n
|
|
1
|
+
{"version":3,"file":"Calendar.messages.mjs","sources":["../../src/Calendar/Calendar.messages.ts"],"sourcesContent":["import { defineMessages } from 'react-intl';\n\nexport default defineMessages({\n next: {\n id: 'neptune.DateLookup.next',\n defaultMessage: 'next',\n description: 'Description of next button',\n },\n previous: {\n id: 'neptune.DateLookup.previous',\n defaultMessage: 'previous',\n description: 'Description of previous button',\n },\n day: {\n id: 'neptune.DateLookup.day',\n defaultMessage: 'day',\n description: 'Description of next/previous/selected day button',\n },\n month: {\n id: 'neptune.DateLookup.month',\n defaultMessage: 'month',\n description: 'Description of next/previous/selected month button',\n },\n year: {\n id: 'neptune.DateLookup.year',\n defaultMessage: 'year',\n description: 'Description of next/previous/selected year button',\n },\n twentyYears: {\n id: 'neptune.DateLookup.twentyYears',\n defaultMessage: '20 years',\n description: 'Description of next/previous 20 years button',\n },\n selected: {\n id: 'neptune.DateLookup.selected',\n defaultMessage: 'selected',\n description: 'Description of the selected day/month/year',\n },\n goTo20YearView: {\n id: 'neptune.DateLookup.goTo20YearView',\n defaultMessage: 'Go to 20 year view',\n description: 'Description of the button to go to 20 year view',\n },\n});\n"],"names":["defineMessages","next","id","previous","day","month","year","twentyYears","selected","goTo20YearView"],"mappings":";;AAEA,eAAeA,cAAc,CAAC;AAC5BC,EAAAA,IAAI,EAAE;IACJC,EAAE,EAAA;GAGH;AACDC,EAAAA,QAAQ,EAAE;IACRD,EAAE,EAAA;GAGH;AACDE,EAAAA,GAAG,EAAE;IACHF,EAAE,EAAA;GAGH;AACDG,EAAAA,KAAK,EAAE;IACLH,EAAE,EAAA;GAGH;AACDI,EAAAA,IAAI,EAAE;IACJJ,EAAE,EAAA;GAGH;AACDK,EAAAA,WAAW,EAAE;IACXL,EAAE,EAAA;GAGH;AACDM,EAAAA,QAAQ,EAAE;IACRN,EAAE,EAAA;GAGH;AACDO,EAAAA,cAAc,EAAE;IACdP,EAAE,EAAA;AAGH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useIntl } from 'react-intl';
|
|
3
|
-
import { formatDate } from '@transferwise/formatting';
|
|
1
|
+
import { useEffect, useState, useCallback } from 'react';
|
|
4
2
|
import '../common/theme.mjs';
|
|
5
3
|
import '../common/direction.mjs';
|
|
6
4
|
import '@transferwise/neptune-tokens';
|
|
@@ -20,66 +18,37 @@ import '../common/PropsValues/variant.mjs';
|
|
|
20
18
|
import '../common/PropsValues/scroll.mjs';
|
|
21
19
|
import '../common/PropsValues/markdownNodeType.mjs';
|
|
22
20
|
import '../common/fileType.mjs';
|
|
21
|
+
import '@transferwise/formatting';
|
|
23
22
|
import '@transferwise/icons';
|
|
24
23
|
import 'clsx';
|
|
24
|
+
import 'react-intl';
|
|
25
25
|
import '../common/CloseButton/CloseButton.messages.mjs';
|
|
26
26
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
27
27
|
import { moveToWithinRange } from '../common/DateUtils/moveToWithinRange/moveToWithinRange.mjs';
|
|
28
28
|
import { isWithinRange } from '../common/DateUtils/isWithinRange/isWithinRange.mjs';
|
|
29
29
|
import { returnDateView } from '../common/DateUtils/getDateView/getDateView.mjs';
|
|
30
|
-
import { clampToDayViewBoundary } from './_helpers/clampToDayViewBoundary/clampToDayViewBoundary.mjs';
|
|
31
|
-
import { isDateDisabled } from './_helpers/isDateDisabled/isDateDisabled.mjs';
|
|
32
|
-
import { hasDisabledDatesInMonth } from './_helpers/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs';
|
|
33
|
-
import { LONG_DAY_FORMAT } from './Calendar.constants.mjs';
|
|
34
|
-
import { InlinePrompt } from '../Prompt/InlinePrompt/InlinePrompt.mjs';
|
|
35
30
|
import DayCalendar from './DayCalendar/DayCalendar.mjs';
|
|
36
31
|
import { getStartOfDay } from './GetStartOfDay/GetStartOfDay.mjs';
|
|
37
|
-
import messages from './Calendar.messages.mjs';
|
|
38
32
|
import MonthCalendar from './MonthCalendar/MonthCalendar.mjs';
|
|
39
33
|
import YearCalendar from './YearCalendar/YearCalendar.mjs';
|
|
40
34
|
|
|
41
|
-
/**
|
|
42
|
-
* Inline calendar for selecting a single date. Powers [DateLookup](?path=/docs/forms-datelookup--docs).
|
|
43
|
-
*/
|
|
44
35
|
const Calendar = ({
|
|
45
36
|
value,
|
|
46
37
|
min: minProp = null,
|
|
47
38
|
max: maxProp = null,
|
|
48
39
|
monthFormat = MonthFormat.LONG,
|
|
49
40
|
placeholder,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
onChange
|
|
41
|
+
onChange,
|
|
42
|
+
onSelect
|
|
53
43
|
}) => {
|
|
54
|
-
const intl = useIntl();
|
|
55
44
|
const selectedDate = getStartOfDay(value);
|
|
56
45
|
const min = getStartOfDay(minProp);
|
|
57
46
|
const max = getStartOfDay(maxProp);
|
|
58
|
-
const disabledReasonId = useId();
|
|
59
|
-
const disabledRulesRef = useRef(disabledRules);
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
disabledRulesRef.current = disabledRules;
|
|
62
|
-
});
|
|
63
|
-
const [hasInteracted, setHasInteracted] = useState(false);
|
|
64
|
-
const [focusedDate, setFocusedDate] = useState(selectedDate);
|
|
65
|
-
useEffect(() => {
|
|
66
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
67
|
-
setFocusedDate(selectedDate);
|
|
68
|
-
}, [selectedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
69
|
-
const checkIsEnabled = date => {
|
|
70
|
-
if (!date) return true;
|
|
71
|
-
return isWithinRange(date, min, max) && !isDateDisabled(date, disabledRulesRef.current);
|
|
72
|
-
};
|
|
73
|
-
const focusedDateDisabled = focusedDate ? !isWithinRange(focusedDate, min, max) || isDateDisabled(focusedDate, disabledRules) : false;
|
|
74
47
|
useEffect(() => {
|
|
75
48
|
if (selectedDate && !isWithinRange(selectedDate, min, max)) {
|
|
76
|
-
|
|
77
|
-
setFocusedDate(clamped); // eslint-disable-line react-hooks/set-state-in-effect
|
|
78
|
-
onDateFocus?.(clamped, {
|
|
79
|
-
isEnabled: checkIsEnabled(clamped)
|
|
80
|
-
});
|
|
49
|
+
onChange(moveToWithinRange(selectedDate, min, max));
|
|
81
50
|
}
|
|
82
|
-
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(),
|
|
51
|
+
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onChange]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
83
52
|
const dateView = returnDateView(selectedDate, min, max);
|
|
84
53
|
const [viewMonth, setViewMonth] = useState(dateView.getMonth());
|
|
85
54
|
const [viewYear, setViewYear] = useState(dateView.getFullYear());
|
|
@@ -90,13 +59,6 @@ const Calendar = ({
|
|
|
90
59
|
setViewMonth(view.getMonth());
|
|
91
60
|
setViewYear(view.getFullYear());
|
|
92
61
|
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
93
|
-
useEffect(() => {
|
|
94
|
-
if (focusedDate) {
|
|
95
|
-
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
96
|
-
setViewMonth(focusedDate.getMonth());
|
|
97
|
-
setViewYear(focusedDate.getFullYear());
|
|
98
|
-
}
|
|
99
|
-
}, [focusedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
100
62
|
const handleViewDateUpdate = useCallback(
|
|
101
63
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization
|
|
102
64
|
({
|
|
@@ -105,56 +67,29 @@ const Calendar = ({
|
|
|
105
67
|
}) => {
|
|
106
68
|
if (month !== undefined) setViewMonth(month);
|
|
107
69
|
if (year !== undefined) setViewYear(year);
|
|
108
|
-
setHasInteracted(false);
|
|
109
70
|
}, []);
|
|
110
71
|
const switchToDays = useCallback(() => setMode('day'), []);
|
|
111
72
|
const switchToMonths = useCallback(() => setMode('month'), []);
|
|
112
73
|
const switchToYears = useCallback(() => setMode('year'), []);
|
|
113
74
|
const handleSelectedDateUpdate = useCallback(date => {
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
onDateFocus?.(date, {
|
|
118
|
-
isEnabled
|
|
119
|
-
});
|
|
120
|
-
if (isEnabled && onChange) {
|
|
75
|
+
if (onSelect) {
|
|
76
|
+
onSelect(date);
|
|
77
|
+
} else {
|
|
121
78
|
onChange(date);
|
|
122
79
|
}
|
|
123
|
-
}, [
|
|
80
|
+
}, [onChange, onSelect]);
|
|
124
81
|
const adjustDate = useCallback((daysToAdd, monthsToAdd, yearsToAdd) => {
|
|
125
|
-
const base = focusedDate ?? selectedDate;
|
|
126
82
|
let date;
|
|
127
|
-
if (
|
|
128
|
-
date = new Date(mode === 'year' ?
|
|
83
|
+
if (selectedDate) {
|
|
84
|
+
date = new Date(mode === 'year' ? selectedDate.getFullYear() + yearsToAdd : selectedDate.getFullYear(), mode === 'month' ? selectedDate.getMonth() + monthsToAdd : selectedDate.getMonth(), mode === 'day' ? selectedDate.getDate() + daysToAdd : selectedDate.getDate());
|
|
129
85
|
} else {
|
|
130
86
|
date = getStartOfDay(new Date());
|
|
131
87
|
}
|
|
132
|
-
date &&=
|
|
133
|
-
if (date?.getTime() !==
|
|
134
|
-
|
|
135
|
-
setFocusedDate(date);
|
|
136
|
-
if (date) {
|
|
137
|
-
setViewMonth(date.getMonth());
|
|
138
|
-
setViewYear(date.getFullYear());
|
|
139
|
-
}
|
|
140
|
-
if (monthChanged) {
|
|
141
|
-
setHasInteracted(false);
|
|
142
|
-
} else if (!hasInteracted) {
|
|
143
|
-
setHasInteracted(true);
|
|
144
|
-
}
|
|
145
|
-
onDateFocus?.(date, {
|
|
146
|
-
isEnabled: checkIsEnabled(date)
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}, [focusedDate, selectedDate, min, max, mode, onDateFocus]);
|
|
150
|
-
const handleDayFocus = useCallback(date => {
|
|
151
|
-
if (date.getTime() !== focusedDate?.getTime()) {
|
|
152
|
-
setFocusedDate(date);
|
|
153
|
-
onDateFocus?.(date, {
|
|
154
|
-
isEnabled: checkIsEnabled(date)
|
|
155
|
-
});
|
|
88
|
+
date &&= moveToWithinRange(date, min, max);
|
|
89
|
+
if (date?.getTime() !== selectedDate?.getTime()) {
|
|
90
|
+
onChange(date);
|
|
156
91
|
}
|
|
157
|
-
}, [
|
|
92
|
+
}, [selectedDate, min, max, mode, onChange]);
|
|
158
93
|
const handleKeyDown = useCallback(event => {
|
|
159
94
|
switch (event.key) {
|
|
160
95
|
case 'ArrowLeft':
|
|
@@ -173,34 +108,8 @@ const Calendar = ({
|
|
|
173
108
|
adjustDate(7, 4, 4);
|
|
174
109
|
event.preventDefault();
|
|
175
110
|
break;
|
|
176
|
-
case 'Enter':
|
|
177
|
-
case ' ':
|
|
178
|
-
if (mode === 'day' && focusedDate && event.target.hasAttribute('data-calendar-cell')) {
|
|
179
|
-
handleSelectedDateUpdate(focusedDate);
|
|
180
|
-
event.preventDefault();
|
|
181
|
-
}
|
|
182
|
-
break;
|
|
183
111
|
}
|
|
184
|
-
}, [adjustDate
|
|
185
|
-
const focusedDateOutOfRange = focusedDate ? !isWithinRange(focusedDate, min, max) : false;
|
|
186
|
-
const formatDateForPrompt = date => formatDate(date, intl.locale, LONG_DAY_FORMAT);
|
|
187
|
-
const outOfRangePromptText = min && max ? intl.formatMessage(messages.outOfRangeBetween, {
|
|
188
|
-
min: formatDateForPrompt(min),
|
|
189
|
-
max: formatDateForPrompt(max)
|
|
190
|
-
}) : min ? intl.formatMessage(messages.outOfRangeAfter, {
|
|
191
|
-
min: formatDateForPrompt(min)
|
|
192
|
-
}) : max ? intl.formatMessage(messages.outOfRangeBefore, {
|
|
193
|
-
max: formatDateForPrompt(max)
|
|
194
|
-
}) : '';
|
|
195
|
-
const hasOutOfRangeDates = mode === 'day' && !!(min || max);
|
|
196
|
-
const showRulesPrompt = mode === 'day' && !!disabledRules && hasDisabledDatesInMonth(viewMonth, viewYear, disabledRules, min, max);
|
|
197
|
-
const showOutOfRangePrompt = mode === 'day' && focusedDateOutOfRange;
|
|
198
|
-
const showPrompt = hasOutOfRangeDates || showRulesPrompt;
|
|
199
|
-
const promptText = showOutOfRangePrompt ? outOfRangePromptText : disabledRules?.reason ?? outOfRangePromptText;
|
|
200
|
-
const promptSentiment = showOutOfRangePrompt || focusedDateDisabled ? 'negative' : 'neutral';
|
|
201
|
-
// Visible when there's an actionable message; sr-only when only hasOutOfRangeDates is true
|
|
202
|
-
// (prompt exists for aria-describedby but no visual cue needed until an out-of-range date is focused)
|
|
203
|
-
const promptClassName = showOutOfRangePrompt || showRulesPrompt ? 'm-t-1' : 'sr-only';
|
|
112
|
+
}, [adjustDate]);
|
|
204
113
|
return (
|
|
205
114
|
/*#__PURE__*/
|
|
206
115
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -208,22 +117,16 @@ const Calendar = ({
|
|
|
208
117
|
onKeyDown: handleKeyDown,
|
|
209
118
|
children: [mode === 'day' && /*#__PURE__*/jsx(DayCalendar, {
|
|
210
119
|
selectedDate: selectedDate,
|
|
211
|
-
focusedDate: focusedDate,
|
|
212
120
|
min: min,
|
|
213
121
|
max: max,
|
|
214
122
|
viewMonth: viewMonth,
|
|
215
123
|
viewYear: viewYear,
|
|
216
124
|
monthFormat: monthFormat,
|
|
217
|
-
disabledRules: disabledRules,
|
|
218
|
-
disabledReasonId: showPrompt ? disabledReasonId : undefined,
|
|
219
|
-
announceReasonOnFocus: !hasInteracted,
|
|
220
125
|
onSelect: handleSelectedDateUpdate,
|
|
221
|
-
onDayFocus: handleDayFocus,
|
|
222
126
|
onLabelClick: switchToYears,
|
|
223
127
|
onViewDateUpdate: handleViewDateUpdate
|
|
224
128
|
}), mode === 'month' && /*#__PURE__*/jsx(MonthCalendar, {
|
|
225
129
|
selectedDate: selectedDate,
|
|
226
|
-
focusedDate: focusedDate,
|
|
227
130
|
min: min,
|
|
228
131
|
max: max,
|
|
229
132
|
viewYear: viewYear,
|
|
@@ -235,7 +138,6 @@ const Calendar = ({
|
|
|
235
138
|
onViewDateUpdate: handleViewDateUpdate
|
|
236
139
|
}), mode === 'year' && /*#__PURE__*/jsx(YearCalendar, {
|
|
237
140
|
selectedDate: selectedDate,
|
|
238
|
-
focusedDate: focusedDate,
|
|
239
141
|
min: min,
|
|
240
142
|
max: max,
|
|
241
143
|
viewYear: viewYear,
|
|
@@ -244,12 +146,6 @@ const Calendar = ({
|
|
|
244
146
|
}),
|
|
245
147
|
onSelect: switchToMonths,
|
|
246
148
|
onViewDateUpdate: handleViewDateUpdate
|
|
247
|
-
}), showPrompt && /*#__PURE__*/jsx(InlinePrompt, {
|
|
248
|
-
sentiment: promptSentiment,
|
|
249
|
-
width: "full",
|
|
250
|
-
id: disabledReasonId,
|
|
251
|
-
className: promptClassName,
|
|
252
|
-
children: promptText
|
|
253
149
|
})]
|
|
254
150
|
})
|
|
255
151
|
);
|