显示文件类型图标
npm i --save @kne/react-file-type根据文件后缀名显示对应的文件图标组件,支持 18 种常见文件格式。
- 基本用法
- 支持18种文件格式,包括:doc | docx | gif | html | jpg | md | mp4 | pdf | png | ppt | pptx | rar | svg | txt | xls | xlsx | zip
- fileType(@kne/current-lib_react-file-type),space(antd/lib/space)
const { default: FileType } = fileType;
const { default: Space } = space;
const BaseExample = () => {
return (
<Space direction="vertical" size="large">
<div>
<div style={{ marginBottom: 12, fontWeight: 'bold' }}>支持的文件格式:</div>
<Space wrap>
<FileType type="doc" />
<FileType type="docx" />
<FileType type="gif" />
<FileType type="html" />
<FileType type="jpg" />
<FileType type="md" />
<FileType type="mp4" />
<FileType type="pdf" />
<FileType type="png" />
<FileType type="ppt" />
<FileType type="pptx" />
<FileType type="rar" />
<FileType type="svg" />
<FileType type="txt" />
<FileType type="xls" />
<FileType type="xlsx" />
<FileType type="zip" />
</Space>
</div>
<div>
<div style={{ marginBottom: 12, fontWeight: 'bold' }}>自定义尺寸:</div>
<Space>
<FileType type="doc" size={30} />
<FileType type="doc" size={40} />
<FileType type="doc" size={50} />
<FileType type="doc" size={60} />
</Space>
</div>
<div>
<div style={{ marginBottom: 12, fontWeight: 'bold' }}>不支持的文件格式:</div>
<FileType type="msg" />
</div>
</Space>
);
};
render(<BaseExample />);| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| type | 文件后缀名 | string | unknow |
| size | 图标大小 | number | 40 |
doc- Word 文档docx- Word 文档gif- GIF 图片html- HTML 文件jpg- JPG 图片md- Markdown 文件mp4- MP4 视频pdf- PDF 文档png- PNG 图片ppt- PowerPoint 演示文稿pptx- PowerPoint 演示文稿rar- RAR 压缩包svg- SVG 矢量图txt- 纯文本文件xls- Excel 表格xlsx- Excel 表格zip- ZIP 压缩包
其他不支持的文件类型将显示为通用图标。