@primer/components 0.0.0-2021111171525 → 0.0.0-20211111716
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/CHANGELOG.md +940 -41
- package/README.md +16 -16
- package/codemods/__tests__/deprecateUtilityComponents.js +200 -0
- package/codemods/__tests__/removeSystemProps.js +225 -0
- package/codemods/deprecateUtilityComponents.js +111 -0
- package/codemods/lib/modifyProps.js +9 -7
- package/codemods/lib/prettify.js +1 -1
- package/codemods/lib/replaceImportSource.js +5 -5
- package/codemods/removeSystemProps.js +312 -0
- package/dist/browser.esm.js +1267 -853
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +1304 -890
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Divider.d.ts +9 -0
- package/lib/ActionList/Divider.js +40 -0
- package/lib/ActionList/Group.d.ts +28 -0
- package/lib/ActionList/Group.js +35 -0
- package/lib/ActionList/Header.d.ts +29 -0
- package/lib/ActionList/Header.js +51 -0
- package/lib/ActionList/Item.d.ts +98 -0
- package/lib/ActionList/Item.js +276 -0
- package/lib/ActionList/List.d.ts +88 -0
- package/lib/ActionList/List.js +199 -0
- package/lib/ActionList/index.d.ts +17 -0
- package/lib/ActionList/index.js +29 -0
- package/lib/ActionList2/Description.d.ts +12 -0
- package/lib/ActionList2/Description.js +57 -0
- package/lib/ActionList2/Divider.d.ts +5 -0
- package/lib/ActionList2/Divider.js +35 -0
- package/lib/ActionList2/Group.d.ts +37 -0
- package/lib/ActionList2/Group.js +106 -0
- package/lib/ActionList2/Item.d.ts +63 -0
- package/lib/ActionList2/Item.js +244 -0
- package/lib/ActionList2/LinkItem.d.ts +17 -0
- package/lib/ActionList2/LinkItem.js +57 -0
- package/lib/ActionList2/List.d.ts +26 -0
- package/lib/ActionList2/List.js +58 -0
- package/lib/ActionList2/Selection.d.ts +5 -0
- package/lib/ActionList2/Selection.js +86 -0
- package/lib/ActionList2/Visuals.d.ts +9 -0
- package/lib/ActionList2/Visuals.js +90 -0
- package/lib/ActionList2/index.d.ts +36 -0
- package/lib/ActionList2/index.js +47 -0
- package/lib/ActionMenu.d.ts +40 -0
- package/lib/ActionMenu.js +103 -0
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +62 -0
- package/lib/AnchoredOverlay/AnchoredOverlay.js +124 -0
- package/lib/AnchoredOverlay/index.d.ts +2 -0
- package/lib/AnchoredOverlay/index.js +13 -0
- package/lib/Autocomplete/Autocomplete.d.ts +305 -0
- package/lib/Autocomplete/Autocomplete.js +145 -0
- package/lib/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib/Autocomplete/AutocompleteContext.js +11 -0
- package/lib/Autocomplete/AutocompleteInput.d.ts +293 -0
- package/lib/Autocomplete/AutocompleteInput.js +157 -0
- package/lib/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib/Autocomplete/AutocompleteMenu.js +224 -0
- package/lib/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib/Autocomplete/AutocompleteOverlay.js +80 -0
- package/lib/Autocomplete/index.d.ts +2 -0
- package/lib/Autocomplete/index.js +15 -0
- package/lib/Avatar.d.ts +14 -0
- package/lib/Avatar.js +1 -12
- package/lib/AvatarPair.d.ts +8 -0
- package/lib/AvatarPair.js +9 -16
- package/lib/AvatarStack.d.ts +8 -0
- package/lib/AvatarStack.js +12 -23
- package/lib/BaseStyles.d.ts +14 -0
- package/lib/BaseStyles.js +25 -31
- package/lib/BorderBox.d.ts +7 -0
- package/lib/BorderBox.js +5 -16
- package/lib/Box.d.ts +6 -0
- package/lib/Box.js +2 -15
- package/lib/BranchName.d.ts +5 -0
- package/lib/BranchName.js +1 -14
- package/lib/Breadcrumbs.d.ts +41 -0
- package/lib/Breadcrumbs.js +82 -0
- package/lib/Button/Button.d.ts +284 -0
- package/lib/Button/Button.js +3 -15
- package/lib/Button/ButtonBase.d.ts +9 -0
- package/lib/Button/ButtonBase.js +2 -25
- package/lib/Button/ButtonClose.d.ts +279 -0
- package/lib/Button/ButtonClose.js +9 -26
- package/lib/Button/ButtonDanger.d.ts +284 -0
- package/lib/Button/ButtonDanger.js +2 -14
- package/lib/Button/ButtonGroup.d.ts +4 -0
- package/lib/Button/ButtonGroup.js +2 -8
- package/lib/Button/ButtonInvisible.d.ts +284 -0
- package/lib/Button/ButtonInvisible.js +3 -15
- package/lib/Button/ButtonOutline.d.ts +284 -0
- package/lib/Button/ButtonOutline.js +2 -14
- package/lib/Button/ButtonPrimary.d.ts +284 -0
- package/lib/Button/ButtonPrimary.js +2 -14
- package/lib/Button/ButtonStyles.d.ts +2 -0
- package/lib/Button/ButtonTableList.d.ts +5 -0
- package/lib/Button/ButtonTableList.js +1 -15
- package/lib/Button/index.d.ts +16 -0
- package/lib/Button/index.js +9 -59
- package/lib/Caret.d.ts +21 -0
- package/lib/Caret.js +14 -17
- package/lib/Checkbox.d.ts +29 -0
- package/lib/Checkbox.js +64 -0
- package/lib/CircleBadge.d.ts +24 -0
- package/lib/CircleBadge.js +2 -20
- package/lib/CircleOcticon.d.ts +392 -0
- package/lib/CircleOcticon.js +9 -18
- package/lib/CounterLabel.d.ts +7 -0
- package/lib/CounterLabel.js +3 -17
- package/lib/Details.d.ts +5 -0
- package/lib/Details.js +1 -11
- package/lib/Dialog/ConfirmationDialog.d.ts +44 -0
- package/lib/Dialog/ConfirmationDialog.js +191 -0
- package/lib/Dialog/Dialog.d.ts +163 -0
- package/lib/Dialog/Dialog.js +311 -0
- package/lib/Dialog.d.ts +406 -0
- package/lib/Dialog.js +34 -49
- package/lib/Dropdown.d.ts +1113 -0
- package/lib/Dropdown.js +45 -60
- package/lib/DropdownMenu/DropdownButton.d.ts +280 -0
- package/lib/DropdownMenu/DropdownButton.js +33 -0
- package/lib/DropdownMenu/DropdownMenu.d.ts +43 -0
- package/lib/DropdownMenu/DropdownMenu.js +94 -0
- package/lib/DropdownMenu/index.d.ts +4 -0
- package/lib/DropdownMenu/index.js +21 -0
- package/lib/DropdownStyles.d.ts +3 -0
- package/lib/DropdownStyles.js +6 -6
- package/lib/FilterList.d.ts +283 -0
- package/lib/FilterList.js +2 -30
- package/lib/FilteredActionList/FilteredActionList.d.ts +16 -0
- package/lib/FilteredActionList/FilteredActionList.js +137 -0
- package/lib/FilteredActionList/index.d.ts +2 -0
- package/lib/FilteredActionList/index.js +13 -0
- package/lib/FilteredSearch.d.ts +5 -0
- package/lib/FilteredSearch.js +1 -12
- package/lib/Flash.d.ts +8 -0
- package/lib/Flash.js +35 -14
- package/lib/Flex.d.ts +7 -0
- package/lib/Flex.js +3 -5
- package/lib/FormGroup.d.ts +11 -0
- package/lib/FormGroup.js +2 -22
- package/lib/Grid.d.ts +7 -0
- package/lib/Grid.js +4 -9
- package/lib/Header.d.ts +23 -0
- package/lib/Header.js +7 -37
- package/lib/Heading.d.ts +5 -0
- package/lib/Heading.js +1 -13
- package/lib/Label.d.ts +10 -0
- package/lib/Label.js +5 -19
- package/lib/LabelGroup.d.ts +5 -0
- package/lib/LabelGroup.js +1 -9
- package/lib/Link.d.ts +9 -0
- package/lib/Link.js +2 -30
- package/lib/NewButton/button-counter.d.ts +6 -0
- package/lib/NewButton/button-counter.js +31 -0
- package/lib/NewButton/button.d.ts +13 -0
- package/lib/NewButton/button.js +308 -0
- package/lib/NewButton/index.d.ts +14 -0
- package/lib/NewButton/index.js +15 -0
- package/lib/NewButton/types.d.ts +32 -0
- package/lib/{utils → NewButton}/types.js +0 -0
- package/lib/Overlay.d.ts +66 -0
- package/lib/Overlay.js +184 -0
- package/lib/Pagehead.d.ts +5 -0
- package/lib/Pagehead.js +1 -13
- package/lib/Pagination/Pagination.d.ts +24 -0
- package/lib/Pagination/Pagination.js +14 -29
- package/lib/Pagination/index.d.ts +3 -0
- package/lib/Pagination/model.d.ts +26 -0
- package/lib/Pagination/model.js +1 -1
- package/lib/PointerBox.d.ts +11 -0
- package/lib/PointerBox.js +4 -13
- package/lib/Popover.d.ts +20 -0
- package/lib/Popover.js +5 -29
- package/lib/Portal/Portal.d.ts +25 -0
- package/lib/Portal/Portal.js +101 -0
- package/lib/Portal/index.d.ts +4 -0
- package/lib/Portal/index.js +17 -0
- package/lib/Position.d.ts +34 -0
- package/lib/Position.js +46 -46
- package/lib/ProgressBar.d.ts +26 -0
- package/lib/ProgressBar.js +8 -27
- package/lib/SelectMenu/SelectMenu.d.ts +1670 -0
- package/lib/SelectMenu/SelectMenu.js +32 -44
- package/lib/SelectMenu/SelectMenuContext.d.ts +8 -0
- package/lib/SelectMenu/SelectMenuContext.js +1 -1
- package/lib/SelectMenu/SelectMenuDivider.d.ts +5 -0
- package/lib/SelectMenu/SelectMenuDivider.js +6 -14
- package/lib/SelectMenu/SelectMenuFilter.d.ts +9 -0
- package/lib/SelectMenu/SelectMenuFilter.js +13 -21
- package/lib/SelectMenu/SelectMenuFooter.d.ts +5 -0
- package/lib/SelectMenu/SelectMenuFooter.js +6 -14
- package/lib/SelectMenu/SelectMenuHeader.d.ts +10 -0
- package/lib/SelectMenu/SelectMenuHeader.js +4 -17
- package/lib/SelectMenu/SelectMenuItem.d.ts +14 -0
- package/lib/SelectMenu/SelectMenuItem.js +13 -21
- package/lib/SelectMenu/SelectMenuList.d.ts +5 -0
- package/lib/SelectMenu/SelectMenuList.js +6 -14
- package/lib/SelectMenu/SelectMenuLoadingAnimation.d.ts +7 -0
- package/lib/SelectMenu/SelectMenuLoadingAnimation.js +6 -17
- package/lib/SelectMenu/SelectMenuModal.d.ts +14 -0
- package/lib/SelectMenu/SelectMenuModal.js +11 -23
- package/lib/SelectMenu/SelectMenuTab.d.ts +13 -0
- package/lib/SelectMenu/SelectMenuTab.js +16 -26
- package/lib/SelectMenu/SelectMenuTabPanel.d.ts +12 -0
- package/lib/SelectMenu/SelectMenuTabPanel.js +14 -25
- package/lib/SelectMenu/SelectMenuTabs.d.ts +10 -0
- package/lib/SelectMenu/SelectMenuTabs.js +10 -17
- package/lib/SelectMenu/hooks/useKeyboardNav.d.ts +2 -0
- package/lib/SelectMenu/hooks/useKeyboardNav.js +2 -0
- package/lib/SelectMenu/index.d.ts +2 -0
- package/lib/SelectMenu/index.js +7 -5
- package/lib/SelectPanel/SelectPanel.d.ts +25 -0
- package/lib/SelectPanel/SelectPanel.js +147 -0
- package/lib/SelectPanel/index.d.ts +2 -0
- package/lib/SelectPanel/index.js +13 -0
- package/lib/SideNav.d.ts +34 -0
- package/lib/SideNav.js +23 -41
- package/lib/Spinner.d.ts +16 -0
- package/lib/Spinner.js +58 -0
- package/lib/StateLabel.d.ts +15 -0
- package/lib/StateLabel.js +53 -23
- package/lib/StyledOcticon.d.ts +11 -0
- package/lib/StyledOcticon.js +1 -15
- package/lib/SubNav.d.ts +26 -0
- package/lib/SubNav.js +27 -49
- package/lib/TabNav.d.ts +19 -0
- package/lib/TabNav.js +15 -37
- package/lib/Text.d.ts +6 -0
- package/lib/Text.js +0 -12
- package/lib/TextInput.d.ts +14 -0
- package/lib/TextInput.js +25 -76
- package/lib/TextInputWithTokens.d.ts +328 -0
- package/lib/TextInputWithTokens.js +318 -0
- package/lib/ThemeProvider.d.ts +26 -0
- package/lib/ThemeProvider.js +193 -0
- package/lib/Timeline.d.ts +33 -0
- package/lib/Timeline.js +34 -87
- package/lib/Token/AvatarToken.d.ts +7 -0
- package/lib/Token/AvatarToken.js +64 -0
- package/lib/Token/IssueLabelToken.d.ts +14 -0
- package/lib/Token/IssueLabelToken.js +144 -0
- package/lib/Token/Token.d.ts +15 -0
- package/lib/Token/Token.js +105 -0
- package/lib/Token/TokenBase.d.ts +31 -0
- package/lib/Token/TokenBase.js +104 -0
- package/lib/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib/Token/_RemoveTokenButton.js +90 -0
- package/lib/Token/_TokenTextContainer.d.ts +3 -0
- package/lib/Token/_TokenTextContainer.js +17 -0
- package/lib/Token/index.d.ts +3 -0
- package/lib/Token/index.js +31 -0
- package/lib/Tooltip.d.ts +17 -0
- package/lib/Tooltip.js +4 -21
- package/lib/Truncate.d.ts +10 -0
- package/lib/Truncate.js +2 -18
- package/lib/UnderlineNav.d.ts +24 -0
- package/lib/UnderlineNav.js +3 -29
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/behaviors/anchoredPosition.d.ts +89 -0
- package/lib/behaviors/anchoredPosition.js +316 -0
- package/lib/behaviors/focusTrap.d.ts +12 -0
- package/lib/behaviors/focusTrap.js +179 -0
- package/lib/behaviors/focusZone.d.ts +137 -0
- package/lib/behaviors/focusZone.js +578 -0
- package/lib/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib/behaviors/scrollIntoViewingArea.js +39 -0
- package/lib/constants.d.ts +20 -0
- package/lib/constants.js +11 -27
- package/lib/drafts.d.ts +8 -0
- package/lib/drafts.js +31 -0
- package/lib/hooks/index.d.ts +11 -0
- package/lib/hooks/index.js +61 -0
- package/lib/hooks/useAnchoredPosition.d.ts +20 -0
- package/lib/hooks/useAnchoredPosition.js +51 -0
- package/lib/hooks/useCombinedRefs.d.ts +10 -0
- package/lib/hooks/useCombinedRefs.js +47 -0
- package/lib/hooks/useDetails.d.ts +17 -0
- package/lib/hooks/useDialog.d.ts +16 -0
- package/lib/hooks/useDialog.js +21 -6
- package/lib/hooks/useFocusTrap.d.ts +32 -0
- package/lib/hooks/useFocusTrap.js +69 -0
- package/lib/hooks/useFocusZone.d.ts +23 -0
- package/lib/hooks/useFocusZone.js +53 -0
- package/lib/hooks/useOnEscapePress.d.ts +23 -0
- package/lib/hooks/useOnEscapePress.js +69 -0
- package/lib/hooks/useOnOutsideClick.d.ts +8 -0
- package/lib/hooks/useOnOutsideClick.js +90 -0
- package/lib/hooks/useOpenAndCloseFocus.d.ts +8 -0
- package/lib/hooks/useOpenAndCloseFocus.js +36 -0
- package/lib/hooks/useOverlay.d.ts +15 -0
- package/lib/hooks/useOverlay.js +43 -0
- package/lib/hooks/useProvidedRefOrCreate.d.ts +10 -0
- package/lib/hooks/useProvidedRefOrCreate.js +24 -0
- package/lib/hooks/useProvidedStateOrCreate.d.ts +10 -0
- package/lib/hooks/useProvidedStateOrCreate.js +27 -0
- package/lib/hooks/useRenderForcingRef.d.ts +8 -0
- package/lib/hooks/useRenderForcingRef.js +25 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -0
- package/lib/hooks/useResizeObserver.js +20 -0
- package/lib/hooks/useSafeTimeout.d.ts +12 -0
- package/lib/hooks/useSafeTimeout.js +38 -0
- package/lib/hooks/useScrollFlash.d.ts +6 -0
- package/lib/hooks/useScrollFlash.js +29 -0
- package/lib/index.d.ts +120 -0
- package/lib/index.js +191 -7
- package/lib/polyfills/eventListenerSignal.d.ts +6 -0
- package/lib/polyfills/eventListenerSignal.js +64 -0
- package/lib/sx.d.ts +14 -0
- package/lib/sx.js +8 -5
- package/lib/theme-preval.d.ts +49 -0
- package/lib/theme-preval.js +3119 -357
- package/lib/theme.d.ts +80 -0
- package/lib/theme.js +5 -8
- package/lib/utils/create-slots.d.ts +17 -0
- package/lib/utils/create-slots.js +105 -0
- package/lib/utils/deprecate.d.ts +18 -0
- package/lib/utils/deprecate.js +6 -5
- package/lib/utils/isNumeric.d.ts +1 -0
- package/lib/utils/isNumeric.js +1 -0
- package/lib/utils/iterateFocusableElements.d.ts +42 -0
- package/lib/utils/iterateFocusableElements.js +113 -0
- package/lib/utils/ssr.d.ts +1 -0
- package/lib/utils/ssr.js +19 -0
- package/lib/utils/test-deprecations.d.ts +1 -0
- package/lib/utils/test-deprecations.js +2 -1
- package/lib/utils/test-helpers.d.ts +0 -0
- package/lib/utils/test-helpers.js +9 -0
- package/lib/utils/test-matchers.d.ts +1 -0
- package/lib/utils/test-matchers.js +6 -50
- package/lib/utils/testing.d.ts +545 -0
- package/lib/utils/testing.js +65 -49
- package/lib/utils/theme.d.ts +9 -0
- package/lib/utils/theme.js +68 -0
- package/lib/utils/types/AriaRole.d.ts +1 -0
- package/lib/utils/types/AriaRole.js +1 -0
- package/lib/utils/types/ComponentProps.d.ts +9 -0
- package/lib/utils/types/ComponentProps.js +1 -0
- package/lib/utils/types/Flatten.d.ts +4 -0
- package/lib/utils/types/Flatten.js +1 -0
- package/lib/utils/types/KeyPaths.d.ts +3 -0
- package/lib/utils/types/KeyPaths.js +1 -0
- package/lib/utils/types/MandateProps.d.ts +3 -0
- package/lib/utils/types/MandateProps.js +1 -0
- package/lib/utils/types/Merge.d.ts +19 -0
- package/lib/utils/types/Merge.js +1 -0
- package/lib/utils/types/index.d.ts +5 -0
- package/lib/utils/types/index.js +70 -0
- package/lib/utils/uniqueId.d.ts +1 -0
- package/lib/utils/uniqueId.js +12 -0
- package/lib/utils/use-force-update.d.ts +1 -0
- package/lib/utils/use-force-update.js +19 -0
- package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
- package/lib/utils/userAgent.d.ts +1 -0
- package/lib/utils/userAgent.js +15 -0
- package/lib-esm/ActionList/Divider.d.ts +9 -0
- package/lib-esm/ActionList/Divider.js +23 -0
- package/lib-esm/ActionList/Group.d.ts +28 -0
- package/lib-esm/ActionList/Group.js +24 -0
- package/lib-esm/ActionList/Header.d.ts +29 -0
- package/lib-esm/ActionList/Header.js +33 -0
- package/lib-esm/ActionList/Item.d.ts +98 -0
- package/lib-esm/ActionList/Item.js +241 -0
- package/lib-esm/ActionList/List.d.ts +88 -0
- package/lib-esm/ActionList/List.js +181 -0
- package/lib-esm/ActionList/index.d.ts +17 -0
- package/lib-esm/ActionList/index.js +18 -0
- package/lib-esm/ActionList2/Description.d.ts +12 -0
- package/lib-esm/ActionList2/Description.js +41 -0
- package/lib-esm/ActionList2/Divider.d.ts +5 -0
- package/lib-esm/ActionList2/Divider.js +23 -0
- package/lib-esm/ActionList2/Group.d.ts +37 -0
- package/lib-esm/ActionList2/Group.js +87 -0
- package/lib-esm/ActionList2/Item.d.ts +63 -0
- package/lib-esm/ActionList2/Item.js +210 -0
- package/lib-esm/ActionList2/LinkItem.d.ts +17 -0
- package/lib-esm/ActionList2/LinkItem.js +43 -0
- package/lib-esm/ActionList2/List.d.ts +26 -0
- package/lib-esm/ActionList2/List.js +36 -0
- package/lib-esm/ActionList2/Selection.d.ts +5 -0
- package/lib-esm/ActionList2/Selection.js +68 -0
- package/lib-esm/ActionList2/Visuals.d.ts +9 -0
- package/lib-esm/ActionList2/Visuals.js +68 -0
- package/lib-esm/ActionList2/index.d.ts +36 -0
- package/lib-esm/ActionList2/index.js +33 -0
- package/lib-esm/ActionMenu.d.ts +40 -0
- package/lib-esm/ActionMenu.js +82 -0
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +62 -0
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.js +104 -0
- package/lib-esm/AnchoredOverlay/index.d.ts +2 -0
- package/lib-esm/AnchoredOverlay/index.js +1 -0
- package/lib-esm/Autocomplete/Autocomplete.d.ts +305 -0
- package/lib-esm/Autocomplete/Autocomplete.js +123 -0
- package/lib-esm/Autocomplete/AutocompleteContext.d.ts +17 -0
- package/lib-esm/Autocomplete/AutocompleteContext.js +2 -0
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +293 -0
- package/lib-esm/Autocomplete/AutocompleteInput.js +138 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.d.ts +72 -0
- package/lib-esm/Autocomplete/AutocompleteMenu.js +205 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.d.ts +20 -0
- package/lib-esm/Autocomplete/AutocompleteOverlay.js +62 -0
- package/lib-esm/Autocomplete/index.d.ts +2 -0
- package/lib-esm/Autocomplete/index.js +1 -0
- package/lib-esm/Avatar.d.ts +14 -0
- package/lib-esm/Avatar.js +2 -11
- package/lib-esm/AvatarPair.d.ts +8 -0
- package/lib-esm/AvatarPair.js +8 -14
- package/lib-esm/AvatarStack.d.ts +8 -0
- package/lib-esm/AvatarStack.js +12 -21
- package/lib-esm/BaseStyles.d.ts +14 -0
- package/lib-esm/BaseStyles.js +23 -26
- package/lib-esm/BorderBox.d.ts +7 -0
- package/lib-esm/BorderBox.js +6 -12
- package/lib-esm/Box.d.ts +6 -0
- package/lib-esm/Box.js +2 -13
- package/lib-esm/BranchName.d.ts +5 -0
- package/lib-esm/BranchName.js +2 -13
- package/lib-esm/Breadcrumbs.d.ts +41 -0
- package/lib-esm/Breadcrumbs.js +58 -0
- package/lib-esm/Button/Button.d.ts +284 -0
- package/lib-esm/Button/Button.js +3 -10
- package/lib-esm/Button/ButtonBase.d.ts +9 -0
- package/lib-esm/Button/ButtonBase.js +1 -19
- package/lib-esm/Button/ButtonClose.d.ts +279 -0
- package/lib-esm/Button/ButtonClose.js +5 -20
- package/lib-esm/Button/ButtonDanger.d.ts +284 -0
- package/lib-esm/Button/ButtonDanger.js +2 -9
- package/lib-esm/Button/ButtonGroup.d.ts +4 -0
- package/lib-esm/Button/ButtonGroup.js +2 -7
- package/lib-esm/Button/ButtonInvisible.d.ts +284 -0
- package/lib-esm/Button/ButtonInvisible.js +3 -10
- package/lib-esm/Button/ButtonOutline.d.ts +284 -0
- package/lib-esm/Button/ButtonOutline.js +2 -9
- package/lib-esm/Button/ButtonPrimary.d.ts +284 -0
- package/lib-esm/Button/ButtonPrimary.js +2 -9
- package/lib-esm/Button/ButtonStyles.d.ts +2 -0
- package/lib-esm/Button/ButtonTableList.d.ts +5 -0
- package/lib-esm/Button/ButtonTableList.js +2 -14
- package/lib-esm/Button/index.d.ts +16 -0
- package/lib-esm/Button/index.js +8 -8
- package/lib-esm/Caret.d.ts +21 -0
- package/lib-esm/Caret.js +13 -16
- package/lib-esm/Checkbox.d.ts +29 -0
- package/lib-esm/Checkbox.js +44 -0
- package/lib-esm/CircleBadge.d.ts +24 -0
- package/lib-esm/CircleBadge.js +3 -19
- package/lib-esm/CircleOcticon.d.ts +392 -0
- package/lib-esm/CircleOcticon.js +9 -15
- package/lib-esm/CounterLabel.d.ts +7 -0
- package/lib-esm/CounterLabel.js +4 -16
- package/lib-esm/Details.d.ts +5 -0
- package/lib-esm/Details.js +1 -9
- package/lib-esm/Dialog/ConfirmationDialog.d.ts +44 -0
- package/lib-esm/Dialog/ConfirmationDialog.js +169 -0
- package/lib-esm/Dialog/Dialog.d.ts +163 -0
- package/lib-esm/Dialog/Dialog.js +275 -0
- package/lib-esm/Dialog.d.ts +406 -0
- package/lib-esm/Dialog.js +31 -46
- package/lib-esm/Dropdown.d.ts +1113 -0
- package/lib-esm/Dropdown.js +38 -58
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +280 -0
- package/lib-esm/DropdownMenu/DropdownButton.js +18 -0
- package/lib-esm/DropdownMenu/DropdownMenu.d.ts +43 -0
- package/lib-esm/DropdownMenu/DropdownMenu.js +77 -0
- package/lib-esm/DropdownMenu/index.d.ts +4 -0
- package/lib-esm/DropdownMenu/index.js +2 -0
- package/lib-esm/DropdownStyles.d.ts +3 -0
- package/lib-esm/DropdownStyles.js +6 -6
- package/lib-esm/FilterList.d.ts +283 -0
- package/lib-esm/FilterList.js +3 -29
- package/lib-esm/FilteredActionList/FilteredActionList.d.ts +16 -0
- package/lib-esm/FilteredActionList/FilteredActionList.js +109 -0
- package/lib-esm/FilteredActionList/index.d.ts +2 -0
- package/lib-esm/FilteredActionList/index.js +1 -0
- package/lib-esm/FilteredSearch.d.ts +5 -0
- package/lib-esm/FilteredSearch.js +2 -11
- package/lib-esm/Flash.d.ts +8 -0
- package/lib-esm/Flash.js +36 -13
- package/lib-esm/Flex.d.ts +7 -0
- package/lib-esm/Flex.js +4 -4
- package/lib-esm/FormGroup.d.ts +11 -0
- package/lib-esm/FormGroup.js +3 -20
- package/lib-esm/Grid.d.ts +7 -0
- package/lib-esm/Grid.js +5 -7
- package/lib-esm/Header.d.ts +23 -0
- package/lib-esm/Header.js +6 -34
- package/lib-esm/Heading.d.ts +5 -0
- package/lib-esm/Heading.js +2 -12
- package/lib-esm/Label.d.ts +10 -0
- package/lib-esm/Label.js +3 -15
- package/lib-esm/LabelGroup.d.ts +5 -0
- package/lib-esm/LabelGroup.js +2 -9
- package/lib-esm/Link.d.ts +9 -0
- package/lib-esm/Link.js +2 -28
- package/lib-esm/NewButton/button-counter.d.ts +6 -0
- package/lib-esm/NewButton/button-counter.js +18 -0
- package/lib-esm/NewButton/button.d.ts +13 -0
- package/lib-esm/NewButton/button.js +287 -0
- package/lib-esm/NewButton/index.d.ts +14 -0
- package/lib-esm/NewButton/index.js +5 -0
- package/lib-esm/NewButton/types.d.ts +32 -0
- package/lib-esm/NewButton/types.js +1 -0
- package/lib-esm/Overlay.d.ts +66 -0
- package/lib-esm/Overlay.js +160 -0
- package/lib-esm/Pagehead.d.ts +5 -0
- package/lib-esm/Pagehead.js +2 -12
- package/lib-esm/Pagination/Pagination.d.ts +24 -0
- package/lib-esm/Pagination/Pagination.js +15 -28
- package/lib-esm/Pagination/index.d.ts +3 -0
- package/lib-esm/Pagination/model.d.ts +26 -0
- package/lib-esm/Pagination/model.js +1 -1
- package/lib-esm/PointerBox.d.ts +11 -0
- package/lib-esm/PointerBox.js +4 -11
- package/lib-esm/Popover.d.ts +20 -0
- package/lib-esm/Popover.js +5 -27
- package/lib-esm/Portal/Portal.d.ts +25 -0
- package/lib-esm/Portal/Portal.js +83 -0
- package/lib-esm/Portal/index.d.ts +4 -0
- package/lib-esm/Portal/index.js +3 -0
- package/lib-esm/Position.d.ts +34 -0
- package/lib-esm/Position.js +42 -37
- package/lib-esm/ProgressBar.d.ts +26 -0
- package/lib-esm/ProgressBar.js +9 -25
- package/lib-esm/SelectMenu/SelectMenu.d.ts +1670 -0
- package/lib-esm/SelectMenu/SelectMenu.js +27 -38
- package/lib-esm/SelectMenu/SelectMenuContext.d.ts +8 -0
- package/lib-esm/SelectMenu/SelectMenuContext.js +1 -1
- package/lib-esm/SelectMenu/SelectMenuDivider.d.ts +5 -0
- package/lib-esm/SelectMenu/SelectMenuDivider.js +4 -11
- package/lib-esm/SelectMenu/SelectMenuFilter.d.ts +9 -0
- package/lib-esm/SelectMenu/SelectMenuFilter.js +13 -19
- package/lib-esm/SelectMenu/SelectMenuFooter.d.ts +5 -0
- package/lib-esm/SelectMenu/SelectMenuFooter.js +4 -11
- package/lib-esm/SelectMenu/SelectMenuHeader.d.ts +10 -0
- package/lib-esm/SelectMenu/SelectMenuHeader.js +7 -18
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +14 -0
- package/lib-esm/SelectMenu/SelectMenuItem.js +11 -17
- package/lib-esm/SelectMenu/SelectMenuList.d.ts +5 -0
- package/lib-esm/SelectMenu/SelectMenuList.js +4 -11
- package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.d.ts +7 -0
- package/lib-esm/SelectMenu/SelectMenuLoadingAnimation.js +7 -13
- package/lib-esm/SelectMenu/SelectMenuModal.d.ts +14 -0
- package/lib-esm/SelectMenu/SelectMenuModal.js +10 -20
- package/lib-esm/SelectMenu/SelectMenuTab.d.ts +13 -0
- package/lib-esm/SelectMenu/SelectMenuTab.js +13 -21
- package/lib-esm/SelectMenu/SelectMenuTabPanel.d.ts +12 -0
- package/lib-esm/SelectMenu/SelectMenuTabPanel.js +9 -19
- package/lib-esm/SelectMenu/SelectMenuTabs.d.ts +10 -0
- package/lib-esm/SelectMenu/SelectMenuTabs.js +8 -15
- package/lib-esm/SelectMenu/hooks/useKeyboardNav.d.ts +2 -0
- package/lib-esm/SelectMenu/hooks/useKeyboardNav.js +2 -0
- package/lib-esm/SelectMenu/index.d.ts +2 -0
- package/lib-esm/SelectMenu/index.js +1 -2
- package/lib-esm/SelectPanel/SelectPanel.d.ts +25 -0
- package/lib-esm/SelectPanel/SelectPanel.js +127 -0
- package/lib-esm/SelectPanel/index.d.ts +2 -0
- package/lib-esm/SelectPanel/index.js +1 -0
- package/lib-esm/SideNav.d.ts +34 -0
- package/lib-esm/SideNav.js +20 -36
- package/lib-esm/Spinner.d.ts +16 -0
- package/lib-esm/Spinner.js +45 -0
- package/lib-esm/StateLabel.d.ts +15 -0
- package/lib-esm/StateLabel.js +55 -23
- package/lib-esm/StyledOcticon.d.ts +11 -0
- package/lib-esm/StyledOcticon.js +1 -12
- package/lib-esm/SubNav.d.ts +26 -0
- package/lib-esm/SubNav.js +24 -48
- package/lib-esm/TabNav.d.ts +19 -0
- package/lib-esm/TabNav.js +13 -33
- package/lib-esm/Text.d.ts +6 -0
- package/lib-esm/Text.js +0 -10
- package/lib-esm/TextInput.d.ts +14 -0
- package/lib-esm/TextInput.js +24 -62
- package/lib-esm/TextInputWithTokens.d.ts +328 -0
- package/lib-esm/TextInputWithTokens.js +291 -0
- package/lib-esm/ThemeProvider.d.ts +26 -0
- package/lib-esm/ThemeProvider.js +161 -0
- package/lib-esm/Timeline.d.ts +33 -0
- package/lib-esm/Timeline.js +26 -81
- package/lib-esm/Token/AvatarToken.d.ts +7 -0
- package/lib-esm/Token/AvatarToken.js +43 -0
- package/lib-esm/Token/IssueLabelToken.d.ts +14 -0
- package/lib-esm/Token/IssueLabelToken.js +124 -0
- package/lib-esm/Token/Token.d.ts +15 -0
- package/lib-esm/Token/Token.js +84 -0
- package/lib-esm/Token/TokenBase.d.ts +31 -0
- package/lib-esm/Token/TokenBase.js +83 -0
- package/lib-esm/Token/_RemoveTokenButton.d.ts +12 -0
- package/lib-esm/Token/_RemoveTokenButton.js +69 -0
- package/lib-esm/Token/_TokenTextContainer.d.ts +3 -0
- package/lib-esm/Token/_TokenTextContainer.js +6 -0
- package/lib-esm/Token/index.d.ts +3 -0
- package/lib-esm/Token/index.js +3 -0
- package/lib-esm/Tooltip.d.ts +17 -0
- package/lib-esm/Tooltip.js +4 -19
- package/lib-esm/Truncate.d.ts +10 -0
- package/lib-esm/Truncate.js +2 -15
- package/lib-esm/UnderlineNav.d.ts +24 -0
- package/lib-esm/UnderlineNav.js +5 -28
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/behaviors/anchoredPosition.d.ts +89 -0
- package/lib-esm/behaviors/anchoredPosition.js +309 -0
- package/lib-esm/behaviors/focusTrap.d.ts +12 -0
- package/lib-esm/behaviors/focusTrap.js +170 -0
- package/lib-esm/behaviors/focusZone.d.ts +137 -0
- package/lib-esm/behaviors/focusZone.js +560 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +1 -0
- package/lib-esm/behaviors/scrollIntoViewingArea.js +30 -0
- package/lib-esm/constants.d.ts +20 -0
- package/lib-esm/constants.js +9 -23
- package/lib-esm/drafts.d.ts +8 -0
- package/lib-esm/drafts.js +9 -0
- package/lib-esm/hooks/index.d.ts +11 -0
- package/lib-esm/hooks/index.js +7 -0
- package/lib-esm/hooks/useAnchoredPosition.d.ts +20 -0
- package/lib-esm/hooks/useAnchoredPosition.js +35 -0
- package/lib-esm/hooks/useCombinedRefs.d.ts +10 -0
- package/lib-esm/hooks/useCombinedRefs.js +37 -0
- package/lib-esm/hooks/useDetails.d.ts +17 -0
- package/lib-esm/hooks/useDialog.d.ts +16 -0
- package/lib-esm/hooks/useDialog.js +21 -6
- package/lib-esm/hooks/useFocusTrap.d.ts +32 -0
- package/lib-esm/hooks/useFocusTrap.js +54 -0
- package/lib-esm/hooks/useFocusZone.d.ts +23 -0
- package/lib-esm/hooks/useFocusZone.js +37 -0
- package/lib-esm/hooks/useOnEscapePress.d.ts +23 -0
- package/lib-esm/hooks/useOnEscapePress.js +59 -0
- package/lib-esm/hooks/useOnOutsideClick.d.ts +8 -0
- package/lib-esm/hooks/useOnOutsideClick.js +79 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.d.ts +8 -0
- package/lib-esm/hooks/useOpenAndCloseFocus.js +27 -0
- package/lib-esm/hooks/useOverlay.d.ts +15 -0
- package/lib-esm/hooks/useOverlay.js +30 -0
- package/lib-esm/hooks/useProvidedRefOrCreate.d.ts +10 -0
- package/lib-esm/hooks/useProvidedRefOrCreate.js +14 -0
- package/lib-esm/hooks/useProvidedStateOrCreate.d.ts +10 -0
- package/lib-esm/hooks/useProvidedStateOrCreate.js +20 -0
- package/lib-esm/hooks/useRenderForcingRef.d.ts +8 -0
- package/lib-esm/hooks/useRenderForcingRef.js +18 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -0
- package/lib-esm/hooks/useResizeObserver.js +10 -0
- package/lib-esm/hooks/useSafeTimeout.d.ts +12 -0
- package/lib-esm/hooks/useSafeTimeout.js +31 -0
- package/lib-esm/hooks/useScrollFlash.d.ts +6 -0
- package/lib-esm/hooks/useScrollFlash.js +22 -0
- package/lib-esm/index.d.ts +120 -0
- package/lib-esm/index.js +29 -7
- package/lib-esm/polyfills/eventListenerSignal.d.ts +6 -0
- package/lib-esm/polyfills/eventListenerSignal.js +57 -0
- package/lib-esm/sx.d.ts +14 -0
- package/lib-esm/sx.js +3 -5
- package/lib-esm/theme-preval.d.ts +49 -0
- package/lib-esm/theme-preval.js +3119 -357
- package/lib-esm/theme.d.ts +80 -0
- package/lib-esm/theme.js +3 -8
- package/lib-esm/utils/create-slots.d.ts +17 -0
- package/lib-esm/utils/create-slots.js +84 -0
- package/lib-esm/utils/deprecate.d.ts +18 -0
- package/lib-esm/utils/deprecate.js +6 -5
- package/lib-esm/utils/isNumeric.d.ts +1 -0
- package/lib-esm/utils/isNumeric.js +1 -0
- package/lib-esm/utils/iterateFocusableElements.d.ts +42 -0
- package/lib-esm/utils/iterateFocusableElements.js +102 -0
- package/lib-esm/utils/ssr.d.ts +1 -0
- package/lib-esm/utils/ssr.js +1 -0
- package/lib-esm/utils/test-deprecations.d.ts +1 -0
- package/lib-esm/utils/test-deprecations.js +1 -1
- package/lib-esm/utils/{types.js → test-helpers.d.ts} +0 -0
- package/lib-esm/utils/test-helpers.js +7 -0
- package/lib-esm/utils/test-matchers.d.ts +1 -0
- package/lib-esm/utils/test-matchers.js +7 -49
- package/lib-esm/utils/testing.d.ts +545 -0
- package/lib-esm/utils/testing.js +60 -46
- package/lib-esm/utils/theme.d.ts +9 -0
- package/lib-esm/utils/theme.js +66 -0
- package/lib-esm/utils/types/AriaRole.d.ts +1 -0
- package/lib-esm/utils/types/AriaRole.js +1 -0
- package/lib-esm/utils/types/ComponentProps.d.ts +9 -0
- package/lib-esm/utils/types/ComponentProps.js +1 -0
- package/lib-esm/utils/types/Flatten.d.ts +4 -0
- package/lib-esm/utils/types/Flatten.js +1 -0
- package/lib-esm/utils/types/KeyPaths.d.ts +3 -0
- package/lib-esm/utils/types/KeyPaths.js +1 -0
- package/lib-esm/utils/types/MandateProps.d.ts +3 -0
- package/lib-esm/utils/types/MandateProps.js +1 -0
- package/lib-esm/utils/types/Merge.d.ts +19 -0
- package/lib-esm/utils/types/Merge.js +1 -0
- package/lib-esm/utils/types/index.d.ts +5 -0
- package/lib-esm/utils/types/index.js +5 -0
- package/lib-esm/utils/uniqueId.d.ts +1 -0
- package/lib-esm/utils/uniqueId.js +5 -0
- package/lib-esm/utils/use-force-update.d.ts +1 -0
- package/lib-esm/utils/use-force-update.js +6 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/lib-esm/utils/userAgent.d.ts +1 -0
- package/lib-esm/utils/userAgent.js +8 -0
- package/package.json +116 -93
- package/index.d.ts +0 -828
- package/lib/Breadcrumb.js +0 -96
- package/lib/hooks/useMouseIntent.js +0 -58
- package/lib/stories/Button.stories.js +0 -100
- package/lib-esm/Breadcrumb.js +0 -70
- package/lib-esm/hooks/useMouseIntent.js +0 -50
- package/lib-esm/stories/Button.stories.js +0 -65
@@ -0,0 +1,11 @@
|
|
1
|
+
export { useOnOutsideClick } from './useOnOutsideClick';
|
2
|
+
export type { UseOnOutsideClickSettings, TouchOrMouseEvent } from './useOnOutsideClick';
|
3
|
+
export { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
4
|
+
export { useOnEscapePress } from './useOnEscapePress';
|
5
|
+
export { useOpenAndCloseFocus } from './useOpenAndCloseFocus';
|
6
|
+
export type { UseOpenAndCloseFocusSettings } from './useOpenAndCloseFocus';
|
7
|
+
export type { AnchoredPositionHookSettings } from './useAnchoredPosition';
|
8
|
+
export { useAnchoredPosition } from './useAnchoredPosition';
|
9
|
+
export { useOverlay } from './useOverlay';
|
10
|
+
export type { UseOverlaySettings } from './useOverlay';
|
11
|
+
export { useRenderForcingRef } from './useRenderForcingRef';
|
@@ -0,0 +1,7 @@
|
|
1
|
+
export { useOnOutsideClick } from './useOnOutsideClick';
|
2
|
+
export { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
3
|
+
export { useOnEscapePress } from './useOnEscapePress';
|
4
|
+
export { useOpenAndCloseFocus } from './useOpenAndCloseFocus';
|
5
|
+
export { useAnchoredPosition } from './useAnchoredPosition';
|
6
|
+
export { useOverlay } from './useOverlay';
|
7
|
+
export { useRenderForcingRef } from './useRenderForcingRef';
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { PositionSettings, AnchorPosition } from '../behaviors/anchoredPosition';
|
3
|
+
export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
|
4
|
+
floatingElementRef?: React.RefObject<Element>;
|
5
|
+
anchorElementRef?: React.RefObject<Element>;
|
6
|
+
}
|
7
|
+
/**
|
8
|
+
* Calculates the top and left values for an absolutely-positioned floating element
|
9
|
+
* to be anchored to some anchor element. Returns refs for the floating element
|
10
|
+
* and the anchor element, along with the position.
|
11
|
+
* @param settings Settings for calculating the anchored position.
|
12
|
+
* @param dependencies Dependencies to determine when to re-calculate the position.
|
13
|
+
* @returns An object of {top: number, left: number} to absolutely-position the
|
14
|
+
* floating element.
|
15
|
+
*/
|
16
|
+
export declare function useAnchoredPosition(settings?: AnchoredPositionHookSettings, dependencies?: React.DependencyList): {
|
17
|
+
floatingElementRef: React.RefObject<Element>;
|
18
|
+
anchorElementRef: React.RefObject<Element>;
|
19
|
+
position: AnchorPosition | undefined;
|
20
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { getAnchoredPosition } from '../behaviors/anchoredPosition';
|
3
|
+
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
4
|
+
import { useResizeObserver } from './useResizeObserver';
|
5
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Calculates the top and left values for an absolutely-positioned floating element
|
9
|
+
* to be anchored to some anchor element. Returns refs for the floating element
|
10
|
+
* and the anchor element, along with the position.
|
11
|
+
* @param settings Settings for calculating the anchored position.
|
12
|
+
* @param dependencies Dependencies to determine when to re-calculate the position.
|
13
|
+
* @returns An object of {top: number, left: number} to absolutely-position the
|
14
|
+
* floating element.
|
15
|
+
*/
|
16
|
+
export function useAnchoredPosition(settings, dependencies = []) {
|
17
|
+
const floatingElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.floatingElementRef);
|
18
|
+
const anchorElementRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.anchorElementRef);
|
19
|
+
const [position, setPosition] = React.useState(undefined);
|
20
|
+
const updatePosition = React.useCallback(() => {
|
21
|
+
if (floatingElementRef.current instanceof Element && anchorElementRef.current instanceof Element) {
|
22
|
+
setPosition(getAnchoredPosition(floatingElementRef.current, anchorElementRef.current, settings));
|
23
|
+
} else {
|
24
|
+
setPosition(undefined);
|
25
|
+
}
|
26
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
27
|
+
[floatingElementRef, anchorElementRef, ...dependencies]);
|
28
|
+
useLayoutEffect(updatePosition, [updatePosition]);
|
29
|
+
useResizeObserver(updatePosition);
|
30
|
+
return {
|
31
|
+
floatingElementRef,
|
32
|
+
anchorElementRef,
|
33
|
+
position
|
34
|
+
};
|
35
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { ForwardedRef } from 'react';
|
2
|
+
/**
|
3
|
+
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
4
|
+
* should be passed as the ref for the element that needs to be shared. This is
|
5
|
+
* particularly useful when you are using `React.forwardRef` in your component but you
|
6
|
+
* also want to be able to access the local element. This is a small anti-pattern,
|
7
|
+
* though, as it breaks encapsulation.
|
8
|
+
* @param refs
|
9
|
+
*/
|
10
|
+
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { useRef } from 'react';
|
2
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
3
|
+
/**
|
4
|
+
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
5
|
+
* should be passed as the ref for the element that needs to be shared. This is
|
6
|
+
* particularly useful when you are using `React.forwardRef` in your component but you
|
7
|
+
* also want to be able to access the local element. This is a small anti-pattern,
|
8
|
+
* though, as it breaks encapsulation.
|
9
|
+
* @param refs
|
10
|
+
*/
|
11
|
+
|
12
|
+
export function useCombinedRefs(...refs) {
|
13
|
+
const combinedRef = useRef(null);
|
14
|
+
useLayoutEffect(() => {
|
15
|
+
function setRefs(current = null) {
|
16
|
+
for (const ref of refs) {
|
17
|
+
if (!ref) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
|
21
|
+
if (typeof ref === 'function') {
|
22
|
+
ref(current);
|
23
|
+
} else {
|
24
|
+
ref.current = current;
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
setRefs(combinedRef.current);
|
30
|
+
return () => {
|
31
|
+
// ensure the refs get updated on unmount
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
33
|
+
setRefs(combinedRef.current);
|
34
|
+
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
35
|
+
}, [...refs, combinedRef.current]);
|
36
|
+
return combinedRef;
|
37
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
declare type UseDetailsParameters = {
|
3
|
+
ref?: React.RefObject<HTMLElement>;
|
4
|
+
closeOnOutsideClick?: boolean;
|
5
|
+
defaultOpen?: boolean;
|
6
|
+
onClickOutside?: (event: MouseEvent) => void;
|
7
|
+
};
|
8
|
+
declare function useDetails({ ref, closeOnOutsideClick, defaultOpen, onClickOutside }: UseDetailsParameters): {
|
9
|
+
open: boolean | undefined;
|
10
|
+
setOpen: import("react").Dispatch<import("react").SetStateAction<boolean | undefined>>;
|
11
|
+
getDetailsProps: () => {
|
12
|
+
onToggle: (e: React.SyntheticEvent<HTMLElement, Event>) => void;
|
13
|
+
open: boolean | undefined;
|
14
|
+
ref: import("react").RefObject<HTMLElement>;
|
15
|
+
};
|
16
|
+
};
|
17
|
+
export default useDetails;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
declare type UseDialogParameters = {
|
3
|
+
modalRef: React.RefObject<HTMLElement>;
|
4
|
+
overlayRef: React.RefObject<HTMLElement>;
|
5
|
+
isOpen?: boolean;
|
6
|
+
onDismiss?: () => void;
|
7
|
+
initialFocusRef?: React.RefObject<HTMLElement>;
|
8
|
+
closeButtonRef?: React.RefObject<HTMLElement>;
|
9
|
+
returnFocusRef?: React.RefObject<HTMLElement>;
|
10
|
+
};
|
11
|
+
declare function useDialog({ modalRef, overlayRef, isOpen, onDismiss, initialFocusRef, closeButtonRef }: UseDialogParameters): {
|
12
|
+
getDialogProps: () => {
|
13
|
+
onKeyDown: (event: any) => void;
|
14
|
+
};
|
15
|
+
};
|
16
|
+
export default useDialog;
|
@@ -1,21 +1,24 @@
|
|
1
1
|
import { useCallback, useEffect } from 'react';
|
2
2
|
|
3
|
+
const noop = () => null;
|
4
|
+
|
3
5
|
function visible(el) {
|
4
6
|
return !el.hidden && (!el.type || el.type !== 'hidden') && (el.offsetWidth > 0 || el.offsetHeight > 0);
|
5
7
|
}
|
6
8
|
|
7
9
|
function focusable(el) {
|
8
|
-
|
10
|
+
const inputEl = el;
|
11
|
+
return inputEl.tabIndex >= 0 && !inputEl.disabled && visible(inputEl);
|
9
12
|
}
|
10
13
|
|
11
14
|
function useDialog({
|
12
15
|
modalRef,
|
13
16
|
overlayRef,
|
14
17
|
isOpen,
|
15
|
-
onDismiss,
|
18
|
+
onDismiss = noop,
|
16
19
|
initialFocusRef,
|
17
20
|
closeButtonRef
|
18
|
-
}
|
21
|
+
}) {
|
19
22
|
const onClickOutside = useCallback(e => {
|
20
23
|
if (modalRef.current && overlayRef.current && !modalRef.current.contains(e.target) && overlayRef.current.contains(e.target)) {
|
21
24
|
onDismiss();
|
@@ -39,20 +42,32 @@ function useDialog({
|
|
39
42
|
}
|
40
43
|
}, [isOpen, initialFocusRef, closeButtonRef]);
|
41
44
|
const getFocusableItem = useCallback((e, movement) => {
|
42
|
-
if (modalRef
|
45
|
+
if (modalRef.current) {
|
43
46
|
const items = Array.from(modalRef.current.querySelectorAll('*')).filter(focusable);
|
44
47
|
if (items.length === 0) return;
|
45
48
|
e.preventDefault();
|
46
49
|
const focusedElement = document.activeElement;
|
50
|
+
|
51
|
+
if (!focusedElement) {
|
52
|
+
return;
|
53
|
+
}
|
54
|
+
|
47
55
|
const index = items.indexOf(focusedElement);
|
48
56
|
const offsetIndex = index + movement;
|
49
57
|
const fallbackIndex = movement === 1 ? 0 : items.length - 1;
|
50
|
-
|
58
|
+
const focusableItem = items[offsetIndex] || items[fallbackIndex];
|
59
|
+
return focusableItem;
|
51
60
|
}
|
52
61
|
}, [modalRef]);
|
53
62
|
const handleTab = useCallback(e => {
|
54
63
|
const movement = e.shiftKey ? -1 : 1;
|
55
|
-
getFocusableItem(e, movement)
|
64
|
+
const focusableItem = getFocusableItem(e, movement);
|
65
|
+
|
66
|
+
if (!focusableItem) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
|
70
|
+
focusableItem.focus();
|
56
71
|
}, [getFocusableItem]);
|
57
72
|
const onKeyDown = useCallback(event => {
|
58
73
|
switch (event.key) {
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export interface FocusTrapHookSettings {
|
3
|
+
/**
|
4
|
+
* Ref that will be used for the trapping container. If not provided, one will
|
5
|
+
* be created by this hook and returned.
|
6
|
+
*/
|
7
|
+
containerRef?: React.RefObject<HTMLElement>;
|
8
|
+
/**
|
9
|
+
* Ref for the element that should receive focus when the focus trap is first enabled. If
|
10
|
+
* not provided, one will be created by this hook and returned. Its use is optional.
|
11
|
+
*/
|
12
|
+
initialFocusRef?: React.RefObject<HTMLElement>;
|
13
|
+
/**
|
14
|
+
* Set to true to disable the focus trap and clean up listeners. Can be re-enabled at
|
15
|
+
* any time.
|
16
|
+
*/
|
17
|
+
disabled?: boolean;
|
18
|
+
/**
|
19
|
+
* If true, when this focus trap is cleaned up, restore focus to the element that had
|
20
|
+
* focus immediately before the focus trap was enabled. (Default: false)
|
21
|
+
*/
|
22
|
+
restoreFocusOnCleanUp?: boolean;
|
23
|
+
}
|
24
|
+
/**
|
25
|
+
* Hook used to trap focus inside a container. Returns a ref that can be added to the container
|
26
|
+
* that should trap focus.
|
27
|
+
* @param settings {FocusTrapHookSettings}
|
28
|
+
*/
|
29
|
+
export declare function useFocusTrap(settings?: FocusTrapHookSettings, dependencies?: React.DependencyList): {
|
30
|
+
containerRef: React.RefObject<HTMLElement>;
|
31
|
+
initialFocusRef: React.RefObject<HTMLElement>;
|
32
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { focusTrap } from '../behaviors/focusTrap';
|
3
|
+
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Hook used to trap focus inside a container. Returns a ref that can be added to the container
|
7
|
+
* that should trap focus.
|
8
|
+
* @param settings {FocusTrapHookSettings}
|
9
|
+
*/
|
10
|
+
export function useFocusTrap(settings, dependencies = []) {
|
11
|
+
const containerRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.containerRef);
|
12
|
+
const initialFocusRef = useProvidedRefOrCreate(settings === null || settings === void 0 ? void 0 : settings.initialFocusRef);
|
13
|
+
const disabled = settings === null || settings === void 0 ? void 0 : settings.disabled;
|
14
|
+
const abortController = React.useRef();
|
15
|
+
const previousFocusedElement = React.useRef(null); // If we are enabling a focus trap and haven't already stored the previously focused element
|
16
|
+
// go ahead an do that so we can restore later when the trap is disabled.
|
17
|
+
|
18
|
+
if (!previousFocusedElement.current && !(settings !== null && settings !== void 0 && settings.disabled)) {
|
19
|
+
previousFocusedElement.current = document.activeElement;
|
20
|
+
} // This function removes the event listeners that enable the focus trap and restores focus
|
21
|
+
// to the previously-focused element (if necessary).
|
22
|
+
|
23
|
+
|
24
|
+
function disableTrap() {
|
25
|
+
var _abortController$curr;
|
26
|
+
|
27
|
+
(_abortController$curr = abortController.current) === null || _abortController$curr === void 0 ? void 0 : _abortController$curr.abort();
|
28
|
+
|
29
|
+
if (settings !== null && settings !== void 0 && settings.restoreFocusOnCleanUp && previousFocusedElement.current instanceof HTMLElement) {
|
30
|
+
previousFocusedElement.current.focus();
|
31
|
+
previousFocusedElement.current = null;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
React.useEffect(() => {
|
36
|
+
if (containerRef.current instanceof HTMLElement) {
|
37
|
+
if (!disabled) {
|
38
|
+
var _initialFocusRef$curr;
|
39
|
+
|
40
|
+
abortController.current = focusTrap(containerRef.current, (_initialFocusRef$curr = initialFocusRef.current) !== null && _initialFocusRef$curr !== void 0 ? _initialFocusRef$curr : undefined);
|
41
|
+
return () => {
|
42
|
+
disableTrap();
|
43
|
+
};
|
44
|
+
} else {
|
45
|
+
disableTrap();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
49
|
+
[containerRef, initialFocusRef, disabled, ...dependencies]);
|
50
|
+
return {
|
51
|
+
containerRef,
|
52
|
+
initialFocusRef
|
53
|
+
};
|
54
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FocusZoneSettings } from '../behaviors/focusZone';
|
3
|
+
export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
|
4
|
+
/**
|
5
|
+
* Optional ref for the container that holds all elements participating in arrow key focus.
|
6
|
+
* If one is not passed, we will create one for you and return it from the hook.
|
7
|
+
*/
|
8
|
+
containerRef?: React.RefObject<HTMLElement>;
|
9
|
+
/**
|
10
|
+
* If using the "active descendant" focus pattern, pass `true` or a ref to the controlling
|
11
|
+
* element. If a ref object is not passed, we will create one for you.
|
12
|
+
*/
|
13
|
+
activeDescendantFocus?: boolean | React.RefObject<HTMLElement>;
|
14
|
+
/**
|
15
|
+
* Set to true to disable the focus zone and clean up listeners. Can be re-enabled at
|
16
|
+
* any time.
|
17
|
+
*/
|
18
|
+
disabled?: boolean;
|
19
|
+
}
|
20
|
+
export declare function useFocusZone(settings?: FocusZoneHookSettings, dependencies?: React.DependencyList): {
|
21
|
+
containerRef: React.RefObject<HTMLElement>;
|
22
|
+
activeDescendantControlRef: React.RefObject<HTMLElement>;
|
23
|
+
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import React, { useEffect } from 'react';
|
2
|
+
import { focusZone } from '../behaviors/focusZone';
|
3
|
+
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
4
|
+
export function useFocusZone(settings = {}, dependencies = []) {
|
5
|
+
const containerRef = useProvidedRefOrCreate(settings.containerRef);
|
6
|
+
const useActiveDescendant = !!settings.activeDescendantFocus;
|
7
|
+
const passedActiveDescendantRef = typeof settings.activeDescendantFocus === 'boolean' || !settings.activeDescendantFocus ? undefined : settings.activeDescendantFocus;
|
8
|
+
const activeDescendantControlRef = useProvidedRefOrCreate(passedActiveDescendantRef);
|
9
|
+
const disabled = settings.disabled;
|
10
|
+
const abortController = React.useRef();
|
11
|
+
useEffect(() => {
|
12
|
+
if (containerRef.current instanceof HTMLElement && (!useActiveDescendant || activeDescendantControlRef.current instanceof HTMLElement)) {
|
13
|
+
if (!disabled) {
|
14
|
+
var _activeDescendantCont;
|
15
|
+
|
16
|
+
const vanillaSettings = { ...settings,
|
17
|
+
activeDescendantControl: (_activeDescendantCont = activeDescendantControlRef.current) !== null && _activeDescendantCont !== void 0 ? _activeDescendantCont : undefined
|
18
|
+
};
|
19
|
+
abortController.current = focusZone(containerRef.current, vanillaSettings);
|
20
|
+
return () => {
|
21
|
+
var _abortController$curr;
|
22
|
+
|
23
|
+
(_abortController$curr = abortController.current) === null || _abortController$curr === void 0 ? void 0 : _abortController$curr.abort();
|
24
|
+
};
|
25
|
+
} else {
|
26
|
+
var _abortController$curr2;
|
27
|
+
|
28
|
+
(_abortController$curr2 = abortController.current) === null || _abortController$curr2 === void 0 ? void 0 : _abortController$curr2.abort();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
32
|
+
[disabled, ...dependencies]);
|
33
|
+
return {
|
34
|
+
containerRef,
|
35
|
+
activeDescendantControlRef
|
36
|
+
};
|
37
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
/**
|
3
|
+
* Sets up a `keydown` listener on `window.document`. If
|
4
|
+
* 1) The pressed key is "Escape", and
|
5
|
+
* 2) The event has not had `.preventDefault()` called
|
6
|
+
* The given callback will be executed.
|
7
|
+
*
|
8
|
+
* Note: If multiple `useOnEscapePress` hooks are active simultaneously, the
|
9
|
+
* callbacks will occur in reverse order. In other words, if a parent component
|
10
|
+
* and a child component both call `useOnEscapePress`, when the user presses
|
11
|
+
* Escape, the child component's callback will execute, followed by the parent's
|
12
|
+
* callback. Each callback has the chance to call `.preventDefault()` on the
|
13
|
+
* event to prevent further callbacks.
|
14
|
+
*
|
15
|
+
* @param callback {(e: KeyboardEvent) => void} The callback that gets executed
|
16
|
+
* when the Escape key is pressed. The KeyboardEvent generated by the Escape
|
17
|
+
* keypress is passed as the only argument.
|
18
|
+
*
|
19
|
+
* @param callbackDependencies {React.DependencyList} The dependencies of the given
|
20
|
+
* `onEscape` callback for memoization. Omit this param if the callback is already
|
21
|
+
* memoized. See `React.useCallback` for more info on memoization.
|
22
|
+
*/
|
23
|
+
export declare const useOnEscapePress: (onEscape: (e: KeyboardEvent) => void, callbackDependencies?: import("react").DependencyList) => void;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { useEffect, useCallback } from 'react';
|
2
|
+
const handlers = [];
|
3
|
+
/**
|
4
|
+
* Calls all handlers in reverse order
|
5
|
+
* @param event The KeyboardEvent generated by the Escape keydown.
|
6
|
+
*/
|
7
|
+
|
8
|
+
function handleEscape(event) {
|
9
|
+
if (event.key === 'Escape' && !event.defaultPrevented) {
|
10
|
+
for (let i = handlers.length - 1; i >= 0; --i) {
|
11
|
+
handlers[i](event); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
12
|
+
|
13
|
+
if (event.defaultPrevented) {
|
14
|
+
break;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
/**
|
20
|
+
* Sets up a `keydown` listener on `window.document`. If
|
21
|
+
* 1) The pressed key is "Escape", and
|
22
|
+
* 2) The event has not had `.preventDefault()` called
|
23
|
+
* The given callback will be executed.
|
24
|
+
*
|
25
|
+
* Note: If multiple `useOnEscapePress` hooks are active simultaneously, the
|
26
|
+
* callbacks will occur in reverse order. In other words, if a parent component
|
27
|
+
* and a child component both call `useOnEscapePress`, when the user presses
|
28
|
+
* Escape, the child component's callback will execute, followed by the parent's
|
29
|
+
* callback. Each callback has the chance to call `.preventDefault()` on the
|
30
|
+
* event to prevent further callbacks.
|
31
|
+
*
|
32
|
+
* @param callback {(e: KeyboardEvent) => void} The callback that gets executed
|
33
|
+
* when the Escape key is pressed. The KeyboardEvent generated by the Escape
|
34
|
+
* keypress is passed as the only argument.
|
35
|
+
*
|
36
|
+
* @param callbackDependencies {React.DependencyList} The dependencies of the given
|
37
|
+
* `onEscape` callback for memoization. Omit this param if the callback is already
|
38
|
+
* memoized. See `React.useCallback` for more info on memoization.
|
39
|
+
*/
|
40
|
+
|
41
|
+
|
42
|
+
export const useOnEscapePress = (onEscape, callbackDependencies = [onEscape]) => {
|
43
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
44
|
+
const escapeCallback = useCallback(onEscape, callbackDependencies);
|
45
|
+
useEffect(() => {
|
46
|
+
if (handlers.length === 0) {
|
47
|
+
document.addEventListener('keydown', handleEscape);
|
48
|
+
}
|
49
|
+
|
50
|
+
handlers.push(escapeCallback);
|
51
|
+
return () => {
|
52
|
+
handlers.splice(handlers.findIndex(h => h === escapeCallback), 1);
|
53
|
+
|
54
|
+
if (handlers.length === 0) {
|
55
|
+
document.removeEventListener('keydown', handleEscape);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
}, [escapeCallback]);
|
59
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export declare type TouchOrMouseEvent = MouseEvent | TouchEvent;
|
3
|
+
export declare type UseOnOutsideClickSettings = {
|
4
|
+
containerRef: React.RefObject<HTMLDivElement>;
|
5
|
+
ignoreClickRefs?: React.RefObject<HTMLElement>[];
|
6
|
+
onClickOutside: (e: TouchOrMouseEvent) => void;
|
7
|
+
};
|
8
|
+
export declare const useOnOutsideClick: ({ containerRef, ignoreClickRefs, onClickOutside }: UseOnOutsideClickSettings) => void;
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { useEffect, useCallback, useMemo } from 'react';
|
2
|
+
// Because events are handled at the document level, we provide a mechanism for early return.
|
3
|
+
const stopPropagation = true;
|
4
|
+
/**
|
5
|
+
* Calls all handlers in reverse order
|
6
|
+
* @param event The MouseEvent generated by the click event.
|
7
|
+
*/
|
8
|
+
|
9
|
+
function handleClick(event) {
|
10
|
+
if (!event.defaultPrevented) {
|
11
|
+
for (const handler of Object.values(registry).reverse()) {
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
13
|
+
if (handler(event) === stopPropagation || event.defaultPrevented) {
|
14
|
+
break;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
const registry = {};
|
21
|
+
|
22
|
+
function register(id, handler) {
|
23
|
+
registry[id] = handler;
|
24
|
+
}
|
25
|
+
|
26
|
+
function deregister(id) {
|
27
|
+
delete registry[id];
|
28
|
+
} // For auto-incrementing unique identifiers for registered handlers.
|
29
|
+
|
30
|
+
|
31
|
+
let handlerId = 0;
|
32
|
+
export const useOnOutsideClick = ({
|
33
|
+
containerRef,
|
34
|
+
ignoreClickRefs,
|
35
|
+
onClickOutside
|
36
|
+
}) => {
|
37
|
+
const id = useMemo(() => handlerId++, []);
|
38
|
+
const handler = useCallback(event => {
|
39
|
+
var _containerRef$current;
|
40
|
+
|
41
|
+
// don't call click handler if the mouse event was triggered by an auxiliary button (right click/wheel button/etc)
|
42
|
+
if (event instanceof MouseEvent && event.button > 0) {
|
43
|
+
return stopPropagation;
|
44
|
+
} // don't call handler if the click happened inside of the container
|
45
|
+
|
46
|
+
|
47
|
+
if ((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(event.target)) {
|
48
|
+
return stopPropagation;
|
49
|
+
} // don't call handler if click happened on an ignored ref
|
50
|
+
|
51
|
+
|
52
|
+
if (ignoreClickRefs && ignoreClickRefs.some(({
|
53
|
+
current
|
54
|
+
}) => current === null || current === void 0 ? void 0 : current.contains(event.target))) {
|
55
|
+
return stopPropagation;
|
56
|
+
}
|
57
|
+
|
58
|
+
onClickOutside(event);
|
59
|
+
}, [containerRef, ignoreClickRefs, onClickOutside]);
|
60
|
+
useEffect(() => {
|
61
|
+
if (Object.keys(registry).length === 0) {
|
62
|
+
// use capture to ensure we get all events
|
63
|
+
document.addEventListener('mousedown', handleClick, {
|
64
|
+
capture: true
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
register(id, handler);
|
69
|
+
return () => {
|
70
|
+
deregister(id);
|
71
|
+
|
72
|
+
if (Object.keys(registry).length === 0) {
|
73
|
+
document.removeEventListener('mousedown', handleClick, {
|
74
|
+
capture: true
|
75
|
+
});
|
76
|
+
}
|
77
|
+
};
|
78
|
+
}, [id, handler]);
|
79
|
+
};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export declare type UseOpenAndCloseFocusSettings = {
|
3
|
+
initialFocusRef?: React.RefObject<HTMLElement>;
|
4
|
+
containerRef: React.RefObject<HTMLElement>;
|
5
|
+
returnFocusRef: React.RefObject<HTMLElement>;
|
6
|
+
preventFocusOnOpen?: boolean;
|
7
|
+
};
|
8
|
+
export declare function useOpenAndCloseFocus({ initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen }: UseOpenAndCloseFocusSettings): void;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { useEffect } from 'react';
|
2
|
+
import { iterateFocusableElements } from '../utils/iterateFocusableElements';
|
3
|
+
export function useOpenAndCloseFocus({
|
4
|
+
initialFocusRef,
|
5
|
+
returnFocusRef,
|
6
|
+
containerRef,
|
7
|
+
preventFocusOnOpen
|
8
|
+
}) {
|
9
|
+
useEffect(() => {
|
10
|
+
if (preventFocusOnOpen) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
|
14
|
+
const returnRef = returnFocusRef.current;
|
15
|
+
|
16
|
+
if (initialFocusRef && initialFocusRef.current) {
|
17
|
+
initialFocusRef.current.focus();
|
18
|
+
} else if (containerRef.current) {
|
19
|
+
const firstItem = iterateFocusableElements(containerRef.current).next().value;
|
20
|
+
firstItem === null || firstItem === void 0 ? void 0 : firstItem.focus();
|
21
|
+
}
|
22
|
+
|
23
|
+
return function () {
|
24
|
+
returnRef === null || returnRef === void 0 ? void 0 : returnRef.focus();
|
25
|
+
};
|
26
|
+
}, [initialFocusRef, returnFocusRef, containerRef, preventFocusOnOpen]);
|
27
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
import { TouchOrMouseEvent } from './useOnOutsideClick';
|
3
|
+
export declare type UseOverlaySettings = {
|
4
|
+
ignoreClickRefs?: React.RefObject<HTMLElement>[];
|
5
|
+
initialFocusRef?: React.RefObject<HTMLElement>;
|
6
|
+
returnFocusRef: React.RefObject<HTMLElement>;
|
7
|
+
onEscape: (e: KeyboardEvent) => void;
|
8
|
+
onClickOutside: (e: TouchOrMouseEvent) => void;
|
9
|
+
overlayRef?: React.RefObject<HTMLDivElement>;
|
10
|
+
preventFocusOnOpen?: boolean;
|
11
|
+
};
|
12
|
+
export declare type OverlayReturnProps = {
|
13
|
+
ref: React.RefObject<HTMLDivElement>;
|
14
|
+
};
|
15
|
+
export declare const useOverlay: ({ overlayRef: _overlayRef, returnFocusRef, initialFocusRef, onEscape, ignoreClickRefs, onClickOutside, preventFocusOnOpen }: UseOverlaySettings) => OverlayReturnProps;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { useOnOutsideClick } from './useOnOutsideClick';
|
2
|
+
import { useOpenAndCloseFocus } from './useOpenAndCloseFocus';
|
3
|
+
import { useOnEscapePress } from './useOnEscapePress';
|
4
|
+
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
5
|
+
export const useOverlay = ({
|
6
|
+
overlayRef: _overlayRef,
|
7
|
+
returnFocusRef,
|
8
|
+
initialFocusRef,
|
9
|
+
onEscape,
|
10
|
+
ignoreClickRefs,
|
11
|
+
onClickOutside,
|
12
|
+
preventFocusOnOpen
|
13
|
+
}) => {
|
14
|
+
const overlayRef = useProvidedRefOrCreate(_overlayRef);
|
15
|
+
useOpenAndCloseFocus({
|
16
|
+
containerRef: overlayRef,
|
17
|
+
returnFocusRef,
|
18
|
+
initialFocusRef,
|
19
|
+
preventFocusOnOpen
|
20
|
+
});
|
21
|
+
useOnOutsideClick({
|
22
|
+
containerRef: overlayRef,
|
23
|
+
ignoreClickRefs,
|
24
|
+
onClickOutside
|
25
|
+
});
|
26
|
+
useOnEscapePress(onEscape);
|
27
|
+
return {
|
28
|
+
ref: overlayRef
|
29
|
+
};
|
30
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
/**
|
3
|
+
* There are some situations where we only want to create a new ref if one is not provided to a component
|
4
|
+
* or hook as a prop. However, due to the `rules-of-hooks`, we cannot conditionally make a call to `React.useRef`
|
5
|
+
* only in the situations where the ref is not provided as a prop.
|
6
|
+
* This hook aims to encapsulate that logic, so the consumer doesn't need to be concerned with violating `rules-of-hooks`.
|
7
|
+
* @param providedRef The ref to use - if undefined, will use the ref from a call to React.useRef
|
8
|
+
* @type TRef The type of the RefObject which should be created.
|
9
|
+
*/
|
10
|
+
export declare function useProvidedRefOrCreate<TRef>(providedRef?: React.RefObject<TRef>): React.RefObject<TRef>;
|