@octanejs/aria 0.0.1 → 0.0.3
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/package.json +6 -3
- package/src/breadcrumbs/useBreadcrumbItem.ts +95 -0
- package/src/breadcrumbs/useBreadcrumbs.ts +51 -0
- package/src/button/useButton.ts +273 -0
- package/src/button/useToggleButton.ts +131 -0
- package/src/button/useToggleButtonGroup.ts +131 -0
- package/src/checkbox/useCheckbox.ts +114 -0
- package/src/checkbox/useCheckboxGroup.ts +107 -0
- package/src/checkbox/useCheckboxGroupItem.ts +132 -0
- package/src/checkbox/utils.ts +15 -0
- package/src/combobox/useComboBox.ts +602 -0
- package/src/dialog/useDialog.ts +147 -0
- package/src/disclosure/useDisclosure.ts +180 -0
- package/src/focus/FocusRing.ts +69 -0
- package/src/focus/FocusScope.ts +1205 -0
- package/src/focus/useFocusRing.ts +125 -0
- package/src/focus/useHasTabbableChild.ts +82 -0
- package/src/focus/virtualFocus.ts +38 -0
- package/src/form/useFormValidation.ts +205 -0
- package/src/grid/useGridSelectionAnnouncement.ts +177 -0
- package/src/grid/useGridSelectionCheckbox.ts +86 -0
- package/src/grid/useHighlightSelectionDescription.ts +81 -0
- package/src/gridlist/useGridList.ts +236 -0
- package/src/gridlist/useGridListItem.ts +512 -0
- package/src/gridlist/useGridListSection.ts +78 -0
- package/src/gridlist/useGridListSelectionCheckbox.ts +47 -0
- package/src/gridlist/utils.ts +36 -0
- package/src/i18n/I18nProvider.ts +97 -0
- package/src/i18n/server.ts +115 -0
- package/src/i18n/useCollator.ts +42 -0
- package/src/i18n/useDateFormatter.ts +64 -0
- package/src/i18n/useDefaultLocale.ts +93 -0
- package/src/i18n/useFilter.ts +107 -0
- package/src/i18n/useListFormatter.ts +33 -0
- package/src/i18n/useLocalizedStringFormatter.ts +90 -0
- package/src/i18n/useNumberFormatter.ts +33 -0
- package/src/i18n/utils.ts +67 -0
- package/src/index.ts +268 -0
- package/src/intl/breadcrumbs/ar-AE.json +3 -0
- package/src/intl/breadcrumbs/bg-BG.json +3 -0
- package/src/intl/breadcrumbs/cs-CZ.json +3 -0
- package/src/intl/breadcrumbs/da-DK.json +3 -0
- package/src/intl/breadcrumbs/de-DE.json +3 -0
- package/src/intl/breadcrumbs/el-GR.json +3 -0
- package/src/intl/breadcrumbs/en-US.json +3 -0
- package/src/intl/breadcrumbs/es-ES.json +3 -0
- package/src/intl/breadcrumbs/et-EE.json +3 -0
- package/src/intl/breadcrumbs/fi-FI.json +3 -0
- package/src/intl/breadcrumbs/fr-FR.json +3 -0
- package/src/intl/breadcrumbs/he-IL.json +3 -0
- package/src/intl/breadcrumbs/hr-HR.json +3 -0
- package/src/intl/breadcrumbs/hu-HU.json +3 -0
- package/src/intl/breadcrumbs/index.ts +75 -0
- package/src/intl/breadcrumbs/it-IT.json +3 -0
- package/src/intl/breadcrumbs/ja-JP.json +3 -0
- package/src/intl/breadcrumbs/ko-KR.json +3 -0
- package/src/intl/breadcrumbs/lt-LT.json +3 -0
- package/src/intl/breadcrumbs/lv-LV.json +3 -0
- package/src/intl/breadcrumbs/nb-NO.json +3 -0
- package/src/intl/breadcrumbs/nl-NL.json +3 -0
- package/src/intl/breadcrumbs/pl-PL.json +3 -0
- package/src/intl/breadcrumbs/pt-BR.json +3 -0
- package/src/intl/breadcrumbs/pt-PT.json +3 -0
- package/src/intl/breadcrumbs/ro-RO.json +3 -0
- package/src/intl/breadcrumbs/ru-RU.json +3 -0
- package/src/intl/breadcrumbs/sk-SK.json +3 -0
- package/src/intl/breadcrumbs/sl-SI.json +3 -0
- package/src/intl/breadcrumbs/sr-SP.json +3 -0
- package/src/intl/breadcrumbs/sv-SE.json +3 -0
- package/src/intl/breadcrumbs/tr-TR.json +3 -0
- package/src/intl/breadcrumbs/uk-UA.json +3 -0
- package/src/intl/breadcrumbs/zh-CN.json +3 -0
- package/src/intl/breadcrumbs/zh-TW.json +3 -0
- package/src/intl/combobox/ar-AE.json +7 -0
- package/src/intl/combobox/bg-BG.json +7 -0
- package/src/intl/combobox/cs-CZ.json +7 -0
- package/src/intl/combobox/da-DK.json +7 -0
- package/src/intl/combobox/de-DE.json +7 -0
- package/src/intl/combobox/el-GR.json +7 -0
- package/src/intl/combobox/en-US.json +7 -0
- package/src/intl/combobox/es-ES.json +7 -0
- package/src/intl/combobox/et-EE.json +7 -0
- package/src/intl/combobox/fi-FI.json +7 -0
- package/src/intl/combobox/fr-FR.json +7 -0
- package/src/intl/combobox/he-IL.json +7 -0
- package/src/intl/combobox/hr-HR.json +7 -0
- package/src/intl/combobox/hu-HU.json +7 -0
- package/src/intl/combobox/index.ts +75 -0
- package/src/intl/combobox/it-IT.json +7 -0
- package/src/intl/combobox/ja-JP.json +7 -0
- package/src/intl/combobox/ko-KR.json +7 -0
- package/src/intl/combobox/lt-LT.json +7 -0
- package/src/intl/combobox/lv-LV.json +7 -0
- package/src/intl/combobox/nb-NO.json +7 -0
- package/src/intl/combobox/nl-NL.json +7 -0
- package/src/intl/combobox/pl-PL.json +7 -0
- package/src/intl/combobox/pt-BR.json +7 -0
- package/src/intl/combobox/pt-PT.json +7 -0
- package/src/intl/combobox/ro-RO.json +7 -0
- package/src/intl/combobox/ru-RU.json +7 -0
- package/src/intl/combobox/sk-SK.json +7 -0
- package/src/intl/combobox/sl-SI.json +7 -0
- package/src/intl/combobox/sr-SP.json +7 -0
- package/src/intl/combobox/sv-SE.json +7 -0
- package/src/intl/combobox/tr-TR.json +7 -0
- package/src/intl/combobox/uk-UA.json +7 -0
- package/src/intl/combobox/zh-CN.json +7 -0
- package/src/intl/combobox/zh-TW.json +7 -0
- package/src/intl/grid/ar-AE.json +8 -0
- package/src/intl/grid/bg-BG.json +8 -0
- package/src/intl/grid/cs-CZ.json +8 -0
- package/src/intl/grid/da-DK.json +8 -0
- package/src/intl/grid/de-DE.json +8 -0
- package/src/intl/grid/el-GR.json +8 -0
- package/src/intl/grid/en-US.json +8 -0
- package/src/intl/grid/es-ES.json +8 -0
- package/src/intl/grid/et-EE.json +8 -0
- package/src/intl/grid/fi-FI.json +8 -0
- package/src/intl/grid/fr-FR.json +8 -0
- package/src/intl/grid/he-IL.json +8 -0
- package/src/intl/grid/hr-HR.json +8 -0
- package/src/intl/grid/hu-HU.json +8 -0
- package/src/intl/grid/index.ts +75 -0
- package/src/intl/grid/it-IT.json +8 -0
- package/src/intl/grid/ja-JP.json +8 -0
- package/src/intl/grid/ko-KR.json +8 -0
- package/src/intl/grid/lt-LT.json +8 -0
- package/src/intl/grid/lv-LV.json +8 -0
- package/src/intl/grid/nb-NO.json +8 -0
- package/src/intl/grid/nl-NL.json +8 -0
- package/src/intl/grid/pl-PL.json +8 -0
- package/src/intl/grid/pt-BR.json +8 -0
- package/src/intl/grid/pt-PT.json +8 -0
- package/src/intl/grid/ro-RO.json +8 -0
- package/src/intl/grid/ru-RU.json +8 -0
- package/src/intl/grid/sk-SK.json +8 -0
- package/src/intl/grid/sl-SI.json +8 -0
- package/src/intl/grid/sr-SP.json +8 -0
- package/src/intl/grid/sv-SE.json +8 -0
- package/src/intl/grid/tr-TR.json +8 -0
- package/src/intl/grid/uk-UA.json +8 -0
- package/src/intl/grid/zh-CN.json +8 -0
- package/src/intl/grid/zh-TW.json +8 -0
- package/src/intl/gridlist/ar-AE.json +4 -0
- package/src/intl/gridlist/bg-BG.json +4 -0
- package/src/intl/gridlist/cs-CZ.json +4 -0
- package/src/intl/gridlist/da-DK.json +4 -0
- package/src/intl/gridlist/de-DE.json +4 -0
- package/src/intl/gridlist/el-GR.json +4 -0
- package/src/intl/gridlist/en-US.json +4 -0
- package/src/intl/gridlist/es-ES.json +4 -0
- package/src/intl/gridlist/et-EE.json +4 -0
- package/src/intl/gridlist/fi-FI.json +4 -0
- package/src/intl/gridlist/fr-FR.json +4 -0
- package/src/intl/gridlist/he-IL.json +4 -0
- package/src/intl/gridlist/hr-HR.json +4 -0
- package/src/intl/gridlist/hu-HU.json +4 -0
- package/src/intl/gridlist/index.ts +75 -0
- package/src/intl/gridlist/it-IT.json +4 -0
- package/src/intl/gridlist/ja-JP.json +4 -0
- package/src/intl/gridlist/ko-KR.json +4 -0
- package/src/intl/gridlist/lt-LT.json +4 -0
- package/src/intl/gridlist/lv-LV.json +4 -0
- package/src/intl/gridlist/nb-NO.json +4 -0
- package/src/intl/gridlist/nl-NL.json +4 -0
- package/src/intl/gridlist/pl-PL.json +4 -0
- package/src/intl/gridlist/pt-BR.json +4 -0
- package/src/intl/gridlist/pt-PT.json +4 -0
- package/src/intl/gridlist/ro-RO.json +4 -0
- package/src/intl/gridlist/ru-RU.json +4 -0
- package/src/intl/gridlist/sk-SK.json +4 -0
- package/src/intl/gridlist/sl-SI.json +4 -0
- package/src/intl/gridlist/sr-SP.json +4 -0
- package/src/intl/gridlist/sv-SE.json +4 -0
- package/src/intl/gridlist/tr-TR.json +4 -0
- package/src/intl/gridlist/uk-UA.json +4 -0
- package/src/intl/gridlist/zh-CN.json +4 -0
- package/src/intl/gridlist/zh-TW.json +4 -0
- package/src/intl/menu/ar-AE.json +3 -0
- package/src/intl/menu/bg-BG.json +3 -0
- package/src/intl/menu/cs-CZ.json +3 -0
- package/src/intl/menu/da-DK.json +3 -0
- package/src/intl/menu/de-DE.json +3 -0
- package/src/intl/menu/el-GR.json +3 -0
- package/src/intl/menu/en-US.json +3 -0
- package/src/intl/menu/es-ES.json +3 -0
- package/src/intl/menu/et-EE.json +3 -0
- package/src/intl/menu/fi-FI.json +3 -0
- package/src/intl/menu/fr-FR.json +3 -0
- package/src/intl/menu/he-IL.json +3 -0
- package/src/intl/menu/hr-HR.json +3 -0
- package/src/intl/menu/hu-HU.json +3 -0
- package/src/intl/menu/index.ts +75 -0
- package/src/intl/menu/it-IT.json +3 -0
- package/src/intl/menu/ja-JP.json +3 -0
- package/src/intl/menu/ko-KR.json +3 -0
- package/src/intl/menu/lt-LT.json +3 -0
- package/src/intl/menu/lv-LV.json +3 -0
- package/src/intl/menu/nb-NO.json +3 -0
- package/src/intl/menu/nl-NL.json +3 -0
- package/src/intl/menu/pl-PL.json +3 -0
- package/src/intl/menu/pt-BR.json +3 -0
- package/src/intl/menu/pt-PT.json +3 -0
- package/src/intl/menu/ro-RO.json +3 -0
- package/src/intl/menu/ru-RU.json +3 -0
- package/src/intl/menu/sk-SK.json +3 -0
- package/src/intl/menu/sl-SI.json +3 -0
- package/src/intl/menu/sr-SP.json +3 -0
- package/src/intl/menu/sv-SE.json +3 -0
- package/src/intl/menu/tr-TR.json +3 -0
- package/src/intl/menu/uk-UA.json +3 -0
- package/src/intl/menu/zh-CN.json +3 -0
- package/src/intl/menu/zh-TW.json +3 -0
- package/src/intl/numberfield/ar-AE.json +5 -0
- package/src/intl/numberfield/bg-BG.json +5 -0
- package/src/intl/numberfield/cs-CZ.json +5 -0
- package/src/intl/numberfield/da-DK.json +5 -0
- package/src/intl/numberfield/de-DE.json +5 -0
- package/src/intl/numberfield/el-GR.json +5 -0
- package/src/intl/numberfield/en-US.json +5 -0
- package/src/intl/numberfield/es-ES.json +5 -0
- package/src/intl/numberfield/et-EE.json +5 -0
- package/src/intl/numberfield/fi-FI.json +5 -0
- package/src/intl/numberfield/fr-FR.json +5 -0
- package/src/intl/numberfield/he-IL.json +5 -0
- package/src/intl/numberfield/hr-HR.json +5 -0
- package/src/intl/numberfield/hu-HU.json +5 -0
- package/src/intl/numberfield/index.ts +75 -0
- package/src/intl/numberfield/it-IT.json +5 -0
- package/src/intl/numberfield/ja-JP.json +5 -0
- package/src/intl/numberfield/ko-KR.json +5 -0
- package/src/intl/numberfield/lt-LT.json +5 -0
- package/src/intl/numberfield/lv-LV.json +5 -0
- package/src/intl/numberfield/nb-NO.json +5 -0
- package/src/intl/numberfield/nl-NL.json +5 -0
- package/src/intl/numberfield/pl-PL.json +5 -0
- package/src/intl/numberfield/pt-BR.json +5 -0
- package/src/intl/numberfield/pt-PT.json +5 -0
- package/src/intl/numberfield/ro-RO.json +5 -0
- package/src/intl/numberfield/ru-RU.json +5 -0
- package/src/intl/numberfield/sk-SK.json +5 -0
- package/src/intl/numberfield/sl-SI.json +5 -0
- package/src/intl/numberfield/sr-SP.json +5 -0
- package/src/intl/numberfield/sv-SE.json +5 -0
- package/src/intl/numberfield/tr-TR.json +5 -0
- package/src/intl/numberfield/uk-UA.json +5 -0
- package/src/intl/numberfield/zh-CN.json +5 -0
- package/src/intl/numberfield/zh-TW.json +5 -0
- package/src/intl/overlays/ar-AE.json +3 -0
- package/src/intl/overlays/bg-BG.json +3 -0
- package/src/intl/overlays/cs-CZ.json +3 -0
- package/src/intl/overlays/da-DK.json +3 -0
- package/src/intl/overlays/de-DE.json +3 -0
- package/src/intl/overlays/el-GR.json +3 -0
- package/src/intl/overlays/en-US.json +3 -0
- package/src/intl/overlays/es-ES.json +3 -0
- package/src/intl/overlays/et-EE.json +3 -0
- package/src/intl/overlays/fi-FI.json +3 -0
- package/src/intl/overlays/fr-FR.json +3 -0
- package/src/intl/overlays/he-IL.json +3 -0
- package/src/intl/overlays/hr-HR.json +3 -0
- package/src/intl/overlays/hu-HU.json +3 -0
- package/src/intl/overlays/index.ts +75 -0
- package/src/intl/overlays/it-IT.json +3 -0
- package/src/intl/overlays/ja-JP.json +3 -0
- package/src/intl/overlays/ko-KR.json +3 -0
- package/src/intl/overlays/lt-LT.json +3 -0
- package/src/intl/overlays/lv-LV.json +3 -0
- package/src/intl/overlays/nb-NO.json +3 -0
- package/src/intl/overlays/nl-NL.json +3 -0
- package/src/intl/overlays/pl-PL.json +3 -0
- package/src/intl/overlays/pt-BR.json +3 -0
- package/src/intl/overlays/pt-PT.json +3 -0
- package/src/intl/overlays/ro-RO.json +3 -0
- package/src/intl/overlays/ru-RU.json +3 -0
- package/src/intl/overlays/sk-SK.json +3 -0
- package/src/intl/overlays/sl-SI.json +3 -0
- package/src/intl/overlays/sr-SP.json +3 -0
- package/src/intl/overlays/sv-SE.json +3 -0
- package/src/intl/overlays/tr-TR.json +3 -0
- package/src/intl/overlays/uk-UA.json +3 -0
- package/src/intl/overlays/zh-CN.json +3 -0
- package/src/intl/overlays/zh-TW.json +3 -0
- package/src/intl/searchfield/ar-AE.json +3 -0
- package/src/intl/searchfield/bg-BG.json +3 -0
- package/src/intl/searchfield/cs-CZ.json +3 -0
- package/src/intl/searchfield/da-DK.json +3 -0
- package/src/intl/searchfield/de-DE.json +3 -0
- package/src/intl/searchfield/el-GR.json +3 -0
- package/src/intl/searchfield/en-US.json +3 -0
- package/src/intl/searchfield/es-ES.json +3 -0
- package/src/intl/searchfield/et-EE.json +3 -0
- package/src/intl/searchfield/fi-FI.json +3 -0
- package/src/intl/searchfield/fr-FR.json +3 -0
- package/src/intl/searchfield/he-IL.json +3 -0
- package/src/intl/searchfield/hr-HR.json +3 -0
- package/src/intl/searchfield/hu-HU.json +3 -0
- package/src/intl/searchfield/index.ts +75 -0
- package/src/intl/searchfield/it-IT.json +3 -0
- package/src/intl/searchfield/ja-JP.json +3 -0
- package/src/intl/searchfield/ko-KR.json +3 -0
- package/src/intl/searchfield/lt-LT.json +3 -0
- package/src/intl/searchfield/lv-LV.json +3 -0
- package/src/intl/searchfield/nb-NO.json +3 -0
- package/src/intl/searchfield/nl-NL.json +3 -0
- package/src/intl/searchfield/pl-PL.json +3 -0
- package/src/intl/searchfield/pt-BR.json +3 -0
- package/src/intl/searchfield/pt-PT.json +3 -0
- package/src/intl/searchfield/ro-RO.json +3 -0
- package/src/intl/searchfield/ru-RU.json +3 -0
- package/src/intl/searchfield/sk-SK.json +3 -0
- package/src/intl/searchfield/sl-SI.json +3 -0
- package/src/intl/searchfield/sr-SP.json +3 -0
- package/src/intl/searchfield/sv-SE.json +3 -0
- package/src/intl/searchfield/tr-TR.json +3 -0
- package/src/intl/searchfield/uk-UA.json +3 -0
- package/src/intl/searchfield/zh-CN.json +3 -0
- package/src/intl/searchfield/zh-TW.json +3 -0
- package/src/intl/spinbutton/ar-AE.json +3 -0
- package/src/intl/spinbutton/bg-BG.json +3 -0
- package/src/intl/spinbutton/cs-CZ.json +3 -0
- package/src/intl/spinbutton/da-DK.json +3 -0
- package/src/intl/spinbutton/de-DE.json +3 -0
- package/src/intl/spinbutton/el-GR.json +3 -0
- package/src/intl/spinbutton/en-US.json +3 -0
- package/src/intl/spinbutton/es-ES.json +3 -0
- package/src/intl/spinbutton/et-EE.json +3 -0
- package/src/intl/spinbutton/fi-FI.json +3 -0
- package/src/intl/spinbutton/fr-FR.json +3 -0
- package/src/intl/spinbutton/he-IL.json +3 -0
- package/src/intl/spinbutton/hr-HR.json +3 -0
- package/src/intl/spinbutton/hu-HU.json +3 -0
- package/src/intl/spinbutton/index.ts +75 -0
- package/src/intl/spinbutton/it-IT.json +3 -0
- package/src/intl/spinbutton/ja-JP.json +3 -0
- package/src/intl/spinbutton/ko-KR.json +3 -0
- package/src/intl/spinbutton/lt-LT.json +3 -0
- package/src/intl/spinbutton/lv-LV.json +3 -0
- package/src/intl/spinbutton/nb-NO.json +3 -0
- package/src/intl/spinbutton/nl-NL.json +3 -0
- package/src/intl/spinbutton/pl-PL.json +3 -0
- package/src/intl/spinbutton/pt-BR.json +3 -0
- package/src/intl/spinbutton/pt-PT.json +3 -0
- package/src/intl/spinbutton/ro-RO.json +3 -0
- package/src/intl/spinbutton/ru-RU.json +3 -0
- package/src/intl/spinbutton/sk-SK.json +3 -0
- package/src/intl/spinbutton/sl-SI.json +3 -0
- package/src/intl/spinbutton/sr-SP.json +3 -0
- package/src/intl/spinbutton/sv-SE.json +3 -0
- package/src/intl/spinbutton/tr-TR.json +3 -0
- package/src/intl/spinbutton/uk-UA.json +3 -0
- package/src/intl/spinbutton/zh-CN.json +3 -0
- package/src/intl/spinbutton/zh-TW.json +3 -0
- package/src/intl/tag/ar-AE.json +4 -0
- package/src/intl/tag/bg-BG.json +4 -0
- package/src/intl/tag/cs-CZ.json +4 -0
- package/src/intl/tag/da-DK.json +4 -0
- package/src/intl/tag/de-DE.json +4 -0
- package/src/intl/tag/el-GR.json +4 -0
- package/src/intl/tag/en-US.json +4 -0
- package/src/intl/tag/es-ES.json +4 -0
- package/src/intl/tag/et-EE.json +4 -0
- package/src/intl/tag/fi-FI.json +4 -0
- package/src/intl/tag/fr-FR.json +4 -0
- package/src/intl/tag/he-IL.json +4 -0
- package/src/intl/tag/hr-HR.json +4 -0
- package/src/intl/tag/hu-HU.json +4 -0
- package/src/intl/tag/index.ts +75 -0
- package/src/intl/tag/it-IT.json +4 -0
- package/src/intl/tag/ja-JP.json +4 -0
- package/src/intl/tag/ko-KR.json +4 -0
- package/src/intl/tag/lt-LT.json +4 -0
- package/src/intl/tag/lv-LV.json +4 -0
- package/src/intl/tag/nb-NO.json +4 -0
- package/src/intl/tag/nl-NL.json +4 -0
- package/src/intl/tag/pl-PL.json +4 -0
- package/src/intl/tag/pt-BR.json +4 -0
- package/src/intl/tag/pt-PT.json +4 -0
- package/src/intl/tag/ro-RO.json +4 -0
- package/src/intl/tag/ru-RU.json +4 -0
- package/src/intl/tag/sk-SK.json +4 -0
- package/src/intl/tag/sl-SI.json +4 -0
- package/src/intl/tag/sr-SP.json +4 -0
- package/src/intl/tag/sv-SE.json +4 -0
- package/src/intl/tag/tr-TR.json +4 -0
- package/src/intl/tag/uk-UA.json +4 -0
- package/src/intl/tag/zh-CN.json +4 -0
- package/src/intl/tag/zh-TW.json +4 -0
- package/src/label/useField.ts +67 -0
- package/src/label/useLabel.ts +78 -0
- package/src/link/useLink.ts +108 -0
- package/src/listbox/useListBox.ts +224 -0
- package/src/listbox/useListBoxSection.ts +74 -0
- package/src/listbox/useOption.ts +212 -0
- package/src/listbox/utils.ts +38 -0
- package/src/live-announcer/LiveAnnouncer.ts +172 -0
- package/src/menu/useMenu.ts +139 -0
- package/src/menu/useMenuItem.ts +453 -0
- package/src/menu/useMenuSection.ts +70 -0
- package/src/menu/useMenuTrigger.ts +189 -0
- package/src/menu/useSafelyMouseToSubmenu.ts +236 -0
- package/src/menu/useSubmenuTrigger.ts +357 -0
- package/src/menu/utils.ts +16 -0
- package/src/meter/useMeter.ts +43 -0
- package/src/numberfield/useNumberField.ts +572 -0
- package/src/overlays/DismissButton.ts +50 -0
- package/src/overlays/Overlay.ts +106 -0
- package/src/overlays/PortalProvider.ts +37 -0
- package/src/overlays/ariaHideOutside.ts +299 -0
- package/src/overlays/calculatePosition.ts +856 -0
- package/src/overlays/useCloseOnScroll.ts +75 -0
- package/src/overlays/useModal.ts +224 -0
- package/src/overlays/useModalOverlay.ts +103 -0
- package/src/overlays/useOverlay.ts +199 -0
- package/src/overlays/useOverlayPosition.ts +462 -0
- package/src/overlays/useOverlayTrigger.ts +94 -0
- package/src/overlays/usePopover.ts +170 -0
- package/src/overlays/usePreventScroll.ts +316 -0
- package/src/progress/useProgressBar.ts +115 -0
- package/src/radio/useRadio.ts +219 -0
- package/src/radio/useRadioGroup.ts +184 -0
- package/src/radio/utils.ts +15 -0
- package/src/searchfield/useSearchField.ts +156 -0
- package/src/select/HiddenSelect.ts +261 -0
- package/src/select/useSelect.ts +332 -0
- package/src/selection/DOMLayoutDelegate.ts +51 -0
- package/src/selection/ListKeyboardDelegate.ts +392 -0
- package/src/selection/useSelectableCollection.ts +750 -0
- package/src/selection/useSelectableItem.ts +499 -0
- package/src/selection/useSelectableList.ts +132 -0
- package/src/selection/useTypeSelect.ts +192 -0
- package/src/selection/utils.ts +50 -0
- package/src/separator/useSeparator.ts +41 -0
- package/src/slider/useSlider.ts +277 -0
- package/src/slider/useSliderThumb.ts +375 -0
- package/src/slider/utils.ts +20 -0
- package/src/spinbutton/useSpinButton.ts +380 -0
- package/src/stately/checkbox/useCheckboxGroupState.ts +177 -0
- package/src/stately/collections/CollectionBuilder.ts +332 -0
- package/src/stately/collections/Item.ts +78 -0
- package/src/stately/collections/Section.ts +52 -0
- package/src/stately/collections/getChildNodes.ts +94 -0
- package/src/stately/collections/getItemCount.ts +29 -0
- package/src/stately/collections/types.ts +20 -0
- package/src/stately/collections/useCollection.ts +54 -0
- package/src/stately/combobox/useComboBoxState.ts +763 -0
- package/src/stately/disclosure/useDisclosureGroupState.ts +108 -0
- package/src/stately/disclosure/useDisclosureState.ts +84 -0
- package/src/stately/form/useFormValidationState.ts +331 -0
- package/src/stately/index.ts +111 -0
- package/src/stately/list/ListCollection.ts +104 -0
- package/src/stately/list/useListState.ts +178 -0
- package/src/stately/list/useSingleSelectListState.ts +101 -0
- package/src/stately/menu/useMenuTriggerState.ts +120 -0
- package/src/stately/menu/useSubmenuTriggerState.ts +116 -0
- package/src/stately/numberfield/useNumberFieldState.ts +430 -0
- package/src/stately/overlays/useOverlayTriggerState.ts +85 -0
- package/src/stately/radio/useRadioGroupState.ts +150 -0
- package/src/stately/searchfield/useSearchFieldState.ts +79 -0
- package/src/stately/select/useSelectState.ts +322 -0
- package/src/stately/selection/Selection.ts +23 -0
- package/src/stately/selection/SelectionManager.ts +541 -0
- package/src/stately/selection/types.ts +117 -0
- package/src/stately/selection/useMultipleSelectionState.ts +178 -0
- package/src/stately/slider/useSliderState.ts +458 -0
- package/src/stately/tabs/useTabListState.ts +149 -0
- package/src/stately/toggle/useToggleGroupState.ts +109 -0
- package/src/stately/toggle/useToggleState.ts +100 -0
- package/src/stately/tooltip/useTooltipTriggerState.ts +218 -0
- package/src/stately/tree/TreeCollection.ts +92 -0
- package/src/stately/tree/useTreeState.ts +121 -0
- package/src/stately/utils/useControlledState.ts +7 -0
- package/src/switch/useSwitch.ts +77 -0
- package/src/tabs/TabsKeyboardDelegate.ts +99 -0
- package/src/tabs/useTab.ts +117 -0
- package/src/tabs/useTabList.ts +105 -0
- package/src/tabs/useTabPanel.ts +75 -0
- package/src/tabs/utils.ts +32 -0
- package/src/tag/useTag.ts +162 -0
- package/src/tag/useTagGroup.ts +192 -0
- package/src/textfield/useFormattedTextField.ts +203 -0
- package/src/textfield/useTextField.ts +248 -0
- package/src/toggle/useToggle.ts +265 -0
- package/src/toolbar/useToolbar.ts +147 -0
- package/src/tooltip/useTooltip.ts +64 -0
- package/src/tooltip/useTooltipTrigger.ts +187 -0
- package/src/utils/filterDOMProps.ts +121 -0
- package/src/utils/getScrollParent.ts +16 -0
- package/src/utils/getScrollParents.ts +20 -0
- package/src/utils/keyboard.ts +38 -0
- package/src/utils/scrollIntoView.ts +178 -0
- package/src/utils/useDeepMemo.ts +30 -0
- package/src/utils/useFormReset.ts +54 -0
- package/src/utils/useId.ts +5 -0
- package/src/utils/useLabels.ts +53 -0
- package/src/utils/useResizeObserver.ts +70 -0
- package/src/utils/useSlot.ts +78 -0
- package/src/utils/useUpdateEffect.ts +54 -0
- package/src/utils/useUpdateLayoutEffect.ts +58 -0
- package/src/visually-hidden/VisuallyHidden.ts +100 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
// Ported from react-aria (source: .react-spectrum/packages/react-aria/src/spinbutton/useSpinButton.ts).
|
|
2
|
+
// octane adaptations:
|
|
3
|
+
// - Handlers receive NATIVE events (there is no synthetic layer): the spinbutton keydown
|
|
4
|
+
// handler is attached as a plain delegated DOM handler, so upstream's
|
|
5
|
+
// `e.nativeEvent.isComposing` reads `e.isComposing` off the native KeyboardEvent.
|
|
6
|
+
// - The Parcel glob intl import becomes the generated src/intl/spinbutton index
|
|
7
|
+
// (verbatim dictionaries).
|
|
8
|
+
// - `DOMAttributes` is a local structural prop-bag alias (upstream's is typed over
|
|
9
|
+
// React's synthetic handlers).
|
|
10
|
+
// - Public-hook slot threading (splitSlot/subSlot); explicit dependency arrays are kept
|
|
11
|
+
// verbatim.
|
|
12
|
+
import { announce, clearAnnouncer } from '../live-announcer/LiveAnnouncer';
|
|
13
|
+
|
|
14
|
+
import type { AriaButtonProps } from '../button/useButton';
|
|
15
|
+
import type { InputBase, RangeInputBase, Validation, ValueBase } from '@react-types/shared';
|
|
16
|
+
import intlMessages from '../intl/spinbutton';
|
|
17
|
+
import { useCallback, useEffect, useRef, useState } from 'octane';
|
|
18
|
+
import { useEffectEvent } from '../utils/useEffectEvent';
|
|
19
|
+
import { useGlobalListeners } from '../utils/useGlobalListeners';
|
|
20
|
+
import { useLocalizedStringFormatter } from '../i18n/useLocalizedStringFormatter';
|
|
21
|
+
|
|
22
|
+
import { S, splitSlot, subSlot } from '../internal';
|
|
23
|
+
|
|
24
|
+
// octane adaptation: minimal structural DOMAttributes (upstream's drags React's synthetic
|
|
25
|
+
// handler types along).
|
|
26
|
+
type DOMAttributes = Record<string, any>;
|
|
27
|
+
|
|
28
|
+
const noop = () => {};
|
|
29
|
+
|
|
30
|
+
export interface SpinButtonProps
|
|
31
|
+
extends InputBase, Validation<number>, ValueBase<number>, RangeInputBase<number> {
|
|
32
|
+
textValue?: string;
|
|
33
|
+
onIncrement?: () => void;
|
|
34
|
+
onIncrementPage?: () => void;
|
|
35
|
+
onDecrement?: () => void;
|
|
36
|
+
onDecrementPage?: () => void;
|
|
37
|
+
onDecrementToMin?: () => void;
|
|
38
|
+
onIncrementToMax?: () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface SpinbuttonAria {
|
|
42
|
+
spinButtonProps: DOMAttributes;
|
|
43
|
+
incrementButtonProps: AriaButtonProps;
|
|
44
|
+
decrementButtonProps: AriaButtonProps;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function useSpinButton(props: SpinButtonProps): SpinbuttonAria;
|
|
48
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
49
|
+
export function useSpinButton(props: SpinButtonProps, slot: symbol | undefined): SpinbuttonAria;
|
|
50
|
+
export function useSpinButton(...args: any[]): SpinbuttonAria {
|
|
51
|
+
const [user, slotArg] = splitSlot(args);
|
|
52
|
+
const slot = slotArg ?? S('useSpinButton');
|
|
53
|
+
const props = user[0] as SpinButtonProps;
|
|
54
|
+
|
|
55
|
+
const _async = useRef<number | undefined>(undefined, subSlot(slot, 'async'));
|
|
56
|
+
let {
|
|
57
|
+
value,
|
|
58
|
+
textValue,
|
|
59
|
+
minValue,
|
|
60
|
+
maxValue,
|
|
61
|
+
isDisabled,
|
|
62
|
+
isReadOnly,
|
|
63
|
+
isRequired,
|
|
64
|
+
onIncrement,
|
|
65
|
+
onIncrementPage,
|
|
66
|
+
onDecrement,
|
|
67
|
+
onDecrementPage,
|
|
68
|
+
onDecrementToMin,
|
|
69
|
+
onIncrementToMax,
|
|
70
|
+
} = props;
|
|
71
|
+
const stringFormatter = useLocalizedStringFormatter(
|
|
72
|
+
intlMessages,
|
|
73
|
+
'@react-aria/spinbutton',
|
|
74
|
+
subSlot(slot, 'strings'),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
let isSpinning = useRef(false, subSlot(slot, 'isSpinning'));
|
|
78
|
+
const clearAsync = useCallback(
|
|
79
|
+
() => {
|
|
80
|
+
clearTimeout(_async.current);
|
|
81
|
+
isSpinning.current = false;
|
|
82
|
+
},
|
|
83
|
+
[],
|
|
84
|
+
subSlot(slot, 'clearAsync'),
|
|
85
|
+
);
|
|
86
|
+
const clearAsyncEvent = useEffectEvent(
|
|
87
|
+
() => {
|
|
88
|
+
clearAsync();
|
|
89
|
+
},
|
|
90
|
+
subSlot(slot, 'clearAsyncEvent'),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
useEffect(
|
|
94
|
+
() => {
|
|
95
|
+
return () => clearAsyncEvent();
|
|
96
|
+
},
|
|
97
|
+
[],
|
|
98
|
+
subSlot(slot, 'unmountFx'),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
let onKeyDown = (e: KeyboardEvent) => {
|
|
102
|
+
// octane adaptation: `e.nativeEvent.isComposing` → the native event's own flag.
|
|
103
|
+
if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly || e.isComposing) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
switch (e.key) {
|
|
108
|
+
case 'PageUp':
|
|
109
|
+
if (onIncrementPage) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
onIncrementPage?.();
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
// fallthrough!
|
|
115
|
+
case 'ArrowUp':
|
|
116
|
+
case 'Up':
|
|
117
|
+
if (onIncrement) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
onIncrement?.();
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case 'PageDown':
|
|
123
|
+
if (onDecrementPage) {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
onDecrementPage?.();
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
// fallthrough
|
|
129
|
+
case 'ArrowDown':
|
|
130
|
+
case 'Down':
|
|
131
|
+
if (onDecrement) {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
onDecrement?.();
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case 'Home':
|
|
137
|
+
if (onDecrementToMin) {
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
onDecrementToMin?.();
|
|
140
|
+
}
|
|
141
|
+
break;
|
|
142
|
+
case 'End':
|
|
143
|
+
if (onIncrementToMax) {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
onIncrementToMax?.();
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
let isFocused = useRef(false, subSlot(slot, 'isFocused'));
|
|
152
|
+
let onFocus = () => {
|
|
153
|
+
isFocused.current = true;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
let onBlur = () => {
|
|
157
|
+
isFocused.current = false;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
|
|
161
|
+
// This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
|
|
162
|
+
// and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
|
|
163
|
+
// In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
|
|
164
|
+
let ariaTextValue =
|
|
165
|
+
textValue === ''
|
|
166
|
+
? stringFormatter.format('Empty')
|
|
167
|
+
: (textValue || `${value}`).replace('-', '\u2212');
|
|
168
|
+
|
|
169
|
+
useEffect(
|
|
170
|
+
() => {
|
|
171
|
+
if (isFocused.current) {
|
|
172
|
+
clearAnnouncer('assertive');
|
|
173
|
+
announce(ariaTextValue, 'assertive');
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
[ariaTextValue],
|
|
177
|
+
subSlot(slot, 'announceFx'),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// For touch users, if they move their finger like they're scrolling, we don't want to trigger a spin.
|
|
181
|
+
let onPointerCancel = useCallback(
|
|
182
|
+
() => {
|
|
183
|
+
clearAsync();
|
|
184
|
+
},
|
|
185
|
+
[clearAsync],
|
|
186
|
+
subSlot(slot, 'pointerCancel'),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
const onIncrementEvent = useEffectEvent(onIncrement ?? noop, subSlot(slot, 'incEvent'));
|
|
190
|
+
const onDecrementEvent = useEffectEvent(onDecrement ?? noop, subSlot(slot, 'decEvent'));
|
|
191
|
+
|
|
192
|
+
const stepUpEvent = useEffectEvent(
|
|
193
|
+
() => {
|
|
194
|
+
if (
|
|
195
|
+
maxValue === undefined ||
|
|
196
|
+
isNaN(maxValue) ||
|
|
197
|
+
value === undefined ||
|
|
198
|
+
isNaN(value) ||
|
|
199
|
+
value < maxValue
|
|
200
|
+
) {
|
|
201
|
+
onIncrementEvent();
|
|
202
|
+
onIncrementPressStartEvent(60);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
subSlot(slot, 'stepUp'),
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
const onIncrementPressStartEvent = useEffectEvent(
|
|
209
|
+
(initialStepDelay: number) => {
|
|
210
|
+
clearAsyncEvent();
|
|
211
|
+
isSpinning.current = true;
|
|
212
|
+
// Start spinning after initial delay
|
|
213
|
+
_async.current = window.setTimeout(stepUpEvent, initialStepDelay);
|
|
214
|
+
},
|
|
215
|
+
subSlot(slot, 'incPressStart'),
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const stepDownEvent = useEffectEvent(
|
|
219
|
+
() => {
|
|
220
|
+
if (
|
|
221
|
+
minValue === undefined ||
|
|
222
|
+
isNaN(minValue) ||
|
|
223
|
+
value === undefined ||
|
|
224
|
+
isNaN(value) ||
|
|
225
|
+
value > minValue
|
|
226
|
+
) {
|
|
227
|
+
onDecrementEvent();
|
|
228
|
+
onDecrementPressStartEvent(60);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
subSlot(slot, 'stepDown'),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const onDecrementPressStartEvent = useEffectEvent(
|
|
235
|
+
(initialStepDelay: number) => {
|
|
236
|
+
clearAsyncEvent();
|
|
237
|
+
isSpinning.current = true;
|
|
238
|
+
// Start spinning after initial delay
|
|
239
|
+
_async.current = window.setTimeout(stepDownEvent, initialStepDelay);
|
|
240
|
+
},
|
|
241
|
+
subSlot(slot, 'decPressStart'),
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
let cancelContextMenu = (e: Event) => {
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
let { addGlobalListener, removeAllGlobalListeners } = useGlobalListeners(
|
|
249
|
+
subSlot(slot, 'globalListeners'),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
// Tracks in touch if the press end event was preceded by a press up.
|
|
253
|
+
// If it wasn't, then we know the finger left the button while still in contact with the screen.
|
|
254
|
+
// This means that the user is trying to scroll or interact in some way that shouldn't trigger
|
|
255
|
+
// an increment or decrement.
|
|
256
|
+
let isUp = useRef(false, subSlot(slot, 'isUp'));
|
|
257
|
+
|
|
258
|
+
let [isIncrementPressed, setIsIncrementPressed] = useState<'touch' | 'mouse' | null>(
|
|
259
|
+
null,
|
|
260
|
+
subSlot(slot, 'incPressed'),
|
|
261
|
+
);
|
|
262
|
+
useEffect(
|
|
263
|
+
() => {
|
|
264
|
+
if (isIncrementPressed === 'touch') {
|
|
265
|
+
onIncrementPressStartEvent(600);
|
|
266
|
+
} else if (isIncrementPressed) {
|
|
267
|
+
onIncrementPressStartEvent(400);
|
|
268
|
+
} else if (!isIncrementPressed) {
|
|
269
|
+
clearAsyncEvent();
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
[isIncrementPressed],
|
|
273
|
+
subSlot(slot, 'incPressedFx'),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
let [isDecrementPressed, setIsDecrementPressed] = useState<'touch' | 'mouse' | null>(
|
|
277
|
+
null,
|
|
278
|
+
subSlot(slot, 'decPressed'),
|
|
279
|
+
);
|
|
280
|
+
useEffect(
|
|
281
|
+
() => {
|
|
282
|
+
if (isDecrementPressed === 'touch') {
|
|
283
|
+
onDecrementPressStartEvent(600);
|
|
284
|
+
} else if (isDecrementPressed) {
|
|
285
|
+
onDecrementPressStartEvent(400);
|
|
286
|
+
} else if (!isDecrementPressed) {
|
|
287
|
+
clearAsyncEvent();
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
[isDecrementPressed],
|
|
291
|
+
subSlot(slot, 'decPressedFx'),
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
spinButtonProps: {
|
|
296
|
+
role: 'spinbutton',
|
|
297
|
+
'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,
|
|
298
|
+
'aria-valuetext': ariaTextValue,
|
|
299
|
+
'aria-valuemin': minValue,
|
|
300
|
+
'aria-valuemax': maxValue,
|
|
301
|
+
'aria-disabled': isDisabled || undefined,
|
|
302
|
+
'aria-readonly': isReadOnly || undefined,
|
|
303
|
+
'aria-required': isRequired || undefined,
|
|
304
|
+
onKeyDown,
|
|
305
|
+
onFocus,
|
|
306
|
+
onBlur,
|
|
307
|
+
},
|
|
308
|
+
incrementButtonProps: {
|
|
309
|
+
onPressStart: (e) => {
|
|
310
|
+
clearAsync();
|
|
311
|
+
if (e.pointerType !== 'touch') {
|
|
312
|
+
onIncrement?.();
|
|
313
|
+
setIsIncrementPressed('mouse');
|
|
314
|
+
} else {
|
|
315
|
+
addGlobalListener(window, 'pointercancel', onPointerCancel, { capture: true });
|
|
316
|
+
isUp.current = false;
|
|
317
|
+
// For touch users, don't trigger a decrement on press start, we'll wait for the press end to trigger it if
|
|
318
|
+
// the control isn't spinning.
|
|
319
|
+
setIsIncrementPressed('touch');
|
|
320
|
+
}
|
|
321
|
+
addGlobalListener(window, 'contextmenu', cancelContextMenu);
|
|
322
|
+
},
|
|
323
|
+
onPressUp: (e) => {
|
|
324
|
+
clearAsync();
|
|
325
|
+
if (e.pointerType === 'touch') {
|
|
326
|
+
isUp.current = true;
|
|
327
|
+
}
|
|
328
|
+
removeAllGlobalListeners();
|
|
329
|
+
setIsIncrementPressed(null);
|
|
330
|
+
},
|
|
331
|
+
onPressEnd: (e) => {
|
|
332
|
+
clearAsync();
|
|
333
|
+
if (e.pointerType === 'touch') {
|
|
334
|
+
if (!isSpinning.current && isUp.current) {
|
|
335
|
+
onIncrement?.();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
isUp.current = false;
|
|
339
|
+
setIsIncrementPressed(null);
|
|
340
|
+
},
|
|
341
|
+
onFocus,
|
|
342
|
+
onBlur,
|
|
343
|
+
},
|
|
344
|
+
decrementButtonProps: {
|
|
345
|
+
onPressStart: (e) => {
|
|
346
|
+
clearAsync();
|
|
347
|
+
if (e.pointerType !== 'touch') {
|
|
348
|
+
onDecrement?.();
|
|
349
|
+
setIsDecrementPressed('mouse');
|
|
350
|
+
} else {
|
|
351
|
+
addGlobalListener(window, 'pointercancel', onPointerCancel, { capture: true });
|
|
352
|
+
isUp.current = false;
|
|
353
|
+
// For touch users, don't trigger a decrement on press start, we'll wait for the press end to trigger it if
|
|
354
|
+
// the control isn't spinning.
|
|
355
|
+
setIsDecrementPressed('touch');
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
onPressUp: (e) => {
|
|
359
|
+
clearAsync();
|
|
360
|
+
if (e.pointerType === 'touch') {
|
|
361
|
+
isUp.current = true;
|
|
362
|
+
}
|
|
363
|
+
removeAllGlobalListeners();
|
|
364
|
+
setIsDecrementPressed(null);
|
|
365
|
+
},
|
|
366
|
+
onPressEnd: (e) => {
|
|
367
|
+
clearAsync();
|
|
368
|
+
if (e.pointerType === 'touch') {
|
|
369
|
+
if (!isSpinning.current && isUp.current) {
|
|
370
|
+
onDecrement?.();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
isUp.current = false;
|
|
374
|
+
setIsDecrementPressed(null);
|
|
375
|
+
},
|
|
376
|
+
onFocus,
|
|
377
|
+
onBlur,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Ported from react-stately (source: .react-spectrum/packages/react-stately/src/checkbox/useCheckboxGroupState.ts).
|
|
2
|
+
// octane adaptations: public-hook slot threading (splitSlot/subSlot) per the binding
|
|
3
|
+
// convention. The public value-level `onChange` callback is unchanged (the onInput rule
|
|
4
|
+
// applies only to DOM wiring).
|
|
5
|
+
import type {
|
|
6
|
+
HelpTextProps,
|
|
7
|
+
InputBase,
|
|
8
|
+
InputDOMProps,
|
|
9
|
+
LabelableProps,
|
|
10
|
+
Validation,
|
|
11
|
+
ValidationResult,
|
|
12
|
+
ValidationState,
|
|
13
|
+
ValueBase,
|
|
14
|
+
} from '@react-types/shared';
|
|
15
|
+
import { useRef, useState } from 'octane';
|
|
16
|
+
|
|
17
|
+
import { S, splitSlot, subSlot } from '../../internal';
|
|
18
|
+
import {
|
|
19
|
+
FormValidationState,
|
|
20
|
+
mergeValidation,
|
|
21
|
+
useFormValidationState,
|
|
22
|
+
} from '../form/useFormValidationState';
|
|
23
|
+
import { useControlledState } from '../utils/useControlledState';
|
|
24
|
+
|
|
25
|
+
export interface CheckboxGroupProps
|
|
26
|
+
extends
|
|
27
|
+
ValueBase<string[]>,
|
|
28
|
+
Pick<InputDOMProps, 'name'>,
|
|
29
|
+
InputBase,
|
|
30
|
+
LabelableProps,
|
|
31
|
+
HelpTextProps,
|
|
32
|
+
Validation<string[]> {}
|
|
33
|
+
|
|
34
|
+
export interface CheckboxGroupState extends FormValidationState {
|
|
35
|
+
/** Current selected values. */
|
|
36
|
+
readonly value: readonly string[];
|
|
37
|
+
/** Default selected values. */
|
|
38
|
+
readonly defaultValue: readonly string[];
|
|
39
|
+
|
|
40
|
+
/** Whether the checkbox group is disabled. */
|
|
41
|
+
readonly isDisabled: boolean;
|
|
42
|
+
|
|
43
|
+
/** Whether the checkbox group is read only. */
|
|
44
|
+
readonly isReadOnly: boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The current validation state of the checkbox group.
|
|
48
|
+
*
|
|
49
|
+
* @deprecated Use `isInvalid` instead.
|
|
50
|
+
*/
|
|
51
|
+
readonly validationState: ValidationState | null;
|
|
52
|
+
|
|
53
|
+
/** Whether the checkbox group is invalid. */
|
|
54
|
+
readonly isInvalid: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Whether the checkboxes in the group are required.
|
|
58
|
+
* This changes to false once at least one item is selected.
|
|
59
|
+
*/
|
|
60
|
+
readonly isRequired: boolean;
|
|
61
|
+
|
|
62
|
+
/** Returns whether the given value is selected. */
|
|
63
|
+
isSelected(value: string): boolean;
|
|
64
|
+
|
|
65
|
+
/** Sets the selected values. */
|
|
66
|
+
setValue(value: string[]): void;
|
|
67
|
+
|
|
68
|
+
/** Adds a value to the set of selected values. */
|
|
69
|
+
addValue(value: string): void;
|
|
70
|
+
|
|
71
|
+
/** Removes a value from the set of selected values. */
|
|
72
|
+
removeValue(value: string): void;
|
|
73
|
+
|
|
74
|
+
/** Toggles a value in the set of selected values. */
|
|
75
|
+
toggleValue(value: string): void;
|
|
76
|
+
|
|
77
|
+
/** Sets whether one of the checkboxes is invalid. */
|
|
78
|
+
setInvalid(value: string, validation: ValidationResult): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Provides state management for a checkbox group component. Provides a name for the group,
|
|
83
|
+
* and manages selection and focus state.
|
|
84
|
+
*/
|
|
85
|
+
export function useCheckboxGroupState(props?: CheckboxGroupProps): CheckboxGroupState;
|
|
86
|
+
// Slot-threading form: sibling ported hooks pass their derived sub-slot as the trailing arg.
|
|
87
|
+
export function useCheckboxGroupState(
|
|
88
|
+
props: CheckboxGroupProps | undefined,
|
|
89
|
+
slot: symbol | undefined,
|
|
90
|
+
): CheckboxGroupState;
|
|
91
|
+
export function useCheckboxGroupState(...args: any[]): CheckboxGroupState {
|
|
92
|
+
const [user, slotArg] = splitSlot(args);
|
|
93
|
+
const slot = slotArg ?? S('useCheckboxGroupState');
|
|
94
|
+
const props = (user[0] as CheckboxGroupProps | undefined) ?? {};
|
|
95
|
+
|
|
96
|
+
let [selectedValues, setValue] = useControlledState(
|
|
97
|
+
props.value,
|
|
98
|
+
props.defaultValue || [],
|
|
99
|
+
props.onChange,
|
|
100
|
+
subSlot(slot, 'value'),
|
|
101
|
+
);
|
|
102
|
+
let [initialValues] = useState(selectedValues, subSlot(slot, 'initial'));
|
|
103
|
+
let isRequired = !!props.isRequired && selectedValues.length === 0;
|
|
104
|
+
|
|
105
|
+
let invalidValues = useRef(new Map<string, ValidationResult>(), subSlot(slot, 'invalid'));
|
|
106
|
+
let validation = useFormValidationState(
|
|
107
|
+
{
|
|
108
|
+
...props,
|
|
109
|
+
value: selectedValues,
|
|
110
|
+
},
|
|
111
|
+
subSlot(slot, 'validation'),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
let isInvalid = validation.displayValidation.isInvalid;
|
|
115
|
+
const state: CheckboxGroupState = {
|
|
116
|
+
...validation,
|
|
117
|
+
value: selectedValues,
|
|
118
|
+
defaultValue: props.defaultValue ?? initialValues,
|
|
119
|
+
setValue(value) {
|
|
120
|
+
if (props.isReadOnly || props.isDisabled) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
setValue(value);
|
|
125
|
+
},
|
|
126
|
+
isDisabled: props.isDisabled || false,
|
|
127
|
+
isReadOnly: props.isReadOnly || false,
|
|
128
|
+
isSelected(value) {
|
|
129
|
+
return selectedValues.includes(value);
|
|
130
|
+
},
|
|
131
|
+
addValue(value) {
|
|
132
|
+
if (props.isReadOnly || props.isDisabled) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
setValue((selectedValues) => {
|
|
136
|
+
if (!selectedValues.includes(value)) {
|
|
137
|
+
return selectedValues.concat(value);
|
|
138
|
+
}
|
|
139
|
+
return selectedValues;
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
removeValue(value) {
|
|
143
|
+
if (props.isReadOnly || props.isDisabled) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (selectedValues.includes(value)) {
|
|
147
|
+
setValue(selectedValues.filter((existingValue) => existingValue !== value));
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
toggleValue(value) {
|
|
151
|
+
if (props.isReadOnly || props.isDisabled) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (selectedValues.includes(value)) {
|
|
155
|
+
setValue(selectedValues.filter((existingValue) => existingValue !== value));
|
|
156
|
+
} else {
|
|
157
|
+
setValue(selectedValues.concat(value));
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
setInvalid(value, v) {
|
|
161
|
+
let s = new Map(invalidValues.current);
|
|
162
|
+
if (v.isInvalid) {
|
|
163
|
+
s.set(value, v);
|
|
164
|
+
} else {
|
|
165
|
+
s.delete(value);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
invalidValues.current = s;
|
|
169
|
+
validation.updateValidation(mergeValidation(...s.values()));
|
|
170
|
+
},
|
|
171
|
+
validationState: props.validationState ?? (isInvalid ? 'invalid' : null),
|
|
172
|
+
isInvalid,
|
|
173
|
+
isRequired,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
return state;
|
|
177
|
+
}
|