Skip to content

Commit 31fbf25

Browse files
authored
Merge pull request #101 from cherylli/feature/reveal-sections-scrolling
Feature/reveal sections scrolling
2 parents 5e4d73f + dbb5522 commit 31fbf25

File tree

5 files changed

+115
-42
lines changed

5 files changed

+115
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2424
- footer copyright
2525
- Header.js component
2626
- reCAPTCHA
27+
- useIntersect Hook, Reveal container for scrolling using intersection API
2728

2829
### Fixed
2930

components/RevealContentContainer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { useEffect, useState } from 'react';
2+
import { useIntersect } from '../hooks/useIntersect';
3+
import styles from '../styles/RevealContainer.module.scss';
4+
5+
const RevealContentContainer = ({ children }) => {
6+
const [ref, entry] = useIntersect({ threshold: 0.15 });
7+
const [firstLoad, setFirstLoad] = useState(true);
8+
const [hiddenStyle, setHiddenStyle] = useState('section__hidden');
9+
10+
useEffect(() => {
11+
if (entry.isIntersecting && firstLoad) {
12+
setHiddenStyle('');
13+
setFirstLoad(false);
14+
}
15+
}, [entry.isIntersecting]);
16+
17+
return (
18+
<div ref={ref} className={`${styles.wrapper} ${styles[hiddenStyle]}`}>
19+
{children}
20+
</div>
21+
);
22+
};
23+
24+
export default RevealContentContainer;

hooks/useIntersect.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useState, useEffect, useRef } from 'react';
2+
3+
export const useIntersect = ({ root = null, rootMargin, threshold = 0 }) => {
4+
const [entry, setEntry] = useState({});
5+
const [node, setNode] = useState(null);
6+
7+
const observer = useRef(null);
8+
9+
useEffect(() => {
10+
observer = new window.IntersectionObserver(
11+
([entry]) => {
12+
setEntry(entry);
13+
},
14+
{ root, rootMargin, threshold }
15+
);
16+
17+
if (node) {
18+
observer.observe(node);
19+
}
20+
return () => {
21+
observer.disconnect();
22+
if (node) {
23+
observer.unobserve(node);
24+
}
25+
};
26+
}, [node, root, rootMargin, threshold]);
27+
28+
return [setNode, entry];
29+
};

pages/index.js

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,64 @@ import TwoColumn from '../components/TwoColumn';
44
import CardsColumns from '../components/CardsColumns';
55
import styles from '../styles/Home.module.scss';
66
import { white, primary } from '../styles/TwoColumn.module.scss';
7+
import RevealContentContainer from '../components/RevealContentContainer';
78

89
export default function Home() {
910
return (
1011
<>
11-
<TwoColumn
12-
title="Let's grow together."
13-
image="/images/join-us.jpg"
14-
content="The Web Dev Path is a team of professional developers project that aims to provide a comprehensive path for people who seek to begin their web development journey."
15-
link="/about"
16-
customBtnClass="inverted-grey"
17-
/>
12+
<RevealContentContainer>
13+
<TwoColumn
14+
title="Let's grow together."
15+
image="/images/join-us.jpg"
16+
content="The Web Dev Path is a team of professional developers project that aims to provide a comprehensive path for people who seek to begin their web development journey."
17+
link="/about"
18+
customBtnClass="inverted-grey"
19+
/>
20+
</RevealContentContainer>
1821

19-
<Bracket className={styles.bracket} />
22+
<RevealContentContainer>
23+
<Bracket className={styles.bracket} />
24+
<TwoColumn
25+
title="Get involved."
26+
content="Web Dev Path runs on volunteers. Here are the ways you can get involved with us:"
27+
rowOrder="row-reverse"
28+
customInnerClass="get-involved"
29+
bgColor={white}
30+
/>
31+
</RevealContentContainer>
2032

21-
<TwoColumn
22-
title="Get involved."
23-
content="Web Dev Path runs on volunteers. Here are the ways you can get involved with us:"
24-
rowOrder="row-reverse"
25-
customInnerClass="get-involved"
26-
bgColor={white}
27-
/>
33+
<RevealContentContainer>
34+
<CardsColumns
35+
titles={['Join us', 'Volunteer', 'Become a mentor']}
36+
images={[
37+
'/images/join-us.jpg',
38+
'/images/volunteer.jpg',
39+
'/images/mentor.jpg',
40+
]}
41+
altTags={['Join us', 'Volunteer', 'Become a mentor']}
42+
content={[
43+
'Are you learning web development and need mentorship? Are you a web dev looking for help or a code buddy for a project? ',
44+
'Would you like to volunteer? For roles other than mentor/mentee, please get in touch.',
45+
'Are you an experienced web dev who wants to become a mentor? Welcome!',
46+
]}
47+
links={['/about', '/contact', '/about']}
48+
linkText={['Learn more', 'Contact us', 'Learn more']}
49+
/>
50+
</RevealContentContainer>
2851

29-
<CardsColumns
30-
titles={['Join us', 'Volunteer', 'Become a mentor']}
31-
images={[
32-
'/images/join-us.jpg',
33-
'/images/volunteer.jpg',
34-
'/images/mentor.jpg',
35-
]}
36-
altTags={['Join us', 'Volunteer', 'Become a mentor']}
37-
content={[
38-
'Are you learning web development and need mentorship? Are you a web dev looking for help or a code buddy for a project? ',
39-
'Would you like to volunteer? For roles other than mentor/mentee, please get in touch.',
40-
'Are you an experienced web dev who wants to become a mentor? Welcome!',
41-
]}
42-
links={['/about', '/contact', '/about']}
43-
linkText={['Learn more', 'Contact us', 'Learn more']}
44-
/>
52+
<RevealContentContainer>
53+
<Stick className={styles.stick} />
4554

46-
<Stick className={styles.stick} />
47-
48-
<TwoColumn
49-
title="Nonprofit?"
50-
content="Web Dev Path can help your nonprofit with web projects of various sizes. Connect with us to find out how."
51-
color={white}
52-
bgColor={primary}
53-
link="/about"
54-
customInnerClass="non-profit"
55-
customBtnClass="inverted-white"
56-
/>
55+
<TwoColumn
56+
title="Nonprofit?"
57+
content="Web Dev Path can help your nonprofit with web projects of various sizes. Connect with us to find out how."
58+
color={white}
59+
bgColor={primary}
60+
link="/about"
61+
customInnerClass="non-profit"
62+
customBtnClass="inverted-white"
63+
/>
64+
</RevealContentContainer>
5765
</>
5866
);
5967
}

styles/RevealContainer.module.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@use './variables' as *;
2+
@use './mixins' as *;
3+
4+
.section__hidden {
5+
opacity: 0;
6+
transform: translateY(8rem);
7+
}
8+
9+
.wrapper {
10+
transition: transform 1s, opacity 1s;
11+
}

0 commit comments

Comments
 (0)