index.js 1.61 KB
Newer Older
jim's avatar
jim committed
1
import React, { PureComponent } from 'react';
zinkey's avatar
zinkey committed
2
import Link from 'umi/link';
jim's avatar
jim committed
3
import RightContent from '../GlobalHeader/RightContent';
Erwin Zhang's avatar
Erwin Zhang committed
4
import BaseMenu from '../SiderMenu/BaseMenu';
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
5
import { getFlatMenuKeys } from '../SiderMenu/SiderMenuUtils';
jim's avatar
jim committed
6
import styles from './index.less';
7
import { title } from '../../defaultSettings';
jim's avatar
jim committed
8 9

export default class TopNavHeader extends PureComponent {
afc163's avatar
afc163 committed
10 11 12
  state = {
    maxWidth: undefined,
  };
13 14 15

  static getDerivedStateFromProps(props) {
    return {
16 17 18 19 20
      maxWidth:
        (props.contentWidth === 'Fixed' && window.innerWidth > 1200 ? 1200 : window.innerWidth) -
        280 -
        120 -
        40,
21 22 23
    };
  }

jim's avatar
jim committed
24
  render() {
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
25
    const { theme, contentWidth, menuData, logo } = this.props;
26
    const { maxWidth } = this.state;
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
27
    const flatMenuKeys = getFlatMenuKeys(menuData);
jim's avatar
jim committed
28
    return (
29
      <div className={`${styles.head} ${theme === 'light' ? styles.light : ''}`}>
30 31 32 33
        <div
          ref={ref => {
            this.maim = ref;
          }}
afc163's avatar
afc163 committed
34
          className={`${styles.main} ${contentWidth === 'Fixed' ? styles.wide : ''}`}
35
        >
jim's avatar
jim committed
36
          <div className={styles.left}>
37
            <div className={styles.logo} key="logo" id="logo">
jim's avatar
jim committed
38
              <Link to="/">
39
                <img src={logo} alt="logo" />
40
                <h1>{title}</h1>
jim's avatar
jim committed
41 42
              </Link>
            </div>
43 44 45 46 47
            <div
              style={{
                maxWidth,
              }}
            >
48
              <BaseMenu {...this.props} flatMenuKeys={flatMenuKeys} className={styles.menu} />
49
            </div>
jim's avatar
jim committed
50
          </div>
51
          <RightContent {...this.props} />
jim's avatar
jim committed
52 53 54 55 56
        </div>
      </div>
    );
  }
}