ant-design/components/drawer/demo/placement.md

64 lines
1.3 KiB
Markdown
Raw Normal View History

2018-08-10 13:32:33 +08:00
---
order: 1
title:
zh-CN: 自定义位置
en-US: Custom Placement
---
## zh-CN
自定义位置,点击触发按钮抽屉从相应的位置滑出,点击遮罩区关闭。
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
```jsx
import { Drawer, Button, Radio, Space } from 'antd';
2018-08-10 13:32:33 +08:00
export default () => {
const [visible, setVisible] = React.useState(false);
const [placement, setPlacement] = React.useState('left');
2018-08-10 13:32:33 +08:00
const showDrawer = () => {
setVisible(true);
2018-08-10 13:32:33 +08:00
};
const onClose = () => {
setVisible(false);
2018-08-10 13:32:33 +08:00
};
const onChange = e => {
setPlacement(e.target.value);
2019-05-07 14:57:32 +08:00
};
2018-08-10 13:32:33 +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>
</>
);
};
2018-08-10 13:32:33 +08:00
```