Text Along Path
fancy/text-along-pathFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/text-along-path.jsonSource
1import { RefObject, useEffect, useRef } from "react"2import { useScroll, UseScrollOptions, useTransform } from "motion/react"34type PreserveAspectRatioAlign =5 | "none"6 | "xMinYMin"7 | "xMidYMin"8 | "xMaxYMin"9 | "xMinYMid"10 | "xMidYMid"11 | "xMaxYMid"12 | "xMinYMax"13 | "xMidYMax"14 | "xMaxYMax"1516type PreserveAspectRatioMeetOrSlice = "meet" | "slice"1718type PreserveAspectRatio =19 | PreserveAspectRatioAlign20 | `${Exclude<PreserveAspectRatioAlign, "none">} ${PreserveAspectRatioMeetOrSlice}`2122interface AnimatedPathTextProps {23 // Path properties24 path: string25 pathId?: string26 pathClassName?: string27 preserveAspectRatio?: PreserveAspectRatio28 showPath?: boolean2930 // SVG properties31 width?: string | number32 height?: string | number33 viewBox?: string34 svgClassName?: string3536 // Text properties37 text: string38 textClassName?: string39 textAnchor?: "start" | "middle" | "end"4041 // Animation properties42 animationType?: "auto" | "scroll"4344 // Animation properties if animationType is auto45 duration?: number46 repeatCount?: number | "indefinite"47 easingFunction?: {48 calcMode?: string49 keyTimes?: string50 keySplines?: string51 }5253 // Scroll animation properties if animationType is scroll54 scrollContainer?: RefObject<HTMLElement | null>55 scrollOffset?: UseScrollOptions["offset"]56 scrollTransformValues?: [number, number]57}5859const AnimatedPathText = ({60 // Path defaults61 path,62 pathId,63 pathClassName,64 preserveAspectRatio = "xMidYMid meet",65 showPath = false,6667 // SVG defaults68 width = "100%",69 height = "100%",70 viewBox = "0 0 100 100",71 svgClassName,7273 // Text defaults74 text,75 textClassName,76 textAnchor = "start",7778 // Animation type79 animationType = "auto",8081 // Animation defaults82 duration = 4,83 repeatCount = "indefinite",8485 easingFunction = {},8687 // Scroll animation defaults88 scrollContainer,89 scrollOffset = ["start end", "end end"],90 scrollTransformValues = [0, 100],91}: AnimatedPathTextProps) => {92 const textPathRefs = useRef<SVGTextPathElement[]>([])9394 // naive id for the path. you should rather use yours :)95 const id =96 pathId || `animated-path-${Math.random().toString(36).substring(7)}`9798 const { scrollYProgress } = useScroll({99 ...(scrollContainer && { container: scrollContainer }),100 offset: scrollOffset,101 })102103 const t = useTransform(scrollYProgress, [0, 1], scrollTransformValues)104105 useEffect(() => {106 // Re-initialize scroll handler when container ref changes107// … truncated
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 |
