key
KeyIcon is an animated key icon for React, built on Motion and Heroicons-style outline paths. It bobs and wiggles once on hover by default, and can also be driven imperatively through a ref.
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 { KeyIcon } from "@/components/ui/key";<KeyIcon className="text-foreground" />- Login, sign-in, password, or access-control UI where a key icon adds meaning and a playful hover cue.
- Feature cards, navigation items, or CTA buttons that need a small attention-grabbing micro-interaction.
- Controlling the animation from parent state (for example, animating while a request is pending) through the ref handle.
- Replacing a static key icon in a shadcn/ui project when you want consistent motion styling.
Examples
Basic hover animation
Renders the icon with default size (28px). It animates automatically when the pointer enters the wrapper element.
import { KeyIcon } from "@/components/ui/key";export default function Demo() { return <KeyIcon className="text-foreground" />;}Imperative control via ref
Once a ref is attached, hover is no longer handled internally. The parent decides when to start and stop the animation.
import { useRef } from "react";import { KeyIcon, type KeyIconHandle } from "@/components/ui/key";export default function Demo() { const ref = useRef<KeyIconHandle>(null); return ( <div onMouseEnter={() => ref.current?.startAnimation()} onMouseLeave={() => ref.current?.stopAnimation()} > <KeyIcon ref={ref} size={32} /> </div> );}Icon inside a button
Places the icon next to a label inside a shadcn/ui Button. The icon animates when the button is hovered.
import { Button } from "@/components/ui/button";import { KeyIcon } from "@/components/ui/key";export default function Demo() { return ( <Button> <KeyIcon size={16} className="mr-2" /> Sign in </Button> );}Custom size and color
Sets a larger size with the size prop and a Tailwind color class for a highlighted feature icon.
import { KeyIcon } from "@/components/ui/key";export default function Demo() { return <KeyIcon size={48} className="text-amber-500" />;}API reference
Accessibility
- The SVG has no title, role, or aria-label, so screen readers may ignore it or announce nothing useful. If the icon conveys meaning, pass role="img" and aria-label="Key" (or similar) through the spread props. If it is decorative next to visible text, pass aria-hidden="true".
- The animation runs only on mouse enter and leave. Keyboard-only users get no visual cue, so do not rely on the animation to convey state; pair it with text or another indicator.
- The component does not check prefers-reduced-motion. To honor the user's setting, wrap the tree in Motion's MotionConfig with reducedMotion="user".
- Motion's hover animation is decorative. Keep the icon's color contrast at WCAG levels by setting className with a sufficient foreground color.
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 "key" component (heroicons-animated/key) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/key2. 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 { KeyIcon } from "@/components/ui/key";<KeyIcon className="text-foreground" />```Files & dependencies
- key.tsx