react-native-varia 0.2.3 → 0.3.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 (43) hide show
  1. package/bin/cli.js +24 -34
  2. package/lib/components/Accordion.tsx +113 -0
  3. package/lib/components/Button.tsx +16 -3
  4. package/lib/components/Checkbox.tsx +12 -7
  5. package/lib/components/CircleProgress.tsx +30 -21
  6. package/lib/components/Divider.tsx +23 -19
  7. package/lib/components/Drawer.tsx +23 -69
  8. package/lib/components/Field.tsx +24 -39
  9. package/lib/components/GradientBackground.tsx +25 -7
  10. package/lib/components/GradientText.tsx +61 -21
  11. package/lib/components/IconWrapper.tsx +20 -14
  12. package/lib/components/Input.tsx +107 -25
  13. package/lib/components/Modal.tsx +4 -10
  14. package/lib/components/NumberInput.tsx +54 -11
  15. package/lib/components/OldSlider.tsx +327 -0
  16. package/lib/components/RadioGroup.tsx +58 -18
  17. package/lib/components/ReText.tsx +1 -1
  18. package/lib/components/Select.tsx +58 -22
  19. package/lib/components/Slider.tsx +273 -138
  20. package/lib/components/Slideshow.tsx +65 -63
  21. package/lib/components/SlidingDrawer.tsx +20 -21
  22. package/lib/components/Spinner.tsx +13 -5
  23. package/lib/components/Toast.tsx +89 -0
  24. package/lib/components/context/Field.tsx +27 -0
  25. package/lib/patterns/index.tsx +16 -5
  26. package/lib/patterns/newPatterns.tsx +285 -0
  27. package/lib/theme/Button.recipe.tsx +11 -1
  28. package/lib/theme/CircleProgress.recipe.tsx +3 -3
  29. package/lib/theme/Drawer.recipe.tsx +107 -0
  30. package/lib/theme/Field.recipe.tsx +17 -2
  31. package/lib/theme/Input.recipe.tsx +12 -3
  32. package/lib/theme/NumberInput.recipe.tsx +8 -3
  33. package/lib/theme/RadioGroup.recipe.tsx +7 -1
  34. package/lib/theme/Select.recipe.tsx +7 -7
  35. package/lib/theme/Slider.recipe.tsx +402 -27
  36. package/lib/theme/Slideshow.recipe.tsx +1 -1
  37. package/lib/theme/Toast.recipe.tsx +71 -0
  38. package/lib/varia/mixins.ts +0 -4
  39. package/lib/varia/types.ts +8 -0
  40. package/lib/varia/utils.ts +66 -0
  41. package/package.json +1 -1
  42. package/lib/theme/Button.recipe-old.tsx +0 -67
  43. package/lib/theme/SlidingDrawer.recipe.tsx +0 -53
@@ -16,11 +16,8 @@ import Animated, {
16
16
  withSpring,
17
17
  withTiming,
18
18
  } from 'react-native-reanimated'
19
- import {runOnUI, scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
20
- import {
21
- SlidingDrawerTokens,
22
- SlidingDrawerStyles,
23
- } from '../theme/SlidingDrawer.recipe'
19
+ import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
20
+ import {DrawerTokens, DrawerStyles} from '../theme/Drawer.recipe'
24
21
  import {PalettesWithNestedKeys} from '../style/varia/types'
25
22
  import {
26
23
  StyleSheet,
@@ -33,21 +30,21 @@ import {HStack} from '../patterns'
33
30
  * Types
34
31
  * ----------------------------*/
35
32
 
36
- export type SlidingDrawerRef = {
33
+ export type DrawerRef = {
37
34
  expand: () => void | null
38
35
  collapse: () => void | null
39
36
  snapTo: (point: number) => void | null
40
37
  isCollapsed: () => boolean
41
38
  }
42
39
 
43
- type SlidingDrawerVariants = UnistylesVariants<typeof SlidingDrawerStyles>
40
+ type DrawerVariants = UnistylesVariants<typeof DrawerStyles>
44
41
 
45
- type DrawerContextType = SlidingDrawerVariants & {
42
+ type DrawerContextType = DrawerVariants & {
46
43
  colorPalette: PalettesWithNestedKeys
47
44
  overlayOpacity: SharedValue<number>
48
45
  }
49
46
 
50
- type DrawerRootProps = SlidingDrawerVariants & {
47
+ type DrawerRootProps = DrawerVariants & {
51
48
  colorPalette?: PalettesWithNestedKeys
52
49
  children?: React.ReactNode
53
50
  }
@@ -70,10 +67,10 @@ const useDrawer = () => {
70
67
 
71
68
  const DrawerRoot = ({
72
69
  colorPalette = 'accent',
73
- variant = SlidingDrawerTokens.defaultProps.variant,
70
+ variant = DrawerTokens.defaultProps.variant,
74
71
  children,
75
72
  }: DrawerRootProps) => {
76
- SlidingDrawerStyles.useVariants({variant})
73
+ DrawerStyles.useVariants({variant})
77
74
 
78
75
  const overlayOpacity = useSharedValue(0)
79
76
  const value = useMemo(
@@ -103,7 +100,7 @@ const DrawerPositioner = ({
103
100
  axis: 'x' | 'y'
104
101
  }) => {
105
102
  const {variant} = useDrawer()
106
- SlidingDrawerStyles.useVariants({variant})
103
+ DrawerStyles.useVariants({variant})
107
104
 
108
105
  type WithDirection = {direction?: 1 | -1; axis?: 'x' | 'y'}
109
106
 
@@ -121,7 +118,7 @@ const DrawerPositioner = ({
121
118
  <HStack
122
119
  style={[
123
120
  styles.positioner,
124
- SlidingDrawerStyles.positioner,
121
+ DrawerStyles.positioner,
125
122
  {
126
123
  justifyContent:
127
124
  axis === 'y'
@@ -151,7 +148,7 @@ const AnimatedTouchable = Animated.createAnimatedComponent(
151
148
 
152
149
  const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
153
150
  const {colorPalette, overlayOpacity, variant} = useDrawer()
154
- SlidingDrawerStyles.useVariants({variant})
151
+ DrawerStyles.useVariants({variant})
155
152
  const visible = useSharedValue(0)
156
153
 
157
154
  useAnimatedReaction(
@@ -176,7 +173,7 @@ const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
176
173
  style={[
177
174
  StyleSheet.absoluteFillObject,
178
175
  displayOverlayStyle,
179
- SlidingDrawerStyles.overlay(colorPalette),
176
+ DrawerStyles.overlay(colorPalette),
180
177
  ]}
181
178
  />
182
179
  </AnimatedTouchable>
@@ -192,17 +189,16 @@ type InternalDrawerSliderProps = {
192
189
  direction: 1 | -1
193
190
  lockAtEdges?: boolean
194
191
  snapPoints?: number[] | ('hidden' | 'content')[]
195
- animation?: keyof typeof SlidingDrawerTokens.variants.animation
192
+ animation?: keyof typeof DrawerTokens.variants.animation
196
193
  onExpand?: () => void
197
194
  onCollapse?: () => void
198
195
  onSnap?: (point: number) => void
199
196
  allowGestures?: boolean
200
197
  children?: React.ReactNode
201
- ref?: React.RefObject<SlidingDrawerRef | null>
198
+ ref?: React.RefObject<DrawerRef | null>
202
199
  externalTranslate?: SharedValue<number>
203
200
  }
204
201
 
205
- // Tipo público — el que exportas (sin direction)
206
202
  export type DrawerSliderProps = Omit<
207
203
  InternalDrawerSliderProps,
208
204
  'direction' | 'axis'
@@ -217,7 +213,7 @@ const DrawerSliderInternal = ({
217
213
  direction,
218
214
  lockAtEdges = false,
219
215
  snapPoints = ['hidden', 'content'],
220
- animation = SlidingDrawerTokens.defaultProps.animation,
216
+ animation = DrawerTokens.defaultProps.animation,
221
217
  onExpand,
222
218
  onCollapse,
223
219
  onSnap,
@@ -228,17 +224,16 @@ const DrawerSliderInternal = ({
228
224
  }: InternalDrawerSliderProps) => {
229
225
  const {variant, colorPalette, overlayOpacity} = useDrawer()
230
226
 
231
- SlidingDrawerStyles.useVariants({variant})
227
+ DrawerStyles.useVariants({variant})
232
228
 
233
229
  const screenHeight =
234
230
  UnistylesRuntime.screen.height - UnistylesRuntime.insets.top
235
231
  const screenWidth = UnistylesRuntime.screen.width
236
232
 
237
233
  const animations = {withSpring, withTiming}
238
- const animationVariant = SlidingDrawerTokens.variants.animation[animation]
234
+ const animationVariant = DrawerTokens.variants.animation[animation]
239
235
  const VELOCITY_THRESHOLD = 2000
240
236
 
241
- // --- shared values base ---
242
237
  const viewRef = useAnimatedRef<Animated.View>()
243
238
  const translate = useSharedValue(screenHeight)
244
239
  const context = useSharedValue({position: screenHeight, snapPoint: 0})
@@ -254,37 +249,7 @@ const DrawerSliderInternal = ({
254
249
  )
255
250
  }
256
251
 
257
- // --- medir el contenido dinámicamente ---
258
- // const onLayout = () => {
259
- // scheduleOnUI(() => {
260
- // 'worklet'
261
- // const measured = measure(viewRef)
262
- // if (measured) {
263
- // const {height} = measured
264
- // contentHeight.value = height
265
-
266
- // // resuelve snapPoints declarativos
267
- // const resolved = snapPoints.map(p => {
268
- // if (p === 'hidden') return screenHeight * direction
269
- // if (p === 'content') return (screenHeight - height) * direction
270
- // // if (typeof p === 'string' && p.endsWith('%')) {
271
- // // const percentage = parseFloat(p) / 100
272
- // // return screenHeight * (1 - percentage) * direction
273
- // // }
274
- // return p * direction
275
- // })
276
-
277
- // resolvedSnapPoints.value = resolved
278
-
279
- // // inicializa la posición (oculto)
280
- // translate.value = resolved[0]
281
- // context.value = {position: resolved[0], snapPoint: 0}
282
- // }
283
- // })
284
- // }
285
-
286
252
  const onLayout = () => {
287
- // captura valores aquí (en JS)
288
253
  const _screenHeight = screenHeight
289
254
  const _screenWidth = screenWidth
290
255
  const _axis = axis
@@ -316,10 +281,13 @@ const DrawerSliderInternal = ({
316
281
  'worklet'
317
282
  return resolvedSnapPoints.value.length > 0
318
283
  ? resolvedSnapPoints.value
319
- : snapPoints.map(p => (p as any) * direction)
284
+ : snapPoints.map(p => {
285
+ // if (p === 'hidden') return screenHeight * direction
286
+ // if (p === 'content') return (screenHeight - contentHeight.value) * direction
287
+ return (p as number) * direction
288
+ })
320
289
  }
321
290
 
322
- // --- lógica de snapping ---
323
291
  const updateCurrentSnapPoint = (snapPoint: number) => {
324
292
  'worklet'
325
293
  context.value = {position: context.value.position, snapPoint}
@@ -374,7 +342,6 @@ const DrawerSliderInternal = ({
374
342
  isCollapsed,
375
343
  }))
376
344
 
377
- // --- sincronizar overlay con movimiento ---
378
345
  useAnimatedReaction(
379
346
  () => translate.value,
380
347
  value => {
@@ -392,7 +359,6 @@ const DrawerSliderInternal = ({
392
359
  },
393
360
  )
394
361
 
395
- // --- Gestures ---
396
362
  const slideGesture = Gesture.Pan()
397
363
  .enabled(allowGestures)
398
364
  .onBegin(() => {
@@ -408,16 +374,13 @@ const DrawerSliderInternal = ({
408
374
 
409
375
  if (proposed < minPoint) {
410
376
  if (lockAtEdges) {
411
- // Bloquea overscroll superior (cuando ya estás en el extremo)
412
377
  clamped = minPoint
413
378
  } else {
414
- // Aplica resistencia
415
379
  const overdrag = minPoint - proposed
416
380
  clamped = minPoint - overdrag / (1 + overdrag / 60)
417
381
  }
418
382
  } else if (proposed > maxPoint) {
419
383
  if (lockAtEdges) {
420
- // Bloquea overscroll inferior
421
384
  clamped = maxPoint
422
385
  } else {
423
386
  const overdrag = proposed - maxPoint
@@ -477,7 +440,6 @@ const DrawerSliderInternal = ({
477
440
  }
478
441
  })
479
442
 
480
- // --- estilos animados ---
481
443
  const blockAnimatedStyle = useAnimatedStyle(() => {
482
444
  return {
483
445
  transform: [
@@ -496,7 +458,7 @@ const DrawerSliderInternal = ({
496
458
  style={[
497
459
  styles.slider,
498
460
  blockAnimatedStyle,
499
- SlidingDrawerStyles.slider(colorPalette),
461
+ DrawerStyles.slider(colorPalette),
500
462
  ]}>
501
463
  {children}
502
464
  </Animated.View>
@@ -504,10 +466,6 @@ const DrawerSliderInternal = ({
504
466
  )
505
467
  }
506
468
 
507
- /* -----------------------------
508
- * Export grouped
509
- * ----------------------------*/
510
-
511
469
  export const Drawer = {
512
470
  Root: DrawerRoot,
513
471
  Positioner: DrawerPositioner,
@@ -515,10 +473,6 @@ export const Drawer = {
515
473
  Slider: DrawerSlider,
516
474
  }
517
475
 
518
- /* -----------------------------
519
- * Styles
520
- * ----------------------------*/
521
-
522
476
  const styles = StyleSheet.create((theme, rt) => ({
523
477
  positioner: {
524
478
  flex: 1,
@@ -1,36 +1,21 @@
1
- import React, {createContext, useContext} from 'react'
2
- import {UnistylesVariants} from 'react-native-unistyles'
1
+ import React from 'react'
3
2
  import Text from './Text'
4
- import {VStack} from '../patterns'
5
3
  import {DefaultFieldVariants, FieldStyles} from '../theme/Field.recipe'
6
- import {PalettesWithNestedKeys} from '../style/varia/types'
7
-
8
- type FieldVariants = UnistylesVariants<typeof FieldStyles>
9
-
10
- type FieldContextType = {
11
- error?: string
12
- variant?: FieldVariants['variant']
13
- size?: FieldVariants['size']
14
- colorPalette?: PalettesWithNestedKeys
15
- }
16
-
17
- const FieldContext = createContext<FieldContextType | undefined>(undefined)
18
-
19
- function useField() {
20
- const context = useContext(FieldContext)
21
- if (!context) {
22
- throw new Error(
23
- 'Field subcomponents (Label, Error) must be used inside Field.Root',
24
- )
25
- }
26
- return context
27
- }
4
+ import {Flex, PalettesWithNestedKeys} from '../style/varia/types'
5
+ import FieldContext, {
6
+ FieldContextType,
7
+ FieldVariants,
8
+ useField,
9
+ } from './context/Field'
10
+ import {StyleProp, View, ViewStyle} from 'react-native'
11
+ import {StyleSheet} from 'react-native-unistyles'
28
12
 
29
13
  type FieldRootProps = FieldVariants & {
30
14
  children: React.ReactNode
31
15
  error?: string
32
16
  colorPalette?: PalettesWithNestedKeys
33
17
  flex?: number
18
+ style?: StyleProp<ViewStyle>
34
19
  }
35
20
 
36
21
  const FieldRoot = ({
@@ -39,7 +24,8 @@ const FieldRoot = ({
39
24
  variant = DefaultFieldVariants.variant,
40
25
  size = DefaultFieldVariants.size,
41
26
  colorPalette = 'accent',
42
- flex = 1,
27
+ flex = 0,
28
+ style,
43
29
  }: FieldRootProps) => {
44
30
  FieldStyles.useVariants({size})
45
31
 
@@ -53,20 +39,16 @@ const FieldRoot = ({
53
39
  FieldStyles.useVariants({variant, size})
54
40
 
55
41
  return (
56
- <VStack
42
+ <View
57
43
  style={[
58
- {
59
- flexShrink: 1,
60
- flexGrow: flex,
61
- alignItems: 'stretch',
62
- alignSelf: 'stretch',
63
- },
44
+ styles.root(flex),
64
45
  FieldStyles.root(colorPalette),
46
+ style && style,
65
47
  ]}>
66
48
  <FieldContext.Provider value={contextValue}>
67
49
  {children}
68
50
  </FieldContext.Provider>
69
- </VStack>
51
+ </View>
70
52
  )
71
53
  }
72
54
 
@@ -89,11 +71,7 @@ const FieldLabel = ({children, ...props}: FieldLabelProps) => {
89
71
 
90
72
  FieldStyles.useVariants({variant, size})
91
73
 
92
- return (
93
- <Text size={size} color={FieldStyles.label(colorPalette).color}>
94
- {children}
95
- </Text>
96
- )
74
+ return <Text style={FieldStyles.label(colorPalette)}>{children}</Text>
97
75
  }
98
76
 
99
77
  type FieldErrorProps = {
@@ -124,6 +102,13 @@ const FieldError = ({...props}: FieldErrorProps) => {
124
102
  )
125
103
  }
126
104
 
105
+ const styles = StyleSheet.create({
106
+ root: (flex: Flex) => ({
107
+ flex,
108
+ flexDirection: 'column',
109
+ }),
110
+ })
111
+
127
112
  export const Field = Object.assign(FieldRoot, {
128
113
  Root: FieldRoot,
129
114
  Label: FieldLabel,
@@ -1,16 +1,23 @@
1
- import {View, StyleSheet, StyleProp, ViewStyle} from 'react-native'
1
+ import {View, StyleProp, ViewStyle} from 'react-native'
2
2
  import Svg, {Defs, LinearGradient, Stop, Rect} from 'react-native-svg'
3
3
  import {withUnistyles} from 'react-native-unistyles'
4
4
  import {gradientBackgroundTokens} from '../theme/GradientBackground.recipe'
5
- import {PalettesWithNestedKeys} from '../style/varia/types'
5
+ import {
6
+ NestedColorsType,
7
+ PalettesWithNestedKeys,
8
+ ThemeColors,
9
+ } from '../style/varia/types'
6
10
  import {resolveColor} from '../style/varia/utils'
11
+ import {StyleSheet} from 'react-native-unistyles'
7
12
 
8
13
  interface GradientBackgroundProps {
9
14
  colorPalette?: PalettesWithNestedKeys
10
15
  variant?: keyof typeof gradientBackgroundTokens.variants.variant
11
16
  direction?: keyof typeof gradientBackgroundTokens.variants.direction
12
17
  containerStyles?: StyleProp<ViewStyle>
13
- colors: any
18
+ colors: NestedColorsType
19
+ startColor?: ThemeColors
20
+ endColor?: ThemeColors
14
21
  }
15
22
 
16
23
  const BaseGradientBackground = ({
@@ -19,10 +26,20 @@ const BaseGradientBackground = ({
19
26
  direction = gradientBackgroundTokens.defaultProps.direction,
20
27
  containerStyles,
21
28
  colors,
29
+ startColor,
30
+ endColor,
22
31
  }: GradientBackgroundProps) => {
23
32
  const colorValue = gradientBackgroundTokens.variants.variant[variant]
24
- const startColor = resolveColor(colorValue.startColor, colors, colorPalette)
25
- const endColor = resolveColor(colorValue.endColor, colors, colorPalette)
33
+ const resolvedStartColor = resolveColor(
34
+ startColor || colorValue.startColor,
35
+ colors,
36
+ colorPalette,
37
+ )
38
+ const resolvedEndColor = resolveColor(
39
+ endColor || colorValue.endColor,
40
+ colors,
41
+ colorPalette,
42
+ )
26
43
 
27
44
  const directionVariant =
28
45
  gradientBackgroundTokens.variants.direction[direction]
@@ -41,8 +58,8 @@ const BaseGradientBackground = ({
41
58
  y1={directionVariant?.y1}
42
59
  x2={directionVariant?.x2}
43
60
  y2={directionVariant?.y2}>
44
- <Stop offset="0%" stopColor={startColor} stopOpacity="1" />
45
- <Stop offset="100%" stopColor={endColor} stopOpacity="1" />
61
+ <Stop offset="0%" stopColor={resolvedStartColor} stopOpacity="1" />
62
+ <Stop offset="100%" stopColor={resolvedEndColor} stopOpacity="1" />
46
63
  </LinearGradient>
47
64
  </Defs>
48
65
  <Rect width="100" height="100" fill="url(#grad)" />
@@ -54,6 +71,7 @@ const BaseGradientBackground = ({
54
71
  const styles = StyleSheet.create({
55
72
  container: {
56
73
  ...StyleSheet.absoluteFillObject,
74
+ alignSelf: 'stretch',
57
75
  borderWidth: 0,
58
76
  overflow: 'hidden',
59
77
  borderColor: 'transparent',
@@ -1,4 +1,4 @@
1
- import {View, type ColorValue} from 'react-native'
1
+ import {StyleSheet, TextStyle, View, type ColorValue} from 'react-native'
2
2
  import Svg, {
3
3
  Defs,
4
4
  LinearGradient,
@@ -6,20 +6,31 @@ import Svg, {
6
6
  Text,
7
7
  type NumberProp,
8
8
  } from 'react-native-svg'
9
- import {withUnistyles} from 'react-native-unistyles'
9
+ import {UnistylesVariants, withUnistyles} from 'react-native-unistyles'
10
10
  import {gradientTextTokens} from '../theme/GradientText.recipe'
11
- import {PalettesWithNestedKeys} from '../style/varia/types'
12
- import {resolveColor, resolveFontSize} from '../style/varia/utils'
11
+ import {
12
+ NestedColorsType,
13
+ PalettesWithNestedKeys,
14
+ ThemeType,
15
+ } from '../style/varia/types'
16
+ import {getVariantValue, resolveColor, resolveFontSize} from '../style/varia/utils'
17
+ import {ThemeColors} from '../style/varia/types'
18
+ import { TextStyles } from '../theme/Text.recipe'
13
19
 
14
- interface GradientTextProps {
20
+ type AllTextVariants = UnistylesVariants<typeof TextStyles>
21
+ type TextVariantsWithoutVariant = Omit<AllTextVariants, "variant">;
22
+
23
+ type GradientTextProps = TextVariantsWithoutVariant & {
15
24
  colorPalette: PalettesWithNestedKeys
16
25
  variant?: keyof typeof gradientTextTokens.variants.variant
17
26
  direction?: keyof typeof gradientTextTokens.variants.direction
18
- colors: any
19
- fontSizes: any
20
- fontSize?: number | undefined
27
+ colors: NestedColorsType
28
+ startColor?: ThemeColors
29
+ endColor?: ThemeColors
30
+ fontSizes: ThemeType['fontSizes']
31
+ fontSize?: TextStyle['fontSize']
21
32
  children?: React.ReactNode
22
- size?: keyof typeof gradientTextTokens.variants.size
33
+ // size?: keyof typeof gradientTextTokens.variants.size
23
34
  }
24
35
 
25
36
  const BaseGradientText = ({
@@ -28,22 +39,41 @@ const BaseGradientText = ({
28
39
  colorPalette = 'accent',
29
40
  direction = gradientTextTokens.defaultProps.direction,
30
41
  colors,
42
+ startColor,
43
+ endColor,
31
44
  fontSizes,
32
45
  children,
33
46
  size = gradientTextTokens.defaultProps.size,
34
47
  }: GradientTextProps) => {
48
+ TextStyles.useVariants({
49
+ size
50
+ })
51
+
35
52
  const colorValue = gradientTextTokens.variants.variant[variant]
36
- const startColor = resolveColor(colorValue.startColor, colors, colorPalette)
37
- const endColor = resolveColor(colorValue.endColor, colors, colorPalette)
38
53
 
39
- const fontSizeValue = gradientTextTokens.variants.size[size].fontSize
40
- const resolvedFontSize = fontSize || resolveFontSize(fontSizeValue, fontSizes)
54
+ const resolvedStartColor = resolveColor(
55
+ startColor || colorValue.startColor,
56
+ colors,
57
+ colorPalette,
58
+ )
59
+ const resolvedEndColor = resolveColor(
60
+ endColor || colorValue.endColor,
61
+ colors,
62
+ colorPalette,
63
+ )
64
+
65
+ // const fontSizeValue = gradientTextTokens.variants.size[size].fontSize
66
+ // const resolvedFontSize = fontSize || resolveFontSize(fontSizeValue, fontSizes)
67
+
68
+ const resolvedFontSize = fontSize || getVariantValue(TextStyles.text(colorPalette), 'size', size, 'fontSize')
69
+ const resolvedFontWeight = getVariantValue(TextStyles.text(colorPalette), 'size', size, 'fontWeight') || 400
70
+
41
71
 
42
72
  const directionVariant = gradientTextTokens.variants.direction[direction]
43
73
 
44
74
  return (
45
- <View style={{flexDirection: 'row'}}>
46
- <View style={{width: '100%'}}>
75
+ <View style={styles.root}>
76
+ <View style={styles.innerContainer}>
47
77
  <Svg height={resolvedFontSize + 20} width="100%">
48
78
  <Defs>
49
79
  <LinearGradient
@@ -52,17 +82,18 @@ const BaseGradientText = ({
52
82
  y1={directionVariant?.y1 as NumberProp}
53
83
  x2={directionVariant?.x2 as NumberProp}
54
84
  y2={directionVariant?.y2 as NumberProp}>
55
- <Stop offset="0%" stopColor={startColor as ColorValue} />
56
- <Stop offset="100%" stopColor={endColor as ColorValue} />
85
+ <Stop offset="0%" stopColor={resolvedStartColor as ColorValue} />
86
+ <Stop offset="100%" stopColor={resolvedEndColor as ColorValue} />
57
87
  </LinearGradient>
58
88
  </Defs>
59
89
  <Text
60
90
  fill="url(#gradient)"
61
91
  fontSize={resolvedFontSize}
62
- fontWeight={
63
- (gradientTextTokens.variants.size[size] as {fontWeight?: number})
64
- .fontWeight ?? 400
65
- }
92
+ // fontWeight={
93
+ // (gradientTextTokens.variants.size[size] as {fontWeight?: number})
94
+ // .fontWeight ?? 400
95
+ // }
96
+ fontWeight={resolvedFontWeight}
66
97
  x="50%"
67
98
  y={resolvedFontSize}
68
99
  textAnchor="middle">
@@ -74,6 +105,15 @@ const BaseGradientText = ({
74
105
  )
75
106
  }
76
107
 
108
+ const styles = StyleSheet.create({
109
+ root: {
110
+ flexDirection: 'row',
111
+ },
112
+ innerContainer: {
113
+ width: '100%',
114
+ },
115
+ })
116
+
77
117
  const GradientText = withUnistyles(BaseGradientText, theme => ({
78
118
  colors: theme.colors,
79
119
  fontSizes: theme.fontSizes,
@@ -7,20 +7,20 @@ import {
7
7
  type ReactNode,
8
8
  } from 'react'
9
9
  import Svg from 'react-native-svg'
10
- import {View} from 'react-native'
11
- import {withUnistyles} from 'react-native-unistyles'
10
+ import {StyleProp, View, ViewStyle} from 'react-native'
11
+ import {StyleSheet, withUnistyles} from 'react-native-unistyles'
12
12
  import {IconTokens} from '../theme/IconWrapper.recipe'
13
13
  import {
14
14
  NestedColorsType,
15
15
  PalettesWithNestedKeys,
16
16
  ThemeColors,
17
+ ThemeType,
17
18
  } from '../style/varia/types'
18
19
  import {resolveColor} from '../style/varia/utils'
19
20
 
20
21
  interface SVGChildProps {
21
22
  color?: string
22
23
  }
23
-
24
24
  export type IconWrapperProps = {
25
25
  variant?: keyof typeof IconTokens.variants.variant
26
26
  size?: number
@@ -30,7 +30,8 @@ export type IconWrapperProps = {
30
30
  scale?: number
31
31
  color?: ThemeColors
32
32
  rotation?: number
33
- colors?: any
33
+ colors?: NestedColorsType
34
+ style?: StyleProp<ViewStyle>
34
35
  }
35
36
 
36
37
  /**
@@ -50,12 +51,13 @@ const Icon = ({
50
51
  color,
51
52
  rotation,
52
53
  colors,
54
+ style,
53
55
  ...rest
54
56
  }: IconWrapperProps) => {
55
57
  const colorValue = IconTokens.variants.variant[variant].color
56
58
  const resolvedColor = color
57
- ? resolveColor(color, colors, colorPalette)
58
- : resolveColor(colorValue, colors, colorPalette)
59
+ ? resolveColor(color, colors as NestedColorsType, colorPalette)
60
+ : resolveColor(colorValue, colors as NestedColorsType, colorPalette)
59
61
 
60
62
  const width = IconTokens.variants.sizeVariant[sizeVariant].width ?? 0
61
63
  const height = IconTokens.variants.sizeVariant[sizeVariant].height ?? 0
@@ -63,14 +65,7 @@ const Icon = ({
63
65
  // const viewBoxHeight = IconTokens.variants.size[size].viewBoxHeight ?? 0
64
66
 
65
67
  return (
66
- <View
67
- style={{
68
- width: size || width,
69
- height: size || height,
70
- justifyContent: 'center',
71
- alignItems: 'center',
72
- transform: rotation ? [{rotate: `${rotation}deg`}] : [],
73
- }}>
68
+ <View style={[styles.root(size, width, height, rotation), style]}>
74
69
  <Svg
75
70
  width={size || width}
76
71
  height={size || height}
@@ -105,6 +100,17 @@ const Icon = ({
105
100
 
106
101
  export default Icon
107
102
 
103
+ const styles = StyleSheet.create({
104
+ root: (size, width, height, rotation) => ({
105
+ width: size || width,
106
+ height: size || height,
107
+ justifyContent: 'center',
108
+ alignItems: 'center',
109
+ ...(rotation && {transform: [{rotate: `${rotation}deg`}]}),
110
+ // transform: rotation ? [{rotate: `${rotation}deg`}] : [],
111
+ }),
112
+ })
113
+
108
114
  export const ThemedIcon = withUnistyles(Icon, theme => ({
109
115
  colors: theme.colors,
110
116
  }))