index.tsx 983 Bytes
Newer Older
陈帅's avatar
陈帅 committed
1 2
import React from 'react';
import { RouteContext } from '@ant-design/pro-layout';
陈帅's avatar
陈帅 committed
3
import { PageHeader, Typography } from 'antd';
陈帅's avatar
陈帅 committed
4 5 6 7
import styles from './index.less';

interface IPageHeaderWrapperProps {
  content: React.ReactNode;
陈帅's avatar
陈帅 committed
8
  title?: React.ReactNode;
陈帅's avatar
陈帅 committed
9 10 11 12
}

const PageHeaderWrapper: React.SFC<IPageHeaderWrapperProps> = ({
  children,
陈帅's avatar
陈帅 committed
13
  title,
陈帅's avatar
陈帅 committed
14 15 16 17 18 19
  content,
  ...restProps
}) => (
  <RouteContext.Consumer>
    {value => (
      <div style={{ margin: '-24px -24px 0' }}>
陈帅's avatar
陈帅 committed
20
        <PageHeader
陈帅's avatar
陈帅 committed
21
          {...value}
陈帅's avatar
陈帅 committed
22 23 24 25 26 27 28
          title={
            <Typography.Title
              level={4}
              style={{
                margin: 0,
              }}
            >
陈帅's avatar
陈帅 committed
29
              {title || value.title}
陈帅's avatar
陈帅 committed
30 31 32 33
            </Typography.Title>
          }
          {...restProps}
        >
陈帅's avatar
陈帅 committed
34 35 36 37 38 39 40 41 42
          {content}
        </PageHeader>
        {children ? <div className={styles.content}>{children}</div> : null}
      </div>
    )}
  </RouteContext.Consumer>
);

export default PageHeaderWrapper;