@octanejs/aria 0.0.40 → 0.0.42
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/LICENSE-APACHE-2.0 +201 -0
- package/README.md +20 -7
- package/UPSTREAM.md +108 -0
- package/package.json +10 -6
- package/src/calendar/useCalendar.tsx +36 -0
- package/src/calendar/useCalendarBase.tsx +142 -0
- package/src/calendar/useCalendarCell.tsx +416 -0
- package/src/calendar/useCalendarGrid.tsx +202 -0
- package/src/calendar/useCalendarHeading.tsx +85 -0
- package/src/calendar/useCalendarMonthPicker.tsx +92 -0
- package/src/calendar/useCalendarYearPicker.tsx +127 -0
- package/src/calendar/useRangeCalendar.tsx +121 -0
- package/src/calendar/utils.tsx +183 -0
- package/src/color/useColorArea.tsx +599 -0
- package/src/color/useColorAreaGradient.tsx +157 -0
- package/src/color/useColorChannelField.tsx +53 -0
- package/src/color/useColorField.tsx +170 -0
- package/src/color/useColorSlider.tsx +177 -0
- package/src/color/useColorSwatch.tsx +83 -0
- package/src/color/useColorWheel.tsx +401 -0
- package/src/compat/react.ts +111 -0
- package/src/components/Calendar.tsx +842 -0
- package/src/components/ColorArea.tsx +120 -0
- package/src/components/ColorField.tsx +304 -0
- package/src/components/ColorPicker.tsx +86 -0
- package/src/components/ColorSlider.tsx +144 -0
- package/src/components/ColorSwatch.tsx +72 -0
- package/src/components/ColorSwatchPicker.tsx +176 -0
- package/src/components/ColorThumb.tsx +140 -0
- package/src/components/ColorWheel.tsx +163 -0
- package/src/components/DateField.tsx +580 -0
- package/src/components/DatePicker.tsx +386 -0
- package/src/components/DropZone.tsx +181 -0
- package/src/components/FileTrigger.tsx +96 -0
- package/src/components/GridLayout.tsx +33 -0
- package/src/components/HiddenDateInput.tsx +169 -0
- package/src/components/TableLayout.tsx +39 -0
- package/src/components/Toast.tsx +336 -0
- package/src/components/Virtualizer.tsx +219 -0
- package/src/components/index.ts +257 -7
- package/src/components/useDragAndDrop.tsx +221 -0
- package/src/components/utils.ts +12 -89
- package/src/datepicker/useDateField.tsx +272 -0
- package/src/datepicker/useDatePicker.tsx +229 -0
- package/src/datepicker/useDatePickerGroup.tsx +147 -0
- package/src/datepicker/useDateRangePicker.tsx +288 -0
- package/src/datepicker/useDateSegment.tsx +439 -0
- package/src/datepicker/useDisplayNames.tsx +53 -0
- package/src/dnd/DragManager.tsx +718 -0
- package/src/dnd/DragPreview.tsx +100 -0
- package/src/dnd/DropTargetKeyboardNavigation.tsx +317 -0
- package/src/dnd/ListDropTargetDelegate.tsx +215 -0
- package/src/dnd/constants.tsx +93 -0
- package/src/dnd/useAutoScroll.tsx +116 -0
- package/src/dnd/useClipboard.tsx +160 -0
- package/src/dnd/useDrag.tsx +437 -0
- package/src/dnd/useDraggableCollection.tsx +35 -0
- package/src/dnd/useDraggableItem.tsx +168 -0
- package/src/dnd/useDrop.tsx +518 -0
- package/src/dnd/useDropIndicator.tsx +129 -0
- package/src/dnd/useDroppableCollection.tsx +808 -0
- package/src/dnd/useDroppableItem.tsx +99 -0
- package/src/dnd/useVirtualDrop.tsx +52 -0
- package/src/dnd/utils.tsx +430 -0
- package/src/intl/calendar/ar-AE.json +14 -0
- package/src/intl/calendar/bg-BG.json +14 -0
- package/src/intl/calendar/cs-CZ.json +14 -0
- package/src/intl/calendar/da-DK.json +14 -0
- package/src/intl/calendar/de-DE.json +14 -0
- package/src/intl/calendar/el-GR.json +14 -0
- package/src/intl/calendar/en-US.json +14 -0
- package/src/intl/calendar/es-ES.json +14 -0
- package/src/intl/calendar/et-EE.json +14 -0
- package/src/intl/calendar/fi-FI.json +14 -0
- package/src/intl/calendar/fr-FR.json +14 -0
- package/src/intl/calendar/he-IL.json +14 -0
- package/src/intl/calendar/hr-HR.json +14 -0
- package/src/intl/calendar/hu-HU.json +14 -0
- package/src/intl/calendar/index.ts +73 -0
- package/src/intl/calendar/it-IT.json +14 -0
- package/src/intl/calendar/ja-JP.json +14 -0
- package/src/intl/calendar/ko-KR.json +14 -0
- package/src/intl/calendar/lt-LT.json +14 -0
- package/src/intl/calendar/lv-LV.json +14 -0
- package/src/intl/calendar/nb-NO.json +14 -0
- package/src/intl/calendar/nl-NL.json +14 -0
- package/src/intl/calendar/pl-PL.json +14 -0
- package/src/intl/calendar/pt-BR.json +14 -0
- package/src/intl/calendar/pt-PT.json +14 -0
- package/src/intl/calendar/ro-RO.json +14 -0
- package/src/intl/calendar/ru-RU.json +14 -0
- package/src/intl/calendar/sk-SK.json +14 -0
- package/src/intl/calendar/sl-SI.json +14 -0
- package/src/intl/calendar/sr-SP.json +14 -0
- package/src/intl/calendar/sv-SE.json +14 -0
- package/src/intl/calendar/tr-TR.json +14 -0
- package/src/intl/calendar/uk-UA.json +14 -0
- package/src/intl/calendar/zh-CN.json +14 -0
- package/src/intl/calendar/zh-TW.json +14 -0
- package/src/intl/color/ar-AE.json +8 -0
- package/src/intl/color/bg-BG.json +8 -0
- package/src/intl/color/cs-CZ.json +8 -0
- package/src/intl/color/da-DK.json +8 -0
- package/src/intl/color/de-DE.json +8 -0
- package/src/intl/color/el-GR.json +8 -0
- package/src/intl/color/en-US.json +8 -0
- package/src/intl/color/es-ES.json +8 -0
- package/src/intl/color/et-EE.json +8 -0
- package/src/intl/color/fi-FI.json +8 -0
- package/src/intl/color/fr-FR.json +8 -0
- package/src/intl/color/he-IL.json +8 -0
- package/src/intl/color/hr-HR.json +8 -0
- package/src/intl/color/hu-HU.json +8 -0
- package/src/intl/color/index.ts +73 -0
- package/src/intl/color/it-IT.json +8 -0
- package/src/intl/color/ja-JP.json +8 -0
- package/src/intl/color/ko-KR.json +8 -0
- package/src/intl/color/lt-LT.json +8 -0
- package/src/intl/color/lv-LV.json +8 -0
- package/src/intl/color/nb-NO.json +8 -0
- package/src/intl/color/nl-NL.json +8 -0
- package/src/intl/color/pl-PL.json +8 -0
- package/src/intl/color/pt-BR.json +8 -0
- package/src/intl/color/pt-PT.json +8 -0
- package/src/intl/color/ro-RO.json +8 -0
- package/src/intl/color/ru-RU.json +8 -0
- package/src/intl/color/sk-SK.json +8 -0
- package/src/intl/color/sl-SI.json +8 -0
- package/src/intl/color/sr-SP.json +8 -0
- package/src/intl/color/sv-SE.json +8 -0
- package/src/intl/color/tr-TR.json +8 -0
- package/src/intl/color/uk-UA.json +8 -0
- package/src/intl/color/zh-CN.json +8 -0
- package/src/intl/color/zh-TW.json +8 -0
- package/src/intl/datepicker/ar-AE.json +18 -0
- package/src/intl/datepicker/bg-BG.json +18 -0
- package/src/intl/datepicker/cs-CZ.json +18 -0
- package/src/intl/datepicker/da-DK.json +18 -0
- package/src/intl/datepicker/de-DE.json +18 -0
- package/src/intl/datepicker/el-GR.json +18 -0
- package/src/intl/datepicker/en-US.json +18 -0
- package/src/intl/datepicker/es-ES.json +18 -0
- package/src/intl/datepicker/et-EE.json +18 -0
- package/src/intl/datepicker/fi-FI.json +18 -0
- package/src/intl/datepicker/fr-FR.json +18 -0
- package/src/intl/datepicker/he-IL.json +18 -0
- package/src/intl/datepicker/hr-HR.json +18 -0
- package/src/intl/datepicker/hu-HU.json +18 -0
- package/src/intl/datepicker/index.ts +73 -0
- package/src/intl/datepicker/it-IT.json +18 -0
- package/src/intl/datepicker/ja-JP.json +18 -0
- package/src/intl/datepicker/ko-KR.json +18 -0
- package/src/intl/datepicker/lt-LT.json +18 -0
- package/src/intl/datepicker/lv-LV.json +18 -0
- package/src/intl/datepicker/nb-NO.json +18 -0
- package/src/intl/datepicker/nl-NL.json +18 -0
- package/src/intl/datepicker/pl-PL.json +18 -0
- package/src/intl/datepicker/pt-BR.json +18 -0
- package/src/intl/datepicker/pt-PT.json +18 -0
- package/src/intl/datepicker/ro-RO.json +18 -0
- package/src/intl/datepicker/ru-RU.json +18 -0
- package/src/intl/datepicker/sk-SK.json +18 -0
- package/src/intl/datepicker/sl-SI.json +18 -0
- package/src/intl/datepicker/sr-SP.json +18 -0
- package/src/intl/datepicker/sv-SE.json +18 -0
- package/src/intl/datepicker/tr-TR.json +18 -0
- package/src/intl/datepicker/uk-UA.json +18 -0
- package/src/intl/datepicker/zh-CN.json +18 -0
- package/src/intl/datepicker/zh-TW.json +18 -0
- package/src/intl/dnd/ar-AE.json +29 -0
- package/src/intl/dnd/bg-BG.json +29 -0
- package/src/intl/dnd/cs-CZ.json +29 -0
- package/src/intl/dnd/da-DK.json +29 -0
- package/src/intl/dnd/de-DE.json +29 -0
- package/src/intl/dnd/el-GR.json +29 -0
- package/src/intl/dnd/en-US.json +29 -0
- package/src/intl/dnd/es-ES.json +29 -0
- package/src/intl/dnd/et-EE.json +29 -0
- package/src/intl/dnd/fi-FI.json +29 -0
- package/src/intl/dnd/fr-FR.json +29 -0
- package/src/intl/dnd/he-IL.json +29 -0
- package/src/intl/dnd/hr-HR.json +29 -0
- package/src/intl/dnd/hu-HU.json +29 -0
- package/src/intl/dnd/index.ts +73 -0
- package/src/intl/dnd/it-IT.json +29 -0
- package/src/intl/dnd/ja-JP.json +29 -0
- package/src/intl/dnd/ko-KR.json +29 -0
- package/src/intl/dnd/lt-LT.json +29 -0
- package/src/intl/dnd/lv-LV.json +29 -0
- package/src/intl/dnd/nb-NO.json +29 -0
- package/src/intl/dnd/nl-NL.json +29 -0
- package/src/intl/dnd/pl-PL.json +29 -0
- package/src/intl/dnd/pt-BR.json +29 -0
- package/src/intl/dnd/pt-PT.json +29 -0
- package/src/intl/dnd/ro-RO.json +29 -0
- package/src/intl/dnd/ru-RU.json +29 -0
- package/src/intl/dnd/sk-SK.json +29 -0
- package/src/intl/dnd/sl-SI.json +29 -0
- package/src/intl/dnd/sr-SP.json +29 -0
- package/src/intl/dnd/sv-SE.json +29 -0
- package/src/intl/dnd/tr-TR.json +29 -0
- package/src/intl/dnd/uk-UA.json +29 -0
- package/src/intl/dnd/zh-CN.json +29 -0
- package/src/intl/dnd/zh-TW.json +29 -0
- package/src/intl/react-aria-components/ar-AE.json +6 -0
- package/src/intl/react-aria-components/bg-BG.json +6 -0
- package/src/intl/react-aria-components/cs-CZ.json +6 -0
- package/src/intl/react-aria-components/da-DK.json +6 -0
- package/src/intl/react-aria-components/de-DE.json +6 -0
- package/src/intl/react-aria-components/el-GR.json +6 -0
- package/src/intl/react-aria-components/en-US.json +6 -0
- package/src/intl/react-aria-components/es-ES.json +6 -0
- package/src/intl/react-aria-components/et-EE.json +6 -0
- package/src/intl/react-aria-components/fi-FI.json +6 -0
- package/src/intl/react-aria-components/fr-FR.json +6 -0
- package/src/intl/react-aria-components/he-IL.json +6 -0
- package/src/intl/react-aria-components/hr-HR.json +6 -0
- package/src/intl/react-aria-components/hu-HU.json +6 -0
- package/src/intl/react-aria-components/index.ts +73 -0
- package/src/intl/react-aria-components/it-IT.json +6 -0
- package/src/intl/react-aria-components/ja-JP.json +6 -0
- package/src/intl/react-aria-components/ko-KR.json +6 -0
- package/src/intl/react-aria-components/lt-LT.json +6 -0
- package/src/intl/react-aria-components/lv-LV.json +6 -0
- package/src/intl/react-aria-components/nb-NO.json +6 -0
- package/src/intl/react-aria-components/nl-NL.json +6 -0
- package/src/intl/react-aria-components/pl-PL.json +6 -0
- package/src/intl/react-aria-components/pt-BR.json +6 -0
- package/src/intl/react-aria-components/pt-PT.json +6 -0
- package/src/intl/react-aria-components/ro-RO.json +6 -0
- package/src/intl/react-aria-components/ru-RU.json +6 -0
- package/src/intl/react-aria-components/sk-SK.json +6 -0
- package/src/intl/react-aria-components/sl-SI.json +6 -0
- package/src/intl/react-aria-components/sr-SP.json +6 -0
- package/src/intl/react-aria-components/sv-SE.json +6 -0
- package/src/intl/react-aria-components/tr-TR.json +6 -0
- package/src/intl/react-aria-components/uk-UA.json +6 -0
- package/src/intl/react-aria-components/zh-CN.json +6 -0
- package/src/intl/react-aria-components/zh-TW.json +6 -0
- package/src/intl/stately-color/ar-AE.json +39 -0
- package/src/intl/stately-color/bg-BG.json +39 -0
- package/src/intl/stately-color/cs-CZ.json +39 -0
- package/src/intl/stately-color/da-DK.json +39 -0
- package/src/intl/stately-color/de-DE.json +39 -0
- package/src/intl/stately-color/el-GR.json +39 -0
- package/src/intl/stately-color/en-US.json +39 -0
- package/src/intl/stately-color/es-ES.json +39 -0
- package/src/intl/stately-color/et-EE.json +39 -0
- package/src/intl/stately-color/fi-FI.json +39 -0
- package/src/intl/stately-color/fr-FR.json +39 -0
- package/src/intl/stately-color/he-IL.json +39 -0
- package/src/intl/stately-color/hr-HR.json +39 -0
- package/src/intl/stately-color/hu-HU.json +39 -0
- package/src/intl/stately-color/index.ts +73 -0
- package/src/intl/stately-color/it-IT.json +39 -0
- package/src/intl/stately-color/ja-JP.json +39 -0
- package/src/intl/stately-color/ko-KR.json +39 -0
- package/src/intl/stately-color/lt-LT.json +39 -0
- package/src/intl/stately-color/lv-LV.json +39 -0
- package/src/intl/stately-color/nb-NO.json +39 -0
- package/src/intl/stately-color/nl-NL.json +39 -0
- package/src/intl/stately-color/pl-PL.json +39 -0
- package/src/intl/stately-color/pt-BR.json +39 -0
- package/src/intl/stately-color/pt-PT.json +39 -0
- package/src/intl/stately-color/ro-RO.json +39 -0
- package/src/intl/stately-color/ru-RU.json +39 -0
- package/src/intl/stately-color/sk-SK.json +39 -0
- package/src/intl/stately-color/sl-SI.json +39 -0
- package/src/intl/stately-color/sr-SP.json +39 -0
- package/src/intl/stately-color/sv-SE.json +39 -0
- package/src/intl/stately-color/tr-TR.json +39 -0
- package/src/intl/stately-color/uk-UA.json +39 -0
- package/src/intl/stately-color/zh-CN.json +39 -0
- package/src/intl/stately-color/zh-TW.json +39 -0
- package/src/intl/toast/ar-AE.json +4 -0
- package/src/intl/toast/bg-BG.json +4 -0
- package/src/intl/toast/cs-CZ.json +4 -0
- package/src/intl/toast/da-DK.json +4 -0
- package/src/intl/toast/de-DE.json +4 -0
- package/src/intl/toast/el-GR.json +4 -0
- package/src/intl/toast/en-US.json +4 -0
- package/src/intl/toast/es-ES.json +4 -0
- package/src/intl/toast/et-EE.json +4 -0
- package/src/intl/toast/fi-FI.json +4 -0
- package/src/intl/toast/fr-FR.json +4 -0
- package/src/intl/toast/he-IL.json +4 -0
- package/src/intl/toast/hr-HR.json +4 -0
- package/src/intl/toast/hu-HU.json +4 -0
- package/src/intl/toast/index.ts +73 -0
- package/src/intl/toast/it-IT.json +4 -0
- package/src/intl/toast/ja-JP.json +4 -0
- package/src/intl/toast/ko-KR.json +4 -0
- package/src/intl/toast/lt-LT.json +4 -0
- package/src/intl/toast/lv-LV.json +4 -0
- package/src/intl/toast/nb-NO.json +4 -0
- package/src/intl/toast/nl-NL.json +4 -0
- package/src/intl/toast/pl-PL.json +4 -0
- package/src/intl/toast/pt-BR.json +4 -0
- package/src/intl/toast/pt-PT.json +4 -0
- package/src/intl/toast/ro-RO.json +4 -0
- package/src/intl/toast/ru-RU.json +4 -0
- package/src/intl/toast/sk-SK.json +4 -0
- package/src/intl/toast/sl-SI.json +4 -0
- package/src/intl/toast/sr-SP.json +4 -0
- package/src/intl/toast/sv-SE.json +4 -0
- package/src/intl/toast/tr-TR.json +4 -0
- package/src/intl/toast/uk-UA.json +4 -0
- package/src/intl/toast/zh-CN.json +4 -0
- package/src/intl/toast/zh-TW.json +4 -0
- package/src/landmark/useLandmark.tsx +569 -0
- package/src/stately/calendar/types.tsx +239 -0
- package/src/stately/calendar/useCalendarState.tsx +527 -0
- package/src/stately/calendar/useRangeCalendarState.tsx +323 -0
- package/src/stately/calendar/utils.tsx +175 -0
- package/src/stately/color/Color.tsx +889 -0
- package/src/stately/color/types.tsx +82 -0
- package/src/stately/color/useColor.tsx +30 -0
- package/src/stately/color/useColorAreaState.tsx +255 -0
- package/src/stately/color/useColorChannelFieldState.tsx +86 -0
- package/src/stately/color/useColorFieldState.tsx +220 -0
- package/src/stately/color/useColorPickerState.tsx +31 -0
- package/src/stately/color/useColorSliderState.tsx +143 -0
- package/src/stately/color/useColorWheelState.tsx +225 -0
- package/src/stately/data/useAsyncList.tsx +382 -0
- package/src/stately/data/useListData.tsx +447 -0
- package/src/stately/data/useTreeData.tsx +603 -0
- package/src/stately/datepicker/IncompleteDate.tsx +427 -0
- package/src/stately/datepicker/placeholders.tsx +116 -0
- package/src/stately/datepicker/types.tsx +169 -0
- package/src/stately/datepicker/useDateFieldState.tsx +564 -0
- package/src/stately/datepicker/useDatePickerState.tsx +244 -0
- package/src/stately/datepicker/useDateRangePickerState.tsx +397 -0
- package/src/stately/datepicker/useTimeFieldState.tsx +123 -0
- package/src/stately/datepicker/utils.tsx +316 -0
- package/src/stately/dnd/useDraggableCollectionState.tsx +191 -0
- package/src/stately/dnd/useDroppableCollectionState.tsx +288 -0
- package/src/stately/layout/GridLayout.tsx +449 -0
- package/src/stately/layout/ListLayout.tsx +872 -0
- package/src/stately/layout/TableLayout.tsx +793 -0
- package/src/stately/layout/WaterfallLayout.tsx +399 -0
- package/src/stately/toast/useToastState.tsx +219 -0
- package/src/stately/virtualizer/Layout.tsx +105 -0
- package/src/stately/virtualizer/LayoutInfo.tsx +127 -0
- package/src/stately/virtualizer/OverscanManager.tsx +56 -0
- package/src/stately/virtualizer/Point.tsx +47 -0
- package/src/stately/virtualizer/Rect.tsx +194 -0
- package/src/stately/virtualizer/ReusableView.tsx +101 -0
- package/src/stately/virtualizer/Size.tsx +48 -0
- package/src/stately/virtualizer/Virtualizer.tsx +408 -0
- package/src/stately/virtualizer/types.tsx +48 -0
- package/src/stately/virtualizer/useVirtualizerState.tsx +138 -0
- package/src/stately/virtualizer/utils.tsx +32 -0
- package/src/textfield/useTextField.ts +3 -0
- package/src/toast/useToast.tsx +105 -0
- package/src/toast/useToastRegion.tsx +223 -0
- package/src/upstream-exports/react-aria/I18nProvider.tsx +17 -0
- package/src/upstream-exports/react-aria/ListDropTargetDelegate.tsx +15 -0
- package/src/upstream-exports/react-aria/PortalProvider.tsx +19 -0
- package/src/upstream-exports/react-aria/SSRProvider.tsx +15 -0
- package/src/upstream-exports/react-aria/VisuallyHidden.tsx +15 -0
- package/src/upstream-exports/react-aria/filterDOMProps.tsx +3 -0
- package/src/upstream-exports/react-aria/mergeProps.tsx +14 -0
- package/src/upstream-exports/react-aria/private/dnd/DragManager.tsx +3 -0
- package/src/upstream-exports/react-aria/private/interactions/PressResponder.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/isFocusable.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/shadowdom/DOMFunctions.tsx +8 -0
- package/src/upstream-exports/react-aria/private/utils/useId.tsx +3 -0
- package/src/upstream-exports/react-aria/private/utils/useLabels.tsx +3 -0
- package/src/upstream-exports/react-aria/private/virtualizer/ScrollView.tsx +3 -0
- package/src/upstream-exports/react-aria/private/virtualizer/VirtualizerItem.tsx +3 -0
- package/src/upstream-exports/react-aria/useButton.tsx +22 -0
- package/src/upstream-exports/react-aria/useCalendar.tsx +37 -0
- package/src/upstream-exports/react-aria/useClipboard.tsx +23 -0
- package/src/upstream-exports/react-aria/useColorArea.tsx +19 -0
- package/src/upstream-exports/react-aria/useColorField.tsx +20 -0
- package/src/upstream-exports/react-aria/useColorSlider.tsx +19 -0
- package/src/upstream-exports/react-aria/useColorSwatch.tsx +15 -0
- package/src/upstream-exports/react-aria/useColorWheel.tsx +19 -0
- package/src/upstream-exports/react-aria/useDateField.tsx +23 -0
- package/src/upstream-exports/react-aria/useDatePicker.tsx +17 -0
- package/src/upstream-exports/react-aria/useDateRangePicker.tsx +24 -0
- package/src/upstream-exports/react-aria/useDraggableCollection.tsx +31 -0
- package/src/upstream-exports/react-aria/useDrop.tsx +33 -0
- package/src/upstream-exports/react-aria/useDroppableCollection.tsx +47 -0
- package/src/upstream-exports/react-aria/useFocusRing.tsx +16 -0
- package/src/upstream-exports/react-aria/useHover.tsx +17 -0
- package/src/upstream-exports/react-aria/useLocalizedStringFormatter.tsx +19 -0
- package/src/upstream-exports/react-aria/useObjectRef.tsx +14 -0
- package/src/upstream-exports/react-aria/useRangeCalendar.tsx +38 -0
- package/src/upstream-exports/react-aria/useTimeField.tsx +23 -0
- package/src/upstream-exports/react-aria/useToast.tsx +18 -0
- package/src/upstream-exports/react-stately/Color.tsx +23 -0
- package/src/upstream-exports/react-stately/private/form/useFormValidationState.tsx +11 -0
- package/src/upstream-exports/react-stately/useCalendarState.tsx +24 -0
- package/src/upstream-exports/react-stately/useColorAreaState.tsx +24 -0
- package/src/upstream-exports/react-stately/useColorFieldState.tsx +22 -0
- package/src/upstream-exports/react-stately/useColorPickerState.tsx +25 -0
- package/src/upstream-exports/react-stately/useColorSliderState.tsx +25 -0
- package/src/upstream-exports/react-stately/useColorWheelState.tsx +24 -0
- package/src/upstream-exports/react-stately/useDateFieldState.tsx +29 -0
- package/src/upstream-exports/react-stately/useDatePickerState.tsx +25 -0
- package/src/upstream-exports/react-stately/useDateRangePickerState.tsx +26 -0
- package/src/upstream-exports/react-stately/useDraggableCollectionState.tsx +19 -0
- package/src/upstream-exports/react-stately/useDroppableCollectionState.tsx +19 -0
- package/src/upstream-exports/react-stately/useRangeCalendarState.tsx +27 -0
- package/src/upstream-exports/react-stately/useTimeFieldState.tsx +26 -0
- package/src/upstream-exports/react-stately/useToastState.tsx +21 -0
- package/src/upstream-exports/react-stately/useVirtualizerState.tsx +22 -0
- package/src/utils/useLoadMore.tsx +89 -0
- package/src/virtualizer/ScrollView.tsx +401 -0
- package/src/virtualizer/Virtualizer.tsx +147 -0
- package/src/virtualizer/VirtualizerItem.tsx +108 -0
- package/src/virtualizer/useVirtualizerItem.tsx +57 -0
- package/src/virtualizer/utils.tsx +105 -0
- package/LICENSE +0 -21
- package/src/components/useDragAndDrop.ts +0 -164
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/** @jsxImportSource octane */
|
|
2
|
+
// Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/datepicker/useDatePicker.ts).
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { AriaButtonProps } from '../button/useButton';
|
|
16
|
+
import { AriaDialogProps } from '../dialog/useDialog';
|
|
17
|
+
import {
|
|
18
|
+
AriaLabelingProps,
|
|
19
|
+
DOMAttributes,
|
|
20
|
+
DOMProps,
|
|
21
|
+
GroupDOMAttributes,
|
|
22
|
+
InputDOMProps,
|
|
23
|
+
KeyboardEvent,
|
|
24
|
+
RefObject,
|
|
25
|
+
ValidationResult,
|
|
26
|
+
} from '@react-types/shared';
|
|
27
|
+
import { CalendarProps } from '../upstream-exports/react-stately/useCalendarState';
|
|
28
|
+
import { createFocusManager } from '../focus/FocusScope';
|
|
29
|
+
import {
|
|
30
|
+
DatePickerProps,
|
|
31
|
+
DatePickerState,
|
|
32
|
+
DateValue,
|
|
33
|
+
} from '../upstream-exports/react-stately/useDatePickerState';
|
|
34
|
+
import { filterDOMProps } from '../utils/filterDOMProps';
|
|
35
|
+
import intlMessages from '../intl/datepicker/index';
|
|
36
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
37
|
+
import { nodeContains } from '../utils/shadowdom/DOMFunctions';
|
|
38
|
+
import { privateValidationStateProp } from '../upstream-exports/react-stately/private/form/useFormValidationState';
|
|
39
|
+
import { roleSymbol } from './useDateField';
|
|
40
|
+
import { useDatePickerGroup } from './useDatePickerGroup';
|
|
41
|
+
import { useDescription } from '../utils/useDescription';
|
|
42
|
+
import { useField } from '../label/useField';
|
|
43
|
+
import { useFocusWithin } from '../interactions/useFocusWithin';
|
|
44
|
+
import { useId } from '../utils/useId';
|
|
45
|
+
import { useLocale } from '../i18n/I18nProvider';
|
|
46
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
47
|
+
import { useMemo, useRef } from '../compat/react';
|
|
48
|
+
|
|
49
|
+
export interface AriaDatePickerProps<T extends DateValue>
|
|
50
|
+
extends DatePickerProps<T>, AriaLabelingProps, InputDOMProps, DOMProps, InputDOMProps {
|
|
51
|
+
/**
|
|
52
|
+
* Describes the type of autocomplete functionality the input should provide if any. See
|
|
53
|
+
* [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefautocomplete).
|
|
54
|
+
*/
|
|
55
|
+
autoComplete?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface DatePickerAria extends ValidationResult {
|
|
59
|
+
/** Props for the date picker's visible label element, if any. */
|
|
60
|
+
labelProps: DOMAttributes;
|
|
61
|
+
/** Props for the grouping element containing the date field and button. */
|
|
62
|
+
groupProps: GroupDOMAttributes;
|
|
63
|
+
/** Props for the date field. */
|
|
64
|
+
fieldProps: AriaDatePickerProps<DateValue>;
|
|
65
|
+
/** Props for the popover trigger button. */
|
|
66
|
+
buttonProps: AriaButtonProps;
|
|
67
|
+
/** Props for the description element, if any. */
|
|
68
|
+
descriptionProps: DOMAttributes;
|
|
69
|
+
/** Props for the error message element, if any. */
|
|
70
|
+
errorMessageProps: DOMAttributes;
|
|
71
|
+
/** Props for the popover dialog. */
|
|
72
|
+
dialogProps: AriaDialogProps;
|
|
73
|
+
/** Props for the calendar within the popover dialog. */
|
|
74
|
+
calendarProps: CalendarProps<DateValue>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Provides the behavior and accessibility implementation for a date picker component. A date picker
|
|
79
|
+
* combines a DateField and a Calendar popover to allow users to enter or select a date and time
|
|
80
|
+
* value.
|
|
81
|
+
*/
|
|
82
|
+
export function useDatePicker<T extends DateValue>(
|
|
83
|
+
props: AriaDatePickerProps<T>,
|
|
84
|
+
state: DatePickerState,
|
|
85
|
+
ref: RefObject<Element | null>,
|
|
86
|
+
): DatePickerAria {
|
|
87
|
+
let buttonId = useId();
|
|
88
|
+
let dialogId = useId();
|
|
89
|
+
let fieldId = useId();
|
|
90
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/datepicker');
|
|
91
|
+
|
|
92
|
+
let { isInvalid, validationErrors, validationDetails } = state.displayValidation;
|
|
93
|
+
let { labelProps, fieldProps, descriptionProps, errorMessageProps } = useField({
|
|
94
|
+
...props,
|
|
95
|
+
labelElementType: 'span',
|
|
96
|
+
isInvalid,
|
|
97
|
+
errorMessage: props.errorMessage || validationErrors,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
let groupProps = useDatePickerGroup(state, ref);
|
|
101
|
+
|
|
102
|
+
let labelledBy = fieldProps['aria-labelledby'] || fieldProps.id;
|
|
103
|
+
|
|
104
|
+
let { locale } = useLocale();
|
|
105
|
+
let date = state.formatValue(locale, { month: 'long' });
|
|
106
|
+
let description = date ? stringFormatter.format('selectedDateDescription', { date }) : '';
|
|
107
|
+
let descProps = useDescription(description);
|
|
108
|
+
let ariaDescribedBy =
|
|
109
|
+
[descProps['aria-describedby'], fieldProps['aria-describedby']].filter(Boolean).join(' ') ||
|
|
110
|
+
undefined;
|
|
111
|
+
let domProps = filterDOMProps(props);
|
|
112
|
+
let focusManager = useMemo(() => createFocusManager(ref), [ref]);
|
|
113
|
+
|
|
114
|
+
let isFocused = useRef(false);
|
|
115
|
+
let { focusWithinProps } = useFocusWithin({
|
|
116
|
+
...props,
|
|
117
|
+
isDisabled: state.isOpen,
|
|
118
|
+
onBlurWithin: (e) => {
|
|
119
|
+
// Ignore when focus moves into the popover.
|
|
120
|
+
let dialog = document.getElementById(dialogId);
|
|
121
|
+
if (!nodeContains(dialog, e.relatedTarget as Node | null)) {
|
|
122
|
+
isFocused.current = false;
|
|
123
|
+
props.onBlur?.(e as any);
|
|
124
|
+
props.onFocusChange?.(false);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
onFocusWithin: (e) => {
|
|
128
|
+
if (!isFocused.current) {
|
|
129
|
+
isFocused.current = true;
|
|
130
|
+
props.onFocus?.(e as any);
|
|
131
|
+
props.onFocusChange?.(true);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
groupProps: mergeProps(domProps, groupProps, fieldProps, descProps, focusWithinProps, {
|
|
138
|
+
role: 'group' as const,
|
|
139
|
+
'aria-disabled': props.isDisabled || null,
|
|
140
|
+
'aria-labelledby': labelledBy,
|
|
141
|
+
'aria-describedby': ariaDescribedBy,
|
|
142
|
+
onKeyDown(e: KeyboardEvent) {
|
|
143
|
+
if (state.isOpen) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (props.onKeyDown) {
|
|
148
|
+
props.onKeyDown(e);
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
onKeyUp(e: KeyboardEvent) {
|
|
152
|
+
if (state.isOpen) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (props.onKeyUp) {
|
|
157
|
+
props.onKeyUp(e);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
labelProps: {
|
|
162
|
+
...labelProps,
|
|
163
|
+
onClick: () => {
|
|
164
|
+
focusManager.focusFirst();
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
fieldProps: {
|
|
168
|
+
...fieldProps,
|
|
169
|
+
id: fieldId,
|
|
170
|
+
[roleSymbol]: 'presentation',
|
|
171
|
+
'aria-describedby': ariaDescribedBy,
|
|
172
|
+
value: state.value,
|
|
173
|
+
defaultValue: state.defaultValue,
|
|
174
|
+
onChange: state.setValue,
|
|
175
|
+
placeholderValue: props.placeholderValue,
|
|
176
|
+
hideTimeZone: props.hideTimeZone,
|
|
177
|
+
hourCycle: props.hourCycle,
|
|
178
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
179
|
+
granularity: props.granularity,
|
|
180
|
+
isDisabled: props.isDisabled,
|
|
181
|
+
isReadOnly: props.isReadOnly,
|
|
182
|
+
isRequired: props.isRequired,
|
|
183
|
+
validationBehavior: props.validationBehavior,
|
|
184
|
+
// DatePicker owns the validation state for the date field.
|
|
185
|
+
[privateValidationStateProp]: state,
|
|
186
|
+
autoFocus: props.autoFocus,
|
|
187
|
+
name: props.name,
|
|
188
|
+
form: props.form,
|
|
189
|
+
},
|
|
190
|
+
descriptionProps,
|
|
191
|
+
errorMessageProps,
|
|
192
|
+
buttonProps: {
|
|
193
|
+
...descProps,
|
|
194
|
+
id: buttonId,
|
|
195
|
+
'aria-haspopup': 'dialog',
|
|
196
|
+
'aria-label': stringFormatter.format('calendar'),
|
|
197
|
+
'aria-labelledby': `${buttonId} ${labelledBy}`,
|
|
198
|
+
'aria-describedby': ariaDescribedBy,
|
|
199
|
+
'aria-expanded': state.isOpen,
|
|
200
|
+
isDisabled: props.isDisabled || props.isReadOnly,
|
|
201
|
+
onPress: () => state.setOpen(true),
|
|
202
|
+
},
|
|
203
|
+
dialogProps: {
|
|
204
|
+
id: dialogId,
|
|
205
|
+
'aria-labelledby': `${buttonId} ${labelledBy}`,
|
|
206
|
+
},
|
|
207
|
+
calendarProps: {
|
|
208
|
+
autoFocus: true,
|
|
209
|
+
value: state.dateValue,
|
|
210
|
+
onChange: state.setDateValue,
|
|
211
|
+
minValue: props.minValue,
|
|
212
|
+
maxValue: props.maxValue,
|
|
213
|
+
isDisabled: props.isDisabled,
|
|
214
|
+
isReadOnly: props.isReadOnly,
|
|
215
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
216
|
+
defaultFocusedValue: state.dateValue ? undefined : props.placeholderValue,
|
|
217
|
+
isInvalid: state.isInvalid,
|
|
218
|
+
errorMessage:
|
|
219
|
+
typeof props.errorMessage === 'function'
|
|
220
|
+
? props.errorMessage(state.displayValidation)
|
|
221
|
+
: props.errorMessage || state.displayValidation.validationErrors.join(' '),
|
|
222
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
223
|
+
pageBehavior: props.pageBehavior,
|
|
224
|
+
},
|
|
225
|
+
isInvalid,
|
|
226
|
+
validationErrors,
|
|
227
|
+
validationDetails,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** @jsxImportSource octane */
|
|
2
|
+
// Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/datepicker/useDatePickerGroup.ts).
|
|
3
|
+
import { createFocusManager, getFocusableTreeWalker } from '../focus/FocusScope';
|
|
4
|
+
import { DateFieldState } from '../upstream-exports/react-stately/useDateFieldState';
|
|
5
|
+
import { DatePickerState } from '../upstream-exports/react-stately/useDatePickerState';
|
|
6
|
+
import { DateRangePickerState } from '../upstream-exports/react-stately/useDateRangePickerState';
|
|
7
|
+
import { DOMAttributes, FocusableElement, KeyboardEvent, RefObject } from '@react-types/shared';
|
|
8
|
+
import { getEventTarget, nodeContains } from '../utils/shadowdom/DOMFunctions';
|
|
9
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
10
|
+
import { useLocale } from '../i18n/I18nProvider';
|
|
11
|
+
import { useMemo } from '../compat/react';
|
|
12
|
+
import { usePress } from '../interactions/usePress';
|
|
13
|
+
|
|
14
|
+
export function useDatePickerGroup(
|
|
15
|
+
state: DatePickerState | DateRangePickerState | DateFieldState,
|
|
16
|
+
ref: RefObject<Element | null>,
|
|
17
|
+
disableArrowNavigation?: boolean,
|
|
18
|
+
): DOMAttributes<FocusableElement> {
|
|
19
|
+
let { direction } = useLocale();
|
|
20
|
+
let focusManager = useMemo(() => createFocusManager(ref), [ref]);
|
|
21
|
+
|
|
22
|
+
// Open the popover on alt + arrow down
|
|
23
|
+
let onKeyDown = (e: KeyboardEvent) => {
|
|
24
|
+
if (!nodeContains(e.currentTarget, getEventTarget(e as unknown as Event) as Element)) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (e.altKey && (e.key === 'ArrowDown' || e.key === 'ArrowUp') && 'setOpen' in state) {
|
|
29
|
+
e.preventDefault();
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
state.setOpen(true);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (disableArrowNavigation) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch (e.key) {
|
|
39
|
+
case 'ArrowLeft':
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
if (direction === 'rtl') {
|
|
43
|
+
if (ref.current) {
|
|
44
|
+
let target = getEventTarget(e as unknown as Event) as FocusableElement;
|
|
45
|
+
let prev = findNextSegment(ref.current, target.getBoundingClientRect().left, -1);
|
|
46
|
+
|
|
47
|
+
if (prev) {
|
|
48
|
+
prev.focus();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
focusManager.focusPrevious();
|
|
53
|
+
}
|
|
54
|
+
break;
|
|
55
|
+
case 'ArrowRight':
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
e.stopPropagation();
|
|
58
|
+
if (direction === 'rtl') {
|
|
59
|
+
if (ref.current) {
|
|
60
|
+
let target = getEventTarget(e as unknown as Event) as FocusableElement;
|
|
61
|
+
let next = findNextSegment(ref.current, target.getBoundingClientRect().left, 1);
|
|
62
|
+
|
|
63
|
+
if (next) {
|
|
64
|
+
next.focus();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
focusManager.focusNext();
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Focus the first placeholder segment from the end on mouse down/touch up in the field.
|
|
75
|
+
let focusLast = () => {
|
|
76
|
+
if (!ref.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Try to find the segment prior to the element that was clicked on.
|
|
80
|
+
let target = window.event ? (getEventTarget(window.event) as FocusableElement) : null;
|
|
81
|
+
let walker = getFocusableTreeWalker(ref.current, { tabbable: true });
|
|
82
|
+
if (target) {
|
|
83
|
+
walker.currentNode = target;
|
|
84
|
+
target = walker.previousNode() as FocusableElement;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// If no target found, find the last element from the end.
|
|
88
|
+
if (!target) {
|
|
89
|
+
let last: FocusableElement;
|
|
90
|
+
do {
|
|
91
|
+
last = walker.lastChild() as FocusableElement;
|
|
92
|
+
if (last) {
|
|
93
|
+
target = last;
|
|
94
|
+
}
|
|
95
|
+
} while (last);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Now go backwards until we find an element that is not a placeholder.
|
|
99
|
+
while (target?.hasAttribute('data-placeholder')) {
|
|
100
|
+
let prev = walker.previousNode() as FocusableElement;
|
|
101
|
+
if (prev && prev.hasAttribute('data-placeholder')) {
|
|
102
|
+
target = prev;
|
|
103
|
+
} else {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (target) {
|
|
109
|
+
target.focus();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
let { pressProps } = usePress({
|
|
114
|
+
preventFocusOnPress: true,
|
|
115
|
+
allowTextSelectionOnPress: true,
|
|
116
|
+
onPressStart(e) {
|
|
117
|
+
if (e.pointerType === 'mouse') {
|
|
118
|
+
focusLast();
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
onPress(e) {
|
|
122
|
+
if (e.pointerType === 'touch' || e.pointerType === 'pen') {
|
|
123
|
+
focusLast();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return mergeProps(pressProps, { onKeyDown });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function findNextSegment(group: Element, fromX: number, direction: number) {
|
|
132
|
+
let walker = getFocusableTreeWalker(group, { tabbable: true });
|
|
133
|
+
let node = walker.nextNode();
|
|
134
|
+
let closest: FocusableElement | null = null;
|
|
135
|
+
let closestDistance = Infinity;
|
|
136
|
+
while (node) {
|
|
137
|
+
let x = (node as Element).getBoundingClientRect().left;
|
|
138
|
+
let distance = x - fromX;
|
|
139
|
+
let absoluteDistance = Math.abs(distance);
|
|
140
|
+
if (Math.sign(distance) === direction && absoluteDistance < closestDistance) {
|
|
141
|
+
closest = node as FocusableElement;
|
|
142
|
+
closestDistance = absoluteDistance;
|
|
143
|
+
}
|
|
144
|
+
node = walker.nextNode();
|
|
145
|
+
}
|
|
146
|
+
return closest;
|
|
147
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/** @jsxImportSource octane */
|
|
2
|
+
// Ported from adobe/react-spectrum@1c84a49a1faf50b571c84e00bcf9c60b22ddd03e (packages/react-aria/src/datepicker/useDateRangePicker.ts).
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { AriaButtonProps } from '../button/useButton';
|
|
16
|
+
import { AriaDatePickerProps } from './useDatePicker';
|
|
17
|
+
import { AriaDialogProps } from '../dialog/useDialog';
|
|
18
|
+
import {
|
|
19
|
+
AriaLabelingProps,
|
|
20
|
+
DOMAttributes,
|
|
21
|
+
DOMProps,
|
|
22
|
+
GroupDOMAttributes,
|
|
23
|
+
InputDOMProps,
|
|
24
|
+
KeyboardEvent,
|
|
25
|
+
RefObject,
|
|
26
|
+
ValidationResult,
|
|
27
|
+
} from '@react-types/shared';
|
|
28
|
+
import { createFocusManager } from '../focus/FocusScope';
|
|
29
|
+
import {
|
|
30
|
+
DateRange,
|
|
31
|
+
DateRangePickerProps,
|
|
32
|
+
DateRangePickerState,
|
|
33
|
+
DateValue,
|
|
34
|
+
} from '../upstream-exports/react-stately/useDateRangePickerState';
|
|
35
|
+
import {
|
|
36
|
+
DEFAULT_VALIDATION_RESULT,
|
|
37
|
+
mergeValidation,
|
|
38
|
+
privateValidationStateProp,
|
|
39
|
+
} from '../upstream-exports/react-stately/private/form/useFormValidationState';
|
|
40
|
+
import { filterDOMProps } from '../utils/filterDOMProps';
|
|
41
|
+
import { focusManagerSymbol, roleSymbol } from './useDateField';
|
|
42
|
+
import intlMessages from '../intl/datepicker/index';
|
|
43
|
+
import { mergeProps } from '../utils/mergeProps';
|
|
44
|
+
import { nodeContains } from '../utils/shadowdom/DOMFunctions';
|
|
45
|
+
import { RangeCalendarProps } from '../upstream-exports/react-stately/useRangeCalendarState';
|
|
46
|
+
import { useDatePickerGroup } from './useDatePickerGroup';
|
|
47
|
+
import { useDescription } from '../utils/useDescription';
|
|
48
|
+
import { useField } from '../label/useField';
|
|
49
|
+
import { useFocusWithin } from '../interactions/useFocusWithin';
|
|
50
|
+
import { useId } from '../utils/useId';
|
|
51
|
+
import { useLocale } from '../i18n/I18nProvider';
|
|
52
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
53
|
+
import { useMemo, useRef } from '../compat/react';
|
|
54
|
+
|
|
55
|
+
export interface AriaDateRangePickerProps<T extends DateValue>
|
|
56
|
+
extends DateRangePickerProps<T>, AriaLabelingProps, Omit<InputDOMProps, 'name'>, DOMProps {}
|
|
57
|
+
|
|
58
|
+
export interface DateRangePickerAria extends ValidationResult {
|
|
59
|
+
/** Props for the date range picker's visible label element, if any. */
|
|
60
|
+
labelProps: DOMAttributes;
|
|
61
|
+
/** Props for the grouping element containing the date fields and button. */
|
|
62
|
+
groupProps: GroupDOMAttributes;
|
|
63
|
+
/** Props for the start date field. */
|
|
64
|
+
startFieldProps: AriaDatePickerProps<DateValue>;
|
|
65
|
+
/** Props for the end date field. */
|
|
66
|
+
endFieldProps: AriaDatePickerProps<DateValue>;
|
|
67
|
+
/** Props for the popover trigger button. */
|
|
68
|
+
buttonProps: AriaButtonProps;
|
|
69
|
+
/** Props for the description element, if any. */
|
|
70
|
+
descriptionProps: DOMAttributes;
|
|
71
|
+
/** Props for the error message element, if any. */
|
|
72
|
+
errorMessageProps: DOMAttributes;
|
|
73
|
+
/** Props for the popover dialog. */
|
|
74
|
+
dialogProps: AriaDialogProps;
|
|
75
|
+
/** Props for the range calendar within the popover dialog. */
|
|
76
|
+
calendarProps: RangeCalendarProps<DateValue>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Provides the behavior and accessibility implementation for a date picker component.
|
|
81
|
+
* A date range picker combines two DateFields and a RangeCalendar popover to allow
|
|
82
|
+
* users to enter or select a date and time range.
|
|
83
|
+
*/
|
|
84
|
+
export function useDateRangePicker<T extends DateValue>(
|
|
85
|
+
props: AriaDateRangePickerProps<T>,
|
|
86
|
+
state: DateRangePickerState,
|
|
87
|
+
ref: RefObject<Element | null>,
|
|
88
|
+
): DateRangePickerAria {
|
|
89
|
+
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/datepicker');
|
|
90
|
+
let { isInvalid, validationErrors, validationDetails } = state.displayValidation;
|
|
91
|
+
let { labelProps, fieldProps, descriptionProps, errorMessageProps } = useField({
|
|
92
|
+
...props,
|
|
93
|
+
labelElementType: 'span',
|
|
94
|
+
isInvalid,
|
|
95
|
+
errorMessage: props.errorMessage || validationErrors,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
let labelledBy = fieldProps['aria-labelledby'] || fieldProps.id;
|
|
99
|
+
|
|
100
|
+
let { locale } = useLocale();
|
|
101
|
+
let range = state.formatValue(locale, { month: 'long' });
|
|
102
|
+
let description = range
|
|
103
|
+
? stringFormatter.format('selectedRangeDescription', {
|
|
104
|
+
startDate: range.start,
|
|
105
|
+
endDate: range.end,
|
|
106
|
+
})
|
|
107
|
+
: '';
|
|
108
|
+
let descProps = useDescription(description);
|
|
109
|
+
|
|
110
|
+
let startFieldProps = {
|
|
111
|
+
'aria-label': stringFormatter.format('startDate'),
|
|
112
|
+
'aria-labelledby': labelledBy,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
let endFieldProps = {
|
|
116
|
+
'aria-label': stringFormatter.format('endDate'),
|
|
117
|
+
'aria-labelledby': labelledBy,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
let buttonId = useId();
|
|
121
|
+
let dialogId = useId();
|
|
122
|
+
|
|
123
|
+
let groupProps = useDatePickerGroup(state, ref);
|
|
124
|
+
|
|
125
|
+
let ariaDescribedBy =
|
|
126
|
+
[descProps['aria-describedby'], fieldProps['aria-describedby']].filter(Boolean).join(' ') ||
|
|
127
|
+
undefined;
|
|
128
|
+
let focusManager = useMemo(
|
|
129
|
+
() =>
|
|
130
|
+
createFocusManager(ref, {
|
|
131
|
+
// Exclude the button from the focus manager.
|
|
132
|
+
accept: (element) => element.id !== buttonId,
|
|
133
|
+
}),
|
|
134
|
+
[ref, buttonId],
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
let commonFieldProps = {
|
|
138
|
+
[focusManagerSymbol]: focusManager,
|
|
139
|
+
[roleSymbol]: 'presentation',
|
|
140
|
+
'aria-describedby': ariaDescribedBy,
|
|
141
|
+
placeholderValue: props.placeholderValue,
|
|
142
|
+
hideTimeZone: props.hideTimeZone,
|
|
143
|
+
hourCycle: props.hourCycle,
|
|
144
|
+
granularity: props.granularity,
|
|
145
|
+
shouldForceLeadingZeros: props.shouldForceLeadingZeros,
|
|
146
|
+
isDisabled: props.isDisabled,
|
|
147
|
+
isReadOnly: props.isReadOnly,
|
|
148
|
+
isRequired: props.isRequired,
|
|
149
|
+
validationBehavior: props.validationBehavior,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
let domProps = filterDOMProps(props);
|
|
153
|
+
|
|
154
|
+
let isFocused = useRef(false);
|
|
155
|
+
let { focusWithinProps } = useFocusWithin({
|
|
156
|
+
...props,
|
|
157
|
+
isDisabled: state.isOpen,
|
|
158
|
+
onBlurWithin: (e) => {
|
|
159
|
+
// Ignore when focus moves into the popover.
|
|
160
|
+
let dialog = document.getElementById(dialogId);
|
|
161
|
+
if (!nodeContains(dialog, e.relatedTarget as Node | null)) {
|
|
162
|
+
isFocused.current = false;
|
|
163
|
+
props.onBlur?.(e as any);
|
|
164
|
+
props.onFocusChange?.(false);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
onFocusWithin: (e) => {
|
|
168
|
+
if (!isFocused.current) {
|
|
169
|
+
isFocused.current = true;
|
|
170
|
+
props.onFocus?.(e as any);
|
|
171
|
+
props.onFocusChange?.(true);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
let startFieldValidation = useRef(DEFAULT_VALIDATION_RESULT);
|
|
177
|
+
let endFieldValidation = useRef(DEFAULT_VALIDATION_RESULT);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
groupProps: mergeProps(domProps, groupProps, fieldProps, descProps, focusWithinProps, {
|
|
181
|
+
role: 'group' as const,
|
|
182
|
+
'aria-disabled': props.isDisabled || null,
|
|
183
|
+
'aria-describedby': ariaDescribedBy,
|
|
184
|
+
onKeyDown(e: KeyboardEvent) {
|
|
185
|
+
if (state.isOpen) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (props.onKeyDown) {
|
|
190
|
+
props.onKeyDown(e);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
onKeyUp(e: KeyboardEvent) {
|
|
194
|
+
if (state.isOpen) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (props.onKeyUp) {
|
|
199
|
+
props.onKeyUp(e);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
labelProps: {
|
|
204
|
+
...labelProps,
|
|
205
|
+
onClick: () => {
|
|
206
|
+
focusManager.focusFirst();
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
buttonProps: {
|
|
210
|
+
...descProps,
|
|
211
|
+
id: buttonId,
|
|
212
|
+
'aria-haspopup': 'dialog',
|
|
213
|
+
'aria-label': stringFormatter.format('calendar'),
|
|
214
|
+
'aria-labelledby': `${buttonId} ${labelledBy}`,
|
|
215
|
+
'aria-describedby': ariaDescribedBy,
|
|
216
|
+
'aria-expanded': state.isOpen,
|
|
217
|
+
isDisabled: props.isDisabled || props.isReadOnly,
|
|
218
|
+
onPress: () => state.setOpen(true),
|
|
219
|
+
},
|
|
220
|
+
dialogProps: {
|
|
221
|
+
id: dialogId,
|
|
222
|
+
'aria-labelledby': `${buttonId} ${labelledBy}`,
|
|
223
|
+
},
|
|
224
|
+
startFieldProps: {
|
|
225
|
+
...startFieldProps,
|
|
226
|
+
...commonFieldProps,
|
|
227
|
+
value: state.value?.start ?? null,
|
|
228
|
+
defaultValue: state.defaultValue?.start,
|
|
229
|
+
onChange: (start) => state.setDateTime('start', start),
|
|
230
|
+
autoFocus: props.autoFocus,
|
|
231
|
+
name: props.startName,
|
|
232
|
+
form: props.form,
|
|
233
|
+
[privateValidationStateProp]: {
|
|
234
|
+
realtimeValidation: state.realtimeValidation,
|
|
235
|
+
displayValidation: state.displayValidation,
|
|
236
|
+
updateValidation(e: ValidationResult) {
|
|
237
|
+
startFieldValidation.current = e;
|
|
238
|
+
state.updateValidation(mergeValidation(e, endFieldValidation.current));
|
|
239
|
+
},
|
|
240
|
+
resetValidation: state.resetValidation,
|
|
241
|
+
commitValidation: state.commitValidation,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
endFieldProps: {
|
|
245
|
+
...endFieldProps,
|
|
246
|
+
...commonFieldProps,
|
|
247
|
+
value: state.value?.end ?? null,
|
|
248
|
+
defaultValue: state.defaultValue?.end,
|
|
249
|
+
onChange: (end) => state.setDateTime('end', end),
|
|
250
|
+
name: props.endName,
|
|
251
|
+
form: props.form,
|
|
252
|
+
[privateValidationStateProp]: {
|
|
253
|
+
realtimeValidation: state.realtimeValidation,
|
|
254
|
+
displayValidation: state.displayValidation,
|
|
255
|
+
updateValidation(e: ValidationResult) {
|
|
256
|
+
endFieldValidation.current = e;
|
|
257
|
+
state.updateValidation(mergeValidation(startFieldValidation.current, e));
|
|
258
|
+
},
|
|
259
|
+
resetValidation: state.resetValidation,
|
|
260
|
+
commitValidation: state.commitValidation,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
descriptionProps,
|
|
264
|
+
errorMessageProps,
|
|
265
|
+
calendarProps: {
|
|
266
|
+
autoFocus: true,
|
|
267
|
+
value: state.dateRange?.start && state.dateRange.end ? (state.dateRange as DateRange) : null,
|
|
268
|
+
onChange: state.setDateRange,
|
|
269
|
+
minValue: props.minValue,
|
|
270
|
+
maxValue: props.maxValue,
|
|
271
|
+
isDisabled: props.isDisabled,
|
|
272
|
+
isReadOnly: props.isReadOnly,
|
|
273
|
+
isDateUnavailable: props.isDateUnavailable,
|
|
274
|
+
allowsNonContiguousRanges: props.allowsNonContiguousRanges,
|
|
275
|
+
defaultFocusedValue: state.dateRange ? undefined : props.placeholderValue,
|
|
276
|
+
isInvalid: state.isInvalid,
|
|
277
|
+
errorMessage:
|
|
278
|
+
typeof props.errorMessage === 'function'
|
|
279
|
+
? props.errorMessage(state.displayValidation)
|
|
280
|
+
: props.errorMessage || state.displayValidation.validationErrors.join(' '),
|
|
281
|
+
firstDayOfWeek: props.firstDayOfWeek,
|
|
282
|
+
pageBehavior: props.pageBehavior,
|
|
283
|
+
},
|
|
284
|
+
isInvalid,
|
|
285
|
+
validationErrors,
|
|
286
|
+
validationDetails,
|
|
287
|
+
};
|
|
288
|
+
}
|