Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: correct extended type (#551)

Arghya Das7ced578ca8a2
diff --git a/content/docs/components/flip-text.mdx b/content/docs/components/flip-text.mdx
index a23ddfdf..4307febd 100644
--- a/content/docs/components/flip-text.mdx
+++ b/content/docs/components/flip-text.mdx
@@ -42,10 +42,11 @@ npx shadcn@latest add "https://magicui.design/r/flip-text"
## Props
-| Prop | Type | Default | Description |
-| --------------- | ----------------- | ------- | --------------------------------------------- |
-| `className` | `string` | `-` | The class name to be applied to the component |
-| `duration` | `number` | `0.2` | Duration of the animation |
-| `delayMultiple` | `number` | `0.08` | Transition delay multiplier. |
-| `word` | `string` | `""` | An array of words to rotate through |
-| `motionProps` | `HTMLMotionProps` | `{}` | An object containing motion animation props |
+| Prop | Type | Default | Description |
+| --------------- | ----------------- | ---------- | --------------------------------------------- |
+| `className` | `string` | `-` | The class name to be applied to the component |
+| `duration` | `number` | `0.5` | Duration of the animation |
+| `delayMultiple` | `number` | `0.08` | Transition delay multiplier. |
+| `variants` | `Variants` | `{}` | An object containing motion variants |
+| `as` | `ElementType` | `span` | The element type of the component |
+| `children` | `React.ReactNode` | `required` | The children of the component |
diff --git a/public/r/blur-fade.json b/public/r/blur-fade.json
index 8ce12888..319d6a70 100644
--- a/public/r/blur-fade.json
+++ b/public/r/blur-fade.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/blur-fade.tsx",
- "content": "\"use client\";\n\nimport {\n AnimatePresence,\n motion,\n useInView,\n UseInViewOptions,\n Variants,\n} from \"motion/react\";\nimport { useRef } from \"react\";\n\ntype MarginType = UseInViewOptions[\"margin\"];\n\ninterface BlurFadeProps {\n children: React.ReactNode;\n className?: string;\n variant?: {\n hidden: { y: number };\n visible: { y: number };\n };\n duration?: number;\n delay?: number;\n offset?: number;\n direction?: \"up\" | \"down\" | \"left\" | \"right\";\n inView?: boolean;\n inViewMargin?: MarginType;\n blur?: string;\n}\n\nexport function BlurFade({\n children,\n className,\n variant,\n duration = 0.4,\n delay = 0,\n offset = 6,\n direction = \"down\",\n inView = false,\n inViewMargin = \"-50px\",\n blur = \"6px\",\n}: BlurFadeProps) {\n const ref = useRef(null);\n const inViewResult = useInView(ref, { once: true, margin: inViewMargin });\n const isInView = !inView || inViewResult;\n const defaultVariants: Variants = {\n hidden: {\n [direction === \"left\" || direction === \"right\" ? \"x\" : \"y\"]:\n direction === \"right\" || direction === \"down\" ? -offset : offset,\n opacity: 0,\n filter: `blur(${blur})`,\n },\n visible: {\n [direction === \"left\" || direction === \"right\" ? \"x\" : \"y\"]: 0,\n opacity: 1,\n filter: `blur(0px)`,\n },\n };\n const combinedVariants = variant || defaultVariants;\n return (\n <AnimatePresence>\n <motion.div\n ref={ref}\n initial=\"hidden\"\n animate={isInView ? \"visible\" : \"hidden\"}\n exit=\"hidden\"\n variants={combinedVariants}\n transition={{\n delay: 0.04 + delay,\n duration,\n ease: \"easeOut\",\n }}\n className={className}\n >\n {children}\n </motion.div>\n </AnimatePresence>\n );\n}\n",
+ "content": "\"use client\";\n\nimport {\n AnimatePresence,\n motion,\n useInView,\n UseInViewOptions,\n Variants,\n MotionProps,\n} from \"motion/react\";\nimport { useRef } from \"react\";\n\ntype MarginType = UseInViewOptions[\"margin\"];\n\ninterface BlurFadeProps extends MotionProps {\n children: React.ReactNode;\n className?: string;\n variant?: {\n hidden: { y: number };\n visible: { y: number };\n };\n duration?: number;\n delay?: number;\n offset?: number;\n direction?: \"up\" | \"down\" | \"left\" | \"right\";\n inView?: boolean;\n inViewMargin?: MarginType;\n blur?: string;\n}\n\nexport function BlurFade({\n children,\n className,\n variant,\n duration = 0.4,\n delay = 0,\n offset = 6,\n direction = \"down\",\n inView = false,\n inViewMargin = \"-50px\",\n blur = \"6px\",\n ...props\n}: BlurFadeProps) {\n const ref = useRef(null);\n const inViewResult = useInView(ref, { once: true, margin: inViewMargin });\n const isInView = !inView || inViewResult;\n const defaultVariants: Variants = {\n hidden: {\n [direction === \"left\" || direction === \"right\" ? \"x\" : \"y\"]:\n direction === \"right\" || direction === \"down\" ? -offset : offset,\n opacity: 0,\n filter: `blur(${blur})`,\n },\n visible: {\n [direction === \"left\" || direction === \"right\" ? \"x\" : \"y\"]: 0,\n opacity: 1,\n filter: `blur(0px)`,\n },\n };\n const combinedVariants = variant || defaultVariants;\n return (\n <AnimatePresence>\n <motion.div\n ref={ref}\n initial=\"hidden\"\n animate={isInView ? \"visible\" : \"hidden\"}\n exit=\"hidden\"\n variants={combinedVariants}\n transition={{\n delay: 0.04 + delay,\n duration,\n ease: \"easeOut\",\n }}\n className={className}\n {...props}\n >\n {children}\n </motion.div>\n </AnimatePresence>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/blur-fade.tsx"
}
diff --git a/public/r/flip-text-demo.json b/public/r/flip-text-demo.json
index 3b6fb400..9bfeb4fe 100644
--- a/public/r/flip-text-demo.json
+++ b/public/r/flip-text-demo.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/example/flip-text-demo.tsx",
- "content": "import { FlipText } from \"@/components/magicui/flip-text\";\n\nexport default function FlipTextDemo() {\n return (\n <FlipText\n className=\"text-4xl font-bold -tracking-widest text-black dark:text-white md:text-7xl md:leading-[5rem]\"\n word=\"Flip Text\"\n />\n );\n}\n",
+ "content": "import { FlipText } from \"@/components/magicui/flip-text\";\n\nexport default function FlipTextDemo() {\n return (\n <FlipText className=\"text-4xl font-bold -tracking-widest text-black dark:text-white md:text-7xl md:leading-[5rem]\">\n Flip Text\n </FlipText>\n );\n}\n",
"type": "registry:example",
"target": "components/flip-text-demo.tsx"
}
diff --git a/public/r/flip-text.json b/public/r/flip-text.json
index 9dcf2fc6..28fad17a 100644
--- a/public/r/flip-text.json
+++ b/public/r/flip-text.json
@@ -10,7 +10,7 @@
"files": [
{
"path": "registry/magicui/flip-text.tsx",
- "content": "\"use client\";\n\nimport { AnimatePresence, motion, Variants } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface FlipTextProps {\n word: string;\n duration?: number;\n delayMultiple?: number;\n framerProps?: Variants;\n className?: string;\n}\n\nexport function FlipText({\n word,\n duration = 0.5,\n delayMultiple = 0.08,\n framerProps = {\n hidden: { rotateX: -90, opacity: 0 },\n visible: { rotateX: 0, opacity: 1 },\n },\n className,\n}: FlipTextProps) {\n return (\n <div className=\"flex justify-center space-x-2\">\n <AnimatePresence mode=\"wait\">\n {word.split(\"\").map((char, i) => (\n <motion.span\n key={i}\n initial=\"hidden\"\n animate=\"visible\"\n exit=\"hidden\"\n variants={framerProps}\n transition={{ duration, delay: i * delayMultiple }}\n className={cn(\"origin-center drop-shadow-sm\", className)}\n >\n {char}\n </motion.span>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n",
+ "content": "\"use client\";\n\nimport { AnimatePresence, motion, Variants, MotionProps } from \"motion/react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { ElementType } from \"react\";\nimport React from \"react\";\n\ninterface FlipTextProps extends MotionProps {\n /** The duration of the animation */\n duration?: number;\n /** The delay between each character */\n delayMultiple?: number;\n /** The variants of the animation */\n framerProps?: Variants;\n /** The class name of the component */\n className?: string;\n /** The element type of the component */\n as?: ElementType;\n /** The children of the component */\n children: React.ReactNode;\n /** The variants of the animation */\n variants?: Variants;\n}\n\nconst defaultVariants: Variants = {\n hidden: { rotateX: -90, opacity: 0 },\n visible: { rotateX: 0, opacity: 1 },\n};\n\nexport function FlipText({\n children,\n duration = 0.5,\n delayMultiple = 0.08,\n\n className,\n as: Component = \"span\",\n variants,\n ...props\n}: FlipTextProps) {\n const MotionComponent = motion.create(Component);\n const characters = React.Children.toArray(children).join(\"\").split(\"\");\n\n return (\n <div className=\"flex justify-center space-x-2\">\n <AnimatePresence mode=\"wait\">\n {characters.map((char, i) => (\n <MotionComponent\n key={i}\n initial=\"hidden\"\n animate=\"visible\"\n exit=\"hidden\"\n variants={variants || defaultVariants}\n transition={{ duration, delay: i * delayMultiple }}\n className={cn(\"origin-center drop-shadow-sm\", className)}\n {...props}\n >\n {char}\n </MotionComponent>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/flip-text.tsx"
}
diff --git a/registry/example/flip-text-demo.tsx b/registry/example/flip-text-demo.tsx
index b2cf1763..a8b68304 100644
--- a/registry/example/flip-text-demo.tsx
+++ b/registry/example/flip-text-demo.tsx
@@ -2,9 +2,8 @@ import { FlipText } from "@/registry/magicui/flip-text";
export default function FlipTextDemo() {
return (
- <FlipText
- className="text-4xl font-bold -tracking-widest text-black dark:text-white md:text-7xl md:leading-[5rem]"
- word="Flip Text"
- />
+ <FlipText className="text-4xl font-bold -tracking-widest text-black dark:text-white md:text-7xl md:leading-[5rem]">
+ Flip Text
+ </FlipText>
);
}
diff --git a/registry/magicui/blur-fade.tsx b/registry/magicui/blur-fade.tsx
index 0d3361b2..5f83fc5b 100644
--- a/registry/magicui/blur-fade.tsx
+++ b/registry/magicui/blur-fade.tsx
@@ -6,12 +6,13 @@ import {
useInView,
UseInViewOptions,
Variants,
+ MotionProps,
} from "motion/react";
import { useRef } from "react";
type MarginType = UseInViewOptions["margin"];
-interface BlurFadeProps {
+interface BlurFadeProps extends MotionProps {
children: React.ReactNode;
className?: string;
variant?: {
@@ -38,6 +39,7 @@ export function BlurFade({
inView = false,
inViewMargin = "-50px",
blur = "6px",
+ ...props
}: BlurFadeProps) {
const ref = useRef(null);
const inViewResult = useInView(ref, { once: true, margin: inViewMargin });
@@ -70,6 +72,7 @@ export function BlurFade({
ease: "easeOut",
}}
className={className}
+ {...props}
>
{children}
</motion.div>
diff --git a/registry/magicui/flip-text.tsx b/registry/magicui/flip-text.tsx
index c1a132af..d701c73d 100644
--- a/registry/magicui/flip-text.tsx
+++ b/registry/magicui/flip-text.tsx
@@ -1,42 +1,62 @@
"use client";
-import { AnimatePresence, motion, Variants } from "motion/react";
+import { AnimatePresence, motion, Variants, MotionProps } from "motion/react";
import { cn } from "@/lib/utils";
+import { ElementType } from "react";
+import React from "react";
-interface FlipTextProps {
- word: string;
+interface FlipTextProps extends MotionProps {
+ /** The duration of the animation */
duration?: number;
+ /** The delay between each character */
delayMultiple?: number;
+ /** The variants of the animation */
framerProps?: Variants;
+ /** The class name of the component */
className?: string;
+ /** The element type of the component */
+ as?: ElementType;
+ /** The children of the component */
+ children: React.ReactNode;
+ /** The variants of the animation */
+ variants?: Variants;
}
+const defaultVariants: Variants = {
+ hidden: { rotateX: -90, opacity: 0 },
+ visible: { rotateX: 0, opacity: 1 },
+};
+
export function FlipText({
- word,
+ children,
duration = 0.5,
delayMultiple = 0.08,
- framerProps = {
- hidden: { rotateX: -90, opacity: 0 },
- visible: { rotateX: 0, opacity: 1 },
- },
+
className,
+ as: Component = "span",
+ variants,
+ ...props
}: FlipTextProps) {
+ const MotionComponent = motion.create(Component);
+ const characters = React.Children.toArray(children).join("").split("");
+
return (
<div className="flex justify-center space-x-2">
<AnimatePresence mode="wait">
- {word.split("").map((char, i) => (
- <motion.span
+ {characters.map((char, i) => (
+ <MotionComponent
key={i}
initial="hidden"
animate="visible"
exit="hidden"
- variants={framerProps}
+ variants={variants || defaultVariants}
transition={{ duration, delay: i * delayMultiple }}
className={cn("origin-center drop-shadow-sm", className)}
+ {...props}
>
{char}
- </motion.span>
+ </MotionComponent>
))}
</AnimatePresence>
</div>