2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 4
|
2017-02-04 01:13:35 +08:00
|
|
|
title:
|
2016-08-23 14:15:34 +08:00
|
|
|
zh-CN: 附加内容
|
|
|
|
en-US: Extra content
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-12-14 22:16:25 +08:00
|
|
|
|
2016-08-03 10:39:20 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2020-08-07 09:53:45 +08:00
|
|
|
可以在页签两边添加附加操作。
|
2015-12-14 22:16:25 +08:00
|
|
|
|
2016-08-03 10:39:20 +08:00
|
|
|
## en-US
|
|
|
|
|
2020-08-07 09:53:45 +08:00
|
|
|
You can add extra actions to the right or left or even both side of Tabs.
|
2016-08-03 10:39:20 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2022-05-21 22:14:15 +08:00
|
|
|
import { Button, Checkbox, Divider, Tabs } from 'antd';
|
2022-05-19 09:46:26 +08:00
|
|
|
import React, { useMemo, useState } from 'react';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-27 21:32:45 +08:00
|
|
|
const { TabPane } = Tabs;
|
2015-12-14 22:16:25 +08:00
|
|
|
|
2020-08-07 09:53:45 +08:00
|
|
|
const CheckboxGroup = Checkbox.Group;
|
|
|
|
|
2016-08-03 10:39:20 +08:00
|
|
|
const operations = <Button>Extra Action</Button>;
|
2015-12-14 22:16:25 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const OperationsSlot: Record<PositionType, React.ReactNode> = {
|
2020-09-30 17:08:39 +08:00
|
|
|
left: <Button className="tabs-extra-demo-button">Left Extra Action</Button>,
|
2020-08-07 09:53:45 +08:00
|
|
|
right: <Button>Right Extra Action</Button>,
|
|
|
|
};
|
|
|
|
|
|
|
|
const options = ['left', 'right'];
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
type PositionType = 'left' | 'right';
|
2020-08-07 09:53:45 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [position, setPosition] = useState<PositionType[]>(['left', 'right']);
|
|
|
|
|
|
|
|
const slot = useMemo(() => {
|
2020-08-26 11:09:14 +08:00
|
|
|
if (position.length === 0) return null;
|
2020-08-07 09:53:45 +08:00
|
|
|
|
2020-08-26 11:09:14 +08:00
|
|
|
return position.reduce(
|
|
|
|
(acc, direction) => ({ ...acc, [direction]: OperationsSlot[direction] }),
|
2020-08-07 09:53:45 +08:00
|
|
|
{},
|
|
|
|
);
|
2020-08-26 11:09:14 +08:00
|
|
|
}, [position]);
|
2020-08-07 09:53:45 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Tabs tabBarExtraContent={operations}>
|
|
|
|
<TabPane tab="Tab 1" key="1">
|
|
|
|
Content of tab 1
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 2" key="2">
|
|
|
|
Content of tab 2
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 3" key="3">
|
|
|
|
Content of tab 3
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<div>You can also specify its direction or both side</div>
|
|
|
|
<Divider />
|
|
|
|
<CheckboxGroup
|
|
|
|
options={options}
|
2020-08-26 11:09:14 +08:00
|
|
|
value={position}
|
2020-08-07 09:53:45 +08:00
|
|
|
onChange={value => {
|
2022-05-19 09:46:26 +08:00
|
|
|
setPosition(value as PositionType[]);
|
2020-08-07 09:53:45 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<Tabs tabBarExtraContent={slot}>
|
|
|
|
<TabPane tab="Tab 1" key="1">
|
|
|
|
Content of tab 1
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 2" key="2">
|
|
|
|
Content of tab 2
|
|
|
|
</TabPane>
|
|
|
|
<TabPane tab="Tab 3" key="3">
|
|
|
|
Content of tab 3
|
|
|
|
</TabPane>
|
|
|
|
</Tabs>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|
2020-09-30 17:08:39 +08:00
|
|
|
|
|
|
|
```css
|
|
|
|
.tabs-extra-demo-button {
|
|
|
|
margin-right: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.ant-row-rtl .tabs-extra-demo-button {
|
|
|
|
margin-right: 0;
|
|
|
|
margin-left: 16px;
|
|
|
|
}
|
|
|
|
```
|