currency-dollar

An animated currency-dollar (dollar sign in a circle) icon for React, built on motion/react. On hover it flips horizontally with a scaleX bounce, and a ref handle lets you start and stop the flip programmatically.

currency-dollar
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/currency-dollar

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

Usage

usage.tsx
import { CurrencyDollarIcon } from "@/components/ui/currency-dollar";export function Price() {  return <CurrencyDollarIcon size={28} className="text-emerald-600" />;}
  • Showing a price, payment, currency or finance concept with a playful hover flip
  • Adding a subtle micro-interaction to CTA buttons, pricing cards or checkout rows
  • Decorating a dashboard tile or nav item that should feel lively without a heavy animation
  • Triggering the coin-flip from parent code (for example on mount or on a successful action) via the ref handle

Examples

Basic hover icon

Hovering the icon plays the flip animation automatically. Size and color are controlled through props and className.

basic-hover-icon.tsx
import { CurrencyDollarIcon } from "@/components/ui/currency-dollar";export function PriceBadge() {  return (    <div className="inline-flex items-center gap-2 text-emerald-600">      <CurrencyDollarIcon size={32} />      <span className="font-semibold text-foreground">1,200 USD</span>    </div>  );}

Programmatic control with a ref

Passing a ref switches the component to controlled mode: hover no longer animates by itself, so the parent starts and stops the flip through the handle.

programmatic-control-with-a-ref.tsx
import { useRef } from "react";import { CurrencyDollarIcon, type CurrencyDollarIconHandle } from "@/components/ui/currency-dollar";export function PayButton() {  const ref = useRef<CurrencyDollarIconHandle>(null);  return (    <button      type="button"      onMouseEnter={() => ref.current?.startAnimation()}      onMouseLeave={() => ref.current?.stopAnimation()}      className="inline-flex items-center gap-2 rounded-md border px-3 py-2"    >      <CurrencyDollarIcon ref={ref} size={20} />      Pay now    </button>  );}

Flip once on mount

Starts the animation when the component mounts and resets it after the 0.6 second duration, which matches the variant's transition length.

flip-once-on-mount.tsx
import { useEffect, useRef } from "react";import { CurrencyDollarIcon, type CurrencyDollarIconHandle } from "@/components/ui/currency-dollar";export function PriceChangedHint() {  const ref = useRef<CurrencyDollarIconHandle>(null);  useEffect(() => {    ref.current?.startAnimation();    const timer = setTimeout(() => ref.current?.stopAnimation(), 600);    return () => clearTimeout(timer);  }, []);  return <CurrencyDollarIcon ref={ref} size={24} className="text-amber-500" />;}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes.
classNamestring—Class names applied to the wrapping div (passed through cn). Use it for color via text-* utilities and for spacing.
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse enter. When a ref is attached (controlled mode), the animation no longer runs automatically and this handler is the only hover hook; the component calls it instead of starting the animation.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse leave. In controlled mode (ref attached) the animation is not reset automatically; this handler is called instead.
...rest (HTMLAttributes<HTMLDivElement>)HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, aria-*, style, data-*, onClick, etc.) are spread onto the wrapping div, not the SVG.
refReact.Ref<CurrencyDollarIconHandle>—Exposes startAnimation() (plays the flip) and stopAnimation() (returns to the normal state). Attaching a ref also switches hover behavior to controlled mode, as described above.

Accessibility

  • The SVG has no title or role, so screen readers may announce nothing or a generic graphic; if the icon conveys meaning, add aria-label or a visible text label on the wrapper.
  • When purely decorative (next to visible text such as 'Pay now'), wrap the icon in an element with aria-hidden="true".
  • The animation is a hover-only flip with no looping, but respect prefers-reduced-motion by avoiding automatic startAnimation() calls for users who request reduced motion.
  • Hover-only animation gives no feedback to keyboard or touch users; do not rely on it to convey state, and pair it with a focus or label change when the icon signals an action.
  • The icon inherits currentColor, so keep its contrast against the background at WCAG 1.4.11 non-text levels (3:1).

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 "currency-dollar" component (heroicons-animated/currency-dollar) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/currency-dollar2. 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, ...rest (HTMLAttributes<HTMLDivElement>), ref.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CurrencyDollarIcon } from "@/components/ui/currency-dollar";export function Price() {  return <CurrencyDollarIcon size={28} className="text-emerald-600" />;}```

Files & dependencies

  • currency-dollar.tsx
dependenciesmotion

Looks similar, elsewhere