index.tsx 2.5 KB
Newer Older
1
import React, { Component } 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 defaultSettings from '../../../config/defaultSettings';
jim's avatar
jim committed
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
export declare type CollapseType = 'clickTrigger' | 'responsive';
export declare type SiderTheme = 'light' | 'dark';
export declare type MenuMode =
  | 'vertical'
  | 'vertical-left'
  | 'vertical-right'
  | 'horizontal'
  | 'inline';

const { title } = defaultSettings;
interface TopNavHeaderProps {
  theme: SiderTheme;
  contentWidth?: string;
  menuData?: any[];
  logo?: string;
  mode?: MenuMode;
  flatMenuKeys?: any[];
  onCollapse?: (collapsed: boolean, type?: CollapseType) => void;
  isMobile?: boolean;
  openKeys?: any;
  className?: string;
  collapsed?: boolean;
  handleOpenChange?: (openKeys: any[]) => void;
  style?: React.CSSProperties;
  onOpenChange?: (openKeys: string[]) => void;
  onNoticeClear?: (type: string) => void;
  onMenuClick?: ({ key: string }) => void;
  onNoticeVisibleChange?: (b: boolean) => void;
}

interface TopNavHeaderState {
  maxWidth: undefined | number;
}

export default class TopNavHeader extends Component<TopNavHeaderProps, TopNavHeaderState> {
afc163's avatar
afc163 committed
44 45 46
  state = {
    maxWidth: undefined,
  };
47

48 49
  maim: HTMLDivElement;

50 51
  static getDerivedStateFromProps(props) {
    return {
afc163's avatar
afc163 committed
52
      maxWidth: (props.contentWidth === 'Fixed' ? 1200 : window.innerWidth) - 280 - 165 - 40,
53 54 55
    };
  }

jim's avatar
jim committed
56
  render() {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
57
    const { theme, contentWidth, menuData, logo } = this.props;
58
    const { maxWidth } = this.state;
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
59
    const flatMenuKeys = getFlatMenuKeys(menuData);
jim's avatar
jim committed
60
    return (
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
61
      <div className={`${styles.head} ${theme === 'light' ? styles.light : ''}`}>
62 63 64 65
        <div
          ref={ref => {
            this.maim = ref;
          }}
afc163's avatar
afc163 committed
66
          className={`${styles.main} ${contentWidth === 'Fixed' ? styles.wide : ''}`}
67
        >
jim's avatar
jim committed
68
          <div className={styles.left}>
69
            <div className={styles.logo} key="logo" id="logo">
jim's avatar
jim committed
70
              <Link to="/">
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
71
                <img src={logo} alt="logo" />
Yu's avatar
Yu committed
72
                <h1>{title}</h1>
jim's avatar
jim committed
73 74
              </Link>
            </div>
75 76 77 78 79
            <div
              style={{
                maxWidth,
              }}
            >
80
              <BaseMenu {...this.props} flatMenuKeys={flatMenuKeys} className={styles.menu} />
81
            </div>
jim's avatar
jim committed
82
          </div>
83
          <RightContent {...this.props} />
jim's avatar
jim committed
84 85 86 87 88
        </div>
      </div>
    );
  }
}