mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
|
import React from 'react';
|
||
|
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||
|
import { Button, Modal, Space } from 'antd';
|
||
|
|
||
|
const { confirm } = Modal;
|
||
|
|
||
|
const showConfirm = () => {
|
||
|
confirm({
|
||
|
title: 'Do you Want to delete these items?',
|
||
|
icon: <ExclamationCircleFilled />,
|
||
|
content: 'Some descriptions',
|
||
|
onOk() {
|
||
|
console.log('OK');
|
||
|
},
|
||
|
onCancel() {
|
||
|
console.log('Cancel');
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const showPromiseConfirm = () => {
|
||
|
confirm({
|
||
|
title: 'Do you want to delete these items?',
|
||
|
icon: <ExclamationCircleFilled />,
|
||
|
content: 'When clicked the OK button, this dialog will be closed after 1 second',
|
||
|
onOk() {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
|
||
|
}).catch(() => console.log('Oops errors!'));
|
||
|
},
|
||
|
onCancel() {},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const showDeleteConfirm = () => {
|
||
|
confirm({
|
||
|
title: 'Are you sure delete this task?',
|
||
|
icon: <ExclamationCircleFilled />,
|
||
|
content: 'Some descriptions',
|
||
|
okText: 'Yes',
|
||
|
okType: 'danger',
|
||
|
cancelText: 'No',
|
||
|
onOk() {
|
||
|
console.log('OK');
|
||
|
},
|
||
|
onCancel() {
|
||
|
console.log('Cancel');
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const showPropsConfirm = () => {
|
||
|
confirm({
|
||
|
title: 'Are you sure delete this task?',
|
||
|
icon: <ExclamationCircleFilled />,
|
||
|
content: 'Some descriptions',
|
||
|
okText: 'Yes',
|
||
|
okType: 'danger',
|
||
|
okButtonProps: {
|
||
|
disabled: true,
|
||
|
},
|
||
|
cancelText: 'No',
|
||
|
onOk() {
|
||
|
console.log('OK');
|
||
|
},
|
||
|
onCancel() {
|
||
|
console.log('Cancel');
|
||
|
},
|
||
|
});
|
||
|
};
|
||
|
|
||
|
const App: React.FC = () => (
|
||
|
<Space wrap>
|
||
|
<Button onClick={showConfirm}>Confirm</Button>
|
||
|
<Button onClick={showPromiseConfirm}>With promise</Button>
|
||
|
<Button onClick={showDeleteConfirm} type="dashed">
|
||
|
Delete
|
||
|
</Button>
|
||
|
<Button onClick={showPropsConfirm} type="dashed">
|
||
|
With extra props
|
||
|
</Button>
|
||
|
</Space>
|
||
|
);
|
||
|
|
||
|
export default App;
|