Skip to content

Commit

Permalink
Recompose component structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kpyszkowski committed Apr 17, 2024
1 parent e962925 commit a4ba563
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 176 deletions.
45 changes: 45 additions & 0 deletions dapp/src/components/shared/SeasonCountdownSection/LiveTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react"
import { TagProps, Tag, TagLabel, Box } from "@chakra-ui/react"
import { motion } from "framer-motion"

const MotionBox = motion(Box)

export function LiveTag(props: TagProps) {
return (
<Tag
px={4}
py={2}
rounded="3xl"
bg="grey.700"
variant="solid"
pos="relative"
{...props}
>
<Box rounded="full" w={2} h={2} mr={3} bg="brand.400" />
<MotionBox
pos="absolute"
rounded="full"
w={2}
h={2}
bg="brand.400"
animate={{ scale: [1, 6], opacity: [0.5, 0] }}
transition={{
duration: 2,
ease: "easeInOut",
repeat: Infinity,
}}
/>
<TagLabel
color="gold.200"
textTransform="uppercase"
fontStyle="italic"
overflow="visible"
fontSize="md"
lineHeight={5}
fontWeight="bold"
>
Live
</TagLabel>
</Tag>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React, { useRef } from "react"
import { Box } from "@chakra-ui/react"
import seasonCountdownBackground from "#/assets/images/season-countdown-section-background.png"
import seasonCountdownForeground from "#/assets/images/season-countdown-section-foreground.png"
import {
MotionValue,
motion,
useScroll,
useSpring,
useTransform,
useTime,
wrap,
} from "framer-motion"

export function SeasonCountdownSectionBackground() {
const containerRef = useRef(null)
const { scrollYProgress } = useScroll({
target: containerRef,
offset: ["center start", "start end"],
})
const smoothScrollYProgress = useSpring(scrollYProgress, {
damping: 10,
stiffness: 90,
mass: 0.75,
}) as MotionValue<number>
const foregroundParallax = useTransform(
smoothScrollYProgress,
[0, 1],
["25%", "65%"],
)
const time = useTime()
// Seed value is wrapped to prevent infinite increment causing potential memory leaks
const seed = useTransform(time, (value) => wrap(0, 2137, Math.floor(value)))

return (
<Box
as="svg"
ref={containerRef}
w="full"
h="full"
minH={720}
rounded="2xl"
pos="absolute"
inset={0}
zIndex={-1}
>
<defs>
<filter
id="noise-filter"
x="-20%"
y="-20%"
width="140%"
height="140%"
filterUnits="objectBoundingBox"
primitiveUnits="userSpaceOnUse"
colorInterpolationFilters="linearRGB"
>
<motion.feTurbulence
type="fractalNoise"
baseFrequency="0.119"
numOctaves="4"
seed={seed}
stitchTiles="stitch"
x="0%"
y="0%"
width="100%"
height="100%"
result="turbulence"
/>
<feSpecularLighting
surfaceScale="4"
specularConstant="3"
specularExponent="20"
lightingColor="#0600ff"
x="0%"
y="0%"
width="100%"
height="100%"
in="turbulence"
result="specularLighting"
>
<feDistantLight azimuth="3" elevation="107" />
</feSpecularLighting>
<feColorMatrix
type="saturate"
values="0"
x="0%"
y="0%"
width="100%"
height="100%"
in="specularLighting"
result="colormatrix"
/>
</filter>
</defs>
<Box as="rect" x="0" y="0" w="full" h="full" fill="brand.400" />
<Box as="g" mixBlendMode="overlay">
<Box
as="image"
href={seasonCountdownBackground}
w="full"
h="full"
preserveAspectRatio="xMidYMin slice"
/>
<Box
as={motion.image}
href={seasonCountdownForeground}
w="full"
h="full"
preserveAspectRatio="xMinYMin slice"
y={foregroundParallax}
/>
</Box>
<Box
as="rect"
mixBlendMode="soft-light"
w="full"
h="full"
fill="#0600ff"
filter="url(#noise-filter)"
opacity={0.64}
/>
</Box>
)
}
3 changes: 3 additions & 0 deletions dapp/src/components/shared/SeasonCountdownSection/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./LiveTag"
export * from "./CountdownTimer"
export * from "./SeasonCountdownSectionBackground"
184 changes: 8 additions & 176 deletions dapp/src/pages/LandingPage/SeasonCountdownSection.tsx
Original file line number Diff line number Diff line change
@@ -1,182 +1,14 @@
import React, { useRef } from "react"
import {
Box,
Tag,
TagLabel,
TagProps,
VStack,
Heading,
Text,
} from "@chakra-ui/react"
import seasonCountdownBackground from "#/assets/images/season-countdown-section-background.png"
import seasonCountdownForeground from "#/assets/images/season-countdown-section-foreground.png"
import React from "react"
import { Box, VStack, Heading, Text } from "@chakra-ui/react"

import {
MotionValue,
motion,
useScroll,
useSpring,
useTransform,
useTime,
wrap,
} from "framer-motion"
import { CountdownTimer } from "#/components/shared/CountdownTimer"
LiveTag,
SeasonCountdownSectionBackground,
CountdownTimer,
} from "#/components/shared/SeasonCountdownSection"

const MOCK_SEASON_DUE_TIMESTAMP = new Date(2024, 3, 20).getTime() / 1000

const MotionBox = motion(Box)

function Background() {
const containerRef = useRef(null)
const { scrollYProgress } = useScroll({
target: containerRef,
offset: ["center start", "start end"],
})
const smoothScrollYProgress = useSpring(scrollYProgress, {
damping: 10,
stiffness: 90,
mass: 0.75,
}) as MotionValue<number>
const foregroundParallax = useTransform(
smoothScrollYProgress,
[0, 1],
["25%", "65%"],
)
const time = useTime()
// Seed value is wrapped to prevent infinite increment causing potential memory leaks
const seed = useTransform(time, (value) => wrap(0, 2137, Math.floor(value)))

return (
<Box
as="svg"
ref={containerRef}
w="full"
h="full"
minH={720}
rounded="2xl"
pos="absolute"
inset={0}
zIndex={-1}
>
<defs>
<filter
id="noise-filter"
x="-20%"
y="-20%"
width="140%"
height="140%"
filterUnits="objectBoundingBox"
primitiveUnits="userSpaceOnUse"
colorInterpolationFilters="linearRGB"
>
<motion.feTurbulence
type="fractalNoise"
baseFrequency="0.119"
numOctaves="4"
seed={seed}
stitchTiles="stitch"
x="0%"
y="0%"
width="100%"
height="100%"
result="turbulence"
/>
<feSpecularLighting
surfaceScale="4"
specularConstant="3"
specularExponent="20"
lightingColor="#0600ff"
x="0%"
y="0%"
width="100%"
height="100%"
in="turbulence"
result="specularLighting"
>
<feDistantLight azimuth="3" elevation="107" />
</feSpecularLighting>
<feColorMatrix
type="saturate"
values="0"
x="0%"
y="0%"
width="100%"
height="100%"
in="specularLighting"
result="colormatrix"
/>
</filter>
</defs>
<Box as="rect" x="0" y="0" w="full" h="full" fill="brand.400" />
<Box as="g" mixBlendMode="overlay">
<Box
as="image"
href={seasonCountdownBackground}
w="full"
h="full"
preserveAspectRatio="xMidYMin slice"
/>
<Box
as={motion.image}
href={seasonCountdownForeground}
w="full"
h="full"
preserveAspectRatio="xMinYMin slice"
y={foregroundParallax}
/>
</Box>
<Box
as="rect"
mixBlendMode="soft-light"
w="full"
h="full"
fill="#0600ff"
filter="url(#noise-filter)"
opacity={0.64}
/>
</Box>
)
}

function LiveTag(props: TagProps) {
return (
<Tag
px={4}
py={2}
rounded="3xl"
bg="grey.700"
variant="solid"
pos="relative"
{...props}
>
<Box rounded="full" w={2} h={2} mr={3} bg="brand.400" />
<MotionBox
pos="absolute"
rounded="full"
w={2}
h={2}
bg="brand.400"
animate={{ scale: [1, 6], opacity: [0.5, 0] }}
transition={{
duration: 2,
ease: "easeInOut",
repeat: Infinity,
}}
/>
<TagLabel
color="gold.200"
textTransform="uppercase"
fontStyle="italic"
overflow="visible"
fontSize="md"
lineHeight={5}
fontWeight="bold"
>
Live
</TagLabel>
</Tag>
)
}

export default function SeasonCountdownSection() {
return (
<Box position="relative">
Expand All @@ -198,7 +30,7 @@ export default function SeasonCountdownSection() {
</Text>
<CountdownTimer timestamp={MOCK_SEASON_DUE_TIMESTAMP} />
</VStack>
<Background />
<SeasonCountdownSectionBackground />
</Box>
)
}

0 comments on commit a4ba563

Please sign in to comment.