# File Icon

> 用带颜色的文件标识区分文档、表格、演示、PDF、媒体与其他常见资源。

网页来源：/components/file-icon

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

`QuireFileIcon` 根据文件名扩展名选择颜色与短标识，无需 IconProvider。它只表示资源类型，不表示上传状态，也不是文件内容校验。

## 常见文件类型

提供 `name`，可选 `mediaType` 作为未知扩展名的回退。支持文档、表格、演示、PDF、OFD、图片、视频、音频、压缩包、代码、网页、Markdown、文本、设计与字体；未知类型使用中性文件标识。OFD 通过 `.ofd` 扩展名或显式 `kind="ofd"` 识别。

### 示例：file-icon/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { QuireFileIcon } from '@quirekit/ui/vue';
const files = ['实施方案.docx', '预算表.xlsx', '季度汇报.pptx', '签署合同.pdf', '电子公文.ofd', '场景照片.png', '会议录屏.mp4', '讲解音频.mp3', '交付资料.zip', '应用入口.ts', '介绍页面.html', '使用说明.md', '运行记录.txt', '界面方案.fig', '品牌字体.woff2', '其他资源.bin'];
</script>
<template>
  <div class="grid grid-cols-2 gap-5 p-qk-surface sm:grid-cols-3" data-file-icons>
    <div v-for="name in files" :key="name" class="flex min-w-0 items-center gap-3">
      <QuireFileIcon :name="name" /><span class="truncate text-qk-compact" :title="name">{{ name }}</span>
    </div>
  </div>
</template>
```

`kind` 可显式覆盖分类；`size` 指定图标宽度，高度按比例保持。图标与可见文件名并列时默认对辅助技术隐藏；独立使用时提供 `label`。这些是 QuireKit 文件类别标识，不是软件品牌徽标。

## 主题与组合

颜色仅用于文件身份，不给整个卡片填充强调色；字母/类型文字提供非颜色线索。可在主题容器设置 `--qk-file-icon-document`、`--qk-file-icon-spreadsheet`、`--qk-file-icon-pdf` 等同名类别变量覆盖颜色。

[Attachments](/raw/components/attachments.md) 与 [FileUpload](/raw/components/file-upload.md) 已使用同一套标识。需要自行组织列表时，可调用 `resolveQuireKitFileIdentity({ name, mediaType })` 获取 `{ kind, badge }`，不必再维护扩展名映射。

## API

### QuireFileIcon

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| name | 否 | — | Filename used to identify a familiar extension, case-insensitively. |
| mediaType | 否 | — | MIME fallback for names without a recognized extension. |
| kind | 否 | — | Explicit host classification, taking precedence over filename and MIME. |
| size | 否 | 32 | Icon width in pixels; height preserves the document silhouette. |
| label | 否 | — | Optional accessible name; omitted when accompanying a visible filename. |

**name**

```ts
string | undefined
```

```ts
undefined | string
```

**mediaType**

```ts
string | undefined
```

```ts
undefined | string
```

**kind**

```ts
QuireKitFileKind | undefined
```

```ts
undefined | "document" | "spreadsheet" | "presentation" | "pdf" | "ofd" | "image" | "video" | "audio" | "archive" | "code" | "web" | "markdown" | "text" | "design" | "font" | "file"
```

**size**

```ts
number | undefined
```

```ts
undefined | number
```

**label**

```ts
string | undefined
```

```ts
undefined | string
```

#### Events

无。

#### Slots

无。

#### 公开实例成员

无。
