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

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 (152) 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 +1 -0
  29. package/components/Checkbox/index.tsx +1 -5
  30. package/components/Checkbox/utils.ts +6 -6
  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/index.tsx +1 -5
  39. package/components/DatePickerInput/utils.ts +5 -6
  40. package/components/DatePickerModal/DatePickerModalHeader.tsx +1 -1
  41. package/components/DatePickerModal/index.tsx +1 -5
  42. package/components/DatePickerModal/utils.ts +17 -16
  43. package/components/DateTimePicker/index.tsx +1 -5
  44. package/components/DateTimePicker/utils.ts +5 -6
  45. package/components/Dialog/index.tsx +1 -5
  46. package/components/Dialog/utils.ts +22 -16
  47. package/components/Drawer/Collapsible/utils.ts +13 -13
  48. package/components/Drawer/Drawer.tsx +2 -3
  49. package/components/Drawer/DrawerContent.tsx +5 -3
  50. package/components/Drawer/DrawerFooter.tsx +5 -4
  51. package/components/Drawer/DrawerHeader.tsx +5 -4
  52. package/components/Drawer/DrawerItem.tsx +5 -3
  53. package/components/Drawer/DrawerItemGroup.tsx +5 -4
  54. package/components/Drawer/index.tsx +1 -5
  55. package/components/Drawer/utils.ts +7 -7
  56. package/components/ElementGroup/ElementGroup.tsx +16 -14
  57. package/components/ElementGroup/index.tsx +1 -5
  58. package/components/ElementGroup/utils.ts +5 -6
  59. package/components/FAB/index.tsx +1 -5
  60. package/components/FAB/utils.ts +2 -6
  61. package/components/FilePicker/index.tsx +1 -5
  62. package/components/FilePicker/utils.ts +5 -6
  63. package/components/HelperText/index.tsx +1 -5
  64. package/components/HelperText/utils.ts +5 -7
  65. package/components/HorizontalDivider/HorizontalDivider.tsx +5 -3
  66. package/components/HorizontalDivider/index.tsx +1 -5
  67. package/components/Icon/CrossFadeIcon.tsx +3 -5
  68. package/components/Icon/Icon.tsx +2 -4
  69. package/components/Icon/iconFactory.tsx +3 -3
  70. package/components/Icon/index.tsx +2 -6
  71. package/components/Icon/types.ts +17 -6
  72. package/components/IconButton/IconButton.tsx +45 -58
  73. package/components/IconButton/index.tsx +1 -5
  74. package/components/IconButton/utils.ts +15 -26
  75. package/components/If/index.tsx +1 -5
  76. package/components/InputAddon/index.tsx +1 -5
  77. package/components/InputAddon/utils.ts +5 -6
  78. package/components/Link/index.tsx +1 -5
  79. package/components/Link/utils.ts +2 -6
  80. package/components/ListItem/index.tsx +1 -5
  81. package/components/ListItem/utils.ts +13 -11
  82. package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
  83. package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
  84. package/components/LoadingIndicator/index.tsx +13 -0
  85. package/components/LoadingIndicator/utils.ts +117 -0
  86. package/components/Menu/index.tsx +1 -5
  87. package/components/Menu/utils.ts +6 -8
  88. package/components/Modal/index.tsx +1 -5
  89. package/components/Modal/utils.ts +2 -6
  90. package/components/NavigationRail/NavigationRailHeader.tsx +1 -1
  91. package/components/NavigationRail/index.tsx +1 -5
  92. package/components/NavigationRail/utils.ts +21 -17
  93. package/components/NavigationStack/index.tsx +1 -5
  94. package/components/NavigationStack/utils.tsx +7 -1
  95. package/components/Portal/index.tsx +1 -5
  96. package/components/RadioButton/index.ts +1 -5
  97. package/components/RadioButton/utils.ts +9 -8
  98. package/components/Rating/index.tsx +1 -5
  99. package/components/Rating/utils.ts +6 -8
  100. package/components/Select/Select.tsx +360 -501
  101. package/components/Select/index.ts +7 -14
  102. package/components/Select/types.ts +2 -4
  103. package/components/Select/utils.ts +215 -0
  104. package/components/Slot/Slot.tsx +244 -0
  105. package/components/Slot/compose-refs.tsx +60 -0
  106. package/components/Slot/index.tsx +8 -0
  107. package/components/StateLayer/index.tsx +1 -5
  108. package/components/StateLayer/utils.ts +5 -6
  109. package/components/Surface/Surface.android.tsx +34 -8
  110. package/components/Surface/Surface.ios.tsx +36 -29
  111. package/components/Surface/Surface.tsx +31 -4
  112. package/components/Surface/index.tsx +1 -5
  113. package/components/Surface/utils.ts +49 -36
  114. package/components/Switch/Switch.tsx +8 -2
  115. package/components/Switch/index.tsx +1 -5
  116. package/components/Switch/utils.ts +2 -6
  117. package/components/Tabs/index.tsx +1 -5
  118. package/components/Tabs/utils.ts +10 -10
  119. package/components/Text/Text.tsx +2 -8
  120. package/components/TextInput/TextInput.tsx +5 -4
  121. package/components/TextInput/index.tsx +1 -5
  122. package/components/TextInput/utils.ts +8 -15
  123. package/components/TextInputWithMask/index.tsx +1 -5
  124. package/components/TimePicker/AmPmSwitcher.tsx +1 -1
  125. package/components/TimePicker/index.tsx +1 -5
  126. package/components/TimePicker/utils.ts +29 -21
  127. package/components/TimePickerField/index.tsx +1 -5
  128. package/components/TimePickerField/utils.ts +5 -6
  129. package/components/TimePickerModal/TimePickerModal.tsx +6 -2
  130. package/components/TimePickerModal/index.tsx +1 -5
  131. package/components/TimePickerModal/utils.ts +5 -6
  132. package/components/Tooltip/TooltipTrigger.tsx +25 -16
  133. package/components/Tooltip/index.tsx +1 -5
  134. package/components/Tooltip/utils.ts +5 -6
  135. package/components/TouchableRipple/TouchableRipple.native.tsx +49 -13
  136. package/components/TouchableRipple/TouchableRipple.tsx +136 -46
  137. package/components/TouchableRipple/index.tsx +1 -5
  138. package/components/TouchableRipple/utils.ts +5 -6
  139. package/components/VerticalDivider/VerticalDivider.tsx +9 -8
  140. package/components/VerticalDivider/index.tsx +1 -5
  141. package/core/componentsRegistry.ts +31 -19
  142. package/hocs/withPortal.tsx +1 -1
  143. package/hooks/useControlledValue.tsx +20 -4
  144. package/hooks/useSubcomponents.tsx +56 -22
  145. package/hooks/useWhatHasUpdated.tsx +48 -0
  146. package/package.json +10 -13
  147. package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
  148. package/styles/shadow.ts +2 -1
  149. package/styles/themes/LightTheme.tsx +1 -1
  150. package/utils/extractPropertiesFromStyles.ts +25 -0
  151. package/utils/lodash.ts +77 -6
  152. package/utils/repository.ts +2 -52
@@ -1,140 +1,92 @@
1
- import setColor from 'color';
1
+ import { forwardRef, memo, type PropsWithoutRef, type ReactNode, useContext, useMemo } from 'react';
2
2
  import {
3
- forwardRef,
4
- memo,
5
- type PropsWithoutRef,
6
- type ReactNode,
7
- useCallback,
8
- useMemo,
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 IconType } from '../Icon';
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 { defaultStyles, sizeToIconSizeMap } from './utils';
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
- * Mode of the button. You can change the mode to adjust the styling to give it desired emphasis.
28
- * - `text` - flat button without background or outline, used for the lowest priority actions, especially when presenting multiple options.
29
- * - `outlined` - button with an outline without background, typically used for important, but not primary action represents medium emphasis.
30
- * - `contained` - button with a background color, used for important action, have the most visual impact and high emphasis.
31
- * - `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
32
- * - `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
33
- */
34
- variant?: ButtonVariant;
35
- /**
36
- * @supported Available in v5.x
37
- * Custom button's background color.
38
- */
39
- buttonColor?: string;
40
- /**
41
- * Whether to show a loading indicator.
42
- */
43
- loading?: boolean;
44
- /**
45
- * Icon to display for the `Button`.
46
- */
47
- iconType?: IconType;
48
- iconName?: string;
49
- iconSize?: number;
50
- /**
51
- * Whether the button is disabled. A disabled button is greyed out and `onPress` is not called on touch.
52
- */
53
- disabled?: boolean;
54
- /**
55
- * Label text of the button.
56
- */
57
- children: ReactNode;
58
- /**
59
- * Accessibility label for the button. This is read by the screen reader when the user taps the button.
60
- */
61
- accessibilityLabel?: string;
62
- /**
63
- * Accessibility hint for the button. This is read by the screen reader when the user taps the button.
64
- */
65
- accessibilityHint?: string;
66
- /**
67
- * Function to execute on press.
68
- */
69
- onPress?: () => void;
70
- /**
71
- * @supported Available in v5.x
72
- * Function to execute as soon as the touchable element is pressed and invoked even before onPress.
73
- */
74
- onPressIn?: () => void;
75
- /**
76
- * @supported Available in v5.x
77
- * Function to execute as soon as the touch is released even before onPress.
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
- size = 'lg',
134
- loading,
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
- iconStyle: _iconStyleProp,
156
- ...rest
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
- defaultStyles.useVariants({
115
+ buttonStyles.useVariants({
168
116
  variant,
169
- state,
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
- customLabelColor: labelColor,
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: [defaultStyles.stateLayer, stateLayerProps?.style],
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 = useMemo(
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
- {...rest}
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
- {iconName && loading !== true ? (
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
- <StateLayer
339
- testID={testID ? `${testID}-stateLayer` : ''}
340
- {...stateLayerProps}
341
- style={stateLayerStyle}
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, registerMoleculesComponents } from '../../core';
2
- import ButtonDefault from './Button';
1
+ import { getRegisteredComponentWithFallback } from '../../core';
2
+ import ButtonDefault, { ButtonActivityIndicator, ButtonIcon, ButtonText } from './Button';
3
3
 
4
- registerMoleculesComponents({
5
- Button: ButtonDefault,
6
- });
4
+ const ButtonBase = getRegisteredComponentWithFallback('Button', ButtonDefault);
7
5
 
8
- export const Button = getRegisteredComponentWithFallback('Button', ButtonDefault);
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 { defaultStyles } from './utils';
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 ButtonStates = 'hovered' | 'disabled';
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
+ };