react-native-varia 0.2.4 → 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.
@@ -0,0 +1,285 @@
1
+ import {useMemo} from 'react'
2
+ import {StyleProp, View, ViewStyle} from 'react-native'
3
+ import {StyleSheet} from 'react-native-unistyles'
4
+
5
+ interface StackProps {
6
+ backgroundColor?: ViewStyle['backgroundColor']
7
+ bg?: ViewStyle['backgroundColor']
8
+ width?: ViewStyle['width']
9
+ w?: ViewStyle['width']
10
+ height?: ViewStyle['height']
11
+ h?: ViewStyle['height']
12
+ borderColor?: ViewStyle['borderColor']
13
+ borderWidth?: ViewStyle['borderWidth']
14
+ borderStyle?: ViewStyle['borderStyle']
15
+ borderRadius?: ViewStyle['borderRadius']
16
+ br?: ViewStyle['borderRadius']
17
+ alignSelf?: ViewStyle['alignSelf']
18
+ alignItems?: ViewStyle['alignItems']
19
+ justifyContent?: ViewStyle['justifyContent']
20
+ flex?: ViewStyle['flex']
21
+ flexShrink?: ViewStyle['flexShrink']
22
+ flexGrow?: ViewStyle['flexGrow']
23
+ flexBasis?: ViewStyle['flexBasis']
24
+ flexWrap?: ViewStyle['flexWrap']
25
+ gap?: ViewStyle['gap']
26
+ m?: ViewStyle['margin']
27
+ mt?: ViewStyle['marginTop']
28
+ mb?: ViewStyle['marginBottom']
29
+ ml?: ViewStyle['marginLeft']
30
+ mr?: ViewStyle['marginRight']
31
+ mx?: ViewStyle['marginHorizontal']
32
+ my?: ViewStyle['marginVertical']
33
+ margin?: ViewStyle['margin']
34
+ marginVertical?: ViewStyle['marginVertical']
35
+ marginHorizontal?: ViewStyle['marginHorizontal']
36
+ marginTop?: ViewStyle['marginTop']
37
+ marginBottom?: ViewStyle['marginBottom']
38
+ marginLeft?: ViewStyle['marginLeft']
39
+ marginRight?: ViewStyle['marginRight']
40
+ p?: ViewStyle['padding']
41
+ pt?: ViewStyle['paddingVertical']
42
+ pb?: ViewStyle['paddingVertical']
43
+ pl?: ViewStyle['paddingLeft']
44
+ pr?: ViewStyle['paddingRight']
45
+ px?: ViewStyle['paddingHorizontal']
46
+ py?: ViewStyle['paddingVertical']
47
+ padding?: ViewStyle['padding']
48
+ paddingVertical?: ViewStyle['paddingVertical']
49
+ paddingHorizontal?: ViewStyle['paddingHorizontal']
50
+ paddingTop?: ViewStyle['paddingTop']
51
+ paddingBottom?: ViewStyle['paddingBottom']
52
+ paddingLeft?: ViewStyle['paddingLeft']
53
+ paddingRight?: ViewStyle['paddingRight']
54
+ children?: React.ReactNode
55
+ // style?: ViewStyle
56
+ style?: StyleProp<ViewStyle>
57
+ align?: 'center' | 'vCenter' | 'hCenter'
58
+ }
59
+
60
+ function mapProps(props: StackProps) {
61
+ const stylesArr: any[] = []
62
+
63
+ Object.entries(props).forEach(([key, value]) => {
64
+ if (value == null) return
65
+
66
+ const fn = (stackStyles as any)[key]
67
+ if (typeof fn === 'function') {
68
+ stylesArr.push(fn(value))
69
+ }
70
+ })
71
+
72
+ return stylesArr
73
+ }
74
+
75
+ const VStack = ({children, style, align, ...props}: StackProps) => {
76
+ stackStyles.useVariants({align})
77
+ const styleArr = useMemo(() => mapProps(props), [props])
78
+
79
+ return (
80
+ <View style={[stackStyles.stack, stackStyles.vstack, styleArr, style]}>
81
+ {children}
82
+ </View>
83
+ )
84
+ }
85
+
86
+ const HStack = ({children, style, align, ...props}: StackProps) => {
87
+ stackStyles.useVariants({align})
88
+ const styleArr = useMemo(() => mapProps(props), [props])
89
+
90
+ return (
91
+ <View style={[stackStyles.stack, stackStyles.hstack, styleArr, style]}>
92
+ {children}
93
+ </View>
94
+ )
95
+ }
96
+
97
+ const stackStyles = StyleSheet.create({
98
+ stack: {},
99
+ vstack: {
100
+ flexDirection: 'column',
101
+ variants: {
102
+ align: {
103
+ center: {
104
+ alignItems: 'center',
105
+ justifyContent: 'center',
106
+ },
107
+ vCenter: {
108
+ justifyContent: 'center',
109
+ },
110
+ hCenter: {
111
+ alignItems: 'center',
112
+ },
113
+ },
114
+ },
115
+ },
116
+ hstack: {
117
+ flexDirection: 'row',
118
+ variants: {
119
+ align: {
120
+ center: {
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ },
124
+ vCenter: {
125
+ alignItems: 'center',
126
+ },
127
+ hCenter: {
128
+ justifyContent: 'center',
129
+ },
130
+ },
131
+ },
132
+ },
133
+
134
+ backgroundColor: value => ({
135
+ backgroundColor: value,
136
+ }),
137
+ bg: value => ({
138
+ backgroundColor: value,
139
+ }),
140
+
141
+ width: value => ({
142
+ width: value,
143
+ }),
144
+ w: value => ({
145
+ width: value,
146
+ }),
147
+ height: value => ({
148
+ height: value,
149
+ }),
150
+ h: value => ({
151
+ height: value,
152
+ }),
153
+
154
+ borderColor: value => ({
155
+ borderColor: value,
156
+ }),
157
+ borderWidth: value => ({
158
+ borderWidth: value,
159
+ }),
160
+ borderStyle: value => ({
161
+ borderStyle: value,
162
+ }),
163
+ borderRadius: value => ({
164
+ borderRadius: value,
165
+ }),
166
+ br: value => ({
167
+ borderRadius: value,
168
+ }),
169
+
170
+ flex: value => ({
171
+ flex: value,
172
+ }),
173
+ flexShrink: value => ({
174
+ flexShrink: value,
175
+ }),
176
+ flexGrow: value => ({
177
+ flexGrow: value,
178
+ }),
179
+ flexBasis: value => ({
180
+ flexBasis: value,
181
+ }),
182
+ flexWrap: value => ({
183
+ flexWrap: value,
184
+ }),
185
+ alignSelf: value => ({
186
+ alignSelf: value,
187
+ }),
188
+ alignItems: value => ({
189
+ alignItems: value,
190
+ }),
191
+ justifyContent: value => ({
192
+ justifyContent: value,
193
+ }),
194
+ gap: value => ({
195
+ gap: value,
196
+ }),
197
+
198
+ m: value => ({
199
+ margin: value,
200
+ }),
201
+ mt: value => ({
202
+ marginTop: value,
203
+ }),
204
+ mb: value => ({
205
+ marginBottom: value,
206
+ }),
207
+ ml: value => ({
208
+ marginLeft: value,
209
+ }),
210
+ mr: value => ({
211
+ marginRight: value,
212
+ }),
213
+ mx: value => ({
214
+ marginHorizontal: value,
215
+ }),
216
+ my: value => ({
217
+ marginVertical: value,
218
+ }),
219
+ margin: value => ({
220
+ margin: value,
221
+ }),
222
+ marginVertical: value => ({
223
+ marginVertical: value,
224
+ }),
225
+ marginHorizontal: value => ({
226
+ marginHorizontal: value,
227
+ }),
228
+ marginLeft: value => ({
229
+ marginLeft: value,
230
+ }),
231
+ marginRight: value => ({
232
+ marginRight: value,
233
+ }),
234
+ marginTop: value => ({
235
+ marginTop: value,
236
+ }),
237
+ marginBottom: value => ({
238
+ marginBottom: value,
239
+ }),
240
+
241
+ p: value => ({
242
+ padding: value,
243
+ }),
244
+ pt: value => ({
245
+ paddingTop: value,
246
+ }),
247
+ pb: value => ({
248
+ paddingBottom: value,
249
+ }),
250
+ pl: value => ({
251
+ paddingLeft: value,
252
+ }),
253
+ pr: value => ({
254
+ paddingRight: value,
255
+ }),
256
+ px: value => ({
257
+ paddingHorizontal: value,
258
+ }),
259
+ py: value => ({
260
+ paddingVertical: value,
261
+ }),
262
+ padding: value => ({
263
+ padding: value,
264
+ }),
265
+ paddingHorizontal: value => ({
266
+ paddingHorizontal: value,
267
+ }),
268
+ paddingVertical: value => ({
269
+ paddingVertical: value,
270
+ }),
271
+ paddingLeft: value => ({
272
+ paddingLeft: value,
273
+ }),
274
+ paddingRight: value => ({
275
+ paddingRight: value,
276
+ }),
277
+ paddingTop: value => ({
278
+ paddingTop: value,
279
+ }),
280
+ paddingBottom: value => ({
281
+ paddingBottom: value,
282
+ }),
283
+ })
284
+
285
+ export {VStack, HStack}
@@ -1,7 +1,7 @@
1
1
  import {StyleSheet} from 'react-native-unistyles'
2
2
  import {PalettesWithNestedKeys} from '../style/varia/types'
3
3
 
4
- export const SlidingDrawerTokens = {
4
+ export const DrawerTokens = {
5
5
  defaultProps: {
6
6
  variant: 'solid',
7
7
  animation: 'defaultSpring',
@@ -35,7 +35,7 @@ export const SlidingDrawerTokens = {
35
35
  },
36
36
  },
37
37
  } as const
38
- export const SlidingDrawerStyles = StyleSheet.create((theme, rt) => ({
38
+ export const DrawerStyles = StyleSheet.create((theme, rt) => ({
39
39
  positioner: {
40
40
  variants: {
41
41
  variant: {
@@ -1,5 +1,4 @@
1
1
  import {StyleSheet} from 'react-native-unistyles'
2
- import {hexToRgba} from '../style/varia/utils'
3
2
  import {PalettesWithNestedKeys} from '../style/varia/types'
4
3
 
5
4
  export const SliderDefaultVariants = {
@@ -73,6 +72,13 @@ export const SliderStyles = StyleSheet.create(theme => ({
73
72
  height: theme.sizes[10],
74
73
  },
75
74
  },
75
+ {
76
+ axis: 'x',
77
+ size: 'flex',
78
+ styles: {
79
+ minHeight: 50,
80
+ },
81
+ },
76
82
  {
77
83
  axis: 'y',
78
84
  size: 'xs',
@@ -108,6 +114,13 @@ export const SliderStyles = StyleSheet.create(theme => ({
108
114
  width: theme.sizes[10],
109
115
  },
110
116
  },
117
+ {
118
+ axis: 'y',
119
+ size: 'flex',
120
+ styles: {
121
+ minWidth: 50,
122
+ },
123
+ },
111
124
  ],
112
125
  }),
113
126
  maximumTrack: (colorPalette: PalettesWithNestedKeys) => ({
@@ -177,6 +190,11 @@ export const SliderStyles = StyleSheet.create(theme => ({
177
190
  height: theme.sizes[10],
178
191
  },
179
192
  },
193
+ {
194
+ axis: 'x',
195
+ size: 'flex',
196
+ styles: {},
197
+ },
180
198
  {
181
199
  axis: 'y',
182
200
  size: 'xs',
@@ -218,10 +236,11 @@ export const SliderStyles = StyleSheet.create(theme => ({
218
236
  colorPalette: PalettesWithNestedKeys,
219
237
  opacityTrack: boolean,
220
238
  ) => ({
221
- backgroundColor: opacityTrack
222
- ? hexToRgba(theme.colors[colorPalette].default, 0.5)
223
- : theme.colors[colorPalette].default,
224
- height: theme.sizes[5],
239
+ backgroundColor: theme.colors[colorPalette].default,
240
+ // opacityTrack
241
+ // ? hexToRgba(theme.colors[colorPalette].default, 0.5)
242
+ // : theme.colors[colorPalette].default,
243
+ // height: theme.sizes[5],
225
244
  variants: {
226
245
  axis: {
227
246
  x: {},
@@ -246,6 +265,7 @@ export const SliderStyles = StyleSheet.create(theme => ({
246
265
  xl: {
247
266
  // height: theme.sizes[10],
248
267
  },
268
+ flex: {},
249
269
  },
250
270
  },
251
271
  compoundVariants: [
@@ -284,6 +304,11 @@ export const SliderStyles = StyleSheet.create(theme => ({
284
304
  height: theme.sizes[10],
285
305
  },
286
306
  },
307
+ {
308
+ axis: 'x',
309
+ size: 'flex',
310
+ styles: {},
311
+ },
287
312
  {
288
313
  axis: 'y',
289
314
  size: 'xs',
@@ -409,7 +434,9 @@ export const SliderStyles = StyleSheet.create(theme => ({
409
434
  size: 'flex',
410
435
  styles: {
411
436
  width: 30,
412
- height: 50,
437
+ // height: 50,
438
+ // alignSel: 'stretch',
439
+ // flex: 1,
413
440
  },
414
441
  },
415
442
  {
@@ -456,7 +483,7 @@ export const SliderStyles = StyleSheet.create(theme => ({
456
483
  axis: 'y',
457
484
  size: 'flex',
458
485
  styles: {
459
- width: 50,
486
+ alignSelf: 'stretch',
460
487
  height: 30,
461
488
  },
462
489
  },
@@ -465,7 +492,7 @@ export const SliderStyles = StyleSheet.create(theme => ({
465
492
  step: (colorPalette: PalettesWithNestedKeys) => ({
466
493
  // TODO: type correctly theme.colors
467
494
  // @ts-ignore
468
- backgroundColor: theme.colors.white['0'],
495
+ backgroundColor: theme.colors.bg.default,
469
496
  variants: {
470
497
  axis: {
471
498
  x: {},
@@ -480,6 +507,10 @@ export const SliderStyles = StyleSheet.create(theme => ({
480
507
  md: {},
481
508
  lg: {},
482
509
  xl: {},
510
+ flex: {
511
+ width: 5,
512
+ height: 5,
513
+ },
483
514
  },
484
515
  },
485
516
  }),
@@ -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,10 @@ 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 progressDirection = 'forward' | 'reverse'
283
+ export type rotationDirection = 'clockwise' | 'counterclockwise'
284
+ export type Flex = ViewStyle['flex']
285
+ 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,
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-varia",
3
- "version": "0.2.4",
3
+ "version": "0.3.0",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },