import React, { useEffect, useState } from 'react'; import { cn } from '@/lib/utils'; /** * FormSuccess Component * Display success messages with different variants and auto-dismiss */ export interface FormSuccessProps { message?: string; variant?: 'inline' | 'block' | 'toast'; className?: string; showIcon?: boolean; animate?: boolean; autoDismiss?: boolean; autoDismissTimeout?: number; onClose?: () => void; id?: string; } export const FormSuccess: React.FC = ({ message, variant = 'inline', className, showIcon = true, animate = true, autoDismiss = false, autoDismissTimeout = 5000, onClose, id, }) => { const [isVisible, setIsVisible] = useState(true); useEffect(() => { if (!message) { setIsVisible(false); return; } setIsVisible(true); if (autoDismiss && autoDismissTimeout > 0) { const timer = setTimeout(() => { setIsVisible(false); if (onClose) { onClose(); } }, autoDismissTimeout); return () => clearTimeout(timer); } }, [message, autoDismiss, autoDismissTimeout, onClose]); if (!message || !isVisible) { return null; } const baseClasses = { inline: 'text-sm text-success mt-1', block: 'p-3 bg-success/10 border border-success/20 rounded-md text-success text-sm', toast: 'fixed bottom-4 right-4 p-4 bg-success text-white rounded-lg shadow-lg max-w-md z-tooltip animate-slide-up', }; const animationClasses = animate ? 'animate-fade-in' : ''; const Icon = () => ( ); const handleClose = () => { setIsVisible(false); if (onClose) { onClose(); } }; return (
{showIcon && } {message}
{autoDismiss && ( )}
); }; FormSuccess.displayName = 'FormSuccess'; export default FormSuccess;