|
1 |
| -import React from 'react'; |
2 |
| -import { Alert, type AlertProps, Modal, type ModalProps } from 'antd'; |
3 |
| -import classNames from 'classnames'; |
4 |
| -import { omit } from 'lodash-es'; |
| 1 | +import { Modal as AntdModal } from 'antd'; |
| 2 | +import { ModalStaticFunctions } from 'antd/lib/modal/confirm'; |
5 | 3 |
|
6 |
| -import './index.scss'; |
| 4 | +import InternalModal from './modal'; |
7 | 5 |
|
8 |
| -export interface IModalProps extends ModalProps { |
9 |
| - size?: 'small' | 'default' | 'middle' | 'large'; |
10 |
| - banner?: AlertProps['message'] | Omit<AlertProps, 'banner'>; |
11 |
| -} |
| 6 | +type ModalType = typeof InternalModal & |
| 7 | + ModalStaticFunctions & { |
| 8 | + useModal: typeof AntdModal.useModal; |
| 9 | + destroyAll: () => void; |
| 10 | + config: typeof AntdModal.config; |
| 11 | + }; |
12 | 12 |
|
13 |
| -const getWidthFromSize = (size: IModalProps['size']) => { |
14 |
| - if (size === 'small') return 400; |
15 |
| - if (size === 'middle') return 640; |
16 |
| - if (size === 'large') return 900; |
17 |
| - return 520; |
18 |
| -}; |
| 13 | +const { useModal, info, success, error, warning, confirm, destroyAll, config } = AntdModal; |
19 | 14 |
|
20 |
| -const isValidBanner = (banner: IModalProps['banner']): banner is AlertProps['message'] => { |
21 |
| - if (typeof banner === 'object') return React.isValidElement(banner); |
22 |
| - return true; |
23 |
| -}; |
| 15 | +const Modal = InternalModal as ModalType; |
24 | 16 |
|
25 |
| -export default function InternalModal({ |
26 |
| - bodyStyle, |
27 |
| - banner, |
28 |
| - size = 'default', |
29 |
| - children, |
30 |
| - width, |
31 |
| - className, |
32 |
| - ...rest |
33 |
| -}: IModalProps) { |
34 |
| - const finalWidth = width ?? getWidthFromSize(size); |
| 17 | +Object.assign(Modal, { |
| 18 | + useModal, |
| 19 | + info, |
| 20 | + success, |
| 21 | + error, |
| 22 | + warning, |
| 23 | + confirm, |
| 24 | + destroyAll, |
| 25 | + config, |
| 26 | +}); |
35 | 27 |
|
36 |
| - return ( |
37 |
| - <Modal |
38 |
| - className={classNames('dtc-modal', className)} |
39 |
| - bodyStyle={{ padding: 0, ...bodyStyle }} |
40 |
| - width={finalWidth} |
41 |
| - {...rest} |
42 |
| - > |
43 |
| - {banner && ( |
44 |
| - <Alert |
45 |
| - message={isValidBanner(banner) ? banner : banner.message} |
46 |
| - banner |
47 |
| - {...(isValidBanner(banner) ? {} : omit(banner, 'message'))} |
48 |
| - /> |
49 |
| - )} |
50 |
| - <section className="dtc-modal-body">{children}</section> |
51 |
| - </Modal> |
52 |
| - ); |
53 |
| -} |
| 28 | +export { IModalProps } from './modal'; |
| 29 | + |
| 30 | +export default Modal; |
0 commit comments