Git Compare Arrows

An animated Git compare-arrows icon for shadcn/ui, built on motion/react. Two nodes are connected by routed arrows that draw in on hover, and the animation can also be triggered imperatively through a ref.

Git Compare Arrows
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add https://lucide-animated.com/r/git-compare-arrows.json

Usage

usage.tsx
import { GitCompareArrowsIcon } from '@/components/ui/git-compare-arrows';export function Example() {  return <GitCompareArrowsIcon className='text-foreground' size={28} />;}
  • Showing a diff, comparison, or branch-compare action in developer tools, repository UIs, or code review screens
  • Adding a playful hover micro-interaction to a toolbar, sidebar, or menu item that represents comparing or merging versions
  • Triggering the compare animation programmatically, for example while a comparison is loading, through the exposed ref handle
  • Building a Git-themed landing page or dashboard that needs a lightweight animated icon without an image asset

Examples

Basic hover icon

Renders the icon with a text color class; the animation plays on mouse enter and reverses on mouse leave.

basic-hover-icon.tsx
import { GitCompareArrowsIcon } from '@/components/ui/git-compare-arrows';export default function BasicExample() {  return (    <div className='flex items-center gap-2 text-foreground'>      <GitCompareArrowsIcon size={28} />      <span>Compare branches</span>    </div>  );}

Icon inside a button

Uses the icon as a toolbar action with a larger size and a hover-friendly wrapper.

icon-inside-a-button.tsx
import { GitCompareArrowsIcon } from '@/components/ui/git-compare-arrows';export default function ToolbarButton() {  return (    <button type='button' className='inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm hover:bg-accent'>      <GitCompareArrowsIcon size={20} />      Compare    </button>  );}

Imperative control via ref

Attaches a ref to start or stop the animation programmatically, for example while a diff is being computed. When a ref is attached, hover no longer triggers the animation and instead calls the optional onMouseEnter/onMouseLeave props.

imperative-control-via-ref.tsx
import { useRef } from 'react';import { GitCompareArrowsIcon, type GitCompareArrowsIconHandle } from '@/components/ui/git-compare-arrows';export default function LoadingCompare({ isLoading }: { isLoading: boolean }) {  const iconRef = useRef<GitCompareArrowsIconHandle>(null);  return (    <div      onMouseEnter={() => (isLoading ? iconRef.current?.startAnimation() : null)}      onMouseLeave={() => iconRef.current?.stopAnimation()}    >      <GitCompareArrowsIcon ref={iconRef} size={32} />    </div>  );}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the rendered SVG in pixels. The viewBox stays 0 0 24 24, so the icon scales proportionally.
classNamestring—Additional classes applied to the outer div wrapper (passed through cn). Use it for color via text-* utilities and for layout or spacing.
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Mouse enter handler from HTMLAttributes. When the ref handle is attached (controlled mode), it is called instead of the built-in animate start; otherwise it is called in addition to nothing extra and the built-in animation starts.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Mouse leave handler from HTMLAttributes. In controlled mode (ref attached) it replaces the built-in reset; otherwise the animation returns to its normal state.
refReact.Ref<GitCompareArrowsIconHandle>—Forwarded ref exposing startAnimation() and stopAnimation(). Calling startAnimation plays the draw-in animation; stopAnimation resets the icon to its normal state.
...propsHTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, data-*, onClick, etc.) are spread onto the outer wrapper div, not the svg.

Accessibility

  • The SVG has no title, desc, or role attribute, so it is decorative by default. If the icon conveys meaning on its own, wrap it with an accessible label, for example aria-label on the wrapper or a visually hidden span.
  • When the icon sits next to visible text, add aria-hidden='true' to the component (passed through props onto the wrapper div) to avoid redundant announcements.
  • The animation is purely visual and runs on mouse enter; it has no keyboard trigger. Keyboard users should rely on the surrounding focusable control, and you can call startAnimation from onFocus if the motion is meaningful.
  • Motion is a brief 0.3s transition with short delays. For users who prefer reduced motion, consider disabling the imperative start or wrapping calls with a prefers-reduced-motion check.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Git Compare Arrows" component (lucide-animated/git-compare-arrows) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/git-compare-arrows.json2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: size, className, onMouseEnter, onMouseLeave, ref, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { GitCompareArrowsIcon } from '@/components/ui/git-compare-arrows';export function Example() {  return <GitCompareArrowsIcon className='text-foreground' size={28} />;}```

Files & dependencies

  • git-compare-arrows.tsx
dependenciesmotion

Looks similar, elsewhere