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

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.
@@ -22,7 +22,6 @@ const iconButtonSizeToIconSizeMapDefault = {
22
22
  const iconButtonStylesDefault = StyleSheet.create(theme => ({
23
23
  root: {
24
24
  borderColor: theme.colors.outline,
25
- color: theme.colors.onSurfaceVariant,
26
25
  borderRadius: theme.shapes.corner.full,
27
26
  overflow: 'hidden',
28
27
  borderWidth: 0,
@@ -73,16 +72,13 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
73
72
 
74
73
  contained: {
75
74
  backgroundColor: theme.colors.surfaceVariant,
76
- color: theme.colors.primary,
77
75
  },
78
76
 
79
77
  'contained-tonal': {
80
78
  backgroundColor: theme.colors.surfaceVariant,
81
- color: theme.colors.onSurfaceVariant,
82
79
  },
83
80
 
84
81
  outlined: {
85
- color: theme.colors.onSurfaceVariant,
86
82
  borderWidth: 1,
87
83
  },
88
84
  },
@@ -92,30 +88,23 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
92
88
  {
93
89
  variant: 'default',
94
90
  state: 'selectedAndDisabled',
95
- styles: {
96
- color: theme.colors.primary,
97
- },
91
+ styles: {},
98
92
  },
99
93
  {
100
94
  variant: 'default',
101
95
  state: 'selected',
102
- styles: {
103
- color: theme.colors.primary,
104
- },
96
+ styles: {},
105
97
  },
106
98
  {
107
99
  variant: 'default',
108
100
  state: 'selectedAndHovered',
109
- styles: {
110
- color: theme.colors.primary,
111
- },
101
+ styles: {},
112
102
  },
113
103
  {
114
104
  variant: 'contained',
115
105
  state: 'selectedAndDisabled',
116
106
  styles: {
117
107
  backgroundColor: theme.colors.primary,
118
- color: theme.colors.onPrimary,
119
108
  },
120
109
  },
121
110
  {
@@ -130,14 +119,13 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
130
119
  state: 'selected',
131
120
  styles: {
132
121
  backgroundColor: theme.colors.primary,
133
- color: theme.colors.onPrimary,
134
122
  },
135
123
  },
136
124
  {
137
125
  variant: 'contained',
138
126
  state: 'selectedAndHovered',
139
127
  styles: {
140
- color: theme.colors.primary,
128
+ backgroundColor: theme.colors.primary,
141
129
  },
142
130
  },
143
131
  {
@@ -145,7 +133,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
145
133
  state: 'hovered',
146
134
  styles: {
147
135
  backgroundColor: theme.colors.primary,
148
- color: theme.colors.onPrimary,
149
136
  },
150
137
  },
151
138
  {
@@ -153,7 +140,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
153
140
  state: 'selectedAndDisabled',
154
141
  styles: {
155
142
  backgroundColor: theme.colors.secondaryContainer,
156
- color: theme.colors.onSecondaryContainer,
157
143
  },
158
144
  },
159
145
  {
@@ -168,7 +154,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
168
154
  state: 'selected',
169
155
  styles: {
170
156
  backgroundColor: theme.colors.secondaryContainer,
171
- color: theme.colors.onSecondaryContainer,
172
157
  },
173
158
  },
174
159
  {
@@ -176,7 +161,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
176
161
  state: 'selectedAndHovered',
177
162
  styles: {
178
163
  backgroundColor: theme.colors.secondaryContainer,
179
- color: theme.colors.onSecondaryContainer,
180
164
  },
181
165
  },
182
166
  {
@@ -184,7 +168,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
184
168
  state: 'selectedAndDisabled',
185
169
  styles: {
186
170
  backgroundColor: theme.colors.inverseSurface,
187
- color: theme.colors.inverseOnSurface,
188
171
  borderWidth: 0,
189
172
  },
190
173
  },
@@ -200,7 +183,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
200
183
  state: 'selected',
201
184
  styles: {
202
185
  backgroundColor: theme.colors.inverseSurface,
203
- color: theme.colors.inverseOnSurface,
204
186
  borderWidth: 0,
205
187
  },
206
188
  },
@@ -209,7 +191,6 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
209
191
  state: 'selectedAndHovered',
210
192
  styles: {
211
193
  backgroundColor: theme.colors.secondaryContainer,
212
- color: theme.colors.onSecondaryContainer,
213
194
  },
214
195
  },
215
196
  {
@@ -294,13 +275,147 @@ const iconButtonStylesDefault = StyleSheet.create(theme => ({
294
275
  variant: 'outlined',
295
276
  state: 'hovered',
296
277
  styles: {
297
- backgroundColor: theme.colors.stateLayer.hover.inverseOnSurface,
278
+ backgroundColor: theme.colors.stateLayer.hover.onSurfaceVariant,
298
279
  },
299
280
  },
300
281
  ],
301
282
  },
302
283
 
303
- icon: {},
284
+ icon: {
285
+ color: theme.colors.onSurfaceVariant,
286
+
287
+ variants: {
288
+ variant: {
289
+ default: {},
290
+
291
+ contained: {
292
+ color: theme.colors.primary,
293
+ },
294
+
295
+ 'contained-tonal': {
296
+ color: theme.colors.onSurfaceVariant,
297
+ },
298
+
299
+ outlined: {
300
+ color: theme.colors.onSurfaceVariant,
301
+ },
302
+ },
303
+ },
304
+
305
+ compoundVariants: [
306
+ {
307
+ variant: 'default',
308
+ state: 'selectedAndDisabled',
309
+ styles: {
310
+ color: theme.colors.primary,
311
+ },
312
+ },
313
+ {
314
+ variant: 'default',
315
+ state: 'selected',
316
+ styles: {
317
+ color: theme.colors.primary,
318
+ },
319
+ },
320
+ {
321
+ variant: 'default',
322
+ state: 'selectedAndHovered',
323
+ styles: {
324
+ color: theme.colors.primary,
325
+ },
326
+ },
327
+ {
328
+ variant: 'contained',
329
+ state: 'selectedAndDisabled',
330
+ styles: {
331
+ color: theme.colors.onPrimary,
332
+ },
333
+ },
334
+ {
335
+ variant: 'contained',
336
+ state: 'disabled',
337
+ styles: {},
338
+ },
339
+ {
340
+ variant: 'contained',
341
+ state: 'selected',
342
+ styles: {
343
+ color: theme.colors.onPrimary,
344
+ },
345
+ },
346
+ {
347
+ variant: 'contained',
348
+ state: 'selectedAndHovered',
349
+ styles: {
350
+ color: theme.colors.onPrimary,
351
+ },
352
+ },
353
+ {
354
+ variant: 'contained',
355
+ state: 'hovered',
356
+ styles: {
357
+ color: theme.colors.onPrimary,
358
+ },
359
+ },
360
+ {
361
+ variant: 'contained-tonal',
362
+ state: 'selectedAndDisabled',
363
+ styles: {
364
+ color: theme.colors.onSecondaryContainer,
365
+ },
366
+ },
367
+ {
368
+ variant: 'contained-tonal',
369
+ state: 'disabled',
370
+ styles: {},
371
+ },
372
+ {
373
+ variant: 'contained-tonal',
374
+ state: 'selected',
375
+ styles: {
376
+ color: theme.colors.onSecondaryContainer,
377
+ },
378
+ },
379
+ {
380
+ variant: 'contained-tonal',
381
+ state: 'selectedAndHovered',
382
+ styles: {
383
+ color: theme.colors.onSecondaryContainer,
384
+ },
385
+ },
386
+ {
387
+ variant: 'outlined',
388
+ state: 'selectedAndDisabled',
389
+ styles: {
390
+ color: theme.colors.inverseOnSurface,
391
+ },
392
+ },
393
+ {
394
+ variant: 'outlined',
395
+ state: 'disabled',
396
+ styles: {},
397
+ },
398
+ {
399
+ variant: 'outlined',
400
+ state: 'selected',
401
+ styles: {
402
+ color: theme.colors.inverseOnSurface,
403
+ },
404
+ },
405
+ {
406
+ variant: 'outlined',
407
+ state: 'selectedAndHovered',
408
+ styles: {
409
+ color: theme.colors.onSecondaryContainer,
410
+ },
411
+ },
412
+ {
413
+ variant: 'outlined',
414
+ state: 'hovered',
415
+ styles: {},
416
+ },
417
+ ],
418
+ },
304
419
  }));
305
420
 
306
421
  export const defaultStyles = getRegisteredComponentStylesWithFallback(
@@ -807,7 +807,7 @@ SelectOption.displayName = 'Select_Option';
807
807
 
808
808
  // Select.SearchInput - handles search
809
809
  const SelectSearchInput = memo(
810
- ({ autoFocus = true, ...textInputProps }: SelectSearchInputProps) => {
810
+ ({ autoFocus = true, children, ...textInputProps }: SelectSearchInputProps) => {
811
811
  const { searchQuery, setSearchQuery } = useSelectContextValue(state => ({
812
812
  searchQuery: state.searchQuery,
813
813
  setSearchQuery: state.setSearchQuery,
@@ -866,16 +866,19 @@ const SelectSearchInput = memo(
866
866
  ref={textInputRef}
867
867
  autoFocus={Platform.OS !== 'web' && autoFocus}
868
868
  style={styles.searchInput}
869
- left={<Icon onPress={onPressLeftIcon} name="magnify" size={20} />}
870
- right={
871
- searchQuery ? (
872
- <IconButton name="close" size={20} onPress={onClearSearchQuery} />
873
- ) : undefined
874
- }
875
869
  size="sm"
876
870
  variant="outlined"
877
- {...inputProps}
878
- />
871
+ {...inputProps}>
872
+ <TextInput.Left>
873
+ <Icon onPress={onPressLeftIcon} name="magnify" size={20} />
874
+ </TextInput.Left>
875
+ {searchQuery && (
876
+ <TextInput.Right>
877
+ <IconButton name="close" size={20} onPress={onClearSearchQuery} />
878
+ </TextInput.Right>
879
+ )}
880
+ {children}
881
+ </TextInput>
879
882
  );
880
883
  },
881
884
  );
@@ -1,29 +1,20 @@
1
- import {
2
- Children,
3
- cloneElement,
4
- forwardRef,
5
- isValidElement,
6
- type JSXElementConstructor,
7
- memo,
8
- type ReactElement,
9
- useCallback,
10
- useMemo,
11
- useRef,
12
- useState,
13
- } from 'react';
1
+ import { forwardRef, memo, type ReactNode, useCallback, useMemo, useRef, useState } from 'react';
14
2
  import { type LayoutChangeEvent, View, type ViewProps, type ViewStyle } from 'react-native';
15
3
 
16
4
  import { useActionState } from '../../hooks';
17
5
  import { resolveStateVariant } from '../../utils';
18
6
  import { StateLayer } from '../StateLayer';
19
7
  import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
20
- import { tabsItemStyles } from './utils';
8
+ import { TabItemContext, tabsItemStyles } from './utils';
21
9
 
22
- export type TabItemProps = Omit<TouchableRippleProps, 'children' | 'ref'> & {
10
+ export type TabItemProps<T extends string | number> = Omit<
11
+ TouchableRippleProps,
12
+ 'children' | 'ref'
13
+ > & {
23
14
  /**
24
15
  * name of the tab. This should be unique like a route name
25
16
  * */
26
- name: string;
17
+ name: T;
27
18
  /**
28
19
  * Allows to define if TabItem is active.
29
20
  * */
@@ -37,22 +28,11 @@ export type TabItemProps = Omit<TouchableRippleProps, 'children' | 'ref'> & {
37
28
  contentsContainerProps?: Omit<ViewProps, 'children' | 'style' | 'onLayout'>;
38
29
  onLayoutContent?: (e: LayoutChangeEvent) => void;
39
30
  accessibilityLabel?: string;
40
- children: ReactElement<
41
- {
42
- active: boolean;
43
- hovered: boolean;
44
- variant: 'primary' | 'secondary';
45
- },
46
- JSXElementConstructor<{
47
- active: boolean;
48
- hovered: boolean;
49
- variant: 'primary' | 'secondary';
50
- }>
51
- >;
31
+ children: ReactNode;
52
32
  stateLayerProps?: ViewProps;
53
33
  };
54
34
 
55
- const TabItem = (
35
+ const TabItem = <T extends string | number>(
56
36
  {
57
37
  active = false,
58
38
  variant = 'primary',
@@ -65,7 +45,7 @@ const TabItem = (
65
45
  children,
66
46
  stateLayerProps,
67
47
  ...rest
68
- }: TabItemProps,
48
+ }: TabItemProps<T>,
69
49
  ref: any,
70
50
  ) => {
71
51
  const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
@@ -110,36 +90,33 @@ const TabItem = (
110
90
  [active, accessibilityLabel, state],
111
91
  );
112
92
 
93
+ const contextValue = useMemo(() => ({ active, hovered, variant }), [active, hovered, variant]);
94
+
113
95
  return (
114
- <TouchableRipple
115
- style={containerStyle}
116
- accessibilityRole="tab"
117
- accessibilityState={accessibilityState}
118
- accessibilityValue={accessibilityValue}
119
- {...rest}
120
- ref={actionsRef}
121
- onLayout={onLayout}>
122
- <>
123
- <View
124
- style={[tabsItemStyles.contentsContainer, contentsContainerStyleProp]}
125
- {...contentsContainerProps}
126
- onLayout={onLayoutHandled}>
127
- {Children.map(children, child => {
128
- if (!isValidElement(child)) return null;
129
- return cloneElement(child, {
130
- active,
131
- hovered,
132
- variant,
133
- });
134
- })}
135
- </View>
96
+ <TabItemContext.Provider value={contextValue}>
97
+ <TouchableRipple
98
+ style={containerStyle}
99
+ accessibilityRole="tab"
100
+ accessibilityState={accessibilityState}
101
+ accessibilityValue={accessibilityValue}
102
+ {...rest}
103
+ ref={actionsRef}
104
+ onLayout={onLayout}>
105
+ <>
106
+ <View
107
+ style={[tabsItemStyles.contentsContainer, contentsContainerStyleProp]}
108
+ {...contentsContainerProps}
109
+ onLayout={onLayoutHandled}>
110
+ {children}
111
+ </View>
136
112
 
137
- <StateLayer
138
- {...stateLayerProps}
139
- style={[tabsItemStyles.stateLayer, stateLayerProps?.style]}
140
- />
141
- </>
142
- </TouchableRipple>
113
+ <StateLayer
114
+ {...stateLayerProps}
115
+ style={[tabsItemStyles.stateLayer, stateLayerProps?.style]}
116
+ />
117
+ </>
118
+ </TouchableRipple>
119
+ </TabItemContext.Provider>
143
120
  );
144
121
  };
145
122
 
@@ -1,9 +1,9 @@
1
- import { type FC, memo, useMemo } from 'react';
1
+ import { memo, useContext, useMemo } from 'react';
2
2
  import { type TextProps, type TextStyle } from 'react-native';
3
3
 
4
4
  import { Icon, type IconProps, type IconType } from '../Icon';
5
5
  import { Text } from '../Text';
6
- import { tabsLabelStyles } from './utils';
6
+ import { TabItemContext, tabsLabelStyles } from './utils';
7
7
 
8
8
  const DEFAULT_ICON_SIZE = 24;
9
9
 
@@ -23,11 +23,6 @@ export type TabLabelProps = {
23
23
  iconStyle?: TextStyle;
24
24
 
25
25
  activeColor?: string;
26
-
27
- active: boolean;
28
- hovered: boolean;
29
-
30
- variant: 'primary' | 'secondary';
31
26
  };
32
27
 
33
28
  const TabLabel = memo((props: TabLabelProps) => {
@@ -40,9 +35,10 @@ const TabLabel = memo((props: TabLabelProps) => {
40
35
  labelStyle: labelStyleProp,
41
36
  labelProps,
42
37
  label,
43
- active,
44
38
  } = props;
45
39
 
40
+ const { active } = useContext(TabItemContext);
41
+
46
42
  // tabsLabelStyles.useVariants({
47
43
  // variant,
48
44
  // state: resolveStateVariant({
@@ -81,4 +77,4 @@ const TabLabel = memo((props: TabLabelProps) => {
81
77
 
82
78
  TabLabel.displayName = 'TabLabel';
83
79
 
84
- export default TabLabel as unknown as FC<Omit<TabLabelProps, 'active' | 'hovered' | 'variant'>>;
80
+ export default TabLabel;