import React, { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { AlertCircle, Inbox, CheckCircle2, RefreshCw, ArrowRight, UserCheck, Building2, Mail, ShieldCheck, } from "lucide-react"; export type CardState = "loading" | "empty" | "error" | "success"; export interface AccountData { name: string; email: string; company: string; status: "active" | "pending" | "verified"; storageUsedGB: number; } export interface CardWithStatesProps { state?: CardState; data?: AccountData | null; errorMessage?: string; onRetry?: () => void; onCreateNew?: () => void; className?: string; } const springTransition = { type: "spring", stiffness: 350, damping: 25, }; export const CardWithStates: React.FC = ({ state = "success", data, errorMessage = "Failed to load account details. Please check your network connection.", onRetry, onCreateNew, className = "", }) => { return (
{/* State 1: Loading (Skeleton) */} {state === "loading" && (
)} {/* State 2: Error */} {state === "error" && (

Unable to Load Data

{errorMessage}

{onRetry && ( Try Again )}
)} {/* State 3: Empty */} {state === "empty" && (

No Account Found

You haven't set up an account profile yet. Create one now to get started.

{onCreateNew && ( Create Profile )}
)} {/* State 4: Success */} {state === "success" && data && (
{data.name .split(" ") .map((n) => n[0]) .join("")}

{data.name}

{data.email}

{data.status}
Organization {data.company}
Storage Used {data.storageUsedGB} GB / 100 GB
)}
); }; // Demo component to switch between all 4 states export default function CardWithStatesExample() { const [currentState, setCurrentState] = useState("success"); const sampleData: AccountData = { name: "Alex Rivera", email: "alex.rivera@example.com", company: "Acme Cloud Inc.", status: "verified", storageUsedGB: 42.5, }; return (

Card With States Demo

Seamless transitions between Loading, Empty, Error, and Success states.

{/* State Switcher Buttons */}
{(["loading", "empty", "error", "success"] as CardState[]).map((state) => ( ))}
setCurrentState("loading")} onCreateNew={() => alert("Creating new profile...")} />
); }