chore: refactor empty
parent
34ac8444f4
commit
632da57962
|
@ -1,71 +1,90 @@
|
||||||
import PropTypes from '../_util/vue-types';
|
import { defineComponent, CSSProperties, VNodeChild, inject, App } from 'vue';
|
||||||
|
import classNames from 'classnames';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import { getComponent } from '../_util/props-util';
|
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import DefaultEmptyImg from './empty';
|
import DefaultEmptyImg from './empty';
|
||||||
import SimpleEmptyImg from './simple';
|
import SimpleEmptyImg from './simple';
|
||||||
|
|
||||||
export const TransferLocale = () => {
|
const defaultEmptyImg = <DefaultEmptyImg />;
|
||||||
return {
|
const simpleEmptyImg = <SimpleEmptyImg />;
|
||||||
description: PropTypes.string,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmptyProps = () => {
|
export interface TransferLocale {
|
||||||
return {
|
description: string;
|
||||||
prefixCls: PropTypes.string,
|
}
|
||||||
image: PropTypes.any,
|
|
||||||
description: PropTypes.any,
|
|
||||||
imageStyle: PropTypes.object,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const Empty = {
|
export interface EmptyProps {
|
||||||
|
prefixCls?: string;
|
||||||
|
class?: string;
|
||||||
|
style?: CSSProperties;
|
||||||
|
imageStyle?: CSSProperties;
|
||||||
|
image?: VNodeChild;
|
||||||
|
description?: VNodeChild;
|
||||||
|
children?: VNodeChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Empty = defineComponent<EmptyProps>({
|
||||||
name: 'AEmpty',
|
name: 'AEmpty',
|
||||||
props: {
|
setup(props) {
|
||||||
...EmptyProps(),
|
const configProvider = inject('configProvider', ConfigConsumerProps);
|
||||||
},
|
const { getPrefixCls } = configProvider;
|
||||||
methods: {
|
const {
|
||||||
renderEmpty(contentLocale) {
|
class: className,
|
||||||
const { prefixCls: customizePrefixCls, imageStyle } = this.$props;
|
prefixCls: customizePrefixCls,
|
||||||
const prefixCls = ConfigConsumerProps.getPrefixCls('empty', customizePrefixCls);
|
image = defaultEmptyImg,
|
||||||
const image = getComponent(this, 'image') || <DefaultEmptyImg />;
|
description,
|
||||||
const description = getComponent(this, 'description');
|
children,
|
||||||
|
imageStyle,
|
||||||
|
...restProps
|
||||||
|
} = props;
|
||||||
|
|
||||||
const des = typeof description !== 'undefined' ? description : contentLocale.description;
|
return () => (
|
||||||
const alt = typeof des === 'string' ? des : 'empty';
|
<LocaleReceiver
|
||||||
const cls = { [prefixCls]: true };
|
componentName="Empty"
|
||||||
let imageNode = null;
|
children={(locale: TransferLocale) => {
|
||||||
if (typeof image === 'string') {
|
const prefixCls = getPrefixCls('empty', customizePrefixCls);
|
||||||
imageNode = <img alt={alt} src={image} />;
|
const des = typeof description !== 'undefined' ? description : locale.description;
|
||||||
} else if (typeof image === 'object' && image.type?.PRESENTED_IMAGE_SIMPLE) {
|
const alt = typeof des === 'string' ? des : 'empty';
|
||||||
const Image = image;
|
|
||||||
imageNode = <Image />;
|
let imageNode: any = null;
|
||||||
cls[`${prefixCls}-normal`] = true;
|
|
||||||
} else {
|
if (typeof image === 'string') {
|
||||||
imageNode = image;
|
imageNode = <img alt={alt} src={image} />;
|
||||||
}
|
} else {
|
||||||
return (
|
imageNode = image;
|
||||||
<div class={cls}>
|
}
|
||||||
<div class={`${prefixCls}-image`} style={imageStyle}>
|
|
||||||
{imageNode}
|
return (
|
||||||
</div>
|
<div
|
||||||
{des && <p class={`${prefixCls}-description`}>{des}</p>}
|
class={classNames(
|
||||||
{this.$slots.default && <div class={`${prefixCls}-footer`}>{this.$slots.default()}</div>}
|
prefixCls,
|
||||||
</div>
|
{
|
||||||
);
|
[`${prefixCls}-normal`]: image === simpleEmptyImg,
|
||||||
},
|
},
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
{...restProps}
|
||||||
|
>
|
||||||
|
<div class={`${prefixCls}-image`} style={imageStyle}>
|
||||||
|
{imageNode}
|
||||||
|
</div>
|
||||||
|
{des && <p class={`${prefixCls}-description`}>{des}</p>}
|
||||||
|
{children && <div class={`${prefixCls}-footer`}>{children}</div>}
|
||||||
|
</div>
|
||||||
|
) as VNodeChild;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return <LocaleReceiver componentName="Empty" children={this.renderEmpty} />;
|
return <LocaleReceiver componentName="Empty" children={this.renderEmpty} />;
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
Empty.PRESENTED_IMAGE_DEFAULT = DefaultEmptyImg;
|
Empty.PRESENTED_IMAGE_DEFAULT = defaultEmptyImg;
|
||||||
Empty.PRESENTED_IMAGE_SIMPLE = SimpleEmptyImg;
|
Empty.PRESENTED_IMAGE_SIMPLE = simpleEmptyImg;
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
Empty.install = function(app) {
|
Empty.install = function(app: App) {
|
||||||
app.component(Empty.name, Empty);
|
app.component(Empty.name, Empty);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
import { inject } from 'vue';
|
import { inject, defineComponent, VNode, VNodeChild } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
|
||||||
import defaultLocaleData from './default';
|
import defaultLocaleData from './default';
|
||||||
|
|
||||||
export default {
|
export interface LocaleReceiverProps {
|
||||||
|
componentName?: string;
|
||||||
|
defaultLocale?: object | Function;
|
||||||
|
children: (locale: object, localeCode?: string, fullLocale?: object) => VNodeChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface LocaleInterface {
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent<LocaleReceiverProps>({
|
||||||
name: 'LocaleReceiver',
|
name: 'LocaleReceiver',
|
||||||
props: {
|
|
||||||
componentName: PropTypes.string.def('global'),
|
|
||||||
defaultLocale: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
|
|
||||||
children: PropTypes.func,
|
|
||||||
},
|
|
||||||
setup() {
|
setup() {
|
||||||
return {
|
return {
|
||||||
localeData: inject('localeData', {}),
|
localeData: inject('localeData', {}),
|
||||||
|
@ -16,8 +20,9 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getLocale() {
|
getLocale() {
|
||||||
const { componentName, defaultLocale } = this;
|
const { componentName = 'global', defaultLocale } = this;
|
||||||
const locale = defaultLocale || defaultLocaleData[componentName || 'global'];
|
const locale =
|
||||||
|
defaultLocale || (defaultLocaleData as LocaleInterface)[componentName || 'global'];
|
||||||
const { antLocale } = this.localeData;
|
const { antLocale } = this.localeData;
|
||||||
|
|
||||||
const localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
|
const localeFromContext = componentName && antLocale ? antLocale[componentName] : {};
|
||||||
|
@ -43,4 +48,4 @@ export default {
|
||||||
const { antLocale } = this.localeData;
|
const { antLocale } = this.localeData;
|
||||||
return children?.(this.getLocale(), this.getLocaleCode(), antLocale);
|
return children?.(this.getLocale(), this.getLocaleCode(), antLocale);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
|
@ -1,25 +1,33 @@
|
||||||
import { provide } from 'vue';
|
import { provide, App, defineComponent, VNode } from 'vue';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import interopDefault from '../_util/interopDefault';
|
import interopDefault from '../_util/interopDefault';
|
||||||
import { changeConfirmLocale } from '../modal/locale';
|
import { ModalLocale, changeConfirmLocale } from '../modal/locale';
|
||||||
import warning from '../_util/warning';
|
import warning from '../_util/warning';
|
||||||
import { getSlot } from '../_util/props-util';
|
import { getSlot } from '../_util/props-util';
|
||||||
// export interface Locale {
|
export interface Locale {
|
||||||
// locale: string;
|
locale: string;
|
||||||
// Pagination?: Object;
|
Pagination?: Object;
|
||||||
// DatePicker?: Object;
|
DatePicker?: Object;
|
||||||
// TimePicker?: Object;
|
TimePicker?: Object;
|
||||||
// Calendar?: Object;
|
Calendar?: Object;
|
||||||
// Table?: Object;
|
Table?: Object;
|
||||||
// Modal?: ModalLocale;
|
Modal?: ModalLocale;
|
||||||
// Popconfirm?: Object;
|
Popconfirm?: Object;
|
||||||
// Transfer?: Object;
|
Transfer?: Object;
|
||||||
// Select?: Object;
|
Select?: Object;
|
||||||
// Upload?: Object;
|
Upload?: Object;
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
export interface LocaleProviderProps {
|
||||||
|
locale: Locale;
|
||||||
|
children?: VNode | VNode[];
|
||||||
|
_ANT_MARK__?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export const ANT_MARK = 'internalMark';
|
export const ANT_MARK = 'internalMark';
|
||||||
function setMomentLocale(locale) {
|
|
||||||
|
function setMomentLocale(locale?: Locale) {
|
||||||
if (locale && locale.locale) {
|
if (locale && locale.locale) {
|
||||||
interopDefault(moment).locale(locale.locale);
|
interopDefault(moment).locale(locale.locale);
|
||||||
} else {
|
} else {
|
||||||
|
@ -27,7 +35,7 @@ function setMomentLocale(locale) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LocaleProvider = {
|
const LocaleProvider = defineComponent({
|
||||||
name: 'ALocaleProvider',
|
name: 'ALocaleProvider',
|
||||||
props: {
|
props: {
|
||||||
locale: PropTypes.object.def(() => ({})),
|
locale: PropTypes.object.def(() => ({})),
|
||||||
|
@ -68,10 +76,10 @@ const LocaleProvider = {
|
||||||
render() {
|
render() {
|
||||||
return getSlot(this);
|
return getSlot(this);
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
LocaleProvider.install = function(app) {
|
LocaleProvider.install = function(app: App) {
|
||||||
app.component(LocaleProvider.name, LocaleProvider);
|
app.component(LocaleProvider.name, LocaleProvider);
|
||||||
};
|
};
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue