-
-
Notifications
You must be signed in to change notification settings - Fork 741
Expand file tree
/
Copy pathmain.tsx
More file actions
148 lines (133 loc) · 4.04 KB
/
Copy pathmain.tsx
File metadata and controls
148 lines (133 loc) · 4.04 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { usePrefersColorScheme } from "@blocknote/react";
import {
AppShell,
MantineProvider,
ScrollArea,
TextInput,
} from "@mantine/core";
import React from "react";
import { createRoot } from "react-dom/client";
import {
Link,
Outlet,
RouterProvider,
createBrowserRouter,
} from "react-router-dom";
import { examples } from "./examples.gen.js";
import "./style.css";
window.React = React;
const modules = import.meta.glob("../../examples/**/*/App.tsx");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const editors = examples as any;
function Root() {
// const linkStyles = (theme) => ({
// root: {
// // background: "red",
// ...theme.fn.hover({
// backgroundColor: "#dfdfdd",
// }),
// "&[data-active]": {
// backgroundColor: "rgba(0, 0, 0, 0.04)",
// },
// },
// // "root:hover": { background: "blue" },
// });
const [searchQuery, setSearchQuery] = React.useState("");
const themePreference = usePrefersColorScheme();
return (
<MantineProvider
forceColorScheme={
themePreference === "no-preference"
? undefined
: (themePreference as "light" | "dark")
}
>
<AppShell
navbar={
window.location.search.includes("hideMenu")
? undefined
: {
width: 300,
breakpoint: 0,
}
}
padding={0}
// header={<Header height={60} p="xs">
// {/* Header content */}
// </Header>}
>
{window.location.search.includes("hideMenu") ? undefined : (
<AppShell.Navbar p="xs">
<TextInput
placeholder="Search examples..."
value={searchQuery}
onChange={(event) => setSearchQuery(event.currentTarget.value)}
mb="md"
/>
<AppShell.Section grow component={ScrollArea} mx="-xs" px="xs">
{Object.values(editors)
.flatMap((g: any) => g.projects)
.filter((editor) =>
editor.title
.toLowerCase()
.includes(searchQuery.toLowerCase()),
)
.map((editor, i) => (
<div key={i}>
<Link to={editor.fullSlug}>{editor.title}</Link>
</div>
))}
{/* manitne <NavLink
styles={linkStyles}
label="Simple"
onClick={navi}
// icon={<IconGauge size={16} stroke={1.5} />}
// rightSection={<IconChevronRight size={12} stroke={1.5} />}
/>
<NavLink
styles={linkStyles}
label="Two"
// icon={<IconGauge size={16} stroke={1.5} />}
// rightSection={<IconChevronRight size={12} stroke={1.5} />}
/> */}
</AppShell.Section>
</AppShell.Navbar>
)}
<AppShell.Main>
<Outlet />
</AppShell.Main>
</AppShell>
</MantineProvider>
);
}
const App = (props: { project: (typeof examples.basic)["projects"][0] }) => {
const [ExampleComponent, setExampleComponent] = React.useState<any>(null);
React.useEffect(() => {
void (async () => {
// load app async
const moduleName = "../../" + props.project.pathFromRoot + "/src/App.tsx";
const module = modules[moduleName];
const c: any = await module();
setExampleComponent(c);
})();
}, [props.project.pathFromRoot]);
if (!ExampleComponent) {
return <div>Loading...</div>;
}
// eslint-disable-next-line react/jsx-pascal-case
return <ExampleComponent.default />;
};
const router = createBrowserRouter([
{
path: "/",
element: <Root />,
children: Object.values(editors)
.flatMap((g: any) => g.projects)
.map((editor) => ({
path: editor.fullSlug,
element: <App project={editor} />,
})),
},
]);
const root = createRoot(document.getElementById("root")!);
root.render(<RouterProvider router={router} />);