UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat(typing-animation): add multi-word animation and cursor control (#769)
Kainf06370a87378
diff --git a/apps/www/content/docs/components/typing-animation.mdx b/apps/www/content/docs/components/typing-animation.mdxindex 4b6e0053..10850603 100644--- a/apps/www/content/docs/components/typing-animation.mdx+++ b/apps/www/content/docs/components/typing-animation.mdx@@ -40,6 +40,40 @@ npx shadcn@latest add @magicui/typing-animation</Tabs>+## Examples++### Basic Usage++<ComponentPreview name="typing-animation-demo" />++### Multiple Words with Loop++<ComponentPreview name="typing-animation-demo-2" />++### Custom Speed++<ComponentPreview name="typing-animation-demo-3" />++### Start on View++<ComponentPreview name="typing-animation-demo-4" />++### Without Cursor++<ComponentPreview name="typing-animation-demo-5" />++### Single Play (No Loop)++<ComponentPreview name="typing-animation-demo-6" />++### Cursor Blinking++<ComponentPreview name="typing-animation-demo-7" />++### Cursor Styles++<ComponentPreview name="typing-animation-demo-8" />+## Usage```tsx showLineNumbers@@ -47,16 +81,24 @@ import { TypingAnimation } from "@/components/ui/typing-animation"``````tsx showLineNumbers-<TypingAnimation>Typing Animation</TypingAnimation>+<TypingAnimation>Hello World! π</TypingAnimation>```## Props-| Prop | Type | Default | Description |-| ------------- | ------------------- | ------- | --------------------------------------------- |-| `children` | `string` | `-` | Text content to animate |-| `className` | `string` | `-` | The class name to be applied to the component |-| `duration` | `number` | `100` | Duration to wait in between each char type |-| `delay` | `number` | `0` | Delay before animation starts (in ms) |-| `as` | `React.ElementType` | `"div"` | Component to render as |-| `startOnView` | `boolean` | `false` | Start animation when component is in view |+| Prop | Type | Default | Description |+| ------------- | ----------------------------------- | -------- | ----------------------------------------------- |+| `children` | `string` | `-` | Single string to animate |+| `words` | `string[]` | `-` | Array of strings to type and delete in sequence |+| `className` | `string` | `-` | The class name to be applied to the component |+| `duration` | `number` | `100` | Duration for each character |+| `typeSpeed` | `number` | `100` | Speed of typing animation (ms per character) |+| `deleteSpeed` | `number` | `50` | Speed of deleting animation (ms per character) |+| `delay` | `number` | `0` | Delay before animation starts (in ms) |+| `pauseDelay` | `number` | `1000` | Pause duration between words (in ms) |+| `loop` | `boolean` | `false` | Whether to loop the animation |+| `as` | `React.ElementType` | `"span"` | Component to render as |+| `startOnView` | `boolean` | `true` | Start animation when component is in view |+| `showCursor` | `boolean` | `true` | Whether to show the typing cursor |+| `blinkCursor` | `boolean` | `true` | Whether the cursor should blink |+| `cursorStyle` | `"line" \| "block" \| "underscore"` | `"line"` | Style of the cursor (like VSCode) |diff --git a/apps/www/public/llms-full.txt b/apps/www/public/llms-full.txtindex d47ec898..10e99970 100644--- a/apps/www/public/llms-full.txt+++ b/apps/www/public/llms-full.txt@@ -15309,21 +15309,37 @@ import { motion, MotionProps, useInView } from "motion/react"import { cn } from "@/lib/utils"interface TypingAnimationProps extends MotionProps {- children: string+ children?: string+ words?: string[]className?: stringduration?: number+ typeSpeed?: number+ deleteSpeed?: numberdelay?: number+ pauseDelay?: number+ loop?: booleanas?: React.ElementTypestartOnView?: boolean+ showCursor?: boolean+ blinkCursor?: boolean+ cursorStyle?: "line" | "block" | "underscore"}export function TypingAnimation({children,+ words,className,duration = 100,+ typeSpeed,+ deleteSpeed,delay = 0,- as: Component = "div",- startOnView = false,+ pauseDelay = 1000,+ loop = false,+ as: Component = "span",+ startOnView = true,+ showCursor = true,+ blinkCursor = true,+ cursorStyle = "line",...props}: TypingAnimationProps) {const MotionComponent = motion.create(Component, {@@ -15331,59 +15347,127 @@ export function TypingAnimation({})const [displayedText, setDisplayedText] = useState<string>("")- const [started, setStarted] = useState(false)+ const [currentWordIndex, setCurrentWordIndex] = useState(0)+ const [currentCharIndex, setCurrentCharIndex] = useState(0)+ const [phase, setPhase] = useState<"typing" | "pause" | "deleting">("typing")const elementRef = useRef<HTMLElement | null>(null)const isInView = useInView(elementRef as React.RefObject<Element>, {amount: 0.3,once: true,})- useEffect(() => {- if (!startOnView) {- const startTimeout = setTimeout(() => {- setStarted(true)- }, delay)- return () => clearTimeout(startTimeout)- }+ const wordsToAnimate = words || (children ? [children] : [])+ const hasMultipleWords = wordsToAnimate.length > 1- if (!isInView) return+ const typingSpeed = typeSpeed || duration+ const deletingSpeed = deleteSpeed || typingSpeed / 2- const startTimeout = setTimeout(() => {- setStarted(true)- }, delay)-- return () => clearTimeout(startTimeout)- }, [delay, startOnView, isInView])+ const shouldStart = startOnView ? isInView : trueuseEffect(() => {- if (!started) return+ if (!shouldStart || wordsToAnimate.length === 0) return++ const timeoutDelay =+ delay > 0 && displayedText === ""+ ? delay+ : phase === "typing"+ ? typingSpeed+ : phase === "deleting"+ ? deletingSpeed+ : pauseDelay++ const timeout = setTimeout(() => {+ const currentWord = wordsToAnimate[currentWordIndex] || ""+ const graphemes = Array.from(currentWord)++ switch (phase) {+ case "typing":+ if (currentCharIndex < graphemes.length) {+ setDisplayedText(graphemes.slice(0, currentCharIndex + 1).join(""))+ setCurrentCharIndex(currentCharIndex + 1)+ } else {+ if (hasMultipleWords || loop) {+ const isLastWord = currentWordIndex === wordsToAnimate.length - 1+ if (!isLastWord || loop) {+ setPhase("pause")+ }+ }+ }+ break- const graphemes = Array.from(children)- let i = 0- const typingEffect = setInterval(() => {- if (i < graphemes.length) {- setDisplayedText(graphemes.slice(0, i + 1).join(""))- i++- } else {- clearInterval(typingEffect)+ case "pause":+ setPhase("deleting")+ break++ case "deleting":+ if (currentCharIndex > 0) {+ setDisplayedText(graphemes.slice(0, currentCharIndex - 1).join(""))+ setCurrentCharIndex(currentCharIndex - 1)+ } else {+ const nextIndex = (currentWordIndex + 1) % wordsToAnimate.length+ setCurrentWordIndex(nextIndex)+ setPhase("typing")+ }+ break}- }, duration)+ }, timeoutDelay)- return () => {- clearInterval(typingEffect)+ return () => clearTimeout(timeout)+ }, [+ shouldStart,+ phase,+ currentCharIndex,+ currentWordIndex,+ displayedText,+ wordsToAnimate,+ hasMultipleWords,+ loop,+ typingSpeed,+ deletingSpeed,+ pauseDelay,+ delay,+ ])++ const currentWordGraphemes = Array.from(+ wordsToAnimate[currentWordIndex] || ""+ )+ const isComplete =+ !loop &&+ currentWordIndex === wordsToAnimate.length - 1 &&+ currentCharIndex >= currentWordGraphemes.length &&+ phase !== "deleting"++ const shouldShowCursor =+ showCursor &&+ !isComplete &&+ (hasMultipleWords || loop || currentCharIndex < currentWordGraphemes.length)++ const getCursorChar = () => {+ switch (cursorStyle) {+ case "block":+ return "β"+ case "underscore":+ return "_"+ case "line":+ default:+ return "|"}- }, [children, duration, started])+ }return (<MotionComponentref={elementRef}- className={cn(- "text-4xl leading-[5rem] font-bold tracking-[-0.02em]",- className- )}+ className={cn("leading-[5rem] tracking-[-0.02em]", className)}{...props}>{displayedText}+ {shouldShowCursor && (+ <span+ className={cn("inline-block", blinkCursor && "animate-blink-cursor")}+ >+ {getCursorChar()}+ </span>+ )}</MotionComponent>)}@@ -15395,9 +15479,159 @@ Title: Typing Animation Demo--- file: example/typing-animation-demo.tsx ---import { TypingAnimation } from "@/registry/magicui/typing-animation"-export default function TypingAnimationDemo() {+export default function Component() {+ return <TypingAnimation>Hello World! π</TypingAnimation>+}+++===== EXAMPLE: typing-animation-demo-2 =====+Title: Typing Animation Multiple Words++--- file: example/typing-animation-demo-2.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation words={["Design π¨", "Build π¨", "Ship π"]} loop />+}+++===== EXAMPLE: typing-animation-demo-3 =====+Title: Typing Animation Custom Speed++--- file: example/typing-animation-demo-3.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <TypingAnimation+ words={["Fast typing", "Slow delete"]}+ typeSpeed={50}+ deleteSpeed={150}+ pauseDelay={2000}+ loop+ />+ )+}+++===== EXAMPLE: typing-animation-demo-4 =====+Title: Typing Animation Start on View++--- file: example/typing-animation-demo-4.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {return (- <TypingAnimation startOnView={true}>Typing Animation π</TypingAnimation>+ <TypingAnimation startOnView>Starts typing when in view</TypingAnimation>+ )+}+++===== EXAMPLE: typing-animation-demo-5 =====+Title: Typing Animation Without Cursor++--- file: example/typing-animation-demo-5.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation showCursor={false}>No cursor shown</TypingAnimation>+}+++===== EXAMPLE: typing-animation-demo-6 =====+Title: Typing Animation Single Play++--- file: example/typing-animation-demo-6.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation words={["First", "Second", "Final"]} loop={false} />+}+++===== EXAMPLE: typing-animation-demo-7 =====+Title: Typing Animation Cursor Blinking++--- file: example/typing-animation-demo-7.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <div className="flex-1 space-y-8">+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ With blinking cursor (default) - watch during pause+ </p>+ <TypingAnimation+ words={["Type", "Pause", "Delete"]}+ blinkCursor={true}+ pauseDelay={2000}+ loop+ className="text-4xl font-bold"+ >+ Blinking cursor+ </TypingAnimation>+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Without blinking cursor - static during pause+ </p>+ <TypingAnimation+ words={["Type", "Pause", "Delete"]}+ blinkCursor={false}+ pauseDelay={2000}+ loop+ className="text-4xl font-bold"+ >+ Static cursor+ </TypingAnimation>+ </div>+ </div>+ )+}+++===== EXAMPLE: typing-animation-demo-8 =====+Title: Typing Animation Cursor Styles++--- file: example/typing-animation-demo-8.tsx ---+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <div className="flex-1 space-y-8">+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Line cursor (default)+ </p>+ <TypingAnimation+ words={["Line cursor"]}+ cursorStyle="line"+ loop+ className="text-4xl font-bold"+ />+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Block cursor (VSCode style)+ </p>+ <TypingAnimation+ words={["Block cursor"]}+ cursorStyle="block"+ loop+ className="text-4xl font-bold"+ />+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">Underscore cursor</p>+ <TypingAnimation+ words={["Underscore cursor"]}+ cursorStyle="underscore"+ loop+ className="text-4xl font-bold"+ />+ </div>+ </div>)}diff --git a/apps/www/public/llms.txt b/apps/www/public/llms.txtindex d827ced9..94f1e90c 100644--- a/apps/www/public/llms.txt+++ b/apps/www/public/llms.txt@@ -151,6 +151,13 @@ This file provides LLM-friendly entry points to documentation and examples.- [Hyper Text Demo](https://github.com/magicuidesign/magicui/blob/main/example/hyper-text-demo.tsx): Example usage- [Avatar Circles Demo](https://github.com/magicuidesign/magicui/blob/main/example/avatar-circles-demo.tsx): Example usage- [Typing Animation Demo](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo.tsx): Example usage+- [Typing Animation Multiple Words](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-2.tsx): Example usage+- [Typing Animation Custom Speed](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-3.tsx): Example usage+- [Typing Animation Start on View](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-4.tsx): Example usage+- [Typing Animation Without Cursor](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-5.tsx): Example usage+- [Typing Animation Single Play](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-6.tsx): Example usage+- [Typing Animation Cursor Blinking](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-7.tsx): Example usage+- [Typing Animation Cursor Styles](https://github.com/magicuidesign/magicui/blob/main/example/typing-animation-demo-8.tsx): Example usage- [Scroll Based Velocity Demo](https://github.com/magicuidesign/magicui/blob/main/example/scroll-based-velocity-demo.tsx): Example usage- [Scroll Based Velocity Images](https://github.com/magicuidesign/magicui/blob/main/example/scroll-based-velocity-images-demo.tsx): Example usage- [Sparkles Text Demo](https://github.com/magicuidesign/magicui/blob/main/example/sparkles-text-demo.tsx): Example usagediff --git a/apps/www/public/r/registry.json b/apps/www/public/r/registry.jsonindex 09e74807..9a498d52 100644--- a/apps/www/public/r/registry.json+++ b/apps/www/public/r/registry.json@@ -808,7 +808,22 @@"path": "registry/magicui/typing-animation.tsx","type": "registry:ui"}- ]+ ],+ "cssVars": {+ "theme": {+ "animate-blink-cursor": "blink-cursor 1.2s step-end infinite"+ }+ },+ "css": {+ "@keyframes blink-cursor": {+ "0%, 49%": {+ "opacity": "1"+ },+ "50%, 100%": {+ "opacity": "0"+ }+ }+ }},{"name": "sparkles-text",@@ -2385,6 +2400,111 @@}]},+ {+ "name": "typing-animation-demo-2",+ "type": "registry:example",+ "title": "Typing Animation Multiple Words",+ "description": "Example showing multiple words with looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-3",+ "type": "registry:example",+ "title": "Typing Animation Custom Speed",+ "description": "Example showing custom typing and deleting speeds.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-4",+ "type": "registry:example",+ "title": "Typing Animation Start on View",+ "description": "Example showing animation that starts when in viewport.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-5",+ "type": "registry:example",+ "title": "Typing Animation Without Cursor",+ "description": "Example showing typing animation without cursor.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-5.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-6",+ "type": "registry:example",+ "title": "Typing Animation Single Play",+ "description": "Example showing single play without looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-6.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-7",+ "type": "registry:example",+ "title": "Typing Animation Cursor Blinking",+ "description": "Example showing cursor blinking control.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-7.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-8",+ "type": "registry:example",+ "title": "Typing Animation Cursor Styles",+ "description": "Example showing different cursor styles (line, block, underscore).",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-8.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "scroll-based-velocity-demo","type": "registry:example",diff --git a/apps/www/public/r/typing-animation-demo-2.json b/apps/www/public/r/typing-animation-demo-2.jsonnew file mode 100644index 00000000..153bd1fd--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-2.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-2",+ "type": "registry:example",+ "title": "Typing Animation Multiple Words",+ "description": "Example showing multiple words with looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-2.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return <TypingAnimation words={[\"Design π¨\", \"Build π¨\", \"Ship π\"]} loop />\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-3.json b/apps/www/public/r/typing-animation-demo-3.jsonnew file mode 100644index 00000000..b3e2d810--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-3.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-3",+ "type": "registry:example",+ "title": "Typing Animation Custom Speed",+ "description": "Example showing custom typing and deleting speeds.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-3.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return (\n <TypingAnimation\n words={[\"Fast typing\", \"Slow delete\"]}\n typeSpeed={50}\n deleteSpeed={150}\n pauseDelay={2000}\n loop\n />\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-4.json b/apps/www/public/r/typing-animation-demo-4.jsonnew file mode 100644index 00000000..0470e86b--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-4.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-4",+ "type": "registry:example",+ "title": "Typing Animation Start on View",+ "description": "Example showing animation that starts when in viewport.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-4.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return (\n <TypingAnimation startOnView>Starts typing when in view</TypingAnimation>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-5.json b/apps/www/public/r/typing-animation-demo-5.jsonnew file mode 100644index 00000000..295a1e5c--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-5.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-5",+ "type": "registry:example",+ "title": "Typing Animation Without Cursor",+ "description": "Example showing typing animation without cursor.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-5.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return <TypingAnimation showCursor={false}>No cursor shown</TypingAnimation>\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-6.json b/apps/www/public/r/typing-animation-demo-6.jsonnew file mode 100644index 00000000..7782e205--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-6.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-6",+ "type": "registry:example",+ "title": "Typing Animation Single Play",+ "description": "Example showing single play without looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-6.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return <TypingAnimation words={[\"First\", \"Second\", \"Final\"]} loop={false} />\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-7.json b/apps/www/public/r/typing-animation-demo-7.jsonnew file mode 100644index 00000000..39619399--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-7.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-7",+ "type": "registry:example",+ "title": "Typing Animation Cursor Blinking",+ "description": "Example showing cursor blinking control.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-7.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return (\n <div className=\"flex-1 space-y-8\">\n <div>\n <p className=\"text-muted-foreground mb-2 text-sm\">\n With blinking cursor (default) - watch during pause\n </p>\n <TypingAnimation\n words={[\"Type\", \"Pause\", \"Delete\"]}\n blinkCursor={true}\n pauseDelay={2000}\n loop\n className=\"text-4xl font-bold\"\n >\n Blinking cursor\n </TypingAnimation>\n </div>\n <div>\n <p className=\"text-muted-foreground mb-2 text-sm\">\n Without blinking cursor - static during pause\n </p>\n <TypingAnimation\n words={[\"Type\", \"Pause\", \"Delete\"]}\n blinkCursor={false}\n pauseDelay={2000}\n loop\n className=\"text-4xl font-bold\"\n >\n Static cursor\n </TypingAnimation>\n </div>\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo-8.json b/apps/www/public/r/typing-animation-demo-8.jsonnew file mode 100644index 00000000..f588c650--- /dev/null+++ b/apps/www/public/r/typing-animation-demo-8.json@@ -0,0 +1,17 @@+{+ "$schema": "https://ui.shadcn.com/schema/registry-item.json",+ "name": "typing-animation-demo-8",+ "type": "registry:example",+ "title": "Typing Animation Cursor Styles",+ "description": "Example showing different cursor styles (line, block, underscore).",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-8.tsx",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return (\n <div className=\"flex-1 space-y-8\">\n <div>\n <p className=\"text-muted-foreground mb-2 text-sm\">\n Line cursor (default)\n </p>\n <TypingAnimation\n words={[\"Line cursor\"]}\n cursorStyle=\"line\"\n loop\n className=\"text-4xl font-bold\"\n />\n </div>\n <div>\n <p className=\"text-muted-foreground mb-2 text-sm\">\n Block cursor (VSCode style)\n </p>\n <TypingAnimation\n words={[\"Block cursor\"]}\n cursorStyle=\"block\"\n loop\n className=\"text-4xl font-bold\"\n />\n </div>\n <div>\n <p className=\"text-muted-foreground mb-2 text-sm\">Underscore cursor</p>\n <TypingAnimation\n words={[\"Underscore cursor\"]}\n cursorStyle=\"underscore\"\n loop\n className=\"text-4xl font-bold\"\n />\n </div>\n </div>\n )\n}\n",+ "type": "registry:example"+ }+ ]+}\ No newline at end of filediff --git a/apps/www/public/r/typing-animation-demo.json b/apps/www/public/r/typing-animation-demo.jsonindex bcc2108f..737ed2cc 100644--- a/apps/www/public/r/typing-animation-demo.json+++ b/apps/www/public/r/typing-animation-demo.json@@ -10,7 +10,7 @@"files": [{"path": "registry/example/typing-animation-demo.tsx",- "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function TypingAnimationDemo() {\n return (\n <TypingAnimation startOnView={true}>Typing Animation π</TypingAnimation>\n )\n}\n",+ "content": "import { TypingAnimation } from \"@/registry/magicui/typing-animation\"\n\nexport default function Component() {\n return <TypingAnimation>Hello World! π</TypingAnimation>\n}\n","type": "registry:example"}]diff --git a/apps/www/public/r/typing-animation.json b/apps/www/public/r/typing-animation.jsonindex f64158b2..1797e62b 100644--- a/apps/www/public/r/typing-animation.json+++ b/apps/www/public/r/typing-animation.json@@ -10,8 +10,23 @@"files": [{"path": "registry/magicui/typing-animation.tsx",- "content": "\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport { motion, MotionProps, useInView } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TypingAnimationProps extends MotionProps {\n children: string\n className?: string\n duration?: number\n delay?: number\n as?: React.ElementType\n startOnView?: boolean\n}\n\nexport function TypingAnimation({\n children,\n className,\n duration = 100,\n delay = 0,\n as: Component = \"div\",\n startOnView = false,\n ...props\n}: TypingAnimationProps) {\n const MotionComponent = motion.create(Component, {\n forwardMotionProps: true,\n })\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [started, setStarted] = useState(false)\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n useEffect(() => {\n if (!startOnView) {\n const startTimeout = setTimeout(() => {\n setStarted(true)\n }, delay)\n return () => clearTimeout(startTimeout)\n }\n\n if (!isInView) return\n\n const startTimeout = setTimeout(() => {\n setStarted(true)\n }, delay)\n\n return () => clearTimeout(startTimeout)\n }, [delay, startOnView, isInView])\n\n useEffect(() => {\n if (!started) return\n\n const graphemes = Array.from(children)\n let i = 0\n const typingEffect = setInterval(() => {\n if (i < graphemes.length) {\n setDisplayedText(graphemes.slice(0, i + 1).join(\"\"))\n i++\n } else {\n clearInterval(typingEffect)\n }\n }, duration)\n\n return () => {\n clearInterval(typingEffect)\n }\n }, [children, duration, started])\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\n \"text-4xl leading-[5rem] font-bold tracking-[-0.02em]\",\n className\n )}\n {...props}\n >\n {displayedText}\n </MotionComponent>\n )\n}\n",+ "content": "\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport { motion, MotionProps, useInView } from \"motion/react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface TypingAnimationProps extends MotionProps {\n children?: string\n words?: string[]\n className?: string\n duration?: number\n typeSpeed?: number\n deleteSpeed?: number\n delay?: number\n pauseDelay?: number\n loop?: boolean\n as?: React.ElementType\n startOnView?: boolean\n showCursor?: boolean\n blinkCursor?: boolean\n cursorStyle?: \"line\" | \"block\" | \"underscore\"\n}\n\nexport function TypingAnimation({\n children,\n words,\n className,\n duration = 100,\n typeSpeed,\n deleteSpeed,\n delay = 0,\n pauseDelay = 1000,\n loop = false,\n as: Component = \"span\",\n startOnView = true,\n showCursor = true,\n blinkCursor = true,\n cursorStyle = \"line\",\n ...props\n}: TypingAnimationProps) {\n const MotionComponent = motion.create(Component, {\n forwardMotionProps: true,\n })\n\n const [displayedText, setDisplayedText] = useState<string>(\"\")\n const [currentWordIndex, setCurrentWordIndex] = useState(0)\n const [currentCharIndex, setCurrentCharIndex] = useState(0)\n const [phase, setPhase] = useState<\"typing\" | \"pause\" | \"deleting\">(\"typing\")\n const elementRef = useRef<HTMLElement | null>(null)\n const isInView = useInView(elementRef as React.RefObject<Element>, {\n amount: 0.3,\n once: true,\n })\n\n const wordsToAnimate = words || (children ? [children] : [])\n const hasMultipleWords = wordsToAnimate.length > 1\n\n const typingSpeed = typeSpeed || duration\n const deletingSpeed = deleteSpeed || typingSpeed / 2\n\n const shouldStart = startOnView ? isInView : true\n\n useEffect(() => {\n if (!shouldStart || wordsToAnimate.length === 0) return\n\n const timeoutDelay =\n delay > 0 && displayedText === \"\"\n ? delay\n : phase === \"typing\"\n ? typingSpeed\n : phase === \"deleting\"\n ? deletingSpeed\n : pauseDelay\n\n const timeout = setTimeout(() => {\n const currentWord = wordsToAnimate[currentWordIndex] || \"\"\n const graphemes = Array.from(currentWord)\n\n switch (phase) {\n case \"typing\":\n if (currentCharIndex < graphemes.length) {\n setDisplayedText(graphemes.slice(0, currentCharIndex + 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex + 1)\n } else {\n if (hasMultipleWords || loop) {\n const isLastWord = currentWordIndex === wordsToAnimate.length - 1\n if (!isLastWord || loop) {\n setPhase(\"pause\")\n }\n }\n }\n break\n\n case \"pause\":\n setPhase(\"deleting\")\n break\n\n case \"deleting\":\n if (currentCharIndex > 0) {\n setDisplayedText(graphemes.slice(0, currentCharIndex - 1).join(\"\"))\n setCurrentCharIndex(currentCharIndex - 1)\n } else {\n const nextIndex = (currentWordIndex + 1) % wordsToAnimate.length\n setCurrentWordIndex(nextIndex)\n setPhase(\"typing\")\n }\n break\n }\n }, timeoutDelay)\n\n return () => clearTimeout(timeout)\n }, [\n shouldStart,\n phase,\n currentCharIndex,\n currentWordIndex,\n displayedText,\n wordsToAnimate,\n hasMultipleWords,\n loop,\n typingSpeed,\n deletingSpeed,\n pauseDelay,\n delay,\n ])\n\n const currentWordGraphemes = Array.from(\n wordsToAnimate[currentWordIndex] || \"\"\n )\n const isComplete =\n !loop &&\n currentWordIndex === wordsToAnimate.length - 1 &&\n currentCharIndex >= currentWordGraphemes.length &&\n phase !== \"deleting\"\n\n const shouldShowCursor =\n showCursor &&\n !isComplete &&\n (hasMultipleWords || loop || currentCharIndex < currentWordGraphemes.length)\n\n const getCursorChar = () => {\n switch (cursorStyle) {\n case \"block\":\n return \"β\"\n case \"underscore\":\n return \"_\"\n case \"line\":\n default:\n return \"|\"\n }\n }\n\n return (\n <MotionComponent\n ref={elementRef}\n className={cn(\"leading-[5rem] tracking-[-0.02em]\", className)}\n {...props}\n >\n {displayedText}\n {shouldShowCursor && (\n <span\n className={cn(\"inline-block\", blinkCursor && \"animate-blink-cursor\")}\n >\n {getCursorChar()}\n </span>\n )}\n </MotionComponent>\n )\n}\n","type": "registry:ui"}- ]+ ],+ "cssVars": {+ "theme": {+ "animate-blink-cursor": "blink-cursor 1.2s step-end infinite"+ }+ },+ "css": {+ "@keyframes blink-cursor": {+ "0%, 49%": {+ "opacity": "1"+ },+ "50%, 100%": {+ "opacity": "0"+ }+ }+ }}\ No newline at end of filediff --git a/apps/www/public/registry.json b/apps/www/public/registry.jsonindex 09e74807..9a498d52 100644--- a/apps/www/public/registry.json+++ b/apps/www/public/registry.json@@ -808,7 +808,22 @@"path": "registry/magicui/typing-animation.tsx","type": "registry:ui"}- ]+ ],+ "cssVars": {+ "theme": {+ "animate-blink-cursor": "blink-cursor 1.2s step-end infinite"+ }+ },+ "css": {+ "@keyframes blink-cursor": {+ "0%, 49%": {+ "opacity": "1"+ },+ "50%, 100%": {+ "opacity": "0"+ }+ }+ }},{"name": "sparkles-text",@@ -2385,6 +2400,111 @@}]},+ {+ "name": "typing-animation-demo-2",+ "type": "registry:example",+ "title": "Typing Animation Multiple Words",+ "description": "Example showing multiple words with looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-3",+ "type": "registry:example",+ "title": "Typing Animation Custom Speed",+ "description": "Example showing custom typing and deleting speeds.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-4",+ "type": "registry:example",+ "title": "Typing Animation Start on View",+ "description": "Example showing animation that starts when in viewport.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-5",+ "type": "registry:example",+ "title": "Typing Animation Without Cursor",+ "description": "Example showing typing animation without cursor.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-5.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-6",+ "type": "registry:example",+ "title": "Typing Animation Single Play",+ "description": "Example showing single play without looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-6.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-7",+ "type": "registry:example",+ "title": "Typing Animation Cursor Blinking",+ "description": "Example showing cursor blinking control.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-7.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-8",+ "type": "registry:example",+ "title": "Typing Animation Cursor Styles",+ "description": "Example showing different cursor styles (line, block, underscore).",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-8.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "scroll-based-velocity-demo","type": "registry:example",diff --git a/apps/www/registry.json b/apps/www/registry.jsonindex 09e74807..9a498d52 100644--- a/apps/www/registry.json+++ b/apps/www/registry.json@@ -808,7 +808,22 @@"path": "registry/magicui/typing-animation.tsx","type": "registry:ui"}- ]+ ],+ "cssVars": {+ "theme": {+ "animate-blink-cursor": "blink-cursor 1.2s step-end infinite"+ }+ },+ "css": {+ "@keyframes blink-cursor": {+ "0%, 49%": {+ "opacity": "1"+ },+ "50%, 100%": {+ "opacity": "0"+ }+ }+ }},{"name": "sparkles-text",@@ -2385,6 +2400,111 @@}]},+ {+ "name": "typing-animation-demo-2",+ "type": "registry:example",+ "title": "Typing Animation Multiple Words",+ "description": "Example showing multiple words with looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-2.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-3",+ "type": "registry:example",+ "title": "Typing Animation Custom Speed",+ "description": "Example showing custom typing and deleting speeds.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-3.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-4",+ "type": "registry:example",+ "title": "Typing Animation Start on View",+ "description": "Example showing animation that starts when in viewport.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-4.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-5",+ "type": "registry:example",+ "title": "Typing Animation Without Cursor",+ "description": "Example showing typing animation without cursor.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-5.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-6",+ "type": "registry:example",+ "title": "Typing Animation Single Play",+ "description": "Example showing single play without looping.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-6.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-7",+ "type": "registry:example",+ "title": "Typing Animation Cursor Blinking",+ "description": "Example showing cursor blinking control.",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-7.tsx",+ "type": "registry:example"+ }+ ]+ },+ {+ "name": "typing-animation-demo-8",+ "type": "registry:example",+ "title": "Typing Animation Cursor Styles",+ "description": "Example showing different cursor styles (line, block, underscore).",+ "registryDependencies": [+ "@magicui/typing-animation"+ ],+ "files": [+ {+ "path": "registry/example/typing-animation-demo-8.tsx",+ "type": "registry:example"+ }+ ]+ },{"name": "scroll-based-velocity-demo","type": "registry:example",diff --git a/apps/www/registry/__index__.tsx b/apps/www/registry/__index__.tsxindex cb204ba3..28b83d4c 100644--- a/apps/www/registry/__index__.tsx+++ b/apps/www/registry/__index__.tsx@@ -2429,6 +2429,125 @@ export const Index: Record<string, any> = {}),meta: undefined,},+ "typing-animation-demo-2": {+ name: "typing-animation-demo-2",+ description: "Example showing multiple words with looping.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-2.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-2.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-3": {+ name: "typing-animation-demo-3",+ description: "Example showing custom typing and deleting speeds.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-3.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-3.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-4": {+ name: "typing-animation-demo-4",+ description: "Example showing animation that starts when in viewport.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-4.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-4.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-5": {+ name: "typing-animation-demo-5",+ description: "Example showing typing animation without cursor.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-5.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-5.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-6": {+ name: "typing-animation-demo-6",+ description: "Example showing single play without looping.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-6.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-6.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-7": {+ name: "typing-animation-demo-7",+ description: "Example showing cursor blinking control.",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-7.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-7.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },+ "typing-animation-demo-8": {+ name: "typing-animation-demo-8",+ description: "Example showing different cursor styles (line, block, underscore).",+ type: "registry:example",+ registryDependencies: ["@magicui/typing-animation"],+ files: [{+ path: "registry/example/typing-animation-demo-8.tsx",+ type: "registry:example",+ target: ""+ }],+ component: React.lazy(async () => {+ const mod = await import("@/registry/example/typing-animation-demo-8.tsx")+ const exportName = Object.keys(mod).find(key => typeof mod[key] === 'function' || typeof mod[key] === 'object') || item.name+ return { default: mod.default || mod[exportName] }+ }),+ meta: undefined,+ },"scroll-based-velocity-demo": {name: "scroll-based-velocity-demo",description: "Example showing text speed changes based on scroll velocity.",diff --git a/apps/www/registry/example/typing-animation-demo-2.tsx b/apps/www/registry/example/typing-animation-demo-2.tsxnew file mode 100644index 00000000..a28a0ee0--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-2.tsx@@ -0,0 +1,5 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation words={["Design π¨", "Build π¨", "Ship π"]} loop />+}diff --git a/apps/www/registry/example/typing-animation-demo-3.tsx b/apps/www/registry/example/typing-animation-demo-3.tsxnew file mode 100644index 00000000..7f7d8332--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-3.tsx@@ -0,0 +1,13 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <TypingAnimation+ words={["Fast typing", "Slow delete"]}+ typeSpeed={50}+ deleteSpeed={150}+ pauseDelay={2000}+ loop+ />+ )+}diff --git a/apps/www/registry/example/typing-animation-demo-4.tsx b/apps/www/registry/example/typing-animation-demo-4.tsxnew file mode 100644index 00000000..d414105a--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-4.tsx@@ -0,0 +1,7 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <TypingAnimation startOnView>Starts typing when in view</TypingAnimation>+ )+}diff --git a/apps/www/registry/example/typing-animation-demo-5.tsx b/apps/www/registry/example/typing-animation-demo-5.tsxnew file mode 100644index 00000000..3d7a3f54--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-5.tsx@@ -0,0 +1,5 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation showCursor={false}>No cursor shown</TypingAnimation>+}diff --git a/apps/www/registry/example/typing-animation-demo-6.tsx b/apps/www/registry/example/typing-animation-demo-6.tsxnew file mode 100644index 00000000..93b1ed7b--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-6.tsx@@ -0,0 +1,5 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return <TypingAnimation words={["First", "Second", "Final"]} loop={false} />+}diff --git a/apps/www/registry/example/typing-animation-demo-7.tsx b/apps/www/registry/example/typing-animation-demo-7.tsxnew file mode 100644index 00000000..f426c043--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-7.tsx@@ -0,0 +1,36 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <div className="flex-1 space-y-8">+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ With blinking cursor (default) - watch during pause+ </p>+ <TypingAnimation+ words={["Type", "Pause", "Delete"]}+ blinkCursor={true}+ pauseDelay={2000}+ loop+ className="text-4xl font-bold"+ >+ Blinking cursor+ </TypingAnimation>+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Without blinking cursor - static during pause+ </p>+ <TypingAnimation+ words={["Type", "Pause", "Delete"]}+ blinkCursor={false}+ pauseDelay={2000}+ loop+ className="text-4xl font-bold"+ >+ Static cursor+ </TypingAnimation>+ </div>+ </div>+ )+}diff --git a/apps/www/registry/example/typing-animation-demo-8.tsx b/apps/www/registry/example/typing-animation-demo-8.tsxnew file mode 100644index 00000000..40f2e21d--- /dev/null+++ b/apps/www/registry/example/typing-animation-demo-8.tsx@@ -0,0 +1,39 @@+import { TypingAnimation } from "@/registry/magicui/typing-animation"++export default function Component() {+ return (+ <div className="flex-1 space-y-8">+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Line cursor (default)+ </p>+ <TypingAnimation+ words={["Line cursor"]}+ cursorStyle="line"+ loop+ className="text-4xl font-bold"+ />+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">+ Block cursor (VSCode style)+ </p>+ <TypingAnimation+ words={["Block cursor"]}+ cursorStyle="block"+ loop+ className="text-4xl font-bold"+ />+ </div>+ <div>+ <p className="text-muted-foreground mb-2 text-sm">Underscore cursor</p>+ <TypingAnimation+ words={["Underscore cursor"]}+ cursorStyle="underscore"+ loop+ className="text-4xl font-bold"+ />+ </div>+ </div>+ )+}diff --git a/apps/www/registry/example/typing-animation-demo.tsx b/apps/www/registry/example/typing-animation-demo.tsxindex aea2845b..071ed229 100644--- a/apps/www/registry/example/typing-animation-demo.tsx+++ b/apps/www/registry/example/typing-animation-demo.tsx@@ -1,7 +1,5 @@import { TypingAnimation } from "@/registry/magicui/typing-animation"-export default function TypingAnimationDemo() {- return (- <TypingAnimation startOnView={true}>Typing Animation π</TypingAnimation>- )+export default function Component() {+ return <TypingAnimation>Hello World! π</TypingAnimation>}diff --git a/apps/www/registry/magicui/typing-animation.tsx b/apps/www/registry/magicui/typing-animation.tsxindex b27675fa..a1ad2e3e 100644--- a/apps/www/registry/magicui/typing-animation.tsx+++ b/apps/www/registry/magicui/typing-animation.tsx@@ -6,21 +6,37 @@ import { motion, MotionProps, useInView } from "motion/react"import { cn } from "@/lib/utils"interface TypingAnimationProps extends MotionProps {- children: string+ children?: string+ words?: string[]className?: stringduration?: number+ typeSpeed?: number+ deleteSpeed?: numberdelay?: number+ pauseDelay?: number+ loop?: booleanas?: React.ElementTypestartOnView?: boolean+ showCursor?: boolean+ blinkCursor?: boolean+ cursorStyle?: "line" | "block" | "underscore"}export function TypingAnimation({children,+ words,className,duration = 100,+ typeSpeed,+ deleteSpeed,delay = 0,- as: Component = "div",- startOnView = false,+ pauseDelay = 1000,+ loop = false,+ as: Component = "span",+ startOnView = true,+ showCursor = true,+ blinkCursor = true,+ cursorStyle = "line",...props}: TypingAnimationProps) {const MotionComponent = motion.create(Component, {@@ -28,59 +44,127 @@ export function TypingAnimation({})const [displayedText, setDisplayedText] = useState<string>("")- const [started, setStarted] = useState(false)+ const [currentWordIndex, setCurrentWordIndex] = useState(0)+ const [currentCharIndex, setCurrentCharIndex] = useState(0)+ const [phase, setPhase] = useState<"typing" | "pause" | "deleting">("typing")const elementRef = useRef<HTMLElement | null>(null)const isInView = useInView(elementRef as React.RefObject<Element>, {amount: 0.3,once: true,})+ const wordsToAnimate = words || (children ? [children] : [])+ const hasMultipleWords = wordsToAnimate.length > 1++ const typingSpeed = typeSpeed || duration+ const deletingSpeed = deleteSpeed || typingSpeed / 2++ const shouldStart = startOnView ? isInView : true+useEffect(() => {- if (!startOnView) {- const startTimeout = setTimeout(() => {- setStarted(true)- }, delay)- return () => clearTimeout(startTimeout)- }+ if (!shouldStart || wordsToAnimate.length === 0) return- if (!isInView) return+ const timeoutDelay =+ delay > 0 && displayedText === ""+ ? delay+ : phase === "typing"+ ? typingSpeed+ : phase === "deleting"+ ? deletingSpeed+ : pauseDelay- const startTimeout = setTimeout(() => {- setStarted(true)- }, delay)+ const timeout = setTimeout(() => {+ const currentWord = wordsToAnimate[currentWordIndex] || ""+ const graphemes = Array.from(currentWord)- return () => clearTimeout(startTimeout)- }, [delay, startOnView, isInView])+ switch (phase) {+ case "typing":+ if (currentCharIndex < graphemes.length) {+ setDisplayedText(graphemes.slice(0, currentCharIndex + 1).join(""))+ setCurrentCharIndex(currentCharIndex + 1)+ } else {+ if (hasMultipleWords || loop) {+ const isLastWord = currentWordIndex === wordsToAnimate.length - 1+ if (!isLastWord || loop) {+ setPhase("pause")+ }+ }+ }+ break- useEffect(() => {- if (!started) return-- const graphemes = Array.from(children)- let i = 0- const typingEffect = setInterval(() => {- if (i < graphemes.length) {- setDisplayedText(graphemes.slice(0, i + 1).join(""))- i++- } else {- clearInterval(typingEffect)+ case "pause":+ setPhase("deleting")+ break++ case "deleting":+ if (currentCharIndex > 0) {+ setDisplayedText(graphemes.slice(0, currentCharIndex - 1).join(""))+ setCurrentCharIndex(currentCharIndex - 1)+ } else {+ const nextIndex = (currentWordIndex + 1) % wordsToAnimate.length+ setCurrentWordIndex(nextIndex)+ setPhase("typing")+ }+ break}- }, duration)+ }, timeoutDelay)- return () => {- clearInterval(typingEffect)+ return () => clearTimeout(timeout)+ }, [+ shouldStart,+ phase,+ currentCharIndex,+ currentWordIndex,+ displayedText,+ wordsToAnimate,+ hasMultipleWords,+ loop,+ typingSpeed,+ deletingSpeed,+ pauseDelay,+ delay,+ ])++ const currentWordGraphemes = Array.from(+ wordsToAnimate[currentWordIndex] || ""+ )+ const isComplete =+ !loop &&+ currentWordIndex === wordsToAnimate.length - 1 &&+ currentCharIndex >= currentWordGraphemes.length &&+ phase !== "deleting"++ const shouldShowCursor =+ showCursor &&+ !isComplete &&+ (hasMultipleWords || loop || currentCharIndex < currentWordGraphemes.length)++ const getCursorChar = () => {+ switch (cursorStyle) {+ case "block":+ return "β"+ case "underscore":+ return "_"+ case "line":+ default:+ return "|"}- }, [children, duration, started])+ }return (<MotionComponentref={elementRef}- className={cn(- "text-4xl leading-[5rem] font-bold tracking-[-0.02em]",- className- )}+ className={cn("leading-[5rem] tracking-[-0.02em]", className)}{...props}>{displayedText}+ {shouldShowCursor && (+ <span+ className={cn("inline-block", blinkCursor && "animate-blink-cursor")}+ >+ {getCursorChar()}+ </span>+ )}</MotionComponent>)}diff --git a/apps/www/registry/registry-examples.ts b/apps/www/registry/registry-examples.tsindex cceba264..e99cb254 100644--- a/apps/www/registry/registry-examples.ts+++ b/apps/www/registry/registry-examples.ts@@ -983,6 +983,98 @@ export const examples: Registry["items"] = [},],},+ {+ name: "typing-animation-demo-2",+ type: "registry:example",+ title: "Typing Animation Multiple Words",+ description: "Example showing multiple words with looping.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-2.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-3",+ type: "registry:example",+ title: "Typing Animation Custom Speed",+ description: "Example showing custom typing and deleting speeds.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-3.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-4",+ type: "registry:example",+ title: "Typing Animation Start on View",+ description: "Example showing animation that starts when in viewport.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-4.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-5",+ type: "registry:example",+ title: "Typing Animation Without Cursor",+ description: "Example showing typing animation without cursor.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-5.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-6",+ type: "registry:example",+ title: "Typing Animation Single Play",+ description: "Example showing single play without looping.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-6.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-7",+ type: "registry:example",+ title: "Typing Animation Cursor Blinking",+ description: "Example showing cursor blinking control.",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-7.tsx",+ type: "registry:example",+ },+ ],+ },+ {+ name: "typing-animation-demo-8",+ type: "registry:example",+ title: "Typing Animation Cursor Styles",+ description:+ "Example showing different cursor styles (line, block, underscore).",+ registryDependencies: ["@magicui/typing-animation"],+ files: [+ {+ path: "example/typing-animation-demo-8.tsx",+ type: "registry:example",+ },+ ],+ },{name: "scroll-based-velocity-demo",type: "registry:example",diff --git a/apps/www/registry/registry-ui.ts b/apps/www/registry/registry-ui.tsindex 1b12091c..c7cadab2 100644--- a/apps/www/registry/registry-ui.ts+++ b/apps/www/registry/registry-ui.ts@@ -767,6 +767,21 @@ export const ui: Registry["items"] = [type: "registry:ui",},],+ cssVars: {+ theme: {+ "animate-blink-cursor": "blink-cursor 1.2s step-end infinite",+ },+ },+ css: {+ "@keyframes blink-cursor": {+ "0%, 49%": {+ opacity: "1",+ },+ "50%, 100%": {+ opacity: "0",+ },+ },+ },},{name: "sparkles-text",diff --git a/apps/www/styles/globals.css b/apps/www/styles/globals.cssindex a8662461..cf0e067e 100644--- a/apps/www/styles/globals.css+++ b/apps/www/styles/globals.css@@ -172,10 +172,22 @@--animate-line-shadow: line-shadow 15s linear infinite;--animate-aurora: aurora 8s ease-in-out infinite alternate;--animate-ping: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite;+ --animate-blink-cursor: blink-cursor 1.2s step-end infinite;/* End Animation Variables *//* Added Keyframes */+ @keyframes blink-cursor {+ 0%,+ 49% {+ opacity: 1;+ }+ 50%,+ 100% {+ opacity: 0;+ }+ }+@keyframes aurora {0% {background-position: 0% 50%;