/
DendronLayout.tsx
192 lines (185 loc) · 5.44 KB
/
DendronLayout.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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import { MenuOutlined } from "@ant-design/icons";
import { ConfigUtils, IntermediateDendronConfig } from "@dendronhq/common-all";
import { Col, Divider, Layout, Row } from "antd";
import Script from "next/script";
import * as React from "react";
import { useEngineAppSelector } from "../features/engine/hooks";
import { DENDRON_STYLE_CONSTANTS } from "../styles/constants";
import { DendronCommonProps } from "../utils/types";
import { DendronBreadCrumb } from "./DendronBreadCrumb";
import DendronLogoOrTitle from "./DendronLogoOrTitle";
import { FooterText } from "./DendronNoteFooter";
import { DendronSearch } from "./DendronSearch";
import DendronTreeMenu from "./DendronTreeMenu";
const { Header, Content, Sider, Footer } = Layout;
const { LAYOUT, HEADER, SIDER } = DENDRON_STYLE_CONSTANTS;
export default function DendronLayout(
props: React.PropsWithChildren<DendronCommonProps>
) {
const [isCollapsed, setCollapsed] = React.useState(false);
const [isResponsive, setResponsive] = React.useState(false);
const sidebar = (
<Sider
width={isResponsive ? "100%" : SIDER.WIDTH}
collapsible
collapsed={isCollapsed && isResponsive}
collapsedWidth={SIDER.COLLAPSED_WIDTH}
onCollapse={(collapsed) => {
setCollapsed(collapsed);
}}
breakpoint="sm"
onBreakpoint={(broken) => {
setResponsive(broken);
}}
style={{
position: "fixed",
overflow: "auto",
height: `calc(100vh - ${HEADER.HEIGHT}px)`,
}}
trigger={null}
>
{isResponsive && (
<div style={{ padding: 16 }}>
<DendronSearch {...props} />
</div>
)}
<DendronTreeMenu
{...props}
collapsed={isCollapsed && isResponsive}
setCollapsed={setCollapsed}
/>
</Sider>
);
const content = (
<>
<Content
className="main-content"
role="main"
style={{ padding: `0 ${LAYOUT.PADDING}px` }}
>
<DendronBreadCrumb {...props} />
{props.children}
</Content>
<Divider />
<Footer
style={{
padding: `0 ${LAYOUT.PADDING}px ${LAYOUT.PADDING}px`,
}}
>
<FooterText />
</Footer>
</>
);
const engine = useEngineAppSelector((state) => state.engine);
const config = engine.config as IntermediateDendronConfig;
const enableMermaid = ConfigUtils.getProp(config, "mermaid");
return (
<Layout
style={{
width: "100%",
minHeight: "100%",
}}
>
{enableMermaid && (
<Script
id="initmermaid"
src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"
onLoad={() => {
const mermaid = (window as any).mermaid;
// save for debugging
// when trying to access mermaid in DOM, <div id="mermaid"></div> gets returned
// we disambiguate by saving a copy of mermaid
(window as any)._mermaid = mermaid;
mermaid.initialize({
startOnLoad: false,
});
// initialize
mermaid.init();
}}
/>
)}
<Header
style={{
position: "fixed",
isolation: "isolate",
zIndex: 1,
width: "100%",
borderBottom: "1px solid #d4dadf",
height: HEADER.HEIGHT,
padding: isResponsive ? 0 : `0 ${LAYOUT.PADDING}px 0 2px`,
}}
>
<Row
justify="center"
style={{
maxWidth: "992px",
justifyContent: "space-between",
margin: "0 auto",
}}
>
<Col xs={4}>
<DendronLogoOrTitle />
</Col>
<Col xs={0} sm={20} md={20} lg={19} className="gutter-row">
<DendronSearch {...props} />
</Col>
<Col xs={12} />
<Col
xs={4}
sm={4}
md={0}
lg={0}
style={{
marginLeft: "4px",
display: isResponsive ? "flex" : "none",
alignItems: "center",
justifyContent: "center",
}}
>
<MenuOutlined
style={{ fontSize: 24 }}
onClick={() => setCollapsed(!isCollapsed)}
/>
</Col>
</Row>
</Header>
<Layout
className="site-layout"
style={{
marginTop: 64,
}}
>
<Layout className="site-layout" style={{ flexDirection: "row" }}>
<Layout
className="site-layout-sidebar"
style={{
flex: "0 0 auto",
width: `calc((100% - ${LAYOUT.BREAKPOINTS.lg}) / 2 + ${
// eslint-disable-next-line no-nested-ternary
isResponsive
? isCollapsed
? SIDER.COLLAPSED_WIDTH
: "100%"
: SIDER.WIDTH
}px)`,
minWidth: isResponsive || isCollapsed ? 0 : SIDER.WIDTH,
paddingLeft: `calc((100% - ${LAYOUT.BREAKPOINTS.lg}) / 2)`,
// eslint-disable-next-line no-nested-ternary
}}
>
{sidebar}
</Layout>
<Layout
className="side-layout-main"
style={{
maxWidth: "1200px",
display: !isCollapsed && isResponsive ? "none" : "initial",
}}
>
{content}
</Layout>
</Layout>
</Layout>
</Layout>
);
}