refactor: page-header to ts
parent
2c60a2c5aa
commit
a62a0296e7
|
@ -1,4 +1,4 @@
|
||||||
import { inject } from 'vue';
|
import { App, defineComponent, inject, VNodeTypes, ExtractPropTypes } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { getComponent, getOptionProps, getSlot } from '../_util/props-util';
|
import { getComponent, getOptionProps, getSlot } from '../_util/props-util';
|
||||||
import { defaultConfigProvider } from '../config-provider';
|
import { defaultConfigProvider } from '../config-provider';
|
||||||
|
@ -9,27 +9,32 @@ import TransButton from '../_util/transButton';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
|
|
||||||
export const PageHeaderProps = {
|
export const PageHeaderProps = {
|
||||||
backIcon: PropTypes.any,
|
backIcon: PropTypes.VNodeChild,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
title: PropTypes.any,
|
title: PropTypes.VNodeChild,
|
||||||
subTitle: PropTypes.any,
|
subTitle: PropTypes.VNodeChild,
|
||||||
breadcrumb: PropTypes.object,
|
breadcrumb: PropTypes.object,
|
||||||
tags: PropTypes.any,
|
tags: PropTypes.any,
|
||||||
footer: PropTypes.any,
|
footer: PropTypes.VNodeChild,
|
||||||
extra: PropTypes.any,
|
extra: PropTypes.VNodeChild,
|
||||||
avatar: PropTypes.object,
|
avatar: PropTypes.object,
|
||||||
ghost: PropTypes.looseBool,
|
ghost: PropTypes.looseBool,
|
||||||
onBack: PropTypes.func,
|
onBack: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderBack = (instance, prefixCls, backIcon, onBack) => {
|
const renderBack = (
|
||||||
|
instance: any,
|
||||||
|
prefixCls: string,
|
||||||
|
backIcon: VNodeTypes,
|
||||||
|
onBack: (e: HTMLElement) => void,
|
||||||
|
) => {
|
||||||
if (!backIcon || !onBack) {
|
if (!backIcon || !onBack) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<LocaleReceiver
|
<LocaleReceiver
|
||||||
componentName="PageHeader"
|
componentName="PageHeader"
|
||||||
children={({ back }) => (
|
children={({ back }: any) => (
|
||||||
<div class={`${prefixCls}-back`}>
|
<div class={`${prefixCls}-back`}>
|
||||||
<TransButton
|
<TransButton
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
|
@ -50,7 +55,7 @@ const renderBreadcrumb = breadcrumb => {
|
||||||
return <Breadcrumb {...breadcrumb} />;
|
return <Breadcrumb {...breadcrumb} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderTitle = (prefixCls, instance) => {
|
const renderTitle = (prefixCls: string, instance: any) => {
|
||||||
const { avatar } = instance;
|
const { avatar } = instance;
|
||||||
const title = getComponent(instance, 'title');
|
const title = getComponent(instance, 'title');
|
||||||
const subTitle = getComponent(instance, 'subTitle');
|
const subTitle = getComponent(instance, 'subTitle');
|
||||||
|
@ -80,18 +85,18 @@ const renderTitle = (prefixCls, instance) => {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderFooter = (prefixCls, footer) => {
|
const renderFooter = (prefixCls: string, footer: VNodeTypes) => {
|
||||||
if (footer) {
|
if (footer) {
|
||||||
return <div class={`${prefixCls}-footer`}>{footer}</div>;
|
return <div class={`${prefixCls}-footer`}>{footer}</div>;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderChildren = (prefixCls, children) => {
|
const renderChildren = (prefixCls: string, children: VNodeTypes) => {
|
||||||
return <div class={`${prefixCls}-content`}>{children}</div>;
|
return <div class={`${prefixCls}-content`}>{children}</div>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const PageHeader = {
|
const PageHeader = defineComponent({
|
||||||
name: 'APageHeader',
|
name: 'APageHeader',
|
||||||
props: PageHeaderProps,
|
props: PageHeaderProps,
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -101,7 +106,7 @@ const PageHeader = {
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
const { getPrefixCls, pageHeader } = this.configProvider;
|
const { getPrefixCls, pageHeader } = this.configProvider;
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this) as ExtractPropTypes<typeof PageHeaderProps>;
|
||||||
const { prefixCls: customizePrefixCls, breadcrumb } = props;
|
const { prefixCls: customizePrefixCls, breadcrumb } = props;
|
||||||
const footer = getComponent(this, 'footer');
|
const footer = getComponent(this, 'footer');
|
||||||
const children = getSlot(this);
|
const children = getSlot(this);
|
||||||
|
@ -133,10 +138,10 @@ const PageHeader = {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
PageHeader.install = function(app) {
|
PageHeader.install = function(app: App) {
|
||||||
app.component(PageHeader.name, PageHeader);
|
app.component(PageHeader.name, PageHeader);
|
||||||
return app;
|
return app;
|
||||||
};
|
};
|
|
@ -1,5 +0,0 @@
|
||||||
import './index.less';
|
|
||||||
|
|
||||||
// style dependencies
|
|
||||||
import '../../breadcrumb/style';
|
|
||||||
import '../../avatar/style';
|
|
Loading…
Reference in New Issue