react-native-molecules 0.5.0-beta.1 → 0.5.0-beta.11

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 (165) hide show
  1. package/README.md +87 -0
  2. package/components/Accordion/index.tsx +1 -6
  3. package/components/Accordion/utils.ts +17 -14
  4. package/components/ActivityIndicator/ActivityIndicator.tsx +12 -20
  5. package/components/ActivityIndicator/index.tsx +1 -5
  6. package/components/Appbar/index.tsx +1 -4
  7. package/components/Appbar/utils.ts +33 -21
  8. package/components/Avatar/index.tsx +1 -5
  9. package/components/Avatar/utils.ts +2 -6
  10. package/components/Backdrop/Backdrop.tsx +2 -2
  11. package/components/Backdrop/index.tsx +1 -5
  12. package/components/Backdrop/utils.ts +5 -6
  13. package/components/Badge/index.tsx +1 -5
  14. package/components/Badge/utils.ts +2 -6
  15. package/components/Button/Button.tsx +211 -264
  16. package/components/Button/index.tsx +9 -7
  17. package/components/Button/types.ts +16 -2
  18. package/components/Button/utils.ts +231 -210
  19. package/components/Card/Card.tsx +8 -4
  20. package/components/Card/CardContent.tsx +5 -4
  21. package/components/Card/CardHeader.tsx +5 -3
  22. package/components/Card/CardMedia.tsx +5 -3
  23. package/components/Card/CardTypography.tsx +5 -3
  24. package/components/Card/index.tsx +1 -5
  25. package/components/Card/utils.ts +5 -6
  26. package/components/Checkbox/Checkbox.tsx +1 -0
  27. package/components/Checkbox/CheckboxBase.ios.tsx +1 -0
  28. package/components/Checkbox/CheckboxBase.tsx +24 -128
  29. package/components/Checkbox/index.tsx +1 -5
  30. package/components/Checkbox/utils.ts +6 -31
  31. package/components/Chip/Chip.tsx +40 -52
  32. package/components/Chip/index.tsx +1 -5
  33. package/components/Chip/utils.ts +5 -13
  34. package/components/DatePickerDocked/index.tsx +1 -5
  35. package/components/DatePickerDocked/utils.ts +21 -19
  36. package/components/DatePickerInline/index.tsx +1 -5
  37. package/components/DatePickerInline/utils.ts +41 -28
  38. package/components/DatePickerInput/DatePickerInput.tsx +4 -2
  39. package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -4
  40. package/components/DatePickerInput/index.tsx +1 -5
  41. package/components/DatePickerInput/types.ts +1 -3
  42. package/components/DatePickerInput/utils.ts +5 -6
  43. package/components/DatePickerModal/CalendarEdit.tsx +10 -9
  44. package/components/DatePickerModal/DatePickerModalHeader.tsx +1 -1
  45. package/components/DatePickerModal/index.tsx +1 -5
  46. package/components/DatePickerModal/utils.ts +17 -16
  47. package/components/DateTimePicker/index.tsx +1 -5
  48. package/components/DateTimePicker/utils.ts +5 -6
  49. package/components/Dialog/index.tsx +1 -5
  50. package/components/Dialog/utils.ts +22 -16
  51. package/components/Drawer/Collapsible/utils.ts +13 -13
  52. package/components/Drawer/Drawer.tsx +2 -3
  53. package/components/Drawer/DrawerContent.tsx +5 -3
  54. package/components/Drawer/DrawerFooter.tsx +5 -4
  55. package/components/Drawer/DrawerHeader.tsx +5 -4
  56. package/components/Drawer/DrawerItem.tsx +5 -3
  57. package/components/Drawer/DrawerItemGroup.tsx +5 -4
  58. package/components/Drawer/index.tsx +1 -5
  59. package/components/Drawer/utils.ts +7 -7
  60. package/components/ElementGroup/ElementGroup.tsx +16 -14
  61. package/components/ElementGroup/index.tsx +1 -5
  62. package/components/ElementGroup/utils.ts +5 -6
  63. package/components/FAB/index.tsx +1 -5
  64. package/components/FAB/utils.ts +2 -6
  65. package/components/FilePicker/FilePicker.tsx +47 -76
  66. package/components/FilePicker/index.tsx +1 -5
  67. package/components/FilePicker/utils.ts +5 -6
  68. package/components/HelperText/HelperText.tsx +0 -35
  69. package/components/HelperText/index.tsx +1 -5
  70. package/components/HelperText/utils.ts +5 -7
  71. package/components/HorizontalDivider/HorizontalDivider.tsx +5 -3
  72. package/components/HorizontalDivider/index.tsx +1 -5
  73. package/components/Icon/CrossFadeIcon.tsx +3 -5
  74. package/components/Icon/Icon.tsx +2 -4
  75. package/components/Icon/iconFactory.tsx +3 -3
  76. package/components/Icon/index.tsx +2 -6
  77. package/components/Icon/types.ts +17 -6
  78. package/components/IconButton/IconButton.tsx +45 -58
  79. package/components/IconButton/index.tsx +1 -5
  80. package/components/IconButton/utils.ts +153 -49
  81. package/components/If/index.tsx +1 -5
  82. package/components/InputAddon/index.tsx +1 -5
  83. package/components/InputAddon/utils.ts +5 -6
  84. package/components/Link/index.tsx +1 -5
  85. package/components/Link/utils.ts +2 -6
  86. package/components/ListItem/index.tsx +1 -5
  87. package/components/ListItem/utils.ts +13 -11
  88. package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
  89. package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
  90. package/components/LoadingIndicator/index.tsx +13 -0
  91. package/components/LoadingIndicator/utils.ts +117 -0
  92. package/components/Menu/index.tsx +1 -5
  93. package/components/Menu/utils.ts +6 -8
  94. package/components/Modal/index.tsx +1 -5
  95. package/components/Modal/utils.ts +2 -6
  96. package/components/NavigationRail/NavigationRailHeader.tsx +1 -1
  97. package/components/NavigationRail/index.tsx +1 -5
  98. package/components/NavigationRail/utils.ts +21 -17
  99. package/components/NavigationStack/index.tsx +1 -5
  100. package/components/NavigationStack/utils.tsx +7 -1
  101. package/components/Portal/index.tsx +1 -5
  102. package/components/RadioButton/index.ts +1 -5
  103. package/components/RadioButton/utils.ts +9 -8
  104. package/components/Rating/index.tsx +1 -5
  105. package/components/Rating/utils.ts +6 -8
  106. package/components/Select/Select.tsx +369 -507
  107. package/components/Select/index.ts +7 -14
  108. package/components/Select/types.ts +2 -4
  109. package/components/Select/utils.ts +215 -0
  110. package/components/Slot/Slot.tsx +244 -0
  111. package/components/Slot/compose-refs.tsx +60 -0
  112. package/components/Slot/index.tsx +8 -0
  113. package/components/StateLayer/index.tsx +1 -5
  114. package/components/StateLayer/utils.ts +5 -6
  115. package/components/Surface/Surface.android.tsx +34 -8
  116. package/components/Surface/Surface.ios.tsx +36 -29
  117. package/components/Surface/Surface.tsx +31 -4
  118. package/components/Surface/index.tsx +1 -5
  119. package/components/Surface/utils.ts +49 -36
  120. package/components/Switch/Switch.tsx +8 -2
  121. package/components/Switch/index.tsx +1 -5
  122. package/components/Switch/utils.ts +2 -6
  123. package/components/Tabs/TabItem.tsx +35 -58
  124. package/components/Tabs/TabLabel.tsx +5 -9
  125. package/components/Tabs/Tabs.tsx +154 -149
  126. package/components/Tabs/index.tsx +1 -5
  127. package/components/Tabs/utils.ts +25 -12
  128. package/components/Text/Text.tsx +2 -8
  129. package/components/TextInput/TextInput.tsx +655 -571
  130. package/components/TextInput/index.tsx +19 -7
  131. package/components/TextInput/types.ts +76 -27
  132. package/components/TextInput/utils.ts +232 -159
  133. package/components/TextInputWithMask/index.tsx +1 -5
  134. package/components/TimePicker/AmPmSwitcher.tsx +1 -1
  135. package/components/TimePicker/index.tsx +1 -5
  136. package/components/TimePicker/utils.ts +29 -21
  137. package/components/TimePickerField/TimePickerField.tsx +7 -5
  138. package/components/TimePickerField/index.tsx +1 -5
  139. package/components/TimePickerField/utils.ts +5 -6
  140. package/components/TimePickerModal/TimePickerModal.tsx +6 -2
  141. package/components/TimePickerModal/index.tsx +1 -5
  142. package/components/TimePickerModal/utils.ts +5 -6
  143. package/components/Tooltip/TooltipTrigger.tsx +25 -16
  144. package/components/Tooltip/index.tsx +1 -5
  145. package/components/Tooltip/utils.ts +5 -6
  146. package/components/TouchableRipple/TouchableRipple.native.tsx +50 -14
  147. package/components/TouchableRipple/TouchableRipple.tsx +137 -47
  148. package/components/TouchableRipple/index.tsx +1 -5
  149. package/components/TouchableRipple/utils.ts +5 -6
  150. package/components/VerticalDivider/VerticalDivider.tsx +9 -8
  151. package/components/VerticalDivider/index.tsx +1 -5
  152. package/core/componentsRegistry.ts +31 -19
  153. package/hocs/withPortal.tsx +1 -1
  154. package/hooks/index.tsx +0 -5
  155. package/hooks/useControlledValue.tsx +20 -4
  156. package/hooks/useSubcomponents.tsx +63 -31
  157. package/hooks/useWhatHasUpdated.tsx +48 -0
  158. package/package.json +12 -15
  159. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
  160. package/styles/shadow.ts +2 -1
  161. package/styles/themes/LightTheme.tsx +1 -1
  162. package/utils/extractPropertiesFromStyles.ts +25 -0
  163. package/utils/lodash.ts +77 -6
  164. package/utils/repository.ts +2 -52
  165. package/hooks/useSearchable.tsx +0 -74
@@ -1,8 +1,8 @@
1
- import { forwardRef, memo, type ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
1
+ import { memo, useCallback, useMemo } from 'react';
2
2
 
3
+ import useControlledValue from '../../hooks/useControlledValue';
3
4
  import useFilePicker from '../../hooks/useFilePicker';
4
5
  import type { DocumentPickerOptions, DocumentResult } from '../../utils/DocumentPicker';
5
- import { ActivityIndicator } from '../ActivityIndicator';
6
6
  import { IconButton } from '../IconButton';
7
7
  import { TextInput, type TextInputProps } from '../TextInput';
8
8
 
@@ -10,6 +10,7 @@ export type OmitProp =
10
10
  | 'editable'
11
11
  | 'multiline'
12
12
  | 'onChangeText'
13
+ | 'onChange'
13
14
  | 'keyboardType'
14
15
  | 'defaultValue'
15
16
  | 'value'
@@ -24,12 +25,9 @@ export type Props = Omit<TextInputProps, OmitProp> &
24
25
  */
25
26
  multiple?: boolean;
26
27
  /**
27
- * Displays the Spinner on the right side in place of the default upload icon
28
- * @default false
28
+ * Default value for uncontrolled usage
29
29
  */
30
- loading?: boolean;
31
- left?: ReactNode;
32
- right?: ReactNode;
30
+ defaultValue?: DocumentResult | DocumentResult[];
33
31
  /**
34
32
  * To Control the value
35
33
  */
@@ -37,32 +35,31 @@ export type Props = Omit<TextInputProps, OmitProp> &
37
35
  /**
38
36
  * The Callback function to return the selected files as an array or object
39
37
  */
40
- onChange?: (result: DocumentResult | DocumentResult[]) => any;
41
- /**
42
- * To replace the default progress indicator
43
- */
44
- progressIndicator?: ReactNode;
38
+ onChange?: (result: DocumentResult | DocumentResult[] | undefined) => any;
45
39
  };
46
40
 
47
- const FilePicker = (
48
- {
49
- loading,
50
- right: rightProp,
51
- progressIndicator,
52
- type,
53
- multiple,
54
- transitionStyle,
55
- mode,
56
- presentationStyle,
57
- value,
58
- onChange = () => {},
59
- onCancel,
60
- onError,
61
- ...rest
62
- }: Props,
63
- ref: any,
64
- ) => {
65
- const [displayText, setDisplayText] = useState('');
41
+ const FilePicker = ({
42
+ ref,
43
+ type,
44
+ multiple,
45
+ transitionStyle,
46
+ mode,
47
+ presentationStyle,
48
+ value: valueProp,
49
+ defaultValue,
50
+ onChange,
51
+ onCancel,
52
+ onError,
53
+ children,
54
+ ...rest
55
+ }: Props) => {
56
+ const [value, onValueChange] = useControlledValue<
57
+ DocumentResult | DocumentResult[] | undefined
58
+ >({
59
+ value: valueProp,
60
+ defaultValue,
61
+ onChange,
62
+ });
66
63
 
67
64
  const { openFilePicker } = useFilePicker({
68
65
  type,
@@ -74,60 +71,34 @@ const FilePicker = (
74
71
  onError,
75
72
  });
76
73
 
77
- const onSetInputValue = useCallback(
78
- (response: DocumentResult | DocumentResult[] | undefined) => {
79
- if (Array.isArray(response)) {
80
- if (response.length > 1) {
81
- setDisplayText(`${response.length} file${response.length > 1 ? 's' : ''}`);
82
- return;
83
- }
74
+ const displayText = useMemo(() => {
75
+ if (!value) return '';
84
76
 
85
- setDisplayText(response[0].name || '');
86
- return;
77
+ if (Array.isArray(value)) {
78
+ if (value.length > 1) {
79
+ return `${value.length} files`;
87
80
  }
81
+ return value[0]?.name || '';
82
+ }
88
83
 
89
- setDisplayText(response?.name || '');
90
- },
91
- [],
92
- );
84
+ return value.name || '';
85
+ }, [value]);
93
86
 
94
87
  const onPress = useCallback(() => {
95
88
  openFilePicker(response => {
96
- onSetInputValue(response);
97
-
98
- onChange?.(response);
89
+ onValueChange(response);
99
90
  });
100
- }, [onChange, onSetInputValue, openFilePicker]);
101
-
102
- const rightElement = useMemo(() => {
103
- if (!loading) {
104
- return (
105
- <>
106
- {rightProp || (
107
- <IconButton type="material-community" name="upload" onPress={onPress} />
108
- )}
109
- </>
110
- );
111
- } else {
112
- return <>{progressIndicator || <ActivityIndicator />}</>;
113
- }
114
- }, [loading, onPress, progressIndicator, rightProp]);
115
-
116
- // if the value changes, we only want file name or the length of the array to display the text
117
- useEffect(() => {
118
- onSetInputValue(value);
119
- }, [onSetInputValue, value]);
91
+ }, [onValueChange, openFilePicker]);
120
92
 
121
93
  return (
122
- <TextInput
123
- label="Choose file"
124
- {...rest}
125
- value={displayText}
126
- editable={false}
127
- right={rightElement}
128
- ref={ref}
129
- />
94
+ <TextInput value={displayText} {...rest} editable={false} ref={ref}>
95
+ <TextInput.Label>Choose file</TextInput.Label>
96
+ <TextInput.Right>
97
+ <IconButton type="material-community" name="upload" onPress={onPress} />
98
+ </TextInput.Right>
99
+ {children}
100
+ </TextInput>
130
101
  );
131
102
  };
132
103
 
133
- export default memo(forwardRef(FilePicker));
104
+ export default memo(FilePicker);
@@ -1,10 +1,6 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import FilePickerDefault from './FilePicker';
3
3
 
4
- registerMoleculesComponents({
5
- FilePicker: FilePickerDefault,
6
- });
7
-
8
4
  export const FilePicker = getRegisteredComponentWithFallback('FilePicker', FilePickerDefault);
9
5
 
10
6
  export type { Props as FilePickerProps } from './FilePicker';
@@ -1,13 +1,12 @@
1
1
  import { StyleSheet } from 'react-native-unistyles';
2
2
 
3
- import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
3
+ import { getRegisteredComponentStylesWithFallback } from '../../core';
4
4
 
5
5
  const filePickerStylesDefault = StyleSheet.create({
6
6
  root: {},
7
7
  });
8
8
 
9
- registerComponentsStyles({
10
- FilePicker: filePickerStylesDefault,
11
- });
12
-
13
- export const defaultStyles = getRegisteredMoleculesComponentStyles('FilePicker');
9
+ export const defaultStyles = getRegisteredComponentStylesWithFallback(
10
+ 'FilePicker',
11
+ filePickerStylesDefault,
12
+ );
@@ -24,41 +24,6 @@ export type Props = TextProps & {
24
24
  testID?: string;
25
25
  };
26
26
 
27
- /**
28
- * Helper text is used in conjuction with input elements to provide additional hints for the user.
29
- *
30
- * <div class="screenshots">
31
- * <img class="small" src="screenshots/helper-text.gif" />
32
- * </div>
33
- *
34
- * ## Usage
35
- * ```js
36
- * import * as React from 'react';
37
- * import { View } from 'react-native';
38
- * import { HelperText, TextInput } from 'react-native-paper';
39
- *
40
- * const MyComponent = () => {
41
- * const [text, setText] = React.useState('');
42
- *
43
- * const onChangeText = text => setText(text);
44
- *
45
- * const hasErrors = () => {
46
- * return !text.includes('@');
47
- * };
48
- *
49
- * return (
50
- * <View>
51
- * <TextInput label="Email" value={text} onChangeText={onChangeText} />
52
- * <HelperText variant="error" visible={hasErrors()}>
53
- * Email address is invalid!
54
- * </HelperText>
55
- * </View>
56
- * );
57
- * };
58
- *
59
- * export default MyComponent;
60
- * ```
61
- */
62
27
  const HelperText = ({
63
28
  style: styleProp,
64
29
  variant = 'info',
@@ -1,10 +1,6 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import HelperTextDefault from './HelperText';
3
3
 
4
- registerMoleculesComponents({
5
- HelperText: HelperTextDefault,
6
- });
7
-
8
4
  export const HelperText = getRegisteredComponentWithFallback('HelperText', HelperTextDefault);
9
5
 
10
6
  export { type Props as HelperTextProps } from './HelperText';
@@ -1,6 +1,6 @@
1
1
  import { StyleSheet } from 'react-native-unistyles';
2
2
 
3
- import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
3
+ import { getRegisteredComponentStylesWithFallback } from '../../core';
4
4
 
5
5
  export const helperTextStylesDefault = StyleSheet.create(theme => ({
6
6
  root: {
@@ -21,9 +21,7 @@ export const helperTextStylesDefault = StyleSheet.create(theme => ({
21
21
  },
22
22
  }));
23
23
 
24
- registerComponentsStyles({
25
- HelperText: helperTextStylesDefault,
26
- });
27
-
28
- export const styles =
29
- getRegisteredMoleculesComponentStyles('HelperText') || helperTextStylesDefault;
24
+ export const styles = getRegisteredComponentStylesWithFallback(
25
+ 'HelperText',
26
+ helperTextStylesDefault,
27
+ );
@@ -2,7 +2,7 @@ import { memo } from 'react';
2
2
  import { type StyleProp, View, type ViewProps, type ViewStyle } 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
  /**
@@ -95,7 +95,9 @@ export const horizontalDividerStylesDefault = StyleSheet.create(theme => ({
95
95
  },
96
96
  }));
97
97
 
98
- registerComponentStyles('HorizontalDivider', horizontalDividerStylesDefault);
99
- export const horizontalDividerStyles = getRegisteredMoleculesComponentStyles('HorizontalDivider');
98
+ export const horizontalDividerStyles = getRegisteredComponentStylesWithFallback(
99
+ 'HorizontalDivider',
100
+ horizontalDividerStylesDefault,
101
+ );
100
102
 
101
103
  export default memo(HorizontalDivider);
@@ -1,10 +1,6 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import HorizontalDividerDefault from './HorizontalDivider';
3
3
 
4
- registerMoleculesComponents({
5
- HorizontalDivider: HorizontalDividerDefault,
6
- });
7
-
8
4
  export const HorizontalDivider = getRegisteredComponentWithFallback(
9
5
  'HorizontalDivider',
10
6
  HorizontalDividerDefault,
@@ -1,14 +1,12 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { Animated, StyleSheet, View } from 'react-native';
3
3
 
4
- import Icon, { styles as iconStyles } from './Icon';
4
+ import Icon from './Icon';
5
5
  import type { IconProps } from './types';
6
6
 
7
7
  type Props = IconProps;
8
8
 
9
9
  const CrossFadeIcon = ({ color, size, name, style, ...rest }: Omit<Props, 'ref'>) => {
10
- // const { animationScale: scale } = useComponentStyles('Icon', style);
11
- const { animationScale: scale } = iconStyles.root;
12
10
  const [currentIcon, setCurrentIcon] = useState<string>(name);
13
11
  const [previousIcon, setPreviousIcon] = useState<string | null>(null);
14
12
  const { current: fade } = useRef<Animated.Value>(new Animated.Value(1));
@@ -25,12 +23,12 @@ const CrossFadeIcon = ({ color, size, name, style, ...rest }: Omit<Props, 'ref'>
25
23
  fade.setValue(1);
26
24
 
27
25
  Animated.timing(fade, {
28
- duration: scale * 200,
26
+ duration: 200,
29
27
  toValue: 0,
30
28
  useNativeDriver: true,
31
29
  }).start();
32
30
  }
33
- }, [currentIcon, previousIcon, fade, scale]);
31
+ }, [currentIcon, previousIcon, fade]);
34
32
 
35
33
  const opacityPrev = fade;
36
34
  const opacityNext = previousIcon
@@ -1,7 +1,7 @@
1
1
  import { forwardRef, memo, useMemo } from 'react';
2
2
  import { StyleSheet } from 'react-native-unistyles';
3
3
 
4
- import { getRegisteredMoleculesComponentStyles, registerComponentStyles } from '../../core';
4
+ import { getRegisteredComponentStylesWithFallback } from '../../core';
5
5
  import { tokenStylesParser } from '../../utils/tokenStylesParser';
6
6
  import iconFactory from './iconFactory';
7
7
  import type { IconProps } from './types';
@@ -25,8 +25,6 @@ export const iconStylesDefault = StyleSheet.create(theme => ({
25
25
  },
26
26
  }));
27
27
 
28
- registerComponentStyles('Icon', iconStylesDefault);
29
-
30
- export const styles = getRegisteredMoleculesComponentStyles('Icon');
28
+ export const styles = getRegisteredComponentStylesWithFallback('Icon', iconStylesDefault);
31
29
 
32
30
  export default memo(forwardRef(Icon));
@@ -1,6 +1,6 @@
1
1
  // import { textFactory } from '../Text/textFactory';
2
2
  import { memoize } from '../../utils/lodash';
3
- import { IconPacks, type IconType } from './types';
3
+ import type { IconType } from './types';
4
4
 
5
5
  const customIcons: any = {};
6
6
 
@@ -10,9 +10,9 @@ export const registerCustomIconType = (id: string, customIcon: any) => {
10
10
 
11
11
  export default memoize((type: IconType) => {
12
12
  switch (type) {
13
- case IconPacks.MaterialCommunity:
13
+ case 'material-community':
14
14
  return require('@react-native-vector-icons/material-design-icons').default;
15
- case IconPacks.Feather:
15
+ case 'feather':
16
16
  return require('@react-native-vector-icons/feather').default;
17
17
  default:
18
18
  if (Object.prototype.hasOwnProperty.call(customIcons, type)) {
@@ -1,11 +1,7 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import IconDefault from './Icon';
3
3
 
4
- registerMoleculesComponents({
5
- Icon: IconDefault,
6
- });
7
-
8
4
  export const Icon = getRegisteredComponentWithFallback('Icon', IconDefault);
9
5
 
10
6
  export { registerCustomIconType } from './iconFactory';
11
- export type { IconPacks, IconProps, IconType } from './types';
7
+ export type { CustomIconTypes, IconProps, IconType } from './types';
@@ -1,10 +1,5 @@
1
1
  import type { ColorValue, TextProps } from 'react-native';
2
2
 
3
- export enum IconPacks {
4
- MaterialCommunity = 'material-community',
5
- Feather = 'feather',
6
- }
7
-
8
3
  export interface VectorIconProps extends TextProps {
9
4
  /**
10
5
  * Size of the icon, can also be passed as fontSize in the style object.
@@ -28,7 +23,23 @@ export interface VectorIconProps extends TextProps {
28
23
  color?: ColorValue | number | undefined;
29
24
  }
30
25
 
31
- export type IconType = `${IconPacks}`; // in TS 4.1+, we can do this to make enum values as a union type
26
+ /**
27
+ * Interface for registering custom icon types.
28
+ * Users can extend this interface via declaration merging to add their own icon types.
29
+ *
30
+ * @example
31
+ * // In your app's type declarations (e.g., global.d.ts or a dedicated types file)
32
+ * declare module 'react-native-molecules' {
33
+ * interface CustomIconTypes {
34
+ * 'my-custom-icons': true;
35
+ * 'another-icon-set': true;
36
+ * }
37
+ * }
38
+ */
39
+
40
+ export interface CustomIconTypes {}
41
+
42
+ export type IconType = 'material-community' | 'feather' | keyof CustomIconTypes;
32
43
 
33
44
  export type IconProps = VectorIconProps & {
34
45
  type?: IconType;
@@ -5,15 +5,13 @@ import {
5
5
  type StyleProp,
6
6
  type TextStyle,
7
7
  type ViewProps,
8
- type ViewStyle,
9
8
  } from 'react-native';
10
9
 
11
10
  import { useActionState } from '../../hooks/useActionState';
12
11
  import { resolveStateVariant } from '../../utils';
13
- import { Icon, type IconType } from '../Icon';
12
+ import { Icon, type IconProps, type IconType } from '../Icon';
14
13
  import CrossFadeIcon from '../Icon/CrossFadeIcon';
15
14
  import { StateLayer } from '../StateLayer';
16
- import { Surface } from '../Surface';
17
15
  import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
18
16
  import type { IconButtonVariant } from './types';
19
17
  import { defaultStyles, iconButtonSizeToIconSizeMap } from './utils';
@@ -63,14 +61,11 @@ export type Props = Omit<TouchableRippleProps, 'children' | 'style'> & {
63
61
  */
64
62
  style?: StyleProp<TextStyle>;
65
63
  iconStyle?: StyleProp<TextStyle>;
64
+ iconProps?: Omit<IconProps, 'name' | 'type' | 'style' | 'color' | 'size'>;
66
65
  /**
67
66
  * color of the icon
68
67
  */
69
68
  color?: string;
70
- /**
71
- * Style of the innerContainer
72
- */
73
- innerContainerStyle?: ViewStyle;
74
69
  /**
75
70
  * Props for the state layer
76
71
  * */
@@ -92,10 +87,10 @@ const IconButton = (
92
87
  animated = false,
93
88
  variant = 'default',
94
89
  style,
95
- innerContainerStyle: innerContainerStyleProp = emptyObject,
96
90
  testID,
97
91
  stateLayerProps = emptyObject,
98
- iconStyle,
92
+ iconStyle: iconStyleProp,
93
+ iconProps,
99
94
  ...rest
100
95
  }: Props,
101
96
  ref: any,
@@ -113,7 +108,9 @@ const IconButton = (
113
108
  });
114
109
 
115
110
  defaultStyles.useVariants({
116
- variant,
111
+ // @ts-ignore // TODO - fix this
112
+ variant: variant as any,
113
+ // @ts-ignore // TODO - fix this
117
114
  state,
118
115
  size: typeof size === 'string' && size ? size : undefined,
119
116
  });
@@ -124,9 +121,9 @@ const IconButton = (
124
121
  rippleColor,
125
122
  containerStyle,
126
123
  accessibilityState,
127
- innerContainerStyle,
128
124
  // accessibilityTraits,
129
125
  stateLayerStyle,
126
+ iconStyle,
130
127
  } = useMemo(() => {
131
128
  const iconSizeInNum =
132
129
  iconButtonSizeToIconSizeMap[size as keyof typeof iconButtonSizeToIconSizeMap] ??
@@ -144,7 +141,6 @@ const IconButton = (
144
141
  iconColor: _iconColor,
145
142
  iconSize: iconSizeInNum,
146
143
  rippleColor: _rippleColor,
147
- innerContainerStyle: [defaultStyles.innerContainer, innerContainerStyleProp],
148
144
  containerStyle: [
149
145
  iconSizeInNum
150
146
  ? {
@@ -155,60 +151,51 @@ const IconButton = (
155
151
  defaultStyles.root,
156
152
  style,
157
153
  ],
154
+ iconStyle: [defaultStyles.icon, iconStyleProp],
158
155
  // accessibilityTraits: disabled ? ['button', 'disabled'] : 'button',
159
156
  accessibilityState: { disabled },
160
157
  stateLayerStyle: [defaultStyles.stateLayer, stateLayerProps?.style],
161
158
  };
162
159
  // eslint-disable-next-line react-hooks/exhaustive-deps
163
- }, [
164
- _iconColor,
165
- disabled,
166
- innerContainerStyleProp,
167
- size,
168
- stateLayerProps?.style,
169
- style,
170
- state,
171
- variant,
172
- ]);
160
+ }, [_iconColor, disabled, size, stateLayerProps?.style, style, state, variant]);
173
161
 
174
162
  return (
175
- <Surface style={containerStyle} elevation={0}>
176
- <TouchableRipple
177
- borderless
178
- centered
179
- onPress={onPress}
180
- rippleColor={rippleColor}
181
- accessibilityLabel={accessibilityLabel}
182
- style={innerContainerStyle}
183
- // accessibilityTraits={accessibilityTraits}
184
- // accessibilityComponentType="button"
185
- accessibilityRole="button"
186
- accessibilityState={accessibilityState}
187
- disabled={disabled}
188
- hitSlop={
189
- // @ts-ignore
190
- TouchableRipple?.supported ? rippleSupportedHitSlop : rippleUnsupportedHitSlop
191
- }
163
+ <TouchableRipple
164
+ borderless
165
+ centered
166
+ onPress={onPress}
167
+ rippleColor={rippleColor}
168
+ accessibilityLabel={accessibilityLabel}
169
+ style={containerStyle}
170
+ // accessibilityTraits={accessibilityTraits}
171
+ // accessibilityComponentType="button"
172
+ accessibilityRole="button"
173
+ accessibilityState={accessibilityState}
174
+ disabled={disabled}
175
+ hitSlop={
192
176
  // @ts-ignore
193
- ref={actionsRef}
194
- testID={testID}
195
- {...rest}>
196
- <>
197
- <IconComponent
198
- color={iconColor}
199
- name={name}
200
- size={iconSize}
201
- type={type}
202
- style={iconStyle}
203
- />
204
- <StateLayer
205
- testID={testID ? `${testID}-stateLayer` : ''}
206
- {...stateLayerProps}
207
- style={stateLayerStyle}
208
- />
209
- </>
210
- </TouchableRipple>
211
- </Surface>
177
+ TouchableRipple?.supported ? rippleSupportedHitSlop : rippleUnsupportedHitSlop
178
+ }
179
+ // @ts-ignore
180
+ ref={actionsRef}
181
+ testID={testID}
182
+ {...rest}>
183
+ <>
184
+ <IconComponent
185
+ color={iconColor}
186
+ name={name}
187
+ size={iconSize}
188
+ type={type}
189
+ style={iconStyle}
190
+ {...iconProps}
191
+ />
192
+ <StateLayer
193
+ testID={testID ? `${testID}-stateLayer` : ''}
194
+ {...stateLayerProps}
195
+ style={stateLayerStyle}
196
+ />
197
+ </>
198
+ </TouchableRipple>
212
199
  );
213
200
  };
214
201
 
@@ -1,10 +1,6 @@
1
- import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
2
  import IconButtonDefault from './IconButton';
3
3
 
4
- registerMoleculesComponents({
5
- IconButton: IconButtonDefault,
6
- });
7
-
8
4
  export const IconButton = getRegisteredComponentWithFallback('IconButton', IconButtonDefault);
9
5
 
10
6
  export type { Props as IconButtonProps } from './IconButton';