Skip to content

บทที่ 7: Component Libraries

“ทำไมต้องออกแบบโซฟาเอง ในเมื่อ IKEA มีให้เลือกเป็นร้อย?”

The Blueprint (พิมพ์เขียว)

Section titled “The Blueprint (พิมพ์เขียว)”

เมื่อสร้างเว็บแอป คุณต้องมี:

  • ปุ่ม, ฟอร์ม, ตาราง
  • Modal, Dropdown, Tab
  • DatePicker, Slider, Toast

Component Library = แค็ตตาล็อก IKEA — เฟอร์นิเจอร์สำเร็จรูปที่ประกอบเข้ากับบ้านได้ทันที

The Construction Site (หน้างานก่อสร้าง)

Section titled “The Construction Site (หน้างานก่อสร้าง)”

🛋️ ทำไมต้องใช้ Component Library?

Section titled “🛋️ ทำไมต้องใช้ Component Library?”
DIY (ทำเอง)ใช้ Library
⏰ ใช้เวลานาน⚡ ประหยัดเวลา
🐛 อาจมี Bug✅ ผ่านการทดสอบ
📱 ต้องทำ Responsive เอง📱 Responsive พร้อมใช้
♿ ต้องทำ A11y เอง♿ Accessible ในตัว

Material Selection (เลือกสเปกวัสดุ)

Section titled “Material Selection (เลือกสเปกวัสดุ)”

🎨 Component Libraries ยอดนิยม

Section titled “🎨 Component Libraries ยอดนิยม”
LibraryStyleข้อดี
shadcn/uiMinimalCopy-paste, customize ได้เต็มที่
Ant DesignEnterpriseComponents ครบ
MUIMaterial DesignGoogle style
Chakra UISimpleใช้ง่าย
Terminal window
# ติดตั้ง
npx shadcn@latest init
npx shadcn@latest add button card table
import { Button } from "@/components/ui/button";
<Button variant="default">Default</Button>
<Button variant="outline">Outline</Button>
<Button variant="destructive">Delete</Button>
import { Button, Table, Modal, Form } from 'antd';
<Button type="primary">Primary Button</Button>
<Table columns={columns} dataSource={data} />

Architect’s Note (บันทึกสถาปนิก)

Section titled “Architect’s Note (บันทึกสถาปนิก)”
  1. เลือก Library ที่เหมาะกับโปรเจกต์

    • Dashboard → Ant Design
    • Landing Page → shadcn/ui
  2. Bundle Size สำคัญ — Import เฉพาะที่ใช้

  3. Customization — ตรวจสอบว่าแก้ไข Theme ได้ง่ายไหม

  1. ใช้ Design Tokens สำหรับ Theming
  2. สร้าง Wrapper Components เพื่อ customize
  3. อ่าน Documentation ให้ละเอียด