Skip to content

Commit 659894e

Browse files
Style nav menu and fix hiding nav content on link selection
1 parent 54a19ad commit 659894e

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

web/components/NavMenu.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react'
2+
import { Link } from 'gatsby'
23
import styled from 'styled-components'
34

45
const NavMenuPanel = styled.nav`
@@ -18,15 +19,22 @@ const A = styled.a`
1819
}
1920
`
2021

21-
export default function NavMenu({ data }) {
22-
console.log('menu props: ', data)
22+
export default function NavMenu({ data, handleNavMenuToggle }) {
23+
// console.log('menu props: ', data)
24+
2325
return (
2426
<NavMenuPanel>
2527
<ul>
28+
<li>
29+
<A href='#top-of-page'>Home</A>
30+
</li>
2631
{data.map(({ node }) => {
2732
return node.section_active && (
2833
<li key={node._id}>
29-
<A href={`#${node.anchor_id}`}>
34+
<A
35+
href={`#${node.anchor_id}`}
36+
onClick={handleNavMenuToggle}
37+
>
3038
{node.name}
3139
</A>
3240
</li>

web/src/pages/index.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ import Footer from '../../components/footer'
66
import ToC from '../../components/TableOfContents'
77
import NavMenu from '../../components/NavMenu'
88
import TopicSection from '../../components/TopicSection'
9-
import { styles } from 'prism-react-renderer/themes/oceanicNext'
9+
// import { styles } from 'prism-react-renderer/themes/oceanicNext'
1010

11-
// TODO: add styles
1211
const SecondaryNavBar = styled.nav`
13-
14-
`
15-
const NavMenuBtn = styled.button`
12+
display: flex;
13+
align-content: center;
1614
position: fixed;
1715
top: 0;
18-
right: 0;
16+
width: 100%;
17+
background-color: rgb(255, 159, 128);
18+
`
19+
const NavMenuBtn = styled.button`
20+
font-family: 'Work Sans', sans-serif;
21+
font-size: 1em;
1922
z-index: 1;
20-
opacity: .7;
21-
height: 50px;
22-
/* width: 100%; */
2323
background-color: rgb(255, 159, 128);
2424
text-align: center;
25+
padding: 5px;
2526
border: none;
2627
&:hover {
2728
cursor: pointer;
@@ -30,8 +31,8 @@ const NavMenuBtn = styled.button`
3031

3132
export default function Index({ data }) {
3233
// these "nav" references are for the secondary nav that appears once you've scrolled past table of contents
33-
const [navActive, setNavActive] = useState(false)
34-
const [navMenuActive, toggleNavMenu] = useState(false)
34+
const [navIsActive, setNavIsActive] = useState(false)
35+
const [navMenuIsActive, setNavMenuIsActive] = useState(false)
3536
// console.log('Index data: ', data)
3637

3738
useEffect(() => {
@@ -45,19 +46,20 @@ export default function Index({ data }) {
4546
console.log('handleScroll')
4647
// TODO: replace offset number with calculation that determines once ToC section has been passed
4748
if (window.pageYOffset > 900) {
48-
setNavActive(true)
49+
setNavIsActive(true)
4950
} else {
50-
setNavActive(false)
51+
setNavIsActive(false)
52+
setNavMenuIsActive(false)
5153
}
5254
}
5355

5456
function handleNavMenuToggle() {
55-
toggleNavMenu(navMenuActive ? false : true)
57+
setNavMenuIsActive(navMenuIsActive ? false : true)
5658
}
5759

5860
return (
5961
<>
60-
<Layout>
62+
<Layout id="top-of-page">
6163
<ToC data={data.allSanitySection.edges} />
6264

6365
{data.allSanitySection.edges.map(section => {
@@ -70,21 +72,23 @@ export default function Index({ data }) {
7072
})}
7173
</Layout>
7274

73-
{navActive && (
75+
{navIsActive && (
7476
<SecondaryNavBar>
7577
<NavMenuBtn
7678
id="navmenu_button"
7779
onClick={handleNavMenuToggle}
7880
>
7981
Toggle Menu
8082
</NavMenuBtn>
83+
{navMenuIsActive && (
84+
<NavMenu
85+
data={data.allSanitySection.edges}
86+
handleNavMenuToggle={handleNavMenuToggle}
87+
/>
88+
)}
8189
</SecondaryNavBar>
8290
)}
8391

84-
{navMenuActive && (
85-
<NavMenu data={data.allSanitySection.edges} />
86-
)}
87-
8892
<Footer />
8993
</>
9094
)

web/src/styles/global.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ li {
3030

3131
a {
3232
text-decoration: none;
33-
/* color: rgb(144, 210, 245); */
3433
color: black;
3534
}
3635

3736
a:hover {
38-
/* text-decoration: underline; */
39-
/* color: rgb(144, 210, 245); */
4037
border-bottom: 2px solid rgb(255, 159, 128);
4138
}
4239

0 commit comments

Comments
 (0)