Added Modal animation a updated css

This commit is contained in:
Sadrinho27 2025-10-02 23:21:45 +02:00
parent 6d9118b564
commit 73d1d47cd1
2 changed files with 69 additions and 62 deletions

View File

@ -1,104 +1,101 @@
/* Modal Overlay */ /* Overlay */
.modal-overlay { .modal-overlay {
position: fixed; position: fixed;
top: 0; inset: 0;
left: 0; background-color: rgba(17, 24, 39, 0.55);
right: 0; backdrop-filter: blur(6px);
bottom: 0;
background-color: rgba(0, 0, 0, 0.5);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 1000; z-index: 1000;
padding: 1rem; padding: 1rem;
transition: opacity 0.3s ease;
} }
/* Modal Container */ .fade-in { opacity: 1; }
.fade-out { opacity: 0; }
/* Container */
.modal-container { .modal-container {
background: white; background: #fff;
border-radius: 0.75rem; border-radius: 1rem;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
max-height: 90vh; max-height: 90vh;
overflow: hidden; overflow: hidden;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 100%; width: 100%;
transition: all 0.3s ease;
} }
.modal-sm { .modal-sm { max-width: 28rem; }
max-width: 28rem; .modal-md { max-width: 32rem; }
.modal-lg { max-width: 48rem; }
.modal-xl { max-width: 64rem; }
.slide-in {
transform: translateY(0);
opacity: 1;
} }
.modal-md { .slide-out {
max-width: 32rem; transform: translateY(20px);
opacity: 0;
} }
.modal-lg { /* Header */
max-width: 48rem;
}
.modal-xl {
max-width: 64rem;
}
/* Modal Header */
.modal-header { .modal-header {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 1.5rem; padding: 1.25rem 1.5rem;
background: linear-gradient(90deg, #f9fafb, #f3f4f6);
border-bottom: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb;
background: #f9fafb;
} }
.modal-title { .modal-title {
font-size: 1.25rem; font-size: 1.3rem;
font-weight: 600; font-weight: 600;
color: #111827; color: #111827;
margin: 0; margin: 0;
} }
/* Close Button */
.modal-close-button { .modal-close-button {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 2rem; width: 2.25rem;
height: 2rem; height: 2.25rem;
border: none; border: none;
background: none; background: none;
border-radius: 0.375rem; border-radius: 0.5rem;
color: #6b7280; color: #6b7280;
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
} }
.modal-close-button:hover { .modal-close-button:hover {
background-color: #f3f4f6; background-color: rgba(0, 0, 0, 0.05);
color: #374151; color: #111827;
transform: rotate(90deg);
} }
/* Modal Content */ /* Content */
.modal-content { .modal-content {
flex: 1; flex: 1;
overflow-y: auto; overflow-y: auto;
padding: 0; padding: 1.5rem;
background: #fff;
} }
/* Responsive */ @keyframes fadeInSuccess {
@media (max-width: 640px) { from {
.modal-overlay { opacity: 0;
padding: 0.5rem; transform: scale(0.95);
} }
to {
.modal-container { opacity: 1;
max-height: 95vh; transform: scale(1);
} }
}
.modal-header {
padding: 1rem;
}
.modal-title {
font-size: 1.125rem;
}
}

View File

@ -1,4 +1,4 @@
import React from 'react'; import React, { useEffect, useState } from 'react';
import { X } from 'lucide-react'; import { X } from 'lucide-react';
import './Modal.css'; import './Modal.css';
@ -10,14 +10,26 @@ interface ModalProps {
size?: 'sm' | 'md' | 'lg' | 'xl'; size?: 'sm' | 'md' | 'lg' | 'xl';
} }
const Modal: React.FC<ModalProps> = ({ const Modal: React.FC<ModalProps> = ({
isOpen, isOpen,
onClose, onClose,
title, title,
children, children,
size = 'md' size = 'md'
}) => { }) => {
if (!isOpen) return null; const [isVisible, setIsVisible] = useState(isOpen);
useEffect(() => {
if (isOpen) {
setIsVisible(true);
} else {
// attendre que l'animation de fermeture se joue
const timer = setTimeout(() => setIsVisible(false), 300); // durée en ms = durée CSS
return () => clearTimeout(timer);
}
}, [isOpen]);
if (!isVisible) return null;
const handleBackdropClick = (e: React.MouseEvent) => { const handleBackdropClick = (e: React.MouseEvent) => {
if (e.target === e.currentTarget) { if (e.target === e.currentTarget) {
@ -26,8 +38,8 @@ const Modal: React.FC<ModalProps> = ({
}; };
return ( return (
<div className="modal-overlay" onClick={handleBackdropClick}> <div className={`modal-overlay ${isOpen ? 'fade-in' : 'fade-out'}`} onClick={handleBackdropClick}>
<div className={`modal-container modal-${size}`}> <div className={`modal-container modal-${size} ${isOpen ? 'slide-in' : 'slide-out'}`}>
<div className="modal-header"> <div className="modal-header">
<h2 className="modal-title">{title}</h2> <h2 className="modal-title">{title}</h2>
<button <button
@ -38,9 +50,7 @@ const Modal: React.FC<ModalProps> = ({
<X className="h-5 w-5" /> <X className="h-5 w-5" />
</button> </button>
</div> </div>
<div className="modal-content"> <div className="modal-content">{children}</div>
{children}
</div>
</div> </div>
</div> </div>
); );