@react-aria/calendar 3.0.0-nightly.3134 → 3.0.0-nightly.3156

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/types.d.ts CHANGED
@@ -1,39 +1,94 @@
1
1
  import { AriaButtonProps } from "@react-types/button";
2
2
  import { HTMLAttributes, RefObject } from "react";
3
- import { CalendarProps, DateValue, RangeCalendarProps, CalendarPropsBase } from "@react-types/calendar";
3
+ import { CalendarProps, DateValue, RangeCalendarProps } from "@react-types/calendar";
4
4
  import { CalendarState, RangeCalendarState } from "@react-stately/calendar";
5
5
  import { CalendarDate } from "@internationalized/date";
6
- import { PressProps } from "@react-aria/interactions";
7
6
  export interface CalendarAria {
7
+ /** Props for the calendar grouping element. */
8
8
  calendarProps: HTMLAttributes<HTMLElement>;
9
+ /** Props for the next button. */
9
10
  nextButtonProps: AriaButtonProps;
11
+ /** Props for the previous button. */
10
12
  prevButtonProps: AriaButtonProps;
13
+ /** A description of the visible date range, for use in the calendar title. */
14
+ title: string;
11
15
  }
12
16
  export interface CalendarGridAria {
17
+ /** Props for the date grid element (e.g. `<table>`). */
13
18
  gridProps: HTMLAttributes<HTMLElement>;
19
+ /** A list of week days formatted for the current locale, typically used in column headers. */
20
+ weekDays: WeekDay[];
14
21
  }
22
+ interface WeekDay {
23
+ /** A short name (e.g. single letter) for the day. */
24
+ narrow: string;
25
+ /** The full day name. If not displayed visually, it should be used as the accessiblity name. */
26
+ long: string;
27
+ }
28
+ /**
29
+ * Provides the behavior and accessibility implementation for a calendar component.
30
+ * A calendar displays one or more date grids and allows users to select a single date.
31
+ */
15
32
  export function useCalendar<T extends DateValue>(props: CalendarProps<T>, state: CalendarState): CalendarAria;
33
+ /**
34
+ * Provides the behavior and accessibility implementation for a range calendar component.
35
+ * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
36
+ */
16
37
  export function useRangeCalendar<T extends DateValue>(props: RangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<HTMLElement>): CalendarAria;
17
- interface CalendarGridProps extends CalendarPropsBase {
38
+ interface CalendarGridProps {
39
+ /**
40
+ * The first date displayed in the calendar grid.
41
+ * Defaults to the first visible date in the calendar.
42
+ * Override this to display multiple date grids in a calendar.
43
+ */
18
44
  startDate?: CalendarDate;
45
+ /**
46
+ * The last date displayed in the calendar grid.
47
+ * Defaults to the last visible date in the calendar.
48
+ * Override this to display multiple date grids in a calendar.
49
+ */
19
50
  endDate?: CalendarDate;
20
51
  }
52
+ /**
53
+ * Provides the behavior and accessibility implementation for a calendar grid component.
54
+ * A calendar grid displays a single grid of days within a calendar or range calendar which
55
+ * can be keyboard navigated and selected by the user.
56
+ */
21
57
  export function useCalendarGrid(props: CalendarGridProps, state: CalendarState | RangeCalendarState): CalendarGridAria;
22
58
  export interface AriaCalendarCellProps {
59
+ /** The date that this cell represents. */
23
60
  date: CalendarDate;
61
+ /**
62
+ * Whether the cell is disabled. By default, this is determined by the
63
+ * Calendar's `minValue`, `maxValue`, and `isDisabled` props.
64
+ */
24
65
  isDisabled?: boolean;
25
66
  }
26
67
  interface CalendarCellAria {
27
- cellProps: PressProps & HTMLAttributes<HTMLElement>;
68
+ /** Props for the grid cell element (e.g. `<td>`). */
69
+ cellProps: HTMLAttributes<HTMLElement>;
70
+ /** Props for the button element within the cell. */
28
71
  buttonProps: HTMLAttributes<HTMLElement>;
72
+ /** Whether the cell is currently being pressed. */
29
73
  isPressed: boolean;
74
+ /** Whether the cell is selected. */
75
+ isSelected: boolean;
76
+ /** Whether the cell is focused. */
77
+ isFocused: boolean;
78
+ /** Whether the cell is disabled. */
79
+ isDisabled: boolean;
80
+ /**
81
+ * Whether the cell is outside the visible range of the calendar.
82
+ * For example, dates before the first day of a month in the same week.
83
+ */
84
+ isOutsideVisibleRange: boolean;
85
+ /** The day number formatted according to the current locale. */
86
+ formattedDate: string;
30
87
  }
88
+ /**
89
+ * Provides the behavior and accessibility implementation for a calendar cell component.
90
+ * A calendar cell displays a date cell within a calendar grid which can be selected by the user.
91
+ */
31
92
  export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarState | RangeCalendarState, ref: RefObject<HTMLElement>): CalendarCellAria;
32
- interface CalendarTableHeaderAria {
33
- columnHeaderProps: {
34
- scope?: 'col';
35
- };
36
- }
37
- export function useCalendarTableHeader(): CalendarTableHeaderAria;
38
93
 
39
94
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAeA;IACE,aAAa,EAAE,eAAe,WAAW,CAAC,CAAC;IAC3C,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,EAAE,eAAe,CAAA;CACjC;AAGD;IACE,SAAS,EAAE,eAAe,WAAW,CAAC,CAAA;CACvC;AGPD,4BAA4B,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAE5G;ACAD,iCAAiC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,YAAY,CAmDxJ;ACjDD,2BAA4B,SAAQ,iBAAiB;IACnD,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,gCAAgC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,GAAG,gBAAgB,CA+FrH;ACnGD;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,SAAS,EAAE,UAAU,GAAG,eAAe,WAAW,CAAC,CAAC;IACpD,WAAW,EAAE,eAAe,WAAW,CAAC,CAAC;IACzC,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,gCAAgC,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,aAAa,GAAG,kBAAkB,EAAE,GAAG,EAAE,UAAU,WAAW,CAAC,GAAG,gBAAgB,CAkNtJ;ACnPD;IACE,iBAAiB,EAAE;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAC,CAAA;CACnC;AAED,0CAA0C,uBAAuB,CAMhE","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/useCalendarTableHeader.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,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 './useCalendarTableHeader';\nexport * from './types';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
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,CAwOtJ","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.3134+6fa5706ef",
3
+ "version": "3.0.0-nightly.3156+2c25922e2",
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.3134+6fa5706ef",
22
- "@react-aria/i18n": "3.0.0-nightly.1438+6fa5706ef",
23
- "@react-aria/interactions": "3.0.0-nightly.1438+6fa5706ef",
24
- "@react-aria/live-announcer": "3.0.0-nightly.1438+6fa5706ef",
25
- "@react-aria/utils": "3.0.0-nightly.1438+6fa5706ef",
26
- "@react-stately/calendar": "3.0.0-nightly.1438+6fa5706ef",
27
- "@react-types/button": "3.4.4-nightly.3134+6fa5706ef",
28
- "@react-types/calendar": "3.0.0-nightly.3134+6fa5706ef",
29
- "@react-types/shared": "3.0.0-nightly.1438+6fa5706ef",
21
+ "@internationalized/date": "3.0.0-nightly.3156+2c25922e2",
22
+ "@react-aria/i18n": "3.0.0-nightly.1460+2c25922e2",
23
+ "@react-aria/interactions": "3.0.0-nightly.1460+2c25922e2",
24
+ "@react-aria/live-announcer": "3.0.0-nightly.1460+2c25922e2",
25
+ "@react-aria/utils": "3.0.0-nightly.1460+2c25922e2",
26
+ "@react-stately/calendar": "3.0.0-nightly.1460+2c25922e2",
27
+ "@react-types/button": "3.4.4-nightly.3156+2c25922e2",
28
+ "@react-types/calendar": "3.0.0-nightly.3156+2c25922e2",
29
+ "@react-types/shared": "3.0.0-nightly.1460+2c25922e2",
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": "6fa5706efb7bb7d8c322b8f756c451378ca962ce"
39
+ "gitHead": "2c25922e23ec51bd487b7838adb48a60c558dc36"
40
40
  }
package/src/index.ts CHANGED
@@ -14,5 +14,4 @@ export * from './useCalendar';
14
14
  export * from './useRangeCalendar';
15
15
  export * from './useCalendarGrid';
16
16
  export * from './useCalendarCell';
17
- export * from './useCalendarTableHeader';
18
17
  export * from './types';
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
- prevButtonProps: AriaButtonProps
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
- gridProps: HTMLAttributes<HTMLElement>
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
  }
@@ -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
  }
@@ -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
  }
@@ -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
- cellProps: PressProps & HTMLAttributes<HTMLElement>,
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
- isPressed: boolean
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);
@@ -104,6 +129,11 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
104
129
  preventFocusOnPress: true,
105
130
  isDisabled,
106
131
  onPressStart(e) {
132
+ if (state.isReadOnly) {
133
+ state.setFocusedDate(date);
134
+ return;
135
+ }
136
+
107
137
  if ('highlightedRange' in state && !state.anchorDate && (e.pointerType === 'mouse' || e.pointerType === 'touch')) {
108
138
  // Allow dragging the start or end date of a range to modify it
109
139
  // rather than starting a new selection.
@@ -149,12 +179,16 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
149
179
  },
150
180
  onPress() {
151
181
  // For non-range selection, always select on press up.
152
- if (!('anchorDate' in state)) {
182
+ if (!('anchorDate' in state) && !state.isReadOnly) {
153
183
  state.selectDate(date);
154
184
  state.setFocusedDate(date);
155
185
  }
156
186
  },
157
187
  onPressUp(e) {
188
+ if (state.isReadOnly) {
189
+ return;
190
+ }
191
+
158
192
  // If the user tapped quickly, the date won't be selected yet and the
159
193
  // timer will still be in progress. In this case, select the date on touch up.
160
194
  // Timer is cleared in onPressEnd.
@@ -204,6 +238,14 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
204
238
  }
205
239
  }, [isFocused, ref]);
206
240
 
241
+ let cellDateFormatter = useDateFormatter({
242
+ day: 'numeric',
243
+ timeZone: state.timeZone,
244
+ calendar: date.calendar.identifier
245
+ });
246
+
247
+ let formattedDate = useMemo(() => cellDateFormatter.format(nativeDate), [cellDateFormatter, nativeDate]);
248
+
207
249
  return {
208
250
  cellProps: {
209
251
  role: 'gridcell',
@@ -239,6 +281,11 @@ export function useCalendarCell(props: AriaCalendarCellProps, state: CalendarSta
239
281
  e.preventDefault();
240
282
  }
241
283
  }),
242
- isPressed
284
+ isPressed,
285
+ isFocused,
286
+ isSelected,
287
+ isDisabled,
288
+ isOutsideVisibleRange: date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,
289
+ formattedDate
243
290
  };
244
291
  }
@@ -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 extends CalendarPropsBase {
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
  }
@@ -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, toDate} from '@internationalized/date';
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(start, state.timeZone)});
39
+ return formatMessage('selectedDateDescription', {date: start.toDate(state.timeZone)});
40
40
  } else {
41
- return formatMessage('selectedRangeDescription', {start: toDate(start, state.timeZone), end: toDate(end, state.timeZone)});
41
+ return formatMessage('selectedRangeDescription', {start: start.toDate(state.timeZone), end: end.toDate(state.timeZone)});
42
42
  }
43
43
  }
44
44
  return '';
@@ -1,11 +0,0 @@
1
- interface CalendarTableHeaderAria {
2
- columnHeaderProps: {scope?: 'col'}
3
- }
4
-
5
- export function useCalendarTableHeader(): CalendarTableHeaderAria {
6
- return {
7
- columnHeaderProps: {
8
- scope: 'col'
9
- }
10
- };
11
- }