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

Link

ลิงก์พาผู้ใช้ไปหน้าอื่น ไปจุดอื่นในหน้านี้ หรือไปที่ไฟล์ เป็นสีน้ำเงิน ขีดเส้นใต้ตอน hover และตอนโฟกัส และมีกรอบโฟกัสแบบ Carbon

นโยบายการลงนาม
HTMLReactReact + Tailwind<ui-link href="#link-policy">นโยบายการลงนาม</ui-link> <UiLink href="/policies/signing">นโยบายการลงนาม</UiLink> <Link href="/policies/signing">นโยบายการลงนาม</Link>

ติดตั้ง

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

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

วิธีใช้

HTMLReactReact + Tailwind<script type="module">import '@purpurabog/ui/link';</script> <ui-link href="/policies/signing">นโยบายการลงนาม</ui-link> import { UiLink } from '@purpurabog/ui/react'; <UiLink href="/policies/signing">นโยบายการลงนาม</UiLink> import { Link } from '@/components/ui/react-tw/link'; <Link href="/policies/signing">นโยบายการลงนาม</Link>
Component ใช้เมื่อ
Link พาไปที่อื่น: หน้าอื่น ส่วนอื่นของหน้านี้ หรือไฟล์ ความสามารถของลิงก์ใน browser ใช้ได้ครบ (เปิดในแท็บใหม่ คัดลอกที่อยู่)
Button ทำบางอย่างตรงนี้: ส่งฟอร์ม เปิด modal เริ่ม export

ถ้าต้องการให้หน้าตาเป็นปุ่มแต่พาไปหน้าอื่น ให้ใช้ปุ่มที่มี href ดู Button

ขนาด

size: sm 12px (ขนาด helper text), md 14px (ค่าเริ่มต้น), lg 16px ให้เข้ากับข้อความรอบลิงก์

ลิงก์เล็ก ลิงก์กลาง ลิงก์ใหญ่
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center"> <ui-link href="#link-policy" size="sm">ลิงก์เล็ก</ui-link> <ui-link href="#link-policy">ลิงก์กลาง</ui-link> <ui-link href="#link-policy" size="lg">ลิงก์ใหญ่</ui-link> </div> <UiLink href="/policies/signing" size="sm">ลิงก์เล็ก</UiLink> <UiLink href="/policies/signing">ลิงก์กลาง</UiLink> <UiLink href="/policies/signing" size="lg">ลิงก์ใหญ่</UiLink> <Link href="/policies/signing" size="sm">ลิงก์เล็ก</Link> <Link href="/policies/signing">ลิงก์กลาง</Link> <Link href="/policies/signing" size="lg">ลิงก์ใหญ่</Link>

ลิงก์ในประโยค

inline ขีดเส้นใต้ลิงก์ตลอดเวลา ลิงก์จึงเด่นในข้อความที่สีอย่างเดียวไม่พอ ลิงก์แบบ inline ไม่แสดงไอคอน

สำเนาที่ลงนามแล้วเก็บไว้ 10 ปีตามนโยบายการเก็บเอกสาร สอบถามฝ่ายกฎหมายก่อนทำลายสำเนา

HTMLReactReact + Tailwind<p>สำเนาที่ลงนามแล้วเก็บไว้ 10 ปีตาม<ui-link href="#link-retention" inline>นโยบายการเก็บเอกสาร</ui-link> สอบถามฝ่ายกฎหมายก่อนทำลายสำเนา</p> <p>สำเนาที่ลงนามแล้วเก็บไว้ 10 ปีตาม<UiLink href="/policies/retention" inline>นโยบายการเก็บเอกสาร</UiLink> สอบถามฝ่ายกฎหมายก่อนทำลายสำเนา</p> <p>สำเนาที่ลงนามแล้วเก็บไว้ 10 ปีตาม<Link href="/policies/retention" inline>นโยบายการเก็บเอกสาร</Link> สอบถามฝ่ายกฎหมายก่อนทำลายสำเนา</p>

มีไอคอน

ใส่ไอคอน 16px ใน slot icon (prop icon ใน React + Tailwind) ไอคอนจะอยู่หลังข้อความ 8px ใช้สีของลิงก์ และขยายเป็น 20px เมื่อ size="lg" ใช้กับลิงก์ที่อยู่เดี่ยว ๆ เช่น "ดูทั้งหมด" ท้ายรายการ

ดูสัญญาทั้งหมด ดูสัญญาทั้งหมด
HTMLReactReact + Tailwind<div style="display: flex; flex-wrap: wrap; gap: 16px; align-items: center"> <ui-link href="#link-contracts">ดูสัญญาทั้งหมด <svg slot="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M9.3 3.7 13.1 7.5H1v1h12.1l-3.8 3.8.7.7 5-5-5-5z" /></svg></ui-link> <ui-link href="#link-contracts" size="lg">ดูสัญญาทั้งหมด <svg slot="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M9.3 3.7 13.1 7.5H1v1h12.1l-3.8 3.8.7.7 5-5-5-5z" /></svg></ui-link> </div> <UiLink href="/contracts"> ดูสัญญาทั้งหมด <svg slot="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M9.3 3.7 13.1 7.5H1v1h12.1l-3.8 3.8.7.7 5-5-5-5z" /></svg> </UiLink> <UiLink href="/contracts" size="lg">ดูสัญญาทั้งหมด {arrowIcon}</UiLink> const arrowIcon = <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M9.3 3.7 13.1 7.5H1v1h12.1l-3.8 3.8.7.7 5-5-5-5z" /></svg>; <Link href="/contracts" icon={arrowIcon}>ดูสัญญาทั้งหมด</Link> <Link href="/contracts" size="lg" icon={arrowIcon}>ดูสัญญาทั้งหมด</Link>

เปิดในแท็บใหม่

target="_blank" เปิดหน้าในแท็บใหม่ และลิงก์จะใส่ rel="noopener noreferrer" ให้ ถ้าคุณไม่ได้ตั้ง rel เอง บอกผู้ใช้ในข้อความหรือด้วยไอคอน Launch ของ Carbon เพื่อไม่ให้แท็บใหม่ทำให้แปลกใจ

แนวทางการใช้ลิงก์ของ Carbon
HTMLReactReact + Tailwind<ui-link href="https://carbondesignsystem.com/components/link/usage/" target="_blank">แนวทางการใช้ลิงก์ของ Carbon <svg slot="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M13 14H3V4h5V3H3a1 1 0 0 0-1 1v10a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V8h-1z" /><path d="M10 1v1h3.3L7 8.3l.7.7L14 2.7V6h1V1z" /></svg></ui-link> <UiLink href="https://carbondesignsystem.com/components/link/usage/" target="_blank"> แนวทางการใช้ลิงก์ของ Carbon {launchIcon} </UiLink> <Link href="https://carbondesignsystem.com/components/link/usage/" target="_blank" icon={launchIcon}> แนวทางการใช้ลิงก์ของ Carbon </Link>

ดาวน์โหลดไฟล์

download ทำให้ลิงก์บันทึกไฟล์แทนการเปิด ค่าของมันคือชื่อไฟล์ บอกชนิดและขนาดไฟล์ไว้ในข้อความ (เว็บเอกสารนี้ไม่มีไฟล์นั้นจริง ตัวอย่างนี้จึงสร้างไฟล์ขึ้นใน browser)

ดาวน์โหลดเช็กลิสต์สัญญา (TXT, 1 KB)
HTMLReactReact + Tailwind<ui-link id="link-download" href="/files/contract-checklist.txt" download="contract-checklist.txt">ดาวน์โหลดเช็กลิสต์สัญญา (TXT, 1 KB)</ui-link> <script type="module"> const link = document.getElementById('link-download'); const text = 'เช็กลิสต์สัญญา\n- ระบุคู่สัญญาครบทั้งสองฝ่าย\n- จำนวนเงินและวันครบกำหนด\n- ลายเซ็นและพยาน\n'; link.href = URL.createObjectURL(new Blob([text], { type: 'text/plain' })); </script> <UiLink href="/files/contract-checklist.txt" download="contract-checklist.txt"> ดาวน์โหลดเช็กลิสต์สัญญา (TXT, 1 KB) </UiLink> <Link href="/files/contract-checklist.txt" download="contract-checklist.txt"> ดาวน์โหลดเช็กลิสต์สัญญา (TXT, 1 KB) </Link>

ลิงก์ที่เคยเปิดแล้ว

visited เปิดใช้สีของลิงก์ที่เคยเปิดแล้วแบบ Carbon (สีม่วง) สำหรับลิงก์ที่ browser เคยไปแล้ว ใช้กับรายการที่ผู้ใช้ไล่เปิดทีละรายการ เช่น ผลการค้นหา ลองคลิกลิงก์แล้วดูอีกครั้ง

CT-2026-0142: เครื่องเขียนสำนักงาน
HTMLReactReact + Tailwind<ui-link href="#link-visited" visited>CT-2026-0142: เครื่องเขียนสำนักงาน</ui-link> <UiLink href="/contracts/ct-2026-0142" visited>CT-2026-0142: เครื่องเขียนสำนักงาน</UiLink> <Link href="/contracts/ct-2026-0142" visited>CT-2026-0142: เครื่องเขียนสำนักงาน</Link>

ปิดใช้งาน

disabled แสดงเป็นข้อความสีเทาที่มี role="link" และ aria-disabled="true" จึงไม่ใช่ลิงก์อีกต่อไปและไม่รับโฟกัส ทางที่ดีกว่าคือไม่แสดงลิงก์นั้น หรืออธิบายไว้ข้าง ๆ ว่าทำไมใช้ไม่ได้

ดาวน์โหลดสำเนาที่ลงนามแล้ว
HTMLReactReact + Tailwind<ui-link href="#link-signed" disabled>ดาวน์โหลดสำเนาที่ลงนามแล้ว</ui-link> <UiLink href="/contracts/ct-2026-0142/signed.pdf" disabled>ดาวน์โหลดสำเนาที่ลงนามแล้ว</UiLink> <Link href="/contracts/ct-2026-0142/signed.pdf" disabled>ดาวน์โหลดสำเนาที่ลงนามแล้ว</Link>

ใช้กับ router ของแอปหน้าเดียว

การคลิกแบบปกติ (ปุ่มซ้าย ไม่กดปุ่ม modifier แท็บเดิม เว็บเดียวกัน ไม่ใช่การดาวน์โหลด) จะส่ง ui-navigate ที่ยกเลิกได้ก่อน โดยมี detail.href เรียก preventDefault() แล้วส่ง path ให้ router ของคุณ browser จะไม่โหลดหน้านั้น ส่วน Ctrl-, ⌘- และคลิกปุ่มกลางยังเป็นลิงก์ปกติ Link ของ React + Tailwind เป็น <a> ธรรมดา ให้จัดการใน onClick หรือครอบลิงก์ของ router เอง

เปิด CT-2026-0142

router ได้รับ:

HTMLReactReact + Tailwind<ui-link id="link-route" href="/contracts/ct-2026-0142">เปิด CT-2026-0142</ui-link> <p>router ได้รับ: <output id="link-route-out"></output></p> <script type="module"> const link = document.getElementById('link-route'); const out = document.getElementById('link-route-out'); link.addEventListener('ui-navigate', (event) => { event.preventDefault(); out.value = event.detail.href; }); </script> const navigate = useNavigate(); // router ของคุณ <UiLink href="/contracts/ct-2026-0142" onUiNavigate={(e) => { e.preventDefault(); navigate(e.detail.href); }}> เปิด CT-2026-0142 </UiLink> const navigate = useNavigate(); // router ของคุณ <Link href="/contracts/ct-2026-0142" onClick={(e) => { if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) return; e.preventDefault(); navigate('/contracts/ct-2026-0142'); }} > เปิด CT-2026-0142 </Link>

Accessibility

  • ลิงก์เป็น <a href> จริง กด Enter เพื่อไปตามลิงก์ และเมนูของ browser (เปิดในแท็บใหม่ คัดลอกที่อยู่) ใช้ได้
  • เขียนข้อความที่เข้าใจได้แม้อ่านลำพัง ("ดาวน์โหลดเช็กลิสต์สัญญา" ไม่ใช่ "คลิกที่นี่") เพราะผู้ใช้ screen reader มักไล่ฟังทีละลิงก์
  • ไอคอนใน slot icon เป็นแค่การตกแต่ง ใส่ aria-hidden="true" และให้ความหมายอยู่ในข้อความ
  • ลิงก์ที่ปิดใช้งานจะถูกอ่านว่าเป็นลิงก์ที่ใช้ไม่ได้ แต่ไม่รับโฟกัส ผู้ใช้คีย์บอร์ดจึงไปไม่ถึง อธิบายเหตุผลไว้ในข้อความใกล้ ๆ
  • inline ขีดเส้นใต้ลิงก์ในประโยค จึงไม่ต้องพึ่งสีอย่างเดียว

API

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

Attribute

Attribute Property ชนิด ค่าเริ่มต้น คำอธิบาย
href href string ''
target target string ''
rel rel string ''
download download string ''
size size LinkSize 'md'
inline inline boolean false Underlined at rest, for links inside a sentence.
visited visited boolean false Opt into Carbon's visited colour (browser :visited).
disabled disabled boolean false Renders as inert text with aria-disabled.

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 คำอธิบาย
(ค่าเริ่มต้น) Link text
icon A 16px (lg: 20px) icon after the text (Carbon renderIcon; not shown when inline)

CSS part

Part คำอธิบาย
base The anchor
icon The icon wrapper

CSS custom property

Custom property ค่าเริ่มต้น คำอธิบาย
--ui-link-focus-radius Corners of the focus ring (default 0; Kanok: 4px)