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.
- package/README.md +87 -0
- package/components/Accordion/index.tsx +1 -6
- package/components/Accordion/utils.ts +17 -14
- package/components/ActivityIndicator/ActivityIndicator.tsx +12 -20
- package/components/ActivityIndicator/index.tsx +1 -5
- package/components/Appbar/index.tsx +1 -4
- package/components/Appbar/utils.ts +33 -21
- package/components/Avatar/index.tsx +1 -5
- package/components/Avatar/utils.ts +2 -6
- package/components/Backdrop/Backdrop.tsx +2 -2
- package/components/Backdrop/index.tsx +1 -5
- package/components/Backdrop/utils.ts +5 -6
- package/components/Badge/index.tsx +1 -5
- package/components/Badge/utils.ts +2 -6
- package/components/Button/Button.tsx +211 -264
- package/components/Button/index.tsx +9 -7
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +231 -210
- package/components/Card/Card.tsx +8 -4
- package/components/Card/CardContent.tsx +5 -4
- package/components/Card/CardHeader.tsx +5 -3
- package/components/Card/CardMedia.tsx +5 -3
- package/components/Card/CardTypography.tsx +5 -3
- package/components/Card/index.tsx +1 -5
- package/components/Card/utils.ts +5 -6
- package/components/Checkbox/Checkbox.tsx +1 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +1 -0
- package/components/Checkbox/CheckboxBase.tsx +24 -128
- package/components/Checkbox/index.tsx +1 -5
- package/components/Checkbox/utils.ts +6 -31
- package/components/Chip/Chip.tsx +40 -52
- package/components/Chip/index.tsx +1 -5
- package/components/Chip/utils.ts +5 -13
- package/components/DatePickerDocked/index.tsx +1 -5
- package/components/DatePickerDocked/utils.ts +21 -19
- package/components/DatePickerInline/index.tsx +1 -5
- package/components/DatePickerInline/utils.ts +41 -28
- package/components/DatePickerInput/DatePickerInput.tsx +4 -2
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -4
- package/components/DatePickerInput/index.tsx +1 -5
- package/components/DatePickerInput/types.ts +1 -3
- package/components/DatePickerInput/utils.ts +5 -6
- package/components/DatePickerModal/CalendarEdit.tsx +10 -9
- package/components/DatePickerModal/DatePickerModalHeader.tsx +1 -1
- package/components/DatePickerModal/index.tsx +1 -5
- package/components/DatePickerModal/utils.ts +17 -16
- package/components/DateTimePicker/index.tsx +1 -5
- package/components/DateTimePicker/utils.ts +5 -6
- package/components/Dialog/index.tsx +1 -5
- package/components/Dialog/utils.ts +22 -16
- package/components/Drawer/Collapsible/utils.ts +13 -13
- package/components/Drawer/Drawer.tsx +2 -3
- package/components/Drawer/DrawerContent.tsx +5 -3
- package/components/Drawer/DrawerFooter.tsx +5 -4
- package/components/Drawer/DrawerHeader.tsx +5 -4
- package/components/Drawer/DrawerItem.tsx +5 -3
- package/components/Drawer/DrawerItemGroup.tsx +5 -4
- package/components/Drawer/index.tsx +1 -5
- package/components/Drawer/utils.ts +7 -7
- package/components/ElementGroup/ElementGroup.tsx +16 -14
- package/components/ElementGroup/index.tsx +1 -5
- package/components/ElementGroup/utils.ts +5 -6
- package/components/FAB/index.tsx +1 -5
- package/components/FAB/utils.ts +2 -6
- package/components/FilePicker/FilePicker.tsx +47 -76
- package/components/FilePicker/index.tsx +1 -5
- package/components/FilePicker/utils.ts +5 -6
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/HelperText/index.tsx +1 -5
- package/components/HelperText/utils.ts +5 -7
- package/components/HorizontalDivider/HorizontalDivider.tsx +5 -3
- package/components/HorizontalDivider/index.tsx +1 -5
- package/components/Icon/CrossFadeIcon.tsx +3 -5
- package/components/Icon/Icon.tsx +2 -4
- package/components/Icon/iconFactory.tsx +3 -3
- package/components/Icon/index.tsx +2 -6
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +45 -58
- package/components/IconButton/index.tsx +1 -5
- package/components/IconButton/utils.ts +153 -49
- package/components/If/index.tsx +1 -5
- package/components/InputAddon/index.tsx +1 -5
- package/components/InputAddon/utils.ts +5 -6
- package/components/Link/index.tsx +1 -5
- package/components/Link/utils.ts +2 -6
- package/components/ListItem/index.tsx +1 -5
- package/components/ListItem/utils.ts +13 -11
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- package/components/Menu/index.tsx +1 -5
- package/components/Menu/utils.ts +6 -8
- package/components/Modal/index.tsx +1 -5
- package/components/Modal/utils.ts +2 -6
- package/components/NavigationRail/NavigationRailHeader.tsx +1 -1
- package/components/NavigationRail/index.tsx +1 -5
- package/components/NavigationRail/utils.ts +21 -17
- package/components/NavigationStack/index.tsx +1 -5
- package/components/NavigationStack/utils.tsx +7 -1
- package/components/Portal/index.tsx +1 -5
- package/components/RadioButton/index.ts +1 -5
- package/components/RadioButton/utils.ts +9 -8
- package/components/Rating/index.tsx +1 -5
- package/components/Rating/utils.ts +6 -8
- package/components/Select/Select.tsx +369 -507
- package/components/Select/index.ts +7 -14
- package/components/Select/types.ts +2 -4
- package/components/Select/utils.ts +215 -0
- package/components/Slot/Slot.tsx +244 -0
- package/components/Slot/compose-refs.tsx +60 -0
- package/components/Slot/index.tsx +8 -0
- package/components/StateLayer/index.tsx +1 -5
- package/components/StateLayer/utils.ts +5 -6
- package/components/Surface/Surface.android.tsx +34 -8
- package/components/Surface/Surface.ios.tsx +36 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/index.tsx +1 -5
- package/components/Surface/utils.ts +49 -36
- package/components/Switch/Switch.tsx +8 -2
- package/components/Switch/index.tsx +1 -5
- package/components/Switch/utils.ts +2 -6
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +154 -149
- package/components/Tabs/index.tsx +1 -5
- package/components/Tabs/utils.ts +25 -12
- package/components/Text/Text.tsx +2 -8
- package/components/TextInput/TextInput.tsx +655 -571
- package/components/TextInput/index.tsx +19 -7
- package/components/TextInput/types.ts +76 -27
- package/components/TextInput/utils.ts +232 -159
- package/components/TextInputWithMask/index.tsx +1 -5
- package/components/TimePicker/AmPmSwitcher.tsx +1 -1
- package/components/TimePicker/index.tsx +1 -5
- package/components/TimePicker/utils.ts +29 -21
- package/components/TimePickerField/TimePickerField.tsx +7 -5
- package/components/TimePickerField/index.tsx +1 -5
- package/components/TimePickerField/utils.ts +5 -6
- package/components/TimePickerModal/TimePickerModal.tsx +6 -2
- package/components/TimePickerModal/index.tsx +1 -5
- package/components/TimePickerModal/utils.ts +5 -6
- package/components/Tooltip/TooltipTrigger.tsx +25 -16
- package/components/Tooltip/index.tsx +1 -5
- package/components/Tooltip/utils.ts +5 -6
- package/components/TouchableRipple/TouchableRipple.native.tsx +50 -14
- package/components/TouchableRipple/TouchableRipple.tsx +137 -47
- package/components/TouchableRipple/index.tsx +1 -5
- package/components/TouchableRipple/utils.ts +5 -6
- package/components/VerticalDivider/VerticalDivider.tsx +9 -8
- package/components/VerticalDivider/index.tsx +1 -5
- package/core/componentsRegistry.ts +31 -19
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +0 -5
- package/hooks/useControlledValue.tsx +20 -4
- package/hooks/useSubcomponents.tsx +63 -31
- package/hooks/useWhatHasUpdated.tsx +48 -0
- package/package.json +12 -15
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/extractPropertiesFromStyles.ts +25 -0
- package/utils/lodash.ts +77 -6
- package/utils/repository.ts +2 -52
- package/hooks/useSearchable.tsx +0 -74
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
28
|
-
* @default false
|
|
28
|
+
* Default value for uncontrolled usage
|
|
29
29
|
*/
|
|
30
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
78
|
-
(
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
[],
|
|
92
|
-
);
|
|
84
|
+
return value.name || '';
|
|
85
|
+
}, [value]);
|
|
93
86
|
|
|
94
87
|
const onPress = useCallback(() => {
|
|
95
88
|
openFilePicker(response => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
onChange?.(response);
|
|
89
|
+
onValueChange(response);
|
|
99
90
|
});
|
|
100
|
-
}, [
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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(
|
|
104
|
+
export default memo(FilePicker);
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
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 {
|
|
3
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
4
|
|
|
5
5
|
const filePickerStylesDefault = StyleSheet.create({
|
|
6
6
|
root: {},
|
|
7
7
|
});
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
FilePicker
|
|
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
|
|
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 {
|
|
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
|
-
|
|
25
|
-
HelperText
|
|
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 {
|
|
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
|
-
|
|
99
|
-
|
|
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
|
|
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
|
|
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:
|
|
26
|
+
duration: 200,
|
|
29
27
|
toValue: 0,
|
|
30
28
|
useNativeDriver: true,
|
|
31
29
|
}).start();
|
|
32
30
|
}
|
|
33
|
-
}, [currentIcon, previousIcon, fade
|
|
31
|
+
}, [currentIcon, previousIcon, fade]);
|
|
34
32
|
|
|
35
33
|
const opacityPrev = fade;
|
|
36
34
|
const opacityNext = previousIcon
|
package/components/Icon/Icon.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { forwardRef, memo, useMemo } from 'react';
|
|
2
2
|
import { StyleSheet } from 'react-native-unistyles';
|
|
3
3
|
|
|
4
|
-
import {
|
|
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
|
-
|
|
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 {
|
|
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
|
|
13
|
+
case 'material-community':
|
|
14
14
|
return require('@react-native-vector-icons/material-design-icons').default;
|
|
15
|
-
case
|
|
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
|
|
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 {
|
|
7
|
+
export type { CustomIconTypes, IconProps, IconType } from './types';
|
package/components/Icon/types.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
<
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
|
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';
|