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,7 @@
1
+ export { add } from 'date-fns/add';
2
+ export { addDays } from 'date-fns/addDays';
3
+ export { endOfDay } from 'date-fns/endOfDay';
4
+ export { format } from 'date-fns/format';
5
+ export { isValid } from 'date-fns/isValid';
6
+ export { parse } from 'date-fns/parse';
7
+ export { startOfWeek } from 'date-fns/startOfWeek';
@@ -0,0 +1,5 @@
1
+ export function range(start: number, end: number) {
2
+ return Array(end - start + 1)
3
+ .fill(null)
4
+ .map((_, i) => start + i);
5
+ }
@@ -0,0 +1,9 @@
1
+ export const escapeRegex = (string: string) => {
2
+ if (typeof string !== 'string') {
3
+ throw new TypeError('Expected a string');
4
+ }
5
+
6
+ // Escape characters with special meaning either inside or outside character sets.
7
+ // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
8
+ return string.replace(/[|\\{}()[\]^$+\-*?.]/g, '\\$&').replace(/-/g, '\\x2d');
9
+ };
@@ -0,0 +1,52 @@
1
+ import type { TextStyle } from 'react-native';
2
+
3
+ import { memoize } from './lodash';
4
+
5
+ const textStyleProps = [
6
+ 'color',
7
+ 'fontFamily',
8
+ 'fontSize',
9
+ 'fontStyle',
10
+ 'fontWeight',
11
+ 'letterSpacing',
12
+ 'lineHeight',
13
+ 'textAlign',
14
+ 'textDecorationLine',
15
+ 'textDecorationStyle',
16
+ 'textDecorationColor',
17
+ 'textShadowColor',
18
+ 'textShadowOffset',
19
+ 'textShadowRadius',
20
+ 'textTransform',
21
+ ] as const;
22
+
23
+ const defaultTextStyle: TextStyle = {};
24
+ const extract = <T extends TextStyle>(styles: T) => {
25
+ const { textStyle, otherStyle } = textStyleProps.reduce(
26
+ (obj, key) => {
27
+ if (key in obj.otherStyle) {
28
+ const value = obj.otherStyle[key] as T[typeof key];
29
+
30
+ // delete from the object;
31
+ obj.otherStyle = { ...obj.otherStyle };
32
+ delete obj.otherStyle[key];
33
+
34
+ // return if value is falsy
35
+ if (!value) return obj;
36
+
37
+ obj.textStyle = { ...obj.textStyle, [key]: value };
38
+ }
39
+ return obj;
40
+ },
41
+ {
42
+ textStyle: defaultTextStyle,
43
+ otherStyle: styles as T,
44
+ },
45
+ );
46
+
47
+ return [textStyle, otherStyle];
48
+ };
49
+
50
+ export const extractTextStyle = Object.assign(memoize, { Cache: Map })(extract, style =>
51
+ JSON.stringify(style),
52
+ );
@@ -0,0 +1,26 @@
1
+ import { createNumberMask, type CreateNumberMaskProps } from '../createNumberMask';
2
+ import { isNil } from '../lodash';
3
+ import { formatWithMask } from './formatWithMask';
4
+
5
+ export type FormatNumberWithMaskProps = CreateNumberMaskProps & {
6
+ number: number | string | undefined | null;
7
+ };
8
+
9
+ export const formatNumberWithMask = ({
10
+ number,
11
+ separator = '.',
12
+ suffix = '',
13
+ precision = 0,
14
+ ...rest
15
+ }: FormatNumberWithMaskProps) => {
16
+ if (isNil(number) || number === '' || isNaN(Number(number))) return '';
17
+
18
+ const numberMask = createNumberMask({ separator, suffix, precision, ...rest });
19
+
20
+ const numberString = `${Number(number).toFixed(precision)}`;
21
+
22
+ const separatorReplacedNumber =
23
+ numberString.replace('.', separator) + (numberString ? suffix : '');
24
+
25
+ return formatWithMask({ text: separatorReplacedNumber, mask: numberMask }).masked;
26
+ };
@@ -0,0 +1,119 @@
1
+ // https://github.com/CaioQuirinoMedeiros/react-native-mask-input/blob/main/src/formatWithMask.ts
2
+
3
+ import type { Mask } from '../createNumberMask/createNumberMask';
4
+
5
+ export type FormatWithMaskResult = {
6
+ masked: string;
7
+ unmasked: string;
8
+ obfuscated: string;
9
+ };
10
+
11
+ export type FormatWithMaskProps = {
12
+ /**
13
+ * Text to be formatted with the mask.
14
+ */
15
+ text?: string;
16
+ /**
17
+ * Mask
18
+ */
19
+ mask?: Mask;
20
+ /**
21
+ * Character to be used on the obfuscated characters. Defaults to `"*"`
22
+ */
23
+ obfuscationCharacter?: string;
24
+ /** Add next mask characters at the end of the value. Defaults to `false`.
25
+ *
26
+ * Example: In a date mask, a input value of `"15/10"` will result:
27
+ * - When set to false: `"15/10"`
28
+ * - When set to true: `"15/10/"`
29
+ */
30
+ maskAutoComplete?: boolean;
31
+ };
32
+
33
+ export const formatWithMask = (props: FormatWithMaskProps): FormatWithMaskResult => {
34
+ const { text, mask, obfuscationCharacter = '*', maskAutoComplete = false } = props;
35
+
36
+ // make sure it'll not break with null or undefined inputs
37
+ if (!text) return { masked: '', unmasked: '', obfuscated: '' };
38
+ if (!mask)
39
+ return {
40
+ masked: text || '',
41
+ unmasked: text || '',
42
+ obfuscated: text || '',
43
+ };
44
+
45
+ const maskArray = typeof mask === 'function' ? mask(text) : mask;
46
+
47
+ let masked = '';
48
+ let obfuscated = '';
49
+ let unmasked = '';
50
+
51
+ let maskCharIndex = 0;
52
+ let valueCharIndex = 0;
53
+
54
+ while (true) {
55
+ // if mask is ended, break.
56
+ if (maskCharIndex === maskArray.length) {
57
+ break;
58
+ }
59
+
60
+ const maskChar = maskArray[maskCharIndex];
61
+ const valueChar = text[valueCharIndex];
62
+
63
+ // if value is ended, break.
64
+ if (valueCharIndex === text.length) {
65
+ if (typeof maskChar === 'string' && maskAutoComplete) {
66
+ masked += maskChar;
67
+ obfuscated += maskChar;
68
+
69
+ maskCharIndex += 1;
70
+ continue;
71
+ }
72
+ break;
73
+ }
74
+
75
+ // value equals mask: add to masked result and advance on both mask and value indexes
76
+ if (maskChar === valueChar) {
77
+ masked += maskChar;
78
+ obfuscated += maskChar;
79
+
80
+ valueCharIndex += 1;
81
+ maskCharIndex += 1;
82
+ continue;
83
+ }
84
+
85
+ const unmaskedValueChar = text[valueCharIndex];
86
+
87
+ // it's a regex maskChar: let's advance on value index and validate the value within the regex
88
+ if (typeof maskChar === 'object') {
89
+ // advance on value index
90
+ valueCharIndex += 1;
91
+
92
+ const shouldObsfucateChar = Array.isArray(maskChar);
93
+
94
+ const maskCharRegex = Array.isArray(maskChar) ? maskChar[0] : maskChar;
95
+
96
+ const matchRegex = RegExp(maskCharRegex).test(valueChar);
97
+
98
+ // value match regex: add to masked and unmasked result and advance on mask index too
99
+ if (matchRegex) {
100
+ masked += valueChar;
101
+ obfuscated += shouldObsfucateChar ? obfuscationCharacter : valueChar;
102
+ unmasked += unmaskedValueChar;
103
+
104
+ maskCharIndex += 1;
105
+ }
106
+
107
+ continue;
108
+ } else {
109
+ // it's a fixed maskChar: add to maskedResult and advance on mask index
110
+ masked += maskChar;
111
+ obfuscated += maskChar;
112
+
113
+ maskCharIndex += 1;
114
+ continue;
115
+ }
116
+ }
117
+
118
+ return { masked, unmasked, obfuscated };
119
+ };
@@ -0,0 +1,6 @@
1
+ export { formatNumberWithMask, type FormatNumberWithMaskProps } from './formatNumberWithMask';
2
+ export {
3
+ formatWithMask,
4
+ type FormatWithMaskProps,
5
+ type FormatWithMaskResult,
6
+ } from './formatWithMask';
@@ -0,0 +1 @@
1
+ export const getCursorStyle = (_cursor: string) => ({});
@@ -0,0 +1 @@
1
+ export const getCursorStyle = (cursor: string) => ({ cursor });
@@ -0,0 +1 @@
1
+ export * from './getCursorStyle';
@@ -0,0 +1,7 @@
1
+ import { Platform } from 'react-native';
2
+
3
+ export const getOS = () => {
4
+ return Platform.OS;
5
+ };
6
+
7
+ export const isMac = () => false;
@@ -0,0 +1,24 @@
1
+ export const getOS = () => {
2
+ if (!globalThis.navigator) return 'server';
3
+ const userAgent = globalThis.navigator.userAgent.toLowerCase();
4
+ const macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i;
5
+ const windowsPlatforms = /(win32|win64|windows|wince)/i;
6
+ const iosPlatforms = /(iphone|ipad|ipod)/i;
7
+ let os = null;
8
+
9
+ if (macosPlatforms.test(userAgent)) {
10
+ os = 'macos';
11
+ } else if (iosPlatforms.test(userAgent)) {
12
+ os = 'ios';
13
+ } else if (windowsPlatforms.test(userAgent)) {
14
+ os = 'windows';
15
+ } else if (/android/.test(userAgent)) {
16
+ os = 'android';
17
+ } else if (!os && /linux/.test(userAgent)) {
18
+ os = 'linux';
19
+ }
20
+
21
+ return os;
22
+ };
23
+
24
+ export const isMac = () => getOS() === 'macos';
@@ -0,0 +1 @@
1
+ export * from './getOS';
@@ -0,0 +1,5 @@
1
+ import { range } from './dateTimePicker';
2
+
3
+ export const getYearRange = (startYear = 1800, endYear = 2200) => {
4
+ return range(startYear, endYear);
5
+ };
package/utils/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ export { addEventListener, addListener } from './addEventListener';
2
+ export { BackgroundContext } from './backgroundContext';
3
+ export { default as color, resolveContrastColor } from './color';
4
+ export * from './compare';
5
+ export { default as composeEventHandlers } from './composeEventHandlers';
6
+ export { createNumberMask, type CreateNumberMaskProps } from './createNumberMask';
7
+ export * from './createSyntheticEvent';
8
+ export { formatNumberWithMask, type FormatNumberWithMaskProps } from './formatNumberWithMask';
9
+ export * from './getCursorStyle';
10
+ export * from './getOS';
11
+ export { getYearRange } from './getyearRange';
12
+ export { default as mergeRefs } from './mergeRefs';
13
+ export { normalizeBorderRadiuses } from './normalizeBorderRadiuses';
14
+ export { normalizeSpacings, type SpacingKey, type SpacingType } from './normalizeSpacings';
15
+ export {
16
+ normalizeToNumberString,
17
+ type NormalizeToNumberStringProps,
18
+ } from './normalizeToNumberString';
19
+ export { Repository } from './repository';
20
+ export * from './resolveStateVariant';
@@ -0,0 +1,50 @@
1
+ import memoize from 'lodash.memoize';
2
+ export { default as debounce } from 'lodash.debounce';
3
+ export { default as get } from 'lodash.get';
4
+ export { default as keyBy } from 'lodash.keyby';
5
+ export { default as memoize } from 'lodash.memoize';
6
+ export { default as omitBy } from 'lodash.omitby';
7
+
8
+ export const isNil = (value: unknown): value is null | undefined => value == null;
9
+ export const noop = () => {};
10
+
11
+ const uniqueIdFactory = () => {
12
+ let number = Number.MAX_SAFE_INTEGER;
13
+ return () => number--;
14
+ };
15
+
16
+ const getUniqueId = uniqueIdFactory();
17
+ const weakMemoize = Object.assign(memoize.bind(null), { Cache: WeakMap });
18
+ const getObjectMemoryAddress = weakMemoize((x: unknown | null) => x && getUniqueId());
19
+
20
+ export const allArgumentResolver = (...args: unknown[]) =>
21
+ args
22
+ .map(x => {
23
+ const type = typeof x;
24
+ switch (type) {
25
+ case 'object':
26
+ case 'function':
27
+ return type.slice(0, 2)! + getObjectMemoryAddress(x);
28
+ default:
29
+ return type.slice(0, 2)! + String(x);
30
+ }
31
+ })
32
+ .join('_');
33
+
34
+ export const createMemoizedFunction = ({
35
+ resolver = allArgumentResolver,
36
+ Cache = Map,
37
+ }: {
38
+ resolver?: (...args: any[]) => any;
39
+ Cache?: typeof memoize.Cache;
40
+ } = {}) => {
41
+ const memo = Object.assign(memoize.bind(null), { Cache });
42
+ return Object.assign(
43
+ <T extends (...args: any[]) => any>(func: T, resolverOverwride?: (...args: any[]) => any) =>
44
+ memo(func, resolverOverwride ?? resolver),
45
+ );
46
+ };
47
+
48
+ export const weakMemoized = createMemoizedFunction({
49
+ Cache: WeakMap,
50
+ });
@@ -0,0 +1,13 @@
1
+ export default function mergeRefs<T = any>(
2
+ refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined>,
3
+ ): React.RefCallback<T> {
4
+ return value => {
5
+ refs.forEach(ref => {
6
+ if (typeof ref === 'function') {
7
+ ref(value);
8
+ } else if (ref != null) {
9
+ (ref as React.MutableRefObject<T | null>).current = value;
10
+ }
11
+ });
12
+ };
13
+ }
@@ -0,0 +1,24 @@
1
+ import type { ViewStyle } from 'react-native';
2
+
3
+ export const normalizeBorderRadiuses = ({
4
+ borderTopLeftRadius,
5
+ borderTopRightRadius,
6
+ borderBottomLeftRadius,
7
+ borderBottomRightRadius,
8
+ borderRadius,
9
+ }: ViewStyle) => {
10
+ const borderRadiuses: Record<string, any> = {
11
+ borderTopLeftRadius,
12
+ borderTopRightRadius,
13
+ borderBottomLeftRadius,
14
+ borderBottomRightRadius,
15
+ borderRadius,
16
+ };
17
+
18
+ return Object.keys(borderRadiuses).reduce((acc: Record<string, any>, key) => {
19
+ if (borderRadiuses[key] !== undefined && borderRadiuses[key] !== null) {
20
+ acc[key] = borderRadiuses[key];
21
+ }
22
+ return acc;
23
+ }, {});
24
+ };
@@ -0,0 +1,110 @@
1
+ import { I18nManager, type TextStyle } from 'react-native';
2
+
3
+ export type SpacingKey =
4
+ | 'margin'
5
+ | 'marginBottom'
6
+ | 'marginEnd'
7
+ | 'marginHorizontal'
8
+ | 'marginLeft'
9
+ | 'marginRight'
10
+ | 'marginStart'
11
+ | 'marginTop'
12
+ | 'marginVertical'
13
+ | 'padding'
14
+ | 'paddingBottom'
15
+ | 'paddingEnd'
16
+ | 'paddingHorizontal'
17
+ | 'paddingLeft'
18
+ | 'paddingRight'
19
+ | 'paddingStart'
20
+ | 'paddingTop'
21
+ | 'paddingVertical';
22
+
23
+ export type SpacingType =
24
+ | 'paddingTop'
25
+ | 'paddingBottom'
26
+ | 'paddingLeft'
27
+ | 'paddingRight'
28
+ | 'marginTop'
29
+ | 'marginBottom'
30
+ | 'marginLeft'
31
+ | 'marginRight';
32
+
33
+ type StyleObject = TextStyle & Partial<Record<SpacingKey, number>>; // only support number values
34
+
35
+ const normalizeMarginRight = (styleObj: StyleObject) => {
36
+ return (
37
+ styleObj?.marginRight ||
38
+ styleObj?.marginHorizontal ||
39
+ styleObj?.margin ||
40
+ (I18nManager.isRTL ? styleObj?.marginStart : styleObj?.marginEnd) ||
41
+ 0
42
+ );
43
+ };
44
+
45
+ const normalizeMarginLeft = (styleObj: StyleObject) => {
46
+ return (
47
+ styleObj?.marginLeft ||
48
+ styleObj?.marginHorizontal ||
49
+ styleObj?.margin ||
50
+ (I18nManager.isRTL ? styleObj?.marginEnd : styleObj?.marginStart) ||
51
+ 0
52
+ );
53
+ };
54
+
55
+ const normalizeMarginTop = (styleObj: StyleObject) => {
56
+ return styleObj?.marginTop || styleObj?.marginVertical || styleObj?.margin || 0;
57
+ };
58
+
59
+ const normalizeMarginBottom = (styleObj: StyleObject) => {
60
+ return styleObj?.marginBottom || styleObj?.marginVertical || styleObj?.margin || 0;
61
+ };
62
+
63
+ const normalizePaddingRight = (styleObj: StyleObject) => {
64
+ return (
65
+ styleObj?.paddingRight ||
66
+ styleObj?.paddingHorizontal ||
67
+ styleObj?.padding ||
68
+ (I18nManager.isRTL ? styleObj?.paddingStart : styleObj?.paddingEnd) ||
69
+ 0
70
+ );
71
+ };
72
+
73
+ const normalizePaddingLeft = (styleObj: StyleObject) => {
74
+ return (
75
+ styleObj?.paddingLeft ||
76
+ styleObj?.paddingHorizontal ||
77
+ styleObj?.padding ||
78
+ (I18nManager.isRTL ? styleObj?.paddingEnd : styleObj?.paddingStart) ||
79
+ 0
80
+ );
81
+ };
82
+
83
+ const normalizePaddingTop = (styleObj: StyleObject) => {
84
+ return styleObj?.paddingTop || styleObj?.paddingVertical || styleObj?.padding || 0;
85
+ };
86
+
87
+ const normalizePaddingBottom = (styleObj: StyleObject) => {
88
+ return styleObj?.paddingBottom || styleObj?.paddingVertical || styleObj?.padding || 0;
89
+ };
90
+
91
+ export const normalizeSpacings = (styleObj: StyleObject, spacingType: SpacingType) => {
92
+ switch (spacingType) {
93
+ case 'paddingTop':
94
+ return normalizePaddingTop(styleObj);
95
+ case 'paddingBottom':
96
+ return normalizePaddingBottom(styleObj);
97
+ case 'paddingLeft':
98
+ return normalizePaddingLeft(styleObj);
99
+ case 'paddingRight':
100
+ return normalizePaddingRight(styleObj);
101
+ case 'marginTop':
102
+ return normalizeMarginTop(styleObj);
103
+ case 'marginBottom':
104
+ return normalizeMarginBottom(styleObj);
105
+ case 'marginLeft':
106
+ return normalizeMarginLeft(styleObj);
107
+ case 'marginRight':
108
+ return normalizeMarginRight(styleObj);
109
+ }
110
+ };
@@ -0,0 +1,4 @@
1
+ export {
2
+ normalizeToNumberString,
3
+ type NormalizeToNumberStringProps,
4
+ } from './normalizeToNumberString';
@@ -0,0 +1,48 @@
1
+ import { isNil } from '../lodash';
2
+
3
+ export type NormalizeToNumberStringProps = {
4
+ text: string;
5
+ prefix?: string;
6
+ suffix?: string;
7
+ separator?: string;
8
+ allowNegative?: boolean;
9
+ precision?: number;
10
+ };
11
+
12
+ const checkAndRemove = (text: string, searchValue: string): string =>
13
+ searchValue && text.includes(searchValue) ? text.replace(searchValue, '') : text;
14
+
15
+ const checkAndReplaceAll = (text: string, searchValue: string, replaceValue: string): string =>
16
+ searchValue && text.includes(searchValue) ? text.replaceAll(searchValue, replaceValue) : text;
17
+
18
+ // TODO - Need to improvement this, later this should also work with mathematical constants like e
19
+ export const normalizeToNumberString = ({
20
+ text: _text,
21
+ prefix = '',
22
+ suffix = '',
23
+ separator = '',
24
+ allowNegative = false,
25
+ precision = 0,
26
+ }: NormalizeToNumberStringProps) => {
27
+ const text = _text || '';
28
+
29
+ const removedSuffixAndPrefix = checkAndRemove(checkAndRemove(text, prefix), suffix);
30
+
31
+ const separatorReplacedText = checkAndReplaceAll(removedSuffixAndPrefix, separator, '.');
32
+
33
+ const textWithNumbersDotsAndMinusSign = separatorReplacedText.replace(/[^0-9.-]/g, '');
34
+
35
+ const numberText = textWithNumbersDotsAndMinusSign.replace(/[^0-9.]/g, '');
36
+
37
+ const number = parseFloat(numberText);
38
+
39
+ const outputNumberString = !isNil(number) && !isNaN(number) ? number.toFixed(precision) : '';
40
+
41
+ // after removing everything we expect the minus sign to be in front of the number if it's exists and if the number exists
42
+ const prefixText =
43
+ allowNegative && outputNumberString && textWithNumbersDotsAndMinusSign[0] === '-'
44
+ ? '-'
45
+ : '';
46
+
47
+ return `${prefixText}${outputNumberString}`;
48
+ };
@@ -0,0 +1,103 @@
1
+ import EventEmitter, {
2
+ type ConstructorOptions,
3
+ type event as Event,
4
+ type eventNS,
5
+ } from 'eventemitter2';
6
+
7
+ import { debounce } from './lodash';
8
+
9
+ interface RepositoryConstructor<T> extends ConstructorOptions {
10
+ onRegister?: (arg: T, name: string, registery: Record<string, T>) => T;
11
+ name?: string;
12
+ }
13
+
14
+ let id = Date.now();
15
+
16
+ export class Repository<T> extends EventEmitter {
17
+ private registry: Record<string, T> = {};
18
+ readonly #name!: string;
19
+
20
+ readonly #onRegister!: (arg: T, name: string, registery: Record<string, T>) => T;
21
+
22
+ get name() {
23
+ return this.#name;
24
+ }
25
+
26
+ static get uniqueId() {
27
+ return (id++).toString(36).substring(0, 15);
28
+ }
29
+
30
+ constructor({
31
+ onRegister = arg => arg,
32
+ name = Repository.uniqueId,
33
+ ...options
34
+ }: RepositoryConstructor<T> = {}) {
35
+ super(options);
36
+ this.#onRegister = onRegister;
37
+ this.#name = name;
38
+ }
39
+
40
+ has = (itemName: string): boolean => {
41
+ return !!this.registry[itemName];
42
+ };
43
+
44
+ emit(event: eventNS | Event, ...values: any[]) {
45
+ event = typeof event === 'string' ? `${this.#name}::event` : event;
46
+ return super.emit(event, ...values);
47
+ }
48
+
49
+ /**
50
+ * Register a item with the src.
51
+ */
52
+ register = <X extends T = T, ItemName extends string = ''>(itemName: ItemName, item: X) => {
53
+ let updatedItem = this.#onRegister?.(item, itemName, { ...this.registry });
54
+ if (!updatedItem) updatedItem = item;
55
+
56
+ this.registry = {
57
+ ...this.registry,
58
+ [itemName]: updatedItem,
59
+ };
60
+
61
+ this.emit('item_registered', itemName);
62
+ };
63
+
64
+ /**
65
+ * Get all registered module from the registry.
66
+ */
67
+ getAll = () => {
68
+ return this.registry;
69
+ };
70
+
71
+ /**
72
+ * Register a listener to the module registry.
73
+ * Return value returns a function that removes the listener.
74
+ */
75
+ listen = (
76
+ callback: (events: string[]) => void,
77
+ { throttle = 100 }: { throttle?: number } = {},
78
+ ) => {
79
+ let cached: string[] = [];
80
+
81
+ const wrappedCallback = () => {
82
+ callback(cached);
83
+ cached = [];
84
+ };
85
+
86
+ const debouncedCallback = !throttle
87
+ ? wrappedCallback
88
+ : debounce(wrappedCallback, Math.abs(throttle), {
89
+ trailing: true,
90
+ leading: false,
91
+ });
92
+
93
+ const handledCallback = (itemName: string) => {
94
+ cached.push(itemName);
95
+ debouncedCallback();
96
+ };
97
+
98
+ this.on('item_registered', handledCallback);
99
+ return () => {
100
+ this.off('item_registered', handledCallback);
101
+ };
102
+ };
103
+ }
@@ -0,0 +1,9 @@
1
+ import { Appearance } from 'react-native';
2
+
3
+ export declare type ColorMode = 'auto' | 'light' | 'dark';
4
+
5
+ export const resolveColorMode = (colorMode: ColorMode) => {
6
+ const defaultMode = Appearance.getColorScheme() || 'light';
7
+
8
+ return colorMode === 'auto' ? defaultMode : colorMode;
9
+ };