Skip to content

Commit 54a19ad

Browse files
Add basic nav menu toggling
1 parent 09b3cee commit 54a19ad

File tree

10 files changed

+144
-41
lines changed

10 files changed

+144
-41
lines changed

web/components/DescriptiveItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const LineNo = styled.span`
2525
`
2626

2727
export default function DescriptiveItem({ section }) {
28-
console.log('DescriptiveItem props: ', section)
28+
// console.log('DescriptiveItem props: ', section)
2929
return (
3030
<div>
3131
{section.subsections.map(secData => {

web/components/NavMenu.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react'
2+
import styled from 'styled-components'
3+
4+
const NavMenuPanel = styled.nav`
5+
background-color: rgb(16, 16, 16);
6+
opacity: .9;
7+
position: fixed;
8+
top: 0;
9+
width: 100%;
10+
text-align: center;
11+
/* TODO: how does scroll work when menu expands beyond bottom of window? (scroll currently operates on the content behind the menu) */
12+
font-size: 1.2em;
13+
`
14+
const A = styled.a`
15+
color: rgb(255, 159, 128);
16+
&:hover {
17+
border-bottom: 2px solid rgb(144, 210, 245);
18+
}
19+
`
20+
21+
export default function NavMenu({ data }) {
22+
console.log('menu props: ', data)
23+
return (
24+
<NavMenuPanel>
25+
<ul>
26+
{data.map(({ node }) => {
27+
return node.section_active && (
28+
<li key={node._id}>
29+
<A href={`#${node.anchor_id}`}>
30+
{node.name}
31+
</A>
32+
</li>
33+
)
34+
})}
35+
</ul>
36+
</NavMenuPanel>
37+
)
38+
}

web/components/ShortcutTable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

33
export default function ShortcutTable(props) {
4-
console.log('ShortcutTable props: ', props)
4+
// console.log('ShortcutTable props: ', props)
55
return (
66
<div className="table_container">
77
<table>

web/components/TableOfContents.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import React from 'react'
2-
import styled from 'styled-components'
3-
4-
// const H2 = styled.h2`
5-
// margin-top: 50px;
6-
// font-weight: 400;
7-
// `
82

93
export default function TableOfContents({ data }) {
10-
console.log('ToC data: ', data)
4+
// console.log('ToC data: ', data)
115
return (
126
<div id="toc">
137
<h2>Table of Contents</h2>
148
<nav>
15-
{/* TODO: figure out some way to order the different sections and subsections */}
169
<ul>
1710
{data.map(({ node }) => {
18-
console.log('node map', node)
11+
// console.log('node map', node)
1912
return (
2013
<li key={node._id}>
2114
<a

web/components/TopicSection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DescriptiveItem from './DescriptiveItem'
1010
// `
1111

1212
export default function TopicSection(props) {
13-
console.log('TopicSection props: ', props)
13+
// console.log('TopicSection props: ', props)
1414
return (
1515
<section
1616
id={props.section.anchor_id}

web/components/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export default function Layout({ children }) {
2626
</nav>
2727
</header>
2828

29-
<div>
29+
<>
3030
{children}
31-
</div>
31+
</>
3232

3333
</div>
3434
)

web/package-lock.json

Lines changed: 8 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
1515
},
1616
"dependencies": {
17+
"eslint-plugin-react-hooks": "^4.0.7",
1718
"gatsby": "^2.20.12",
1819
"gatsby-plugin-typography": "^2.4.1",
1920
"gatsby-source-sanity": "^5.0.6",

web/src/pages/index.js

Lines changed: 81 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,93 @@
1-
import React from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import { graphql } from 'gatsby'
3+
import styled from 'styled-components'
34
import Layout from '../../components/layout'
45
import Footer from '../../components/footer'
56
import ToC from '../../components/TableOfContents'
7+
import NavMenu from '../../components/NavMenu'
68
import TopicSection from '../../components/TopicSection'
9+
import { styles } from 'prism-react-renderer/themes/oceanicNext'
10+
11+
// TODO: add styles
12+
const SecondaryNavBar = styled.nav`
13+
14+
`
15+
const NavMenuBtn = styled.button`
16+
position: fixed;
17+
top: 0;
18+
right: 0;
19+
z-index: 1;
20+
opacity: .7;
21+
height: 50px;
22+
/* width: 100%; */
23+
background-color: rgb(255, 159, 128);
24+
text-align: center;
25+
border: none;
26+
&:hover {
27+
cursor: pointer;
28+
}
29+
`
730

831
export default function Index({ data }) {
9-
console.log('Index data: ', data)
10-
return (
11-
<>
12-
<Layout>
13-
<ToC data={data.allSanitySection.edges} />
32+
// 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)
35+
// console.log('Index data: ', data)
36+
37+
useEffect(() => {
38+
window.addEventListener('scroll', handleScroll)
39+
return () => {
40+
window.removeEventListener('scroll', handleScroll)
41+
}
42+
}, [])
43+
44+
function handleScroll() {
45+
console.log('handleScroll')
46+
// TODO: replace offset number with calculation that determines once ToC section has been passed
47+
if (window.pageYOffset > 900) {
48+
setNavActive(true)
49+
} else {
50+
setNavActive(false)
51+
}
52+
}
53+
54+
function handleNavMenuToggle() {
55+
toggleNavMenu(navMenuActive ? false : true)
56+
}
57+
58+
return (
59+
<>
60+
<Layout>
61+
<ToC data={data.allSanitySection.edges} />
62+
63+
{data.allSanitySection.edges.map(section => {
64+
return (
65+
<TopicSection
66+
section={section.node}
67+
key={section._id}
68+
/>
69+
)
70+
})}
71+
</Layout>
72+
73+
{navActive && (
74+
<SecondaryNavBar>
75+
<NavMenuBtn
76+
id="navmenu_button"
77+
onClick={handleNavMenuToggle}
78+
>
79+
Toggle Menu
80+
</NavMenuBtn>
81+
</SecondaryNavBar>
82+
)}
1483

15-
{data.allSanitySection.edges.map(section => {
16-
return (
17-
<TopicSection
18-
section={section.node}
19-
key={section._id}
20-
/>
21-
)
22-
})}
23-
</Layout>
84+
{navMenuActive && (
85+
<NavMenu data={data.allSanitySection.edges} />
86+
)}
2487

25-
<Footer />
26-
</>
27-
)
88+
<Footer />
89+
</>
90+
)
2891
}
2992

3093
export const query = graphql`

web/src/styles/global.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ a {
3737
a:hover {
3838
/* text-decoration: underline; */
3939
/* color: rgb(144, 210, 245); */
40-
border-bottom: 2px solid rgb(144, 210, 245);
40+
border-bottom: 2px solid rgb(255, 159, 128);
4141
}
4242

4343
header {
@@ -129,14 +129,14 @@ h2, h4, thead th {
129129

130130
.description_container ul {
131131
background-color: rgb(235, 232, 232);
132+
font-size: .9em;
132133
}
133134

134135
.description_container li a {
135136
font-family: 'Work Sans', sans-serif;
136137
}
137138

138-
.description_container li::before,
139-
.description_container li::after {
139+
.description_container li::before {
140140
content: ' \2022 ';
141141
}
142142

@@ -238,6 +238,9 @@ footer span {
238238
line-height: 1.5;
239239
}
240240

241-
/* @media screen and (max-width: 672px) {
242-
243-
} */
241+
@media screen and (max-width: 672px) {
242+
body {
243+
font-size: .8em;
244+
}
245+
246+
}

0 commit comments

Comments
 (0)