mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
1919b5f7d9
Co-authored-by: 二货机器人 <smith3816@gmail.com>
68 lines
1.4 KiB
Markdown
68 lines
1.4 KiB
Markdown
---
|
|
order: 1
|
|
title:
|
|
zh-CN: 自定义位置
|
|
en-US: Custom Placement
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
自定义位置,点击触发按钮抽屉从相应的位置滑出,点击遮罩区关闭。
|
|
|
|
## en-US
|
|
|
|
The Drawer can appear from any edge of the screen.
|
|
|
|
```tsx
|
|
import type { DrawerProps, RadioChangeEvent } from 'antd';
|
|
import { Button, Drawer, Radio, Space } from 'antd';
|
|
import React, { useState } from 'react';
|
|
|
|
const App: React.FC = () => {
|
|
const [open, setOpen] = useState(false);
|
|
const [placement, setPlacement] = useState<DrawerProps['placement']>('left');
|
|
|
|
const showDrawer = () => {
|
|
setOpen(true);
|
|
};
|
|
|
|
const onClose = () => {
|
|
setOpen(false);
|
|
};
|
|
|
|
const onChange = (e: RadioChangeEvent) => {
|
|
setPlacement(e.target.value);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Space>
|
|
<Radio.Group value={placement} onChange={onChange}>
|
|
<Radio value="top">top</Radio>
|
|
<Radio value="right">right</Radio>
|
|
<Radio value="bottom">bottom</Radio>
|
|
<Radio value="left">left</Radio>
|
|
</Radio.Group>
|
|
<Button type="primary" onClick={showDrawer}>
|
|
Open
|
|
</Button>
|
|
</Space>
|
|
<Drawer
|
|
title="Basic Drawer"
|
|
placement={placement}
|
|
closable={false}
|
|
onClose={onClose}
|
|
open={open}
|
|
key={placement}
|
|
>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
</Drawer>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|