Chess King

ChessKingIcon is an animated chess king icon built on Motion, drawn as a stroked SVG from the lucide style. On hover it rocks and bobs like a piece being nudged, and it can also be driven imperatively through a ref.

Chess King
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/chess-king.json

Usage

usage.tsx
import { ChessKingIcon } from "@/components/ui/chess-king";export function Example() {  return <ChessKingIcon size={28} className="text-foreground" />;}
  • Adding a playful hover animation to a chess, board game, or strategy-game UI element such as a piece selector or game-mode card.
  • Showing a king or royalty symbol in navigation, menus, or feature lists where a subtle motion adds emphasis.
  • Triggering the king animation programmatically (for example when a checkmate or a turn starts) through the exposed ref handle.
  • Replacing a static chess king icon with an interactive one inside buttons or links while keeping the same size and color behavior as other lucide icons.

Examples

Basic hover animation

Hovering the icon plays the king animation automatically. No ref is needed.

basic-hover-animation.tsx
import { ChessKingIcon } from "@/components/ui/chess-king";export function HoverDemo() {  return (    <div className="flex items-center gap-2 text-zinc-900">      <ChessKingIcon size={32} />      <span>King</span>    </div>  );}

Imperative control via ref

Attaching a ref switches the icon to controlled mode. Hover no longer triggers the animation automatically, so startAnimation and stopAnimation are called from your own handlers.

imperative-control-via-ref.tsx
import { useRef } from "react";import { ChessKingIcon, type ChessKingIconHandle } from "@/components/ui/chess-king";export function ControlledDemo() {  const ref = useRef<ChessKingIconHandle>(null);  return (    <div className="flex items-center gap-3">      <ChessKingIcon ref={ref} size={36} />      <button type="button" onClick={() => ref.current?.startAnimation()}>        Play      </button>      <button type="button" onClick={() => ref.current?.stopAnimation()}>        Reset      </button>    </div>  );}

Inside a styled button

The icon uses currentColor, so it follows the button text color and can be sized with a prop.

inside-a-styled-button.tsx
import { ChessKingIcon } from "@/components/ui/chess-king";export function KingButton() {  return (    <button      type="button"      className="inline-flex items-center gap-2 rounded-md border px-4 py-2 text-sm font-medium hover:bg-zinc-100"    >      <ChessKingIcon size={18} />      Choose King    </button>  );}

API reference

PropTypeDefaultDescription
sizenumber28Width and height of the SVG in pixels. Applied to both the width and height attributes of the svg element.
classNamestring—Class names applied to the outer div wrapper through cn(). Use it for color, margin, and layout (for example text-foreground).
onMouseEnter(event: React.MouseEvent<HTMLDivElement>) => void—Called on mouse enter. When the ref is attached (controlled mode), this handler is called instead of the built-in hover animation. Otherwise it is called in addition to the built-in animation through the internal handler.
onMouseLeave(event: React.MouseEvent<HTMLDivElement>) => void—Called on mouse leave. Behaves like onMouseEnter: in controlled mode it replaces the built-in reset, otherwise it runs alongside the default behavior.
...props (HTMLAttributes<HTMLDivElement>)HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, data-*, onClick, and so on) are spread onto the outer div wrapper. Note that the spread comes after the internal mouse handlers, so an onMouseEnter or onMouseLeave passed in props is handled as described above.
refReact.Ref<ChessKingIconHandle>—Exposes ChessKingIconHandle with startAnimation() (plays the animate variant) and stopAnimation() (returns to the normal variant). Attaching the ref switches the icon to controlled mode.

Accessibility

  • The SVG has no title, desc, or role, so screen readers may announce nothing or only the wrapper contents. When the icon conveys meaning, add role="img" and aria-label (for example aria-label="King") through the div props, or place visible text next to it.
  • If the icon is decorative (next to a visible label), add aria-hidden="true" to the component so assistive technology skips it.
  • The animation is a short, one-time movement of about 1.1 seconds and does not loop. Respect prefers-reduced-motion by disabling or changing the animation in the consuming component if needed.
  • The wrapper is a div with no focus behavior. If the icon acts as a control, put it inside a button or link that provides keyboard focus and a visible focus ring, and keep the hover effect as a visual enhancement only.
  • Because the stroke uses currentColor, make sure the surrounding text color has sufficient contrast against its 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 "Chess King" component (lucide-animated/chess-king) from its shadcn registry.1. Install it with: npx shadcn@latest add https://lucide-animated.com/r/chess-king.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, ...props (HTMLAttributes<HTMLDivElement>), ref.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { ChessKingIcon } from "@/components/ui/chess-king";export function Example() {  return <ChessKingIcon size={28} className="text-foreground" />;}```

Files & dependencies

  • chess-king.tsx
dependenciesmotion

Looks similar, elsewhere