calendar

An animated calendar icon for React built on motion/react. On hover it gently scales and lifts the calendar outline, and it can also be controlled imperatively through a ref.

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

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

Usage

usage.tsx
import { CalendarIcon } from '@/components/ui/calendar'<CalendarIcon size={28} className='text-foreground' />
  • Adding a scheduling, date, or booking affordance to buttons, menu items, or navigation links that should react to hover.
  • Showing a date-picker or events entry point where a subtle, lightweight motion cue helps the user recognize the action.
  • Driving the animation from parent state (for example, playing it when a new event is created) by using the ref handle.
  • Replacing a static calendar glyph in a design system that already uses motion/react and wants consistent Heroicons-style outlines.

Examples

Hover-animated icon in a button

The icon animates on hover automatically. Hover events bubble to the wrapper div, so the animation is driven without any extra code.

hover-animated-icon-in-a-button.tsx
import { CalendarIcon } from '@/components/ui/calendar'export function ScheduleButton() {  return (    <button className='inline-flex items-center gap-2 rounded-md border px-3 py-2 text-sm'>      <CalendarIcon size={20} />      Schedule a call    </button>  )}

Programmatic control through the ref

Passing a ref switches the component to controlled mode, so hover no longer triggers the animation and startAnimation and stopAnimation are used instead.

programmatic-control-through-the-ref.tsx
import { useRef } from 'react'import { CalendarIcon, type CalendarIconHandle } from '@/components/ui/calendar'export function EventCreated() {  const iconRef = useRef<CalendarIconHandle>(null)  return (    <div onMouseEnter={() => iconRef.current?.startAnimation()} onMouseLeave={() => iconRef.current?.stopAnimation()}>      <CalendarIcon ref={iconRef} size={32} />    </div>  )}

Larger icon in a navigation item with an accessible label

Sets a larger size and passes aria-label through the wrapper div, since the SVG itself has no text alternative.

larger-icon-in-a-navigation-item-with-an-accessible-label.tsx
import { CalendarIcon } from '@/components/ui/calendar'export function NavCalendarLink() {  return (    <a href='/calendar' className='flex items-center gap-3 text-zinc-800 hover:text-zinc-950'>      <CalendarIcon size={24} aria-label='Calendar' role='img' />      <span>Calendar</span>    </a>  )}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. It is applied to both the width and height attributes, and the viewBox stays 0 0 24 24.
refReact.Ref<CalendarIconHandle>—Forwarded ref exposing startAnimation() and stopAnimation(). Attaching a ref switches the component to controlled mode, where hover calls the user's onMouseEnter and onMouseLeave handlers instead of playing the animation.
classNamestring—Class name applied to the outer wrapper div (passed through cn). Use it for color, spacing, and layout.
onMouseEnter(event: React.MouseEvent<HTMLDivElement>) => void—Mouse enter handler on the wrapper div. Called in addition to the built-in animation when uncontrolled, and used instead of it when controlled through the ref.
onMouseLeave(event: React.MouseEvent<HTMLDivElement>) => void—Mouse leave handler on the wrapper div. Behaves the same way as onMouseEnter for the reverse animation.
...HTMLAttributes<HTMLDivElement>React.HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, role, data-*, and so on) are spread onto the wrapper div. The SVG accepts no extra props.

Accessibility

  • The SVG has no built-in text alternative. When the icon conveys meaning, pass aria-label and role="img" to the component so they land on the wrapper div.
  • When the icon is decorative beside visible text, leave it unlabeled and rely on the adjacent text, or hide it from assistive technology with aria-hidden="true".
  • Hover-only animation is not announced to screen readers. Do not rely on the motion to convey state or information.
  • Respect reduced motion preferences. Wrap the component in a condition that skips animation when prefers-reduced-motion is set, or call stopAnimation() from your own logic.
  • Color contrast depends on the parent. Since stroke is currentColor, set a text color that meets WCAG contrast against the background.

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 "calendar" component (heroicons-animated/calendar) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/calendar2. 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, ref, className, onMouseEnter, onMouseLeave, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CalendarIcon } from '@/components/ui/calendar'<CalendarIcon size={28} className='text-foreground' />```

Files & dependencies

  • calendar.tsx
dependenciesmotion

Looks similar, elsewhere