Matrix Text
kokonut-ui/matrix-textFreeComponent
010110010110111101110101011100100010000001110111011001010110110001100011011011110110110101100101
Live preview
live · rendered by the registry
Rendered by kokonut-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://kokonutui.com/r/matrix-text.jsonSource
1"use client";23/**4 * @author: @dorianbaffier5 * @description: Matrix Text6 * @version: 1.0.07 * @date: 2025-06-268 * @license: MIT9 * @website: https://kokonutui.com10 * @github: https://github.com/kokonut-labs/kokonutui11 */1213import { motion } from "motion/react";14import { useCallback, useEffect, useMemo, useState } from "react";15import { cn } from "@/lib/utils";1617interface LetterState {18 char: string;19 isMatrix: boolean;20 isSpace: boolean;21}2223interface MatrixTextProps {24 text?: string;25 className?: string;26 initialDelay?: number;27 letterAnimationDuration?: number;28 letterInterval?: number;29}3031const MatrixText = ({32 text = "HelloWorld!",33 className,34 initialDelay = 200,35 letterAnimationDuration = 500,36 letterInterval = 100,37}: MatrixTextProps) => {38 const [letters, setLetters] = useState<LetterState[]>(() =>39 text.split("").map((char) => ({40 char,41 isMatrix: false,42 isSpace: char === " ",43 }))44 );45 const [isAnimating, setIsAnimating] = useState(false);4647 const getRandomChar = useCallback(48 () => (Math.random() > 0.5 ? "1" : "0"),49 []50 );5152 const animateLetter = useCallback(53 (index: number) => {54 if (index >= text.length) return;5556 requestAnimationFrame(() => {57 setLetters((prev) => {58 const newLetters = [...prev];59 if (!newLetters[index].isSpace) {60 newLetters[index] = {61 ...newLetters[index],62 char: getRandomChar(),63 isMatrix: true,64 };65 }66 return newLetters;67 });6869 setTimeout(() => {70 setLetters((prev) => {71 const newLetters = [...prev];72 newLetters[index] = {73 ...newLetters[index],74 char: text[index],75 isMatrix: false,76 };77 return newLetters;78 });79 }, letterAnimationDuration);80 });81 },82 [getRandomChar, text, letterAnimationDuration]83 );8485 const startAnimation = useCallback(() => {86 if (isAnimating) return;8788 setIsAnimating(true);89 let currentIndex = 0;9091 const animate = () => {92 if (currentIndex >= text.length) {93 setIsAnimating(false);94 return;95 }9697 animateLetter(currentIndex);98 currentIndex++;99 setTimeout(animate, letterInterval);100 };101102 animate();103 }, [animateLetter, text, isAnimating, letterInterval]);104105 useEffect(() => {106 const timer = setTimeout(startAnimation, initialDelay);107// … truncated
What it pulls in
npm packages
Files it writes
More from kokonut-ui
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Action Search Baraction-search-bar | kokonut-ui | Components | Free | 2 deps · 2 files | |
| AI Input Searchai-input-search | kokonut-ui | Components | Free | 1 dep · 2 files | |
| AI State Loadingai-loading | kokonut-ui | Components | Free | 1 dep | |
| AI Input Selectorai-prompt | kokonut-ui | Components | Free | 2 deps · 4 files | |
| AI Text Loadingai-text-loading | kokonut-ui | Components | Free | 1 dep | |
| AI Voiceai-voice | kokonut-ui | Components | Free | 2 deps | |
| Apple Activity Cardapple-activity-card | kokonut-ui | Components | Free | 1 dep | |
| Magnet Buttonattract-button | kokonut-ui | Components | Free | 2 deps |
