ม่านระหว่างบันทึก
Veil
Covers only the busy area, so the rest of the page stays usable. Put it first inside a `relative` container. It stays in the page while hidden, so screen readers hear the label when it appears.
ใช้ครอบส่วนที่กำลังบันทึกหรือคำนวณ เมื่อเนื้อหาแสดงอยู่แล้ว เพื่อกันไม่ให้แก้ระหว่างนั้น ส่วนอื่นของหน้ายังใช้ได้ ถ้ายังไม่มีเนื้อหาให้แสดง ใช้ Skeleton ถ้าเป็นการรอเล็ก ๆ ในบรรทัดเดียว ใช้ Spinner ถ้าต้องหยุดทั้งหน้าจนกว่าจะมีคำตอบ ใช้ Dialog
import { Veil } from "@bsru/ui";ตัวอย่าง
ครอบส่วนที่กำลังบันทึก
ส่ง show และข้อความที่บอกว่ากำลังทำอะไร วาง Veil เป็นลูกตัวแรกของกล่องที่มี relative
ยอดรวมคำขอ
ครอบเฉพาะส่วนที่กำลังทำงาน ส่วนอื่นของหน้ายังใช้ได้
<Veil show>กำลังบันทึก</Veil>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| show* จำเป็น | true | boolean | Whether the area is busy. The screen keeps this in its state. |
เปิดระหว่างทำงาน
เก็บสถานะไว้ใน state ของหน้าจอ ตั้ง show เป็น true เมื่อเริ่ม และ false เมื่อเสร็จหรือผิดพลาด ปิดปุ่มที่สั่งงานซ้ำระหว่างนั้น
ยอดรวมคำขอ
125,400.00 บาท
const [busy, setBusy] = useState(false);
async function recalculate() {
setBusy(true);
try {
await recalculateTotals();
} finally {
setBusy(false);
}
}
<div className="panel relative p-5">
<Veil show={busy}>กำลังคำนวณยอดใหม่</Veil>
<p className="font-semibold">ยอดรวมคำขอ</p>
<p className="text-ink-600 tabular-nums">125,400.00 บาท</p>
<div className="mt-3">
<Button label="คำนวณใหม่" disabled={busy} onClick={recalculate} />
</div>
</div>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| show* จำเป็น | false | boolean | Whether the area is busy. The screen keeps this in its state. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| show* จำเป็น | boolean | — | Whether the area is busy. The screen keeps this in its state. |
| children* จำเป็น | ReactNode | — | What is happening, shown beside the spinner and read by screen readers. |
ข้อควรปฏิบัติ
- Veil มี role status และอยู่ในหน้าตลอดแม้ซ่อนอยู่ โปรแกรมอ่านหน้าจอจึงอ่านข้อความเมื่อแสดงขึ้น อย่าสร้างหรือลบ Veil เอง ให้ส่ง show แทน
- Veil ไม่กันการกด Tab ไปยังปุ่มข้างใต้ ปิดปุ่มและช่องในส่วนนั้นระหว่างทำงานด้วย
- เมื่อเสร็จ บอกผลด้วย Toast
ซอร์สโค้ด: ui/src/progress.tsx