Skip to content

Commit f9c83d3

Browse files
Adding homepage hero effect
1 parent 7e16b75 commit f9c83d3

File tree

8 files changed

+69
-55
lines changed

8 files changed

+69
-55
lines changed

components/Hero.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState, useEffect } from 'react';
12
import Image from 'next/image';
23
import Nav from './Nav';
34
import Container from './Container';
@@ -7,13 +8,23 @@ export default function Hero({
78
title,
89
imgBg,
910
imgAlt,
10-
dynamicTitle,
11+
dynamicTitles = [],
1112
content,
1213
customClass,
1314
titleClass,
1415
}) {
16+
const [titleIndex, setTitleIndex] = useState(0);
17+
const handleTitleIndex = () =>
18+
setTitleIndex(titleIndex === dynamicTitles.length - 1 ? 0 : titleIndex + 1);
19+
20+
useEffect(() => {
21+
setTimeout(handleTitleIndex, 1350);
22+
}, [titleIndex]);
23+
1524
return (
16-
<div className={`${styles.header} ${customClass && styles[customClass]}`}>
25+
<div
26+
className={`${styles.header} ${customClass ? styles[customClass] : ''}`}
27+
>
1728
<Nav />
1829
<Image
1930
src={imgBg}
@@ -26,9 +37,9 @@ export default function Hero({
2637
/>
2738
<Container className={styles.header__content}>
2839
<div className={styles.header__content__upper}>
29-
<h1 className={`${titleClass && styles[titleClass]}`}>
40+
<h1 className={titleClass ? `${styles[titleClass]}` : ''}>
3041
{title}
31-
{dynamicTitle && <span> {dynamicTitle}</span>}
42+
{dynamicTitles && <span> {dynamicTitles[titleIndex]}</span>}
3243
</h1>
3344
</div>
3445
<div className={styles.header__content__bottom}>

components/Layout.js

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,22 @@
11
import { useRouter } from 'next/router';
2+
import { heroOptions } from '../utils/hero-options';
23
import Hero from './Hero';
34
import Meta from './Meta';
45
import Footer from './Footer';
56
import styles from '../styles/Layout.module.scss';
67

78
export default function Layout({ children }) {
89
const router = useRouter();
9-
const heroOptions = {
10-
'/': {
11-
imgBg: '/images/home-bg.png',
12-
imgAlt: 'Homepage',
13-
title: 'Web Dev Path is about',
14-
dynamicTitle: 'Community',
15-
content:
16-
'We help junior tech professionals, such as developers and designers, to grow.',
17-
},
18-
'/about': {
19-
imgBg: '/images/about-us-bg.png',
20-
imgAlt: 'About Us',
21-
title: 'About Us',
22-
titleClass: 'accent-title',
23-
content:
24-
'While the demand for web developers only increases, becoming one can be quite a journey!',
25-
},
26-
'/contact': {
27-
imgBg: '/images/about-us-bg.png',
28-
imgAlt: 'Contact Us',
29-
title: 'Contact Us',
30-
titleClass: 'accent-title',
31-
content:
32-
'We help junior tech professionals, such as developers and designers, to grow.',
33-
},
34-
'/blog': {
35-
imgBg: '/images/about-us-bg.png',
36-
imgAlt: 'Blog',
37-
title: 'Our Blog',
38-
titleClass: 'accent-title',
39-
content:
40-
'We help junior tech professionals, such as developers and designers, to grow.',
41-
},
42-
'/404': {
43-
imgBg: '/images/about-us-bg.png',
44-
imgAlt: 'Not Found',
45-
title: 'Not Found',
46-
titleClass: 'accent-title',
47-
content:
48-
'We help junior tech professionals, such as developers and designers, to grow.',
49-
},
50-
};
10+
const heroPathKeys = Object.keys(heroOptions)
11+
.sort((a, b) => a - b)
12+
.filter(k => router.pathname.startsWith(k));
13+
14+
const heroKey = heroPathKeys[heroPathKeys.length - 1];
5115
return (
5216
<>
5317
<Meta />
5418
<main className={styles.main}>
55-
<Hero {...heroOptions[router.pathname]} />
19+
<Hero {...heroOptions[heroKey]} />
5620
{children}
5721
<Footer />
5822
</main>

pages/about.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function AboutUs() {
22
return (
33
<div className="about-us">
4-
<h1>About Us</h1>
4+
<h2>About Us</h2>
55
<p>We're building this page.</p>
66
<p>Stay tuned!</p>
77
</div>

pages/blog/first-post.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function FirstPost() {
22
return (
3-
<div class="post">
4-
<h1>First Post</h1>
3+
<div className="post">
4+
<h2>First Post</h2>
55
<p>We're building this page.</p>
66
<p>Stay tuned!</p>
77
</div>

pages/blog/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Link from 'next/link';
33
export default function Blog() {
44
return (
55
<div className="blog">
6-
<h1>Blog Page</h1>
6+
<h2>Blog Page</h2>
77
<p>We're building this page. Stay tuned!</p>
88
<ul>
99
<li>

pages/contact.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default function ContactUs() {
22
return (
33
<div className="contact-us">
4-
<h1>Contact Us</h1>
4+
<h2>Contact Us</h2>
55
<p>We're building this page.</p>
66
<p>Stay tuned!</p>
77
</div>

styles/_variables.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,3 @@ $box-shadow-bottom: 0 10px 20px -5px rgba(0, 0, 0, 0.15);
2525
//Fonts
2626
$copy-font: 'Assistant';
2727
$heading-font: 'Open Sans';
28-
29-
//Constants
30-
$nav-height: 184px;

utils/hero-options.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export const heroOptions = {
2+
'/': {
3+
imgBg: '/images/home-bg.png',
4+
imgAlt: 'Homepage',
5+
title: 'Web Dev Path is about',
6+
dynamicTitles: ['community', 'learning', 'growth'],
7+
content:
8+
'We help junior tech professionals, such as developers and designers, to grow.',
9+
},
10+
'/about': {
11+
imgBg: '/images/about-us-bg.png',
12+
imgAlt: 'About Us',
13+
title: 'About Us',
14+
titleClass: 'accent-title',
15+
content:
16+
'While the demand for web developers only increases, becoming one can be quite a journey!',
17+
},
18+
'/contact': {
19+
imgBg: '/images/about-us-bg.png',
20+
imgAlt: 'Contact Us',
21+
title: 'Contact Us',
22+
titleClass: 'accent-title',
23+
content:
24+
'We help junior tech professionals, such as developers and designers, to grow.',
25+
},
26+
'/blog': {
27+
imgBg: '/images/about-us-bg.png',
28+
imgAlt: 'Blog',
29+
title: 'Our Blog',
30+
titleClass: 'accent-title',
31+
content:
32+
'We help junior tech professionals, such as developers and designers, to grow.',
33+
},
34+
'/404': {
35+
imgBg: '/images/about-us-bg.png',
36+
imgAlt: 'Not Found',
37+
title: 'Not Found',
38+
titleClass: 'accent-title',
39+
content:
40+
'We help junior tech professionals, such as developers and designers, to grow.',
41+
},
42+
};

0 commit comments

Comments
 (0)