UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
fix: sparkles text children support added (#630)
Arghya Dasaba480625d58
diff --git a/content/docs/components/sparkles-text.mdx b/content/docs/components/sparkles-text.mdxindex 1a2e7475..cc5c8d52 100644--- a/content/docs/components/sparkles-text.mdx+++ b/content/docs/components/sparkles-text.mdx@@ -47,14 +47,14 @@ import { SparklesText } from "@/components/magicui/sparkles-text";``````tsx-<SparklesText text="Sparkles Text" />+<SparklesText>Sparkles Text</SparklesText>```## Props| Prop | Type | Default | Description || --------------- | -------- | --------------------------------------- | -------------------------------------------------- |-| `text` | `string` | `-` | The text to display |+| `children` | `string` | `-` | The content to display || `className` | `string` | `-` | The class name to be applied to the sparkles text. || `sparklesCount` | `number` | `10` | sparkles count that appears on the text || `colors` | `object` | `{first: '#A07CFE', second: '#FE8FB5'}` | the sparkles colors |diff --git a/public/r/sparkles-text-demo.json b/public/r/sparkles-text-demo.jsonindex 72359888..9cfd0fd4 100644--- a/public/r/sparkles-text-demo.json+++ b/public/r/sparkles-text-demo.json@@ -10,7 +10,7 @@"files": [{"path": "registry/example/sparkles-text-demo.tsx",- "content": "import { SparklesText } from \"@/registry/magicui/sparkles-text\";\n\nexport default function SparklesTextDemo() {\n return <SparklesText text=\"Magic UI\" />;\n}\n",+ "content": "import { SparklesText } from \"@/registry/magicui/sparkles-text\";\n\nexport default function SparklesTextDemo() {\n return <SparklesText>Magic UI</SparklesText>;\n}\n","type": "registry:example","target": "components/sparkles-text-demo.tsx"}diff --git a/public/r/sparkles-text.json b/public/r/sparkles-text.jsonindex 3269948a..f0a4ee6e 100644--- a/public/r/sparkles-text.json+++ b/public/r/sparkles-text.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/sparkles-text.tsx",- "content": "\"use client\";\n\nimport { motion } from \"motion/react\";\nimport { CSSProperties, ReactElement, useEffect, useState } from \"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<Sparkle> = ({ id, x, y, color, delay, scale }) => {\n return (\n <motion.svg\n key={id}\n className=\"pointer-events-none absolute z-20\"\n initial={{ opacity: 0, left: x, top: y }}\n animate={{\n opacity: [0, 1, 0],\n scale: [0, scale, 0],\n rotate: [75, 120, 150],\n }}\n transition={{ duration: 0.8, repeat: Infinity, delay }}\n width=\"21\"\n height=\"21\"\n viewBox=\"0 0 21 21\"\n >\n <path\n d=\"M9.82531 0.843845C10.0553 0.215178 10.9446 0.215178 11.1746 0.843845L11.8618 2.72026C12.4006 4.19229 12.3916 6.39157 13.5 7.5C14.6084 8.60843 16.8077 8.59935 18.2797 9.13822L20.1561 9.82534C20.7858 10.0553 20.7858 10.9447 20.1561 11.1747L18.2797 11.8618C16.8077 12.4007 14.6084 12.3916 13.5 13.5C12.3916 14.6084 12.4006 16.8077 11.8618 18.2798L11.1746 20.1562C10.9446 20.7858 10.0553 20.7858 9.82531 20.1562L9.13819 18.2798C8.59932 16.8077 8.60843 14.6084 7.5 13.5C6.39157 12.3916 4.19225 12.4007 2.72023 11.8618L0.843814 11.1747C0.215148 10.9447 0.215148 10.0553 0.843814 9.82534L2.72023 9.13822C4.19225 8.59935 6.39157 8.60843 7.5 7.5C8.60843 6.39157 8.59932 4.19229 9.13819 2.72026L9.82531 0.843845Z\"\n fill={color}\n />\n </motion.svg>\n );\n};\n\ninterface SparklesTextProps {\n /**\n * @default <div />\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 string\n * @description\n * The text to be displayed\n * */\n text: string;\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<SparklesTextProps> = ({\n text,\n colors = { first: \"#9E7AFF\", second: \"#FE8BBB\" },\n className,\n sparklesCount = 10,\n ...props\n}) => {\n const [sparkles, setSparkles] = useState<Sparkle[]>([]);\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 <div\n className={cn(\"text-6xl font-bold\", className)}\n {...props}\n style={\n {\n \"--sparkles-first-color\": `${colors.first}`,\n \"--sparkles-second-color\": `${colors.second}`,\n } as CSSProperties\n }\n >\n <span className=\"relative inline-block\">\n {sparkles.map((sparkle) => (\n <Sparkle key={sparkle.id} {...sparkle} />\n ))}\n <strong>{text}</strong>\n </span>\n </div>\n );\n};\n",+ "content": "\"use client\";\n\nimport { motion } from \"motion/react\";\nimport { CSSProperties, ReactElement, useEffect, useState } from \"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<Sparkle> = ({ id, x, y, color, delay, scale }) => {\n return (\n <motion.svg\n key={id}\n className=\"pointer-events-none absolute z-20\"\n initial={{ opacity: 0, left: x, top: y }}\n animate={{\n opacity: [0, 1, 0],\n scale: [0, scale, 0],\n rotate: [75, 120, 150],\n }}\n transition={{ duration: 0.8, repeat: Infinity, delay }}\n width=\"21\"\n height=\"21\"\n viewBox=\"0 0 21 21\"\n >\n <path\n d=\"M9.82531 0.843845C10.0553 0.215178 10.9446 0.215178 11.1746 0.843845L11.8618 2.72026C12.4006 4.19229 12.3916 6.39157 13.5 7.5C14.6084 8.60843 16.8077 8.59935 18.2797 9.13822L20.1561 9.82534C20.7858 10.0553 20.7858 10.9447 20.1561 11.1747L18.2797 11.8618C16.8077 12.4007 14.6084 12.3916 13.5 13.5C12.3916 14.6084 12.4006 16.8077 11.8618 18.2798L11.1746 20.1562C10.9446 20.7858 10.0553 20.7858 9.82531 20.1562L9.13819 18.2798C8.59932 16.8077 8.60843 14.6084 7.5 13.5C6.39157 12.3916 4.19225 12.4007 2.72023 11.8618L0.843814 11.1747C0.215148 10.9447 0.215148 10.0553 0.843814 9.82534L2.72023 9.13822C4.19225 8.59935 6.39157 8.60843 7.5 7.5C8.60843 6.39157 8.59932 4.19229 9.13819 2.72026L9.82531 0.843845Z\"\n fill={color}\n />\n </motion.svg>\n );\n};\n\ninterface SparklesTextProps {\n /**\n * @default <div />\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<SparklesTextProps> = ({\n children,\n colors = { first: \"#9E7AFF\", second: \"#FE8BBB\" },\n className,\n sparklesCount = 10,\n ...props\n}) => {\n const [sparkles, setSparkles] = useState<Sparkle[]>([]);\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 <div\n className={cn(\"text-6xl font-bold\", className)}\n {...props}\n style={\n {\n \"--sparkles-first-color\": `${colors.first}`,\n \"--sparkles-second-color\": `${colors.second}`,\n } as CSSProperties\n }\n >\n <span className=\"relative inline-block\">\n {sparkles.map((sparkle) => (\n <Sparkle key={sparkle.id} {...sparkle} />\n ))}\n <strong>{children}</strong>\n </span>\n </div>\n );\n};\n","type": "registry:ui","target": "components/magicui/sparkles-text.tsx"}diff --git a/registry/example/sparkles-text-demo.tsx b/registry/example/sparkles-text-demo.tsxindex 51bb4f82..cfdbac33 100644--- a/registry/example/sparkles-text-demo.tsx+++ b/registry/example/sparkles-text-demo.tsx@@ -1,5 +1,5 @@import { SparklesText } from "@/registry/magicui/sparkles-text";export default function SparklesTextDemo() {- return <SparklesText text="Magic UI" />;+ return <SparklesText>Magic UI</SparklesText>;}diff --git a/registry/magicui/sparkles-text.tsx b/registry/magicui/sparkles-text.tsxindex 4ab2baa3..17b3a364 100644--- a/registry/magicui/sparkles-text.tsx+++ b/registry/magicui/sparkles-text.tsx@@ -58,11 +58,11 @@ interface SparklesTextProps {/*** @required- * @type string+ * @type ReactNode* @description- * The text to be displayed+ * The content to be displayed* */- text: string;+ children: React.ReactNode;/*** @default 10@@ -85,7 +85,7 @@ interface SparklesTextProps {}export const SparklesText: React.FC<SparklesTextProps> = ({- text,+ children,colors = { first: "#9E7AFF", second: "#FE8BBB" },className,sparklesCount = 10,@@ -143,7 +143,7 @@ export const SparklesText: React.FC<SparklesTextProps> = ({{sparkles.map((sparkle) => (<Sparkle key={sparkle.id} {...sparkle} />))}- <strong>{text}</strong>+ <strong>{children}</strong></span></div>);