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

ติดตั้ง

แพ็กเกจอยู่บน npm แบบ public เลือกวิธีที่เหมาะกับแอปของคุณ ใช้หลายวิธีร่วมกันได้

เลือกรูปแบบ

component มีให้เลือกสองรูปแบบ ใช้ JavaScript ชุดเดียวกัน ต่างกันแค่ stylesheet

รูปแบบ โหลด บนหน้า
Carbon (ค่าเริ่มต้น) tokens.css ไม่ต้องเพิ่มอะไร
Kanok (ดีไซน์ของเราเอง) tokens.css แล้วตามด้วย kanok.css ใส่ data-design="kanok" ที่ <html> หรือที่ element รากของแอป
ทั้งสองแบบ สลับได้ สองไฟล์เดิม ตั้งหรือลบ data-design ระหว่างใช้งาน
<html data-design="kanok"> <link rel="stylesheet" href="node_modules/@purpurabog/ui/dist/tokens.css" /> <link rel="stylesheet" href="node_modules/@purpurabog/ui/dist/kanok.css" />

Kanok ใช้ฟอนต์ Bai Jamjuree (ไทยและละติน สัญญาอนุญาต SIL Open Font License) ติดตั้งด้วย npm i @fontsource/bai-jamjuree แล้ว import น้ำหนัก 400, 500, 600 และ 700 (import '@fontsource/bai-jamjuree/400.css'; เป็นต้น)

ดูทั้งเว็บนี้เป็น Kanok ได้ที่ ตั้งค่า (รูปเฟืองบนแถบด้านบน) เลือก Kanok ในหัวข้อรูปแบบ หรือแชร์ลิงก์ที่ลงท้ายด้วย ?design=kanok อ่านต่อที่ ดีไซน์ Kanok

Web components (ใช้ได้ทุก framework)

npm i @purpurabog/ui lit

โหลด design token ครั้งเดียวต่อหน้า แล้วโหลด component ที่ใช้:

<link rel="stylesheet" href="node_modules/@purpurabog/ui/dist/tokens.css" /> <script type="module"> import '@purpurabog/ui'; // ทุก component // หรือเฉพาะที่ใช้: import '@purpurabog/ui/date-picker'; </script>

React

แพ็กเกจมี wrapper สำหรับ React ที่มี type ของ prop และ event ให้ ต้องติดตั้ง @lit/react เพิ่ม (peer dependency แบบ optional ใช้เฉพาะ @purpurabog/ui/react):

npm i @purpurabog/ui lit @lit/react

โหลด token ครั้งเดียว (import '@purpurabog/ui/tokens.css';) แล้ว import wrapper ที่ใช้จาก @purpurabog/ui/react

React + Tailwind ด้วย shadcn

copy component เข้าแอปแล้วแก้ class ได้เอง ส่วนพฤติกรรม (คีย์บอร์ด โฟกัส ARIA) มาจาก @purpurabog/ui/headless ซึ่ง CLI ติดตั้งให้เอง

  1. แอปต้องมี Tailwind v4 และไฟล์ components.json ถ้าใช้ shadcn อยู่แล้ว ให้เพิ่มแค่ส่วน registries:
{ "$schema": "https://ui.shadcn.com/schema.json", "style": "new-york", "rsc": false, "tsx": true, "tailwind": { "config": "", "css": "src/index.css", "baseColor": "neutral", "cssVariables": true, "prefix": "" }, "aliases": { "components": "@/components", "utils": "@/lib/utils", "ui": "@/components/ui", "lib": "@/lib", "hooks": "@/hooks" }, "registries": { "@kanok-ui": { "url": "https://cdn.jsdelivr.net/npm/@purpurabog/ui@latest/registry/{name}.json" } } }

ควรระบุเวอร์ชันใน URL (@purpurabog/ui@0.82.0 แทน @latest) ทุกไฟล์ที่ copy มาจะได้มาจาก release เดียวกัน

  1. เพิ่ม component:
npx shadcn@4 add @kanok-ui/tw-select @kanok-ui/tw-button
  1. import token และธีม ต่อจาก Tailwind ในไฟล์ CSS หลัก:
@import 'tailwindcss'; @import './components/ui/primitives/tokens.css'; @import './components/ui/react-tw/theme.css';

ไฟล์จะไปอยู่ที่ components/ui/ (ใต้ src/ ถ้าแอปมีโฟลเดอร์นี้)

React แบบไม่มี style (headless)

สำหรับ design system ของคุณเอง: ได้พฤติกรรมครบโดยไม่มี class เลยสักตัว

npm i @purpurabog/ui react react-dom

สถานะแสดงเป็น attribute data-* (data-open, data-selected, data-highlighted …) ใช้แต่งหน้าตาได้ ชิ้นส่วนเหล่านี้มีหมวดของตัวเอง เริ่มที่ Headless

ใช้ component ตัวแรก

dropdown ตัวเดียวกันแบบ web component, wrapper ของ React และ React + Tailwind ตัวอย่างทุกตัวในเว็บนี้มีแท็บเหล่านี้ เลือกแท็บของคุณครั้งเดียว หน้าอื่นจะเปิดแท็บนั้นตาม แบบ headless อยู่ที่ Headless

HTMLReactReact + Tailwind<html lang="th"> <ui-dropdown label="ประเภทสัญญา" name="type" placeholder="เลือกประเภท"> <option value="sale">ซื้อขาย</option> <option value="lease">เช่า</option> </ui-dropdown> import { UiDropdown } from '@purpurabog/ui/react'; <UiDropdown label="ประเภทสัญญา" name="type" placeholder="เลือกประเภท"> <option value="sale">ซื้อขาย</option> <option value="lease">เช่า</option> </UiDropdown> // npx shadcn@4 add @kanok-ui/tw-dropdown import { Dropdown } from '@/components/ui/react-tw/dropdown'; const types = [ { value: 'sale', label: 'ซื้อขาย' }, { value: 'lease', label: 'เช่า' }, ]; <Dropdown label="ประเภทสัญญา" name="type" placeholder="เลือกประเภท" items={types} />

lang ที่ element หรือ ancestor ใดก็ได้ กำหนดภาษาของข้อความในตัว component ทั้งของ web component และ wrapper ของ React (มีไทยและอังกฤษให้แล้ว)