react-native-molecules 0.5.0-beta.4 → 0.5.0-beta.5
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/components/Button/Button.tsx +5 -20
- package/components/Button/utils.ts +0 -1
- package/components/Chip/Chip.tsx +39 -51
- package/components/Chip/utils.ts +3 -7
- package/components/IconButton/IconButton.tsx +42 -57
- package/components/IconButton/utils.ts +4 -5
- package/components/Select/Select.tsx +360 -501
- 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/Surface/Surface.android.tsx +20 -7
- package/components/Surface/Surface.ios.tsx +22 -29
- package/components/Surface/Surface.tsx +14 -4
- package/components/Surface/utils.ts +44 -6
- package/components/Switch/Switch.tsx +8 -2
- package/components/TextInput/TextInput.tsx +2 -2
- package/components/TouchableRipple/TouchableRipple.native.tsx +35 -13
- package/components/TouchableRipple/TouchableRipple.tsx +119 -46
- package/hooks/useControlledValue.tsx +20 -4
- package/hooks/useWhatHasUpdated.tsx +48 -0
- package/package.json +1 -1
- package/styles/shadow.ts +2 -1
|
@@ -12,7 +12,6 @@ import { type StyleProp, type TextStyle, View, type ViewProps, type ViewStyle }
|
|
|
12
12
|
import { useActionState } from '../../hooks';
|
|
13
13
|
import type { MD3Elevation } from '../../types/theme';
|
|
14
14
|
import { resolveStateVariant } from '../../utils';
|
|
15
|
-
import { extractPropertiesFromStyles } from '../../utils/extractPropertiesFromStyles';
|
|
16
15
|
import { ActivityIndicator } from '../ActivityIndicator';
|
|
17
16
|
import { Icon, type IconType } from '../Icon';
|
|
18
17
|
import { StateLayer } from '../StateLayer';
|
|
@@ -200,7 +199,6 @@ const Button = (
|
|
|
200
199
|
surfaceStyle,
|
|
201
200
|
textStyle,
|
|
202
201
|
iconStyle,
|
|
203
|
-
viewStyle,
|
|
204
202
|
iconContainerStyle,
|
|
205
203
|
accessibilityState,
|
|
206
204
|
stateLayerStyle,
|
|
@@ -208,12 +206,6 @@ const Button = (
|
|
|
208
206
|
const { button, content, icon, iconTextMode, label, labelText, labelTextAddons } =
|
|
209
207
|
defaultStyles;
|
|
210
208
|
|
|
211
|
-
// for mobile
|
|
212
|
-
const { borderRadius } = extractPropertiesFromStyles(
|
|
213
|
-
[defaultStyles.root, styleProp],
|
|
214
|
-
['borderRadius'],
|
|
215
|
-
);
|
|
216
|
-
|
|
217
209
|
const backgroundColor = customButtonColor && !disabled ? customButtonColor : undefined;
|
|
218
210
|
|
|
219
211
|
const _iconStyle = [icon, isVariant('text') && iconTextMode];
|
|
@@ -235,18 +227,14 @@ const Button = (
|
|
|
235
227
|
rippleColor: _rippleColor,
|
|
236
228
|
surfaceStyle: [
|
|
237
229
|
button,
|
|
230
|
+
content,
|
|
238
231
|
backgroundColor ? { backgroundColor } : {},
|
|
239
232
|
defaultStyles.root,
|
|
240
233
|
styleProp,
|
|
234
|
+
contentStyle,
|
|
241
235
|
],
|
|
242
236
|
|
|
243
237
|
iconStyle: [_iconStyle, textRelatedStyle, _iconStyleProp] as unknown as ViewStyle,
|
|
244
|
-
viewStyle: [
|
|
245
|
-
content,
|
|
246
|
-
{ flexGrow: 1 },
|
|
247
|
-
borderRadius ? { borderRadius } : {},
|
|
248
|
-
contentStyle,
|
|
249
|
-
],
|
|
250
238
|
iconContainerStyle: [defaultStyles.iconContainer, iconContainerStyleProp],
|
|
251
239
|
textStyle: [
|
|
252
240
|
// @ts-ignore // TODO - fix this
|
|
@@ -274,10 +262,7 @@ const Button = (
|
|
|
274
262
|
styleProp,
|
|
275
263
|
]);
|
|
276
264
|
|
|
277
|
-
const elevation =
|
|
278
|
-
() => (elevationProp === undefined ? elevationLevel ?? 0 : elevationProp),
|
|
279
|
-
[elevationLevel, elevationProp],
|
|
280
|
-
);
|
|
265
|
+
const elevation = elevationProp === undefined ? elevationLevel ?? 0 : elevationProp;
|
|
281
266
|
|
|
282
267
|
return (
|
|
283
268
|
<Surface
|
|
@@ -289,7 +274,8 @@ const Button = (
|
|
|
289
274
|
: hovered
|
|
290
275
|
? (elevationProp || 0) + elevationLevel
|
|
291
276
|
: elevation) as MD3Elevation
|
|
292
|
-
}
|
|
277
|
+
}
|
|
278
|
+
asChild>
|
|
293
279
|
<TouchableRipple
|
|
294
280
|
borderless
|
|
295
281
|
onPress={onPress}
|
|
@@ -303,7 +289,6 @@ const Button = (
|
|
|
303
289
|
accessible={accessible}
|
|
304
290
|
disabled={disabled}
|
|
305
291
|
rippleColor={rippleColor}
|
|
306
|
-
style={viewStyle}
|
|
307
292
|
ref={actionsRef}
|
|
308
293
|
testID={testID}>
|
|
309
294
|
<>
|
package/components/Chip/Chip.tsx
CHANGED
|
@@ -97,10 +97,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
|
97
97
|
* Whether to show the ActivityIndicator or not
|
|
98
98
|
*/
|
|
99
99
|
loading?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* container style
|
|
102
|
-
*/
|
|
103
|
-
containerStyle?: ViewStyle;
|
|
104
100
|
/**
|
|
105
101
|
* left element container style
|
|
106
102
|
*/
|
|
@@ -132,7 +128,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
|
132
128
|
const Chip = (
|
|
133
129
|
{
|
|
134
130
|
style,
|
|
135
|
-
containerStyle: containerStyleProp,
|
|
136
131
|
label: _label,
|
|
137
132
|
labelCharacterLimit = 20,
|
|
138
133
|
variant = 'outlined',
|
|
@@ -158,11 +153,13 @@ const Chip = (
|
|
|
158
153
|
leftElementIconProps,
|
|
159
154
|
invertLabelColor,
|
|
160
155
|
backgroundColor,
|
|
156
|
+
onPress,
|
|
161
157
|
...rest
|
|
162
158
|
}: Props,
|
|
163
159
|
ref: any,
|
|
164
160
|
) => {
|
|
165
161
|
const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
162
|
+
const Wrapper = onPress ? TouchableRipple : View;
|
|
166
163
|
|
|
167
164
|
const state = resolveStateVariant({
|
|
168
165
|
disabled: !!disabled,
|
|
@@ -192,47 +189,39 @@ const Chip = (
|
|
|
192
189
|
// selectedColorProp ? { selectedColor: selectedColorProp } : {},
|
|
193
190
|
// ]);
|
|
194
191
|
|
|
195
|
-
const {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
styles.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
stateLayerProps?.style,
|
|
229
|
-
style,
|
|
230
|
-
containerStyleProp,
|
|
231
|
-
labelStyleProp,
|
|
232
|
-
state,
|
|
233
|
-
size,
|
|
234
|
-
variant,
|
|
235
|
-
]);
|
|
192
|
+
const { containerStyle, leftElementStyle, rightElementStyle, labelStyle, stateLayerStyle } =
|
|
193
|
+
useMemo(() => {
|
|
194
|
+
return {
|
|
195
|
+
containerStyle: [
|
|
196
|
+
styles.container,
|
|
197
|
+
selected && selectionBackgroundColor
|
|
198
|
+
? { backgroundColor: selectionBackgroundColor }
|
|
199
|
+
: {},
|
|
200
|
+
style,
|
|
201
|
+
],
|
|
202
|
+
leftElementStyle: [styles.leftElement, leftElementContainerStyle],
|
|
203
|
+
rightElementStyle: [styles.rightElement, rightElementContainerStyle],
|
|
204
|
+
labelStyle: [
|
|
205
|
+
styles.label,
|
|
206
|
+
selected && selectedColor ? { color: selectedColor } : {},
|
|
207
|
+
labelStyleProp,
|
|
208
|
+
],
|
|
209
|
+
stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
|
|
210
|
+
};
|
|
211
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
+
}, [
|
|
213
|
+
leftElementContainerStyle,
|
|
214
|
+
rightElementContainerStyle,
|
|
215
|
+
selected,
|
|
216
|
+
selectedColor,
|
|
217
|
+
selectionBackgroundColor,
|
|
218
|
+
stateLayerProps?.style,
|
|
219
|
+
style,
|
|
220
|
+
labelStyleProp,
|
|
221
|
+
state,
|
|
222
|
+
size,
|
|
223
|
+
variant,
|
|
224
|
+
]);
|
|
236
225
|
|
|
237
226
|
const { accessibilityState, elevation } = useMemo(
|
|
238
227
|
() => ({
|
|
@@ -251,14 +240,13 @@ const Chip = (
|
|
|
251
240
|
{...containerProps}
|
|
252
241
|
elevation={elevation}
|
|
253
242
|
style={containerStyle}
|
|
254
|
-
backgroundColor={backgroundColor}
|
|
255
|
-
|
|
243
|
+
backgroundColor={backgroundColor}
|
|
244
|
+
asChild>
|
|
245
|
+
<Wrapper
|
|
256
246
|
borderless
|
|
257
247
|
{...rest}
|
|
258
248
|
disabled={disabled}
|
|
259
|
-
style={touchableRippleStyle}
|
|
260
249
|
accessibilityLabel={accessibilityLabel}
|
|
261
|
-
accessibilityRole="button"
|
|
262
250
|
accessibilityState={accessibilityState}
|
|
263
251
|
ref={actionsRef}
|
|
264
252
|
testID={testID}>
|
|
@@ -297,7 +285,7 @@ const Chip = (
|
|
|
297
285
|
style={stateLayerStyle}
|
|
298
286
|
/>
|
|
299
287
|
</>
|
|
300
|
-
</
|
|
288
|
+
</Wrapper>
|
|
301
289
|
</Surface>
|
|
302
290
|
);
|
|
303
291
|
};
|
package/components/Chip/utils.ts
CHANGED
|
@@ -6,6 +6,9 @@ const chipStylesDefault = StyleSheet.create(theme => ({
|
|
|
6
6
|
container: {
|
|
7
7
|
borderRadius: theme.shapes.corner.small,
|
|
8
8
|
backgroundColor: theme.colors.surface,
|
|
9
|
+
paddingHorizontal: theme.spacings['2'],
|
|
10
|
+
flexDirection: 'row',
|
|
11
|
+
alignItems: 'center',
|
|
9
12
|
|
|
10
13
|
variants: {
|
|
11
14
|
variant: {
|
|
@@ -47,13 +50,6 @@ const chipStylesDefault = StyleSheet.create(theme => ({
|
|
|
47
50
|
},
|
|
48
51
|
},
|
|
49
52
|
},
|
|
50
|
-
touchableRippleContainer: {
|
|
51
|
-
flex: 1,
|
|
52
|
-
paddingHorizontal: theme.spacings['2'],
|
|
53
|
-
borderRadius: theme.shapes.corner.small,
|
|
54
|
-
flexDirection: 'row',
|
|
55
|
-
alignItems: 'center',
|
|
56
|
-
},
|
|
57
53
|
label: {
|
|
58
54
|
display: 'flex',
|
|
59
55
|
color: theme.colors.onSurfaceVariant,
|
|
@@ -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,
|
|
@@ -126,9 +121,9 @@ const IconButton = (
|
|
|
126
121
|
rippleColor,
|
|
127
122
|
containerStyle,
|
|
128
123
|
accessibilityState,
|
|
129
|
-
innerContainerStyle,
|
|
130
124
|
// accessibilityTraits,
|
|
131
125
|
stateLayerStyle,
|
|
126
|
+
iconStyle,
|
|
132
127
|
} = useMemo(() => {
|
|
133
128
|
const iconSizeInNum =
|
|
134
129
|
iconButtonSizeToIconSizeMap[size as keyof typeof iconButtonSizeToIconSizeMap] ??
|
|
@@ -146,7 +141,6 @@ const IconButton = (
|
|
|
146
141
|
iconColor: _iconColor,
|
|
147
142
|
iconSize: iconSizeInNum,
|
|
148
143
|
rippleColor: _rippleColor,
|
|
149
|
-
innerContainerStyle: [defaultStyles.innerContainer, innerContainerStyleProp],
|
|
150
144
|
containerStyle: [
|
|
151
145
|
iconSizeInNum
|
|
152
146
|
? {
|
|
@@ -157,60 +151,51 @@ const IconButton = (
|
|
|
157
151
|
defaultStyles.root,
|
|
158
152
|
style,
|
|
159
153
|
],
|
|
154
|
+
iconStyle: [defaultStyles.icon, iconStyleProp],
|
|
160
155
|
// accessibilityTraits: disabled ? ['button', 'disabled'] : 'button',
|
|
161
156
|
accessibilityState: { disabled },
|
|
162
157
|
stateLayerStyle: [defaultStyles.stateLayer, stateLayerProps?.style],
|
|
163
158
|
};
|
|
164
159
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
165
|
-
}, [
|
|
166
|
-
_iconColor,
|
|
167
|
-
disabled,
|
|
168
|
-
innerContainerStyleProp,
|
|
169
|
-
size,
|
|
170
|
-
stateLayerProps?.style,
|
|
171
|
-
style,
|
|
172
|
-
state,
|
|
173
|
-
variant,
|
|
174
|
-
]);
|
|
160
|
+
}, [_iconColor, disabled, size, stateLayerProps?.style, style, state, variant]);
|
|
175
161
|
|
|
176
162
|
return (
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
hitSlop={
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
TouchableRipple?.supported ? rippleSupportedHitSlop : rippleUnsupportedHitSlop
|
|
193
|
-
}
|
|
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={
|
|
194
176
|
// @ts-ignore
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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>
|
|
214
199
|
);
|
|
215
200
|
};
|
|
216
201
|
|
|
@@ -27,6 +27,9 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
|
|
|
27
27
|
overflow: 'hidden',
|
|
28
28
|
borderWidth: 0,
|
|
29
29
|
backgroundColor: 'transparent',
|
|
30
|
+
flexGrow: 1,
|
|
31
|
+
justifyContent: 'center',
|
|
32
|
+
alignItems: 'center',
|
|
30
33
|
|
|
31
34
|
variants: {
|
|
32
35
|
size: {
|
|
@@ -302,11 +305,7 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
|
|
|
302
305
|
],
|
|
303
306
|
},
|
|
304
307
|
|
|
305
|
-
|
|
306
|
-
flexGrow: 1,
|
|
307
|
-
justifyContent: 'center',
|
|
308
|
-
alignItems: 'center',
|
|
309
|
-
},
|
|
308
|
+
icon: {},
|
|
310
309
|
}));
|
|
311
310
|
|
|
312
311
|
export const defaultStyles = getRegisteredComponentStylesWithFallback(
|