From 32849d164471baed42e2b9ce58c15591ae03034f Mon Sep 17 00:00:00 2001 From: Yash Jaiswal Date: Sun, 29 Nov 2026 16:26:09 +0530 Subject: [PATCH] fix(registry): respect reduced motion in WordRotate, SpinningText and SparklesText --- apps/www/public/llms-full.txt | 66 ++++++++++++++------- apps/www/public/r/sparkles-text.json | 2 +- apps/www/public/r/spinning-text.json | 2 +- apps/www/public/r/word-rotate.json | 2 +- apps/www/registry/magicui/sparkles-text.tsx | 29 ++++++--- apps/www/registry/magicui/spinning-text.tsx | 10 +++- apps/www/registry/magicui/word-rotate.tsx | 27 +++++---- 7 files changed, 95 insertions(+), 43 deletions(-) diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txt index 8ceee71a0..59786b99a 100644 --- a/apps/www/public/llms-full.txt +++ b/apps/www/public/llms-full.txt @@ -20170,7 +20170,7 @@ import { type CSSProperties, type ReactElement, } from "react" -import { motion } from "motion/react" +import { motion, useReducedMotion } from "motion/react" import { cn } from "@/lib/utils" @@ -20185,17 +20185,27 @@ interface Sparkle { } const Sparkle: React.FC = ({ id, x, y, color, delay, scale }) => { + const prefersReducedMotion = useReducedMotion() + return ( = ({ ...props }) => { const [sparkles, setSparkles] = useState([]) + const prefersReducedMotion = useReducedMotion() useEffect(() => { const generateStar = (): Sparkle => { @@ -20292,10 +20303,12 @@ export const SparklesText: React.FC = ({ } initializeStars() + if (prefersReducedMotion) return + const interval = setInterval(updateStars, 100) return () => clearInterval(interval) - }, [colors.first, colors.second, sparklesCount]) + }, [colors.first, colors.second, sparklesCount, prefersReducedMotion]) return (
{letters.map((letter, index) => ( - - - {words[index]} - - + + + + {words[index]} + + +
) } diff --git a/apps/www/public/r/sparkles-text.json b/apps/www/public/r/sparkles-text.json index 69338a6c3..6e5bfc26a 100644 --- a/apps/www/public/r/sparkles-text.json +++ b/apps/www/public/r/sparkles-text.json @@ -9,7 +9,7 @@ "files": [ { "path": "registry/magicui/sparkles-text.tsx", - "content": "\"use client\"\n\nimport {\n useEffect,\n useState,\n type CSSProperties,\n type ReactElement,\n} from \"react\"\nimport { motion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface Sparkle {\n id: string\n x: string\n y: string\n color: string\n delay: number\n scale: number\n lifespan: number\n}\n\nconst Sparkle: React.FC = ({ id, x, y, color, delay, scale }) => {\n return (\n \n \n
\n )\n}\n\ninterface SparklesTextProps {\n /**\n * @default
\n * @type ReactElement\n * @description\n * The component to be rendered as the text\n * */\n as?: ReactElement\n\n /**\n * @default \"\"\n * @type string\n * @description\n * The className of the text\n */\n className?: string\n\n /**\n * @required\n * @type ReactNode\n * @description\n * The content to be displayed\n * */\n children: React.ReactNode\n\n /**\n * @default 10\n * @type number\n * @description\n * The count of sparkles\n * */\n sparklesCount?: number\n\n /**\n * @default \"{first: '#9E7AFF', second: '#FE8BBB'}\"\n * @type string\n * @description\n * The colors of the sparkles\n * */\n colors?: {\n first: string\n second: string\n }\n}\n\nexport const SparklesText: React.FC = ({\n children,\n colors = { first: \"#9E7AFF\", second: \"#FE8BBB\" },\n className,\n sparklesCount = 10,\n ...props\n}) => {\n const [sparkles, setSparkles] = useState([])\n\n useEffect(() => {\n const generateStar = (): Sparkle => {\n const starX = `${Math.random() * 100}%`\n const starY = `${Math.random() * 100}%`\n const color = Math.random() > 0.5 ? colors.first : colors.second\n const delay = Math.random() * 2\n const scale = Math.random() * 1 + 0.3\n const lifespan = Math.random() * 10 + 5\n const id = `${starX}-${starY}-${Date.now()}`\n return { id, x: starX, y: starY, color, delay, scale, lifespan }\n }\n\n const initializeStars = () => {\n const newSparkles = Array.from({ length: sparklesCount }, generateStar)\n setSparkles(newSparkles)\n }\n\n const updateStars = () => {\n setSparkles((currentSparkles) =>\n currentSparkles.map((star) => {\n if (star.lifespan <= 0) {\n return generateStar()\n } else {\n return { ...star, lifespan: star.lifespan - 0.1 }\n }\n })\n )\n }\n\n initializeStars()\n const interval = setInterval(updateStars, 100)\n\n return () => clearInterval(interval)\n }, [colors.first, colors.second, sparklesCount])\n\n return (\n \n \n {sparkles.map((sparkle) => (\n \n ))}\n {children}\n \n
\n )\n}\n", + "content": "\"use client\"\n\nimport {\n useEffect,\n useState,\n type CSSProperties,\n type ReactElement,\n} from \"react\"\nimport { motion, useReducedMotion } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface Sparkle {\n id: string\n x: string\n y: string\n color: string\n delay: number\n scale: number\n lifespan: number\n}\n\nconst Sparkle: React.FC = ({ id, x, y, color, delay, scale }) => {\n const prefersReducedMotion = useReducedMotion()\n\n return (\n \n \n \n )\n}\n\ninterface SparklesTextProps {\n /**\n * @default
\n * @type ReactElement\n * @description\n * The component to be rendered as the text\n * */\n as?: ReactElement\n\n /**\n * @default \"\"\n * @type string\n * @description\n * The className of the text\n */\n className?: string\n\n /**\n * @required\n * @type ReactNode\n * @description\n * The content to be displayed\n * */\n children: React.ReactNode\n\n /**\n * @default 10\n * @type number\n * @description\n * The count of sparkles\n * */\n sparklesCount?: number\n\n /**\n * @default \"{first: '#9E7AFF', second: '#FE8BBB'}\"\n * @type string\n * @description\n * The colors of the sparkles\n * */\n colors?: {\n first: string\n second: string\n }\n}\n\nexport const SparklesText: React.FC = ({\n children,\n colors = { first: \"#9E7AFF\", second: \"#FE8BBB\" },\n className,\n sparklesCount = 10,\n ...props\n}) => {\n const [sparkles, setSparkles] = useState([])\n const prefersReducedMotion = useReducedMotion()\n\n useEffect(() => {\n const generateStar = (): Sparkle => {\n const starX = `${Math.random() * 100}%`\n const starY = `${Math.random() * 100}%`\n const color = Math.random() > 0.5 ? colors.first : colors.second\n const delay = Math.random() * 2\n const scale = Math.random() * 1 + 0.3\n const lifespan = Math.random() * 10 + 5\n const id = `${starX}-${starY}-${Date.now()}`\n return { id, x: starX, y: starY, color, delay, scale, lifespan }\n }\n\n const initializeStars = () => {\n const newSparkles = Array.from({ length: sparklesCount }, generateStar)\n setSparkles(newSparkles)\n }\n\n const updateStars = () => {\n setSparkles((currentSparkles) =>\n currentSparkles.map((star) => {\n if (star.lifespan <= 0) {\n return generateStar()\n } else {\n return { ...star, lifespan: star.lifespan - 0.1 }\n }\n })\n )\n }\n\n initializeStars()\n if (prefersReducedMotion) return\n\n const interval = setInterval(updateStars, 100)\n\n return () => clearInterval(interval)\n }, [colors.first, colors.second, sparklesCount, prefersReducedMotion])\n\n return (\n \n \n {sparkles.map((sparkle) => (\n \n ))}\n {children}\n \n
\n )\n}\n", "type": "registry:ui" } ], diff --git a/apps/www/public/r/spinning-text.json b/apps/www/public/r/spinning-text.json index f9e6ddc94..f6f770a81 100644 --- a/apps/www/public/r/spinning-text.json +++ b/apps/www/public/r/spinning-text.json @@ -9,7 +9,7 @@ "files": [ { "path": "registry/magicui/spinning-text.tsx", - "content": "\"use client\"\n\nimport React, { type ComponentPropsWithoutRef } from \"react\"\nimport { motion, type Transition, type Variants } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SpinningTextProps extends ComponentPropsWithoutRef<\"div\"> {\n children: string | string[]\n duration?: number\n reverse?: boolean\n radius?: number\n transition?: Transition\n variants?: {\n container?: Variants\n item?: Variants\n }\n}\n\nconst BASE_TRANSITION: Transition = {\n repeat: Infinity,\n ease: \"linear\",\n}\n\nconst BASE_ITEM_VARIANTS: Variants = {\n hidden: {\n opacity: 1,\n },\n visible: {\n opacity: 1,\n },\n}\n\nexport function SpinningText({\n children,\n duration = 10,\n reverse = false,\n radius = 5,\n transition,\n variants,\n className,\n style,\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: Transition = {\n ...BASE_TRANSITION,\n ...transition,\n duration: (transition as { duration?: number })?.duration ?? duration,\n }\n\n const containerVariants: Variants = {\n visible: { rotate: reverse ? -360 : 360 },\n ...variants?.container,\n }\n\n const itemVariants: Variants = {\n ...BASE_ITEM_VARIANTS,\n ...variants?.item,\n }\n\n return (\n \n {letters.map((letter, index) => (\n \n {letter}\n \n ))}\n {children}\n \n )\n}\n", + "content": "\"use client\"\n\nimport React, { type ComponentPropsWithoutRef } from \"react\"\nimport {\n motion,\n useReducedMotion,\n type Transition,\n type Variants,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface SpinningTextProps extends ComponentPropsWithoutRef<\"div\"> {\n children: string | string[]\n duration?: number\n reverse?: boolean\n radius?: number\n transition?: Transition\n variants?: {\n container?: Variants\n item?: Variants\n }\n}\n\nconst BASE_TRANSITION: Transition = {\n repeat: Infinity,\n ease: \"linear\",\n}\n\nconst BASE_ITEM_VARIANTS: Variants = {\n hidden: {\n opacity: 1,\n },\n visible: {\n opacity: 1,\n },\n}\n\nexport function SpinningText({\n children,\n duration = 10,\n reverse = false,\n radius = 5,\n transition,\n variants,\n className,\n style,\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 prefersReducedMotion = useReducedMotion()\n const letters = children.split(\"\")\n letters.push(\" \")\n\n const finalTransition: Transition = {\n ...BASE_TRANSITION,\n ...transition,\n duration: (transition as { duration?: number })?.duration ?? duration,\n }\n\n const containerVariants: Variants = {\n visible: { rotate: reverse ? -360 : 360 },\n ...variants?.container,\n }\n\n const itemVariants: Variants = {\n ...BASE_ITEM_VARIANTS,\n ...variants?.item,\n }\n\n return (\n \n {letters.map((letter, index) => (\n \n {letter}\n \n ))}\n {children}\n \n )\n}\n", "type": "registry:ui" } ], diff --git a/apps/www/public/r/word-rotate.json b/apps/www/public/r/word-rotate.json index 60a8ea107..dc0446f93 100644 --- a/apps/www/public/r/word-rotate.json +++ b/apps/www/public/r/word-rotate.json @@ -9,7 +9,7 @@ "files": [ { "path": "registry/magicui/word-rotate.tsx", - "content": "\"use client\"\n\nimport { useEffect, useState } from \"react\"\nimport { AnimatePresence, motion, type MotionProps } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface WordRotateProps {\n words: string[]\n duration?: number\n motionProps?: MotionProps\n className?: string\n}\n\nexport function WordRotate({\n words,\n duration = 2500,\n motionProps = {\n initial: { opacity: 0, y: -50 },\n animate: { opacity: 1, y: 0 },\n exit: { opacity: 0, y: 50 },\n transition: { duration: 0.25, ease: \"easeOut\" },\n },\n className,\n}: WordRotateProps) {\n const [index, setIndex] = useState(0)\n\n useEffect(() => {\n const interval = setInterval(() => {\n setIndex((prevIndex) => (prevIndex + 1) % words.length)\n }, duration)\n\n // Clean up interval on unmount\n return () => clearInterval(interval)\n }, [words, duration])\n\n return (\n
\n \n \n {words[index]}\n \n \n
\n )\n}\n", + "content": "\"use client\"\n\nimport { useEffect, useState } from \"react\"\nimport {\n AnimatePresence,\n motion,\n MotionConfig,\n type MotionProps,\n} from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface WordRotateProps {\n words: string[]\n duration?: number\n motionProps?: MotionProps\n className?: string\n}\n\nexport function WordRotate({\n words,\n duration = 2500,\n motionProps = {\n initial: { opacity: 0, y: -50 },\n animate: { opacity: 1, y: 0 },\n exit: { opacity: 0, y: 50 },\n transition: { duration: 0.25, ease: \"easeOut\" },\n },\n className,\n}: WordRotateProps) {\n const [index, setIndex] = useState(0)\n\n useEffect(() => {\n const interval = setInterval(() => {\n setIndex((prevIndex) => (prevIndex + 1) % words.length)\n }, duration)\n\n // Clean up interval on unmount\n return () => clearInterval(interval)\n }, [words, duration])\n\n return (\n
\n \n \n \n {words[index]}\n \n \n \n
\n )\n}\n", "type": "registry:ui" } ], diff --git a/apps/www/registry/magicui/sparkles-text.tsx b/apps/www/registry/magicui/sparkles-text.tsx index 2befd5174..01bc9113c 100644 --- a/apps/www/registry/magicui/sparkles-text.tsx +++ b/apps/www/registry/magicui/sparkles-text.tsx @@ -6,7 +6,7 @@ import { type CSSProperties, type ReactElement, } from "react" -import { motion } from "motion/react" +import { motion, useReducedMotion } from "motion/react" import { cn } from "@/lib/utils" @@ -21,17 +21,27 @@ interface Sparkle { } const Sparkle: React.FC = ({ id, x, y, color, delay, scale }) => { + const prefersReducedMotion = useReducedMotion() + return ( = ({ ...props }) => { const [sparkles, setSparkles] = useState([]) + const prefersReducedMotion = useReducedMotion() useEffect(() => { const generateStar = (): Sparkle => { @@ -128,10 +139,12 @@ export const SparklesText: React.FC = ({ } initializeStars() + if (prefersReducedMotion) return + const interval = setInterval(updateStars, 100) return () => clearInterval(interval) - }, [colors.first, colors.second, sparklesCount]) + }, [colors.first, colors.second, sparklesCount, prefersReducedMotion]) return (
{letters.map((letter, index) => ( - - - {words[index]} - - + + + + {words[index]} + + +
) }