-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
components.js
104 lines (94 loc) · 2.37 KB
/
components.js
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
93
94
95
96
97
98
99
100
101
102
103
104
/** @jsx jsx */
import { jsx } from "@emotion/core";
import { DialogContent, DialogOverlay } from "@reach/dialog";
import { forwardRef } from "react";
import { Transition } from "react-spring/renderprops.cjs";
import { useTheme } from "../ThemeProvider";
import { useColorMode } from "../ColorModeProvider";
import Box from "../Box";
import Flex from "../Flex";
import styled from "@emotion/styled-base";
import { systemProps } from "../Box";
import extraConfig from "../Box/config";
const ModalHeader = props => (
<Box
px={6}
py={4}
as="header"
position="relative"
fontSize="xl"
fontWeight="semibold"
{...props}
/>
);
const ModalFooter = props => (
<Flex px={6} py={4} as="footer" justifyContent="flex-end" {...props} />
);
const ModalBody = props => <Box px={6} py={2} flex="1" {...props} />;
const StyledDialogOverlay = styled(DialogOverlay)(systemProps, extraConfig);
const ModalOverlay = forwardRef(
({ bg = "rgba(16,22,26,0.7)", zIndex, ...props }, ref) => (
<StyledDialogOverlay
ref={ref}
position="fixed"
zIndex={zIndex}
bottom="0"
top="0"
left="0"
right="0"
overflowY="auto"
bg={bg}
{...props}
/>
),
);
export const modalContentStyle = ({ colorMode }) => {
let style = {
light: {
bg: "#fff",
boxShadow:
"0 7px 14px 0 rgba(0,0,0, 0.1), 0 3px 6px 0 rgba(0, 0, 0, .07)",
},
dark: {
bg: "gray.700",
boxShadow: `rgba(0, 0, 0, 0.1) 0px 0px 0px 1px, rgba(0, 0, 0, 0.2) 0px 5px 10px, rgba(0, 0, 0, 0.4) 0px 15px 40px`,
},
};
return style[colorMode];
};
const ModalContent = forwardRef((props, ref) => {
const { colorMode } = useColorMode();
const theme = useTheme();
const styleProps = modalContentStyle({ colorMode, theme });
return (
<Box
as={DialogContent}
width="100%"
position="relative"
display="flex"
flexDirection="column"
ref={ref}
{...styleProps}
{...props}
/>
);
});
const ModalTransition = ({ isOpen, duration = 150, children }) => (
<Transition
items={isOpen}
from={{ opacity: 0, y: 10 }}
enter={{ opacity: 1, y: 0 }}
leave={{ opacity: 0, y: -10 }}
config={{ duration }}
>
{isOpen => isOpen && (styles => children(styles))}
</Transition>
);
export {
ModalHeader,
ModalTransition,
ModalFooter,
ModalBody,
ModalOverlay,
ModalContent,
};