bootstrap-rn 0.4.6 → 0.4.7
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/lib/module/Context.js.map +1 -1
- package/lib/module/Provider.js +3 -7
- package/lib/module/Provider.js.map +1 -1
- package/lib/module/components/Body.js +8 -1
- package/lib/module/components/Body.js.map +1 -1
- package/lib/module/components/buttons/Button.js +10 -8
- package/lib/module/components/buttons/Button.js.map +1 -1
- package/lib/module/components/close/CloseButton.js +7 -3
- package/lib/module/components/close/CloseButton.js.map +1 -1
- package/lib/module/components/collapse/useCollapse.js +2 -3
- package/lib/module/components/collapse/useCollapse.js.map +1 -1
- package/lib/module/components/dropdown/Dropdown.js +1 -2
- package/lib/module/components/dropdown/Dropdown.js.map +1 -1
- package/lib/module/components/dropdown/DropdownContext.js.map +1 -1
- package/lib/module/components/dropdown/DropdownMenu.js +33 -59
- package/lib/module/components/dropdown/DropdownMenu.js.map +1 -1
- package/lib/module/components/dropdown/useDismissDropdown.js +5 -4
- package/lib/module/components/dropdown/useDismissDropdown.js.map +1 -1
- package/lib/module/components/dropdown/useDropdown.js +35 -11
- package/lib/module/components/dropdown/useDropdown.js.map +1 -1
- package/lib/module/components/dropdown/useToggleDropdown.js +4 -6
- package/lib/module/components/dropdown/useToggleDropdown.js.map +1 -1
- package/lib/module/components/forms/FormCheckInput.js +1 -1
- package/lib/module/components/forms/Input.js +1 -1
- package/lib/module/components/forms/internals/PickerNative.js +1 -1
- package/lib/module/components/forms/internals/PickerNative.js.map +1 -1
- package/lib/module/components/helpers/BackdropHandler.js +6 -92
- package/lib/module/components/helpers/BackdropHandler.js.map +1 -1
- package/lib/module/components/helpers/BackdropHandler.web.js +8 -0
- package/lib/module/components/helpers/BackdropHandler.web.js.map +1 -0
- package/lib/module/components/helpers/Dialog.js +29 -0
- package/lib/module/components/helpers/Dialog.js.map +1 -0
- package/lib/module/components/helpers/Dialog.web.js +117 -0
- package/lib/module/components/helpers/Dialog.web.js.map +1 -0
- package/lib/module/components/helpers/Portal.js +5 -0
- package/lib/module/components/helpers/Portal.js.map +1 -0
- package/lib/module/components/helpers/Portal.web.js +16 -0
- package/lib/module/components/helpers/Portal.web.js.map +1 -0
- package/lib/module/components/helpers/PortalHost.js +5 -0
- package/lib/module/components/helpers/PortalHost.js.map +1 -0
- package/lib/module/components/helpers/PortalHost.web.js +15 -0
- package/lib/module/components/helpers/PortalHost.web.js.map +1 -0
- package/lib/module/components/modal/Modal.js +58 -48
- package/lib/module/components/modal/Modal.js.map +1 -1
- package/lib/module/components/modal/ModalContext.js.map +1 -1
- package/lib/module/components/modal/ModalTitle.js +6 -0
- package/lib/module/components/modal/ModalTitle.js.map +1 -1
- package/lib/module/components/modal/useModal.js +4 -13
- package/lib/module/components/modal/useModal.js.map +1 -1
- package/lib/module/components/nav/useTabbable.js +2 -3
- package/lib/module/components/nav/useTabbable.js.map +1 -1
- package/lib/module/components/navbar/NavbarToggler.js +1 -1
- package/lib/module/components/navbar/useNavbar.js +2 -3
- package/lib/module/components/navbar/useNavbar.js.map +1 -1
- package/lib/module/components/offcanvas/Offcanvas.js +84 -82
- package/lib/module/components/offcanvas/Offcanvas.js.map +1 -1
- package/lib/module/components/offcanvas/OffcanvasContext.js.map +1 -1
- package/lib/module/components/offcanvas/OffcanvasTitle.js +6 -0
- package/lib/module/components/offcanvas/OffcanvasTitle.js.map +1 -1
- package/lib/module/components/offcanvas/useOffcanvas.js +6 -14
- package/lib/module/components/offcanvas/useOffcanvas.js.map +1 -1
- package/lib/module/components/pagination/PaginationItem.js +39 -39
- package/lib/module/components/popover/Popover.js +6 -8
- package/lib/module/components/popover/Popover.js.map +1 -1
- package/lib/module/components/popover/PopoverArrow.js +18 -9
- package/lib/module/components/popover/PopoverArrow.js.map +1 -1
- package/lib/module/components/popover/PopoverContext.js.map +1 -1
- package/lib/module/components/popover/injectPopover.js +48 -45
- package/lib/module/components/popover/injectPopover.js.map +1 -1
- package/lib/module/components/tooltip/Tooltip.js +7 -23
- package/lib/module/components/tooltip/Tooltip.js.map +1 -1
- package/lib/module/components/tooltip/TooltipArrow.js +22 -12
- package/lib/module/components/tooltip/TooltipArrow.js.map +1 -1
- package/lib/module/components/tooltip/TooltipContext.js.map +1 -1
- package/lib/module/components/tooltip/injectTooltip.js +46 -42
- package/lib/module/components/tooltip/injectTooltip.js.map +1 -1
- package/lib/module/hooks/useBackgroundNative.js.map +1 -1
- package/lib/module/hooks/useFocusRing.js +13 -0
- package/lib/module/hooks/useFocusRing.js.map +1 -0
- package/lib/module/hooks/useFocusRing.web.js +5 -0
- package/lib/module/hooks/useFocusRing.web.js.map +1 -0
- package/lib/module/hooks/useInteractionState.js +11 -11
- package/lib/module/hooks/useInteractionState.js.map +1 -1
- package/lib/module/hooks/useOverlay.js +121 -0
- package/lib/module/hooks/useOverlay.js.map +1 -0
- package/lib/module/hooks/useOverlay.web.js +113 -0
- package/lib/module/hooks/useOverlay.web.js.map +1 -0
- package/lib/module/hooks/useScrollbarEffects.js +7 -60
- package/lib/module/hooks/useScrollbarEffects.js.map +1 -1
- package/lib/module/hooks/useScrollbarEffects.web.js +59 -0
- package/lib/module/hooks/useScrollbarEffects.web.js.map +1 -0
- package/lib/module/index.js +3 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/style/StyleSheet.js +1 -3
- package/lib/module/style/StyleSheet.js.map +1 -1
- package/lib/module/theme/variables.js +9 -9
- package/lib/module/utils.js +0 -11
- package/lib/module/utils.js.map +1 -1
- package/lib/typescript/Context.d.ts +0 -1
- package/lib/typescript/Context.d.ts.map +1 -1
- package/lib/typescript/Provider.d.ts.map +1 -1
- package/lib/typescript/components/Body.d.ts.map +1 -1
- package/lib/typescript/components/Link.d.ts +1 -1
- package/lib/typescript/components/Link.d.ts.map +1 -1
- package/lib/typescript/components/Pressable.d.ts +1 -1
- package/lib/typescript/components/Pressable.d.ts.map +1 -1
- package/lib/typescript/components/TextInput.d.ts +3 -3
- package/lib/typescript/components/TextInput.d.ts.map +1 -1
- package/lib/typescript/components/buttons/Button.d.ts +1 -1
- package/lib/typescript/components/buttons/Button.d.ts.map +1 -1
- package/lib/typescript/components/close/CloseButton.d.ts +1 -1
- package/lib/typescript/components/close/CloseButton.d.ts.map +1 -1
- package/lib/typescript/components/collapse/useCollapse.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/Dropdown.d.ts +0 -1
- package/lib/typescript/components/dropdown/Dropdown.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/DropdownContext.d.ts +14 -3
- package/lib/typescript/components/dropdown/DropdownContext.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/DropdownMenu.d.ts +0 -1
- package/lib/typescript/components/dropdown/DropdownMenu.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/useDismissDropdown.d.ts +1 -1
- package/lib/typescript/components/dropdown/useDismissDropdown.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/useDropdown.d.ts +38 -4
- package/lib/typescript/components/dropdown/useDropdown.d.ts.map +1 -1
- package/lib/typescript/components/dropdown/useToggleDropdown.d.ts +4 -3
- package/lib/typescript/components/dropdown/useToggleDropdown.d.ts.map +1 -1
- package/lib/typescript/components/forms/Picker.d.ts +1 -1
- package/lib/typescript/components/forms/internals/PickerNative.d.ts +1 -1
- package/lib/typescript/components/forms/internals/PickerNative.d.ts.map +1 -1
- package/lib/typescript/components/forms/internals/PickerWeb.d.ts +1 -1
- package/lib/typescript/components/forms/internals/PickerWeb.d.ts.map +1 -1
- package/lib/typescript/components/helpers/BackdropHandler.d.ts +2 -11
- package/lib/typescript/components/helpers/BackdropHandler.d.ts.map +1 -1
- package/lib/typescript/components/helpers/BackdropHandler.web.d.ts +3 -0
- package/lib/typescript/components/helpers/BackdropHandler.web.d.ts.map +1 -0
- package/lib/typescript/components/helpers/Dialog.d.ts +15 -0
- package/lib/typescript/components/helpers/Dialog.d.ts.map +1 -0
- package/lib/typescript/components/helpers/Dialog.web.d.ts +15 -0
- package/lib/typescript/components/helpers/Dialog.web.d.ts.map +1 -0
- package/lib/typescript/components/helpers/Portal.d.ts +8 -0
- package/lib/typescript/components/helpers/Portal.d.ts.map +1 -0
- package/lib/typescript/components/helpers/Portal.web.d.ts +8 -0
- package/lib/typescript/components/helpers/Portal.web.d.ts.map +1 -0
- package/lib/typescript/components/helpers/PortalHost.d.ts +6 -0
- package/lib/typescript/components/helpers/PortalHost.d.ts.map +1 -0
- package/lib/typescript/components/helpers/PortalHost.web.d.ts +7 -0
- package/lib/typescript/components/helpers/PortalHost.web.d.ts.map +1 -0
- package/lib/typescript/components/list-group/ListGroup.d.ts +1 -1
- package/lib/typescript/components/list-group/ListGroupItemAction.d.ts +1 -1
- package/lib/typescript/components/list-group/ListGroupItemAction.d.ts.map +1 -1
- package/lib/typescript/components/modal/Modal.d.ts +1 -1
- package/lib/typescript/components/modal/Modal.d.ts.map +1 -1
- package/lib/typescript/components/modal/ModalContext.d.ts +1 -0
- package/lib/typescript/components/modal/ModalContext.d.ts.map +1 -1
- package/lib/typescript/components/modal/ModalTitle.d.ts.map +1 -1
- package/lib/typescript/components/modal/useModal.d.ts +2 -1
- package/lib/typescript/components/modal/useModal.d.ts.map +1 -1
- package/lib/typescript/components/nav/Nav.d.ts +1 -1
- package/lib/typescript/components/nav/NavLink.d.ts +1 -1
- package/lib/typescript/components/nav/NavLink.d.ts.map +1 -1
- package/lib/typescript/components/nav/useTabbable.d.ts.map +1 -1
- package/lib/typescript/components/navbar/Navbar.d.ts +2 -2
- package/lib/typescript/components/navbar/NavbarBrand.d.ts +1 -1
- package/lib/typescript/components/navbar/NavbarBrand.d.ts.map +1 -1
- package/lib/typescript/components/navbar/NavbarToggler.d.ts +1 -1
- package/lib/typescript/components/navbar/NavbarToggler.d.ts.map +1 -1
- package/lib/typescript/components/navbar/useNavbar.d.ts.map +1 -1
- package/lib/typescript/components/offcanvas/Offcanvas.d.ts +1 -4
- package/lib/typescript/components/offcanvas/Offcanvas.d.ts.map +1 -1
- package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts +3 -1
- package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts.map +1 -1
- package/lib/typescript/components/offcanvas/OffcanvasTitle.d.ts.map +1 -1
- package/lib/typescript/components/offcanvas/useOffcanvas.d.ts +3 -1
- package/lib/typescript/components/offcanvas/useOffcanvas.d.ts.map +1 -1
- package/lib/typescript/components/popover/Popover.d.ts +3 -4
- package/lib/typescript/components/popover/Popover.d.ts.map +1 -1
- package/lib/typescript/components/popover/PopoverArrow.d.ts.map +1 -1
- package/lib/typescript/components/popover/PopoverContext.d.ts +3 -4
- package/lib/typescript/components/popover/PopoverContext.d.ts.map +1 -1
- package/lib/typescript/components/popover/injectPopover.d.ts +5 -7
- package/lib/typescript/components/popover/injectPopover.d.ts.map +1 -1
- package/lib/typescript/components/tooltip/Tooltip.d.ts +3 -4
- package/lib/typescript/components/tooltip/Tooltip.d.ts.map +1 -1
- package/lib/typescript/components/tooltip/TooltipArrow.d.ts.map +1 -1
- package/lib/typescript/components/tooltip/TooltipContext.d.ts +3 -4
- package/lib/typescript/components/tooltip/TooltipContext.d.ts.map +1 -1
- package/lib/typescript/components/tooltip/injectTooltip.d.ts +5 -7
- package/lib/typescript/components/tooltip/injectTooltip.d.ts.map +1 -1
- package/lib/typescript/hooks/useBackgroundNative.d.ts.map +1 -1
- package/lib/typescript/hooks/useFocusRing.d.ts +3 -0
- package/lib/typescript/hooks/useFocusRing.d.ts.map +1 -0
- package/lib/typescript/hooks/useFocusRing.web.d.ts +3 -0
- package/lib/typescript/hooks/useFocusRing.web.d.ts.map +1 -0
- package/lib/typescript/hooks/useInteractionState.d.ts +7 -7
- package/lib/typescript/hooks/useInteractionState.d.ts.map +1 -1
- package/lib/typescript/hooks/useOverlay.d.ts +64 -0
- package/lib/typescript/hooks/useOverlay.d.ts.map +1 -0
- package/lib/typescript/hooks/useOverlay.web.d.ts +37 -0
- package/lib/typescript/hooks/useOverlay.web.d.ts.map +1 -0
- package/lib/typescript/hooks/useScrollbarEffects.d.ts.map +1 -1
- package/lib/typescript/hooks/useScrollbarEffects.web.d.ts +7 -0
- package/lib/typescript/hooks/useScrollbarEffects.web.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/style/StyleSheet.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +12 -6
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils.d.ts +2 -3
- package/lib/typescript/utils.d.ts.map +1 -1
- package/package.json +92 -85
- package/src/Context.ts +37 -38
- package/src/Provider.tsx +61 -66
- package/src/components/Body.tsx +16 -1
- package/src/components/TextInput.tsx +66 -66
- package/src/components/buttons/Button.tsx +381 -379
- package/src/components/close/CloseButton.tsx +142 -138
- package/src/components/collapse/useCollapse.ts +25 -26
- package/src/components/dropdown/Dropdown.tsx +77 -80
- package/src/components/dropdown/DropdownContext.ts +14 -3
- package/src/components/dropdown/DropdownMenu.tsx +243 -284
- package/src/components/dropdown/useDismissDropdown.ts +30 -29
- package/src/components/dropdown/useDropdown.ts +55 -38
- package/src/components/dropdown/useToggleDropdown.ts +31 -32
- package/src/components/forms/FormCheckInput.tsx +268 -268
- package/src/components/forms/Input.tsx +220 -220
- package/src/components/forms/internals/PickerNative.tsx +9 -10
- package/src/components/helpers/BackdropHandler.tsx +5 -119
- package/src/components/helpers/BackdropHandler.web.tsx +6 -0
- package/src/components/helpers/Dialog.tsx +49 -0
- package/src/components/helpers/Dialog.web.tsx +145 -0
- package/src/components/helpers/Portal.tsx +10 -0
- package/src/components/helpers/Portal.web.tsx +22 -0
- package/src/components/helpers/PortalHost.tsx +7 -0
- package/src/components/helpers/PortalHost.web.tsx +14 -0
- package/src/components/modal/Modal.tsx +60 -48
- package/src/components/modal/ModalContext.ts +12 -11
- package/src/components/modal/ModalTitle.tsx +41 -31
- package/src/components/modal/useModal.ts +13 -25
- package/src/components/nav/useTabbable.ts +31 -32
- package/src/components/navbar/NavbarToggler.tsx +130 -130
- package/src/components/navbar/useNavbar.ts +30 -31
- package/src/components/offcanvas/Offcanvas.tsx +91 -92
- package/src/components/offcanvas/OffcanvasContext.ts +13 -11
- package/src/components/offcanvas/OffcanvasTitle.tsx +43 -33
- package/src/components/offcanvas/useOffcanvas.ts +12 -20
- package/src/components/pagination/PaginationItem.tsx +139 -139
- package/src/components/popover/Popover.tsx +87 -90
- package/src/components/popover/PopoverArrow.tsx +22 -6
- package/src/components/popover/PopoverContext.ts +13 -18
- package/src/components/popover/injectPopover.tsx +63 -55
- package/src/components/tooltip/Tooltip.tsx +79 -98
- package/src/components/tooltip/TooltipArrow.tsx +26 -8
- package/src/components/tooltip/TooltipContext.ts +13 -18
- package/src/components/tooltip/injectTooltip.tsx +62 -53
- package/src/hooks/useAction.ts +78 -78
- package/src/hooks/useBackgroundNative.tsx +6 -4
- package/src/hooks/useFocusRing.ts +13 -0
- package/src/hooks/useFocusRing.web.ts +3 -0
- package/src/hooks/useInteractionState.ts +75 -81
- package/src/hooks/useOverlay.ts +197 -0
- package/src/hooks/useOverlay.web.ts +190 -0
- package/src/hooks/useScrollbarEffects.ts +5 -83
- package/src/hooks/useScrollbarEffects.web.ts +83 -0
- package/src/index.ts +5 -5
- package/src/style/StyleSheet.ts +2 -5
- package/src/theme/variables.ts +1420 -1420
- package/src/types.ts +14 -14
- package/src/utils.ts +4 -22
- package/lib/module/components/SafeAreaView.js +0 -42
- package/lib/module/components/SafeAreaView.js.map +0 -1
- package/lib/module/components/helpers/Overlay.js +0 -50
- package/lib/module/components/helpers/Overlay.js.map +0 -1
- package/lib/module/hooks/useIdentifier.js +0 -14
- package/lib/module/hooks/useIdentifier.js.map +0 -1
- package/lib/module/hooks/useTrigger.js +0 -97
- package/lib/module/hooks/useTrigger.js.map +0 -1
- package/lib/typescript/components/SafeAreaView.d.ts +0 -12
- package/lib/typescript/components/SafeAreaView.d.ts.map +0 -1
- package/lib/typescript/components/helpers/Overlay.d.ts +0 -28
- package/lib/typescript/components/helpers/Overlay.d.ts.map +0 -1
- package/lib/typescript/hooks/useIdentifier.d.ts +0 -2
- package/lib/typescript/hooks/useIdentifier.d.ts.map +0 -1
- package/lib/typescript/hooks/useTrigger.d.ts +0 -33
- package/lib/typescript/hooks/useTrigger.d.ts.map +0 -1
- package/src/components/SafeAreaView.tsx +0 -64
- package/src/components/helpers/Overlay.tsx +0 -81
- package/src/hooks/useIdentifier.ts +0 -15
- package/src/hooks/useTrigger.ts +0 -141
package/src/hooks/useAction.ts
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import type { UseToggleButtonProps } from '../components/buttons/useToggleButton';
|
|
2
|
-
import type { UseToggleCollapseProps } from '../components/collapse/useToggleCollapse';
|
|
3
|
-
import type { UseDismissDropdownProps } from '../components/dropdown/useDismissDropdown';
|
|
4
|
-
import type { UseToggleDropdownProps } from '../components/dropdown/useToggleDropdown';
|
|
5
|
-
import type { UseToggleTabProps } from '../components/nav/useToggleTab';
|
|
6
|
-
import type { UseDismissNavbarProps } from '../components/navbar/useDismissNavbar';
|
|
7
|
-
import type { UseToggleNavbarProps } from '../components/navbar/useToggleNavbar';
|
|
8
|
-
import { concatRefs } from '../utils';
|
|
9
|
-
|
|
10
|
-
interface UseToggleProps
|
|
11
|
-
extends UseToggleTabProps,
|
|
12
|
-
UseToggleNavbarProps,
|
|
13
|
-
UseToggleButtonProps,
|
|
14
|
-
UseToggleCollapseProps,
|
|
15
|
-
UseToggleDropdownProps {}
|
|
16
|
-
|
|
17
|
-
interface UseDismissProps
|
|
18
|
-
extends UseDismissDropdownProps,
|
|
19
|
-
UseDismissNavbarProps {}
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
type ToggleFunction = <T>(props: T & UseToggleProps) => any;
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
type DismissFunction = <T>(props: T & UseDismissProps) => any;
|
|
26
|
-
|
|
27
|
-
type ToggleType =
|
|
28
|
-
| ToggleFunction
|
|
29
|
-
| {
|
|
30
|
-
useToggle: ToggleFunction;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type DismissType =
|
|
34
|
-
| DismissFunction
|
|
35
|
-
| {
|
|
36
|
-
useDismiss: DismissFunction;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export interface UseActionProps extends UseToggleProps, UseDismissProps {
|
|
40
|
-
toggle?: ToggleType;
|
|
41
|
-
dismiss?: DismissType;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getActionHook(toggle?: ToggleType, dismiss?: DismissType) {
|
|
45
|
-
if (toggle) {
|
|
46
|
-
return typeof toggle === 'function' ? toggle : toggle.useToggle;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (dismiss) {
|
|
50
|
-
return typeof dismiss === 'function' ? dismiss : dismiss.useDismiss;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default function useAction<T, P>(
|
|
57
|
-
props: UseActionProps & P,
|
|
58
|
-
ref: React.Ref<T>,
|
|
59
|
-
) {
|
|
60
|
-
const { toggle, dismiss, ...restProps } = props;
|
|
61
|
-
|
|
62
|
-
const useActionHook = getActionHook(toggle, dismiss);
|
|
63
|
-
|
|
64
|
-
if (!useActionHook) {
|
|
65
|
-
return [restProps, ref] as const;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof useActionHook !== 'function') {
|
|
69
|
-
throw new Error('Action hook must be of type function.');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// TODO: Remove as and define return type on ActionFunction
|
|
73
|
-
const { ref: actionRef, ...actionProps } = useActionHook(restProps) as P & {
|
|
74
|
-
ref?: React.Ref<T>;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return [actionProps, actionRef ? concatRefs(actionRef, ref) : ref] as const;
|
|
78
|
-
}
|
|
1
|
+
import type { UseToggleButtonProps } from '../components/buttons/useToggleButton';
|
|
2
|
+
import type { UseToggleCollapseProps } from '../components/collapse/useToggleCollapse';
|
|
3
|
+
import type { UseDismissDropdownProps } from '../components/dropdown/useDismissDropdown';
|
|
4
|
+
import type { UseToggleDropdownProps } from '../components/dropdown/useToggleDropdown';
|
|
5
|
+
import type { UseToggleTabProps } from '../components/nav/useToggleTab';
|
|
6
|
+
import type { UseDismissNavbarProps } from '../components/navbar/useDismissNavbar';
|
|
7
|
+
import type { UseToggleNavbarProps } from '../components/navbar/useToggleNavbar';
|
|
8
|
+
import { concatRefs } from '../utils';
|
|
9
|
+
|
|
10
|
+
interface UseToggleProps
|
|
11
|
+
extends UseToggleTabProps,
|
|
12
|
+
UseToggleNavbarProps,
|
|
13
|
+
UseToggleButtonProps,
|
|
14
|
+
UseToggleCollapseProps,
|
|
15
|
+
UseToggleDropdownProps {}
|
|
16
|
+
|
|
17
|
+
interface UseDismissProps
|
|
18
|
+
extends UseDismissDropdownProps,
|
|
19
|
+
UseDismissNavbarProps {}
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
type ToggleFunction = <T>(props: T & UseToggleProps) => any;
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
type DismissFunction = <T>(props: T & UseDismissProps) => any;
|
|
26
|
+
|
|
27
|
+
type ToggleType =
|
|
28
|
+
| ToggleFunction
|
|
29
|
+
| {
|
|
30
|
+
useToggle: ToggleFunction;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type DismissType =
|
|
34
|
+
| DismissFunction
|
|
35
|
+
| {
|
|
36
|
+
useDismiss: DismissFunction;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export interface UseActionProps extends UseToggleProps, UseDismissProps {
|
|
40
|
+
toggle?: ToggleType;
|
|
41
|
+
dismiss?: DismissType;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getActionHook(toggle?: ToggleType, dismiss?: DismissType) {
|
|
45
|
+
if (toggle) {
|
|
46
|
+
return typeof toggle === 'function' ? toggle : toggle.useToggle;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (dismiss) {
|
|
50
|
+
return typeof dismiss === 'function' ? dismiss : dismiss.useDismiss;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default function useAction<T, P>(
|
|
57
|
+
props: UseActionProps & P,
|
|
58
|
+
ref: React.Ref<T>,
|
|
59
|
+
) {
|
|
60
|
+
const { toggle, dismiss, ...restProps } = props;
|
|
61
|
+
|
|
62
|
+
const useActionHook = getActionHook(toggle, dismiss);
|
|
63
|
+
|
|
64
|
+
if (!useActionHook) {
|
|
65
|
+
return [restProps, ref] as const;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof useActionHook !== 'function') {
|
|
69
|
+
throw new Error('Action hook must be of type function.');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// TODO: Remove as and define return type on ActionFunction
|
|
73
|
+
const { ref: actionRef, ...actionProps } = useActionHook(restProps) as P & {
|
|
74
|
+
ref?: React.Ref<T>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return [actionProps, actionRef ? concatRefs(actionRef, ref) : ref] as const;
|
|
78
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { I18nManager, StyleSheet, View } from 'react-native';
|
|
3
3
|
import { SvgXml } from 'react-native-svg';
|
|
4
|
-
import type { BaseStyle
|
|
4
|
+
import type { BaseStyle } from '../types';
|
|
5
|
+
|
|
6
|
+
type Position = 'center' | 'left' | 'right' | 'top' | 'bottom';
|
|
5
7
|
|
|
6
8
|
type BackgroundSize = 'cover' | 'contain' | { width: number; height: number };
|
|
7
9
|
|
|
@@ -94,7 +96,7 @@ const transforms = {
|
|
|
94
96
|
height,
|
|
95
97
|
};
|
|
96
98
|
},
|
|
97
|
-
backgroundPosition(value:
|
|
99
|
+
backgroundPosition(value: Position) {
|
|
98
100
|
if (value === 'center') {
|
|
99
101
|
return {
|
|
100
102
|
alignItems: 'center',
|
|
@@ -123,7 +125,7 @@ const transforms = {
|
|
|
123
125
|
return null;
|
|
124
126
|
},
|
|
125
127
|
backgroundPositionX(
|
|
126
|
-
value:
|
|
128
|
+
value: Position | { position: Position; offset: number },
|
|
127
129
|
) {
|
|
128
130
|
const { position = 'left', offset } =
|
|
129
131
|
typeof value === 'object'
|
|
@@ -139,7 +141,7 @@ const transforms = {
|
|
|
139
141
|
return horizontalPosition(offset);
|
|
140
142
|
},
|
|
141
143
|
backgroundPositionY(
|
|
142
|
-
value:
|
|
144
|
+
value: Position | { position: Position; offset: number },
|
|
143
145
|
) {
|
|
144
146
|
const { position = 'top', offset } =
|
|
145
147
|
typeof value === 'object'
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { AriaFocusRingProps, FocusRingAria } from '@react-aria/focus';
|
|
2
|
+
|
|
3
|
+
export default function useFocusRing(
|
|
4
|
+
// @ts-expect-error Argument props is used on web only
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
6
|
+
props?: AriaFocusRingProps,
|
|
7
|
+
): FocusRingAria {
|
|
8
|
+
return {
|
|
9
|
+
isFocused: false,
|
|
10
|
+
isFocusVisible: false,
|
|
11
|
+
focusProps: {},
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,81 +1,75 @@
|
|
|
1
|
-
import { useState, useMemo } from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
const interaction = { hover, focus, focusVisible, active };
|
|
79
|
-
|
|
80
|
-
return { interaction, interactionProps };
|
|
81
|
-
}
|
|
1
|
+
import { useState, useMemo } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
MouseEvent,
|
|
4
|
+
GestureResponderEvent,
|
|
5
|
+
FocusEvent,
|
|
6
|
+
BlurEvent,
|
|
7
|
+
} from 'react-native';
|
|
8
|
+
import useFocusRing from './useFocusRing';
|
|
9
|
+
|
|
10
|
+
type InteractionProps = {
|
|
11
|
+
onFocus?: null | ((event: FocusEvent) => void) | undefined;
|
|
12
|
+
onBlur?: null | ((event: BlurEvent) => void) | undefined;
|
|
13
|
+
onHoverIn?: null | ((event: MouseEvent) => void) | undefined;
|
|
14
|
+
onHoverOut?: null | ((event: MouseEvent) => void) | undefined;
|
|
15
|
+
onPressIn?: null | ((event: GestureResponderEvent) => void) | undefined;
|
|
16
|
+
onPressOut?: null | ((event: GestureResponderEvent) => void) | undefined;
|
|
17
|
+
autoFocus?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default function useInteractionState({
|
|
21
|
+
onFocus,
|
|
22
|
+
onBlur,
|
|
23
|
+
onHoverIn,
|
|
24
|
+
onHoverOut,
|
|
25
|
+
onPressIn,
|
|
26
|
+
onPressOut,
|
|
27
|
+
autoFocus,
|
|
28
|
+
}: InteractionProps) {
|
|
29
|
+
const [active, setActive] = useState(false);
|
|
30
|
+
const [hover, setHovered] = useState(false);
|
|
31
|
+
|
|
32
|
+
const focusRingProps = useFocusRing({ autoFocus });
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
isFocused: focus,
|
|
36
|
+
isFocusVisible: focusVisible,
|
|
37
|
+
focusProps,
|
|
38
|
+
} = focusRingProps;
|
|
39
|
+
|
|
40
|
+
const interactionProps = useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
onHoverIn(event: MouseEvent) {
|
|
43
|
+
setHovered(true);
|
|
44
|
+
onHoverIn?.(event);
|
|
45
|
+
},
|
|
46
|
+
onHoverOut(event: MouseEvent) {
|
|
47
|
+
setHovered(false);
|
|
48
|
+
onHoverOut?.(event);
|
|
49
|
+
},
|
|
50
|
+
onFocus(event: FocusEvent) {
|
|
51
|
+
// @ts-expect-error We can use the native event for a web prop here.
|
|
52
|
+
focusProps.onFocus?.(event);
|
|
53
|
+
onFocus?.(event);
|
|
54
|
+
},
|
|
55
|
+
onBlur(event: BlurEvent) {
|
|
56
|
+
// @ts-expect-error We can use the native event for a web prop here.
|
|
57
|
+
focusProps.onBlur?.(event);
|
|
58
|
+
onBlur?.(event);
|
|
59
|
+
},
|
|
60
|
+
onPressIn(event: GestureResponderEvent) {
|
|
61
|
+
setActive(true);
|
|
62
|
+
onPressIn?.(event);
|
|
63
|
+
},
|
|
64
|
+
onPressOut(event: GestureResponderEvent) {
|
|
65
|
+
setActive(false);
|
|
66
|
+
onPressOut?.(event);
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
[onFocus, onBlur, onHoverIn, onHoverOut, onPressIn, onPressOut, focusProps],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const interaction = { hover, focus, focusVisible, active };
|
|
73
|
+
|
|
74
|
+
return { interaction, interactionProps };
|
|
75
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
GestureResponderEvent,
|
|
4
|
+
type LayoutChangeEvent,
|
|
5
|
+
type LayoutRectangle,
|
|
6
|
+
} from 'react-native';
|
|
7
|
+
import { useRelativePosition, type LayoutPosition } from '@rn-primitives/hooks';
|
|
8
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
9
|
+
import useControlledState from './useControlledState';
|
|
10
|
+
import { type ViewRef } from '../components/View';
|
|
11
|
+
import { type PressableRef } from '../components/Pressable';
|
|
12
|
+
import type {
|
|
13
|
+
OverlayTrigger,
|
|
14
|
+
OverlayAlignment,
|
|
15
|
+
OverlayPlacement,
|
|
16
|
+
OverlayPhysicalPlacement,
|
|
17
|
+
} from '../types';
|
|
18
|
+
|
|
19
|
+
type UseOverlayOptions = {
|
|
20
|
+
defaultVisible: boolean;
|
|
21
|
+
controlledVisible: boolean | undefined;
|
|
22
|
+
onToggle: (value: boolean) => void;
|
|
23
|
+
offset: number;
|
|
24
|
+
align: OverlayAlignment;
|
|
25
|
+
placement: OverlayPlacement;
|
|
26
|
+
trigger?: OverlayTrigger;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const transformAlign = (align: OverlayAlignment) => {
|
|
30
|
+
if (align === 'top') {
|
|
31
|
+
return 'start';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (align === 'bottom') {
|
|
35
|
+
return 'end';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return align;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getNativePlacement = (placement: OverlayPlacement) => {
|
|
42
|
+
// Currently on native only top and bottom is supported.
|
|
43
|
+
if (placement !== 'top') {
|
|
44
|
+
return 'bottom';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return placement;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default function useOverlay({
|
|
51
|
+
defaultVisible,
|
|
52
|
+
controlledVisible,
|
|
53
|
+
onToggle,
|
|
54
|
+
offset,
|
|
55
|
+
align,
|
|
56
|
+
placement,
|
|
57
|
+
}: UseOverlayOptions) {
|
|
58
|
+
const identifier = useId();
|
|
59
|
+
|
|
60
|
+
const triggerRef = useRef<PressableRef | null>(null);
|
|
61
|
+
const contentRef = useRef<ViewRef | null>(null);
|
|
62
|
+
|
|
63
|
+
const [triggerPosition, setTriggerPosition] = useState<LayoutPosition | null>(
|
|
64
|
+
null,
|
|
65
|
+
);
|
|
66
|
+
const [contentLayout, setContentLayout] = useState<LayoutRectangle | null>(
|
|
67
|
+
null,
|
|
68
|
+
);
|
|
69
|
+
const [arrowLayout, setArrowLayout] = useState<LayoutRectangle | null>(null);
|
|
70
|
+
|
|
71
|
+
const handleToggle = useCallback(
|
|
72
|
+
(value: boolean) => {
|
|
73
|
+
if (value) {
|
|
74
|
+
triggerRef.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
75
|
+
setTriggerPosition({ width, pageX, pageY, height });
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
setTriggerPosition(null);
|
|
79
|
+
setContentLayout(null);
|
|
80
|
+
setArrowLayout(null);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
onToggle?.(value);
|
|
84
|
+
},
|
|
85
|
+
[onToggle],
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const [visible, setVisible] = useControlledState(
|
|
89
|
+
defaultVisible,
|
|
90
|
+
controlledVisible,
|
|
91
|
+
handleToggle,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
const insets = useSafeAreaInsets();
|
|
95
|
+
|
|
96
|
+
const nativePlacement = getNativePlacement(placement);
|
|
97
|
+
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
+
const positionStyle = useRelativePosition({
|
|
100
|
+
avoidCollisions: true,
|
|
101
|
+
triggerPosition,
|
|
102
|
+
contentLayout,
|
|
103
|
+
insets,
|
|
104
|
+
align: transformAlign(align),
|
|
105
|
+
alignOffset: 0,
|
|
106
|
+
side: nativePlacement,
|
|
107
|
+
sideOffset: offset,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Note: We do not use hover and focus trigger, so the trigger is always press.
|
|
111
|
+
const getTriggerProps = useCallback(
|
|
112
|
+
(
|
|
113
|
+
props: { onPress?: (event: GestureResponderEvent) => void } & Record<
|
|
114
|
+
string,
|
|
115
|
+
unknown
|
|
116
|
+
>,
|
|
117
|
+
) => ({
|
|
118
|
+
onPress: (event: GestureResponderEvent) => {
|
|
119
|
+
setVisible((value) => !value);
|
|
120
|
+
props.onPress?.(event);
|
|
121
|
+
},
|
|
122
|
+
}),
|
|
123
|
+
[],
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
const getContentProps = useCallback(
|
|
127
|
+
(
|
|
128
|
+
props: { onLayout?: (event: LayoutChangeEvent) => void } & Record<
|
|
129
|
+
string,
|
|
130
|
+
unknown
|
|
131
|
+
>,
|
|
132
|
+
) => ({
|
|
133
|
+
onLayout: (event: LayoutChangeEvent) => {
|
|
134
|
+
setContentLayout(event.nativeEvent.layout);
|
|
135
|
+
|
|
136
|
+
props.onLayout?.(event);
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
[],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const getArrowProps = useCallback(
|
|
143
|
+
(
|
|
144
|
+
props: { onLayout?: (event: LayoutChangeEvent) => void } & Record<
|
|
145
|
+
string,
|
|
146
|
+
unknown
|
|
147
|
+
>,
|
|
148
|
+
) => ({
|
|
149
|
+
onLayout: (event: LayoutChangeEvent) => {
|
|
150
|
+
setArrowLayout(event.nativeEvent.layout);
|
|
151
|
+
|
|
152
|
+
props.onLayout?.(event);
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
[],
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
const arrowStyle = useMemo(() => {
|
|
159
|
+
if (!contentLayout || !arrowLayout || !triggerPosition) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const triggerCenter = triggerPosition.pageX + triggerPosition.width / 2;
|
|
164
|
+
const contentCenter = contentLayout.x + contentLayout.width / 2;
|
|
165
|
+
const shift = triggerCenter - contentCenter;
|
|
166
|
+
|
|
167
|
+
return contentLayout
|
|
168
|
+
? {
|
|
169
|
+
left: contentLayout.width / 2 - arrowLayout.width / 2 + shift,
|
|
170
|
+
}
|
|
171
|
+
: null;
|
|
172
|
+
}, [contentLayout, arrowLayout, triggerPosition]);
|
|
173
|
+
|
|
174
|
+
return useMemo(
|
|
175
|
+
() => ({
|
|
176
|
+
identifier,
|
|
177
|
+
visible,
|
|
178
|
+
setVisible,
|
|
179
|
+
placement: nativePlacement as OverlayPhysicalPlacement,
|
|
180
|
+
trigger: {
|
|
181
|
+
ref: triggerRef,
|
|
182
|
+
getProps: getTriggerProps,
|
|
183
|
+
},
|
|
184
|
+
content: {
|
|
185
|
+
ref: contentRef,
|
|
186
|
+
getProps: getContentProps,
|
|
187
|
+
style: positionStyle,
|
|
188
|
+
},
|
|
189
|
+
arrow: {
|
|
190
|
+
ref: null,
|
|
191
|
+
getProps: getArrowProps,
|
|
192
|
+
style: arrowStyle,
|
|
193
|
+
},
|
|
194
|
+
}),
|
|
195
|
+
[visible, placement, positionStyle, arrowStyle],
|
|
196
|
+
);
|
|
197
|
+
}
|