ui
ธีม รูปแบบ CarbonKanok ภาษา English
ภาพรวมติดตั้งการย้ายไป 1.0ธีมและ layerดีไซน์ Kanokปรับแต่งหน้าตาไอคอนฟอร์มและการตรวจค่าใช้กับ frameworkใช้กับ AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeแนะนำText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place

Tile

Tile คือกล่องเรียบ ๆ ที่ใช้สีของ layer ถัดไป มี padding 16px ไม่มีเส้นขอบ ไม่มีเงา ใช้จัดกลุ่มเนื้อหาบน dashboard หรือหน้าสรุป ถ้าใส่ href ทั้ง tile จะเป็นลิงก์เดียว Carbon มี tile อีกสี่แบบ ที่นี่คือ ui-expandable-tile, ui-selectable-tile และ ui-radio-tile

รอลงนาม

12

ลงนามเดือนนี้

48

หมดอายุใน 30 วัน

5

HTMLReactReact + Tailwind<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px"> <ui-tile> <p style="margin: 0 0 8px; font: var(--ui-font-caption); color: var(--ui-ink-muted)">รอลงนาม</p> <p style="margin: 0; font: var(--ui-font-heading-04)">12</p> </ui-tile> <ui-tile> <p style="margin: 0 0 8px; font: var(--ui-font-caption); color: var(--ui-ink-muted)">ลงนามเดือนนี้</p> <p style="margin: 0; font: var(--ui-font-heading-04)">48</p> </ui-tile> <ui-tile> <p style="margin: 0 0 8px; font: var(--ui-font-caption); color: var(--ui-ink-muted)">หมดอายุใน 30 วัน</p> <p style="margin: 0; font: var(--ui-font-heading-04)">5</p> </ui-tile> </div> <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))', gap: 16 }}> <UiTile> <p className="caption">รอลงนาม</p> <p className="figure">12</p> </UiTile> <UiTile> <p className="caption">ลงนามเดือนนี้</p> <p className="figure">48</p> </UiTile> <UiTile> <p className="caption">หมดอายุใน 30 วัน</p> <p className="figure">5</p> </UiTile> </div> <div className="grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4"> <Tile> <p className="mb-2 type-caption text-ink-muted">รอลงนาม</p> <p className="type-heading-04">12</p> </Tile> <Tile> <p className="mb-2 type-caption text-ink-muted">ลงนามเดือนนี้</p> <p className="type-heading-04">48</p> </Tile> <Tile> <p className="mb-2 type-caption text-ink-muted">หมดอายุใน 30 วัน</p> <p className="type-heading-04">5</p> </Tile> </div>

ติดตั้ง

npmshadcn · Web componentshadcn · React + Tailwindคัดลอกเองnpm install @purpurabog/ui npx shadcn@4 add @kanok-ui/tile npx shadcn@4 add @kanok-ui/tw-tile # Web component # 1. ติดตั้ง dependency npm install lit@^3.3.0 # 2. คัดลอก "content" ของแต่ละไฟล์จาก # https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tile.json # ไปไว้ที่ target ของมัน: # components/ui/primitives/tile/expandable-tile.ts # components/ui/primitives/tile/radio-tile.ts # components/ui/primitives/tile/selectable-tile.ts # components/ui/primitives/tile/selection-tiles-shared.ts # components/ui/primitives/tile/selection-tiles.ts # components/ui/primitives/tile/tile.ts # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # checkbox, radio, shared-element, shared-events, shared-field, shared-localize, shared-navigate, 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-tile.json # ไปไว้ที่ target ของมัน: # components/ui/react-tw/tile.tsx # 3. ทำแบบเดียวกันกับ item ที่มันใช้ (registry/<name>.json): # tw-checkbox, tw-field, tw-i18n, tw-radio-group, tw-theme, tw-utils

npm ให้ทุก component จากแพ็กเกจ ส่วน shadcn คัดลอกซอร์สเข้าแอปของคุณแทน เป็นสำเนาที่ล็อกเวอร์ชันนี้และแก้เองได้ คำสั่ง shadcn ต้องตั้ง registry @kanok-ui ใน components.json ครั้งเดียวก่อน ดู ติดตั้ง

วิธีใช้

แต่ละแบบมี module ของตัวเอง: tile สำหรับ ui-tile, expandable-tile และ selection-tiles สำหรับ tile แบบเลือกได้และแบบ radio

HTMLReactReact + Tailwind<script type="module"> import '@purpurabog/ui/tile'; import '@purpurabog/ui/expandable-tile'; import '@purpurabog/ui/selection-tiles'; </script> <ui-tile>สัญญารอลงนาม: 12</ui-tile> import { UiTile, UiExpandableTile, UiSelectableTile, UiRadioTile } from '@purpurabog/ui/react'; <UiTile>สัญญารอลงนาม: 12</UiTile> import { Tile, ExpandableTile, SelectableTile, RadioTile } from '@/components/ui/react-tw/tile'; <Tile>สัญญารอลงนาม: 12</Tile>

ใช้ tile แบบไหน?

Tile Element ใช้เมื่อ
Tile ui-tile กล่องเนื้อหา เช่น ตัวเลข สรุปสั้น ๆ
Tile ที่คลิกได้ ui-tile href ทั้ง tile พาไปหน้าเดียว
Tile ที่ขยายได้ ui-expandable-tile สรุปที่กดเปิดดูเพิ่มได้
Tile แบบเลือกได้ ui-selectable-tile checkbox ที่มีที่สำหรับหัวข้อและคำอธิบาย ดูเพิ่มที่หน้า checkbox
Radio tile ui-radio-tile ตัวเลือก radio ที่มีที่สำหรับหัวข้อและคำอธิบาย ดูเพิ่มที่หน้า radio

ถ้าต้องการกล่องที่มี header, รูป และปุ่ม ให้ใช้ Card

เนื้อหา

ใส่เนื้อหาอะไรใน tile ก็ได้ ทั้งหัวข้อ ข้อความ ตารางเล็ก ๆ tile สูงอย่างน้อย 64px กว้างอย่างน้อย 128px และเต็มคอลัมน์ของมัน จึงจัดหลายอันด้วย CSS grid ได้ ข้อความข้างในเป็น body-compact-01 ถ้าไม่ได้ตั้ง font อื่น

สัญญาเช่าสำนักงาน สาขาสีลม

สัญญาเช่าสามปี เริ่ม 1 มกราคม 2570 ชำระค่าเช่าทุกวันที่ 5 ของเดือน

ผู้รับผิดชอบ: ฝ่ายกฎหมาย

HTMLReactReact + Tailwind<ui-tile style="max-width: 420px"> <h3 style="margin: 0 0 8px; font: var(--ui-font-heading-02)">สัญญาเช่าสำนักงาน สาขาสีลม</h3> <p style="margin: 0 0 16px">สัญญาเช่าสามปี เริ่ม 1 มกราคม 2570 ชำระค่าเช่าทุกวันที่ 5 ของเดือน</p> <p style="margin: 0; color: var(--ui-ink-muted)">ผู้รับผิดชอบ: ฝ่ายกฎหมาย</p> </ui-tile> <UiTile style={{ maxWidth: 420 }}> <h3>สัญญาเช่าสำนักงาน สาขาสีลม</h3> <p>สัญญาเช่าสามปี เริ่ม 1 มกราคม 2570 ชำระค่าเช่าทุกวันที่ 5 ของเดือน</p> <p>ผู้รับผิดชอบ: ฝ่ายกฎหมาย</p> </UiTile> <Tile className="max-w-[420px]"> <h3 className="mb-2 type-heading-02">สัญญาเช่าสำนักงาน สาขาสีลม</h3> <p className="mb-4">สัญญาเช่าสามปี เริ่ม 1 มกราคม 2570 ชำระค่าเช่าทุกวันที่ 5 ของเดือน</p> <p className="text-ink-muted">ผู้รับผิดชอบ: ฝ่ายกฎหมาย</p> </Tile>

Tile ที่คลิกได้

ถ้าใส่ href ทั้ง tile จะเป็นลิงก์เดียวและเป็นจุดหยุดของ Tab จุดเดียว เมื่อเอาเมาส์ชี้ สีพื้นจะเปลี่ยนเป็นสี hover ข้อความใน tile คือชื่อของลิงก์ จึงควรสั้น และอย่าใส่ปุ่มหรือลิงก์อื่นข้างใน เหมือน Carbon tile ที่เป็นลิงก์จะไม่มีไอคอนจนกว่าคุณจะใส่ใน slot icon (React + Tailwind ใช้ prop icon) ขนาด 20px ห่างมุมล่างด้านท้าย 12px

สัญญารอลงนาม

12 ฉบับ เกินกำหนด 3 ฉบับ

คำขออนุมัติ

4 รายการรอคุณ

HTMLReactReact + Tailwind<div style="display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px"> <ui-tile href="#accessibility"> <h3 style="margin: 0 0 8px; font: var(--ui-font-heading-02)">สัญญารอลงนาม</h3> <p style="margin: 0 0 24px">12 ฉบับ เกินกำหนด 3 ฉบับ</p> <svg slot="icon" viewBox="0 0 20 20" aria-hidden="true"><path d="m11.8 2.8-.9.9 5.6 5.7H1.7v1.2h14.8l-5.6 5.7.9.9 7.2-7.2z" /></svg> </ui-tile> <ui-tile href="#accessibility"> <h3 style="margin: 0 0 8px; font: var(--ui-font-heading-02)">คำขออนุมัติ</h3> <p style="margin: 0 0 24px">4 รายการรอคุณ</p> <svg slot="icon" viewBox="0 0 20 20" aria-hidden="true"><path d="m11.8 2.8-.9.9 5.6 5.7H1.7v1.2h14.8l-5.6 5.7.9.9 7.2-7.2z" /></svg> </ui-tile> </div> const arrow = <svg slot="icon" viewBox="0 0 20 20" aria-hidden="true"><path d="m11.8 2.8-.9.9 5.6 5.7H1.7v1.2h14.8l-5.6 5.7.9.9 7.2-7.2z" /></svg>; <UiTile href="/contracts?status=awaiting"> <h3>สัญญารอลงนาม</h3> <p>12 ฉบับ เกินกำหนด 3 ฉบับ</p> {arrow} </UiTile> <UiTile href="/approvals"> <h3>คำขออนุมัติ</h3> <p>4 รายการรอคุณ</p> {arrow} </UiTile> const arrow = <svg viewBox="0 0 20 20" aria-hidden="true"><path d="m11.8 2.8-.9.9 5.6 5.7H1.7v1.2h14.8l-5.6 5.7.9.9 7.2-7.2z" /></svg>; <Tile href="/contracts?status=awaiting" icon={arrow}> <h3 className="mb-2 type-heading-02">สัญญารอลงนาม</h3> <p className="mb-6">12 ฉบับ เกินกำหนด 3 ฉบับ</p> </Tile> <Tile href="/approvals" icon={arrow}> <h3 className="mb-2 type-heading-02">คำขออนุมัติ</h3> <p className="mb-6">4 รายการรอคุณ</p> </Tile>

target="_blank" เปิดลิงก์ในแท็บใหม่ tile จะเติม "(เปิดในแท็บใหม่)" ให้ screen reader และใส่ rel="noopener noreferrer" ให้

Tile ที่คลิกได้แต่ปิดใช้งาน

disabled บน tile ที่เป็นลิงก์ทำให้มันเป็นข้อความสีเทาธรรมดา ไม่มีลิงก์ (เหมือน ClickableTile ที่ disabled ของ Carbon) ใช้กับหน้าที่ผู้ใช้ยังเปิดไม่ได้ตอนนี้ และบอกเหตุผลไว้ใน tile

รายงานประจำปี 2569

เปิดได้หลังปิดบัญชีวันที่ 31 มกราคม

HTMLReactReact + Tailwind<ui-tile href="#accessibility" disabled style="max-width: 320px"> <h3 style="margin: 0 0 8px; font: inherit; font-weight: 600">รายงานประจำปี 2569</h3> <p style="margin: 0">เปิดได้หลังปิดบัญชีวันที่ 31 มกราคม</p> </ui-tile> <UiTile href="/reports/2026" disabled style={{ maxWidth: 320 }}> <h3>รายงานประจำปี 2569</h3> <p>เปิดได้หลังปิดบัญชีวันที่ 31 มกราคม</p> </UiTile> <Tile href="/reports/2026" disabled className="max-w-[320px]"> <h3 className="mb-2 font-semibold">รายงานประจำปี 2569</h3> <p>เปิดได้หลังปิดบัญชีวันที่ 31 มกราคม</p> </Tile>

ใช้กับ router ของ SPA

การคลิกธรรมดาบน tile ที่เป็นลิงก์จะยิง ui-navigate ที่ยกเลิกได้พร้อม { href } ก่อน ยกเลิกมันแล้วให้ router ของคุณเปลี่ยนหน้า listener ตัวเดียวบน document ครอบคลุมทุก element ดูที่ Frameworks demo นี้ยกเลิก event แล้วแสดงที่อยู่แทน

C-2026-014

สัญญาซื้อขาย โรงงานเชียงใหม่

router จะเปิด: ยังไม่มี

HTMLReactReact + Tailwind<ui-tile id="tile-route" href="/contracts/C-2026-014" style="max-width: 320px"> <h3 style="margin: 0 0 8px; font: var(--ui-font-heading-02)">C-2026-014</h3> <p style="margin: 0">สัญญาซื้อขาย โรงงานเชียงใหม่</p> </ui-tile> <p>router จะเปิด: <output id="tile-route-out">ยังไม่มี</output></p> <script type="module"> const tile = document.getElementById('tile-route'); const out = document.getElementById('tile-route-out'); tile.addEventListener('ui-navigate', (event) => { event.preventDefault(); out.value = event.detail.href; }); </script> const navigate = useNavigate(); // router ของคุณ <UiTile href="/contracts/C-2026-014" onUiNavigate={(e) => { e.preventDefault(); navigate(e.detail.href); }} > <h3>C-2026-014</h3> <p>สัญญาซื้อขาย โรงงานเชียงใหม่</p> </UiTile> // tile เป็น <a> จริง: ครอบด้วยลิงก์ของ router หรือจัดการ click เอง <Tile href="/contracts/C-2026-014" onClick={(e) => { if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return; e.preventDefault(); navigate('/contracts/C-2026-014'); }} > <h3 className="mb-2 type-heading-02">C-2026-014</h3> <p>สัญญาซื้อขาย โรงงานเชียงใหม่</p> </Tile>

บน layer

tile วาดตัวเองด้วยสีของ layer ที่มันวางอยู่ ใน ui-layer มันจะใช้สีของ layer ถัดไป จึงยังเด่นบนแผงสีเทา

บน layer 1
tile ใช้สีของ layer 2
คลิกได้
สี hover ก็ตาม layer ด้วย
HTMLReactReact + Tailwind<ui-layer level="1" with-background style="display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; padding: 16px"> <ui-tile><b>บน layer 1</b><br />tile ใช้สีของ layer 2</ui-tile> <ui-tile href="#accessibility"><b>คลิกได้</b><br />สี hover ก็ตาม layer ด้วย</ui-tile> </ui-layer> <UiLayer level={1} withBackground style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(180px, 1fr))', gap: 16, padding: 16 }}> <UiTile><b>บน layer 1</b><br />tile ใช้สีของ layer 2</UiTile> <UiTile href="/contracts"><b>คลิกได้</b><br />สี hover ก็ตาม layer ด้วย</UiTile> </UiLayer> // npx shadcn@4 add @kanok-ui/tw-layer import { Layer } from '@/components/ui/react-tw/layer'; <Layer level={1} withBackground className="grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-4 p-4"> <Tile><b>บน layer 1</b><br />tile ใช้สีของ layer 2</Tile> <Tile href="/contracts"><b>คลิกได้</b><br />สี hover ก็ตาม layer ด้วย</Tile> </Layer>

เรื่อง layer ดูเพิ่มที่ Layer

Tile ที่ขยายได้

ui-expandable-tile แสดงสรุปและกดเปิดดูเพิ่มได้ ส่วนสรุป (slot="summary") อยู่ในปุ่มเปิดปิด จึงควรเป็นข้อความอย่างเดียว ลิงก์ ช่องกรอก และปุ่มให้ใส่ในส่วนที่เปิดออกมา ลูกศรที่มุมล่างด้านท้ายจะหมุนเมื่อเปิด

ตัวเลือกการลงนาม
การเก็บรักษา ลายน้ำ บันทึกผู้ลงนาม

เก็บสำเนาที่ลงนามแล้ว 10 ปี ทุกหน้ามีลายน้ำเลขที่สัญญา และบันทึก IP address ของผู้ลงนาม

HTMLReactReact + Tailwind<ui-expandable-tile style="max-width: 560px"> <span slot="summary"><b>ตัวเลือกการลงนาม</b><br />การเก็บรักษา ลายน้ำ บันทึกผู้ลงนาม</span> <p style="margin: 16px 0 0">เก็บสำเนาที่ลงนามแล้ว 10 ปี ทุกหน้ามีลายน้ำเลขที่สัญญา และบันทึก IP address ของผู้ลงนาม</p> </ui-expandable-tile> <UiExpandableTile style={{ maxWidth: 560 }}> <span slot="summary"><b>ตัวเลือกการลงนาม</b><br />การเก็บรักษา ลายน้ำ บันทึกผู้ลงนาม</span> <p>เก็บสำเนาที่ลงนามแล้ว 10 ปี ทุกหน้ามีลายน้ำเลขที่สัญญา และบันทึก IP address ของผู้ลงนาม</p> </UiExpandableTile> <ExpandableTile className="max-w-[560px]" summary={<><b>ตัวเลือกการลงนาม</b><br />การเก็บรักษา ลายน้ำ บันทึกผู้ลงนาม</>}> <p className="mt-4">เก็บสำเนาที่ลงนามแล้ว 10 ปี ทุกหน้ามีลายน้ำเลขที่สัญญา และบันทึก IP address ของผู้ลงนาม</p> </ExpandableTile>

สถานะเปิดและ event

expanded เปิด tile (ตั้งไว้ถ้าจะให้เปิดตั้งแต่แรก) หลังเปิดหรือปิดแต่ละครั้ง ui-toggle จะยิงพร้อม detail.expanded เรียก toggle() บน element เพื่อเปิดหรือปิดจากโค้ด toggle(true) จะเปิดอย่างเดียว

ตารางชำระเงิน
12 งวด

ทุกวันที่ 5 ของเดือน งวดละ 85,000 บาท โอนผ่านธนาคาร

เปิด เปิดอยู่:
HTMLReactReact + Tailwind<ui-expandable-tile id="tile-expand" expanded style="max-width: 560px"> <span slot="summary"><b>ตารางชำระเงิน</b><br />12 งวด</span> <p style="margin: 16px 0 0">ทุกวันที่ 5 ของเดือน งวดละ 85,000 บาท โอนผ่านธนาคาร</p> </ui-expandable-tile> <div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center"> <ui-button id="tile-expand-open" kind="tertiary" size="sm">เปิด</ui-button> <span>เปิดอยู่: <output id="tile-expand-out"></output></span> </div> <script type="module"> const tile = document.getElementById('tile-expand'); const out = document.getElementById('tile-expand-out'); out.value = tile.expanded; tile.addEventListener('ui-toggle', (event) => (out.value = event.detail.expanded)); document.getElementById('tile-expand-open').addEventListener('click', () => tile.toggle(true)); </script> const [expanded, setExpanded] = useState(true); <UiExpandableTile expanded={expanded} onUiToggle={(e) => setExpanded(e.detail.expanded)}> <span slot="summary"><b>ตารางชำระเงิน</b><br />12 งวด</span> <p>ทุกวันที่ 5 ของเดือน งวดละ 85,000 บาท โอนผ่านธนาคาร</p> </UiExpandableTile> <UiButton kind="tertiary" size="sm" onClick={() => setExpanded(true)}>เปิด</UiButton> <p>เปิดอยู่: <output>{String(expanded)}</output></p> const [expanded, setExpanded] = useState(true); <ExpandableTile expanded={expanded} onToggle={setExpanded} summary={<><b>ตารางชำระเงิน</b><br />12 งวด</>}> <p className="mt-4">ทุกวันที่ 5 ของเดือน งวดละ 85,000 บาท โอนผ่านธนาคาร</p> </ExpandableTile> <Button kind="tertiary" size="sm" onClick={() => setExpanded(true)}>เปิด</Button> <p>เปิดอยู่: <output>{String(expanded)}</output></p>

React + Tailwind รับ defaultExpanded ด้วย สำหรับ tile ที่คุณไม่ได้คุมค่าเอง

ให้เปิดค้างไว้

ก่อนเปลี่ยนสถานะ tile จะยิง ui-before-toggle ที่ยกเลิกได้พร้อมสถานะที่กำลังจะเป็น ยกเลิกมันเพื่อให้ tile อยู่แบบเดิม เช่น ตอนที่บันทึกข้างในยังไม่ได้บันทึก ใน React + Tailwind ให้ onBeforeToggle คืนค่า false ลองพิมพ์บันทึกแล้วปิด tile ดู

บันทึกถึงผู้อนุมัติ
บันทึก

ครั้งล่าสุด: ยังไม่มี

HTMLReactReact + Tailwind<ui-expandable-tile id="tile-note" expanded style="max-width: 560px"> <span slot="summary"><b>บันทึกถึงผู้อนุมัติ</b></span> <div style="display: grid; gap: 16px; margin-top: 16px"> <ui-text-area id="tile-note-text" label="บันทึก" rows="2"></ui-text-area> <div><ui-button id="tile-note-save" size="sm">บันทึก</ui-button></div> </div> </ui-expandable-tile> <p>ครั้งล่าสุด: <output id="tile-note-out">ยังไม่มี</output></p> <script type="module"> const tile = document.getElementById('tile-note'); const text = document.getElementById('tile-note-text'); const out = document.getElementById('tile-note-out'); tile.addEventListener('ui-before-toggle', (event) => { if (!event.detail.expanded && text.value.trim() !== '') { event.preventDefault(); out.value = 'เปิดค้างไว้: บันทึกยังไม่ได้บันทึก'; } else { out.value = event.detail.expanded ? 'เปิด' : 'ปิด'; } }); document.getElementById('tile-note-save').addEventListener('click', () => { out.value = `บันทึกแล้ว "${text.value.trim()}"`; text.value = ''; }); </script> import type { UiTextArea as TextAreaElement } from '@purpurabog/ui'; const [note, setNote] = useState(''); const [expanded, setExpanded] = useState(true); <UiExpandableTile expanded={expanded} onUiBeforeToggle={(e) => { if (!e.detail.expanded && note.trim() !== '') e.preventDefault(); }} onUiToggle={(e) => setExpanded(e.detail.expanded)} > <span slot="summary"><b>บันทึกถึงผู้อนุมัติ</b></span> <UiTextArea label="บันทึก" rows={2} value={note} onInput={(e) => setNote((e.target as TextAreaElement).value)} /> <UiButton size="sm" onClick={() => save(note)}>บันทึก</UiButton> </UiExpandableTile> const [note, setNote] = useState(''); <ExpandableTile defaultExpanded onBeforeToggle={(next) => next || note.trim() === ''} summary={<b>บันทึกถึงผู้อนุมัติ</b>}> <TextArea label="บันทึก" rows={2} value={note} onChange={(e) => setNote(e.target.value)} /> <Button size="sm" onClick={() => save(note)}>บันทึก</Button> </ExpandableTile>

Tile แบบเลือกได้

ui-selectable-tile คือ checkbox ที่วาดเป็น tile มี API เดียวกับ ui-checkbox คือ checked, name, value, change และส่งค่าไปกับฟอร์ม ถ้าใช้เดี่ยว ๆ แต่ละ tile คือตัวเลือกใช่หรือไม่หนึ่งข้อ เรื่องกลุ่ม required อ่านอย่างเดียว และ error อยู่ที่หน้า checkbox

อากรแสตมป์
คำนวณและชำระให้
แปลเอกสาร
ฉบับภาษาไทยและอังกฤษ
ส่งเอกสาร
ยังไม่ให้บริการในพื้นที่ของคุณ

เลือกแล้ว:

HTMLReactReact + Tailwind<div id="tile-addons" style="display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px"> <ui-selectable-tile name="addons" value="stamp"><b>อากรแสตมป์</b><br />คำนวณและชำระให้</ui-selectable-tile> <ui-selectable-tile name="addons" value="translate" checked><b>แปลเอกสาร</b><br />ฉบับภาษาไทยและอังกฤษ</ui-selectable-tile> <ui-selectable-tile name="addons" value="courier" disabled><b>ส่งเอกสาร</b><br />ยังไม่ให้บริการในพื้นที่ของคุณ</ui-selectable-tile> </div> <p>เลือกแล้ว: <output id="tile-addons-out"></output></p> <script type="module"> const row = document.getElementById('tile-addons'); const out = document.getElementById('tile-addons-out'); const show = () => (out.value = [...row.querySelectorAll('ui-selectable-tile')].filter((tile) => tile.checked).map((tile) => tile.value).join(', ') || 'ไม่มี'); show(); row.addEventListener('change', show); </script> import type { UiSelectableTile as SelectableTileElement } from '@purpurabog/ui'; const [chosen, setChosen] = useState<string[]>(['translate']); const toggle = (e: Event) => { const tile = e.target as SelectableTileElement; setChosen(tile.checked ? [...chosen, tile.value] : chosen.filter((v) => v !== tile.value)); }; <UiSelectableTile name="addons" value="stamp" checked={chosen.includes('stamp')} onChange={toggle}><b>อากรแสตมป์</b><br />คำนวณและชำระให้</UiSelectableTile> <UiSelectableTile name="addons" value="translate" checked={chosen.includes('translate')} onChange={toggle}><b>แปลเอกสาร</b><br />ฉบับภาษาไทยและอังกฤษ</UiSelectableTile> <UiSelectableTile name="addons" value="courier" disabled><b>ส่งเอกสาร</b><br />ยังไม่ให้บริการในพื้นที่ของคุณ</UiSelectableTile> <p>เลือกแล้ว: <output>{chosen.join(', ') || 'ไม่มี'}</output></p> const [chosen, setChosen] = useState<string[]>(['translate']); const toggle = (e: ChangeEvent<HTMLInputElement>) => setChosen(e.target.checked ? [...chosen, e.target.value] : chosen.filter((v) => v !== e.target.value)); <SelectableTile name="addons" value="stamp" checked={chosen.includes('stamp')} onChange={toggle}><b>อากรแสตมป์</b><br />คำนวณและชำระให้</SelectableTile> <SelectableTile name="addons" value="translate" checked={chosen.includes('translate')} onChange={toggle}><b>แปลเอกสาร</b><br />ฉบับภาษาไทยและอังกฤษ</SelectableTile> <SelectableTile name="addons" value="courier" disabled><b>ส่งเอกสาร</b><br />ยังไม่ให้บริการในพื้นที่ของคุณ</SelectableTile> <p>เลือกแล้ว: <output>{chosen.join(', ') || 'ไม่มี'}</output></p>

Radio tile

ui-radio-tile คือตัวเลือกหนึ่งของ ui-radio-group ที่วาดเป็น tile กลุ่มเป็นคนจัดการปุ่มลูกศร ค่า change และฟอร์ม เครื่องหมายถูกขึ้นเฉพาะ tile ที่เลือก เรื่องแนวการวาง required อ่านอย่างเดียว และ error อยู่ที่หน้า radio

ลายเซ็นอิเล็กทรอนิกส์
ลงนามออนไลน์ได้ในไม่กี่นาที
กระดาษ
พิมพ์ ลงนาม แล้วสแกน
ที่สาขา
ลงนามโดยมีพนักงานเป็นพยาน

ค่า:

HTMLReactReact + Tailwind<ui-radio-group id="tile-method" label="วิธีลงนาม" name="method" value="esign"> <ui-radio-tile value="esign"><b>ลายเซ็นอิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</ui-radio-tile> <ui-radio-tile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</ui-radio-tile> <ui-radio-tile value="branch"><b>ที่สาขา</b><br />ลงนามโดยมีพนักงานเป็นพยาน</ui-radio-tile> </ui-radio-group> <p>ค่า: <output id="tile-method-out"></output></p> <script type="module"> const group = document.getElementById('tile-method'); const out = document.getElementById('tile-method-out'); out.value = group.value; group.addEventListener('change', () => (out.value = group.value)); </script> import type { UiRadioGroup as RadioGroupElement } from '@purpurabog/ui'; const [method, setMethod] = useState('esign'); <UiRadioGroup label="วิธีลงนาม" name="method" value={method} onChange={(e) => setMethod((e.target as RadioGroupElement).value)}> <UiRadioTile value="esign"><b>ลายเซ็นอิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</UiRadioTile> <UiRadioTile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</UiRadioTile> <UiRadioTile value="branch"><b>ที่สาขา</b><br />ลงนามโดยมีพนักงานเป็นพยาน</UiRadioTile> </UiRadioGroup> <p>ค่า: <output>{method}</output></p> // npx shadcn@4 add @kanok-ui/tw-radio-group import { RadioGroup } from '@/components/ui/react-tw/radio-group'; const [method, setMethod] = useState('esign'); <RadioGroup label="วิธีลงนาม" name="method" value={method} onValueChange={setMethod}> <RadioTile value="esign"><b>ลายเซ็นอิเล็กทรอนิกส์</b><br />ลงนามออนไลน์ได้ในไม่กี่นาที</RadioTile> <RadioTile value="paper"><b>กระดาษ</b><br />พิมพ์ ลงนาม แล้วสแกน</RadioTile> <RadioTile value="branch"><b>ที่สาขา</b><br />ลงนามโดยมีพนักงานเป็นพยาน</RadioTile> </RadioGroup> <p>ค่า: <output>{method}</output></p>

เครื่องหมายลอยทับมุม

selectable tile และ radio tile กันที่ด้านท้าย 48px ไว้ให้เครื่องหมายแบบ Carbon คอลัมน์แคบจึงตัดบรรทัดเร็ว ตั้ง --ui-tile-mark-space (เกินจาก Carbon) เป็น 16px แล้วเครื่องหมายจะลอยทับมุมบนแทน ความกว้างทั้งหมดจึงเป็นของเนื้อหา

เครื่องเขียนและอุปกรณ์สำนักงาน เดินทางและที่พัก เลี้ยงรับรองลูกค้า
HTMLReactReact + Tailwind<div style="display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-width: 520px; --ui-tile-mark-space: 16px"> <ui-selectable-tile name="spend" value="0" checked>เครื่องเขียนและอุปกรณ์สำนักงาน</ui-selectable-tile> <ui-selectable-tile name="spend" value="1">เดินทางและที่พัก</ui-selectable-tile> <ui-selectable-tile name="spend" value="2">เลี้ยงรับรองลูกค้า</ui-selectable-tile> </div> <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, minmax(0, 1fr))', gap: 8, '--ui-tile-mark-space': '16px' } as CSSProperties}> <UiSelectableTile name="spend" value="0">เครื่องเขียนและอุปกรณ์สำนักงาน</UiSelectableTile> <UiSelectableTile name="spend" value="1">เดินทางและที่พัก</UiSelectableTile> <UiSelectableTile name="spend" value="2">เลี้ยงรับรองลูกค้า</UiSelectableTile> </div> <div className="grid grid-cols-3 gap-2 [--ui-tile-mark-space:16px]"> <SelectableTile name="spend" value="0">เครื่องเขียนและอุปกรณ์สำนักงาน</SelectableTile> <SelectableTile name="spend" value="1">เดินทางและที่พัก</SelectableTile> <SelectableTile name="spend" value="2">เลี้ยงรับรองลูกค้า</SelectableTile> </div>

คีย์บอร์ด

ปุ่ม ทำอะไร
Tab ไปที่ tile ที่คลิกได้ ปุ่มของ tile ที่ขยายได้ tile แบบเลือกได้ หรือ radio tile ที่เลือกอยู่ tile ธรรมดาไม่ใช่จุดที่ Tab หยุด
Enter ไปตามลิงก์ของ tile ที่คลิกได้ เปิดหรือปิด tile ที่ขยายได้
Space เปิดหรือปิด tile ที่ขยายได้ เลือกหรือไม่เลือก tile แบบเลือกได้
ปุ่มลูกศร ย้ายไปมาระหว่าง radio tile และเลือก

Accessibility

  • tile ธรรมดาเป็นกล่องที่ไม่มี role ให้ใช้หัวข้อจริงในเนื้อหา โครงหัวข้อของหน้าจะได้ถูกต้อง
  • tile ที่คลิกได้คือลิงก์เดียว ข้อความทั้งหมดใน tile คือชื่อลิงก์ ควรสั้น และอย่าใส่ control อื่นข้างใน
  • ปุ่มของ tile ที่ขยายได้มี aria-expanded และ aria-controls ส่วนสรุปเป็นส่วนหนึ่งของชื่อปุ่ม จึงต้องเป็นข้อความอย่างเดียว
  • tile แบบเลือกได้คือ checkbox จริง และ radio tile คือ radio จริง screen reader จึงอ่านสถานะได้ และข้อความใน tile คือชื่อของมัน

API

สร้างจากแพ็กเกจโดยตรง ใน React ส่ง property เป็น prop ชื่อเดียวกัน ส่วน event ก็เป็น prop เช่นกัน (ดูคอลัมน์ React)

<ui-tile> · React UiTile

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
href href string '' Makes the whole tile a link.
target target '_self' | '_blank' '_self'
disabled disabled boolean false A linked tile that can't be followed right now (Carbon ClickableTile disabled): plain text, no link.

Event

Event React คำอธิบาย
ui-navigate ไม่มี (ใช้ ref) detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Tile content
icon A linked tile's icon (e.g. an arrow), 20px, 12px from the bottom-end corner

CSS part

Part คำอธิบาย
base The container (<div> or <a>)

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-card-radius Corner radius (default 0; Kanok: 12px)
--ui-card-border Border (default none; Kanok: a hairline)
--ui-card-background Its fill (default --ui-surface-1; Kanok paper: a cool grey that sets it apart from the page, no border)
--ui-focus-offset outline-offset of its focus ring (default -2px: inside; Kanok: 2px outside)

<ui-expandable-tile> · React UiExpandableTile

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
expanded expanded boolean false

Event

Event React คำอธิบาย
ui-toggle onUiToggle detail: { expanded }
ui-before-toggle onUiBeforeToggle Cancelable; detail: { expanded } — the state about to be applied

Slot

Slot คำอธิบาย
summary Always visible (text only)
(ค่าเริ่มต้น) Revealed content

CSS part

Part คำอธิบาย
summary The always-visible button row
chevron The arrow icon
content The expandable body

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-card-border / --ui-card-radius - Border and corners, as the cards (default none and square; Kanok: a hairline, 12px)
--ui-card-background Its fill (default --ui-surface-1; Kanok paper: a cool grey that sets it apart from the page, no border)
--ui-focus-offset outline-offset of its focus ring (default -2px: inside; Kanok: 2px outside)

<ui-selectable-tile> · React UiSelectableTile

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
checked checked boolean false
indeterminate indeterminate boolean false Mixed state, e.g. a "select all" box with some children checked. Cleared on user toggle.
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
required required boolean false Blocks form submission while the field is empty.
readonly readonly boolean false Shows and submits the value but blocks changes.
hide-label hideLabel boolean false Keep the label text for screen readers but don't show it.
name name string '' Reflected: form-associated elements submit under the name attribute.
value value string 'on'
helper-text helperText string '' Helper text under the field, shown while there is no error or warning.
invalid-text invalidText string '' Error text shown while invalid or while the field fails validation.
invalid invalid boolean false Forces the error state, e.g. after server-side validation.
warn warn boolean false Non-blocking warning; shown when there is no error.
warn-text warnText string '' Text of the warning shown while warn.

Property

Property ชนิด คำอธิบาย
groupDisabled boolean Set by ui-checkbox-group; kept apart from the author's own disabled / readonly.
groupMessage string Error text of the owning ui-checkbox-group while the group is invalid. The group shows it once below the boxes; each box repeats it as its own accessible description and reports aria-invalid, so a screen reader landing on the first box hears why (an IDREF cannot cross the group's shadow root).
willValidate (อ่านอย่างเดียว) Whether the field takes part in constraint validation (not while disabled), as natively.
labels (อ่านอย่างเดียว) The <label>s that point at this field.

Method

Method คำอธิบาย
setCustomValidity(message) Like <input>.setCustomValidity(): a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''.

Event

Event React คำอธิบาย
change ไม่มี (ใช้ ref) When the user toggles the box

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Tile content (title, description…)

CSS part

Part คำอธิบาย
base The clickable row (label element)
control The native checkbox input
box The drawn 16px box
label The text beside the box
status-icon The error / warning icon
helper-text The helper line
warning-text The warning line
warn-text Same line as warning-text (named after the warn-text attribute / slot)
error-text The error line
invalid-text Same line as error-text (named after the invalid-text attribute / slot)

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-tile-border-color Border of an unchosen tile (default transparent; Kanok: a hairline); --ui-card-radius its corners
--ui-card-background Its fill (default --ui-surface-1; Kanok paper: a cool grey that sets it apart from the page, no border)
--ui-tile-selected-border Border of the chosen tile (default --ui-layer-selected-inverse; Kanok: primary blue); --ui-tile-selected-mark its check mark (default --ui-icon-primary)
--ui-tile-selected-background Fill of the chosen tile (default --ui-card-background; Kanok: soft highlight wash)
--ui-tile-mark-space End padding kept clear for the mark (default 48px, Carbon's); e.g. 16px lets the content run under the mark in the top-end corner (beyond Carbon)
--ui-checkbox-border Border of the box (default --ui-ink; Kanok: --ui-ink-subtle)
--ui-checkbox-checked Fill and border when checked or mixed (default --ui-ink; Kanok: --ui-primary)
--ui-checkbox-mark Check mark colour (default --ui-icon-inverse; Kanok: --ui-on-primary)

<ui-radio-tile> · React UiRadioTile

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
value value string ''
checked checked boolean false
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
label-position labelPosition RadioLabelPosition | undefined Carbon labelPosition: left puts the text before the circle; unset, the group's label-position applies.

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) Tile content (title, description…)

CSS part

Part คำอธิบาย
circle The drawn radio circle
label The text beside it

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-tile-border-color Border of an unchosen tile (default transparent; Kanok: a hairline); --ui-card-radius its corners
--ui-card-background Its fill (default --ui-surface-1; Kanok paper: a cool grey that sets it apart from the page, no border)
--ui-tile-selected-border Border of the chosen tile (default --ui-layer-selected-inverse; Kanok: primary blue); --ui-tile-selected-mark its check mark (default --ui-icon-primary)
--ui-tile-selected-background Fill of the chosen tile (default --ui-card-background; Kanok: soft highlight wash)
--ui-tile-mark-space End padding kept clear for the mark (default 48px, Carbon's); e.g. 16px lets the content run under the mark in the top-end corner (beyond Carbon)
--ui-radio-border Ring colour (default --ui-ink; Kanok: --ui-ink-subtle)
--ui-radio-checked Ring and dot when chosen (default --ui-ink; Kanok: --ui-primary)