diff --git a/src/components/Nav.js b/src/components/Nav.js index d2ea1a5e..a2137621 100644 --- a/src/components/Nav.js +++ b/src/components/Nav.js @@ -5,6 +5,9 @@ import { breakpoints, colors } from '../utils/variables' import Hamburger from '../resources/hamburger.svg' import Multiply from '../resources/multiply.svg' import TheiaLogoDark from '../resources/theia-logo-dark.svg' +import { useState } from 'react' +import { useEffect } from 'react' +import { useRef } from 'react' const StyledNav = styled.div` @media(max-width: ${breakpoints.xmd}) { @@ -14,6 +17,12 @@ const StyledNav = styled.div` right: 0; } + &.fixed { + position: fixed; + background: #fff; + width: 100%; + } + .nav { display: flex; position: relative; @@ -144,58 +153,66 @@ const StyledNav = styled.div` } ` -class Nav extends React.Component { +const Nav = ({ shouldRenderLogo }) => { + const [isNavRendered, setIsNavRendered] = useState(false) + const navRef = useRef(null) - state = { - isNavRendered: false, + const toggleNavigation = () => { + setIsNavRendered(!isNavRendered) } - toggleNavigation = () => { - this.setState({ isNavRendered: !this.state.isNavRendered }) + const handleScroll = () => { + if (window.scrollY > 200) { + navRef.current.classList.add('fixed') + } } - render() { - const { shouldRenderLogo } = this.props - return ( - - + + ) } export default Nav diff --git a/src/layouts/docs-layout.js b/src/layouts/docs-layout.js index 79967777..7b104560 100644 --- a/src/layouts/docs-layout.js +++ b/src/layouts/docs-layout.js @@ -28,6 +28,7 @@ const DocContainer = styled.div` } .docs-row { + position: relative; width: 85%; max-width: 100rem; margin: 0 auto; diff --git a/src/layouts/layout.js b/src/layouts/layout.js index 2a43eeb1..4f085408 100644 --- a/src/layouts/layout.js +++ b/src/layouts/layout.js @@ -88,6 +88,7 @@ const Layout = ({ children, canonical }) => { /* --------------------------------------------- */ .row { + position: relative; max-width: ${grid.maxWidth}; width: 80%; margin: 0 auto;