|
1 | | -import React, { useState, useCallback, useEffect } from "react"; |
2 | | -import { createPortal } from "react-dom"; |
3 | | - |
4 | | -interface SimpleModalProps { |
5 | | - isOpen: boolean; |
6 | | - onClose: () => void; |
7 | | - children?: React.ReactNode; |
8 | | -} |
9 | | - |
10 | | -function SimpleModal({ isOpen, onClose, children }: SimpleModalProps) { |
11 | | - if (!isOpen) return null; |
12 | | - |
13 | | - return createPortal( |
14 | | - <div |
15 | | - style={{ |
16 | | - position: "fixed", |
17 | | - top: 0, |
18 | | - left: 0, |
19 | | - right: 0, |
20 | | - bottom: 0, |
21 | | - backgroundColor: "rgba(0, 0, 0, 0.5)", |
22 | | - display: "flex", |
23 | | - alignItems: "center", |
24 | | - justifyContent: "center", |
25 | | - zIndex: 9999, |
26 | | - }} |
27 | | - onClick={onClose} |
28 | | - > |
29 | | - <div |
30 | | - style={{ |
31 | | - backgroundColor: "var(--ifm-background-color)", |
32 | | - padding: "2rem", |
33 | | - borderRadius: "8px", |
34 | | - maxWidth: "500px", |
35 | | - width: "90%", |
36 | | - position: "relative", |
37 | | - boxShadow: "0 4px 20px rgba(0, 0, 0, 0.3)", |
38 | | - }} |
39 | | - onClick={(e) => e.stopPropagation()} |
40 | | - > |
41 | | - <button |
42 | | - onClick={onClose} |
43 | | - style={{ |
44 | | - position: "absolute", |
45 | | - top: "10px", |
46 | | - right: "15px", |
47 | | - background: "none", |
48 | | - border: "none", |
49 | | - fontSize: "1.5rem", |
50 | | - cursor: "pointer", |
51 | | - color: "var(--ifm-color-emphasis-600)", |
52 | | - }} |
53 | | - > |
54 | | - × |
55 | | - </button> |
56 | | - {children} |
57 | | - </div> |
58 | | - </div>, |
59 | | - document.body |
60 | | - ); |
61 | | -} |
| 1 | +import React from "react"; |
62 | 2 |
|
63 | 3 | export default function Root({ children }: { children: React.ReactNode }) { |
64 | | - const [showModal, setShowModal] = useState(false); |
65 | | - |
66 | | - const handleCloseModal = useCallback(() => setShowModal(false), []); |
67 | | - |
68 | | - useEffect(() => { |
69 | | - const handleNavbarClick = () => { |
70 | | - setShowModal(true); |
71 | | - }; |
72 | | - |
73 | | - // Add listener when component mounts |
74 | | - const disclaimerBtn = document.getElementById("disclaimer-btn"); |
75 | | - if (disclaimerBtn) { |
76 | | - disclaimerBtn.addEventListener("click", handleNavbarClick); |
77 | | - } |
78 | | - |
79 | | - // Cleanup listener when component unmounts |
80 | | - return () => { |
81 | | - const disclaimerBtn = document.getElementById("disclaimer-btn"); |
82 | | - if (disclaimerBtn) { |
83 | | - disclaimerBtn.removeEventListener("click", handleNavbarClick); |
84 | | - } |
85 | | - }; |
86 | | - }, []); |
87 | | - |
88 | | - return ( |
89 | | - <> |
90 | | - {children} |
91 | | - <SimpleModal isOpen={showModal} onClose={handleCloseModal}> |
92 | | - <h2>Disclaimer</h2> |
93 | | - <p> |
94 | | - This handbook is not intended to replace Optimism's documentation. |
95 | | - This is the internal material we use at Wonderland to onboard new |
96 | | - people working with Optimism as a core development member. We open |
97 | | - source it in the hopes that it helps somebody else, but beware it can |
98 | | - be outdated on the latest updates. |
99 | | - </p> |
100 | | - </SimpleModal> |
101 | | - </> |
102 | | - ); |
| 4 | + return <>{children}</>; |
103 | 5 | } |
0 commit comments