Structured list
Structured list แสดงข้อความไม่กี่แถวเป็นคอลัมน์ เช่น เปรียบเทียบแพ็กเกจ หรือแสดงเงื่อนไขของสัญญา เบากว่า data table คือไม่มีการเรียงลำดับและไม่มี toolbar ถ้าใส่ selection ผู้ใช้จะเลือกได้หนึ่งแถว
แพ็กเกจ
ผู้ใช้
ราคา
สิ่งที่ได้
พื้นฐาน
ไม่เกิน 5 คน
ฟรี
แม่แบบใช้ร่วมกัน เก็บประวัติการใช้งาน 30 วัน
ทีม
ไม่เกิน 50 คน
฿390 / คน
ขั้นตอนอนุมัติ SSO เก็บประวัติการใช้งาน 1 ปี
องค์กร
ไม่จำกัด
ติดต่อฝ่ายขาย
เลือก region เอง กำหนดระยะเก็บข้อมูลเอง มี SLA
HTMLReactReact + Tailwind<ui-structured-list label="แพ็กเกจ">
<ui-structured-list-row head>
<ui-structured-list-cell>แพ็กเกจ</ui-structured-list-cell>
<ui-structured-list-cell>ผู้ใช้</ui-structured-list-cell>
<ui-structured-list-cell>ราคา</ui-structured-list-cell>
<ui-structured-list-cell>สิ่งที่ได้</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>พื้นฐาน</ui-structured-list-cell>
<ui-structured-list-cell>ไม่เกิน 5 คน</ui-structured-list-cell>
<ui-structured-list-cell>ฟรี</ui-structured-list-cell>
<ui-structured-list-cell>แม่แบบใช้ร่วมกัน เก็บประวัติการใช้งาน 30 วัน</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>ทีม</ui-structured-list-cell>
<ui-structured-list-cell>ไม่เกิน 50 คน</ui-structured-list-cell>
<ui-structured-list-cell>฿390 / คน</ui-structured-list-cell>
<ui-structured-list-cell>ขั้นตอนอนุมัติ SSO เก็บประวัติการใช้งาน 1 ปี</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>องค์กร</ui-structured-list-cell>
<ui-structured-list-cell>ไม่จำกัด</ui-structured-list-cell>
<ui-structured-list-cell>ติดต่อฝ่ายขาย</ui-structured-list-cell>
<ui-structured-list-cell>เลือก region เอง กำหนดระยะเก็บข้อมูลเอง มี SLA</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<UiStructuredList label="แพ็กเกจ">
<UiStructuredListRow head>
<UiStructuredListCell>แพ็กเกจ</UiStructuredListCell>
<UiStructuredListCell>ผู้ใช้</UiStructuredListCell>
<UiStructuredListCell>ราคา</UiStructuredListCell>
<UiStructuredListCell>สิ่งที่ได้</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>พื้นฐาน</UiStructuredListCell>
<UiStructuredListCell>ไม่เกิน 5 คน</UiStructuredListCell>
<UiStructuredListCell>ฟรี</UiStructuredListCell>
<UiStructuredListCell>แม่แบบใช้ร่วมกัน เก็บประวัติการใช้งาน 30 วัน</UiStructuredListCell>
</UiStructuredListRow>
{/* … ทีม, องค์กร */}
</UiStructuredList>
<StructuredList label="แพ็กเกจ">
<StructuredListRow head>
<StructuredListCell>แพ็กเกจ</StructuredListCell>
<StructuredListCell>ผู้ใช้</StructuredListCell>
<StructuredListCell>ราคา</StructuredListCell>
<StructuredListCell>สิ่งที่ได้</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>พื้นฐาน</StructuredListCell>
<StructuredListCell>ไม่เกิน 5 คน</StructuredListCell>
<StructuredListCell>ฟรี</StructuredListCell>
<StructuredListCell>แม่แบบใช้ร่วมกัน เก็บประวัติการใช้งาน 30 วัน</StructuredListCell>
</StructuredListRow>
{/* … ทีม, องค์กร */}
</StructuredList>
ติดตั้ง
npmshadcn · Web componentshadcn · React + Tailwindคัดลอกเองnpm install @purpurabog/ui
npx shadcn@4 add @kanok-ui/structured-list
npx shadcn@4 add @kanok-ui/tw-structured-list
# Web component
# 1. ติดตั้ง dependency
npm install lit@^3.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/structured-list.json
# ไปไว้ที่ target ของมัน:
# components/ui/primitives/structured-list/structured-list-cell.ts
# components/ui/primitives/structured-list/structured-list-row.ts
# components/ui/primitives/structured-list/structured-list-skeleton.ts
# components/ui/primitives/structured-list/structured-list.ts
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# core-roving, shared-element, shared-field, shared-localize, shared-skeleton, tokens
# React + Tailwind
# 1. ติดตั้ง dependency
npm install @purpurabog/ui@^2.3.0
# 2. คัดลอก "content" ของแต่ละไฟล์จาก
# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-structured-list.json
# ไปไว้ที่ target ของมัน:
# components/ui/react-tw/structured-list.tsx
# 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json):
# tw-i18n, tw-refs, tw-theme, tw-utils
npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง
วิธีใช้
HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/structured-list';</script>
<ui-structured-list label="เงื่อนไขสัญญา">
<ui-structured-list-row head>
<ui-structured-list-cell>หัวข้อ</ui-structured-list-cell>
<ui-structured-list-cell>ค่า</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell>ระยะเวลา</ui-structured-list-cell>
<ui-structured-list-cell>12 เดือน</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
import { UiStructuredList, UiStructuredListRow, UiStructuredListCell } from '@purpurabog/ui/react';
<UiStructuredList label="เงื่อนไขสัญญา">
<UiStructuredListRow head>
<UiStructuredListCell>หัวข้อ</UiStructuredListCell>
<UiStructuredListCell>ค่า</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell>ระยะเวลา</UiStructuredListCell>
<UiStructuredListCell>12 เดือน</UiStructuredListCell>
</UiStructuredListRow>
</UiStructuredList>
import { StructuredList, StructuredListRow, StructuredListCell } from '@/components/ui/react-tw/structured-list';
<StructuredList label="เงื่อนไขสัญญา">
<StructuredListRow head>
<StructuredListCell>หัวข้อ</StructuredListCell>
<StructuredListCell>ค่า</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell>ระยะเวลา</StructuredListCell>
<StructuredListCell>12 เดือน</StructuredListCell>
</StructuredListRow>
</StructuredList>
Structured list หรือ data table?
| Component |
ใช้เมื่อ |
| Structured list |
มีไม่กี่แถวให้อ่าน เปรียบเทียบ หรือเลือกหนึ่งแถว ข้อความในเซลล์ตัดบรรทัดได้และใส่อะไรก็ได้ |
| Data table |
มีหลายแถว ผู้ใช้ต้องเรียงลำดับ ค้นหา เลือกหลายแถว หรือเปลี่ยนหน้า |
| Contained list |
รายการคอลัมน์เดียว แต่ละรายการมีปุ่มของตัวเอง อยู่ใน panel หรือ tile |
แถวหัวตาราง
head ที่แถวแรกทำให้เซลล์ในแถวนั้นเป็นหัวคอลัมน์ (ตัวหนา, columnheader) ไม่ต้องใส่ถ้าเป็นรายการคู่ ชื่อ–ค่า ที่คอลัมน์แรกบอกอยู่แล้วว่าแต่ละแถวคืออะไร
คู่สัญญา
บริษัท เอซีเอ็ม จำกัด
ลงนามเมื่อ
30 กันยายน 2569
ผู้รับผิดชอบ
ฝ่ายกฎหมาย คุณสมชาย ก.
HTMLReactReact + Tailwind<ui-structured-list label="สรุปสัญญา">
<ui-structured-list-row>
<ui-structured-list-cell nowrap>คู่สัญญา</ui-structured-list-cell>
<ui-structured-list-cell>บริษัท เอซีเอ็ม จำกัด</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>ลงนามเมื่อ</ui-structured-list-cell>
<ui-structured-list-cell>30 กันยายน 2569</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>ผู้รับผิดชอบ</ui-structured-list-cell>
<ui-structured-list-cell>ฝ่ายกฎหมาย คุณสมชาย ก.</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<UiStructuredList label="สรุปสัญญา">
<UiStructuredListRow>
<UiStructuredListCell nowrap>คู่สัญญา</UiStructuredListCell>
<UiStructuredListCell>บริษัท เอซีเอ็ม จำกัด</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>ลงนามเมื่อ</UiStructuredListCell>
<UiStructuredListCell>30 กันยายน 2569</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>ผู้รับผิดชอบ</UiStructuredListCell>
<UiStructuredListCell>ฝ่ายกฎหมาย คุณสมชาย ก.</UiStructuredListCell>
</UiStructuredListRow>
</UiStructuredList>
<StructuredList label="สรุปสัญญา">
<StructuredListRow>
<StructuredListCell nowrap>คู่สัญญา</StructuredListCell>
<StructuredListCell>บริษัท เอซีเอ็ม จำกัด</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>ลงนามเมื่อ</StructuredListCell>
<StructuredListCell>30 กันยายน 2569</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>ผู้รับผิดชอบ</StructuredListCell>
<StructuredListCell>ฝ่ายกฎหมาย คุณสมชาย ก.</StructuredListCell>
</StructuredListRow>
</StructuredList>
ข้อความยาวและ nowrap
ข้อความในเซลล์ตัดบรรทัดเอง แต่ละเซลล์กว้างได้ถึง 576px nowrap ทำให้เซลล์อยู่บรรทัดเดียว ใช้กับเซลล์สั้น ๆ อย่างชื่อหรือจำนวนเงิน เซลล์ยาวข้าง ๆ จะตัดบรรทัดแทน
ข้อ
สรุป
5.1 การชำระเงิน
ผู้ว่าจ้างชำระใบแจ้งหนี้ภายใน 30 วันนับจากวันที่ได้รับ ถ้าชำระช้าคิดดอกเบี้ยร้อยละ 1.25 ต่อเดือนของยอดที่ค้าง
9.2 การเลิกสัญญา
คู่สัญญาฝ่ายใดก็เลิกสัญญาได้โดยแจ้งเป็นหนังสือล่วงหน้า 60 วัน งานที่ทำไปแล้วจ่ายตามอัตราที่ตกลงกัน
HTMLReactReact + Tailwind<ui-structured-list label="ข้อสัญญา">
<ui-structured-list-row head>
<ui-structured-list-cell>ข้อ</ui-structured-list-cell>
<ui-structured-list-cell>สรุป</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>5.1 การชำระเงิน</ui-structured-list-cell>
<ui-structured-list-cell>ผู้ว่าจ้างชำระใบแจ้งหนี้ภายใน 30 วันนับจากวันที่ได้รับ ถ้าชำระช้าคิดดอกเบี้ยร้อยละ 1.25 ต่อเดือนของยอดที่ค้าง</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>9.2 การเลิกสัญญา</ui-structured-list-cell>
<ui-structured-list-cell>คู่สัญญาฝ่ายใดก็เลิกสัญญาได้โดยแจ้งเป็นหนังสือล่วงหน้า 60 วัน งานที่ทำไปแล้วจ่ายตามอัตราที่ตกลงกัน</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<UiStructuredList label="ข้อสัญญา">
<UiStructuredListRow head>
<UiStructuredListCell>ข้อ</UiStructuredListCell>
<UiStructuredListCell>สรุป</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>5.1 การชำระเงิน</UiStructuredListCell>
<UiStructuredListCell>ผู้ว่าจ้างชำระใบแจ้งหนี้ภายใน 30 วันนับจากวันที่ได้รับ …</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>9.2 การเลิกสัญญา</UiStructuredListCell>
<UiStructuredListCell>คู่สัญญาฝ่ายใดก็เลิกสัญญาได้โดยแจ้งเป็นหนังสือล่วงหน้า 60 วัน …</UiStructuredListCell>
</UiStructuredListRow>
</UiStructuredList>
<StructuredList label="ข้อสัญญา">
<StructuredListRow head>
<StructuredListCell>ข้อ</StructuredListCell>
<StructuredListCell>สรุป</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>5.1 การชำระเงิน</StructuredListCell>
<StructuredListCell>ผู้ว่าจ้างชำระใบแจ้งหนี้ภายใน 30 วันนับจากวันที่ได้รับ …</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>9.2 การเลิกสัญญา</StructuredListCell>
<StructuredListCell>คู่สัญญาฝ่ายใดก็เลิกสัญญาได้โดยแจ้งเป็นหนังสือล่วงหน้า 60 วัน …</StructuredListCell>
</StructuredListRow>
</StructuredList>
แบบกระชับ
condensed ลด padding ของเซลล์ลงครึ่งหนึ่ง (condensed list ของ Carbon) ใช้เมื่อมีแถวสั้น ๆ หลายแถว เช่น ใน side panel
ชื่อ
บทบาท
ลงนาม
อนันต์ พ.
กรรมการผู้จัดการ
1 ต.ค. 2569
กัญญา ศ.
ที่ปรึกษากฎหมาย
2 ต.ค. 2569
สมชาย ด.
พยาน
—
HTMLReactReact + Tailwind<ui-structured-list label="ผู้ลงนาม" condensed>
<ui-structured-list-row head>
<ui-structured-list-cell>ชื่อ</ui-structured-list-cell>
<ui-structured-list-cell>บทบาท</ui-structured-list-cell>
<ui-structured-list-cell>ลงนาม</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell>อนันต์ พ.</ui-structured-list-cell>
<ui-structured-list-cell>กรรมการผู้จัดการ</ui-structured-list-cell>
<ui-structured-list-cell>1 ต.ค. 2569</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell>กัญญา ศ.</ui-structured-list-cell>
<ui-structured-list-cell>ที่ปรึกษากฎหมาย</ui-structured-list-cell>
<ui-structured-list-cell>2 ต.ค. 2569</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell>สมชาย ด.</ui-structured-list-cell>
<ui-structured-list-cell>พยาน</ui-structured-list-cell>
<ui-structured-list-cell>—</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<UiStructuredList label="ผู้ลงนาม" condensed>
<UiStructuredListRow head>
<UiStructuredListCell>ชื่อ</UiStructuredListCell>
<UiStructuredListCell>บทบาท</UiStructuredListCell>
<UiStructuredListCell>ลงนาม</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell>อนันต์ พ.</UiStructuredListCell>
<UiStructuredListCell>กรรมการผู้จัดการ</UiStructuredListCell>
<UiStructuredListCell>1 ต.ค. 2569</UiStructuredListCell>
</UiStructuredListRow>
{/* … */}
</UiStructuredList>
<StructuredList label="ผู้ลงนาม" condensed>
<StructuredListRow head>
<StructuredListCell>ชื่อ</StructuredListCell>
<StructuredListCell>บทบาท</StructuredListCell>
<StructuredListCell>ลงนาม</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell>อนันต์ พ.</StructuredListCell>
<StructuredListCell>กรรมการผู้จัดการ</StructuredListCell>
<StructuredListCell>1 ต.ค. 2569</StructuredListCell>
</StructuredListRow>
{/* … */}
</StructuredList>
ชิดขอบ (flush)
flush เอา padding หน้าคอลัมน์แรกออก ข้อความจึงตรงกับหัวข้อหรือข้อความด้านบน ไม่มีผลเมื่อใส่ selection เพราะคอลัมน์ radio ต้องใช้ padding นี้
การออกใบแจ้งหนี้
ออกในนาม
ฝ่ายบัญชีเจ้าหนี้ บริษัท เอซีเอ็ม จำกัด
เลขประจำตัวผู้เสียภาษี
0105556012345
HTMLReactReact + Tailwind<div>
<p style="margin: 0 0 8px; font: var(--ui-font-body-emphasis)">การออกใบแจ้งหนี้</p>
<ui-structured-list label="การออกใบแจ้งหนี้" flush>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>ออกในนาม</ui-structured-list-cell>
<ui-structured-list-cell>ฝ่ายบัญชีเจ้าหนี้ บริษัท เอซีเอ็ม จำกัด</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row>
<ui-structured-list-cell nowrap>เลขประจำตัวผู้เสียภาษี</ui-structured-list-cell>
<ui-structured-list-cell>0105556012345</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
</div>
<h3>การออกใบแจ้งหนี้</h3>
<UiStructuredList label="การออกใบแจ้งหนี้" flush>
<UiStructuredListRow>
<UiStructuredListCell nowrap>ออกในนาม</UiStructuredListCell>
<UiStructuredListCell>ฝ่ายบัญชีเจ้าหนี้ บริษัท เอซีเอ็ม จำกัด</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow>
<UiStructuredListCell nowrap>เลขประจำตัวผู้เสียภาษี</UiStructuredListCell>
<UiStructuredListCell>0105556012345</UiStructuredListCell>
</UiStructuredListRow>
</UiStructuredList>
<h3>การออกใบแจ้งหนี้</h3>
<StructuredList label="การออกใบแจ้งหนี้" flush>
<StructuredListRow>
<StructuredListCell nowrap>ออกในนาม</StructuredListCell>
<StructuredListCell>ฝ่ายบัญชีเจ้าหนี้ บริษัท เอซีเอ็ม จำกัด</StructuredListCell>
</StructuredListRow>
<StructuredListRow>
<StructuredListCell nowrap>เลขประจำตัวผู้เสียภาษี</StructuredListCell>
<StructuredListCell>0105556012345</StructuredListCell>
</StructuredListRow>
</StructuredList>
เลือกหนึ่งแถว
selection ทำให้แถวในตัวตารางเป็นตัวเลือกเดียว แต่ละแถวมี radio ในเซลล์แรก คลิกตรงไหนของแถวก็ได้ หรือกด Space หรือปุ่มลูกศรเพื่อเลือก ใส่ value ให้ทุกแถว value ของ list คือแถวที่เลือกอยู่ และ ui-change (onChange ใน React + Tailwind) ยิงเมื่อผู้ใช้เลือกแถวอื่น
แพ็กเกจ
ผู้ใช้
ราคา
พื้นฐาน
ไม่เกิน 5 คน
ฟรี
ทีม
ไม่เกิน 50 คน
฿390 / คน
องค์กร
ไม่จำกัด
ติดต่อฝ่ายขาย
ค่า:
HTMLReactReact + Tailwind<ui-structured-list id="structured-list-plan" label="เลือกแพ็กเกจ" selection value="team">
<ui-structured-list-row head>
<ui-structured-list-cell>แพ็กเกจ</ui-structured-list-cell>
<ui-structured-list-cell>ผู้ใช้</ui-structured-list-cell>
<ui-structured-list-cell>ราคา</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="basic">
<ui-structured-list-cell>พื้นฐาน</ui-structured-list-cell>
<ui-structured-list-cell>ไม่เกิน 5 คน</ui-structured-list-cell>
<ui-structured-list-cell>ฟรี</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="team">
<ui-structured-list-cell>ทีม</ui-structured-list-cell>
<ui-structured-list-cell>ไม่เกิน 50 คน</ui-structured-list-cell>
<ui-structured-list-cell>฿390 / คน</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="enterprise">
<ui-structured-list-cell>องค์กร</ui-structured-list-cell>
<ui-structured-list-cell>ไม่จำกัด</ui-structured-list-cell>
<ui-structured-list-cell>ติดต่อฝ่ายขาย</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<p>ค่า: <output id="structured-list-plan-out">team</output></p>
<script type="module">
const list = document.getElementById('structured-list-plan');
const out = document.getElementById('structured-list-plan-out');
list.addEventListener('ui-change', (event) => (out.value = event.detail.value));
</script>
const [plan, setPlan] = useState('team');
<UiStructuredList label="เลือกแพ็กเกจ" selection value={plan} onUiChange={(e) => setPlan(e.detail.value)}>
<UiStructuredListRow head>
<UiStructuredListCell>แพ็กเกจ</UiStructuredListCell>
<UiStructuredListCell>ผู้ใช้</UiStructuredListCell>
<UiStructuredListCell>ราคา</UiStructuredListCell>
</UiStructuredListRow>
<UiStructuredListRow value="basic">
<UiStructuredListCell>พื้นฐาน</UiStructuredListCell>
<UiStructuredListCell>ไม่เกิน 5 คน</UiStructuredListCell>
<UiStructuredListCell>ฟรี</UiStructuredListCell>
</UiStructuredListRow>
{/* … team, enterprise */}
</UiStructuredList>
<p>ค่า: <output>{plan}</output></p>
const [plan, setPlan] = useState('team');
<StructuredList label="เลือกแพ็กเกจ" selection value={plan} onChange={setPlan}>
<StructuredListRow head>
<StructuredListCell>แพ็กเกจ</StructuredListCell>
<StructuredListCell>ผู้ใช้</StructuredListCell>
<StructuredListCell>ราคา</StructuredListCell>
</StructuredListRow>
<StructuredListRow value="basic">
<StructuredListCell>พื้นฐาน</StructuredListCell>
<StructuredListCell>ไม่เกิน 5 คน</StructuredListCell>
<StructuredListCell>ฟรี</StructuredListCell>
</StructuredListRow>
{/* … team, enterprise */}
</StructuredList>
<p>ค่า: <output>{plan}</output></p>
React + Tailwind รับ defaultValue สำหรับ list ที่ไม่ควบคุมค่าเองได้ด้วย ถ้าไม่มี value (หรือไม่มีแถวไหนมีค่านั้น) จะไม่มีแถวที่ถูกเลือก และ Tab จะหยุดที่แถวแรก
เปลี่ยนตัวเลือกจากโค้ด
ตั้ง value เพื่อเลือกแถวจากโค้ดของคุณเอง เช่น จากปุ่ม "ใช้วิธีที่แนะนำ" การตั้งค่าแบบนี้ไม่ยิง ui-change event นั้นมีไว้สำหรับการเลือกของผู้ใช้เท่านั้น
วิธีส่ง
ถึงภายใน
PDF ที่ลงนามแล้วทางอีเมล
วันนี้
ไปรษณีย์ลงทะเบียน
3–5 วัน
แมสเซนเจอร์
วันถัดไป
ใช้วิธีที่แนะนำ
ล้าง
HTMLReactReact + Tailwind<ui-structured-list id="structured-list-method" label="วิธีส่งเอกสาร" selection condensed>
<ui-structured-list-row head>
<ui-structured-list-cell>วิธีส่ง</ui-structured-list-cell>
<ui-structured-list-cell>ถึงภายใน</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="email">
<ui-structured-list-cell>PDF ที่ลงนามแล้วทางอีเมล</ui-structured-list-cell>
<ui-structured-list-cell>วันนี้</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="post">
<ui-structured-list-cell>ไปรษณีย์ลงทะเบียน</ui-structured-list-cell>
<ui-structured-list-cell>3–5 วัน</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="courier">
<ui-structured-list-cell>แมสเซนเจอร์</ui-structured-list-cell>
<ui-structured-list-cell>วันถัดไป</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center">
<ui-button id="structured-list-method-recommend" kind="tertiary" size="sm">ใช้วิธีที่แนะนำ</ui-button>
<ui-button id="structured-list-method-clear" kind="ghost" size="sm">ล้าง</ui-button>
</div>
<script type="module">
const list = document.getElementById('structured-list-method');
document.getElementById('structured-list-method-recommend').addEventListener('click', () => (list.value = 'email'));
document.getElementById('structured-list-method-clear').addEventListener('click', () => (list.value = ''));
</script>
const [method, setMethod] = useState('');
<UiStructuredList label="วิธีส่งเอกสาร" selection condensed value={method} onUiChange={(e) => setMethod(e.detail.value)}>
{/* แถวหัว แล้วตามด้วยแถว value="email", "post", "courier" */}
</UiStructuredList>
<UiButton kind="tertiary" size="sm" onClick={() => setMethod('email')}>ใช้วิธีที่แนะนำ</UiButton>
<UiButton kind="ghost" size="sm" onClick={() => setMethod('')}>ล้าง</UiButton>
const [method, setMethod] = useState('');
<StructuredList label="วิธีส่งเอกสาร" selection condensed value={method} onChange={setMethod}>
{/* แถวหัว แล้วตามด้วยแถว value="email", "post", "courier" */}
</StructuredList>
<Button kind="tertiary" size="sm" onClick={() => setMethod('email')}>ใช้วิธีที่แนะนำ</Button>
<Button kind="ghost" size="sm" onClick={() => setMethod('')}>ล้าง</Button>
ชื่อสำหรับ screen reader
label ตั้งชื่อตาราง (ค่าเริ่มต้นคือ "รายการแบบตาราง") ใน list ที่เลือกได้ radio ของแต่ละแถวใช้ข้อความของแถวเป็นชื่อ ถ้าข้อความยาว ให้ใส่ aria-label สั้น ๆ ที่แถว selection-label (selectionLabel ใน React + Tailwind) ตั้งชื่อคอลัมน์ radio (ค่าเริ่มต้นคือ "เลือก")
ผู้ลงนาม
เหตุผล
กรรมการผู้จัดการ
ลงนามในนามบริษัท ผู้ลงนามคนอื่นลงตามฉบับของกรรมการ
ที่ปรึกษากฎหมาย
ตรวจถ้อยคำสุดท้ายก่อนทุกคนลงนาม แล้วลงชื่อย่อทุกหน้า
HTMLReactReact + Tailwind<ui-structured-list label="ลำดับการลงนาม" selection selection-label="ลงนามก่อน" value="md">
<ui-structured-list-row head>
<ui-structured-list-cell>ผู้ลงนาม</ui-structured-list-cell>
<ui-structured-list-cell>เหตุผล</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="md" aria-label="กรรมการผู้จัดการ">
<ui-structured-list-cell nowrap>กรรมการผู้จัดการ</ui-structured-list-cell>
<ui-structured-list-cell>ลงนามในนามบริษัท ผู้ลงนามคนอื่นลงตามฉบับของกรรมการ</ui-structured-list-cell>
</ui-structured-list-row>
<ui-structured-list-row value="counsel" aria-label="ที่ปรึกษากฎหมาย">
<ui-structured-list-cell nowrap>ที่ปรึกษากฎหมาย</ui-structured-list-cell>
<ui-structured-list-cell>ตรวจถ้อยคำสุดท้ายก่อนทุกคนลงนาม แล้วลงชื่อย่อทุกหน้า</ui-structured-list-cell>
</ui-structured-list-row>
</ui-structured-list>
<UiStructuredList label="ลำดับการลงนาม" selection selectionLabel="ลงนามก่อน" value="md">
{/* แถวหัว */}
<UiStructuredListRow value="md" aria-label="กรรมการผู้จัดการ">…</UiStructuredListRow>
<UiStructuredListRow value="counsel" aria-label="ที่ปรึกษากฎหมาย">…</UiStructuredListRow>
</UiStructuredList>
<StructuredList label="ลำดับการลงนาม" selection selectionLabel="ลงนามก่อน" defaultValue="md">
{/* แถวหัว */}
<StructuredListRow value="md" aria-label="กรรมการผู้จัดการ">…</StructuredListRow>
<StructuredListRow value="counsel" aria-label="ที่ปรึกษากฎหมาย">…</StructuredListRow>
</StructuredList>
Skeleton
ระหว่างโหลดแถว ให้แสดง ui-structured-list-skeleton แทน คือหัวตารางเป็นแถบสามแถบ และแถวว่าง rows แถว (ค่าเริ่มต้น 5) มันซ่อนจาก screen reader จึงต้องบอก "กำลังโหลด" ที่ตัวที่ครอบอยู่ (เช่น aria-busy)
HTMLReactReact + Tailwind<ui-structured-list-skeleton rows="3"></ui-structured-list-skeleton>
import { UiStructuredListSkeleton } from '@purpurabog/ui/react';
<UiStructuredListSkeleton rows={3} />
import { StructuredListSkeleton } from '@/components/ui/react-tw/structured-list';
<StructuredListSkeleton rows={3} />
สำหรับ web component ให้ import จาก @purpurabog/ui/structured-list-skeleton
Accessibility
- list เป็น
role="table" มี role row, cell และ columnheader ส่วน React + Tailwind สร้าง <table> จริง
- ใน list ที่เลือกได้ radio ของทุกแถวเป็นกลุ่มเดียวกัน Tab ไปถึงแถวที่เลือกอยู่ (ถ้าไม่มีก็แถวแรก) ปุ่มลูกศรย้ายและเลือก วนกลับเมื่อสุดปลาย แต่ละ radio บอกลำดับ เช่น "1 จาก 3"
- แถวที่เลือกมี
aria-selected เมื่อ focus จะมีเส้นขอบ 2px รอบทั้งแถว
- list ที่เลือกได้ไม่ใช่ช่องในฟอร์ม ให้อ่าน
value แล้วส่งเอง
ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Structured list
API
สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)
<ui-structured-list> · React UiStructuredList
Attribute
| Attribute |
Property |
ชนิด |
ค่าเริ่มต้น |
คำอธิบาย |
selection |
selection |
boolean |
false |
|
condensed |
condensed |
boolean |
false |
|
flush |
flush |
boolean |
false |
|
value |
value |
string |
'' |
Selected row's value (selection lists). |
label |
label |
string |
'' |
|
selection-label |
selectionLabel |
string |
'' |
Screen-reader name of the radio column (selection lists). |
Method
| Method |
คำอธิบาย |
focus(options) |
Selection lists: focus the selected (or first) row's radio. |
Event
| Event |
React |
คำอธิบาย |
ui-change |
onUiChange |
detail: { value } when the user selects another row |
Slot
| Slot |
คำอธิบาย |
| (ค่าเริ่มต้น) |
<ui-structured-list-row> elements (first one usually head) |
<ui-structured-list-row> · React UiStructuredListRow
Attribute
| Attribute |
Property |
ชนิด |
ค่าเริ่มต้น |
คำอธิบาย |
head |
head |
boolean |
false |
|
value |
value |
string |
'' |
Identifies the row in the list's value / ui-change. |
selected |
selected |
boolean |
false |
Set by the list. |
data-selection |
selection |
boolean |
false |
Set by the list: selection mode renders the radio cell. |
data-condensed |
condensed |
boolean |
false |
Set by the list. |
data-flush |
flush |
boolean |
false |
Set by the list. |
Property
| Property |
ชนิด |
คำอธิบาย |
focusable |
boolean |
Set by the list: the hidden radio is the row's tab stop. |
selectionLabel |
string |
Set by the list: screen-reader name of the radio column header. |
position |
number |
Set by the list: position among the selectable rows and their count. Each radio sits in its own shadow root, so the browser would count "1 of 1". |
Method
| Method |
คำอธิบาย |
focus(options) |
Focus the row's radio (selection lists). |
Event
| Event |
React |
คำอธิบาย |
ui-row-select |
ไม่มี (ใช้ ref) |
|
Slot
| Slot |
คำอธิบาย |
| (ค่าเริ่มต้น) |
<ui-structured-list-cell> elements |
CSS part
| Part |
คำอธิบาย |
radio-cell |
The leading cell with the radio icon (selection lists) |
CSS custom property
| Custom property |
ค่าเริ่มต้น |
คำอธิบาย |
--ui-structured-list-selected |
|
Fill of the chosen row of a selection list (default --ui-surface-2; Kanok: --ui-highlight) |
<ui-structured-list-cell> · React UiStructuredListCell
Attribute
| Attribute |
Property |
ชนิด |
ค่าเริ่มต้น |
คำอธิบาย |
head |
head |
boolean |
false |
Set by the row: this cell is a column header. |
nowrap |
nowrap |
boolean |
false |
|
Slot
| Slot |
คำอธิบาย |
| (ค่าเริ่มต้น) |
Cell content |
<ui-structured-list-skeleton> · React UiStructuredListSkeleton
Attribute
| Attribute |
Property |
ชนิด |
ค่าเริ่มต้น |
คำอธิบาย |
rows |
rows |
number |
5 |
|
CSS part
| Part |
คำอธิบาย |
header |
The header bars |
row |
Each empty row |