UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add wavy text component (#30)
Ali2c96277adb68
diff --git a/config/docs.ts b/config/docs.tsindex 4f867e64..f9866e56 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -157,6 +157,12 @@ export const docsConfig: DocsConfig = {items: [],label: "New",},+ {+ title: "Wavy Text",+ href: `/docs/components/wavy-text`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/wavy-text.mdx b/content/docs/components/wavy-text.mdxnew file mode 100644index 00000000..fd7f9495--- /dev/null+++ b/content/docs/components/wavy-text.mdx@@ -0,0 +1,34 @@+---+title: Wave Text+date: 2024-05-23+description: An animated text component that waves the text.+author: DoffuXx+published: true+---++<ComponentPreview name="wavy-text-demo" />++<Steps>++### Installation++Copy and paste the following code into your project.++```text+components/magicui/wavy-text.tsx+```++<ComponentSource name="wavy-text" />++</Steps>++## Props++| Prop | Type | Description | Default |+| ----------- | --------------- | -------------------------------------------------- | ------- |+| className | string | The class name to be applied to the component | |+| duration | number | Durations (seconds) for the animation | 0.5 |+| words | string | The word to be animated | |+| variant | object | Custom animation variants for motion component | hidden: { y: 10 },+ visible: { y: -10 },+ |diff --git a/registry/components/example/wavy-text-demo.tsx b/registry/components/example/wavy-text-demo.tsxnew file mode 100644index 00000000..f37196fa--- /dev/null+++ b/registry/components/example/wavy-text-demo.tsx@@ -0,0 +1,11 @@+import WavyText from "../magicui/wavy-text";++const WavyTextDemo = () => {+ return (+ <WavyText+ word="Hello, World!"+ className="text-4xl font-bold text-black dark:text-white"+ />+ );+};+export default WavyTextDemo;diff --git a/registry/components/magicui/wavy-text.tsx b/registry/components/magicui/wavy-text.tsxnew file mode 100644index 00000000..85de2a4b--- /dev/null+++ b/registry/components/magicui/wavy-text.tsx@@ -0,0 +1,58 @@+"use client";++import { cn } from "@/lib/utils";+import { AnimatePresence, motion } from "framer-motion";+import { useMemo } from "react";++interface WavyTextProps {+ word: string;+ className?: string;+ variant?: {+ hidden: { y: number };+ visible: { y: number };+ };+ duration?: number;+}+const WavyText = ({+ word,+ className,+ variant,+ duration = 0.5,+}: WavyTextProps) => {+ const defaultVariants = {+ hidden: { y: 10 },+ visible: { y: -10 },+ };+ const combinedVariants = variant || defaultVariants;+ const characters = useMemo(() => word.split(""), [word]);+ return (+ <div className="overflow-hidden py-2">+ <div className="flex justify-center space-x-2">+ <AnimatePresence>+ {characters.map((char, i) => (+ <motion.h1+ key={i}+ initial="hidden"+ animate="visible"+ exit="hidden"+ variants={combinedVariants}+ transition={{+ yoyo: Infinity,+ duration: duration,+ delay: i * 0.2,+ }}+ className={cn(+ className,+ "font-display text-center text-4xl font-bold tracking-[-0.02em] drop-shadow-sm md:text-7xl md:leading-[5rem]",+ )}+ >+ {char}+ </motion.h1>+ ))}+ </AnimatePresence>+ </div>+ </div>+ );+};++export default WavyText;diff --git a/registry/index.tsx b/registry/index.tsxindex 4dd9fece..36153dd8 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -147,6 +147,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/typing-animation.tsx"],},+ "wavy-text": {+ name: "wavy-text",+ type: "components:ui",+ files: ["registry/components/magicui/wavy-text.tsx"],+ },};const example: Registry = {@@ -578,6 +583,14 @@ const example: Registry = {() => import("@/registry/components/example/typing-animation-demo"),),},+ "wavy-text-demo": {+ name: "wavy-text-demo",+ type: "components:example",+ files: ["registry/components/example/wavy-text-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/wavy-text-demo"),+ ),+ },};export const registry: Registry = {