mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +00:00
feat: add onBackdropClick and position prop
This commit is contained in:
@@ -53,15 +53,25 @@ interface ModalProps {
|
|||||||
ref: RefObject<HTMLDialogElement | null>;
|
ref: RefObject<HTMLDialogElement | null>;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
closeOnBackdrop?: boolean;
|
closeOnBackdrop?: boolean;
|
||||||
|
onBackdropClick?: () => void;
|
||||||
|
position?: 'top' | 'middle' | 'bottom' | 'start' | 'end';
|
||||||
className?: {
|
className?: {
|
||||||
modal?: string;
|
modal?: string;
|
||||||
modalBox?: string;
|
modalBox?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Modal = ({ ref, children, closeOnBackdrop, className }: ModalProps) => {
|
const Modal = ({
|
||||||
|
ref,
|
||||||
|
children,
|
||||||
|
closeOnBackdrop,
|
||||||
|
onBackdropClick,
|
||||||
|
position = 'middle',
|
||||||
|
className,
|
||||||
|
}: ModalProps) => {
|
||||||
const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
||||||
if (closeOnBackdrop && e.target === ref.current) {
|
if (closeOnBackdrop && e.target === ref.current) {
|
||||||
|
onBackdropClick?.();
|
||||||
ref.current?.close();
|
ref.current?.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -69,7 +79,17 @@ const Modal = ({ ref, children, closeOnBackdrop, className }: ModalProps) => {
|
|||||||
return (
|
return (
|
||||||
<dialog
|
<dialog
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn('modal', className?.modal)}
|
className={cn(
|
||||||
|
'modal',
|
||||||
|
{
|
||||||
|
'modal-top': position === 'top',
|
||||||
|
'modal-middle': position === 'middle',
|
||||||
|
'modal-bottom': position === 'bottom',
|
||||||
|
'modal-start': position === 'start',
|
||||||
|
'modal-end': position === 'end',
|
||||||
|
},
|
||||||
|
className?.modal
|
||||||
|
)}
|
||||||
onClick={handleBackdropClick}
|
onClick={handleBackdropClick}
|
||||||
>
|
>
|
||||||
<div className={cn('modal-box', className?.modalBox)}>{children}</div>
|
<div className={cn('modal-box', className?.modalBox)}>{children}</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user