Moon
An animated moon icon React component that gently wobbles (rotates back and forth) when hovered, built with Motion for React. It renders an SVG crescent moon inside a div wrapper and can also be controlled imperatively via a ref.


Installed with plain
See how it was built shadcn add · no workarounds · theme neutral (none shipped)Installation
pnpm dlx shadcn@latest add https://lucide-animated.com/r/moon.json
Usage
usage.tsx
import { MoonIcon } from "@/components/ui/moon";export default function Example() { return <MoonIcon size={28} className="text-foreground" />;}- Adding a playful night or dark-mode toggle icon that animates on hover
- Decorating navigation, settings, or theme-switch buttons with a subtle motion cue
- Showing a sleep, night, or moon-phase related indicator in a UI that benefits from micro-interactions
- Triggering the wobble programmatically (for example when a theme changes) through the exposed ref handle
Examples
Hover-animated theme toggle button
Wraps the icon inside a button so the wobble plays when the user hovers the control.
hover-animated-theme-toggle-button.tsx
import { MoonIcon } from "@/components/ui/moon";export default function ThemeToggle() { return ( <button type="button" aria-label="Switch to dark mode" className="inline-flex size-9 items-center justify-center rounded-md hover:bg-accent"> <MoonIcon size={20} /> </button> );}Programmatic control via ref
Uses the forwarded ref to start and stop the animation from outside, for example when a parent state changes.
programmatic-control-via-ref.tsx
import { useRef } from "react";import { MoonIcon, type MoonIconHandle } from "@/components/ui/moon";export default function NightModeBadge() { const iconRef = useRef<MoonIconHandle>(null); return ( <div onMouseEnter={() => iconRef.current?.startAnimation()} onMouseLeave={() => iconRef.current?.stopAnimation()} className="flex items-center gap-2" > <MoonIcon ref={iconRef} size={24} /> <span>Night mode</span> </div> );}Larger icon with custom color
Shows the icon at a bigger size with a Tailwind color class applied to the wrapper.
larger-icon-with-custom-color.tsx
import { MoonIcon } from "@/components/ui/moon";export default function Hero() { return <MoonIcon size={48} className="text-indigo-500" />;}API reference
PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes.
classNamestring—Class name applied to the outer wrapper div (HTMLDivElement), typically used for color and spacing via currentColor.
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Mouse enter handler. Called after the component's own handling only when the ref handle is in use (controlled mode); otherwise the built-in hover animation runs.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Mouse leave handler. Called in controlled mode (after the ref handle has been attached); otherwise the built-in animation resets to the normal state.
refReact.Ref<MoonIconHandle>—Forwarded ref exposing startAnimation() and stopAnimation() to play the wobble or return to the resting rotation imperatively.
...propsHTMLAttributes<HTMLDivElement>—All other standard div attributes are spread onto the outer wrapper div, such as id, style, aria-* and data-* attributes.
Accessibility
- The component renders no text or accessible name by itself; when the icon is the only content of a control, add aria-label to the button or link that contains it.
- If the icon is purely decorative next to visible text, pass aria-hidden="true" through props to hide the wrapper from assistive technology.
- The animation is a rotation of roughly 10 degrees and lasts about 1.2 seconds; consider respecting prefers-reduced-motion by disabling the hover trigger in user-level CSS or by not calling startAnimation when the user prefers reduced motion.
- Hover is the only built-in trigger, so keyboard and touch users do not see the animation; ensure the surrounding control conveys its meaning without it.
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 "Moon" component (lucide-animated/moon) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/moon.json2. 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, ...props.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { MoonIcon } from "@/components/ui/moon";export default function Example() { return <MoonIcon size={28} className="text-foreground" />;}```Files & dependencies
- moon.tsx
dependenciesmotion