mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 09:49:57 +08:00
771c7a6f2d
* feat: change visible to open for Modal * feat: add warning when use visible * test: fix lint Co-authored-by: 二货机器人 <smith3816@gmail.com>
62 lines
1.4 KiB
Markdown
62 lines
1.4 KiB
Markdown
---
|
|
order: 7
|
|
title:
|
|
zh-CN: 自定义位置
|
|
en-US: To customize the position of modal
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
使用 `centered` 或类似 `style.top` 的样式来设置对话框位置。
|
|
|
|
## en-US
|
|
|
|
You can use `centered`,`style.top` or other styles to set position of modal dialog.
|
|
|
|
```tsx
|
|
import { Button, Modal } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [modal1Open, setModal1Open] = useState(false);
|
|
const [modal2Open, setModal2Open] = useState(false);
|
|
|
|
return (
|
|
<>
|
|
<Button type="primary" onClick={() => setModal1Open(true)}>
|
|
Display a modal dialog at 20px to Top
|
|
</Button>
|
|
<Modal
|
|
title="20px to Top"
|
|
style={{ top: 20 }}
|
|
open={modal1Open}
|
|
onOk={() => setModal1Open(false)}
|
|
onCancel={() => setModal1Open(false)}
|
|
>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
</Modal>
|
|
<br />
|
|
<br />
|
|
<Button type="primary" onClick={() => setModal2Open(true)}>
|
|
Vertically centered modal dialog
|
|
</Button>
|
|
<Modal
|
|
title="Vertically centered modal dialog"
|
|
centered
|
|
open={modal2Open}
|
|
onOk={() => setModal2Open(false)}
|
|
onCancel={() => setModal2Open(false)}
|
|
>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
<p>some contents...</p>
|
|
</Modal>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|