|
1 | | -import { Modal as AntdModal } from 'antd'; |
2 | | -import { ModalStaticFunctions } from 'antd/lib/modal/confirm'; |
| 1 | +import React from 'react'; |
| 2 | +import { CheckFilled, CloseFilled, InformationFilled, WarningFilled } from '@dtinsight/react-icons'; |
| 3 | +import { Modal as AntdModal, ModalFuncProps } from 'antd'; |
| 4 | +import { ModalFunc, ModalStaticFunctions } from 'antd/lib/modal/confirm'; |
3 | 5 |
|
4 | 6 | import InternalModal from './modal'; |
5 | 7 |
|
| 8 | +const OK_TEXT = '确认'; |
| 9 | + |
6 | 10 | type ModalType = typeof InternalModal & |
7 | 11 | ModalStaticFunctions & { |
8 | 12 | useModal: typeof AntdModal.useModal; |
9 | 13 | destroyAll: () => void; |
10 | 14 | config: typeof AntdModal.config; |
| 15 | + delete: (props: ModalFuncProps) => void; |
11 | 16 | }; |
12 | 17 |
|
13 | 18 | const { useModal, info, success, error, warning, confirm, destroyAll, config } = AntdModal; |
14 | 19 |
|
15 | | -const Modal = InternalModal as ModalType; |
| 20 | +const customProps: Record< |
| 21 | + | keyof Pick<ModalStaticFunctions, 'info' | 'success' | 'error' | 'warning' | 'confirm'> |
| 22 | + | 'delete', |
| 23 | + ModalFuncProps |
| 24 | +> = { |
| 25 | + info: { icon: <InformationFilled color="#1D78FF" />, okText: OK_TEXT }, |
| 26 | + success: { icon: <CheckFilled color="#11D7B2" />, okText: OK_TEXT }, |
| 27 | + error: { |
| 28 | + icon: <CloseFilled color="#F96C5B" />, |
| 29 | + okText: OK_TEXT, |
| 30 | + okButtonProps: { danger: true }, |
| 31 | + }, |
| 32 | + warning: { icon: <WarningFilled color="#FBB310" />, okText: OK_TEXT }, |
| 33 | + confirm: { icon: <WarningFilled color="#FBB310" />, okText: OK_TEXT, cancelText: '取消' }, |
| 34 | + delete: { |
| 35 | + icon: <CloseFilled color="#F96C5B" />, |
| 36 | + okButtonProps: { danger: true }, |
| 37 | + okText: OK_TEXT, |
| 38 | + cancelText: '暂不', |
| 39 | + }, |
| 40 | +}; |
| 41 | + |
| 42 | +function withCustomIcon(fn: ModalFunc, type: keyof typeof customProps) { |
| 43 | + return (props: ModalFuncProps) => |
| 44 | + fn({ ...customProps[type], wrapClassName: 'dtc-modal', ...props }); |
| 45 | +} |
| 46 | + |
| 47 | +const Modal = InternalModal as unknown as ModalType; |
16 | 48 |
|
17 | 49 | Object.assign(Modal, { |
| 50 | + InternalModal, |
18 | 51 | useModal, |
19 | | - info, |
20 | | - success, |
21 | | - error, |
22 | | - warning, |
23 | | - confirm, |
| 52 | + info: withCustomIcon(info, 'info'), |
| 53 | + success: withCustomIcon(success, 'success'), |
| 54 | + error: withCustomIcon(error, 'error'), |
| 55 | + warning: withCustomIcon(warning, 'warning'), |
| 56 | + confirm: withCustomIcon(confirm, 'confirm'), |
| 57 | + delete: withCustomIcon(confirm, 'delete'), |
24 | 58 | destroyAll, |
25 | 59 | config, |
26 | 60 | }); |
|
0 commit comments