-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathHeader.tsx
More file actions
114 lines (98 loc) · 2.63 KB
/
Header.tsx
File metadata and controls
114 lines (98 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
111
112
113
114
import * as React from 'react'
import { NavLink } from 'react-router-dom'
import styled from '../../utils/styled'
import LayoutContainer from '../../containers/LayoutContainer'
import Container from './Container'
interface HeaderProps {
title: string
}
const Wrapper = styled('header')`
padding: 0.5rem 1.5rem;
background-color: ${props => props.theme.colors.brand};
color: ${props => props.theme.colors.white};
font-family: ${props => props.theme.fonts.headings};
`
const HeaderInner = styled(Container)`
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
@media (min-width: ${props => props.theme.breakpoints.lg}) {
flex-direction: row;
}
`
const HeaderLeft = styled('div')`
padding-right: 1rem;
`
const HeaderNav = styled('nav')`
flex: 1 1 auto;
margin: 1rem 0;
@media (min-width: ${props => props.theme.breakpoints.lg}) {
margin: 0;
}
`
const HeaderNavLink = styled(NavLink)`
margin: 0 1rem;
&.is-active {
text-decoration: underline;
}
`
const HeaderRight = styled('div')`
padding-left: 1rem;
`
const Title = styled('h2')`
margin: 0;
font-weight: 500;
`
const CurrentTheme = styled('span')`
margin-right: 1rem;
`
const ThemeSwitcherButton = styled('button')`
display: inline-block;
padding: 0.25rem 0.5rem;
border: 1px solid ${props => props.theme.colors.white};
border-radius: 3px;
background-color: ${props => props.theme.colors.white};
color: ${props => props.theme.colors.brand};
font-size: 0.8rem;
text-transform: uppercase;
letter-spacing: 1px;
cursor: pointer;
transition: all 0.3s ease;
&:hover,
&:focus {
background-color: transparent;
color: ${props => props.theme.colors.white};
}
`
const Header: React.SFC<HeaderProps> = ({ title }) => (
<Wrapper>
<HeaderInner>
<HeaderLeft>
<Title>{title}</Title>
</HeaderLeft>
<HeaderNav>
<HeaderNavLink exact to="/" activeClassName="is-active">
Home
</HeaderNavLink>
<HeaderNavLink to="/heroes" activeClassName="is-active">
Heroes
</HeaderNavLink>
<HeaderNavLink to="/teams" activeClassName="is-active">
Teams
</HeaderNavLink>
</HeaderNav>
<HeaderRight>
<LayoutContainer>
{({ theme, setTheme }) => (
<>
<CurrentTheme>Current theme: {theme}</CurrentTheme>
<ThemeSwitcherButton onClick={() => setTheme(theme === 'light' ? 'dark' : 'light')}>Switch theme</ThemeSwitcherButton>
</>
)}
</LayoutContainer>
</HeaderRight>
</HeaderInner>
</Wrapper>
)
export default Header