LoginTab.js 723 Bytes
Newer Older
ddcat1115's avatar
ddcat1115 committed
1 2
import React, { Component } from 'react';
import { Tabs } from 'antd';
jim's avatar
jim committed
3
import LoginContext from './loginContext';
ddcat1115's avatar
ddcat1115 committed
4 5 6 7 8

const { TabPane } = Tabs;

const generateId = (() => {
  let i = 0;
afc163's avatar
afc163 committed
9
  return (prefix = '') => {
ddcat1115's avatar
ddcat1115 committed
10 11 12 13 14
    i += 1;
    return `${prefix}${i}`;
  };
})();

jim's avatar
jim committed
15
class LoginTab extends Component {
ddcat1115's avatar
ddcat1115 committed
16 17 18 19
  constructor(props) {
    super(props);
    this.uniqueId = generateId('login-tab-');
  }
jim's avatar
jim committed
20 21
  componentDidMount() {
    this.props.tabUtil.addTab(this.uniqueId);
ddcat1115's avatar
ddcat1115 committed
22 23 24 25 26
  }
  render() {
    return <TabPane {...this.props} />;
  }
}
jim's avatar
jim committed
27 28 29 30 31 32 33 34 35

const warpContext = props => {
  return (
    <LoginContext.Consumer>
      {value => <LoginTab tabUtil={value.tabUtil} {...props} />}
    </LoginContext.Consumer>
  );
};
export default warpContext;