index.js 1.51 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 7 8
import styles from './index.less';

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

  static getDerivedStateFromProps(props) {
    return {
afc163's avatar
afc163 committed
15
      maxWidth: (props.contentWidth === 'Fixed' ? 1200 : window.innerWidth) - 280 - 165 - 40,
16 17 18
    };
  }

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