-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPageLayout.tsx
122 lines (119 loc) · 3.05 KB
/
PageLayout.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
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
import React, { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { Link, NavLink, Outlet, useSearchParams } from "react-router-dom";
export default function PageLayout(props: {}) {
const [searchParams, setSearchParams] = useSearchParams();
// bg & color
const prevBgColor = useRef<string[]>();
const bgColor = useMemo(() => [
searchParams.get('bg') || prevBgColor.current?.[0] || '#fff9e6',
searchParams.get('color') || prevBgColor.current?.[1] || '#000'
], [searchParams]);
prevBgColor.current = bgColor;
// iframe id
const [iframeId, setiframeId] = useState(searchParams.get('iframe_id')!);
const [menu, setmenu] = useState(() => [
{
title: 'Base - Flat Data',
path: '/base_flat_data',
},
{
title: 'Base - Tree Data',
path: '/base_tree_data',
},
{
title: 'Custom Drag Trigger',
path: '/custom_drag_trigger_flat_data',
},
{
title: 'Open',
path: '/open_ids',
},
{
title: 'Checked',
path: '/checked_ids',
},
{
title: 'Update Data',
path: '/update_data',
},
{
title: 'Update Flat Data With Immer',
path: '/update_flat_data_with_immer',
},
{
title: 'Update Tree Data With Immer',
path: '/update_tree_data_with_immer',
},
{
title: 'Customize Placeholder and Node Box',
path: '/customize_placeholder_and_node_box',
},
{
title: 'Draggable & Droppable',
path: '/draggable_droppable'
},
{
title: 'Open Node when Drag over',
path: '/dragopen'
},
{
title: 'Drag and Drop to External',
path: '/external_drag'
},
{
title: 'Big Data with Virtual List',
path: '/virtual_list'
},
{
title: 'Scroll to Node',
path: '/scroll_to_node',
},
{
title: 'Custom Style',
path: '/custom_style',
},
{
title: 'Home',
path: '/',
},
]);
useLayoutEffect(() => {
const { ResizeObserver } = window
const observer = ResizeObserver && new ResizeObserver(() => {
window.parent.postMessage({ type: 'iframeHeight', height: document.body.offsetHeight, id: iframeId }, '*')
})
// observer is undefined in test environment
observer?.observe(document.body)
return () => {
observer?.disconnect()
}
}, [])
return <div className="page-layout">
<Outlet />
<div className="main-menu fixed top-1 right-2 px-4 py-4 bg-gray-100 max-md:hidden">
<div className="text-xl font-bold mb-5 text-black">Menu</div>
{menu.map((item, index) => <div key={index} className="menu-item py-1">
<NavLink to={item.path}>{item.title}</NavLink>
</div>
)}
</div>
<style>{`
body{
margin: 0;
background-color: ${bgColor[0]};
color: ${bgColor[1]};
}
.main-menu{
}
.main-menu a{
text-decoration: none;
}
.main-menu a.active{
font-weight: bold;
}
.main-menu a:hover{
text-decoration: underline;
}
`}</style>
</div>
}