Variable Font Hover By Letter
fancy/variable-font-hover-by-letterFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/variable-font-hover-by-letter.jsonSource
1"use client"23import { useState } from "react"4import { debounce } from "lodash"5import { AnimationOptions, motion, stagger, useAnimate } from "motion/react"67interface TextProps {8 label: string9 fromFontVariationSettings: string10 toFontVariationSettings: string11 transition?: AnimationOptions12 staggerDuration?: number13 staggerFrom?: "first" | "last" | "center" | number14 className?: string15 onClick?: () => void16}1718const VariableFontHoverByLetter = ({19 label,20 fromFontVariationSettings = "'wght' 400, 'slnt' 0",21 toFontVariationSettings = "'wght' 900, 'slnt' -10",22 transition = {23 type: "spring",24 duration: 0.7,25 },26 staggerDuration = 0.03,27 staggerFrom = "first",28 className,29 onClick,30 ...props31}: TextProps) => {32 const [scope, animate] = useAnimate()33 const [isHovered, setIsHovered] = useState(false)3435 const mergeTransition = (baseTransition: AnimationOptions) => ({36 ...baseTransition,37 delay: stagger(staggerDuration, {38 from: staggerFrom,39 }),40 })4142 const hoverStart = debounce(43 () => {44 if (isHovered) return45 setIsHovered(true)4647 animate(48 ".letter",49 { fontVariationSettings: toFontVariationSettings },50 mergeTransition(transition)51 )52 },53 100,54 { leading: true, trailing: true }55 )5657 const hoverEnd = debounce(58 () => {59 setIsHovered(false)6061 animate(62 ".letter",63 { fontVariationSettings: fromFontVariationSettings },64 mergeTransition(transition)65 )66 },67 100,68 { leading: true, trailing: true }69 )7071 return (72 <motion.span73 className={`${className}`}74 onHoverStart={hoverStart}75 onHoverEnd={hoverEnd}76 onClick={onClick}77 ref={scope}78 {...props}79 >80 <span className="sr-only">{label}</span>8182 {label.split("").map((letter: string, i: number) => {83 return (84 <motion.span85 key={i}86 className="inline-block whitespace-pre letter"87 aria-hidden="true"88 >89 {letter}90 </motion.span>91 )92 })}93 </motion.span>94 )95}9697export default VariableFontHoverByLetter
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep |
