arrows-right-left

An animated arrows-right-left icon for React that renders a pair of opposing arrows inside an SVG and nudges each arrow horizontally on hover or when triggered imperatively. It is built with motion/react and exposes a ref handle for programmatic start and stop of the animation.

arrows-right-left
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 @heroicons-animated/arrows-right-left

Requires @heroicons-animated in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { ArrowsRightLeftIcon } from "@/components/ui/arrows-right-left";export default function Example() {  return <ArrowsRightLeftIcon />;}
  • Showing a swap, exchange, transfer, or bidirectional sync action in a toolbar, button, or menu item
  • Adding subtle hover feedback to a navigation or settings link that represents switching between two states
  • Indicating a two-way data flow or reordering control in dashboards and settings panels
  • Triggering the icon animation programmatically via a ref when a related async action starts or finishes

Examples

Hover-triggered swap button

Uses the icon inside a button so the animation plays when the pointer enters the wrapper div.

hover-triggered-swap-button.tsx
import { ArrowsRightLeftIcon } from "@/components/ui/arrows-right-left";export default function SwapButton() {  return (    <button type="button" className="inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm">      <ArrowsRightLeftIcon size={18} />      Swap currencies    </button>  );}

Programmatic control via ref

Starts and stops the animation imperatively, for example while a request is in flight.

programmatic-control-via-ref.tsx
import { useRef, useEffect } from "react";import { ArrowsRightLeftIcon, type ArrowsRightLeftIconHandle } from "@/components/ui/arrows-right-left";export default function SyncStatus({ syncing }: { syncing: boolean }) {  const iconRef = useRef<ArrowsRightLeftIconHandle>(null);  useEffect(() => {    if (syncing) {      iconRef.current?.startAnimation();    } else {      iconRef.current?.stopAnimation();    }  }, [syncing]);  return <ArrowsRightLeftIcon ref={iconRef} size={24} className="text-blue-600" />;}

Menu item with larger icon

Places the icon in a menu row with a custom size and color via className.

menu-item-with-larger-icon.tsx
import { ArrowsRightLeftIcon } from "@/components/ui/arrows-right-left";export default function TransferMenuItem() {  return (    <div role="menuitem" tabIndex={0} className="flex items-center gap-3 p-2 hover:bg-accent">      <ArrowsRightLeftIcon size={20} className="text-muted-foreground" />      <span>Transfer ownership</span>    </div>  );}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the svg width and height attributes.
classNamestring—Class name applied to the outer wrapper div, passed through cn().
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Optional handler called after the animation starts on mouse enter. Invoked regardless of ref control.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Optional handler. When the icon is controlled via ref it is called directly; otherwise the animation resets to normal and this handler is called only in the controlled case.
refReact.Ref<ArrowsRightLeftIconHandle>—Forwarded ref exposing startAnimation() and stopAnimation(). Using the ref disables automatic hover animation for this instance.
...HTMLAttributes<HTMLDivElement>HTMLAttributes<HTMLDivElement>—All other standard div attributes are spread onto the outer wrapper div, such as id, style, aria-label, and event handlers.

Accessibility

  • The component renders a decorative SVG with no title or role, so add aria-label or visually hidden text on the wrapper when the icon is the only content of a control.
  • Pass aria-hidden="true" to the icon when a visible text label already describes the action.
  • Because the animation is a short 0.5 second translation, it does not rely on color alone; consider respecting prefers-reduced-motion by calling stopAnimation or not triggering startAnimation for users who opt out.
  • The outer wrapper is a non-focusable div, so make sure the parent interactive element (button or link) provides keyboard focus and an accessible name.

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 "arrows-right-left" component (heroicons-animated/arrows-right-left) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/arrows-right-left2. 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, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ArrowsRightLeftIcon } from "@/components/ui/arrows-right-left";export default function Example() {  return <ArrowsRightLeftIcon />;}```

Files & dependencies

  • arrows-right-left.tsx
dependenciesmotion

Looks similar, elsewhere