blob: 37356a6a47a05440c2069b28b03ea54391f49478 (
plain)
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
|
import React from 'react'
import styled from 'styled-components'
import {Flex, Image, Box} from 'rebass'
import cliLogo from '../images/cli-logo.svg'
import {Link} from 'gatsby'
import {NavLink, BasicNavLink} from './links'
import MobileSidebar from '../components/MobileSidebar'
import hamburger from '../images/hamburger.svg'
import hamburgerClose from '../images/hamburger-close.svg'
const IS_STATIC = !!process.env.GATSBY_IS_STATIC
const Container = styled(Flex)`
width: 100%;
border-bottom: 1px solid #86838333;
position: sticky;
top: 0;
background-color: ${(props) => props.theme.colors.white};
z-index: 1;
`
const Inner = styled(Flex)`
border-top: 3px solid;
border-image: linear-gradient(139deg, #fb8817, #ff4b01, #c12127, #e02aff) 3;
margin: auto;
height: 53px;
padding: 0 30px;
align-items: center;
width: 100%;
`
const Logo = styled(Image)`
width: 120px;
padding: 0px 5px;
height: 18px;
vertical-align: middle;
display: inline-block;
transition: opacity .5s;
&:hover {
opacity: .8;
}
`
const Links = styled.ul`
display: none;
@media screen and (min-width: ${(props) => props.theme.breakpoints.TABLET}) {
display: block;
margin-left: auto;
}
`
const Heart = styled(Box)`
font-size: 15px;
display: inline-block;
`
const Hamburger = styled.button`
border: none;
background: center no-repeat url(${(props) => props.isOpen ? hamburgerClose : hamburger});
height: 30px;
width: 30px;
display: block;
margin-left: auto;
transition: opacity .5s;
cursor: pointer;
&:hover {
opacity: .6;
}
@media screen and (min-width: ${(props) => props.theme.breakpoints.TABLET}) {
display: none;
}
`
class Navbar extends React.Component {
constructor (props) {
super(props)
this.state = {
value: null,
showMobileNav: false
}
this.enableBody = this.enableBody.bind(this)
this.toggleNav = this.toggleNav.bind(this)
}
componentDidMount () {
window.addEventListener('resize', () => {
this.enableBody()
this.setState({showMobileNav: false})
})
}
componentWillUnmount () {
this.enableBody()
}
enableBody () {
window.document.getElementsByTagName('body')[0].classList.remove('disabled-body')
}
toggleNav () {
this.setState({showMobileNav: !this.state.showMobileNav})
window.document.getElementsByTagName('body')[0].classList.toggle('disabled-body')
}
render () {
return (
<React.Fragment>
<Container>
<Inner>
<Link to='/'>
<Heart ml={1} mr={'24px'}>❤</Heart><Logo src={cliLogo} />
</Link>
<Links>
<NavLink
to={`cli-commands/npm${IS_STATIC ? '/index.html' : ''}`}
partiallyActive
activeClassName='active-navbar-link'
>
docs
</NavLink>
<BasicNavLink href='https://www.npmjs.com/'>npmjs.org</BasicNavLink>
</Links>
<Hamburger isOpen={this.state.showMobileNav} onClick={this.toggleNav} />
</Inner>
</Container>
{this.state.showMobileNav && <MobileSidebar />}
</React.Fragment>
)
}
}
export default Navbar
|