All files / src/tips FoundTip.tsx

100% Statements 4/4
83.33% Branches 5/6
100% Functions 1/1
100% Lines 4/4

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                                                    1x 1x             1x 1x                                                
import React from "react";
import classNames from "classnames";
import { useTranslation } from "../i18n";
import { StyledProps } from "../_type";
import { useConfig } from "../_util/config-context";
 
export interface FoundTipProps extends StyledProps {
  /**
   * 找到结果的文案
   * @default "找到下列结果"
   */
  foundText?: React.ReactNode;
 
  /**
   * 清空结果提示文案
   * @default "返回原列表"
   */
  clearResultText?: React.ReactNode;
 
  /**
   * 返回原列表时回调,如果不传则不渲染此操作
   */
  onClear?: () => void;
}
 
export function FoundTip(props: FoundTipProps) {
  const { classPrefix } = useConfig();
  const t = useTranslation();
  const {
    foundText = t.foundText,
    clearResultText = t.clearResultText,
    onClear,
    className,
    style,
  } = props;
  return (
    <span
      className={classNames(`${classPrefix}-action-state`, className)}
      style={style}
    >
      {typeof foundText === "string" ? (
        <span className={`${classPrefix}-action-state__text`}>{foundText}</span>
      ) : (
        foundText
      )}
      {onClear && (
        <>
          {" "}
          <a
            className={`${classPrefix}-action-state__text ${classPrefix}-ml-1n`}
            onClick={onClear}
          >
            {clearResultText}
          </a>
        </>
      )}
    </span>
  );
}