แถบความคืบหน้า
ProgressBar
A progress bar on the native progress element, so the value never needs a style attribute. Leave value out when the length is unknown, and the bar moves instead. `warn` is for a figure over a threshold: pair it with text and an icon. `busy` shows the fill is still moving, such as during an upload.
ใช้แสดงความคืบหน้าของงานหนึ่งงาน หรือสัดส่วนที่ใช้ไปของทั้งหมด เช่น งบที่ใช้ไป หรือการอัปโหลดไฟล์ ถ้าไม่รู้ความยาว ไม่ต้องส่ง value แล้วแถบจะเคลื่อนไหว ถ้าเป็นสัดส่วนเดียวในพื้นที่เล็ก ใช้ ProgressRing ถ้าเป็นงบที่มีหลายส่วน เช่น ผูกพันและเบิกจ่าย ใช้ BudgetBar ถ้าเป็นการรอสั้น ๆ ไม่มีตัวเลข ใช้ Spinner
import { ProgressBar } from "@bsru/ui";ตัวอย่าง
รู้ความคืบหน้า
ส่ง value และ label ค่าเริ่มต้นของ max คือ 100 แสดงข้อความและตัวเลขไว้เหนือแถบ
<div className="flex justify-between text-sm">
<span>ใช้งบไปแล้ว</span>
<span className="tabular-nums">62%</span>
</div>
<ProgressBar value={62} label="ใช้งบไปแล้ว" />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| value | 62 | number | How far along, from 0 to max. Leave it out when the length is unknown. |
| label* จำเป็น | "ใช้งบไปแล้ว" | string | Names the bar for screen readers. |
เกินเกณฑ์
warn เปลี่ยนสีแถบ ต้องมีข้อความและไอคอนกำกับด้วย ไม่ใช้สีอย่างเดียว
<div className="flex justify-between text-sm">
<span className="flex items-center gap-1 font-medium">
<Icon icon={TriangleAlert} className="size-4 text-gold-800" />
<span>งบใกล้หมด</span>
</span>
<span className="tabular-nums">91%</span>
</div>
<ProgressBar value={91} warn label="งบใกล้หมด" />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| value | 91 | number | How far along, from 0 to max. Leave it out when the length is unknown. |
| warn | true | boolean | Shows the warning fill, for a figure over a threshold. |
| label* จำเป็น | "งบใกล้หมด" | string | Names the bar for screen readers. |
กำลังทำงาน
busy บอกว่างานยังเดินอยู่ เช่น ระหว่างอัปโหลด เมื่อเสร็จให้ตั้ง busy เป็น false
<ProgressBar value={40} busy label="อัปโหลดไฟล์การชำระเงิน" />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| value | 40 | number | How far along, from 0 to max. Leave it out when the length is unknown. |
| busy | true | boolean | Shows the fill is still moving, such as during an upload. |
| label* จำเป็น | "อัปโหลดไฟล์การชำระเงิน" | string | Names the bar for screen readers. |
ไม่รู้ความยาว
ไม่ส่ง value แถบจะเคลื่อนไปมา
<ProgressBar label="กำลังโหลด" />| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | "กำลังโหลด" | string | Names the bar for screen readers. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| value | number | — | How far along, from 0 to max. Leave it out when the length is unknown. |
| max | number | 100 | The value of a full bar. |
| label* จำเป็น | string | — | Names the bar for screen readers. |
| warn | boolean | false | Shows the warning fill, for a figure over a threshold. |
| busy | boolean | false | Shows the fill is still moving, such as during an upload. |
| className | string | — | Extra classes for the bar, such as spacing. |
ข้อควรปฏิบัติ
- label ต้องมีเสมอ เป็นชื่อของแถบสำหรับโปรแกรมอ่านหน้าจอ
- แถบไม่มีข้อความที่มองเห็นได้ แสดงร้อยละเป็นตัวเลขไว้ใกล้แถบเสมอ
- เมื่อผู้ใช้ตั้งค่าลดการเคลื่อนไหว แถบที่ไม่รู้ความยาวจะหยุดนิ่ง ข้อความกำกับจึงจำเป็น
ซอร์สโค้ด: ui/src/progress.tsx