UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add word rotate component (#12)
Dillion Verma96571eb15b51
diff --git a/config/docs.ts b/config/docs.tsindex 3c15d43b..9c943f99 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -145,6 +145,12 @@ export const docsConfig: DocsConfig = {items: [],label: "",},+ {+ title: "Word Rotate",+ href: `/docs/components/word-rotate`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/word-rotate.mdx b/content/docs/components/word-rotate.mdxnew file mode 100644index 00000000..9469b15a--- /dev/null+++ b/content/docs/components/word-rotate.mdx@@ -0,0 +1,32 @@+---+title: Word Rotate+date: 2024-05-21+description: An vertical rotation of words+author: dillionverma+published: true+---++<ComponentPreview name="word-rotate-demo" />++<Steps>++### Installation++Copy and paste the following code into your project.++```text+components/magicui/word-rotate.tsx+```++<ComponentSource name="word-rotate" />++</Steps>++## Props++| Prop | Type | Description | Default |+| ----------- | --------------- | -------------------------------------------------- | ------- |+| className | string | The class name to be applied to the component | |+| duration | number | The class name to be applied to the shimmer. | 2500 |+| words | string[] | An array of words to rotate through | "" |+| framerProps | HTMLMotionProps | An object containing framer-motion animation props | {} |diff --git a/registry/components/example/word-rotate-demo.tsx b/registry/components/example/word-rotate-demo.tsxnew file mode 100644index 00000000..89e473eb--- /dev/null+++ b/registry/components/example/word-rotate-demo.tsx@@ -0,0 +1,23 @@+import WordRotate from "@/registry/components/magicui/word-rotate";++export default async function TextRevealDemo() {+ return (+ <WordRotate+ className="text-4xl font-bold text-black dark:text-white"+ words={[+ "Web Development.",+ "UI/UX Design.",+ "Cloud Computing.",+ "Web Security.",+ "Frontend Frameworks.",+ "Backend Architectures.",+ "API Design.",+ "Content Management Systems.",+ "SEO Strategies.",+ "Web Performance Optimization.",+ "Responsive Design.",+ "JavaScript Libraries.",+ ]}+ />+ );+}diff --git a/registry/components/magicui/word-rotate.tsx b/registry/components/magicui/word-rotate.tsxnew file mode 100644index 00000000..5325d671--- /dev/null+++ b/registry/components/magicui/word-rotate.tsx@@ -0,0 +1,49 @@+"use client";++import { cn } from "@/lib/utils";+import { AnimatePresence, HTMLMotionProps, motion } from "framer-motion";+import { useEffect, useState } from "react";++interface WordRotateProps {+ words: string[];+ duration?: number;+ framerProps?: HTMLMotionProps<"h1">;+ className?: string;+}++export default function WordRotate({+ words,+ duration = 2500,+ framerProps = {+ initial: { opacity: 0, y: -50 },+ animate: { opacity: 1, y: 0 },+ exit: { opacity: 0, y: 50 },+ transition: { duration: 0.25, ease: "easeOut" },+ },+ className,+}: WordRotateProps) {+ const [index, setIndex] = useState(0);++ useEffect(() => {+ const interval = setInterval(() => {+ setIndex((prevIndex) => (prevIndex + 1) % words.length);+ }, duration);++ // Clean up interval on unmount+ return () => clearInterval(interval);+ }, [words, duration]);++ return (+ <div className="overflow-hidden py-2">+ <AnimatePresence mode="wait">+ <motion.h1+ key={words[index]}+ className={cn(className)}+ {...framerProps}+ >+ {words[index]}+ </motion.h1>+ </AnimatePresence>+ </div>+ );+}diff --git a/registry/index.tsx b/registry/index.tsxindex 1679f0a6..11087b1f 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -137,6 +137,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/dock.tsx"],},+ "word-rotate": {+ name: "word-rotate",+ type: "components:ui",+ files: ["registry/components/magicui/word-rotate.tsx"],+ },};const example: Registry = {@@ -552,6 +557,14 @@ const example: Registry = {() => import("@/registry/components/example/dock-demo"),),},+ "word-rotate-demo": {+ name: "word-rotate-demo",+ type: "components:example",+ files: ["registry/components/example/word-rotate-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/word-rotate-demo"),+ ),+ },};export const registry: Registry = {