forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.jsx
More file actions
106 lines (91 loc) · 2.13 KB
/
Header.jsx
File metadata and controls
106 lines (91 loc) · 2.13 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
import React from 'react';
import PropTypes from 'prop-types';
import styled, { css } from 'styled-components';
import { Route, withRouter, NavLink as Link } from 'react-router-dom';
import Toggle from './Toggle';
import Title from './Title';
const StyledHeader = styled.header`
align-items: center;
display: flex;
flex-wrap: wrap;
justify-content: start;
margin-top: 1rem;
@media (min-width: 769px) {
justify-content: space-between;
}
`;
const StyledLinkContainer = styled.div`
display: inline-flex;
`;
const StyledSettingsContainer = styled.div`
display: inline-flex;
margin: 1rem 0;
width: 100%;
@media (min-width: 541px) {
margin: 0;
width: auto;
}
`;
const linkStyle = css`
border-bottom: 1px solid ${props => props.theme.link};
color: ${props => props.theme.link};
display: inline-flex;
font-size: 0.875rem;
margin: 0.5rem 2rem 0 0;
padding-bottom: 1px;
text-decoration: none;
`;
const StyledRouterLink = styled(Link)`
${linkStyle}
&:hover {
border-bottom: none;
}
`;
const StyledRouterSpan = styled.span`
${linkStyle}
border-bottom: none;
color: ${props => props.theme.active};
`;
const Header = props => {
const {
location: { pathname }
} = props;
const paths = [
{
path: '/',
page: 'Game'
},
{
path: '/patterns',
page: 'Pattern Reference'
},
{
path: '/about',
page: 'About'
}
];
return (
<StyledHeader>
<StyledLinkContainer>
{paths.map(({ path, page }) =>
pathname === path || (path === '/patterns' && pathname.includes(path)) ? (
<StyledRouterSpan key={page}>{page}</StyledRouterSpan>
) : (
<StyledRouterLink key={page} to={path}>
{page}
</StyledRouterLink>
)
)}
</StyledLinkContainer>
<StyledSettingsContainer>
<Route exact path="/" render={() => <Toggle control="js" />} />
<Toggle control="mode" />
</StyledSettingsContainer>
<Title />
</StyledHeader>
);
};
Header.propTypes = {
location: PropTypes.object.isRequired
};
export default withRouter(Header);