@react-aria/calendar 3.0.0 → 3.0.1
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/dist/main.js +670 -58
- package/dist/main.js.map +1 -1
- package/dist/module.js +670 -58
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +9 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/useCalendarBase.ts +8 -7
- package/src/useCalendarCell.ts +13 -12
- package/src/useCalendarGrid.ts +4 -3
- package/src/useRangeCalendar.ts +4 -3
- package/src/utils.ts +13 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/calendar",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@internationalized/date": "^3.0.
|
|
22
|
-
"@react-aria/i18n": "^3.
|
|
23
|
-
"@react-aria/interactions": "^3.
|
|
24
|
-
"@react-aria/live-announcer": "^3.1.
|
|
25
|
-
"@react-aria/utils": "^3.13.
|
|
26
|
-
"@react-stately/calendar": "^3.0.
|
|
27
|
-
"@react-types/button": "^3.
|
|
28
|
-
"@react-types/calendar": "^3.0.
|
|
29
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@internationalized/date": "^3.0.1",
|
|
22
|
+
"@react-aria/i18n": "^3.5.0",
|
|
23
|
+
"@react-aria/interactions": "^3.10.0",
|
|
24
|
+
"@react-aria/live-announcer": "^3.1.1",
|
|
25
|
+
"@react-aria/utils": "^3.13.2",
|
|
26
|
+
"@react-stately/calendar": "^3.0.1",
|
|
27
|
+
"@react-types/button": "^3.6.0",
|
|
28
|
+
"@react-types/calendar": "^3.0.1",
|
|
29
|
+
"@react-types/shared": "^3.14.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "cd7c0ec917122c7612f653c22f8ed558f8b66ecd"
|
|
39
39
|
}
|
package/src/useCalendarBase.ts
CHANGED
|
@@ -14,29 +14,30 @@ import {announce} from '@react-aria/live-announcer';
|
|
|
14
14
|
import {AriaButtonProps} from '@react-types/button';
|
|
15
15
|
import {CalendarPropsBase} from '@react-types/calendar';
|
|
16
16
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
17
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
17
18
|
import {DOMProps} from '@react-types/shared';
|
|
18
19
|
import {filterDOMProps, mergeProps, useLabels, useSlotId, useUpdateEffect} from '@react-aria/utils';
|
|
19
20
|
import {hookData, useSelectedDateDescription, useVisibleRangeDescription} from './utils';
|
|
20
|
-
import {HTMLAttributes, useRef} from 'react';
|
|
21
21
|
// @ts-ignore
|
|
22
22
|
import intlMessages from '../intl/*.json';
|
|
23
|
-
import {
|
|
23
|
+
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
24
|
+
import {useRef} from 'react';
|
|
24
25
|
|
|
25
26
|
export interface CalendarAria {
|
|
26
27
|
/** Props for the calendar grouping element. */
|
|
27
|
-
calendarProps:
|
|
28
|
+
calendarProps: DOMAttributes,
|
|
28
29
|
/** Props for the next button. */
|
|
29
30
|
nextButtonProps: AriaButtonProps,
|
|
30
31
|
/** Props for the previous button. */
|
|
31
32
|
prevButtonProps: AriaButtonProps,
|
|
32
33
|
/** Props for the error message element, if any. */
|
|
33
|
-
errorMessageProps:
|
|
34
|
+
errorMessageProps: DOMAttributes,
|
|
34
35
|
/** A description of the visible date range, for use in the calendar title. */
|
|
35
36
|
title: string
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export function useCalendarBase(props: CalendarPropsBase & DOMProps, state: CalendarState | RangeCalendarState): CalendarAria {
|
|
39
|
-
let
|
|
40
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
40
41
|
let domProps = filterDOMProps(props);
|
|
41
42
|
|
|
42
43
|
let title = useVisibleRangeDescription(state.visibleRange.start, state.visibleRange.end, state.timeZone, false);
|
|
@@ -97,14 +98,14 @@ export function useCalendarBase(props: CalendarPropsBase & DOMProps, state: Cale
|
|
|
97
98
|
}),
|
|
98
99
|
nextButtonProps: {
|
|
99
100
|
onPress: () => state.focusNextPage(),
|
|
100
|
-
'aria-label':
|
|
101
|
+
'aria-label': stringFormatter.format('next'),
|
|
101
102
|
isDisabled: nextDisabled,
|
|
102
103
|
onFocus: () => nextFocused.current = true,
|
|
103
104
|
onBlur: () => nextFocused.current = false
|
|
104
105
|
},
|
|
105
106
|
prevButtonProps: {
|
|
106
107
|
onPress: () => state.focusPreviousPage(),
|
|
107
|
-
'aria-label':
|
|
108
|
+
'aria-label': stringFormatter.format('previous'),
|
|
108
109
|
isDisabled: previousDisabled,
|
|
109
110
|
onFocus: () => previousFocused.current = true,
|
|
110
111
|
onBlur: () => previousFocused.current = false
|
package/src/useCalendarCell.ts
CHANGED
|
@@ -12,14 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
import {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
15
16
|
import {focusWithoutScrolling, getScrollParent, scrollIntoView, useDescription} from '@react-aria/utils';
|
|
16
17
|
import {getEraFormat, hookData} from './utils';
|
|
17
18
|
import {getInteractionModality, usePress} from '@react-aria/interactions';
|
|
18
|
-
import {HTMLAttributes, RefObject, useEffect, useMemo, useRef} from 'react';
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
import intlMessages from '../intl/*.json';
|
|
21
21
|
import {mergeProps} from '@react-aria/utils';
|
|
22
|
-
import {
|
|
22
|
+
import {RefObject, useEffect, useMemo, useRef} from 'react';
|
|
23
|
+
import {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
23
24
|
|
|
24
25
|
export interface AriaCalendarCellProps {
|
|
25
26
|
/** The date that this cell represents. */
|
|
@@ -33,9 +34,9 @@ export interface AriaCalendarCellProps {
|
|
|
33
34
|
|
|
34
35
|
export interface CalendarCellAria {
|
|
35
36
|
/** Props for the grid cell element (e.g. `<td>`). */
|
|
36
|
-
cellProps:
|
|
37
|
+
cellProps: DOMAttributes,
|
|
37
38
|
/** Props for the button element within the cell. */
|
|
38
|
-
buttonProps:
|
|
39
|
+
buttonProps: DOMAttributes,
|
|
39
40
|
/** Whether the cell is currently being pressed. */
|
|
40
41
|
isPressed: boolean,
|
|
41
42
|
/** Whether the cell is selected. */
|
|
@@ -75,7 +76,7 @@ export interface CalendarCellAria {
|
|
|
75
76
|
export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement>): CalendarCellAria {
|
|
76
77
|
let {date, isDisabled} = props;
|
|
77
78
|
let {errorMessageId, selectedDateDescription} = hookData.get(state);
|
|
78
|
-
let
|
|
79
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
79
80
|
let dateFormatter = useDateFormatter({
|
|
80
81
|
weekday: 'long',
|
|
81
82
|
day: 'numeric',
|
|
@@ -129,24 +130,24 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
129
130
|
label += dateFormatter.format(nativeDate);
|
|
130
131
|
if (isDateToday) {
|
|
131
132
|
// If date is today, set appropriate string depending on selected state:
|
|
132
|
-
label =
|
|
133
|
+
label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {
|
|
133
134
|
date: label
|
|
134
135
|
});
|
|
135
136
|
} else if (isSelected) {
|
|
136
137
|
// If date is selected but not today:
|
|
137
|
-
label =
|
|
138
|
+
label = stringFormatter.format('dateSelected', {
|
|
138
139
|
date: label
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
if (state.minValue && isSameDay(date, state.minValue)) {
|
|
143
|
-
label += ', ' +
|
|
144
|
+
label += ', ' + stringFormatter.format('minimumDate');
|
|
144
145
|
} else if (state.maxValue && isSameDay(date, state.maxValue)) {
|
|
145
|
-
label += ', ' +
|
|
146
|
+
label += ', ' + stringFormatter.format('maximumDate');
|
|
146
147
|
}
|
|
147
148
|
|
|
148
149
|
return label;
|
|
149
|
-
}, [dateFormatter, nativeDate,
|
|
150
|
+
}, [dateFormatter, nativeDate, stringFormatter, isSelected, isDateToday, date, state, selectedDateDescription]);
|
|
150
151
|
|
|
151
152
|
// When a cell is focused and this is a range calendar, add a prompt to help
|
|
152
153
|
// screenreader users know that they are in a range selection mode.
|
|
@@ -154,10 +155,10 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
154
155
|
if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {
|
|
155
156
|
// If selection has started add "click to finish selecting range"
|
|
156
157
|
if (state.anchorDate) {
|
|
157
|
-
rangeSelectionPrompt =
|
|
158
|
+
rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');
|
|
158
159
|
// Otherwise, add "click to start selecting range" prompt
|
|
159
160
|
} else {
|
|
160
|
-
rangeSelectionPrompt =
|
|
161
|
+
rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
package/src/useCalendarGrid.ts
CHANGED
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
import {CalendarDate, startOfWeek, today} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
|
+
import {DOMAttributes} from '@react-types/shared';
|
|
15
16
|
import {hookData, useVisibleRangeDescription} from './utils';
|
|
16
|
-
import {
|
|
17
|
+
import {KeyboardEvent, useMemo} from 'react';
|
|
17
18
|
import {mergeProps, useLabels} from '@react-aria/utils';
|
|
18
19
|
import {useDateFormatter, useLocale} from '@react-aria/i18n';
|
|
19
20
|
|
|
@@ -34,9 +35,9 @@ export interface AriaCalendarGridProps {
|
|
|
34
35
|
|
|
35
36
|
export interface CalendarGridAria {
|
|
36
37
|
/** Props for the date grid element (e.g. `<table>`). */
|
|
37
|
-
gridProps:
|
|
38
|
+
gridProps: DOMAttributes,
|
|
38
39
|
/** Props for the grid header element (e.g. `<thead>`). */
|
|
39
|
-
headerProps:
|
|
40
|
+
headerProps: DOMAttributes,
|
|
40
41
|
/** A list of week day abbreviations formatted for the current locale, typically used in column headers. */
|
|
41
42
|
weekDays: string[]
|
|
42
43
|
}
|
package/src/useRangeCalendar.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {CalendarAria, useCalendarBase} from './useCalendarBase';
|
|
14
14
|
import {DateValue, RangeCalendarProps} from '@react-types/calendar';
|
|
15
|
+
import {FocusableElement} from '@react-types/shared';
|
|
15
16
|
import {RangeCalendarState} from '@react-stately/calendar';
|
|
16
17
|
import {RefObject, useRef} from 'react';
|
|
17
18
|
import {useEvent} from '@react-aria/utils';
|
|
@@ -20,7 +21,7 @@ import {useEvent} from '@react-aria/utils';
|
|
|
20
21
|
* Provides the behavior and accessibility implementation for a range calendar component.
|
|
21
22
|
* A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
|
|
22
23
|
*/
|
|
23
|
-
export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<
|
|
24
|
+
export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<FocusableElement>): CalendarAria {
|
|
24
25
|
let res = useCalendarBase(props, state);
|
|
25
26
|
|
|
26
27
|
// We need to ignore virtual pointer events from VoiceOver due to these bugs.
|
|
@@ -37,7 +38,7 @@ export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<
|
|
|
37
38
|
|
|
38
39
|
// Stop range selection when pressing or releasing a pointer outside the calendar body,
|
|
39
40
|
// except when pressing the next or previous buttons to switch months.
|
|
40
|
-
let endDragging = e => {
|
|
41
|
+
let endDragging = (e: PointerEvent) => {
|
|
41
42
|
if (isVirtualClick.current) {
|
|
42
43
|
isVirtualClick.current = false;
|
|
43
44
|
return;
|
|
@@ -48,7 +49,7 @@ export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<
|
|
|
48
49
|
return;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
let target = e.target as
|
|
52
|
+
let target = e.target as Element;
|
|
52
53
|
let body = document.getElementById(res.calendarProps.id);
|
|
53
54
|
if (
|
|
54
55
|
body &&
|
package/src/utils.ts
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
import {CalendarDate, DateFormatter, endOfMonth, isSameDay, startOfMonth} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
|
-
import {FormatMessage, useDateFormatter, useMessageFormatter} from '@react-aria/i18n';
|
|
16
15
|
// @ts-ignore
|
|
17
16
|
import intlMessages from '../intl/*.json';
|
|
17
|
+
import type {LocalizedStringFormatter} from '@internationalized/string';
|
|
18
|
+
import {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
18
19
|
import {useMemo} from 'react';
|
|
19
20
|
|
|
20
21
|
interface HookData {
|
|
@@ -31,7 +32,7 @@ export function getEraFormat(date: CalendarDate): 'short' | undefined {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export function useSelectedDateDescription(state: CalendarState | RangeCalendarState) {
|
|
34
|
-
let
|
|
35
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
35
36
|
|
|
36
37
|
let start: CalendarDate, end: CalendarDate;
|
|
37
38
|
if ('highlightedRange' in state) {
|
|
@@ -57,19 +58,19 @@ export function useSelectedDateDescription(state: CalendarState | RangeCalendarS
|
|
|
57
58
|
// otherwise include both dates.
|
|
58
59
|
if (isSameDay(start, end)) {
|
|
59
60
|
let date = dateFormatter.format(start.toDate(state.timeZone));
|
|
60
|
-
return
|
|
61
|
+
return stringFormatter.format('selectedDateDescription', {date});
|
|
61
62
|
} else {
|
|
62
|
-
let dateRange = formatRange(dateFormatter,
|
|
63
|
+
let dateRange = formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);
|
|
63
64
|
|
|
64
|
-
return
|
|
65
|
+
return stringFormatter.format('selectedRangeDescription', {dateRange});
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
return '';
|
|
68
|
-
}, [start, end, anchorDate, state.timeZone,
|
|
69
|
+
}, [start, end, anchorDate, state.timeZone, stringFormatter, dateFormatter]);
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
export function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean) {
|
|
72
|
-
let
|
|
73
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
73
74
|
let era: any = getEraFormat(startDate) || getEraFormat(endDate);
|
|
74
75
|
let monthFormatter = useDateFormatter({
|
|
75
76
|
month: 'long',
|
|
@@ -96,18 +97,18 @@ export function useVisibleRangeDescription(startDate: CalendarDate, endDate: Cal
|
|
|
96
97
|
return monthFormatter.format(startDate.toDate(timeZone));
|
|
97
98
|
} else if (isSameDay(endDate, endOfMonth(endDate))) {
|
|
98
99
|
return isAria
|
|
99
|
-
? formatRange(monthFormatter,
|
|
100
|
+
? formatRange(monthFormatter, stringFormatter, startDate, endDate, timeZone)
|
|
100
101
|
: monthFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
return isAria
|
|
105
|
-
? formatRange(dateFormatter,
|
|
106
|
+
? formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone)
|
|
106
107
|
: dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
107
|
-
}, [startDate, endDate, monthFormatter, dateFormatter,
|
|
108
|
+
}, [startDate, endDate, monthFormatter, dateFormatter, stringFormatter, timeZone, isAria]);
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
function formatRange(dateFormatter: DateFormatter,
|
|
111
|
+
function formatRange(dateFormatter: DateFormatter, stringFormatter: LocalizedStringFormatter, start: CalendarDate, end: CalendarDate, timeZone: string) {
|
|
111
112
|
let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));
|
|
112
113
|
|
|
113
114
|
// Find the separator between the start and end date. This is determined
|
|
@@ -133,5 +134,5 @@ function formatRange(dateFormatter: DateFormatter, formatMessage: FormatMessage,
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
return
|
|
137
|
+
return stringFormatter.format('dateRange', {startDate: startValue, endDate: endValue});
|
|
137
138
|
}
|