Skip to content
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 16 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions src/components/DataRoom/SeeMore/Wave.tsx
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()
}, [])
Copy link
Member

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.


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)
Copy link
Member

Choose a reason for hiding this comment

The 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
43 changes: 43 additions & 0 deletions src/components/DataRoom/SeeMore/index.tsx
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
83 changes: 83 additions & 0 deletions src/components/DataRoom/SeeMore/styles.module.css
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
}
4 changes: 4 additions & 0 deletions src/content/dataroom.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"href": "https://dune.com/queries/3737066"
}
},
{
"component": "DataRoom/SeeMore",
"text": "Want to see more?"
},
{
"component": "DataRoom/ExternalLinksGrid",
"title": "Dune Boards",
Expand Down
Loading