2018-07-25 07:47:26 -04:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import Link from 'gatsby-link';
|
|
|
|
import classnames from 'classnames';
|
2018-08-23 17:58:38 -04:00
|
|
|
import { Location } from '@reach/router';
|
2018-07-25 07:47:26 -04:00
|
|
|
|
|
|
|
import DocSearch from './docsearch';
|
|
|
|
|
|
|
|
import logo from '../img/netlify-cms-logo.svg';
|
|
|
|
|
|
|
|
import '../css/imports/header.css';
|
|
|
|
|
|
|
|
class Header extends Component {
|
|
|
|
state = {
|
2018-08-07 14:46:54 -06:00
|
|
|
scrolled: false,
|
2018-07-25 07:47:26 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
// TODO: use raf to throttle events
|
|
|
|
window.addEventListener('scroll', this.handleScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('scroll', this.handleScroll);
|
|
|
|
}
|
|
|
|
|
2018-08-07 09:53:31 -06:00
|
|
|
handleScroll = () => {
|
2018-08-07 14:46:54 -06:00
|
|
|
const currentWindowPos = document.documentElement.scrollTop || document.body.scrollTop;
|
2018-07-25 07:47:26 -04:00
|
|
|
|
|
|
|
const scrolled = currentWindowPos > 0;
|
|
|
|
|
|
|
|
this.setState({
|
2018-08-07 14:46:54 -06:00
|
|
|
scrolled,
|
2018-07-25 07:47:26 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { scrolled } = this.state;
|
|
|
|
|
|
|
|
return (
|
2018-08-23 17:58:38 -04:00
|
|
|
<Location>
|
|
|
|
{({ location }) => {
|
|
|
|
const isDocs = location.pathname.indexOf('docs') !== -1;
|
|
|
|
const isBlog = location.pathname.indexOf('blog') !== -1;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<header
|
|
|
|
id="header"
|
|
|
|
className={classnames({
|
|
|
|
docs: isDocs,
|
|
|
|
blog: isBlog,
|
|
|
|
scrolled,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<div className="contained">
|
|
|
|
<div className="logo-container">
|
|
|
|
<Link to="/" className="logo">
|
|
|
|
<img src={logo} />
|
|
|
|
</Link>
|
|
|
|
{isDocs && <DocSearch />}
|
|
|
|
</div>
|
|
|
|
<div className="nav-container">
|
|
|
|
<Link className="nav-link docs-link" to="/docs/intro">
|
|
|
|
Docs
|
|
|
|
</Link>
|
|
|
|
<Link className="nav-link contributing-link" to="/docs/contributor-guide">
|
|
|
|
Contributing
|
|
|
|
</Link>
|
|
|
|
<Link className="nav-link" to="/community">
|
|
|
|
Community
|
|
|
|
</Link>
|
|
|
|
<Link className="nav-link" to="/blog">
|
|
|
|
Blog
|
|
|
|
</Link>
|
|
|
|
<span className="gh-button">
|
|
|
|
<a
|
|
|
|
id="ghstars"
|
|
|
|
className="github-button"
|
|
|
|
href="https://github.com/netlify/netlify-cms"
|
|
|
|
data-icon="octicon-star"
|
|
|
|
data-show-count="true"
|
|
|
|
aria-label="Star netlify/netlify-cms on GitHub"
|
|
|
|
>
|
|
|
|
Star
|
|
|
|
</a>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Location>
|
2018-07-25 07:47:26 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Header;
|