import React, { HTMLAttributes, useEffect, useMemo, useState } from "react";
import { Colors } from "../colors";
export interface ModalProps extends HTMLAttributes {
title?: string;
onClose?: () => void;
footer?: React.ReactNode;
show?: boolean;
fullWidth?: boolean;
scollable?: boolean;
size?: 'lg' | 'sm' | 'default';
statusColor?: Colors;
}
const Modal = ({
className,
children,
title,
footer,
show,
style,
onClose,
fullWidth,
scollable,
statusColor,
size = 'default',
...props
}: ModalProps) => {
const [Style, setStyle] = useState(style || {});
const [visible, setVisible] = useState();
const classes = useMemo(() => {
return [
'modal',
'modal-blur',
'fade',
className,
].filter(Boolean).join(' ');
}, [className]);
const innerClasses = useMemo(() => {
return [
'modal-dialog',
'modal-dialog-centered',
['lg', 'sm'].includes(size) && `modal-${size}`,
fullWidth && 'modal-full-width',
scollable && 'modal-dialog-scrollable',
].filter(Boolean).join(' ');
}, [fullWidth, screen]);
const otherProps = useMemo>(() => {
const o: HTMLAttributes = {};
if (show) {
o['aria-modal'] = "true";
o['role'] = "dialog";
} else {
o['aria-hidden'] = "true";
}
return o;
}, [show]);
useEffect(() => {
if (show) {
setStyle({ ...Style, display: 'block' });
setTimeout(() => {
setVisible(true)
}, 0.15 * 1000)
} else {
setVisible(false);
setTimeout(() => {
setStyle({ ...Style, display: 'none' })
}, 0.15 * 1000)
}
}, [show]);
return (
{statusColor &&
}
{title &&
{title}
}
{children}
{footer &&
{footer}
}
)
}
export interface AlertModalProps {
title: string;
message: string;
cancelText?: string;
okText?: string;
onConfirm?: (ev: any) => void;
onCancel?: (ev: any) => void;
}
export const AlertModal: React.FC = ({
title,
message,
cancelText,
okText,
onCancel,
onConfirm,
...props
}) => {
const footer = (
)
return (
)
}
export const SuccessModal: React.FC = ({
title,
message,
cancelText,
okText,
onCancel,
onConfirm,
...props
}) => {
const footer = (
)
return (
)
}
export default Modal;