Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 1x 1x 1x 1x | import React from "react";
import classNames from "classnames";
import { Icon } from "../icon";
import { Text } from "../text";
import { useTranslation } from "../i18n";
import { StyledProps } from "../_type";
import { useConfig } from "../_util/config-context";
export interface ErrorTipProps extends StyledProps {
/**
* 错误文案
* @default "加载失败"
*/
errorText?: React.ReactNode;
/**
* 重试文案
* @default "重试"
*/
retryText?: React.ReactNode;
/**
* 重试时回调,如果传空,则不进行重试
*/
onRetry?: () => void;
/**
* 隐藏图标
* @default false
*/
hideIcon?: boolean;
}
export function ErrorTip(props: ErrorTipProps) {
const { classPrefix } = useConfig();
const t = useTranslation();
const {
errorText = t.loadErrorText,
retryText = t.loadRetryText,
onRetry,
hideIcon,
className,
style,
} = props;
return (
<span
className={classNames(`${classPrefix}-action-state`, className)}
style={style}
>
{!hideIcon && <Icon type="error" className={`${classPrefix}-mr-2n`} />}
{typeof errorText === "string" ? (
<Text className={`${classPrefix}-action-state__text`} theme="danger">
{errorText}
</Text>
) : (
errorText
)}
{onRetry && (
<>
{" "}
<a
className={`${classPrefix}-action-state__text ${classPrefix}-ml-1n`}
onClick={onRetry}
>
{retryText}
</a>
</>
)}
</span>
);
}
|