bootstrap-rn 0.4.6 → 0.4.8

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 (289) 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/Picker.js +1 -1
  26. package/lib/module/components/forms/internals/PickerNative.js +1 -1
  27. package/lib/module/components/forms/internals/PickerNative.js.map +1 -1
  28. package/lib/module/components/helpers/BackdropHandler.js +6 -92
  29. package/lib/module/components/helpers/BackdropHandler.js.map +1 -1
  30. package/lib/module/components/helpers/BackdropHandler.web.js +8 -0
  31. package/lib/module/components/helpers/BackdropHandler.web.js.map +1 -0
  32. package/lib/module/components/helpers/Dialog.js +29 -0
  33. package/lib/module/components/helpers/Dialog.js.map +1 -0
  34. package/lib/module/components/helpers/Dialog.web.js +117 -0
  35. package/lib/module/components/helpers/Dialog.web.js.map +1 -0
  36. package/lib/module/components/helpers/Portal.js +5 -0
  37. package/lib/module/components/helpers/Portal.js.map +1 -0
  38. package/lib/module/components/helpers/Portal.web.js +31 -0
  39. package/lib/module/components/helpers/Portal.web.js.map +1 -0
  40. package/lib/module/components/helpers/PortalHost.js +5 -0
  41. package/lib/module/components/helpers/PortalHost.js.map +1 -0
  42. package/lib/module/components/helpers/PortalHost.web.js +15 -0
  43. package/lib/module/components/helpers/PortalHost.web.js.map +1 -0
  44. package/lib/module/components/modal/Modal.js +58 -48
  45. package/lib/module/components/modal/Modal.js.map +1 -1
  46. package/lib/module/components/modal/ModalContext.js.map +1 -1
  47. package/lib/module/components/modal/ModalTitle.js +6 -0
  48. package/lib/module/components/modal/ModalTitle.js.map +1 -1
  49. package/lib/module/components/modal/useModal.js +4 -13
  50. package/lib/module/components/modal/useModal.js.map +1 -1
  51. package/lib/module/components/nav/useTabbable.js +2 -3
  52. package/lib/module/components/nav/useTabbable.js.map +1 -1
  53. package/lib/module/components/navbar/NavbarToggler.js +1 -1
  54. package/lib/module/components/navbar/useNavbar.js +2 -3
  55. package/lib/module/components/navbar/useNavbar.js.map +1 -1
  56. package/lib/module/components/offcanvas/Offcanvas.js +84 -82
  57. package/lib/module/components/offcanvas/Offcanvas.js.map +1 -1
  58. package/lib/module/components/offcanvas/OffcanvasContext.js.map +1 -1
  59. package/lib/module/components/offcanvas/OffcanvasTitle.js +6 -0
  60. package/lib/module/components/offcanvas/OffcanvasTitle.js.map +1 -1
  61. package/lib/module/components/offcanvas/useOffcanvas.js +6 -14
  62. package/lib/module/components/offcanvas/useOffcanvas.js.map +1 -1
  63. package/lib/module/components/pagination/PaginationItem.js +39 -39
  64. package/lib/module/components/popover/Popover.js +6 -8
  65. package/lib/module/components/popover/Popover.js.map +1 -1
  66. package/lib/module/components/popover/PopoverArrow.js +18 -9
  67. package/lib/module/components/popover/PopoverArrow.js.map +1 -1
  68. package/lib/module/components/popover/PopoverContext.js.map +1 -1
  69. package/lib/module/components/popover/injectPopover.js +48 -45
  70. package/lib/module/components/popover/injectPopover.js.map +1 -1
  71. package/lib/module/components/tooltip/Tooltip.js +7 -23
  72. package/lib/module/components/tooltip/Tooltip.js.map +1 -1
  73. package/lib/module/components/tooltip/TooltipArrow.js +22 -12
  74. package/lib/module/components/tooltip/TooltipArrow.js.map +1 -1
  75. package/lib/module/components/tooltip/TooltipContext.js.map +1 -1
  76. package/lib/module/components/tooltip/injectTooltip.js +46 -42
  77. package/lib/module/components/tooltip/injectTooltip.js.map +1 -1
  78. package/lib/module/hooks/useBackgroundNative.js.map +1 -1
  79. package/lib/module/hooks/useFocusRing.js +13 -0
  80. package/lib/module/hooks/useFocusRing.js.map +1 -0
  81. package/lib/module/hooks/useFocusRing.web.js +5 -0
  82. package/lib/module/hooks/useFocusRing.web.js.map +1 -0
  83. package/lib/module/hooks/useInteractionState.js +11 -11
  84. package/lib/module/hooks/useInteractionState.js.map +1 -1
  85. package/lib/module/hooks/useOverlay.js +121 -0
  86. package/lib/module/hooks/useOverlay.js.map +1 -0
  87. package/lib/module/hooks/useOverlay.web.js +113 -0
  88. package/lib/module/hooks/useOverlay.web.js.map +1 -0
  89. package/lib/module/hooks/useScrollbarEffects.js +7 -60
  90. package/lib/module/hooks/useScrollbarEffects.js.map +1 -1
  91. package/lib/module/hooks/useScrollbarEffects.web.js +59 -0
  92. package/lib/module/hooks/useScrollbarEffects.web.js.map +1 -0
  93. package/lib/module/index.js +3 -3
  94. package/lib/module/index.js.map +1 -1
  95. package/lib/module/style/StyleSheet.js +1 -3
  96. package/lib/module/style/StyleSheet.js.map +1 -1
  97. package/lib/module/theme/variables.js +9 -9
  98. package/lib/module/utils.js +0 -11
  99. package/lib/module/utils.js.map +1 -1
  100. package/lib/typescript/Context.d.ts +0 -1
  101. package/lib/typescript/Context.d.ts.map +1 -1
  102. package/lib/typescript/Provider.d.ts.map +1 -1
  103. package/lib/typescript/components/Body.d.ts.map +1 -1
  104. package/lib/typescript/components/Link.d.ts +1 -1
  105. package/lib/typescript/components/Link.d.ts.map +1 -1
  106. package/lib/typescript/components/Pressable.d.ts +1 -1
  107. package/lib/typescript/components/Pressable.d.ts.map +1 -1
  108. package/lib/typescript/components/TextInput.d.ts +3 -3
  109. package/lib/typescript/components/TextInput.d.ts.map +1 -1
  110. package/lib/typescript/components/buttons/Button.d.ts +1 -1
  111. package/lib/typescript/components/buttons/Button.d.ts.map +1 -1
  112. package/lib/typescript/components/close/CloseButton.d.ts +1 -1
  113. package/lib/typescript/components/close/CloseButton.d.ts.map +1 -1
  114. package/lib/typescript/components/collapse/useCollapse.d.ts.map +1 -1
  115. package/lib/typescript/components/dropdown/Dropdown.d.ts +0 -1
  116. package/lib/typescript/components/dropdown/Dropdown.d.ts.map +1 -1
  117. package/lib/typescript/components/dropdown/DropdownContext.d.ts +14 -3
  118. package/lib/typescript/components/dropdown/DropdownContext.d.ts.map +1 -1
  119. package/lib/typescript/components/dropdown/DropdownMenu.d.ts +0 -1
  120. package/lib/typescript/components/dropdown/DropdownMenu.d.ts.map +1 -1
  121. package/lib/typescript/components/dropdown/useDismissDropdown.d.ts +1 -1
  122. package/lib/typescript/components/dropdown/useDismissDropdown.d.ts.map +1 -1
  123. package/lib/typescript/components/dropdown/useDropdown.d.ts +38 -4
  124. package/lib/typescript/components/dropdown/useDropdown.d.ts.map +1 -1
  125. package/lib/typescript/components/dropdown/useToggleDropdown.d.ts +4 -3
  126. package/lib/typescript/components/dropdown/useToggleDropdown.d.ts.map +1 -1
  127. package/lib/typescript/components/forms/Picker.d.ts +1 -1
  128. package/lib/typescript/components/forms/internals/PickerNative.d.ts +1 -1
  129. package/lib/typescript/components/forms/internals/PickerNative.d.ts.map +1 -1
  130. package/lib/typescript/components/forms/internals/PickerWeb.d.ts +1 -1
  131. package/lib/typescript/components/forms/internals/PickerWeb.d.ts.map +1 -1
  132. package/lib/typescript/components/helpers/BackdropHandler.d.ts +2 -11
  133. package/lib/typescript/components/helpers/BackdropHandler.d.ts.map +1 -1
  134. package/lib/typescript/components/helpers/BackdropHandler.web.d.ts +3 -0
  135. package/lib/typescript/components/helpers/BackdropHandler.web.d.ts.map +1 -0
  136. package/lib/typescript/components/helpers/Dialog.d.ts +15 -0
  137. package/lib/typescript/components/helpers/Dialog.d.ts.map +1 -0
  138. package/lib/typescript/components/helpers/Dialog.web.d.ts +15 -0
  139. package/lib/typescript/components/helpers/Dialog.web.d.ts.map +1 -0
  140. package/lib/typescript/components/helpers/Portal.d.ts +8 -0
  141. package/lib/typescript/components/helpers/Portal.d.ts.map +1 -0
  142. package/lib/typescript/components/helpers/Portal.web.d.ts +8 -0
  143. package/lib/typescript/components/helpers/Portal.web.d.ts.map +1 -0
  144. package/lib/typescript/components/helpers/PortalHost.d.ts +6 -0
  145. package/lib/typescript/components/helpers/PortalHost.d.ts.map +1 -0
  146. package/lib/typescript/components/helpers/PortalHost.web.d.ts +7 -0
  147. package/lib/typescript/components/helpers/PortalHost.web.d.ts.map +1 -0
  148. package/lib/typescript/components/list-group/ListGroup.d.ts +1 -1
  149. package/lib/typescript/components/list-group/ListGroupItemAction.d.ts +1 -1
  150. package/lib/typescript/components/list-group/ListGroupItemAction.d.ts.map +1 -1
  151. package/lib/typescript/components/modal/Modal.d.ts +1 -1
  152. package/lib/typescript/components/modal/Modal.d.ts.map +1 -1
  153. package/lib/typescript/components/modal/ModalContext.d.ts +1 -0
  154. package/lib/typescript/components/modal/ModalContext.d.ts.map +1 -1
  155. package/lib/typescript/components/modal/ModalTitle.d.ts.map +1 -1
  156. package/lib/typescript/components/modal/useModal.d.ts +2 -1
  157. package/lib/typescript/components/modal/useModal.d.ts.map +1 -1
  158. package/lib/typescript/components/nav/Nav.d.ts +1 -1
  159. package/lib/typescript/components/nav/NavLink.d.ts +1 -1
  160. package/lib/typescript/components/nav/NavLink.d.ts.map +1 -1
  161. package/lib/typescript/components/nav/useTabbable.d.ts.map +1 -1
  162. package/lib/typescript/components/navbar/Navbar.d.ts +2 -2
  163. package/lib/typescript/components/navbar/NavbarBrand.d.ts +1 -1
  164. package/lib/typescript/components/navbar/NavbarBrand.d.ts.map +1 -1
  165. package/lib/typescript/components/navbar/NavbarToggler.d.ts +1 -1
  166. package/lib/typescript/components/navbar/NavbarToggler.d.ts.map +1 -1
  167. package/lib/typescript/components/navbar/useNavbar.d.ts.map +1 -1
  168. package/lib/typescript/components/offcanvas/Offcanvas.d.ts +1 -4
  169. package/lib/typescript/components/offcanvas/Offcanvas.d.ts.map +1 -1
  170. package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts +3 -1
  171. package/lib/typescript/components/offcanvas/OffcanvasContext.d.ts.map +1 -1
  172. package/lib/typescript/components/offcanvas/OffcanvasTitle.d.ts.map +1 -1
  173. package/lib/typescript/components/offcanvas/useOffcanvas.d.ts +3 -1
  174. package/lib/typescript/components/offcanvas/useOffcanvas.d.ts.map +1 -1
  175. package/lib/typescript/components/popover/Popover.d.ts +3 -4
  176. package/lib/typescript/components/popover/Popover.d.ts.map +1 -1
  177. package/lib/typescript/components/popover/PopoverArrow.d.ts.map +1 -1
  178. package/lib/typescript/components/popover/PopoverContext.d.ts +3 -4
  179. package/lib/typescript/components/popover/PopoverContext.d.ts.map +1 -1
  180. package/lib/typescript/components/popover/injectPopover.d.ts +5 -7
  181. package/lib/typescript/components/popover/injectPopover.d.ts.map +1 -1
  182. package/lib/typescript/components/tooltip/Tooltip.d.ts +3 -4
  183. package/lib/typescript/components/tooltip/Tooltip.d.ts.map +1 -1
  184. package/lib/typescript/components/tooltip/TooltipArrow.d.ts.map +1 -1
  185. package/lib/typescript/components/tooltip/TooltipContext.d.ts +3 -4
  186. package/lib/typescript/components/tooltip/TooltipContext.d.ts.map +1 -1
  187. package/lib/typescript/components/tooltip/injectTooltip.d.ts +5 -7
  188. package/lib/typescript/components/tooltip/injectTooltip.d.ts.map +1 -1
  189. package/lib/typescript/hooks/useBackgroundNative.d.ts.map +1 -1
  190. package/lib/typescript/hooks/useFocusRing.d.ts +3 -0
  191. package/lib/typescript/hooks/useFocusRing.d.ts.map +1 -0
  192. package/lib/typescript/hooks/useFocusRing.web.d.ts +3 -0
  193. package/lib/typescript/hooks/useFocusRing.web.d.ts.map +1 -0
  194. package/lib/typescript/hooks/useInteractionState.d.ts +7 -7
  195. package/lib/typescript/hooks/useInteractionState.d.ts.map +1 -1
  196. package/lib/typescript/hooks/useOverlay.d.ts +64 -0
  197. package/lib/typescript/hooks/useOverlay.d.ts.map +1 -0
  198. package/lib/typescript/hooks/useOverlay.web.d.ts +37 -0
  199. package/lib/typescript/hooks/useOverlay.web.d.ts.map +1 -0
  200. package/lib/typescript/hooks/useScrollbarEffects.d.ts.map +1 -1
  201. package/lib/typescript/hooks/useScrollbarEffects.web.d.ts +7 -0
  202. package/lib/typescript/hooks/useScrollbarEffects.web.d.ts.map +1 -0
  203. package/lib/typescript/index.d.ts +5 -4
  204. package/lib/typescript/index.d.ts.map +1 -1
  205. package/lib/typescript/style/StyleSheet.d.ts.map +1 -1
  206. package/lib/typescript/types.d.ts +12 -6
  207. package/lib/typescript/types.d.ts.map +1 -1
  208. package/lib/typescript/utils.d.ts +2 -3
  209. package/lib/typescript/utils.d.ts.map +1 -1
  210. package/package.json +28 -21
  211. package/src/Context.ts +37 -38
  212. package/src/Provider.tsx +61 -66
  213. package/src/components/Body.tsx +68 -53
  214. package/src/components/TextInput.tsx +66 -66
  215. package/src/components/buttons/Button.tsx +381 -379
  216. package/src/components/close/CloseButton.tsx +142 -138
  217. package/src/components/collapse/useCollapse.ts +25 -26
  218. package/src/components/dropdown/Dropdown.tsx +77 -80
  219. package/src/components/dropdown/DropdownContext.ts +14 -3
  220. package/src/components/dropdown/DropdownMenu.tsx +243 -284
  221. package/src/components/dropdown/useDismissDropdown.ts +30 -29
  222. package/src/components/dropdown/useDropdown.ts +55 -38
  223. package/src/components/dropdown/useToggleDropdown.ts +31 -32
  224. package/src/components/forms/FormCheckInput.tsx +268 -268
  225. package/src/components/forms/Input.tsx +220 -220
  226. package/src/components/forms/Picker.tsx +1 -1
  227. package/src/components/forms/internals/PickerNative.tsx +9 -10
  228. package/src/components/helpers/BackdropHandler.tsx +5 -119
  229. package/src/components/helpers/BackdropHandler.web.tsx +6 -0
  230. package/src/components/helpers/Dialog.tsx +49 -0
  231. package/src/components/helpers/Dialog.web.tsx +145 -0
  232. package/src/components/helpers/Portal.tsx +10 -0
  233. package/src/components/helpers/Portal.web.tsx +42 -0
  234. package/src/components/helpers/PortalHost.tsx +7 -0
  235. package/src/components/helpers/PortalHost.web.tsx +14 -0
  236. package/src/components/modal/Modal.tsx +60 -48
  237. package/src/components/modal/ModalContext.ts +12 -11
  238. package/src/components/modal/ModalTitle.tsx +41 -31
  239. package/src/components/modal/useModal.ts +13 -25
  240. package/src/components/nav/useTabbable.ts +31 -32
  241. package/src/components/navbar/NavbarToggler.tsx +130 -130
  242. package/src/components/navbar/useNavbar.ts +30 -31
  243. package/src/components/offcanvas/Offcanvas.tsx +91 -92
  244. package/src/components/offcanvas/OffcanvasContext.ts +13 -11
  245. package/src/components/offcanvas/OffcanvasTitle.tsx +43 -33
  246. package/src/components/offcanvas/useOffcanvas.ts +12 -20
  247. package/src/components/pagination/PaginationItem.tsx +139 -139
  248. package/src/components/popover/Popover.tsx +87 -90
  249. package/src/components/popover/PopoverArrow.tsx +22 -6
  250. package/src/components/popover/PopoverContext.ts +13 -18
  251. package/src/components/popover/injectPopover.tsx +63 -55
  252. package/src/components/tooltip/Tooltip.tsx +79 -98
  253. package/src/components/tooltip/TooltipArrow.tsx +26 -8
  254. package/src/components/tooltip/TooltipContext.ts +13 -18
  255. package/src/components/tooltip/injectTooltip.tsx +62 -53
  256. package/src/hooks/useAction.ts +78 -78
  257. package/src/hooks/useBackgroundNative.tsx +6 -4
  258. package/src/hooks/useFocusRing.ts +13 -0
  259. package/src/hooks/useFocusRing.web.ts +3 -0
  260. package/src/hooks/useInteractionState.ts +75 -81
  261. package/src/hooks/useOverlay.ts +197 -0
  262. package/src/hooks/useOverlay.web.ts +190 -0
  263. package/src/hooks/useScrollbarEffects.ts +5 -83
  264. package/src/hooks/useScrollbarEffects.web.ts +83 -0
  265. package/src/index.ts +5 -5
  266. package/src/style/StyleSheet.ts +2 -5
  267. package/src/theme/variables.ts +1420 -1420
  268. package/src/types.ts +14 -14
  269. package/src/utils.ts +4 -22
  270. package/lib/module/components/SafeAreaView.js +0 -42
  271. package/lib/module/components/SafeAreaView.js.map +0 -1
  272. package/lib/module/components/helpers/Overlay.js +0 -50
  273. package/lib/module/components/helpers/Overlay.js.map +0 -1
  274. package/lib/module/hooks/useIdentifier.js +0 -14
  275. package/lib/module/hooks/useIdentifier.js.map +0 -1
  276. package/lib/module/hooks/useTrigger.js +0 -97
  277. package/lib/module/hooks/useTrigger.js.map +0 -1
  278. package/lib/typescript/components/SafeAreaView.d.ts +0 -12
  279. package/lib/typescript/components/SafeAreaView.d.ts.map +0 -1
  280. package/lib/typescript/components/helpers/Overlay.d.ts +0 -28
  281. package/lib/typescript/components/helpers/Overlay.d.ts.map +0 -1
  282. package/lib/typescript/hooks/useIdentifier.d.ts +0 -2
  283. package/lib/typescript/hooks/useIdentifier.d.ts.map +0 -1
  284. package/lib/typescript/hooks/useTrigger.d.ts +0 -33
  285. package/lib/typescript/hooks/useTrigger.d.ts.map +0 -1
  286. package/src/components/SafeAreaView.tsx +0 -64
  287. package/src/components/helpers/Overlay.tsx +0 -81
  288. package/src/hooks/useIdentifier.ts +0 -15
  289. package/src/hooks/useTrigger.ts +0 -141
@@ -1,379 +1,381 @@
1
- import React, { useContext } from 'react';
2
- import invariant from 'tiny-invariant';
3
- import Pressable, { PressableRef, PressableProps } from '../Pressable';
4
- import { THEME_COLORS } from '../../theme/proxies';
5
- import { shadeColor, colorContrast } from '../../theme/functions';
6
- import ButtonGroupContext, {
7
- ButtonGroupContextType,
8
- } from '../button-group/ButtonGroupContext';
9
- import StyleSheet from '../../style/StyleSheet';
10
- import css from '../../style/css';
11
- import { getStyles, each } from '../../utils';
12
- import useToggleButton from './useToggleButton';
13
- import ListContext from '../helpers/ListContext';
14
- import type { ThemeVariables } from '../../types';
15
-
16
- type ButtonThemeColors = keyof typeof THEME_COLORS | 'link';
17
-
18
- export interface ButtonProps extends PressableProps {
19
- color?: ButtonThemeColors;
20
- size?: 'lg' | 'sm';
21
- outline?: boolean;
22
- active?: boolean;
23
- disabled?: boolean;
24
- }
25
-
26
- const styles = StyleSheet.create({
27
- '.btn': css`
28
- flex-direction: row; // added for bootstrap-rn
29
- justify-content: center; // added for bootstrap-rn
30
- // display: inline-block;
31
- @include platform(web) {
32
- // cursor: if($enable-button-pointers, pointer, null);
33
- }
34
- user-select: none;
35
- background-color: transparent;
36
- border: $btn-border-width solid transparent;
37
- padding: $btn-padding-y $btn-padding-x;
38
- // Manually declare to provide an override to the browser default
39
- border-radius: $btn-border-radius;
40
- // @include transition($btn-transition);
41
-
42
- &:focus-visible {
43
- // outline: 0;
44
- // box-shadow: $btn-focus-box-shadow;
45
- }
46
-
47
- &:active {
48
- // @include box-shadow($btn-active-box-shadow);
49
-
50
- &:focus-visible {
51
- // @include box-shadow($btn-focus-box-shadow, $btn-active-box-shadow);
52
- }
53
- }
54
- `,
55
- '.btn --text': css`
56
- font-family: $btn-font-family;
57
- font-weight: $btn-font-weight;
58
- line-height: $btn-font-size * $btn-line-height;
59
- color: $body-color;
60
- text-align: center;
61
- text-decoration: none; // if($link-decoration == none, null, none);
62
- white-space: $btn-white-space;
63
- vertical-align: middle;
64
- font-size: $btn-font-size;
65
-
66
- &:hover {
67
- color: $body-color;
68
- text-decoration: none; // if($link-decoration == none, null, none);
69
- }
70
- `,
71
- '.btn.disabled': css`
72
- pointer-events: none;
73
- opacity: $btn-disabled-opacity;
74
- // @include box-shadow(none);
75
- `,
76
- ...each(THEME_COLORS, (color, value) => ({
77
- [`.btn-${color}`]: css`
78
- background-color: ${value};
79
- border-color: ${value};
80
- // @include box-shadow($btn-box-shadow);
81
-
82
- &:hover {
83
- background-color: ${shadeColor(
84
- value,
85
- (t: ThemeVariables) => t['btn-hover-bg-shade-amount'],
86
- )};
87
- border-color: ${shadeColor(
88
- value,
89
- (t: ThemeVariables) => t['btn-hover-border-shade-amount'],
90
- )};
91
- }
92
-
93
- &:focus-visible {
94
- background-color: ${shadeColor(
95
- value,
96
- (t: ThemeVariables) => t['btn-hover-bg-shade-amount'],
97
- )};
98
- border-color: ${shadeColor(
99
- value,
100
- (t: ThemeVariables) => t['btn-hover-border-shade-amount'],
101
- )};
102
- /* @if $enable-shadows {
103
- @include box-shadow($btn-box-shadow, 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5));
104
- } @else {
105
- // Avoid using mixin so we can pass custom focus shadow properly
106
- box-shadow: 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5);
107
- } */
108
- }
109
-
110
- &:active {
111
- background-color: ${shadeColor(
112
- value,
113
- (t: ThemeVariables) => t['btn-active-bg-shade-amount'],
114
- )};
115
- // Remove CSS gradients if they're enabled
116
- // background-image: if($enable-gradients, none, null);
117
- border-color: ${shadeColor(
118
- value,
119
- (t: ThemeVariables) => t['btn-active-border-shade-amount'],
120
- )};
121
- }
122
- `,
123
- [`.btn-${color} --text`]: css`
124
- color: ${colorContrast(value)};
125
-
126
- &:hover {
127
- color: ${colorContrast(value)};
128
- }
129
-
130
- &:focus-visible {
131
- color: ${colorContrast(value)};
132
- }
133
-
134
- &:active {
135
- color: ${colorContrast(value)};
136
- }
137
- `,
138
- [`.btn-${color}.active`]: css`
139
- background-color: ${shadeColor(
140
- value,
141
- (t: ThemeVariables) => t['btn-active-bg-shade-amount'],
142
- )};
143
- // Remove CSS gradients if they're enabled
144
- // background-image: if($enable-gradients, none, null);
145
- border-color: ${shadeColor(
146
- value,
147
- (t: ThemeVariables) => t['btn-active-border-shade-amount'],
148
- )};
149
- `,
150
- [`.btn-${color}.active --text`]: css`
151
- color: ${colorContrast(value)};
152
- `,
153
- [`.btn-${color}.disabled`]: css`
154
- $disabled-background: ${value};
155
- $disabled-border: ${value};
156
-
157
- background-color: $disabled-background;
158
- // Remove CSS gradients if they're enabled
159
- // background-image: if($enable-gradients, none, null);
160
- border-color: $disabled-border;
161
- `,
162
- [`.btn-${color}.disabled --text`]: css`
163
- $disabled-color: ${colorContrast(value)};
164
-
165
- color: $disabled-color;
166
- `,
167
- [`.btn-outline-${color}`]: css`
168
- border-color: ${value};
169
-
170
- &:hover {
171
- background-color: ${value};
172
- border-color: ${value};
173
- }
174
-
175
- &:focus-visible {
176
- // box-shadow: 0 0 0 $btn-focus-width rgba($color, .5);
177
- }
178
-
179
- &:active {
180
- background-color: ${value};
181
- border-color: ${value};
182
-
183
- /* &:focus {
184
- @if $enable-shadows {
185
- @include box-shadow(
186
- $btn-active-box-shadow,
187
- 0 0 0 $btn-focus-width rgba($color, 0.5)
188
- );
189
- } @else {
190
- // Avoid using mixin so we can pass custom focus shadow properly
191
- box-shadow: 0 0 0 $btn-focus-width rgba($color, 0.5);
192
- }
193
- } */
194
- }
195
- `,
196
- [`.btn-outline-${color} --text`]: css`
197
- color: ${value};
198
-
199
- &:hover {
200
- color: ${colorContrast(value)};
201
- }
202
-
203
- &:active {
204
- color: ${colorContrast(value)};
205
- }
206
- `,
207
- [`.btn-outline-${color}.disabled`]: css`
208
- background-color: transparent;
209
- `,
210
- [`.btn-outline-${color}.disabled --text`]: css`
211
- color: ${value};
212
- `,
213
- })),
214
- '.btn-link --text': css`
215
- font-weight: $font-weight-normal;
216
- color: $btn-link-color;
217
- text-decoration-color: $btn-link-color; // added for bootstrap-rn
218
- text-decoration-line: $link-decoration;
219
-
220
- &:hover {
221
- color: $btn-link-hover-color;
222
- text-decoration-color: $btn-link-hover-color; // added for bootstrap-rn
223
- text-decoration-line: $link-hover-decoration;
224
- }
225
-
226
- &:focus-visible {
227
- text-decoration-line: $link-hover-decoration;
228
- }
229
-
230
- // No need for an active state here
231
- `,
232
- '.btn-link.disabled --text': css`
233
- color: $btn-link-disabled-color;
234
- `,
235
- '.btn-lg': css`
236
- padding: $btn-padding-y-lg $btn-padding-x-lg;
237
- // Manually declare to provide an override to the browser default
238
- border-radius: $btn-border-radius-lg;
239
- `,
240
- '.btn-lg --text': css`
241
- line-height: $btn-font-size-lg * $btn-line-height;
242
- font-size: $btn-font-size-lg;
243
- `,
244
- '.btn-sm': css`
245
- padding: $btn-padding-y-sm $btn-padding-x-sm;
246
- // Manually declare to provide an override to the browser default
247
- border-radius: $btn-border-radius-sm;
248
- `,
249
- '.btn-sm --text': css`
250
- line-height: $btn-font-size-sm * $btn-line-height;
251
- font-size: $btn-font-size-sm;
252
- `,
253
- '.btn-group > .btn': css`
254
- position: relative;
255
- // flex: 1 1 auto;
256
-
257
- &:hover {
258
- z-index: 1;
259
- }
260
- &:focus-visible {
261
- z-index: 1;
262
- }
263
- &:active {
264
- z-index: 1;
265
- }
266
- `,
267
- '.btn-group > .btn.active': css`
268
- z-index: 2; // 1;
269
- `,
270
- '.btn-group > .btn:not(:first-child)': css`
271
- margin-left: -$btn-border-width;
272
- border-top-left-radius: 0;
273
- border-bottom-left-radius: 0;
274
- `,
275
- '.btn-group > .btn:not(:last-child)': css`
276
- border-top-right-radius: 0;
277
- border-bottom-right-radius: 0;
278
- `,
279
- });
280
-
281
- const getVariant = (color: ButtonThemeColors, outline?: boolean) => {
282
- if (color === 'link') {
283
- return null;
284
- }
285
-
286
- if (outline) {
287
- return `.btn-outline-${color}`;
288
- }
289
-
290
- return `.btn-${color}`;
291
- };
292
-
293
- const hasSize = (
294
- value: string,
295
- group: ButtonGroupContextType | null,
296
- size?: string,
297
- ) => {
298
- if (size !== undefined || !group) {
299
- return size === value;
300
- }
301
-
302
- return group.size === value;
303
- };
304
-
305
- const Button = React.forwardRef<PressableRef, ButtonProps>((props, ref) => {
306
- const {
307
- children,
308
- color = 'primary',
309
- size,
310
- outline = false,
311
- active = false,
312
- disabled = false,
313
- style,
314
- activeStyle,
315
- textStyle,
316
- activeTextStyle,
317
- ...elementProps
318
- } = props;
319
-
320
- invariant(
321
- color !== 'link' || !outline,
322
- 'Button link variant is only available as non outline style.',
323
- );
324
-
325
- const listItem = useContext(ListContext);
326
- const group = useContext(ButtonGroupContext);
327
-
328
- const classes = getStyles(styles, [
329
- '.btn',
330
- getVariant(color, outline),
331
- disabled && '.btn.disabled',
332
- disabled && `${getVariant(color, outline)}.disabled`,
333
- hasSize('lg', group, size) && '.btn-lg',
334
- hasSize('sm', group, size) && '.btn-sm',
335
- group && '.btn-group > .btn',
336
- group && active && '.btn-group > .btn.active',
337
- group && !listItem?.first && '.btn-group > .btn:not(:first-child)',
338
- group && !listItem?.last && '.btn-group > .btn:not(:last-child)',
339
- ]);
340
-
341
- const activeClasses = getStyles(styles, [
342
- `${getVariant(color, outline)}.active`,
343
- ]);
344
-
345
- const textClasses = getStyles(styles, [
346
- '.btn --text',
347
- `${getVariant(color, outline)} --text`,
348
- color === 'link' && '.btn-link --text',
349
- disabled && `${getVariant(color, outline)}.disabled --text`,
350
- disabled && color === 'link' && '.btn-link.disabled --text',
351
- hasSize('lg', group, size) && '.btn-lg --text',
352
- hasSize('sm', group, size) && '.btn-sm --text',
353
- ]);
354
-
355
- const activeTextClasses = getStyles(styles, [
356
- `${getVariant(color, outline)}.active --text`,
357
- ]);
358
-
359
- return (
360
- <Pressable
361
- {...elementProps}
362
- ref={ref}
363
- active={active}
364
- disabled={disabled}
365
- style={[...classes, style]}
366
- activeStyle={[...activeClasses, activeStyle]}
367
- textStyle={[...textClasses, textStyle]}
368
- activeTextStyle={[...activeTextClasses, activeTextStyle]}
369
- >
370
- {children}
371
- </Pressable>
372
- );
373
- });
374
-
375
- Button.displayName = 'Button';
376
-
377
- export default Object.assign(Button, {
378
- useToggle: useToggleButton,
379
- });
1
+ import React, { useContext } from 'react';
2
+ import invariant from 'tiny-invariant';
3
+ import Pressable, { PressableRef, PressableProps } from '../Pressable';
4
+ import { THEME_COLORS } from '../../theme/proxies';
5
+ import { shadeColor, colorContrast } from '../../theme/functions';
6
+ import ButtonGroupContext, {
7
+ ButtonGroupContextType,
8
+ } from '../button-group/ButtonGroupContext';
9
+ import StyleSheet from '../../style/StyleSheet';
10
+ import css from '../../style/css';
11
+ import { getStyles, each } from '../../utils';
12
+ import useToggleButton from './useToggleButton';
13
+ import ListContext from '../helpers/ListContext';
14
+ import type { ThemeVariables } from '../../types';
15
+
16
+ type ButtonThemeColors = keyof typeof THEME_COLORS | 'link';
17
+
18
+ export interface ButtonProps extends PressableProps {
19
+ color?: ButtonThemeColors;
20
+ size?: 'lg' | 'sm';
21
+ outline?: boolean;
22
+ active?: boolean;
23
+ disabled?: boolean;
24
+ }
25
+
26
+ const styles = StyleSheet.create({
27
+ '.btn': css`
28
+ flex-direction: row; // added for bootstrap-rn
29
+ justify-content: center; // added for bootstrap-rn
30
+ // display: inline-block;
31
+ @include platform(web) {
32
+ // cursor: if($enable-button-pointers, pointer, null);
33
+ }
34
+ user-select: none;
35
+ background-color: transparent;
36
+ border: $btn-border-width solid transparent;
37
+ padding: $btn-padding-y $btn-padding-x;
38
+ // Manually declare to provide an override to the browser default
39
+ border-radius: $btn-border-radius;
40
+ // @include transition($btn-transition);
41
+
42
+ @include platform(web) {
43
+ &:focus-visible {
44
+ outline-style: none; // outline: 0;
45
+ box-shadow: $btn-focus-box-shadow;
46
+ }
47
+
48
+ &:active {
49
+ // box-shadow: $btn-active-box-shadow;
50
+
51
+ &:focus-visible {
52
+ box-shadow: $btn-focus-box-shadow; // , $btn-active-box-shadow;
53
+ }
54
+ }
55
+ }
56
+ `,
57
+ '.btn --text': css`
58
+ font-family: $btn-font-family;
59
+ font-weight: $btn-font-weight;
60
+ line-height: $btn-font-size * $btn-line-height;
61
+ color: $body-color;
62
+ text-align: center;
63
+ text-decoration: none; // if($link-decoration == none, null, none);
64
+ white-space: $btn-white-space;
65
+ vertical-align: middle;
66
+ font-size: $btn-font-size;
67
+
68
+ &:hover {
69
+ color: $body-color;
70
+ text-decoration: none; // if($link-decoration == none, null, none);
71
+ }
72
+ `,
73
+ '.btn.disabled': css`
74
+ pointer-events: none;
75
+ opacity: $btn-disabled-opacity;
76
+ // @include box-shadow(none);
77
+ `,
78
+ ...each(THEME_COLORS, (color, value) => ({
79
+ [`.btn-${color}`]: css`
80
+ background-color: ${value};
81
+ border-color: ${value};
82
+ // @include box-shadow($btn-box-shadow);
83
+
84
+ &:hover {
85
+ background-color: ${shadeColor(
86
+ value,
87
+ (t: ThemeVariables) => t['btn-hover-bg-shade-amount'],
88
+ )};
89
+ border-color: ${shadeColor(
90
+ value,
91
+ (t: ThemeVariables) => t['btn-hover-border-shade-amount'],
92
+ )};
93
+ }
94
+
95
+ &:focus-visible {
96
+ background-color: ${shadeColor(
97
+ value,
98
+ (t: ThemeVariables) => t['btn-hover-bg-shade-amount'],
99
+ )};
100
+ border-color: ${shadeColor(
101
+ value,
102
+ (t: ThemeVariables) => t['btn-hover-border-shade-amount'],
103
+ )};
104
+ /* @if $enable-shadows {
105
+ @include box-shadow($btn-box-shadow, 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5));
106
+ } @else {
107
+ // Avoid using mixin so we can pass custom focus shadow properly
108
+ box-shadow: 0 0 0 $btn-focus-width rgba(mix($color, $border, 15%), .5);
109
+ } */
110
+ }
111
+
112
+ &:active {
113
+ background-color: ${shadeColor(
114
+ value,
115
+ (t: ThemeVariables) => t['btn-active-bg-shade-amount'],
116
+ )};
117
+ // Remove CSS gradients if they're enabled
118
+ // background-image: if($enable-gradients, none, null);
119
+ border-color: ${shadeColor(
120
+ value,
121
+ (t: ThemeVariables) => t['btn-active-border-shade-amount'],
122
+ )};
123
+ }
124
+ `,
125
+ [`.btn-${color} --text`]: css`
126
+ color: ${colorContrast(value)};
127
+
128
+ &:hover {
129
+ color: ${colorContrast(value)};
130
+ }
131
+
132
+ &:focus-visible {
133
+ color: ${colorContrast(value)};
134
+ }
135
+
136
+ &:active {
137
+ color: ${colorContrast(value)};
138
+ }
139
+ `,
140
+ [`.btn-${color}.active`]: css`
141
+ background-color: ${shadeColor(
142
+ value,
143
+ (t: ThemeVariables) => t['btn-active-bg-shade-amount'],
144
+ )};
145
+ // Remove CSS gradients if they're enabled
146
+ // background-image: if($enable-gradients, none, null);
147
+ border-color: ${shadeColor(
148
+ value,
149
+ (t: ThemeVariables) => t['btn-active-border-shade-amount'],
150
+ )};
151
+ `,
152
+ [`.btn-${color}.active --text`]: css`
153
+ color: ${colorContrast(value)};
154
+ `,
155
+ [`.btn-${color}.disabled`]: css`
156
+ $disabled-background: ${value};
157
+ $disabled-border: ${value};
158
+
159
+ background-color: $disabled-background;
160
+ // Remove CSS gradients if they're enabled
161
+ // background-image: if($enable-gradients, none, null);
162
+ border-color: $disabled-border;
163
+ `,
164
+ [`.btn-${color}.disabled --text`]: css`
165
+ $disabled-color: ${colorContrast(value)};
166
+
167
+ color: $disabled-color;
168
+ `,
169
+ [`.btn-outline-${color}`]: css`
170
+ border-color: ${value};
171
+
172
+ &:hover {
173
+ background-color: ${value};
174
+ border-color: ${value};
175
+ }
176
+
177
+ &:focus-visible {
178
+ // box-shadow: 0 0 0 $btn-focus-width rgba($color, .5);
179
+ }
180
+
181
+ &:active {
182
+ background-color: ${value};
183
+ border-color: ${value};
184
+
185
+ /* &:focus {
186
+ @if $enable-shadows {
187
+ @include box-shadow(
188
+ $btn-active-box-shadow,
189
+ 0 0 0 $btn-focus-width rgba($color, 0.5)
190
+ );
191
+ } @else {
192
+ // Avoid using mixin so we can pass custom focus shadow properly
193
+ box-shadow: 0 0 0 $btn-focus-width rgba($color, 0.5);
194
+ }
195
+ } */
196
+ }
197
+ `,
198
+ [`.btn-outline-${color} --text`]: css`
199
+ color: ${value};
200
+
201
+ &:hover {
202
+ color: ${colorContrast(value)};
203
+ }
204
+
205
+ &:active {
206
+ color: ${colorContrast(value)};
207
+ }
208
+ `,
209
+ [`.btn-outline-${color}.disabled`]: css`
210
+ background-color: transparent;
211
+ `,
212
+ [`.btn-outline-${color}.disabled --text`]: css`
213
+ color: ${value};
214
+ `,
215
+ })),
216
+ '.btn-link --text': css`
217
+ font-weight: $font-weight-normal;
218
+ color: $btn-link-color;
219
+ text-decoration-color: $btn-link-color; // added for bootstrap-rn
220
+ text-decoration-line: $link-decoration;
221
+
222
+ &:hover {
223
+ color: $btn-link-hover-color;
224
+ text-decoration-color: $btn-link-hover-color; // added for bootstrap-rn
225
+ text-decoration-line: $link-hover-decoration;
226
+ }
227
+
228
+ &:focus-visible {
229
+ text-decoration-line: $link-hover-decoration;
230
+ }
231
+
232
+ // No need for an active state here
233
+ `,
234
+ '.btn-link.disabled --text': css`
235
+ color: $btn-link-disabled-color;
236
+ `,
237
+ '.btn-lg': css`
238
+ padding: $btn-padding-y-lg $btn-padding-x-lg;
239
+ // Manually declare to provide an override to the browser default
240
+ border-radius: $btn-border-radius-lg;
241
+ `,
242
+ '.btn-lg --text': css`
243
+ line-height: $btn-font-size-lg * $btn-line-height;
244
+ font-size: $btn-font-size-lg;
245
+ `,
246
+ '.btn-sm': css`
247
+ padding: $btn-padding-y-sm $btn-padding-x-sm;
248
+ // Manually declare to provide an override to the browser default
249
+ border-radius: $btn-border-radius-sm;
250
+ `,
251
+ '.btn-sm --text': css`
252
+ line-height: $btn-font-size-sm * $btn-line-height;
253
+ font-size: $btn-font-size-sm;
254
+ `,
255
+ '.btn-group > .btn': css`
256
+ position: relative;
257
+ // flex: 1 1 auto;
258
+
259
+ &:hover {
260
+ z-index: 1;
261
+ }
262
+ &:focus-visible {
263
+ z-index: 1;
264
+ }
265
+ &:active {
266
+ z-index: 1;
267
+ }
268
+ `,
269
+ '.btn-group > .btn.active': css`
270
+ z-index: 2; // 1;
271
+ `,
272
+ '.btn-group > .btn:not(:first-child)': css`
273
+ margin-left: -$btn-border-width;
274
+ border-top-left-radius: 0;
275
+ border-bottom-left-radius: 0;
276
+ `,
277
+ '.btn-group > .btn:not(:last-child)': css`
278
+ border-top-right-radius: 0;
279
+ border-bottom-right-radius: 0;
280
+ `,
281
+ });
282
+
283
+ const getVariant = (color: ButtonThemeColors, outline?: boolean) => {
284
+ if (color === 'link') {
285
+ return null;
286
+ }
287
+
288
+ if (outline) {
289
+ return `.btn-outline-${color}`;
290
+ }
291
+
292
+ return `.btn-${color}`;
293
+ };
294
+
295
+ const hasSize = (
296
+ value: string,
297
+ group: ButtonGroupContextType | null,
298
+ size?: string,
299
+ ) => {
300
+ if (size !== undefined || !group) {
301
+ return size === value;
302
+ }
303
+
304
+ return group.size === value;
305
+ };
306
+
307
+ const Button = React.forwardRef<PressableRef, ButtonProps>((props, ref) => {
308
+ const {
309
+ children,
310
+ color = 'primary',
311
+ size,
312
+ outline = false,
313
+ active = false,
314
+ disabled = false,
315
+ style,
316
+ activeStyle,
317
+ textStyle,
318
+ activeTextStyle,
319
+ ...elementProps
320
+ } = props;
321
+
322
+ invariant(
323
+ color !== 'link' || !outline,
324
+ 'Button link variant is only available as non outline style.',
325
+ );
326
+
327
+ const listItem = useContext(ListContext);
328
+ const group = useContext(ButtonGroupContext);
329
+
330
+ const classes = getStyles(styles, [
331
+ '.btn',
332
+ getVariant(color, outline),
333
+ disabled && '.btn.disabled',
334
+ disabled && `${getVariant(color, outline)}.disabled`,
335
+ hasSize('lg', group, size) && '.btn-lg',
336
+ hasSize('sm', group, size) && '.btn-sm',
337
+ group && '.btn-group > .btn',
338
+ group && active && '.btn-group > .btn.active',
339
+ group && !listItem?.first && '.btn-group > .btn:not(:first-child)',
340
+ group && !listItem?.last && '.btn-group > .btn:not(:last-child)',
341
+ ]);
342
+
343
+ const activeClasses = getStyles(styles, [
344
+ `${getVariant(color, outline)}.active`,
345
+ ]);
346
+
347
+ const textClasses = getStyles(styles, [
348
+ '.btn --text',
349
+ `${getVariant(color, outline)} --text`,
350
+ color === 'link' && '.btn-link --text',
351
+ disabled && `${getVariant(color, outline)}.disabled --text`,
352
+ disabled && color === 'link' && '.btn-link.disabled --text',
353
+ hasSize('lg', group, size) && '.btn-lg --text',
354
+ hasSize('sm', group, size) && '.btn-sm --text',
355
+ ]);
356
+
357
+ const activeTextClasses = getStyles(styles, [
358
+ `${getVariant(color, outline)}.active --text`,
359
+ ]);
360
+
361
+ return (
362
+ <Pressable
363
+ {...elementProps}
364
+ ref={ref}
365
+ active={active}
366
+ disabled={disabled}
367
+ style={[...classes, style]}
368
+ activeStyle={[...activeClasses, activeStyle]}
369
+ textStyle={[...textClasses, textStyle]}
370
+ activeTextStyle={[...activeTextClasses, activeTextStyle]}
371
+ >
372
+ {children}
373
+ </Pressable>
374
+ );
375
+ });
376
+
377
+ Button.displayName = 'Button';
378
+
379
+ export default Object.assign(Button, {
380
+ useToggle: useToggleButton,
381
+ });