/
modal-content.tsx
92 lines (80 loc) · 2.29 KB
/
modal-content.tsx
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { cx } from "@chakra-ui/shared-utils"
import {
HTMLChakraProps,
chakra,
SystemStyleObject,
forwardRef,
} from "@chakra-ui/system"
import { HTMLMotionProps } from "framer-motion"
import { useModalContext, useModalStyles } from "./modal"
import { ModalFocusScope } from "./modal-focus"
import { ModalTransition } from "./modal-transition"
export interface ModalContentProps extends HTMLChakraProps<"section"> {
/**
* The props to forward to the modal's content wrapper
*/
containerProps?: HTMLChakraProps<"div">
/**
* The custom framer-motion transition to use for the modal
*/
motionProps?: HTMLMotionProps<"section">
}
/**
* ModalContent is used to group modal's content. It has all the
* necessary `aria-*` properties to indicate that it is a modal
*/
export const ModalContent = forwardRef<ModalContentProps, "section">(
(props, ref) => {
const {
className,
children,
containerProps: rootProps,
motionProps,
...rest
} = props
const { getDialogProps, getDialogContainerProps } = useModalContext()
const dialogProps = getDialogProps(rest, ref) as any
const containerProps = getDialogContainerProps(rootProps)
const _className = cx("chakra-modal__content", className)
const styles = useModalStyles()
const dialogStyles: SystemStyleObject = {
display: "flex",
flexDirection: "column",
position: "relative",
width: "100%",
outline: 0,
...styles.dialog,
}
const dialogContainerStyles: SystemStyleObject = {
display: "flex",
width: "100vw",
height: "$100vh",
position: "fixed",
left: 0,
top: 0,
...styles.dialogContainer,
}
const { motionPreset } = useModalContext()
return (
<ModalFocusScope>
<chakra.div
{...containerProps}
className="chakra-modal__content-container"
tabIndex={-1}
__css={dialogContainerStyles}
>
<ModalTransition
preset={motionPreset}
motionProps={motionProps}
className={_className}
{...dialogProps}
__css={dialogStyles}
>
{children}
</ModalTransition>
</chakra.div>
</ModalFocusScope>
)
},
)
ModalContent.displayName = "ModalContent"