2018-08-10 13:32:33 +08:00
|
|
|
---
|
|
|
|
order: 1
|
|
|
|
title:
|
|
|
|
zh-CN: 自定义位置
|
|
|
|
en-US: Custom Placement
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2021-06-11 08:39:17 +08:00
|
|
|
自定义位置,点击触发按钮抽屉从相应的位置滑出,点击遮罩区关闭。
|
2018-08-10 13:32:33 +08:00
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
2019-04-19 20:59:45 +08:00
|
|
|
The Drawer can appear from any edge of the screen.
|
2018-08-10 13:32:33 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
|
|
|
import type { DrawerProps, RadioChangeEvent } from 'antd';
|
2022-05-21 22:14:15 +08:00
|
|
|
import { Button, Drawer, Radio, Space } from 'antd';
|
|
|
|
import React, { useState } from 'react';
|
2018-08-10 13:32:33 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
const [placement, setPlacement] = useState<DrawerProps['placement']>('left');
|
2018-08-10 13:32:33 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const showDrawer = () => {
|
|
|
|
setVisible(true);
|
2018-08-10 13:32:33 +08:00
|
|
|
};
|
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
const onClose = () => {
|
|
|
|
setVisible(false);
|
2018-08-10 13:32:33 +08:00
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const onChange = (e: RadioChangeEvent) => {
|
2022-05-14 16:40:42 +08:00
|
|
|
setPlacement(e.target.value);
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-08-10 13:32:33 +08:00
|
|
|
|
2022-05-14 16:40:42 +08:00
|
|
|
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}
|
|
|
|
visible={visible}
|
|
|
|
key={placement}
|
|
|
|
>
|
|
|
|
<p>Some contents...</p>
|
|
|
|
<p>Some contents...</p>
|
|
|
|
<p>Some contents...</p>
|
|
|
|
</Drawer>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2022-05-19 09:46:26 +08:00
|
|
|
|
|
|
|
export default App;
|
2018-08-10 13:32:33 +08:00
|
|
|
```
|