Trên trang này

Attachment

Cài đặt, prop và các phần tạo nên Attachment.

Cài đặt

Chạy lệnh này trong app, sau shadcn-vue init và theme Beehexa (Button › Code):

npx shadcn-vue@latest add https://beehexa.design/r/attachment.json

Cách dùng

<script setup lang="ts">
import { FileText, X } from '@lucide/vue'
import {
  Attachment,
  AttachmentAction,
  AttachmentActions,
  AttachmentContent,
  AttachmentDescription,
  AttachmentMedia,
  AttachmentTitle,
  AttachmentTrigger,
} from '@/components/ui/attachment'
</script>

<template>
  <Attachment state="uploading">
    <AttachmentTrigger as-child>
      <a href="/files/hoa-don-10482.pdf"><span class="sr-only">Mở hoa-don-10482.pdf</span></a>
    </AttachmentTrigger>
    <AttachmentMedia><FileText /></AttachmentMedia>
    <AttachmentContent>
      <AttachmentTitle>hoa-don-10482.pdf</AttachmentTitle>
      <AttachmentDescription>Đang tải lên · 62%</AttachmentDescription>
    </AttachmentContent>
    <AttachmentActions>
      <AttachmentAction aria-label="Gỡ hoa-don-10482.pdf"><X /></AttachmentAction>
    </AttachmentActions>
  </Attachment>
</template>

Prop

Phần Prop Giá trị Ghi chú
Attachment state done (mặc định), uploading, processing, error, idle Xem Cách dùng › Trạng thái
Attachment size default, sm, xs Ô hình 40, 32 hoặc 24 px
Attachment orientation horizontal (mặc định), vertical Vertical là một ô có tên bên dưới; thao tác chuyển lên góc
AttachmentMedia variant icon (mặc định), image image lấp đầy ô bằng một img
AttachmentTrigger as, as-child tên phần tử, boolean Mặc định là nút (type="button"); là link khi dùng as-child. Phủ cả card
AttachmentAction variant, size biến thể Button Mặc định ghost và icon-xs (24 px)
AttachmentGroup — — Một hàng cuộn ngang và dừng đúng từng card

attachmentVariants và attachmentMediaVariants được export để dựng phần riêng.

Dựng từ

Các phần tử thường và Button của Beehexa, theo API Attachment của shadcn-vue. Beehexa thêm style. Những khác biệt người dùng sẽ thấy:

  • Vòng focus bao quanh card chỉ khi trigger có focus bàn phím. Thao tác có vòng focus riêng của Button, nên card không hiện vòng thứ hai.
  • Ảnh giữ nguyên độ đậm khi đang tải lên (shadcn-vue làm mờ còn 60%).
  • AttachmentTrigger có import Primitive (file của shadcn-vue thiếu) và đặt type="button", nên không bao giờ gửi form.
  • AttachmentGroup có padding space.050 ở mọi phía, để vòng focus của card đầu và cuối không bị cắt.