แท็บ
Tabs
Tabs for the parts of one record, such as details, items and history. Follows the ARIA tabs pattern: Left and Right move between tabs, Home and End jump to the first and last, and the tab chosen shows at once. Only the chosen tab is in the Tab order, so Tab moves from it into its panel.
ใช้แบ่งส่วนของรายการเดียวในหน้ารายละเอียด เช่น รายละเอียด รายการ ไฟล์แนบ และประวัติ ให้ผู้ใช้ดูทีละส่วน ส่งอาร์เรย์ของแท็บพร้อมเนื้อหา และเก็บแท็บที่เลือกไว้ใน state ของหน้าจอ ถ้าเป็นการเลือกมุมมองหรือตัวกรองของข้อมูลชุดเดียว ใช้ Segmented ถ้าทุกส่วนควรเห็นพร้อมกัน เช่น ในแผงดูเร็ว ใช้ RecordSection
import { Tabs } from "@bsru/ui";ตัวอย่าง
ส่วนของคำขอซื้อ
แต่ละแท็บมี value label และ panel บอกจำนวนในชื่อแท็บเมื่อช่วยให้ตัดสินใจได้ว่าจะเปิดหรือไม่ เนื้อหาของแต่ละแท็บเป็นส่วนประกอบที่รับข้อมูล
- หน่วยงาน
- หน่วยงาน ก
- ผู้ค้า
- บริษัท ตัวอย่าง จำกัด
- รหัสงบประมาณ
- BG-2570-ก-001
- ผู้ขอ
- นายทดสอบ มีสุข
- หมายเหตุ
- ไม่มีข้อมูล
| รายการ | จำนวน | ราคาต่อหน่วย | จำนวนเงิน (บาท) |
|---|---|---|---|
| คอมพิวเตอร์โน้ตบุ๊ก | 5 เครื่อง | 27,000.00 | 135,000.00 |
| กระเป๋าใส่โน้ตบุ๊ก | 5 ใบ | 1,000.00 | 5,000.00 |
| ติดตั้งและตั้งค่าซอฟต์แวร์ | 1 งาน | 10,000.00 | 10,000.00 |
| รวมทั้งสิ้น | 150,000.00 | ||
- ใบเสนอราคา-บริษัทตัวอย่าง.pdf245 KB
- รายละเอียดคุณลักษณะเฉพาะ.pdf1.4 MB
สร้างคำขอ
นายทดสอบ มีสุข, 30 ก.ย. 2569 เวลา 16:05 น.ส่งขออนุมัติ
นายทดสอบ มีสุข, 1 ต.ค. 2569 เวลา 09:12 น.หัวหน้าหน่วยงานอนุมัติ
นางทดสอบ รักงาน, 1 ต.ค. 2569 เวลา 10:40 น.รอรองอธิการบดีที่กำกับอนุมัติ
const [part, setPart] = useState("details");
<Tabs
label="ส่วนของคำขอ"
value={part}
onChange={setPart}
tabs={[
{ value: "details", label: "รายละเอียด", panel: <FieldList fields={fields} /> },
{
value: "items",
label: `รายการ (${items.length})`,
panel: (
<LineItems
caption="รายการในคำขอ PR-2570-0001"
columns={columns}
items={items}
totalLabel="รวมทั้งสิ้น"
total={150000}
/>
),
},
{
value: "files",
label: `ไฟล์แนบ (${files.length})`,
panel: <AttachmentList files={files} downloadLabel="ดาวน์โหลด" />,
},
{ value: "history", label: "ประวัติ", panel: <ApprovalChain levels={history} /> },
]}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | "ส่วนของคำขอ" | string | Names the tab list for screen readers. |
| value* จำเป็น | part | V | The value of the chosen tab. |
| onChange* จำเป็น | setPart | (next: V) => void | Called with the tab's value when someone picks a tab, by click or by arrow key. |
| tabs* จำเป็น | รายการ 4 รายการ[
{
value: "details",
label: "รายละเอียด",
panel: <Component
fields={[
{ label: "หน่วยงาน", value: "หน่วยงาน ก" },
{ label: "ผู้ค้า", value: "บริษัท ตัวอย่าง จำกัด" },
{ label: "รหัสงบประมาณ", value: "BG-2570-ก-001", numeric: true },
{ label: "ผู้ขอ", value: "นายทดสอบ มีสุข" },
{ label: "หมายเหตุ" },
]}
/>,
},
{
value: "items",
label: "รายการ (3)",
panel: <Component
caption="รายการในคำขอ PR-2570-0001"
columns={{
description: "รายการ",
quantity: "จำนวน",
unitPrice: "ราคาต่อหน่วย",
amount: "จำนวนเงิน (บาท)",
}}
items={[
{
key: "1",
description: "คอมพิวเตอร์โน้ตบุ๊ก",
quantity: 5,
unit: "เครื่อง",
unitPrice: 27000,
amount: 135000,
},
{
key: "2",
description: "กระเป๋าใส่โน้ตบุ๊ก",
quantity: 5,
unit: "ใบ",
unitPrice: 1000,
amount: 5000,
},
{
key: "3",
description: "ติดตั้งและตั้งค่าซอฟต์แวร์",
quantity: 1,
unit: "งาน",
unitPrice: 10000,
amount: 10000,
},
]}
totalLabel="รวมทั้งสิ้น"
total={150000}
/>,
},
{
value: "files",
label: "ไฟล์แนบ (2)",
panel: <Component
files={[
{
key: "quote",
name: "ใบเสนอราคา-บริษัทตัวอย่าง.pdf",
size: 250880,
},
{
key: "spec",
name: "รายละเอียดคุณลักษณะเฉพาะ.pdf",
size: 1468006,
},
]}
downloadLabel="ดาวน์โหลด"
onDownload={handleDownload}
/>,
},
{
value: "history",
label: "ประวัติ",
panel: <Component
levels={[
{
state: "done",
title: "สร้างคำขอ",
detail: "นายทดสอบ มีสุข, 30 ก.ย. 2569 เวลา 16:05 น.",
},
{
state: "done",
title: "ส่งขออนุมัติ",
detail: "นายทดสอบ มีสุข, 1 ต.ค. 2569 เวลา 09:12 น.",
},
{
state: "done",
title: "หัวหน้าหน่วยงานอนุมัติ",
detail: "นางทดสอบ รักงาน, 1 ต.ค. 2569 เวลา 10:40 น.",
},
{ state: "current", title: "รอรองอธิการบดีที่กำกับอนุมัติ" },
]}
/>,
},
] | readonly TabItem<V>[] | The tabs, in order. |
สองแท็บ
ใช้แท็บเมื่อมีอย่างน้อยสองส่วน ถ้ามีส่วนเดียวให้แสดงเนื้อหาเลยโดยไม่มีแท็บ
- PR-2570-0001
- รอรองอธิการบดีที่กำกับอนุมัติ
- PR-2570-0005
- รอหัวหน้าหน่วยงานอนุมัติ
- PR-2570-0003
- อนุมัติแล้ว
const [value, setValue] = useState("open");
<Tabs
label="งานของฉัน"
value={value}
onChange={setValue}
tabs={[
{
value: "open",
label: "รอดำเนินการ (2)",
panel: <Component
fields={[
{
label: "PR-2570-0001",
value: "รอรองอธิการบดีที่กำกับอนุมัติ",
},
{ label: "PR-2570-0005", value: "รอหัวหน้าหน่วยงานอนุมัติ" },
]}
/>,
},
{
value: "done",
label: "เสร็จแล้ว (1)",
panel: <Component
fields={[{ label: "PR-2570-0003", value: "อนุมัติแล้ว" }]}
/>,
},
]}
/>| Prop | ค่าในตัวอย่างนี้ | ชนิดข้อมูล | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | "งานของฉัน" | string | Names the tab list for screen readers. |
| value* จำเป็น | value | V | The value of the chosen tab. |
| onChange* จำเป็น | setValue | (next: V) => void | Called with the tab's value when someone picks a tab, by click or by arrow key. |
| tabs* จำเป็น | รายการ 2 รายการ[
{
value: "open",
label: "รอดำเนินการ (2)",
panel: <Component
fields={[
{
label: "PR-2570-0001",
value: "รอรองอธิการบดีที่กำกับอนุมัติ",
},
{ label: "PR-2570-0005", value: "รอหัวหน้าหน่วยงานอนุมัติ" },
]}
/>,
},
{
value: "done",
label: "เสร็จแล้ว (1)",
panel: <Component
fields={[{ label: "PR-2570-0003", value: "อนุมัติแล้ว" }]}
/>,
},
] | readonly TabItem<V>[] | The tabs, in order. |
props ทั้งหมด
ตัวอย่างด้านบนใช้ props เพียงบางตัว ตารางนี้แสดงทุกตัวที่คอมโพเนนต์รับ พร้อมค่าเริ่มต้นและค่าที่ใช้ได้
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| label* จำเป็น | string | — | Names the tab list for screen readers. |
| tabs* จำเป็น | readonly TabItem<V>[] | — | The tabs, in order. |
| value* จำเป็น | V | — | The value of the chosen tab. |
| onChange* จำเป็น | (next: V) => void | — | Called with the tab's value when someone picks a tab, by click or by arrow key. |
| className | string | — | Classes for the wrapper, such as grid column spans. |
ชนิดข้อมูล
TabItem
One tab and the panel it shows.
| ชื่อ | ชนิดข้อมูล | ค่าเริ่มต้น | คำอธิบาย |
|---|---|---|---|
| value* จำเป็น | V | — | Unique among the tabs. The screen keeps the chosen one in state. |
| label* จำเป็น | ReactNode | — | The tab's name, already in the screen language, such as รายการ (3). |
| panel* จำเป็น | ReactNode | — | What the tab shows, such as a FieldList. |
ข้อควรปฏิบัติ
- แป้นพิมพ์: ลูกศรซ้ายขวาย้ายแท็บและแสดงทันที Home และ End ไปแท็บแรกและสุดท้าย Tab ออกจากแถบแท็บเข้าสู่เนื้อหา
- label ตั้งชื่อแถบแท็บให้โปรแกรมอ่านหน้าจอ ส่งในภาษาของหน้าจอ
- value ต้องไม่ซ้ำกัน ถ้า value ไม่ตรงกับแท็บใด แท็บแรกจะถูกเลือก
ซอร์สโค้ด: ui/src/tabs.tsx