drawer closeWithConfirm props

This commit is contained in:
chenos 2021-05-23 09:20:22 +08:00
parent 8df3da7d49
commit 68f3d86761
2 changed files with 35 additions and 3 deletions

View File

@ -11,7 +11,7 @@ group:
# Drawer - 抽屉
与 Ant Design
通过 `Drawer.open(props)` 方法打开抽屉,无需预渲染,可在任意触发事件中使用,多层抽屉的实现也更为巧妙。
### 基础抽屉
@ -69,3 +69,35 @@ export default () => (
}}>Open drawer</Button>
);
```
### 关闭时提示
```tsx
/**
* title: 关闭时提示
* desc: 更多参数请参考 `Modal.confirm`
*/
import React from 'react';
import { Button } from 'antd';
import Drawer from './index.tsx';
export default () => (
<Button onClick={() => {
Drawer.open({
title: 'Basic Drawer',
content: ({ closeWithConfirm }) => {
closeWithConfirm({
title: '您确定关闭抽屉吗?'
});
return (
<div>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</div>
)
},
});
}}>Open Drawer</Button>
);
```

View File

@ -84,7 +84,7 @@ export function Drawer(title: any, content: any): IDrawer {
},
};
const drawer = {
const drawer: any = {
open: (props: any) => {
render(
false,
@ -113,7 +113,7 @@ export function Drawer(title: any, content: any): IDrawer {
if (!env.root) return;
if (drawer.closeWithConfirm) {
Modal.confirm({
title: '表单内容发生变化,确定不保存吗?',
title: drawer.closeWithConfirm === true ? '表单内容发生变化,确定不保存吗?' : drawer.closeWithConfirm.title,
okText: '确定',
cancelText: '取消',
onOk() {