AI Response Typing Stream
tripled/ai-response-typing-shadcnuiFreeComponent
Character-by-character typing animation with natural pauses and thinking states
Install it
npx shadcn@latest add https://ui.tripled.work/r/ai-response-typing-shadcnui.jsonSource
1"use client";23import { motion } from "framer-motion";4import { useEffect, useRef, useState } from "react";56type AIResponseTypingProps = {7 text?: string;8 speed?: number;9 showCursor?: boolean;10 onComplete?: () => void;11 thinkingState?: "idle" | "thinking" | "typing";12};1314export function AIResponseTyping({15 text = "Hello! I'm an AI assistant. I can help you with questions, provide information, and assist with various tasks. Feel free to ask me anything!",16 speed = 30,17 showCursor = true,18 onComplete,19 thinkingState = "typing",20}: AIResponseTypingProps) {21 const [displayedText, setDisplayedText] = useState("");22 const [isThinking, setIsThinking] = useState(false);23 const [isTyping, setIsTyping] = useState(false);24 const intervalRef = useRef<NodeJS.Timeout | null>(null);2526 useEffect(() => {27 if (thinkingState === "thinking") {28 setIsThinking(true);29 setIsTyping(false);30 setDisplayedText("");31 return;32 }3334 if (thinkingState === "typing" && text) {35 setIsThinking(false);36 setIsTyping(true);37 setDisplayedText("");3839 let currentIndex = 0;40 const chars = text.split("");4142 const typeNextChar = () => {43 if (currentIndex < chars.length) {44 const nextChar = chars[currentIndex];4546 // Simulate natural typing pauses at punctuation47 const isPause =48 nextChar === "." ||49 nextChar === "," ||50 nextChar === "!" ||51 nextChar === "?" ||52 nextChar === "\n";5354 setDisplayedText((prev) => prev + nextChar);55 currentIndex++;5657 // Schedule next character with pause if needed58 if (isPause) {59 intervalRef.current = setTimeout(() => {60 typeNextChar();61 }, speed * 3);62 } else {63 intervalRef.current = setTimeout(() => {64 typeNextChar();65 }, speed);66 }67 } else {68 if (intervalRef.current) clearTimeout(intervalRef.current);69 setIsTyping(false);70 onComplete?.();71 }72 };7374 // Start typing75 typeNextChar();7677 return () => {78 if (intervalRef.current) clearTimeout(intervalRef.current);79 };80 }81 }, [text, speed, thinkingState, onComplete]);8283 return (84 <div className="w-full max-w-2xl">85 <div className="relative rounded-2xl border border-border bg-card p-6 min-h-[100px]">86 {/* Thinking state shimmer */}87// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tripled
All 282 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| AI Chat Interfaceai-chat-interface-shadcnui | tripled | Components | Free | 2 deps | |
| AI Glow Inputai-glow-input-shadcnui | tripled | Components | Free | 2 deps | |
| AI Loading Skeletonai-loading-skeleton-shadcnui | tripled | Components | Free | 2 deps | |
| AI Unlock Animationai-unlock-animation-shadcnui | tripled | Components | Free | 2 deps | |
| Animated Accordionanimated-accordion-shadcnui | tripled | Components | Free | 2 deps | |
| Animated Card Stackanimated-card-stack-baseui | tripled | Components | Free | 2 deps | |
| Animated Card Stackanimated-card-stack-shadcnui | tripled | Components | Free | 2 deps | |
| Animated Checkboxanimated-checkbox-shadcnui | tripled | Components | Free | 2 deps |
