Skip to content

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

fix: update animated gradient text api (#571)

Dillion Verma4896f73270ad
diff --git a/__registry__/index.tsx b/__registry__/index.tsx
index 25f9b6fd..81163156 100644
--- a/__registry__/index.tsx
+++ b/__registry__/index.tsx
@@ -2944,6 +2944,32 @@ export const Index: Record<string, any> = {
}),
meta: undefined,
},
+ "animated-gradient-text-demo-2": {
+ name: "animated-gradient-text-demo-2",
+ description:
+ "Second example showing text with animated gradient backgrounds.",
+ type: "registry:example",
+ registryDependencies: ["https://magicui.design/r/animated-gradient-text"],
+ files: [
+ {
+ path: "registry/example/animated-gradient-text-demo-2.tsx",
+ type: "registry:example",
+ target: "components/animated-gradient-text-demo-2.tsx",
+ },
+ ],
+ component: React.lazy(async () => {
+ const mod = await import(
+ "@/registry/example/animated-gradient-text-demo-2.tsx"
+ );
+ const exportName =
+ Object.keys(mod).find(
+ (key) =>
+ typeof mod[key] === "function" || typeof mod[key] === "object",
+ ) || item.name;
+ return { default: mod.default || mod[exportName] };
+ }),
+ meta: undefined,
+ },
"orbiting-circles-demo": {
name: "orbiting-circles-demo",
description: "Example showing circles moving in orbital paths.",
diff --git a/content/docs/components/animated-gradient-text.mdx b/content/docs/components/animated-gradient-text.mdx
index 0e0c2ad6..86eac148 100644
--- a/content/docs/components/animated-gradient-text.mdx
+++ b/content/docs/components/animated-gradient-text.mdx
@@ -65,9 +65,18 @@ module.exports = {
</Tabs>
+## Examples
+
+### Custom Speed
+
+<ComponentPreview name="animated-gradient-text-demo-2" />
+
## Props
-| Prop | Type | Default | Description |
-| ----------- | -------- | ------- | -------------------------------------- |
-| `children` | `node` | `-` | The children passed into the component |
-| `className` | `string` | `-` | The class name to be applied. |
+| Prop | Type | Default | Description |
+| ----------- | -------- | ----------- | -------------------------------------- |
+| `children` | `node` | `-` | The children passed into the component |
+| `className` | `string` | `-` | The class name to be applied |
+| `speed` | `number` | `1` | The speed of the gradient animation |
+| `colorFrom` | `string` | `"#ffaa40"` | The starting color of the gradient |
+| `colorTo` | `string` | `"#9c40ff"` | The ending color of the gradient |
diff --git a/public/r/animated-gradient-text-demo-2.json b/public/r/animated-gradient-text-demo-2.json
new file mode 100644
index 00000000..1c7f81d3
--- /dev/null
+++ b/public/r/animated-gradient-text-demo-2.json
@@ -0,0 +1,18 @@
+{
+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",
+ "name": "animated-gradient-text-demo-2",
+ "type": "registry:example",
+ "title": "Animated Gradient Text Demo 2",
+ "description": "Second example showing text with animated gradient backgrounds.",
+ "registryDependencies": [
+ "https://magicui.design/r/animated-gradient-text"
+ ],
+ "files": [
+ {
+ "path": "registry/example/animated-gradient-text-demo-2.tsx",
+ "content": "import { AnimatedGradientText } from \"@/components/magicui/animated-gradient-text\";\n\nexport default function AnimatedGradientTextDemo() {\n return (\n <AnimatedGradientText\n speed={2}\n colorFrom=\"#4ade80\"\n colorTo=\"#06b6d4\"\n className=\"text-4xl font-semibold tracking-tight\"\n >\n Fast Gradient\n </AnimatedGradientText>\n );\n}\n",
+ "type": "registry:example",
+ "target": "components/animated-gradient-text-demo-2.tsx"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/public/r/animated-gradient-text-demo.json b/public/r/animated-gradient-text-demo.json
index 9fed7edb..02fca298 100644
--- a/public/r/animated-gradient-text-demo.json
+++ b/public/r/animated-gradient-text-demo.json
@@ -13,7 +13,7 @@
"files": [
{
"path": "registry/example/animated-gradient-text-demo.tsx",
- "content": "import { ChevronRight } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { AnimatedGradientText } from \"@/components/magicui/animated-gradient-text\";\n\nexport default async function AnimatedGradientTextDemo() {\n return (\n <div className=\"z-10 flex min-h-64 items-center justify-center\">\n <AnimatedGradientText>\n πŸŽ‰ <hr className=\"mx-2 h-4 w-px shrink-0 bg-gray-300\" />{\" \"}\n <span\n className={cn(\n `inline animate-gradient bg-gradient-to-r from-[#ffaa40] via-[#9c40ff] to-[#ffaa40] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent`,\n )}\n >\n Introducing Magic UI\n </span>\n <ChevronRight className=\"ml-1 size-3 transition-transform duration-300 ease-in-out group-hover:translate-x-0.5\" />\n </AnimatedGradientText>\n </div>\n );\n}\n",
+ "content": "import { cn } from \"@/lib/utils\";\nimport { AnimatedGradientText } from \"@/components/magicui/animated-gradient-text\";\nimport { ChevronRight } from \"lucide-react\";\n\nexport default function AnimatedGradientTextDemo() {\n return (\n <div className=\"group relative mx-auto flex items-center justify-center rounded-full px-4 py-1.5 shadow-[inset_0_-8px_10px_#8fdfff1f] transition-shadow duration-500 ease-out hover:shadow-[inset_0_-5px_10px_#8fdfff3f] \">\n <span\n className={cn(\n \"absolute inset-0 block h-full w-full animate-gradient rounded-[inherit] bg-gradient-to-r from-[#ffaa40]/50 via-[#9c40ff]/50 to-[#ffaa40]/50 bg-[length:300%_100%] p-[1px]\",\n \"[mask-composite:subtract] [mask:linear-gradient(#fff_0_0)_content-box,linear-gradient(#fff_0_0)]\",\n )}\n />\n πŸŽ‰ <hr className=\"mx-2 h-4 w-px shrink-0 bg-neutral-500\" />\n <AnimatedGradientText className=\"text-sm font-medium\">\n Introducing Magic UI\n </AnimatedGradientText>\n <ChevronRight\n className=\"ml-1 size-4 stroke-neutral-500 transition-transform\n duration-300 ease-in-out group-hover:translate-x-0.5\"\n />\n </div>\n );\n}\n",
"type": "registry:example",
"target": "components/animated-gradient-text-demo.tsx"
}
diff --git a/public/r/animated-gradient-text.json b/public/r/animated-gradient-text.json
index 6d770f8f..51fd08b8 100644
--- a/public/r/animated-gradient-text.json
+++ b/public/r/animated-gradient-text.json
@@ -7,7 +7,7 @@
"files": [
{
"path": "registry/magicui/animated-gradient-text.tsx",
- "content": "import { ComponentPropsWithoutRef, ReactNode } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface AnimatedGradientTextProps\n extends ComponentPropsWithoutRef<\"div\"> {\n children: ReactNode;\n}\n\nexport function AnimatedGradientText({\n children,\n className,\n ...props\n}: AnimatedGradientTextProps) {\n return (\n <div\n className={cn(\n \"group relative mx-auto flex max-w-fit flex-row items-center justify-center rounded-2xl bg-white/40 px-4 py-1.5 text-sm font-medium shadow-[inset_0_-8px_10px_#8fdfff1f] backdrop-blur-sm transition-shadow duration-500 ease-out [--bg-size:300%] hover:shadow-[inset_0_-5px_10px_#8fdfff3f] dark:bg-black/40\",\n className,\n )}\n {...props}\n >\n <div\n className={`absolute inset-0 block h-full w-full animate-gradient bg-gradient-to-r from-[#ffaa40]/50 via-[#9c40ff]/50 to-[#ffaa40]/50 bg-[length:var(--bg-size)_100%] p-[1px] ![mask-composite:subtract] [border-radius:inherit] [mask:linear-gradient(#fff_0_0)_content-box,linear-gradient(#fff_0_0)]`}\n />\n\n {children}\n </div>\n );\n}\n",
+ "content": "import { cn } from \"@/lib/utils\";\nimport { ComponentPropsWithoutRef } from \"react\";\n\nexport interface AnimatedGradientTextProps\n extends ComponentPropsWithoutRef<\"div\"> {\n speed?: number;\n colorFrom?: string;\n colorTo?: string;\n}\n\nexport function AnimatedGradientText({\n children,\n className,\n speed = 1,\n colorFrom = \"#ffaa40\",\n colorTo = \"#9c40ff\",\n ...props\n}: AnimatedGradientTextProps) {\n return (\n <span\n style={\n {\n \"--bg-size\": `${speed * 300}%`,\n \"--color-from\": colorFrom,\n \"--color-to\": colorTo,\n } as React.CSSProperties\n }\n className={cn(\n `inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent`,\n className,\n )}\n {...props}\n >\n {children}\n </span>\n );\n}\n",
"type": "registry:ui",
"target": "components/magicui/animated-gradient-text.tsx"
}
@@ -22,7 +22,7 @@
"keyframes": {
"gradient": {
"to": {
- "backgroundPosition": "var(--bg-size) 0"
+ "backgroundPosition": "var(--bg-size, 300%) 0"
}
}
}
diff --git a/registry.json b/registry.json
index 591621f9..5be0bb7b 100644
--- a/registry.json
+++ b/registry.json
@@ -845,7 +845,7 @@
"keyframes": {
"gradient": {
"to": {
- "backgroundPosition": "var(--bg-size) 0"
+ "backgroundPosition": "var(--bg-size, 300%) 0"
}
}
}
@@ -2375,6 +2375,22 @@
}
]
},
+ {
+ "name": "animated-gradient-text-demo-2",
+ "type": "registry:example",
+ "title": "Animated Gradient Text Demo 2",
+ "description": "Second example showing text with animated gradient backgrounds.",
+ "registryDependencies": [
+ "https://magicui.design/r/animated-gradient-text"
+ ],
+ "files": [
+ {
+ "path": "registry/example/animated-gradient-text-demo-2.tsx",
+ "type": "registry:example",
+ "target": "components/animated-gradient-text-demo-2.tsx"
+ }
+ ]
+ },
{
"name": "orbiting-circles-demo",
"type": "registry:example",
diff --git a/registry/example/animated-gradient-text-demo-2.tsx b/registry/example/animated-gradient-text-demo-2.tsx
new file mode 100644
index 00000000..489bc8d1
--- /dev/null
+++ b/registry/example/animated-gradient-text-demo-2.tsx
@@ -0,0 +1,14 @@
+import { AnimatedGradientText } from "@/registry/magicui/animated-gradient-text";
+
+export default function AnimatedGradientTextDemo() {
+ return (
+ <AnimatedGradientText
+ speed={2}
+ colorFrom="#4ade80"
+ colorTo="#06b6d4"
+ className="text-4xl font-semibold tracking-tight"
+ >
+ Fast Gradient
+ </AnimatedGradientText>
+ );
+}
diff --git a/registry/example/animated-gradient-text-demo.tsx b/registry/example/animated-gradient-text-demo.tsx
index a9e87dbf..fba52855 100644
--- a/registry/example/animated-gradient-text-demo.tsx
+++ b/registry/example/animated-gradient-text-demo.tsx
@@ -1,22 +1,31 @@
-import { ChevronRight } from "lucide-react";
-
import { cn } from "@/lib/utils";
import { AnimatedGradientText } from "@/registry/magicui/animated-gradient-text";
+import { ChevronRight } from "lucide-react";
-export default async function AnimatedGradientTextDemo() {
+export default function AnimatedGradientTextDemo() {
return (
- <div className="z-10 flex min-h-64 items-center justify-center">
- <AnimatedGradientText>
- πŸŽ‰ <hr className="mx-2 h-4 w-px shrink-0 bg-gray-300" />{" "}
- <span
- className={cn(
- `inline animate-gradient bg-gradient-to-r from-[#ffaa40] via-[#9c40ff] to-[#ffaa40] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent`,
- )}
- >
- Introducing Magic UI
- </span>
- <ChevronRight className="ml-1 size-3 transition-transform duration-300 ease-in-out group-hover:translate-x-0.5" />
+ <div className="group relative mx-auto flex items-center justify-center rounded-full px-4 py-1.5 shadow-[inset_0_-8px_10px_#8fdfff1f] transition-shadow duration-500 ease-out hover:shadow-[inset_0_-5px_10px_#8fdfff3f] ">
+ <span
+ className={cn(
+ "absolute inset-0 block h-full w-full animate-gradient rounded-[inherit] bg-gradient-to-r from-[#ffaa40]/50 via-[#9c40ff]/50 to-[#ffaa40]/50 bg-[length:300%_100%] p-[1px]",
+ )}
+ style={{
+ WebkitMask:
+ "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
+ WebkitMaskComposite: "destination-out",
+ mask: "linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0)",
+ maskComposite: "subtract",
+ WebkitClipPath: "padding-box",
+ }}
+ />
+ πŸŽ‰ <hr className="mx-2 h-4 w-px shrink-0 bg-neutral-500" />
+ <AnimatedGradientText className="text-sm font-medium">
+ Introducing Magic UI
</AnimatedGradientText>
+ <ChevronRight
+ className="ml-1 size-4 stroke-neutral-500 transition-transform
+ duration-300 ease-in-out group-hover:translate-x-0.5"
+ />
</div>
);
}
diff --git a/registry/magicui/animated-gradient-text.tsx b/registry/magicui/animated-gradient-text.tsx
index adfcab89..22a75698 100644
--- a/registry/magicui/animated-gradient-text.tsx
+++ b/registry/magicui/animated-gradient-text.tsx
@@ -1,30 +1,37 @@
-import { ComponentPropsWithoutRef, ReactNode } from "react";
-
import { cn } from "@/lib/utils";
+import { ComponentPropsWithoutRef } from "react";
export interface AnimatedGradientTextProps
extends ComponentPropsWithoutRef<"div"> {
- children: ReactNode;
+ speed?: number;
+ colorFrom?: string;
+ colorTo?: string;
}
export function AnimatedGradientText({
children,
className,
+ speed = 1,
+ colorFrom = "#ffaa40",
+ colorTo = "#9c40ff",
...props
}: AnimatedGradientTextProps) {
return (
- <div
+ <span
+ style={
+ {
+ "--bg-size": `${speed * 300}%`,
+ "--color-from": colorFrom,
+ "--color-to": colorTo,
+ } as React.CSSProperties
+ }
className={cn(
- "group relative mx-auto flex max-w-fit flex-row items-center justify-center rounded-2xl bg-white/40 px-4 py-1.5 text-sm font-medium shadow-[inset_0_-8px_10px_#8fdfff1f] backdrop-blur-sm transition-shadow duration-500 ease-out [--bg-size:300%] hover:shadow-[inset_0_-5px_10px_#8fdfff3f] dark:bg-black/40",
+ `inline animate-gradient bg-gradient-to-r from-[var(--color-from)] via-[var(--color-to)] to-[var(--color-from)] bg-[length:var(--bg-size)_100%] bg-clip-text text-transparent`,
className,
)}
{...props}
>
- <div
- className={`absolute inset-0 block h-full w-full animate-gradient bg-gradient-to-r from-[#ffaa40]/50 via-[#9c40ff]/50 to-[#ffaa40]/50 bg-[length:var(--bg-size)_100%] p-[1px] ![mask-composite:subtract] [border-radius:inherit] [mask:linear-gradient(#fff_0_0)_content-box,linear-gradient(#fff_0_0)]`}
- />
-
{children}
- </div>
+ </span>
);
}
diff --git a/registry/registry-examples.ts b/registry/registry-examples.ts
index 495fc1c9..2d839e2c 100644
--- a/registry/registry-examples.ts
+++ b/registry/registry-examples.ts
@@ -856,6 +856,21 @@ export const examples: Registry["items"] = [
},
],
},
+ {
+ name: "animated-gradient-text-demo-2",
+ type: "registry:example",
+ title: "Animated Gradient Text Demo 2",
+ description:
+ "Second example showing text with animated gradient backgrounds.",
+ registryDependencies: ["https://magicui.design/r/animated-gradient-text"],
+ files: [
+ {
+ path: "registry/example/animated-gradient-text-demo-2.tsx",
+ type: "registry:example",
+ target: "components/animated-gradient-text-demo-2.tsx",
+ },
+ ],
+ },
{
name: "orbiting-circles-demo",
type: "registry:example",
diff --git a/registry/registry-ui.ts b/registry/registry-ui.ts
index 7c61e816..e0b924ab 100644
--- a/registry/registry-ui.ts
+++ b/registry/registry-ui.ts
@@ -743,7 +743,7 @@ export const ui: Registry["items"] = [
keyframes: {
gradient: {
to: {
- backgroundPosition: "var(--bg-size) 0",
+ backgroundPosition: "var(--bg-size, 300%) 0",
},
},
},
diff --git a/tailwind.config.cjs b/tailwind.config.cjs
index c7d7fb8b..61ab7b13 100644
--- a/tailwind.config.cjs
+++ b/tailwind.config.cjs
@@ -102,7 +102,7 @@ module.exports = {
},
gradient: {
to: {
- backgroundPosition: "var(--bg-size) 0",
+ backgroundPosition: "var(--bg-size, 300%) 0",
},
},
meteor: {