diff --git a/config/docs.ts b/config/docs.ts
index 53d6066fe..b60b4e79e 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -334,6 +334,12 @@ export const docsConfig: DocsConfig = {
items: [],
label: "",
},
+ {
+ title: "Text Underline",
+ href: `/docs/components/text-underline`,
+ items: [],
+ label: "New",
+ },
],
},
{
diff --git a/content/docs/components/text-underline.mdx b/content/docs/components/text-underline.mdx
new file mode 100644
index 000000000..13b88384f
--- /dev/null
+++ b/content/docs/components/text-underline.mdx
@@ -0,0 +1,53 @@
+---
+title: Text Underline
+date: 2024-05-23
+description: Text underline animation
+author: HydenLiu
+published: true
+---
+
+
+
+## Installation
+
+
+
+
+ CLI
+ Manual
+
+
+
+```bash
+npx magicui-cli add text-underline
+```
+
+
+
+
+
+
+
+Copy and paste the following code into your project.
+
+
+
+Update the import paths to match your project setup.
+
+
+
+
+
+
+
+## Props
+
+| Prop | Type | Description | Default |
+| --------------- | ------------------ | --------------------------------------------- | -------- |
+| className | string | The class name to be applied to the component | |
+| lineStrokeWidth | number \| string | Default width of the line | "0.1rem" |
+| duration | number | The class name to be applied to the shimmer | 0.5 |
+| word | string | An array of words to rotate through | "" |
+| startPlacement | "left" \| "right" | The position where this animation begin | "right" |
+| endPlacement | "left" \| "right" | TThe position where this animation end | "left" |
+| color | string \| string[] | Defines the color of the text line | "#000" |
diff --git a/registry/components/example/text-underline-demo.tsx b/registry/components/example/text-underline-demo.tsx
new file mode 100644
index 000000000..86a7cfe63
--- /dev/null
+++ b/registry/components/example/text-underline-demo.tsx
@@ -0,0 +1,28 @@
+import TextUnderline from "@/components/magicui/text-underline";
+
+export default async function TextUnderlineDemo() {
+ return (
+
+ );
+}
diff --git a/registry/components/magicui/text-underline.tsx b/registry/components/magicui/text-underline.tsx
new file mode 100644
index 000000000..cbb6cccbe
--- /dev/null
+++ b/registry/components/magicui/text-underline.tsx
@@ -0,0 +1,66 @@
+"use client";
+
+import { motion } from "framer-motion";
+
+import { cn } from "@/lib/utils";
+
+interface Props {
+ word: string;
+ duration?: number;
+ className?: string;
+ color?: string | string[];
+ lineStrokeWidth?: number | string;
+ startPlacement?: "left" | "right";
+ endPlacement?: "left" | "right";
+}
+
+export default function TextUnderline({
+ word,
+ duration = 0.5,
+ className,
+ color = "#000000",
+ lineStrokeWidth = "0.1rem",
+ startPlacement = "right",
+ endPlacement = "left",
+}: Props) {
+ const lineStroke =
+ typeof lineStrokeWidth === "number"
+ ? `${lineStrokeWidth}px`
+ : lineStrokeWidth;
+
+ const textVariants = {
+ initial: {
+ backgroundSize: `0% ${lineStroke}`,
+ backgroundPosition: `${startPlacement} bottom`,
+ },
+ hover: {
+ backgroundSize: `100% ${lineStroke}`,
+ backgroundPosition: `${endPlacement} bottom`,
+ },
+ };
+
+ const backgroundStyle = {
+ backgroundImage: `linear-gradient(to right, ${Array.isArray(color) ? color.join(",") : `${color}, ${color}`})`,
+ transitionDuration: `${duration}s`,
+ };
+
+ return (
+
+
+ {word}
+
+
+ );
+}
diff --git a/registry/index.tsx b/registry/index.tsx
index 568af1b0f..68c61e2b8 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -178,6 +178,11 @@ const ui: Registry = {
type: "components:magicui",
files: ["registry/components/magicui/flip-text.tsx"],
},
+ "text-underline": {
+ name: "text-underline",
+ type: "components:magicui",
+ files: ["registry/components/magicui/text-underline.tsx"],
+ },
"icon-cloud": {
name: "icon-cloud",
type: "components:magicui",
@@ -712,6 +717,15 @@ const example: Registry = {
() => import("@/registry/components/example/flip-text-demo"),
),
},
+ "text-underline-demo": {
+ name: "text-underline-demo",
+ type: "components:example",
+ registryDependencies: ["text-underline"],
+ files: ["registry/components/example/text-underline-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/text-underline-demo"),
+ ),
+ },
"sparkles-text-demo": {
name: "sparkles-text-demo",
type: "components:example",