UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
dillion/text reveal api update (#573)
Dillion Vermac4cf068c5010
diff --git a/content/docs/components/text-reveal.mdx b/content/docs/components/text-reveal.mdxindex fa9b2a36..36a0af6a 100644--- a/content/docs/components/text-reveal.mdx+++ b/content/docs/components/text-reveal.mdx@@ -41,13 +41,12 @@ npx shadcn@latest add "https://magicui.design/r/text-reveal"</Tabs>-## Props+## Usage-| Prop | Type | Default | Description |-| ----------- | -------- | ------- | -------------------------------------------- |-| `className` | `string` | `-` | The class name to be applied to the shimmer. |-| `text` | `string` | `-` | The text to do the animation for |--## Credits+```tsx+import { TextReveal } from "@/components/magicui/text-reveal";+```-- Credit to [@itsarghyadas](https://twitter.com/itsarghyadas) for figuring out the foundation of this!+```tsx+<TextReveal>Magic UI will change the way you design.</TextReveal>+```diff --git a/public/r/text-reveal-demo.json b/public/r/text-reveal-demo.jsonindex fd14825f..61492733 100644--- a/public/r/text-reveal-demo.json+++ b/public/r/text-reveal-demo.json@@ -10,7 +10,7 @@"files": [{"path": "registry/example/text-reveal-demo.tsx",- "content": "import { TextReveal } from \"@/components/magicui/text-reveal\";\n\nexport default function TextRevealDemo() {\n return (\n <div className=\"z-10 flex min-h-64 items-center justify-center rounded-lg border bg-white dark:bg-black\">\n <TextReveal text=\"Magic UI will change the way you design.\" />\n </div>\n );\n}\n",+ "content": "import { TextReveal } from \"@/components/magicui/text-reveal\";\n\nexport default function TextRevealDemo() {\n return <TextReveal>Magic UI will change the way you design.</TextReveal>;\n}\n","type": "registry:example","target": "components/text-reveal-demo.tsx"}diff --git a/public/r/text-reveal.json b/public/r/text-reveal.jsonindex fb6df658..4ea7a272 100644--- a/public/r/text-reveal.json+++ b/public/r/text-reveal.json@@ -10,7 +10,7 @@"files": [{"path": "registry/magicui/text-reveal.tsx",- "content": "\"use client\";\n\nimport { motion, MotionValue, useScroll, useTransform } from \"motion/react\";\nimport { ComponentPropsWithoutRef, FC, ReactNode, useRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface TextRevealProps extends ComponentPropsWithoutRef<\"div\"> {\n text: string;\n}\n\nexport const TextReveal: FC<TextRevealProps> = ({ text, className }) => {\n const targetRef = useRef<HTMLDivElement | null>(null);\n\n const { scrollYProgress } = useScroll({\n target: targetRef,\n });\n const words = text.split(\" \");\n\n return (\n <div ref={targetRef} className={cn(\"relative z-0 h-[200vh]\", className)}>\n <div\n className={\n \"sticky top-0 mx-auto flex h-[50%] max-w-4xl items-center bg-transparent px-[1rem] py-[5rem]\"\n }\n >\n <p\n ref={targetRef}\n className={\n \"flex flex-wrap p-5 text-2xl font-bold text-black/20 dark:text-white/20 md:p-8 md:text-3xl lg:p-10 lg:text-4xl xl:text-5xl\"\n }\n >\n {words.map((word, i) => {\n const start = i / words.length;\n const end = start + 1 / words.length;\n return (\n <Word key={i} progress={scrollYProgress} range={[start, end]}>\n {word}\n </Word>\n );\n })}\n </p>\n </div>\n </div>\n );\n};\n\ninterface WordProps {\n children: ReactNode;\n progress: MotionValue<number>;\n range: [number, number];\n}\n\nconst Word: FC<WordProps> = ({ children, progress, range }) => {\n const opacity = useTransform(progress, range, [0, 1]);\n return (\n <span className=\"xl:lg-3 relative mx-1 lg:mx-2.5\">\n <span className={\"absolute opacity-30\"}>{children}</span>\n <motion.span\n style={{ opacity: opacity }}\n className={\"text-black dark:text-white\"}\n >\n {children}\n </motion.span>\n </span>\n );\n};\n",+ "content": "\"use client\";\n\nimport { motion, MotionValue, useScroll, useTransform } from \"motion/react\";\nimport { ComponentPropsWithoutRef, FC, ReactNode, useRef } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport interface TextRevealProps extends ComponentPropsWithoutRef<\"div\"> {\n children: string;\n}\n\nexport const TextReveal: FC<TextRevealProps> = ({ children, className }) => {\n const targetRef = useRef<HTMLDivElement | null>(null);\n const { scrollYProgress } = useScroll({\n target: targetRef,\n });\n\n if (typeof children !== \"string\") {\n throw new Error(\"TextReveal: children must be a string\");\n }\n\n const words = children.split(\" \");\n\n return (\n <div ref={targetRef} className={cn(\"relative z-0 h-[200vh]\", className)}>\n <div\n className={\n \"sticky top-0 mx-auto flex h-[50%] max-w-4xl items-center bg-transparent px-[1rem] py-[5rem]\"\n }\n >\n <span\n ref={targetRef}\n className={\n \"flex flex-wrap p-5 text-2xl font-bold text-black/20 dark:text-white/20 md:p-8 md:text-3xl lg:p-10 lg:text-4xl xl:text-5xl\"\n }\n >\n {words.map((word, i) => {\n const start = i / words.length;\n const end = start + 1 / words.length;\n return (\n <Word key={i} progress={scrollYProgress} range={[start, end]}>\n {word}\n </Word>\n );\n })}\n </span>\n </div>\n </div>\n );\n};\n\ninterface WordProps {\n children: ReactNode;\n progress: MotionValue<number>;\n range: [number, number];\n}\n\nconst Word: FC<WordProps> = ({ children, progress, range }) => {\n const opacity = useTransform(progress, range, [0, 1]);\n return (\n <span className=\"xl:lg-3 relative mx-1 lg:mx-1.5\">\n <span className=\"absolute opacity-30\">{children}</span>\n <motion.span\n style={{ opacity: opacity }}\n className={\"text-black dark:text-white\"}\n >\n {children}\n </motion.span>\n </span>\n );\n};\n","type": "registry:ui","target": "components/magicui/text-reveal.tsx"}diff --git a/registry/example/text-reveal-demo.tsx b/registry/example/text-reveal-demo.tsxindex 9202f572..cc2d87a0 100644--- a/registry/example/text-reveal-demo.tsx+++ b/registry/example/text-reveal-demo.tsx@@ -1,9 +1,5 @@import { TextReveal } from "@/registry/magicui/text-reveal";export default function TextRevealDemo() {- return (- <div className="z-10 flex min-h-64 items-center justify-center rounded-lg border bg-white dark:bg-black">- <TextReveal text="Magic UI will change the way you design." />- </div>- );+ return <TextReveal>Magic UI will change the way you design.</TextReveal>;}diff --git a/registry/magicui/text-reveal.tsx b/registry/magicui/text-reveal.tsxindex ef05225c..31127b60 100644--- a/registry/magicui/text-reveal.tsx+++ b/registry/magicui/text-reveal.tsx@@ -6,16 +6,20 @@ import { ComponentPropsWithoutRef, FC, ReactNode, useRef } from "react";import { cn } from "@/lib/utils";export interface TextRevealProps extends ComponentPropsWithoutRef<"div"> {- text: string;+ children: string;}-export const TextReveal: FC<TextRevealProps> = ({ text, className }) => {+export const TextReveal: FC<TextRevealProps> = ({ children, className }) => {const targetRef = useRef<HTMLDivElement | null>(null);-const { scrollYProgress } = useScroll({target: targetRef,});- const words = text.split(" ");++ if (typeof children !== "string") {+ throw new Error("TextReveal: children must be a string");+ }++ const words = children.split(" ");return (<div ref={targetRef} className={cn("relative z-0 h-[200vh]", className)}>@@ -24,7 +28,7 @@ export const TextReveal: FC<TextRevealProps> = ({ text, className }) => {"sticky top-0 mx-auto flex h-[50%] max-w-4xl items-center bg-transparent px-[1rem] py-[5rem]"}>- <p+ <spanref={targetRef}className={"flex flex-wrap p-5 text-2xl font-bold text-black/20 dark:text-white/20 md:p-8 md:text-3xl lg:p-10 lg:text-4xl xl:text-5xl"@@ -39,7 +43,7 @@ export const TextReveal: FC<TextRevealProps> = ({ text, className }) => {</Word>);})}- </p>+ </span></div></div>);@@ -54,8 +58,8 @@ interface WordProps {const Word: FC<WordProps> = ({ children, progress, range }) => {const opacity = useTransform(progress, range, [0, 1]);return (- <span className="xl:lg-3 relative mx-1 lg:mx-2.5">- <span className={"absolute opacity-30"}>{children}</span>+ <span className="xl:lg-3 relative mx-1 lg:mx-1.5">+ <span className="absolute opacity-30">{children}</span><motion.spanstyle={{ opacity: opacity }}className={"text-black dark:text-white"}