Blur Fade
magicui/blur-fadeFreeComponent
Blur fade in and out animation. Used to smoothly fade in and out content.
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/blur-fade.jsonSource
1"use client"23import { useRef } from "react"4import {5 AnimatePresence,6 motion,7 useInView,8 type MotionProps,9 type UseInViewOptions,10 type Variants,11} from "motion/react"1213type MarginType = UseInViewOptions["margin"]1415interface BlurFadeProps extends MotionProps {16 children: React.ReactNode17 className?: string18 variant?: {19 hidden: { y: number }20 visible: { y: number }21 }22 duration?: number23 delay?: number24 offset?: number25 direction?: "up" | "down" | "left" | "right"26 inView?: boolean27 inViewMargin?: MarginType28 blur?: string29}3031const getFilter = (v: Variants[string]) =>32 typeof v === "function" ? undefined : v.filter3334export function BlurFade({35 children,36 className,37 variant,38 duration = 0.4,39 delay = 0,40 offset = 6,41 direction = "down",42 inView = false,43 inViewMargin = "-50px",44 blur = "6px",45 ...props46}: BlurFadeProps) {47 const ref = useRef(null)48 const inViewResult = useInView(ref, { once: true, margin: inViewMargin })49 const isInView = !inView || inViewResult50 const defaultVariants: Variants = {51 hidden: {52 [direction === "left" || direction === "right" ? "x" : "y"]:53 direction === "right" || direction === "down" ? -offset : offset,54 opacity: 0,55 filter: `blur(${blur})`,56 },57 visible: {58 [direction === "left" || direction === "right" ? "x" : "y"]: 0,59 opacity: 1,60 filter: `blur(0px)`,61 },62 }63 const combinedVariants = variant ?? defaultVariants6465 const hiddenFilter = getFilter(combinedVariants.hidden)66 const visibleFilter = getFilter(combinedVariants.visible)6768 const shouldTransitionFilter =69 hiddenFilter != null &&70 visibleFilter != null &&71 hiddenFilter !== visibleFilter7273 return (74 <AnimatePresence>75 <motion.div76 ref={ref}77 initial="hidden"78 animate={isInView ? "visible" : "hidden"}79 exit="hidden"80 variants={combinedVariants}81 transition={{82 delay: 0.04 + delay,83 duration,84 ease: "easeOut",85 ...(shouldTransitionFilter ? { filter: { duration } } : {}),86 }}87 className={className}88 {...props}89 >90 {children}91 </motion.div>92 </AnimatePresence>93 )94}
What it pulls in
npm packages
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
