@transferwise/components 0.0.0-experimental-15273df → 0.0.0-experimental-d6d5b6e
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 +94 -16
- package/build/Calendar/Calendar.js.map +1 -1
- package/build/Calendar/Calendar.messages.js +12 -0
- package/build/Calendar/Calendar.messages.js.map +1 -1
- package/build/Calendar/Calendar.messages.mjs +12 -0
- package/build/Calendar/Calendar.messages.mjs.map +1 -1
- package/build/Calendar/Calendar.mjs +95 -17
- package/build/Calendar/Calendar.mjs.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.js +5 -1
- package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.mjs +5 -1
- package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.js +14 -0
- package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.mjs +14 -0
- package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +53 -19
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +53 -19
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.js +6 -0
- package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs +6 -0
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +8 -3
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +8 -3
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
- package/build/Calendar/{tableLink → TableLink}/TableLink.js +26 -11
- package/build/Calendar/TableLink/TableLink.js.map +1 -0
- package/build/Calendar/{tableLink → TableLink}/TableLink.mjs +26 -11
- package/build/Calendar/TableLink/TableLink.mjs.map +1 -0
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +8 -3
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +8 -3
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.js +7 -0
- package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.mjs +7 -0
- package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
- package/build/DateLookup/DateLookup.js +19 -9
- package/build/DateLookup/DateLookup.js.map +1 -1
- package/build/DateLookup/DateLookup.mjs +19 -9
- package/build/DateLookup/DateLookup.mjs.map +1 -1
- package/build/Sticky/Sticky.js +0 -1
- package/build/Sticky/Sticky.js.map +1 -1
- package/build/Sticky/Sticky.mjs +0 -1
- package/build/Sticky/Sticky.mjs.map +1 -1
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +33 -0
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +1 -0
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +31 -0
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +1 -0
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +40 -0
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +1 -0
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +38 -0
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +1 -0
- package/build/i18n/en.json +4 -0
- package/build/i18n/en.json.js +4 -0
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +4 -0
- 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 +123 -48
- package/build/styles/Calendar/Calendar.css +112 -37
- package/build/styles/Calendar/TableLink/TableLink.css +115 -0
- package/build/styles/main.css +123 -48
- package/build/types/Calendar/Calendar.d.ts +16 -3
- package/build/types/Calendar/Calendar.d.ts.map +1 -1
- package/build/types/Calendar/Calendar.messages.d.ts +20 -0
- package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
- package/build/types/Calendar/Calendar.types.d.ts +32 -0
- package/build/types/Calendar/Calendar.types.d.ts.map +1 -0
- package/build/types/Calendar/DateHeader/DateHeader.d.ts +2 -0
- package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +5 -1
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +4 -0
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +1 -0
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +2 -1
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/{tableLink → TableLink}/TableLink.d.ts +3 -1
- 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/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +2 -1
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +1 -0
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
- package/build/types/Calendar/index.d.ts +1 -0
- package/build/types/Calendar/index.d.ts.map +1 -1
- package/build/types/DateLookup/DateLookup.d.ts +23 -4
- package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/DateLookup/index.d.ts +1 -0
- package/build/types/DateLookup/index.d.ts.map +1 -1
- package/build/types/Sticky/Sticky.d.ts.map +1 -1
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +3 -0
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +1 -0
- package/build/types/common/DateUtils/index.d.ts +2 -0
- package/build/types/common/DateUtils/index.d.ts.map +1 -1
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +3 -0
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +1 -0
- package/build/types/index.d.ts +3 -2
- package/build/types/index.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +8 -0
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Calendar/Calendar.css +112 -37
- package/src/Calendar/Calendar.disabledDates.test.tsx +518 -0
- package/src/Calendar/Calendar.less +5 -35
- package/src/Calendar/Calendar.messages.ts +21 -0
- package/src/Calendar/Calendar.test.tsx +217 -28
- package/src/Calendar/Calendar.tsx +136 -19
- package/src/Calendar/Calendar.types.ts +35 -0
- package/src/Calendar/DateHeader/DateHeader.tsx +6 -0
- package/src/Calendar/DayCalendar/DayCalendar.tsx +33 -1
- package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +62 -28
- package/src/Calendar/MonthCalendar/MonthCalendar.tsx +8 -0
- package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +15 -3
- package/src/Calendar/TableLink/TableLink.css +115 -0
- package/src/Calendar/TableLink/TableLink.less +68 -0
- package/src/Calendar/{tableLink → TableLink}/TableLink.tsx +29 -14
- package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +15 -3
- package/src/Calendar/YearCalendar/YearCalendar.tsx +9 -0
- package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +118 -0
- package/src/Calendar/_stories/Calendar.story.tsx +138 -4
- package/src/Calendar/index.ts +7 -0
- package/src/DateLookup/DateLookup.disabledDates.test.tsx +293 -0
- package/src/DateLookup/DateLookup.test.tsx +34 -37
- package/src/DateLookup/DateLookup.tsx +36 -13
- package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +108 -0
- package/src/DateLookup/_stories/DateLookup.story.tsx +124 -2
- package/src/DateLookup/index.ts +6 -0
- package/src/Sticky/Sticky.test.tsx +0 -1
- package/src/Sticky/Sticky.tsx +0 -1
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +98 -0
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +45 -0
- package/src/common/DateUtils/index.ts +2 -0
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +159 -0
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +59 -0
- package/src/i18n/en.json +4 -0
- package/src/index.ts +3 -2
- package/src/main.css +123 -48
- package/src/main.less +0 -1
- package/build/Calendar/tableLink/TableLink.js.map +0 -1
- package/build/Calendar/tableLink/TableLink.mjs.map +0 -1
- package/build/styles/Sticky/Sticky.css +0 -4
- package/build/types/Calendar/tableLink/TableLink.d.ts.map +0 -1
- package/build/types/Calendar/tableLink/index.d.ts.map +0 -1
- package/src/Sticky/Sticky.css +0 -4
- package/src/Sticky/Sticky.less +0 -6
- package/src/Sticky/_stories/Sticky.test.story.tsx +0 -177
- /package/build/types/Calendar/{tableLink → TableLink}/index.d.ts +0 -0
- /package/src/Calendar/{tableLink → TableLink}/index.ts +0 -0
|
@@ -3,6 +3,8 @@
|
|
|
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');
|
|
6
8
|
require('../common/theme.js');
|
|
7
9
|
require('../common/direction.js');
|
|
8
10
|
require('@transferwise/neptune-tokens');
|
|
@@ -22,17 +24,19 @@ require('../common/PropsValues/variant.js');
|
|
|
22
24
|
require('../common/PropsValues/scroll.js');
|
|
23
25
|
require('../common/PropsValues/markdownNodeType.js');
|
|
24
26
|
require('../common/fileType.js');
|
|
25
|
-
require('@transferwise/formatting');
|
|
26
27
|
require('@transferwise/icons');
|
|
27
28
|
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 isDateDisabled = require('../common/DateUtils/isDateDisabled/isDateDisabled.js');
|
|
35
|
+
var hasDisabledDatesInMonth = require('../common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js');
|
|
36
|
+
var InlinePrompt = require('../Prompt/InlinePrompt/InlinePrompt.js');
|
|
34
37
|
var DayCalendar = require('./DayCalendar/DayCalendar.js');
|
|
35
38
|
var GetStartOfDay = require('./GetStartOfDay/GetStartOfDay.js');
|
|
39
|
+
var Calendar_messages = require('./Calendar.messages.js');
|
|
36
40
|
var MonthCalendar = require('./MonthCalendar/MonthCalendar.js');
|
|
37
41
|
var YearCalendar = require('./YearCalendar/YearCalendar.js');
|
|
38
42
|
|
|
@@ -42,17 +46,38 @@ const Calendar = ({
|
|
|
42
46
|
max: maxProp = null,
|
|
43
47
|
monthFormat: monthFormat$1 = monthFormat.MonthFormat.LONG,
|
|
44
48
|
placeholder,
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
disabledRules,
|
|
50
|
+
onDateFocus,
|
|
51
|
+
onChange
|
|
47
52
|
}) => {
|
|
53
|
+
const intl = reactIntl.useIntl();
|
|
48
54
|
const selectedDate = GetStartOfDay.getStartOfDay(value);
|
|
49
55
|
const min = GetStartOfDay.getStartOfDay(minProp);
|
|
50
56
|
const max = GetStartOfDay.getStartOfDay(maxProp);
|
|
57
|
+
const disabledReasonId = React.useId();
|
|
58
|
+
const disabledRulesRef = React.useRef(disabledRules);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
disabledRulesRef.current = disabledRules;
|
|
61
|
+
});
|
|
62
|
+
const [focusedDate, setFocusedDate] = React.useState(selectedDate);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
65
|
+
setFocusedDate(selectedDate);
|
|
66
|
+
}, [selectedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
67
|
+
const checkIsEnabled = date => {
|
|
68
|
+
if (!date) return true;
|
|
69
|
+
return isWithinRange.isWithinRange(date, min, max) && !isDateDisabled.isDateDisabled(date, disabledRulesRef.current);
|
|
70
|
+
};
|
|
71
|
+
const focusedDateDisabled = focusedDate ? !isWithinRange.isWithinRange(focusedDate, min, max) || isDateDisabled.isDateDisabled(focusedDate, disabledRules) : false;
|
|
51
72
|
React.useEffect(() => {
|
|
52
73
|
if (selectedDate && !isWithinRange.isWithinRange(selectedDate, min, max)) {
|
|
53
|
-
|
|
74
|
+
const clamped = moveToWithinRange.moveToWithinRange(selectedDate, min, max);
|
|
75
|
+
setFocusedDate(clamped); // eslint-disable-line react-hooks/set-state-in-effect
|
|
76
|
+
onDateFocus?.(clamped, {
|
|
77
|
+
isEnabled: checkIsEnabled(clamped)
|
|
78
|
+
});
|
|
54
79
|
}
|
|
55
|
-
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(),
|
|
80
|
+
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onDateFocus]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
56
81
|
const dateView = getDateView.returnDateView(selectedDate, min, max);
|
|
57
82
|
const [viewMonth, setViewMonth] = React.useState(dateView.getMonth());
|
|
58
83
|
const [viewYear, setViewYear] = React.useState(dateView.getFullYear());
|
|
@@ -63,6 +88,13 @@ const Calendar = ({
|
|
|
63
88
|
setViewMonth(view.getMonth());
|
|
64
89
|
setViewYear(view.getFullYear());
|
|
65
90
|
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (focusedDate) {
|
|
93
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
94
|
+
setViewMonth(focusedDate.getMonth());
|
|
95
|
+
setViewYear(focusedDate.getFullYear());
|
|
96
|
+
}
|
|
97
|
+
}, [focusedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
66
98
|
const handleViewDateUpdate = React.useCallback(
|
|
67
99
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization
|
|
68
100
|
({
|
|
@@ -76,24 +108,31 @@ const Calendar = ({
|
|
|
76
108
|
const switchToMonths = React.useCallback(() => setMode('month'), []);
|
|
77
109
|
const switchToYears = React.useCallback(() => setMode('year'), []);
|
|
78
110
|
const handleSelectedDateUpdate = React.useCallback(date => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
111
|
+
const isEnabled = checkIsEnabled(date);
|
|
112
|
+
setFocusedDate(date);
|
|
113
|
+
onDateFocus?.(date, {
|
|
114
|
+
isEnabled
|
|
115
|
+
});
|
|
116
|
+
if (isEnabled && onChange) {
|
|
82
117
|
onChange(date);
|
|
83
118
|
}
|
|
84
|
-
}, [
|
|
119
|
+
}, [onDateFocus, onChange]);
|
|
85
120
|
const adjustDate = React.useCallback((daysToAdd, monthsToAdd, yearsToAdd) => {
|
|
121
|
+
const base = focusedDate ?? selectedDate;
|
|
86
122
|
let date;
|
|
87
|
-
if (
|
|
88
|
-
date = new Date(mode === 'year' ?
|
|
123
|
+
if (base) {
|
|
124
|
+
date = new Date(mode === 'year' ? base.getFullYear() + yearsToAdd : base.getFullYear(), mode === 'month' ? base.getMonth() + monthsToAdd : base.getMonth(), mode === 'day' ? base.getDate() + daysToAdd : base.getDate());
|
|
89
125
|
} else {
|
|
90
126
|
date = GetStartOfDay.getStartOfDay(new Date());
|
|
91
127
|
}
|
|
92
128
|
date &&= moveToWithinRange.moveToWithinRange(date, min, max);
|
|
93
|
-
if (date?.getTime() !==
|
|
94
|
-
|
|
129
|
+
if (date?.getTime() !== focusedDate?.getTime()) {
|
|
130
|
+
setFocusedDate(date);
|
|
131
|
+
onDateFocus?.(date, {
|
|
132
|
+
isEnabled: checkIsEnabled(date)
|
|
133
|
+
});
|
|
95
134
|
}
|
|
96
|
-
}, [selectedDate, min, max, mode,
|
|
135
|
+
}, [focusedDate, selectedDate, min, max, mode, onDateFocus]);
|
|
97
136
|
const handleKeyDown = React.useCallback(event => {
|
|
98
137
|
switch (event.key) {
|
|
99
138
|
case 'ArrowLeft':
|
|
@@ -112,8 +151,36 @@ const Calendar = ({
|
|
|
112
151
|
adjustDate(7, 4, 4);
|
|
113
152
|
event.preventDefault();
|
|
114
153
|
break;
|
|
154
|
+
case 'Enter':
|
|
155
|
+
case ' ':
|
|
156
|
+
if (mode === 'day' && focusedDate && event.target.hasAttribute('data-calendar-cell')) {
|
|
157
|
+
handleSelectedDateUpdate(focusedDate);
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
115
161
|
}
|
|
116
|
-
}, [adjustDate]);
|
|
162
|
+
}, [adjustDate, focusedDate, mode, handleSelectedDateUpdate]);
|
|
163
|
+
const focusedDateOutOfRange = focusedDate ? !isWithinRange.isWithinRange(focusedDate, min, max) : false;
|
|
164
|
+
const formatDateForPrompt = date => formatting.formatDate(date, intl.locale, {
|
|
165
|
+
day: 'numeric',
|
|
166
|
+
month: 'long',
|
|
167
|
+
year: 'numeric'
|
|
168
|
+
});
|
|
169
|
+
const outOfRangePromptText = min && max ? intl.formatMessage(Calendar_messages.default.outOfRangeBetween, {
|
|
170
|
+
min: formatDateForPrompt(min),
|
|
171
|
+
max: formatDateForPrompt(max)
|
|
172
|
+
}) : min ? intl.formatMessage(Calendar_messages.default.outOfRangeAfter, {
|
|
173
|
+
min: formatDateForPrompt(min)
|
|
174
|
+
}) : max ? intl.formatMessage(Calendar_messages.default.outOfRangeBefore, {
|
|
175
|
+
max: formatDateForPrompt(max)
|
|
176
|
+
}) : '';
|
|
177
|
+
const hasOutOfRangeDates = mode === 'day' && !!(min || max);
|
|
178
|
+
const showRulesPrompt = mode === 'day' && !!disabledRules && hasDisabledDatesInMonth.hasDisabledDatesInMonth(viewMonth, viewYear, disabledRules, min, max);
|
|
179
|
+
const showOutOfRangePrompt = mode === 'day' && focusedDateOutOfRange;
|
|
180
|
+
const showPrompt = hasOutOfRangeDates || showRulesPrompt;
|
|
181
|
+
const promptText = showOutOfRangePrompt ? outOfRangePromptText : disabledRules?.reason ?? outOfRangePromptText;
|
|
182
|
+
const promptSentiment = showOutOfRangePrompt || focusedDateDisabled ? 'negative' : 'neutral';
|
|
183
|
+
const promptClassName = showOutOfRangePrompt || showRulesPrompt && !showOutOfRangePrompt ? 'm-t-1' : 'sr-only';
|
|
117
184
|
return (
|
|
118
185
|
/*#__PURE__*/
|
|
119
186
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -121,16 +188,20 @@ const Calendar = ({
|
|
|
121
188
|
onKeyDown: handleKeyDown,
|
|
122
189
|
children: [mode === 'day' && /*#__PURE__*/jsxRuntime.jsx(DayCalendar.default, {
|
|
123
190
|
selectedDate: selectedDate,
|
|
191
|
+
focusedDate: focusedDate,
|
|
124
192
|
min: min,
|
|
125
193
|
max: max,
|
|
126
194
|
viewMonth: viewMonth,
|
|
127
195
|
viewYear: viewYear,
|
|
128
196
|
monthFormat: monthFormat$1,
|
|
197
|
+
disabledRules: disabledRules,
|
|
198
|
+
disabledReasonId: showPrompt ? disabledReasonId : undefined,
|
|
129
199
|
onSelect: handleSelectedDateUpdate,
|
|
130
200
|
onLabelClick: switchToYears,
|
|
131
201
|
onViewDateUpdate: handleViewDateUpdate
|
|
132
202
|
}), mode === 'month' && /*#__PURE__*/jsxRuntime.jsx(MonthCalendar.default, {
|
|
133
203
|
selectedDate: selectedDate,
|
|
204
|
+
focusedDate: focusedDate,
|
|
134
205
|
min: min,
|
|
135
206
|
max: max,
|
|
136
207
|
viewYear: viewYear,
|
|
@@ -142,6 +213,7 @@ const Calendar = ({
|
|
|
142
213
|
onViewDateUpdate: handleViewDateUpdate
|
|
143
214
|
}), mode === 'year' && /*#__PURE__*/jsxRuntime.jsx(YearCalendar.default, {
|
|
144
215
|
selectedDate: selectedDate,
|
|
216
|
+
focusedDate: focusedDate,
|
|
145
217
|
min: min,
|
|
146
218
|
max: max,
|
|
147
219
|
viewYear: viewYear,
|
|
@@ -150,6 +222,12 @@ const Calendar = ({
|
|
|
150
222
|
}),
|
|
151
223
|
onSelect: switchToMonths,
|
|
152
224
|
onViewDateUpdate: handleViewDateUpdate
|
|
225
|
+
}), showPrompt && /*#__PURE__*/jsxRuntime.jsx(InlinePrompt.InlinePrompt, {
|
|
226
|
+
sentiment: promptSentiment,
|
|
227
|
+
width: "full",
|
|
228
|
+
id: disabledReasonId,
|
|
229
|
+
className: promptClassName,
|
|
230
|
+
children: promptText
|
|
153
231
|
})]
|
|
154
232
|
})
|
|
155
233
|
);
|
|
@@ -1 +1 @@
|
|
|
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,CA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AC3CE,QAAAA,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;;;;"}
|
|
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 {\n isWithinRange,\n moveToWithinRange,\n returnDateView,\n isDateDisabled,\n hasDisabledDatesInMonth,\n} from '../common/DateUtils';\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) => void;\n}\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 [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 },\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 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 &&= moveToWithinRange(date, min, max);\n if (date?.getTime() !== focusedDate?.getTime()) {\n setFocusedDate(date);\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 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) =>\n formatDate(date, intl.locale, { day: 'numeric', month: 'long', year: 'numeric' });\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 const promptClassName =\n showOutOfRangePrompt || (showRulesPrompt && !showOutOfRangePrompt) ? '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 onSelect={handleSelectedDateUpdate}\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","focusedDate","setFocusedDate","useState","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","handleKeyDown","event","key","preventDefault","target","hasAttribute","focusedDateOutOfRange","formatDateForPrompt","formatDate","locale","day","outOfRangePromptText","formatMessage","messages","outOfRangeBetween","outOfRangeAfter","outOfRangeBefore","hasOutOfRangeDates","showRulesPrompt","hasDisabledDatesInMonth","showOutOfRangePrompt","showPrompt","promptText","reason","promptSentiment","promptClassName","_jsxs","onKeyDown","children","_jsx","DayCalendar","onSelect","onLabelClick","onViewDateUpdate","MonthCalendar","YearCalendar","InlinePrompt","sentiment","width","id","className"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,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,CAAC;AAClC,EAAA,MAAMY,gBAAgB,GAAGC,WAAK,EAAE;AAChC,EAAA,MAAMC,gBAAgB,GAAGC,YAAM,CAACV,aAAa,CAAC;AAC9CW,EAAAA,eAAS,CAAC,MAAK;IACbF,gBAAgB,CAACG,OAAO,GAAGZ,aAAa;AAC1C,EAAA,CAAC,CAAC;EAEF,MAAM,CAACa,WAAW,EAAEC,cAAc,CAAC,GAAGC,cAAQ,CAAcV,YAAY,CAAC;AAEzEM,EAAAA,eAAS,CAAC,MAAK;AACb;IACAG,cA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,EAAEzC,aAAc;AAC5B0C,QAAAA,gBAAgB,EAAEjD;OAAqB,CAE1C,EACAH,IAAI,KAAK,MAAM,iBACdgD,cAAA,CAACM,oBAAY,EAAA;AACXlF,QAAAA,YAAY,EAAEA,YAAa;AAC3BQ,QAAAA,WAAW,EAAEA,WAAY;AACzBrB,QAAAA,GAAG,EAAEA,GAAI;AACTE,QAAAA,GAAG,EAAEA,GAAI;AACToC,QAAAA,QAAQ,EAAEA,QAAS;QAAA,IACd/B,WAAW,IAAI,IAAI,IAAI;AAAEA,UAAAA;SAAa,CAAA;AAC3CoF,QAAAA,QAAQ,EAAEzC,cAAe;AACzB2C,QAAAA,gBAAgB,EAAEjD;AAAqB,OAAA,CAE1C,EACAqC,UAAU,iBACTQ,cAAA,CAACO,yBAAY,EAAA;AACXC,QAAAA,SAAS,EAAEb,eAAgB;AAC3Bc,QAAAA,KAAK,EAAC,MAAM;AACZC,QAAAA,EAAE,EAAEpF,gBAAiB;AACrBqF,QAAAA,SAAS,EAAEf,eAAgB;AAAAG,QAAAA,QAAA,EAE1BN;AAAU,OACC,CACf;KACE;AAAC;AAEV;;;;"}
|
|
@@ -26,8 +26,20 @@ var messages = reactIntl.defineMessages({
|
|
|
26
26
|
selected: {
|
|
27
27
|
id: "neptune.DateLookup.selected"
|
|
28
28
|
},
|
|
29
|
+
notAvailable: {
|
|
30
|
+
id: "neptune.DateLookup.notAvailable"
|
|
31
|
+
},
|
|
29
32
|
goTo20YearView: {
|
|
30
33
|
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"
|
|
31
43
|
}
|
|
32
44
|
});
|
|
33
45
|
|
|
@@ -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 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;
|
|
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 notAvailable: {\n id: 'neptune.DateLookup.notAvailable',\n defaultMessage: 'not available',\n description: 'Announces that a date is disabled/unavailable',\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 outOfRangeBetween: {\n id: 'neptune.DateLookup.outOfRangeBetween',\n defaultMessage: 'Please select a date between {min} and {max}.',\n description:\n 'Inline prompt when a date outside min/max boundaries is focused and both min and max are set',\n },\n outOfRangeAfter: {\n id: 'neptune.DateLookup.outOfRangeAfter',\n defaultMessage: 'Please select a date on or after {min}.',\n description: 'Inline prompt when a date before min is focused and only min is set',\n },\n outOfRangeBefore: {\n id: 'neptune.DateLookup.outOfRangeBefore',\n defaultMessage: 'Please select a date on or before {max}.',\n description: 'Inline prompt when a date after max is focused and only max is set',\n },\n});\n"],"names":["defineMessages","next","id","previous","day","month","year","twentyYears","selected","notAvailable","goTo20YearView","outOfRangeBetween","outOfRangeAfter","outOfRangeBefore"],"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,YAAY,EAAE;IACZP,EAAE,EAAA;GAGH;AACDQ,EAAAA,cAAc,EAAE;IACdR,EAAE,EAAA;GAGH;AACDS,EAAAA,iBAAiB,EAAE;IACjBT,EAAE,EAAA;GAIH;AACDU,EAAAA,eAAe,EAAE;IACfV,EAAE,EAAA;GAGH;AACDW,EAAAA,gBAAgB,EAAE;IAChBX,EAAE,EAAA;AAGH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -22,8 +22,20 @@ var messages = defineMessages({
|
|
|
22
22
|
selected: {
|
|
23
23
|
id: "neptune.DateLookup.selected"
|
|
24
24
|
},
|
|
25
|
+
notAvailable: {
|
|
26
|
+
id: "neptune.DateLookup.notAvailable"
|
|
27
|
+
},
|
|
25
28
|
goTo20YearView: {
|
|
26
29
|
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"
|
|
27
39
|
}
|
|
28
40
|
});
|
|
29
41
|
|
|
@@ -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 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;
|
|
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 notAvailable: {\n id: 'neptune.DateLookup.notAvailable',\n defaultMessage: 'not available',\n description: 'Announces that a date is disabled/unavailable',\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 outOfRangeBetween: {\n id: 'neptune.DateLookup.outOfRangeBetween',\n defaultMessage: 'Please select a date between {min} and {max}.',\n description:\n 'Inline prompt when a date outside min/max boundaries is focused and both min and max are set',\n },\n outOfRangeAfter: {\n id: 'neptune.DateLookup.outOfRangeAfter',\n defaultMessage: 'Please select a date on or after {min}.',\n description: 'Inline prompt when a date before min is focused and only min is set',\n },\n outOfRangeBefore: {\n id: 'neptune.DateLookup.outOfRangeBefore',\n defaultMessage: 'Please select a date on or before {max}.',\n description: 'Inline prompt when a date after max is focused and only max is set',\n },\n});\n"],"names":["defineMessages","next","id","previous","day","month","year","twentyYears","selected","notAvailable","goTo20YearView","outOfRangeBetween","outOfRangeAfter","outOfRangeBefore"],"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,YAAY,EAAE;IACZP,EAAE,EAAA;GAGH;AACDQ,EAAAA,cAAc,EAAE;IACdR,EAAE,EAAA;GAGH;AACDS,EAAAA,iBAAiB,EAAE;IACjBT,EAAE,EAAA;GAIH;AACDU,EAAAA,eAAe,EAAE;IACfV,EAAE,EAAA;GAGH;AACDW,EAAAA,gBAAgB,EAAE;IAChBX,EAAE,EAAA;AAGH;AACF,CAAA,CAAC;;;;"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { useEffect, useState, useCallback } from 'react';
|
|
1
|
+
import { useId, useRef, useEffect, useState, useCallback } from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { formatDate } from '@transferwise/formatting';
|
|
2
4
|
import '../common/theme.mjs';
|
|
3
5
|
import '../common/direction.mjs';
|
|
4
6
|
import '@transferwise/neptune-tokens';
|
|
@@ -18,17 +20,19 @@ import '../common/PropsValues/variant.mjs';
|
|
|
18
20
|
import '../common/PropsValues/scroll.mjs';
|
|
19
21
|
import '../common/PropsValues/markdownNodeType.mjs';
|
|
20
22
|
import '../common/fileType.mjs';
|
|
21
|
-
import '@transferwise/formatting';
|
|
22
23
|
import '@transferwise/icons';
|
|
23
24
|
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 { isDateDisabled } from '../common/DateUtils/isDateDisabled/isDateDisabled.mjs';
|
|
31
|
+
import { hasDisabledDatesInMonth } from '../common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs';
|
|
32
|
+
import { InlinePrompt } from '../Prompt/InlinePrompt/InlinePrompt.mjs';
|
|
30
33
|
import DayCalendar from './DayCalendar/DayCalendar.mjs';
|
|
31
34
|
import { getStartOfDay } from './GetStartOfDay/GetStartOfDay.mjs';
|
|
35
|
+
import messages from './Calendar.messages.mjs';
|
|
32
36
|
import MonthCalendar from './MonthCalendar/MonthCalendar.mjs';
|
|
33
37
|
import YearCalendar from './YearCalendar/YearCalendar.mjs';
|
|
34
38
|
|
|
@@ -38,17 +42,38 @@ const Calendar = ({
|
|
|
38
42
|
max: maxProp = null,
|
|
39
43
|
monthFormat = MonthFormat.LONG,
|
|
40
44
|
placeholder,
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
disabledRules,
|
|
46
|
+
onDateFocus,
|
|
47
|
+
onChange
|
|
43
48
|
}) => {
|
|
49
|
+
const intl = useIntl();
|
|
44
50
|
const selectedDate = getStartOfDay(value);
|
|
45
51
|
const min = getStartOfDay(minProp);
|
|
46
52
|
const max = getStartOfDay(maxProp);
|
|
53
|
+
const disabledReasonId = useId();
|
|
54
|
+
const disabledRulesRef = useRef(disabledRules);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
disabledRulesRef.current = disabledRules;
|
|
57
|
+
});
|
|
58
|
+
const [focusedDate, setFocusedDate] = useState(selectedDate);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
61
|
+
setFocusedDate(selectedDate);
|
|
62
|
+
}, [selectedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
63
|
+
const checkIsEnabled = date => {
|
|
64
|
+
if (!date) return true;
|
|
65
|
+
return isWithinRange(date, min, max) && !isDateDisabled(date, disabledRulesRef.current);
|
|
66
|
+
};
|
|
67
|
+
const focusedDateDisabled = focusedDate ? !isWithinRange(focusedDate, min, max) || isDateDisabled(focusedDate, disabledRules) : false;
|
|
47
68
|
useEffect(() => {
|
|
48
69
|
if (selectedDate && !isWithinRange(selectedDate, min, max)) {
|
|
49
|
-
|
|
70
|
+
const clamped = moveToWithinRange(selectedDate, min, max);
|
|
71
|
+
setFocusedDate(clamped); // eslint-disable-line react-hooks/set-state-in-effect
|
|
72
|
+
onDateFocus?.(clamped, {
|
|
73
|
+
isEnabled: checkIsEnabled(clamped)
|
|
74
|
+
});
|
|
50
75
|
}
|
|
51
|
-
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(),
|
|
76
|
+
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime(), onDateFocus]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
52
77
|
const dateView = returnDateView(selectedDate, min, max);
|
|
53
78
|
const [viewMonth, setViewMonth] = useState(dateView.getMonth());
|
|
54
79
|
const [viewYear, setViewYear] = useState(dateView.getFullYear());
|
|
@@ -59,6 +84,13 @@ const Calendar = ({
|
|
|
59
84
|
setViewMonth(view.getMonth());
|
|
60
85
|
setViewYear(view.getFullYear());
|
|
61
86
|
}, [selectedDate?.getTime(), min?.getTime(), max?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (focusedDate) {
|
|
89
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
90
|
+
setViewMonth(focusedDate.getMonth());
|
|
91
|
+
setViewYear(focusedDate.getFullYear());
|
|
92
|
+
}
|
|
93
|
+
}, [focusedDate?.getTime()]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
62
94
|
const handleViewDateUpdate = useCallback(
|
|
63
95
|
// eslint-disable-next-line react-hooks/preserve-manual-memoization
|
|
64
96
|
({
|
|
@@ -72,24 +104,31 @@ const Calendar = ({
|
|
|
72
104
|
const switchToMonths = useCallback(() => setMode('month'), []);
|
|
73
105
|
const switchToYears = useCallback(() => setMode('year'), []);
|
|
74
106
|
const handleSelectedDateUpdate = useCallback(date => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
107
|
+
const isEnabled = checkIsEnabled(date);
|
|
108
|
+
setFocusedDate(date);
|
|
109
|
+
onDateFocus?.(date, {
|
|
110
|
+
isEnabled
|
|
111
|
+
});
|
|
112
|
+
if (isEnabled && onChange) {
|
|
78
113
|
onChange(date);
|
|
79
114
|
}
|
|
80
|
-
}, [
|
|
115
|
+
}, [onDateFocus, onChange]);
|
|
81
116
|
const adjustDate = useCallback((daysToAdd, monthsToAdd, yearsToAdd) => {
|
|
117
|
+
const base = focusedDate ?? selectedDate;
|
|
82
118
|
let date;
|
|
83
|
-
if (
|
|
84
|
-
date = new Date(mode === 'year' ?
|
|
119
|
+
if (base) {
|
|
120
|
+
date = new Date(mode === 'year' ? base.getFullYear() + yearsToAdd : base.getFullYear(), mode === 'month' ? base.getMonth() + monthsToAdd : base.getMonth(), mode === 'day' ? base.getDate() + daysToAdd : base.getDate());
|
|
85
121
|
} else {
|
|
86
122
|
date = getStartOfDay(new Date());
|
|
87
123
|
}
|
|
88
124
|
date &&= moveToWithinRange(date, min, max);
|
|
89
|
-
if (date?.getTime() !==
|
|
90
|
-
|
|
125
|
+
if (date?.getTime() !== focusedDate?.getTime()) {
|
|
126
|
+
setFocusedDate(date);
|
|
127
|
+
onDateFocus?.(date, {
|
|
128
|
+
isEnabled: checkIsEnabled(date)
|
|
129
|
+
});
|
|
91
130
|
}
|
|
92
|
-
}, [selectedDate, min, max, mode,
|
|
131
|
+
}, [focusedDate, selectedDate, min, max, mode, onDateFocus]);
|
|
93
132
|
const handleKeyDown = useCallback(event => {
|
|
94
133
|
switch (event.key) {
|
|
95
134
|
case 'ArrowLeft':
|
|
@@ -108,8 +147,36 @@ const Calendar = ({
|
|
|
108
147
|
adjustDate(7, 4, 4);
|
|
109
148
|
event.preventDefault();
|
|
110
149
|
break;
|
|
150
|
+
case 'Enter':
|
|
151
|
+
case ' ':
|
|
152
|
+
if (mode === 'day' && focusedDate && event.target.hasAttribute('data-calendar-cell')) {
|
|
153
|
+
handleSelectedDateUpdate(focusedDate);
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
111
157
|
}
|
|
112
|
-
}, [adjustDate]);
|
|
158
|
+
}, [adjustDate, focusedDate, mode, handleSelectedDateUpdate]);
|
|
159
|
+
const focusedDateOutOfRange = focusedDate ? !isWithinRange(focusedDate, min, max) : false;
|
|
160
|
+
const formatDateForPrompt = date => formatDate(date, intl.locale, {
|
|
161
|
+
day: 'numeric',
|
|
162
|
+
month: 'long',
|
|
163
|
+
year: 'numeric'
|
|
164
|
+
});
|
|
165
|
+
const outOfRangePromptText = min && max ? intl.formatMessage(messages.outOfRangeBetween, {
|
|
166
|
+
min: formatDateForPrompt(min),
|
|
167
|
+
max: formatDateForPrompt(max)
|
|
168
|
+
}) : min ? intl.formatMessage(messages.outOfRangeAfter, {
|
|
169
|
+
min: formatDateForPrompt(min)
|
|
170
|
+
}) : max ? intl.formatMessage(messages.outOfRangeBefore, {
|
|
171
|
+
max: formatDateForPrompt(max)
|
|
172
|
+
}) : '';
|
|
173
|
+
const hasOutOfRangeDates = mode === 'day' && !!(min || max);
|
|
174
|
+
const showRulesPrompt = mode === 'day' && !!disabledRules && hasDisabledDatesInMonth(viewMonth, viewYear, disabledRules, min, max);
|
|
175
|
+
const showOutOfRangePrompt = mode === 'day' && focusedDateOutOfRange;
|
|
176
|
+
const showPrompt = hasOutOfRangeDates || showRulesPrompt;
|
|
177
|
+
const promptText = showOutOfRangePrompt ? outOfRangePromptText : disabledRules?.reason ?? outOfRangePromptText;
|
|
178
|
+
const promptSentiment = showOutOfRangePrompt || focusedDateDisabled ? 'negative' : 'neutral';
|
|
179
|
+
const promptClassName = showOutOfRangePrompt || showRulesPrompt && !showOutOfRangePrompt ? 'm-t-1' : 'sr-only';
|
|
113
180
|
return (
|
|
114
181
|
/*#__PURE__*/
|
|
115
182
|
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
|
|
@@ -117,16 +184,20 @@ const Calendar = ({
|
|
|
117
184
|
onKeyDown: handleKeyDown,
|
|
118
185
|
children: [mode === 'day' && /*#__PURE__*/jsx(DayCalendar, {
|
|
119
186
|
selectedDate: selectedDate,
|
|
187
|
+
focusedDate: focusedDate,
|
|
120
188
|
min: min,
|
|
121
189
|
max: max,
|
|
122
190
|
viewMonth: viewMonth,
|
|
123
191
|
viewYear: viewYear,
|
|
124
192
|
monthFormat: monthFormat,
|
|
193
|
+
disabledRules: disabledRules,
|
|
194
|
+
disabledReasonId: showPrompt ? disabledReasonId : undefined,
|
|
125
195
|
onSelect: handleSelectedDateUpdate,
|
|
126
196
|
onLabelClick: switchToYears,
|
|
127
197
|
onViewDateUpdate: handleViewDateUpdate
|
|
128
198
|
}), mode === 'month' && /*#__PURE__*/jsx(MonthCalendar, {
|
|
129
199
|
selectedDate: selectedDate,
|
|
200
|
+
focusedDate: focusedDate,
|
|
130
201
|
min: min,
|
|
131
202
|
max: max,
|
|
132
203
|
viewYear: viewYear,
|
|
@@ -138,6 +209,7 @@ const Calendar = ({
|
|
|
138
209
|
onViewDateUpdate: handleViewDateUpdate
|
|
139
210
|
}), mode === 'year' && /*#__PURE__*/jsx(YearCalendar, {
|
|
140
211
|
selectedDate: selectedDate,
|
|
212
|
+
focusedDate: focusedDate,
|
|
141
213
|
min: min,
|
|
142
214
|
max: max,
|
|
143
215
|
viewYear: viewYear,
|
|
@@ -146,6 +218,12 @@ const Calendar = ({
|
|
|
146
218
|
}),
|
|
147
219
|
onSelect: switchToMonths,
|
|
148
220
|
onViewDateUpdate: handleViewDateUpdate
|
|
221
|
+
}), showPrompt && /*#__PURE__*/jsx(InlinePrompt, {
|
|
222
|
+
sentiment: promptSentiment,
|
|
223
|
+
width: "full",
|
|
224
|
+
id: disabledReasonId,
|
|
225
|
+
className: promptClassName,
|
|
226
|
+
children: promptText
|
|
149
227
|
})]
|
|
150
228
|
})
|
|
151
229
|
);
|