cube

CubeIcon is an animated 3D cube icon built on motion/react that rotates on the Y axis when hovered. It can also be controlled imperatively through a ref with startAnimation and stopAnimation.

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

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

Usage

usage.tsx
import { CubeIcon } from '@/components/ui/cube'export function Example() {  return <CubeIcon size={28} className='text-foreground' />}
  • Show a 3D or product/package/box metaphor in navigation, feature lists, or settings pages with a subtle hover effect.
  • Signal a loading, processing, or 'building' state by starting the rotation programmatically through a ref.
  • Add a playful micro-interaction to cards, buttons, or menu items without a heavy animation library setup beyond motion.
  • Use it where a consistent line icon style is needed alongside other heroicons-animated icons.

Examples

Hover-animated icon in a navigation item

The icon rotates on hover by default. No ref is needed because the component manages its own animation.

hover-animated-icon-in-a-navigation-item.tsx
import { CubeIcon } from '@/components/ui/cube'export function NavItem() {  return (    <a href='/products' className='flex items-center gap-2 text-sm'>      <CubeIcon size={20} className='text-muted-foreground' />      <span>Products</span>    </a>  )}

Imperative control through a ref

Attaching a ref switches the component into controlled mode. Hover no longer animates the icon; instead the parent calls startAnimation and stopAnimation.

imperative-control-through-a-ref.tsx
import { useRef } from 'react'import { CubeIcon, type CubeIconHandle } from '@/components/ui/cube'export function BuildingStatus({ busy }: { busy: boolean }) {  const ref = useRef<CubeIconHandle>(null)  return (    <button      type='button'      onMouseEnter={() => ref.current?.startAnimation()}      onMouseLeave={() => ref.current?.stopAnimation()}      onFocus={() => (busy ? ref.current?.startAnimation() : undefined)}      className='inline-flex items-center gap-2'    >      <CubeIcon ref={ref} size={24} />      <span>{busy ? 'Building...' : 'Build'}</span>    </button>  )}

Feature card with a decorative icon

Uses the default size and passes through standard div attributes such as aria-hidden for purely decorative icons.

feature-card-with-a-decorative-icon.tsx
import { CubeIcon } from '@/components/ui/cube'export function FeatureCard() {  return (    <div className='rounded-xl border p-6'>      <CubeIcon size={36} className='mb-4 text-primary' aria-hidden='true' />      <h3 className='font-semibold'>3D previews</h3>      <p className='text-sm text-muted-foreground'>Inspect your models from every angle.</p>    </div>  )}

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 name applied to the outer wrapper div. Passed through cn(className).
onMouseEnter(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse enter. In uncontrolled mode it is called before the built-in hover animation starts. When a ref is attached (controlled mode), it replaces the built-in animation, so the component no longer animates on hover by itself.
onMouseLeave(e: React.MouseEvent<HTMLDivElement>) => void—Called on mouse leave. Behaves the same way as onMouseEnter: it runs the built-in reset animation in uncontrolled mode and is only forwarded in controlled mode.
refReact.Ref<CubeIconHandle>—Forwarded ref exposing startAnimation() and stopAnimation(). Attaching it enables controlled mode.
...HTMLAttributes<HTMLDivElement>HTMLAttributes<HTMLDivElement>—All other standard div attributes (id, style, aria-*, data-*, event handlers, etc.) are spread onto the outer wrapper div.

Accessibility

  • The SVG has no title, role, or aria-label, so it is treated as decorative by default. Add aria-label or a visible text label on the wrapper when the icon conveys meaning on its own.
  • For decorative use, pass aria-hidden='true' through the wrapper props so screen readers skip it.
  • The animation is hover-based and does not run on keyboard focus. When the icon is important to a control, trigger startAnimation from onFocus through the ref so keyboard users get the same feedback.
  • The motion is a 15-degree swing lasting 0.6s. Respect prefers-reduced-motion by disabling the ref-driven animation in those contexts if the motion could be distracting.
  • Color comes from currentColor, so ensure the surrounding text color has sufficient 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 "cube" component (heroicons-animated/cube) from its shadcn registry.1. Install it with: npx shadcn@latest add @heroicons-animated/cube2. 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, ...HTMLAttributes<HTMLDivElement>.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { CubeIcon } from '@/components/ui/cube'export function Example() {  return <CubeIcon size={28} className='text-foreground' />}```

Files & dependencies

  • cube.tsx
dependenciesmotion

Looks similar, elsewhere