mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-13 23:59:12 +08:00
451d2f6ee2
* feat(popconfirm): make title bold and add description prop * feat(popconfirm): make title bold and add description prop(update demos) * feat(popconfirm): make title bold and add description prop(the update of demos translation) * feat(popconfirm): make title bold and add description prop(the update of snapshot) * feat(popconfirm): make title bold and add description prop(the update of popconfirm md) * feat(popconfirm): make title bold and add description prop(the update of popconfirm md)2 * feat(popconfirm): make title bold and add description prop(run all test.ts.snaps and update popconfirm)
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
||
import { message, Popconfirm, Switch } from 'antd';
|
||
|
||
const App: React.FC = () => {
|
||
const [open, setOpen] = useState(false);
|
||
const [condition, setCondition] = useState(true);
|
||
|
||
const changeCondition = (checked: boolean) => {
|
||
setCondition(checked);
|
||
};
|
||
|
||
const confirm = () => {
|
||
setOpen(false);
|
||
message.success('Next step.');
|
||
};
|
||
|
||
const cancel = () => {
|
||
setOpen(false);
|
||
message.error('Click on cancel.');
|
||
};
|
||
|
||
const handleOpenChange = (newOpen: boolean) => {
|
||
if (!newOpen) {
|
||
setOpen(newOpen);
|
||
return;
|
||
}
|
||
// Determining condition before show the popconfirm.
|
||
console.log(condition);
|
||
if (condition) {
|
||
confirm(); // next step
|
||
} else {
|
||
setOpen(newOpen);
|
||
}
|
||
};
|
||
|
||
return (
|
||
<div>
|
||
<Popconfirm
|
||
title="Delete the task"
|
||
description="Are you sure to delete this task?"
|
||
open={open}
|
||
onOpenChange={handleOpenChange}
|
||
onConfirm={confirm}
|
||
onCancel={cancel}
|
||
okText="Yes"
|
||
cancelText="No"
|
||
>
|
||
<a href="#">Delete a task</a>
|
||
</Popconfirm>
|
||
<br />
|
||
<br />
|
||
Whether directly execute:
|
||
<Switch defaultChecked onChange={changeCondition} />
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default App;
|