# Family Style Modal

Multi-step modal component with smooth animations and stateful workflow using Framer Motion.

Live demo: https://bearerop.in/craft/family-style-modal

## Install

### 1. Install dependencies

```bash
npm install motion lucide-react
```

### 2. Copy and paste the following code into your project.

#### Usage

```tsx
import { FamilyStyleModal } from "@/components/craft/family-style-modal";

export default function MyPage() {
  return (
    <div className="min-h-screen p-8">
      <FamilyStyleModal />
    </div>
  );
}
```

#### Source

```tsx
"use client";

import { useState, useEffect } from "react";
import { X, Check, Loader2 } from "lucide-react";
import { motion, AnimatePresence } from "motion/react";

const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1];

type ModalStep = "initial" | "confirmation" | "processing" | "success";

export function FamilyStyleModal() {
  const [step, setStep] = useState<ModalStep>("initial");
  const [isOpen, setIsOpen] = useState(false);

  useEffect(() => {
    if (step === "processing") {
      const timer = setTimeout(() => setStep("success"), 5000);
      return () => clearTimeout(timer);
    }
  }, [step]);

  const handleReceive = () => { setIsOpen(true); setStep("confirmation"); };
  const handleConfirm = () => setStep("processing");
  const handleCancel = () => { setIsOpen(false); setStep("initial"); };
  const handleClose = () => { setIsOpen(false); setStep("initial"); };

  return (
    <div className="relative flex items-center justify-center min-h-[400px] bg-zinc-100 dark:bg-zinc-900 rounded-3xl p-8 overflow-hidden">
      <div className="text-center space-y-4">
        <AnimatePresence>
          {!isOpen && (
            <motion.button whileHover={{ scale: 1.03 }} whileTap={{ scale: 0.97 }}
              initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }}
              exit={{ opacity: 0, scale: 0.95 }} transition={{ duration: 0.2, ease: EASE_OUT }}
              layoutId="receive-button" onClick={handleReceive}
              className="bg-zinc-900 dark:bg-zinc-100 text-zinc-100 dark:text-zinc-900 rounded-full px-6 py-3 font-semibold cursor-pointer">
              <motion.span layoutId="receive-button-text">Receive</motion.span>
            </motion.button>
          )}
        </AnimatePresence>

        <AnimatePresence>
          {isOpen && (
            <>
              <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }}
                transition={{ duration: 0.2 }} onClick={handleClose}
                className="absolute inset-0 bg-black/50 z-40 backdrop-blur-sm rounded-3xl" />

              <motion.div initial={{ opacity: 0, y: 50, scale: 0.9 }}
                animate={{ opacity: 1, y: 0, scale: 1 }} exit={{ opacity: 0, y: 50, scale: 0.9 }}
                transition={{ type: "spring", duration: 0.4, bounce: 0 }}
                onClick={(e) => e.stopPropagation()}
                className="absolute inset-0 z-50 flex items-center justify-center p-4">
                <div className="bg-white dark:bg-zinc-800 rounded-3xl shadow-2xl max-w-md w-full p-6 md:p-8 relative">
                  {step !== "processing" && (
                    <motion.button initial={{ opacity: 0, scale: 0.9 }} animate={{ opacity: 1, scale: 1 }}
                      whileHover={{ scale: 1.03 }} whileTap={{ scale: 0.97 }}
                      transition={{ duration: 0.15, ease: "easeOut" }} onClick={handleClose}
                      className="absolute top-4 right-4 text-zinc-500 hover:text-zinc-900 dark:hover:text-zinc-100">
                      <X className="w-5 h-5" />
                    </motion.button>
                  )}

                  <AnimatePresence mode="wait">
                    {step === "confirmation" && (
                      <motion.div key="confirmation" initial={{ opacity: 0, y: 10 }}
                        animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -10 }}
                        transition={{ duration: 0.2, ease: EASE_OUT }} className="space-y-6">
                        <div className="text-center">
                          <motion.h3 initial={{ opacity: 0, y: -10 }} animate={{ opacity: 1, y: 0 }}
                            transition={{ delay: 0.1, duration: 0.25, ease: EASE_OUT }}
                            className="text-xl md:text-2xl font-bold text-zinc-900 dark:text-white mb-2">
                            Confirm
                          </motion.h3>
                          <motion.p initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ delay: 0.15, duration: 0.25, ease: EASE_OUT }}
                            className="text-zinc-600 dark:text-zinc-400">
                            Are you sure you want to receive a load of money?
                          </motion.p>
                        </div>
                        <motion.div initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }}
                          transition={{ delay: 0.2, duration: 0.25, ease: EASE_OUT }} className="flex gap-3">
                          <motion.button whileHover={{ scale: 1.02 }} whileTap={{ scale: 0.97 }}
                            onClick={handleCancel}
                            className="flex-1 px-6 py-3 rounded-full border-2 border-zinc-300 dark:border-zinc-600 text-zinc-900 dark:text-white font-semibold">
                            Cancel
                          </motion.button>
                          <motion.button layoutId="receive-button" whileHover={{ scale: 1.03 }}
                            whileTap={{ scale: 0.97 }} onClick={handleConfirm}
                            className="flex-1 px-6 py-3 rounded-full bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 font-semibold">
                            Receive
                          </motion.button>
                        </motion.div>
                      </motion.div>
                    )}

                    {step === "processing" && (
                      <motion.div key="processing" initial={{ opacity: 0, scale: 0.9 }}
                        animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.9 }}
                        transition={{ duration: 0.25, ease: EASE_OUT }} className="text-center py-8">
                        <div className="flex flex-col items-center gap-4">
                          <motion.div animate={{ rotate: 360 }}
                            transition={{ duration: 1, repeat: Infinity, ease: "linear" }}>
                            <Loader2 className="w-12 h-12 text-zinc-900 dark:text-zinc-100" />
                          </motion.div>
                          <motion.p initial={{ opacity: 0 }} animate={{ opacity: 1 }}
                            transition={{ delay: 0.2, duration: 0.25, ease: EASE_OUT }}
                            className="text-lg font-semibold text-zinc-900 dark:text-white">
                            Processing...
                          </motion.p>
                        </div>
                      </motion.div>
                    )}

                    {step === "success" && (
                      <motion.div key="success" initial={{ opacity: 0, scale: 0.9 }}
                        animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.9 }}
                        transition={{ type: "spring", duration: 0.4, bounce: 0 }}
                        className="text-center py-8">
                        <div className="flex flex-col items-center gap-4">
                          <motion.div initial={{ opacity: 0, scale: 0.9 }} animate={{ opacity: 1, scale: 1 }}
                            transition={{ type: "spring", duration: 0.4, bounce: 0.2, delay: 0.1 }}
                            className="w-16 h-16 rounded-full bg-green-500 flex items-center justify-center">
                            <motion.div initial={{ opacity: 0, scale: 0.9, rotate: -90 }} animate={{ opacity: 1, scale: 1, rotate: 0 }}
                              transition={{ delay: 0.3, type: "spring", duration: 0.4, bounce: 0.2 }}>
                              <Check className="w-8 h-8 text-white" />
                            </motion.div>
                          </motion.div>
                          <motion.p initial={{ opacity: 0, y: 10 }} animate={{ opacity: 1, y: 0 }}
                            transition={{ delay: 0.4, duration: 0.25, ease: EASE_OUT }}
                            className="text-xl font-bold text-zinc-900 dark:text-white">
                            Amount Credited
                          </motion.p>
                          <motion.button initial={{ opacity: 0, y: 10 }}
                            animate={{ opacity: 1, y: 0, transition: { delay: 0.5, duration: 0.25, ease: EASE_OUT } }}
                            transition={{ duration: 0.15, ease: "easeOut" }} whileHover={{ scale: 1.03 }}
                            whileTap={{ scale: 0.97 }} onClick={handleClose}
                            className="mt-4 px-6 py-2 rounded-full bg-zinc-900 dark:bg-zinc-100 text-white dark:text-zinc-900 font-semibold">
                            Done
                          </motion.button>
                        </div>
                      </motion.div>
                    )}
                  </AnimatePresence>
                </div>
              </motion.div>
            </>
          )}
        </AnimatePresence>
      </div>
    </div>
  );
}
```

## Features

- **Multi-step workflow (4 states)**
- **Layout animations with layoutId**
- **Staggered entrance animations**
- **Spring physics transitions**
- **Dark mode support**
- **Responsive design**
- **Auto-progression (processing to success)**
- **Backdrop blur effect**

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| - | - | - | No props required. Component manages its own state. |

The component is self-contained with internal state management. For customization, you can modify the source code directly.
