-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathDocsLayout.js
86 lines (71 loc) · 2.18 KB
/
DocsLayout.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
import AnchorJS from 'anchor-js'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { Head, withRouter } from 'react-static'
import { Grid } from 'semantic-ui-react'
import style from 'docs/src/Style'
import { scrollToAnchor } from 'docs/src/utils'
import { isBrowser } from 'src/lib'
const anchors = new AnchorJS({
icon: '#',
})
class DocsLayout extends Component {
componentDidMount() {
this.resetPage()
}
componentDidUpdate() {
this.resetPage()
}
componentWillUnmount() {
clearTimeout(this.scrollStartTimeout)
}
resetPage = () => {
const { location } = this.props
// only reset the page when changing routes
if (this.pathname === location.pathname) return
clearTimeout(this.scrollStartTimeout)
if (isBrowser()) window.scrollTo(0, 0)
anchors.add('h2, h3, h4, h5, h6')
anchors.remove([1, 2, 3, 4, 5, 6].map((n) => `.rendered-example h${n}`).join(', '))
anchors.remove('.no-anchor')
this.scrollStartTimeout = setTimeout(scrollToAnchor, 500)
this.pathname = location.pathname
}
render() {
const { additionalTitle, children, sidebar, title } = this.props
const bottomColumnWidth = sidebar
? { computer: 11, largeScreen: 12, widescreen: 12 }
: { width: 16 }
const mainStyle = sidebar ? style.sidebarMain : style.main
return (
<>
<Head>
<title>
{additionalTitle ? `${additionalTitle} - ` : ''}
{title}
</title>
</Head>
<div style={mainStyle}>
{children}
<Grid>
<Grid.Column {...bottomColumnWidth} textAlign='center'>
Blazing deployments by{' '}
<a href='https://vercel.com/?utm_source=semantic-ui-react'>
<img height='12' width='14' alt="Vercel-Logo" src='/vercel-logo.svg' /> Vercel
</a>
.
</Grid.Column>
</Grid>
</div>
</>
)
}
}
DocsLayout.propTypes = {
additionalTitle: PropTypes.string,
children: PropTypes.node,
location: PropTypes.object.isRequired,
sidebar: PropTypes.bool,
title: PropTypes.string.isRequired,
}
export default withRouter(DocsLayout)