joseestevez520

Icon Morph

Buttons

About

An SVG icon whose strokes travel point-by-point into another icon's shape (menu into close, play into pause) instead of cross-fading, for use inside a toggle button.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Icon Morph to your project and fits it to your theme.

Code

How Icon Morph is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import IconMorph from "@/components/ui/icon-morph";

type GlyphName =
  | "menu"
  | "close"
  | "plus"
  | "minus"
  | "check"
  | "play"
  | "pause"
  | "chevronDown"
  | "chevronUp"
  | "arrowRight"
  | "chevronRight"
  | "chevronLeft"
  | "arrowLeft"
  | "arrowUp"
  | "arrowDown";

// Ported from elastic-ui's IconMorph.stories.ts ("Pairs" story).
const pairs: [GlyphName, GlyphName, string][] = [
  ["menu", "close", "Menu"],
  ["play", "pause", "Play"],
  ["plus", "minus", "Add"],
  ["plus", "close", "Add, then close"],
  ["chevronDown", "chevronUp", "Open"],
  ["chevronRight", "chevronDown", "Expand"],
  ["arrowRight", "check", "Send, then done"],
  ["arrowUp", "check", "Upload, then done"],
  ["arrowDown", "check", "Download, then done"],
  ["arrowLeft", "close", "Back, then close"],
];

export default function IconMorphDemo() {
  const [on, setOn] = React.useState<boolean[]>(() => pairs.map(() => false));

  return (
    <div className="grid max-w-xl grid-cols-3 gap-4">
      {pairs.map(([a, b, label], i) => (
        <button
          key={label}
          type="button"
          aria-pressed={on[i]}
          className="flex cursor-pointer flex-col items-center gap-3 rounded-2xl bg-muted px-4 py-6 text-foreground transition-colors hover:text-muted-foreground focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring"
          onClick={() =>
            setOn((prev) => prev.map((v, idx) => (idx === i ? !v : v)))
          }
        >
          <IconMorph icon={on[i] ? b : a} className="size-7" />
          <span className="text-xs text-muted-foreground">{label}</span>
        </button>
      ))}
    </div>
  );
}

More by joseestevez520

View all
  • Progress Button

    Progress Button

    13
  • Chart

    Chart

    5
  • Stat

    Stat

  • Marquee

    Marquee

  • Day Strip

    Day Strip

  • Prose

    Prose

  • File Drop Zone

    File Drop Zone

More in Buttons

View all
  • Button

    Button

    20
  • Button

    Button

    3
  • Button Group

    Button Group

    18
  • Button

    Button

    149
  • Icon Label Subtext Button

    Icon Label Subtext Button

    69
  • Button

    Button

    9
  • Button

    Button

    37
  • Texture Button

    Texture Button

    113