UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
add: fade text component (#61)
Manu Bhardwaj13f588cc5fdc
diff --git a/config/docs.ts b/config/docs.tsindex 5d2eea9c..b0b6cb39 100644--- a/config/docs.ts+++ b/config/docs.ts@@ -219,6 +219,12 @@ export const docsConfig: DocsConfig = {items: [],label: "New",},+ {+ title: "Fade Text",+ href: `/docs/components/fade-text`,+ items: [],+ label: "New",+ },],},{diff --git a/content/docs/components/fade-text.mdx b/content/docs/components/fade-text.mdxnew file mode 100644index 00000000..bdb0b966--- /dev/null+++ b/content/docs/components/fade-text.mdx@@ -0,0 +1,32 @@+---+title: Fade Text+date: 2024-05-22+description: Characters appearing from faded view+author: imanubhardwaj+published: true+---++<ComponentPreview name="fade-text-demo" />++<Steps>++### Installation++Copy and paste the following code into your project.++```text+components/magicui/fade-text.tsx+```++<ComponentSource name="fade-text" />++</Steps>++## Props++| Prop | Type | Description | Default |+| ----------- | --------------- | -------------------------------------------------- | ------- |+| className | string | The class name to be applied to the component | |+| direction | string | Can be: "down" , "left", "right", "up" | "up" |+| text | string | Text to animate | "" |+| framerProps | HTMLMotionProps | An object containing framer-motion animation props | {} |diff --git a/registry/components/example/fade-text-demo.tsx b/registry/components/example/fade-text-demo.tsxnew file mode 100644index 00000000..8e548007--- /dev/null+++ b/registry/components/example/fade-text-demo.tsx@@ -0,0 +1,40 @@+import { FadeText } from "@/registry/components/magicui/fade-text";++export default async function FadeTextDemo() {+ return (+ <div className="flex flex-col space-y-8 text-center">+ <FadeText+ className="text-4xl font-bold text-black dark:text-white"+ direction="up"+ framerProps={{+ show: { transition: { delay: 0.2 } },+ }}+ text="Fade Up"+ />+ <FadeText+ className="text-4xl font-bold text-black dark:text-white"+ direction="right"+ framerProps={{+ show: { transition: { delay: 0.4 } },+ }}+ text="Fade Right"+ />+ <FadeText+ className="text-4xl font-bold text-black dark:text-white"+ direction="down"+ framerProps={{+ show: { transition: { delay: 0.6 } },+ }}+ text="Fade Down"+ />+ <FadeText+ className="text-4xl font-bold text-black dark:text-white"+ direction="left"+ framerProps={{+ show: { transition: { delay: 0.8 } },+ }}+ text="Fade Left"+ />+ </div>+ );+}diff --git a/registry/components/magicui/fade-text.tsx b/registry/components/magicui/fade-text.tsxnew file mode 100644index 00000000..6ddd50f8--- /dev/null+++ b/registry/components/magicui/fade-text.tsx@@ -0,0 +1,59 @@+"use client";++import { motion, Variants } from "framer-motion";+import { useMemo } from "react";++type FadeTextProps = {+ className?: string;+ direction?: "up" | "down" | "left" | "right";+ framerProps?: Variants;+ text: string;+};++export function FadeText({+ direction = "up",+ className,+ framerProps = {+ hidden: { opacity: 0 },+ show: { opacity: 1, transition: { type: "spring" } },+ },+ text,+}: FadeTextProps) {+ const directionOffset = useMemo(() => {+ const map = { up: 10, down: -10, left: -10, right: 10 };+ return map[direction];+ }, [direction]);++ const axis = direction === "up" || direction === "down" ? "y" : "x";++ const FADE_ANIMATION_VARIANTS = useMemo(() => {+ const { hidden, show, ...rest } = framerProps as {+ [name: string]: { [name: string]: number; opacity: number };+ };++ return {+ ...rest,+ hidden: {+ ...(hidden ?? {}),+ opacity: hidden?.opacity ?? 0,+ [axis]: hidden?.[axis] ?? directionOffset,+ },+ show: {+ ...(show ?? {}),+ opacity: show?.opacity ?? 1,+ [axis]: show?.[axis] ?? 0,+ },+ };+ }, [directionOffset, axis, framerProps]);++ return (+ <motion.div+ initial="hidden"+ animate="show"+ viewport={{ once: true }}+ variants={FADE_ANIMATION_VARIANTS}+ >+ <motion.h1 className={className}>{text}</motion.h1>+ </motion.div>+ );+}diff --git a/registry/index.tsx b/registry/index.tsxindex 376459ba..fd1319b9 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -202,6 +202,11 @@ const ui: Registry = {type: "components:ui",files: ["registry/components/magicui/scroll-based-velocity.tsx"],},+ "fade-text": {+ name: "fade-text",+ type: "components:ui",+ files: ["registry/components/magicui/fade-text.tsx"],+ },};const example: Registry = {@@ -721,6 +726,14 @@ const example: Registry = {() => import("@/registry/components/example/word-fade-in-demo"),),},+ "fade-text-demo": {+ name: "fade-text-demo",+ type: "components:example",+ files: ["registry/components/example/fade-text-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/fade-text-demo"),+ ),+ },};export const registry: Registry = {...ui,