Skip to content

Commit

Permalink
feat(Tab): feat addIcon func, close alibaba-fusion#4109
Browse files Browse the repository at this point in the history
  • Loading branch information
weinianyang authored and 潕量 committed Sep 19, 2022
1 parent b7b6bc6 commit df84688
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/tab/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Fusion 提供了三级选项卡,分别用于不同的场景。
| popupProps | 弹层属性透传, 只有当 excessMode 为 dropdown 时生效 | Object | - |
| icons | 自定义组件内 icon | Object | {} |
| showAdd | 新增按钮 | Boolean | - |
| addIcon | 自定义添加按钮 | ReactNode | - |
| onAdd | 新增的事件回调<br/><br/>**签名**:<br/>Function() => void | Function | - |

### Tab.Item
Expand Down
6 changes: 6 additions & 0 deletions src/tab/tab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ class Tab extends Component {
* 新增的事件回调
*/
onAdd: PropTypes.func,
/**
* 自定义添加按钮
*/
addIcon: PropTypes.node,
};

static defaultProps = {
Expand Down Expand Up @@ -312,6 +316,7 @@ class Tab extends Component {
icons,
showAdd,
onAdd,
addIcon,
...others
} = this.props;
const { activeKey } = this.state;
Expand Down Expand Up @@ -353,6 +358,7 @@ class Tab extends Component {
locale,
icons,
showAdd,
addIcon,
onAdd,
};

Expand Down
11 changes: 4 additions & 7 deletions src/tab/tabs/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Nav extends React.Component {
};

renderTabList(props, hideAdd) {
const { prefix, tabs, activeKey, tabRender, showAdd, onAdd } = props;
const { prefix, tabs, activeKey, tabRender, showAdd, onAdd, addIcon } = props;
const tabTemplateFn = tabRender || this.defaultTabTemplateRender;

const rst = [];
Expand Down Expand Up @@ -339,9 +339,7 @@ class Nav extends React.Component {
if (!hideAdd && showAdd) {
rst.push(
<li role="button" className={`${prefix}tabs-tab ${prefix}tabs-add`} onClick={onAdd} key="add">
<div className={`${prefix}tabs-tab-inner`}>
<Icon type="add" />
</div>
<div className={`${prefix}tabs-tab-inner`}>{addIcon ? addIcon : <Icon type="add" />}</div>
</li>
);
}
Expand Down Expand Up @@ -499,6 +497,7 @@ class Nav extends React.Component {
className,
showAdd,
onAdd,
addIcon,
rtl,
} = this.props;
const state = this.state;
Expand Down Expand Up @@ -594,9 +593,7 @@ class Nav extends React.Component {
{nextButton}
{restButton}
<li className={`${prefix}tabs-tab ${prefix}tabs-add`} onClick={onAdd} key="add">
<div className={`${prefix}tabs-tab-inner`}>
<Icon type="add" />
</div>
<div className={`${prefix}tabs-tab-inner`}>{addIcon ? addIcon : <Icon type="add" />}</div>
</li>
</div>
) : (
Expand Down
5 changes: 5 additions & 0 deletions types/tab/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export interface TabProps extends HTMLAttributesWeak, CommonProps {
* 新增的事件回调
*/
onAdd?: () => void,

/**
* 自定义添加按钮
*/
addIcon?: React.ReactNode;
}

export default class Tab extends React.Component<TabProps, any> {
Expand Down

0 comments on commit df84688

Please sign in to comment.