import React, {Children, Component} from 'react'; import {observer} from "mobx-react"; import * as classNames from 'classnames'; import {ITabBarMixinPropTypes} from "./PropsType"; const tabBarExtraContentStyle = { float: 'right', }; @observer export default class TabBar extends Component { static defaultProps = { styles: {} }; onTabClick(key) { this.props.onTabClick(key); } getTabs() { const props = this.props; const children = props.panels; const activeKey = props.activeKey; const rst = []; const prefixCls = props.prefixCls; Children.forEach(children, (child: any) => { if (!child) { return; } const key = child.key; let cls = activeKey === key ? `${prefixCls}-tab-active` : ''; cls += ` ${prefixCls}-tab`; let events = {}; if (child.props.disabled) { cls += ` ${prefixCls}-tab-disabled`; } else { events = { onClick: this.onTabClick.bind(this, key), }; } const ref = {ref: undefined}; if (activeKey === key) { ref.ref = 'activeTab'; } rst.push(
{child.props.tab}
); }); return rst; } getRootNode(contents) { const {prefixCls, onKeyDown, className, extraContent, style} = this.props; const cls = classNames({ [`${prefixCls}-bar`]: 1, [`${className}`]: !!className, }); return (
{extraContent ? (
{extraContent}
) : null} {contents}
); } render() { const tabs = this.getTabs(); return this.getRootNode(tabs); } }