'use client'; import React, {ReactNode, useEffect, useState} from 'react'; import {createPortal} from 'react-dom'; import {LucideIcon, X} from "lucide-react"; import Button from "@/components/ui/Button"; import IconButton from "@/components/ui/IconButton"; type ModalSize = 'sm' | 'md' | 'lg'; interface ModalProps { title: string; icon?: LucideIcon; children: ReactNode; size?: ModalSize; onClose: () => void; onConfirm?: () => void; confirmText?: string; cancelText?: string; footer?: ReactNode; actions?: ReactNode; enableOverflow?: boolean; } const sizeClasses: Record = { sm: 'md:w-3/4 xl:w-1/4 lg:w-2/4 sm:w-11/12', md: 'md:w-3/4 xl:w-2/5 lg:w-2/4 sm:w-11/12', lg: 'md:w-3/4 xl:w-3/5 lg:w-3/4 sm:w-11/12', }; export default function Modal( { title, icon: Icon, children, size = 'md', onClose, onConfirm, confirmText = 'Confirmer', cancelText = 'Annuler', footer, actions, enableOverflow = true, }: ModalProps) { const [mounted, setMounted] = useState(false); useEffect((): (() => void) => { setMounted(true); document.body.style.overflow = 'hidden'; return (): void => { setMounted(false); document.body.style.overflow = 'auto'; }; }, []); const hasFooter: boolean = !!footer || !!onConfirm; const modalContent: React.JSX.Element = (

{Icon && } {title}

{actions}
{children}
{hasFooter && (
{footer ? footer : ( <> )}
)}
); if (!mounted) return null; return createPortal(modalContent, document.body); }