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,140 +1,92 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { forwardRef, memo, type PropsWithoutRef, type ReactNode, useContext, useMemo } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from 'react';
|
|
10
|
-
import { type StyleProp, type TextStyle, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
type StyleProp,
|
|
4
|
+
type TextProps,
|
|
5
|
+
type TextStyle,
|
|
6
|
+
type ViewProps,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
11
9
|
|
|
12
10
|
import { useActionState } from '../../hooks';
|
|
13
11
|
import type { MD3Elevation } from '../../types/theme';
|
|
14
12
|
import { resolveStateVariant } from '../../utils';
|
|
15
|
-
import { ActivityIndicator } from '../ActivityIndicator';
|
|
16
|
-
import { Icon, type
|
|
13
|
+
import { ActivityIndicator, type ActivityIndicatorProps } from '../ActivityIndicator';
|
|
14
|
+
import { Icon, type IconProps } from '../Icon';
|
|
17
15
|
import { StateLayer } from '../StateLayer';
|
|
18
16
|
import { Surface, type SurfaceProps } from '../Surface';
|
|
19
|
-
import { extractProperties } from '../Surface/utils';
|
|
20
17
|
import { Text } from '../Text';
|
|
21
|
-
import { TouchableRipple } from '../TouchableRipple';
|
|
22
|
-
import type { ButtonSize, ButtonVariant } from './types';
|
|
23
|
-
import {
|
|
18
|
+
import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
|
|
19
|
+
import type { ButtonContextType, ButtonShape, ButtonSize, ButtonVariant } from './types';
|
|
20
|
+
import {
|
|
21
|
+
buttonActivityIndicatorStyles,
|
|
22
|
+
ButtonContext,
|
|
23
|
+
buttonIconStyles,
|
|
24
|
+
buttonStyles,
|
|
25
|
+
buttonTextStyles,
|
|
26
|
+
elevationMap,
|
|
27
|
+
sizeToIconSizeMap,
|
|
28
|
+
} from './utils';
|
|
24
29
|
|
|
25
|
-
export type Props = Omit<SurfaceProps, 'style'> &
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/
|
|
79
|
-
onPressOut?: () => void;
|
|
80
|
-
/**
|
|
81
|
-
* Function to execute on long press.
|
|
82
|
-
*/
|
|
83
|
-
onLongPress?: () => void;
|
|
84
|
-
/**
|
|
85
|
-
* Style of button's inner content.
|
|
86
|
-
* Use this prop to apply custom height and width and to set the icon on the right with `flexDirection: 'row-reverse'`.
|
|
87
|
-
*/
|
|
88
|
-
contentStyle?: StyleProp<ViewStyle>;
|
|
89
|
-
style?: StyleProp<TextStyle>;
|
|
90
|
-
/**
|
|
91
|
-
* Style for the button text.
|
|
92
|
-
*/
|
|
93
|
-
labelStyle?: TextStyle;
|
|
94
|
-
/**
|
|
95
|
-
* Style for the Icon
|
|
96
|
-
*/
|
|
97
|
-
iconContainerStyle?: StyleProp<ViewStyle>;
|
|
98
|
-
iconStyle?: StyleProp<TextStyle>;
|
|
99
|
-
/*
|
|
100
|
-
* Size
|
|
101
|
-
* */
|
|
102
|
-
size?: ButtonSize;
|
|
103
|
-
/*
|
|
104
|
-
* Elevation level
|
|
105
|
-
* */
|
|
106
|
-
elevation?: MD3Elevation;
|
|
107
|
-
/**
|
|
108
|
-
* testID to be used on tests.
|
|
109
|
-
*/
|
|
110
|
-
testID?: string;
|
|
111
|
-
/**
|
|
112
|
-
* props for the stateLayer
|
|
113
|
-
*/
|
|
114
|
-
stateLayerProps?: PropsWithoutRef<ViewProps>;
|
|
115
|
-
textRelatedStyle?: StyleProp<TextStyle>;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const elevationMap: Record<string, Record<string, number>> = {
|
|
119
|
-
true: {
|
|
120
|
-
contained: 1,
|
|
121
|
-
'contained-tonal': 1,
|
|
122
|
-
elevated: 2,
|
|
123
|
-
},
|
|
124
|
-
false: {
|
|
125
|
-
elevated: 1,
|
|
126
|
-
},
|
|
127
|
-
};
|
|
30
|
+
export type Props = Omit<SurfaceProps, 'style'> &
|
|
31
|
+
Pick<TouchableRippleProps, 'onPress' | 'onPressIn' | 'onPressOut' | 'onLongPress'> & {
|
|
32
|
+
/**
|
|
33
|
+
* Mode of the button. You can change the mode to adjust the styling to give it desired emphasis.
|
|
34
|
+
* - `text` - flat button without background or outline, used for the lowest priority actions, especially when presenting multiple options.
|
|
35
|
+
* - `outlined` - button with an outline without background, typically used for important, but not primary action – represents medium emphasis.
|
|
36
|
+
* - `contained` - button with a background color, used for important action, have the most visual impact and high emphasis.
|
|
37
|
+
* - `elevated` - button with a background color and elevation, used when absolutely necessary e.g. button requires visual separation from a patterned background. @supported Available in v5.x with theme version 3
|
|
38
|
+
* - `contained-tonal` - button with a secondary background color, an alternative middle ground between contained and outlined buttons. @supported Available in v5.x with theme version 3
|
|
39
|
+
*/
|
|
40
|
+
variant?: ButtonVariant;
|
|
41
|
+
/**
|
|
42
|
+
* Shape of the button.
|
|
43
|
+
* - `rounded` - fully rounded corners (default)
|
|
44
|
+
* - `square` - square corners with medium border radius
|
|
45
|
+
*/
|
|
46
|
+
shape?: ButtonShape;
|
|
47
|
+
/**
|
|
48
|
+
* Whether the button is disabled. A disabled button is greyed out and `onPress` is not called on touch.
|
|
49
|
+
*/
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Content of the button. Use Button.Icon and Button.Text compound components.
|
|
53
|
+
*/
|
|
54
|
+
children?: ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* Accessibility label for the button. This is read by the screen reader when the user taps the button.
|
|
57
|
+
*/
|
|
58
|
+
accessibilityLabel?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Accessibility hint for the button. This is read by the screen reader when the user taps the button.
|
|
61
|
+
*/
|
|
62
|
+
accessibilityHint?: string;
|
|
63
|
+
style?: StyleProp<TextStyle>;
|
|
64
|
+
/*
|
|
65
|
+
* Size
|
|
66
|
+
* */
|
|
67
|
+
size?: ButtonSize;
|
|
68
|
+
/*
|
|
69
|
+
* Elevation level
|
|
70
|
+
* */
|
|
71
|
+
elevation?: MD3Elevation;
|
|
72
|
+
/**
|
|
73
|
+
* testID to be used on tests.
|
|
74
|
+
*/
|
|
75
|
+
testID?: string;
|
|
76
|
+
/**
|
|
77
|
+
* props for the stateLayer
|
|
78
|
+
*/
|
|
79
|
+
stateLayerProps?: PropsWithoutRef<ViewProps>;
|
|
80
|
+
textRelatedStyle?: StyleProp<TextStyle>;
|
|
81
|
+
disabledPress?: boolean;
|
|
82
|
+
};
|
|
128
83
|
|
|
129
84
|
const Button = (
|
|
130
85
|
{
|
|
131
86
|
disabled = false,
|
|
132
87
|
variant = 'text',
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
iconType,
|
|
136
|
-
iconName,
|
|
137
|
-
buttonColor: customButtonColor,
|
|
88
|
+
shape = 'rounded',
|
|
89
|
+
size = 'sm',
|
|
138
90
|
children,
|
|
139
91
|
accessibilityLabel,
|
|
140
92
|
accessibilityHint,
|
|
@@ -143,17 +95,13 @@ const Button = (
|
|
|
143
95
|
onPressOut,
|
|
144
96
|
onLongPress,
|
|
145
97
|
style: styleProp,
|
|
146
|
-
contentStyle,
|
|
147
|
-
labelStyle,
|
|
148
|
-
iconContainerStyle: iconContainerStyleProp,
|
|
149
98
|
testID,
|
|
150
99
|
accessible,
|
|
151
100
|
stateLayerProps = {},
|
|
152
101
|
elevation: elevationProp,
|
|
153
|
-
iconSize: _iconSizeProp,
|
|
154
102
|
textRelatedStyle,
|
|
155
|
-
|
|
156
|
-
...
|
|
103
|
+
disabledPress,
|
|
104
|
+
...restProps
|
|
157
105
|
}: Props,
|
|
158
106
|
ref: any,
|
|
159
107
|
) => {
|
|
@@ -164,122 +112,48 @@ const Button = (
|
|
|
164
112
|
hovered,
|
|
165
113
|
});
|
|
166
114
|
|
|
167
|
-
|
|
115
|
+
buttonStyles.useVariants({
|
|
168
116
|
variant,
|
|
169
|
-
|
|
117
|
+
// @ts-ignore // TODO - fix this
|
|
118
|
+
state: state as any,
|
|
170
119
|
size,
|
|
120
|
+
shape,
|
|
171
121
|
});
|
|
172
|
-
|
|
173
|
-
// const componentStyles = useComponentStyles(
|
|
174
|
-
// 'Button',
|
|
175
|
-
// [styleProp, { customButtonColor, customTextColor }],
|
|
176
|
-
// {
|
|
177
|
-
// variant,
|
|
178
|
-
// state: disabled ? 'disabled' : hovered ? 'hovered' : undefined,
|
|
179
|
-
// size,
|
|
180
|
-
// },
|
|
181
|
-
// );
|
|
182
|
-
|
|
183
|
-
// console.log({ hovered, componentStyles });
|
|
184
|
-
|
|
185
|
-
const isVariant = useCallback(
|
|
186
|
-
(variantComponent: ButtonVariant) => {
|
|
187
|
-
return variant === variantComponent;
|
|
188
|
-
},
|
|
189
|
-
[variant],
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const iconSize = _iconSizeProp ?? sizeToIconSizeMap[size] ?? sizeToIconSizeMap.md;
|
|
122
|
+
const iconSize = sizeToIconSizeMap[size] ?? sizeToIconSizeMap.md;
|
|
193
123
|
const elevationLevel = elevationMap[(!!hovered).toString()][variant] ?? 0;
|
|
194
124
|
|
|
195
|
-
const {
|
|
196
|
-
customLabelColor,
|
|
197
|
-
customLabelSize,
|
|
198
|
-
rippleColor,
|
|
199
|
-
surfaceStyle,
|
|
200
|
-
textStyle,
|
|
201
|
-
iconStyle,
|
|
202
|
-
viewStyle,
|
|
203
|
-
iconContainerStyle,
|
|
204
|
-
accessibilityState,
|
|
205
|
-
stateLayerStyle,
|
|
206
|
-
} = useMemo(() => {
|
|
207
|
-
const { button, content, icon, iconTextMode, label, labelText, labelTextAddons } =
|
|
208
|
-
defaultStyles;
|
|
209
|
-
|
|
210
|
-
// for mobile
|
|
211
|
-
const { borderRadius } = extractProperties(
|
|
212
|
-
[defaultStyles.root, styleProp],
|
|
213
|
-
['borderRadius'],
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
const backgroundColor = customButtonColor && !disabled ? customButtonColor : undefined;
|
|
217
|
-
|
|
218
|
-
const _iconStyle = [icon, isVariant('text') && iconTextMode];
|
|
219
|
-
|
|
220
|
-
const { color: labelColor, fontSize: labelFontSize } = labelStyle ?? {};
|
|
221
|
-
|
|
222
|
-
// TODO - remove this workaround
|
|
223
|
-
let _rippleColor: string | undefined;
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
_rippleColor = setColor(labelColor).alpha(0.12).rgb().string();
|
|
227
|
-
} catch (e) {
|
|
228
|
-
_rippleColor = undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
125
|
+
const { surfaceStyle, accessibilityState, stateLayerStyle, contextValue } = useMemo(() => {
|
|
231
126
|
return {
|
|
232
|
-
|
|
233
|
-
customLabelSize: labelFontSize,
|
|
234
|
-
rippleColor: _rippleColor,
|
|
235
|
-
surfaceStyle: [
|
|
236
|
-
button,
|
|
237
|
-
backgroundColor ? { backgroundColor } : {},
|
|
238
|
-
defaultStyles.root,
|
|
239
|
-
styleProp,
|
|
240
|
-
],
|
|
241
|
-
|
|
242
|
-
iconStyle: [_iconStyle, textRelatedStyle, _iconStyleProp] as unknown as ViewStyle,
|
|
243
|
-
viewStyle: [
|
|
244
|
-
content,
|
|
245
|
-
{ flexGrow: 1 },
|
|
246
|
-
borderRadius ? { borderRadius } : {},
|
|
247
|
-
contentStyle,
|
|
248
|
-
],
|
|
249
|
-
iconContainerStyle: [defaultStyles.iconContainer, iconContainerStyleProp],
|
|
250
|
-
textStyle: [
|
|
251
|
-
isVariant('text') ? (iconName || loading ? labelTextAddons : labelText) : label,
|
|
252
|
-
textRelatedStyle,
|
|
253
|
-
labelStyle,
|
|
254
|
-
],
|
|
127
|
+
surfaceStyle: [buttonStyles.root, styleProp],
|
|
255
128
|
accessibilityState: { disabled },
|
|
256
|
-
stateLayerStyle: [
|
|
129
|
+
stateLayerStyle: [buttonStyles.stateLayer, stateLayerProps?.style],
|
|
130
|
+
contextValue: {
|
|
131
|
+
variant,
|
|
132
|
+
size,
|
|
133
|
+
state: state as ButtonContextType['state'],
|
|
134
|
+
disabled,
|
|
135
|
+
iconSize,
|
|
136
|
+
textRelatedStyle,
|
|
137
|
+
} as ButtonContextType,
|
|
257
138
|
};
|
|
258
|
-
// eslint-disable-next-line
|
|
139
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
259
140
|
}, [
|
|
141
|
+
shape,
|
|
260
142
|
state,
|
|
261
143
|
variant,
|
|
262
144
|
size,
|
|
263
|
-
contentStyle,
|
|
264
|
-
customButtonColor,
|
|
265
145
|
disabled,
|
|
266
|
-
iconContainerStyleProp,
|
|
267
|
-
iconName,
|
|
268
|
-
isVariant,
|
|
269
|
-
labelStyle,
|
|
270
|
-
loading,
|
|
271
146
|
stateLayerProps?.style,
|
|
272
147
|
styleProp,
|
|
148
|
+
iconSize,
|
|
149
|
+
textRelatedStyle,
|
|
273
150
|
]);
|
|
274
151
|
|
|
275
|
-
const elevation =
|
|
276
|
-
() => (elevationProp === undefined ? elevationLevel ?? 0 : elevationProp),
|
|
277
|
-
[elevationLevel, elevationProp],
|
|
278
|
-
);
|
|
152
|
+
const elevation = elevationProp === undefined ? elevationLevel ?? 0 : elevationProp;
|
|
279
153
|
|
|
280
154
|
return (
|
|
281
155
|
<Surface
|
|
282
|
-
{...
|
|
156
|
+
{...restProps}
|
|
283
157
|
style={surfaceStyle}
|
|
284
158
|
elevation={
|
|
285
159
|
(disabled
|
|
@@ -287,7 +161,8 @@ const Button = (
|
|
|
287
161
|
: hovered
|
|
288
162
|
? (elevationProp || 0) + elevationLevel
|
|
289
163
|
: elevation) as MD3Elevation
|
|
290
|
-
}
|
|
164
|
+
}
|
|
165
|
+
asChild>
|
|
291
166
|
<TouchableRipple
|
|
292
167
|
borderless
|
|
293
168
|
onPress={onPress}
|
|
@@ -299,51 +174,123 @@ const Button = (
|
|
|
299
174
|
accessibilityRole="button"
|
|
300
175
|
accessibilityState={accessibilityState}
|
|
301
176
|
accessible={accessible}
|
|
302
|
-
disabled={disabled}
|
|
303
|
-
rippleColor={rippleColor}
|
|
304
|
-
style={viewStyle}
|
|
177
|
+
disabled={disabled || disabledPress}
|
|
305
178
|
ref={actionsRef}
|
|
306
179
|
testID={testID}>
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
<View style={iconContainerStyle}>
|
|
310
|
-
<Icon
|
|
311
|
-
type={iconType}
|
|
312
|
-
name={iconName}
|
|
313
|
-
size={iconSize ?? customLabelSize}
|
|
314
|
-
color={
|
|
315
|
-
typeof customLabelColor === 'string'
|
|
316
|
-
? customLabelColor
|
|
317
|
-
: undefined
|
|
318
|
-
}
|
|
319
|
-
style={iconStyle}
|
|
320
|
-
/>
|
|
321
|
-
</View>
|
|
322
|
-
) : null}
|
|
323
|
-
{loading ? (
|
|
324
|
-
<ActivityIndicator
|
|
325
|
-
size={customLabelSize ?? iconSize}
|
|
326
|
-
color={
|
|
327
|
-
(typeof customLabelColor === 'string'
|
|
328
|
-
? customLabelColor
|
|
329
|
-
: undefined) as string
|
|
330
|
-
}
|
|
331
|
-
style={iconStyle}
|
|
332
|
-
/>
|
|
333
|
-
) : null}
|
|
334
|
-
<Text selectable={false} numberOfLines={1} style={textStyle}>
|
|
180
|
+
<ButtonContext.Provider value={contextValue}>
|
|
181
|
+
<>
|
|
335
182
|
{children}
|
|
336
|
-
</Text>
|
|
337
183
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
184
|
+
<StateLayer
|
|
185
|
+
testID={testID ? `${testID}-stateLayer` : ''}
|
|
186
|
+
{...stateLayerProps}
|
|
187
|
+
style={stateLayerStyle}
|
|
188
|
+
/>
|
|
189
|
+
</>
|
|
190
|
+
</ButtonContext.Provider>
|
|
344
191
|
</TouchableRipple>
|
|
345
192
|
</Surface>
|
|
346
193
|
);
|
|
347
194
|
};
|
|
348
195
|
|
|
349
196
|
export default memo(forwardRef(Button));
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Button.Icon - Renders an icon within the button
|
|
200
|
+
*/
|
|
201
|
+
export const ButtonIcon = memo(
|
|
202
|
+
({ type, name, size: sizeProp, color: colorProp, style, ...rest }: IconProps) => {
|
|
203
|
+
const { labelColor, iconSize, variant, state, disabled, textRelatedStyle } =
|
|
204
|
+
useContext(ButtonContext);
|
|
205
|
+
|
|
206
|
+
const iconSizeResolved = sizeProp ?? iconSize;
|
|
207
|
+
const colorResolved =
|
|
208
|
+
colorProp ?? (typeof labelColor === 'string' ? labelColor : undefined);
|
|
209
|
+
|
|
210
|
+
buttonIconStyles.useVariants({
|
|
211
|
+
variant,
|
|
212
|
+
// @ts-ignore - state includes 'default' which is valid but not typed
|
|
213
|
+
state,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<Icon
|
|
218
|
+
type={type}
|
|
219
|
+
name={name}
|
|
220
|
+
size={iconSizeResolved}
|
|
221
|
+
color={disabled ? undefined : colorResolved}
|
|
222
|
+
style={[buttonIconStyles.root, textRelatedStyle, style]}
|
|
223
|
+
{...rest}
|
|
224
|
+
/>
|
|
225
|
+
);
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
ButtonIcon.displayName = 'Button_Icon';
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Button.Text - Renders text within the button
|
|
233
|
+
*/
|
|
234
|
+
export const ButtonText = memo(({ children, style, ...rest }: TextProps) => {
|
|
235
|
+
const { variant, state, size, textRelatedStyle } = useContext(ButtonContext);
|
|
236
|
+
|
|
237
|
+
buttonTextStyles.useVariants({
|
|
238
|
+
variant,
|
|
239
|
+
// @ts-ignore - state includes 'default' which is valid but not typed
|
|
240
|
+
state,
|
|
241
|
+
// @ts-ignore - size type mismatch
|
|
242
|
+
size,
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
return (
|
|
246
|
+
// @ts-ignore - deep type instantiation
|
|
247
|
+
<Text
|
|
248
|
+
selectable={false}
|
|
249
|
+
numberOfLines={1}
|
|
250
|
+
{...rest}
|
|
251
|
+
style={[buttonTextStyles.root, textRelatedStyle, style]}>
|
|
252
|
+
{children}
|
|
253
|
+
</Text>
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
ButtonText.displayName = 'Button_Text';
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Button.Loading - Renders a loading indicator within the button
|
|
261
|
+
*/
|
|
262
|
+
export const ButtonActivityIndicator = memo(
|
|
263
|
+
({
|
|
264
|
+
size: sizeProp,
|
|
265
|
+
color: colorProp,
|
|
266
|
+
style,
|
|
267
|
+
...rest
|
|
268
|
+
}: Omit<ActivityIndicatorProps, 'animating'>) => {
|
|
269
|
+
const { iconSize, variant, state } = useContext(ButtonContext);
|
|
270
|
+
|
|
271
|
+
const sizeResolved = sizeProp ?? iconSize;
|
|
272
|
+
// Default to onPrimary for contained variants, primary for others
|
|
273
|
+
const colorResolved = colorProp ?? (variant === 'contained' ? 'onPrimary' : 'primary');
|
|
274
|
+
|
|
275
|
+
buttonActivityIndicatorStyles.useVariants({
|
|
276
|
+
variant,
|
|
277
|
+
// @ts-ignore - state includes 'default' which is valid but not typed
|
|
278
|
+
state,
|
|
279
|
+
});
|
|
280
|
+
const activityIndicatorStyle = useMemo(() => {
|
|
281
|
+
return [buttonActivityIndicatorStyles.root, style] as StyleProp<ViewStyle>;
|
|
282
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
283
|
+
}, [style, variant, state]);
|
|
284
|
+
|
|
285
|
+
return (
|
|
286
|
+
<ActivityIndicator
|
|
287
|
+
size={sizeResolved}
|
|
288
|
+
color={colorResolved}
|
|
289
|
+
style={activityIndicatorStyle}
|
|
290
|
+
{...rest}
|
|
291
|
+
/>
|
|
292
|
+
);
|
|
293
|
+
},
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
ButtonActivityIndicator.displayName = 'Button_ActivityIndicator';
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback
|
|
2
|
-
import ButtonDefault from './Button';
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
+
import ButtonDefault, { ButtonActivityIndicator, ButtonIcon, ButtonText } from './Button';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
Button: ButtonDefault,
|
|
6
|
-
});
|
|
4
|
+
const ButtonBase = getRegisteredComponentWithFallback('Button', ButtonDefault);
|
|
7
5
|
|
|
8
|
-
export const Button =
|
|
6
|
+
export const Button = Object.assign(ButtonBase, {
|
|
7
|
+
Icon: ButtonIcon,
|
|
8
|
+
Text: ButtonText,
|
|
9
|
+
ActivityIndicator: ButtonActivityIndicator,
|
|
10
|
+
});
|
|
9
11
|
|
|
10
12
|
export type { Props as ButtonProps } from './Button';
|
|
11
|
-
export {
|
|
13
|
+
export { buttonIconStyles, buttonStyles, buttonTextStyles } from './utils';
|
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle } from 'react-native';
|
|
2
|
+
|
|
1
3
|
export type ButtonVariant = 'text' | 'outlined' | 'contained' | 'elevated' | 'contained-tonal';
|
|
2
4
|
|
|
3
|
-
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
5
|
+
export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
6
|
+
|
|
7
|
+
export type ButtonStates = 'hovered' | 'disabled' | 'default';
|
|
8
|
+
|
|
9
|
+
export type ButtonShape = 'rounded' | 'square';
|
|
4
10
|
|
|
5
|
-
export type
|
|
11
|
+
export type ButtonContextType = {
|
|
12
|
+
variant: ButtonVariant;
|
|
13
|
+
size: ButtonSize;
|
|
14
|
+
state: ButtonStates;
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
labelColor?: string;
|
|
17
|
+
iconSize?: number;
|
|
18
|
+
textRelatedStyle?: StyleProp<TextStyle>;
|
|
19
|
+
};
|