Animated icons in Next.js

kubai-icons-react works in the App Router and the Pages Router with no configuration. Icons render as SVG on the server, so they show in the first HTML, and their hover motion is added on hydration.

Install

bash
npm install kubai-icons-react

Use an icon in a Server Component

Import icons by name. A page or layout can stay a Server Component: each icon is its own client module, so only the icons you render reach the browser.

tsx
// app/page.tsx
import { Folder, Bell } from "kubai-icons-react";

export default function Home() {
  return (
    <main>
      <h1><Folder size={32} /> Projects</h1>
      <Bell color="#F59E0B" title="Notifications" />
    </main>
  );
}

Without a title, an icon is hidden from screen readers. Add one when the icon carries meaning on its own, as the bell does here. See Accessibility.

Play the motion when a link is hovered

By default, an icon plays its motion when the icon itself is hovered or focused. In a nav link, it reads better when the whole link starts it. Mark the link with data-kubai-trigger and set trigger="parent" on the icon:

tsx
import Link from "next/link";
import { Settings } from "kubai-icons-react";

export function SettingsLink() {
  return (
    <Link href="/settings" data-kubai-trigger className="flex items-center gap-2">
      <Settings size={18} trigger="parent" />
      Settings
    </Link>
  );
}

Icons chosen at runtime

When the icon name comes from data, such as a CMS or a database, use DynamicIcon. It loads each icon as a separate chunk the first time it is shown. It renders an empty placeholder on the server, so prefer named imports for icons that are always on the page.

tsx
"use client";
import { DynamicIcon } from "kubai-icons-react/dynamic";

export function CategoryIcon({ name }: { name: string }) {
  return <DynamicIcon name={name} size={20} />;
}

Faster dev server

In development, next dev may load the package index, which references every icon. Importing each icon from its own file avoids that and keeps reloads quick:

tsx
import Folder from "kubai-icons-react/icons/folder";

Production builds remove unused icons either way. See Performance.

Color & theme

Icons take their color from currentColor, so they follow the text color of the element around them, including in dark mode. To set a soft look for the whole app, set the variant once on the <body>. See Colors & dark mode.

Questions

Do the icons need "use client"?

No. Each icon module already declares itself a client module, so you can import icons into Server Components directly. Only your own components that use hooks or DynamicIcon need the directive.

Do the icons cause a layout shift?

No. The SVG is in the server HTML at its final size, and the motion only changes shapes inside it.

Does the motion respect reduced motion settings?

Yes. When prefers-reduced-motion is set, an icon moves straight to its end pose without animating.

How much does an icon add to the bundle?

Minified and gzipped, the first icon adds about 4 KB including the shared runtime, and each further icon about 0.6 KB.