import { inject } from 'vue'; import PropTypes from '../_util/vue-types'; import { getComponent, getOptionProps } from '../_util/props-util'; import { ConfigConsumerProps } from '../config-provider'; import ArrowLeftOutlined from '@ant-design/icons-vue/ArrowLeftOutlined'; import Breadcrumb from '../breadcrumb'; import Avatar from '../avatar'; import TransButton from '../_util/transButton'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; export const PageHeaderProps = { backIcon: PropTypes.any, prefixCls: PropTypes.string, title: PropTypes.any, subTitle: PropTypes.any, breadcrumb: PropTypes.object, tags: PropTypes.any, footer: PropTypes.any, extra: PropTypes.any, avatar: PropTypes.object, ghost: PropTypes.bool, }; const renderBack = (instance, prefixCls, backIcon, onBack) => { if (!backIcon || !onBack) { return null; } return ( (
{ instance.$emit('back', e); }} class={`${prefixCls}-back-button`} aria-label={back} > {backIcon}
)} >
); }; const renderBreadcrumb = breadcrumb => { return ; }; const renderTitle = (prefixCls, instance) => { const { avatar } = instance; const title = getComponent(instance, 'title'); const subTitle = getComponent(instance, 'subTitle'); const tags = getComponent(instance, 'tags'); const extra = getComponent(instance, 'extra'); const backIcon = getComponent(instance, 'backIcon') !== undefined ? ( getComponent(instance, 'backIcon') ) : ( ); const onBack = instance.$attrs.onBack; const headingPrefixCls = `${prefixCls}-heading`; if (title || subTitle || tags || extra) { const backIconDom = renderBack(instance, prefixCls, backIcon, onBack); return (
{backIconDom} {avatar && } {title && {title}} {subTitle && {subTitle}} {tags && {tags}} {extra && {extra}}
); } return null; }; const renderFooter = (prefixCls, footer) => { if (footer) { return
{footer}
; } return null; }; const renderChildren = (prefixCls, children) => { return
{children}
; }; const PageHeader = { name: 'APageHeader', props: PageHeaderProps, setup() { return { configProvider: inject('configProvider', ConfigConsumerProps), }; }, render() { const { getPrefixCls, pageHeader } = this.configProvider; const props = getOptionProps(this); const { prefixCls: customizePrefixCls, breadcrumb } = props; const footer = getComponent(this, 'footer'); const children = this.$slots.default && this.$slots.default(); let ghost = true; // Use `ghost` from `props` or from `ConfigProvider` instead. if ('ghost' in props) { ghost = props.ghost; } else if (pageHeader && 'ghost' in pageHeader) { ghost = pageHeader.ghost; } const prefixCls = getPrefixCls('page-header', customizePrefixCls); const breadcrumbDom = breadcrumb && breadcrumb.props && breadcrumb.props.routes ? renderBreadcrumb(breadcrumb) : null; const className = [ prefixCls, { 'has-breadcrumb': breadcrumbDom, 'has-footer': footer, [`${prefixCls}-ghost`]: ghost, }, ]; return (
{breadcrumbDom} {renderTitle(prefixCls, this)} {children && children.length && renderChildren(prefixCls, children)} {renderFooter(prefixCls, footer)}
); }, }; /* istanbul ignore next */ PageHeader.install = function(app) { app.component(PageHeader.name, PageHeader); }; export default PageHeader;