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.
Files changed (287) hide show
  1. package/lib/module/Context.js.map +1 -1
  2. package/lib/module/Provider.js +3 -7
  3. package/lib/module/Provider.js.map +1 -1
  4. package/lib/module/components/Body.js +8 -1
  5. package/lib/module/components/Body.js.map +1 -1
  6. package/lib/module/components/buttons/Button.js +10 -8
  7. package/lib/module/components/buttons/Button.js.map +1 -1
  8. package/lib/module/components/close/CloseButton.js +7 -3
  9. package/lib/module/components/close/CloseButton.js.map +1 -1
  10. package/lib/module/components/collapse/useCollapse.js +2 -3
  11. package/lib/module/components/collapse/useCollapse.js.map +1 -1
  12. package/lib/module/components/dropdown/Dropdown.js +1 -2
  13. package/lib/module/components/dropdown/Dropdown.js.map +1 -1
  14. package/lib/module/components/dropdown/DropdownContext.js.map +1 -1
  15. package/lib/module/components/dropdown/DropdownMenu.js +33 -59
  16. package/lib/module/components/dropdown/DropdownMenu.js.map +1 -1
  17. package/lib/module/components/dropdown/useDismissDropdown.js +5 -4
  18. package/lib/module/components/dropdown/useDismissDropdown.js.map +1 -1
  19. package/lib/module/components/dropdown/useDropdown.js +35 -11
  20. package/lib/module/components/dropdown/useDropdown.js.map +1 -1
  21. package/lib/module/components/dropdown/useToggleDropdown.js +4 -6
  22. package/lib/module/components/dropdown/useToggleDropdown.js.map +1 -1
  23. package/lib/module/components/forms/FormCheckInput.js +1 -1
  24. package/lib/module/components/forms/Input.js +1 -1
  25. package/lib/module/components/forms/internals/PickerNative.js +1 -1
  26. package/lib/module/components/forms/internals/PickerNative.js.map +1 -1
  27. package/lib/module/components/helpers/BackdropHandler.js +6 -92
  28. package/lib/module/components/helpers/BackdropHandler.js.map +1 -1
  29. package/lib/module/components/helpers/BackdropHandler.web.js +8 -0
  30. package/lib/module/components/helpers/BackdropHandler.web.js.map +1 -0
  31. package/lib/module/components/helpers/Dialog.js +29 -0
  32. package/lib/module/components/helpers/Dialog.js.map +1 -0
  33. package/lib/module/components/helpers/Dialog.web.js +117 -0
  34. package/lib/module/components/helpers/Dialog.web.js.map +1 -0
  35. package/lib/module/components/helpers/Portal.js +5 -0
  36. package/lib/module/components/helpers/Portal.js.map +1 -0
  37. package/lib/module/components/helpers/Portal.web.js +16 -0
  38. package/lib/module/components/helpers/Portal.web.js.map +1 -0
  39. package/lib/module/components/helpers/PortalHost.js +5 -0
  40. package/lib/module/components/helpers/PortalHost.js.map +1 -0
  41. package/lib/module/components/helpers/PortalHost.web.js +15 -0
  42. package/lib/module/components/helpers/PortalHost.web.js.map +1 -0
  43. package/lib/module/components/modal/Modal.js +58 -48
  44. package/lib/module/components/modal/Modal.js.map +1 -1
  45. package/lib/module/components/modal/ModalContext.js.map +1 -1
  46. package/lib/module/components/modal/ModalTitle.js +6 -0
  47. package/lib/module/components/modal/ModalTitle.js.map +1 -1
  48. package/lib/module/components/modal/useModal.js +4 -13
  49. package/lib/module/components/modal/useModal.js.map +1 -1
  50. package/lib/module/components/nav/useTabbable.js +2 -3
  51. package/lib/module/components/nav/useTabbable.js.map +1 -1
  52. package/lib/module/components/navbar/NavbarToggler.js +1 -1
  53. package/lib/module/components/navbar/useNavbar.js +2 -3
  54. package/lib/module/components/navbar/useNavbar.js.map +1 -1
  55. package/lib/module/components/offcanvas/Offcanvas.js +84 -82
  56. package/lib/module/components/offcanvas/Offcanvas.js.map +1 -1
  57. package/lib/module/components/offcanvas/OffcanvasContext.js.map +1 -1
  58. package/lib/module/components/offcanvas/OffcanvasTitle.js +6 -0
  59. package/lib/module/components/offcanvas/OffcanvasTitle.js.map +1 -1
  60. package/lib/module/components/offcanvas/useOffcanvas.js +6 -14
  61. package/lib/module/components/offcanvas/useOffcanvas.js.map +1 -1
  62. package/lib/module/components/pagination/PaginationItem.js +39 -39
  63. package/lib/module/components/popover/Popover.js +6 -8
  64. package/lib/module/components/popover/Popover.js.map +1 -1
  65. package/lib/module/components/popover/PopoverArrow.js +18 -9
  66. package/lib/module/components/popover/PopoverArrow.js.map +1 -1
  67. package/lib/module/components/popover/PopoverContext.js.map +1 -1
  68. package/lib/module/components/popover/injectPopover.js +48 -45
  69. package/lib/module/components/popover/injectPopover.js.map +1 -1
  70. package/lib/module/components/tooltip/Tooltip.js +7 -23
  71. package/lib/module/components/tooltip/Tooltip.js.map +1 -1
  72. package/lib/module/components/tooltip/TooltipArrow.js +22 -12
  73. package/lib/module/components/tooltip/TooltipArrow.js.map +1 -1
  74. package/lib/module/components/tooltip/TooltipContext.js.map +1 -1
  75. package/lib/module/components/tooltip/injectTooltip.js +46 -42
  76. package/lib/module/components/tooltip/injectTooltip.js.map +1 -1
  77. package/lib/module/hooks/useBackgroundNative.js.map +1 -1
  78. package/lib/module/hooks/useFocusRing.js +13 -0
  79. package/lib/module/hooks/useFocusRing.js.map +1 -0
  80. package/lib/module/hooks/useFocusRing.web.js +5 -0
  81. package/lib/module/hooks/useFocusRing.web.js.map +1 -0
  82. package/lib/module/hooks/useInteractionState.js +11 -11
  83. package/lib/module/hooks/useInteractionState.js.map +1 -1
  84. package/lib/module/hooks/useOverlay.js +121 -0
  85. package/lib/module/hooks/useOverlay.js.map +1 -0
  86. package/lib/module/hooks/useOverlay.web.js +113 -0
  87. package/lib/module/hooks/useOverlay.web.js.map +1 -0
  88. package/lib/module/hooks/useScrollbarEffects.js +7 -60
  89. package/lib/module/hooks/useScrollbarEffects.js.map +1 -1
  90. package/lib/module/hooks/useScrollbarEffects.web.js +59 -0
  91. package/lib/module/hooks/useScrollbarEffects.web.js.map +1 -0
  92. package/lib/module/index.js +3 -3
  93. package/lib/module/index.js.map +1 -1
  94. package/lib/module/style/StyleSheet.js +1 -3
  95. package/lib/module/style/StyleSheet.js.map +1 -1
  96. package/lib/module/theme/variables.js +9 -9
  97. package/lib/module/utils.js +0 -11
  98. package/lib/module/utils.js.map +1 -1
  99. package/lib/typescript/Context.d.ts +0 -1
  100. package/lib/typescript/Context.d.ts.map +1 -1
  101. package/lib/typescript/Provider.d.ts.map +1 -1
  102. package/lib/typescript/components/Body.d.ts.map +1 -1
  103. package/lib/typescript/components/Link.d.ts +1 -1
  104. package/lib/typescript/components/Link.d.ts.map +1 -1
  105. package/lib/typescript/components/Pressable.d.ts +1 -1
  106. package/lib/typescript/components/Pressable.d.ts.map +1 -1
  107. package/lib/typescript/components/TextInput.d.ts +3 -3
  108. package/lib/typescript/components/TextInput.d.ts.map +1 -1
  109. package/lib/typescript/components/buttons/Button.d.ts +1 -1
  110. package/lib/typescript/components/buttons/Button.d.ts.map +1 -1
  111. package/lib/typescript/components/close/CloseButton.d.ts +1 -1
  112. package/lib/typescript/components/close/CloseButton.d.ts.map +1 -1
  113. package/lib/typescript/components/collapse/useCollapse.d.ts.map +1 -1
  114. package/lib/typescript/components/dropdown/Dropdown.d.ts +0 -1
  115. package/lib/typescript/components/dropdown/Dropdown.d.ts.map +1 -1
  116. package/lib/typescript/components/dropdown/DropdownContext.d.ts +14 -3
  117. package/lib/typescript/components/dropdown/DropdownContext.d.ts.map +1 -1
  118. package/lib/typescript/components/dropdown/DropdownMenu.d.ts +0 -1
  119. package/lib/typescript/components/dropdown/DropdownMenu.d.ts.map +1 -1
  120. package/lib/typescript/components/dropdown/useDismissDropdown.d.ts +1 -1
  121. package/lib/typescript/components/dropdown/useDismissDropdown.d.ts.map +1 -1
  122. package/lib/typescript/components/dropdown/useDropdown.d.ts +38 -4
  123. package/lib/typescript/components/dropdown/useDropdown.d.ts.map +1 -1
  124. package/lib/typescript/components/dropdown/useToggleDropdown.d.ts +4 -3
  125. package/lib/typescript/components/dropdown/useToggleDropdown.d.ts.map +1 -1
  126. package/lib/typescript/components/forms/Picker.d.ts +1 -1
  127. package/lib/typescript/components/forms/internals/PickerNative.d.ts +1 -1
  128. package/lib/typescript/components/forms/internals/PickerNative.d.ts.map +1 -1
  129. package/lib/typescript/components/forms/internals/PickerWeb.d.ts +1 -1
  130. package/lib/typescript/components/forms/internals/PickerWeb.d.ts.map +1 -1
  131. package/lib/typescript/components/helpers/BackdropHandler.d.ts +2 -11
  132. package/lib/typescript/components/helpers/BackdropHandler.d.ts.map +1 -1
  133. package/lib/typescript/components/helpers/BackdropHandler.web.d.ts +3 -0
  134. package/lib/typescript/components/helpers/BackdropHandler.web.d.ts.map +1 -0
  135. package/lib/typescript/components/helpers/Dialog.d.ts +15 -0
  136. package/lib/typescript/components/helpers/Dialog.d.ts.map +1 -0
  137. package/lib/typescript/components/helpers/Dialog.web.d.ts +15 -0
  138. package/lib/typescript/components/helpers/Dialog.web.d.ts.map +1 -0
  139. package/lib/typescript/components/helpers/Portal.d.ts +8 -0
  140. package/lib/typescript/components/helpers/Portal.d.ts.map +1 -0
  141. package/lib/typescript/components/helpers/Portal.web.d.ts +8 -0
  142. package/lib/typescript/components/helpers/Portal.web.d.ts.map +1 -0
  143. package/lib/typescript/components/helpers/PortalHost.d.ts +6 -0
  144. package/lib/typescript/components/helpers/PortalHost.d.ts.map +1 -0
  145. package/lib/typescript/components/helpers/PortalHost.web.d.ts +7 -0
  146. package/lib/typescript/components/helpers/PortalHost.web.d.ts.map +1 -0
  147. package/lib/typescript/components/list-group/ListGroup.d.ts +1 -1
  148. package/lib/typescript/components/list-group/ListGroupItemAction.d.ts +1 -1
  149. package/lib/typescript/components/list-group/ListGroupItemAction.d.ts.map +1 -1
  150. package/lib/typescript/components/modal/Modal.d.ts +1 -1
  151. package/lib/typescript/components/modal/Modal.d.ts.map +1 -1
  152. package/lib/typescript/components/modal/ModalContext.d.ts +1 -0
  153. package/lib/typescript/components/modal/ModalContext.d.ts.map +1 -1
  154. package/lib/typescript/components/modal/ModalTitle.d.ts.map +1 -1
  155. package/lib/typescript/components/modal/useModal.d.ts +2 -1
  156. package/lib/typescript/components/modal/useModal.d.ts.map +1 -1
  157. package/lib/typescript/components/nav/Nav.d.ts +1 -1
  158. package/lib/typescript/components/nav/NavLink.d.ts +1 -1
  159. package/lib/typescript/components/nav/NavLink.d.ts.map +1 -1
  160. package/lib/typescript/components/nav/useTabbable.d.ts.map +1 -1
  161. package/lib/typescript/components/navbar/Navbar.d.ts +2 -2
  162. package/lib/typescript/components/navbar/NavbarBrand.d.ts +1 -1
  163. package/lib/typescript/components/navbar/NavbarBrand.d.ts.map +1 -1
  164. package/lib/typescript/components/navbar/NavbarToggler.d.ts +1 -1
  165. package/lib/typescript/components/navbar/NavbarToggler.d.ts.map +1 -1
  166. package/lib/typescript/components/navbar/useNavbar.d.ts.map +1 -1
  167. package/lib/typescript/components/offcanvas/Offcanvas.d.ts +1 -4
  168. package/lib/typescript/components/offcanvas/Offcanvas.d.ts.map +1 -1
  169. package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts +3 -1
  170. package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts.map +1 -1
  171. package/lib/typescript/components/offcanvas/OffcanvasTitle.d.ts.map +1 -1
  172. package/lib/typescript/components/offcanvas/useOffcanvas.d.ts +3 -1
  173. package/lib/typescript/components/offcanvas/useOffcanvas.d.ts.map +1 -1
  174. package/lib/typescript/components/popover/Popover.d.ts +3 -4
  175. package/lib/typescript/components/popover/Popover.d.ts.map +1 -1
  176. package/lib/typescript/components/popover/PopoverArrow.d.ts.map +1 -1
  177. package/lib/typescript/components/popover/PopoverContext.d.ts +3 -4
  178. package/lib/typescript/components/popover/PopoverContext.d.ts.map +1 -1
  179. package/lib/typescript/components/popover/injectPopover.d.ts +5 -7
  180. package/lib/typescript/components/popover/injectPopover.d.ts.map +1 -1
  181. package/lib/typescript/components/tooltip/Tooltip.d.ts +3 -4
  182. package/lib/typescript/components/tooltip/Tooltip.d.ts.map +1 -1
  183. package/lib/typescript/components/tooltip/TooltipArrow.d.ts.map +1 -1
  184. package/lib/typescript/components/tooltip/TooltipContext.d.ts +3 -4
  185. package/lib/typescript/components/tooltip/TooltipContext.d.ts.map +1 -1
  186. package/lib/typescript/components/tooltip/injectTooltip.d.ts +5 -7
  187. package/lib/typescript/components/tooltip/injectTooltip.d.ts.map +1 -1
  188. package/lib/typescript/hooks/useBackgroundNative.d.ts.map +1 -1
  189. package/lib/typescript/hooks/useFocusRing.d.ts +3 -0
  190. package/lib/typescript/hooks/useFocusRing.d.ts.map +1 -0
  191. package/lib/typescript/hooks/useFocusRing.web.d.ts +3 -0
  192. package/lib/typescript/hooks/useFocusRing.web.d.ts.map +1 -0
  193. package/lib/typescript/hooks/useInteractionState.d.ts +7 -7
  194. package/lib/typescript/hooks/useInteractionState.d.ts.map +1 -1
  195. package/lib/typescript/hooks/useOverlay.d.ts +64 -0
  196. package/lib/typescript/hooks/useOverlay.d.ts.map +1 -0
  197. package/lib/typescript/hooks/useOverlay.web.d.ts +37 -0
  198. package/lib/typescript/hooks/useOverlay.web.d.ts.map +1 -0
  199. package/lib/typescript/hooks/useScrollbarEffects.d.ts.map +1 -1
  200. package/lib/typescript/hooks/useScrollbarEffects.web.d.ts +7 -0
  201. package/lib/typescript/hooks/useScrollbarEffects.web.d.ts.map +1 -0
  202. package/lib/typescript/index.d.ts +5 -4
  203. package/lib/typescript/index.d.ts.map +1 -1
  204. package/lib/typescript/style/StyleSheet.d.ts.map +1 -1
  205. package/lib/typescript/types.d.ts +12 -6
  206. package/lib/typescript/types.d.ts.map +1 -1
  207. package/lib/typescript/utils.d.ts +2 -3
  208. package/lib/typescript/utils.d.ts.map +1 -1
  209. package/package.json +92 -85
  210. package/src/Context.ts +37 -38
  211. package/src/Provider.tsx +61 -66
  212. package/src/components/Body.tsx +16 -1
  213. package/src/components/TextInput.tsx +66 -66
  214. package/src/components/buttons/Button.tsx +381 -379
  215. package/src/components/close/CloseButton.tsx +142 -138
  216. package/src/components/collapse/useCollapse.ts +25 -26
  217. package/src/components/dropdown/Dropdown.tsx +77 -80
  218. package/src/components/dropdown/DropdownContext.ts +14 -3
  219. package/src/components/dropdown/DropdownMenu.tsx +243 -284
  220. package/src/components/dropdown/useDismissDropdown.ts +30 -29
  221. package/src/components/dropdown/useDropdown.ts +55 -38
  222. package/src/components/dropdown/useToggleDropdown.ts +31 -32
  223. package/src/components/forms/FormCheckInput.tsx +268 -268
  224. package/src/components/forms/Input.tsx +220 -220
  225. package/src/components/forms/internals/PickerNative.tsx +9 -10
  226. package/src/components/helpers/BackdropHandler.tsx +5 -119
  227. package/src/components/helpers/BackdropHandler.web.tsx +6 -0
  228. package/src/components/helpers/Dialog.tsx +49 -0
  229. package/src/components/helpers/Dialog.web.tsx +145 -0
  230. package/src/components/helpers/Portal.tsx +10 -0
  231. package/src/components/helpers/Portal.web.tsx +22 -0
  232. package/src/components/helpers/PortalHost.tsx +7 -0
  233. package/src/components/helpers/PortalHost.web.tsx +14 -0
  234. package/src/components/modal/Modal.tsx +60 -48
  235. package/src/components/modal/ModalContext.ts +12 -11
  236. package/src/components/modal/ModalTitle.tsx +41 -31
  237. package/src/components/modal/useModal.ts +13 -25
  238. package/src/components/nav/useTabbable.ts +31 -32
  239. package/src/components/navbar/NavbarToggler.tsx +130 -130
  240. package/src/components/navbar/useNavbar.ts +30 -31
  241. package/src/components/offcanvas/Offcanvas.tsx +91 -92
  242. package/src/components/offcanvas/OffcanvasContext.ts +13 -11
  243. package/src/components/offcanvas/OffcanvasTitle.tsx +43 -33
  244. package/src/components/offcanvas/useOffcanvas.ts +12 -20
  245. package/src/components/pagination/PaginationItem.tsx +139 -139
  246. package/src/components/popover/Popover.tsx +87 -90
  247. package/src/components/popover/PopoverArrow.tsx +22 -6
  248. package/src/components/popover/PopoverContext.ts +13 -18
  249. package/src/components/popover/injectPopover.tsx +63 -55
  250. package/src/components/tooltip/Tooltip.tsx +79 -98
  251. package/src/components/tooltip/TooltipArrow.tsx +26 -8
  252. package/src/components/tooltip/TooltipContext.ts +13 -18
  253. package/src/components/tooltip/injectTooltip.tsx +62 -53
  254. package/src/hooks/useAction.ts +78 -78
  255. package/src/hooks/useBackgroundNative.tsx +6 -4
  256. package/src/hooks/useFocusRing.ts +13 -0
  257. package/src/hooks/useFocusRing.web.ts +3 -0
  258. package/src/hooks/useInteractionState.ts +75 -81
  259. package/src/hooks/useOverlay.ts +197 -0
  260. package/src/hooks/useOverlay.web.ts +190 -0
  261. package/src/hooks/useScrollbarEffects.ts +5 -83
  262. package/src/hooks/useScrollbarEffects.web.ts +83 -0
  263. package/src/index.ts +5 -5
  264. package/src/style/StyleSheet.ts +2 -5
  265. package/src/theme/variables.ts +1420 -1420
  266. package/src/types.ts +14 -14
  267. package/src/utils.ts +4 -22
  268. package/lib/module/components/SafeAreaView.js +0 -42
  269. package/lib/module/components/SafeAreaView.js.map +0 -1
  270. package/lib/module/components/helpers/Overlay.js +0 -50
  271. package/lib/module/components/helpers/Overlay.js.map +0 -1
  272. package/lib/module/hooks/useIdentifier.js +0 -14
  273. package/lib/module/hooks/useIdentifier.js.map +0 -1
  274. package/lib/module/hooks/useTrigger.js +0 -97
  275. package/lib/module/hooks/useTrigger.js.map +0 -1
  276. package/lib/typescript/components/SafeAreaView.d.ts +0 -12
  277. package/lib/typescript/components/SafeAreaView.d.ts.map +0 -1
  278. package/lib/typescript/components/helpers/Overlay.d.ts +0 -28
  279. package/lib/typescript/components/helpers/Overlay.d.ts.map +0 -1
  280. package/lib/typescript/hooks/useIdentifier.d.ts +0 -2
  281. package/lib/typescript/hooks/useIdentifier.d.ts.map +0 -1
  282. package/lib/typescript/hooks/useTrigger.d.ts +0 -33
  283. package/lib/typescript/hooks/useTrigger.d.ts.map +0 -1
  284. package/src/components/SafeAreaView.tsx +0 -64
  285. package/src/components/helpers/Overlay.tsx +0 -81
  286. package/src/hooks/useIdentifier.ts +0 -15
  287. package/src/hooks/useTrigger.ts +0 -141
@@ -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, PlacementAxis } from '../types';
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: PlacementAxis) {
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: PlacementAxis | { position: PlacementAxis; offset: number },
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: PlacementAxis | { position: PlacementAxis; offset: number },
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
+ }
@@ -0,0 +1,3 @@
1
+ import { useFocusRing } from '@react-aria/focus';
2
+
3
+ export default useFocusRing;
@@ -1,81 +1,75 @@
1
- import { useState, useMemo } from 'react';
2
- import type {
3
- TextInputFocusEventData,
4
- NativeSyntheticEvent,
5
- MouseEvent,
6
- GestureResponderEvent,
7
- TargetedEvent,
8
- } from 'react-native';
9
- import { useFocusRing } from '@react-native-aria/focus';
10
-
11
- type InteractionProps = {
12
- onFocus?:
13
- | null
14
- | ((event: NativeSyntheticEvent<TargetedEvent>) => void)
15
- | undefined;
16
- onBlur?:
17
- | null
18
- | ((event: NativeSyntheticEvent<TargetedEvent>) => void)
19
- | undefined;
20
- onHoverIn?: null | ((event: MouseEvent) => void) | undefined;
21
- onHoverOut?: null | ((event: MouseEvent) => void) | undefined;
22
- onPressIn?: null | ((event: GestureResponderEvent) => void) | undefined;
23
- onPressOut?: null | ((event: GestureResponderEvent) => void) | undefined;
24
- autoFocus?: boolean;
25
- };
26
-
27
- export default function useInteractionState({
28
- onFocus,
29
- onBlur,
30
- onHoverIn,
31
- onHoverOut,
32
- onPressIn,
33
- onPressOut,
34
- autoFocus,
35
- }: InteractionProps) {
36
- const [active, setActive] = useState(false);
37
- const [hover, setHovered] = useState(false);
38
-
39
- // @ts-expect-error definition is on @react-aria/focus but not on @react-native-aria/focus
40
- const focusRingProps = useFocusRing({ autoFocus }) as unresolved;
41
-
42
- const {
43
- isFocused: focus,
44
- isFocusVisible: focusVisible,
45
- focusProps,
46
- } = focusRingProps;
47
-
48
- const interactionProps = useMemo(
49
- () => ({
50
- onHoverIn(event: MouseEvent) {
51
- setHovered(true);
52
- if (onHoverIn) onHoverIn(event);
53
- },
54
- onHoverOut(event: MouseEvent) {
55
- setHovered(false);
56
- if (onHoverOut) onHoverOut(event);
57
- },
58
- onFocus(event: NativeSyntheticEvent<TextInputFocusEventData>) {
59
- focusProps.onFocus(event);
60
- if (onFocus) onFocus(event);
61
- },
62
- onBlur(event: NativeSyntheticEvent<TextInputFocusEventData>) {
63
- focusProps.onBlur(event);
64
- if (onBlur) onBlur(event);
65
- },
66
- onPressIn(event: GestureResponderEvent) {
67
- setActive(true);
68
- if (onPressIn) onPressIn(event);
69
- },
70
- onPressOut(event: GestureResponderEvent) {
71
- setActive(false);
72
- if (onPressOut) onPressOut(event);
73
- },
74
- }),
75
- [onFocus, onBlur, onHoverIn, onHoverOut, onPressIn, onPressOut, focusProps],
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
+ }