2018-12-26 16:01:00 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
|
|
|
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
2019-01-07 14:43:51 +08:00
|
|
|
import emptyImg from './empty.svg';
|
2018-12-26 16:01:00 +08:00
|
|
|
|
|
|
|
export interface TransferLocale {
|
|
|
|
description: string;
|
|
|
|
}
|
|
|
|
export interface EmptyProps {
|
|
|
|
prefixCls?: string;
|
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
2019-01-13 21:53:10 +08:00
|
|
|
image?: React.ReactNode;
|
|
|
|
description?: React.ReactNode;
|
2018-12-26 16:01:00 +08:00
|
|
|
children?: React.ReactNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Empty: React.SFC<EmptyProps> = (props: EmptyProps) => (
|
|
|
|
<ConfigConsumer>
|
|
|
|
{({ getPrefixCls }: ConfigConsumerProps) => {
|
2019-01-17 22:32:52 +08:00
|
|
|
const {
|
|
|
|
className,
|
|
|
|
prefixCls: customizePrefixCls,
|
|
|
|
image,
|
|
|
|
description,
|
|
|
|
children,
|
|
|
|
...restProps
|
|
|
|
} = props;
|
|
|
|
const prefixCls = getPrefixCls('empty', customizePrefixCls);
|
2018-12-26 16:01:00 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<LocaleReceiver componentName="Empty">
|
|
|
|
{(locale: TransferLocale) => {
|
|
|
|
const des = description || locale.description;
|
|
|
|
const alt = typeof des === 'string' ? des : 'empty';
|
|
|
|
|
|
|
|
let imageNode: React.ReactNode = null;
|
|
|
|
if (!image) {
|
|
|
|
imageNode = <img alt={alt} src={emptyImg} />;
|
|
|
|
} else if (typeof image === 'string') {
|
|
|
|
imageNode = <img alt={alt} src={image} />;
|
|
|
|
} else {
|
|
|
|
imageNode = image;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames(prefixCls, className)} {...restProps}>
|
|
|
|
<div className={`${prefixCls}-image`}>{imageNode}</div>
|
|
|
|
|
|
|
|
<p className={`${prefixCls}-description`}>{des}</p>
|
|
|
|
|
|
|
|
{children && <div className={`${prefixCls}-footer`}>{children}</div>}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</LocaleReceiver>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</ConfigConsumer>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default Empty;
|