Skip to content

Commit bf5c829

Browse files
update main site
1 parent c26ecc7 commit bf5c829

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

ui/react-example/src/App.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { AppShell, Group, Title, Button, Flex, Burger, Space, useMantineColorSch
22
import { useDisclosure } from "@mantine/hooks";
33
import { IconMoon, IconSun } from "@tabler/icons-react";
44

5+
import { DevTool } from "./components/DevTool";
56
import { ExampleContent } from "./components/ExampleContent";
67
import { Github } from "./components/icons";
78
import { MainContent } from "./components/MainContent";
@@ -119,6 +120,7 @@ function App() {
119120
<>
120121
<MainContent />
121122
<StartContent />
123+
<DevTool />
122124
</>
123125
)}
124126
{type === "example" && (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Button } from "@mantine/core";
2+
import { useState } from "react";
3+
4+
const src = "https://mrwangjusttodo.github.io/myreact-devtools";
5+
6+
function loadScript(url: string) {
7+
const script = document.createElement("script");
8+
return new Promise((resolve, reject) => {
9+
script.src = url;
10+
script.onload = resolve;
11+
script.onerror = reject;
12+
document.head.appendChild(script);
13+
}).finally(() => script.remove());
14+
}
15+
16+
const getFunc = () => (window as any).__MY_REACT_DEVTOOL_IFRAME__;
17+
18+
async function init() {
19+
if (typeof getFunc() === "function") {
20+
getFunc()(src);
21+
} else {
22+
await loadScript(`${src}/bundle/iframe.js`);
23+
await init();
24+
}
25+
}
26+
27+
export const DevTool = () => {
28+
const [open, setOpen] = useState(false);
29+
30+
return (
31+
<Button
32+
className="fixed bottom-16 left-4 z-50"
33+
color="red"
34+
size="md"
35+
onClick={async () => {
36+
if (!open) {
37+
await init();
38+
39+
setOpen(true);
40+
} else {
41+
getFunc()?.["close"]?.();
42+
43+
setOpen(false);
44+
}
45+
}}
46+
>
47+
{!open ? "Open" : "Close"} DevTool
48+
</Button>
49+
);
50+
};

0 commit comments

Comments
 (0)