2025-08-03 15:29:57 +03:00
|
|
|
import { useEffect, useRef } from "preact/hooks";
|
|
|
|
|
import { t } from "../../services/i18n";
|
|
|
|
|
import { ComponentChildren } from "preact";
|
|
|
|
|
|
|
|
|
|
interface ModalProps {
|
|
|
|
|
className: string;
|
|
|
|
|
title: string;
|
|
|
|
|
size: "lg" | "sm";
|
|
|
|
|
children: ComponentChildren;
|
|
|
|
|
onShown?: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Modal({ children, className, size, title, onShown }: ModalProps) {
|
|
|
|
|
const modalRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
if (onShown) {
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const modalElement = modalRef.current;
|
|
|
|
|
if (modalElement) {
|
|
|
|
|
modalElement.addEventListener("shown.bs.modal", onShown);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 13:39:23 +03:00
|
|
|
return (
|
2025-08-03 15:29:57 +03:00
|
|
|
<div className={`modal fade mx-auto ${className}`} tabIndex={-1} role="dialog" ref={modalRef}>
|
|
|
|
|
<div className={`modal-dialog modal-${size}`} role="document">
|
2025-08-03 13:39:23 +03:00
|
|
|
<div className="modal-content">
|
2025-08-03 15:29:57 +03:00
|
|
|
<div className="modal-header">
|
|
|
|
|
<h5 className="modal-title">{title}</h5>
|
|
|
|
|
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label={t("modal.close")}></button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="modal-body">
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
2025-08-03 13:39:23 +03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|