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.
- package/bin/cli.js +35 -18
- package/lib/components/Badge.tsx +31 -32
- package/lib/components/Button.tsx +20 -20
- package/lib/components/Checkbox.tsx +95 -0
- package/lib/components/CircleProgress.tsx +56 -66
- package/lib/components/Field.tsx +137 -0
- package/lib/components/GradientBackground.tsx +17 -18
- package/lib/components/GradientText.tsx +25 -64
- package/lib/components/IconWrapper.tsx +32 -25
- package/lib/components/Input.tsx +66 -68
- package/lib/components/Link.tsx +14 -28
- package/lib/components/Modal.tsx +197 -97
- package/lib/components/NewSelect.tsx +202 -0
- package/lib/components/NumberInput.tsx +226 -0
- package/lib/components/RadioGroup.tsx +195 -0
- package/lib/components/ReText.tsx +53 -87
- package/lib/components/Select.tsx +272 -0
- package/lib/components/SelectOld.tsx +153 -0
- package/lib/components/Slider.tsx +32 -40
- package/lib/components/Slideshow.tsx +174 -261
- package/lib/components/SlidingDrawer.tsx +216 -265
- package/lib/components/Spinner.tsx +21 -12
- package/lib/components/Switch.tsx +133 -180
- package/lib/components/Switchold.tsx +174 -0
- package/lib/components/Text.tsx +36 -83
- package/lib/components/layoutTest.tsx +74 -0
- package/lib/patterns/index.tsx +143 -202
- package/lib/theme/Badge.recipe.tsx +44 -39
- package/lib/theme/Button.recipe.tsx +139 -48
- package/lib/theme/Checkbox.recipe.tsx +121 -0
- package/lib/theme/CircleProgress.recipe.tsx +16 -22
- package/lib/theme/Field.recipe.tsx +66 -0
- package/lib/theme/GradientBackground.recipe.tsx +7 -20
- package/lib/theme/GradientText.recipe.tsx +42 -28
- package/lib/theme/IconWrapper.recipe.tsx +10 -85
- package/lib/theme/Input.recipe.tsx +76 -83
- package/lib/theme/Link.recipe.tsx +16 -43
- package/lib/theme/Modal.recipe.tsx +59 -21
- package/lib/theme/NumberInput.recipe.tsx +191 -0
- package/lib/theme/RadioGroup.recipe.tsx +163 -0
- package/lib/theme/ReText.recipe.tsx +4 -7
- package/lib/theme/Select.recipe.tsx +121 -0
- package/lib/theme/Slider.recipe.tsx +97 -181
- package/lib/theme/Slideshow.recipe.tsx +24 -102
- package/lib/theme/SlidingDrawer.recipe.tsx +21 -59
- package/lib/theme/Spinner.recipe.tsx +28 -3
- package/lib/theme/Switch.recipe.tsx +75 -54
- package/lib/theme/Text.recipe.tsx +66 -8
- package/lib/theme/animations.tsx +13 -0
- package/lib/varia/colorPalettes/amber.ts +54 -0
- package/lib/varia/colorPalettes/blue.ts +54 -0
- package/lib/varia/colorPalettes/bronze.ts +54 -0
- package/lib/varia/colorPalettes/brown.ts +54 -0
- package/lib/varia/colorPalettes/crimson.ts +55 -0
- package/lib/varia/colorPalettes/cyan.ts +54 -0
- package/lib/varia/colorPalettes/gold.ts +54 -0
- package/lib/varia/colorPalettes/grass.ts +54 -0
- package/lib/varia/colorPalettes/green.ts +54 -0
- package/lib/varia/colorPalettes/indigo.ts +54 -0
- package/lib/varia/colorPalettes/iris.ts +54 -0
- package/lib/varia/colorPalettes/jade.ts +54 -0
- package/lib/varia/colorPalettes/lime.ts +55 -0
- package/lib/varia/colorPalettes/mauve.ts +54 -0
- package/lib/varia/colorPalettes/mint.ts +54 -0
- package/lib/varia/colorPalettes/neutral.ts +54 -0
- package/lib/varia/colorPalettes/olive.ts +54 -0
- package/lib/varia/colorPalettes/orange.ts +54 -0
- package/lib/varia/colorPalettes/pink.ts +54 -0
- package/lib/varia/colorPalettes/plum.ts +54 -0
- package/lib/varia/colorPalettes/purple.ts +56 -0
- package/lib/varia/colorPalettes/red.ts +55 -0
- package/lib/varia/colorPalettes/ruby.ts +56 -0
- package/lib/varia/colorPalettes/sage.ts +56 -0
- package/lib/varia/colorPalettes/sand.ts +56 -0
- package/lib/varia/colorPalettes/sky.ts +56 -0
- package/lib/varia/colorPalettes/slate.ts +56 -0
- package/lib/varia/colorPalettes/teal.ts +56 -0
- package/lib/varia/colorPalettes/tomato.ts +56 -0
- package/lib/varia/colorPalettes/violet.ts +56 -0
- package/lib/varia/colorPalettes/yellow.ts +56 -0
- package/lib/varia/defaultTheme.ts +174 -0
- package/lib/varia/mixins.ts +223 -0
- package/lib/varia/textStyles.ts +48 -0
- package/lib/varia/types.ts +277 -0
- package/lib/varia/utils.ts +283 -0
- package/package.json +1 -1
|
@@ -1,224 +1,177 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {TouchableWithoutFeedback} from 'react-native'
|
|
2
2
|
import Animated, {
|
|
3
3
|
useAnimatedStyle,
|
|
4
|
-
interpolateColor,
|
|
5
4
|
useSharedValue,
|
|
5
|
+
withSpring,
|
|
6
6
|
withTiming,
|
|
7
|
-
|
|
8
|
-
} from 'react-native-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
const animatedRef = useRef(null);
|
|
44
|
+
const animatedRef = useRef(null)
|
|
44
45
|
|
|
45
|
-
|
|
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
|
-
|
|
53
|
-
size
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
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
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
208
|
-
) => ({
|
|
209
|
-
borderRadius: 50,
|
|
172
|
+
thumb: {
|
|
173
|
+
borderRadius: 9999,
|
|
210
174
|
justifyContent: 'center',
|
|
211
175
|
alignItems: 'center',
|
|
212
|
-
|
|
213
|
-
|
|
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
|
+
}))
|
package/lib/components/Text.tsx
CHANGED
|
@@ -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
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
22
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
38
|
+
TextStyles.text(colorPalette),
|
|
41
39
|
styles.text(color, fontSize),
|
|
40
|
+
mixins && mixins,
|
|
42
41
|
style,
|
|
43
|
-
// mixins && mixins,
|
|
44
42
|
]}
|
|
45
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|