react-native-varia 0.0.1 → 0.2.0

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 (86) hide show
  1. package/bin/cli.js +35 -18
  2. package/lib/components/Badge.tsx +31 -32
  3. package/lib/components/Button.tsx +20 -20
  4. package/lib/components/Checkbox.tsx +95 -0
  5. package/lib/components/CircleProgress.tsx +56 -66
  6. package/lib/components/Field.tsx +137 -0
  7. package/lib/components/GradientBackground.tsx +17 -18
  8. package/lib/components/GradientText.tsx +25 -64
  9. package/lib/components/IconWrapper.tsx +32 -25
  10. package/lib/components/Input.tsx +66 -68
  11. package/lib/components/Link.tsx +14 -28
  12. package/lib/components/Modal.tsx +197 -97
  13. package/lib/components/NewSelect.tsx +202 -0
  14. package/lib/components/NumberInput.tsx +226 -0
  15. package/lib/components/RadioGroup.tsx +195 -0
  16. package/lib/components/ReText.tsx +53 -87
  17. package/lib/components/Select.tsx +272 -0
  18. package/lib/components/SelectOld.tsx +153 -0
  19. package/lib/components/Slider.tsx +32 -40
  20. package/lib/components/Slideshow.tsx +174 -261
  21. package/lib/components/SlidingDrawer.tsx +216 -265
  22. package/lib/components/Spinner.tsx +21 -12
  23. package/lib/components/Switch.tsx +133 -180
  24. package/lib/components/Switchold.tsx +174 -0
  25. package/lib/components/Text.tsx +36 -83
  26. package/lib/components/layoutTest.tsx +74 -0
  27. package/lib/patterns/index.tsx +143 -202
  28. package/lib/theme/Badge.recipe.tsx +44 -39
  29. package/lib/theme/Button.recipe.tsx +139 -48
  30. package/lib/theme/Checkbox.recipe.tsx +121 -0
  31. package/lib/theme/CircleProgress.recipe.tsx +16 -22
  32. package/lib/theme/Field.recipe.tsx +66 -0
  33. package/lib/theme/GradientBackground.recipe.tsx +7 -20
  34. package/lib/theme/GradientText.recipe.tsx +42 -28
  35. package/lib/theme/IconWrapper.recipe.tsx +10 -85
  36. package/lib/theme/Input.recipe.tsx +76 -83
  37. package/lib/theme/Link.recipe.tsx +16 -43
  38. package/lib/theme/Modal.recipe.tsx +59 -21
  39. package/lib/theme/NumberInput.recipe.tsx +191 -0
  40. package/lib/theme/RadioGroup.recipe.tsx +163 -0
  41. package/lib/theme/ReText.recipe.tsx +4 -7
  42. package/lib/theme/Select.recipe.tsx +121 -0
  43. package/lib/theme/Slider.recipe.tsx +97 -181
  44. package/lib/theme/Slideshow.recipe.tsx +24 -102
  45. package/lib/theme/SlidingDrawer.recipe.tsx +21 -59
  46. package/lib/theme/Spinner.recipe.tsx +28 -3
  47. package/lib/theme/Switch.recipe.tsx +75 -54
  48. package/lib/theme/Text.recipe.tsx +66 -8
  49. package/lib/theme/animations.tsx +13 -0
  50. package/lib/varia/colorPalettes/amber.ts +54 -0
  51. package/lib/varia/colorPalettes/blue.ts +54 -0
  52. package/lib/varia/colorPalettes/bronze.ts +54 -0
  53. package/lib/varia/colorPalettes/brown.ts +54 -0
  54. package/lib/varia/colorPalettes/crimson.ts +55 -0
  55. package/lib/varia/colorPalettes/cyan.ts +54 -0
  56. package/lib/varia/colorPalettes/gold.ts +54 -0
  57. package/lib/varia/colorPalettes/grass.ts +54 -0
  58. package/lib/varia/colorPalettes/green.ts +54 -0
  59. package/lib/varia/colorPalettes/indigo.ts +54 -0
  60. package/lib/varia/colorPalettes/iris.ts +54 -0
  61. package/lib/varia/colorPalettes/jade.ts +54 -0
  62. package/lib/varia/colorPalettes/lime.ts +55 -0
  63. package/lib/varia/colorPalettes/mauve.ts +54 -0
  64. package/lib/varia/colorPalettes/mint.ts +54 -0
  65. package/lib/varia/colorPalettes/neutral.ts +54 -0
  66. package/lib/varia/colorPalettes/olive.ts +54 -0
  67. package/lib/varia/colorPalettes/orange.ts +54 -0
  68. package/lib/varia/colorPalettes/pink.ts +54 -0
  69. package/lib/varia/colorPalettes/plum.ts +54 -0
  70. package/lib/varia/colorPalettes/purple.ts +56 -0
  71. package/lib/varia/colorPalettes/red.ts +55 -0
  72. package/lib/varia/colorPalettes/ruby.ts +56 -0
  73. package/lib/varia/colorPalettes/sage.ts +56 -0
  74. package/lib/varia/colorPalettes/sand.ts +56 -0
  75. package/lib/varia/colorPalettes/sky.ts +56 -0
  76. package/lib/varia/colorPalettes/slate.ts +56 -0
  77. package/lib/varia/colorPalettes/teal.ts +56 -0
  78. package/lib/varia/colorPalettes/tomato.ts +56 -0
  79. package/lib/varia/colorPalettes/violet.ts +56 -0
  80. package/lib/varia/colorPalettes/yellow.ts +56 -0
  81. package/lib/varia/defaultTheme.ts +174 -0
  82. package/lib/varia/mixins.ts +223 -0
  83. package/lib/varia/textStyles.ts +48 -0
  84. package/lib/varia/types.ts +277 -0
  85. package/lib/varia/utils.ts +283 -0
  86. package/package.json +1 -1
@@ -1,224 +1,177 @@
1
- import React, { useLayoutEffect, useRef } from 'react';
1
+ import {TouchableWithoutFeedback} from 'react-native'
2
2
  import Animated, {
3
3
  useAnimatedStyle,
4
- interpolateColor,
5
4
  useSharedValue,
5
+ withSpring,
6
6
  withTiming,
7
- Easing,
8
- } from 'react-native-reanimated';
9
- import { runOnJS } from 'react-native-worklets';
10
- import { ColorValue, TouchableWithoutFeedback } from 'react-native';
11
- import { StyleSheet, UnistylesVariants, withUnistyles } from 'react-native-unistyles';
12
- import { SwitchStyles, SwitchTokens } from '../theme/Switch.recipe';
7
+ } from 'react-native-reanimated'
8
+ import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
9
+ import {useAnimatedVariantColor} from 'react-native-unistyles/reanimated'
10
+ import {ReactNode, useLayoutEffect, useRef} from 'react'
11
+ import {SwitchTokens, SwitchStyles} from '../theme/Switch.recipe'
12
+ import {PalettesWithNestedKeys} from '../style/varia/types'
13
+
14
+ const animations = {
15
+ withSpring,
16
+ withTiming,
17
+ }
18
+
19
+ type AnimationType = 'withSpring' | 'withTiming'
13
20
 
14
- type SwitchVariants = UnistylesVariants<typeof SwitchStyles>;
21
+ type SwitchVariants = UnistylesVariants<typeof SwitchStyles>
15
22
 
16
23
  type SwitchProps = SwitchVariants & {
17
- value: boolean;
18
- onValueChange: (value: boolean) => void;
19
- flex?: number;
20
- thumbChildren?: React.ReactNode;
21
- colors?: Record<string, ColorValue>;
22
- };
23
-
24
- // interface SwitchProps {
25
- // value: boolean;
26
- // onValueChange: (value: boolean) => void;
27
- // size: keyof SwitchSizeVariants;
28
- // colorScheme: keyof SwitchColorSchemeVariants;
29
- // flex?: number;
30
- // thumbChildren?: React.ReactNode;
31
- // }
24
+ colorPalette?: PalettesWithNestedKeys
25
+ value?: boolean
26
+ animation?: keyof typeof SwitchTokens.variants.animation
27
+ onValueChange?: (value: boolean) => void
28
+ flex?: number
29
+ enabledIcon: ReactNode
30
+ disabledIcon: ReactNode
31
+ }
32
32
 
33
33
  const Switch = ({
34
+ colorPalette = 'accent',
34
35
  value,
35
- onValueChange,
36
- size,
37
- colorPalette,
38
- flex = 0,
39
- thumbChildren: ThumbChildren,
40
- colors
36
+ enabledIcon: EnabledIcon,
37
+ disabledIcon: DisabledIcon,
38
+ animation = SwitchTokens.defaultProps.animation,
39
+ onValueChange = () => {},
40
+ variant = SwitchTokens.defaultProps.variant,
41
+ size = SwitchTokens.defaultProps.size,
42
+ flex = 1,
41
43
  }: SwitchProps) => {
42
- // const switchTokens = useTokens('switch')();
43
- const animatedRef = useRef(null);
44
+ const animatedRef = useRef(null)
44
45
 
45
- // const resolvedColorScheme =
46
- // colorScheme ??
47
- // (switchTokens.defaultProps.colorScheme as keyof SwitchColorSchemeVariants);
48
- // const resolvedSize =
49
- // size ?? (switchTokens.defaultProps.size as keyof SwitchSizeVariants);
46
+ const isAnimating = useSharedValue(false)
50
47
 
51
48
  SwitchStyles.useVariants({
52
- // colorPalette: colorPalette,
53
- size: size,
54
- });
55
-
56
- // const { styles, theme } = useStyles(stylesheet, {
57
- // size,
58
- // // type,
59
- // });
60
- const trackTokenColorKey = SwitchTokens.track.variants.colorPalette[colorPalette];
61
- console.log("🚀 ~ trackTokenColorKey:", trackTokenColorKey)
62
- const thumbTokenColorKey = SwitchTokens.thumb.variants.colorPalette[colorPalette];
63
- console.log("🚀 ~ thumbTokenColorKey:", thumbTokenColorKey)
64
- console.log("🚀 ~ colors:", colors)
65
-
66
- const trackDisabledColor = colors[trackTokenColorKey?.disabled?.backgroundColor];
67
- console.log("🚀 ~ trackDisabledColor:", trackDisabledColor)
68
- const trackEnabledColor =
69
- colors[trackTokenColorKey?.enabled?.backgroundColor];
70
- console.log("🚀 ~ trackEnabledColor:", trackEnabledColor)
71
- const thumbDisabledColor =
72
- colors[thumbTokenColorKey?.disabled?.backgroundColor];
73
- console.log("🚀 ~ thumbDisabledColor:", thumbDisabledColor)
74
- const thumbEnabledColor =
75
- colors[thumbTokenColorKey?.enabled?.backgroundColor];
76
- console.log("🚀 ~ thumbEnabledColor:", thumbEnabledColor)
77
- const trackBorderWidth = 1;
78
- const trackBorderColor = 'white';
79
- // const trackBorderWidth =
80
- // switchTokens?.track?.variants?.colorScheme?.[colorScheme]?.borderWidth ?? 0;
81
- // const trackBorderColor =
82
- // switchTokens?.track?.variants?.colorScheme?.[colorScheme]?.borderColor ?? 'transparent';
83
- const maxHeight = SwitchTokens?.track?.variants?.size?.[size]?.height;
84
-
85
- const animatedValue = useSharedValue(0);
86
- const containerWidth = useSharedValue(0);
49
+ variant,
50
+ size,
51
+ enabled: value,
52
+ })
53
+
54
+ const animationVariant =
55
+ SwitchTokens.variants?.animation && animation
56
+ ? SwitchTokens.variants.animation[animation]
57
+ : {
58
+ type: 'withSpring' as AnimationType,
59
+ props: {
60
+ damping: 15,
61
+ stiffness: 100,
62
+ mass: 1,
63
+ },
64
+ }
65
+
66
+ const color = useAnimatedVariantColor(
67
+ SwitchStyles.container(colorPalette),
68
+ 'backgroundColor',
69
+ )
70
+ const thumbColor = useAnimatedVariantColor(
71
+ SwitchStyles.thumb(colorPalette),
72
+ 'backgroundColor',
73
+ )
74
+ const thumbEnabledPosition = useSharedValue(0)
75
+ const animatedValue = useSharedValue(0)
76
+ const containerWidth = useSharedValue(0)
87
77
 
88
78
  useLayoutEffect(() => {
89
79
  //@ts-ignore
90
- animatedRef.current?.measure((x, y, width, height, pageX, pageY) => {
91
- console.log("🚀 ~ animatedRef.current?.measure ~ width:", width)
92
- const thumbWidth =
93
- SwitchTokens?.thumb?.variants?.size?.[size]?.width ?? 0;
94
- containerWidth.value = width - thumbWidth;
95
- });
96
- }, []);
97
-
98
- const animate = () => {
99
- if (animatedValue.value === 0) {
100
- animatedValue.value = withTiming(
101
- containerWidth.value - 6 - trackBorderWidth * 2,
102
- {
103
- duration: 200,
104
- easing: Easing.ease,
105
- },
106
- () => {
107
- runOnJS(onValueChange)(!value);
108
- }
109
- );
110
- } else {
111
- animatedValue.value = withTiming(
112
- 0,
113
- { duration: 200, easing: Easing.ease },
114
- () => {
115
- runOnJS(onValueChange)(!value);
116
- }
117
- );
80
+ animatedRef.current?.measure((x, y, width) => {
81
+ containerWidth.value = width
82
+ //@ts-ignore
83
+ const thumbWidth = SwitchStyles.thumb(colorPalette).width
84
+ //@ts-ignore
85
+ const padding = SwitchStyles.container(colorPalette).padding || 0
86
+ const trackBorderWidth =
87
+ //@ts-ignore
88
+ SwitchStyles.container(colorPalette).borderWidth || 0
89
+ thumbEnabledPosition.value =
90
+ width - thumbWidth - trackBorderWidth * 2 - padding * 2
91
+ })
92
+ }, [])
93
+
94
+ const animatedStyle = useAnimatedStyle(() => {
95
+ return {
96
+ backgroundColor: animations[animationVariant.type](
97
+ color.value,
98
+ animationVariant.props,
99
+ ),
118
100
  }
119
- };
101
+ })
102
+ const thumbAnimatedStyle = useAnimatedStyle(() => {
103
+ return {
104
+ backgroundColor: animations[animationVariant.type](
105
+ thumbColor.value,
106
+ animationVariant.props,
107
+ ),
108
+ }
109
+ })
120
110
 
121
- const backgroundColorStyle = useAnimatedStyle(() => {
122
- //@ts-ignore
123
- const backgroundColor = interpolateColor(
124
- animatedValue.value,
125
- [0, containerWidth.value],
126
- [trackDisabledColor, trackEnabledColor]
127
- );
128
- return { backgroundColor };
129
- });
130
111
  const circleTranslationStyle = useAnimatedStyle(() => {
131
- //@ts-ignore
132
- const backgroundColor = interpolateColor(
133
- animatedValue.value,
134
- [0, containerWidth.value],
135
- [thumbDisabledColor, thumbEnabledColor]
136
- );
137
112
  return {
138
- backgroundColor,
139
113
  transform: [
140
114
  {
141
115
  translateX: animatedValue.value,
142
116
  },
143
117
  ],
144
- };
145
- });
118
+ }
119
+ })
120
+
121
+ const Icon = value ? EnabledIcon : DisabledIcon
122
+
146
123
  return (
147
124
  <TouchableWithoutFeedback
148
125
  onPress={() => {
149
- animate();
150
- }}
151
- >
126
+ if (isAnimating.value) return
127
+ isAnimating.value = true
128
+ const toValue =
129
+ animatedValue.value === 0 ? thumbEnabledPosition.value : 0
130
+ onValueChange(!value)
131
+ animatedValue.value = animations[animationVariant.type](
132
+ toValue,
133
+ animationVariant.props,
134
+ () => {
135
+ 'worklet'
136
+ isAnimating.value = false
137
+ },
138
+ )
139
+ }}>
152
140
  <Animated.View
153
141
  ref={animatedRef}
154
142
  style={[
155
- styles.container(
156
- flex,
157
- maxHeight,
158
- trackBorderWidth,
159
- trackBorderColor,
160
- // switchTokens.track.variants
161
- ),
162
- SwitchStyles.track,
163
- backgroundColorStyle,
164
- ]}
165
- testID="switch"
166
- >
143
+ styles.container(flex),
144
+ animatedStyle,
145
+ SwitchStyles.container(colorPalette),
146
+ ]}>
167
147
  <Animated.View
168
148
  style={[
169
- styles.thumb(),
170
- SwitchStyles.thumb,
149
+ styles.thumb,
150
+ SwitchStyles.thumb(colorPalette),
151
+ thumbAnimatedStyle,
171
152
  circleTranslationStyle,
172
- ]}
173
- >
174
- {ThumbChildren || null}
153
+ ]}>
154
+ {Icon && Icon}
175
155
  </Animated.View>
176
156
  </Animated.View>
177
157
  </TouchableWithoutFeedback>
178
- );
179
- };
158
+ )
159
+ }
180
160
 
181
- // type SwitchTokenType = ReturnType<Tokens['switch']>; // This is the return of the function
182
- // type TrackVariantsType = SwitchTokenType['track']['variants'];
183
- // type ThumbVariantsType = SwitchTokenType['thumb']['variants'];
161
+ export default Switch
184
162
 
185
163
  const styles = StyleSheet.create({
186
- container: (
187
- flex,
188
- maxHeight,
189
- borderWidth,
190
- borderColor,
191
- // variants: TrackVariantsType
192
- ) => ({
193
- // width: 60,
194
- // height: 34,
195
- flex,
196
- maxHeight,
197
- borderRadius: 9999,
198
- justifyContent: 'center',
199
- padding: 3,
200
- borderWidth,
201
- borderColor,
202
- // variants: {
203
- // size: variants.size,
204
- // },
164
+ container: (flex: number) => ({
165
+ flexGrow: flex,
166
+ flexShrink: 0,
167
+ alignSelf: 'flex-start',
168
+ flexDirection: 'row',
169
+ alignItems: 'center',
170
+ margin: 0,
205
171
  }),
206
- thumb: (
207
- // variants: ThumbVariantsType
208
- ) => ({
209
- borderRadius: 50,
172
+ thumb: {
173
+ borderRadius: 9999,
210
174
  justifyContent: 'center',
211
175
  alignItems: 'center',
212
- // variants: {
213
- // size: variants.size,
214
- // type: thumbVariants.type(theme),
215
- // type: switchTokens.thumb.variants.type(theme),
216
- // },
217
- }),
218
- });
219
-
220
- export default Switch;
221
-
222
- export const ThemedSwitch = withUnistyles(Switch, (theme, rt) => ({
223
- colors: theme.colors,
224
- }));
176
+ },
177
+ })
@@ -0,0 +1,174 @@
1
+ import {TouchableWithoutFeedback} from 'react-native'
2
+ import Animated, {
3
+ Easing,
4
+ useAnimatedStyle,
5
+ useSharedValue,
6
+ withSpring,
7
+ withTiming,
8
+ } from 'react-native-reanimated'
9
+ import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
10
+ import {useAnimatedVariantColor} from 'react-native-unistyles/reanimated'
11
+ import {useLayoutEffect, useRef, useState} from 'react'
12
+ import {SwitchTokens, SwitchStyles} from '../theme/Switch.recipe'
13
+ import {PalettesWithNestedKeys} from '../style/varia/types'
14
+
15
+ const animations = {
16
+ withSpring,
17
+ withTiming,
18
+ }
19
+
20
+ type AnimationType = 'withSpring' | 'withTiming'
21
+
22
+ type SwitchVariants = UnistylesVariants<typeof SwitchStyles>
23
+
24
+ type SwitchProps = SwitchVariants & {
25
+ colorPalette?: PalettesWithNestedKeys
26
+ value?: boolean
27
+ animation?: keyof typeof SwitchTokens.variants.animation
28
+ onValueChange?: (value: boolean) => void
29
+ flex?: number
30
+ }
31
+
32
+ const Switch = ({
33
+ colorPalette = 'accent',
34
+ value,
35
+ animation = SwitchTokens.defaultProps.animation,
36
+ onValueChange = () => {},
37
+ variant = SwitchTokens.defaultProps.variant,
38
+ size = SwitchTokens.defaultProps.size,
39
+ flex = 1,
40
+ }: SwitchProps) => {
41
+ const animatedRef = useRef(null)
42
+
43
+ SwitchStyles.useVariants({
44
+ variant,
45
+ size,
46
+ enabled: value,
47
+ })
48
+
49
+ const animationVariant =
50
+ SwitchTokens.variants?.animation && animation
51
+ ? SwitchTokens.variants.animation[animation]
52
+ : {
53
+ type: 'withSpring' as AnimationType,
54
+ props: {
55
+ damping: 15,
56
+ stiffness: 100,
57
+ mass: 1,
58
+ },
59
+ }
60
+ console.log('🚀 ~ animationVariant:', animationVariant)
61
+
62
+ const color = useAnimatedVariantColor(
63
+ SwitchStyles.container(colorPalette),
64
+ 'backgroundColor',
65
+ )
66
+ const thumbColor = useAnimatedVariantColor(
67
+ SwitchStyles.thumb(colorPalette),
68
+ 'backgroundColor',
69
+ )
70
+ const thumbEnabledPosition = useSharedValue(0)
71
+ const animatedValue = useSharedValue(0)
72
+ const containerWidth = useSharedValue(0)
73
+
74
+ useLayoutEffect(() => {
75
+ //@ts-ignore
76
+ animatedRef.current?.measure((x, y, width) => {
77
+ containerWidth.value = width
78
+ //@ts-ignore
79
+ const thumbWidth = SwitchStyles.thumb(colorPalette).width
80
+ //@ts-ignore
81
+ const padding = SwitchStyles.container(colorPalette).padding || 0
82
+ const trackBorderWidth =
83
+ //@ts-ignore
84
+ SwitchStyles.container(colorPalette).borderWidth || 0
85
+ thumbEnabledPosition.value =
86
+ width - thumbWidth - trackBorderWidth * 2 - padding * 2
87
+ })
88
+ }, [])
89
+
90
+ const animatedStyle = useAnimatedStyle(() => {
91
+ return {
92
+ backgroundColor: animations[animationVariant.type](
93
+ color.value,
94
+ animationVariant.props,
95
+ ),
96
+ // backgroundColor: withTiming(color.value, {
97
+ // duration: 100,
98
+ // easing: Easing.ease,
99
+ // }),
100
+ }
101
+ })
102
+ const thumbAnimatedStyle = useAnimatedStyle(() => {
103
+ return {
104
+ backgroundColor: animations[animationVariant.type](
105
+ thumbColor.value,
106
+ animationVariant.props,
107
+ ),
108
+ // backgroundColor: withTiming(thumbColor.value, {
109
+ // duration: 100,
110
+ // easing: Easing.ease,
111
+ // }),
112
+ }
113
+ })
114
+
115
+ const circleTranslationStyle = useAnimatedStyle(() => {
116
+ return {
117
+ transform: [
118
+ {
119
+ translateX: animatedValue.value,
120
+ },
121
+ ],
122
+ }
123
+ })
124
+
125
+ return (
126
+ <TouchableWithoutFeedback
127
+ onPress={() => {
128
+ onValueChange(!value)
129
+ animatedValue.value = animations[animationVariant.type](
130
+ animatedValue.value === 0 ? thumbEnabledPosition.value : 0,
131
+ animationVariant.props,
132
+ )
133
+ // animatedValue.value = withTiming(
134
+ // animatedValue.value === 0 ? thumbEnabledPosition.value : 0,
135
+ // {duration: 100, easing: Easing.ease},
136
+ // )
137
+ }}>
138
+ <Animated.View
139
+ ref={animatedRef}
140
+ style={[
141
+ styles.container(flex),
142
+ animatedStyle,
143
+ SwitchStyles.container(colorPalette),
144
+ ]}>
145
+ <Animated.View
146
+ style={[
147
+ styles.thumb,
148
+ SwitchStyles.thumb(colorPalette),
149
+ thumbAnimatedStyle,
150
+ circleTranslationStyle,
151
+ ]}
152
+ />
153
+ </Animated.View>
154
+ </TouchableWithoutFeedback>
155
+ )
156
+ }
157
+
158
+ export default Switch
159
+
160
+ const styles = StyleSheet.create((theme, rt) => ({
161
+ container: (flex: number) => ({
162
+ // flex,
163
+ flexGrow: flex,
164
+ flexShrink: 0,
165
+ alignSelf: 'flex-start',
166
+ flexDirection: 'row',
167
+ alignItems: 'center',
168
+ margin: 0,
169
+ borderRadius: 20,
170
+ }),
171
+ thumb: {
172
+ borderRadius: 9999,
173
+ },
174
+ }))
@@ -1,107 +1,60 @@
1
- import {Text as RNText} from 'react-native'
1
+ import {Text as RNText, TextProps as RNTextProps} from 'react-native'
2
2
  import type {StyleProp, TextStyle} from 'react-native'
3
- import {StyleSheet} from 'react-native-unistyles'
4
- import textStyles from '../theme/Text.recipe'
5
- // import { useTokens } from '../style/useTokens';
3
+ import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
4
+ import {DefaultTextVariants, TextStyles} from '../theme/Text.recipe'
5
+ import {PalettesWithNestedKeys, ThemeColors} from '../style/varia/types'
6
+ import {extractThemeColor} from '../style/varia/utils'
6
7
 
7
- export interface Props {
8
- as?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'h7' | 'h8' | 'h9' | 'body'
9
- fontSize?: number | undefined
10
- color?: string | undefined
11
- style?: TextStyle
12
- children?: React.ReactNode
13
- numberOfLines?: number
14
- adjustsFontSizeToFit?: boolean
15
- mixins?: StyleProp<TextStyle> | StyleProp<TextStyle>[]
16
- }
17
-
18
- const fontSizeDefined = (textStyles.text as any).fontSize // solo si realmente confías
19
- const variant = fontSizeDefined ? undefined : 'h1'
8
+ type TextVariants = UnistylesVariants<typeof TextStyles>
9
+ type TextProps = TextVariants &
10
+ RNTextProps & {
11
+ colorPalette?: PalettesWithNestedKeys
12
+ fontSize?: number | undefined
13
+ color?: ThemeColors
14
+ style?: TextStyle
15
+ children?: React.ReactNode
16
+ mixins?: StyleProp<TextStyle> | StyleProp<TextStyle>[]
17
+ }
20
18
 
21
- const Text: React.FC<Props> = ({
22
- as = variant,
19
+ const Text = ({
20
+ colorPalette = 'accent',
21
+ variant,
22
+ size = DefaultTextVariants.size,
23
23
  fontSize,
24
24
  color,
25
25
  style,
26
26
  children,
27
- numberOfLines,
28
- adjustsFontSizeToFit = false,
29
- // mixins,
30
- }) => {
31
- // const textTokens = useTokens('text')();
32
-
33
- styles.useVariants({
34
- as,
27
+ mixins,
28
+ ...props
29
+ }: TextProps) => {
30
+ TextStyles.useVariants({
31
+ variant,
32
+ size,
35
33
  })
36
34
 
37
35
  return (
38
36
  <RNText
39
37
  style={[
40
- textStyles.text,
38
+ TextStyles.text(colorPalette),
41
39
  styles.text(color, fontSize),
40
+ mixins && mixins,
42
41
  style,
43
- // mixins && mixins,
44
42
  ]}
45
- numberOfLines={numberOfLines !== undefined ? numberOfLines : undefined}
46
- adjustsFontSizeToFit={adjustsFontSizeToFit}>
43
+ {...props}>
47
44
  {children}
48
45
  </RNText>
49
46
  )
50
47
  }
51
48
 
52
49
  const styles = StyleSheet.create(theme => ({
53
- text: (color?: string, fontSize?: number) => {
54
- return {
55
- verticalAlign: 'bottom',
56
- textAlign: 'left',
57
- ...(color && {color: color}),
58
- ...(fontSize && {fontSize: fontSize}),
59
- variants: {
60
- as: {
61
- h1: {
62
- //@ts-ignore
63
- fontSize: fontSize || theme.fontSizes.xxl,
64
- },
65
- h2: {
66
- //@ts-ignore
67
- fontSize: fontSize || theme.fontSizes.xl,
68
- },
69
- h3: {
70
- //@ts-ignore
71
- fontSize: fontSize || theme.fontSizes.lg,
72
- },
73
- h4: {
74
- //@ts-ignore
75
- fontSize: fontSize || theme.fontSizes.md,
76
- },
77
- h5: {
78
- //@ts-ignore
79
- fontSize: fontSize || theme.fontSizes.sm,
80
- },
81
- h6: {
82
- //@ts-ignore
83
- fontSize: fontSize || theme.fontSizes.xs,
84
- },
85
- h7: {
86
- //@ts-ignore
87
- fontSize: fontSize || theme.fontSizes.xs,
88
- },
89
- h8: {
90
- //@ts-ignore
91
- fontSize: fontSize || theme.fontSizes.xxs,
92
- },
93
- h9: {
94
- //@ts-ignore
95
- fontSize: fontSize || theme.fontSizes.xxs,
96
- },
97
- body: {
98
- //@ts-ignore
99
- fontSize: fontSize || theme.fontSizes.md,
100
- },
101
- },
102
- },
103
- }
104
- },
50
+ text: (color?: string, fontSize?: number) => ({
51
+ verticalAlign: 'bottom',
52
+ textAlign: 'left',
53
+ ...(color && {
54
+ color: extractThemeColor(color, theme),
55
+ }),
56
+ ...(fontSize && {fontSize}),
57
+ }),
105
58
  }))
106
59
 
107
60
  export default Text