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

68 lines
1.4 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
```tsx
import type { DrawerProps, RadioChangeEvent } from 'antd';
2022-05-23 14:37:16 +08:00
import { Button, Drawer, Radio, Space } from 'antd';
import React, { useState } from 'react';
2018-08-10 13:32:33 +08:00
const App: React.FC = () => {
const [open, setOpen] = useState(false);
const [placement, setPlacement] = useState<DrawerProps['placement']>('left');
2018-08-10 13:32:33 +08:00
const showDrawer = () => {
setOpen(true);
2018-08-10 13:32:33 +08:00
};
const onClose = () => {
setOpen(false);
2018-08-10 13:32:33 +08:00
};
const onChange = (e: RadioChangeEvent) => {
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}
open={open}
key={placement}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
);
};
export default App;
2018-08-10 13:32:33 +08:00
```