react-native-molecules 0.5.0-beta.0

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 (355) hide show
  1. package/components/Accordion/Accordion.tsx +89 -0
  2. package/components/Accordion/AccordionItem.tsx +94 -0
  3. package/components/Accordion/AccordionItemContent.tsx +17 -0
  4. package/components/Accordion/AccordionItemHeader.tsx +122 -0
  5. package/components/Accordion/index.tsx +36 -0
  6. package/components/Accordion/utils.ts +62 -0
  7. package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
  8. package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
  9. package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
  10. package/components/ActivityIndicator/index.tsx +17 -0
  11. package/components/Appbar/AppbarActions.tsx +13 -0
  12. package/components/Appbar/AppbarBase.tsx +60 -0
  13. package/components/Appbar/AppbarCenterAligned.tsx +13 -0
  14. package/components/Appbar/AppbarLarge.tsx +13 -0
  15. package/components/Appbar/AppbarLeft.tsx +26 -0
  16. package/components/Appbar/AppbarMedium.tsx +13 -0
  17. package/components/Appbar/AppbarRight.tsx +40 -0
  18. package/components/Appbar/AppbarSmall.tsx +13 -0
  19. package/components/Appbar/AppbarTitle.tsx +49 -0
  20. package/components/Appbar/index.tsx +46 -0
  21. package/components/Appbar/types.ts +19 -0
  22. package/components/Appbar/utils.ts +127 -0
  23. package/components/Avatar/Avatar.tsx +189 -0
  24. package/components/Avatar/index.tsx +11 -0
  25. package/components/Avatar/utils.ts +35 -0
  26. package/components/Backdrop/Backdrop.tsx +18 -0
  27. package/components/Backdrop/index.tsx +11 -0
  28. package/components/Backdrop/types.ts +3 -0
  29. package/components/Backdrop/utils.ts +21 -0
  30. package/components/Badge/Badge.tsx +29 -0
  31. package/components/Badge/index.tsx +11 -0
  32. package/components/Badge/utils.ts +38 -0
  33. package/components/Button/Button.tsx +349 -0
  34. package/components/Button/index.tsx +11 -0
  35. package/components/Button/types.ts +5 -0
  36. package/components/Button/utils.ts +416 -0
  37. package/components/Card/Card.tsx +160 -0
  38. package/components/Card/CardActions.tsx +18 -0
  39. package/components/Card/CardContent.tsx +29 -0
  40. package/components/Card/CardHeader.tsx +31 -0
  41. package/components/Card/CardHeadline.tsx +15 -0
  42. package/components/Card/CardMedia.tsx +36 -0
  43. package/components/Card/CardSubhead.tsx +15 -0
  44. package/components/Card/CardText.tsx +13 -0
  45. package/components/Card/CardTypography.tsx +113 -0
  46. package/components/Card/index.tsx +38 -0
  47. package/components/Card/types.ts +1 -0
  48. package/components/Card/utils.ts +23 -0
  49. package/components/Checkbox/Checkbox.tsx +123 -0
  50. package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
  51. package/components/Checkbox/CheckboxBase.tsx +216 -0
  52. package/components/Checkbox/index.tsx +11 -0
  53. package/components/Checkbox/types.ts +72 -0
  54. package/components/Checkbox/utils.ts +210 -0
  55. package/components/Chip/Chip.tsx +416 -0
  56. package/components/Chip/index.tsx +51 -0
  57. package/components/Chip/utils.ts +100 -0
  58. package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
  59. package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
  60. package/components/DatePickerDocked/index.tsx +21 -0
  61. package/components/DatePickerDocked/types.ts +11 -0
  62. package/components/DatePickerDocked/utils.ts +155 -0
  63. package/components/DatePickerInline/AutoSizer.tsx +46 -0
  64. package/components/DatePickerInline/DatePickerContext.tsx +21 -0
  65. package/components/DatePickerInline/DatePickerInline.tsx +82 -0
  66. package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
  67. package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
  68. package/components/DatePickerInline/Day.tsx +88 -0
  69. package/components/DatePickerInline/DayName.tsx +17 -0
  70. package/components/DatePickerInline/DayNames.tsx +32 -0
  71. package/components/DatePickerInline/DayRange.tsx +48 -0
  72. package/components/DatePickerInline/HeaderItem.tsx +111 -0
  73. package/components/DatePickerInline/Month.tsx +233 -0
  74. package/components/DatePickerInline/MonthPicker.tsx +174 -0
  75. package/components/DatePickerInline/Swiper.native.tsx +172 -0
  76. package/components/DatePickerInline/Swiper.tsx +172 -0
  77. package/components/DatePickerInline/SwiperUtils.ts +40 -0
  78. package/components/DatePickerInline/Week.tsx +67 -0
  79. package/components/DatePickerInline/YearPicker.tsx +139 -0
  80. package/components/DatePickerInline/dateUtils.tsx +334 -0
  81. package/components/DatePickerInline/index.tsx +41 -0
  82. package/components/DatePickerInline/types.ts +104 -0
  83. package/components/DatePickerInline/utils.ts +367 -0
  84. package/components/DatePickerInput/DatePickerInput.tsx +139 -0
  85. package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
  86. package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
  87. package/components/DatePickerInput/DateRangeInput.tsx +88 -0
  88. package/components/DatePickerInput/index.tsx +14 -0
  89. package/components/DatePickerInput/inputUtils.ts +138 -0
  90. package/components/DatePickerInput/types.ts +28 -0
  91. package/components/DatePickerInput/utils.ts +16 -0
  92. package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
  93. package/components/DatePickerModal/CalendarEdit.tsx +139 -0
  94. package/components/DatePickerModal/DatePickerModal.tsx +85 -0
  95. package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
  96. package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
  97. package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
  98. package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
  99. package/components/DatePickerModal/index.tsx +20 -0
  100. package/components/DatePickerModal/types.ts +92 -0
  101. package/components/DatePickerModal/utils.ts +121 -0
  102. package/components/DateTimePicker/DateTimePicker.tsx +172 -0
  103. package/components/DateTimePicker/index.tsx +14 -0
  104. package/components/DateTimePicker/utils.ts +13 -0
  105. package/components/Dialog/Dialog.tsx +66 -0
  106. package/components/Dialog/DialogActions.tsx +89 -0
  107. package/components/Dialog/DialogContent.tsx +37 -0
  108. package/components/Dialog/DialogIcon.tsx +69 -0
  109. package/components/Dialog/DialogTitle.tsx +68 -0
  110. package/components/Dialog/index.tsx +37 -0
  111. package/components/Dialog/utils.ts +80 -0
  112. package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
  113. package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
  114. package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
  115. package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
  116. package/components/Drawer/Collapsible/index.tsx +23 -0
  117. package/components/Drawer/Collapsible/utils.ts +49 -0
  118. package/components/Drawer/Drawer.tsx +43 -0
  119. package/components/Drawer/DrawerContent.tsx +35 -0
  120. package/components/Drawer/DrawerFooter.tsx +27 -0
  121. package/components/Drawer/DrawerHeader.tsx +27 -0
  122. package/components/Drawer/DrawerItem.tsx +206 -0
  123. package/components/Drawer/DrawerItemGroup.tsx +82 -0
  124. package/components/Drawer/index.tsx +47 -0
  125. package/components/Drawer/types.ts +3 -0
  126. package/components/Drawer/utils.ts +8 -0
  127. package/components/ElementGroup/ElementGroup.tsx +139 -0
  128. package/components/ElementGroup/index.tsx +11 -0
  129. package/components/ElementGroup/utils.ts +25 -0
  130. package/components/FAB/FAB.tsx +176 -0
  131. package/components/FAB/index.tsx +12 -0
  132. package/components/FAB/types.ts +1 -0
  133. package/components/FAB/utils.ts +221 -0
  134. package/components/FilePicker/FilePicker.tsx +133 -0
  135. package/components/FilePicker/index.tsx +11 -0
  136. package/components/FilePicker/utils.ts +13 -0
  137. package/components/HelperText/HelperText.tsx +139 -0
  138. package/components/HelperText/index.tsx +11 -0
  139. package/components/HelperText/utils.ts +29 -0
  140. package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
  141. package/components/HorizontalDivider/index.tsx +13 -0
  142. package/components/Icon/CrossFadeIcon.tsx +116 -0
  143. package/components/Icon/Icon.tsx +41 -0
  144. package/components/Icon/iconFactory.tsx +23 -0
  145. package/components/Icon/index.tsx +11 -0
  146. package/components/Icon/types.ts +35 -0
  147. package/components/IconButton/IconButton.tsx +218 -0
  148. package/components/IconButton/index.tsx +11 -0
  149. package/components/IconButton/types.ts +1 -0
  150. package/components/IconButton/utils.ts +325 -0
  151. package/components/If/index.tsx +13 -0
  152. package/components/InputAddon/InputAddon.tsx +27 -0
  153. package/components/InputAddon/index.tsx +11 -0
  154. package/components/InputAddon/utils.ts +33 -0
  155. package/components/Link/Link.tsx +48 -0
  156. package/components/Link/index.tsx +11 -0
  157. package/components/Link/utils.ts +37 -0
  158. package/components/ListItem/ListItem.tsx +136 -0
  159. package/components/ListItem/ListItemDescription.tsx +25 -0
  160. package/components/ListItem/ListItemTitle.tsx +25 -0
  161. package/components/ListItem/index.tsx +18 -0
  162. package/components/ListItem/utils.ts +113 -0
  163. package/components/Menu/Menu.tsx +69 -0
  164. package/components/Menu/MenuDivider.tsx +13 -0
  165. package/components/Menu/MenuItem.tsx +128 -0
  166. package/components/Menu/index.tsx +19 -0
  167. package/components/Menu/utils.ts +92 -0
  168. package/components/Modal/Modal.tsx +261 -0
  169. package/components/Modal/index.tsx +11 -0
  170. package/components/Modal/utils.ts +45 -0
  171. package/components/NavigationRail/NavigationRail.tsx +32 -0
  172. package/components/NavigationRail/NavigationRailContent.tsx +25 -0
  173. package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
  174. package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
  175. package/components/NavigationRail/NavigationRailItem.tsx +226 -0
  176. package/components/NavigationRail/index.tsx +35 -0
  177. package/components/NavigationRail/utils.ts +170 -0
  178. package/components/NavigationStack/NavigationStack.tsx +85 -0
  179. package/components/NavigationStack/NavigationStackItem.tsx +60 -0
  180. package/components/NavigationStack/index.tsx +20 -0
  181. package/components/NavigationStack/utils.tsx +16 -0
  182. package/components/Popover/Popover.native.tsx +185 -0
  183. package/components/Popover/Popover.tsx +198 -0
  184. package/components/Popover/common.ts +459 -0
  185. package/components/Popover/index.ts +2 -0
  186. package/components/Portal/Portal.tsx +13 -0
  187. package/components/Portal/index.tsx +12 -0
  188. package/components/RadioButton/RadioButton.tsx +138 -0
  189. package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
  190. package/components/RadioButton/RadioButtonGroup.tsx +98 -0
  191. package/components/RadioButton/RadioButtonIOS.tsx +106 -0
  192. package/components/RadioButton/RadioButtonItem.tsx +232 -0
  193. package/components/RadioButton/index.ts +27 -0
  194. package/components/RadioButton/utils.ts +164 -0
  195. package/components/Rating/Rating.tsx +149 -0
  196. package/components/Rating/RatingItem.tsx +125 -0
  197. package/components/Rating/index.tsx +13 -0
  198. package/components/Rating/utils.ts +38 -0
  199. package/components/Select/Select.tsx +1038 -0
  200. package/components/Select/index.ts +14 -0
  201. package/components/Select/types.ts +115 -0
  202. package/components/StateLayer/StateLayer.tsx +12 -0
  203. package/components/StateLayer/index.tsx +11 -0
  204. package/components/StateLayer/utils.ts +17 -0
  205. package/components/Surface/BackgroundContextWrapper.tsx +27 -0
  206. package/components/Surface/Surface.android.tsx +62 -0
  207. package/components/Surface/Surface.ios.tsx +123 -0
  208. package/components/Surface/Surface.tsx +48 -0
  209. package/components/Surface/index.tsx +12 -0
  210. package/components/Surface/utils.ts +106 -0
  211. package/components/Switch/Switch.ios.tsx +67 -0
  212. package/components/Switch/Switch.tsx +278 -0
  213. package/components/Switch/index.tsx +11 -0
  214. package/components/Switch/utils.ts +283 -0
  215. package/components/Tabs/TabItem.tsx +150 -0
  216. package/components/Tabs/TabLabel.tsx +84 -0
  217. package/components/Tabs/Tabs.tsx +398 -0
  218. package/components/Tabs/index.tsx +21 -0
  219. package/components/Tabs/utils.ts +126 -0
  220. package/components/Text/Text.tsx +23 -0
  221. package/components/Text/index.tsx +2 -0
  222. package/components/Text/textFactory.tsx +33 -0
  223. package/components/TextInput/InputLabel.tsx +181 -0
  224. package/components/TextInput/TextInput.tsx +693 -0
  225. package/components/TextInput/index.tsx +16 -0
  226. package/components/TextInput/types.ts +96 -0
  227. package/components/TextInput/utils.ts +544 -0
  228. package/components/TextInputWithMask/TextInputMask.tsx +57 -0
  229. package/components/TextInputWithMask/index.tsx +11 -0
  230. package/components/TextInputWithMask/utils.ts +56 -0
  231. package/components/TimePicker/AmPmSwitcher.tsx +99 -0
  232. package/components/TimePicker/AnalogClock.tsx +165 -0
  233. package/components/TimePicker/AnalogClockHours.tsx +163 -0
  234. package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
  235. package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
  236. package/components/TimePicker/DisplayModeContext.tsx +6 -0
  237. package/components/TimePicker/TimeInput.tsx +112 -0
  238. package/components/TimePicker/TimeInputs.tsx +148 -0
  239. package/components/TimePicker/TimePicker.tsx +130 -0
  240. package/components/TimePicker/index.tsx +19 -0
  241. package/components/TimePicker/timeUtils.ts +159 -0
  242. package/components/TimePicker/utils.ts +285 -0
  243. package/components/TimePickerField/TimePickerField.tsx +152 -0
  244. package/components/TimePickerField/index.tsx +14 -0
  245. package/components/TimePickerField/sanitizeTime.ts +85 -0
  246. package/components/TimePickerField/utils.ts +95 -0
  247. package/components/TimePickerModal/TimePickerModal.tsx +115 -0
  248. package/components/TimePickerModal/index.tsx +14 -0
  249. package/components/TimePickerModal/utils.ts +48 -0
  250. package/components/Tooltip/Tooltip.tsx +137 -0
  251. package/components/Tooltip/TooltipContent.tsx +12 -0
  252. package/components/Tooltip/TooltipTrigger.tsx +94 -0
  253. package/components/Tooltip/index.tsx +20 -0
  254. package/components/Tooltip/utils.ts +21 -0
  255. package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
  256. package/components/TouchableRipple/TouchableRipple.tsx +286 -0
  257. package/components/TouchableRipple/index.tsx +14 -0
  258. package/components/TouchableRipple/utils.ts +15 -0
  259. package/components/VerticalDivider/VerticalDivider.tsx +99 -0
  260. package/components/VerticalDivider/index.tsx +13 -0
  261. package/context-bridge/index.tsx +87 -0
  262. package/core/componentsRegistry.ts +164 -0
  263. package/core/index.tsx +2 -0
  264. package/fast-context/index.tsx +190 -0
  265. package/hocs/index.tsx +5 -0
  266. package/hocs/typedMemo.tsx +5 -0
  267. package/hocs/withKeyboardAccessibility.tsx +231 -0
  268. package/hocs/withPortal.tsx +16 -0
  269. package/hooks/createPsuedoHook.tsx +50 -0
  270. package/hooks/index.tsx +29 -0
  271. package/hooks/useActionState.native.tsx +22 -0
  272. package/hooks/useActionState.tsx +34 -0
  273. package/hooks/useActive.tsx +5 -0
  274. package/hooks/useBreakpoints.tsx +7 -0
  275. package/hooks/useColorMode.tsx +17 -0
  276. package/hooks/useContrastColor.ts +15 -0
  277. package/hooks/useControlledValue.tsx +68 -0
  278. package/hooks/useFilePicker.tsx +48 -0
  279. package/hooks/useFocus.tsx +5 -0
  280. package/hooks/useHandleNumberFormat.tsx +106 -0
  281. package/hooks/useHover.tsx +5 -0
  282. package/hooks/useKeyboardDismissable.ts +66 -0
  283. package/hooks/useLatest.tsx +9 -0
  284. package/hooks/useMediaQuery.tsx +64 -0
  285. package/hooks/useMergedRefs.ts +14 -0
  286. package/hooks/usePrevious.ts +13 -0
  287. package/hooks/useQueryFilter.tsx +35 -0
  288. package/hooks/useSearchable.tsx +74 -0
  289. package/hooks/useSubcomponents.tsx +59 -0
  290. package/hooks/useTheme.ts +3 -0
  291. package/hooks/useToggle.tsx +24 -0
  292. package/package.json +114 -0
  293. package/shortcuts-manager/EventsManager.tsx +121 -0
  294. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
  295. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
  296. package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
  297. package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
  298. package/shortcuts-manager/index.tsx +6 -0
  299. package/shortcuts-manager/types.ts +24 -0
  300. package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
  301. package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
  302. package/shortcuts-manager/useSetScopes/index.tsx +1 -0
  303. package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
  304. package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
  305. package/shortcuts-manager/useShortcut/index.tsx +2 -0
  306. package/shortcuts-manager/useShortcut/types.ts +3 -0
  307. package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
  308. package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
  309. package/shortcuts-manager/utils.ts +105 -0
  310. package/styles/index.ts +4 -0
  311. package/styles/overlay.ts +69 -0
  312. package/styles/shadow.ts +21 -0
  313. package/styles/themes/DarkTheme.tsx +98 -0
  314. package/styles/themes/LightTheme.tsx +212 -0
  315. package/styles/themes/tokens.ts +248 -0
  316. package/styles/utils.ts +11 -0
  317. package/types/index.ts +129 -0
  318. package/types/theme.ts +159 -0
  319. package/utils/DocumentPicker/documentPicker.native.ts +10 -0
  320. package/utils/DocumentPicker/documentPicker.ts +76 -0
  321. package/utils/DocumentPicker/index.ts +2 -0
  322. package/utils/DocumentPicker/types.ts +28 -0
  323. package/utils/addEventListener.tsx +51 -0
  324. package/utils/backgroundContext.ts +9 -0
  325. package/utils/color.ts +22 -0
  326. package/utils/compare/index.ts +54 -0
  327. package/utils/composeEventHandlers.ts +9 -0
  328. package/utils/createNumberMask/createNumberMask.ts +98 -0
  329. package/utils/createNumberMask/index.ts +5 -0
  330. package/utils/createSyntheticEvent.ts +31 -0
  331. package/utils/date-fns.ts +7 -0
  332. package/utils/dateTimePicker.ts +5 -0
  333. package/utils/escapeRegex.ts +9 -0
  334. package/utils/extractTextStyles.ts +52 -0
  335. package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
  336. package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
  337. package/utils/formatNumberWithMask/index.ts +6 -0
  338. package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
  339. package/utils/getCursorStyle/getCursorStyle.ts +1 -0
  340. package/utils/getCursorStyle/index.ts +1 -0
  341. package/utils/getOS/getOS.native.ts +7 -0
  342. package/utils/getOS/getOS.ts +24 -0
  343. package/utils/getOS/index.ts +1 -0
  344. package/utils/getyearRange.ts +5 -0
  345. package/utils/index.ts +20 -0
  346. package/utils/lodash.ts +50 -0
  347. package/utils/mergeRefs.ts +13 -0
  348. package/utils/normalizeBorderRadiuses.ts +24 -0
  349. package/utils/normalizeSpacings.ts +110 -0
  350. package/utils/normalizeToNumberString/index.ts +4 -0
  351. package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
  352. package/utils/repository.ts +103 -0
  353. package/utils/resolveColorMode.ts +9 -0
  354. package/utils/resolveStateVariant.ts +26 -0
  355. package/utils/tokenStylesParser.ts +7 -0
@@ -0,0 +1,115 @@
1
+ import { memo, useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { KeyboardAvoidingView, Platform, View } from 'react-native';
3
+
4
+ import { format } from '../../utils/date-fns';
5
+ import { Button } from '../Button';
6
+ import { IconButton } from '../IconButton';
7
+ import { Modal, type ModalProps } from '../Modal';
8
+ import { Portal } from '../Portal';
9
+ import { Text } from '../Text';
10
+ import TimePicker from '../TimePicker/TimePicker';
11
+ import {
12
+ clockTypes,
13
+ getTimeInputTypeIcon,
14
+ inputTypes,
15
+ type PossibleClockTypes,
16
+ type PossibleInputTypes,
17
+ reverseInputTypes,
18
+ } from '../TimePicker/timeUtils';
19
+ import { styles } from './utils';
20
+
21
+ export type Props = Omit<ModalProps, 'children'> & {
22
+ is24Hour?: boolean;
23
+ label?: string;
24
+ uppercase?: boolean;
25
+ cancelLabel?: string;
26
+ confirmLabel?: string;
27
+ time?: string;
28
+ onConfirm: (time: string) => any;
29
+ keyboardIcon?: string;
30
+ clockIcon?: string;
31
+ isLandscape?: boolean;
32
+ };
33
+
34
+ export function TimePickerModal({
35
+ isOpen,
36
+ onClose,
37
+ onConfirm: onConfirmProp,
38
+ time: timeProp,
39
+ label = 'Select time',
40
+ uppercase = false,
41
+ cancelLabel = 'Cancel',
42
+ confirmLabel = 'Ok',
43
+ is24Hour,
44
+ keyboardIcon = 'keyboard-outline',
45
+ clockIcon = 'clock-outline',
46
+ isLandscape = false,
47
+ style,
48
+ ...rest
49
+ }: Props) {
50
+ const [inputType, setInputType] = useState<PossibleInputTypes>(inputTypes.picker);
51
+ const [focused, setFocused] = useState<PossibleClockTypes>(clockTypes.hours);
52
+ const [time, setTime] = useState(() => timeProp || format(new Date(), 'HH:mm'));
53
+
54
+ const modelStyle = useMemo(() => [styles.modalContent, style], [style]);
55
+
56
+ const onFocusInput = useCallback((type: PossibleClockTypes) => setFocused(type), []);
57
+
58
+ const onChange = useCallback(
59
+ (params: { focused?: PossibleClockTypes | undefined; time: string }) => {
60
+ if (params.focused) {
61
+ setFocused(params.focused);
62
+ }
63
+
64
+ setTime(params.time);
65
+ },
66
+ [setFocused, setTime],
67
+ );
68
+
69
+ const onConfirm = useCallback(() => onConfirmProp(time), [onConfirmProp, time]);
70
+
71
+ useEffect(() => {
72
+ setTime(timeProp || format(new Date(), 'HH:mm'));
73
+ }, [timeProp]);
74
+
75
+ return (
76
+ <Portal>
77
+ <Modal {...rest} isOpen={isOpen} style={modelStyle} onClose={onClose}>
78
+ <KeyboardAvoidingView
79
+ style={styles.keyboardView}
80
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}>
81
+ <View style={styles.labelContainer}>
82
+ <Text style={styles.label}>{uppercase ? label.toUpperCase() : label}</Text>
83
+ </View>
84
+ <View style={styles.timePickerContainer}>
85
+ <TimePicker
86
+ is24Hour={is24Hour}
87
+ inputType={inputType}
88
+ focused={focused}
89
+ time={time}
90
+ onTimeChange={onChange}
91
+ onFocusInput={onFocusInput}
92
+ isLandscape={isLandscape}
93
+ />
94
+ </View>
95
+ <View style={styles.footer}>
96
+ <IconButton
97
+ name={getTimeInputTypeIcon(inputType, {
98
+ keyboard: keyboardIcon,
99
+ picker: clockIcon,
100
+ })}
101
+ onPress={() => setInputType(reverseInputTypes[inputType])}
102
+ style={styles.inputTypeToggle}
103
+ accessibilityLabel="toggle keyboard"
104
+ />
105
+ <View style={styles.fill} />
106
+ <Button onPress={onClose}>{cancelLabel}</Button>
107
+ <Button onPress={onConfirm}>{confirmLabel}</Button>
108
+ </View>
109
+ </KeyboardAvoidingView>
110
+ </Modal>
111
+ </Portal>
112
+ );
113
+ }
114
+
115
+ export default memo(TimePickerModal);
@@ -0,0 +1,14 @@
1
+ import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
2
+ import TimePickerModalDefault from './TimePickerModal';
3
+
4
+ registerMoleculesComponents({
5
+ TimePickerModal: TimePickerModalDefault,
6
+ });
7
+
8
+ export const TimePickerModal = getRegisteredComponentWithFallback(
9
+ 'TimePickerModal',
10
+ TimePickerModalDefault,
11
+ );
12
+
13
+ export type { Props as TimePickerModalProps } from './TimePickerModal';
14
+ export { styles } from './utils';
@@ -0,0 +1,48 @@
1
+ import { StyleSheet } from 'react-native-unistyles';
2
+
3
+ import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
4
+
5
+ const timepickerModalStylesDefault = StyleSheet.create(theme => ({
6
+ keyboardView: {
7
+ justifyContent: 'center',
8
+ alignItems: 'center',
9
+ flex: 1,
10
+ },
11
+ modalContent: {
12
+ minWidth: 287,
13
+ width: undefined,
14
+ maxWidth: undefined,
15
+ flex: undefined,
16
+ borderRadius: theme.shapes.corner.extraLarge,
17
+ },
18
+ labelContainer: {
19
+ height: 28,
20
+ justifyContent: 'flex-end',
21
+ paddingLeft: theme.spacings['6'],
22
+ paddingRight: theme.spacings['6'],
23
+ alignSelf: 'flex-start',
24
+ },
25
+ label: {
26
+ letterSpacing: 1,
27
+ fontSize: theme.typescale.labelLarge.fontSize,
28
+ color: theme.colors.onSurface,
29
+ fontWeight: theme.typescale.labelLarge.fontWeight,
30
+ },
31
+ timePickerContainer: {
32
+ padding: theme.spacings['6'],
33
+ },
34
+ footer: {
35
+ flexDirection: 'row',
36
+ alignItems: 'center',
37
+ padding: theme.spacings['2'],
38
+ width: '100%',
39
+ },
40
+ inputTypeToggle: { margin: theme.spacings['1'] },
41
+ fill: { flex: 1 },
42
+ }));
43
+
44
+ registerComponentsStyles({
45
+ TimePickerModal: timepickerModalStylesDefault,
46
+ });
47
+
48
+ export const styles = getRegisteredMoleculesComponentStyles('TimePickerModal');
@@ -0,0 +1,137 @@
1
+ import {
2
+ createContext,
3
+ memo,
4
+ type ReactElement,
5
+ useCallback,
6
+ useEffect,
7
+ useMemo,
8
+ useRef,
9
+ } from 'react';
10
+ import { Text, type ViewProps, type ViewStyle } from 'react-native';
11
+
12
+ import { useSubcomponents, useToggle } from '../../hooks';
13
+ import { Popover, type PopoverProps } from '../Popover';
14
+ import { tooltipStyles } from './utils';
15
+
16
+ export type Props = Omit<PopoverProps, 'isOpen' | 'triggerRef'> & {
17
+ fadeInDelay?: number;
18
+ fadeOutDelay?: number;
19
+ showArrow?: boolean;
20
+ style?: ViewStyle;
21
+ children: ReactElement | ReactElement[];
22
+ hoverableContent?: boolean;
23
+ };
24
+
25
+ const Tooltip = ({
26
+ style,
27
+ children,
28
+ fadeInDelay = 100,
29
+ fadeOutDelay = 300,
30
+ showArrow = false,
31
+ hoverableContent = false,
32
+ ...rest
33
+ }: Props) => {
34
+ const { state: isOpen, setState: setIsOpen } = useToggle(false);
35
+ const triggerRef = useRef(null);
36
+ const timeOutRef = useRef<NodeJS.Timeout>(undefined);
37
+ const popoverTimeoutRef = useRef<NodeJS.Timeout>(undefined);
38
+ const preventCloseRef = useRef(false);
39
+
40
+ const onClose = useCallback(() => {
41
+ if (preventCloseRef.current) return;
42
+ clearTimeout(timeOutRef.current);
43
+ timeOutRef.current = setTimeout(() => setIsOpen(false), fadeOutDelay);
44
+ }, [fadeOutDelay, setIsOpen]);
45
+
46
+ const onOpen = useCallback(() => {
47
+ clearTimeout(timeOutRef.current);
48
+ timeOutRef.current = setTimeout(() => setIsOpen(true), fadeInDelay);
49
+ }, [fadeInDelay, setIsOpen]);
50
+
51
+ // const setPopoverOpen = useCallback(
52
+ // (_isOpen: boolean) => {
53
+ // clearTimeout(popoverTimeoutRef.current);
54
+ // popoverTimeoutRef.current = setTimeout(
55
+ // () => setIsOpen(_isOpen),
56
+ // isOpen ? fadeInDelay : fadeOutDelay,
57
+ // );
58
+ // },
59
+ // [fadeInDelay, fadeOutDelay, isOpen, setIsOpen],
60
+ // );
61
+
62
+ const { Tooltip_Trigger, Tooltip_Content } = useSubcomponents({
63
+ children,
64
+ allowedChildren: ['Tooltip_Trigger', 'Tooltip_Content'],
65
+ });
66
+
67
+ const contextValue = useMemo(
68
+ () => ({
69
+ triggerRef,
70
+ onOpen,
71
+ onClose,
72
+ }),
73
+ [onClose, onOpen],
74
+ );
75
+
76
+ const { popoverContentProps, popoverStyle } = useMemo(
77
+ () => ({
78
+ popoverContentProps: (hoverableContent
79
+ ? {
80
+ onMouseEnter: () => {
81
+ preventCloseRef.current = true;
82
+ clearTimeout(timeOutRef.current);
83
+ setIsOpen(true);
84
+ },
85
+ onMouseLeave: () => {
86
+ preventCloseRef.current = false;
87
+ clearTimeout(timeOutRef.current);
88
+ setIsOpen(false);
89
+ },
90
+ }
91
+ : {}) as ViewProps,
92
+ popoverStyle: [tooltipStyles.content, style],
93
+ }),
94
+ [hoverableContent, setIsOpen, style],
95
+ );
96
+
97
+ useEffect(() => {
98
+ const popoverTimeout = popoverTimeoutRef;
99
+
100
+ return () => {
101
+ clearTimeout(timeOutRef.current);
102
+ clearTimeout(popoverTimeout.current);
103
+ };
104
+ }, []);
105
+
106
+ return (
107
+ <TooltipContext.Provider value={contextValue}>
108
+ {Tooltip_Trigger[0]}
109
+ {isOpen && (
110
+ <Popover
111
+ isOpen={isOpen}
112
+ inverted
113
+ // placement={placement}
114
+ showArrow={showArrow}
115
+ // backdropStyles={styles.backdrop}
116
+ triggerRef={triggerRef}
117
+ // setIsOpen={setPopoverOpen}
118
+ {...popoverContentProps}
119
+ {...rest}
120
+ style={popoverStyle}
121
+ // contentTextStyles={contentTextStyles}
122
+ // popoverContentProps={popoverContentProps}
123
+ onClose={onClose}>
124
+ <Text style={tooltipStyles.contentText}>{Tooltip_Content[0]}</Text>
125
+ </Popover>
126
+ )}
127
+ </TooltipContext.Provider>
128
+ );
129
+ };
130
+
131
+ export const TooltipContext = createContext({
132
+ onOpen: () => {},
133
+ onClose: () => {},
134
+ triggerRef: null as any,
135
+ });
136
+
137
+ export default memo(Tooltip);
@@ -0,0 +1,12 @@
1
+ import { memo, type ReactElement, type ReactNode } from 'react';
2
+
3
+ export type Props = {
4
+ children: ReactElement | ReactNode;
5
+ };
6
+
7
+ const TooltipContent = memo(({ children }: Props) => {
8
+ return <>{children}</>;
9
+ });
10
+
11
+ TooltipContent.displayName = 'Tooltip_Content';
12
+ export default TooltipContent;
@@ -0,0 +1,94 @@
1
+ import {
2
+ cloneElement,
3
+ memo,
4
+ type ReactElement,
5
+ type RefAttributes,
6
+ useCallback,
7
+ useContext,
8
+ useEffect,
9
+ useImperativeHandle,
10
+ useMemo,
11
+ } from 'react';
12
+ import { Platform } from 'react-native';
13
+
14
+ import { useActionState } from '../../hooks';
15
+ import { TooltipContext } from './Tooltip';
16
+
17
+ export type Props = {
18
+ children: ReactElement;
19
+ };
20
+
21
+ const TooltipTrigger = memo(({ children }: { children: ReactElement }) => {
22
+ const isWeb = Platform.OS === 'web';
23
+ const { onOpen, onClose, triggerRef } = useContext(TooltipContext);
24
+ const { hovered, actionsRef } = useActionState({ ref: triggerRef, actionsToListen: ['hover'] });
25
+
26
+ // this will make sure children's ref is not overwritten by the triggerRef
27
+ useImperativeHandle(
28
+ // @ts-ignore
29
+ (children as ReactElement & RefAttributes<any>)?.ref,
30
+ () => triggerRef?.current,
31
+ );
32
+
33
+ const onPress = useCallback(() => {
34
+ // @ts-ignore
35
+ children?.props?.onPress?.();
36
+ }, [children?.props]);
37
+
38
+ const onLongPress = useCallback(() => {
39
+ // @ts-ignore
40
+ children?.props?.onLongPress?.();
41
+
42
+ if (isWeb) return;
43
+ onOpen();
44
+ }, [children?.props, isWeb, onOpen]);
45
+
46
+ const onPressOut = useCallback(() => {
47
+ // @ts-ignore
48
+
49
+ children?.props?.onPressOut?.();
50
+
51
+ if (isWeb) return;
52
+ onClose();
53
+ }, [children?.props, isWeb, onClose]);
54
+
55
+ const onHoverIn = useCallback(() => {
56
+ // @ts-ignore
57
+ children?.props?.onHoverIn?.();
58
+
59
+ onOpen();
60
+ }, [children?.props, onOpen]);
61
+
62
+ const onHoverOut = useCallback(() => {
63
+ // @ts-ignore
64
+ children?.props?.onHoverOut?.();
65
+
66
+ onClose();
67
+ }, [onClose, children?.props]);
68
+
69
+ useEffect(() => {
70
+ if (!isWeb) return;
71
+
72
+ if (hovered) {
73
+ onHoverIn();
74
+ return;
75
+ }
76
+
77
+ onHoverOut();
78
+ }, [hovered, isWeb, onHoverIn, onHoverOut]);
79
+
80
+ return useMemo(
81
+ () =>
82
+ cloneElement(children, {
83
+ // @ts-ignore
84
+ ref: actionsRef,
85
+ onLongPress,
86
+ onPressOut,
87
+ onPress,
88
+ }),
89
+ [children, onLongPress, onPress, onPressOut, actionsRef],
90
+ );
91
+ });
92
+
93
+ TooltipTrigger.displayName = 'Tooltip_Trigger';
94
+ export default TooltipTrigger;
@@ -0,0 +1,20 @@
1
+ import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
2
+ import TooltipComponent from './Tooltip';
3
+ import TooltipTrigger from './TooltipTrigger';
4
+ import TooltipContent from './TooltipContent';
5
+
6
+ export const TooltipDefault = Object.assign(TooltipComponent, {
7
+ Trigger: TooltipTrigger,
8
+ Content: TooltipContent,
9
+ });
10
+
11
+ registerMoleculesComponents({
12
+ Tooltip: TooltipDefault,
13
+ });
14
+
15
+ export const Tooltip = getRegisteredComponentWithFallback('Tooltip', TooltipDefault);
16
+
17
+ export { Props as TooltipProps } from './Tooltip';
18
+ export { Props as TooltipTriggerProps } from './TooltipTrigger';
19
+ export { Props as TooltipContentProps } from './TooltipContent';
20
+ export { tooltipStyles } from './utils';
@@ -0,0 +1,21 @@
1
+ import { StyleSheet } from 'react-native-unistyles';
2
+
3
+ import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
4
+
5
+ const tooltipStylesDefault = StyleSheet.create(theme => ({
6
+ content: {
7
+ backgroundColor: theme.colors.surfaceVariant,
8
+ borderRadius: theme.shapes.corner.extraSmall,
9
+ padding: theme.spacings['2'],
10
+ },
11
+ contentText: {
12
+ color: theme.colors.onSurface,
13
+ ...theme.typescale.bodySmall,
14
+ },
15
+ }));
16
+
17
+ registerComponentsStyles({
18
+ Tooltip: tooltipStylesDefault,
19
+ });
20
+
21
+ export const tooltipStyles = getRegisteredMoleculesComponentStyles('Tooltip');
@@ -0,0 +1,105 @@
1
+ import React, { forwardRef, memo, useMemo } from 'react';
2
+ import {
3
+ type BackgroundPropType,
4
+ Platform,
5
+ Pressable,
6
+ type StyleProp,
7
+ StyleSheet,
8
+ TouchableNativeFeedback,
9
+ TouchableWithoutFeedback,
10
+ View,
11
+ type ViewStyle,
12
+ } from 'react-native';
13
+ import { withUnistyles } from 'react-native-unistyles';
14
+
15
+ import { touchableRippleStyles } from './utils';
16
+
17
+ const ANDROID_VERSION_LOLLIPOP = 21;
18
+ const ANDROID_VERSION_PIE = 28;
19
+
20
+ type Props = React.ComponentProps<typeof TouchableWithoutFeedback> & {
21
+ borderless?: boolean;
22
+ background?: BackgroundPropType;
23
+ disabled?: boolean;
24
+ onPress?: () => void | null;
25
+ rippleColor?: string;
26
+ underlayColor?: string;
27
+ children: React.ReactNode;
28
+ style?: StyleProp<ViewStyle>;
29
+ };
30
+
31
+ const TouchableRipple = (
32
+ {
33
+ style,
34
+ background,
35
+ borderless = false,
36
+ disabled: disabledProp,
37
+ rippleColor: rippleColorProp,
38
+ underlayColor: underlayColorProp,
39
+ children,
40
+ ...rest
41
+ }: Props,
42
+ ref: any,
43
+ ) => {
44
+ const disabled = disabledProp || !rest.onPress;
45
+
46
+ const componentStyles = touchableRippleStyles;
47
+
48
+ const { rippleColor, underlayColor, containerStyle } = useMemo(() => {
49
+ return {
50
+ rippleColor: rippleColorProp,
51
+ underlayColor: underlayColorProp || rippleColorProp,
52
+ containerStyle: [borderless && styles.borderless, componentStyles.root, style],
53
+ };
54
+ }, [borderless, componentStyles.root, rippleColorProp, style, underlayColorProp]);
55
+
56
+ // A workaround for ripple on Android P is to use useForeground + overflow: 'hidden'
57
+ // https://github.com/facebook/react-native/issues/6480
58
+ const useForeground =
59
+ Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_PIE && borderless;
60
+
61
+ if (TouchableRipple.supported) {
62
+ return (
63
+ <TouchableNativeFeedback
64
+ {...rest}
65
+ ref={ref}
66
+ disabled={disabled}
67
+ useForeground={useForeground}
68
+ background={
69
+ background != null
70
+ ? background
71
+ : TouchableNativeFeedback.Ripple(rippleColor!, borderless)
72
+ }>
73
+ <View style={containerStyle}>{React.Children.only(children)}</View>
74
+ </TouchableNativeFeedback>
75
+ );
76
+ }
77
+
78
+ return (
79
+ <Pressable
80
+ {...rest}
81
+ ref={ref}
82
+ disabled={disabled}
83
+ style={({ pressed }) => [
84
+ containerStyle,
85
+ pressed && { backgroundColor: underlayColor },
86
+ ]}>
87
+ {React.Children.only(children)}
88
+ </Pressable>
89
+ );
90
+ };
91
+
92
+ const styles = StyleSheet.create({
93
+ borderless: {
94
+ overflow: 'hidden',
95
+ },
96
+ });
97
+
98
+ TouchableRipple.supported =
99
+ Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP;
100
+
101
+ export default memo(
102
+ withUnistyles(forwardRef(TouchableRipple), theme => ({
103
+ rippleColor: theme.colors.onSurfaceRipple,
104
+ })),
105
+ );