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.
shadcn add · no workarounds · theme neutral (none shipped)Installation
Requires @heroicons-animated in the registries of your components.json (shadcn adds official directory namespaces automatically).
Usage
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.
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.
"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.
"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
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.
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