/
SideNav.js
268 lines (236 loc) · 5.94 KB
/
SideNav.js
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import startCase from 'lodash/startCase';
import classNames from 'classnames';
import React from 'react';
import Nav from 'react-bootstrap/Nav';
import FormControl from 'react-bootstrap/FormControl';
import styled from 'astroturf';
import Button from 'react-bootstrap/Button';
import Collapse from 'react-bootstrap/Collapse';
const MenuButton = styled(Button).attrs({ variant: 'link' })`
composes: p-0 d-md-none ml-3 from global;
line-height: 1;
color: #212529;
`;
const SidePanel = styled('div')`
@import '../css/theme';
$top: 4rem;
composes: d-flex flex-column from global;
background-color: #f7f7f7;
@include media-breakpoint-up(md) {
position: sticky;
top: $top;
z-index: 1000;
height: calc(100vh - #{$top});
background-color: #f7f7f7;
border-right: 1px solid $divider;
}
& > * + * {
border-top: 1px solid $divider;
}
`;
const OverflowWrapper = styled('div')`
@import '../css/theme';
@include media-breakpoint-up(md) {
overflow: hidden;
display: block !important;
height: 100% !important;
}
`;
const TableOfContents = styled('nav')`
@import '../css/theme';
composes: pt-2 pb-4 from global;
@include media-breakpoint-up(md) {
height: 100% !important;
overflow: auto;
margin-right: -40px;
padding-right: calc(40px + 1rem);
}
`;
const TocLink = styled(Nav.Link)`
@import '../css/theme';
&.active,
&:global(.active) {
font-weight: 500;
color: $text !important;
}
&.active {
margin-top: 1rem;
& + * {
margin-bottom: 1rem;
}
}
&,
&:hover,
&:focus,
&:active {
text-decoration: none;
color: transparentize($text, 0.25);
transition: color 0.2s ease-out;
}
&:hover,
&:focus,
&:active {
text-decoration: none;
color: $subtle-on-dark;
}
`;
const TocSubLink = styled(TocLink)`
font-size: 90%;
padding-top: 0.25rem;
`;
const gettingStarted = [
'introduction',
'why-react-bootstrap',
'theming',
'support',
];
const layout = ['grid', 'media'];
const components = [
'alerts',
'accordion',
'badge',
'breadcrumb',
'buttons',
'button-group',
'cards',
'carousel',
'dropdowns',
'forms',
'input-group',
'images',
'figures',
'jumbotron',
'list-group',
'modal',
'navs',
'navbar',
'overlays',
'pagination',
'popovers',
'progress',
'spinners',
'table',
'tabs',
'tooltips',
'toasts',
];
const utilities = ['transitions', 'responsive-embed', 'react-overlays'];
// We need to configure this
function attachSearch(ref) {
if (ref && window)
import('docsearch.js').then(({ default: docsearch }) => {
docsearch({
apiKey: '00f98b765b687b91399288e7c4c68ce1',
indexName: 'react_bootstrap_v4',
inputSelector: `#${ref.id}`,
debug: process.env.NODE_ENV !== 'production', // Set debug to true if you want to inspect the dropdown
});
});
}
function NavSection({ heading, location: { pathname }, items, path }) {
let active = pathname.startsWith(path);
return (
<>
<TocLink
active={active}
href={items ? `${path}/${items[0]}/` : `${path}/`}
className={classNames(
'js-search-toc-item',
active && 'js-search-active',
)}
>
{heading}
</TocLink>
{items && active && (
<Nav activeKey={pathname} onSelect={() => {}} className="d-block">
{items.map((name) => (
<Nav.Item key={`${path}/${name}/`}>
<TocSubLink href={`${path}/${name}/`}>
{startCase(name.toLowerCase()).replace(
'React Bootstrap',
'React-Bootstrap',
)}
</TocSubLink>
</Nav.Item>
))}
</Nav>
)}
</>
);
}
class SideNav extends React.Component {
state = { collapsed: false };
handleCollapse = () => {
this.setState((s) => ({ collapsed: !s.collapsed }));
};
render() {
const { location, ...props } = this.props;
return (
<SidePanel {...props}>
<form className="py-3 d-flex align-items-center">
<FormControl
id="docs-search-input"
type="text"
placeholder="Search…"
ref={attachSearch}
/>
<MenuButton onClick={this.handleCollapse}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 30 30"
width="30"
height="30"
focusable="false"
>
<title>Menu</title>
<path
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeMiterlimit="10"
d="M4 7h22M4 15h22M4 23h22"
/>
</svg>
</MenuButton>
</form>
<Collapse in={this.state.collapsed}>
<OverflowWrapper>
<TableOfContents role="complementary">
<NavSection
heading="Getting started"
path="/getting-started"
location={location}
items={gettingStarted}
/>
<NavSection
heading="Layout"
location={location}
items={layout}
path="/layout"
/>
<NavSection
heading="Components"
location={location}
items={components}
path="/components"
/>
<NavSection
heading="Utilities"
location={location}
items={utilities}
path="/utilities"
/>
<NavSection
heading="Migrating"
location={location}
path="/migrating"
/>
<NavSection heading="About" location={location} path="/about" />
</TableOfContents>
</OverflowWrapper>
</Collapse>
</SidePanel>
);
}
}
export default SideNav;