react-native-molecules 0.5.0-beta.0 → 0.5.0-beta.10

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 (164) hide show
  1. package/README.md +87 -0
  2. package/components/Accordion/AccordionItem.tsx +3 -2
  3. package/components/Accordion/AccordionItemContent.tsx +1 -0
  4. package/components/Accordion/AccordionItemHeader.tsx +6 -5
  5. package/components/Accordion/index.tsx +8 -14
  6. package/components/Accordion/utils.ts +17 -14
  7. package/components/ActivityIndicator/ActivityIndicator.tsx +12 -20
  8. package/components/ActivityIndicator/index.tsx +1 -5
  9. package/components/Appbar/index.tsx +1 -4
  10. package/components/Appbar/utils.ts +33 -21
  11. package/components/Avatar/index.tsx +1 -5
  12. package/components/Avatar/utils.ts +2 -6
  13. package/components/Backdrop/Backdrop.tsx +2 -2
  14. package/components/Backdrop/index.tsx +1 -5
  15. package/components/Backdrop/utils.ts +5 -6
  16. package/components/Badge/index.tsx +1 -5
  17. package/components/Badge/utils.ts +2 -6
  18. package/components/Button/Button.tsx +211 -264
  19. package/components/Button/index.tsx +9 -7
  20. package/components/Button/types.ts +16 -2
  21. package/components/Button/utils.ts +231 -212
  22. package/components/Card/Card.tsx +8 -4
  23. package/components/Card/CardContent.tsx +5 -4
  24. package/components/Card/CardHeader.tsx +5 -3
  25. package/components/Card/CardMedia.tsx +5 -3
  26. package/components/Card/CardTypography.tsx +5 -3
  27. package/components/Card/index.tsx +1 -5
  28. package/components/Card/utils.ts +5 -6
  29. package/components/Checkbox/Checkbox.tsx +1 -0
  30. package/components/Checkbox/CheckboxBase.ios.tsx +1 -0
  31. package/components/Checkbox/CheckboxBase.tsx +1 -0
  32. package/components/Checkbox/index.tsx +1 -5
  33. package/components/Checkbox/utils.ts +6 -6
  34. package/components/Chip/Chip.tsx +40 -52
  35. package/components/Chip/index.tsx +1 -5
  36. package/components/Chip/utils.ts +5 -13
  37. package/components/DatePickerDocked/index.tsx +1 -5
  38. package/components/DatePickerDocked/utils.ts +21 -19
  39. package/components/DatePickerInline/index.tsx +1 -5
  40. package/components/DatePickerInline/utils.ts +41 -28
  41. package/components/DatePickerInput/index.tsx +2 -6
  42. package/components/DatePickerInput/utils.ts +5 -6
  43. package/components/DatePickerModal/DatePickerModalHeader.tsx +1 -1
  44. package/components/DatePickerModal/index.tsx +1 -5
  45. package/components/DatePickerModal/utils.ts +17 -16
  46. package/components/DateTimePicker/index.tsx +1 -5
  47. package/components/DateTimePicker/utils.ts +5 -6
  48. package/components/Dialog/index.tsx +1 -5
  49. package/components/Dialog/utils.ts +22 -16
  50. package/components/Drawer/Collapsible/utils.ts +13 -13
  51. package/components/Drawer/Drawer.tsx +2 -3
  52. package/components/Drawer/DrawerContent.tsx +5 -3
  53. package/components/Drawer/DrawerFooter.tsx +5 -4
  54. package/components/Drawer/DrawerHeader.tsx +5 -4
  55. package/components/Drawer/DrawerItem.tsx +5 -3
  56. package/components/Drawer/DrawerItemGroup.tsx +5 -4
  57. package/components/Drawer/index.tsx +1 -5
  58. package/components/Drawer/utils.ts +7 -7
  59. package/components/ElementGroup/ElementGroup.tsx +16 -14
  60. package/components/ElementGroup/index.tsx +1 -5
  61. package/components/ElementGroup/utils.ts +5 -6
  62. package/components/FAB/index.tsx +1 -5
  63. package/components/FAB/utils.ts +3 -7
  64. package/components/FilePicker/index.tsx +1 -5
  65. package/components/FilePicker/utils.ts +5 -6
  66. package/components/HelperText/index.tsx +1 -5
  67. package/components/HelperText/utils.ts +5 -7
  68. package/components/HorizontalDivider/HorizontalDivider.tsx +5 -3
  69. package/components/HorizontalDivider/index.tsx +1 -5
  70. package/components/Icon/CrossFadeIcon.tsx +3 -5
  71. package/components/Icon/Icon.tsx +3 -14
  72. package/components/Icon/iconFactory.tsx +3 -3
  73. package/components/Icon/index.tsx +2 -6
  74. package/components/Icon/types.ts +17 -6
  75. package/components/IconButton/IconButton.tsx +45 -58
  76. package/components/IconButton/index.tsx +1 -5
  77. package/components/IconButton/utils.ts +15 -26
  78. package/components/If/index.tsx +1 -5
  79. package/components/InputAddon/index.tsx +1 -5
  80. package/components/InputAddon/utils.ts +5 -6
  81. package/components/Link/index.tsx +1 -5
  82. package/components/Link/utils.ts +7 -9
  83. package/components/ListItem/index.tsx +1 -5
  84. package/components/ListItem/utils.ts +13 -11
  85. package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
  86. package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
  87. package/components/LoadingIndicator/index.tsx +13 -0
  88. package/components/LoadingIndicator/utils.ts +117 -0
  89. package/components/Menu/index.tsx +1 -5
  90. package/components/Menu/utils.ts +6 -8
  91. package/components/Modal/index.tsx +1 -5
  92. package/components/Modal/utils.ts +2 -6
  93. package/components/NavigationRail/NavigationRailHeader.tsx +1 -1
  94. package/components/NavigationRail/NavigationRailItem.tsx +2 -1
  95. package/components/NavigationRail/index.tsx +1 -5
  96. package/components/NavigationRail/utils.ts +21 -17
  97. package/components/NavigationStack/index.tsx +1 -5
  98. package/components/NavigationStack/utils.tsx +7 -1
  99. package/components/Portal/index.tsx +1 -5
  100. package/components/RadioButton/index.ts +5 -10
  101. package/components/RadioButton/utils.ts +9 -8
  102. package/components/Rating/RatingItem.tsx +2 -1
  103. package/components/Rating/index.tsx +1 -5
  104. package/components/Rating/utils.ts +6 -8
  105. package/components/Select/Select.tsx +360 -501
  106. package/components/Select/index.ts +7 -14
  107. package/components/Select/types.ts +2 -4
  108. package/components/Select/utils.ts +215 -0
  109. package/components/Slot/Slot.tsx +244 -0
  110. package/components/Slot/compose-refs.tsx +60 -0
  111. package/components/Slot/index.tsx +8 -0
  112. package/components/StateLayer/index.tsx +1 -5
  113. package/components/StateLayer/utils.ts +5 -6
  114. package/components/Surface/Surface.android.tsx +34 -8
  115. package/components/Surface/Surface.ios.tsx +36 -29
  116. package/components/Surface/Surface.tsx +31 -4
  117. package/components/Surface/index.tsx +1 -5
  118. package/components/Surface/utils.ts +49 -36
  119. package/components/Switch/Switch.tsx +8 -2
  120. package/components/Switch/index.tsx +1 -5
  121. package/components/Switch/utils.ts +2 -6
  122. package/components/Tabs/Tabs.tsx +14 -13
  123. package/components/Tabs/index.tsx +1 -5
  124. package/components/Tabs/utils.ts +10 -10
  125. package/components/Text/Text.tsx +2 -8
  126. package/components/TextInput/TextInput.tsx +5 -4
  127. package/components/TextInput/index.tsx +1 -5
  128. package/components/TextInput/utils.ts +8 -15
  129. package/components/TextInputWithMask/index.tsx +1 -5
  130. package/components/TimePicker/AmPmSwitcher.tsx +1 -1
  131. package/components/TimePicker/index.tsx +1 -5
  132. package/components/TimePicker/utils.ts +29 -21
  133. package/components/TimePickerField/index.tsx +1 -5
  134. package/components/TimePickerField/utils.ts +5 -6
  135. package/components/TimePickerModal/TimePickerModal.tsx +6 -2
  136. package/components/TimePickerModal/index.tsx +1 -5
  137. package/components/TimePickerModal/utils.ts +5 -6
  138. package/components/Tooltip/TooltipTrigger.tsx +25 -16
  139. package/components/Tooltip/index.tsx +5 -9
  140. package/components/Tooltip/utils.ts +5 -6
  141. package/components/TouchableRipple/TouchableRipple.native.tsx +49 -13
  142. package/components/TouchableRipple/TouchableRipple.tsx +136 -46
  143. package/components/TouchableRipple/index.tsx +1 -5
  144. package/components/TouchableRipple/utils.ts +5 -6
  145. package/components/VerticalDivider/VerticalDivider.tsx +9 -8
  146. package/components/VerticalDivider/index.tsx +1 -5
  147. package/core/componentsRegistry.ts +31 -19
  148. package/hocs/withPortal.tsx +1 -1
  149. package/hooks/index.tsx +0 -1
  150. package/hooks/useControlledValue.tsx +20 -4
  151. package/hooks/useSubcomponents.tsx +56 -22
  152. package/hooks/useWhatHasUpdated.tsx +48 -0
  153. package/package.json +10 -13
  154. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
  155. package/shortcuts-manager/ShortcutsManager/utils.tsx +3 -2
  156. package/shortcuts-manager/useShortcut/index.tsx +1 -1
  157. package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
  158. package/styles/shadow.ts +2 -1
  159. package/styles/themes/LightTheme.tsx +1 -1
  160. package/utils/extractPropertiesFromStyles.ts +25 -0
  161. package/utils/lodash.ts +77 -6
  162. package/utils/repository.ts +2 -52
  163. package/utils/tokenStylesParser.ts +3 -1
  164. package/hooks/useBreakpoints.tsx +0 -7
@@ -1,8 +1,8 @@
1
1
  import { memo } from 'react';
2
- import { type StyleProp, View, type ViewProps, type ViewStyle } from 'react-native';
2
+ import { View, type ViewProps } from 'react-native';
3
3
  import { StyleSheet } from 'react-native-unistyles';
4
4
 
5
- import { getRegisteredMoleculesComponentStyles, registerComponentStyles } from '../../core';
5
+ import { getRegisteredComponentStylesWithFallback } from '../../core';
6
6
 
7
7
  export type Props = Omit<ViewProps, 'children'> & {
8
8
  /**
@@ -21,7 +21,6 @@ export type Props = Omit<ViewProps, 'children'> & {
21
21
  * Horizontal spacing of the Divider
22
22
  */
23
23
  spacing?: number;
24
- style?: StyleProp<ViewStyle>;
25
24
  };
26
25
 
27
26
  /**
@@ -70,9 +69,9 @@ const VerticalDivider = ({
70
69
  style={[
71
70
  verticalDividerStyles.root,
72
71
  style,
73
- topInset && { marginTop: topInset },
74
- bottomInset && { marginBottom: bottomInset },
75
- spacing && { marginHorizontal: spacing },
72
+ topInset ? { marginTop: topInset } : undefined,
73
+ bottomInset ? { marginBottom: bottomInset } : undefined,
74
+ spacing ? { marginHorizontal: spacing } : undefined,
76
75
  ]}
77
76
  />
78
77
  );
@@ -93,7 +92,9 @@ export const verticalDividerStylesDefault = StyleSheet.create(theme => ({
93
92
  },
94
93
  }));
95
94
 
96
- registerComponentStyles('VerticalDivider', verticalDividerStylesDefault);
97
- export const verticalDividerStyles = getRegisteredMoleculesComponentStyles('HorizontalDivider');
95
+ export const verticalDividerStyles = getRegisteredComponentStylesWithFallback(
96
+ 'VerticalDivider',
97
+ verticalDividerStylesDefault,
98
+ );
98
99
 
99
100
  export default memo(VerticalDivider);
@@ -1,10 +1,6 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import VerticalDividerDefault from './VerticalDivider';
3
3
 
4
- registerMoleculesComponents({
5
- VerticalDivider: VerticalDividerDefault,
6
- });
7
-
8
4
  export const VerticalDivider = getRegisteredComponentWithFallback(
9
5
  'VerticalDivider',
10
6
  VerticalDividerDefault,
@@ -1,18 +1,13 @@
1
- import EventEmitter, {
2
- type ConstructorOptions,
3
- type event as Event,
4
- type eventNS,
5
- } from 'eventemitter2';
6
1
  import type { ComponentType } from 'react';
7
2
 
8
- interface RepositoryConstructor<T> extends ConstructorOptions {
3
+ interface RepositoryConstructor<T> {
9
4
  onRegister?: (arg: T, name: string, registery: Record<string, T>) => T;
10
5
  name?: string;
11
6
  }
12
7
 
13
8
  let id = Date.now();
14
9
 
15
- export class Repository<T> extends EventEmitter {
10
+ export class Repository<T> {
16
11
  private registry: Record<string, T> = {};
17
12
  readonly #name!: string;
18
13
 
@@ -29,9 +24,7 @@ export class Repository<T> extends EventEmitter {
29
24
  constructor({
30
25
  onRegister = arg => arg,
31
26
  name = Repository.uniqueId,
32
- ...options
33
27
  }: RepositoryConstructor<T> = {}) {
34
- super(options);
35
28
  this.#onRegister = onRegister;
36
29
  this.#name = name;
37
30
  }
@@ -40,11 +33,6 @@ export class Repository<T> extends EventEmitter {
40
33
  return !!this.registry[itemName];
41
34
  };
42
35
 
43
- emit(event: eventNS | Event, ...values: any[]) {
44
- event = typeof event === 'string' ? `${this.#name}::event` : event;
45
- return super.emit(event, ...values);
46
- }
47
-
48
36
  /**
49
37
  * Register a item with the src.
50
38
  */
@@ -58,8 +46,6 @@ export class Repository<T> extends EventEmitter {
58
46
  ...this.registry,
59
47
  [itemName]: updatedItem,
60
48
  };
61
-
62
- this.emit('item_registered', itemName);
63
49
  };
64
50
 
65
51
  /**
@@ -92,17 +78,14 @@ export class Repository<T> extends EventEmitter {
92
78
 
93
79
  export const componentsRepository = new Repository<Record<string, any>>({
94
80
  name: 'Components_Repository',
95
- maxListeners: 0,
96
81
  });
97
82
 
98
83
  export const componentsStylesRepository = new Repository<Record<string, any>>({
99
84
  name: 'Components_Styles_Repository',
100
- maxListeners: 0,
101
85
  });
102
86
 
103
87
  export const componentsUtilsRepository = new Repository<Record<string, any>>({
104
88
  name: 'Components_Utils_Repository',
105
- maxListeners: 0,
106
89
  });
107
90
 
108
91
  export const registerMoleculesComponent = componentsRepository.registerOne;
@@ -162,3 +145,32 @@ export function getRegisteredComponentWithFallback<T extends ComponentType<any>>
162
145
  ): T {
163
146
  return (getRegisteredMoleculesComponent(name) ?? defaultComponent) as T;
164
147
  }
148
+
149
+ /**
150
+ * Gets a registered component with a fallback to the default component
151
+ * @param name The name of the component to retrieve
152
+ * @param defaultStyles The default styles to use as fallback
153
+ * @returns The registered styles or the default styles
154
+ */
155
+ export function getRegisteredComponentStylesWithFallback<T extends unknown>(
156
+ name: string,
157
+ defaultStyles: T,
158
+ ): T {
159
+ return (getRegisteredMoleculesComponentStyles(name) ?? defaultStyles) as T;
160
+ }
161
+
162
+ /**
163
+ * Gets a registered component with a fallback to the default component
164
+ * @param name The name of the component to retrieve
165
+ * @param defaultUtils The default utils to use as fallback
166
+ * @returns The registered utils or the default utils
167
+ */
168
+ export function getRegisteredComponentUtilsWithFallback<T extends unknown>(
169
+ name: string,
170
+ defaultUtils: T,
171
+ key?: string,
172
+ ): T {
173
+ return key
174
+ ? (((getRegisteredComponentUtils(name) as Record<string, any>)?.[key] ?? defaultUtils) as T)
175
+ : ((getRegisteredComponentUtils(name) ?? defaultUtils) as T);
176
+ }
@@ -6,7 +6,7 @@ const withPortal =
6
6
  <T,>(Component: ComponentType<T>) =>
7
7
  (props: T) => {
8
8
  return (
9
- <Portal name={'withPortal' + (Component.displayName ?? '')}>
9
+ <Portal>
10
10
  {/* @ts-ignore */}
11
11
  <Component {...(props as T)} />
12
12
  </Portal>
package/hooks/index.tsx CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  export * from './useActionState';
4
4
  export * from './useActive';
5
- export { default as useBreakpoints } from './useBreakpoints';
6
5
  export { default as useColorMode } from './useColorMode';
7
6
  export { useContrastColor } from './useContrastColor';
8
7
  export { default as useControlledValue } from './useControlledValue';
@@ -1,5 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
2
 
3
+ import useLatest from './useLatest';
4
+
3
5
  type ReturnType<T> = [T, (value: T, ...args: any[]) => void];
4
6
 
5
7
  type Args<T> = {
@@ -31,21 +33,35 @@ const useControlledValue = <T,>({
31
33
 
32
34
  const isUncontrolled = useRef(valueProp).current === undefined;
33
35
  const [uncontrolledValue, setValue] = useState(value);
36
+ const valuePropRef = useLatest(valueProp);
37
+ const onChangeRef = useLatest(onChange);
38
+ const manipulateValueRef = useLatest(manipulateValue);
39
+ const uncontrolledValueRef = useLatest(uncontrolledValue);
34
40
 
35
41
  const updateValue = useCallback(
36
42
  (val: T, ...rest: any[]) => {
37
43
  if (disabled) return;
38
44
 
39
45
  if (isUncontrolled) {
40
- setValue(manipulateValue(val, uncontrolledValue));
46
+ setValue(manipulateValueRef.current(val, uncontrolledValueRef.current));
41
47
  }
42
48
 
43
- onChange?.(
44
- manipulateValue(val, isUncontrolled ? uncontrolledValue : valueProp),
49
+ onChangeRef.current?.(
50
+ manipulateValueRef.current(
51
+ val,
52
+ isUncontrolled ? uncontrolledValueRef.current : valuePropRef.current,
53
+ ),
45
54
  ...rest,
46
55
  );
47
56
  },
48
- [disabled, isUncontrolled, manipulateValue, onChange, uncontrolledValue, valueProp],
57
+ [
58
+ disabled,
59
+ isUncontrolled,
60
+ manipulateValueRef,
61
+ onChangeRef,
62
+ uncontrolledValueRef,
63
+ valuePropRef,
64
+ ],
49
65
  );
50
66
 
51
67
  useEffect(() => {
@@ -1,14 +1,23 @@
1
- import type { ReactElement } from 'react';
1
+ import type { ReactElement, ReactNode } from 'react';
2
2
  import { Children, type FC, isValidElement, useMemo } from 'react';
3
3
 
4
4
  export type UseSubcomponentsProps<T extends string> = {
5
- children: ReactElement | ReactElement[];
5
+ children: ReactNode;
6
6
  /**
7
7
  * array of displayName as string
8
8
  * */
9
9
  allowedChildren: T[];
10
+ /**
11
+ * If true, also returns the remaining children that don't match any of the allowedChildren
12
+ * in a `rest` property
13
+ */
14
+ includeRest?: boolean;
10
15
  };
11
16
 
17
+ export type UseSubcomponentsResult<T extends string, IncludeRest extends boolean = false> = {
18
+ [key in T]: ReactElement[];
19
+ } & (IncludeRest extends true ? { rest: ReactNode[] } : {});
20
+
12
21
  /**
13
22
  * This will return an object with the displayNames as the property names
14
23
  * eg. allowedChildren: ['Drawer_Header', 'Drawer_Content', 'Drawer_Footer', 'DrawerItem'];
@@ -19,41 +28,66 @@ export type UseSubcomponentsProps<T extends string> = {
19
28
  * Drawer_Footer: [],
20
29
  * DrawerItem: [],
21
30
  * }
31
+ *
32
+ * If includeRest is true, also returns:
33
+ * {
34
+ * ...above,
35
+ * rest: [remaining children that don't match allowedChildren]
36
+ * }
22
37
  * */
23
- const useSubcomponents = <T extends string = string>({
38
+ function useSubcomponents<T extends string = string, IncludeRest extends boolean = false>({
24
39
  children,
25
40
  allowedChildren,
26
- }: UseSubcomponentsProps<T>) => {
41
+ includeRest,
42
+ }: UseSubcomponentsProps<T> & { includeRest?: IncludeRest }): UseSubcomponentsResult<
43
+ T,
44
+ IncludeRest
45
+ > {
27
46
  return useMemo(() => {
28
47
  // this will create properties with default empty array values even if they don't exist in the children
29
- const defaultContext = allowedChildren.reduce((context, childName) => {
30
- return {
31
- ...context,
32
- [childName]: [],
33
- };
34
- }, {}) as {
35
- [key in T]: ReactElement[];
36
- };
48
+ const defaultContext = allowedChildren.reduce(
49
+ (context, childName) => {
50
+ return {
51
+ ...context,
52
+ [childName]: [],
53
+ };
54
+ },
55
+ includeRest ? { rest: [] as ReactNode[] } : {},
56
+ ) as UseSubcomponentsResult<T, IncludeRest>;
37
57
 
38
- return Children.map(children, child => child).reduce((context, child) => {
39
- if (!isValidElement(child)) return context;
58
+ const childArray = Children.toArray(children);
40
59
 
41
- if (
42
- !allowedChildren.find(name => name === ((child.type as FC).displayName as string))
43
- ) {
60
+ return childArray.reduce((context, child) => {
61
+ if (!isValidElement(child)) {
62
+ // Non-element children go to rest if includeRest is enabled
63
+ if (includeRest) {
64
+ return {
65
+ ...context,
66
+ rest: [...(context as any).rest, child],
67
+ };
68
+ }
44
69
  return context;
45
70
  }
46
71
 
47
- const name = (child.type as FC).displayName as T;
72
+ const displayName = (child.type as FC)?.displayName as string | undefined;
48
73
 
49
- if (!name) return context;
74
+ if (!displayName || !allowedChildren.includes(displayName as T)) {
75
+ // Unmatched elements go to rest if includeRest is enabled
76
+ if (includeRest) {
77
+ return {
78
+ ...context,
79
+ rest: [...(context as any).rest, child],
80
+ };
81
+ }
82
+ return context;
83
+ }
50
84
 
51
85
  return {
52
86
  ...context,
53
- [name]: [...context[name], child],
87
+ [displayName]: [...(context as any)[displayName], child],
54
88
  };
55
89
  }, defaultContext);
56
- }, [allowedChildren, children]);
57
- };
90
+ }, [allowedChildren, children, includeRest]);
91
+ }
58
92
 
59
93
  export default useSubcomponents;
@@ -0,0 +1,48 @@
1
+ import { useEffect, useMemo } from 'react';
2
+
3
+ import useLatest from './useLatest';
4
+
5
+ const map = new Map();
6
+
7
+ export const whatHasUpdatedFactory = <T extends Record<string, unknown>>(
8
+ name: string,
9
+ prevObject: T,
10
+ { debug = false, useCached = false } = {},
11
+ ) => {
12
+ const getPrev = () => {
13
+ if (!map.has(name)) map.set(name, prevObject);
14
+ return useCached ? map.get(name) : prevObject;
15
+ };
16
+
17
+ const setPrev = (value: T) => {
18
+ if (useCached) map.set(name, value);
19
+ else prevObject = value;
20
+ };
21
+
22
+ return (nextObject: T) => {
23
+ const old = getPrev();
24
+ const changes = Object.keys({ ...nextObject, ...old }).reduce((all, key) => {
25
+ const newValue = nextObject?.[key];
26
+ const oldValue = old[key];
27
+ if (oldValue === newValue) return all;
28
+ return { ...all, [key]: { newValue, oldValue } };
29
+ }, {});
30
+
31
+ setPrev(nextObject);
32
+
33
+ if (!debug && !Object.keys(changes).length) return;
34
+ // eslint-disable-next-line no-console
35
+ console.log('🚨🕵️ UPDATED', name, changes);
36
+ };
37
+ };
38
+
39
+ export const useWhatHasUpdated = (name: string, props: Record<string, any>) => {
40
+ const argRef = useLatest({ name, props });
41
+ const checkFunc = useMemo(
42
+ () => whatHasUpdatedFactory(argRef.current.name, argRef.current.props),
43
+ [argRef],
44
+ );
45
+ useEffect(() => {
46
+ checkFunc(props);
47
+ });
48
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-molecules",
3
- "version": "0.5.0-beta.0",
3
+ "version": "0.5.0-beta.10",
4
4
  "author": "Thet Aung <thetaung.dev@gmail.com>",
5
5
  "license": "MIT",
6
6
  "main": "index.ts",
@@ -42,40 +42,37 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@gorhom/portal": "^1.0.14",
45
+ "@radix-ui/react-compose-refs": "^1.1.2",
45
46
  "@react-native-vector-icons/feather": "^12.4.0",
46
47
  "@react-native-vector-icons/material-design-icons": "^12.4.0",
47
48
  "color": "^4.2.3",
48
49
  "date-fns": "^4.1.0",
49
50
  "eventemitter2": "^6.4.9",
50
- "lodash.debounce": "^4.0.8",
51
- "lodash.get": "^4.4.2",
52
- "lodash.keyby": "^4.6.0",
53
- "lodash.memoize": "^4.1.2",
54
- "lodash.omitby": "^4.6.0",
51
+ "flubber": "^0.4.2",
55
52
  "use-sync-external-store": "^1.2.0"
56
53
  },
57
54
  "peerDependencies": {
58
55
  "@react-native-documents/picker": "^10.1.2",
59
56
  "react": "19.1.0",
60
57
  "react-native": "0.81.4",
58
+ "react-native-svg": ">=12.1.0",
61
59
  "react-native-unistyles": "^3.0.15",
62
- "react-native-web": "~0.21.1"
60
+ "react-native-web": "~0.21.1",
61
+ "react-native-reanimated": ">=4.0.0",
62
+ "react-native-redash": ">=18.0.0"
63
63
  },
64
64
  "devDependencies": {
65
+ "@types/flubber": "^0.4.0",
66
+ "react-native-svg": "^15.10.1",
65
67
  "@react-native-documents/picker": "^10.1.2",
66
68
  "@types/color": "^3.0.3",
67
69
  "@types/jest": "^29.1.2",
68
- "@types/lodash": "^4.17.13",
69
- "@types/lodash.debounce": "^4.0.7",
70
- "@types/lodash.get": "^4.4.7",
71
- "@types/lodash.keyby": "^4.6.7",
72
- "@types/lodash.memoize": "^4.1.7",
73
- "@types/lodash.omitby": "^4.6.7",
74
70
  "@types/react": "~19.1.10",
75
71
  "@types/use-sync-external-store": "^1.5.0",
76
72
  "react": "19.1.0",
77
73
  "react-native": "0.81.4",
78
74
  "react-native-builder-bob": "^0.17.1",
75
+ "react-native-reanimated": "~4.1.1",
79
76
  "react-native-unistyles": "^3.0.15",
80
77
  "react-native-web": "~0.21.1"
81
78
  },
@@ -10,9 +10,12 @@ import {
10
10
  type ShortcutsManagerProps,
11
11
  } from './utils';
12
12
 
13
+ const defaultScopes: ShortcutsManagerProps['scopes'] = [];
14
+ const defaultShortcuts: Shortcut[] = [];
15
+
13
16
  const _ShortcutsManager = ({ shortcuts, scopes, children }: ShortcutsManagerProps) => {
14
- const shortcutsRef = useRef<Shortcut[]>(shortcuts || []);
15
- const scopesRef = useRef(scopes);
17
+ const shortcutsRef = useRef<Shortcut[]>(shortcuts || defaultShortcuts);
18
+ const scopesRef = useRef(scopes || defaultScopes);
16
19
  const parentContextRef = useContext(ShortcutsManagerContext);
17
20
 
18
21
  const contextValue = useMemo(() => {
@@ -1,7 +1,8 @@
1
- import type { Scope, Shortcut } from '../types';
2
- import { createFastContext } from '../../fast-context';
3
1
  import type { ReactNode } from 'react';
4
2
 
3
+ import { createFastContext } from '../../fast-context';
4
+ import type { Scope, Shortcut } from '../types';
5
+
5
6
  export type ShortcutsManagerContextType = {
6
7
  shortcuts: Record<string, Shortcut>;
7
8
  scopes: Record<string, Scope>;
@@ -1,2 +1,2 @@
1
- export { default as useShortcut } from './useShortcut';
2
1
  export * from './types';
2
+ export { default as useShortcut } from './useShortcut';
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect } from 'react';
2
- import useLatest from '../../hooks/useLatest';
3
2
 
3
+ import useLatest from '../../hooks/useLatest';
4
4
  import { useShortcutsManagerStoreRef } from '../ShortcutsManager';
5
5
  import type { ShortcutEventDetail } from '../types';
6
6
  import { calculateShortcutEventName } from '../utils';
package/styles/shadow.ts CHANGED
@@ -8,7 +8,8 @@ export const inputRange: MD3Elevation[] = [0, 1, 2, 3, 4, 5];
8
8
  export const shadowHeight = [0, 1, 2, 4, 6, 8];
9
9
  export const shadowRadius = [0, 3, 6, 8, 10, 12];
10
10
 
11
- export default function shadow(elevation: number) {
11
+ export default function shadow(_elevation: number) {
12
+ const elevation = typeof _elevation === 'number' ? (_elevation > 5 ? 5 : _elevation) : 0;
12
13
  return {
13
14
  shadowColor: MD3_SHADOW_COLOR,
14
15
  shadowOpacity: elevation ? MD3_SHADOW_OPACITY : 0,
@@ -25,7 +25,7 @@ export const generateLightThemeColors = (
25
25
  error: palette.error40,
26
26
  errorContainer: palette.error90,
27
27
  onPrimary: palette.primary100,
28
- onPrimaryContainer: palette.primary10,
28
+ onPrimaryContainer: palette.primary30,
29
29
  onSecondary: palette.secondary100,
30
30
  onSecondaryContainer: palette.secondary10,
31
31
  onTertiary: palette.tertiary100,
@@ -0,0 +1,25 @@
1
+ import { StyleSheet } from 'react-native-unistyles';
2
+
3
+ // TODO - abstract this
4
+ export function extractPropertiesFromStyles(
5
+ _objectsArray: Record<string, any>,
6
+ propertiesToExtract: string[],
7
+ ) {
8
+ const extracted: Record<string, any> = {};
9
+
10
+ const objectsArray = StyleSheet.flatten(_objectsArray);
11
+
12
+ for (let i = objectsArray.length - 1; i >= 0; i--) {
13
+ const obj = objectsArray[i];
14
+
15
+ for (const prop of propertiesToExtract) {
16
+ if (!obj) continue;
17
+ if (prop in obj) {
18
+ // @ts-ignore
19
+ extracted[prop] = obj[prop];
20
+ }
21
+ }
22
+ }
23
+
24
+ return extracted;
25
+ }
package/utils/lodash.ts CHANGED
@@ -1,9 +1,80 @@
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';
1
+ type MemoizeCache<K = any, V = any> = {
2
+ has(key: K): boolean;
3
+ get(key: K): V | undefined;
4
+ set(key: K, value: V): unknown;
5
+ };
6
+
7
+ type MemoizeFn = {
8
+ <T extends (...args: any[]) => any>(
9
+ func: T,
10
+ resolver?: (...args: Parameters<T>) => any,
11
+ ): MemoizedFunction<T>;
12
+ Cache: { new (): MemoizeCache<any, any> };
13
+ };
14
+
15
+ export interface MemoizedFunction<T extends (...args: any[]) => any> {
16
+ (...args: Parameters<T>): ReturnType<T>;
17
+ cache: MemoizeCache<any, ReturnType<T>>;
18
+ }
19
+
20
+ export const memoize: MemoizeFn = ((
21
+ func: (...args: any[]) => any,
22
+ resolver?: (...args: any[]) => any,
23
+ ) => {
24
+ if (typeof func !== 'function') {
25
+ throw new TypeError('Expected a function');
26
+ }
27
+ const memoized = function (this: unknown, ...args: any[]) {
28
+ const key = resolver ? resolver.apply(this, args) : args[0];
29
+ const { cache } = memoized as MemoizedFunction<typeof func>;
30
+ if (cache.has(key)) {
31
+ return cache.get(key);
32
+ }
33
+ const result = func.apply(this, args);
34
+ cache.set(key, result);
35
+ return result;
36
+ } as MemoizedFunction<typeof func>;
37
+
38
+ (memoized as MemoizedFunction<typeof func>).cache = new memoize.Cache();
39
+ return memoized;
40
+ }) as MemoizeFn;
41
+
42
+ memoize.Cache = Map;
43
+
44
+ type Iteratee<T> = ((item: T) => string | number | symbol) | keyof T;
45
+
46
+ export const keyBy = <T extends Record<string, any>>(
47
+ collection: T[],
48
+ iteratee: Iteratee<T>,
49
+ ): Record<string, T> => {
50
+ const result: Record<string, T> = {};
51
+ if (!Array.isArray(collection)) return result;
52
+
53
+ const getter = typeof iteratee === 'function' ? iteratee : (item: T) => item[iteratee];
54
+ for (const item of collection) {
55
+ const key = getter(item);
56
+ if (key != null) {
57
+ result[String(key)] = item;
58
+ }
59
+ }
60
+ return result;
61
+ };
62
+
63
+ type Predicate = (value: any, key: string) => boolean;
64
+
65
+ export const omitBy = <T extends Record<string, any>>(
66
+ object: T,
67
+ predicate: Predicate,
68
+ ): Partial<T> => {
69
+ if (object == null) return {};
70
+ const result: Partial<T> = {};
71
+ for (const [key, value] of Object.entries(object)) {
72
+ if (!predicate(value, key)) {
73
+ result[key as keyof T] = value;
74
+ }
75
+ }
76
+ return result;
77
+ };
7
78
 
8
79
  export const isNil = (value: unknown): value is null | undefined => value == null;
9
80
  export const noop = () => {};