react-native-varia 0.2.4 → 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 +21 -6
  4. package/lib/components/Checkbox.tsx +22 -8
  5. package/lib/components/CircleProgress.tsx +8 -0
  6. package/lib/components/Divider.tsx +11 -4
  7. package/lib/components/Drawer.tsx +34 -25
  8. package/lib/components/Field.tsx +4 -0
  9. package/lib/components/GradientBackground.tsx +3 -0
  10. package/lib/components/GradientText.tsx +37 -11
  11. package/lib/components/IconWrapper.tsx +3 -2
  12. package/lib/components/Input.tsx +47 -20
  13. package/lib/components/Link.tsx +4 -0
  14. package/lib/components/Modal.tsx +21 -14
  15. package/lib/components/NumberInput.tsx +27 -5
  16. package/lib/components/RadioGroup.tsx +19 -6
  17. package/lib/components/ReText.tsx +4 -1
  18. package/lib/components/Select.tsx +20 -0
  19. package/lib/components/Slider.tsx +244 -134
  20. package/lib/components/Slideshow.tsx +19 -3
  21. package/lib/components/Spinner.tsx +12 -2
  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 -79
  26. package/lib/theme/Accordion.tsx +184 -0
  27. package/lib/theme/Button.recipe.tsx +24 -7
  28. package/lib/theme/{SlidingDrawer.recipe.tsx → Drawer.recipe.tsx} +4 -6
  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 +108 -141
  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/mixins.ts +0 -4
  39. package/lib/varia/types.ts +11 -0
  40. package/lib/varia/utils.ts +172 -14
  41. package/package.json +1 -1
  42. package/lib/components/OldSlider.tsx +0 -327
  43. package/lib/components/SlidingDrawer.tsx +0 -301
@@ -10,6 +10,7 @@ export const SpinnerTokens = {
10
10
 
11
11
  export const SpinnerStyles = StyleSheet.create(theme => ({
12
12
  base: {
13
+ height: 100,
13
14
  variants: {
14
15
  size: {
15
16
  xs: {
@@ -29,5 +30,8 @@ export const SpinnerStyles = StyleSheet.create(theme => ({
29
30
  },
30
31
  },
31
32
  },
33
+ _web: {
34
+ height: 120,
35
+ },
32
36
  },
33
37
  }))
@@ -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
  },
@@ -18,9 +18,6 @@ const mixins = StyleSheet.create((theme, rt) => ({
18
18
  alignItems: 'center',
19
19
  justifyContent: 'center',
20
20
  },
21
- sx: (sx: any) => ({
22
- ...sx,
23
- }),
24
21
  w: (width: number) => ({
25
22
  width,
26
23
  }),
@@ -181,7 +178,6 @@ export const {
181
178
  row,
182
179
  gap,
183
180
  center,
184
- sx,
185
181
  flexColumn,
186
182
  w,
187
183
  h,
@@ -1,3 +1,4 @@
1
+ import {ViewStyle} from 'react-native'
1
2
  import {darkTheme, lightTheme} from '../themes'
2
3
 
3
4
  export interface AlphaPalette {
@@ -275,3 +276,13 @@ export function createCircleProgressTokens<
275
276
  }) {
276
277
  return tokens
277
278
  }
279
+
280
+ export type AlignSelf = ViewStyle['alignSelf']
281
+ export type StackDirection = 'row' | 'column'
282
+ export type JustifyContent = ViewStyle['justifyContent']
283
+ export type Gap = ViewStyle['gap']
284
+ export type AlignItems = ViewStyle['alignItems']
285
+ export type progressDirection = 'forward' | 'reverse'
286
+ export type rotationDirection = 'clockwise' | 'counterclockwise'
287
+ export type Flex = ViewStyle['flex']
288
+ export type MaxWidth = ViewStyle['maxWidth']
@@ -1,3 +1,9 @@
1
+ import {Platform} from 'react-native'
2
+
3
+ type StyleObj = {
4
+ variants?: Record<string, Record<string, Record<string, any>>>
5
+ [key: string]: any
6
+ }
1
7
  export function hexToRgba(hex: string, alpha: number = 1) {
2
8
  hex = hex.replace(/^#/, '')
3
9
 
@@ -22,6 +28,7 @@ export function hexToRgba(hex: string, alpha: number = 1) {
22
28
 
23
29
  import {Dimensions, PixelRatio} from 'react-native'
24
30
  import {
31
+ AlignSelf,
25
32
  AlphaPalette,
26
33
  ColorPalette,
27
34
  ColorPaletteBackground,
@@ -85,29 +92,77 @@ export {
85
92
  heightFromPixel as hpx,
86
93
  }
87
94
 
88
- export const extractThemeColor = (color: ThemeColors, theme: any) => {
89
- return color.includes('.')
90
- ? (
91
- theme.colors[
92
- color.split('.')[0] as keyof typeof theme.colors
93
- ] as unknown as Record<string, string>
94
- )[color.split('.')[1]]
95
- : color in theme.colors &&
96
- typeof theme.colors[color as keyof typeof theme.colors] === 'string'
97
- ? (theme.colors[color as keyof typeof theme.colors] as string)
98
- : !(color in theme.colors)
99
- ? color
100
- : 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
101
126
  }
102
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
+
103
156
  export const resolveColor = (
104
157
  value: string,
105
158
  colors: NestedColorsType,
106
159
  colorPalette?: string,
107
160
  ): string => {
161
+ // Caso: value incluye punto → color anidado tipo "pink.10"
108
162
  if (value.includes('.')) {
109
163
  const [palette, key] = value.split('.')
110
164
 
165
+ // Caso especial cuando la paleta es "colorPalette"
111
166
  if (palette === 'colorPalette' && colorPalette) {
112
167
  const paletteObj = (colors as any)[colorPalette]
113
168
  if (paletteObj && key in paletteObj) {
@@ -121,10 +176,21 @@ export const resolveColor = (
121
176
  }
122
177
  }
123
178
 
179
+ // Caso: value es key simple dentro del theme
124
180
  if (value in colors) {
125
- 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
126
191
  }
127
192
 
193
+ // Caso: no existe como key → asumir que es un color CSS válido
128
194
  return value
129
195
  }
130
196
 
@@ -281,3 +347,95 @@ export const createPreset = <T extends CreatePresetDTO>(
281
347
  }
282
348
  }
283
349
  }
350
+
351
+ export function computeFlexSync(
352
+ parentFlex: number,
353
+ parentStretch: AlignSelf,
354
+ parentDirection: 'row' | 'column',
355
+ ) {
356
+ const flex = typeof parentFlex === 'number' ? parentFlex : 0
357
+ const stretch = parentStretch === 'stretch'
358
+ const dir = parentDirection === 'row' ? 'row' : 'column'
359
+
360
+ let childFlex = flex
361
+
362
+ if (dir === 'column') {
363
+ if (flex === 0 && stretch) {
364
+ childFlex = 1
365
+ } else if (flex >= 1 && !stretch) {
366
+ childFlex = 0
367
+ } else if (flex >= 1 && stretch) {
368
+ childFlex = 1
369
+ }
370
+ } else if (dir === 'row') {
371
+ if (flex === 0 && stretch) {
372
+ childFlex = 0
373
+ }
374
+ }
375
+
376
+ return {flex: childFlex}
377
+ }
378
+
379
+ export function getVariantValue<
380
+ VariantGroup extends string,
381
+ VariantValue extends string | undefined,
382
+ PropName extends string,
383
+ >(
384
+ styleObj: StyleObj,
385
+ variantGroup: VariantGroup,
386
+ variantValue: VariantValue,
387
+ propName: PropName,
388
+ ): undefined | any {
389
+ if (variantValue == null) {
390
+ // Si no hay variante, devolvemos undefined
391
+ return undefined
392
+ }
393
+
394
+ if (Platform.OS === 'web') {
395
+ const variants = styleObj.variants
396
+ if (!variants) return undefined
397
+
398
+ const group = variants[variantGroup] as any
399
+ if (!group) return undefined
400
+
401
+ const variantStyles = group[variantValue] as any
402
+ if (!variantStyles) return undefined
403
+
404
+ return variantStyles[propName]
405
+ } else {
406
+ return (styleObj as any)[propName]
407
+ }
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.2.4",
3
+ "version": "0.4.0",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },