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AI,MAAM,yBAAyB;IACtE,IAAI,gBAAgB,aAAa;QAC/B,eAAe;QACf,MAAM,UAAU,CAAC;IACnB;IAEA,IAAI,CAAC,iBAAiB,mBAAmB,GAAG,CAAA,GAAA,eAAO,EAAE;IACrD,IAAI,mBAAmB,MAAM,UAAU,IAAI,MAAM,6BAA6B;IAC9E,IAAI,oBAAoB,iBAAiB;QACvC,mBAAmB;QACnB,MAAM,UAAU,CAAC;IACnB;IAEA,IAAI,aAAa,CAAA,GAAA,yCAAQ,EAAE;QACzB,IAAI,KAAK,CAAC,KAAK;QACf,cAAc;YAAC,KAAK,CAAC,aAAa;YAAE;SAAwB,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC;QAClF,mBAAmB,KAAK,CAAC,kBAAkB;IAC7C;IAEA,OAAO;QACL,eAAe,CAAA,GAAA,yCAAS,EAAE,UAAU,YAAY;YAC9C,MAAM;YACN,gBAAgB,KAAK,CAAC,eAAe,IAAI;YACzC,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;QACnD;QACA,iBAAiB;YACf,SAAS,IAAM,MAAM,aAAa;YAClC,cAAc,gBAAgB,MAAM,CAAC;YACrC,YAAY;YACZ,eAAe;QACjB;QACA,iBAAiB;YACf,SAAS,IAAM,MAAM,iBAAiB;YACtC,cAAc,gBAAgB,MAAM,CAAC;YACrC,YAAY;YACZ,eAAe;QACjB;QACA,mBAAmB;YACjB,IAAI;QACN;eACA;IACF;AACF","sources":["packages/react-aria/src/calendar/useCalendarBase.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 {announce} from '../live-announcer/LiveAnnouncer';\nimport {AriaButtonProps} from '../button/useButton';\nimport {AriaLabelingProps, DOMAttributes, DOMProps} from '@react-types/shared';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState\n} from 'react-stately/useCalendarState';\nimport {filterDOMProps} from '../utils/filterDOMProps';\nimport {hookData, useSelectedDateDescription, useVisibleRangeDescription} from './utils';\nimport intlMessages from '../../intl/calendar/*.json';\nimport {mergeProps} from '../utils/mergeProps';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {useSlotId} from '../utils/useId';\nimport {useState} from 'react';\nimport {useUpdateEffect} from '../utils/useUpdateEffect';\n\nexport interface CalendarAria {\n /** Props for the calendar grouping element. */\n calendarProps: DOMAttributes;\n /** Props for the next button. */\n nextButtonProps: AriaButtonProps;\n /** Props for the previous button. */\n prevButtonProps: AriaButtonProps;\n /** Props for the error message element, if any. */\n errorMessageProps: DOMAttributes;\n /** A description of the visible date range, for use in the calendar title. */\n title: string;\n}\n\nexport function useCalendarBase(\n props: CalendarPropsBase & DOMProps & AriaLabelingProps,\n state: CalendarState<CalendarSelectionMode> | RangeCalendarState\n): CalendarAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let domProps = filterDOMProps(props);\n\n let title = useVisibleRangeDescription(\n state.visibleRange.start,\n state.visibleRange.end,\n state.timeZone,\n false\n );\n let visibleRangeDescription = useVisibleRangeDescription(\n state.visibleRange.start,\n state.visibleRange.end,\n state.timeZone,\n true\n );\n\n // Announce when the visible date range changes\n useUpdateEffect(() => {\n // only when pressing the Previous or Next button\n if (!state.isFocused) {\n announce(visibleRangeDescription);\n }\n }, [visibleRangeDescription]);\n\n // Announce when the selected value changes\n let selectedDateDescription = useSelectedDateDescription(state);\n useUpdateEffect(() => {\n if (selectedDateDescription) {\n announce(selectedDateDescription, 'polite', 4000);\n }\n // handle an update to the caption that describes the currently selected range, to announce the new value\n }, [selectedDateDescription]);\n\n let errorMessageId = useSlotId([\n Boolean(props.errorMessage),\n props.isInvalid,\n props.validationState\n ]);\n\n // Pass the label to the child grid elements.\n hookData.set(state, {\n ariaLabel: props['aria-label'],\n ariaLabelledBy: props['aria-labelledby'],\n errorMessageId,\n selectedDateDescription\n });\n\n // If the next or previous buttons become disabled while they are focused, move focus to the calendar body.\n let [nextFocused, setNextFocused] = useState(false);\n let nextDisabled = props.isDisabled || state.isNextVisibleRangeInvalid();\n if (nextDisabled && nextFocused) {\n setNextFocused(false);\n state.setFocused(true);\n }\n\n let [previousFocused, setPreviousFocused] = useState(false);\n let previousDisabled = props.isDisabled || state.isPreviousVisibleRangeInvalid();\n if (previousDisabled && previousFocused) {\n setPreviousFocused(false);\n state.setFocused(true);\n }\n\n let labelProps = useLabels({\n id: props['id'],\n 'aria-label': [props['aria-label'], visibleRangeDescription].filter(Boolean).join(', '),\n 'aria-labelledby': props['aria-labelledby']\n });\n\n return {\n calendarProps: mergeProps(domProps, labelProps, {\n role: 'application',\n 'aria-details': props['aria-details'] || undefined,\n 'aria-describedby': props['aria-describedby'] || undefined\n }),\n nextButtonProps: {\n onPress: () => state.focusNextPage(),\n 'aria-label': stringFormatter.format('next'),\n isDisabled: nextDisabled,\n onFocusChange: setNextFocused\n },\n prevButtonProps: {\n onPress: () => state.focusPreviousPage(),\n 'aria-label': stringFormatter.format('previous'),\n isDisabled: previousDisabled,\n onFocusChange: setPreviousFocused\n },\n errorMessageProps: {\n id: errorMessageId\n },\n title\n };\n}\n"],"names":[],"version":3,"file":"useCalendarBase.mjs.map"}