|
1 |
| -import React from 'react'; |
| 1 | +import React, { useEffect, useState } from 'react'; |
2 | 2 | import ReactDOM from 'react-dom';
|
3 |
| -import styled, { useTheme } from 'styled-components'; |
| 3 | +import styled from 'styled-components'; |
4 | 4 | import { Typography } from '../../theme/styles/Typography';
|
5 | 5 | import { Button } from '../../theme/styles/Inputs';
|
6 | 6 |
|
| 7 | +const Overlay = styled.div` |
| 8 | + position: fixed; |
| 9 | + top: 0; |
| 10 | + left: 0; |
| 11 | + width: 100%; |
| 12 | + height: 100%; |
| 13 | + background-color: rgba(0, 0, 0, 0.5); |
| 14 | + backdrop-filter: blur(10px); |
| 15 | + display: flex; |
| 16 | + justify-content: center; |
| 17 | + align-items: center; |
| 18 | + z-index: 4; |
7 | 19 |
|
8 |
| - |
| 20 | + opacity: ${({ $visible }) => ($visible ? 1 : 0)}; |
| 21 | + transition: opacity 0.3s ease-in-out; |
| 22 | +`; |
9 | 23 |
|
10 | 24 | const Content = styled.div`
|
11 |
| - position: fixed; |
12 |
| - top: 0; |
13 |
| - left: 0; |
14 |
| - width: 100%; |
15 |
| - height: 100%; |
16 |
| - background-color: rgba(0, 0, 0, 0.75); |
17 |
| - display: flex; |
18 |
| - flex-direction: column; |
19 |
| - justify-content: center; |
20 |
| - align-items: center; |
21 |
| - z-index: 1000; |
22 |
| - textSize: 3rem; |
23 |
| - color:'#DBDBDB'; |
24 |
| - gap: 10px; |
25 |
| -` |
| 25 | + background: #151515; |
| 26 | + padding: 20px; |
| 27 | + border-radius: 10px; |
| 28 | + text-align: center; |
| 29 | + color: none; |
| 30 | + white-space: pre-line; |
| 31 | +
|
| 32 | + min-width: 300px; |
| 33 | +
|
| 34 | + display: flex; |
| 35 | + flex-direction: column; |
| 36 | + align-items: center; |
| 37 | + justify-content: center; |
| 38 | +
|
| 39 | + opacity: ${({ $visible }) => ($visible ? 1 : 0)}; |
| 40 | + transform: ${({ $visible }) => ($visible ? 'scale(1)' : 'scale(0.9)')}; |
| 41 | + transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out; |
| 42 | +`; |
26 | 43 |
|
27 | 44 | const Exit = styled.button`
|
28 | 45 | position: absolute;
|
29 |
| - top: 50px; |
30 |
| - right: 30px; |
| 46 | + top: -30px; |
| 47 | + right: -30px; |
31 | 48 | border: none;
|
32 |
| - background: none; |
33 |
| - font-size: 25px; |
| 49 | + border-radius: 25px; |
| 50 | + width: 25px; |
| 51 | + height: 25px; |
| 52 | + background: #151515; |
| 53 | + font-size: 10px; |
| 54 | + font-weight: bold; |
34 | 55 | cursor: pointer;
|
35 | 56 | color: #DBDBDB;
|
36 |
| -` |
| 57 | +`; |
37 | 58 |
|
38 | 59 | const Modal = ({ isOpen, onClose, title, body, button, action }) => {
|
39 |
| - const Body1 = Typography.Body1 |
40 |
| - const Title = Typography.Title |
| 60 | + const Body1 = Typography.Body1; |
| 61 | + const Display2 = Typography.Display2; |
| 62 | + const [visible, setVisible] = useState(false); |
| 63 | + const [shouldRender, setShouldRender] = useState(isOpen); |
41 | 64 |
|
42 |
| - if (!isOpen) return null; // Don't render the modal if it's not open |
| 65 | + useEffect(() => { |
| 66 | + if (isOpen) { |
| 67 | + setShouldRender(true); |
| 68 | + setTimeout(() => setVisible(true), 10); // Ensure transition triggers |
| 69 | + } else { |
| 70 | + setVisible(false); |
| 71 | + setTimeout(() => setShouldRender(false), 300); // Delay unmounting until fade-out finishes |
| 72 | + } |
| 73 | + }, [isOpen]); |
| 74 | + |
| 75 | + if (!shouldRender) return null; // Prevent render when modal is fully closed |
43 | 76 |
|
44 | 77 | return ReactDOM.createPortal(
|
45 |
| - <Content> |
46 |
| - <Title> {title} </Title> |
47 |
| - <Body1>{body} </Body1> |
48 |
| - {action ? |
49 |
| - <Button style={{width: '300px', background: '#151515'}} onClick={action}> |
50 |
| - {button} |
51 |
| - </Button> : <></>} |
52 |
| - <Exit onClick={onClose}> |
53 |
| - X |
54 |
| - </Exit> |
55 |
| - </Content>, |
56 |
| - document.getElementById('root') // The modal renders in this DOM element |
| 78 | + <Overlay $visible={visible}> |
| 79 | + <Content $visible={visible}> |
| 80 | + <Display2>{title}</Display2> |
| 81 | + <Body1>{body}</Body1> |
| 82 | + {action ? ( |
| 83 | + <Button style={{ width: '300px', background: '#101010' }} onClick={action}> |
| 84 | + {button} |
| 85 | + </Button> |
| 86 | + ) : null} |
| 87 | + <Exit onClick={onClose}>X</Exit> |
| 88 | + </Content> |
| 89 | + </Overlay>, |
| 90 | + document.getElementById('root') |
57 | 91 | );
|
58 | 92 | };
|
59 | 93 |
|
60 |
| - |
61 | 94 | export default Modal;
|
0 commit comments