@react-aria/calendar 3.0.0-rc.0 → 3.0.0-rc.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 +25 -6
- package/dist/main.js.map +1 -1
- package/dist/module.js +26 -7
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/useCalendarCell.ts +2 -2
- package/src/useCalendarGrid.ts +11 -3
- package/src/utils.ts +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/calendar",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@internationalized/date": "3.0.0-rc.
|
|
22
|
-
"@react-aria/i18n": "^3.
|
|
23
|
-
"@react-aria/interactions": "^3.
|
|
24
|
-
"@react-aria/live-announcer": "^3.0
|
|
25
|
-
"@react-aria/utils": "^3.
|
|
26
|
-
"@react-stately/calendar": "3.0.0-rc.
|
|
27
|
-
"@react-types/button": "^3.
|
|
28
|
-
"@react-types/calendar": "3.0.0-rc.
|
|
29
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@internationalized/date": "3.0.0-rc.1",
|
|
22
|
+
"@react-aria/i18n": "^3.4.0",
|
|
23
|
+
"@react-aria/interactions": "^3.9.0",
|
|
24
|
+
"@react-aria/live-announcer": "^3.1.0",
|
|
25
|
+
"@react-aria/utils": "^3.13.0",
|
|
26
|
+
"@react-stately/calendar": "3.0.0-rc.1",
|
|
27
|
+
"@react-types/button": "^3.5.0",
|
|
28
|
+
"@react-types/calendar": "3.0.0-rc.1",
|
|
29
|
+
"@react-types/shared": "^3.13.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"react": "^16.8.0 || ^17.0.0-rc.1",
|
|
33
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1"
|
|
32
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
33
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
|
|
39
39
|
}
|
package/src/useCalendarCell.ts
CHANGED
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
import {CalendarDate, isEqualDay, isSameDay, isToday} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
15
|
import {focusWithoutScrolling, useDescription} from '@react-aria/utils';
|
|
16
|
+
import {getEraFormat, hookData} from './utils';
|
|
16
17
|
import {getInteractionModality, usePress} from '@react-aria/interactions';
|
|
17
|
-
import {hookData} from './utils';
|
|
18
18
|
import {HTMLAttributes, RefObject, useEffect, useMemo, useRef} from 'react';
|
|
19
19
|
// @ts-ignore
|
|
20
20
|
import intlMessages from '../intl/*.json';
|
|
@@ -81,7 +81,7 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
81
81
|
day: 'numeric',
|
|
82
82
|
month: 'long',
|
|
83
83
|
year: 'numeric',
|
|
84
|
-
era: date
|
|
84
|
+
era: getEraFormat(date),
|
|
85
85
|
timeZone: state.timeZone
|
|
86
86
|
});
|
|
87
87
|
let isSelected = state.isSelected(date);
|
package/src/useCalendarGrid.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CalendarDate, startOfWeek} from '@internationalized/date';
|
|
13
|
+
import {CalendarDate, startOfWeek, today} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
15
|
import {hookData, useVisibleRangeDescription} from './utils';
|
|
16
16
|
import {HTMLAttributes, KeyboardEvent, useMemo} from 'react';
|
|
@@ -63,22 +63,27 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
63
63
|
break;
|
|
64
64
|
case 'PageUp':
|
|
65
65
|
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
66
67
|
state.focusPreviousSection(e.shiftKey);
|
|
67
68
|
break;
|
|
68
69
|
case 'PageDown':
|
|
69
70
|
e.preventDefault();
|
|
71
|
+
e.stopPropagation();
|
|
70
72
|
state.focusNextSection(e.shiftKey);
|
|
71
73
|
break;
|
|
72
74
|
case 'End':
|
|
73
75
|
e.preventDefault();
|
|
76
|
+
e.stopPropagation();
|
|
74
77
|
state.focusSectionEnd();
|
|
75
78
|
break;
|
|
76
79
|
case 'Home':
|
|
77
80
|
e.preventDefault();
|
|
81
|
+
e.stopPropagation();
|
|
78
82
|
state.focusSectionStart();
|
|
79
83
|
break;
|
|
80
84
|
case 'ArrowLeft':
|
|
81
85
|
e.preventDefault();
|
|
86
|
+
e.stopPropagation();
|
|
82
87
|
if (direction === 'rtl') {
|
|
83
88
|
state.focusNextDay();
|
|
84
89
|
} else {
|
|
@@ -87,10 +92,12 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
87
92
|
break;
|
|
88
93
|
case 'ArrowUp':
|
|
89
94
|
e.preventDefault();
|
|
95
|
+
e.stopPropagation();
|
|
90
96
|
state.focusPreviousRow();
|
|
91
97
|
break;
|
|
92
98
|
case 'ArrowRight':
|
|
93
99
|
e.preventDefault();
|
|
100
|
+
e.stopPropagation();
|
|
94
101
|
if (direction === 'rtl') {
|
|
95
102
|
state.focusPreviousDay();
|
|
96
103
|
} else {
|
|
@@ -99,6 +106,7 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
99
106
|
break;
|
|
100
107
|
case 'ArrowDown':
|
|
101
108
|
e.preventDefault();
|
|
109
|
+
e.stopPropagation();
|
|
102
110
|
state.focusNextRow();
|
|
103
111
|
break;
|
|
104
112
|
case 'Escape':
|
|
@@ -122,13 +130,13 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
122
130
|
let dayFormatter = useDateFormatter({weekday: 'narrow', timeZone: state.timeZone});
|
|
123
131
|
let {locale} = useLocale();
|
|
124
132
|
let weekDays = useMemo(() => {
|
|
125
|
-
let weekStart = startOfWeek(state.
|
|
133
|
+
let weekStart = startOfWeek(today(state.timeZone), locale);
|
|
126
134
|
return [...new Array(7).keys()].map((index) => {
|
|
127
135
|
let date = weekStart.add({days: index});
|
|
128
136
|
let dateDay = date.toDate(state.timeZone);
|
|
129
137
|
return dayFormatter.format(dateDay);
|
|
130
138
|
});
|
|
131
|
-
}, [
|
|
139
|
+
}, [locale, state.timeZone, dayFormatter]);
|
|
132
140
|
|
|
133
141
|
return {
|
|
134
142
|
gridProps: mergeProps(labelProps, {
|
package/src/utils.ts
CHANGED
|
@@ -26,6 +26,14 @@ interface HookData {
|
|
|
26
26
|
|
|
27
27
|
export const hookData = new WeakMap<CalendarState | RangeCalendarState, HookData>();
|
|
28
28
|
|
|
29
|
+
export function getEraFormat(date: CalendarDate) {
|
|
30
|
+
if (date?.calendar.identifier !== 'gregory') {
|
|
31
|
+
return 'long';
|
|
32
|
+
} else if (date?.era === 'BC') {
|
|
33
|
+
return 'short';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
export function useSelectedDateDescription(state: CalendarState | RangeCalendarState) {
|
|
30
38
|
let formatMessage = useMessageFormatter(intlMessages);
|
|
31
39
|
|
|
@@ -37,7 +45,11 @@ export function useSelectedDateDescription(state: CalendarState | RangeCalendarS
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
let dateFormatter = useDateFormatter({
|
|
40
|
-
|
|
48
|
+
weekday: 'long',
|
|
49
|
+
month: 'long',
|
|
50
|
+
year: 'numeric',
|
|
51
|
+
day: 'numeric',
|
|
52
|
+
era: getEraFormat(start) || getEraFormat(end),
|
|
41
53
|
timeZone: state.timeZone
|
|
42
54
|
});
|
|
43
55
|
|
|
@@ -62,16 +74,20 @@ export function useSelectedDateDescription(state: CalendarState | RangeCalendarS
|
|
|
62
74
|
|
|
63
75
|
export function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean) {
|
|
64
76
|
let formatMessage = useMessageFormatter(intlMessages);
|
|
77
|
+
let era: any = getEraFormat(startDate) || getEraFormat(endDate);
|
|
65
78
|
let monthFormatter = useDateFormatter({
|
|
66
79
|
month: 'long',
|
|
67
80
|
year: 'numeric',
|
|
68
|
-
era
|
|
81
|
+
era,
|
|
69
82
|
calendar: startDate.calendar.identifier,
|
|
70
83
|
timeZone
|
|
71
84
|
});
|
|
72
85
|
|
|
73
86
|
let dateFormatter = useDateFormatter({
|
|
74
|
-
|
|
87
|
+
month: 'long',
|
|
88
|
+
year: 'numeric',
|
|
89
|
+
day: 'numeric',
|
|
90
|
+
era,
|
|
75
91
|
calendar: startDate.calendar.identifier,
|
|
76
92
|
timeZone
|
|
77
93
|
});
|