บทที่ 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 ยอดนิยม”| Library | Style | ข้อดี |
|---|---|---|
| shadcn/ui | Minimal | Copy-paste, customize ได้เต็มที่ |
| Ant Design | Enterprise | Components ครบ |
| MUI | Material Design | Google style |
| Chakra UI | Simple | ใช้ง่าย |
⚫ shadcn/ui — Modern Choice
Section titled “⚫ shadcn/ui — Modern Choice”# ติดตั้งnpx shadcn@latest initnpx shadcn@latest add button card tableimport { Button } from "@/components/ui/button";
<Button variant="default">Default</Button><Button variant="outline">Outline</Button><Button variant="destructive">Delete</Button>🐜 Ant Design — Enterprise Ready
Section titled “🐜 Ant Design — Enterprise Ready”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 (บันทึกสถาปนิก)”⚠️ ข้อควรระวัง
Section titled “⚠️ ข้อควรระวัง”-
เลือก Library ที่เหมาะกับโปรเจกต์
- Dashboard → Ant Design
- Landing Page → shadcn/ui
-
Bundle Size สำคัญ — Import เฉพาะที่ใช้
-
Customization — ตรวจสอบว่าแก้ไข Theme ได้ง่ายไหม
💡 Best Practices
Section titled “💡 Best Practices”- ใช้ Design Tokens สำหรับ Theming
- สร้าง Wrapper Components เพื่อ customize
- อ่าน Documentation ให้ละเอียด