2022-05-10 00:34:02 +02:00
|
|
|
import { Spin, Skeleton, Modal as AntModal } from 'antd';
|
2022-09-07 09:00:28 +02:00
|
|
|
import React, { FC, ReactNode, useState } from 'react';
|
|
|
|
import styles from './Modal.module.scss';
|
2022-05-10 00:34:02 +02:00
|
|
|
|
2022-09-07 09:00:28 +02:00
|
|
|
export type ModalProps = {
|
2022-05-10 00:34:02 +02:00
|
|
|
title: string;
|
|
|
|
url?: string;
|
2022-10-11 02:11:29 +02:00
|
|
|
open: boolean;
|
2022-05-10 00:34:02 +02:00
|
|
|
handleOk?: () => void;
|
|
|
|
handleCancel?: () => void;
|
|
|
|
afterClose?: () => void;
|
|
|
|
children?: ReactNode;
|
2022-05-30 06:52:38 +02:00
|
|
|
height?: string;
|
2022-08-23 03:27:47 +02:00
|
|
|
width?: string;
|
2022-09-07 09:00:28 +02:00
|
|
|
};
|
2022-05-10 00:34:02 +02:00
|
|
|
|
2022-09-07 09:00:28 +02:00
|
|
|
export const Modal: FC<ModalProps> = ({
|
|
|
|
title,
|
|
|
|
url,
|
2022-10-11 02:11:29 +02:00
|
|
|
open,
|
2022-09-07 09:00:28 +02:00
|
|
|
handleOk,
|
|
|
|
handleCancel,
|
|
|
|
afterClose,
|
|
|
|
height,
|
|
|
|
width,
|
|
|
|
children,
|
|
|
|
}) => {
|
2022-05-10 00:34:02 +02:00
|
|
|
const [loading, setLoading] = useState(!!url);
|
|
|
|
|
2022-12-06 04:42:08 +01:00
|
|
|
let defaultHeight = '100%';
|
|
|
|
let defaultWidth = '520px';
|
|
|
|
if (url) {
|
|
|
|
defaultHeight = '70vh';
|
|
|
|
defaultWidth = '900px';
|
|
|
|
}
|
|
|
|
|
2022-12-15 08:54:31 +01:00
|
|
|
const modalContentBodyStyle = {
|
2022-05-10 00:34:02 +02:00
|
|
|
padding: '0px',
|
2022-08-23 03:27:47 +02:00
|
|
|
minHeight: height,
|
2022-12-06 04:42:08 +01:00
|
|
|
height: height ?? defaultHeight,
|
2022-05-10 00:34:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const iframe = url && (
|
|
|
|
<iframe
|
|
|
|
title={title}
|
|
|
|
src={url}
|
|
|
|
width="100%"
|
|
|
|
height="100%"
|
|
|
|
sandbox="allow-same-origin allow-scripts allow-popups allow-forms"
|
|
|
|
frameBorder="0"
|
|
|
|
allowFullScreen
|
2022-12-06 04:42:08 +01:00
|
|
|
style={{ display: 'block' }}
|
2022-09-05 07:52:32 +02:00
|
|
|
// eslint-disable-next-line react/no-unknown-property
|
2022-05-10 00:34:02 +02:00
|
|
|
onLoad={() => setLoading(false)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const iframeDisplayStyle = loading ? 'none' : 'inline';
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AntModal
|
|
|
|
title={title}
|
2022-10-11 02:11:29 +02:00
|
|
|
open={open}
|
2022-05-10 00:34:02 +02:00
|
|
|
onOk={handleOk}
|
|
|
|
onCancel={handleCancel}
|
|
|
|
afterClose={afterClose}
|
2022-12-15 08:54:31 +01:00
|
|
|
bodyStyle={modalContentBodyStyle}
|
2022-12-06 04:42:08 +01:00
|
|
|
width={width ?? defaultWidth}
|
2022-11-23 19:52:39 +01:00
|
|
|
zIndex={999}
|
2022-05-10 00:34:02 +02:00
|
|
|
footer={null}
|
|
|
|
centered
|
|
|
|
destroyOnClose
|
|
|
|
>
|
2022-12-15 08:54:31 +01:00
|
|
|
<div id="modal-container" style={{ height: '100%' }}>
|
2022-05-10 00:34:02 +02:00
|
|
|
{loading && (
|
|
|
|
<Skeleton active={loading} style={{ padding: '10px' }} paragraph={{ rows: 10 }} />
|
|
|
|
)}
|
|
|
|
|
|
|
|
{iframe && <div style={{ display: iframeDisplayStyle }}>{iframe}</div>}
|
2022-09-07 09:00:28 +02:00
|
|
|
{children && <div className={styles.content}>{children}</div>}
|
|
|
|
{loading && <Spin className={styles.spinner} spinning={loading} size="large" />}
|
2022-12-12 06:06:20 +01:00
|
|
|
</div>
|
2022-05-10 00:34:02 +02:00
|
|
|
</AntModal>
|
|
|
|
);
|
2022-09-07 09:00:28 +02:00
|
|
|
};
|
|
|
|
export default Modal;
|
2022-05-10 00:34:02 +02:00
|
|
|
|
|
|
|
Modal.defaultProps = {
|
|
|
|
url: undefined,
|
|
|
|
children: undefined,
|
|
|
|
handleOk: undefined,
|
|
|
|
handleCancel: undefined,
|
|
|
|
afterClose: undefined,
|
|
|
|
};
|