@react-aria/calendar 3.7.1 → 3.8.0
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 +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useCalendarGrid.main.js +3 -1
- package/dist/useCalendarGrid.main.js.map +1 -1
- package/dist/useCalendarGrid.mjs +4 -2
- package/dist/useCalendarGrid.module.js +4 -2
- package/dist/useCalendarGrid.module.js.map +1 -1
- package/dist/utils.main.js +6 -2
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +6 -2
- package/dist/utils.module.js +6 -2
- package/dist/utils.module.js.map +1 -1
- package/package.json +11 -11
- package/src/useCalendarGrid.ts +7 -3
- package/src/utils.ts +14 -5
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ export interface CalendarGridAria {
|
|
|
56
56
|
headerProps: DOMAttributes;
|
|
57
57
|
/** A list of week day abbreviations formatted for the current locale, typically used in column headers. */
|
|
58
58
|
weekDays: string[];
|
|
59
|
+
/** The number of weeks in the month. */
|
|
60
|
+
weeksInMonth: number;
|
|
59
61
|
}
|
|
60
62
|
/**
|
|
61
63
|
* Provides the behavior and accessibility implementation for a calendar grid component.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;ACwBA;IACE,+CAA+C;IAC/C,aAAa,EAAE,aAAa,CAAC;IAC7B,iCAAiC;IACjC,eAAe,EAAE,eAAe,CAAC;IACjC,qCAAqC;IACrC,eAAe,EAAE,eAAe,CAAC;IACjC,mDAAmD;IACnD,iBAAiB,EAAE,aAAa,CAAC;IACjC,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAA;CACd;ACnBD;;;GAGG;AACH,4BAA4B,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,EAAE,KAAK,EAAE,aAAa,GAAG,YAAY,CAEhH;ACHD;;;GAGG;AACH,iCA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B,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAsR7J;AC/UD,YAAY,EAAC,iBAAiB,EAAE,sBAAsB,EAAE,aAAa,EAAE,SAAS,EAAE,kBAAkB,EAAC,MAAM,uBAAuB,CAAC","sources":["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,"/*\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 {useCalendar} from './useCalendar';\nexport {useRangeCalendar} from './useRangeCalendar';\nexport {useCalendarGrid} from './useCalendarGrid';\nexport {useCalendarCell} from './useCalendarCell';\n\nexport type {AriaCalendarProps, AriaRangeCalendarProps, CalendarProps, DateValue, RangeCalendarProps} from '@react-types/calendar';\nexport type {CalendarAria} from './useCalendarBase';\nexport type {AriaCalendarGridProps, CalendarGridAria} from './useCalendarGrid';\nexport type {AriaCalendarCellProps, CalendarCellAria} from './useCalendarCell';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -117,6 +117,7 @@ function $a07388a797d86b95$export$cb95147730a423f5(props, state) {
|
|
|
117
117
|
dayFormatter,
|
|
118
118
|
firstDayOfWeek
|
|
119
119
|
]);
|
|
120
|
+
let weeksInMonth = (0, $iASLq$internationalizeddate.getWeeksInMonth)(startDate, locale, firstDayOfWeek);
|
|
120
121
|
return {
|
|
121
122
|
gridProps: (0, $iASLq$reactariautils.mergeProps)(labelProps, {
|
|
122
123
|
role: 'grid',
|
|
@@ -132,7 +133,8 @@ function $a07388a797d86b95$export$cb95147730a423f5(props, state) {
|
|
|
132
133
|
// The day names are already included in the label of each cell, so there's no need to announce them twice.
|
|
133
134
|
'aria-hidden': true
|
|
134
135
|
},
|
|
135
|
-
weekDays: weekDays
|
|
136
|
+
weekDays: weekDays,
|
|
137
|
+
weeksInMonth: weeksInMonth
|
|
136
138
|
};
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAmDM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC;IACrG,IAAI,aACF,YAAY,MAAM,YAAY,CAAC,KAAK,WACpC,UAAU,MAAM,YAAY,CAAC,GAAG,kBAChC,cAAc,EACf,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAE1B,IAAI,YAAY,CAAC;QACf,OAAQ,EAAE,GAAG;YACX,KAAK;YACL,KAAK;gBACH,EAAE,cAAc;gBAChB,MAAM,iBAAiB;gBACvB;YACF,KAAK;gBACH,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,MAAM,oBAAoB,CAAC,EAAE,QAAQ;gBACrC;YACF,KAAK;gBACH,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,MAAM,gBAAgB,CAAC,EAAE,QAAQ;gBACjC;YACF,KAAK;gBACH,EAAE,cAAc;gBAChB,EAAE,e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IAAI,MAAM,GAAG,IAAI;SAAG,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,OAAO,UAAU,GAAG,CAAC;gBAAC,MAAM;YAAK;YACrC,IAAI,UAAU,KAAK,MAAM,CAAC,MAAM,QAAQ;YACxC,OAAO,aAAa,MAAM,CAAC;QAC7B;IACF,GAAG;QAAC;QAAQ,MAAM,QAAQ;QAAE;QAAc;KAAe;IACzD,IAAI,eAAe,CAAA,GAAA,4CAAc,EAAE,WAAW,QAAQ;IAEtD,OAAO;QACL,WAAW,CAAA,GAAA,gCAAS,EAAE,YAAY;YAChC,MAAM;YACN,iBAAiB,MAAM,UAAU,IAAI;YACrC,iBAAiB,MAAM,UAAU,IAAI;YACrC,wBAAwB,AAAC,sBAAsB,SAAU;uBACzD;YACA,SAAS,IAAM,MAAM,UAAU,CAAC;YAChC,QAAQ,IAAM,MAAM,UAAU,CAAC;QACjC;QACA,aAAa;YACX,oGAAoG;YACpG,2GAA2G;YAC3G,eAAe;QACjB;kBACA;sBACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarGrid.ts"],"sourcesContent":["/*\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\nimport {CalendarDate, getWeeksInMonth, startOfWeek, today} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes} from '@react-types/shared';\nimport {hookData, useVisibleRangeDescription} from './utils';\nimport {KeyboardEvent, useMemo} from 'react';\nimport {mergeProps, useLabels} from '@react-aria/utils';\nimport {useDateFormatter, useLocale} from '@react-aria/i18n';\n\nexport interface AriaCalendarGridProps {\n /**\n * The first date displayed in the calendar grid.\n * Defaults to the first visible date in the calendar.\n * Override this to display multiple date grids in a calendar.\n */\n startDate?: CalendarDate,\n /**\n * The last date displayed in the calendar grid.\n * Defaults to the last visible date in the calendar.\n * Override this to display multiple date grids in a calendar.\n */\n endDate?: CalendarDate,\n /**\n * The style of weekday names to display in the calendar grid header,\n * e.g. single letter, abbreviation, or full day name.\n * @default \"narrow\"\n */\n weekdayStyle?: 'narrow' | 'short' | 'long',\n /**\n * The day that starts the week.\n */\n firstDayOfWeek?: 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'\n}\n\nexport interface CalendarGridAria {\n /** Props for the date grid element (e.g. `<table>`). */\n gridProps: DOMAttributes,\n /** Props for the grid header element (e.g. `<thead>`). */\n headerProps: DOMAttributes,\n /** A list of week day abbreviations formatted for the current locale, typically used in column headers. */\n weekDays: string[],\n /** The number of weeks in the month. */\n weeksInMonth: number\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar grid component.\n * A calendar grid displays a single grid of days within a calendar or range calendar which\n * can be keyboard navigated and selected by the user.\n */\nexport function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarState | RangeCalendarState): CalendarGridAria {\n let {\n startDate = state.visibleRange.start,\n endDate = state.visibleRange.end,\n firstDayOfWeek\n } = props;\n\n let {direction} = useLocale();\n\n let onKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n state.selectFocusedDate();\n break;\n case 'PageUp':\n e.preventDefault();\n e.stopPropagation();\n state.focusPreviousSection(e.shiftKey);\n break;\n case 'PageDown':\n e.preventDefault();\n e.stopPropagation();\n state.focusNextSection(e.shiftKey);\n break;\n case 'End':\n e.preventDefault();\n e.stopPropagation();\n state.focusSectionEnd();\n break;\n case 'Home':\n e.preventDefault();\n e.stopPropagation();\n state.focusSectionStart();\n break;\n case 'ArrowLeft':\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n state.focusNextDay();\n } else {\n state.focusPreviousDay();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n state.focusPreviousRow();\n break;\n case 'ArrowRight':\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n state.focusPreviousDay();\n } else {\n state.focusNextDay();\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n state.focusNextRow();\n break;\n case 'Escape':\n // Cancel the selection.\n if ('setAnchorDate' in state) {\n e.preventDefault();\n state.setAnchorDate(null);\n }\n break;\n }\n };\n\n let visibleRangeDescription = useVisibleRangeDescription(startDate, endDate, state.timeZone, true);\n\n let {ariaLabel, ariaLabelledBy} = hookData.get(state)!;\n let labelProps = useLabels({\n 'aria-label': [ariaLabel, visibleRangeDescription].filter(Boolean).join(', '),\n 'aria-labelledby': ariaLabelledBy\n });\n\n let dayFormatter = useDateFormatter({weekday: props.weekdayStyle || 'narrow', timeZone: state.timeZone});\n let {locale} = useLocale();\n let weekDays = useMemo(() => {\n let weekStart = startOfWeek(today(state.timeZone), locale, firstDayOfWeek);\n return [...new Array(7).keys()].map((index) => {\n let date = weekStart.add({days: index});\n let dateDay = date.toDate(state.timeZone);\n return dayFormatter.format(dateDay);\n });\n }, [locale, state.timeZone, dayFormatter, firstDayOfWeek]);\n let weeksInMonth = getWeeksInMonth(startDate, locale, firstDayOfWeek);\n\n return {\n gridProps: mergeProps(labelProps, {\n role: 'grid',\n 'aria-readonly': state.isReadOnly || undefined,\n 'aria-disabled': state.isDisabled || undefined,\n 'aria-multiselectable': ('highlightedRange' in state) || undefined,\n onKeyDown,\n onFocus: () => state.setFocused(true),\n onBlur: () => state.setFocused(false)\n }),\n headerProps: {\n // Column headers are hidden to screen readers to make navigating with a touch screen reader easier.\n // The day names are already included in the label of each cell, so there's no need to announce them twice.\n 'aria-hidden': true\n },\n weekDays,\n weeksInMonth\n };\n}\n"],"names":[],"version":3,"file":"useCalendarGrid.main.js.map"}
|
package/dist/useCalendarGrid.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {hookData as $a074e1e2d0f0a665$export$653eddfc964b0f8a, useVisibleRangeDescription as $a074e1e2d0f0a665$export$31afe65d91ef6e8} from "./utils.mjs";
|
|
2
|
-
import {startOfWeek as $NQfxu$startOfWeek, today as $NQfxu$today} from "@internationalized/date";
|
|
2
|
+
import {startOfWeek as $NQfxu$startOfWeek, today as $NQfxu$today, getWeeksInMonth as $NQfxu$getWeeksInMonth} from "@internationalized/date";
|
|
3
3
|
import {useMemo as $NQfxu$useMemo} from "react";
|
|
4
4
|
import {useLabels as $NQfxu$useLabels, mergeProps as $NQfxu$mergeProps} from "@react-aria/utils";
|
|
5
5
|
import {useLocale as $NQfxu$useLocale, useDateFormatter as $NQfxu$useDateFormatter} from "@react-aria/i18n";
|
|
@@ -111,6 +111,7 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
|
|
|
111
111
|
dayFormatter,
|
|
112
112
|
firstDayOfWeek
|
|
113
113
|
]);
|
|
114
|
+
let weeksInMonth = (0, $NQfxu$getWeeksInMonth)(startDate, locale, firstDayOfWeek);
|
|
114
115
|
return {
|
|
115
116
|
gridProps: (0, $NQfxu$mergeProps)(labelProps, {
|
|
116
117
|
role: 'grid',
|
|
@@ -126,7 +127,8 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
|
|
|
126
127
|
// The day names are already included in the label of each cell, so there's no need to announce them twice.
|
|
127
128
|
'aria-hidden': true
|
|
128
129
|
},
|
|
129
|
-
weekDays: weekDays
|
|
130
|
+
weekDays: weekDays,
|
|
131
|
+
weeksInMonth: weeksInMonth
|
|
130
132
|
};
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {hookData as $a074e1e2d0f0a665$export$653eddfc964b0f8a, useVisibleRangeDescription as $a074e1e2d0f0a665$export$31afe65d91ef6e8} from "./utils.module.js";
|
|
2
|
-
import {startOfWeek as $NQfxu$startOfWeek, today as $NQfxu$today} from "@internationalized/date";
|
|
2
|
+
import {startOfWeek as $NQfxu$startOfWeek, today as $NQfxu$today, getWeeksInMonth as $NQfxu$getWeeksInMonth} from "@internationalized/date";
|
|
3
3
|
import {useMemo as $NQfxu$useMemo} from "react";
|
|
4
4
|
import {useLabels as $NQfxu$useLabels, mergeProps as $NQfxu$mergeProps} from "@react-aria/utils";
|
|
5
5
|
import {useLocale as $NQfxu$useLocale, useDateFormatter as $NQfxu$useDateFormatter} from "@react-aria/i18n";
|
|
@@ -111,6 +111,7 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
|
|
|
111
111
|
dayFormatter,
|
|
112
112
|
firstDayOfWeek
|
|
113
113
|
]);
|
|
114
|
+
let weeksInMonth = (0, $NQfxu$getWeeksInMonth)(startDate, locale, firstDayOfWeek);
|
|
114
115
|
return {
|
|
115
116
|
gridProps: (0, $NQfxu$mergeProps)(labelProps, {
|
|
116
117
|
role: 'grid',
|
|
@@ -126,7 +127,8 @@ function $e3031d1f8c9d64eb$export$cb95147730a423f5(props, state) {
|
|
|
126
127
|
// The day names are already included in the label of each cell, so there's no need to announce them twice.
|
|
127
128
|
'aria-hidden': true
|
|
128
129
|
},
|
|
129
|
-
weekDays: weekDays
|
|
130
|
+
weekDays: weekDays,
|
|
131
|
+
weeksInMonth: weeksInMonth
|
|
130
132
|
};
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAmDM,SAAS,0CAAgB,KAA4B,EAAE,KAAyC;IACrG,IAAI,aACF,YAAY,MAAM,YAAY,CAAC,KAAK,WACpC,UAAU,MAAM,YAAY,CAAC,GAAG,kBAChC,cAAc,EACf,GAAG;IAEJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IA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IAAI,CAAC;QACxE,mBAAmB;IACrB;IAEA,IAAI,eAAe,CAAA,GAAA,uBAAe,EAAE;QAAC,SAAS,MAAM,YAAY,IAAI;QAAU,UAAU,MAAM,QAAQ;IAAA;IACtG,IAAI,UAAC,MAAM,EAAC,GAAG,CAAA,GAAA,gBAAQ;IACvB,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE;QACrB,IAAI,YAAY,CAAA,GAAA,kBAAU,EAAE,CAAA,GAAA,YAAI,EAAE,MAAM,QAAQ,GAAG,QAAQ;QAC3D,OAAO;eAAI,IAAI,MAAM,GAAG,IAAI;SAAG,CAAC,GAAG,CAAC,CAAC;YACnC,IAAI,OAAO,UAAU,GAAG,CAAC;gBAAC,MAAM;YAAK;YACrC,IAAI,UAAU,KAAK,MAAM,CAAC,MAAM,QAAQ;YACxC,OAAO,aAAa,MAAM,CAAC;QAC7B;IACF,GAAG;QAAC;QAAQ,MAAM,QAAQ;QAAE;QAAc;KAAe;IACzD,IAAI,eAAe,CAAA,GAAA,sBAAc,EAAE,WAAW,QAAQ;IAEtD,OAAO;QACL,WAAW,CAAA,GAAA,iBAAS,EAAE,YAAY;YAChC,MAAM;YACN,iBAAiB,MAAM,UAAU,IAAI;YACrC,iBAAiB,MAAM,UAAU,IAAI;YACrC,wBAAwB,AAAC,sBAAsB,SAAU;uBACzD;YACA,SAAS,IAAM,MAAM,UAAU,CAAC;YAChC,QAAQ,IAAM,MAAM,UAAU,CAAC;QACjC;QACA,aAAa;YACX,oGAAoG;YACpG,2GAA2G;YAC3G,eAAe;QACjB;kBACA;sBACA;IACF;AACF","sources":["packages/@react-aria/calendar/src/useCalendarGrid.ts"],"sourcesContent":["/*\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\nimport {CalendarDate, getWeeksInMonth, startOfWeek, today} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\nimport {DOMAttributes} from '@react-types/shared';\nimport {hookData, useVisibleRangeDescription} from './utils';\nimport {KeyboardEvent, useMemo} from 'react';\nimport {mergeProps, useLabels} from '@react-aria/utils';\nimport {useDateFormatter, useLocale} from '@react-aria/i18n';\n\nexport interface AriaCalendarGridProps {\n /**\n * The first date displayed in the calendar grid.\n * Defaults to the first visible date in the calendar.\n * Override this to display multiple date grids in a calendar.\n */\n startDate?: CalendarDate,\n /**\n * The last date displayed in the calendar grid.\n * Defaults to the last visible date in the calendar.\n * Override this to display multiple date grids in a calendar.\n */\n endDate?: CalendarDate,\n /**\n * The style of weekday names to display in the calendar grid header,\n * e.g. single letter, abbreviation, or full day name.\n * @default \"narrow\"\n */\n weekdayStyle?: 'narrow' | 'short' | 'long',\n /**\n * The day that starts the week.\n */\n firstDayOfWeek?: 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat'\n}\n\nexport interface CalendarGridAria {\n /** Props for the date grid element (e.g. `<table>`). */\n gridProps: DOMAttributes,\n /** Props for the grid header element (e.g. `<thead>`). */\n headerProps: DOMAttributes,\n /** A list of week day abbreviations formatted for the current locale, typically used in column headers. */\n weekDays: string[],\n /** The number of weeks in the month. */\n weeksInMonth: number\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar grid component.\n * A calendar grid displays a single grid of days within a calendar or range calendar which\n * can be keyboard navigated and selected by the user.\n */\nexport function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarState | RangeCalendarState): CalendarGridAria {\n let {\n startDate = state.visibleRange.start,\n endDate = state.visibleRange.end,\n firstDayOfWeek\n } = props;\n\n let {direction} = useLocale();\n\n let onKeyDown = (e: KeyboardEvent) => {\n switch (e.key) {\n case 'Enter':\n case ' ':\n e.preventDefault();\n state.selectFocusedDate();\n break;\n case 'PageUp':\n e.preventDefault();\n e.stopPropagation();\n state.focusPreviousSection(e.shiftKey);\n break;\n case 'PageDown':\n e.preventDefault();\n e.stopPropagation();\n state.focusNextSection(e.shiftKey);\n break;\n case 'End':\n e.preventDefault();\n e.stopPropagation();\n state.focusSectionEnd();\n break;\n case 'Home':\n e.preventDefault();\n e.stopPropagation();\n state.focusSectionStart();\n break;\n case 'ArrowLeft':\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n state.focusNextDay();\n } else {\n state.focusPreviousDay();\n }\n break;\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n state.focusPreviousRow();\n break;\n case 'ArrowRight':\n e.preventDefault();\n e.stopPropagation();\n if (direction === 'rtl') {\n state.focusPreviousDay();\n } else {\n state.focusNextDay();\n }\n break;\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n state.focusNextRow();\n break;\n case 'Escape':\n // Cancel the selection.\n if ('setAnchorDate' in state) {\n e.preventDefault();\n state.setAnchorDate(null);\n }\n break;\n }\n };\n\n let visibleRangeDescription = useVisibleRangeDescription(startDate, endDate, state.timeZone, true);\n\n let {ariaLabel, ariaLabelledBy} = hookData.get(state)!;\n let labelProps = useLabels({\n 'aria-label': [ariaLabel, visibleRangeDescription].filter(Boolean).join(', '),\n 'aria-labelledby': ariaLabelledBy\n });\n\n let dayFormatter = useDateFormatter({weekday: props.weekdayStyle || 'narrow', timeZone: state.timeZone});\n let {locale} = useLocale();\n let weekDays = useMemo(() => {\n let weekStart = startOfWeek(today(state.timeZone), locale, firstDayOfWeek);\n return [...new Array(7).keys()].map((index) => {\n let date = weekStart.add({days: index});\n let dateDay = date.toDate(state.timeZone);\n return dayFormatter.format(dateDay);\n });\n }, [locale, state.timeZone, dayFormatter, firstDayOfWeek]);\n let weeksInMonth = getWeeksInMonth(startDate, locale, firstDayOfWeek);\n\n return {\n gridProps: mergeProps(labelProps, {\n role: 'grid',\n 'aria-readonly': state.isReadOnly || undefined,\n 'aria-disabled': state.isDisabled || undefined,\n 'aria-multiselectable': ('highlightedRange' in state) || undefined,\n onKeyDown,\n onFocus: () => state.setFocused(true),\n onBlur: () => state.setFocused(false)\n }),\n headerProps: {\n // Column headers are hidden to screen readers to make navigating with a touch screen reader easier.\n // The day names are already included in the label of each cell, so there's no need to announce them twice.\n 'aria-hidden': true\n },\n weekDays,\n weeksInMonth\n };\n}\n"],"names":[],"version":3,"file":"useCalendarGrid.module.js.map"}
|
package/dist/utils.main.js
CHANGED
|
@@ -98,8 +98,12 @@ function $df1d8e967e73ec8e$export$31afe65d91ef6e8(startDate, endDate, timeZone,
|
|
|
98
98
|
// Special case for month granularity. Format as a single month if only a
|
|
99
99
|
// single month is visible, otherwise format as a range of months.
|
|
100
100
|
if ((0, $idq92$internationalizeddate.isSameDay)(startDate, (0, $idq92$internationalizeddate.startOfMonth)(startDate))) {
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
let startMonth = startDate;
|
|
102
|
+
let endMonth = endDate;
|
|
103
|
+
if (startDate.calendar.getFormattableMonth) startMonth = startDate.calendar.getFormattableMonth(startDate);
|
|
104
|
+
if (endDate.calendar.getFormattableMonth) endMonth = endDate.calendar.getFormattableMonth(endDate);
|
|
105
|
+
if ((0, $idq92$internationalizeddate.isSameDay)(endDate, (0, $idq92$internationalizeddate.endOfMonth)(startDate))) return monthFormatter.format(startMonth.toDate(timeZone));
|
|
106
|
+
else if ((0, $idq92$internationalizeddate.isSameDay)(endDate, (0, $idq92$internationalizeddate.endOfMonth)(endDate))) return isAria ? $df1d8e967e73ec8e$var$formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone) : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));
|
|
103
107
|
}
|
|
104
108
|
return isAria ? $df1d8e967e73ec8e$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(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I,KAAK,MAAM,KAAK,YACzB;IAEJ;IAEA,2DAA2D;IAC3D,IAAI,aAAa;IACjB,IAAI,WAAW;IACf,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,IAAI,gBACN,cAAc,KAAK,CAAC,EAAE,CAAC,KAAK;aACvB,IAAI,IAAI,gBACb,YAAY,KAAK,CAAC,EAAE,CAAC,KAAK;IAE9B;IAEA,OAAO,gBAAgB,MAAM,CAAC,aAAa;QAAC,WAAW;QAAY,SAAS;IAAQ;AACtF","sources":["packages/@react-aria/calendar/src/utils.ts"],"sourcesContent":["/*\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\nimport {CalendarDate, DateFormatter, endOfMonth, isSameDay, startOfMonth} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport type {LocalizedStringFormatter} from '@internationalized/string';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMemo} from 'react';\n\ninterface HookData {\n ariaLabel?: string,\n ariaLabelledBy?: string,\n errorMessageId: string,\n selectedDateDescription: string\n}\n\nexport const hookData = new WeakMap<CalendarState | RangeCalendarState, HookData>();\n\nexport function getEraFormat(date: CalendarDate | undefined): 'short' | undefined {\n return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;\n}\n\nexport function useSelectedDateDescription(state: CalendarState | RangeCalendarState): string {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n\n let start: CalendarDate | undefined, end: CalendarDate | undefined;\n if ('highlightedRange' in state) {\n ({start, end} = state.highlightedRange || {});\n } else {\n start = end = state.value ?? undefined;\n }\n\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era: getEraFormat(start) || getEraFormat(end),\n timeZone: state.timeZone\n });\n\n let anchorDate = 'anchorDate' in state ? state.anchorDate : null;\n return useMemo(() => {\n // No message if currently selecting a range, or there is nothing highlighted.\n if (!anchorDate && start && end) {\n // Use a single date message if the start and end dates are the same day,\n // otherwise include both dates.\n if (isSameDay(start, end)) {\n let date = dateFormatter.format(start.toDate(state.timeZone));\n return stringFormatter.format('selectedDateDescription', {date});\n } else {\n let dateRange = formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);\n\n return stringFormatter.format('selectedRangeDescription', {dateRange});\n }\n }\n return '';\n }, [start, end, anchorDate, state.timeZone, stringFormatter, dateFormatter]);\n}\n\nexport function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean): string {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let era: any = getEraFormat(startDate) || getEraFormat(endDate);\n let monthFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n let dateFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n return useMemo(() => {\n // Special case for month granularity. Format as a single month if only a\n // single month is visible, otherwise format as a range of months.\n if (isSameDay(startDate, startOfMonth(startDate))) {\n let startMonth = startDate;\n let endMonth = endDate;\n if (startDate.calendar.getFormattableMonth) {\n startMonth = startDate.calendar.getFormattableMonth(startDate);\n }\n if (endDate.calendar.getFormattableMonth) {\n endMonth = endDate.calendar.getFormattableMonth(endDate);\n }\n\n if (isSameDay(endDate, endOfMonth(startDate))) {\n return monthFormatter.format(startMonth.toDate(timeZone));\n } else if (isSameDay(endDate, endOfMonth(endDate))) {\n return isAria\n ? formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone)\n : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));\n }\n }\n\n return isAria\n ? formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone)\n : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));\n }, [startDate, endDate, monthFormatter, dateFormatter, stringFormatter, timeZone, isAria]);\n}\n\nfunction formatRange(dateFormatter: DateFormatter, stringFormatter: LocalizedStringFormatter, start: CalendarDate, end: CalendarDate, timeZone: string) {\n let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));\n\n // Find the separator between the start and end date. This is determined\n // by finding the last shared literal before the end range.\n let separatorIndex = -1;\n for (let i = 0; i < parts.length; i++) {\n let part = parts[i];\n if (part.source === 'shared' && part.type === 'literal') {\n separatorIndex = i;\n } else if (part.source === 'endRange') {\n break;\n }\n }\n\n // Now we can combine the parts into start and end strings.\n let startValue = '';\n let endValue = '';\n for (let i = 0; i < parts.length; i++) {\n if (i < separatorIndex) {\n startValue += parts[i].value;\n } else if (i > separatorIndex) {\n endValue += parts[i].value;\n }\n }\n\n return stringFormatter.format('dateRange', {startDate: startValue, endDate: endValue});\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
|
package/dist/utils.mjs
CHANGED
|
@@ -89,8 +89,12 @@ function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone,
|
|
|
89
89
|
// Special case for month granularity. Format as a single month if only a
|
|
90
90
|
// single month is visible, otherwise format as a range of months.
|
|
91
91
|
if ((0, $3HATx$isSameDay)(startDate, (0, $3HATx$startOfMonth)(startDate))) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
let startMonth = startDate;
|
|
93
|
+
let endMonth = endDate;
|
|
94
|
+
if (startDate.calendar.getFormattableMonth) startMonth = startDate.calendar.getFormattableMonth(startDate);
|
|
95
|
+
if (endDate.calendar.getFormattableMonth) endMonth = endDate.calendar.getFormattableMonth(endDate);
|
|
96
|
+
if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(startDate))) return monthFormatter.format(startMonth.toDate(timeZone));
|
|
97
|
+
else if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(endDate))) return isAria ? $a074e1e2d0f0a665$var$formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone) : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));
|
|
94
98
|
}
|
|
95
99
|
return isAria ? $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
96
100
|
}, [
|
package/dist/utils.module.js
CHANGED
|
@@ -89,8 +89,12 @@ function $a074e1e2d0f0a665$export$31afe65d91ef6e8(startDate, endDate, timeZone,
|
|
|
89
89
|
// Special case for month granularity. Format as a single month if only a
|
|
90
90
|
// single month is visible, otherwise format as a range of months.
|
|
91
91
|
if ((0, $3HATx$isSameDay)(startDate, (0, $3HATx$startOfMonth)(startDate))) {
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
let startMonth = startDate;
|
|
93
|
+
let endMonth = endDate;
|
|
94
|
+
if (startDate.calendar.getFormattableMonth) startMonth = startDate.calendar.getFormattableMonth(startDate);
|
|
95
|
+
if (endDate.calendar.getFormattableMonth) endMonth = endDate.calendar.getFormattableMonth(endDate);
|
|
96
|
+
if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(startDate))) return monthFormatter.format(startMonth.toDate(timeZone));
|
|
97
|
+
else if ((0, $3HATx$isSameDay)(endDate, (0, $3HATx$endOfMonth)(endDate))) return isAria ? $a074e1e2d0f0a665$var$formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone) : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));
|
|
94
98
|
}
|
|
95
99
|
return isAria ? $a074e1e2d0f0a665$var$formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone) : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));
|
|
96
100
|
}, [
|
package/dist/utils.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiBM,MAAM,4CAAW,IAAI;AAErB,SAAS,0CAAa,IAA8B;IACzD,OAAO,CAAA,iBAAA,2BAAA,KAAM,QAAQ,CAAC,UAAU,MAAK,aAAa,KAAK,GAAG,KAAK,OAAO,UAAU;AAClF;AAEO,SAAS,0CAA2B,KAAyC;IAClF,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAEhE,IAAI,OAAiC;QAIrB;IAHhB,IAAI,sBAAsB,OACvB,CAAA,SAAC,KAAK,OAAE,GAAG,EAAC,GAAG,MAAM,gBAAgB,IAAI,CAAC,CAAA;SAE3C,QAAQ,MAAM,CAAA,eAAA,MAAM,KAAK,cAAX,0BAAA,eAAe;IAG/B,IAAI,gBAAgB,CAAA,GAAA,uBAAe,EAAE;QACnC,SAAS;QACT,OAAO;QACP,MAAM;QACN,KAAK;QACL,KAAK,0CAAa,UAAU,0CAAa;QACzC,UAAU,MAAM,QAAQ;IAC1B;IAEA,IAAI,aAAa,gBAAgB,QAAQ,MAAM,UAAU,GAAG;IAC5D,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,8EAA8E;QAC9E,IAAI,CAAC,cAAc,SAAS;YAC1B,yEAAyE;YACzE,gCAAgC;YAChC,IAAI,CAAA,GAAA,gBAAQ,EAAE,OAAO,MAAM;gBACzB,IAAI,OAAO,cAAc,MAAM,CAAC,MAAM,MAAM,CAAC,MAAM,QAAQ;gBAC3D,OAAO,gBAAgB,MAAM,CAAC,2BAA2B;0BAAC;gBAAI;YAChE,OAAO;gBACL,IAAI,YAAY,kCA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E;QACnB,IAAI,KAAK,MAAM,KAAK,YAAY,KAAK,IAAI,KAAK,WAC5C,iBAAiB;aACZ,IAAI,KAAK,MAAM,KAAK,YACzB;IAEJ;IAEA,2DAA2D;IAC3D,IAAI,aAAa;IACjB,IAAI,WAAW;IACf,IAAK,IAAI,IAAI,GAAG,IAAI,MAAM,MAAM,EAAE,IAAK;QACrC,IAAI,IAAI,gBACN,cAAc,KAAK,CAAC,EAAE,CAAC,KAAK;aACvB,IAAI,IAAI,gBACb,YAAY,KAAK,CAAC,EAAE,CAAC,KAAK;IAE9B;IAEA,OAAO,gBAAgB,MAAM,CAAC,aAAa;QAAC,WAAW;QAAY,SAAS;IAAQ;AACtF","sources":["packages/@react-aria/calendar/src/utils.ts"],"sourcesContent":["/*\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\nimport {CalendarDate, DateFormatter, endOfMonth, isSameDay, startOfMonth} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from '@react-stately/calendar';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport type {LocalizedStringFormatter} from '@internationalized/string';\nimport {useDateFormatter, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useMemo} from 'react';\n\ninterface HookData {\n ariaLabel?: string,\n ariaLabelledBy?: string,\n errorMessageId: string,\n selectedDateDescription: string\n}\n\nexport const hookData = new WeakMap<CalendarState | RangeCalendarState, HookData>();\n\nexport function getEraFormat(date: CalendarDate | undefined): 'short' | undefined {\n return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;\n}\n\nexport function useSelectedDateDescription(state: CalendarState | RangeCalendarState): string {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n\n let start: CalendarDate | undefined, end: CalendarDate | undefined;\n if ('highlightedRange' in state) {\n ({start, end} = state.highlightedRange || {});\n } else {\n start = end = state.value ?? undefined;\n }\n\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era: getEraFormat(start) || getEraFormat(end),\n timeZone: state.timeZone\n });\n\n let anchorDate = 'anchorDate' in state ? state.anchorDate : null;\n return useMemo(() => {\n // No message if currently selecting a range, or there is nothing highlighted.\n if (!anchorDate && start && end) {\n // Use a single date message if the start and end dates are the same day,\n // otherwise include both dates.\n if (isSameDay(start, end)) {\n let date = dateFormatter.format(start.toDate(state.timeZone));\n return stringFormatter.format('selectedDateDescription', {date});\n } else {\n let dateRange = formatRange(dateFormatter, stringFormatter, start, end, state.timeZone);\n\n return stringFormatter.format('selectedRangeDescription', {dateRange});\n }\n }\n return '';\n }, [start, end, anchorDate, state.timeZone, stringFormatter, dateFormatter]);\n}\n\nexport function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean): string {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let era: any = getEraFormat(startDate) || getEraFormat(endDate);\n let monthFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n let dateFormatter = useDateFormatter({\n month: 'long',\n year: 'numeric',\n day: 'numeric',\n era,\n calendar: startDate.calendar.identifier,\n timeZone\n });\n\n return useMemo(() => {\n // Special case for month granularity. Format as a single month if only a\n // single month is visible, otherwise format as a range of months.\n if (isSameDay(startDate, startOfMonth(startDate))) {\n let startMonth = startDate;\n let endMonth = endDate;\n if (startDate.calendar.getFormattableMonth) {\n startMonth = startDate.calendar.getFormattableMonth(startDate);\n }\n if (endDate.calendar.getFormattableMonth) {\n endMonth = endDate.calendar.getFormattableMonth(endDate);\n }\n\n if (isSameDay(endDate, endOfMonth(startDate))) {\n return monthFormatter.format(startMonth.toDate(timeZone));\n } else if (isSameDay(endDate, endOfMonth(endDate))) {\n return isAria\n ? formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone)\n : monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));\n }\n }\n\n return isAria\n ? formatRange(dateFormatter, stringFormatter, startDate, endDate, timeZone)\n : dateFormatter.formatRange(startDate.toDate(timeZone), endDate.toDate(timeZone));\n }, [startDate, endDate, monthFormatter, dateFormatter, stringFormatter, timeZone, isAria]);\n}\n\nfunction formatRange(dateFormatter: DateFormatter, stringFormatter: LocalizedStringFormatter, start: CalendarDate, end: CalendarDate, timeZone: string) {\n let parts = dateFormatter.formatRangeToParts(start.toDate(timeZone), end.toDate(timeZone));\n\n // Find the separator between the start and end date. This is determined\n // by finding the last shared literal before the end range.\n let separatorIndex = -1;\n for (let i = 0; i < parts.length; i++) {\n let part = parts[i];\n if (part.source === 'shared' && part.type === 'literal') {\n separatorIndex = i;\n } else if (part.source === 'endRange') {\n break;\n }\n }\n\n // Now we can combine the parts into start and end strings.\n let startValue = '';\n let endValue = '';\n for (let i = 0; i < parts.length; i++) {\n if (i < separatorIndex) {\n startValue += parts[i].value;\n } else if (i > separatorIndex) {\n endValue += parts[i].value;\n }\n }\n\n return stringFormatter.format('dateRange', {startDate: startValue, endDate: endValue});\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/calendar",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@internationalized/date": "^3.
|
|
26
|
-
"@react-aria/i18n": "^3.12.
|
|
27
|
-
"@react-aria/interactions": "^3.
|
|
28
|
-
"@react-aria/live-announcer": "^3.4.
|
|
29
|
-
"@react-aria/utils": "^3.28.
|
|
30
|
-
"@react-stately/calendar": "^3.
|
|
31
|
-
"@react-types/button": "^3.
|
|
32
|
-
"@react-types/calendar": "^3.
|
|
33
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@internationalized/date": "^3.8.0",
|
|
26
|
+
"@react-aria/i18n": "^3.12.8",
|
|
27
|
+
"@react-aria/interactions": "^3.25.0",
|
|
28
|
+
"@react-aria/live-announcer": "^3.4.2",
|
|
29
|
+
"@react-aria/utils": "^3.28.2",
|
|
30
|
+
"@react-stately/calendar": "^3.8.0",
|
|
31
|
+
"@react-types/button": "^3.12.0",
|
|
32
|
+
"@react-types/calendar": "^3.7.0",
|
|
33
|
+
"@react-types/shared": "^3.29.0",
|
|
34
34
|
"@swc/helpers": "^0.5.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "9b66d270572f482948afee95622a85cdf68ed408"
|
|
44
44
|
}
|
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, today} from '@internationalized/date';
|
|
13
|
+
import {CalendarDate, getWeeksInMonth, startOfWeek, today} from '@internationalized/date';
|
|
14
14
|
import {CalendarState, RangeCalendarState} from '@react-stately/calendar';
|
|
15
15
|
import {DOMAttributes} from '@react-types/shared';
|
|
16
16
|
import {hookData, useVisibleRangeDescription} from './utils';
|
|
@@ -49,7 +49,9 @@ export interface CalendarGridAria {
|
|
|
49
49
|
/** Props for the grid header element (e.g. `<thead>`). */
|
|
50
50
|
headerProps: DOMAttributes,
|
|
51
51
|
/** A list of week day abbreviations formatted for the current locale, typically used in column headers. */
|
|
52
|
-
weekDays: string[]
|
|
52
|
+
weekDays: string[],
|
|
53
|
+
/** The number of weeks in the month. */
|
|
54
|
+
weeksInMonth: number
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/**
|
|
@@ -149,6 +151,7 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
149
151
|
return dayFormatter.format(dateDay);
|
|
150
152
|
});
|
|
151
153
|
}, [locale, state.timeZone, dayFormatter, firstDayOfWeek]);
|
|
154
|
+
let weeksInMonth = getWeeksInMonth(startDate, locale, firstDayOfWeek);
|
|
152
155
|
|
|
153
156
|
return {
|
|
154
157
|
gridProps: mergeProps(labelProps, {
|
|
@@ -165,6 +168,7 @@ export function useCalendarGrid(props: AriaCalendarGridProps, state: CalendarSta
|
|
|
165
168
|
// The day names are already included in the label of each cell, so there's no need to announce them twice.
|
|
166
169
|
'aria-hidden': true
|
|
167
170
|
},
|
|
168
|
-
weekDays
|
|
171
|
+
weekDays,
|
|
172
|
+
weeksInMonth
|
|
169
173
|
};
|
|
170
174
|
}
|
package/src/utils.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function getEraFormat(date: CalendarDate | undefined): 'short' | undefine
|
|
|
31
31
|
return date?.calendar.identifier === 'gregory' && date.era === 'BC' ? 'short' : undefined;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function useSelectedDateDescription(state: CalendarState | RangeCalendarState) {
|
|
34
|
+
export function useSelectedDateDescription(state: CalendarState | RangeCalendarState): string {
|
|
35
35
|
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');
|
|
36
36
|
|
|
37
37
|
let start: CalendarDate | undefined, end: CalendarDate | undefined;
|
|
@@ -69,7 +69,7 @@ export function useSelectedDateDescription(state: CalendarState | RangeCalendarS
|
|
|
69
69
|
}, [start, end, anchorDate, state.timeZone, stringFormatter, dateFormatter]);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
export function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean) {
|
|
72
|
+
export function useVisibleRangeDescription(startDate: CalendarDate, endDate: CalendarDate, timeZone: string, isAria: boolean): string {
|
|
73
73
|
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');
|
|
74
74
|
let era: any = getEraFormat(startDate) || getEraFormat(endDate);
|
|
75
75
|
let monthFormatter = useDateFormatter({
|
|
@@ -93,12 +93,21 @@ export function useVisibleRangeDescription(startDate: CalendarDate, endDate: Cal
|
|
|
93
93
|
// Special case for month granularity. Format as a single month if only a
|
|
94
94
|
// single month is visible, otherwise format as a range of months.
|
|
95
95
|
if (isSameDay(startDate, startOfMonth(startDate))) {
|
|
96
|
+
let startMonth = startDate;
|
|
97
|
+
let endMonth = endDate;
|
|
98
|
+
if (startDate.calendar.getFormattableMonth) {
|
|
99
|
+
startMonth = startDate.calendar.getFormattableMonth(startDate);
|
|
100
|
+
}
|
|
101
|
+
if (endDate.calendar.getFormattableMonth) {
|
|
102
|
+
endMonth = endDate.calendar.getFormattableMonth(endDate);
|
|
103
|
+
}
|
|
104
|
+
|
|
96
105
|
if (isSameDay(endDate, endOfMonth(startDate))) {
|
|
97
|
-
return monthFormatter.format(
|
|
106
|
+
return monthFormatter.format(startMonth.toDate(timeZone));
|
|
98
107
|
} else if (isSameDay(endDate, endOfMonth(endDate))) {
|
|
99
108
|
return isAria
|
|
100
|
-
? formatRange(monthFormatter, stringFormatter,
|
|
101
|
-
: monthFormatter.formatRange(
|
|
109
|
+
? formatRange(monthFormatter, stringFormatter, startMonth, endMonth, timeZone)
|
|
110
|
+
: monthFormatter.formatRange(startMonth.toDate(timeZone), endMonth.toDate(timeZone));
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
|