Animated icons in shadcn/ui

shadcn/ui components accept any SVG icon, so Kubai Icons drop in where the default icons go. One detail matters: shadcn/ui styles turn off pointer events on icons inside buttons and menu items, so the control itself has to start the motion.

Install

bash
npm install kubai-icons-react

shadcn/ui components import their own icons from lucide-react. If a file uses both libraries and two names clash, import Kubai's icon with an alias:

tsx
import { Settings as SettingsIcon } from "kubai-icons-react";

Buttons

The shadcn/ui Button includes [&_svg]:pointer-events-none in its classes. Hovering the icon then counts as hovering the button, and the icon itself never receives the hover. Add data-kubai-trigger to the button and trigger="parent" to the icon, so the button starts the motion:

tsx
import { Button } from "@/components/ui/button";
import { Download } from "kubai-icons-react";

export function ExportButton() {
  return (
    <Button variant="outline" data-kubai-trigger>
      <Download trigger="parent" />
      Export
    </Button>
  );
}

The button also sizes icons with [&_svg:not([class*='size-'])]:size-4, so icons show at 16px whatever their size prop. For another size, give the icon a size-* class, such as className="size-5".

Buttons that render a link

When a button renders a link, through asChild in Radix-based projects or the render prop in Base UI-based ones, props you pass to the button are passed on to the element it renders. Put data-kubai-trigger on the button as before:

tsx
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Rocket } from "kubai-icons-react";

// Radix-based projects
<Button asChild data-kubai-trigger>
  <Link href="/deploy"><Rocket trigger="parent" /> Deploy</Link>
</Button>

// Base UI-based projects
<Button nativeButton={false} render={<Link href="/deploy" />} data-kubai-trigger>
  <Rocket trigger="parent" /> Deploy
</Button>

Sidebar

In a sidebar, the whole menu button should start the motion. Mark SidebarMenuButton the same way:

tsx
import { SidebarMenu, SidebarMenuButton, SidebarMenuItem } from "@/components/ui/sidebar";
import { Inbox, Calendar, Settings } from "kubai-icons-react";

const items = [
  { title: "Inbox", url: "/inbox", icon: Inbox },
  { title: "Calendar", url: "/calendar", icon: Calendar },
  { title: "Settings", url: "/settings", icon: Settings },
];

export function NavMain() {
  return (
    <SidebarMenu>
      {items.map((item) => (
        <SidebarMenuItem key={item.title}>
          <SidebarMenuButton asChild data-kubai-trigger>
            <a href={item.url}>
              <item.icon trigger="parent" />
              <span>{item.title}</span>
            </a>
          </SidebarMenuButton>
        </SidebarMenuItem>
      ))}
    </SidebarMenu>
  );
}

Dropdown menus

DropdownMenuItem also turns off pointer events on its icons. Mark each item:

tsx
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { LogOut, User } from "kubai-icons-react";

<DropdownMenuItem data-kubai-trigger>
  <User trigger="parent" /> Profile
</DropdownMenuItem>
<DropdownMenuItem data-kubai-trigger>
  <LogOut trigger="parent" /> Log out
</DropdownMenuItem>

Colors that match your theme

Icons take their color from currentColor, so inside a shadcn/ui button they follow the button's text color in each variant and in dark mode. To give an icon its own color, use a text class or a theme variable:

tsx
<Bell className="text-primary" />
<Trash color="var(--destructive)" />

See Colors & dark mode for the soft variant and page-wide settings.

Questions

Why does the icon in my shadcn/ui Button not animate on hover?

The Button sets pointer-events: none on child SVGs, so the icon never sees the pointer. Add data-kubai-trigger to the Button and trigger="parent" to the icon.

Why is my icon 16px even though I set size={24}?

The Button and menu item styles set size-4 on any SVG without a size-* class, and CSS overrides the size attributes. Add a class such as size-6 to the icon.

Does keyboard navigation play the motion?

When a marked button receives keyboard focus, its icon plays as it does on hover. Focus left behind by a mouse click does not play it.

Do I need to remove lucide-react?

No. Both libraries can be installed together. Use an import alias where names clash.