ไฟล์แนบ
AttachmentList
The files attached to a record, each with its size and a download button. `downloadLabel` comes before the name.
ใช้แสดงไฟล์ที่แนบกับรายการ พร้อมขนาดและปุ่มดาวน์โหลด ส่งชื่อไฟล์และขนาดเป็นไบต์ ส่วนประกอบแสดงขนาดเป็น KB หรือ MB เอง ถ้าผู้ใช้ต้องแนบไฟล์ใหม่ ใช้ FileDrop
import { AttachmentList } from "@bsru/ui";ตัวอย่าง
ไฟล์ของคำขอ
href ชี้ไปที่ Route Handler สำหรับดาวน์โหลดของแอป ห้ามใส่ลิงก์ที่มี token หน้าเอกสารนี้ไม่มี route นั้น จึงปิดการกดลิงก์ไว้
<AttachmentList
files={[
{
key: "quote",
name: "ใบเสนอราคา-บริษัทตัวอย่าง.pdf",
size: 250880,
href: "/api/requests/PR-2570-0001/files/quote",
},
{
key: "spec",
name: "รายละเอียดคุณลักษณะเฉพาะ.pdf",
size: 1468006,
href: "/api/requests/PR-2570-0001/files/spec",
},
]}
downloadLabel="ดาวน์โหลด"
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| files* จำเป็น | รายการ 2 รายการ[
{
key: "quote",
name: "ใบเสนอราคา-บริษัทตัวอย่าง.pdf",
size: 250880,
href: "/api/requests/PR-2570-0001/files/quote",
},
{
key: "spec",
name: "รายละเอียดคุณลักษณะเฉพาะ.pdf",
size: 1468006,
href: "/api/requests/PR-2570-0001/files/spec",
},
] | readonly Attachment[] | The files, in the order to show them. |
| downloadLabel* จำเป็น | "ดาวน์โหลด" | string | Such as ดาวน์โหลด, read with the file name by screen readers. |
| onDownload | ไม่ได้ส่งในตัวอย่างนี้ | (file: Attachment) => void | Called for a file without href, such as in a mock. |
ไฟล์จำลองในต้นแบบ
ไฟล์ที่ไม่มี href เรียก onDownload แทน ใช้ในต้นแบบหรือการทดสอบ ลองกดปุ่มดาวน์โหลด
- ใบเสนอราคา-บริษัทตัวอย่าง.pdf245 KB
- รายละเอียดคุณลักษณะเฉพาะ.pdf1.4 MB
<AttachmentList
files={[
{
key: "quote",
name: "ใบเสนอราคา-บริษัทตัวอย่าง.pdf",
size: 250880,
},
{ key: "spec", name: "รายละเอียดคุณลักษณะเฉพาะ.pdf", size: 1468006 },
]}
downloadLabel="ดาวน์โหลด"
onDownload={handleDownload}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| files* จำเป็น | รายการ 2 รายการ[
{ key: "quote", name: "ใบเสนอราคา-บริษัทตัวอย่าง.pdf", size: 250880 },
{ key: "spec", name: "รายละเอียดคุณลักษณะเฉพาะ.pdf", size: 1468006 },
] | readonly Attachment[] | The files, in the order to show them. |
| downloadLabel* จำเป็น | "ดาวน์โหลด" | string | Such as ดาวน์โหลด, read with the file name by screen readers. |
| onDownload | handleDownload | (file: Attachment) => void | Called for a file without href, such as in a mock. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| files* จำเป็น | readonly Attachment[] | — | The files, in the order to show them. |
| downloadLabel* จำเป็น | string | — | Such as ดาวน์โหลด, read with the file name by screen readers. |
| onDownload | (file: Attachment) => void | — | Called for a file without href, such as in a mock. |
ชนิดข้อมูล
Attachment
One file attached to a record.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| key* จำเป็น | string | — | Unique among the files. |
| name* จำเป็น | string | — | The file name, with its extension. |
| size* จำเป็น | number | — | Size in bytes. |
| href | string | — | The app's download Route Handler, never a link with a token in it. |
ข้อควรปฏิบัติ
- downloadLabel อ่านคู่กับชื่อไฟล์ เช่น ดาวน์โหลด ใบเสนอราคา.pdf ส่งในภาษาของหน้าจอ
- ตรวจสิทธิ์ที่ Route Handler ทุกครั้งที่ดาวน์โหลด ไม่ใช่แค่ซ่อนปุ่ม
- ชื่อไฟล์ยาวถูกตัดด้วย … ในแถวเดียว ขนาดไฟล์ใช้ fileSize() ถ้าต้องแสดงที่อื่น
ซอร์สโค้ด: ui/src/record.tsx