react-native-varia 0.3.0 → 0.4.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/lib/components/Accordion.tsx +61 -21
  2. package/lib/components/Badge.tsx +9 -0
  3. package/lib/components/Button.tsx +19 -8
  4. package/lib/components/Checkbox.tsx +21 -12
  5. package/lib/components/CircleProgress.tsx +8 -0
  6. package/lib/components/Divider.tsx +6 -0
  7. package/lib/components/Drawer.tsx +16 -4
  8. package/lib/components/Field.tsx +4 -0
  9. package/lib/components/GradientBackground.tsx +3 -0
  10. package/lib/components/GradientText.tsx +27 -14
  11. package/lib/components/IconWrapper.tsx +3 -2
  12. package/lib/components/Input.tsx +47 -21
  13. package/lib/components/Link.tsx +4 -0
  14. package/lib/components/Modal.tsx +18 -5
  15. package/lib/components/NumberInput.tsx +27 -5
  16. package/lib/components/RadioGroup.tsx +16 -5
  17. package/lib/components/ReText.tsx +4 -1
  18. package/lib/components/Select.tsx +20 -0
  19. package/lib/components/Slider.tsx +59 -23
  20. package/lib/components/Slideshow.tsx +19 -3
  21. package/lib/components/Spinner.tsx +9 -3
  22. package/lib/components/Switch.tsx +57 -26
  23. package/lib/components/Text.tsx +3 -0
  24. package/lib/components/Toast.tsx +110 -36
  25. package/lib/patterns/index.tsx +299 -90
  26. package/lib/theme/Accordion.tsx +184 -0
  27. package/lib/theme/Button.recipe.tsx +24 -7
  28. package/lib/theme/Drawer.recipe.tsx +2 -4
  29. package/lib/theme/Field.recipe.tsx +45 -15
  30. package/lib/theme/GradientText.recipe.tsx +103 -34
  31. package/lib/theme/Input.recipe.tsx +14 -6
  32. package/lib/theme/Select.recipe.tsx +3 -0
  33. package/lib/theme/Slider.recipe.tsx +86 -150
  34. package/lib/theme/Spinner.recipe.tsx +4 -0
  35. package/lib/theme/Switch.recipe.tsx +19 -0
  36. package/lib/theme/Text.recipe.tsx +63 -12
  37. package/lib/theme/Toast.recipe.tsx +40 -7
  38. package/lib/varia/types.ts +3 -0
  39. package/lib/varia/utils.ts +110 -18
  40. package/package.json +1 -1
  41. package/lib/components/OldSlider.tsx +0 -327
  42. package/lib/components/SlidingDrawer.tsx +0 -301
  43. package/lib/patterns/newPatterns.tsx +0 -285
@@ -30,7 +30,11 @@ export const SwitchTokens = {
30
30
 
31
31
  export const SwitchStyles = StyleSheet.create(theme => ({
32
32
  container: (colorPalette: PalettesWithNestedKeys) => ({
33
+ // width: theme.sizes[16],
34
+ // height: theme.sizes[16],
33
35
  borderRadius: theme.radii.full,
36
+ padding: theme.spacing['0.5'],
37
+ borderWidth: 0,
34
38
  variants: {
35
39
  variant: {
36
40
  solid: {},
@@ -39,14 +43,21 @@ export const SwitchStyles = StyleSheet.create(theme => ({
39
43
  sm: {
40
44
  padding: theme.spacing['0.5'],
41
45
  maxWidth: theme.sizes[10],
46
+ minWidth: theme.sizes[10],
42
47
  },
43
48
  md: {
44
49
  padding: theme.spacing['0.5'],
45
50
  maxWidth: theme.sizes[16],
51
+ minWidth: theme.sizes[16],
46
52
  },
47
53
  lg: {
48
54
  padding: theme.spacing[1],
49
55
  maxWidth: theme.sizes[20],
56
+ minWidth: theme.sizes[20],
57
+ },
58
+ flex: {
59
+ borderRadius: theme.radii.md,
60
+ // alignSelf: 'stretch',
50
61
  },
51
62
  },
52
63
  enabled: {
@@ -70,6 +81,8 @@ export const SwitchStyles = StyleSheet.create(theme => ({
70
81
  thumb: (colorPalette: PalettesWithNestedKeys) => ({
71
82
  backgroundColor: theme.colors.bg.default,
72
83
  borderRadius: theme.radii.full,
84
+ // width: theme.sizes[6],
85
+ // height: theme.sizes[6],
73
86
  variants: {
74
87
  variant: {
75
88
  solid: {},
@@ -78,6 +91,12 @@ export const SwitchStyles = StyleSheet.create(theme => ({
78
91
  sm: {height: theme.sizes[5], width: theme.sizes[5]},
79
92
  md: {height: theme.sizes[6], width: theme.sizes[6]},
80
93
  lg: {height: theme.sizes[8], width: theme.sizes[8]},
94
+ flex: {
95
+ borderRadius: theme.radii.md,
96
+ alignSelf: 'stretch',
97
+ width: 30,
98
+ minHeight: 30,
99
+ },
81
100
  },
82
101
  },
83
102
  compoundVariants: [
@@ -11,7 +11,7 @@ export const TextStyles = StyleSheet.create(theme => ({
11
11
  variant: {
12
12
  heading: {
13
13
  color: theme.colors.fg.default,
14
- fontWeight: theme.fontWeights.semibold,
14
+ fontWeight: theme.fontWeights.bold,
15
15
  },
16
16
  default: {
17
17
  color: theme.colors.fg.default,
@@ -19,46 +19,97 @@ export const TextStyles = StyleSheet.create(theme => ({
19
19
  },
20
20
  },
21
21
  size: {
22
+ // xs: {
23
+ // ...textStyle.xs,
24
+ // // fontSize: 100
25
+ // },
26
+ // sm: {
27
+ // ...textStyle.sm,
28
+ // // fontSize: 100
29
+ // },
30
+ // md: {
31
+ // // ...textStyle.md,
32
+ // fontSize: 100
33
+ // },
34
+ // lg: {
35
+ // ...textStyle.lg,
36
+ // },
37
+ // xl: {
38
+ // ...textStyle.xl,
39
+ // },
40
+ // '2xl': {
41
+ // ...textStyle['2xl'],
42
+ // lineHeight: 32,
43
+ // },
44
+ // '3xl': {
45
+ // ...textStyle['3xl'],
46
+ // lineHeight: 38,
47
+ // },
48
+ // '4xl': {
49
+ // ...textStyle['4xl'],
50
+ // lineHeight: 44,
51
+ // letterSpacing: -0.032,
52
+ // },
53
+ // '5xl': {
54
+ // ...textStyle['5xl'],
55
+ // lineHeight: 60,
56
+ // letterSpacing: -0.032,
57
+ // },
58
+ // '6xl': {
59
+ // ...textStyle['6xl'],
60
+ // lineHeight: 72,
61
+ // letterSpacing: -0.032,
62
+ // },
63
+ // '7xl': {
64
+ // ...textStyle['7xl'],
65
+ // lineHeight: 92,
66
+ // letterSpacing: -0.032,
67
+ // },
22
68
  xs: {
23
- ...textStyle.xs,
69
+ fontSize: theme.fontSizes.xs,
70
+ lineHeight: 12,
24
71
  },
25
72
  sm: {
26
- ...textStyle.sm,
73
+ fontSize: theme.fontSizes.sm,
74
+ lineHeight: 20,
27
75
  },
28
76
  md: {
29
- ...textStyle.md,
77
+ fontSize: theme.fontSizes.md,
78
+ lineHeight: 24,
30
79
  },
31
80
  lg: {
32
- ...textStyle.lg,
81
+ fontSize: theme.fontSizes.lg,
82
+ lineHeight: 28,
33
83
  },
34
84
  xl: {
35
- ...textStyle.xl,
85
+ fontSize: theme.fontSizes.xl,
86
+ lineHeight: 30,
36
87
  },
37
88
  '2xl': {
38
- ...textStyle['2xl'],
89
+ fontSize: theme.fontSizes['2xl'],
39
90
  lineHeight: 32,
40
91
  },
41
92
  '3xl': {
42
- ...textStyle['3xl'],
93
+ fontSize: theme.fontSizes['3xl'],
43
94
  lineHeight: 38,
44
95
  },
45
96
  '4xl': {
46
- ...textStyle['4xl'],
97
+ fontSize: theme.fontSizes['4xl'],
47
98
  lineHeight: 44,
48
99
  letterSpacing: -0.032,
49
100
  },
50
101
  '5xl': {
51
- ...textStyle['5xl'],
102
+ fontSize: theme.fontSizes['5xl'],
52
103
  lineHeight: 60,
53
104
  letterSpacing: -0.032,
54
105
  },
55
106
  '6xl': {
56
- ...textStyle['6xl'],
107
+ fontSize: theme.fontSizes['6xl'],
57
108
  lineHeight: 72,
58
109
  letterSpacing: -0.032,
59
110
  },
60
111
  '7xl': {
61
- ...textStyle['7xl'],
112
+ fontSize: theme.fontSizes['7xl'],
62
113
  lineHeight: 92,
63
114
  letterSpacing: -0.032,
64
115
  },
@@ -8,7 +8,34 @@ export const ToastDefaultVariants = {
8
8
  } as const
9
9
 
10
10
  export const ToastStyles = StyleSheet.create(theme => ({
11
+ root: {
12
+ variants: {
13
+ variant: {
14
+ solid: {},
15
+ subtle: {},
16
+ outline: {},
17
+ error: {},
18
+ },
19
+ size: {
20
+ sm: {
21
+ marginVertical: theme.spacing[6],
22
+ marginHorizontal: theme.spacing[6],
23
+ },
24
+ md: {
25
+ marginVertical: theme.spacing[10],
26
+ marginHorizontal: theme.spacing[10],
27
+ },
28
+ lg: {
29
+ marginVertical: theme.spacing[12],
30
+ marginHorizontal: theme.spacing[10],
31
+ },
32
+ },
33
+ },
34
+ },
11
35
  container: (colorPalette: PalettesWithNestedKeys) => ({
36
+ borderRadius: theme.radii.md,
37
+ alignItems: 'center',
38
+ backgroundColor: theme.colors[colorPalette].default,
12
39
  variants: {
13
40
  variant: {
14
41
  solid: {
@@ -21,7 +48,8 @@ export const ToastStyles = StyleSheet.create(theme => ({
21
48
  },
22
49
  outline: {
23
50
  borderWidth: 2,
24
- borderColor: theme.colors.border.default,
51
+ backgroundColor: theme.colors.bg.subtle,
52
+ borderColor: theme.colors[colorPalette][5],
25
53
  },
26
54
  error: {
27
55
  borderColor: theme.colors.red[9],
@@ -31,13 +59,15 @@ export const ToastStyles = StyleSheet.create(theme => ({
31
59
  },
32
60
  size: {
33
61
  sm: {
34
- bottom: theme.spacing[5],
62
+ padding: theme.spacing[3],
35
63
  },
36
64
  md: {
37
- bottom: theme.spacing[5],
65
+ padding: theme.spacing[4],
66
+ alignSelf: 'stretch',
38
67
  },
39
68
  lg: {
40
- bottom: theme.spacing[8],
69
+ padding: theme.spacing[4],
70
+ alignSelf: 'stretch',
41
71
  },
42
72
  },
43
73
  },
@@ -57,13 +87,16 @@ export const ToastStyles = StyleSheet.create(theme => ({
57
87
  },
58
88
  size: {
59
89
  sm: {
60
- ...textStyle.xs,
90
+ // ...textStyle.xs,
91
+ fontSize: theme.fontSizes.xs,
61
92
  },
62
93
  md: {
63
- ...textStyle.xs,
94
+ // ...textStyle.xs,
95
+ fontSize: theme.fontSizes.xs,
64
96
  },
65
97
  lg: {
66
- ...textStyle.sm,
98
+ // ...textStyle.sm,
99
+ fontSize: theme.fontSizes.sm,
67
100
  },
68
101
  },
69
102
  },
@@ -279,6 +279,9 @@ export function createCircleProgressTokens<
279
279
 
280
280
  export type AlignSelf = ViewStyle['alignSelf']
281
281
  export type StackDirection = 'row' | 'column'
282
+ export type JustifyContent = ViewStyle['justifyContent']
283
+ export type Gap = ViewStyle['gap']
284
+ export type AlignItems = ViewStyle['alignItems']
282
285
  export type progressDirection = 'forward' | 'reverse'
283
286
  export type rotationDirection = 'clockwise' | 'counterclockwise'
284
287
  export type Flex = ViewStyle['flex']
@@ -1,4 +1,4 @@
1
- import { Platform } from 'react-native'
1
+ import {Platform} from 'react-native'
2
2
 
3
3
  type StyleObj = {
4
4
  variants?: Record<string, Record<string, Record<string, any>>>
@@ -92,29 +92,77 @@ export {
92
92
  heightFromPixel as hpx,
93
93
  }
94
94
 
95
- export const extractThemeColor = (color: ThemeColors, theme: any) => {
96
- return color.includes('.')
97
- ? (
98
- theme.colors[
99
- color.split('.')[0] as keyof typeof theme.colors
100
- ] as unknown as Record<string, string>
101
- )[color.split('.')[1]]
102
- : color in theme.colors &&
103
- typeof theme.colors[color as keyof typeof theme.colors] === 'string'
104
- ? (theme.colors[color as keyof typeof theme.colors] as string)
105
- : !(color in theme.colors)
106
- ? color
107
- : undefined
95
+ export const extractThemeColor = (
96
+ color: string,
97
+ theme: any,
98
+ ): string | undefined => {
99
+ if (color.includes('.')) {
100
+ const [paletteKey, shadeKey] = color.split('.')
101
+ const palette = theme.colors[paletteKey as keyof typeof theme.colors]
102
+ if (
103
+ palette &&
104
+ typeof palette === 'object' &&
105
+ shadeKey in (palette as Record<string, any>)
106
+ ) {
107
+ return (palette as Record<string, string>)[shadeKey]
108
+ }
109
+ // Si no existe la paleta o el shade, seguimos abajo para fallback
110
+ }
111
+
112
+ // Si el color corresponde a una clave simple en colors
113
+ if (color in theme.colors) {
114
+ const val = theme.colors[color as keyof typeof theme.colors]
115
+ if (typeof val === 'string') {
116
+ // Es un color simple → lo devolvemos
117
+ return val
118
+ } else {
119
+ // Es una paleta / objeto → devolvemos el string literal (p. ej. "pink") para fallback
120
+ return color
121
+ }
122
+ }
123
+
124
+ // Si no existe en theme.colors → asumimos que es un color CSS válido
125
+ return color
108
126
  }
109
127
 
128
+ // export const resolveColor = (
129
+ // value: string,
130
+ // colors: NestedColorsType,
131
+ // colorPalette?: string,
132
+ // ): string => {
133
+ // if (value.includes('.')) {
134
+ // const [palette, key] = value.split('.')
135
+
136
+ // if (palette === 'colorPalette' && colorPalette) {
137
+ // const paletteObj = (colors as any)[colorPalette]
138
+ // if (paletteObj && key in paletteObj) {
139
+ // return paletteObj[key]
140
+ // }
141
+ // }
142
+
143
+ // const paletteObj = (colors as any)[palette]
144
+ // if (paletteObj && key in paletteObj) {
145
+ // return paletteObj[key]
146
+ // }
147
+ // }
148
+
149
+ // if (value in colors) {
150
+ // return (colors as any)[value]
151
+ // }
152
+
153
+ // return value
154
+ // }
155
+
110
156
  export const resolveColor = (
111
157
  value: string,
112
158
  colors: NestedColorsType,
113
159
  colorPalette?: string,
114
160
  ): string => {
161
+ // Caso: value incluye punto → color anidado tipo "pink.10"
115
162
  if (value.includes('.')) {
116
163
  const [palette, key] = value.split('.')
117
164
 
165
+ // Caso especial cuando la paleta es "colorPalette"
118
166
  if (palette === 'colorPalette' && colorPalette) {
119
167
  const paletteObj = (colors as any)[colorPalette]
120
168
  if (paletteObj && key in paletteObj) {
@@ -128,10 +176,21 @@ export const resolveColor = (
128
176
  }
129
177
  }
130
178
 
179
+ // Caso: value es key simple dentro del theme
131
180
  if (value in colors) {
132
- return (colors as any)[value]
181
+ const result = (colors as any)[value]
182
+
183
+ // Si el resultado es un objeto → es una paleta, no un color
184
+ // → devolver el string original
185
+ if (typeof result === 'object' && result !== null) {
186
+ return value
187
+ }
188
+
189
+ // Si es un color simple → devolverlo
190
+ return result
133
191
  }
134
192
 
193
+ // Caso: no existe como key → asumir que es un color CSS válido
135
194
  return value
136
195
  }
137
196
 
@@ -320,12 +379,12 @@ export function computeFlexSync(
320
379
  export function getVariantValue<
321
380
  VariantGroup extends string,
322
381
  VariantValue extends string | undefined,
323
- PropName extends string
382
+ PropName extends string,
324
383
  >(
325
384
  styleObj: StyleObj,
326
385
  variantGroup: VariantGroup,
327
386
  variantValue: VariantValue,
328
- propName: PropName
387
+ propName: PropName,
329
388
  ): undefined | any {
330
389
  if (variantValue == null) {
331
390
  // Si no hay variante, devolvemos undefined
@@ -346,4 +405,37 @@ export function getVariantValue<
346
405
  } else {
347
406
  return (styleObj as any)[propName]
348
407
  }
349
- }
408
+ }
409
+
410
+ export function getCompoundVariantValue<
411
+ Conditions extends Record<string, any>,
412
+ PropName extends string,
413
+ >(
414
+ styleObj: StyleObj,
415
+ conditions: Conditions,
416
+ propName: PropName,
417
+ ): any | undefined {
418
+ if (Platform.OS !== 'web') {
419
+ // En nativo se comporta igual que los estilos planos
420
+ return (styleObj as any)[propName]
421
+ }
422
+
423
+ const compoundVariants = styleObj.compoundVariants
424
+ if (!Array.isArray(compoundVariants)) return undefined
425
+
426
+ // Buscar la variante que cumpla TODAS las condiciones
427
+ const match = compoundVariants.find(variant => {
428
+ for (const key in conditions) {
429
+ if (variant[key] !== conditions[key]) {
430
+ return false
431
+ }
432
+ }
433
+ return true
434
+ })
435
+
436
+ if (!match) return undefined
437
+
438
+ if (!match.styles) return undefined
439
+
440
+ return match.styles[propName]
441
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-varia",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },