mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 09:21:22 +08:00
1719748a29
* chore: eslint add consistent-type-imports * fix avatar * Update Item.tsx
72 lines
1.8 KiB
Markdown
72 lines
1.8 KiB
Markdown
---
|
|
order: 1.1
|
|
title:
|
|
zh-CN: 额外操作
|
|
en-US: Extra Actions
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
在 Ant Design 规范中,操作按钮建议放在抽屉的右上角,可以使用 `extra` 属性来实现。
|
|
|
|
## en-US
|
|
|
|
Extra actions should be placed at corner of drawer in Ant Design, you can using `extra` prop for that.
|
|
|
|
```tsx
|
|
import React, { useState } from 'react';
|
|
import { Drawer, Button, Space, Radio } from 'antd';
|
|
import type { DrawerProps } from 'antd/es/drawer';
|
|
import type { RadioChangeEvent } from 'antd/es/radio';
|
|
|
|
const App: React.FC = () => {
|
|
const [visible, setVisible] = useState(false);
|
|
const [placement, setPlacement] = useState<DrawerProps['placement']>('right');
|
|
const showDrawer = () => {
|
|
setVisible(true);
|
|
};
|
|
const onChange = (e: RadioChangeEvent) => {
|
|
setPlacement(e.target.value);
|
|
};
|
|
const onClose = () => {
|
|
setVisible(false);
|
|
};
|
|
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="Drawer with extra actions"
|
|
placement={placement}
|
|
width={500}
|
|
onClose={onClose}
|
|
visible={visible}
|
|
extra={
|
|
<Space>
|
|
<Button onClick={onClose}>Cancel</Button>
|
|
<Button type="primary" onClick={onClose}>
|
|
OK
|
|
</Button>
|
|
</Space>
|
|
}
|
|
>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
<p>Some contents...</p>
|
|
</Drawer>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
```
|