Blur Fade In
Blur Fade In is a React and Tailwind CSS effect component from Magic UI, licensed MIT. Copy it and paste it into your project.
Magic UI
MIT
effects
What it is
Blur Fade In is a React and Tailwind CSS effect component from Magic UI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i motion
Licence
This component comes from Magic UI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Blur Fade In
"use client"
import { useRef } from "react"
import {
AnimatePresence,
motion,
useInView,
type MotionProps,
type UseInViewOptions,
type Variants,
} from "motion/react"
type MarginType = UseInViewOptions["margin"]
interface BlurFadeProps extends MotionProps {
children: React.ReactNode
className?: string
variant?: {
hidden: { y: number }
visible: { y: number }
}
duration?: number
delay?: number
offset?: number
direction?: "up" | "down" | "left" | "right"
inView?: boolean
inViewMargin?: MarginType
blur?: string
}
const getFilter = (v: Variants[string]) =>
typeof v === "function" ? undefined : v.filter
export function BlurFade({
children,
className,
variant,
duration = 0.4,
delay = 0,
offset = 6,
direction = "down",
inView = false,
inViewMargin = "-50px",
blur = "6px",
...props
}: BlurFadeProps) {
const ref = useRef(null)
const inViewResult = useInView(ref, { once: true, margin: inViewMargin })
const isInView = !inView || inViewResult
const defaultVariants: Variants = {
hidden: {
[direction === "left" || direction === "right" ? "x" : "y"]:
direction === "right" || direction === "down" ? -offset : offset,
opacity: 0,
filter: `blur(${blur})`,
},
visible: {
[direction === "left" || direction === "right" ? "x" : "y"]: 0,
opacity: 1,
filter: `blur(0px)`,
},
}
const combinedVariants = variant ?? defaultVariants
const hiddenFilter = getFilter(combinedVariants.hidden)
const visibleFilter = getFilter(combinedVariants.visible)
const shouldTransitionFilter =
hiddenFilter != null &&
visibleFilter != null &&
hiddenFilter !== visibleFilter
return (
<AnimatePresence>
<motion.div
ref={ref}
initial="hidden"
animate={isInView ? "visible" : "hidden"}
exit="hidden"
variants={combinedVariants}
transition={{
delay: 0.04 + delay,
duration,
ease: "easeOut",
...(shouldTransitionFilter ? { filter: { duration } } : {}),
}}
className={className}
{...props}
>
{children}
</motion.div>
</AnimatePresence>
)
}