mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
3d8cd0b451
* feat: switch visible to open for Modal * test: depcated check * docs: site api update Co-authored-by: 二货机器人 <smith3816@gmail.com>
84 lines
1.9 KiB
Markdown
84 lines
1.9 KiB
Markdown
---
|
|
order: 2
|
|
title:
|
|
zh-CN: 自定义页脚
|
|
en-US: Customized Footer
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
更复杂的例子,自定义了页脚的按钮,点击提交后进入 loading 状态,完成后关闭。
|
|
|
|
不需要默认确定取消按钮时,你可以把 `footer` 设为 `null`。
|
|
|
|
## en-US
|
|
|
|
A more complex example which define a customized footer button bar. The dialog will change to loading state after clicking the submit button, and when the loading is done, the modal dialog will be closed.
|
|
|
|
You could set `footer` to `null` if you don't need default footer buttons.
|
|
|
|
```tsx
|
|
import { Button, Modal } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [loading, setLoading] = useState(false);
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const showModal = () => {
|
|
setOpen(true);
|
|
};
|
|
|
|
const handleOk = () => {
|
|
setLoading(true);
|
|
setTimeout(() => {
|
|
setLoading(false);
|
|
setOpen(false);
|
|
}, 3000);
|
|
};
|
|
|
|
const handleCancel = () => {
|
|
setOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Button type="primary" onClick={showModal}>
|
|
Open Modal with customized footer
|
|
</Button>
|
|
<Modal
|
|
open={open}
|
|
title="Title"
|
|
onOk={handleOk}
|
|
onCancel={handleCancel}
|
|
footer={[
|
|
<Button key="back" onClick={handleCancel}>
|
|
Return
|
|
</Button>,
|
|
<Button key="submit" type="primary" loading={loading} onClick={handleOk}>
|
|
Submit
|
|
</Button>,
|
|
<Button
|
|
key="link"
|
|
href="https://google.com"
|
|
type="primary"
|
|
loading={loading}
|
|
onClick={handleOk}
|
|
>
|
|
Search on Google
|
|
</Button>,
|
|
]}
|
|
>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
</Modal>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|