react-native-varia 0.0.1 → 0.2.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/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,74 @@
|
|
|
1
|
+
import {VStack, HStack} from '../patterns'
|
|
2
|
+
import Text from './Text'
|
|
3
|
+
|
|
4
|
+
const LayoutTest = () => {
|
|
5
|
+
return (
|
|
6
|
+
<VStack
|
|
7
|
+
// flex={1}
|
|
8
|
+
style={{
|
|
9
|
+
flexGrow: 1,
|
|
10
|
+
// flexShrink: 1,
|
|
11
|
+
alignSelf: 'stretch',
|
|
12
|
+
alignItems: 'stretch',
|
|
13
|
+
backgroundColor: 'red',
|
|
14
|
+
gap: 10,
|
|
15
|
+
}}>
|
|
16
|
+
<VStack
|
|
17
|
+
style={{
|
|
18
|
+
// flexGrow: 1,
|
|
19
|
+
// flexShrink: 1,
|
|
20
|
+
// alignSelf: 'stretch',
|
|
21
|
+
backgroundColor: 'pink',
|
|
22
|
+
}}>
|
|
23
|
+
<Component />
|
|
24
|
+
<Component />
|
|
25
|
+
</VStack>
|
|
26
|
+
<VStack
|
|
27
|
+
style={{
|
|
28
|
+
borderWidth: 5,
|
|
29
|
+
borderColor: 'yellow',
|
|
30
|
+
// flexGrow: 1,
|
|
31
|
+
// flexShrink: 1,
|
|
32
|
+
// alignSelf: 'stretch',
|
|
33
|
+
backgroundColor: 'pink',
|
|
34
|
+
}}>
|
|
35
|
+
<Component />
|
|
36
|
+
<Component />
|
|
37
|
+
</VStack>
|
|
38
|
+
</VStack>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const Component = () => {
|
|
43
|
+
return (
|
|
44
|
+
<VStack
|
|
45
|
+
style={{
|
|
46
|
+
borderWidth: 1,
|
|
47
|
+
borderColor: 'black',
|
|
48
|
+
// flexGrow: 1,
|
|
49
|
+
alignSelf: 'stretch',
|
|
50
|
+
backgroundColor: 'blue',
|
|
51
|
+
// flexShrink: 0,
|
|
52
|
+
// alignSelf: 'flex-start',
|
|
53
|
+
}}>
|
|
54
|
+
<Text>hola</Text>
|
|
55
|
+
<HStack
|
|
56
|
+
style={{
|
|
57
|
+
flexShrink: 0,
|
|
58
|
+
flexGrow: 1,
|
|
59
|
+
backgroundColor: 'green',
|
|
60
|
+
minHeight: 50,
|
|
61
|
+
maxHeight: 50,
|
|
62
|
+
width: '100%',
|
|
63
|
+
// opacity: 0.5,
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
<VStack>
|
|
67
|
+
<Text>hola</Text>
|
|
68
|
+
<Text>hola</Text>
|
|
69
|
+
</VStack>
|
|
70
|
+
</VStack>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default LayoutTest
|
package/lib/patterns/index.tsx
CHANGED
|
@@ -1,21 +1,57 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {Children, useLayoutEffect, useRef, useState} from 'react'
|
|
3
|
+
import type {ReactNode} from 'react'
|
|
4
|
+
import {ScrollView, View} from 'react-native'
|
|
5
|
+
import type {StyleProp, ViewProps, ViewStyle} from 'react-native'
|
|
6
|
+
import {StyleSheet, UnistylesRuntime} from 'react-native-unistyles'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
children?: ReactNode;
|
|
10
|
-
style?: StyleProp<ViewStyle>;
|
|
11
|
-
center?: boolean;
|
|
12
|
-
vCenter?: boolean;
|
|
13
|
-
hCenter?: boolean;
|
|
14
|
-
flex?: number;
|
|
15
|
-
gap?: number;
|
|
16
|
-
} & ViewProps;
|
|
8
|
+
type SpacingValue = number | string
|
|
17
9
|
|
|
18
|
-
|
|
10
|
+
export interface SpacingProps {
|
|
11
|
+
m?: SpacingValue
|
|
12
|
+
mt?: SpacingValue
|
|
13
|
+
mb?: SpacingValue
|
|
14
|
+
ml?: SpacingValue
|
|
15
|
+
mr?: SpacingValue
|
|
16
|
+
mx?: SpacingValue
|
|
17
|
+
my?: SpacingValue
|
|
18
|
+
p?: SpacingValue
|
|
19
|
+
pt?: SpacingValue
|
|
20
|
+
pb?: SpacingValue
|
|
21
|
+
pl?: SpacingValue
|
|
22
|
+
pr?: SpacingValue
|
|
23
|
+
px?: SpacingValue
|
|
24
|
+
py?: SpacingValue
|
|
25
|
+
|
|
26
|
+
alignSelf?: ViewStyle['alignSelf']
|
|
27
|
+
|
|
28
|
+
alignItems?: ViewStyle['alignItems']
|
|
29
|
+
justifyContent?: ViewStyle['justifyContent']
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type LayoutProps = {
|
|
33
|
+
center?: boolean
|
|
34
|
+
vCenter?: boolean
|
|
35
|
+
hCenter?: boolean
|
|
36
|
+
flex?: number
|
|
37
|
+
gap?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type HStackProps = SpacingProps &
|
|
41
|
+
LayoutProps &
|
|
42
|
+
Omit<React.ComponentProps<'View'>, keyof SpacingProps | keyof LayoutProps>
|
|
43
|
+
|
|
44
|
+
export type HstackProps = {
|
|
45
|
+
children?: ReactNode
|
|
46
|
+
style?: StyleProp<ViewStyle>
|
|
47
|
+
center?: boolean
|
|
48
|
+
vCenter?: boolean
|
|
49
|
+
hCenter?: boolean
|
|
50
|
+
flex?: number
|
|
51
|
+
gap?: number
|
|
52
|
+
} & ViewProps
|
|
53
|
+
|
|
54
|
+
const HStack: React.FC<HstackProps> = ({
|
|
19
55
|
children,
|
|
20
56
|
style,
|
|
21
57
|
center,
|
|
@@ -27,14 +63,13 @@ const Row: React.FC<RowProps> = ({
|
|
|
27
63
|
}) => {
|
|
28
64
|
return (
|
|
29
65
|
<View
|
|
30
|
-
style={[styles.
|
|
31
|
-
{...props}
|
|
32
|
-
>
|
|
66
|
+
style={[styles.hStack(center, vCenter, hCenter, gap, flex), style]}
|
|
67
|
+
{...props}>
|
|
33
68
|
{children}
|
|
34
69
|
</View>
|
|
35
|
-
)
|
|
36
|
-
}
|
|
37
|
-
const
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
const VStack: React.FC<HstackProps> = ({
|
|
38
73
|
children,
|
|
39
74
|
style,
|
|
40
75
|
center,
|
|
@@ -46,15 +81,14 @@ const Column: React.FC<RowProps> = ({
|
|
|
46
81
|
}) => {
|
|
47
82
|
return (
|
|
48
83
|
<View
|
|
49
|
-
style={[styles.
|
|
50
|
-
{...props}
|
|
51
|
-
>
|
|
84
|
+
style={[styles.vStack(center, vCenter, hCenter, gap, flex), style]}
|
|
85
|
+
{...props}>
|
|
52
86
|
{children}
|
|
53
87
|
</View>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
88
|
+
)
|
|
89
|
+
}
|
|
56
90
|
|
|
57
|
-
export const VSpacer = ({
|
|
91
|
+
export const VSpacer = ({size}: {size?: number}) => {
|
|
58
92
|
return (
|
|
59
93
|
<View
|
|
60
94
|
style={{
|
|
@@ -63,9 +97,9 @@ export const VSpacer = ({ size }: { size?: number }) => {
|
|
|
63
97
|
flex: size ? 0 : 1,
|
|
64
98
|
}}
|
|
65
99
|
/>
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
export const HSpacer = ({
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
export const HSpacer = ({size}: {size?: number}) => {
|
|
69
103
|
return (
|
|
70
104
|
<View
|
|
71
105
|
style={{
|
|
@@ -74,50 +108,50 @@ export const HSpacer = ({ size }: { size?: number }) => {
|
|
|
74
108
|
flex: size ? 0 : 1,
|
|
75
109
|
}}
|
|
76
110
|
/>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
111
|
+
)
|
|
112
|
+
}
|
|
79
113
|
export const FlexSpacer = () => {
|
|
80
114
|
return (
|
|
81
115
|
<View
|
|
82
|
-
style={{
|
|
116
|
+
style={{flex: 1, width: '100%', borderWidth: 1, borderColor: 'lime'}}
|
|
83
117
|
/>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
118
|
+
)
|
|
119
|
+
}
|
|
86
120
|
const styles = StyleSheet.create(() => ({
|
|
87
|
-
|
|
121
|
+
hStack: (center, vCenter, hCenter, gap, flex) => ({
|
|
88
122
|
flex,
|
|
89
123
|
gap,
|
|
90
124
|
flexDirection: 'row',
|
|
91
125
|
alignItems: center ? 'center' : vCenter ? 'center' : 'stretch',
|
|
92
126
|
justifyContent: center ? 'center' : hCenter ? 'center' : 'flex-start',
|
|
93
127
|
}),
|
|
94
|
-
|
|
128
|
+
vStack: (center, vCenter, hCenter, gap, flex) => ({
|
|
95
129
|
flex,
|
|
96
130
|
gap,
|
|
97
131
|
flexDirection: 'column',
|
|
98
132
|
alignItems: center ? 'center' : vCenter ? 'center' : 'flex-start',
|
|
99
133
|
justifyContent: center ? 'center' : hCenter ? 'center' : 'flex-start',
|
|
100
134
|
}),
|
|
101
|
-
}))
|
|
135
|
+
}))
|
|
102
136
|
|
|
103
|
-
export {
|
|
137
|
+
export {HStack, VStack}
|
|
104
138
|
|
|
105
139
|
export const gap = (size: number) => ({
|
|
106
140
|
gap: size,
|
|
107
|
-
})
|
|
141
|
+
})
|
|
108
142
|
|
|
109
143
|
type FullHeightLayoutProps = {
|
|
110
|
-
style?: StyleProp<ViewStyle
|
|
144
|
+
style?: StyleProp<ViewStyle>
|
|
111
145
|
justifyContent?:
|
|
112
146
|
| 'center'
|
|
113
147
|
| 'flex-start'
|
|
114
148
|
| 'flex-end'
|
|
115
149
|
| 'space-between'
|
|
116
150
|
| 'space-around'
|
|
117
|
-
| 'space-evenly'
|
|
118
|
-
alignItems?: 'center' | 'flex-start' | 'flex-end' | 'baseline' | 'stretch'
|
|
119
|
-
children: ReactNode
|
|
120
|
-
}
|
|
151
|
+
| 'space-evenly'
|
|
152
|
+
alignItems?: 'center' | 'flex-start' | 'flex-end' | 'baseline' | 'stretch'
|
|
153
|
+
children: ReactNode
|
|
154
|
+
}
|
|
121
155
|
|
|
122
156
|
export const FullHeightLayout = ({
|
|
123
157
|
style,
|
|
@@ -130,12 +164,11 @@ export const FullHeightLayout = ({
|
|
|
130
164
|
style={[
|
|
131
165
|
fullHeightLayoutStyles.fullHeightLayout(justifyContent, alignItems),
|
|
132
166
|
style,
|
|
133
|
-
]}
|
|
134
|
-
>
|
|
167
|
+
]}>
|
|
135
168
|
{children}
|
|
136
169
|
</View>
|
|
137
|
-
)
|
|
138
|
-
}
|
|
170
|
+
)
|
|
171
|
+
}
|
|
139
172
|
|
|
140
173
|
/* Layout with "100%" height on portrait and scrollable in landscape
|
|
141
174
|
* use case: as Children of KeyboardAwareScrollView it wraps in a scroll view
|
|
@@ -151,10 +184,9 @@ const fullHeightLayoutStyles = StyleSheet.create((_, rt) => ({
|
|
|
151
184
|
justifyContent,
|
|
152
185
|
alignItems,
|
|
153
186
|
}),
|
|
154
|
-
}))
|
|
187
|
+
}))
|
|
155
188
|
|
|
156
189
|
export const FLayout = ({
|
|
157
|
-
// style,
|
|
158
190
|
justifyContent = 'space-between',
|
|
159
191
|
alignItems = 'flex-start',
|
|
160
192
|
children,
|
|
@@ -164,16 +196,17 @@ export const FLayout = ({
|
|
|
164
196
|
contentContainerStyle={{
|
|
165
197
|
flexDirection: 'column',
|
|
166
198
|
alignItems: 'center',
|
|
167
|
-
}}
|
|
168
|
-
>
|
|
199
|
+
}}>
|
|
169
200
|
<View
|
|
170
|
-
style={fHeightLayoutStyles.fullHeightLayout(
|
|
171
|
-
|
|
201
|
+
style={fHeightLayoutStyles.fullHeightLayout(
|
|
202
|
+
justifyContent,
|
|
203
|
+
alignItems,
|
|
204
|
+
)}>
|
|
172
205
|
{children}
|
|
173
206
|
</View>
|
|
174
207
|
</ScrollView>
|
|
175
|
-
)
|
|
176
|
-
}
|
|
208
|
+
)
|
|
209
|
+
}
|
|
177
210
|
const fHeightLayoutStyles = StyleSheet.create((_, rt) => ({
|
|
178
211
|
fullHeightLayout: (justifyContent, alignItems) => ({
|
|
179
212
|
width: '100%',
|
|
@@ -183,7 +216,7 @@ const fHeightLayoutStyles = StyleSheet.create((_, rt) => ({
|
|
|
183
216
|
justifyContent,
|
|
184
217
|
alignItems,
|
|
185
218
|
}),
|
|
186
|
-
}))
|
|
219
|
+
}))
|
|
187
220
|
|
|
188
221
|
const GridChild = ({
|
|
189
222
|
parentGap,
|
|
@@ -191,14 +224,14 @@ const GridChild = ({
|
|
|
191
224
|
width,
|
|
192
225
|
children,
|
|
193
226
|
}: {
|
|
194
|
-
parentGap: number
|
|
195
|
-
columns: number
|
|
196
|
-
width: number
|
|
197
|
-
children: ReactNode
|
|
227
|
+
parentGap: number
|
|
228
|
+
columns: number
|
|
229
|
+
width: number
|
|
230
|
+
children: ReactNode
|
|
198
231
|
}) => {
|
|
199
|
-
if (width === 0) return null
|
|
232
|
+
if (width === 0) return null
|
|
200
233
|
const flexBasis =
|
|
201
|
-
width / columns - ((columns - 1) / columns) * parentGap - 0.1
|
|
234
|
+
width / columns - ((columns - 1) / columns) * parentGap - 0.1
|
|
202
235
|
return (
|
|
203
236
|
width > 0 && (
|
|
204
237
|
<View
|
|
@@ -207,13 +240,12 @@ const GridChild = ({
|
|
|
207
240
|
{
|
|
208
241
|
width: flexBasis,
|
|
209
242
|
},
|
|
210
|
-
]}
|
|
211
|
-
>
|
|
243
|
+
]}>
|
|
212
244
|
{children}
|
|
213
245
|
</View>
|
|
214
246
|
)
|
|
215
|
-
)
|
|
216
|
-
}
|
|
247
|
+
)
|
|
248
|
+
}
|
|
217
249
|
|
|
218
250
|
const gridChildStyles = StyleSheet.create({
|
|
219
251
|
container: {
|
|
@@ -222,17 +254,7 @@ const gridChildStyles = StyleSheet.create({
|
|
|
222
254
|
flex: 0,
|
|
223
255
|
flexShrink: 1,
|
|
224
256
|
},
|
|
225
|
-
})
|
|
226
|
-
|
|
227
|
-
// type Sizes = {
|
|
228
|
-
// xxs: number;
|
|
229
|
-
// xs: number;
|
|
230
|
-
// sm: number;
|
|
231
|
-
// md: number;
|
|
232
|
-
// lg: number;
|
|
233
|
-
// xl: number;
|
|
234
|
-
// xxl: number;
|
|
235
|
-
// };
|
|
257
|
+
})
|
|
236
258
|
|
|
237
259
|
export const FlexGrid = ({
|
|
238
260
|
gap = 0,
|
|
@@ -241,51 +263,47 @@ export const FlexGrid = ({
|
|
|
241
263
|
style,
|
|
242
264
|
children,
|
|
243
265
|
}: {
|
|
244
|
-
gap?: number
|
|
245
|
-
columns: number | {}
|
|
246
|
-
flex?: number
|
|
247
|
-
style?: any
|
|
248
|
-
children: ReactNode
|
|
266
|
+
gap?: number
|
|
267
|
+
columns: number | {}
|
|
268
|
+
flex?: number
|
|
269
|
+
style?: any
|
|
270
|
+
children: ReactNode
|
|
249
271
|
}) => {
|
|
250
|
-
const viewRef = useRef(null)
|
|
251
|
-
const gridItems = Children.toArray(children)
|
|
252
|
-
const [parentWidth, setParentWidth] = useState(0)
|
|
272
|
+
const viewRef = useRef(null)
|
|
273
|
+
const gridItems = Children.toArray(children)
|
|
274
|
+
const [parentWidth, setParentWidth] = useState(0)
|
|
253
275
|
|
|
254
276
|
useLayoutEffect(() => {
|
|
255
|
-
// TODO: fix types
|
|
256
277
|
// @ts-ignore
|
|
257
278
|
viewRef.current?.measure((x, y, width, height, pageX, pageY) => {
|
|
258
|
-
setParentWidth(width)
|
|
259
|
-
})
|
|
260
|
-
}, [UnistylesRuntime.breakpoint])
|
|
279
|
+
setParentWidth(width)
|
|
280
|
+
})
|
|
281
|
+
}, [UnistylesRuntime.breakpoint])
|
|
261
282
|
|
|
262
|
-
let cols: any
|
|
283
|
+
let cols: any
|
|
263
284
|
if (columns instanceof Object) {
|
|
264
|
-
// TODO: fix types
|
|
265
285
|
// @ts-ignore
|
|
266
|
-
cols = getBreakpointColumns(columns, UnistylesRuntime.breakpoint)
|
|
267
|
-
} else cols = columns
|
|
286
|
+
cols = getBreakpointColumns(columns, UnistylesRuntime.breakpoint)
|
|
287
|
+
} else cols = columns
|
|
268
288
|
|
|
269
289
|
return (
|
|
270
290
|
<View
|
|
271
291
|
ref={viewRef}
|
|
272
|
-
style={[flexGridStyles.container(gap, flex), flexGridStyles.sx(style)]}
|
|
273
|
-
>
|
|
292
|
+
style={[flexGridStyles.container(gap, flex), flexGridStyles.sx(style)]}>
|
|
274
293
|
{gridItems.map((Item, index) => {
|
|
275
294
|
return (
|
|
276
295
|
<GridChild
|
|
277
296
|
key={index}
|
|
278
297
|
parentGap={gap}
|
|
279
298
|
columns={cols}
|
|
280
|
-
width={parentWidth}
|
|
281
|
-
>
|
|
299
|
+
width={parentWidth}>
|
|
282
300
|
{Item}
|
|
283
301
|
</GridChild>
|
|
284
|
-
)
|
|
302
|
+
)
|
|
285
303
|
})}
|
|
286
304
|
</View>
|
|
287
|
-
)
|
|
288
|
-
}
|
|
305
|
+
)
|
|
306
|
+
}
|
|
289
307
|
|
|
290
308
|
const flexGridStyles = StyleSheet.create({
|
|
291
309
|
sx: (sx: any) => ({
|
|
@@ -298,101 +316,24 @@ const flexGridStyles = StyleSheet.create({
|
|
|
298
316
|
flexWrap: 'wrap',
|
|
299
317
|
width: '100%',
|
|
300
318
|
}),
|
|
301
|
-
})
|
|
302
|
-
|
|
303
|
-
// For components with flex: 1, this prevents them from taking up all the available height.
|
|
304
|
-
// Instead, their height will adjust based on the height of their children.
|
|
305
|
-
// Additionally, it can be used as a Row layout for such components.
|
|
306
|
-
export const Inline = ({
|
|
307
|
-
children,
|
|
308
|
-
align = 'center',
|
|
309
|
-
gap = 0,
|
|
310
|
-
}: {
|
|
311
|
-
children: ReactNode;
|
|
312
|
-
align?: 'center' | 'flex-start' | 'flex-end';
|
|
313
|
-
gap?: number;
|
|
314
|
-
}) => {
|
|
315
|
-
return (
|
|
316
|
-
<View
|
|
317
|
-
style={{
|
|
318
|
-
flexDirection: 'row',
|
|
319
|
-
gap,
|
|
320
|
-
justifyContent: align,
|
|
321
|
-
}}
|
|
322
|
-
>
|
|
323
|
-
{children}
|
|
324
|
-
</View>
|
|
325
|
-
);
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
export const InlineAbsolute = ({
|
|
329
|
-
children,
|
|
330
|
-
gap = 0,
|
|
331
|
-
}: {
|
|
332
|
-
children: ReactNode;
|
|
333
|
-
gap?: number;
|
|
334
|
-
}) => {
|
|
335
|
-
return (
|
|
336
|
-
<View
|
|
337
|
-
style={{
|
|
338
|
-
flexDirection: 'row',
|
|
339
|
-
width: '100%',
|
|
340
|
-
height: '100%',
|
|
341
|
-
backgroundColor: 'transparent',
|
|
342
|
-
position: 'absolute',
|
|
343
|
-
gap,
|
|
344
|
-
}}
|
|
345
|
-
>
|
|
346
|
-
{children}
|
|
347
|
-
</View>
|
|
348
|
-
);
|
|
349
|
-
};
|
|
350
|
-
export const BlockAbsolute = ({
|
|
351
|
-
children,
|
|
352
|
-
gap = 0,
|
|
353
|
-
}: {
|
|
354
|
-
children: ReactNode;
|
|
355
|
-
gap?: number;
|
|
356
|
-
}) => {
|
|
357
|
-
return (
|
|
358
|
-
<View
|
|
359
|
-
style={{
|
|
360
|
-
flexDirection: 'column',
|
|
361
|
-
width: '100%',
|
|
362
|
-
height: '100%',
|
|
363
|
-
backgroundColor: 'transparent',
|
|
364
|
-
position: 'absolute',
|
|
365
|
-
gap,
|
|
366
|
-
}}
|
|
367
|
-
>
|
|
368
|
-
{children}
|
|
369
|
-
</View>
|
|
370
|
-
);
|
|
371
|
-
};
|
|
319
|
+
})
|
|
372
320
|
|
|
373
321
|
const getBreakpointColumns = (
|
|
374
322
|
columns: Record<string, number>,
|
|
375
|
-
breakpoint: string
|
|
323
|
+
breakpoint: string,
|
|
376
324
|
) => {
|
|
377
|
-
|
|
378
|
-
const breakpointOrder = ['xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl'];
|
|
325
|
+
const breakpointOrder = ['xxs', 'xs', 'sm', 'md', 'lg', 'xl', 'xxl']
|
|
379
326
|
|
|
380
|
-
|
|
381
|
-
const currentIndex = breakpointOrder.indexOf(breakpoint);
|
|
327
|
+
const currentIndex = breakpointOrder.indexOf(breakpoint)
|
|
382
328
|
|
|
383
|
-
// Traverse backwards to find the nearest available value
|
|
384
329
|
for (let i = currentIndex; i >= 0; i--) {
|
|
385
|
-
// TODO: fix types
|
|
386
|
-
// @ts-ignore
|
|
387
330
|
if (columns[breakpointOrder[i]] !== undefined) {
|
|
388
|
-
|
|
389
|
-
return columns[breakpointOrder[i]];
|
|
331
|
+
return columns[breakpointOrder[i]]
|
|
390
332
|
}
|
|
391
333
|
}
|
|
392
334
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
335
|
+
return undefined
|
|
336
|
+
}
|
|
396
337
|
|
|
397
338
|
export const Grid = ({
|
|
398
339
|
cols,
|
|
@@ -402,25 +343,25 @@ export const Grid = ({
|
|
|
402
343
|
columnGap,
|
|
403
344
|
...props
|
|
404
345
|
}: {
|
|
405
|
-
cols: number
|
|
406
|
-
children: React.ReactNode
|
|
407
|
-
gap?: number
|
|
408
|
-
rowGap?: number
|
|
409
|
-
columnGap?: number
|
|
346
|
+
cols: number
|
|
347
|
+
children: React.ReactNode
|
|
348
|
+
gap?: number
|
|
349
|
+
rowGap?: number
|
|
350
|
+
columnGap?: number
|
|
410
351
|
}) => {
|
|
411
|
-
const gridItems = React.Children.toArray(children)
|
|
352
|
+
const gridItems = React.Children.toArray(children)
|
|
412
353
|
|
|
413
|
-
const columns = Array.from({
|
|
414
|
-
gridItems.filter((_, index) => index % cols === i)
|
|
415
|
-
)
|
|
354
|
+
const columns = Array.from({length: cols}, (_, i) =>
|
|
355
|
+
gridItems.filter((_, index) => index % cols === i),
|
|
356
|
+
)
|
|
416
357
|
|
|
417
358
|
return (
|
|
418
|
-
<
|
|
359
|
+
<HStack gap={gap && gap} {...props}>
|
|
419
360
|
{columns.map((column, index) => (
|
|
420
|
-
<
|
|
361
|
+
<VStack style={{flex: 1}} key={index} gap={gap && gap}>
|
|
421
362
|
{column}
|
|
422
|
-
</
|
|
363
|
+
</VStack>
|
|
423
364
|
))}
|
|
424
|
-
</
|
|
425
|
-
)
|
|
426
|
-
}
|
|
365
|
+
</HStack>
|
|
366
|
+
)
|
|
367
|
+
}
|