All files / src/upload/preset File.tsx

100% Statements 2/2
66.67% Branches 2/3
100% Functions 1/1
100% Lines 2/2

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                                            1x 1x                            
import React from "react";
import { useConfig } from "../../_util/config-context";
import { Input } from "../../input";
 
export interface FileProps {
  /**
   * 文件名
   */
  filename?: string;
 
  /**
   * 上传进度
   */
  percent?: number;
 
  /**
   * 按钮区域内容
   */
  button?: React.ReactNode;
}
 
export function File({ filename, percent, button }: FileProps) {
  const { classPrefix } = useConfig();
  return (
    <div className={`${classPrefix}-form-upload`}>
      <div className={`${classPrefix}-form-upload__inner`}>
        <Input readonly placeholder={filename} />
        {(percent || percent === 0) && (
          <span className={`${classPrefix}-form__help-text--inline`}>
            {Math.floor(percent)}%
          </span>
        )}
      </div>
      {button}
    </div>
  );
}