-
Notifications
You must be signed in to change notification settings - Fork 646
Expand file tree
/
Copy pathLayout.js
More file actions
110 lines (100 loc) · 2.63 KB
/
Layout.js
File metadata and controls
110 lines (100 loc) · 2.63 KB
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
import { graphql, Link, withPrefix } from 'gatsby';
import PropTypes from 'prop-types';
import React from 'react';
import { Navbar, Nav } from 'react-bootstrap';
import '../css/bootstrap.scss';
import '../css/prism-theme.scss';
const propTypes = {
data: PropTypes.shape({
site: PropTypes.shape({
siteMetadata: PropTypes.shape({
componentPages: PropTypes.arrayOf(
PropTypes.shape({
path: PropTypes.string.isRequired,
displayName: PropTypes.string.isRequired,
})
).isRequired,
}).isRequired,
}).isRequired,
}).isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired,
}).isRequired,
};
const NavItem = ({ to, location, children }) => (
<li role="presentation">
<Link
to={to}
location={location}
activeStyle={{
color: '#fff',
backgroundColor: '#080808',
}}
>
{children}
</Link>
</li>
);
NavItem.propTypes = {
to: PropTypes.string.isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired,
}).isRequired,
children: PropTypes.node.isRequired,
};
class Layout extends React.Component {
isActive(path, location) {
return withPrefix(path) === withPrefix(location.pathname);
}
render() {
const { data, children } = this.props;
const location = {
...this.props.location,
pathname: withPrefix(this.props.location.pathname),
};
return (
<div>
<Navbar fixedTop inverse collapseOnSelect>
<Navbar.Header>
<Navbar.Brand>
<Link to="/">React Transition Group</Link>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullLeft>
{data.site.siteMetadata.componentPages.map(
({ path, displayName }) => (
<NavItem key={path} to={path} location={location}>
{displayName}
</NavItem>
)
)}
</Nav>
<Nav pullRight>
<NavItem to="/with-react-router" location={location}>
With React Router
</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
<div style={{ paddingTop: '4rem', paddingBottom: '1.5rem' }}>
{children}
</div>
</div>
);
}
}
Layout.propTypes = propTypes;
export default Layout;
export const exposedComponentsFragment = graphql`
fragment Layout_site on Site {
siteMetadata {
componentPages {
path
displayName
codeSandboxId
}
}
}
`;