react-native-varia 0.5.2 → 0.6.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.
@@ -1,411 +1,155 @@
1
1
  import {StyleSheet} from 'react-native-unistyles'
2
2
  import {PalettesWithNestedKeys} from '../style/varia/types'
3
+ import {generateCompoundVariants} from '../style/varia/utils'
3
4
 
4
5
  export const SliderDefaultVariants = {
5
6
  size: 'md',
6
7
  variant: 'solid',
7
8
  } as const
8
- export const SliderStyles = StyleSheet.create(theme => ({
9
- container: (colorPalette: PalettesWithNestedKeys) => ({
10
- backgroundColor: theme.colors.bg.emphasized,
11
- borderRadius: theme.radii.xl,
12
- variants: {
13
- axis: {
14
- x: {},
15
- y: {},
16
- },
17
- variant: {
18
- solid: {},
19
- outline: {
20
- borderRadius: theme.radii.sm,
21
- borderColor: theme.colors[colorPalette].default,
22
- borderWidth: 1,
23
- },
24
- subtle: {
25
- backgroundColor: theme.colors.bg.subtle,
26
- },
27
- },
28
- size: {
29
- sm: {
30
- borderRadius: theme.radii.lg,
31
- },
32
- md: {
33
- borderRadius: theme.radii.xl,
34
- },
35
- lg: {
36
- borderRadius: theme.radii['2xl'],
37
- },
38
- flex: {},
39
- minimal: {},
40
- },
9
+
10
+ export const SliderStyles = StyleSheet.create(theme => {
11
+ const containerSizes = {
12
+ sm: {x: {height: theme.sizes[4]}, y: {width: theme.sizes[4]}},
13
+ md: {x: {height: theme.sizes[5]}, y: {width: theme.sizes[5]}},
14
+ lg: {x: {height: theme.sizes[8]}, y: {width: theme.sizes[8]}},
15
+ flex: {x: {minHeight: 50}, y: {minWidth: 50}},
16
+ minimal: {x: {}, y: {}},
17
+ }
18
+
19
+ const maximumTrackSizes = {
20
+ sm: {x: {height: theme.sizes[4]}, y: {width: theme.sizes[4]}},
21
+ md: {x: {height: theme.sizes[2]}, y: {width: theme.sizes[2]}},
22
+ lg: {x: {height: theme.sizes[4]}, y: {width: theme.sizes[4]}},
23
+ flex: {x: {}, y: {}},
24
+ minimal: {x: {}, y: {}},
25
+ }
26
+
27
+ const minimumTrackSizes = {
28
+ sm: {x: {height: theme.sizes[4]}, y: {width: theme.sizes[4]}},
29
+ // md: {x: {height: theme.sizes[5]}, y: {width: theme.sizes[5]}},
30
+ md: {x: {height: '100%'}, y: {width: '100%'}},
31
+ lg: {
32
+ x: {height: theme.sizes[8]},
33
+ y: {width: theme.sizes[8]},
41
34
  },
42
- compoundVariants: [
43
- {
44
- size: 'sm',
45
- variant: 'outline',
46
- styles: {
47
- borderRadius: theme.radii.sm,
48
- },
49
- },
50
- {
51
- size: 'md',
52
- variant: 'outline',
53
- styles: {
54
- borderRadius: theme.radii.sm,
55
- },
56
- },
57
- {
58
- size: 'lg',
59
- variant: 'outline',
60
- styles: {
61
- borderRadius: theme.radii.sm,
62
- },
63
- },
64
- {
65
- axis: 'x',
66
- size: 'sm',
67
- styles: {
68
- height: theme.sizes[4],
69
- },
70
- },
71
- {
72
- axis: 'x',
73
- size: 'md',
74
- styles: {
75
- height: theme.sizes[5],
76
- },
77
- },
78
- {
79
- axis: 'x',
80
- size: 'lg',
81
- styles: {
82
- height: theme.sizes[8],
83
- },
84
- },
85
- {
86
- axis: 'x',
87
- size: 'flex',
88
- styles: {
89
- minHeight: 50,
90
- },
91
- },
92
- {
93
- axis: 'y',
94
- size: 'sm',
95
- styles: {
96
- width: theme.sizes[4],
97
- },
98
- },
99
- {
100
- axis: 'y',
101
- size: 'md',
102
- styles: {
103
- width: theme.sizes[5],
104
- },
105
- },
106
- {
107
- axis: 'y',
108
- size: 'lg',
109
- styles: {
110
- width: theme.sizes[8],
111
- },
112
- },
113
- {
114
- axis: 'y',
115
- size: 'flex',
116
- styles: {
117
- minWidth: 50,
118
- },
119
- },
120
- ],
121
- }),
122
- maximumTrack: (colorPalette: PalettesWithNestedKeys) => ({
123
- backgroundColor: theme.colors.bg.emphasized,
124
- variants: {
125
- axis: {
126
- x: {},
127
- y: {},
128
- },
129
- variant: {
130
- solid: {},
131
- outline: {},
132
- subtle: {
133
- backgroundColor: theme.colors.bg.subtle,
134
- },
135
- },
136
- size: {
137
- sm: {},
138
- md: {},
139
- lg: {},
140
- flex: {},
141
- minimal: {},
142
- },
35
+ flex: {x: {flex: 1}, y: {flex: 1}},
36
+ minimal: {
37
+ x: {height: theme.sizes[8]},
38
+ y: {width: theme.sizes[8]},
143
39
  },
144
- compoundVariants: [
145
- {
146
- axis: 'x',
147
- size: 'sm',
148
- styles: {
149
- height: theme.sizes[4],
150
- },
151
- },
152
- {
153
- axis: 'x',
154
- size: 'md',
155
- styles: {
156
- height: theme.sizes[5],
157
- },
158
- },
159
- {
160
- axis: 'x',
161
- size: 'lg',
162
- styles: {
163
- height: theme.sizes[8],
164
- },
165
- },
166
- {
167
- axis: 'x',
168
- size: 'flex',
169
- styles: {},
170
- },
171
- {
172
- axis: 'y',
173
- size: 'sm',
174
- styles: {
175
- width: theme.sizes[4],
176
- },
177
- },
178
- {
179
- axis: 'y',
180
- size: 'md',
181
- styles: {
182
- width: theme.sizes[5],
183
- },
184
- },
185
- {
186
- axis: 'y',
187
- size: 'lg',
188
- styles: {
189
- width: theme.sizes[8],
190
- },
191
- },
192
- ],
193
- }),
194
- minimumTrack: (colorPalette: PalettesWithNestedKeys) => ({
195
- backgroundColor: theme.colors[colorPalette].default,
196
- variants: {
197
- axis: {
198
- x: {
199
- // borderBottomLeftRadius: theme.radii.xl,
200
- // borderBottomRightRadius: 0,
201
- // borderTopLeftRadius: theme.radii.xl,
202
- },
203
- y: {
204
- // borderBottomLeftRadius: theme.radii.xl,
205
- // borderBottomRightRadius: theme.radii.xl,
206
- // borderTopLeftRadius: 0,
207
- },
208
- },
209
- variant: {
210
- solid: {},
211
- outline: {},
212
- subtle: {},
213
- },
214
- size: {
215
- sm: {},
216
- md: {},
217
- lg: {},
218
- flex: {},
219
- minimal: {
220
- // borderRadius: theme.radii.sm,
221
- },
222
- },
40
+ }
41
+
42
+ const thumbSizes = {
43
+ sm: {
44
+ x: {width: theme.sizes[4], height: theme.sizes[4]},
45
+ y: {width: theme.sizes[6], height: theme.sizes[6]},
223
46
  },
224
- compoundVariants: [
225
- {
226
- axis: 'x',
227
- size: 'sm',
228
- styles: {
229
- height: theme.sizes[4],
230
- },
231
- },
232
- {
233
- axis: 'x',
234
- size: 'md',
235
- styles: {
236
- height: theme.sizes[5],
237
- },
238
- },
239
- {
240
- axis: 'x',
241
- size: 'lg',
242
- styles: {
243
- height: theme.sizes[8],
244
- },
245
- },
246
- {
247
- axis: 'x',
248
- size: 'flex',
249
- styles: {},
250
- },
251
- {
252
- axis: 'y',
253
- size: 'sm',
254
- styles: {
255
- width: theme.sizes[4],
256
- },
257
- },
258
- {
259
- axis: 'y',
260
- size: 'md',
261
- styles: {
262
- width: theme.sizes[5],
263
- },
264
- },
265
- {
266
- axis: 'y',
267
- size: 'lg',
268
- styles: {
269
- width: theme.sizes[8],
270
- },
271
- },
272
- {
273
- axis: 'y',
274
- size: 'flex',
275
- styles: {},
276
- },
277
- ],
278
- }),
279
- thumb: (colorPalette: PalettesWithNestedKeys) => ({
280
- variants: {
281
- axis: {
282
- x: {},
283
- y: {},
284
- },
285
- variant: {
286
- solid: {
287
- backgroundColor: theme.colors.bg.default,
288
- borderColor: theme.colors[colorPalette].default,
289
- borderRadius: theme.radii.full,
290
- borderWidth: 2,
291
- },
292
- subtle: {
293
- backgroundColor: theme.colors[colorPalette].default,
294
- },
295
- outline: {
296
- backgroundColor: theme.colors[colorPalette][11],
297
- },
298
- },
299
- size: {
300
- sm: {},
301
- md: {},
302
- lg: {},
303
- flex: {},
304
- minimal: {},
305
- },
47
+ md: {
48
+ x: {width: theme.sizes[5], height: theme.sizes[5]},
49
+ y: {width: theme.sizes[5], height: theme.sizes[5]},
306
50
  },
307
- compoundVariants: [
308
- {
309
- axis: 'x',
310
- size: 'sm',
311
- styles: {
312
- width: theme.sizes[4],
313
- height: theme.sizes[4],
314
- },
315
- },
316
- {
317
- axis: 'x',
318
- size: 'md',
319
- styles: {
320
- width: theme.sizes[5],
321
- height: theme.sizes[5],
322
- },
323
- },
324
- {
325
- axis: 'x',
326
- size: 'lg',
327
- styles: {
328
- width: theme.sizes[8],
329
- height: theme.sizes[8],
330
- },
331
- },
332
- {
333
- axis: 'x',
334
- size: 'flex',
335
- styles: {
336
- width: 30,
337
- },
338
- },
339
- {
340
- axis: 'x',
341
- size: 'minimal',
342
- styles: {
343
- width: 0,
344
- },
345
- },
346
- {
347
- axis: 'y',
348
- size: 'sm',
349
- styles: {
350
- width: theme.sizes[6],
351
- height: theme.sizes[6],
352
- },
353
- },
354
- {
355
- axis: 'y',
356
- size: 'md',
357
- styles: {
358
- width: theme.sizes[7],
359
- height: theme.sizes[7],
360
- },
361
- },
362
- {
363
- axis: 'y',
364
- size: 'lg',
365
- styles: {
366
- width: theme.sizes[8],
367
- height: theme.sizes[8],
368
- },
369
- },
370
- {
371
- axis: 'y',
372
- size: 'flex',
373
- styles: {
374
- alignSelf: 'stretch',
375
- height: 30,
376
- },
377
- },
378
- {
379
- axis: 'y',
380
- size: 'minimal',
381
- styles: {
382
- alignSelf: 'stretch',
383
- height: 5,
384
- },
385
- },
386
- ],
387
- }),
388
- step: (colorPalette: PalettesWithNestedKeys) => ({
389
- backgroundColor: theme.colors.bg.default,
390
- variants: {
391
- axis: {
392
- x: {},
393
- y: {},
394
- },
395
- variant: {
396
- solid: {
397
- backgroundColor: theme.colors.bg.default,
398
- },
399
- subtle: {},
400
- outline: {},
401
- },
402
- size: {
403
- sm: {},
404
- md: {},
405
- lg: {},
406
- flex: {},
407
- minimal: {},
408
- },
51
+ lg: {
52
+ x: {width: theme.sizes[8], height: theme.sizes[8]},
53
+ y: {width: theme.sizes[8], height: theme.sizes[8]},
409
54
  },
410
- }),
411
- }))
55
+ flex: {x: {width: 30, flex: 1}, y: {height: 30, alignSelf: 'stretch'}},
56
+ minimal: {x: {width: 0}, y: {height: 0}},
57
+ }
58
+
59
+ return {
60
+ container: (colorPalette: PalettesWithNestedKeys) => ({
61
+ borderRadius: theme.radii.xl,
62
+ variants: {
63
+ axis: {x: {}, y: {}},
64
+ variant: {
65
+ solid: {},
66
+ outline: {
67
+ borderRadius: theme.radii.sm,
68
+ borderColor: theme.colors[colorPalette].default,
69
+ borderWidth: 1,
70
+ },
71
+ subtle: {backgroundColor: theme.colors.bg.subtle},
72
+ },
73
+ size: {
74
+ sm: {borderRadius: theme.radii.lg},
75
+ md: {borderRadius: theme.radii.xl},
76
+ lg: {borderRadius: theme.radii['2xl']},
77
+ flex: {},
78
+ minimal: {},
79
+ },
80
+ },
81
+ compoundVariants: [
82
+ {
83
+ size: 'sm',
84
+ variant: 'outline',
85
+ styles: {borderRadius: theme.radii.sm},
86
+ },
87
+ {
88
+ size: 'md',
89
+ variant: 'outline',
90
+ styles: {borderRadius: theme.radii.sm},
91
+ },
92
+ {
93
+ size: 'lg',
94
+ variant: 'outline',
95
+ styles: {borderRadius: theme.radii.sm},
96
+ },
97
+ ...generateCompoundVariants(containerSizes),
98
+ ],
99
+ }),
100
+
101
+ maximumTrack: (colorPalette: PalettesWithNestedKeys) => ({
102
+ variants: {
103
+ axis: {x: {}, y: {}},
104
+ variant: {
105
+ solid: {backgroundColor: theme.colors.bg.emphasized},
106
+ outline: {},
107
+ subtle: {backgroundColor: theme.colors.bg.subtle},
108
+ },
109
+ size: {sm: {}, md: {}, lg: {}, flex: {}, minimal: {}},
110
+ },
111
+ compoundVariants: generateCompoundVariants(maximumTrackSizes),
112
+ }),
113
+
114
+ minimumTrack: (colorPalette: PalettesWithNestedKeys) => ({
115
+ backgroundColor: theme.colors[colorPalette].default,
116
+ variants: {
117
+ axis: {x: {}, y: {}},
118
+ variant: {solid: {}, outline: {}, subtle: {}},
119
+ size: {sm: {}, md: {}, lg: {}, flex: {}, minimal: {}},
120
+ },
121
+ compoundVariants: generateCompoundVariants(minimumTrackSizes),
122
+ }),
123
+
124
+ thumb: (colorPalette: PalettesWithNestedKeys) => ({
125
+ variants: {
126
+ axis: {x: {}, y: {}},
127
+ variant: {
128
+ solid: {
129
+ backgroundColor: theme.colors.bg.default,
130
+ borderColor: theme.colors[colorPalette].default,
131
+ borderRadius: theme.radii.full,
132
+ borderWidth: 2,
133
+ },
134
+ subtle: {backgroundColor: theme.colors[colorPalette].default},
135
+ outline: {backgroundColor: theme.colors[colorPalette][11]},
136
+ },
137
+ size: {sm: {}, md: {}, lg: {}, flex: {}, minimal: {}},
138
+ },
139
+ compoundVariants: generateCompoundVariants(thumbSizes),
140
+ }),
141
+
142
+ step: (colorPalette: PalettesWithNestedKeys) => ({
143
+ backgroundColor: theme.colors.bg.default,
144
+ variants: {
145
+ axis: {x: {}, y: {}},
146
+ variant: {
147
+ solid: {backgroundColor: theme.colors.bg.default},
148
+ subtle: {},
149
+ outline: {},
150
+ },
151
+ size: {sm: {}, md: {}, lg: {}, flex: {}, minimal: {}},
152
+ },
153
+ }),
154
+ }
155
+ })
@@ -287,3 +287,9 @@ export type rotationDirection = 'clockwise' | 'counterclockwise'
287
287
  export type Flex = ViewStyle['flex']
288
288
  export type MaxWidth = ViewStyle['maxWidth']
289
289
  export type ZIndex = ViewStyle['zIndex']
290
+
291
+ export type Axis = 'x' | 'y'
292
+ export type SizeEntry = {
293
+ x?: Record<string, any>
294
+ y?: Record<string, any>
295
+ }
@@ -37,6 +37,7 @@ import {
37
37
  ColorScheme,
38
38
  CreatePresetDTO,
39
39
  CustomColorScheme,
40
+ SizeEntry,
40
41
  ThemeColors,
41
42
  ThemePresetDTO,
42
43
  } from './types'
@@ -439,3 +440,9 @@ export function getCompoundVariantValue<
439
440
 
440
441
  return match.styles[propName]
441
442
  }
443
+
444
+ export const generateCompoundVariants = (sizes: Record<string, SizeEntry>) =>
445
+ Object.entries(sizes).flatMap(([size, axes]) => [
446
+ {axis: 'x', size, styles: axes.x ?? {}},
447
+ {axis: 'y', size, styles: axes.y ?? {}},
448
+ ])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-varia",
3
- "version": "0.5.2",
3
+ "version": "0.6.1",
4
4
  "bin": {
5
5
  "varia": "bin/cli.js"
6
6
  },