Pen Tool

PenToolIcon is an animated pen-tool icon built on motion/react and forwardRef. On hover it tilts and bobs the pen while the nib-line draws in and the tip circle is revealed, and it can also be driven imperatively through a ref.

Pen Tool
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 https://lucide-animated.com/r/pen-tool.json

Usage

usage.tsx
import { PenToolIcon } from '@/components/ui/pen-tool';export default function Demo() {  return <PenToolIcon className='text-foreground' size={28} />;}
  • Use as a tool or drawing-related icon in toolbars, sidebars, or menus where a playful hover micro-interaction is wanted.
  • Use for CTA or feature cards that depict design, drawing, vector, or path editing tools.
  • Use when you need an icon that can be started and stopped programmatically (for example, to animate while a task runs) via the ref handle.
  • Avoid in dense, performance-sensitive lists with many simultaneously animating icons, or where motion must be suppressed.

Examples

Basic hover icon

Renders the icon with default size 28. It animates automatically on mouse enter and resets on mouse leave, since no ref is attached.

basic-hover-icon.tsx
import { PenToolIcon } from '@/components/ui/pen-tool';export default function BasicExample() {  return (    <div className='flex items-center gap-2 text-foreground'>      <PenToolIcon />      <span>Draw</span>    </div>  );}

Imperative control via ref

Attaching a ref switches the icon to controlled mode. Hover handlers become passthroughs and the parent starts or stops the animation with startAnimation and stopAnimation.

imperative-control-via-ref.tsx
'use client';import { useRef } from 'react';import { PenToolIcon, type PenToolIconHandle } from '@/components/ui/pen-tool';export default function ControlledExample() {  const iconRef = useRef<PenToolIconHandle>(null);  return (    <div      onMouseEnter={() => iconRef.current?.startAnimation()}      onMouseLeave={() => iconRef.current?.stopAnimation()}      className='inline-flex cursor-pointer items-center gap-2'    >      <PenToolIcon ref={iconRef} size={32} />      <span>Hover target</span>    </div>  );}

Icon inside a button

Uses the icon as a decorative leading icon in a button, with the accessible label on the button itself.

icon-inside-a-button.tsx
import { PenToolIcon } from '@/components/ui/pen-tool';export default function ButtonExample() {  return (    <button type='button' aria-label='Create new path' className='inline-flex items-center gap-2 rounded-md border px-3 py-2'>      <PenToolIcon size={20} aria-hidden='true' />      New path    </button>  );}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the rendered SVG in pixels. Applied to both the svg width and height attributes.
classNamestring—Class name applied to the outer wrapper div (passed through cn). Use it to set color via currentColor, spacing, or layout.
refReact.Ref<PenToolIconHandle>—Forwarded ref exposing PenToolIconHandle. Calling it switches the icon to controlled mode, where hover no longer auto-animates.
startAnimation() => void—Method on PenToolIconHandle. Starts the 'animate' variant sequence on the icon.
stopAnimation() => void—Method on PenToolIconHandle. Returns the icon to the 'normal' variant, ending the animation.
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Optional mouse-enter handler from HTMLAttributes. In uncontrolled mode the icon animates and it is not called by the icon; in controlled mode it is invoked instead of animating.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Optional mouse-leave handler from HTMLAttributes. In uncontrolled mode the icon resets; in controlled mode it is invoked instead of resetting.
...HTMLAttributes<HTMLDivElement>HTMLAttributes<HTMLDivElement>—Any other div attributes (id, aria-*, role, style, data-*, etc.) are spread onto the outer wrapper div.

Accessibility

  • The SVG has no title, desc, or role, so it is treated as decorative. Provide meaning through adjacent visible text, or pass aria-label and role='img' to the wrapper via props when the icon is informational.
  • Set aria-hidden='true' when the icon sits next to a visible text label to avoid redundant announcements.
  • Animation is triggered by mouse hover only. Keyboard and touch users get no hover state, so do not rely on the animation to convey information; use the ref handle to trigger it from focus or state changes if needed.
  • The component does not check prefers-reduced-motion. Consider disabling startAnimation/hover triggers or wrapping usage with a media query check when reduced motion is requested.
  • The wrapper div is not focusable. If the icon is interactive, place it inside a native button or link that carries the accessible name.

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 "Pen Tool" component (lucide-animated/pen-tool) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/pen-tool.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, ref, startAnimation, stopAnimation, onMouseEnter, onMouseLeave, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { PenToolIcon } from '@/components/ui/pen-tool';export default function Demo() {  return <PenToolIcon className='text-foreground' size={28} />;}```

Files & dependencies

  • pen-tool.tsx
dependenciesmotion

Looks similar, elsewhere