<commit_before>import React, { Component, PureComponent } from 'react';
import assign from 'lodash/assign';
import PropTypes from 'prop-types';
import noop from 'lodash/noop';

import TabPanel from './components/TabPanel';
import LazyMount from './components/LazyMount';
import Nav from './components/Nav';
import tabUtil from './tabUtil';

export default class Tabs extends (PureComponent || Component) {
  static propTypes = {
    className: PropTypes.string,
    prefix: PropTypes.string,
    type: PropTypes.oneOf(['normal', 'card', 'slider']),
    activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    // 推荐使用activeId代替原来的activeKey
    // 更直观
    activeId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    size: PropTypes.oneOf(['huge', 'normal']),
    align: PropTypes.oneOf(['left', 'right', 'center']),
    onTabChange: PropTypes.func,
    onTabDel: PropTypes.func,
    onTabAdd: PropTypes.func,
    candel: PropTypes.bool,
    canadd: PropTypes.bool,
    tabs: PropTypes.arrayOf(
      PropTypes.shape({
        key: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
          .isRequired,
        title: PropTypes.node.isRequired,
        disabled: PropTypes.bool
      })
    )
  };

  static defaultProps = {
    prefix: 'zent',
    className: '',
    type: 'normal',
    activeKey: '',
    activeId: '',
    size: 'normal',
    align: 'left',
    onTabChange: noop,
    onTabDel: noop,
    onTabAdd: noop,
    candel: false,
    canadd: false
  };

  static uniqueId = 0;

  static TabPanel = TabPanel;

  constructor(props) {
    super(props);
    Tabs.uniqueId++;
  }

  // 选中tab
  onTabChange(selectKey) {
    let { onTabChange } = this.props;
    if (onTabChange) {
      onTabChange(selectKey);
    }
  }

  // 删除tab
  onTabDel(tabKey) {
    let { onTabDel } = this.props;
    if (onTabDel) {
      onTabDel(tabKey);
    }
  }

  // 增加tab
  onTabAdd() {
    let { onTabAdd } = this.props;
    if (onTabAdd) {
      onTabAdd();
    }
  }

  renderNav(tabListData) {
    let { type, align, canadd, candel, prefix, size } = this.props;
    if (tabListData && tabListData.length) {
      return (
        <Nav
          onChange={this.onTabChange.bind(this)}
          tabListData={tabListData}
          type={type}
          align={align}
          size={size}
          onDelete={this.onTabDel.bind(this)}
          onTabAdd={this.onTabAdd.bind(this)}
          canadd={canadd}
          candel={candel}
          prefix={prefix}
          uniqueId={Tabs.uniqueId}
        />
      );
    }
  }

  renderTabPanel(tabListData) {
    let { prefix } = this.props;
    let newChildren = [];
    if (tabListData && tabListData.length) {
      tabListData.forEach(tabItem => {
        newChildren.push(
          <LazyMount mountTrigger={tabItem.actived} key={tabItem.key}>
            <TabPanel
              tab={tabItem.title}
              actived={tabItem.actived}
              onTabReady={tabItem.onTabReady}
              prefix={prefix}
              className={tabItem.panelClassName}
              id={tabItem.key}
              uniqueId={Tabs.uniqueId}
            >
              {tabItem.content}
            </TabPanel>
          </LazyMount>
        );
      });
      return newChildren;
    }
    return null;
  }

  renderWithPanel() {
    let { prefix, className, children, activeKey, activeId } = this.props;
    // 向上兼容
    activeId = activeId === undefined ? activeKey : activeId;
    let tabListData = tabUtil.getTabListData(children, activeId);
    return (
      <div className={`${prefix}-tabs ${className}`}>
        {this.renderNav(tabListData)}
        <div className={`${prefix}-tabs-panewrap`}>
          {this.renderTabPanel(tabListData)}
        </div>
      </div>
    );
  }

  renderWithoutPanel() {<commit_msg>fix: 修复Tabs组件activeKey兼容问题<commit_after>import React, { Component, PureComponent } from 'react';
import assign from 'lodash/assign';
import PropTypes from 'prop-types';
import noop from 'lodash/noop';

import TabPanel from './components/TabPanel';
import LazyMount from './components/LazyMount';
import Nav from './components/Nav';
import tabUtil from './tabUtil';

export default class Tabs extends (PureComponent || Component) {
  static propTypes = {
    className: PropTypes.string,
    prefix: PropTypes.string,
    type: PropTypes.oneOf(['normal', 'card', 'slider']),
    activeKey: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    // 推荐使用activeId代替原来的activeKey
    // 更直观
    activeId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    size: PropTypes.oneOf(['huge', 'normal']),
    align: PropTypes.oneOf(['left', 'right', 'center']),
    onTabChange: PropTypes.func,
    onTabDel: PropTypes.func,
    onTabAdd: PropTypes.func,
    candel: PropTypes.bool,
    canadd: PropTypes.bool,
    tabs: PropTypes.arrayOf(
      PropTypes.shape({
        key: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
          .isRequired,
        title: PropTypes.node.isRequired,
        disabled: PropTypes.bool
      })
    )
  };

  static defaultProps = {
    prefix: 'zent',
    className: '',
    type: 'normal',
    activeKey: '',
    activeId: '',
    size: 'normal',
    align: 'left',
    onTabChange: noop,
    onTabDel: noop,
    onTabAdd: noop,
    candel: false,
    canadd: false
  };

  static uniqueId = 0;

  static TabPanel = TabPanel;

  constructor(props) {
    super(props);
    Tabs.uniqueId++;
  }

  // 选中tab
  onTabChange(selectKey) {
    let { onTabChange } = this.props;
    if (onTabChange) {
      onTabChange(selectKey);
    }
  }

  // 删除tab
  onTabDel(tabKey) {
    let { onTabDel } = this.props;
    if (onTabDel) {
      onTabDel(tabKey);
    }
  }

  // 增加tab
  onTabAdd() {
    let { onTabAdd } = this.props;
    if (onTabAdd) {
      onTabAdd();
    }
  }

  renderNav(tabListData) {
    let { type, align, canadd, candel, prefix, size } = this.props;
    if (tabListData && tabListData.length) {
      return (
        <Nav
          onChange={this.onTabChange.bind(this)}
          tabListData={tabListData}
          type={type}
          align={align}
          size={size}
          onDelete={this.onTabDel.bind(this)}
          onTabAdd={this.onTabAdd.bind(this)}
          canadd={canadd}
          candel={candel}
          prefix={prefix}
          uniqueId={Tabs.uniqueId}
        />
      );
    }
  }

  renderTabPanel(tabListData) {
    let { prefix } = this.props;
    let newChildren = [];
    if (tabListData && tabListData.length) {
      tabListData.forEach(tabItem => {
        newChildren.push(
          <LazyMount mountTrigger={tabItem.actived} key={tabItem.key}>
            <TabPanel
              tab={tabItem.title}
              actived={tabItem.actived}
              onTabReady={tabItem.onTabReady}
              prefix={prefix}
              className={tabItem.panelClassName}
              id={tabItem.key}
              uniqueId={Tabs.uniqueId}
            >
              {tabItem.content}
            </TabPanel>
          </LazyMount>
        );
      });
      return newChildren;
    }
    return null;
  }

  renderWithPanel() {
    let { prefix, className, children, activeKey, activeId } = this.props;
    // 向上兼容
    // 因为defaultProps里面activeId和activeKey默认值为空，所以不应该用是否是undefined来处理
    activeId = activeId === '' ? activeKey : activeId;
    let tabListData = tabUtil.getTabListData(children, activeId);
    return (
      <div className={`${prefix}-tabs ${className}`}>
        {this.renderNav(tabListData)}
        <div className={`${prefix}-tabs-panewrap`}>
          {this.renderTabPanel(tabListData)}
        </div>
      </div>
    );
  }

  renderWithoutPanel() {
{'fraction_non_alphanumeric': 0.1331249185879901, 'fraction_numerical': 0.0002605184316790413, 'mean_word_length': 2.406388642413487, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4417031', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2501, 'n_words': 453}