UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add blur fade component
Dillion Verma5ef4ffc9c495
diff --git a/config/docs.ts b/config/docs.tsindex fe989890..de78e5b3 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -217,7 +217,17 @@ export const docsConfig: DocsConfig = {},],},-+ {+ title: "Animations",+ items: [+ {+ title: "Blur Fade",+ href: `/docs/components/blur-fade`,+ items: [],+ label: "New",+ },+ ],+ },{title: "Text Animations",items: [diff --git a/content/docs/components/blur-fade.mdx b/content/docs/components/blur-fade.mdxnew file mode 100644index 00000000..a9adb39b--- /dev/null+++ b/content/docs/components/blur-fade.mdx@@ -0,0 +1,59 @@+---+title: Blur Fade+date: 2024-07-07+description: Blur fade in and out animation. Used to smoothly fade in and out content.+author: dillionverma+published: true+---++<ComponentPreview name="blur-fade-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>+<TabsContent value="cli">++```bash+npx magicui-cli add blur-fade+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="blur-fade" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Examples++<ComponentPreview name="blur-fade-text-demo" />++## Props++| Prop | Type | Description | Default |+| ------------ | --------------- | ------------------------------------------------------ | ------- |+| children | React.ReactNode | The content to be animated | |+| className | string | The class name to be applied to the component | |+| variant | object | Custom animation variants for motion component | |+| duration | number | Duration (seconds) for the animation | 0.4 |+| delay | number | Delay (seconds) before the animation starts | 0 |+| yOffset | number | Vertical offset for the animation | 6 |+| inView | boolean | Whether to trigger animation when component is in view | false |+| inViewMargin | string | Margin for triggering the in-view animation | "-50px" |+| blur | string | Amount of blur to apply during the animation | "6px" |diff --git a/registry/components/example/blur-fade-demo.tsx b/registry/components/example/blur-fade-demo.tsxnew file mode 100644index 00000000..cc0cce7c--- /dev/null+++ b/registry/components/example/blur-fade-demo.tsx@@ -0,0 +1,26 @@+import BlurFade from "@/registry/components/magicui/blur-fade";++const images = Array.from({ length: 9 }, (_, i) => {+ const isLandscape = i % 2 === 0;+ const width = isLandscape ? 800 : 600;+ const height = isLandscape ? 600 : 800;+ return `https://picsum.photos/seed/${i + 1}/${width}/${height}`;+});++export default function BlurFadeDemo() {+ return (+ <section id="photos">+ <div className="columns-2 gap-4 sm:columns-3">+ {images.map((imageUrl, idx) => (+ <BlurFade key={imageUrl} delay={0.25 + idx * 0.05}>+ <img+ className="mb-4 size-full rounded-lg object-contain"+ src={imageUrl}+ alt={`Random stock image ${idx + 1}`}+ />+ </BlurFade>+ ))}+ </div>+ </section>+ );+}diff --git a/registry/components/example/blur-fade-text-demo.tsx b/registry/components/example/blur-fade-text-demo.tsxnew file mode 100644index 00000000..e86d99a7--- /dev/null+++ b/registry/components/example/blur-fade-text-demo.tsx@@ -0,0 +1,18 @@+import BlurFade from "@/registry/components/magicui/blur-fade";++export default function BlurFadeTextDemo() {+ return (+ <section id="header">+ <BlurFade delay={0.25} inView>+ <h2 className="text-3xl font-bold tracking-tighter sm:text-5xl xl:text-6xl/none">+ Hello World 👋+ </h2>+ </BlurFade>+ <BlurFade delay={0.25 * 2} inView>+ <span className="text-xl text-pretty tracking-tighter sm:text-3xl xl:text-4xl/none">+ Nice to meet you+ </span>+ </BlurFade>+ </section>+ );+}diff --git a/registry/components/magicui/blur-fade.tsx b/registry/components/magicui/blur-fade.tsxnew file mode 100644index 00000000..8204c7f0--- /dev/null+++ b/registry/components/magicui/blur-fade.tsx@@ -0,0 +1,59 @@+"use client";++import { useRef } from "react";+import { AnimatePresence, motion, useInView, Variants } from "framer-motion";++interface BlurFadeProps {+ children: React.ReactNode;+ className?: string;+ variant?: {+ hidden: { y: number };+ visible: { y: number };+ };+ duration?: number;+ delay?: number;+ yOffset?: number;+ inView?: boolean;+ inViewMargin?: string;+ blur?: string;+}++export default function BlurFade({+ children,+ className,+ variant,+ duration = 0.4,+ delay = 0,+ yOffset = 6,+ inView = false,+ inViewMargin = "-50px",+ blur = "6px",+}: BlurFadeProps) {+ const ref = useRef(null);+ const inViewResult = useInView(ref, { once: true, margin: inViewMargin });+ const isInView = !inView || inViewResult;+ const defaultVariants: Variants = {+ hidden: { y: yOffset, opacity: 0, filter: `blur(${blur})` },+ visible: { y: -yOffset, opacity: 1, filter: `blur(0px)` },+ };+ const combinedVariants = variant || defaultVariants;+ return (+ <AnimatePresence>+ <motion.div+ ref={ref}+ initial="hidden"+ animate={isInView ? "visible" : "hidden"}+ exit="hidden"+ variants={combinedVariants}+ transition={{+ delay: 0.04 + delay,+ duration,+ ease: "easeOut",+ }}+ className={className}+ >+ {children}+ </motion.div>+ </AnimatePresence>+ );+}diff --git a/registry/index.tsx b/registry/index.tsxindex 69bdf0c0..42818ace 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -234,6 +234,11 @@ const ui: Registry = {type: "components:magicui",files: ["registry/components/magicui/file-tree.tsx"],},+ "blur-fade": {+ name: "blur-fade",+ type: "components:magicui",+ files: ["registry/components/magicui/blur-fade.tsx"],+ },};const example: Registry = {@@ -630,7 +635,6 @@ const example: Registry = {() => import("@/registry/components/example/typing-animation-demo"),),},-"blur-in-demo": {name: "blur-in-demo",type: "components:example",@@ -640,7 +644,6 @@ const example: Registry = {() => import("@/registry/components/example/blur-in-demo"),),},-"scroll-based-velocity-demo": {name: "scroll-based-velocity-demo",type: "components:example",@@ -859,6 +862,22 @@ const example: Registry = {() => import("@/registry/components/example/file-tree-demo"),),},+ "blur-fade-demo": {+ name: "blur-fade-demo",+ type: "components:example",+ files: ["registry/components/example/blur-fade-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/blur-fade-demo"),+ ),+ },+ "blur-fade-text-demo": {+ name: "blur-fade-text-demo",+ type: "components:example",+ files: ["registry/components/example/blur-fade-text-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/blur-fade-text-demo"),+ ),+ },};export const registry: Registry = {...ui,