Command Palette

Search for a command to run...

Docs
Multi State Morph Button

Multi State Morph Button

Animated button that morphs through different states - idle, loading, success, and error

Component multi-state-morph-button-demo not found in registry.

Installation

Usage

import MultiStateMorphButton from "@/components/ruixen/multi-state-morph-button";
 
export default function App() {
  const handleSubmit = async () => {
    // Simulate API call
    await new Promise((resolve) => setTimeout(resolve, 2000));
    // Throw error to test error state: throw new Error("Failed");
  };
 
  return (
    <MultiStateMorphButton
      label="Submit Form"
      onClick={handleSubmit}
      width={200}
      height={50}
      colors={{
        idle: "#3b82f6",
        loading: "#2563eb",
        success: "#16a34a",
        error: "#dc2626",
      }}
    />
  );
}

Props

PropTypeDefaultDescription
labelstring"Submit"Button text in idle state
onClick() => Promise<void> | void-Click handler function
classNamestring-Additional CSS classes
widthnumber200Button width in pixels
heightnumber50Button height in pixels
colorsStateColorsDefault colorsCustom colors for each state

Features

  • Four States: Idle, loading, success, and error
  • Smooth Morphing: Animated transitions between states
  • Custom Colors: Configurable colors for each state
  • Auto Reset: Returns to idle after success/error
  • Loading Protection: Prevents multiple clicks during loading
  • Icon Animations: Animated icons for success/error states

State Colors

interface StateColors {
  idle?: string; // Default: "#3b82f6"
  loading?: string; // Default: "#2563eb"
  success?: string; // Default: "#16a34a"
  error?: string; // Default: "#dc2626"
}

Button States

  • Idle: Shows label text, ready for interaction
  • Loading: Shows spinning hourglass icon
  • Success: Shows checkmark icon, auto-resets after 2s
  • Error: Shows X icon, auto-resets after 2s