import * as React from 'react'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import Icon from '../icon'; import classnames from 'classnames'; import { BreadcrumbProps } from '../breadcrumb'; import Divider from '../divider'; import Tag from '../tag'; import Breadcrumb from '../breadcrumb'; import Wave from '../_util/wave'; export interface PageHeaderProps { backIcon?: React.ReactNode; prefixCls?: string; title: React.ReactNode; subTitle?: React.ReactNode; style?: React.CSSProperties; breadcrumb?: BreadcrumbProps; tags?: React.ReactElement | React.ReactElement[]; footer?: React.ReactNode; extra?: React.ReactNode; onBack?: (e: React.MouseEvent) => void; className?: string; } const renderBack = ( prefixCls: string, backIcon?: React.ReactNode, onBack?: (e: React.MouseEvent) => void, ) => { if (!backIcon || !onBack) { return null; } return (
{ if (onBack) { onBack(e); } }} > {backIcon}
); }; const renderBreadcrumb = (breadcrumb: BreadcrumbProps) => { return ; }; const renderHeader = (prefixCls: string, props: PageHeaderProps) => { const { breadcrumb, backIcon, onBack } = props; if (breadcrumb && breadcrumb.routes && breadcrumb.routes.length >= 2) { return renderBreadcrumb(breadcrumb); } return renderBack(prefixCls, backIcon, onBack); }; const renderTitle = (prefixCls: string, props: PageHeaderProps) => { const { title, subTitle, tags, extra } = props; const titlePrefixCls = `${prefixCls}-title-view`; return (
{title} {subTitle && {subTitle}} {tags && {tags}} {extra && {extra}}
); }; const renderFooter = (prefixCls: string, footer: React.ReactNode) => { if (footer) { return
{footer}
; } return null; }; const PageHeader: React.SFC = props => ( {({ getPrefixCls }: ConfigConsumerProps) => { const { prefixCls: customizePrefixCls, style, footer, children, className: customizeClassName, } = props; const prefixCls = getPrefixCls('page-header', customizePrefixCls); const className = classnames( prefixCls, { [`${prefixCls}-has-footer`]: footer, }, customizeClassName, ); return (
{renderHeader(prefixCls, props)} {renderTitle(prefixCls, props)} {children &&
{children}
} {renderFooter(prefixCls, footer)}
); }}
); PageHeader.defaultProps = { backIcon: , }; export default PageHeader;