-
Notifications
You must be signed in to change notification settings - Fork 2
Some animation #109
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
base: main
Are you sure you want to change the base?
Some animation #109
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import FadeIn from "@/components/animations/FadeIn"; | ||
|
|
||
| export default function Section({ | ||
| children, | ||
| title, | ||
| subtitle, | ||
| background = "", | ||
| className = "", | ||
| titleClassName = "", | ||
| animate = true, | ||
| animateTitle = true, | ||
| }) { | ||
| const bgClass = background === "grey" ? "bg-grey" : background; | ||
|
|
||
| const content = ( | ||
| <section className={`py-16 lg:py-24 px-4 lg:px-6 ${bgClass} ${className}`}> | ||
| <div className="max-w-screen-xl mx-auto"> | ||
| {(title || subtitle) && ( | ||
| <div className="text-center mb-6 lg:mb-8"> | ||
| {title && ( | ||
| animateTitle ? ( | ||
| <FadeIn> | ||
| <h2 className={`text-3xl font-bold ${titleClassName}`}>{title}</h2> | ||
| </FadeIn> | ||
| ) : ( | ||
| <h2 className={`text-3xl font-bold ${titleClassName}`}>{title}</h2> | ||
| ) | ||
| )} | ||
| {subtitle && ( | ||
| animateTitle ? ( | ||
| <FadeIn delay={0.1}> | ||
| <p className="font-light sm:text-xl mt-4">{subtitle}</p> | ||
| </FadeIn> | ||
| ) : ( | ||
| <p className="font-light sm:text-xl mt-4">{subtitle}</p> | ||
| ) | ||
| )} | ||
| </div> | ||
| )} | ||
| {children} | ||
| </div> | ||
| </section> | ||
| ); | ||
|
|
||
| return content; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| "use client"; | ||
| import { motion, useInView } from "framer-motion"; | ||
| import { useRef } from "react"; | ||
|
|
||
| const directionOffsets = { | ||
| up: { y: 40, x: 0 }, | ||
| down: { y: -40, x: 0 }, | ||
| left: { y: 0, x: 40 }, | ||
| right: { y: 0, x: -40 }, | ||
| none: { y: 0, x: 0 }, | ||
| }; | ||
|
|
||
| export default function FadeIn({ | ||
| children, | ||
| direction = "up", | ||
| delay = 0, | ||
| duration = 0.5, | ||
| className = "", | ||
| once = true, | ||
| threshold = 0.1, | ||
| }) { | ||
| const ref = useRef(null); | ||
| const isInView = useInView(ref, { once, amount: threshold }); | ||
|
|
||
| const offset = directionOffsets[direction] || directionOffsets.up; | ||
|
|
||
| return ( | ||
| <motion.div | ||
| ref={ref} | ||
| initial={{ opacity: 0, x: offset.x, y: offset.y }} | ||
| animate={isInView ? { opacity: 1, x: 0, y: 0 } : { opacity: 0, x: offset.x, y: offset.y }} | ||
| transition={{ | ||
| duration, | ||
| delay, | ||
| ease: "easeOut", | ||
| }} | ||
| className={className} | ||
| > | ||
| {children} | ||
| </motion.div> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| "use client"; | ||
| import { motion, useInView } from "framer-motion"; | ||
| import { useRef, Children, isValidElement } from "react"; | ||
|
|
||
| export default function StaggerContainer({ | ||
| children, | ||
| staggerDelay = 0.1, | ||
| initialDelay = 0, | ||
| duration = 0.5, | ||
| className = "", | ||
| once = true, | ||
| threshold = 0.1, | ||
| direction = "up", | ||
| }) { | ||
| const ref = useRef(null); | ||
| const isInView = useInView(ref, { once, amount: threshold }); | ||
|
|
||
| const directionOffsets = { | ||
| up: { y: 40, x: 0 }, | ||
| down: { y: -40, x: 0 }, | ||
| left: { y: 0, x: 40 }, | ||
| right: { y: 0, x: -40 }, | ||
| none: { y: 0, x: 0 }, | ||
| }; | ||
|
|
||
| const offset = directionOffsets[direction] || directionOffsets.up; | ||
|
|
||
| return ( | ||
| <div ref={ref} className={className}> | ||
| {Children.map(children, (child, index) => { | ||
| if (!isValidElement(child)) return child; | ||
|
|
||
| return ( | ||
| <motion.div | ||
| initial={{ opacity: 0, x: offset.x, y: offset.y }} | ||
| animate={ | ||
| isInView | ||
| ? { opacity: 1, x: 0, y: 0 } | ||
|
Comment on lines
+29
to
+38
|
||
| : { opacity: 0, x: offset.x, y: offset.y } | ||
| } | ||
| transition={{ | ||
| duration, | ||
| delay: initialDelay + index * staggerDelay, | ||
| ease: "easeOut", | ||
| }} | ||
| > | ||
| {child} | ||
| </motion.div> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
animateis exposed as a prop but never used. This makes theSectionAPI misleading (callers can’t actually disable the FadeIn behavior except viaanimateTitle). Either removeanimateor implement it (e.g., use it to disable all FadeIn wrappers / animated behavior in this component).