Dock Text
Dock Text is a React and Tailwind CSS text component from Eldora UI, licensed MIT. Copy it and paste it into your project.
Eldora UI
MIT
text
What it is
Dock Text is a React and Tailwind CSS text component from Eldora UI, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
Needs
npm i react motion
Licence
This component comes from Eldora UI and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Dock Text
"use client"
import React, { useRef, useState } from "react"
import { motion } from "motion/react"
import { cn } from "@/lib/utils"
interface DockTextProps {
text: string
down?: boolean
className?: string
}
export default function DockText({
text,
down = false,
className,
}: DockTextProps) {
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null)
const containerRef = useRef<HTMLHeadingElement>(null)
const handleMouseMove = (e: React.MouseEvent<HTMLHeadingElement>) => {
const container = containerRef.current
if (!container) return
const letters = container.children
const containerRect = container.getBoundingClientRect()
const mouseX = e.clientX - containerRect.left
Array.from(letters).forEach((letter, index) => {
const letterRect = letter.getBoundingClientRect()
const letterCenterX =
letterRect.left + letterRect.width / 2 - containerRect.left
const distance = Math.abs(mouseX - letterCenterX)
if (distance <= 10) {
setHoveredIndex(index)
}
})
}
const handleMouseLeave = () => {
setHoveredIndex(null)
}
return (
<motion.h1
ref={containerRef}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
className={cn(
"my-8 flex cursor-pointer items-center text-6xl font-bold text-gray-900 uppercase md:text-7xl lg:text-8xl dark:text-white",
className
)}
>
{text.split("").map((letter, index) => (
<motion.span
key={index}
animate={{
scaleY:
hoveredIndex === null
? 1
: Math.max(1, 1.3638 - Math.abs(index - hoveredIndex) * 0.1),
}}
transition={{
type: "spring",
stiffness: 150,
damping: 20,
mass: 0.5,
}}
style={{
display: "inline-block",
transformOrigin: down ? "top" : "bottom",
}}
>
{letter}
</motion.span>
))}
</motion.h1>
)
}