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.
- package/bin/cli.js +24 -34
- package/lib/components/Accordion.tsx +113 -0
- package/lib/components/Button.tsx +16 -3
- package/lib/components/Checkbox.tsx +12 -7
- package/lib/components/CircleProgress.tsx +30 -21
- package/lib/components/Divider.tsx +23 -19
- package/lib/components/Drawer.tsx +23 -69
- package/lib/components/Field.tsx +24 -39
- package/lib/components/GradientBackground.tsx +25 -7
- package/lib/components/GradientText.tsx +61 -21
- package/lib/components/IconWrapper.tsx +20 -14
- package/lib/components/Input.tsx +107 -25
- package/lib/components/Modal.tsx +4 -10
- package/lib/components/NumberInput.tsx +54 -11
- package/lib/components/OldSlider.tsx +327 -0
- package/lib/components/RadioGroup.tsx +58 -18
- package/lib/components/ReText.tsx +1 -1
- package/lib/components/Select.tsx +58 -22
- package/lib/components/Slider.tsx +273 -138
- package/lib/components/Slideshow.tsx +65 -63
- package/lib/components/SlidingDrawer.tsx +20 -21
- package/lib/components/Spinner.tsx +13 -5
- package/lib/components/Toast.tsx +89 -0
- package/lib/components/context/Field.tsx +27 -0
- package/lib/patterns/index.tsx +16 -5
- package/lib/patterns/newPatterns.tsx +285 -0
- package/lib/theme/Button.recipe.tsx +11 -1
- package/lib/theme/CircleProgress.recipe.tsx +3 -3
- package/lib/theme/Drawer.recipe.tsx +107 -0
- package/lib/theme/Field.recipe.tsx +17 -2
- package/lib/theme/Input.recipe.tsx +12 -3
- package/lib/theme/NumberInput.recipe.tsx +8 -3
- package/lib/theme/RadioGroup.recipe.tsx +7 -1
- package/lib/theme/Select.recipe.tsx +7 -7
- package/lib/theme/Slider.recipe.tsx +402 -27
- package/lib/theme/Slideshow.recipe.tsx +1 -1
- package/lib/theme/Toast.recipe.tsx +71 -0
- package/lib/varia/mixins.ts +0 -4
- package/lib/varia/types.ts +8 -0
- package/lib/varia/utils.ts +66 -0
- package/package.json +1 -1
- package/lib/theme/Button.recipe-old.tsx +0 -67
- package/lib/theme/SlidingDrawer.recipe.tsx +0 -53
package/lib/varia/utils.ts
CHANGED
|
@@ -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,
|
|
@@ -281,3 +288,62 @@ export const createPreset = <T extends CreatePresetDTO>(
|
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
290
|
}
|
|
291
|
+
|
|
292
|
+
export function computeFlexSync(
|
|
293
|
+
parentFlex: number,
|
|
294
|
+
parentStretch: AlignSelf,
|
|
295
|
+
parentDirection: 'row' | 'column',
|
|
296
|
+
) {
|
|
297
|
+
const flex = typeof parentFlex === 'number' ? parentFlex : 0
|
|
298
|
+
const stretch = parentStretch === 'stretch'
|
|
299
|
+
const dir = parentDirection === 'row' ? 'row' : 'column'
|
|
300
|
+
|
|
301
|
+
let childFlex = flex
|
|
302
|
+
|
|
303
|
+
if (dir === 'column') {
|
|
304
|
+
if (flex === 0 && stretch) {
|
|
305
|
+
childFlex = 1
|
|
306
|
+
} else if (flex >= 1 && !stretch) {
|
|
307
|
+
childFlex = 0
|
|
308
|
+
} else if (flex >= 1 && stretch) {
|
|
309
|
+
childFlex = 1
|
|
310
|
+
}
|
|
311
|
+
} else if (dir === 'row') {
|
|
312
|
+
if (flex === 0 && stretch) {
|
|
313
|
+
childFlex = 0
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return {flex: childFlex}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export function getVariantValue<
|
|
321
|
+
VariantGroup extends string,
|
|
322
|
+
VariantValue extends string | undefined,
|
|
323
|
+
PropName extends string
|
|
324
|
+
>(
|
|
325
|
+
styleObj: StyleObj,
|
|
326
|
+
variantGroup: VariantGroup,
|
|
327
|
+
variantValue: VariantValue,
|
|
328
|
+
propName: PropName
|
|
329
|
+
): undefined | any {
|
|
330
|
+
if (variantValue == null) {
|
|
331
|
+
// Si no hay variante, devolvemos undefined
|
|
332
|
+
return undefined
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (Platform.OS === 'web') {
|
|
336
|
+
const variants = styleObj.variants
|
|
337
|
+
if (!variants) return undefined
|
|
338
|
+
|
|
339
|
+
const group = variants[variantGroup] as any
|
|
340
|
+
if (!group) return undefined
|
|
341
|
+
|
|
342
|
+
const variantStyles = group[variantValue] as any
|
|
343
|
+
if (!variantStyles) return undefined
|
|
344
|
+
|
|
345
|
+
return variantStyles[propName]
|
|
346
|
+
} else {
|
|
347
|
+
return (styleObj as any)[propName]
|
|
348
|
+
}
|
|
349
|
+
}
|
package/package.json
CHANGED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from "react-native-unistyles"
|
|
2
|
-
|
|
3
|
-
const ButtonStyles = StyleSheet.create(theme => ({
|
|
4
|
-
container: {
|
|
5
|
-
variants: {
|
|
6
|
-
colorPalette: {
|
|
7
|
-
primary: {
|
|
8
|
-
backgroundColor: 'tomato',
|
|
9
|
-
},
|
|
10
|
-
secondary: {
|
|
11
|
-
backgroundColor: theme.colors.foreground,
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
size: {
|
|
15
|
-
sm: {
|
|
16
|
-
height: 32,
|
|
17
|
-
maxHeight: 32,
|
|
18
|
-
padding: 6,
|
|
19
|
-
},
|
|
20
|
-
md: {
|
|
21
|
-
maxHeight: 48,
|
|
22
|
-
height: 48,
|
|
23
|
-
padding: 8,
|
|
24
|
-
},
|
|
25
|
-
lg: {
|
|
26
|
-
maxHeight: 64,
|
|
27
|
-
height: 64,
|
|
28
|
-
padding: 12,
|
|
29
|
-
},
|
|
30
|
-
xl: {
|
|
31
|
-
maxHeight: 80,
|
|
32
|
-
height: 80,
|
|
33
|
-
padding: 16,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
text: {
|
|
39
|
-
variants: {
|
|
40
|
-
colorPalette: {
|
|
41
|
-
primary: {
|
|
42
|
-
color: 'white',
|
|
43
|
-
},
|
|
44
|
-
secondary: {
|
|
45
|
-
color: theme.colors.categoryAquamarine,
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
size: {
|
|
49
|
-
sm: {
|
|
50
|
-
fontSize: 24,
|
|
51
|
-
},
|
|
52
|
-
md: {
|
|
53
|
-
fontSize: 28,
|
|
54
|
-
},
|
|
55
|
-
lg: {
|
|
56
|
-
fontSize: 32,
|
|
57
|
-
},
|
|
58
|
-
xl: {
|
|
59
|
-
fontSize: 36,
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export default ButtonStyles
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import {StyleSheet} from 'react-native-unistyles'
|
|
2
|
-
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
3
|
-
|
|
4
|
-
export const SlidingDrawerTokens = {
|
|
5
|
-
defaultProps: {
|
|
6
|
-
variant: 'solid',
|
|
7
|
-
animation: 'defaultSpring',
|
|
8
|
-
},
|
|
9
|
-
variants: {
|
|
10
|
-
animation: {
|
|
11
|
-
defaultSpring: {
|
|
12
|
-
type: 'withSpring' as const,
|
|
13
|
-
props: {
|
|
14
|
-
damping: 20,
|
|
15
|
-
stiffness: 200,
|
|
16
|
-
mass: 1,
|
|
17
|
-
overshootClamping: true,
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
slowSpring: {
|
|
21
|
-
type: 'withSpring' as const,
|
|
22
|
-
props: {
|
|
23
|
-
damping: 200,
|
|
24
|
-
stiffness: 20,
|
|
25
|
-
mass: 10,
|
|
26
|
-
overshootClamping: true,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
defaultTiming: {
|
|
30
|
-
type: 'withTiming' as const,
|
|
31
|
-
props: {
|
|
32
|
-
duration: 1000,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
} as const
|
|
38
|
-
export const SlidingDrawerStyles = StyleSheet.create(theme => ({
|
|
39
|
-
container: (colorPalette: PalettesWithNestedKeys) => ({
|
|
40
|
-
boxShadow: `0px -10px 20px black`,
|
|
41
|
-
borderRadius: theme.radii.lg,
|
|
42
|
-
backgroundColor: theme.colors.bg.default,
|
|
43
|
-
padding: theme.spacing[3],
|
|
44
|
-
variants: {
|
|
45
|
-
variant: {
|
|
46
|
-
solid: {},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
backdrop: (colorPalette: PalettesWithNestedKeys) => ({
|
|
51
|
-
backgroundColor: theme.colors.backdrop,
|
|
52
|
-
}),
|
|
53
|
-
}))
|