envelope

An animated envelope (mail) icon for React that wobbles with a short rotate motion on hover, or can be triggered programmatically through a ref. It is built on motion/react and renders an outline SVG inside a wrapping div.

envelope
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/envelope

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

Usage

usage.tsx
import { EnvelopeIcon } from "@/components/ui/envelope";export function Example() {  return <EnvelopeIcon size={28} className="text-foreground" />;}
  • Mail, inbox, newsletter, or contact-us links and buttons where a playful hover cue is wanted
  • Notification or unread-message indicators that should draw attention with a subtle shake
  • Navigation items or CTAs in landing pages and dashboards that need a lightweight animated icon
  • Cases where the animation should be triggered by app state (for example, after a message is sent) through the imperative ref API

Examples

Hover animation (default)

Without a ref, the icon plays the wobble automatically on mouse enter and resets on mouse leave.

hover-animation-(default).tsx
import { EnvelopeIcon } from "@/components/ui/envelope";export function InboxLink() {  return (    <a href="/inbox" className="inline-flex items-center gap-2 text-sm">      <EnvelopeIcon size={20} />      Inbox    </a>  );}

Programmatic control via ref

Attaching a ref switches the icon to controlled mode: hover no longer animates automatically and you call startAnimation and stopAnimation yourself.

programmatic-control-via-ref.tsx
"use client";import { useRef } from "react";import { EnvelopeIcon, type EnvelopeIconHandle } from "@/components/ui/envelope";export function MailStatus() {  const iconRef = useRef<EnvelopeIconHandle>(null);  return (    <div>      <EnvelopeIcon ref={iconRef} size={24} />      <button type="button" onClick={() => iconRef.current?.startAnimation()}>Shake</button>      <button type="button" onClick={() => iconRef.current?.stopAnimation()}>Reset</button>    </div>  );}

Animate on a notification event

Trigger the wobble when new mail arrives by calling startAnimation from an effect.

animate-on-a-notification-event.tsx
"use client";import { useEffect, useRef } from "react";import { EnvelopeIcon, type EnvelopeIconHandle } from "@/components/ui/envelope";export function UnreadBadge({ unreadCount }: { unreadCount: number }) {  const iconRef = useRef<EnvelopeIconHandle>(null);  useEffect(() => {    if (unreadCount > 0) {      iconRef.current?.startAnimation();    }  }, [unreadCount]);  return <EnvelopeIcon ref={iconRef} size={22} className="text-blue-600" />;}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes of the svg element.
classNamestring—Class name applied to the outer wrapping div (passed through cn). Use it to set color via text-* utilities, since the stroke is currentColor.
onMouseEnter(event: React.MouseEvent<HTMLDivElement>) => void—Mouse enter handler from HTMLAttributes. In uncontrolled mode it runs alongside the built-in wobble. Once a ref is attached (controlled mode), the built-in wobble is disabled and this handler is the only one called on enter.
onMouseLeave(event: React.MouseEvent<HTMLDivElement>) => void—Mouse leave handler from HTMLAttributes. In uncontrolled mode it runs alongside the built-in reset. In controlled mode the built-in reset is disabled and only this handler is called on leave.
refReact.Ref<EnvelopeIconHandle>—Forwarded ref exposing startAnimation() to play the wobble and stopAnimation() to return to the normal rest state. Attaching a ref switches the component to controlled mode.
...HTMLAttributes<HTMLDivElement>React.HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, role, tabIndex, data-*, event handlers) are spread onto the outer wrapping div, not the svg.

Accessibility

  • The SVG has no title, desc, or aria-label, so it is decorative by default. When the icon conveys meaning (for example, an unread mail indicator), add aria-label or role="img" with a label on the wrapper, or place visible text next to it.
  • Because the component spreads HTMLAttributes onto the outer div, you can pass aria-label, role, and aria-hidden there. Use aria-hidden="true" when the icon sits next to a visible text label.
  • The wobble is a decorative motion of about 0.5 seconds. Consider honoring prefers-reduced-motion by avoiding automatic startAnimation calls for users who opt out.
  • Interactive usage needs a focusable parent: the component does not respond to keyboard focus, so pair it with a button or link that calls startAnimation on focus if the animation is meaningful.
  • The icon inherits color from currentColor, so ensure sufficient contrast against its background in both light and dark themes.

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 "envelope" component (heroicons-animated/envelope) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/envelope2. 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 { EnvelopeIcon } from "@/components/ui/envelope";export function Example() {  return <EnvelopeIcon size={28} className="text-foreground" />;}```

Files & dependencies

  • envelope.tsx
dependenciesmotion

Looks similar, elsewhere