Skip to content

Instantly share code, notes, and snippets.

@onuro
Created June 17, 2023 23:04
Show Gist options
  • Save onuro/80e48d127387b0b18972adbf0059b58c to your computer and use it in GitHub Desktop.
Save onuro/80e48d127387b0b18972adbf0059b58c to your computer and use it in GitHub Desktop.
Staggered Framer Animation Code Override
import type { ComponentType } from "react"
import { Children, cloneElement } from "react"
// Learn more: https://www.framer.com/docs/guides/overrides/
export function withStaggerChildren(Component): ComponentType {
return (props: any) => {
const { children } = props
const clonedChildren = Children.map(children, (child, index) =>
cloneElement(child, {
...child.props,
initial: { opacity: 0, y: 60, skewX: -15 },
whileInView: {
opacity: 1,
y: 0,
skewX: 0,
transition: {
delay: 0.1 * index,
ease: "easeInOut",
type: "spring",
duration: 0.8,
bounce: 0,
damping: 20,
},
},
// viewport: { once: true },
})
)
return <Component {...props}>{clonedChildren}</Component>
}
}
export function withStaggerPlain(Component): ComponentType {
return (props: any) => {
const { children } = props
const clonedChildren = Children.map(children, (child, index) =>
cloneElement(child, {
...child.props,
initial: { opacity: 0, y: 60, skewX: 0 },
whileInView: {
opacity: 1,
y: 0,
skewX: 0,
transition: {
delay: 0.1 * index,
ease: "easeInOut",
type: "spring",
duration: 0.5,
bounce: 0,
damping: 20,
},
},
// viewport: { once: true },
})
)
return <Component {...props}>{clonedChildren}</Component>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment