Dialog
Dialog.tsx
import React, { useState } from 'react';
import './Dialog.css';
interface DialogProps {
isOpen: boolean;
title: string;
onClose: () => void;
}
const Dialog = (props: DialogProps) => {
const [isOpen, setIsOpen] = useState(props.isOpen);
const handleClose = () => {
setIsOpen(false);
props.onClose();
};
return (
<div className={`dialog-container ${isOpen ? 'open' : ''}`}>
<div className="dialog-overlay" onClick={handleClose}></div>
<div className="dialog">
<div className="dialog-header">
<h2>{props.title}</h2>
<button className="close-button" onClick={handleClose}>
X
</button>
</div>
<div className="dialog-body">{props.children}</div>
</div>
</div>
);
};
export default Dialog;
Dialog.module.css
.dialog-container {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: auto;
}
.dialog-container.open {
display: flex;
justify-content: center;
align-items: center;
}
.dialog-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.dialog {
position: relative;
display: flex;
flex-direction: column;
max-width: 600px;
min-width: 300px;
background-color: white;
border-radius: 4px;
padding: 20px;
}
.dialog-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
}
.dialog-header h2 {
margin: 0;
}
.close-button {
background-color: transparent;
border: none;
cursor: pointer;
font-size: 24px;
font-weight: bold;
padding: 0;
}
.dialog-body {
margin: 0;
overflow: auto;
flex: 1;
}