Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

feat: add text reveal

Dillion Vermaebe6cf816dcb
diff --git a/components/block-preview.tsx b/components/block-preview.tsx
index 7f62f3e5..970008d3 100644
--- a/components/block-preview.tsx
+++ b/components/block-preview.tsx
@@ -3,7 +3,6 @@
import BlockWrapper from "@/components/block-wrapper";
import ComponentWrapper from "@/components/component-wrapper";
import { Icons } from "@/components/icons";
-import PreOrder from "@/components/preorder";
import { Badge } from "@/components/ui/badge";
import { Separator } from "@/components/ui/separator";
import { Skeleton } from "@/components/ui/skeleton";
@@ -23,14 +22,6 @@ interface BlockPreviewProps extends React.HTMLAttributes<HTMLDivElement> {
scroller?: boolean;
}
-const PayWall = ({ className }: { className?: string }) => {
- return (
- <>
- <PreOrder />
- </>
- );
-};
-
export function BlockPreview({
name,
children,
diff --git a/config/docs.ts b/config/docs.ts
index dd77fbff..92303987 100644
--- a/config/docs.ts
+++ b/config/docs.ts
@@ -220,6 +220,12 @@ export const docsConfig: DocsConfig = {
href: `/docs/components/text-shimmer`,
items: [],
},
+ {
+ title: "Text Reveal",
+ href: `/docs/components/text-reveal`,
+ items: [],
+ label: "New",
+ },
],
},
{
diff --git a/content/docs/components/text-reveal.mdx b/content/docs/components/text-reveal.mdx
new file mode 100644
index 00000000..84d1de42
--- /dev/null
+++ b/content/docs/components/text-reveal.mdx
@@ -0,0 +1,32 @@
+---
+title: Text Reveal
+date: 2024-04-08
+description: Fade in text as you scroll down the page.
+author: dillionverma
+published: true
+video: https://cdn.magicui.design/text-reveal.mp4
+---
+
+<ComponentPreview name="text-reveal-demo" />
+
+<Steps>
+
+### Installation
+
+Copy and paste the following code into your project.
+
+```text
+components/magicui/text-reveal.tsx
+```
+
+<ComponentSource name="text-reveal" />
+
+</Steps>
+
+## Props
+
+| Prop | Type | Description | Default |
+| ------------ | ------ | -------------------------------------------- | ------- |
+| children | | The text to be shimmered. | |
+| className | string | The class name to be applied to the shimmer. | |
+| text | string | The text to do the animation for | "" |
diff --git a/registry/components/example/text-reveal-demo.tsx b/registry/components/example/text-reveal-demo.tsx
new file mode 100644
index 00000000..a522b48e
--- /dev/null
+++ b/registry/components/example/text-reveal-demo.tsx
@@ -0,0 +1,9 @@
+import TextReveal from "@/registry/components/magicui/text-reveal";
+
+export default async function TextRevealDemo() {
+ return (
+ <div className="z-10 flex min-h-[16rem] items-center justify-center rounded-lg border bg-white dark:bg-black">
+ <TextReveal text="Magic UI will change the way you design." />
+ </div>
+ );
+}
diff --git a/registry/components/magicui/text-reveal.tsx b/registry/components/magicui/text-reveal.tsx
new file mode 100644
index 00000000..fdc6af77
--- /dev/null
+++ b/registry/components/magicui/text-reveal.tsx
@@ -0,0 +1,110 @@
+"use client";
+
+import { cn } from "@/lib/utils";
+import { motion, useScroll, useTransform } from "framer-motion";
+import { FC, ReactNode, useRef } from "react";
+
+interface TextRevealByWordProps {
+ text: string;
+ containerClassName?: string;
+ stickyClassName?: string;
+ paragraphContainerClassName?: string;
+ paragraphClassName?: string;
+ defaultTextOpacityClassName?: string;
+ highlightedWordClassName?: string;
+}
+
+export const TextRevealByWord: FC<TextRevealByWordProps> = ({
+ text,
+ containerClassName,
+ stickyClassName,
+ paragraphContainerClassName,
+ paragraphClassName,
+ defaultTextOpacityClassName,
+ highlightedWordClassName,
+}) => {
+ const targetRef = useRef<HTMLDivElement | null>(null);
+
+ const { scrollYProgress } = useScroll({
+ target: targetRef,
+ });
+ const words = text.split(" ");
+
+ return (
+ <div
+ ref={targetRef}
+ className={cn("relative z-0 h-[200vh]", containerClassName)}
+ >
+ <div
+ className={cn(
+ "sticky top-0 flex h-[50%] items-center bg-transparent px-0 py-[5rem]",
+ stickyClassName,
+ )}
+ >
+ <div
+ className={cn(
+ "mx-auto max-w-4xl px-[1rem]",
+ paragraphContainerClassName,
+ )}
+ >
+ <p
+ ref={targetRef}
+ className={cn(
+ "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",
+ paragraphClassName,
+ )}
+ >
+ {words.map((word, i) => {
+ const start = i / words.length;
+ const end = start + 1 / words.length;
+ return (
+ <Word
+ key={i}
+ progress={scrollYProgress}
+ range={[start, end]}
+ defaultTextOpacityClassName={defaultTextOpacityClassName}
+ highlightedWordClassName={highlightedWordClassName}
+ >
+ {word}
+ </Word>
+ );
+ })}
+ </p>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+interface WordProps {
+ children: ReactNode;
+ progress: any;
+ range: [number, number];
+ defaultTextOpacityClassName?: string;
+ highlightedWordClassName?: string;
+}
+
+const Word: FC<WordProps> = ({
+ children,
+ progress,
+ range,
+ defaultTextOpacityClassName,
+ highlightedWordClassName,
+}) => {
+ const opacity = useTransform(progress, range, [0, 1]);
+ return (
+ <span className="xl:lg-3 relative mx-1 lg:mx-2.5">
+ <span className={cn("absolute opacity-30", defaultTextOpacityClassName)}>
+ {children}
+ </span>
+ <motion.span
+ style={{ opacity: opacity }}
+ className={cn("text-black dark:text-white", highlightedWordClassName)}
+ >
+ {children}
+ </motion.span>
+ </span>
+ );
+};
+
+export default TextRevealByWord;
diff --git a/registry/index.tsx b/registry/index.tsx
index 48bb26f1..ba79ae82 100644
--- a/registry/index.tsx
+++ b/registry/index.tsx
@@ -117,6 +117,11 @@ const ui: Registry = {
type: "components:ui",
files: ["registry/components/magicui/animated-beam.tsx"],
},
+ "text-reveal": {
+ name: "text-reveal",
+ type: "components:ui",
+ files: ["registry/components/magicui/text-reveal.tsx"],
+ },
};
const example: Registry = {
@@ -353,6 +358,7 @@ const example: Registry = {
() => import("@/registry/components/example/text-shimmer-demo"),
),
},
+
"particles-demo": {
name: "particles-demo",
type: "components:example",
@@ -500,6 +506,14 @@ const example: Registry = {
() => import("@/registry/components/example/animated-feature-card-10"),
),
},
+ "text-reveal-demo": {
+ name: "text-reveal-demo",
+ type: "components:example",
+ files: ["registry/components/example/text-reveal-demo.tsx"],
+ component: React.lazy(
+ () => import("@/registry/components/example/text-reveal-demo"),
+ ),
+ },
};
const blocks: Registry = {