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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | 18x 1x 1x | import React from "react"; import { EmptyTip } from "./EmptyTip"; import { LoadingTip } from "./LoadingTip"; import { ErrorTip } from "./ErrorTip"; import { FoundTip } from "./FoundTip"; import { StyledProps } from "../_type"; import { withStatics } from "../_util/with-statics"; export interface StatusTipProps extends StyledProps { status: "empty" | "loading" | "found" | "error"; /** * 空数据提示文案 * @default "暂无数据" */ emptyText?: React.ReactNode; /** * 加载文案 * @default "加载中..." */ loadingText?: React.ReactNode; /** * 错误时的提示文案 * @default "加载失败" */ errorText?: React.ReactNode; /** * 重试文案 * 在 `status = “error"` 且包含 `onRetry` 时展现 * @default "重试" */ retryText?: React.ReactNode; /** * 找到结果时的文案 * @default "找到下列结果" */ foundText?: React.ReactNode; /** * 清空结果提示文案 * 在 `status = found"` 且包含 `onClear` 时展现 * @default "返回原列表" */ clearResultText?: React.ReactNode; /** * `status = "found"` 时,用户点击 `clearResultText` 时回调。如果传空,则不渲染返回操作 */ onClear?: () => void; /** * `status = "error"` 时,用户点击 `retryText` 时回调。如果传空,则不渲染重试操作 */ onRetry?: () => void; /** * 隐藏图标 * @default false */ hideIcon?: boolean; } export const StatusTip = withStatics( function StatusTip({ status, emptyText, loadingText, errorText, foundText, clearResultText, retryText, onClear, onRetry, ...styledProps }: StatusTipProps) { switch (status) { case "loading": return <LoadingTip {...styledProps} loadingText={loadingText} />; case "empty": return <EmptyTip {...styledProps} emptyText={emptyText} />; case "found": return ( <FoundTip {...styledProps} foundText={foundText} onClear={onClear} clearResultText={clearResultText} /> ); case "error": return ( <ErrorTip {...styledProps} errorText={errorText} retryText={retryText} onRetry={onRetry} /> ); } return null; }, { LoadingTip, EmptyTip, FoundTip, ErrorTip, } ); |