LoginTab.js 870 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-');
  }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
20

jim's avatar
jim committed
21
  componentDidMount() {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
22 23
    const { tabUtil } = this.props;
    tabUtil.addTab(this.uniqueId);
ddcat1115's avatar
ddcat1115 committed
24
  }
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
25

ddcat1115's avatar
ddcat1115 committed
26
  render() {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
27 28
    const { children } = this.props;
    return <TabPane {...this.props}>{children}</TabPane>;
ddcat1115's avatar
ddcat1115 committed
29 30
  }
}
jim's avatar
jim committed
31

afc163's avatar
afc163 committed
32
const wrapContext = props => (
33 34 35 36
  <LoginContext.Consumer>
    {value => <LoginTab tabUtil={value.tabUtil} {...props} />}
  </LoginContext.Consumer>
);
afc163's avatar
afc163 committed
37

38
// ๆ ‡ๅฟ—ไฝ ็”จๆฅๅˆคๆ–ญๆ˜ฏไธๆ˜ฏ่‡ชๅฎšไน‰็ป„ไปถ
afc163's avatar
afc163 committed
39
wrapContext.typeName = 'LoginTab';
40

afc163's avatar
afc163 committed
41
export default wrapContext;