react-native-varia 0.4.4 → 0.4.5
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/lib/components/Drawer.tsx +12 -29
- package/lib/components/Modal.tsx +15 -12
- package/lib/components/Select.tsx +13 -3
- package/lib/components/Text.tsx +1 -1
- package/lib/components/Toast.tsx +8 -5
- package/lib/theme/Select.recipe.tsx +4 -4
- package/lib/varia/constants.ts +6 -0
- package/lib/varia/hooks/useZIndexGenerator.tsx +12 -0
- package/lib/varia/types.ts +1 -0
- package/package.json +1 -1
|
@@ -9,7 +9,6 @@ import React, {
|
|
|
9
9
|
import {
|
|
10
10
|
Dimensions,
|
|
11
11
|
Keyboard,
|
|
12
|
-
Platform,
|
|
13
12
|
TouchableWithoutFeedback,
|
|
14
13
|
View,
|
|
15
14
|
} from 'react-native'
|
|
@@ -26,17 +25,14 @@ import Animated, {
|
|
|
26
25
|
} from 'react-native-reanimated'
|
|
27
26
|
import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
|
|
28
27
|
import {DrawerTokens, DrawerStyles} from '../theme/Drawer.recipe'
|
|
29
|
-
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
28
|
+
import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
|
|
30
29
|
import {
|
|
31
30
|
StyleSheet,
|
|
32
31
|
UnistylesRuntime,
|
|
33
32
|
UnistylesVariants,
|
|
34
33
|
} from 'react-native-unistyles'
|
|
35
34
|
import {HStack} from '../patterns'
|
|
36
|
-
|
|
37
|
-
/* -----------------------------
|
|
38
|
-
* Types
|
|
39
|
-
* ----------------------------*/
|
|
35
|
+
import {ZINDEXES} from '../style/varia/constants'
|
|
40
36
|
|
|
41
37
|
export type DrawerRef = {
|
|
42
38
|
expand: () => void | null
|
|
@@ -55,12 +51,9 @@ type DrawerContextType = DrawerVariants & {
|
|
|
55
51
|
type DrawerRootProps = DrawerVariants & {
|
|
56
52
|
colorPalette?: PalettesWithNestedKeys
|
|
57
53
|
children?: React.ReactNode
|
|
54
|
+
zIndex?: ZIndex
|
|
58
55
|
}
|
|
59
56
|
|
|
60
|
-
/* -----------------------------
|
|
61
|
-
* Context
|
|
62
|
-
* ----------------------------*/
|
|
63
|
-
|
|
64
57
|
const DrawerContext = createContext<DrawerContextType | null>(null)
|
|
65
58
|
const useDrawer = () => {
|
|
66
59
|
const ctx = useContext(DrawerContext)
|
|
@@ -69,13 +62,10 @@ const useDrawer = () => {
|
|
|
69
62
|
return ctx
|
|
70
63
|
}
|
|
71
64
|
|
|
72
|
-
/* -----------------------------
|
|
73
|
-
* Root
|
|
74
|
-
* ----------------------------*/
|
|
75
|
-
|
|
76
65
|
const DrawerRoot = ({
|
|
77
66
|
colorPalette = 'accent',
|
|
78
67
|
variant = DrawerTokens.defaultProps.variant,
|
|
68
|
+
zIndex,
|
|
79
69
|
children,
|
|
80
70
|
}: DrawerRootProps) => {
|
|
81
71
|
DrawerStyles.useVariants({variant})
|
|
@@ -86,8 +76,9 @@ const DrawerRoot = ({
|
|
|
86
76
|
colorPalette,
|
|
87
77
|
variant,
|
|
88
78
|
overlayOpacity,
|
|
79
|
+
zIndex,
|
|
89
80
|
}),
|
|
90
|
-
[colorPalette, variant],
|
|
81
|
+
[colorPalette, variant, zIndex],
|
|
91
82
|
)
|
|
92
83
|
|
|
93
84
|
return (
|
|
@@ -95,9 +86,6 @@ const DrawerRoot = ({
|
|
|
95
86
|
)
|
|
96
87
|
}
|
|
97
88
|
|
|
98
|
-
/* -----------------------------
|
|
99
|
-
* Positioner
|
|
100
|
-
* ----------------------------*/
|
|
101
89
|
const DrawerPositioner = ({
|
|
102
90
|
children,
|
|
103
91
|
direction,
|
|
@@ -147,9 +135,6 @@ const DrawerPositioner = ({
|
|
|
147
135
|
)
|
|
148
136
|
}
|
|
149
137
|
|
|
150
|
-
/* -----------------------------
|
|
151
|
-
* Overlay
|
|
152
|
-
* ----------------------------*/
|
|
153
138
|
const AnimatedTouchable = Animated.createAnimatedComponent(
|
|
154
139
|
TouchableWithoutFeedback,
|
|
155
140
|
)
|
|
@@ -190,10 +175,6 @@ const DrawerOverlay = ({onPress}: {onPress?: () => void}) => {
|
|
|
190
175
|
)
|
|
191
176
|
}
|
|
192
177
|
|
|
193
|
-
/* -----------------------------
|
|
194
|
-
* Slider (gestión independiente)
|
|
195
|
-
* ----------------------------*/
|
|
196
|
-
|
|
197
178
|
type InternalDrawerSliderProps = {
|
|
198
179
|
axis: 'x' | 'y'
|
|
199
180
|
direction: 1 | -1
|
|
@@ -207,6 +188,7 @@ type InternalDrawerSliderProps = {
|
|
|
207
188
|
children?: React.ReactNode
|
|
208
189
|
ref?: React.RefObject<DrawerRef | null>
|
|
209
190
|
externalTranslate?: SharedValue<number>
|
|
191
|
+
zIndex?: ZIndex
|
|
210
192
|
}
|
|
211
193
|
|
|
212
194
|
export type DrawerSliderProps = Omit<
|
|
@@ -231,6 +213,7 @@ const DrawerSliderInternal = ({
|
|
|
231
213
|
children,
|
|
232
214
|
externalTranslate,
|
|
233
215
|
ref,
|
|
216
|
+
zIndex,
|
|
234
217
|
}: InternalDrawerSliderProps) => {
|
|
235
218
|
const {variant, colorPalette, overlayOpacity} = useDrawer()
|
|
236
219
|
|
|
@@ -489,7 +472,7 @@ const DrawerSliderInternal = ({
|
|
|
489
472
|
ref={viewRef}
|
|
490
473
|
onLayout={onLayout}
|
|
491
474
|
style={[
|
|
492
|
-
styles.slider,
|
|
475
|
+
styles.slider(zIndex || ZINDEXES.drawer),
|
|
493
476
|
blockAnimatedStyle,
|
|
494
477
|
DrawerStyles.slider(colorPalette),
|
|
495
478
|
{pointerEvents: 'auto'},
|
|
@@ -523,14 +506,14 @@ const styles = StyleSheet.create((theme, rt) => ({
|
|
|
523
506
|
_classNames: 'drawer-positioner-base',
|
|
524
507
|
},
|
|
525
508
|
},
|
|
526
|
-
slider: {
|
|
509
|
+
slider: (zIndex: ZIndex) => ({
|
|
527
510
|
flex: 1,
|
|
528
511
|
alignSelf: 'stretch',
|
|
529
512
|
alignItems: 'center',
|
|
530
513
|
justifyContent: 'flex-start',
|
|
531
|
-
zIndex
|
|
514
|
+
zIndex,
|
|
532
515
|
_web: {
|
|
533
516
|
_classNames: 'drawer-slider-base',
|
|
534
517
|
},
|
|
535
|
-
},
|
|
518
|
+
}),
|
|
536
519
|
}))
|
package/lib/components/Modal.tsx
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import React, {createContext, useContext} from 'react'
|
|
2
|
-
import {
|
|
3
|
-
TouchableOpacity,
|
|
4
|
-
TouchableWithoutFeedback,
|
|
5
|
-
View,
|
|
6
|
-
StyleSheet as RNStyleSheet,
|
|
7
|
-
} from 'react-native'
|
|
2
|
+
import {TouchableOpacity, TouchableWithoutFeedback, View} from 'react-native'
|
|
8
3
|
import Animated from 'react-native-reanimated'
|
|
9
4
|
import {Portal} from '@gorhom/portal'
|
|
10
5
|
import Svg, {Path} from 'react-native-svg'
|
|
11
6
|
import {StyleSheet, UnistylesVariants} from 'react-native-unistyles'
|
|
12
7
|
import Text from './Text'
|
|
13
8
|
import {ModalStyles, ModalTokens} from '../theme/Modal.recipe'
|
|
14
|
-
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
9
|
+
import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
|
|
10
|
+
import {ZINDEXES} from '../style/varia/constants'
|
|
15
11
|
|
|
16
12
|
const AnimatedView = Animated.createAnimatedComponent(View)
|
|
17
13
|
type ModalVariants = UnistylesVariants<typeof ModalStyles>
|
|
@@ -24,6 +20,7 @@ type ModalRootProps = ModalVariants & {
|
|
|
24
20
|
portalHostName?: string
|
|
25
21
|
isOpen: boolean
|
|
26
22
|
setIsOpen: (isOpen: boolean) => void
|
|
23
|
+
zIndex?: ZIndex
|
|
27
24
|
children: React.ReactNode
|
|
28
25
|
}
|
|
29
26
|
|
|
@@ -46,6 +43,7 @@ const ModalRoot = ({
|
|
|
46
43
|
portalHostName = 'modal',
|
|
47
44
|
isOpen,
|
|
48
45
|
setIsOpen,
|
|
46
|
+
zIndex,
|
|
49
47
|
children,
|
|
50
48
|
}: ModalRootProps) => {
|
|
51
49
|
ModalStyles.useVariants({
|
|
@@ -59,6 +57,7 @@ const ModalRoot = ({
|
|
|
59
57
|
variant,
|
|
60
58
|
animation,
|
|
61
59
|
setIsOpen,
|
|
60
|
+
zIndex,
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
return (
|
|
@@ -85,6 +84,7 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
85
84
|
variant,
|
|
86
85
|
animation,
|
|
87
86
|
setIsOpen,
|
|
87
|
+
zIndex,
|
|
88
88
|
} = {...context, ...props}
|
|
89
89
|
|
|
90
90
|
ModalStyles.useVariants({variant})
|
|
@@ -92,7 +92,10 @@ const ModalOverlay = ({children, ...props}: ModalOverlayProps) => {
|
|
|
92
92
|
return (
|
|
93
93
|
<AnimatedView
|
|
94
94
|
testID="varia-modal-overlay"
|
|
95
|
-
style={[
|
|
95
|
+
style={[
|
|
96
|
+
styles.overlay(zIndex || ZINDEXES.modal),
|
|
97
|
+
ModalStyles.overlay(colorPalette),
|
|
98
|
+
]}
|
|
96
99
|
entering={ModalTokens.animations.variants[animation]?.enteringOverlay}
|
|
97
100
|
exiting={ModalTokens.animations.variants[animation]?.exitingOverlay}>
|
|
98
101
|
<TouchableWithoutFeedback onPress={() => setIsOpen(false)}>
|
|
@@ -226,15 +229,15 @@ const ModalCloseTrigger = ({children, style}: ModalCloseTriggerProps) => {
|
|
|
226
229
|
|
|
227
230
|
const styles = StyleSheet.create(theme => {
|
|
228
231
|
return {
|
|
229
|
-
overlay: {
|
|
230
|
-
...
|
|
231
|
-
zIndex
|
|
232
|
+
overlay: (zIndex: ZIndex) => ({
|
|
233
|
+
...StyleSheet.absoluteFillObject,
|
|
234
|
+
zIndex,
|
|
232
235
|
justifyContent: 'center',
|
|
233
236
|
alignItems: 'center',
|
|
234
237
|
_web: {
|
|
235
238
|
_classNames: 'modal-overlay-base',
|
|
236
239
|
},
|
|
237
|
-
},
|
|
240
|
+
}),
|
|
238
241
|
content: () => ({
|
|
239
242
|
justifyContent: 'center',
|
|
240
243
|
alignItems: 'center',
|
|
@@ -23,8 +23,10 @@ import {
|
|
|
23
23
|
Flex,
|
|
24
24
|
PalettesWithNestedKeys,
|
|
25
25
|
StackDirection,
|
|
26
|
+
ZIndex,
|
|
26
27
|
} from '../style/varia/types'
|
|
27
28
|
import {computeFlexSync} from '../style/varia/utils'
|
|
29
|
+
import {ZINDEXES} from '../style/varia/constants'
|
|
28
30
|
|
|
29
31
|
type SelectVariants = UnistylesVariants<typeof SelectStyles>
|
|
30
32
|
|
|
@@ -47,6 +49,7 @@ interface SelectContextType {
|
|
|
47
49
|
variant: SelectVariants['variant']
|
|
48
50
|
size: SelectVariants['size']
|
|
49
51
|
flex: Flex
|
|
52
|
+
zIndex: ZIndex
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
const SelectContext = createContext<SelectContextType | undefined>(undefined)
|
|
@@ -70,6 +73,7 @@ type RootProps = SelectVariants & {
|
|
|
70
73
|
flex?: Flex
|
|
71
74
|
stretch?: AlignSelf
|
|
72
75
|
direction?: 'row' | 'column'
|
|
76
|
+
zIndex?: ZIndex
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
const SelectRoot = ({
|
|
@@ -85,6 +89,7 @@ const SelectRoot = ({
|
|
|
85
89
|
flex = 0,
|
|
86
90
|
stretch,
|
|
87
91
|
direction = 'column',
|
|
92
|
+
zIndex,
|
|
88
93
|
}: RootProps) => {
|
|
89
94
|
SelectStyles.useVariants({variant, size})
|
|
90
95
|
const [internalValue, setInternalValue] = useState(defaultValue)
|
|
@@ -147,8 +152,11 @@ const SelectRoot = ({
|
|
|
147
152
|
variant,
|
|
148
153
|
size,
|
|
149
154
|
flex,
|
|
155
|
+
zIndex,
|
|
150
156
|
}}>
|
|
151
|
-
<View style={styles.portalContainer}>
|
|
157
|
+
<View style={styles.portalContainer(zIndex || ZINDEXES.select)}>
|
|
158
|
+
{portalChildren}
|
|
159
|
+
</View>
|
|
152
160
|
</SelectContext.Provider>
|
|
153
161
|
</Portal>
|
|
154
162
|
)}
|
|
@@ -309,6 +317,7 @@ const styles = StyleSheet.create({
|
|
|
309
317
|
},
|
|
310
318
|
},
|
|
311
319
|
backdrop: {
|
|
320
|
+
zIndex: 1001,
|
|
312
321
|
...StyleSheet.absoluteFillObject,
|
|
313
322
|
backgroundColor: 'rgba(0,0,0,0.3)',
|
|
314
323
|
_web: {
|
|
@@ -322,7 +331,8 @@ const styles = StyleSheet.create({
|
|
|
322
331
|
_classNames: 'select-modal-content-base',
|
|
323
332
|
},
|
|
324
333
|
},
|
|
325
|
-
portalContainer: {
|
|
334
|
+
portalContainer: (zIndex: ZIndex) => ({
|
|
335
|
+
zIndex,
|
|
326
336
|
position: 'absolute',
|
|
327
337
|
top: 0,
|
|
328
338
|
left: 0,
|
|
@@ -333,5 +343,5 @@ const styles = StyleSheet.create({
|
|
|
333
343
|
_web: {
|
|
334
344
|
_classNames: 'select-portal-container-base',
|
|
335
345
|
},
|
|
336
|
-
},
|
|
346
|
+
}),
|
|
337
347
|
})
|
package/lib/components/Text.tsx
CHANGED
package/lib/components/Toast.tsx
CHANGED
|
@@ -11,9 +11,10 @@ import Animated, {
|
|
|
11
11
|
import {scheduleOnRN, scheduleOnUI} from 'react-native-worklets'
|
|
12
12
|
import {ToastStyles, ToastDefaultVariants} from '../theme/Toast.recipe'
|
|
13
13
|
import {UnistylesVariants} from 'react-native-unistyles'
|
|
14
|
-
import {PalettesWithNestedKeys} from '../style/varia/types'
|
|
14
|
+
import {PalettesWithNestedKeys, ZIndex} from '../style/varia/types'
|
|
15
15
|
import Text from './Text'
|
|
16
16
|
import {AnimatedHStack, VStack} from '../patterns'
|
|
17
|
+
import {ZINDEXES} from '../style/varia/constants'
|
|
17
18
|
|
|
18
19
|
type ToastVariants = UnistylesVariants<typeof ToastStyles>
|
|
19
20
|
|
|
@@ -23,6 +24,7 @@ export type ToastProps = ToastVariants & {
|
|
|
23
24
|
duration?: number
|
|
24
25
|
onClose?: () => void
|
|
25
26
|
position?: 'top' | 'bottom'
|
|
27
|
+
zIndex?: ZIndex
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
const Toast: React.FC<ToastProps> = ({
|
|
@@ -33,6 +35,7 @@ const Toast: React.FC<ToastProps> = ({
|
|
|
33
35
|
duration = 5000,
|
|
34
36
|
onClose,
|
|
35
37
|
position = 'bottom',
|
|
38
|
+
zIndex,
|
|
36
39
|
}) => {
|
|
37
40
|
ToastStyles.useVariants({variant, size})
|
|
38
41
|
|
|
@@ -88,7 +91,7 @@ const Toast: React.FC<ToastProps> = ({
|
|
|
88
91
|
justifyContent:
|
|
89
92
|
position === 'bottom' || !position ? 'flex-end' : 'flex-start',
|
|
90
93
|
},
|
|
91
|
-
styles.container,
|
|
94
|
+
styles.container(zIndex || ZINDEXES.toast),
|
|
92
95
|
ToastStyles.root,
|
|
93
96
|
]}>
|
|
94
97
|
<AnimatedHStack
|
|
@@ -101,16 +104,16 @@ const Toast: React.FC<ToastProps> = ({
|
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
const styles = StyleSheet.create({
|
|
104
|
-
container: {
|
|
107
|
+
container: (zIndex: ZIndex) => ({
|
|
105
108
|
alignItems: 'center',
|
|
106
109
|
overflow: 'hidden',
|
|
107
|
-
zIndex
|
|
110
|
+
zIndex,
|
|
108
111
|
pointerEvents: 'box-none',
|
|
109
112
|
_web: {
|
|
110
113
|
pointerEvents: 'none',
|
|
111
114
|
_classNames: 'toast-container-base',
|
|
112
115
|
},
|
|
113
|
-
},
|
|
116
|
+
}),
|
|
114
117
|
})
|
|
115
118
|
|
|
116
119
|
export default Toast
|
|
@@ -24,15 +24,15 @@ export const SelectStyles = StyleSheet.create((theme, rt) => ({
|
|
|
24
24
|
size: {
|
|
25
25
|
sm: {
|
|
26
26
|
height: theme.sizes[9],
|
|
27
|
-
|
|
27
|
+
paddingHorizontal: theme.spacing[1],
|
|
28
28
|
},
|
|
29
29
|
md: {
|
|
30
30
|
height: theme.sizes[10],
|
|
31
|
-
|
|
31
|
+
paddingHorizontal: theme.spacing[2],
|
|
32
32
|
},
|
|
33
33
|
lg: {
|
|
34
|
-
height: theme.sizes[
|
|
35
|
-
|
|
34
|
+
height: theme.sizes[12],
|
|
35
|
+
paddingHorizontal: theme.spacing[3],
|
|
36
36
|
},
|
|
37
37
|
nosize: {},
|
|
38
38
|
},
|
package/lib/varia/types.ts
CHANGED