forked from mightymeld/prefabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.tsx
75 lines (70 loc) · 1.67 KB
/
app.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import React from 'react'
import { createRoot } from 'react-dom/client'
import { ErrorBoundary } from 'react-error-boundary'
import * as Chakra from './src/Chakra'
import * as Chakra_Icons from './src/Chakra_Icons'
import * as HTML from './src/HTML'
import * as MUI from './src/MUI'
import * as React_Router from './src/React_Router'
import * as Ant_Design from './src/Ant_Design'
import * as Tailwind from './src/Tailwind'
import * as Radix from './src/Radix_UI'
const PREFABS = {
Chakra,
Chakra_Icons,
HTML,
MUI,
React_Router,
Ant_Design,
Tailwind,
Radix
}
const IGNORED = {
MUI: ['_Backdrop'],
}
const domNode = document.getElementById('root')
const root = createRoot(domNode)
root.render(<App />)
function App() {
const url = new URL(window.location.href)
const prefabName = url.searchParams.get('prefab') || Object.keys(PREFABS)[0]
const prefab = PREFABS[prefabName]
if (!prefab) {
return <h1>Not found</h1>
}
return (
<>
<nav>
<ul>
{Object.keys(PREFABS).map((name) => {
return (
<li key={name}>
<a href={`?prefab=${name}`}>{name}</a>
</li>
)
})}
</ul>
</nav>
<main>
{Object.entries(prefab).map(([name, Component]: [string, any]) => {
return (
<div key={name}>
<h2>{name.replace(/_+/g, ' ').split('$')[0]}</h2>
<div className="item">
{IGNORED[prefabName]?.includes(name) ? (
<p className="error">Ignoring “{name}”</p>
) : (
<ErrorBoundary
fallbackRender={({ error: e }) => <p className="error">{e.message}</p>}
>
<Component />
</ErrorBoundary>
)}
</div>
</div>
)
})}
</main>
</>
)
}