@cloudscape-design/components-themeable 3.0.895 → 3.0.896
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/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/date-range-picker/calendar/grids/styles.scss +52 -44
- package/lib/internal/scss/date-range-picker/relative-range/styles.scss +0 -9
- package/lib/internal/scss/date-range-picker/styles.scss +2 -47
- package/lib/internal/scss/date-range-picker/test-classes/styles.scss +37 -2
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.d.ts.map +1 -1
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.js +1 -1
- package/lib/internal/template/app-layout/visual-refresh-toolbar/toolbar/trigger-button/index.js.map +1 -1
- package/lib/internal/template/breadcrumb-group/item/item.d.ts.map +1 -1
- package/lib/internal/template/breadcrumb-group/item/item.js +1 -1
- package/lib/internal/template/breadcrumb-group/item/item.js.map +1 -1
- package/lib/internal/template/button/internal.d.ts.map +1 -1
- package/lib/internal/template/button/internal.js +1 -1
- package/lib/internal/template/button/internal.js.map +1 -1
- package/lib/internal/template/button-group/file-input-item.d.ts +5 -3
- package/lib/internal/template/button-group/file-input-item.d.ts.map +1 -1
- package/lib/internal/template/button-group/file-input-item.js +2 -2
- package/lib/internal/template/button-group/file-input-item.js.map +1 -1
- package/lib/internal/template/button-group/icon-button-item.d.ts +5 -3
- package/lib/internal/template/button-group/icon-button-item.d.ts.map +1 -1
- package/lib/internal/template/button-group/icon-button-item.js +2 -2
- package/lib/internal/template/button-group/icon-button-item.js.map +1 -1
- package/lib/internal/template/button-group/icon-toggle-button-item.d.ts +5 -3
- package/lib/internal/template/button-group/icon-toggle-button-item.d.ts.map +1 -1
- package/lib/internal/template/button-group/icon-toggle-button-item.js +2 -2
- package/lib/internal/template/button-group/icon-toggle-button-item.js.map +1 -1
- package/lib/internal/template/button-group/item-element.d.ts.map +1 -1
- package/lib/internal/template/button-group/item-element.js +4 -4
- package/lib/internal/template/button-group/item-element.js.map +1 -1
- package/lib/internal/template/button-group/menu-dropdown-item.d.ts +1 -0
- package/lib/internal/template/button-group/menu-dropdown-item.d.ts.map +1 -1
- package/lib/internal/template/button-group/menu-dropdown-item.js +2 -2
- package/lib/internal/template/button-group/menu-dropdown-item.js.map +1 -1
- package/lib/internal/template/calendar/grid/index.d.ts.map +1 -1
- package/lib/internal/template/calendar/grid/index.js +1 -1
- package/lib/internal/template/calendar/grid/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/grid-cell.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/grid-cell.js +2 -2
- package/lib/internal/template/date-range-picker/calendar/grids/grid-cell.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/grid.d.ts +18 -0
- package/lib/internal/template/date-range-picker/calendar/grids/grid.d.ts.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/grid.js +174 -0
- package/lib/internal/template/date-range-picker/calendar/grids/grid.js.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/index.d.ts +3 -20
- package/lib/internal/template/date-range-picker/calendar/grids/index.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/index.js +51 -22
- package/lib/internal/template/date-range-picker/calendar/grids/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/interfaces.d.ts +47 -0
- package/lib/internal/template/date-range-picker/calendar/grids/interfaces.d.ts.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/interfaces.js +2 -0
- package/lib/internal/template/date-range-picker/calendar/grids/interfaces.js.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/intl.d.ts +17 -0
- package/lib/internal/template/date-range-picker/calendar/grids/intl.d.ts.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/intl.js +56 -0
- package/lib/internal/template/date-range-picker/calendar/grids/intl.js.map +1 -0
- package/lib/internal/template/date-range-picker/calendar/grids/styles.css.js +30 -24
- package/lib/internal/template/date-range-picker/calendar/grids/styles.scoped.css +62 -46
- package/lib/internal/template/date-range-picker/calendar/grids/styles.selectors.js +30 -24
- package/lib/internal/template/date-range-picker/calendar/header/header-button.d.ts +5 -4
- package/lib/internal/template/date-range-picker/calendar/header/header-button.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/header/header-button.js +6 -6
- package/lib/internal/template/date-range-picker/calendar/header/header-button.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/header/index.d.ts +6 -4
- package/lib/internal/template/date-range-picker/calendar/header/index.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/header/index.js +18 -13
- package/lib/internal/template/date-range-picker/calendar/header/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/index.d.ts +2 -1
- package/lib/internal/template/date-range-picker/calendar/index.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/index.js +49 -41
- package/lib/internal/template/date-range-picker/calendar/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/range-inputs.d.ts +4 -3
- package/lib/internal/template/date-range-picker/calendar/range-inputs.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/range-inputs.js +23 -10
- package/lib/internal/template/date-range-picker/calendar/range-inputs.js.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/utils.d.ts +2 -0
- package/lib/internal/template/date-range-picker/calendar/utils.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/calendar/utils.js +27 -1
- package/lib/internal/template/date-range-picker/calendar/utils.js.map +1 -1
- package/lib/internal/template/date-range-picker/dropdown.d.ts +3 -2
- package/lib/internal/template/date-range-picker/dropdown.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/dropdown.js +17 -12
- package/lib/internal/template/date-range-picker/dropdown.js.map +1 -1
- package/lib/internal/template/date-range-picker/index.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/index.js +17 -8
- package/lib/internal/template/date-range-picker/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/interfaces.d.ts +89 -14
- package/lib/internal/template/date-range-picker/interfaces.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/interfaces.js.map +1 -1
- package/lib/internal/template/date-range-picker/mode-switcher.js +2 -2
- package/lib/internal/template/date-range-picker/mode-switcher.js.map +1 -1
- package/lib/internal/template/date-range-picker/relative-range/index.d.ts +2 -1
- package/lib/internal/template/date-range-picker/relative-range/index.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/relative-range/index.js +14 -8
- package/lib/internal/template/date-range-picker/relative-range/index.js.map +1 -1
- package/lib/internal/template/date-range-picker/relative-range/styles.css.js +6 -9
- package/lib/internal/template/date-range-picker/relative-range/styles.scoped.css +10 -19
- package/lib/internal/template/date-range-picker/relative-range/styles.selectors.js +6 -9
- package/lib/internal/template/date-range-picker/styles.css.js +23 -38
- package/lib/internal/template/date-range-picker/styles.scoped.css +32 -78
- package/lib/internal/template/date-range-picker/styles.selectors.js +23 -38
- package/lib/internal/template/date-range-picker/test-classes/styles.css.js +36 -2
- package/lib/internal/template/date-range-picker/test-classes/styles.scoped.css +36 -2
- package/lib/internal/template/date-range-picker/test-classes/styles.selectors.js +36 -2
- package/lib/internal/template/date-range-picker/utils.d.ts +9 -11
- package/lib/internal/template/date-range-picker/utils.d.ts.map +1 -1
- package/lib/internal/template/date-range-picker/utils.js +43 -32
- package/lib/internal/template/date-range-picker/utils.js.map +1 -1
- package/lib/internal/template/file-token-group/file-token.d.ts.map +1 -1
- package/lib/internal/template/file-token-group/file-token.js +1 -1
- package/lib/internal/template/file-token-group/file-token.js.map +1 -1
- package/lib/internal/template/i18n/messages/all.all.js +1 -1
- package/lib/internal/template/i18n/messages/all.all.json +1 -1
- package/lib/internal/template/i18n/messages/all.en.js +1 -1
- package/lib/internal/template/i18n/messages/all.en.json +1 -1
- package/lib/internal/template/i18n/messages-types.d.ts +9 -0
- package/lib/internal/template/i18n/messages-types.d.ts.map +1 -1
- package/lib/internal/template/i18n/messages-types.js.map +1 -1
- package/lib/internal/template/internal/components/tooltip/index.d.ts +2 -1
- package/lib/internal/template/internal/components/tooltip/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/tooltip/index.js +21 -2
- package/lib/internal/template/internal/components/tooltip/index.js.map +1 -1
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/internal/environment.json +1 -1
- package/lib/internal/template/internal/utils/date-time/calendar.d.ts +22 -6
- package/lib/internal/template/internal/utils/date-time/calendar.d.ts.map +1 -1
- package/lib/internal/template/internal/utils/date-time/calendar.js +62 -6
- package/lib/internal/template/internal/utils/date-time/calendar.js.map +1 -1
- package/lib/internal/template/multiselect/index.d.ts.map +1 -1
- package/lib/internal/template/multiselect/index.js +2 -3
- package/lib/internal/template/multiselect/index.js.map +1 -1
- package/lib/internal/template/progress-bar/index.d.ts.map +1 -1
- package/lib/internal/template/progress-bar/index.js +4 -3
- package/lib/internal/template/progress-bar/index.js.map +1 -1
- package/lib/internal/template/progress-bar/internal.js +2 -2
- package/lib/internal/template/progress-bar/internal.js.map +1 -1
- package/lib/internal/template/segmented-control/segment.d.ts.map +1 -1
- package/lib/internal/template/segmented-control/segment.js +1 -1
- package/lib/internal/template/segmented-control/segment.js.map +1 -1
- package/lib/internal/template/select/parts/item.d.ts.map +1 -1
- package/lib/internal/template/select/parts/item.js +4 -2
- package/lib/internal/template/select/parts/item.js.map +1 -1
- package/lib/internal/template/select/parts/multiselect-item.d.ts.map +1 -1
- package/lib/internal/template/select/parts/multiselect-item.js +4 -2
- package/lib/internal/template/select/parts/multiselect-item.js.map +1 -1
- package/lib/internal/template/slider/internal.d.ts.map +1 -1
- package/lib/internal/template/slider/internal.js +1 -1
- package/lib/internal/template/slider/internal.js.map +1 -1
- package/lib/internal/template/tabs/tab-header-bar.d.ts.map +1 -1
- package/lib/internal/template/tabs/tab-header-bar.js +1 -1
- package/lib/internal/template/tabs/tab-header-bar.js.map +1 -1
- package/lib/internal/template/test-utils/dom/date-range-picker/index.d.ts +26 -0
- package/lib/internal/template/test-utils/dom/date-range-picker/index.js +58 -24
- package/lib/internal/template/test-utils/dom/date-range-picker/index.js.map +1 -1
- package/lib/internal/template/test-utils/selectors/date-range-picker/index.d.ts +26 -0
- package/lib/internal/template/test-utils/selectors/date-range-picker/index.js +58 -24
- package/lib/internal/template/test-utils/selectors/date-range-picker/index.js.map +1 -1
- package/lib/internal/template/test-utils/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/lib/internal/template/date-range-picker/calendar/grids/monthly-grid.d.ts +0 -39
- package/lib/internal/template/date-range-picker/calendar/grids/monthly-grid.d.ts.map +0 -1
- package/lib/internal/template/date-range-picker/calendar/grids/monthly-grid.js +0 -97
- package/lib/internal/template/date-range-picker/calendar/grids/monthly-grid.js.map +0 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import React, { useMemo } from 'react';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { isLastDayOfMonth, isSameDay, isSameMonth, isSameYear, isThisMonth, isToday } from 'date-fns';
|
|
6
|
+
import { useInternalI18n } from '../../../i18n/context';
|
|
7
|
+
import ScreenreaderOnly from '../../../internal/components/screenreader-only';
|
|
8
|
+
import { formatDate } from '../../../internal/utils/date-time';
|
|
9
|
+
import { MonthCalendar, YearCalendar } from '../../../internal/utils/date-time/calendar';
|
|
10
|
+
import { normalizeStartOfWeek } from '../../../internal/utils/locale/index.js';
|
|
11
|
+
import { GridCell } from './grid-cell';
|
|
12
|
+
import { renderDateAnnouncement, renderDayName } from './intl';
|
|
13
|
+
import testutilStyles from '../../test-classes/styles.css.js';
|
|
14
|
+
import styles from './styles.css.js';
|
|
15
|
+
const dayUtils = {
|
|
16
|
+
getItemKey: (rowIndex, rowItemIndex) => `${rowIndex}:${rowItemIndex}`,
|
|
17
|
+
isSameItem: (date1, date2) => isSameDay(date1, date2),
|
|
18
|
+
isSamePage: (date1, date2) => isSameMonth(date1, date2),
|
|
19
|
+
checkIfCurrentDay: date => isToday(date),
|
|
20
|
+
checkIfCurrentMonth: () => false,
|
|
21
|
+
checkIfCurrent: date => isToday(date),
|
|
22
|
+
getPageName: () => 'month',
|
|
23
|
+
};
|
|
24
|
+
const monthUtils = {
|
|
25
|
+
getItemKey: (rowIndex, rowItemIndex) => `Month ${rowIndex * 3 + rowItemIndex + 1}`,
|
|
26
|
+
isSameItem: (date1, date2) => isSameMonth(date1, date2),
|
|
27
|
+
isSamePage: (date1, date2) => isSameYear(date1, date2),
|
|
28
|
+
checkIfCurrentDay: () => false,
|
|
29
|
+
checkIfCurrentMonth: date => isThisMonth(date),
|
|
30
|
+
checkIfCurrent: date => isThisMonth(date),
|
|
31
|
+
getPageName: () => 'year',
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Calendar grid supports two mechanisms of keyboard navigation:
|
|
35
|
+
* - Native screen-reader table navigation (semantic table markup);
|
|
36
|
+
* - Keyboard arrow-keys navigation (a custom key-down handler).
|
|
37
|
+
*
|
|
38
|
+
* The implementation largely follows the w3 example (https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/datepicker-dialog) and shares the following issues:
|
|
39
|
+
* - (table navigation) Chrome+VO - weekday is announced twice when navigating to the calendar's header;
|
|
40
|
+
* - (table navigation) Safari+VO - "dimmed" state is announced twice;
|
|
41
|
+
* - (table navigation) Firefox/Chrome+NVDA - cannot use table navigation if any cell has a focus;
|
|
42
|
+
* - (keyboard navigation) Firefox+NVDA - every day is announced as "not selected";
|
|
43
|
+
* - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;
|
|
44
|
+
* - (keyboard navigation) Safari/Chrome+VO - days are not announced as interactive (clickable or selectable);
|
|
45
|
+
* - (keyboard navigation) Safari/Chrome+VO - day announcements are not interruptive and can be missed if navigating fast.
|
|
46
|
+
*/
|
|
47
|
+
export function Grid({ padDates, baseDate, selectedStartDate, selectedEndDate, rangeStartDate, rangeEndDate, focusedDate, focusedDateRef, onSelectDate, onGridKeyDownHandler, onFocusedDateChange, isDateEnabled, dateDisabledReason, locale, todayAriaLabel, currentMonthAriaLabel, ariaLabelledby, className, startOfWeek: rawStartOfWeek = 0, granularity = 'day', }) {
|
|
48
|
+
const baseDateTime = baseDate === null || baseDate === void 0 ? void 0 : baseDate.getTime();
|
|
49
|
+
const i18n = useInternalI18n('date-range-picker');
|
|
50
|
+
const isMonthPicker = granularity === 'month';
|
|
51
|
+
const startOfWeek = normalizeStartOfWeek(rawStartOfWeek, locale);
|
|
52
|
+
const calendar = useMemo(() => {
|
|
53
|
+
const startDate = rangeStartDate !== null && rangeStartDate !== void 0 ? rangeStartDate : rangeEndDate;
|
|
54
|
+
const endDate = rangeEndDate !== null && rangeEndDate !== void 0 ? rangeEndDate : rangeStartDate;
|
|
55
|
+
const selection = startDate && endDate ? [startDate, endDate] : null;
|
|
56
|
+
if (isMonthPicker) {
|
|
57
|
+
const calendarData = new YearCalendar({ baseDate, selection });
|
|
58
|
+
return {
|
|
59
|
+
header: [],
|
|
60
|
+
rows: calendarData.quarters,
|
|
61
|
+
range: calendarData.range,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const calendarData = new MonthCalendar({ padDates, startOfWeek, baseDate, selection });
|
|
65
|
+
return {
|
|
66
|
+
header: calendarData.weekdays,
|
|
67
|
+
rows: calendarData.weeks,
|
|
68
|
+
range: calendarData.range,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
72
|
+
[padDates, startOfWeek, baseDateTime, rangeStartDate, rangeEndDate]);
|
|
73
|
+
const currentAnnouncement = i18n(isMonthPicker ? 'i18nStrings.currentMonthAriaLabel' : 'i18nStrings.todayAriaLabel', isMonthPicker ? currentMonthAriaLabel : todayAriaLabel);
|
|
74
|
+
return (React.createElement("table", { role: "grid", "aria-labelledby": ariaLabelledby, className: clsx(styles.grid, className) },
|
|
75
|
+
!isMonthPicker && (React.createElement("thead", null,
|
|
76
|
+
React.createElement("tr", null, calendar.header.map(dayIndex => (React.createElement("th", { key: dayIndex, scope: "col", className: clsx(styles['grid-cell'], styles['day-header'], testutilStyles['day-header']) },
|
|
77
|
+
React.createElement("span", { "aria-hidden": "true" }, renderDayName(locale, dayIndex, 'short')),
|
|
78
|
+
React.createElement(ScreenreaderOnly, null, renderDayName(locale, dayIndex, 'long')))))))),
|
|
79
|
+
React.createElement("tbody", { onKeyDown: onGridKeyDownHandler }, calendar.rows.map((row, rowIndex) => {
|
|
80
|
+
const rowItems = isMonthPicker ? row.months : row.days;
|
|
81
|
+
const weekTestIndex = !isMonthPicker ? row.testIndex : undefined;
|
|
82
|
+
return (React.createElement("tr", Object.assign({ key: rowIndex, className: clsx({
|
|
83
|
+
[testutilStyles['calendar-quarter']]: isMonthPicker,
|
|
84
|
+
[testutilStyles['calendar-week']]: !isMonthPicker,
|
|
85
|
+
}) }, (!isMonthPicker && weekTestIndex
|
|
86
|
+
? {
|
|
87
|
+
['data-awsui-weekindex']: weekTestIndex,
|
|
88
|
+
}
|
|
89
|
+
: {})), rowItems.map(({ date, isVisible, isInRange, isSelectionTop, isSelectionBottom, isSelectionLeft, isSelectionRight }, rowItemIndex) => {
|
|
90
|
+
const { getItemKey, isSameItem, isSamePage, checkIfCurrent, checkIfCurrentDay, checkIfCurrentMonth, getPageName, } = isMonthPicker ? monthUtils : dayUtils;
|
|
91
|
+
const itemKey = getItemKey(rowIndex, rowItemIndex);
|
|
92
|
+
const pageName = getPageName();
|
|
93
|
+
const isCurrentDay = checkIfCurrentDay(date);
|
|
94
|
+
const isCurrentMonth = checkIfCurrentMonth(date);
|
|
95
|
+
const isCurrent = checkIfCurrent(date);
|
|
96
|
+
const isStartDate = !!selectedStartDate && isSameItem(date, selectedStartDate);
|
|
97
|
+
const isEndDate = !!selectedEndDate && isSameItem(date, selectedEndDate);
|
|
98
|
+
const isSelected = isStartDate || isEndDate;
|
|
99
|
+
const isFocused = !!focusedDate && isSameItem(date, focusedDate) && isSamePage(date, baseDate);
|
|
100
|
+
const onlyOneSelected = !!rangeStartDate && !!rangeEndDate
|
|
101
|
+
? isSameItem(rangeStartDate, rangeEndDate)
|
|
102
|
+
: !selectedStartDate || !selectedEndDate;
|
|
103
|
+
const isEnabled = (!isDateEnabled || isDateEnabled(date)) && isSamePage(date, baseDate);
|
|
104
|
+
const disabledReason = dateDisabledReason(date);
|
|
105
|
+
const isDisabledWithReason = !isEnabled && !!disabledReason;
|
|
106
|
+
const isFocusable = isFocused && (isEnabled || isDisabledWithReason);
|
|
107
|
+
const baseClasses = {
|
|
108
|
+
[testutilStyles['calendar-date']]: !isMonthPicker && isSameMonth(date, baseDate),
|
|
109
|
+
[testutilStyles['calendar-month']]: isMonthPicker && isSameYear(date, baseDate),
|
|
110
|
+
[styles.day]: !isMonthPicker,
|
|
111
|
+
[styles.month]: isMonthPicker,
|
|
112
|
+
[styles['grid-cell']]: true,
|
|
113
|
+
[styles['in-first-row']]: rowIndex === 0,
|
|
114
|
+
[styles['in-first-column']]: rowItemIndex === 0,
|
|
115
|
+
};
|
|
116
|
+
if (!isVisible) {
|
|
117
|
+
return (React.createElement("td", { key: itemKey, ref: isFocused ? focusedDateRef : undefined, className: clsx(baseClasses, {
|
|
118
|
+
[styles[`last-day-of-month`]]: !isMonthPicker && isLastDayOfMonth(date),
|
|
119
|
+
[styles[`last-month-of-year`]]: isMonthPicker && date.getMonth() === 11,
|
|
120
|
+
}) }));
|
|
121
|
+
}
|
|
122
|
+
const handlers = {};
|
|
123
|
+
if (isEnabled) {
|
|
124
|
+
handlers.onClick = () => onSelectDate(date);
|
|
125
|
+
handlers.onFocus = () => onFocusedDateChange(date);
|
|
126
|
+
}
|
|
127
|
+
// Screen-reader announcement for the focused day/month.
|
|
128
|
+
let announcement = renderDateAnnouncement({
|
|
129
|
+
date,
|
|
130
|
+
isCurrent,
|
|
131
|
+
locale,
|
|
132
|
+
granularity,
|
|
133
|
+
});
|
|
134
|
+
if (currentAnnouncement) {
|
|
135
|
+
if (isMonthPicker && isThisMonth(date)) {
|
|
136
|
+
announcement += `. ${currentAnnouncement}`;
|
|
137
|
+
}
|
|
138
|
+
else if (!isMonthPicker && isToday(date)) {
|
|
139
|
+
announcement += `. ${currentAnnouncement}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Can't be focused.
|
|
143
|
+
let tabIndex = undefined;
|
|
144
|
+
if (isEnabled || isDisabledWithReason) {
|
|
145
|
+
tabIndex = isFocusable
|
|
146
|
+
? 0 // Next focus target.
|
|
147
|
+
: -1; // Can be focused programmatically.
|
|
148
|
+
}
|
|
149
|
+
return (React.createElement(GridCell, Object.assign({ ref: isFocused ? focusedDateRef : undefined, key: itemKey, className: clsx(baseClasses, {
|
|
150
|
+
[styles['in-visible-calendar']]: true,
|
|
151
|
+
[styles[`in-current-${pageName}`]]: isSamePage(date, baseDate),
|
|
152
|
+
[styles.enabled]: isEnabled,
|
|
153
|
+
[styles.selected]: isSelected,
|
|
154
|
+
[styles['start-date']]: isStartDate,
|
|
155
|
+
[styles['end-date']]: isEndDate,
|
|
156
|
+
[testutilStyles['start-date']]: isStartDate,
|
|
157
|
+
[testutilStyles['end-date']]: isEndDate,
|
|
158
|
+
[styles['no-range']]: isSelected && onlyOneSelected,
|
|
159
|
+
[styles['in-range']]: isInRange,
|
|
160
|
+
[styles['in-range-border-block-start']]: isSelectionTop,
|
|
161
|
+
[styles['in-range-border-block-end']]: isSelectionBottom,
|
|
162
|
+
[styles['in-range-border-inline-start']]: isSelectionLeft,
|
|
163
|
+
[styles['in-range-border-inline-end']]: isSelectionRight,
|
|
164
|
+
[styles.today]: isCurrentDay,
|
|
165
|
+
[testutilStyles.today]: isCurrentDay,
|
|
166
|
+
[styles['this-month']]: isCurrentMonth,
|
|
167
|
+
[testutilStyles['this-month']]: isCurrentMonth,
|
|
168
|
+
}), "aria-selected": isEnabled ? isSelected || isInRange : undefined, "aria-current": isCurrent ? 'date' : undefined, "data-date": formatDate(date, granularity), "aria-disabled": !isEnabled, tabIndex: tabIndex, disabledReason: isDisabledWithReason ? disabledReason : undefined }, handlers),
|
|
169
|
+
React.createElement("span", { className: styles[`${granularity}-inner`], "aria-hidden": "true" }, isMonthPicker ? date.toLocaleString(locale, { month: 'short' }) : date.getDate()),
|
|
170
|
+
React.createElement(ScreenreaderOnly, null, announcement)));
|
|
171
|
+
})));
|
|
172
|
+
}))));
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/grid.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,gBAAgB,MAAM,gDAAgD,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAiC,aAAa,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AACxH,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE/D,OAAO,cAAc,MAAM,kCAAkC,CAAC;AAC9D,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAYrC,MAAM,QAAQ,GAAoB;IAChC,UAAU,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,EAAE,CAAC,GAAG,QAA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,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,eACjC,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,mBACzB,CAAC,SAAS,EACzB,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,oBAAoB,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,IAC7D,QAAQ;oBAEZ,8BAAM,SAAS,EAAE,MAAM,CAAC,GAAG,WAAW,QAAQ,CAAC,iBAAc,MAAM,IAChE,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,CAC5E;oBACP,oBAAC,gBAAgB,QAAE,YAAY,CAAoB,CAC1C,CACZ,CAAC;YACJ,CAAC,CACF,CACE,CACN,CAAC;QACJ,CAAC,CAAC,CACI,CACF,CACT,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useMemo } from 'react';\nimport clsx from 'clsx';\nimport { isLastDayOfMonth, isSameDay, isSameMonth, isSameYear, isThisMonth, isToday } from 'date-fns';\n\nimport { useInternalI18n } from '../../../i18n/context';\nimport ScreenreaderOnly from '../../../internal/components/screenreader-only';\nimport { formatDate } from '../../../internal/utils/date-time';\nimport { CalendarQuarter, CalendarWeek, MonthCalendar, YearCalendar } from '../../../internal/utils/date-time/calendar';\nimport { normalizeStartOfWeek } from '../../../internal/utils/locale/index.js';\nimport { GridCell } from './grid-cell';\nimport { GridProps } from './interfaces';\nimport { renderDateAnnouncement, renderDayName } from './intl';\n\nimport testutilStyles from '../../test-classes/styles.css.js';\nimport styles from './styles.css.js';\n\ninterface DatePickerUtils {\n getItemKey: (rowIndex: number, rowItemIndex: number) => string;\n isSameItem: (date1: Date, date2: Date) => boolean;\n isSamePage: (date1: Date, date2: Date) => boolean;\n checkIfCurrentDay: (date: Date) => boolean;\n checkIfCurrentMonth: (date: Date) => boolean;\n checkIfCurrent: (date: Date) => boolean;\n getPageName: () => string;\n}\n\nconst dayUtils: DatePickerUtils = {\n getItemKey: (rowIndex, rowItemIndex) => `${rowIndex}:${rowItemIndex}`,\n isSameItem: (date1: Date, date2: Date) => isSameDay(date1, date2),\n isSamePage: (date1: Date, date2: Date) => isSameMonth(date1, date2),\n checkIfCurrentDay: date => isToday(date),\n checkIfCurrentMonth: () => false,\n checkIfCurrent: date => isToday(date),\n getPageName: () => 'month',\n};\n\nconst monthUtils: DatePickerUtils = {\n getItemKey: (rowIndex, rowItemIndex) => `Month ${rowIndex * 3 + rowItemIndex + 1}`,\n isSameItem: (date1: Date, date2: Date) => isSameMonth(date1, date2),\n isSamePage: (date1: Date, date2: Date) => isSameYear(date1, date2),\n checkIfCurrentDay: () => false,\n checkIfCurrentMonth: date => isThisMonth(date),\n checkIfCurrent: date => isThisMonth(date),\n getPageName: () => 'year',\n};\n\n/**\n * Calendar grid supports two mechanisms of keyboard navigation:\n * - Native screen-reader table navigation (semantic table markup);\n * - Keyboard arrow-keys navigation (a custom key-down handler).\n *\n * The implementation largely follows the w3 example (https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/datepicker-dialog) and shares the following issues:\n * - (table navigation) Chrome+VO - weekday is announced twice when navigating to the calendar's header;\n * - (table navigation) Safari+VO - \"dimmed\" state is announced twice;\n * - (table navigation) Firefox/Chrome+NVDA - cannot use table navigation if any cell has a focus;\n * - (keyboard navigation) Firefox+NVDA - every day is announced as \"not selected\";\n * - (keyboard navigation) Safari/Chrome+VO - weekdays are not announced;\n * - (keyboard navigation) Safari/Chrome+VO - days are not announced as interactive (clickable or selectable);\n * - (keyboard navigation) Safari/Chrome+VO - day announcements are not interruptive and can be missed if navigating fast.\n */\n\nexport function Grid({\n padDates,\n baseDate,\n selectedStartDate,\n selectedEndDate,\n rangeStartDate,\n rangeEndDate,\n focusedDate,\n\n focusedDateRef,\n\n onSelectDate,\n onGridKeyDownHandler,\n onFocusedDateChange,\n\n isDateEnabled,\n dateDisabledReason,\n\n locale,\n todayAriaLabel,\n currentMonthAriaLabel,\n ariaLabelledby,\n className,\n startOfWeek: rawStartOfWeek = 0,\n granularity = 'day',\n}: GridProps) {\n const baseDateTime = baseDate?.getTime();\n const i18n = useInternalI18n('date-range-picker');\n const isMonthPicker = granularity === 'month';\n const startOfWeek = normalizeStartOfWeek(rawStartOfWeek, locale);\n const calendar = useMemo(\n () => {\n const startDate = rangeStartDate ?? rangeEndDate;\n const endDate = rangeEndDate ?? rangeStartDate;\n const selection = startDate && endDate ? ([startDate, endDate] as [Date, Date]) : null;\n if (isMonthPicker) {\n const calendarData = new YearCalendar({ baseDate, selection });\n return {\n header: [],\n rows: calendarData.quarters,\n range: calendarData.range,\n };\n }\n\n const calendarData = new MonthCalendar({ padDates, startOfWeek, baseDate, selection });\n return {\n header: calendarData.weekdays,\n rows: calendarData.weeks,\n range: calendarData.range,\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [padDates, startOfWeek, baseDateTime, rangeStartDate, rangeEndDate]\n );\n\n const currentAnnouncement = i18n(\n isMonthPicker ? 'i18nStrings.currentMonthAriaLabel' : 'i18nStrings.todayAriaLabel',\n isMonthPicker ? currentMonthAriaLabel : todayAriaLabel\n );\n\n return (\n <table role=\"grid\" aria-labelledby={ariaLabelledby} className={clsx(styles.grid, className)}>\n {!isMonthPicker && (\n <thead>\n <tr>\n {calendar.header.map(dayIndex => (\n <th\n key={dayIndex}\n scope=\"col\"\n className={clsx(styles['grid-cell'], styles['day-header'], testutilStyles['day-header'])}\n >\n <span aria-hidden=\"true\">{renderDayName(locale, dayIndex, 'short')}</span>\n <ScreenreaderOnly>{renderDayName(locale, dayIndex, 'long')}</ScreenreaderOnly>\n </th>\n ))}\n </tr>\n </thead>\n )}\n <tbody onKeyDown={onGridKeyDownHandler}>\n {calendar.rows.map((row, rowIndex) => {\n const rowItems = isMonthPicker ? (row as CalendarQuarter).months : (row as CalendarWeek).days;\n const weekTestIndex = !isMonthPicker ? (row as CalendarWeek).testIndex : undefined;\n return (\n <tr\n key={rowIndex}\n className={clsx({\n [testutilStyles['calendar-quarter']]: isMonthPicker,\n [testutilStyles['calendar-week']]: !isMonthPicker,\n })}\n {...(!isMonthPicker && weekTestIndex\n ? {\n ['data-awsui-weekindex']: weekTestIndex,\n }\n : {})}\n >\n {rowItems.map(\n (\n { date, isVisible, isInRange, isSelectionTop, isSelectionBottom, isSelectionLeft, isSelectionRight },\n rowItemIndex\n ) => {\n const {\n getItemKey,\n isSameItem,\n isSamePage,\n checkIfCurrent,\n checkIfCurrentDay,\n checkIfCurrentMonth,\n getPageName,\n } = isMonthPicker ? monthUtils : dayUtils;\n const itemKey = getItemKey(rowIndex, rowItemIndex);\n const pageName = getPageName();\n const isCurrentDay = checkIfCurrentDay(date);\n const isCurrentMonth = checkIfCurrentMonth(date);\n const isCurrent = checkIfCurrent(date);\n const isStartDate = !!selectedStartDate && isSameItem(date, selectedStartDate);\n const isEndDate = !!selectedEndDate && isSameItem(date, selectedEndDate);\n const isSelected = isStartDate || isEndDate;\n\n const isFocused = !!focusedDate && isSameItem(date, focusedDate) && isSamePage(date, baseDate);\n\n const onlyOneSelected =\n !!rangeStartDate && !!rangeEndDate\n ? isSameItem(rangeStartDate, rangeEndDate)\n : !selectedStartDate || !selectedEndDate;\n\n const isEnabled = (!isDateEnabled || isDateEnabled(date)) && isSamePage(date, baseDate);\n const disabledReason = dateDisabledReason(date);\n\n const isDisabledWithReason = !isEnabled && !!disabledReason;\n const isFocusable = isFocused && (isEnabled || isDisabledWithReason);\n\n const baseClasses = {\n [testutilStyles['calendar-date']]: !isMonthPicker && isSameMonth(date, baseDate),\n [testutilStyles['calendar-month']]: isMonthPicker && isSameYear(date, baseDate),\n [styles.day]: !isMonthPicker,\n [styles.month]: isMonthPicker,\n [styles['grid-cell']]: true,\n [styles['in-first-row']]: rowIndex === 0,\n [styles['in-first-column']]: rowItemIndex === 0,\n };\n\n if (!isVisible) {\n return (\n <td\n key={itemKey}\n ref={isFocused ? focusedDateRef : undefined}\n className={clsx(baseClasses, {\n [styles[`last-day-of-month`]]: !isMonthPicker && isLastDayOfMonth(date),\n [styles[`last-month-of-year`]]: isMonthPicker && date.getMonth() === 11,\n })}\n />\n );\n }\n\n const handlers: React.HTMLAttributes<HTMLDivElement> = {};\n if (isEnabled) {\n handlers.onClick = () => onSelectDate(date);\n handlers.onFocus = () => onFocusedDateChange(date);\n }\n\n // Screen-reader announcement for the focused day/month.\n let announcement = renderDateAnnouncement({\n date,\n isCurrent,\n locale,\n granularity,\n });\n\n if (currentAnnouncement) {\n if (isMonthPicker && isThisMonth(date)) {\n announcement += `. ${currentAnnouncement}`;\n } else if (!isMonthPicker && isToday(date)) {\n announcement += `. ${currentAnnouncement}`;\n }\n }\n\n // Can't be focused.\n let tabIndex: number | undefined = undefined;\n if (isEnabled || isDisabledWithReason) {\n tabIndex = isFocusable\n ? 0 // Next focus target.\n : -1; // Can be focused programmatically.\n }\n\n return (\n <GridCell\n ref={isFocused ? focusedDateRef : undefined}\n key={itemKey}\n className={clsx(baseClasses, {\n [styles['in-visible-calendar']]: true,\n [styles[`in-current-${pageName}`]]: isSamePage(date, baseDate),\n [styles.enabled]: isEnabled,\n [styles.selected]: isSelected,\n [styles['start-date']]: isStartDate,\n [styles['end-date']]: isEndDate,\n [testutilStyles['start-date']]: isStartDate,\n [testutilStyles['end-date']]: isEndDate,\n [styles['no-range']]: isSelected && onlyOneSelected,\n [styles['in-range']]: isInRange,\n [styles['in-range-border-block-start']]: isSelectionTop,\n [styles['in-range-border-block-end']]: isSelectionBottom,\n [styles['in-range-border-inline-start']]: isSelectionLeft,\n [styles['in-range-border-inline-end']]: isSelectionRight,\n [styles.today]: isCurrentDay,\n [testutilStyles.today]: isCurrentDay,\n [styles['this-month']]: isCurrentMonth,\n [testutilStyles['this-month']]: isCurrentMonth,\n })}\n aria-selected={isEnabled ? isSelected || isInRange : undefined}\n aria-current={isCurrent ? 'date' : undefined}\n data-date={formatDate(date, granularity)}\n aria-disabled={!isEnabled}\n tabIndex={tabIndex}\n disabledReason={isDisabledWithReason ? disabledReason : undefined}\n {...handlers}\n >\n <span className={styles[`${granularity}-inner`]} aria-hidden=\"true\">\n {isMonthPicker ? date.toLocaleString(locale, { month: 'short' }) : date.getDate()}\n </span>\n <ScreenreaderOnly>{announcement}</ScreenreaderOnly>\n </GridCell>\n );\n }\n )}\n </tr>\n );\n })}\n </tbody>\n </table>\n );\n}\n"]}
|
|
@@ -1,21 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
baseDate: Date;
|
|
5
|
-
selectedStartDate: Date | null;
|
|
6
|
-
selectedEndDate: Date | null;
|
|
7
|
-
focusedDate: Date | null;
|
|
8
|
-
onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;
|
|
9
|
-
isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;
|
|
10
|
-
dateDisabledReason: DateRangePickerProps.DateDisabledReasonFunction;
|
|
11
|
-
isSingleGrid: boolean;
|
|
12
|
-
onSelectDate: (date: Date) => void;
|
|
13
|
-
onChangeMonth: (date: Date) => void;
|
|
14
|
-
locale: string;
|
|
15
|
-
startOfWeek: DayIndex;
|
|
16
|
-
todayAriaLabel?: string;
|
|
17
|
-
headingIdPrefix: string;
|
|
18
|
-
}
|
|
19
|
-
export declare const Grids: ({ baseDate, selectedStartDate, selectedEndDate, focusedDate, onFocusedDateChange, isDateEnabled, dateDisabledReason, isSingleGrid, onSelectDate, onChangeMonth, locale, startOfWeek, todayAriaLabel, headingIdPrefix, }: GridProps) => JSX.Element;
|
|
20
|
-
export {};
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SelectGridProps } from './interfaces';
|
|
3
|
+
export declare const Grids: ({ baseDate, selectedStartDate, selectedEndDate, focusedDate, onFocusedDateChange, isDateEnabled, dateDisabledReason, isSingleGrid, onSelectDate, onPageChange, locale, todayAriaLabel, currentMonthAriaLabel, headingIdPrefix, startOfWeek, granularity, }: SelectGridProps) => JSX.Element;
|
|
21
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":";AA2BA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAgB/C,eAAO,MAAM,KAAK,+PAqBf,eAAe,gBAkJjB,CAAC"}
|
|
@@ -1,27 +1,37 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
-
import { addMonths, isAfter, isBefore, isSameMonth, max, min } from 'date-fns';
|
|
4
|
+
import { addMonths, addYears, isAfter, isBefore, isSameMonth, isSameYear, max, min } from 'date-fns';
|
|
5
5
|
import { getBaseDay, moveNextDay, moveNextWeek, movePrevDay, movePrevWeek, } from '../../../calendar/utils/navigation-day';
|
|
6
|
+
import { getBaseMonth, moveMonthDown, moveMonthUp, moveNextMonth, movePrevMonth, } from '../../../calendar/utils/navigation-month';
|
|
6
7
|
import { useDateCache } from '../../../internal/hooks/use-date-cache';
|
|
7
8
|
import { KeyCode } from '../../../internal/keycode';
|
|
8
9
|
import handleKey from '../../../internal/utils/handle-key';
|
|
9
10
|
import { hasValue } from '../../../internal/utils/has-value';
|
|
10
11
|
import InternalSpaceBetween from '../../../space-between/internal';
|
|
11
12
|
import { findDateToFocus } from '../utils';
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
function isVisible(date, baseDate, isSingleGrid) {
|
|
13
|
+
import { Grid } from './grid';
|
|
14
|
+
import testutilStyles from '../../test-classes/styles.css.js';
|
|
15
|
+
function isVisible(date, baseDate, isSingleGrid, granularity) {
|
|
16
|
+
const isSame = granularity === 'day' ? isSameMonth : isSameYear;
|
|
17
|
+
const add = granularity === 'day' ? addMonths : addYears;
|
|
15
18
|
if (isSingleGrid) {
|
|
16
|
-
return
|
|
19
|
+
return isSame(date, baseDate);
|
|
17
20
|
}
|
|
18
|
-
const
|
|
19
|
-
return
|
|
21
|
+
const previous = add(baseDate, -1);
|
|
22
|
+
return isSame(date, previous) || isSame(date, baseDate);
|
|
20
23
|
}
|
|
21
|
-
export const Grids = ({ baseDate, selectedStartDate, selectedEndDate, focusedDate, onFocusedDateChange, isDateEnabled, dateDisabledReason, isSingleGrid, onSelectDate,
|
|
24
|
+
export const Grids = ({ baseDate, selectedStartDate, selectedEndDate, focusedDate, onFocusedDateChange, isDateEnabled, dateDisabledReason, isSingleGrid, onSelectDate, onPageChange, locale, todayAriaLabel, currentMonthAriaLabel, headingIdPrefix, startOfWeek = 0, granularity = 'day', }) => {
|
|
22
25
|
const containerRef = useRef(null);
|
|
23
26
|
const [gridHasFocus, setGridHasFocus] = useState(false);
|
|
27
|
+
const isMonthPicker = granularity === 'month';
|
|
24
28
|
const focusedDateRef = useRef(null);
|
|
29
|
+
const addPages = !isMonthPicker ? addMonths : addYears;
|
|
30
|
+
const getBase = !isMonthPicker ? getBaseDay : getBaseMonth;
|
|
31
|
+
const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;
|
|
32
|
+
const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;
|
|
33
|
+
const moveRight = isMonthPicker ? moveNextMonth : moveNextDay;
|
|
34
|
+
const moveUp = isMonthPicker ? moveMonthUp : movePrevWeek;
|
|
25
35
|
const dateCache = useDateCache();
|
|
26
36
|
baseDate = dateCache(baseDate);
|
|
27
37
|
focusedDate = focusedDate ? dateCache(focusedDate) : null;
|
|
@@ -29,16 +39,16 @@ export const Grids = ({ baseDate, selectedStartDate, selectedEndDate, focusedDat
|
|
|
29
39
|
return isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));
|
|
30
40
|
}, [isDateEnabled, dateDisabledReason]);
|
|
31
41
|
useEffect(() => {
|
|
32
|
-
if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid)) {
|
|
42
|
+
if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid, granularity)) {
|
|
33
43
|
const direction = isAfter(focusedDate, baseDate) ? -1 : 1;
|
|
34
|
-
const
|
|
35
|
-
const nearestBaseDate =
|
|
44
|
+
const newPage = !isSingleGrid && direction === -1 ? addPages(baseDate, -1) : baseDate;
|
|
45
|
+
const nearestBaseDate = getBase(newPage, isDateFocusable);
|
|
36
46
|
const newFocusedDate = findDateToFocus(focusedDate, nearestBaseDate, isDateFocusable);
|
|
37
47
|
onFocusedDateChange(newFocusedDate);
|
|
38
48
|
}
|
|
39
|
-
}, [baseDate, focusedDate, isSingleGrid, isDateFocusable, onFocusedDateChange]);
|
|
49
|
+
}, [baseDate, focusedDate, isSingleGrid, granularity, addPages, isDateFocusable, onFocusedDateChange, getBase]);
|
|
40
50
|
const onGridKeyDownHandler = (event) => {
|
|
41
|
-
let updatedFocusDate;
|
|
51
|
+
let updatedFocusDate = null;
|
|
42
52
|
const keys = [KeyCode.up, KeyCode.down, KeyCode.left, KeyCode.right, KeyCode.space, KeyCode.enter];
|
|
43
53
|
if (focusedDate === null || keys.indexOf(event.keyCode) === -1) {
|
|
44
54
|
return;
|
|
@@ -51,18 +61,18 @@ export const Grids = ({ baseDate, selectedStartDate, selectedEndDate, focusedDat
|
|
|
51
61
|
}
|
|
52
62
|
onSelectDate(focusedDate);
|
|
53
63
|
},
|
|
54
|
-
onBlockEnd: () => focusedDate && (updatedFocusDate =
|
|
55
|
-
onBlockStart: () => focusedDate && (updatedFocusDate =
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
onBlockEnd: () => focusedDate && (updatedFocusDate = moveDown(focusedDate, isDateFocusable)),
|
|
65
|
+
onBlockStart: () => focusedDate && (updatedFocusDate = moveUp(focusedDate, isDateFocusable)),
|
|
66
|
+
onInlineStart: () => focusedDate && (updatedFocusDate = moveLeft(focusedDate, isDateFocusable)),
|
|
67
|
+
onInlineEnd: () => focusedDate && (updatedFocusDate = moveRight(focusedDate, isDateFocusable)),
|
|
58
68
|
});
|
|
59
69
|
if (!updatedFocusDate) {
|
|
60
70
|
return;
|
|
61
71
|
}
|
|
62
|
-
const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid);
|
|
72
|
+
const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid, granularity);
|
|
63
73
|
if (!updatedDateIsVisible) {
|
|
64
|
-
const
|
|
65
|
-
|
|
74
|
+
const newPageIsOnLeftSide = !isSingleGrid && isBefore(updatedFocusDate, baseDate);
|
|
75
|
+
onPageChange(newPageIsOnLeftSide ? addPages(updatedFocusDate, 1) : updatedFocusDate);
|
|
66
76
|
}
|
|
67
77
|
onFocusedDateChange(updatedFocusDate);
|
|
68
78
|
};
|
|
@@ -91,9 +101,28 @@ export const Grids = ({ baseDate, selectedStartDate, selectedEndDate, focusedDat
|
|
|
91
101
|
const rangeEnds = [selectedStartDate !== null && selectedStartDate !== void 0 ? selectedStartDate : focusedDate, selectedEndDate !== null && selectedEndDate !== void 0 ? selectedEndDate : focusedDate].filter(hasValue);
|
|
92
102
|
const rangeStartDate = min(rangeEnds);
|
|
93
103
|
const rangeEndDate = max(rangeEnds);
|
|
104
|
+
const pageUnit = isMonthPicker ? 'year' : 'month';
|
|
105
|
+
const sharedGridProps = {
|
|
106
|
+
selectedEndDate,
|
|
107
|
+
selectedStartDate,
|
|
108
|
+
focusedDate,
|
|
109
|
+
focusedDateRef,
|
|
110
|
+
rangeStartDate: isRangeVisible ? rangeStartDate : null,
|
|
111
|
+
rangeEndDate: isRangeVisible ? rangeEndDate : null,
|
|
112
|
+
isDateEnabled,
|
|
113
|
+
dateDisabledReason,
|
|
114
|
+
onSelectDate,
|
|
115
|
+
onGridKeyDownHandler,
|
|
116
|
+
onFocusedDateChange,
|
|
117
|
+
locale,
|
|
118
|
+
granularity,
|
|
119
|
+
currentMonthAriaLabel,
|
|
120
|
+
startOfWeek,
|
|
121
|
+
todayAriaLabel,
|
|
122
|
+
};
|
|
94
123
|
return (React.createElement("div", { ref: containerRef, onFocus: onGridFocus, onBlur: onGridBlur },
|
|
95
124
|
React.createElement(InternalSpaceBetween, { size: "xs", direction: "horizontal" },
|
|
96
|
-
!isSingleGrid && (React.createElement(
|
|
97
|
-
React.createElement(
|
|
125
|
+
!isSingleGrid && (React.createElement(Grid, Object.assign({}, sharedGridProps, { padDates: 'before', className: testutilStyles['first-grid'], baseDate: addPages(baseDate, -1), ariaLabelledby: `${headingIdPrefix}-prev${pageUnit}` }))),
|
|
126
|
+
React.createElement(Grid, Object.assign({}, sharedGridProps, { padDates: 'after', className: testutilStyles['second-grid'], baseDate: baseDate, ariaLabelledby: `${headingIdPrefix}-current${pageUnit}` })))));
|
|
98
127
|
};
|
|
99
128
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/E,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,O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AE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,GAAG,eAAe,eAAe,GACjD,CACmB,CACnB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { addMonths, isAfter, isBefore, isSameMonth, max, min } from 'date-fns';\n\nimport {\n getBaseDay,\n moveNextDay,\n moveNextWeek,\n movePrevDay,\n movePrevWeek,\n} from '../../../calendar/utils/navigation-day';\nimport { useDateCache } from '../../../internal/hooks/use-date-cache';\nimport { KeyCode } from '../../../internal/keycode';\nimport handleKey from '../../../internal/utils/handle-key';\nimport { hasValue } from '../../../internal/utils/has-value';\nimport InternalSpaceBetween from '../../../space-between/internal';\nimport { DateRangePickerProps, DayIndex } from '../../interfaces';\nimport { findDateToFocus } from '../utils';\nimport { MonthlyGrid } from './monthly-grid';\n\nimport styles from '../../styles.css.js';\n\nfunction isVisible(date: Date, baseDate: Date, isSingleGrid: boolean) {\n if (isSingleGrid) {\n return isSameMonth(date, baseDate);\n }\n\n const previousMonth = addMonths(baseDate, -1);\n\n return isSameMonth(date, previousMonth) || isSameMonth(date, baseDate);\n}\n\ninterface GridProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n\n focusedDate: Date | null;\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n dateDisabledReason: DateRangePickerProps.DateDisabledReasonFunction;\n isSingleGrid: boolean;\n\n onSelectDate: (date: Date) => void;\n onChangeMonth: (date: Date) => void;\n\n locale: string;\n startOfWeek: DayIndex;\n todayAriaLabel?: string;\n headingIdPrefix: string;\n}\n\nexport const Grids = ({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n\n focusedDate,\n onFocusedDateChange,\n\n isDateEnabled,\n dateDisabledReason,\n isSingleGrid,\n\n onSelectDate,\n onChangeMonth,\n\n locale,\n startOfWeek,\n todayAriaLabel,\n headingIdPrefix,\n}: GridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n const dateCache = useDateCache();\n baseDate = dateCache(baseDate);\n focusedDate = focusedDate ? dateCache(focusedDate) : null;\n\n const isDateFocusable = useCallback(\n (date: Date) => {\n return isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));\n },\n [isDateEnabled, dateDisabledReason]\n );\n\n useEffect(() => {\n if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid)) {\n const direction = isAfter(focusedDate, baseDate) ? -1 : 1;\n\n const newMonth = !isSingleGrid && direction === -1 ? addMonths(baseDate, -1) : baseDate;\n const nearestBaseDate = getBaseDay(newMonth, isDateFocusable);\n\n const newFocusedDate = findDateToFocus(focusedDate, nearestBaseDate, isDateFocusable);\n\n onFocusedDateChange(newFocusedDate);\n }\n }, [baseDate, focusedDate, isSingleGrid, isDateFocusable, onFocusedDateChange]);\n\n const onGridKeyDownHandler = (event: React.KeyboardEvent<HTMLElement>) => {\n let updatedFocusDate;\n\n const keys = [KeyCode.up, KeyCode.down, KeyCode.left, KeyCode.right, KeyCode.space, KeyCode.enter];\n\n if (focusedDate === null || keys.indexOf(event.keyCode) === -1) {\n return;\n }\n\n event.preventDefault();\n\n handleKey(event, {\n onActivate: () => {\n if (!focusedDate || !isDateEnabled(focusedDate)) {\n return;\n }\n\n onSelectDate(focusedDate);\n },\n onBlockEnd: () => focusedDate && (updatedFocusDate = moveNextWeek(focusedDate, isDateFocusable)),\n onBlockStart: () => focusedDate && (updatedFocusDate = movePrevWeek(focusedDate, isDateFocusable)),\n onInlineEnd: () => focusedDate && (updatedFocusDate = moveNextDay(focusedDate, isDateFocusable)),\n onInlineStart: () => focusedDate && (updatedFocusDate = movePrevDay(focusedDate, isDateFocusable)),\n });\n\n if (!updatedFocusDate) {\n return;\n }\n\n const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid);\n\n if (!updatedDateIsVisible) {\n const newMonthIsOnLeftSide = !isSingleGrid && isBefore(updatedFocusDate, baseDate);\n\n onChangeMonth(newMonthIsOnLeftSide ? addMonths(updatedFocusDate, 1) : updatedFocusDate);\n }\n onFocusedDateChange(updatedFocusDate);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar\n if (focusedDate !== null && gridHasFocus) {\n if (focusedDateRef.current && focusedDateRef.current !== document.activeElement) {\n focusedDateRef.current.focus();\n }\n }\n }, [focusedDate, gridHasFocus]);\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTarget = event.relatedTarget || document.activeElement;\n const newFocusTargetIsInGrid = containerRef.current?.contains(newFocusTarget as Node);\n if (newFocusTarget && !newFocusTargetIsInGrid && gridHasFocus) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n const isRangeVisible = (selectedStartDate && selectedEndDate) || gridHasFocus;\n\n const rangeEnds: Date[] = [selectedStartDate ?? focusedDate, selectedEndDate ?? focusedDate].filter(hasValue);\n\n const rangeStartDate = min(rangeEnds);\n const rangeEndDate = max(rangeEnds);\n\n return (\n <div ref={containerRef} onFocus={onGridFocus} onBlur={onGridBlur}>\n <InternalSpaceBetween size=\"xs\" direction=\"horizontal\">\n {!isSingleGrid && (\n <MonthlyGrid\n padDates=\"before\"\n className={styles['first-grid']}\n baseDate={addMonths(baseDate, -1)}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n dateDisabledReason={dateDisabledReason}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-prevmonth`}\n />\n )}\n <MonthlyGrid\n padDates=\"after\"\n className={styles['second-grid']}\n baseDate={baseDate}\n selectedEndDate={selectedEndDate}\n selectedStartDate={selectedStartDate}\n rangeStartDate={isRangeVisible ? rangeStartDate : null}\n rangeEndDate={isRangeVisible ? rangeEndDate : null}\n focusedDate={focusedDate}\n focusedDateRef={focusedDateRef}\n isDateEnabled={isDateEnabled}\n dateDisabledReason={dateDisabledReason}\n onSelectDate={onSelectDate}\n onGridKeyDownHandler={onGridKeyDownHandler}\n onFocusedDateChange={onFocusedDateChange}\n locale={locale}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n ariaLabelledby={`${headingIdPrefix}-currentmonth`}\n />\n </InternalSpaceBetween>\n </div>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAErG,OAAO,EACL,UAAU,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACX,YAAY,GACb,MAAM,wCAAwC,CAAC;AAChD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,O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BAAK,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU;QAC9D,oBAAC,oBAAoB,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAC,YAAY;YACnD,CAAC,YAAY,IAAI,CAChB,oBAAC,IAAI,oBACC,eAAe,IACnB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,cAAc,CAAC,YAAY,CAAC,EACvC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAChC,cAAc,EAAE,GAAG,eAAe,QAAQ,QAAQ,EAAE,IACpD,CACH;YACD,oBAAC,IAAI,oBACC,eAAe,IACnB,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,cAAc,CAAC,aAAa,CAAC,EACxC,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,GAAG,eAAe,WAAW,QAAQ,EAAE,IACvD,CACmB,CACnB,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { addMonths, addYears, isAfter, isBefore, isSameMonth, isSameYear, max, min } from 'date-fns';\n\nimport {\n getBaseDay,\n moveNextDay,\n moveNextWeek,\n movePrevDay,\n movePrevWeek,\n} from '../../../calendar/utils/navigation-day';\nimport {\n getBaseMonth,\n moveMonthDown,\n moveMonthUp,\n moveNextMonth,\n movePrevMonth,\n} from '../../../calendar/utils/navigation-month';\nimport { useDateCache } from '../../../internal/hooks/use-date-cache';\nimport { KeyCode } from '../../../internal/keycode';\nimport handleKey from '../../../internal/utils/handle-key';\nimport { hasValue } from '../../../internal/utils/has-value';\nimport InternalSpaceBetween from '../../../space-between/internal';\nimport { DateRangePickerProps } from '../../interfaces';\nimport { findDateToFocus } from '../utils';\nimport { Grid } from './grid';\nimport { SelectGridProps } from './interfaces';\n\nimport testutilStyles from '../../test-classes/styles.css.js';\n\nfunction isVisible(date: Date, baseDate: Date, isSingleGrid: boolean, granularity: DateRangePickerProps.Granularity) {\n const isSame = granularity === 'day' ? isSameMonth : isSameYear;\n const add = granularity === 'day' ? addMonths : addYears;\n if (isSingleGrid) {\n return isSame(date, baseDate);\n }\n\n const previous = add(baseDate, -1);\n\n return isSame(date, previous) || isSame(date, baseDate);\n}\n\nexport const Grids = ({\n baseDate,\n selectedStartDate,\n selectedEndDate,\n\n focusedDate,\n onFocusedDateChange,\n\n isDateEnabled,\n dateDisabledReason,\n isSingleGrid,\n\n onSelectDate,\n onPageChange,\n\n locale,\n todayAriaLabel,\n currentMonthAriaLabel,\n headingIdPrefix,\n startOfWeek = 0,\n granularity = 'day',\n}: SelectGridProps) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n const isMonthPicker = granularity === 'month';\n\n const focusedDateRef = useRef<HTMLTableCellElement>(null);\n\n const addPages = !isMonthPicker ? addMonths : addYears;\n const getBase = !isMonthPicker ? getBaseDay : getBaseMonth;\n const moveDown = isMonthPicker ? moveMonthDown : moveNextWeek;\n const moveLeft = isMonthPicker ? movePrevMonth : movePrevDay;\n const moveRight = isMonthPicker ? moveNextMonth : moveNextDay;\n const moveUp = isMonthPicker ? moveMonthUp : movePrevWeek;\n\n const dateCache = useDateCache();\n baseDate = dateCache(baseDate);\n focusedDate = focusedDate ? dateCache(focusedDate) : null;\n\n const isDateFocusable = useCallback(\n (date: Date) => {\n return isDateEnabled(date) || (!isDateEnabled(date) && !!dateDisabledReason(date));\n },\n [isDateEnabled, dateDisabledReason]\n );\n\n useEffect(() => {\n if (focusedDate && !isVisible(focusedDate, baseDate, isSingleGrid, granularity)) {\n const direction = isAfter(focusedDate, baseDate) ? -1 : 1;\n\n const newPage = !isSingleGrid && direction === -1 ? addPages(baseDate, -1) : baseDate;\n const nearestBaseDate = getBase(newPage, isDateFocusable);\n\n const newFocusedDate = findDateToFocus(focusedDate, nearestBaseDate, isDateFocusable);\n\n onFocusedDateChange(newFocusedDate);\n }\n }, [baseDate, focusedDate, isSingleGrid, granularity, addPages, isDateFocusable, onFocusedDateChange, getBase]);\n\n const onGridKeyDownHandler = (event: React.KeyboardEvent<HTMLElement>) => {\n let updatedFocusDate: Date | null = null;\n\n const keys = [KeyCode.up, KeyCode.down, KeyCode.left, KeyCode.right, KeyCode.space, KeyCode.enter];\n\n if (focusedDate === null || keys.indexOf(event.keyCode) === -1) {\n return;\n }\n\n event.preventDefault();\n\n handleKey(event, {\n onActivate: () => {\n if (!focusedDate || !isDateEnabled(focusedDate)) {\n return;\n }\n onSelectDate(focusedDate);\n },\n onBlockEnd: () => focusedDate && (updatedFocusDate = moveDown(focusedDate, isDateFocusable)),\n onBlockStart: () => focusedDate && (updatedFocusDate = moveUp(focusedDate, isDateFocusable)),\n onInlineStart: () => focusedDate && (updatedFocusDate = moveLeft(focusedDate, isDateFocusable)),\n onInlineEnd: () => focusedDate && (updatedFocusDate = moveRight(focusedDate, isDateFocusable)),\n });\n\n if (!updatedFocusDate) {\n return;\n }\n\n const updatedDateIsVisible = isVisible(updatedFocusDate, baseDate, isSingleGrid, granularity);\n\n if (!updatedDateIsVisible) {\n const newPageIsOnLeftSide = !isSingleGrid && isBefore(updatedFocusDate, baseDate);\n onPageChange(newPageIsOnLeftSide ? addPages(updatedFocusDate, 1) : updatedFocusDate);\n }\n onFocusedDateChange(updatedFocusDate);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar\n if (focusedDate !== null && gridHasFocus) {\n if (focusedDateRef.current && focusedDateRef.current !== document.activeElement) {\n focusedDateRef.current.focus();\n }\n }\n }, [focusedDate, gridHasFocus]);\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTarget = event.relatedTarget || document.activeElement;\n const newFocusTargetIsInGrid = containerRef.current?.contains(newFocusTarget as Node);\n if (newFocusTarget && !newFocusTargetIsInGrid && gridHasFocus) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n const isRangeVisible = (selectedStartDate && selectedEndDate) || gridHasFocus;\n\n const rangeEnds: Date[] = [selectedStartDate ?? focusedDate, selectedEndDate ?? focusedDate].filter(hasValue);\n const rangeStartDate = min(rangeEnds);\n const rangeEndDate = max(rangeEnds);\n const pageUnit = isMonthPicker ? 'year' : 'month';\n\n const sharedGridProps = {\n selectedEndDate,\n selectedStartDate,\n focusedDate,\n focusedDateRef,\n rangeStartDate: isRangeVisible ? rangeStartDate : null,\n rangeEndDate: isRangeVisible ? rangeEndDate : null,\n isDateEnabled,\n dateDisabledReason,\n onSelectDate,\n onGridKeyDownHandler,\n onFocusedDateChange,\n locale,\n granularity,\n currentMonthAriaLabel,\n startOfWeek,\n todayAriaLabel,\n };\n\n return (\n <div ref={containerRef} onFocus={onGridFocus} onBlur={onGridBlur}>\n <InternalSpaceBetween size=\"xs\" direction=\"horizontal\">\n {!isSingleGrid && (\n <Grid\n {...sharedGridProps}\n padDates={'before'}\n className={testutilStyles['first-grid']}\n baseDate={addPages(baseDate, -1)}\n ariaLabelledby={`${headingIdPrefix}-prev${pageUnit}`}\n />\n )}\n <Grid\n {...sharedGridProps}\n padDates={'after'}\n className={testutilStyles['second-grid']}\n baseDate={baseDate}\n ariaLabelledby={`${headingIdPrefix}-current${pageUnit}`}\n />\n </InternalSpaceBetween>\n </div>\n );\n};\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { DateRangePickerProps, DayIndex } from '../../interfaces';
|
|
3
|
+
export interface GridBaseProps {
|
|
4
|
+
baseDate: Date;
|
|
5
|
+
selectedStartDate: Date | null;
|
|
6
|
+
selectedEndDate: Date | null;
|
|
7
|
+
focusedDate: Date | null;
|
|
8
|
+
onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;
|
|
9
|
+
onSelectDate: (date: Date) => void;
|
|
10
|
+
isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;
|
|
11
|
+
dateDisabledReason: DateRangePickerProps.DateDisabledReasonFunction;
|
|
12
|
+
locale: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GridProps extends GridBaseProps {
|
|
15
|
+
rangeStartDate: Date | null;
|
|
16
|
+
rangeEndDate: Date | null;
|
|
17
|
+
focusedDateRef: React.RefObject<HTMLTableCellElement>;
|
|
18
|
+
onGridKeyDownHandler: (e: React.KeyboardEvent<HTMLElement>) => void;
|
|
19
|
+
ariaLabelledby: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Used to only add the dates of previous and next months outside the month pages
|
|
23
|
+
*/
|
|
24
|
+
padDates: 'before' | 'after';
|
|
25
|
+
currentMonthAriaLabel?: string;
|
|
26
|
+
startOfWeek?: DayIndex;
|
|
27
|
+
todayAriaLabel?: string;
|
|
28
|
+
granularity: DateRangePickerProps.Granularity;
|
|
29
|
+
}
|
|
30
|
+
export interface SelectGridProps extends GridBaseProps {
|
|
31
|
+
/**
|
|
32
|
+
* changes the page/view of the calendar. Doing so will change to another month or year
|
|
33
|
+
* @param date
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
onPageChange: (date: Date) => void;
|
|
37
|
+
isSingleGrid: boolean;
|
|
38
|
+
headingIdPrefix: string;
|
|
39
|
+
/**
|
|
40
|
+
* not needed for grids with a month granularity
|
|
41
|
+
*/
|
|
42
|
+
startOfWeek?: DayIndex;
|
|
43
|
+
granularity?: DateRangePickerProps.Granularity;
|
|
44
|
+
todayAriaLabel?: string;
|
|
45
|
+
currentMonthAriaLabel?: string;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/interfaces.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MA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e,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,WAAW,CAAC,EAAE,oBAAoB,CAAC,WAAW,CAAC;IAC/C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DateRangePickerProps, DayIndex } from '../../interfaces';\n\nexport interface GridBaseProps {\n baseDate: Date;\n selectedStartDate: Date | null;\n selectedEndDate: Date | null;\n focusedDate: Date | null;\n\n onFocusedDateChange: React.Dispatch<React.SetStateAction<Date | null>>;\n onSelectDate: (date: Date) => void;\n isDateEnabled: DateRangePickerProps.IsDateEnabledFunction;\n dateDisabledReason: DateRangePickerProps.DateDisabledReasonFunction;\n\n locale: string;\n}\n\nexport interface GridProps extends GridBaseProps {\n rangeStartDate: Date | null;\n rangeEndDate: Date | null;\n focusedDateRef: React.RefObject<HTMLTableCellElement>;\n\n onGridKeyDownHandler: (e: React.KeyboardEvent<HTMLElement>) => void;\n\n ariaLabelledby: string;\n className?: string;\n\n /**\n * Used to only add the dates of previous and next months outside the month pages\n */\n padDates: 'before' | 'after';\n currentMonthAriaLabel?: string;\n startOfWeek?: DayIndex;\n todayAriaLabel?: string;\n granularity: DateRangePickerProps.Granularity;\n}\n\nexport interface SelectGridProps extends GridBaseProps {\n /**\n * changes the page/view of the calendar. Doing so will change to another month or year\n * @param date\n * @returns\n */\n onPageChange: (date: Date) => void;\n\n isSingleGrid: boolean;\n\n headingIdPrefix: string;\n /**\n * not needed for grids with a month granularity\n */\n startOfWeek?: DayIndex;\n granularity?: DateRangePickerProps.Granularity;\n todayAriaLabel?: string;\n currentMonthAriaLabel?: string;\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DateRangePickerProps } from '../../interfaces';
|
|
2
|
+
export declare function setDayIndex(date: Date, dayIndex: number): void;
|
|
3
|
+
export declare function renderDayName(locale: string, dayIndex: number, mode: 'short' | 'long'): string;
|
|
4
|
+
export declare function renderMonthAndYear(locale: string, baseDate: Date): string;
|
|
5
|
+
export declare function renderYear(locale: string, date: Date): string;
|
|
6
|
+
export declare function getDateLabel(locale: string, date: Date, mode?: 'full' | 'short'): string;
|
|
7
|
+
export declare function renderTimeLabel(locale: string, date: Date, format?: DateRangePickerProps['timeInputFormat']): string;
|
|
8
|
+
interface RenderDateAnnouncementProps {
|
|
9
|
+
date: Date;
|
|
10
|
+
isCurrent: boolean;
|
|
11
|
+
locale: string;
|
|
12
|
+
granularity?: DateRangePickerProps['granularity'];
|
|
13
|
+
currentLabel?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function renderDateAnnouncement({ date, isCurrent, locale, granularity, currentLabel, }: RenderDateAnnouncementProps): string;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=intl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/intl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAG9D;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAI9F;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,CAOzE;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAI7D;AAGD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAE,MAAM,GAAG,OAAgB,GAAG,MAAM,CAchG;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,GAAG,MAAM,CAUpH;AAED,UAAU,2BAA2B;IACnC,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,oBAAoB,CAAC,aAAa,CAAC,CAAC;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,SAAS,EACT,MAAM,EACN,WAAmB,EACnB,YAAY,GACb,EAAE,2BAA2B,GAAG,MAAM,CAStC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export function setDayIndex(date, dayIndex) {
|
|
2
|
+
const diff = dayIndex - date.getDay();
|
|
3
|
+
date.setDate(date.getDate() + diff);
|
|
4
|
+
}
|
|
5
|
+
export function renderDayName(locale, dayIndex, mode) {
|
|
6
|
+
const tempDate = new Date();
|
|
7
|
+
setDayIndex(tempDate, dayIndex);
|
|
8
|
+
return tempDate.toLocaleDateString(locale, { weekday: mode });
|
|
9
|
+
}
|
|
10
|
+
export function renderMonthAndYear(locale, baseDate) {
|
|
11
|
+
const result = baseDate.toLocaleDateString(locale, {
|
|
12
|
+
year: 'numeric',
|
|
13
|
+
month: 'long',
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
export function renderYear(locale, date) {
|
|
18
|
+
return date.toLocaleDateString(locale, {
|
|
19
|
+
year: 'numeric',
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const dayLabelCache = new Map();
|
|
23
|
+
export function getDateLabel(locale, date, mode = 'full') {
|
|
24
|
+
const cacheKey = locale + date.getTime() + mode;
|
|
25
|
+
const cachedValue = dayLabelCache.get(cacheKey);
|
|
26
|
+
if (cachedValue) {
|
|
27
|
+
return cachedValue;
|
|
28
|
+
}
|
|
29
|
+
const value = date.toLocaleDateString(locale, {
|
|
30
|
+
weekday: mode === 'full' ? 'long' : undefined,
|
|
31
|
+
month: 'long',
|
|
32
|
+
day: 'numeric',
|
|
33
|
+
year: 'numeric',
|
|
34
|
+
});
|
|
35
|
+
dayLabelCache.set(cacheKey, value);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
export function renderTimeLabel(locale, date, format) {
|
|
39
|
+
let options = {};
|
|
40
|
+
if (format === 'hh') {
|
|
41
|
+
options = { hour: '2-digit' };
|
|
42
|
+
}
|
|
43
|
+
if (format === 'hh:mm') {
|
|
44
|
+
options = { hour: '2-digit', minute: '2-digit' };
|
|
45
|
+
}
|
|
46
|
+
const value = date.toLocaleTimeString(locale, options);
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
export function renderDateAnnouncement({ date, isCurrent, locale, granularity = 'day', currentLabel, }) {
|
|
50
|
+
const formattedDate = granularity === 'month' ? renderMonthAndYear(locale, date) : getDateLabel(locale, date, 'short');
|
|
51
|
+
if (isCurrent && currentLabel) {
|
|
52
|
+
return `${formattedDate}. ${currentLabel}`;
|
|
53
|
+
}
|
|
54
|
+
return formattedDate;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=intl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.js","sourceRoot":"","sources":["../../../../../src/date-range-picker/calendar/grids/intl.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,WAAW,CAAC,IAAU,EAAE,QAAgB;IACtD,MAAM,IAAI,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IACtC,IAAI,CAAC,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SAAS;KAChB,CAAC,CAAC;IACH,aAAa,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,IAAU,EAAE,MAAgD;IAC1G,IAAI,OAAO,GAA+B,EAAE,CAAC;IAC7C,IAAI,MAAM,KAAK,IAAI,EAAE;QACnB,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KAC/B;IACD,IAAI,MAAM,KAAK,OAAO,EAAE;QACtB,OAAO,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;KAClD;IACD,MAAM,KAAK,GAAG,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC;AACf,CAAC;AAUD,MAAM,UAAU,sBAAsB,CAAC,EACrC,IAAI,EACJ,SAAS,EACT,MAAM,EACN,WAAW,GAAG,KAAK,EACnB,YAAY,GACgB;IAC5B,MAAM,aAAa,GACjB,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAEnG,IAAI,SAAS,IAAI,YAAY,EAAE;QAC7B,OAAO,GAAG,aAAa,KAAK,YAAY,EAAE,CAAC;KAC5C;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { DateRangePickerProps } from '../../interfaces';\n\nexport function setDayIndex(date: Date, dayIndex: number): void {\n const diff = dayIndex - date.getDay();\n date.setDate(date.getDate() + diff);\n}\n\nexport function renderDayName(locale: string, dayIndex: number, mode: 'short' | 'long'): string {\n const tempDate = new Date();\n setDayIndex(tempDate, dayIndex);\n return tempDate.toLocaleDateString(locale, { weekday: mode });\n}\n\nexport function renderMonthAndYear(locale: string, baseDate: Date): string {\n const result = baseDate.toLocaleDateString(locale, {\n year: 'numeric',\n month: 'long',\n });\n\n return result;\n}\n\nexport function renderYear(locale: string, date: Date): string {\n return date.toLocaleDateString(locale, {\n year: 'numeric',\n });\n}\n\nconst dayLabelCache = new Map<string, string>();\nexport function getDateLabel(locale: string, date: Date, mode: 'full' | 'short' = 'full'): string {\n const cacheKey = locale + date.getTime() + mode;\n const cachedValue = dayLabelCache.get(cacheKey);\n if (cachedValue) {\n return cachedValue;\n }\n const value = date.toLocaleDateString(locale, {\n weekday: mode === 'full' ? 'long' : undefined,\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n });\n dayLabelCache.set(cacheKey, value);\n return value;\n}\n\nexport function renderTimeLabel(locale: string, date: Date, format?: DateRangePickerProps['timeInputFormat']): string {\n let options: Intl.DateTimeFormatOptions = {};\n if (format === 'hh') {\n options = { hour: '2-digit' };\n }\n if (format === 'hh:mm') {\n options = { hour: '2-digit', minute: '2-digit' };\n }\n const value = date.toLocaleTimeString(locale, options);\n return value;\n}\n\ninterface RenderDateAnnouncementProps {\n date: Date;\n isCurrent: boolean;\n locale: string;\n granularity?: DateRangePickerProps['granularity'];\n currentLabel?: string;\n}\n\nexport function renderDateAnnouncement({\n date,\n isCurrent,\n locale,\n granularity = 'day',\n currentLabel,\n}: RenderDateAnnouncementProps): string {\n const formattedDate =\n granularity === 'month' ? renderMonthAndYear(locale, date) : getDateLabel(locale, date, 'short');\n\n if (isCurrent && currentLabel) {\n return `${formattedDate}. ${currentLabel}`;\n }\n\n return formattedDate;\n}\n"]}
|