index.js 2.44 KB
Newer Older
1 2
import React, { PureComponent } from 'react';
import { Tabs, Skeleton } from 'antd';
3 4
import classNames from 'classnames';
import styles from './index.less';
5
import BreadcrumbView from './breadcrumb';
6

afc163's avatar
afc163 committed
7
const { TabPane } = Tabs;
8
export default class PageHeader extends PureComponent {
jim's avatar
jim committed
9
  onChange = key => {
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
10 11 12
    const { onTabChange } = this.props;
    if (onTabChange) {
      onTabChange(key);
13 14
    }
  };
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
15

16
  render() {
偏右's avatar
偏右 committed
17
    const {
18
      title = '',
19 20 21 22 23 24 25
      logo,
      action,
      content,
      extraContent,
      tabList,
      className,
      tabActiveKey,
26
      tabDefaultActiveKey,
27
      tabBarExtraContent,
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
28
      loading = false,
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
29
      wide = false,
30
      hiddenBreadcrumb = false,
偏右's avatar
偏右 committed
31
    } = this.props;
32

33
    const clsString = classNames(styles.pageHeader, className);
34 35 36 37
    const activeKeyProps = {};
    if (tabDefaultActiveKey !== undefined) {
      activeKeyProps.defaultActiveKey = tabDefaultActiveKey;
    }
afc163's avatar
afc163 committed
38 39
    if (tabActiveKey !== undefined) {
      activeKeyProps.activeKey = tabActiveKey;
afc163's avatar
afc163 committed
40
    }
41
    return (
42
      <div className={clsString}>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
43
        <div className={wide ? styles.wide : ''}>
44 45 46 47 48 49 50
          <Skeleton
            loading={loading}
            title={false}
            active
            paragraph={{ rows: 3 }}
            avatar={{ size: 'large', shape: 'circle' }}
          >
51
            {hiddenBreadcrumb ? null : <BreadcrumbView {...this.props} />}
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
52 53 54 55
            <div className={styles.detail}>
              {logo && <div className={styles.logo}>{logo}</div>}
              <div className={styles.main}>
                <div className={styles.row}>
56
                  <h1 className={styles.title}>{title}</h1>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
57 58 59 60 61 62
                  {action && <div className={styles.action}>{action}</div>}
                </div>
                <div className={styles.row}>
                  {content && <div className={styles.content}>{content}</div>}
                  {extraContent && <div className={styles.extraContent}>{extraContent}</div>}
                </div>
63
              </div>
64
            </div>
ι™ˆεΈ…'s avatar
ι™ˆεΈ… committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78
            {tabList && tabList.length ? (
              <Tabs
                className={styles.tabs}
                {...activeKeyProps}
                onChange={this.onChange}
                tabBarExtraContent={tabBarExtraContent}
              >
                {tabList.map(item => (
                  <TabPane tab={item.tab} key={item.key} />
                ))}
              </Tabs>
            ) : null}
          </Skeleton>
        </div>
79
      </div>
80 81 82
    );
  }
}