-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseModal.tsx
More file actions
54 lines (47 loc) · 1.49 KB
/
BaseModal.tsx
File metadata and controls
54 lines (47 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import { Modal, ModalProps } from 'antd';
import { modalSizes } from 'constants/modalSizes';
// Extend ModalProps to include our custom props
interface BaseModalProps extends Omit<ModalProps, 'visible'> {
size?: 'small' | 'medium' | 'large';
visible?: boolean; // Deprecated prop
open?: boolean; // New prop that will replace visible
}
interface BaseModalInterface extends React.FC<BaseModalProps> {
info: typeof Modal.info;
success: typeof Modal.success;
warning: typeof Modal.warning;
error: typeof Modal.error;
}
export const BaseModal: BaseModalInterface = ({
size = 'medium',
visible,
open,
children,
...props
}) => {
const modalSize = Object.entries(modalSizes).find((sz) => sz[0] === size)?.[1];
// If open is provided, use it. Otherwise, fall back to visible.
// This ensures backward compatibility while supporting the new prop.
const isOpen = open !== undefined ? open : visible;
// Show deprecation warning in development mode
if (process.env.NODE_ENV === 'development' && visible !== undefined && open === undefined) {
console.warn(
'[antd: Modal] `visible` will be removed in next major version, please use `open` instead.'
);
}
return (
<Modal
getContainer={false}
width={modalSize}
open={isOpen}
{...props}
>
{children}
</Modal>
);
};
BaseModal.info = Modal.info;
BaseModal.success = Modal.success;
BaseModal.warning = Modal.warning;
BaseModal.error = Modal.error;