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

Checkbox

Checkbox ใช้เปิดหรือปิดตัวเลือกหนึ่งอย่าง ถ้าอยู่เป็นกลุ่ม ผู้ใช้เลือกได้กี่อันก็ได้ รวมถึงไม่เลือกเลย

อีเมล SMS ไปรษณีย์
HTMLReactReact + Tailwind<ui-checkbox-group label="ส่งข่าวสารทาง" helper-text="เลือกได้มากกว่าหนึ่งช่องทาง"> <ui-checkbox name="channels" value="email" checked>อีเมล</ui-checkbox> <ui-checkbox name="channels" value="sms">SMS</ui-checkbox> <ui-checkbox name="channels" value="post">ไปรษณีย์</ui-checkbox> </ui-checkbox-group> <UiCheckboxGroup label="ส่งข่าวสารทาง" helperText="เลือกได้มากกว่าหนึ่งช่องทาง"> <UiCheckbox name="channels" value="email" checked>อีเมล</UiCheckbox> <UiCheckbox name="channels" value="sms">SMS</UiCheckbox> <UiCheckbox name="channels" value="post">ไปรษณีย์</UiCheckbox> </UiCheckboxGroup> <FormGroup legend="ส่งข่าวสารทาง" message="เลือกได้มากกว่าหนึ่งช่องทาง"> <Checkbox label="อีเมล" name="channels" value="email" defaultChecked /> <Checkbox label="SMS" name="channels" value="sms" /> <Checkbox label="ไปรษณีย์" name="channels" value="post" /> </FormGroup>

ติดตั้ง

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

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

วิธีใช้

HTMLReactReact + Tailwind<script type="module"> import '@purpurabog/ui/checkbox'; import '@purpurabog/ui/checkbox-group'; </script> <ui-checkbox name="terms" required>ฉันยอมรับเงื่อนไข</ui-checkbox> import { UiCheckbox, UiCheckboxGroup } from '@purpurabog/ui/react'; <UiCheckbox name="terms" required>ฉันยอมรับเงื่อนไข</UiCheckbox> import { Checkbox } from '@/components/ui/react-tw/checkbox'; <Checkbox label="ฉันยอมรับเงื่อนไข" name="terms" required />

ใน web component ข้อความ label คือเนื้อหาข้างใน element ส่วนใน React + Tailwind คือ prop label import checkbox-group เฉพาะเมื่อใช้กลุ่ม

Checkbox เดี่ยว

  • checked คือสถานะ event change ยิงเมื่อผู้ใช้ติ๊กหรือเอาติ๊กออก
  • ช่องที่ติ๊กไว้จะส่ง value (ค่าเริ่มต้นคือ on) ภายใต้ name ช่องที่ไม่ติ๊กไม่ส่งอะไร
  • required ทำให้ส่งฟอร์มไม่ได้จนกว่าจะติ๊ก เช่น การยอมรับเงื่อนไข
รับจดหมายข่าว

checked: false

HTMLReactReact + Tailwind<ui-checkbox id="checkbox-newsletter" name="newsletter" value="yes">รับจดหมายข่าว</ui-checkbox> <p>checked: <output id="checkbox-newsletter-out">false</output></p> <script type="module"> const box = document.getElementById('checkbox-newsletter'); box.addEventListener('change', () => (document.getElementById('checkbox-newsletter-out').value = box.checked)); </script> import type { UiCheckbox as CheckboxElement } from '@purpurabog/ui'; const [on, setOn] = useState(false); <UiCheckbox name="newsletter" value="yes" checked={on} onChange={(e) => setOn((e.target as CheckboxElement).checked)}> รับจดหมายข่าว </UiCheckbox> <p>checked: <output>{String(on)}</output></p> const [on, setOn] = useState(false); <Checkbox label="รับจดหมายข่าว" name="newsletter" value="yes" checked={on} onChange={(e) => setOn(e.target.checked)} /> <p>checked: <output>{String(on)}</output></p>

กลุ่มของ checkbox

ui-checkbox-group ใส่ label ให้ checkbox ทั้งชุดและถูกอ่านเป็นกลุ่มเดียว

  • required หมายถึง "อย่างน้อยหนึ่งช่อง" ส่งฟอร์มไม่ได้จนกว่าจะติ๊กสักช่อง
  • orientation="horizontal" เรียง checkbox เป็นแถวแนวนอน
  • disabled และ readonly มีผลกับทุกช่อง โดยไม่ทับค่าที่ตั้งไว้ในแต่ละช่อง
  • แต่ละ checkbox ยังส่ง name และ value ของตัวเอง จึงอ่านด้วย FormData.getAll()
บัตรประชาชน ทะเบียนบ้าน สมุดบัญชีธนาคาร
HTMLReactReact + Tailwind<ui-checkbox-group label="เอกสารที่ได้รับ" orientation="horizontal" required> <ui-checkbox name="docs" value="id">บัตรประชาชน</ui-checkbox> <ui-checkbox name="docs" value="house">ทะเบียนบ้าน</ui-checkbox> <ui-checkbox name="docs" value="bank">สมุดบัญชีธนาคาร</ui-checkbox> </ui-checkbox-group> <UiCheckboxGroup label="เอกสารที่ได้รับ" orientation="horizontal" required> <UiCheckbox name="docs" value="id">บัตรประชาชน</UiCheckbox> <UiCheckbox name="docs" value="house">ทะเบียนบ้าน</UiCheckbox> <UiCheckbox name="docs" value="bank">สมุดบัญชีธนาคาร</UiCheckbox> </UiCheckboxGroup> // npx shadcn@4 add @kanok-ui/tw-form-group import { FormGroup } from '@/components/ui/react-tw/form-group'; <FormGroup legend="เอกสารที่ได้รับ" invalid={!!docsError} message={docsError}> <div className="flex gap-6"> <Checkbox label="บัตรประชาชน" name="docs" value="id" /> <Checkbox label="ทะเบียนบ้าน" name="docs" value="house" /> <Checkbox label="สมุดบัญชีธนาคาร" name="docs" value="bank" /> </div> </FormGroup>

React + Tailwind ไม่มี checkbox group ให้ใช้ FormGroup (fieldset ของ Carbon) จัดวาง checkbox เอง และตรวจ "อย่างน้อยหนึ่งช่อง" ใน validation ของคุณเอง ในตัวอย่าง docsError มาจาก validation ของคุณ เช่น "กรุณาเลือกอย่างน้อยหนึ่งรายการ"

ข้อความช่วยเหลือ คำเตือน และ error ของช่องเดี่ยว

checkbox เดี่ยวมีบรรทัดข้อความของตัวเองใต้ label คือ helper-text, warn คู่กับ warn-text ที่ไม่บล็อกการส่ง และ invalid คู่กับ invalid-text error มาก่อนคำเตือน และคำเตือนมาก่อนข้อความช่วยเหลือ

ชำระอากรแสตมป์แล้ว พยานลงนามแล้ว ฉันยอมรับเงื่อนไข
HTMLReactReact + Tailwind<ui-checkbox name="stamp" helper-text="ติ๊กเมื่อแนบใบเสร็จแล้ว">ชำระอากรแสตมป์แล้ว</ui-checkbox> <ui-checkbox name="witness" checked warn warn-text="พยานลงนามแล้วเพียงคนเดียว">พยานลงนามแล้ว</ui-checkbox> <ui-checkbox name="terms" invalid invalid-text="ต้องยอมรับเงื่อนไขก่อนดำเนินการต่อ">ฉันยอมรับเงื่อนไข</ui-checkbox> <UiCheckbox name="stamp" helperText="ติ๊กเมื่อแนบใบเสร็จแล้ว">ชำระอากรแสตมป์แล้ว</UiCheckbox> <UiCheckbox name="witness" checked warn warnText="พยานลงนามแล้วเพียงคนเดียว">พยานลงนามแล้ว</UiCheckbox> <UiCheckbox name="terms" invalid invalidText="ต้องยอมรับเงื่อนไขก่อนดำเนินการต่อ">ฉันยอมรับเงื่อนไข</UiCheckbox> <Checkbox label="ชำระอากรแสตมป์แล้ว" name="stamp" helperText="ติ๊กเมื่อแนบใบเสร็จแล้ว" /> <Checkbox label="พยานลงนามแล้ว" name="witness" defaultChecked warn warnText="พยานลงนามแล้วเพียงคนเดียว" /> <Checkbox label="ฉันยอมรับเงื่อนไข" name="terms" invalid invalidText="ต้องยอมรับเงื่อนไขก่อนดำเนินการต่อ" />

คำเตือนและ error ของกลุ่ม

ใน ui-checkbox-group ข้อความเป็นของทั้งกลุ่มและแสดงครั้งเดียวใต้กลุ่ม error จะทำให้ทุกช่องที่ใช้งานได้เป็นสีแดงด้วย และแต่ละช่องทวน error ให้ screen reader

ผู้ให้เช่า ผู้เช่า ผู้ค้ำประกัน กระดาษ PDF
HTMLReactReact + Tailwind<ui-checkbox-group label="ผู้ลงนาม" warn warn-text="ปกติผู้ค้ำประกันต้องลงนามด้วย"> <ui-checkbox name="parties" value="lessor" checked>ผู้ให้เช่า</ui-checkbox> <ui-checkbox name="parties" value="lessee" checked>ผู้เช่า</ui-checkbox> <ui-checkbox name="parties" value="guarantor">ผู้ค้ำประกัน</ui-checkbox> </ui-checkbox-group> <ui-checkbox-group label="สำเนาที่ต้องเก็บ" invalid invalid-text="เก็บสำเนาอย่างน้อยหนึ่งแบบ เป็นกระดาษหรือ PDF"> <ui-checkbox name="copies" value="paper">กระดาษ</ui-checkbox> <ui-checkbox name="copies" value="pdf">PDF</ui-checkbox> </ui-checkbox-group> <UiCheckboxGroup label="ผู้ลงนาม" warn warnText="ปกติผู้ค้ำประกันต้องลงนามด้วย">…</UiCheckboxGroup> <UiCheckboxGroup label="สำเนาที่ต้องเก็บ" invalid invalidText="เก็บสำเนาอย่างน้อยหนึ่งแบบ เป็นกระดาษหรือ PDF">…</UiCheckboxGroup> <FormGroup legend="สำเนาที่ต้องเก็บ" invalid message="เก็บสำเนาอย่างน้อยหนึ่งแบบ เป็นกระดาษหรือ PDF"> <Checkbox label="กระดาษ" name="copies" value="paper" /> <Checkbox label="PDF" name="copies" value="pdf" /> </FormGroup>

FormGroup ของ React + Tailwind มี invalid และ message (ข้อความเป็นสีแดง) แต่ไม่มีสถานะคำเตือน

Indeterminate

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

ทุกช่องทาง
อีเมล SMS
HTMLReactReact + Tailwind<ui-stack gap="3"> <ui-checkbox id="checkbox-all" indeterminate>ทุกช่องทาง</ui-checkbox> <div id="checkbox-channels" style="padding-inline-start: 24px"> <ui-checkbox value="email" checked>อีเมล</ui-checkbox> <ui-checkbox value="sms">SMS</ui-checkbox> </div> </ui-stack> <script type="module"> const all = document.getElementById('checkbox-all'); const channels = [...document.getElementById('checkbox-channels').children]; const sync = () => { const on = channels.filter((box) => box.checked).length; all.checked = on === channels.length; all.indeterminate = on > 0 && on < channels.length; }; all.addEventListener('change', () => { for (const box of channels) box.checked = all.checked; sync(); }); for (const box of channels) box.addEventListener('change', sync); </script> const all = ['email', 'sms']; const [chosen, setChosen] = useState(['email']); const some = chosen.length > 0 && chosen.length < all.length; const pick = (value: string, on: boolean) => setChosen((c) => (on ? [...c, value] : c.filter((v) => v !== value))); <UiCheckbox checked={chosen.length === all.length} indeterminate={some} onChange={(e) => setChosen((e.target as CheckboxElement).checked ? all : [])}> ทุกช่องทาง </UiCheckbox> <UiCheckbox checked={chosen.includes('email')} onChange={(e) => pick('email', (e.target as CheckboxElement).checked)}>อีเมล</UiCheckbox> <UiCheckbox checked={chosen.includes('sms')} onChange={(e) => pick('sms', (e.target as CheckboxElement).checked)}>SMS</UiCheckbox> <Checkbox label="ทุกช่องทาง" checked={chosen.length === all.length} indeterminate={some} onChange={(e) => setChosen(e.target.checked ? all : [])} /> <Checkbox label="อีเมล" checked={chosen.includes('email')} onChange={(e) => pick('email', e.target.checked)} /> <Checkbox label="SMS" checked={chosen.includes('sms')} onChange={(e) => pick('sms', e.target.checked)} />

all, chosen, some และ pick เหมือนกันในทุกแบบของ React ส่วนใน web component ให้ทำแบบเดียวกันใน listener ของ change คือตั้ง checked และ indeterminate ของ checkbox แม่ตามลูก

ซ่อน label

hide-label เก็บ label ไว้ให้ screen reader อ่านแต่ไม่แสดง เช่น checkbox ในแถวของตาราง

เลือกสัญญา C-2026-0142 C-2026-0142 · สัญญาเช่าโกดังถนนพระรามสี่
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center"> <ui-checkbox hide-label>เลือกสัญญา C-2026-0142</ui-checkbox> <span>C-2026-0142 · สัญญาเช่าโกดังถนนพระรามสี่</span> </div> <UiCheckbox hideLabel>เลือกสัญญา C-2026-0142</UiCheckbox> <Checkbox label="เลือกสัญญา C-2026-0142" hideLabel />

อ่านอย่างเดียวและปิดใช้งาน

readonly (readOnly ใน React + Tailwind) คงสถานะไว้และส่งไปกับฟอร์ม แต่การคลิกและ Space ไม่เปลี่ยนอะไร disabled ทำให้ช่องเป็นสีเทาและไม่ถูกส่งไปกับฟอร์ม

ลงนามครบทั้งสองฝ่ายแล้ว เก็บเข้าคลังแล้ว
HTMLReactReact + Tailwind<ui-checkbox checked readonly>ลงนามครบทั้งสองฝ่ายแล้ว</ui-checkbox> <ui-checkbox disabled>เก็บเข้าคลังแล้ว</ui-checkbox> <UiCheckbox checked readonly>ลงนามครบทั้งสองฝ่ายแล้ว</UiCheckbox> <UiCheckbox disabled>เก็บเข้าคลังแล้ว</UiCheckbox> <Checkbox label="ลงนามครบทั้งสองฝ่ายแล้ว" defaultChecked readOnly /> <Checkbox label="เก็บเข้าคลังแล้ว" disabled />

บังคับเลือกในฟอร์ม

กลุ่มที่ required ต้องติ๊กอย่างน้อยหนึ่งช่อง ส่วน checkbox เดี่ยวที่ required ต้องติ๊ก error จะรอจนผู้ใช้ใช้ช่องนั้นแล้วหรือกดส่ง ลองกดส่งโดยไม่ติ๊กอะไรเพื่อดูทั้งสองแบบ

ฝ่ายกฎหมาย ฝ่ายการเงิน ฝ่ายจัดซื้อ ฉันได้อ่านเงื่อนไขของสัญญาแล้ว
ส่ง

ค่าที่ส่ง:

HTMLReactReact + Tailwind<form id="checkbox-form" style="display: grid; gap: 16px"> <ui-checkbox-group label="ส่งสำเนาถึง" required helper-text="เลือกอย่างน้อยหนึ่งแผนก"> <ui-checkbox name="cc" value="legal">ฝ่ายกฎหมาย</ui-checkbox> <ui-checkbox name="cc" value="finance">ฝ่ายการเงิน</ui-checkbox> <ui-checkbox name="cc" value="procurement">ฝ่ายจัดซื้อ</ui-checkbox> </ui-checkbox-group> <ui-checkbox name="terms" value="accepted" required invalid-text="ยอมรับเงื่อนไขก่อนดำเนินการต่อ">ฉันได้อ่านเงื่อนไขของสัญญาแล้ว</ui-checkbox> <div><ui-button type="submit">ส่ง</ui-button></div> </form> <p>ค่าที่ส่ง: <output id="checkbox-form-out"></output></p> <script type="module"> const form = document.getElementById('checkbox-form'); form.addEventListener('submit', (event) => { event.preventDefault(); document.getElementById('checkbox-form-out').value = [...new FormData(form)].map(([key, value]) => `${key}=${value}`).join(', '); }); </script> <form onSubmit={submit}> <UiCheckboxGroup label="ส่งสำเนาถึง" required helperText="เลือกอย่างน้อยหนึ่งแผนก"> <UiCheckbox name="cc" value="legal">ฝ่ายกฎหมาย</UiCheckbox> <UiCheckbox name="cc" value="finance">ฝ่ายการเงิน</UiCheckbox> <UiCheckbox name="cc" value="procurement">ฝ่ายจัดซื้อ</UiCheckbox> </UiCheckboxGroup> <UiCheckbox name="terms" value="accepted" required invalidText="ยอมรับเงื่อนไขก่อนดำเนินการต่อ">ฉันได้อ่านเงื่อนไขของสัญญาแล้ว</UiCheckbox> <UiButton type="submit">ส่ง</UiButton> </form> <p>ค่าที่ส่ง: <output>{sent}</output></p> // การตรวจค่าเป็นของแอป: `ccError` และ `termsError` มาจากการตรวจตอนกดส่ง <form onSubmit={submit}> <FormGroup legend="ส่งสำเนาถึง" invalid={!!ccError} message={ccError ?? 'เลือกอย่างน้อยหนึ่งแผนก'}> <Checkbox label="ฝ่ายกฎหมาย" name="cc" value="legal" /> <Checkbox label="ฝ่ายการเงิน" name="cc" value="finance" /> <Checkbox label="ฝ่ายจัดซื้อ" name="cc" value="procurement" /> </FormGroup> <Checkbox label="ฉันได้อ่านเงื่อนไขของสัญญาแล้ว" name="terms" value="accepted" invalid={!!termsError} invalidText={termsError} /> <Button type="submit">ส่ง</Button> </form> <p>ค่าที่ส่ง: <output>{sent}</output></p>

submit กันไม่ให้หน้าเปลี่ยน แล้วเก็บ new FormData(form) ไว้ใน sent เหมือนใน HTML ข้อความของกลุ่มมีในตัวทั้งภาษาไทยและอังกฤษ ใช้ required-text หรือ invalid-text เพื่อเปลี่ยน ดูเพิ่มที่ ฟอร์มและการตรวจค่า

Selectable tile

ถ้าแต่ละตัวเลือกต้องมีหัวข้อและคำอธิบาย ให้ใช้ ui-selectable-tile คือ checkbox ที่วาดเป็น tile (SelectableTile ของ Carbon) import จาก @purpurabog/ui/selection-tiles ส่ง name และ value เหมือน checkbox และกด Space เพื่อติ๊กได้ ใน ui-checkbox-group tile เป็นสมาชิกเหมือน checkbox คือ required, disabled, readonly และ error ของกลุ่มมีผลกับ tile ด้วย

อากรแสตมป์
คำนวณและชำระให้
แปลเอกสาร
ไทย ⇄ อังกฤษ
ส่งเอกสาร
ส่งสำเนาที่ลงนามแล้วด้วยแมสเซนเจอร์
HTMLReactReact + Tailwind<ui-checkbox-group label="บริการเสริม" orientation="horizontal"> <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"><b>ส่งเอกสาร</b><br />ส่งสำเนาที่ลงนามแล้วด้วยแมสเซนเจอร์</ui-selectable-tile> </ui-checkbox-group> import { UiSelectableTile } from '@purpurabog/ui/react'; <UiCheckboxGroup label="บริการเสริม" orientation="horizontal"> <UiSelectableTile name="addons" value="stamp"><b>อากรแสตมป์</b><br />คำนวณและชำระให้</UiSelectableTile> <UiSelectableTile name="addons" value="translate" checked><b>แปลเอกสาร</b><br />ไทย ⇄ อังกฤษ</UiSelectableTile> <UiSelectableTile name="addons" value="courier"><b>ส่งเอกสาร</b><br />ส่งสำเนาที่ลงนามแล้วด้วยแมสเซนเจอร์</UiSelectableTile> </UiCheckboxGroup> // npx shadcn@4 add @kanok-ui/tw-tile import { SelectableTile } from '@/components/ui/react-tw/tile'; <FormGroup legend="บริการเสริม"> <div className="flex flex-wrap gap-4"> <SelectableTile name="addons" value="stamp"><b>อากรแสตมป์</b><br />คำนวณและชำระให้</SelectableTile> <SelectableTile name="addons" value="translate" defaultChecked><b>แปลเอกสาร</b><br />ไทย ⇄ อังกฤษ</SelectableTile> <SelectableTile name="addons" value="courier"><b>ส่งเอกสาร</b><br />ส่งสำเนาที่ลงนามแล้วด้วยแมสเซนเจอร์</SelectableTile> </div> </FormGroup>

Skeleton

ระหว่างโหลดตัวเลือก ให้แสดง ui-checkbox-skeleton แถวละหนึ่งตัว เป็นกล่องว่างกับแถบ label skeleton ถูกซ่อนจาก screen reader จึงต้องบอกว่ากำลังโหลดที่ container เช่น aria-busy

HTMLReactReact + Tailwind<div aria-busy="true"> <ui-checkbox-skeleton></ui-checkbox-skeleton> <ui-checkbox-skeleton></ui-checkbox-skeleton> <ui-checkbox-skeleton></ui-checkbox-skeleton> </div> import { UiCheckboxSkeleton } from '@purpurabog/ui/react'; <div aria-busy="true"> <UiCheckboxSkeleton /> <UiCheckboxSkeleton /> <UiCheckboxSkeleton /> </div> import { CheckboxSkeleton } from '@/components/ui/react-tw/checkbox'; <div aria-busy="true"> <CheckboxSkeleton /> <CheckboxSkeleton /> <CheckboxSkeleton /> </div>

ใน web component ให้ import จาก @purpurabog/ui/checkbox-skeleton

คีย์บอร์ด

ปุ่ม ทำอะไร
Space ติ๊กหรือเอาติ๊กออกจากช่องที่โฟกัสอยู่
Tab ไปช่องถัดไป checkbox แต่ละช่องเป็นจุดหยุดของ Tab แยกกัน

Accessibility

  • แต่ละช่องเป็น checkbox จริงอยู่ใน <label> คลิกได้ทั้งแถว และ screen reader ได้ยินสถานะรวมถึง "mixed"
  • ui-checkbox-group เป็น role="group" ที่ใช้ label เป็นชื่อ ข้อความช่วยเหลือ คำเตือน หรือ error เป็นคำอธิบายของกลุ่ม และทุกช่องจะทวน error ของกลุ่ม จึงได้ยินตั้งแต่ช่องแรก
  • อย่าใช้ checkbox กับการตั้งค่าที่มีผลทันที ให้ใช้ Toggle

ต้องการแค่พฤติกรรมโดยไม่มี style: Headless Checkbox

API

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

<ui-checkbox> · React UiCheckbox

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 คำอธิบาย
(ค่าเริ่มต้น) Label text

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-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-checkbox-group> · React UiCheckboxGroup

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
label label string '' Visible label text; the label slot replaces it when markup is needed.
hide-label hideLabel boolean false Keep the group label for screen readers but don't show it.
helper-text helperText string '' Helper text under the field, shown while there is no error or warning.
required required boolean false Blocks form submission while the field is empty.
required-text requiredText string '' Error for an empty required group.
invalid invalid boolean false Forces the error state, e.g. after server-side validation.
invalid-text invalidText string '' Error text shown while invalid or while the field fails 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.
disabled disabled boolean false Disables the control; a disabled <fieldset> ancestor does the same.
readonly readonly boolean false Shows and submits the value but blocks changes.
orientation orientation 'vertical' | 'horizontal' 'vertical'

Property

Property ชนิด คำอธิบาย
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 ''.

Slot

Slot คำอธิบาย
(ค่าเริ่มต้น) <ui-checkbox> or <ui-selectable-tile> elements
label Label content with markup; the label attribute is the plain-text fallback
helper-text Helper text with markup (links, bold); overrides helper-text
warn-text Warning text shown while warn; overrides warn-text
invalid-text Error text shown while invalid; overrides invalid-text

CSS part

Part คำอธิบาย
base The group box holding the checkboxes
label The group label
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)

<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)