Element Along Svg Path
fancy/element-along-svg-pathFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/element-along-svg-path.jsonSource
1import {2 createContext,3 RefObject,4 useContext,5 useEffect,6 useRef,7 useState,8} from "react"9import {10 motion,11 MotionValue,12 useMotionValue,13 useScroll,14 UseScrollOptions,15 useSpring,16 useTime,17 useTransform,18} from "motion/react"1920import { cn } from "@/lib/utils"2122type PreserveAspectRatioAlign =23 | "none"24 | "xMinYMin"25 | "xMidYMin"26 | "xMaxYMin"27 | "xMinYMid"28 | "xMidYMid"29 | "xMaxYMid"30 | "xMinYMax"31 | "xMidYMax"32 | "xMaxYMax"3334type PreserveAspectRatioMeetOrSlice = "meet" | "slice"3536type PreserveAspectRatio =37 | PreserveAspectRatioAlign38 | `${Exclude<PreserveAspectRatioAlign, "none">} ${PreserveAspectRatioMeetOrSlice}`3940interface ElementAlongPathProps {41 // Path properties42 path: string43 pathId?: string44 className?: string45 preserveAspectRatio?: PreserveAspectRatio46 showPath?: boolean47 direction?: "normal" | "reverse"4849 // SVG properties50 width?: string | number51 height?: string | number52 viewBox?: string5354 // Animation properties55 animationType?: "auto" | "scroll"5657 // Animation properties if animationType is auto58 duration?: number59 transition?: any6061 // Scroll animation properties if animationType is scroll62 scrollContainer?: RefObject<HTMLElement | null>63 scrollOffset?: UseScrollOptions["offset"]64 scrollTransformValues?: [number, number]6566 // Children67 children?: React.ReactNode68}6970interface ElementAlongPathItemProps {71 children: React.ReactNode72 className?: string73 startOffset?: number // 0-100 percentage74 transition?: any // Override parent transition75}7677// Create context78const ElementAlongPathContext = createContext<{79 path: string80 animationType: "auto" | "scroll"81 direction: "normal" | "reverse" // Add direction to context82 progress: MotionValue<number>83 scrollYProgress: MotionValue<number>84 scrollTransformValues: [number, number]85 transition: any86 setHovered: (isHovered: boolean) => void87} | null>(null)8889// Context hook90export const useElementAlongPathContext = () => {91 const context = useContext(ElementAlongPathContext)92 if (!context) {93 throw new Error("ElementAlongPathItem must be used within ElementAlongPath")94 }95 return context96}9798// Item component99export const ElementAlongPathItem = ({100 children,101 className,102 startOffset = 0,103 transition: itemTransition,104}: ElementAlongPathItemProps) => {105 const {106 path,107 animationType,108 progress,109 scrollYProgress,110 scrollTransformValues,111 direction,112 transition: parentTransition,113 setHovered,114// … 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 |
