A polished React utility for tracing Lucide SVG strokes on hover or focus.
Project: FireXCore
Author: Farbod Akvan
Website: https://firexcore.com
GitHub: https://github.com/FireXCore
Lucide icons are stroke-based SVGs, which makes them ideal for a clean draw-on-hover effect. This project keeps that effect local, accessible, and predictable:
- traces the full SVG geometry, not only
path - supports hover, focus, and icon-only controls
- respects
prefers-reduced-motion - avoids global CSS hacks
- keeps the animation logic reusable and lightweight
npm installUse useHoverTrace when the entire control should trigger the animation.
import { ChevronRight } from "lucide-react"
import { useHoverTrace } from "./hooks/useHoverTrace"
export function RowAction() {
const { triggerProps, iconRef } = useHoverTrace({ durationMs: 780 })
return (
<button type="button" className="row-action" {...triggerProps}>
<ChevronRight ref={iconRef} className="row-action__icon" size={16} strokeWidth={1.8} />
<span>Open request</span>
</button>
)
}Use TraceIcon when the icon itself is the control target.
import { Plus } from "lucide-react"
import { TraceIcon } from "./components/TraceIcon"
export function CreateButton() {
return <TraceIcon icon={Plus} className="text-primary" />
}Renderless hover controller for a Lucide icon.
Options
durationMs: animation duration in milliseconds. Default900staggerMs: delay between SVG elements in milliseconds. Default70easing: CSS timing function. Defaultcubic-bezier(0.2, 0.8, 0.2, 1)resetOnLeave: restore the icon cleanly when hover ends. Defaulttrue
Returns
triggerProps: spread these on the hoverable controliconRef: attach this ref directly to the Lucide iconactive: current traced state
Convenience component for standalone icon buttons.
Props
icon: a Lucide icon componentclassName: icon class namecontainerClassName: wrapper class namesize: icon size in pixelsstrokeWidth: icon stroke widthdurationMs: trace durationstaggerMs: per-element staggerresetOnLeave: clean reset behavioractive: controlled traced statedecorative: setfalseonly when the icon needs its own accessible labeltitle: optional SVG title
The hook traces these SVG geometry elements:
pathlinecirclerectpolylinepolygon
It reads each element’s total length, sets stroke-dasharray, and animates stroke-dashoffset from full length to zero. The result is a clean stroke-drawing effect without relying on global stylesheet overrides.
Run the demo app locally:
npm run devMIT