react-native-varia 0.0.1 → 0.2.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 +35 -18
- package/lib/components/Badge.tsx +31 -32
- package/lib/components/Button.tsx +20 -20
- package/lib/components/Checkbox.tsx +95 -0
- package/lib/components/CircleProgress.tsx +56 -66
- package/lib/components/Field.tsx +137 -0
- package/lib/components/GradientBackground.tsx +17 -18
- package/lib/components/GradientText.tsx +25 -64
- package/lib/components/IconWrapper.tsx +32 -25
- package/lib/components/Input.tsx +66 -68
- package/lib/components/Link.tsx +14 -28
- package/lib/components/Modal.tsx +197 -97
- package/lib/components/NewSelect.tsx +202 -0
- package/lib/components/NumberInput.tsx +226 -0
- package/lib/components/RadioGroup.tsx +195 -0
- package/lib/components/ReText.tsx +53 -87
- package/lib/components/Select.tsx +272 -0
- package/lib/components/SelectOld.tsx +153 -0
- package/lib/components/Slider.tsx +32 -40
- package/lib/components/Slideshow.tsx +174 -261
- package/lib/components/SlidingDrawer.tsx +216 -265
- package/lib/components/Spinner.tsx +21 -12
- package/lib/components/Switch.tsx +133 -180
- package/lib/components/Switchold.tsx +174 -0
- package/lib/components/Text.tsx +36 -83
- package/lib/components/layoutTest.tsx +74 -0
- package/lib/patterns/index.tsx +143 -202
- package/lib/theme/Badge.recipe.tsx +44 -39
- package/lib/theme/Button.recipe.tsx +139 -48
- package/lib/theme/Checkbox.recipe.tsx +121 -0
- package/lib/theme/CircleProgress.recipe.tsx +16 -22
- package/lib/theme/Field.recipe.tsx +66 -0
- package/lib/theme/GradientBackground.recipe.tsx +7 -20
- package/lib/theme/GradientText.recipe.tsx +42 -28
- package/lib/theme/IconWrapper.recipe.tsx +10 -85
- package/lib/theme/Input.recipe.tsx +76 -83
- package/lib/theme/Link.recipe.tsx +16 -43
- package/lib/theme/Modal.recipe.tsx +59 -21
- package/lib/theme/NumberInput.recipe.tsx +191 -0
- package/lib/theme/RadioGroup.recipe.tsx +163 -0
- package/lib/theme/ReText.recipe.tsx +4 -7
- package/lib/theme/Select.recipe.tsx +121 -0
- package/lib/theme/Slider.recipe.tsx +97 -181
- package/lib/theme/Slideshow.recipe.tsx +24 -102
- package/lib/theme/SlidingDrawer.recipe.tsx +21 -59
- package/lib/theme/Spinner.recipe.tsx +28 -3
- package/lib/theme/Switch.recipe.tsx +75 -54
- package/lib/theme/Text.recipe.tsx +66 -8
- package/lib/theme/animations.tsx +13 -0
- package/lib/varia/colorPalettes/amber.ts +54 -0
- package/lib/varia/colorPalettes/blue.ts +54 -0
- package/lib/varia/colorPalettes/bronze.ts +54 -0
- package/lib/varia/colorPalettes/brown.ts +54 -0
- package/lib/varia/colorPalettes/crimson.ts +55 -0
- package/lib/varia/colorPalettes/cyan.ts +54 -0
- package/lib/varia/colorPalettes/gold.ts +54 -0
- package/lib/varia/colorPalettes/grass.ts +54 -0
- package/lib/varia/colorPalettes/green.ts +54 -0
- package/lib/varia/colorPalettes/indigo.ts +54 -0
- package/lib/varia/colorPalettes/iris.ts +54 -0
- package/lib/varia/colorPalettes/jade.ts +54 -0
- package/lib/varia/colorPalettes/lime.ts +55 -0
- package/lib/varia/colorPalettes/mauve.ts +54 -0
- package/lib/varia/colorPalettes/mint.ts +54 -0
- package/lib/varia/colorPalettes/neutral.ts +54 -0
- package/lib/varia/colorPalettes/olive.ts +54 -0
- package/lib/varia/colorPalettes/orange.ts +54 -0
- package/lib/varia/colorPalettes/pink.ts +54 -0
- package/lib/varia/colorPalettes/plum.ts +54 -0
- package/lib/varia/colorPalettes/purple.ts +56 -0
- package/lib/varia/colorPalettes/red.ts +55 -0
- package/lib/varia/colorPalettes/ruby.ts +56 -0
- package/lib/varia/colorPalettes/sage.ts +56 -0
- package/lib/varia/colorPalettes/sand.ts +56 -0
- package/lib/varia/colorPalettes/sky.ts +56 -0
- package/lib/varia/colorPalettes/slate.ts +56 -0
- package/lib/varia/colorPalettes/teal.ts +56 -0
- package/lib/varia/colorPalettes/tomato.ts +56 -0
- package/lib/varia/colorPalettes/violet.ts +56 -0
- package/lib/varia/colorPalettes/yellow.ts +56 -0
- package/lib/varia/defaultTheme.ts +174 -0
- package/lib/varia/mixins.ts +223 -0
- package/lib/varia/textStyles.ts +48 -0
- package/lib/varia/types.ts +277 -0
- package/lib/varia/utils.ts +283 -0
- package/package.json +1 -1
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
export function hexToRgba(hex: string, alpha: number = 1) {
|
|
2
|
+
hex = hex.replace(/^#/, '')
|
|
3
|
+
|
|
4
|
+
let r, g, b, a
|
|
5
|
+
|
|
6
|
+
if (hex.length === 6) {
|
|
7
|
+
r = parseInt(hex.slice(0, 2), 16)
|
|
8
|
+
g = parseInt(hex.slice(2, 4), 16)
|
|
9
|
+
b = parseInt(hex.slice(4, 6), 16)
|
|
10
|
+
a = alpha
|
|
11
|
+
} else if (hex.length === 8) {
|
|
12
|
+
r = parseInt(hex.slice(0, 2), 16)
|
|
13
|
+
g = parseInt(hex.slice(2, 4), 16)
|
|
14
|
+
b = parseInt(hex.slice(4, 6), 16)
|
|
15
|
+
a = parseInt(hex.slice(6, 8), 16) / 255
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error('Invalid hex color format. Use #RRGGBB or #RRGGBBAA.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
import {Dimensions, PixelRatio} from 'react-native'
|
|
24
|
+
import {
|
|
25
|
+
AlphaPalette,
|
|
26
|
+
ColorPalette,
|
|
27
|
+
ColorPaletteBackground,
|
|
28
|
+
ColorPaletteBorder,
|
|
29
|
+
ColorPaletteForeground,
|
|
30
|
+
ColorScheme,
|
|
31
|
+
CreatePresetDTO,
|
|
32
|
+
CustomColorScheme,
|
|
33
|
+
ThemeColors,
|
|
34
|
+
ThemePresetDTO,
|
|
35
|
+
} from './types'
|
|
36
|
+
import {NestedColorsType} from './types'
|
|
37
|
+
import {defaultColors} from './defaultTheme'
|
|
38
|
+
|
|
39
|
+
const {width, height} = Dimensions.get('window')
|
|
40
|
+
|
|
41
|
+
const guidelineBaseWidth = 375
|
|
42
|
+
const guidelineBaseHeight = 667
|
|
43
|
+
|
|
44
|
+
const scale = (size: number): number => (width / guidelineBaseWidth) * size
|
|
45
|
+
const verticalScale = (size: number): number =>
|
|
46
|
+
(height / guidelineBaseHeight) * size
|
|
47
|
+
const moderateScale = (size: number, factor: number = 0.5): number =>
|
|
48
|
+
size + (scale(size) - size) * factor
|
|
49
|
+
|
|
50
|
+
// FONT SCALING
|
|
51
|
+
// Usage: nf(16)
|
|
52
|
+
const scaleNew = height / 667
|
|
53
|
+
const normalizeFont = (size: number): number => {
|
|
54
|
+
const newSize = size * scaleNew
|
|
55
|
+
return Math.round(PixelRatio.roundToNearestPixel(newSize))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// DYNAMIC DIMENSION CONSTANTS
|
|
59
|
+
// Usage: wp(5), hp(20)
|
|
60
|
+
const widthPercentageToDP = (widthPercent: string): number => {
|
|
61
|
+
// Convert string input to decimal number
|
|
62
|
+
const elemWidth = parseFloat(widthPercent)
|
|
63
|
+
return PixelRatio.roundToNearestPixel((width * elemWidth) / 100)
|
|
64
|
+
}
|
|
65
|
+
const heightPercentageToDP = (heightPercent: string): number => {
|
|
66
|
+
// Convert string input to decimal number
|
|
67
|
+
const elemHeight = parseFloat(heightPercent)
|
|
68
|
+
return PixelRatio.roundToNearestPixel((height * elemHeight) / 100)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Usage: wpx(141), hpx(220)
|
|
72
|
+
const widthFromPixel = (widthPx: number, w: number = 414): number =>
|
|
73
|
+
widthPx * (width / w)
|
|
74
|
+
const heightFromPixel = (heightPx: number, h: number = 896): number =>
|
|
75
|
+
heightPx * (height / h)
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
scale,
|
|
79
|
+
verticalScale,
|
|
80
|
+
moderateScale,
|
|
81
|
+
normalizeFont as nf,
|
|
82
|
+
widthPercentageToDP as wp,
|
|
83
|
+
heightPercentageToDP as hp,
|
|
84
|
+
widthFromPixel as wpx,
|
|
85
|
+
heightFromPixel as hpx,
|
|
86
|
+
}
|
|
87
|
+
|
|
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
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const resolveColor = (
|
|
104
|
+
value: string,
|
|
105
|
+
colors: NestedColorsType,
|
|
106
|
+
colorPalette?: string,
|
|
107
|
+
): string => {
|
|
108
|
+
if (value.includes('.')) {
|
|
109
|
+
const [palette, key] = value.split('.')
|
|
110
|
+
|
|
111
|
+
if (palette === 'colorPalette' && colorPalette) {
|
|
112
|
+
const paletteObj = (colors as any)[colorPalette]
|
|
113
|
+
if (paletteObj && key in paletteObj) {
|
|
114
|
+
return paletteObj[key]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const paletteObj = (colors as any)[palette]
|
|
119
|
+
if (paletteObj && key in paletteObj) {
|
|
120
|
+
return paletteObj[key]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (value in colors) {
|
|
125
|
+
return (colors as any)[value]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return value
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const resolveFontSize = <T extends Record<string, number>>(
|
|
132
|
+
fontSize: number | keyof T,
|
|
133
|
+
fontSizes: T,
|
|
134
|
+
): number => {
|
|
135
|
+
if (typeof fontSize === 'number') {
|
|
136
|
+
return fontSize
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return fontSizes[fontSize]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const createPreset = <T extends CreatePresetDTO>(
|
|
143
|
+
rawPalettes: T,
|
|
144
|
+
): {
|
|
145
|
+
light: ColorScheme &
|
|
146
|
+
CustomColorScheme & {[K in keyof T | 'black' | 'white']: ColorPalette} & {
|
|
147
|
+
backdrop: string
|
|
148
|
+
}
|
|
149
|
+
dark: ColorScheme &
|
|
150
|
+
CustomColorScheme & {[K in keyof T | 'black' | 'white']: ColorPalette} & {
|
|
151
|
+
backdrop: string
|
|
152
|
+
}
|
|
153
|
+
} => {
|
|
154
|
+
const themeColor = {
|
|
155
|
+
light: {} as Record<string, any>,
|
|
156
|
+
dark: {} as Record<string, any>,
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const palettesWithDefaults = {
|
|
160
|
+
...rawPalettes,
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isThemePresetDTO(palette: any): palette is ThemePresetDTO {
|
|
164
|
+
return 'light' in palette && 'dark' in palette
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
Object.keys(palettesWithDefaults).forEach(paletteName => {
|
|
168
|
+
const palette = palettesWithDefaults[paletteName]
|
|
169
|
+
const isGray = paletteName === 'gray'
|
|
170
|
+
|
|
171
|
+
if (isThemePresetDTO(palette)) {
|
|
172
|
+
themeColor.light[paletteName] = {
|
|
173
|
+
...palette.light,
|
|
174
|
+
default: palette.light[9],
|
|
175
|
+
emphasized: palette.light[10],
|
|
176
|
+
fg: isGray ? 'white' : palettesWithDefaults.gray.light[12],
|
|
177
|
+
text: palette.light.a11,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
themeColor.dark[paletteName] = {
|
|
181
|
+
...palette.dark,
|
|
182
|
+
default: palette.dark[9],
|
|
183
|
+
emphasized: palette.dark[10],
|
|
184
|
+
fg: isGray ? 'white' : palettesWithDefaults.gray.light[12],
|
|
185
|
+
text: palette.dark.a11,
|
|
186
|
+
}
|
|
187
|
+
} else {
|
|
188
|
+
const alphaPalette = palette as AlphaPalette
|
|
189
|
+
|
|
190
|
+
themeColor.light[paletteName] = {
|
|
191
|
+
...alphaPalette,
|
|
192
|
+
default: alphaPalette.a9,
|
|
193
|
+
emphasized: alphaPalette.a10,
|
|
194
|
+
fg: 'white',
|
|
195
|
+
text: alphaPalette.a11,
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
themeColor.dark[paletteName] = {
|
|
199
|
+
...alphaPalette,
|
|
200
|
+
default: alphaPalette.a9,
|
|
201
|
+
emphasized: alphaPalette.a10,
|
|
202
|
+
fg: 'white',
|
|
203
|
+
text: alphaPalette.a11,
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
const grayLight = themeColor.light.gray
|
|
209
|
+
const grayDark = themeColor.dark.gray
|
|
210
|
+
|
|
211
|
+
const redLight = themeColor.light.red
|
|
212
|
+
const redDark = themeColor.dark.red
|
|
213
|
+
|
|
214
|
+
Object.assign(themeColor.light, {
|
|
215
|
+
bg: {
|
|
216
|
+
canvas: grayLight['1'],
|
|
217
|
+
default: grayLight['2'],
|
|
218
|
+
subtle: grayLight['3'],
|
|
219
|
+
muted: grayLight['4'],
|
|
220
|
+
emphasized: grayLight['5'],
|
|
221
|
+
disabled: grayLight['6'],
|
|
222
|
+
} satisfies ColorPaletteBackground,
|
|
223
|
+
fg: {
|
|
224
|
+
default: grayLight['12'],
|
|
225
|
+
muted: grayLight['11'],
|
|
226
|
+
subtle: grayLight['10'],
|
|
227
|
+
disabled: grayLight['9'],
|
|
228
|
+
error: redLight['9'],
|
|
229
|
+
} satisfies ColorPaletteForeground,
|
|
230
|
+
border: {
|
|
231
|
+
default: grayLight['7'],
|
|
232
|
+
muted: grayLight['6'],
|
|
233
|
+
subtle: grayLight['4'],
|
|
234
|
+
disabled: grayLight['5'],
|
|
235
|
+
outline: grayLight['a9'],
|
|
236
|
+
error: redLight['9'],
|
|
237
|
+
} satisfies ColorPaletteBorder,
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
Object.assign(themeColor.dark, {
|
|
241
|
+
bg: {
|
|
242
|
+
canvas: grayDark['1'],
|
|
243
|
+
default: grayDark['2'],
|
|
244
|
+
subtle: grayDark['3'],
|
|
245
|
+
muted: grayDark['4'],
|
|
246
|
+
emphasized: grayDark['5'],
|
|
247
|
+
disabled: grayDark['6'],
|
|
248
|
+
} satisfies ColorPaletteBackground,
|
|
249
|
+
fg: {
|
|
250
|
+
default: grayDark['12'],
|
|
251
|
+
muted: grayDark['11'],
|
|
252
|
+
subtle: grayDark['10'],
|
|
253
|
+
disabled: grayDark['9'],
|
|
254
|
+
error: redDark['9'],
|
|
255
|
+
} satisfies ColorPaletteForeground,
|
|
256
|
+
border: {
|
|
257
|
+
default: grayDark['7'],
|
|
258
|
+
muted: grayDark['6'],
|
|
259
|
+
subtle: grayDark['4'],
|
|
260
|
+
disabled: grayDark['5'],
|
|
261
|
+
outline: grayDark['a9'],
|
|
262
|
+
error: redDark['9'],
|
|
263
|
+
} satisfies ColorPaletteBorder,
|
|
264
|
+
})
|
|
265
|
+
|
|
266
|
+
themeColor.light.backdrop = defaultColors.white.a10
|
|
267
|
+
themeColor.dark.backdrop = defaultColors.black.a10
|
|
268
|
+
|
|
269
|
+
return themeColor as {
|
|
270
|
+
light: ColorScheme &
|
|
271
|
+
CustomColorScheme & {[K in keyof T]: ColorPalette} & {
|
|
272
|
+
black: AlphaPalette
|
|
273
|
+
white: AlphaPalette
|
|
274
|
+
backdrop: string
|
|
275
|
+
}
|
|
276
|
+
dark: ColorScheme &
|
|
277
|
+
CustomColorScheme & {[K in keyof T]: ColorPalette} & {
|
|
278
|
+
black: AlphaPalette
|
|
279
|
+
white: AlphaPalette
|
|
280
|
+
backdrop: string
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|