UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
Feat: Add Spinning Text Component (#539)
Aayush Bharti594f5ba05a4c
diff --git a/__registry__/index.tsx b/__registry__/index.tsxindex 07e87f8c..c6a9e316 100644--- a/__registry__/index.tsx+++ b/__registry__/index.tsx@@ -984,6 +984,30 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "spinning-text": {+ name: "spinning-text",+ description:+ "The Spinning Text component animates text in a circular motion with customizable speed, direction, color, and transitions for dynamic and engaging effects.",+ type: "registry:ui",+ registryDependencies: undefined,+ files: [+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/magicui/spinning-text.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,+ },"flip-text": {name: "flip-text",description: "Text flipping character animation",@@ -3402,6 +3426,62 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "spinning-text-demo": {+ name: "spinning-text-demo",+ description: "Example showing spinning text animation.",+ type: "registry:example",+ registryDependencies: ["https://magicui.design/r/spinning-text"],+ files: [+ {+ path: "registry/example/spinning-text-demo.tsx",+ type: "registry:example",+ target: "components/spinning-text-demo.tsx",+ },+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/spinning-text-demo.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,+ },+ "spinning-text-demo-2": {+ name: "spinning-text-demo-2",+ description: "Example showing spinning text animation.",+ type: "registry:example",+ registryDependencies: ["https://magicui.design/r/spinning-text"],+ files: [+ {+ path: "registry/example/spinning-text-demo-2.tsx",+ type: "registry:example",+ target: "components/spinning-text-demo-2.tsx",+ },+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/spinning-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,+ },"icon-cloud-demo": {name: "icon-cloud-demo",description: "Example showing an interactive 3D icon cloud.",diff --git a/config/docs.ts b/config/docs.tsindex 1ba513ea..787e2ceb 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -413,6 +413,12 @@ export const docsConfig: DocsConfig = {items: [],label: "",},+ {+ title: "Spinning Text",+ href: `/docs/components/spinning-text`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/spinning-text.mdx b/content/docs/components/spinning-text.mdxnew file mode 100644index 00000000..73da21b2--- /dev/null+++ b/content/docs/components/spinning-text.mdx@@ -0,0 +1,66 @@+---+title: Spinning Text+date: 2025-02-09+description: The Spinning Text component animates text in a circular motion with customizable speed, direction, color, and transitions for dynamic and engaging effects.+author: aayushbharti+published: true+---++<ComponentPreview name="spinning-text-demo" />++## Installation++<Tabs defaultValue="cli">++<TabsList>+ <TabsTrigger value="cli">CLI</TabsTrigger>+ <TabsTrigger value="manual">Manual</TabsTrigger>+</TabsList>++<TabsContent value="cli">++```bash+npx shadcn@latest add "https://magicui.design/r/spinning-text"+```++</TabsContent>++<TabsContent value="manual">++<Steps>++<Step>Copy and paste the following code into your project.</Step>++<ComponentSource name="spinning-text" />++<Step>Update the import paths to match your project setup.</Step>++</Steps>++</TabsContent>++</Tabs>++## Examples++### Reverse++<ComponentPreview name="spinning-text-demo-2" />++## Props++| Prop | Type | Default | Description |+| ------------ | -------------------------------------------- | ------- | ------------------------------------------------------- |+| `children` | `ReactElement` | | The text content to be animated in a circular motion. |+| `style` | `CSSProperties` | `{}` | Custom styles for the text container. |+| `duration` | `number` | `10` | The duration of the full circular rotation animation. |+| `className` | `string` | | A custom class name for the text container. |+| `reverse` | `boolean` | `false` | Determines if the animation should rotate in reverse. |+| `fontSize` | `number` | `1` | The font size of the text being animated in rem. |+| `radius` | `number` | `5` | The radius of the circular path for the text animation. |+| `transition` | `Transition` | | Custom transition effects for the animation. |+| `variants` | `{ container?: Variants; item?: Variants; }` | | Variants for container and item animations. |++## Credits++- Credit to [@AayushBharti](https://github.com/AayushBharti)diff --git a/public/r/spinning-text-demo-2.json b/public/r/spinning-text-demo-2.jsonnew file mode 100644index 00000000..37689646--- /dev/null+++ b/public/r/spinning-text-demo-2.json@@ -0,0 +1,24 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "spinning-text-demo-2",+ "type": "registry:example",+ "title": "Spinning Text Demo 2",+ "description": "Example showing spinning text animation.",+ "registryDependencies": [+ "https://magicui.design/r/spinning-text"+ ],+ "files": [+ {+ "path": "registry/example/spinning-text-demo-2.tsx",+ "content": "import { SpinningText } from \"@/components/magicui/spinning-text\";\n\nexport default function SpinningTextBasic() {\n return (\n <SpinningText reverse className=\"text-4xl\" duration={4} radius={6}>\n learn more • earn more • grow more •\n </SpinningText>\n );\n}\n",+ "type": "registry:example",+ "target": "components/spinning-text-demo-2.tsx"+ },+ {+ "path": "registry/magicui/spinning-text.tsx",+ "content": "\"use client\";\nimport { cn } from \"@/lib/utils\";\nimport { motion, Transition, Variants } from \"motion/react\";\nimport React, { CSSProperties } from \"react\";\n\ntype SpinningTextProps = {\n children: string | string[];\n style?: CSSProperties;\n duration?: number;\n className?: string;\n reverse?: boolean;\n fontSize?: number;\n radius?: number;\n transition?: Transition;\n variants?: {\n container?: Variants;\n item?: Variants;\n };\n};\n\nconst BASE_TRANSITION = {\n repeat: Infinity,\n ease: \"linear\",\n};\n\nconst BASE_ITEM_VARIANTS = {\n hidden: {\n opacity: 1,\n },\n visible: {\n opacity: 1,\n },\n};\n\nexport function SpinningText({\n children,\n duration = 10,\n style,\n className,\n reverse = false,\n radius = 5,\n transition,\n variants,\n}: SpinningTextProps) {\n if (typeof children !== \"string\" && !Array.isArray(children)) {\n throw new Error(\"children must be a string or an array of strings\");\n }\n\n if (Array.isArray(children)) {\n // Validate all elements are strings\n if (!children.every((child) => typeof child === \"string\")) {\n throw new Error(\"all elements in children array must be strings\");\n }\n children = children.join(\"\");\n }\n\n const letters = children.split(\"\");\n letters.push(\" \");\n\n const finalTransition = {\n ...BASE_TRANSITION,\n ...transition,\n duration: (transition as { duration?: number })?.duration ?? duration,\n };\n\n const containerVariants = {\n visible: { rotate: reverse ? -360 : 360 },\n ...variants?.container,\n };\n\n const itemVariants = {\n ...BASE_ITEM_VARIANTS,\n ...variants?.item,\n };\n\n return (\n <motion.div\n className={cn(\"relative\", className)}\n style={{\n ...style,\n }}\n initial=\"hidden\"\n animate=\"visible\"\n variants={containerVariants}\n transition={finalTransition}\n >\n {letters.map((letter, index) => (\n <motion.span\n aria-hidden=\"true\"\n key={`${index}-${letter}`}\n variants={itemVariants}\n className=\"absolute left-1/2 top-1/2 inline-block\"\n style={\n {\n \"--index\": index,\n \"--total\": letters.length,\n \"--radius\": radius,\n transform: `\n translate(-50%, -50%)\n rotate(calc(360deg / var(--total) * var(--index)))\n translateY(calc(var(--radius, 5) * -1ch))\n `,\n transformOrigin: \"center\",\n } as React.CSSProperties\n }\n >\n {letter}\n </motion.span>\n ))}\n <span className=\"sr-only\">{children}</span>\n </motion.div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+}\ No newline at end of filediff --git a/public/r/spinning-text-demo.json b/public/r/spinning-text-demo.jsonnew file mode 100644index 00000000..ca41e84d--- /dev/null+++ b/public/r/spinning-text-demo.json@@ -0,0 +1,24 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "spinning-text-demo",+ "type": "registry:example",+ "title": "Spinning Text Demo",+ "description": "Example showing spinning text animation.",+ "registryDependencies": [+ "https://magicui.design/r/spinning-text"+ ],+ "files": [+ {+ "path": "registry/example/spinning-text-demo.tsx",+ "content": "import { SpinningText } from \"@/components/magicui/spinning-text\";\n\nexport default function SpinningTextBasic() {\n return <SpinningText>learn more • earn more • grow more •</SpinningText>;\n}\n",+ "type": "registry:example",+ "target": "components/spinning-text-demo.tsx"+ },+ {+ "path": "registry/magicui/spinning-text.tsx",+ "content": "\"use client\";\nimport { cn } from \"@/lib/utils\";\nimport { motion, Transition, Variants } from \"motion/react\";\nimport React, { CSSProperties } from \"react\";\n\ntype SpinningTextProps = {\n children: string | string[];\n style?: CSSProperties;\n duration?: number;\n className?: string;\n reverse?: boolean;\n fontSize?: number;\n radius?: number;\n transition?: Transition;\n variants?: {\n container?: Variants;\n item?: Variants;\n };\n};\n\nconst BASE_TRANSITION = {\n repeat: Infinity,\n ease: \"linear\",\n};\n\nconst BASE_ITEM_VARIANTS = {\n hidden: {\n opacity: 1,\n },\n visible: {\n opacity: 1,\n },\n};\n\nexport function SpinningText({\n children,\n duration = 10,\n style,\n className,\n reverse = false,\n radius = 5,\n transition,\n variants,\n}: SpinningTextProps) {\n if (typeof children !== \"string\" && !Array.isArray(children)) {\n throw new Error(\"children must be a string or an array of strings\");\n }\n\n if (Array.isArray(children)) {\n // Validate all elements are strings\n if (!children.every((child) => typeof child === \"string\")) {\n throw new Error(\"all elements in children array must be strings\");\n }\n children = children.join(\"\");\n }\n\n const letters = children.split(\"\");\n letters.push(\" \");\n\n const finalTransition = {\n ...BASE_TRANSITION,\n ...transition,\n duration: (transition as { duration?: number })?.duration ?? duration,\n };\n\n const containerVariants = {\n visible: { rotate: reverse ? -360 : 360 },\n ...variants?.container,\n };\n\n const itemVariants = {\n ...BASE_ITEM_VARIANTS,\n ...variants?.item,\n };\n\n return (\n <motion.div\n className={cn(\"relative\", className)}\n style={{\n ...style,\n }}\n initial=\"hidden\"\n animate=\"visible\"\n variants={containerVariants}\n transition={finalTransition}\n >\n {letters.map((letter, index) => (\n <motion.span\n aria-hidden=\"true\"\n key={`${index}-${letter}`}\n variants={itemVariants}\n className=\"absolute left-1/2 top-1/2 inline-block\"\n style={\n {\n \"--index\": index,\n \"--total\": letters.length,\n \"--radius\": radius,\n transform: `\n translate(-50%, -50%)\n rotate(calc(360deg / var(--total) * var(--index)))\n translateY(calc(var(--radius, 5) * -1ch))\n `,\n transformOrigin: \"center\",\n } as React.CSSProperties\n }\n >\n {letter}\n </motion.span>\n ))}\n <span className=\"sr-only\">{children}</span>\n </motion.div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+}\ No newline at end of filediff --git a/public/r/spinning-text.json b/public/r/spinning-text.jsonnew file mode 100644index 00000000..d7522176--- /dev/null+++ b/public/r/spinning-text.json@@ -0,0 +1,18 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "spinning-text",+ "type": "registry:ui",+ "title": "Spinning Text",+ "description": "The Spinning Text component animates text in a circular motion with customizable speed, direction, color, and transitions for dynamic and engaging effects.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/spinning-text.tsx",+ "content": "\"use client\";\nimport { cn } from \"@/lib/utils\";\nimport { motion, Transition, Variants } from \"motion/react\";\nimport React, { CSSProperties } from \"react\";\n\ntype SpinningTextProps = {\n children: string | string[];\n style?: CSSProperties;\n duration?: number;\n className?: string;\n reverse?: boolean;\n fontSize?: number;\n radius?: number;\n transition?: Transition;\n variants?: {\n container?: Variants;\n item?: Variants;\n };\n};\n\nconst BASE_TRANSITION = {\n repeat: Infinity,\n ease: \"linear\",\n};\n\nconst BASE_ITEM_VARIANTS = {\n hidden: {\n opacity: 1,\n },\n visible: {\n opacity: 1,\n },\n};\n\nexport function SpinningText({\n children,\n duration = 10,\n style,\n className,\n reverse = false,\n radius = 5,\n transition,\n variants,\n}: SpinningTextProps) {\n if (typeof children !== \"string\" && !Array.isArray(children)) {\n throw new Error(\"children must be a string or an array of strings\");\n }\n\n if (Array.isArray(children)) {\n // Validate all elements are strings\n if (!children.every((child) => typeof child === \"string\")) {\n throw new Error(\"all elements in children array must be strings\");\n }\n children = children.join(\"\");\n }\n\n const letters = children.split(\"\");\n letters.push(\" \");\n\n const finalTransition = {\n ...BASE_TRANSITION,\n ...transition,\n duration: (transition as { duration?: number })?.duration ?? duration,\n };\n\n const containerVariants = {\n visible: { rotate: reverse ? -360 : 360 },\n ...variants?.container,\n };\n\n const itemVariants = {\n ...BASE_ITEM_VARIANTS,\n ...variants?.item,\n };\n\n return (\n <motion.div\n className={cn(\"relative\", className)}\n style={{\n ...style,\n }}\n initial=\"hidden\"\n animate=\"visible\"\n variants={containerVariants}\n transition={finalTransition}\n >\n {letters.map((letter, index) => (\n <motion.span\n aria-hidden=\"true\"\n key={`${index}-${letter}`}\n variants={itemVariants}\n className=\"absolute left-1/2 top-1/2 inline-block\"\n style={\n {\n \"--index\": index,\n \"--total\": letters.length,\n \"--radius\": radius,\n transform: `\n translate(-50%, -50%)\n rotate(calc(360deg / var(--total) * var(--index)))\n translateY(calc(var(--radius, 5) * -1ch))\n `,\n transformOrigin: \"center\",\n } as React.CSSProperties\n }\n >\n {letter}\n </motion.span>\n ))}\n <span className=\"sr-only\">{children}</span>\n </motion.div>\n );\n}\n",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+}\ No newline at end of filediff --git a/registry.json b/registry.jsonindex 4753f9d8..b98431f4 100644--- a/registry.json+++ b/registry.json@@ -967,6 +967,22 @@}]},+ {+ "name": "spinning-text",+ "type": "registry:ui",+ "title": "Spinning Text",+ "description": "The Spinning Text component animates text in a circular motion with customizable speed, direction, color, and transitions for dynamic and engaging effects.",+ "dependencies": [+ "motion"+ ],+ "files": [+ {+ "path": "registry/magicui/spinning-text.tsx",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+ },{"name": "flip-text","type": "registry:ui",@@ -2828,6 +2844,48 @@}]},+ {+ "name": "spinning-text-demo",+ "type": "registry:example",+ "title": "Spinning Text Demo",+ "description": "Example showing spinning text animation.",+ "registryDependencies": [+ "https://magicui.design/r/spinning-text"+ ],+ "files": [+ {+ "path": "registry/example/spinning-text-demo.tsx",+ "type": "registry:example",+ "target": "components/spinning-text-demo.tsx"+ },+ {+ "path": "registry/magicui/spinning-text.tsx",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+ },+ {+ "name": "spinning-text-demo-2",+ "type": "registry:example",+ "title": "Spinning Text Demo 2",+ "description": "Example showing spinning text animation.",+ "registryDependencies": [+ "https://magicui.design/r/spinning-text"+ ],+ "files": [+ {+ "path": "registry/example/spinning-text-demo-2.tsx",+ "type": "registry:example",+ "target": "components/spinning-text-demo-2.tsx"+ },+ {+ "path": "registry/magicui/spinning-text.tsx",+ "type": "registry:ui",+ "target": "components/magicui/spinning-text.tsx"+ }+ ]+ },{"name": "icon-cloud-demo","type": "registry:example",diff --git a/registry/example/spinning-text-demo-2.tsx b/registry/example/spinning-text-demo-2.tsxnew file mode 100644index 00000000..866af2aa--- /dev/null+++ b/registry/example/spinning-text-demo-2.tsx@@ -0,0 +1,9 @@+import { SpinningText } from "@/registry/magicui/spinning-text";++export default function SpinningTextBasic() {+ return (+ <SpinningText reverse className="text-4xl" duration={4} radius={6}>+ learn more • earn more • grow more •+ </SpinningText>+ );+}diff --git a/registry/example/spinning-text-demo.tsx b/registry/example/spinning-text-demo.tsxnew file mode 100644index 00000000..e3b10eaf--- /dev/null+++ b/registry/example/spinning-text-demo.tsx@@ -0,0 +1,5 @@+import { SpinningText } from "@/registry/magicui/spinning-text";++export default function SpinningTextBasic() {+ return <SpinningText>learn more • earn more • grow more •</SpinningText>;+}diff --git a/registry/magicui/spinning-text.tsx b/registry/magicui/spinning-text.tsxnew file mode 100644index 00000000..42b19a89--- /dev/null+++ b/registry/magicui/spinning-text.tsx@@ -0,0 +1,113 @@+"use client";+import { cn } from "@/lib/utils";+import { motion, Transition, Variants } from "motion/react";+import React, { CSSProperties } from "react";++type SpinningTextProps = {+ children: string | string[];+ style?: CSSProperties;+ duration?: number;+ className?: string;+ reverse?: boolean;+ fontSize?: number;+ radius?: number;+ transition?: Transition;+ variants?: {+ container?: Variants;+ item?: Variants;+ };+};++const BASE_TRANSITION = {+ repeat: Infinity,+ ease: "linear",+};++const BASE_ITEM_VARIANTS = {+ hidden: {+ opacity: 1,+ },+ visible: {+ opacity: 1,+ },+};++export function SpinningText({+ children,+ duration = 10,+ style,+ className,+ reverse = false,+ radius = 5,+ transition,+ variants,+}: SpinningTextProps) {+ if (typeof children !== "string" && !Array.isArray(children)) {+ throw new Error("children must be a string or an array of strings");+ }++ if (Array.isArray(children)) {+ // Validate all elements are strings+ if (!children.every((child) => typeof child === "string")) {+ throw new Error("all elements in children array must be strings");+ }+ children = children.join("");+ }++ const letters = children.split("");+ letters.push(" ");++ const finalTransition = {+ ...BASE_TRANSITION,+ ...transition,+ duration: (transition as { duration?: number })?.duration ?? duration,+ };++ const containerVariants = {+ visible: { rotate: reverse ? -360 : 360 },+ ...variants?.container,+ };++ const itemVariants = {+ ...BASE_ITEM_VARIANTS,+ ...variants?.item,+ };++ return (+ <motion.div+ className={cn("relative", className)}+ style={{+ ...style,+ }}+ initial="hidden"+ animate="visible"+ variants={containerVariants}+ transition={finalTransition}+ >+ {letters.map((letter, index) => (+ <motion.span+ aria-hidden="true"+ key={`${index}-${letter}`}+ variants={itemVariants}+ className="absolute left-1/2 top-1/2 inline-block"+ style={+ {+ "--index": index,+ "--total": letters.length,+ "--radius": radius,+ transform: `+ translate(-50%, -50%)+ rotate(calc(360deg / var(--total) * var(--index)))+ translateY(calc(var(--radius, 5) * -1ch))+ `,+ transformOrigin: "center",+ } as React.CSSProperties+ }+ >+ {letter}+ </motion.span>+ ))}+ <span className="sr-only">{children}</span>+ </motion.div>+ );+}diff --git a/registry/registry-examples.ts b/registry/registry-examples.tsindex 0112846a..f1cd53c8 100644--- a/registry/registry-examples.ts+++ b/registry/registry-examples.ts@@ -1301,6 +1301,44 @@ export const examples: Registry["items"] = [},],},+ {+ name: "spinning-text-demo",+ type: "registry:example",+ title: "Spinning Text Demo",+ description: "Example showing spinning text animation.",+ registryDependencies: ["https://magicui.design/r/spinning-text"],+ files: [+ {+ path: "registry/example/spinning-text-demo.tsx",+ type: "registry:example",+ target: "components/spinning-text-demo.tsx",+ },+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ },+ {+ name: "spinning-text-demo-2",+ type: "registry:example",+ title: "Spinning Text Demo 2",+ description: "Example showing spinning text animation.",+ registryDependencies: ["https://magicui.design/r/spinning-text"],+ files: [+ {+ path: "registry/example/spinning-text-demo-2.tsx",+ type: "registry:example",+ target: "components/spinning-text-demo-2.tsx",+ },+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ },{name: "icon-cloud-demo",type: "registry:example",diff --git a/registry/registry-ui.ts b/registry/registry-ui.tsindex 9d2c6592..6da9fba9 100644--- a/registry/registry-ui.ts+++ b/registry/registry-ui.ts@@ -864,6 +864,21 @@ export const ui: Registry["items"] = [},],},+ {+ name: "spinning-text",+ type: "registry:ui",+ title: "Spinning Text",+ description:+ "The Spinning Text component animates text in a circular motion with customizable speed, direction, color, and transitions for dynamic and engaging effects.",+ dependencies: ["motion"],+ files: [+ {+ path: "registry/magicui/spinning-text.tsx",+ type: "registry:ui",+ target: "components/magicui/spinning-text.tsx",+ },+ ],+ },{name: "flip-text",type: "registry:ui",