Skip to content

Commit d41311d

Browse files
committed
feat(modal): change Modal.method to use dtinsightIcon and add Modal.delete
1 parent f687f07 commit d41311d

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export { default as Image } from './image';
2525
export { default as Input } from './input';
2626
export { default as KeyEventListener } from './keyEventListener';
2727
export { default as MarkdownRender } from './markdownRender';
28-
export { default as Modal } from './modal/modal';
28+
export { default as Modal } from './modal';
2929
export { default as NotFound } from './notFound';
3030
export { default as ProgressBar } from './progressBar';
3131
export { default as ProgressLine } from './progressLine';

src/modal/demos/method.tsx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React from 'react';
2+
import { Button, Space } from 'antd';
3+
import { Modal } from 'dt-react-component';
4+
5+
const info = () => {
6+
Modal.info({
7+
title: 'This is a notification message',
8+
content: (
9+
<div>
10+
<p>some messages...some messages...</p>
11+
<p>some messages...some messages...</p>
12+
</div>
13+
),
14+
onOk() {},
15+
});
16+
};
17+
18+
const success = () => {
19+
Modal.success({
20+
title: 'This is an success message',
21+
content: 'some messages...some messages...',
22+
});
23+
};
24+
25+
const error = () => {
26+
Modal.error({
27+
title: 'This is an error message',
28+
content: 'some messages...some messages...',
29+
});
30+
};
31+
32+
const warning = () => {
33+
Modal.warning({
34+
title: 'This is a warning message',
35+
content: 'some messages...some messages...',
36+
});
37+
};
38+
39+
const confirm = () => {
40+
Modal.confirm({
41+
title: 'This is a confirm message',
42+
content: 'some messages...some messages...',
43+
});
44+
};
45+
46+
const handleDelete = () => {
47+
Modal.delete({
48+
title: 'This is a delete message',
49+
content: 'some messages...some messages...',
50+
});
51+
};
52+
53+
const Method: React.FC = () => (
54+
<Space wrap>
55+
<Button onClick={info}>Info</Button>
56+
<Button onClick={success}>Success</Button>
57+
<Button onClick={error}>Error</Button>
58+
<Button onClick={warning}>Warning</Button>
59+
<Button onClick={confirm}>Confirm</Button>
60+
<Button onClick={handleDelete}>Delete</Button>
61+
</Space>
62+
);
63+
64+
export default Method;

src/modal/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ toc: content
2222
<code src="./demos/draggable.tsx" title="draggable"></code>
2323
<code src="./demos/resizable.tsx" title="resizable"></code>
2424
<code src="./demos/window.tsx" title="窗口模式即支持 draggable 同时也支持 resizable"></code>
25+
<code src="./demos/method.tsx" title="重写 Modal.method 的 icon"></code>
2526

2627
## API
2728

@@ -36,3 +37,11 @@ toc: content
3637
| onPositionChange | 位置变化时的回调 | `(data: { x: number; y: number}) => void` | |
3738
| onRectChange | 尺寸变化时的回调 | `(data: { width: number; height: number }) => void` | |
3839
| ...rest | 其他继承自 antd Modal 的属性 | [ModalProps](https://4x.ant.design/components/modal-cn/#API) | |
40+
41+
## Modal.method
42+
43+
新增: Modal.delete
44+
45+
:::info
46+
其余和 antd4.x 的 [Modal.method](<https://4x.ant.design/components/modal-cn/#Modal.method()>) 一致
47+
:::

src/modal/index.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,21 @@ $modal-max-height: 80vh;
4040
flex: 0 1 auto;
4141
}
4242
}
43+
.ant-modal-confirm-body {
44+
.dtstack-icon {
45+
float: left;
46+
margin-right: 8px;
47+
font-size: 20px;
48+
}
49+
.ant-modal-confirm-title {
50+
color: #3D446E;
51+
line-height: 20px;
52+
font-size: 14px;
53+
}
54+
.ant-modal-confirm-content {
55+
margin: 8px 0 16px 30px;
56+
color: #8B8FA8;
57+
line-height: 20px;
58+
}
59+
}
4360
}

src/modal/index.tsx

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,60 @@
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';
35

46
import InternalModal from './modal';
57

8+
const OK_TEXT = '确认';
9+
610
type ModalType = typeof InternalModal &
711
ModalStaticFunctions & {
812
useModal: typeof AntdModal.useModal;
913
destroyAll: () => void;
1014
config: typeof AntdModal.config;
15+
delete: (props: ModalFuncProps) => void;
1116
};
1217

1318
const { useModal, info, success, error, warning, confirm, destroyAll, config } = AntdModal;
1419

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;
1648

1749
Object.assign(Modal, {
50+
InternalModal,
1851
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'),
2458
destroyAll,
2559
config,
2660
});

0 commit comments

Comments
 (0)