dock-text
eldoraui/dock-textFreeComponent
A dock text component with interactive hover effects.
Live preview
live · rendered by the registry
Rendered by eldoraui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://eldoraui.site/r/dock-text.jsonSource
1"use client"23import React, { useRef, useState } from "react"4import { motion } from "motion/react"56import { cn } from "@/lib/utils"78interface DockTextProps {9 text: string10 down?: boolean11 className?: string12}1314export default function DockText({15 text,16 down = false,17 className,18}: DockTextProps) {19 const [hoveredIndex, setHoveredIndex] = useState<number | null>(null)20 const containerRef = useRef<HTMLHeadingElement>(null)2122 const handleMouseMove = (e: React.MouseEvent<HTMLHeadingElement>) => {23 const container = containerRef.current24 if (!container) return2526 const letters = container.children27 const containerRect = container.getBoundingClientRect()28 const mouseX = e.clientX - containerRect.left2930 Array.from(letters).forEach((letter, index) => {31 const letterRect = letter.getBoundingClientRect()32 const letterCenterX =33 letterRect.left + letterRect.width / 2 - containerRect.left34 const distance = Math.abs(mouseX - letterCenterX)3536 if (distance <= 10) {37 setHoveredIndex(index)38 }39 })40 }4142 const handleMouseLeave = () => {43 setHoveredIndex(null)44 }4546 return (47 <motion.h148 ref={containerRef}49 onMouseMove={handleMouseMove}50 onMouseLeave={handleMouseLeave}51 className={cn(52 "my-8 flex cursor-pointer items-center text-6xl font-bold text-gray-900 uppercase md:text-7xl lg:text-8xl dark:text-white",53 className54 )}55 >56 {text.split("").map((letter, index) => (57 <motion.span58 key={index}59 animate={{60 scaleY:61 hoveredIndex === null62 ? 163 : Math.max(1, 1.3638 - Math.abs(index - hoveredIndex) * 0.1),64 }}65 transition={{66 type: "spring",67 stiffness: 150,68 damping: 20,69 mass: 0.5,70 }}71 style={{72 display: "inline-block",73 transformOrigin: down ? "top" : "bottom",74 }}75 >76 {letter}77 </motion.span>78 ))}79 </motion.h1>80 )81}
What it pulls in
npm packages
Files it writes
More from eldoraui
All 115 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| animated-badgeanimated-badge | eldoraui | Components | Free | 2 deps | |
| animated-frameworksanimated-frameworks | eldoraui | Components | Free | 2 deps | |
| animated-grid-patternanimated-grid-pattern | eldoraui | Components | Free | 3 deps | |
| animated-listanimated-list | eldoraui | Components | Free | 1 dep | |
| animated-shiny-buttonanimated-shiny-button | eldoraui | Components | Free | 1 dep | |
| blur-in-textblur-in-text | eldoraui | Components | Free | 3 deps | |
| browserbrowser | eldoraui | Components | Free | 2 deps | |
| card-flip-hovercard-flip-hover | eldoraui | Components | Free | 1 dep |
