-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericModal.tsx
62 lines (55 loc) · 1.67 KB
/
GenericModal.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
import React from "react";
import { motion } from "framer-motion";
import styled from "styled-components";
const ModalDiv = styled(motion.div)`
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
background-color: white;
padding: 1rem 2rem;
border-radius: 1rem;
border: 1px solid var(--light-gray);
z-index: 10;
min-width: 30rem;
`;
const CloseButtonDiv = styled.div`
padding: 0.5rem;
float: right;
`;
const CloseButton = styled.button`
border-radius: 50%;
border: 1px solid var(--light-gray);
background-color: var(--light-gray);
height: 2rem;
width: 2rem;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
`;
const CloseButtonIcon = styled.span`
line-height: 2rem;
height: 2rem;
width: 2rem;
`;
// Generic component for modals
export default function GenericModal(props: {children: JSX.Element, id: string, close: () => void }) {
// Object ganlidng modal animations
const entryExitAnimation = {
initial: { opacity: 0, top: "-50%", transition: { type: "spring" } },
isOpen: { opacity: 1, top: "50%" },
exit: { opacity: 0, top: "-50%" }
};
return (
<ModalDiv className={"modaldiv"} initial={"initial"} animate={"isOpen"} exit={"exit"} variants={entryExitAnimation} id={props.id}>
<CloseButtonDiv>
<CloseButton onClick={props.close}>
<CloseButtonIcon className="material-symbols-outlined">close</CloseButtonIcon>
</CloseButton>
</CloseButtonDiv>
{props.children}
</ModalDiv>
)
}