-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAetherModal.tsx
More file actions
71 lines (56 loc) · 2.12 KB
/
AetherModal.tsx
File metadata and controls
71 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useState } from 'react'
import Animated, { SlideInDown, SlideOutDown } from 'react-native-reanimated'
// Schemas
import { z, aetherSchema, AetherProps } from '../../schemas'
// Primitives
import { Pressable, View } from '../../primitives'
/* --- Schemas --------------------------------------------------------------------------------- */
export const AetherModalProps = aetherSchema('AetherModalProps', {
backdropClasses: z.string().optional(),
backdropColor: z.string().color().default('#333333'),
modalClasses: z.string().optional(),
modalColor: z.string().color().default('#FFFFFF'),
})
export type TAetherModalProps = AetherProps<typeof AetherModalProps> & {
children: React.ReactNode
}
/* --- <AetherModal/> -------------------------------------------------------------------------- */
export const AetherModal = (props: TAetherModalProps) => {
// Props
const { children, backdropClasses, backdropColor, modalClasses, modalColor } =
AetherModalProps.applyDefaults(props) as TAetherModalProps
// State
const [isOpen, setOpen] = useState(false)
// -- Handlers --
const toggleSheet = () => setOpen(!isOpen)
// -- Render --
if (!isOpen) return null
return (
<>
<Pressable
accessibilityRole="button"
tw={[
'absolute left-0 right-0 top-0 bottom-0 z-10',
backdropClasses,
backdropColor && `bg-[${backdropColor}]`,
]}
onPress={toggleSheet}
/>
<AnimatedContainer
tw={[
'absolute p-4 w-full h-auto min-h-[50px] rounded-t-xl z-10 bottom-[-22px]',
modalClasses,
modalColor && `bg-[${modalColor}]`,
]}
entering={SlideInDown.springify().damping(15)}
exiting={SlideOutDown}
>
{children}
</AnimatedContainer>
</>
)
}
/* --- Styles ---------------------------------------------------------------------------------- */
const AnimatedContainer = Animated.createAnimatedComponent(View)
/* --- Docs ------------------------------------------------------------------------------------ */
export const getDocumentationProps = AetherModalProps.introspect()