/
index.tsx
230 lines (227 loc) · 8.82 KB
/
index.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import React from "react";
import {
Box,
Collapse,
Grid,
Heading,
Hide,
Stack,
Text,
ThemeProvider,
} from "@kiwicom/orbit-components";
import { MDXProvider } from "@mdx-js/react";
import { WindowLocation } from "@reach/router";
import { css } from "styled-components";
import theme from "../../theme";
import * as components from "../../mdx-components";
import { DevModeProvider } from "../../hooks/useDevMode";
import Head from "../Head";
import BaseStyles from "../BaseStyles";
import AddBookmark from "../AddBookmark";
import FancyLink from "../FancyLink";
import Guideline from "../Guidelines";
import InlineToken from "../InlineToken";
import GuidelinesSideBySide, { Do, Dont } from "../Guidelines/GuidelinesSideBySide";
import GuidelineImages, { DoImage, DontImage } from "../Guidelines/GuidelineImages";
import HeaderLink from "../HeaderLink";
import ImageContainer from "../ImageContainer";
import Navbar from "../Navbar";
import { BookmarkProvider } from "../../services/bookmarks";
import DocNavigation from "../DocNavigation";
import Breadcrumbs from "../Breadcrumbs";
import ComponentStatus from "../ComponentStatus";
import TableOfContents, { TocItemObject } from "../TableOfContents";
import Tabs, { TabObject } from "../Tabs";
import ReactExample from "../ReactExample";
import Footer from "../Footer";
import StyledWrapper from "./primitives/StyledWrapper";
import StyledMiddle from "./primitives/StyledMiddle";
import StyledMain from "./primitives/StyledMain";
import StyledMobileOutdent from "./primitives/StyledMobileOutdent";
import StyledDocNavigationWidth from "./primitives/StyledDocNavigationWidth";
import StyledDocNavigationWrapper from "./primitives/StyledDocNavigationWrapper";
import StyledTocWrapper from "./primitives/StyledTocWrapper";
import StyledProse from "./primitives/StyledProse";
import { getDocumentPageTitle } from "../../utils/document";
interface Props {
children: React.ReactNode;
description?: string;
headerLink?: string;
location: WindowLocation;
noElevation?: boolean;
path: string;
tableOfContents?: TocItemObject[];
tabs?: TabObject[];
title?: string;
trail?: Array<{
name: string;
url: string;
}>;
custom?: boolean;
}
export default function DocLayout({
children,
description,
headerLink,
location,
noElevation,
path,
tableOfContents = [],
tabs,
title,
trail,
custom,
}: Props) {
const Toc = <TableOfContents items={tableOfContents} />;
const tocHasItems = tableOfContents?.length > 0;
return (
<>
<Head
title={title ? getDocumentPageTitle(title, trail ? trail.map(t => t.name) : []) : "Orbit"}
hasSiteName={Boolean(title)}
description={description}
path={path}
/>
<ThemeProvider theme={theme}>
<DevModeProvider>
<BookmarkProvider page={path} location={location}>
<BaseStyles />
<StyledWrapper>
<Navbar
location={location}
docNavigation={
<DocNavigation
currentUrl={path}
onCollapse={() => {
// hack for when collapsing an overflowing DocNavigationItem in Modal
// causes the fixed ModalFooter to be stuck at the bottom of the screen
setTimeout(() => {
// causing Modal to reposition ModalFooter
window.dispatchEvent(new Event("resize"));
}, 70); // not sure why, but this delay is necessary (the exact threshold is 62)
}}
/>
}
/>
<StyledMiddle>
<Hide block on={["smallMobile", "mediumMobile", "largeMobile", "tablet"]}>
<StyledDocNavigationWidth>
<StyledDocNavigationWrapper>
<DocNavigation currentUrl={path} />
</StyledDocNavigationWrapper>
</StyledDocNavigationWidth>
</Hide>
<StyledMain>
{custom ? (
<StyledProse
padding={
noElevation
? { top: "none", bottom: "XLarge", left: "XLarge", right: "XLarge" }
: { top: "XLarge", bottom: "XXLarge", left: "XLarge", right: "XLarge" }
}
elevation={noElevation ? undefined : "raised"}
>
{children}
</StyledProse>
) : (
<>
{trail && <Breadcrumbs trail={trail} />}
<Box padding={{ bottom: "XLarge" }}>
<Stack inline align="center" spaceAfter="small">
<AddBookmark />
<div
css={css`
/* align with the bookmark icon */
position: relative;
top: 1px;
`}
>
<Heading as="h1" type="title1">
{title}
</Heading>
</div>
</Stack>
{description && (
<Box padding={{ left: "XXLarge" }}>
<Text>{description}</Text>
</Box>
)}
</Box>
<StyledMobileOutdent>
{(tabs || headerLink) && (
<Box
display="flex"
align="end"
justify={tabs && tabs.length > 0 ? "between" : "end"}
tablet={{ maxWidth: tocHasItems ? "80%" : "100%" }}
>
{tabs && <Tabs activeTab={location.pathname} tabs={tabs} />}
{headerLink && (
// align with tabs
<Box padding={{ bottom: "XXSmall" }}>
<HeaderLink href={headerLink} />
</Box>
)}
</Box>
)}
<Grid
columns="1fr"
tablet={{ columns: `${tocHasItems ? "80% 20%" : "100%"}` }}
>
{tocHasItems && (
<StyledTocWrapper>
<Hide on={["smallMobile", "mediumMobile", "largeMobile"]}>{Toc}</Hide>
</StyledTocWrapper>
)}
<StyledProse
padding={
noElevation
? { top: "none", bottom: "XLarge", left: "XLarge", right: "XLarge" }
: {
top: "XLarge",
bottom: "XXLarge",
left: "XLarge",
right: "XLarge",
}
}
elevation={noElevation ? undefined : "raised"}
>
{tocHasItems && (
<Hide on={["tablet", "desktop", "largeDesktop"]}>
<Collapse label="Table of contents">{Toc}</Collapse>
</Hide>
)}
<MDXProvider
components={{
...components,
ComponentStatus,
FancyLink,
Guideline,
GuidelineImages,
DoImage,
DontImage,
GuidelinesSideBySide,
Do,
Dont,
ImageContainer,
InlineToken,
ReactExample,
}}
>
{children}
</MDXProvider>
</StyledProse>
</Grid>
</StyledMobileOutdent>
</>
)}
</StyledMain>
</StyledMiddle>
<Footer hasGradient={!noElevation} />
</StyledWrapper>
</BookmarkProvider>
</DevModeProvider>
</ThemeProvider>
</>
);
}