-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 🎸 Add See More Section #428
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
918350c
Open branch
iamacook 9c09c69
feat: 🎸 Add See More Section
Malayvasa 99aadbc
refactor: 💡 address PR comments
Malayvasa 1637ae0
fix: 🐛 address PR comments + import framer motion on client
Malayvasa b27f0c8
Merge branch 'main' into see-more
Malayvasa 209d11c
fix: 🐛 address console error
Malayvasa 7a1eed3
Merge branch 'main' into see-more
Malayvasa f7e3fc3
fix: 🐛 moved the wav animation to pr #441
Malayvasa e5a34e8
Merge branch 'main' into see-more
Malayvasa 44b8b93
fix: 🐛 remove unused variables and imports
Malayvasa 97060b3
fix: 🐛 remove unused css
Malayvasa c40fc1e
fix: 🐛 remove unused hook
Malayvasa 7a2a5f5
Update src/components/DataRoom/SeeMore/SlidingWave.tsx
Malayvasa 52c2e6f
refactor: 💡 rename component
Malayvasa 30679d6
style: 💄 remove unused styles and update mobile styles
Malayvasa cd99842
fix: 🐛 fix text bounce back issue
Malayvasa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React, { useEffect, useRef, useState } from 'react' | ||
|
||
type WaveProps = { | ||
height?: number | ||
color?: string | ||
amplitude?: number | ||
frequency?: number | ||
speed?: number | ||
} | ||
|
||
const DEFAULT_HEIGHT = 600 | ||
const DEFAULT_COLOR = '#12FF80' | ||
const DEFAULT_AMPLITUDE = 100 | ||
const DEFAULT_FREQUENCY = 1 | ||
const DEFAULT_SPEED = 3 | ||
const STROKE_WIDTH = 4 | ||
|
||
const Wave = ({ | ||
height = DEFAULT_HEIGHT, | ||
color = DEFAULT_COLOR, | ||
amplitude = DEFAULT_AMPLITUDE, | ||
frequency = DEFAULT_FREQUENCY, | ||
speed = DEFAULT_SPEED, | ||
}: WaveProps) => { | ||
const containerRef = useRef<HTMLDivElement>(null) | ||
const pathRef = useRef<SVGPathElement>(null) | ||
const requestRef = useRef<number>() | ||
const startTimeRef = useRef<number>() | ||
const [width, setWidth] = useState(0) | ||
const pointsRef = useRef<string[]>([]) | ||
|
||
useEffect(() => { | ||
if (!containerRef.current) return | ||
|
||
const updateWidth = (entries: ResizeObserverEntry[]) => { | ||
setWidth(entries[0].contentRect.width) | ||
} | ||
|
||
const resizeObserver = new ResizeObserver(updateWidth) | ||
resizeObserver.observe(containerRef.current) | ||
|
||
return () => resizeObserver.disconnect() | ||
}, []) | ||
|
||
useEffect(() => { | ||
const animate = (time: number) => { | ||
if (!startTimeRef.current) startTimeRef.current = time | ||
const elapsed = time - startTimeRef.current | ||
|
||
const path = Array.from({ length: width + 1 }, (_, i) => { | ||
const y = height / 2 + amplitude * Math.sin((i / width) * 2 * Math.PI * frequency + (elapsed * speed) / 1000) | ||
return `${i},${y}` | ||
}).join(' L') | ||
|
||
pathRef.current?.setAttribute('d', `M${path}`) | ||
|
||
requestRef.current = requestAnimationFrame(animate) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to use a ref for this. We can use a local variable. |
||
} | ||
|
||
requestRef.current = requestAnimationFrame(animate) | ||
return () => cancelAnimationFrame(requestRef.current!) | ||
}, [width, height, amplitude, frequency, speed]) | ||
|
||
return ( | ||
<div ref={containerRef} style={{ width: '100%' }}> | ||
<svg width={width} height={height}> | ||
<path ref={pathRef} fill="none" stroke={color} strokeWidth={STROKE_WIDTH} /> | ||
</svg> | ||
</div> | ||
) | ||
} | ||
|
||
export default Wave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { BaseBlock } from '@/components/Home/types' | ||
import { useIsMediumScreen } from '@/hooks/useMaxWidth' | ||
import { useScroll, useTransform, motion } from 'framer-motion' | ||
import css from './styles.module.css' | ||
import { useRef } from 'react' | ||
import Wave from './Wave' | ||
import { Typography } from '@mui/material' | ||
|
||
const SeeMore = ({ text }: BaseBlock) => { | ||
const backgroundRef = useRef<HTMLDivElement>(null) | ||
const isMobile = useIsMediumScreen() | ||
|
||
const { scrollYProgress } = useScroll({ | ||
target: backgroundRef, | ||
offset: ['start end', 'end start'], | ||
}) | ||
|
||
const opacity = useTransform(scrollYProgress, [0, 0.3, 0.6, 0.75], [0, 1, 1, 0]) | ||
const opacitText = useTransform(scrollYProgress, [0, 0.3, 0.5, 0.75], [0, 1, 1, 0]) | ||
DiogoSoaress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const translate = useTransform(scrollYProgress, [0, 0.2, 0.55, 0.75], ['-250px', '0px', '0px', '250px']) | ||
|
||
return ( | ||
<div ref={backgroundRef} className={css.sectionContainer}> | ||
<div className={css.stickyContainer}> | ||
<motion.div style={{ opacity: opacitText, translateY: translate }} className={css.text}> | ||
<Typography variant="h1">{text}</Typography> | ||
</motion.div> | ||
<div className={css.gradientBox}></div> | ||
<motion.div style={{ opacity }} className={css.wave1}> | ||
<Wave color="#12FF80" amplitude={isMobile ? 100 : 200} /> | ||
</motion.div> | ||
<motion.div style={{ opacity }} className={css.wave2}> | ||
<Wave color="#008A40" amplitude={isMobile ? 90 : 170} /> | ||
</motion.div> | ||
<motion.div style={{ opacity }} className={css.wave3}> | ||
<Wave color="#003C1C" amplitude={isMobile ? 80 : 140} /> | ||
</motion.div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default SeeMore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
.sectionContainer { | ||
height: 200vh; | ||
} | ||
|
||
.stickyContainer { | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
position: sticky; | ||
top: 0; | ||
} | ||
|
||
.text { | ||
z-index: 50; | ||
} | ||
DiogoSoaress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.gradientBox { | ||
width: 100%; | ||
height: 100%; | ||
background: linear-gradient( | ||
to right, | ||
#121312 0%, | ||
rgba(18, 19, 18, 0.8) 40%, | ||
rgba(18, 19, 18, 0.4) 70%, | ||
transparent 100% | ||
); | ||
z-index: 40; | ||
position: absolute; | ||
top: 50%; | ||
transform: translateY(-50%); | ||
} | ||
|
||
.wave1 { | ||
position: absolute; | ||
top: 50%; | ||
width: 100%; | ||
transform: translateY(-50%); | ||
right: 0; | ||
z-index: 30; | ||
} | ||
|
||
.wave2 { | ||
position: absolute; | ||
top: 50%; | ||
width: 100%; | ||
transform: translateY(-50%); | ||
right: 0; | ||
z-index: 20; | ||
} | ||
|
||
.wave3 { | ||
position: absolute; | ||
top: 50%; | ||
width: 100%; | ||
transform: translateY(-50%); | ||
right: 0; | ||
z-index: 10; | ||
} | ||
DiogoSoaress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@media (max-width: 900px) { | ||
.text { | ||
padding: 60px; | ||
margin-top: 120px; | ||
text-align: center; | ||
} | ||
.stickyContainer { | ||
justify-content: start; | ||
} | ||
|
||
.wave1 { | ||
transform: translateY(-25%); | ||
} | ||
|
||
.wave2 { | ||
transform: translateY(-25%); | ||
} | ||
|
||
.wave3 { | ||
transform: translateY(-25%); | ||
} | ||
DiogoSoaress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's move this to a custom hook. We could make it reusable and return the width and height.