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

74 lines
1.5 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
class App extends React.Component {
state = { visible: false, placement: 'left' };
showDrawer = () => {
this.setState({
visible: true,
});
};
onClose = () => {
this.setState({
visible: false,
});
};
2019-05-07 14:57:32 +08:00
onChange = e => {
2018-08-10 13:32:33 +08:00
this.setState({
placement: e.target.value,
});
2019-05-07 14:57:32 +08:00
};
2018-08-10 13:32:33 +08:00
render() {
const { placement, visible } = this.state;
2018-08-10 13:32:33 +08:00
return (
<>
<Space>
<Radio.Group value={placement} onChange={this.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={this.showDrawer}>
Open
</Button>
</Space>
2018-08-10 13:32:33 +08:00
<Drawer
title="Basic Drawer"
placement={placement}
2018-08-10 13:32:33 +08:00
closable={false}
onClose={this.onClose}
visible={visible}
key={placement}
2018-08-10 13:32:33 +08:00
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
2018-08-10 13:32:33 +08:00
);
}
}
export default App;
2018-08-10 13:32:33 +08:00
```