@react-aria/calendar 3.0.0-nightly.3132 → 3.0.0-nightly.3148
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 +49 -22
- package/dist/main.js.map +1 -1
- package/dist/module.js +51 -23
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +65 -10
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +0 -1
- package/src/types.ts +17 -2
- package/src/useCalendar.ts +4 -0
- package/src/useCalendarBase.ts +2 -1
- package/src/useCalendarCell.ts +42 -4
- package/src/useCalendarGrid.ts +37 -9
- package/src/useRangeCalendar.ts +4 -0
- package/src/utils.ts +3 -3
- package/src/useCalendarTableHeader.ts +0 -11
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAeA;IACE,+CAA+C;IAC/C,aAAa,EAAE,eAAe,WAAW,CAAC,CAAC;IAC3C,iCAAiC;IACjC,eAAe,EAAE,eAAe,CAAC;IACjC,qCAAqC;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAA;CACd;AAGD;IACE,wDAAwD;IACxD,SAAS,EAAE,eAAe,WAAW,CAAC,CAAC;IACvC,8FAA8F;IAC9F,QAAQ,EAAE,OAAO,EAAE,CAAA;CACpB;AAED;IACE,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,gGAAgG;IAChG,IAAI,EAAE,MAAM,CAAA;CACb;AGtBD;;;GAGG;AACH,4BAA4B,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAE5G;ACJD;;;GAGG;AACH,iCAAiC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,YAAY,CAmDxJ;ACtDD;IACE;;;;OAIG;IACH,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED;;;;GAIG;AACH,gCAAgC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,GAAG,gBAAgB,CA6GrH;AC/HD;IACE,0CAA0C;IAC1C,IAAI,EAAE,YAAY,CAAC;IACnB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,qDAAqD;IACrD,SAAS,EAAE,eAAe,WAAW,CAAC,CAAC;IACvC,oDAAoD;IACpD,WAAW,EAAE,eAAe,WAAW,CAAC,CAAC;IACzC,mDAAmD;IACnD,SAAS,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB,mCAAmC;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,UAAU,EAAE,OAAO,CAAC;IACpB;;;OAGG;IACH,qBAAqB,EAAE,OAAO,CAAC;IAC/B,gEAAgE;IAChE,aAAa,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,gCAAgC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,gBAAgB,CA+NtJ","sources":["packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/types.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/utils.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarBase.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendar.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useRangeCalendar.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarGrid.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/useCalendarCell.ts","packages/@react-aria/calendar/src/packages/@react-aria/calendar/src/index.ts","packages/@react-aria/calendar/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useCalendar';\nexport * from './useRangeCalendar';\nexport * from './useCalendarGrid';\nexport * from './useCalendarCell';\nexport * from './types';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/calendar",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.3148+320c69908",
|
|
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.0-nightly.
|
|
22
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
23
|
-
"@react-aria/interactions": "3.0.0-nightly.
|
|
24
|
-
"@react-aria/live-announcer": "3.0.0-nightly.
|
|
25
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
26
|
-
"@react-stately/calendar": "3.0.0-nightly.
|
|
27
|
-
"@react-types/button": "3.4.4-nightly.
|
|
28
|
-
"@react-types/calendar": "3.0.0-nightly.
|
|
29
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
21
|
+
"@internationalized/date": "3.0.0-nightly.3148+320c69908",
|
|
22
|
+
"@react-aria/i18n": "3.0.0-nightly.1452+320c69908",
|
|
23
|
+
"@react-aria/interactions": "3.0.0-nightly.1452+320c69908",
|
|
24
|
+
"@react-aria/live-announcer": "3.0.0-nightly.1452+320c69908",
|
|
25
|
+
"@react-aria/utils": "3.0.0-nightly.1452+320c69908",
|
|
26
|
+
"@react-stately/calendar": "3.0.0-nightly.1452+320c69908",
|
|
27
|
+
"@react-types/button": "3.4.4-nightly.3148+320c69908",
|
|
28
|
+
"@react-types/calendar": "3.0.0-nightly.3148+320c69908",
|
|
29
|
+
"@react-types/shared": "3.0.0-nightly.1452+320c69908",
|
|
30
30
|
"date-fns": "^1.30.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "320c69908b41be47a3abb2878d04f90384e54321"
|
|
40
40
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -14,12 +14,27 @@ import {AriaButtonProps} from '@react-types/button';
|
|
|
14
14
|
import {HTMLAttributes} from 'react';
|
|
15
15
|
|
|
16
16
|
export interface CalendarAria {
|
|
17
|
+
/** Props for the calendar grouping element. */
|
|
17
18
|
calendarProps: HTMLAttributes<HTMLElement>,
|
|
19
|
+
/** Props for the next button. */
|
|
18
20
|
nextButtonProps: AriaButtonProps,
|
|
19
|
-
|
|
21
|
+
/** Props for the previous button. */
|
|
22
|
+
prevButtonProps: AriaButtonProps,
|
|
23
|
+
/** A description of the visible date range, for use in the calendar title. */
|
|
24
|
+
title: string
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
export interface CalendarGridAria {
|
|
24
|
-
|
|
29
|
+
/** Props for the date grid element (e.g. `<table>`). */
|
|
30
|
+
gridProps: HTMLAttributes<HTMLElement>,
|
|
31
|
+
/** A list of week days formatted for the current locale, typically used in column headers. */
|
|
32
|
+
weekDays: WeekDay[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface WeekDay {
|
|
36
|
+
/** A short name (e.g. single letter) for the day. */
|
|
37
|
+
narrow: string,
|
|
38
|
+
/** The full day name. If not displayed visually, it should be used as the accessiblity name. */
|
|
39
|
+
long: string
|
|
25
40
|
}
|
package/src/useCalendar.ts
CHANGED
|
@@ -15,6 +15,10 @@ import {CalendarProps, DateValue} from '@react-types/calendar';
|
|
|
15
15
|
import {CalendarState} from '@react-stately/calendar';
|
|
16
16
|
import {useCalendarBase} from './useCalendarBase';
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Provides the behavior and accessibility implementation for a calendar component.
|
|
20
|
+
* A calendar displays one or more date grids and allows users to select a single date.
|
|
21
|
+
*/
|
|
18
22
|
export function useCalendar<T extends DateValue>(props: CalendarProps<T>, state: CalendarState): CalendarAria {
|
|
19
23
|
return useCalendarBase(props, state);
|
|
20
24
|
}
|
package/src/useCalendarBase.ts
CHANGED
|
@@ -65,6 +65,7 @@ export function useCalendarBase(props: CalendarPropsBase & DOMProps, state: Cale
|
|
|
65
65
|
onPress: () => state.focusPreviousPage(),
|
|
66
66
|
'aria-label': formatMessage('previous'),
|
|
67
67
|
isDisabled: props.isDisabled || state.isPreviousVisibleRangeInvalid()
|
|
68
|
-
}
|
|
68
|
+
},
|
|
69
|
+
title: visibleRangeDescription
|
|
69
70
|
};
|
|
70
71
|
}
|
package/src/useCalendarCell.ts
CHANGED
|
@@ -17,20 +17,45 @@ import {HTMLAttributes, RefObject, useEffect, useMemo, useRef} from 'react';
|
|
|
17
17
|
// @ts-ignore
|
|
18
18
|
import intlMessages from '../intl/*.json';
|
|
19
19
|
import {mergeProps} from '@react-aria/utils';
|
|
20
|
-
import {PressProps, usePress} from '@react-aria/interactions';
|
|
21
20
|
import {useDateFormatter, useMessageFormatter} from '@react-aria/i18n';
|
|
21
|
+
import {usePress} from '@react-aria/interactions';
|
|
22
22
|
|
|
23
23
|
export interface AriaCalendarCellProps {
|
|
24
|
+
/** The date that this cell represents. */
|
|
24
25
|
date: CalendarDate,
|
|
26
|
+
/**
|
|
27
|
+
* Whether the cell is disabled. By default, this is determined by the
|
|
28
|
+
* Calendar's `minValue`, `maxValue`, and `isDisabled` props.
|
|
29
|
+
*/
|
|
25
30
|
isDisabled?: boolean
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
interface CalendarCellAria {
|
|
29
|
-
|
|
34
|
+
/** Props for the grid cell element (e.g. `<td>`). */
|
|
35
|
+
cellProps: HTMLAttributes<HTMLElement>,
|
|
36
|
+
/** Props for the button element within the cell. */
|
|
30
37
|
buttonProps: HTMLAttributes<HTMLElement>,
|
|
31
|
-
|
|
38
|
+
/** Whether the cell is currently being pressed. */
|
|
39
|
+
isPressed: boolean,
|
|
40
|
+
/** Whether the cell is selected. */
|
|
41
|
+
isSelected: boolean,
|
|
42
|
+
/** Whether the cell is focused. */
|
|
43
|
+
isFocused: boolean,
|
|
44
|
+
/** Whether the cell is disabled. */
|
|
45
|
+
isDisabled: boolean,
|
|
46
|
+
/**
|
|
47
|
+
* Whether the cell is outside the visible range of the calendar.
|
|
48
|
+
* For example, dates before the first day of a month in the same week.
|
|
49
|
+
*/
|
|
50
|
+
isOutsideVisibleRange: boolean,
|
|
51
|
+
/** The day number formatted according to the current locale. */
|
|
52
|
+
formattedDate: string
|
|
32
53
|
}
|
|
33
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Provides the behavior and accessibility implementation for a calendar cell component.
|
|
57
|
+
* A calendar cell displays a date cell within a calendar grid which can be selected by the user.
|
|
58
|
+
*/
|
|
34
59
|
export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement>): CalendarCellAria {
|
|
35
60
|
let {date, isDisabled} = props;
|
|
36
61
|
let formatMessage = useMessageFormatter(intlMessages);
|
|
@@ -204,6 +229,14 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
204
229
|
}
|
|
205
230
|
}, [isFocused, ref]);
|
|
206
231
|
|
|
232
|
+
let cellDateFormatter = useDateFormatter({
|
|
233
|
+
day: 'numeric',
|
|
234
|
+
timeZone: state.timeZone,
|
|
235
|
+
calendar: date.calendar.identifier
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
let formattedDate = useMemo(() => cellDateFormatter.format(nativeDate), [cellDateFormatter, nativeDate]);
|
|
239
|
+
|
|
207
240
|
return {
|
|
208
241
|
cellProps: {
|
|
209
242
|
role: 'gridcell',
|
|
@@ -239,6 +272,11 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
|
|
|
239
272
|
e.preventDefault();
|
|
240
273
|
}
|
|
241
274
|
}),
|
|
242
|
-
isPressed
|
|
275
|
+
isPressed,
|
|
276
|
+
isFocused,
|
|
277
|
+
isSelected,
|
|
278
|
+
isDisabled,
|
|
279
|
+
isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,
|
|
280
|
+
formattedDate
|
|
243
281
|
};
|
|
244
282
|
}
|
package/src/useCalendarGrid.ts
CHANGED
|
@@ -10,24 +10,36 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CalendarDate} from '@internationalized/date';
|
|
13
|
+
import {CalendarDate, startOfWeek} from '@internationalized/date';
|
|
14
14
|
import {CalendarGridAria} from './types';
|
|
15
15
|
import {calendarIds, useSelectedDateDescription, useVisibleRangeDescription} from './utils';
|
|
16
|
-
import {CalendarPropsBase} from '@react-types/calendar';
|
|
17
16
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
18
17
|
import {KeyboardEvent} from 'react';
|
|
19
18
|
import {mergeProps, useDescription, useLabels} from '@react-aria/utils';
|
|
20
|
-
import {useLocale} from '@react-aria/i18n';
|
|
19
|
+
import {useDateFormatter, useLocale} from '@react-aria/i18n';
|
|
21
20
|
|
|
22
|
-
interface CalendarGridProps
|
|
21
|
+
interface CalendarGridProps {
|
|
22
|
+
/**
|
|
23
|
+
* The first date displayed in the calendar grid.
|
|
24
|
+
* Defaults to the first visible date in the calendar.
|
|
25
|
+
* Override this to display multiple date grids in a calendar.
|
|
26
|
+
*/
|
|
23
27
|
startDate?: CalendarDate,
|
|
28
|
+
/**
|
|
29
|
+
* The last date displayed in the calendar grid.
|
|
30
|
+
* Defaults to the last visible date in the calendar.
|
|
31
|
+
* Override this to display multiple date grids in a calendar.
|
|
32
|
+
*/
|
|
24
33
|
endDate?: CalendarDate
|
|
25
34
|
}
|
|
26
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Provides the behavior and accessibility implementation for a calendar grid component.
|
|
38
|
+
* A calendar grid displays a single grid of days within a calendar or range calendar which
|
|
39
|
+
* can be keyboard navigated and selected by the user.
|
|
40
|
+
*/
|
|
27
41
|
export function useCalendarGrid(props: CalendarGridProps, state: CalendarState | RangeCalendarState): CalendarGridAria {
|
|
28
42
|
let {
|
|
29
|
-
isReadOnly = false,
|
|
30
|
-
isDisabled = false,
|
|
31
43
|
startDate = state.visibleRange.start,
|
|
32
44
|
endDate = state.visibleRange.end
|
|
33
45
|
} = props;
|
|
@@ -108,15 +120,31 @@ export function useCalendarGrid(props: CalendarGridProps, state: CalendarState |
|
|
|
108
120
|
'aria-labelledby': calendarIds.get(state)
|
|
109
121
|
});
|
|
110
122
|
|
|
123
|
+
let dayFormatter = useDateFormatter({weekday: 'narrow'});
|
|
124
|
+
let dayFormatterLong = useDateFormatter({weekday: 'long'});
|
|
125
|
+
let {locale} = useLocale();
|
|
126
|
+
let weekStart = startOfWeek(state.visibleRange.start, locale);
|
|
127
|
+
let weekDays = [...new Array(7).keys()].map((index) => {
|
|
128
|
+
let date = weekStart.add({days: index});
|
|
129
|
+
let dateDay = date.toDate(state.timeZone);
|
|
130
|
+
let narrow = dayFormatter.format(dateDay);
|
|
131
|
+
let long = dayFormatterLong.format(dateDay);
|
|
132
|
+
return {
|
|
133
|
+
narrow,
|
|
134
|
+
long
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
|
|
111
138
|
return {
|
|
112
139
|
gridProps: mergeProps(descriptionProps, labelProps, {
|
|
113
140
|
role: 'grid',
|
|
114
|
-
'aria-readonly': isReadOnly || null,
|
|
115
|
-
'aria-disabled': isDisabled || null,
|
|
141
|
+
'aria-readonly': state.isReadOnly || null,
|
|
142
|
+
'aria-disabled': state.isDisabled || null,
|
|
116
143
|
'aria-multiselectable': ('highlightedRange' in state) || undefined,
|
|
117
144
|
onKeyDown,
|
|
118
145
|
onFocus: () => state.setFocused(true),
|
|
119
146
|
onBlur: () => state.setFocused(false)
|
|
120
|
-
})
|
|
147
|
+
}),
|
|
148
|
+
weekDays
|
|
121
149
|
};
|
|
122
150
|
}
|
package/src/useRangeCalendar.ts
CHANGED
|
@@ -17,6 +17,10 @@ import {RefObject, useRef} from 'react';
|
|
|
17
17
|
import {useCalendarBase} from './useCalendarBase';
|
|
18
18
|
import {useEvent, useId} from '@react-aria/utils';
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Provides the behavior and accessibility implementation for a range calendar component.
|
|
22
|
+
* A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
|
|
23
|
+
*/
|
|
20
24
|
export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<HTMLElement>): CalendarAria {
|
|
21
25
|
let res = useCalendarBase(props, state);
|
|
22
26
|
res.nextButtonProps.id = useId();
|
package/src/utils.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {CalendarDate, endOfMonth, isSameDay, startOfMonth
|
|
13
|
+
import {CalendarDate, endOfMonth, isSameDay, startOfMonth} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
15
|
// @ts-ignore
|
|
16
16
|
import intlMessages from '../intl/*.json';
|
|
@@ -36,9 +36,9 @@ export function useSelectedDateDescription(state: CalendarState | RangeCalendarS
|
|
|
36
36
|
// Use a single date message if the start and end dates are the same day,
|
|
37
37
|
// otherwise include both dates.
|
|
38
38
|
if (isSameDay(start, end)) {
|
|
39
|
-
return formatMessage('selectedDateDescription', {date: toDate(
|
|
39
|
+
return formatMessage('selectedDateDescription', {date: start.toDate(state.timeZone)});
|
|
40
40
|
} else {
|
|
41
|
-
return formatMessage('selectedRangeDescription', {start: toDate(
|
|
41
|
+
return formatMessage('selectedRangeDescription', {start: start.toDate(state.timeZone), end: end.toDate(state.timeZone)});
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
return '';
|