Skip to content

Commit 70eb021

Browse files
Merge pull request #86 from Web-Dev-Path/chore/update-navbar
Update navbar with scrolly effect
2 parents 9ece24c + 2cd0947 commit 70eb021

File tree

13 files changed

+304
-265
lines changed

13 files changed

+304
-265
lines changed

CHANGELOG.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1919
- new footer and newsletter components styling
2020
- TwoColumn.js component
2121
- decoration components
22-
- ThreeColumn.js and Card.js
22+
- nav component styling and intersection api
23+
- CardsColumns.js and Card.js
2324

2425
### Fixed
2526

2627
- updated Next.js from 10.0.0 to 12.0.10
2728
- fixed scroll-x added by the layout container, adjust README
2829
- updated TwoColumn.js component with style props
2930
- updated favicon icon and add OG
30-
31-
32-
33-

components/Container.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import containerStyles from '../styles/Container.module.scss';
2+
3+
export default function Container({ className, children }) {
4+
return (
5+
<div
6+
className={`${containerStyles.container} ${className ? className : ''}`}
7+
>
8+
{children}
9+
</div>
10+
);
11+
}

components/Footer.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export default function Footer() {
2020
</nav>
2121
<Link href="/">
2222
<a className={footerStyles.footer__logo} title="Go to the Homepage">
23-
<Image src="/images/svg/logo.svg" height={326} width={326} />
23+
<Image
24+
src="/images/svg/logo.svg"
25+
height={326}
26+
width={326}
27+
alt="Logo"
28+
/>
2429
</a>
2530
</Link>
2631
</section>

components/Nav.js

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,100 @@
1+
import { useState, useEffect, useRef } from 'react';
12
import Link from 'next/link';
2-
import { useEffect, useState } from 'react';
3+
import Image from 'next/image';
4+
import ButtonLink from './ButtonLink';
5+
import Container from './Container';
36
import styles from '../styles/Nav.module.scss';
47
import { linksNav } from '../utils/links';
5-
import Image from 'next/image';
68

79
export default function Nav() {
810
const [active, setActive] = useState(false);
11+
const headerRef = useRef();
12+
const containerRef = useRef();
913

10-
//This function fixes the Navlinks position if the hamburger menu is left open while resizing the window
1114
useEffect(() => {
12-
function setTrueSize() {
13-
if (window.innerWidth >= 768) setActive(false);
14-
}
15-
window.addEventListener('resize', setTrueSize);
15+
const observer = new IntersectionObserver(
16+
([entry]) => {
17+
if (!entry.isIntersecting) {
18+
containerRef.current.classList.add(styles.sticky);
19+
} else {
20+
containerRef.current.classList.remove(styles.sticky);
21+
}
22+
},
23+
{
24+
threshold: 0,
25+
rootMargin: '300px',
26+
}
27+
);
1628

17-
return () => window.removeEventListener('resize', setTrueSize);
18-
});
29+
if (headerRef.current) {
30+
observer.observe(headerRef.current);
31+
}
1932

20-
const toggleActive = () => {
21-
setActive(active => !active);
22-
};
33+
return () => {
34+
if (headerRef.current) {
35+
observer.unobserve(headerRef.current);
36+
}
37+
};
38+
}, []);
2339

2440
return (
25-
<header className={styles.header}>
26-
<div className={`${styles.navContainer} ${styles.row}`}>
27-
<div className={styles.align}>
28-
<Link href="/" passHref>
29-
<a>
30-
<Image
31-
width={86}
32-
height={80}
33-
className={styles.logo}
34-
src="/images/web-dev-path-logo-small.png"
35-
alt="Logo"
36-
/>
37-
</a>
38-
</Link>
39-
<button
40-
className={styles.navToggle}
41-
aria-label="open navigation"
42-
onClick={toggleActive}
43-
>
44-
<span className={styles.hamburger} />
45-
</button>
46-
</div>
47-
<nav className={`${active ? styles.navVisible : styles.nav}`}>
48-
<ul className={styles.navList}>
49-
{linksNav.map(link => (
50-
<li className={styles.navItem} key={link.href}>
51-
<Link href={link.href}>
52-
<a className={styles.navLink} title={link.text}>
53-
{link.text}
54-
</a>
55-
</Link>
41+
<header className={styles.header} ref={headerRef}>
42+
<Container>
43+
<div ref={containerRef}>
44+
<nav className={styles.nav}>
45+
<div className={styles.nav__logo}>
46+
<Link href="/" passHref>
47+
<a>
48+
<Image
49+
src="/images/svg/logo.svg"
50+
height={115}
51+
width={180}
52+
alt="Logo"
53+
/>
54+
</a>
55+
</Link>
56+
</div>
57+
<ul
58+
className={`${styles.nav__links} ${active ? styles.active : ''}`}
59+
>
60+
{linksNav.map(({ text, href, id }) => {
61+
if (text !== 'Join us') {
62+
return (
63+
<li className={styles.nav__item} key={id}>
64+
<Link href={href}>
65+
<a className={styles.nav__link} title={text}>
66+
{text}
67+
</a>
68+
</Link>
69+
</li>
70+
);
71+
}
72+
})}
73+
<li className={styles.nav__item}>
74+
<ButtonLink
75+
className={`${styles.nav__button} ${
76+
active ? styles.active : ''
77+
}`}
78+
link="https://webdevpath.slack.com/join/shared_invite/zt-xqqgwwo5-a09BSVWC9ZrHmS6RaMBzVw#/shared-invite/email"
79+
>
80+
Join us
81+
</ButtonLink>
5682
</li>
57-
))}
58-
</ul>
59-
</nav>
60-
</div>
83+
</ul>
84+
<button
85+
className={`${styles.nav__hamburger} ${
86+
active ? styles.active : ''
87+
}`}
88+
onClick={() => setActive(active => !active)}
89+
aria-label="toggle navigation"
90+
>
91+
<span className={styles.nav__hamburger__bar}></span>
92+
<span className={styles.nav__hamburger__bar}></span>
93+
<span className={styles.nav__hamburger__bar}></span>
94+
</button>
95+
</nav>
96+
</div>
97+
</Container>
6198
</header>
6299
);
63100
}

components/TwoColumn.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default function TwoColumn({
5959
className={styles.img}
6060
layout="fill"
6161
objectFit="cover"
62+
priority
6263
/>
6364
</div>
6465
)}

pages/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default function Home() {
1010
return (
1111
<section className={styles.container}>
1212
<div className={styles.inner}>
13-
<h1 className={styles.title}>&lt; Web Dev wannabe? /&gt;</h1>
1413
<div className={styles.description}>
14+
<h1 className={styles.title}>&lt; Web Dev wannabe? /&gt;</h1>
1515
<p>
1616
Hold our hand and enjoy the road to learn how to start a new
1717
project, the magic behind Github while working in a team

public/favicon.ico

-15 KB
Binary file not shown.

styles/Card.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
margin: 1.5rem;
66
padding: 1.5rem;
77
border-radius: 1.5rem;
8-
box-shadow: 0px 8px 24px rgba(0, 0, 0, 0.15);
8+
box-shadow: $box-shadow;
99
min-width: 28%;
1010
@include desktop {
1111
flex-basis: 28%;

styles/Container.module.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@use './variables' as *;
2+
3+
.container {
4+
margin: 0 auto;
5+
width: 90%;
6+
max-width: $large-desktop-breakpoint;
7+
}

styles/Home.module.scss

Lines changed: 14 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,51 @@
11
@import 'mixins';
22
@import 'variables';
33

4-
hr {
5-
&.divider {
6-
border-top: 1px solid $primary-bg-color;
7-
width: 100%;
8-
margin: 4rem 0;
9-
}
10-
}
11-
124
.title {
135
margin: 0;
146
line-height: 1.15;
157
font-size: 2.5rem;
168
text-align: center;
179

18-
a {
19-
text-decoration: none;
20-
21-
&:hover,
22-
&:focus,
23-
&:active {
24-
text-decoration: underline;
25-
}
10+
@include desktop-breakpoint-plus {
11+
font-size: 4.5rem;
2612
}
2713
}
2814

2915
.description {
30-
line-height: 1.5;
3116
font-size: 1.5rem;
3217
text-align: center;
3318
max-width: 90%;
3419
margin: 0 auto;
35-
padding: 2rem 0 4rem;
36-
}
37-
38-
.centerText {
39-
text-align: center;
40-
width: 90%;
41-
margin: 1.5rem auto;
42-
}
43-
44-
.grid {
45-
display: flex;
46-
align-items: center;
47-
justify-content: center;
48-
flex-wrap: wrap;
49-
margin: 3rem auto;
50-
}
51-
52-
.card {
53-
height: 13rem;
54-
max-width: 40%;
55-
margin: 1.5rem;
56-
flex-basis: 45%;
57-
padding: 1.5rem;
58-
text-align: left;
59-
display: flex;
60-
align-items: center;
61-
justify-content: center;
62-
text-decoration: none;
63-
@include transition(color 0.3s ease);
64-
box-shadow: inset 0px 0px 0px 1px rgb(0 0 0 / 15%),
65-
0px 3px 4px 2px rgb(0 0 0 / 10%);
66-
67-
&:hover,
68-
&:focus,
69-
&:active {
70-
color: $primary-content-color;
71-
border-color: $primary-bg-color;
72-
}
73-
74-
p {
75-
margin: 0 1rem;
76-
font-size: 1.125rem;
77-
line-height: 1.5;
78-
text-align: center;
79-
font-weight: bold;
80-
}
81-
}
82-
83-
.learn_more {
84-
padding: 4rem 0;
85-
}
86-
87-
.button {
88-
height: 2.4rem;
89-
width: 8rem;
90-
border-radius: 5px;
91-
background-color: $primary-content-color;
92-
color: $white;
93-
font-size: 0.875rem;
94-
border: none;
95-
text-transform: uppercase;
96-
transition: opacity 0.3s ease;
97-
98-
&:hover {
99-
opacity: 0.6;
100-
cursor: pointer;
101-
}
20+
padding: 5rem 0;
10221
}
10322

10423
.bracket {
10524
left: 0;
10625
position: absolute;
10726
transform: translate(10rem, -5rem);
27+
28+
@include desktop-breakpoint-plus {
29+
transform: translate(50%, -5rem);
30+
width: 30%;
31+
}
32+
33+
@include desktop-breakpoint-minus {
34+
display: none;
35+
}
10836
}
10937

11038
.stick {
11139
right: 0;
11240
position: absolute;
11341
transform: translate(-10rem, -5rem);
114-
}
11542

116-
@include desktop-breakpoint-plus {
117-
.title {
118-
font-size: 4rem;
119-
}
120-
121-
.bracket {
122-
transform: translate(50%, -5rem);
123-
width: 30%;
124-
}
125-
126-
.stick {
43+
@include desktop-breakpoint-plus {
12744
transform: translate(-50%, -5rem);
12845
width: 30%;
12946
}
130-
}
131-
132-
@include desktop-breakpoint-minus {
133-
.bracket {
134-
display: none;
135-
}
13647

137-
.stick {
48+
@include desktop-breakpoint-minus {
13849
display: none;
13950
}
14051
}

0 commit comments

Comments
 (0)