ข้ามไปยังเนื้อหา

แถบความคืบหน้า

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 แสดงข้อความและตัวเลขไว้เหนือแถบ

ใช้งบไปแล้ว62%
<div className="flex justify-between text-sm">
  <span>ใช้งบไปแล้ว</span>
  <span className="tabular-nums">62%</span>
</div>
<ProgressBar value={62} label="ใช้งบไปแล้ว" />

เกินเกณฑ์

warn เปลี่ยนสีแถบ ต้องมีข้อความและไอคอนกำกับด้วย ไม่ใช้สีอย่างเดียว

งบใกล้หมด91%
<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="งบใกล้หมด" />

กำลังทำงาน

busy บอกว่างานยังเดินอยู่ เช่น ระหว่างอัปโหลด เมื่อเสร็จให้ตั้ง busy เป็น false

อัปโหลดไฟล์การชำระเงิน40%
<ProgressBar value={40} busy label="อัปโหลดไฟล์การชำระเงิน" />

ไม่รู้ความยาว

ไม่ส่ง value แถบจะเคลื่อนไปมา

กำลังโหลด ไม่ทราบเวลา
<ProgressBar label="กำลังโหลด" />

props ทั้งหมด

ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้

ProgressBar props
ชื่อชนิดข้อมูลค่าเริ่มต้นคำอธิบาย
valuenumber—How far along, from 0 to max. Leave it out when the length is unknown.
maxnumber100The value of a full bar.
label* จำเป็นstring—Names the bar for screen readers.
warnbooleanfalseShows the warning fill, for a figure over a threshold.
busybooleanfalseShows the fill is still moving, such as during an upload.
classNamestring—Extra classes for the bar, such as spacing.

ข้อควรปฏิบัติ

  • label ต้องมีเสมอ เป็นชื่อของแถบสำหรับโปรแกรมอ่านหน้าจอ
  • แถบไม่มีข้อความที่มองเห็นได้ แสดงร้อยละเป็นตัวเลขไว้ใกล้แถบเสมอ
  • เมื่อผู้ใช้ตั้งค่าลดการเคลื่อนไหว แถบที่ไม่รู้ความยาวจะหยุดนิ่ง ข้อความกำกับจึงจำเป็น

ซอร์สโค้ด: ui/src/progress.tsx