react-native-molecules 0.5.0-beta.4 → 0.5.0-beta.6

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.
@@ -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 = useMemo(
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
  <>
@@ -192,7 +192,6 @@ const defaultStylesDefault = StyleSheet.create(theme => {
192
192
  flexDirection: 'row',
193
193
  alignItems: 'center',
194
194
  justifyContent: 'center',
195
- flexGrow: 1,
196
195
  },
197
196
  iconContainer: {
198
197
  ...(Platform.OS !== 'web'
@@ -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
- containerStyle,
197
- touchableRippleStyle,
198
- leftElementStyle,
199
- rightElementStyle,
200
- labelStyle,
201
- stateLayerStyle,
202
- } = useMemo(() => {
203
- return {
204
- containerStyle: [
205
- styles.container,
206
- selected && selectionBackgroundColor
207
- ? { backgroundColor: selectionBackgroundColor }
208
- : {},
209
- containerStyleProp,
210
- ],
211
- touchableRippleStyle: [styles.touchableRippleContainer, style],
212
- leftElementStyle: [styles.leftElement, leftElementContainerStyle],
213
- rightElementStyle: [styles.rightElement, rightElementContainerStyle],
214
- labelStyle: [
215
- styles.label,
216
- selected && selectedColor ? { color: selectedColor } : {},
217
- labelStyleProp,
218
- ],
219
- stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
220
- };
221
- // eslint-disable-next-line react-hooks/exhaustive-deps
222
- }, [
223
- leftElementContainerStyle,
224
- rightElementContainerStyle,
225
- selected,
226
- selectedColor,
227
- selectionBackgroundColor,
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
- <TouchableRipple
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
- </TouchableRipple>
288
+ </Wrapper>
301
289
  </Surface>
302
290
  );
303
291
  };
@@ -362,7 +350,7 @@ const RightElement = memo(
362
350
  {onClose ? (
363
351
  <IconButtonWithContrastColor
364
352
  name="close"
365
- size={18}
353
+ size={14}
366
354
  accessibilityLabel="Close"
367
355
  disabled={disabled}
368
356
  onPress={onClose}
@@ -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
- <Surface style={containerStyle} elevation={0}>
178
- <TouchableRipple
179
- borderless
180
- centered
181
- onPress={onPress}
182
- rippleColor={rippleColor}
183
- accessibilityLabel={accessibilityLabel}
184
- style={innerContainerStyle}
185
- // accessibilityTraits={accessibilityTraits}
186
- // accessibilityComponentType="button"
187
- accessibilityRole="button"
188
- accessibilityState={accessibilityState}
189
- disabled={disabled}
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
- ref={actionsRef}
196
- testID={testID}
197
- {...rest}>
198
- <>
199
- <IconComponent
200
- color={iconColor}
201
- name={name}
202
- size={iconSize}
203
- type={type}
204
- style={iconStyle}
205
- />
206
- <StateLayer
207
- testID={testID ? `${testID}-stateLayer` : ''}
208
- {...stateLayerProps}
209
- style={stateLayerStyle}
210
- />
211
- </>
212
- </TouchableRipple>
213
- </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>
214
199
  );
215
200
  };
216
201
 
@@ -27,6 +27,8 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
27
27
  overflow: 'hidden',
28
28
  borderWidth: 0,
29
29
  backgroundColor: 'transparent',
30
+ justifyContent: 'center',
31
+ alignItems: 'center',
30
32
 
31
33
  variants: {
32
34
  size: {
@@ -302,11 +304,7 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
302
304
  ],
303
305
  },
304
306
 
305
- innerContainer: {
306
- flexGrow: 1,
307
- justifyContent: 'center',
308
- alignItems: 'center',
309
- },
307
+ icon: {},
310
308
  }));
311
309
 
312
310
  export const defaultStyles = getRegisteredComponentStylesWithFallback(