Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào app đã cài registry.
Trạng thái tải lên
Xong, đang tải lên (tên file lấp lánh), lỗi (viền đỏ và lý do bằng chữ) và chờ (viền nét đứt, chưa gửi). Thao tác là các icon button được tooltip đặt tên.
AttachmentStates.vue
<script setup lang="ts">
import { FileSpreadsheet, FileText, RotateCcw, TriangleAlert, X } from '@lucide/vue'
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentMedia,
AttachmentTitle,
} from '@/components/ui/attachment'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
</script>
<template>
<TooltipProvider>
<div class="flex w-full max-w-100 flex-col gap-(--bh-space-100)">
<Attachment>
<AttachmentMedia><FileText /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>hoa-don-10482.pdf</AttachmentTitle>
<AttachmentDescription>PDF · 184 KB</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<Tooltip relationship="label">
<TooltipTrigger as-child>
<AttachmentAction><X /></AttachmentAction>
</TooltipTrigger>
<TooltipContent>Gỡ hoa-don-10482.pdf</TooltipContent>
</Tooltip>
</AttachmentActions>
</Attachment>
<Attachment state="uploading">
<AttachmentMedia><FileSpreadsheet /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>bang-gia-si.xlsx</AttachmentTitle>
<AttachmentDescription>Đang tải lên · 62%</AttachmentDescription>
</AttachmentContent>
</Attachment>
<Attachment state="error">
<AttachmentMedia><TriangleAlert /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>kiem-kho-mien-bac.csv</AttachmentTitle>
<AttachmentDescription>Tải lên thất bại: file lớn hơn 10 MB.</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<Tooltip relationship="label">
<TooltipTrigger as-child>
<AttachmentAction><RotateCcw /></AttachmentAction>
</TooltipTrigger>
<TooltipContent>Tải lên lại</TooltipContent>
</Tooltip>
</AttachmentActions>
</Attachment>
<Attachment state="idle">
<AttachmentMedia><FileText /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>phieu-giao-hang.pdf</AttachmentTitle>
<AttachmentDescription>Chờ tải lên</AttachmentDescription>
</AttachmentContent>
</Attachment>
</div>
</TooltipProvider>
</template>Ô xếp thành hàng
orientation="vertical" với AttachmentTrigger, để bấm vào cả ô là mở file. Hàng cuộn ngang và dừng đúng từng ô. Tab tới một ô: vòng focus bao quanh ô đó.
AttachmentTiles.vue
<script setup lang="ts">
import { FileSpreadsheet, FileText, Image as ImageIcon, X } from '@lucide/vue'
import {
Attachment,
AttachmentAction,
AttachmentActions,
AttachmentContent,
AttachmentDescription,
AttachmentGroup,
AttachmentMedia,
AttachmentTitle,
AttachmentTrigger,
} from '@/components/ui/attachment'
const files = [
{ name: 'hoa-don-10482.pdf', meta: 'PDF · 184 KB', icon: FileText },
{ name: 'bang-gia.xlsx', meta: 'XLSX · 42 KB', icon: FileSpreadsheet },
{ name: 'anh-san-pham.png', meta: 'PNG · 1,2 MB', icon: ImageIcon },
{ name: 'phieu-giao-hang.pdf', meta: 'PDF · 96 KB', icon: FileText },
]
</script>
<template>
<AttachmentGroup class="w-full max-w-120" role="list" aria-label="File của đơn 10482">
<Attachment v-for="file in files" :key="file.name" orientation="vertical" role="listitem">
<AttachmentTrigger :aria-label="`Mở ${file.name}`" />
<AttachmentMedia><component :is="file.icon" /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>{{ file.name }}</AttachmentTitle>
<AttachmentDescription>{{ file.meta }}</AttachmentDescription>
</AttachmentContent>
<AttachmentActions>
<AttachmentAction :aria-label="`Gỡ ${file.name}`"><X /></AttachmentAction>
</AttachmentActions>
</Attachment>
</AttachmentGroup>
</template>Kích thước
default, sm và xs. Ô hình bằng chiều cao control của từng cỡ: 40, 32 và 24 px.
AttachmentSizes.vue
<script setup lang="ts">
import { FileText } from '@lucide/vue'
import {
Attachment,
AttachmentContent,
AttachmentDescription,
AttachmentMedia,
AttachmentTitle,
} from '@/components/ui/attachment'
const sizes = ['default', 'sm', 'xs'] as const
</script>
<template>
<div class="flex flex-col items-start gap-(--bh-space-150)">
<Attachment v-for="size in sizes" :key="size" :size="size">
<AttachmentMedia><FileText /></AttachmentMedia>
<AttachmentContent>
<AttachmentTitle>hop-dong-crm-2026.pdf</AttachmentTitle>
<AttachmentDescription v-if="size !== 'xs'">PDF · 184 KB</AttachmentDescription>
</AttachmentContent>
</Attachment>
</div>
</template>