react-native-varia 0.0.1
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/README.md +53 -0
- package/bin/cli.js +200 -0
- package/lib/components/Badge.tsx +96 -0
- package/lib/components/Button.tsx +131 -0
- package/lib/components/CircleProgress.tsx +180 -0
- package/lib/components/Divider.tsx +43 -0
- package/lib/components/GradientBackground.tsx +68 -0
- package/lib/components/GradientText.tsx +121 -0
- package/lib/components/Icon.tsx +13 -0
- package/lib/components/IconWrapper.tsx +109 -0
- package/lib/components/Input.tsx +120 -0
- package/lib/components/Link.tsx +87 -0
- package/lib/components/Modal.tsx +157 -0
- package/lib/components/ReText.tsx +124 -0
- package/lib/components/Slider.tsx +334 -0
- package/lib/components/Slideshow.tsx +317 -0
- package/lib/components/SlidingDrawer.tsx +307 -0
- package/lib/components/Spinner.tsx +44 -0
- package/lib/components/Switch.tsx +224 -0
- package/lib/components/Text.tsx +107 -0
- package/lib/components/index.tsx +83 -0
- package/lib/mixins.ts +180 -0
- package/lib/patterns/index.tsx +426 -0
- package/lib/theme/Badge.recipe.tsx +68 -0
- package/lib/theme/Button.recipe-old.tsx +67 -0
- package/lib/theme/Button.recipe.tsx +83 -0
- package/lib/theme/CircleProgress.recipe.tsx +42 -0
- package/lib/theme/GradientBackground.recipe.tsx +38 -0
- package/lib/theme/GradientText.recipe.tsx +49 -0
- package/lib/theme/Icon.recipe.tsx +122 -0
- package/lib/theme/IconWrapper.recipe.tsx +121 -0
- package/lib/theme/Input.recipe.tsx +110 -0
- package/lib/theme/Link.recipe.tsx +51 -0
- package/lib/theme/Modal.recipe.tsx +34 -0
- package/lib/theme/ReText.recipe.tsx +7 -0
- package/lib/theme/Slider.recipe.tsx +226 -0
- package/lib/theme/Slideshow.recipe.tsx +142 -0
- package/lib/theme/SlidingDrawer.recipe.tsx +91 -0
- package/lib/theme/Spinner.recipe.tsx +8 -0
- package/lib/theme/Switch.recipe.tsx +70 -0
- package/lib/theme/Text.recipe.tsx +10 -0
- package/lib/types.ts +70 -0
- package/lib/utils.ts +80 -0
- package/package.json +18 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
export const SlideshowTokens = {
|
|
4
|
+
defaultProps: {
|
|
5
|
+
colorScheme: 'primary',
|
|
6
|
+
spacing: 'default',
|
|
7
|
+
animation: 'defaultSpring',
|
|
8
|
+
},
|
|
9
|
+
variants: {
|
|
10
|
+
animation: {
|
|
11
|
+
defaultSpring: {
|
|
12
|
+
type: 'withSpring',
|
|
13
|
+
props: {
|
|
14
|
+
damping: 20,
|
|
15
|
+
stiffness: 200,
|
|
16
|
+
mass: 1,
|
|
17
|
+
overshootClamping: true,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
slowSpring: {
|
|
21
|
+
type: 'withSpring',
|
|
22
|
+
props: {
|
|
23
|
+
damping: 200,
|
|
24
|
+
stiffness: 20,
|
|
25
|
+
mass: 10,
|
|
26
|
+
overshootClamping: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultTiming: {
|
|
30
|
+
type: 'withTiming',
|
|
31
|
+
props: {
|
|
32
|
+
duration: 300,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} as const
|
|
38
|
+
|
|
39
|
+
export const SlideshowStyles = StyleSheet.create((theme) => ({
|
|
40
|
+
container: {
|
|
41
|
+
variants: {
|
|
42
|
+
colorPalette: {
|
|
43
|
+
primary: {
|
|
44
|
+
backgroundColor: theme.colors.background,
|
|
45
|
+
borderColor: theme.colors.foreground,
|
|
46
|
+
borderWidth: 0,
|
|
47
|
+
borderRadius: 0,
|
|
48
|
+
},
|
|
49
|
+
secondary: {
|
|
50
|
+
backgroundColor: theme.colors.background,
|
|
51
|
+
borderColor: 'blue',
|
|
52
|
+
borderWidth: 5,
|
|
53
|
+
borderRadius: 20,
|
|
54
|
+
},
|
|
55
|
+
tertiary: {
|
|
56
|
+
backgroundColor: theme.colors.foreground,
|
|
57
|
+
borderColor: theme.colors.foreground,
|
|
58
|
+
borderWidth: 0,
|
|
59
|
+
borderRadius: 0,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
spacing: {
|
|
63
|
+
// default: {
|
|
64
|
+
// margin: 10,
|
|
65
|
+
// },
|
|
66
|
+
// large: {
|
|
67
|
+
// margin: 20,
|
|
68
|
+
// },
|
|
69
|
+
// small: {
|
|
70
|
+
// margin: 5,
|
|
71
|
+
// },
|
|
72
|
+
// none: {
|
|
73
|
+
// margin: 0,
|
|
74
|
+
// },
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// animation: {
|
|
79
|
+
// defaultSpring: {
|
|
80
|
+
// type: 'withSpring',
|
|
81
|
+
// props: {
|
|
82
|
+
// damping: 20,
|
|
83
|
+
// stiffness: 200,
|
|
84
|
+
// mass: 1,
|
|
85
|
+
// overshootClamping: true,
|
|
86
|
+
// },
|
|
87
|
+
// },
|
|
88
|
+
// slowSpring: {
|
|
89
|
+
// type: 'withSpring',
|
|
90
|
+
// props: {
|
|
91
|
+
// damping: 200,
|
|
92
|
+
// stiffness: 20,
|
|
93
|
+
// mass: 10,
|
|
94
|
+
// overshootClamping: true,
|
|
95
|
+
// },
|
|
96
|
+
// },
|
|
97
|
+
// defaultTiming: {
|
|
98
|
+
// type: 'withTiming',
|
|
99
|
+
// props: {
|
|
100
|
+
// duration: 300,
|
|
101
|
+
// },
|
|
102
|
+
// },
|
|
103
|
+
// },
|
|
104
|
+
slideContainer: {
|
|
105
|
+
variants: {
|
|
106
|
+
colorPalette: {
|
|
107
|
+
primary: {
|
|
108
|
+
backgroundColor: 'transparent',
|
|
109
|
+
borderWidth: 0,
|
|
110
|
+
borderRadius: 0,
|
|
111
|
+
borderColor: 'transparent',
|
|
112
|
+
},
|
|
113
|
+
secondary: {
|
|
114
|
+
backgroundColor: 'transparent',
|
|
115
|
+
borderWidth: 0,
|
|
116
|
+
borderRadius: 20,
|
|
117
|
+
borderColor: 'transparent',
|
|
118
|
+
},
|
|
119
|
+
tertiary: {
|
|
120
|
+
backgroundColor: "transparent",
|
|
121
|
+
borderWidth: 5,
|
|
122
|
+
borderRadius: 20,
|
|
123
|
+
borderColor: 'black',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
spacing: {
|
|
127
|
+
default: {
|
|
128
|
+
margin: 10,
|
|
129
|
+
},
|
|
130
|
+
large: {
|
|
131
|
+
margin: 20,
|
|
132
|
+
},
|
|
133
|
+
small: {
|
|
134
|
+
margin: 5,
|
|
135
|
+
},
|
|
136
|
+
none: {
|
|
137
|
+
margin: 0,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
}));
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
export const SlidingDrawerTokens = {
|
|
4
|
+
defaultProps: {
|
|
5
|
+
colorScheme: 'primary',
|
|
6
|
+
animation: "defaultSpring",
|
|
7
|
+
backgroundColor: "white",
|
|
8
|
+
borderRadius: 16,
|
|
9
|
+
boxShadow: '0px -10px 20px rgba(100, 0, 250, 0.6)',
|
|
10
|
+
},
|
|
11
|
+
variants: {
|
|
12
|
+
animation: {
|
|
13
|
+
defaultSpring: {
|
|
14
|
+
type: 'withSpring' as const,
|
|
15
|
+
props: {
|
|
16
|
+
damping: 20,
|
|
17
|
+
stiffness: 200,
|
|
18
|
+
mass: 1,
|
|
19
|
+
overshootClamping: true,
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
slowSpring: {
|
|
23
|
+
type: 'withSpring' as const,
|
|
24
|
+
props: {
|
|
25
|
+
damping: 200,
|
|
26
|
+
stiffness: 20,
|
|
27
|
+
mass: 10,
|
|
28
|
+
overshootClamping: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultTiming: {
|
|
32
|
+
type: 'withTiming' as const,
|
|
33
|
+
props: {
|
|
34
|
+
duration: 1000,
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export const SlidingDrawerStyles = StyleSheet.create((theme) => ({
|
|
41
|
+
// defaultProps: {
|
|
42
|
+
// colorScheme: 'primary',
|
|
43
|
+
// animation: "defaultSpring",
|
|
44
|
+
// backgroundColor: "white",
|
|
45
|
+
// borderRadius: 16,
|
|
46
|
+
// boxShadow: '0px -10px 20px rgba(100, 0, 250, 0.6)',
|
|
47
|
+
// },
|
|
48
|
+
container: {
|
|
49
|
+
variants: {
|
|
50
|
+
colorPalette: {
|
|
51
|
+
primary: {
|
|
52
|
+
backgroundColor: theme.colors.accentBackground,
|
|
53
|
+
// boxShadow: '0px -10px 20px #000000',
|
|
54
|
+
},
|
|
55
|
+
secondary: {
|
|
56
|
+
backgroundColor: "white",
|
|
57
|
+
// boxShadow: `0px -10px 20px lime`,
|
|
58
|
+
},
|
|
59
|
+
tertiary: {
|
|
60
|
+
backgroundColor: 'lime',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
// animation: {
|
|
64
|
+
// defaultSpring: {
|
|
65
|
+
// type: 'withSpring' as const,
|
|
66
|
+
// props: {
|
|
67
|
+
// damping: 20,
|
|
68
|
+
// stiffness: 200,
|
|
69
|
+
// mass: 1,
|
|
70
|
+
// overshootClamping: true,
|
|
71
|
+
// },
|
|
72
|
+
// },
|
|
73
|
+
// slowSpring: {
|
|
74
|
+
// type: 'withSpring' as const,
|
|
75
|
+
// props: {
|
|
76
|
+
// damping: 200,
|
|
77
|
+
// stiffness: 20,
|
|
78
|
+
// mass: 10,
|
|
79
|
+
// overshootClamping: true,
|
|
80
|
+
// },
|
|
81
|
+
// },
|
|
82
|
+
// defaultTiming: {
|
|
83
|
+
// type: 'withTiming' as const,
|
|
84
|
+
// props: {
|
|
85
|
+
// duration: 1000,
|
|
86
|
+
// },
|
|
87
|
+
// },
|
|
88
|
+
// },
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles'
|
|
2
|
+
|
|
3
|
+
const SwitchTokens = {
|
|
4
|
+
track: {
|
|
5
|
+
variants: {
|
|
6
|
+
size: {
|
|
7
|
+
xs: {height: 30, width: 200},
|
|
8
|
+
md: {height: 60, width: 250},
|
|
9
|
+
lg: {height: 40, width: 60},
|
|
10
|
+
},
|
|
11
|
+
colorPalette: {
|
|
12
|
+
primary: {
|
|
13
|
+
enabled: {backgroundColor: 'background'},
|
|
14
|
+
disabled: {backgroundColor: 'foreground'},
|
|
15
|
+
borderColor: 'white',
|
|
16
|
+
borderWidth: 1,
|
|
17
|
+
},
|
|
18
|
+
secondary: {
|
|
19
|
+
enabled: {backgroundColor: 'foreground'},
|
|
20
|
+
disabled: {backgroundColor: 'background'},
|
|
21
|
+
borderColor: 'white',
|
|
22
|
+
borderWidth: 15,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
thumb: {
|
|
28
|
+
variants: {
|
|
29
|
+
size: {
|
|
30
|
+
xs: {height: 20, width: 20},
|
|
31
|
+
md: {height: 50, width: 50},
|
|
32
|
+
lg: {height: 30, width: 30},
|
|
33
|
+
},
|
|
34
|
+
colorPalette: {
|
|
35
|
+
primary: {
|
|
36
|
+
enabled: {backgroundColor: 'foreground'},
|
|
37
|
+
disabled: {backgroundColor: 'background'},
|
|
38
|
+
},
|
|
39
|
+
secondary: {
|
|
40
|
+
enabled: {backgroundColor: 'background'},
|
|
41
|
+
disabled: {backgroundColor: 'foreground'},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export {SwitchTokens};
|
|
49
|
+
const SwitchStyles = StyleSheet.create(theme => ({
|
|
50
|
+
track: {
|
|
51
|
+
variants: {
|
|
52
|
+
size: {
|
|
53
|
+
xs: {height: 30, width: '100%'},
|
|
54
|
+
md: {height: 60, width: '100%'},
|
|
55
|
+
lg: {height: 40, width: '100%'},
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
thumb: {
|
|
60
|
+
variants: {
|
|
61
|
+
size: {
|
|
62
|
+
xs: {height: 20, width: 20},
|
|
63
|
+
md: {height: 50, width: 50},
|
|
64
|
+
lg: {height: 30, width: 80},
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}))
|
|
69
|
+
|
|
70
|
+
export {SwitchStyles};
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { darkTheme, lightTheme } from "./themes";
|
|
2
|
+
|
|
3
|
+
const themes = {
|
|
4
|
+
light: lightTheme,
|
|
5
|
+
dark: darkTheme,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ColorsType = (typeof themes)[keyof typeof themes]['colors'];
|
|
9
|
+
|
|
10
|
+
export type ThemeType = (typeof themes)[keyof typeof themes];
|
|
11
|
+
|
|
12
|
+
export type TextSemanticSizes =
|
|
13
|
+
| 'h1'
|
|
14
|
+
| 'h2'
|
|
15
|
+
| 'h3'
|
|
16
|
+
| 'h4'
|
|
17
|
+
| 'h5'
|
|
18
|
+
| 'h6'
|
|
19
|
+
| 'h7'
|
|
20
|
+
| 'h8'
|
|
21
|
+
| 'h9'
|
|
22
|
+
| 'body';
|
|
23
|
+
|
|
24
|
+
export type directions =
|
|
25
|
+
| 'to top'
|
|
26
|
+
| 'to bottom'
|
|
27
|
+
| 'to left'
|
|
28
|
+
| 'to right'
|
|
29
|
+
| 'to top left'
|
|
30
|
+
| 'to top right'
|
|
31
|
+
| 'to bottom left'
|
|
32
|
+
| 'to bottom right';
|
|
33
|
+
|
|
34
|
+
type ColorName = keyof ColorsType;
|
|
35
|
+
|
|
36
|
+
type LooseString<T extends string> = T | (string & {});
|
|
37
|
+
|
|
38
|
+
export type ThemeColors = LooseString<ColorName>;
|
|
39
|
+
|
|
40
|
+
export function createGradientTokens<
|
|
41
|
+
const CP extends Record<string, { startColor: ThemeColors; endColor: ThemeColors }>
|
|
42
|
+
>(tokens: {
|
|
43
|
+
defaultProps: { colorPalette: keyof CP; direction: directions };
|
|
44
|
+
variants: {
|
|
45
|
+
direction: Record<directions, { x1: number; y1: number; x2: number; y2: number }>;
|
|
46
|
+
colorPalette: CP;
|
|
47
|
+
};
|
|
48
|
+
}) {
|
|
49
|
+
return tokens;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type SVGSize = {
|
|
53
|
+
width: number;
|
|
54
|
+
height: number;
|
|
55
|
+
viewBoxWidth: number;
|
|
56
|
+
viewBoxHeight: number;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createIconTokens<
|
|
60
|
+
const CP extends Record<string, { color: ThemeColors }>
|
|
61
|
+
>(tokens: {
|
|
62
|
+
defaultProps: { colorPalette: keyof CP; size: any, scale: number };
|
|
63
|
+
variants: {
|
|
64
|
+
size: Record<string, SVGSize>;
|
|
65
|
+
colorPalette: CP;
|
|
66
|
+
};
|
|
67
|
+
}) {
|
|
68
|
+
return tokens;
|
|
69
|
+
}
|
|
70
|
+
|
package/lib/utils.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export function hexToRgba(hex: string, alpha: number = 1) {
|
|
2
|
+
// Remove the leading '#' if present
|
|
3
|
+
hex = hex.replace(/^#/, '');
|
|
4
|
+
|
|
5
|
+
// Parse the red, green, and blue components
|
|
6
|
+
let r, g, b, a;
|
|
7
|
+
|
|
8
|
+
if (hex.length === 6) {
|
|
9
|
+
r = parseInt(hex.slice(0, 2), 16);
|
|
10
|
+
g = parseInt(hex.slice(2, 4), 16);
|
|
11
|
+
b = parseInt(hex.slice(4, 6), 16);
|
|
12
|
+
a = alpha; // Use the provided alpha value
|
|
13
|
+
} else if (hex.length === 8) {
|
|
14
|
+
r = parseInt(hex.slice(0, 2), 16);
|
|
15
|
+
g = parseInt(hex.slice(2, 4), 16);
|
|
16
|
+
b = parseInt(hex.slice(4, 6), 16);
|
|
17
|
+
a = parseInt(hex.slice(6, 8), 16) / 255; // Normalize alpha to 0-1
|
|
18
|
+
} else {
|
|
19
|
+
throw new Error('Invalid hex color format. Use #RRGGBB or #RRGGBBAA.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
import {Dimensions, PixelRatio} from 'react-native';
|
|
26
|
+
import { ThemeColors } from '../src/style/types';
|
|
27
|
+
|
|
28
|
+
const {width, height} = Dimensions.get('window');
|
|
29
|
+
|
|
30
|
+
const guidelineBaseWidth = 375;
|
|
31
|
+
const guidelineBaseHeight = 667;
|
|
32
|
+
|
|
33
|
+
const scale = (size: number): number => (width / guidelineBaseWidth) * size;
|
|
34
|
+
const verticalScale = (size: number): number =>
|
|
35
|
+
(height / guidelineBaseHeight) * size;
|
|
36
|
+
const moderateScale = (size: number, factor: number = 0.5): number =>
|
|
37
|
+
size + (scale(size) - size) * factor;
|
|
38
|
+
|
|
39
|
+
// FONT SCALING
|
|
40
|
+
// Usage: nf(16)
|
|
41
|
+
const scaleNew = height / 667;
|
|
42
|
+
const normalizeFont = (size: number): number => {
|
|
43
|
+
const newSize = size * scaleNew;
|
|
44
|
+
return Math.round(PixelRatio.roundToNearestPixel(newSize));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// DYNAMIC DIMENSION CONSTANTS
|
|
48
|
+
// Usage: wp(5), hp(20)
|
|
49
|
+
const widthPercentageToDP = (widthPercent: string): number => {
|
|
50
|
+
// Convert string input to decimal number
|
|
51
|
+
const elemWidth = parseFloat(widthPercent);
|
|
52
|
+
return PixelRatio.roundToNearestPixel((width * elemWidth) / 100);
|
|
53
|
+
};
|
|
54
|
+
const heightPercentageToDP = (heightPercent: string): number => {
|
|
55
|
+
// Convert string input to decimal number
|
|
56
|
+
const elemHeight = parseFloat(heightPercent);
|
|
57
|
+
return PixelRatio.roundToNearestPixel((height * elemHeight) / 100);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Usage: wpx(141), hpx(220)
|
|
61
|
+
const widthFromPixel = (widthPx: number, w: number = 414): number =>
|
|
62
|
+
widthPx * (width / w);
|
|
63
|
+
const heightFromPixel = (heightPx: number, h: number = 896): number =>
|
|
64
|
+
heightPx * (height / h);
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
scale,
|
|
68
|
+
verticalScale,
|
|
69
|
+
moderateScale,
|
|
70
|
+
normalizeFont as nf,
|
|
71
|
+
widthPercentageToDP as wp,
|
|
72
|
+
heightPercentageToDP as hp,
|
|
73
|
+
widthFromPixel as wpx,
|
|
74
|
+
heightFromPixel as hpx,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const extractThemeColor = (color: ThemeColors, theme: any) => {
|
|
78
|
+
return color in theme.colors ? theme.colors[color] : color;
|
|
79
|
+
}
|
|
80
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-varia",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"bin": {
|
|
5
|
+
"varia": "bin/cli.js"
|
|
6
|
+
},
|
|
7
|
+
"files": [
|
|
8
|
+
"bin",
|
|
9
|
+
"lib"
|
|
10
|
+
],
|
|
11
|
+
"author": "migueloatla",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"description": "",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"commander": "^14.0.0",
|
|
16
|
+
"fs-extra": "^11.3.1"
|
|
17
|
+
}
|
|
18
|
+
}
|