@biza-gov/layout 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,718 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # @biza-gov/layout
2
+
3
+ Government Layout Components สำหรับเว็บแอปพลิเคชันภาครัฐ
4
+
5
+ > ใช้คู่กับ `@biza-gov/token-css` เพื่อให้สีตรงตาม Design System
6
+
7
+ ---
8
+
9
+ ## 📥 Installation
10
+
11
+ ```bash
12
+ npm install @biza-gov/layout @biza-gov/token-css
13
+ ```
14
+
15
+ ```css
16
+ /* ใน globals.css */
17
+ @import "@biza-gov/token-css";
18
+ ```
19
+
20
+ ---
21
+
22
+ ## 📦 Components ทั้งหมด
23
+
24
+ | Component | ใช้สำหรับ | import |
25
+ |-----------|----------|--------|
26
+ | `StaffSidebar` | Sidebar เจ้าหน้าที่ | `import { StaffSidebar } from '@biza-gov/layout'` |
27
+ | `UserHeader` | Header ผู้ใช้ทั่วไป | `import { UserHeader } from '@biza-gov/layout'` |
28
+ | `UserSidebar` | Sidebar ผู้ใช้ (slide-in) | `import { UserSidebar } from '@biza-gov/layout'` |
29
+ | `SettingsPanel` | หน้าตั้งค่า (font + theme) | `import { SettingsPanel } from '@biza-gov/layout'` |
30
+ | `SettingsProvider` | Context wrapper | `import { SettingsProvider } from '@biza-gov/layout'` |
31
+ | `useSettings` | Hook อ่าน/เปลี่ยนค่า | `import { useSettings } from '@biza-gov/layout'` |
32
+ | `Icons` | ไอคอน built-in 33 ตัว | `import { Icons } from '@biza-gov/layout'` |
33
+ | `useLineConnectCallback`| Hook จัดการ LIFF Callback | `import { useLineConnectCallback } from '@biza-gov/layout'` |
34
+ | `startLineConnection` | เริ่มการเชื่อมต่อ LINE | `import { startLineConnection } from '@biza-gov/layout'` |
35
+
36
+ ---
37
+
38
+ ## 🎯 Icons (ไอคอน built-in)
39
+
40
+ import ครั้งเดียว ใช้ได้ทุกไอคอน — ไม่ต้องสร้าง SVG เอง
41
+
42
+ ### วิธีใช้งาน
43
+
44
+ ```tsx
45
+ import { Icons } from '@biza-gov/layout';
46
+
47
+ // ใช้ตรงๆ
48
+ <Icons.Folder />
49
+ <Icons.User />
50
+ <Icons.Gear />
51
+
52
+ // ปรับขนาด (default = 20)
53
+ <Icons.Home size={24} />
54
+
55
+ // ใส่ใน MenuItem
56
+ const menuItems: MenuItem[] = [
57
+ { id: 'services', title: 'งานบริการ', icon: <Icons.Folder />, path: '/services' },
58
+ { id: 'users', title: 'จัดการผู้ใช้', icon: <Icons.User />, path: '/users' },
59
+ { id: 'reports', title: 'รายงาน', icon: <Icons.BarChart />, path: '/reports' },
60
+ ];
61
+ ```
62
+
63
+ ### ไอคอนทั้งหมด
64
+
65
+ | ชื่อ | Component | ใช้สำหรับ |
66
+ |------|-----------|----------|
67
+ | 🏠 | `Icons.Home` | หน้าแรก / Dashboard |
68
+ | 🔍 | `Icons.Search` | ค้นหา |
69
+ | 🔔 | `Icons.Bell` | แจ้งเตือน |
70
+ | 📁 | `Icons.Folder` | งานบริการ / หมวดหมู่ |
71
+ | 📋 | `Icons.Clipboard` | แบบฟอร์ม / คำร้อง |
72
+ | 📄 | `Icons.FileText` | รายงาน / เอกสาร |
73
+ | 📅 | `Icons.Calendar` | ตารางงาน / นัดหมาย |
74
+ | 👤 | `Icons.User` | ข้อมูลผู้ใช้ |
75
+ | 👥 | `Icons.Users` | จัดการสมาชิก |
76
+ | ⚙️ | `Icons.Gear` | ตั้งค่าระบบ |
77
+ | 🔧 | `Icons.Wrench` | ซ่อมบำรุง |
78
+ | 🛡️ | `Icons.Shield` | สิทธิ์การใช้งาน |
79
+ | ❓ | `Icons.HelpCircle` | ช่วยเหลือ |
80
+ | 📊 | `Icons.BarChart` | สถิติ / รายงาน |
81
+ | 🕐 | `Icons.History` | ประวัติการใช้งาน |
82
+ | 💾 | `Icons.Database` | สำรองข้อมูล |
83
+ | | `Icons.Building` | หน่วยงาน / องค์กร |
84
+ | 📍 | `Icons.MapPin` | สถานที่ |
85
+ | 📞 | `Icons.Phone` | ติดต่อ |
86
+ | ✉️ | `Icons.Mail` | อีเมล / ข้อความ |
87
+ | ✅ | `Icons.CheckCircle` | สำเร็จ / อนุมัติ |
88
+ | ⚠️ | `Icons.AlertTriangle` | คำเตือน |
89
+ | ❌ | `Icons.XCircle` | ปฏิเสธ / ข้อผิดพลาด |
90
+ | ➕ | `Icons.PlusCircle` | เพิ่มรายการ |
91
+ | 🚪 | `Icons.LogOut` | ออกจากระบบ |
92
+ | ⬇️ | `Icons.Download` | ดาวน์โหลด |
93
+ | ⬆️ | `Icons.Upload` | อัปโหลด |
94
+ | 🖨️ | `Icons.Printer` | พิมพ์เอกสาร |
95
+ | ⭐ | `Icons.Star` | รายการโปรด |
96
+ | ❤️ | `Icons.Heart` | ถูกใจ |
97
+ | 👁️ | `Icons.Eye` | ดูรายละเอียด |
98
+ | ✏️ | `Icons.Edit` | แก้ไข |
99
+ | 🗑️ | `Icons.Trash` | ลบ |
100
+
101
+ ### IconProps
102
+
103
+ | Prop | Type | Default | คำอธิบาย |
104
+ |------|------|---------|----------|
105
+ | `size` | `number?` | `20` | ขนาด (width & height) |
106
+ | `className` | `string?` | - | CSS class |
107
+ | `style` | `CSSProperties?` | - | inline style |
108
+
109
+ > 💡 ถ้าต้องการ import ทีละตัวก็ได้: `import { FolderIcon, UserIcon } from '@biza-gov/layout'`
110
+
111
+ ## 1. StaffSidebar (เจ้าหน้าที่)
112
+
113
+ Sidebar ฝั่งซ้ายแบบ fixed — รองรับพับ/กาง (collapsible) + **รองรับมือถือแบบ Drawer** 🆕
114
+
115
+ ### ตัวอย่างใช้งาน
116
+
117
+ ```tsx
118
+ import { StaffSidebar } from '@biza-gov/layout';
119
+ import type { MenuItem } from '@biza-gov/layout';
120
+
121
+ // ไม่ต้องระบุ icon — sidebar จับคู่ไอคอนให้อัตโนมัติจาก id
122
+ const menuItems: MenuItem[] = [
123
+ {
124
+ id: 'services', // → 📁 FolderIcon
125
+ title: 'งานบริการ',
126
+ children: [
127
+ { id: 'water', title: 'ประปา', path: '/services/water' },
128
+ { id: 'tax', title: 'ภาษี', path: '/services/tax' },
129
+ ],
130
+ dividerAfter: true,
131
+ },
132
+ { id: 'users', title: 'จัดการผู้ใช้', path: '/users' }, // → 👥 UsersIcon
133
+ { id: 'reports', title: 'รายงาน', path: '/reports' }, // → 📊 BarChartIcon
134
+ { id: 'roles', title: 'สิทธิ์การใช้งาน', path: '/roles' }, // → 🛡️ ShieldIcon
135
+ { id: 'logs', title: 'ประวัติ', path: '/logs' }, // → 🕐 HistoryIcon
136
+ { id: 'backup', title: 'สำรองข้อมูล', path: '/backup' }, // → 💾 DatabaseIcon
137
+ ];
138
+
139
+ <StaffSidebar
140
+ orgLogo="/logo.png"
141
+ orgName="เทศบาลตำบล Biza"
142
+ orgSubtitle="จังหวัดราชบุรี"
143
+ menuItems={menuItems}
144
+ user={{ firstName: 'สมชาย', lastName: 'ใจดี' }}
145
+ roleLabel="เจ้าหน้าที่"
146
+ currentPath="/services/water"
147
+ onNavigate={(path) => router.push(path)}
148
+ onLogout={() => signOut()}
149
+ onProfile={() => router.push('/profile')}
150
+ collapsible
151
+ />
152
+ ```
153
+
154
+ > **💡 Auto-Icon:** ไม่ต้อง import ไอคอน — sidebar จับคู่จาก `id` อัตโนมัติ
155
+ > ถ้าอยากกำหนดเอง ก็ส่ง `icon` prop ได้ตามปกติ: `icon: <Icons.Folder />`
156
+
157
+ > **💡 ข้อมูลองค์กร (`orgLogo`, `orgName`, `orgSubtitle`) มาจากไหนก็ได้:**
158
+ > - ดึงจาก **ตัวกลาง SSO** หลังล็อกอิน (แนะนำ) เช่น `useSSOAuth().organization`
159
+ > - ดึงจาก **API** เช่น `fetchOrgInfo()`
160
+ > - **Fix ค่า** ตรงๆ ก็ได้ ถ้าใช้ระบบเดียว
161
+ >
162
+ > Library ไม่ผูกกับแหล่งข้อมูลใดๆ — แค่รับ props แล้วแสดงผล
163
+
164
+ ### Default Bottom Menu
165
+
166
+ ไม่ต้องตั้งค่าเอง — มี **ตั้งค่าระบบ** + **ช่วยเหลือ** อยู่ด้านล่างอัตโนมัติ
167
+
168
+ ```
169
+ งานบริการ ▽
170
+ ประปา / ภาษี / ทะเบียน
171
+ ──────────────
172
+ จัดการผู้ใช้
173
+ รายงาน
174
+ ตั้งค่าระบบ ← default (ไม่ต้องส่ง)
175
+ ช่วยเหลือ ← default (ไม่ต้องส่ง)
176
+ ↕ spacer
177
+ โปรไฟล์ + ออกจากระบบ
178
+ ```
179
+
180
+ ถ้าอยากเปลี่ยน bottom menu เอง:
181
+
182
+ ```tsx
183
+ <StaffSidebar
184
+ bottomMenuItems={[
185
+ { id: 'settings', title: 'ตั้งค่า', icon: <Icons.Gear />, path: '/settings' },
186
+ ]}
187
+ ...
188
+ />
189
+ ```
190
+
191
+ ถ้าไม่อยากมี bottom menu:
192
+
193
+ ```tsx
194
+ <StaffSidebar bottomMenuItems={[]} ... />
195
+ ```
196
+
197
+ ### Props ทั้งหมด
198
+
199
+ | Prop | Type | Default | คำอธิบาย |
200
+ |------|------|---------|----------|
201
+ | `orgLogo` | `string?` | - | URL รูปตราองค์กร |
202
+ | `orgName` | `string` | **required** | ชื่อองค์กร |
203
+ | `orgSubtitle` | `string?` | - | ชื่อรอง เช่น จังหวัด |
204
+ | `menuItems` | `MenuItem[]` | **required** | เมนูหลัก |
205
+ | `bottomMenuItems` | `MenuItem[]?` | ตั้งค่าระบบ + ช่วยเหลือ | เมนูด้านล่าง |
206
+ | `user` | `User \| null` | **required** | ข้อมูลผู้ใช้ |
207
+ | `roleLabel` | `string` | **required** | ป้ายตำแหน่ง เช่น "เจ้าหน้าที่" |
208
+ | `onNavigate` | `(path) => void` | **required** | callback เมื่อคลิกเมนู |
209
+ | `onLogout` | `() => void` | **required** | callback ออกจากระบบ |
210
+ | `onProfile` | `() => void?` | - | callback เมื่อกดโปรไฟล์ผู้ใช้ |
211
+ | `currentPath` | `string?` | - | path ปัจจุบัน (highlight active) |
212
+ | `width` | `string?` | `'280px'` | ความกว้าง sidebar |
213
+ | `collapsible` | `boolean?` | `false` | เปิดโหมดพับ/กาง |
214
+ | `isOpen` | `boolean?` | - | controlled open/close |
215
+ | `onToggle` | `() => void?` | - | callback เมื่อกดพับ/กาง |
216
+ | `mobileBreakpoint` | `number?` | `768` | breakpoint (px) สำหรับสลับเป็นโหมดมือถือ 🆕 |
217
+
218
+ ### 📱 Mobile Responsive (v1.3.5+) 🆕
219
+
220
+ เมื่อหน้าจอ **แคบกว่า `mobileBreakpoint`** (default: 768px) sidebar จะสลับเป็นโหมดมือถืออัตโนมัติ:
221
+
222
+ ```
223
+ ┌─────────────────────────────┐
224
+ │ 🟢 ชื่อองค์กร [☰] │ ← Mobile Header (sticky top)
225
+ ├─────────────────────────────┤
226
+ │ │
227
+ │ เนื้อหาหลัก │
228
+ │ │
229
+ └─────────────────────────────┘
230
+
231
+ กดปุ่ม ☰ →
232
+
233
+ ┌──────────────────┬──────────┐
234
+ │ 🟢 ชื่อองค์กร [✕]│▒▒▒▒▒▒▒▒▒│ ← Drawer + Overlay
235
+ │──────────────────│▒▒▒▒▒▒▒▒▒│
236
+ │ ☐ แดชบอร์ด │▒▒▒▒▒▒▒▒▒│
237
+ │ ☐ ตรวจสอบคำร้อง │▒▒▒▒▒▒▒▒▒│
238
+ │ ☐ รายงาน │▒▒▒▒▒▒▒▒▒│
239
+ │ ... │▒▒▒▒▒▒▒▒▒│
240
+ │──────────────────│▒▒▒▒▒▒▒▒▒│
241
+ │ 👤 ผู้ใช้ [🚪] │▒▒▒▒▒▒▒▒▒│
242
+ └──────────────────┴──────────┘
243
+ ```
244
+
245
+ **ฟีเจอร์โหมดมือถือ:**
246
+
247
+ - ✅ **Mobile Header** — แถบด้านบนสีเขียวแสดงโลโก้ + ชื่อองค์กร + ปุ่ม ☰
248
+ - ✅ **Drawer slide-in** — เลื่อนเข้าจากซ้ายพร้อม animation
249
+ - ✅ **Overlay backdrop** — พื้นหลังมืดเมื่อเปิด drawer (กดปิดได้)
250
+ - ✅ **ปุ่มปิด (✕)** — อยู่ใน header ของ drawer
251
+ - ✅ **ปิดอัตโนมัติ** — เมื่อกดเมนูแล้ว drawer ปิดเอง
252
+ - ✅ **ESC key** — กด Escape ปิด drawer
253
+ - ✅ **Lock scroll** — ล็อก body scroll เมื่อ drawer เปิด
254
+ - ✅ **ไม่ต้องเขียนโค้ดเพิ่ม** — ใช้ `<StaffSidebar>` ตัวเดียว ตรวจจับอัตโนมัติ
255
+
256
+ **ไม่ต้องแก้โค้ดเดิม** — แค่อัพเดตเวอร์ชัน ระบบจะตรวจจับขนาดหน้าจอให้อัตโนมัติ:
257
+
258
+ ```tsx
259
+ // ใช้ StaffSidebar เหมือนเดิม — mobile responsive ทำงานอัตโนมัติ
260
+ <StaffSidebar
261
+ orgName="เทศบาลตำบลหลักเมือง"
262
+ orgSubtitle="จังหวัดราชบุรี"
263
+ menuItems={menuItems}
264
+ user={user}
265
+ roleLabel="เจ้าหน้าที่"
266
+ currentPath={currentPath}
267
+ onNavigate={(path) => router.push(path)}
268
+ onLogout={() => signOut()}
269
+ />
270
+
271
+ // หรือปรับ breakpoint เอง
272
+ <StaffSidebar mobileBreakpoint={1024} ... />
273
+ ```
274
+
275
+ > 💡 **Layout `marginLeft`:** บนมือถือ sidebar ไม่กินพื้นที่ → ใส่ `marginLeft: 0` ให้ main content
276
+ >
277
+ > ```tsx
278
+ > <main style={{ marginLeft: isMobile ? 0 : 280 }}>{children}</main>
279
+ > ```
280
+
281
+ ### Features
282
+
283
+ - ✅ Dropdown submenu (พับ/กางอัตโนมัติ)
284
+ - ✅ Auto-expand เมื่อ child active
285
+ - ✅ Active item highlight
286
+ - ✅ Collapsible — พับเป็น icon-only 64px, กางเป็น 280px
287
+ - ✅ Tooltip เมื่อพับ
288
+ - ✅ Default ตั้งค่าระบบ + ช่วยเหลือ (override ได้)
289
+ - ✅ โปรไฟล์ + ออกจากระบบ ล่างสุดเสมอ
290
+ - ✅ `dividerAfter` เส้นคั่นระหว่างกลุ่ม
291
+ - ✅ ใช้ Standard Avatar Placeholder กรณีที่ไม่มีรูปโปรไฟล์หรือโหลดรูปไม่สำเร็จ (v1.3.2+)
292
+ - ✅ **Mobile Responsive Drawer** — สลับเป็น slide-in drawer บนมือถืออัตโนมัติ (v1.3.5+) 🆕
293
+
294
+ ---
295
+
296
+ ## 2. UserHeader (ผู้ใช้ทั่วไป)
297
+
298
+ Header ด้านบนพร้อม notification bell
299
+
300
+ ```tsx
301
+ import { UserHeader } from '@biza-gov/layout';
302
+
303
+ <UserHeader
304
+ user={{
305
+ firstName: 'ชนธัญ',
306
+ pictureUrl: '/avatar.jpg',
307
+ subtitle: 'ผู้สูงอายุ', // แสดงใต้ข้อความทักทาย (optional)
308
+ }}
309
+ notifications={[
310
+ {
311
+ id: 1,
312
+ title: 'คำร้องใหม่รอตรวจสอบ',
313
+ description: 'มีคำร้องใหม่เข้ามา กรุณาตรวจสอบ',
314
+ date: '2 ชม. ที่แล้ว',
315
+ type: 'warning',
316
+ isRead: false,
317
+ category: 'action', // ← แสดงในแท็บ "ต้องดำเนินการ"
318
+ },
319
+ {
320
+ id: 2,
321
+ title: 'คำร้องได้รับการอนุมัติ',
322
+ description: 'คำร้องหมายเลข #1234 อนุมัติสำเร็จ',
323
+ date: '5 ชม. ที่แล้ว',
324
+ type: 'success',
325
+ isRead: true,
326
+ category: 'general', // ← แสดงในแท็บ "แจ้งเตือนทั่วไป"
327
+ },
328
+ ]}
329
+ onToggleSidebar={() => setOpen(true)}
330
+ onMarkAllRead={() => markAllRead()}
331
+ onViewAll={() => router.push('/notifications')}
332
+ onNotificationClick={(notif) => router.push(`/notifications/${notif.id}`)}
333
+ onProfile={() => router.push('/profile')}
334
+ />
335
+ ```
336
+
337
+ ### Props
338
+
339
+ | Prop | Type | Default | คำอธิบาย |
340
+ |------|------|---------|----------|
341
+ | `user.firstName` | `string?` | - | ชื่อ |
342
+ | `user.lastName` | `string?` | - | นามสกุล |
343
+ | `user.pictureUrl` | `string?` | - | URL รูปโปรไฟล์ |
344
+ | `user.subtitle` | `string?` | - | ข้อความใต้ชื่อ เช่น "ผู้สูงอายุ" |
345
+ | `notifications` | `NotificationItem[]?` | `[]` | รายการแจ้งเตือน |
346
+ | `onToggleSidebar` | `() => void?` | - | callback เปิด sidebar |
347
+ | `onMarkAllRead` | `() => void?` | - | callback อ่านทั้งหมดแล้ว |
348
+ | `onViewAll` | `() => void?` | - | callback ดูทั้งหมด |
349
+ | `onNotificationClick` | `(notification) => void?` | - | callback เมื่อกดแจ้งเตือนแต่ละรายการ |
350
+ | `onProfile` | `() => void?` | - | callback เมื่อกดโปรไฟล์ |
351
+ | `notificationBell` | `ReactNode?` | - | custom bell icon |
352
+ | `className` | `string?` | - | className เพิ่มเติม |
353
+
354
+ ### 🔔 Notification Filter Tabs (v1.2.25+)
355
+
356
+ Dropdown แจ้งเตือนมีแท็บกรอง 3 หมวด พร้อม badge ตัวเลข:
357
+
358
+ | แท็บ | กรองจาก `category` | ตัวอย่างใช้งาน |
359
+ |------|-------------------|----------------|
360
+ | **ทั้งหมด** | แสดงทุกรายการ | ดูภาพรวม |
361
+ | **ต้องดำเนินการ** | `'action'` | คำร้องใหม่รอตรวจสอบ, ต้องอัปโหลดเอกสาร, มีคิวใหม่ |
362
+ | **แจ้งเตือนทั่วไป** | `'general'` หรือไม่ระบุ | อนุมัติสำเร็จ, จองสำเร็จ, ยกเลิกแล้ว |
363
+
364
+ > 💡 ถ้าไม่ส่ง `category` จะถูกจัดเป็น **แจ้งเตือนทั่วไป** อัตโนมัติ (backward compatible)
365
+
366
+ ### Features
367
+
368
+ - ✅ Notification bell พร้อม badge (99+ เมื่อเกิน)
369
+ - ✅ ไม่มีแจ้งเตือน → ไม่แสดง badge
370
+ - ✅ Notification dropdown แบบ scroll
371
+ - ✅ **Filter tabs**: ทั้งหมด / ต้องดำเนินการ / แจ้งเตือนทั่วไป 🆕
372
+ - ✅ **Badge ตัวเลข** แต่ละแท็บ 🆕
373
+ - ✅ **Category badge** "ต้องดำเนินการ" ติดแต่ละรายการ 🆕
374
+ - ✅ **Empty state แยกตาม filter** 🆕
375
+ - ✅ กดแจ้งเตือนแต่ละรายการ → `onNotificationClick`
376
+ - ✅ Subtitle ใต้ข้อความทักทาย (เช่น "ผู้สูงอายุ")
377
+ - ✅ ปุ่มเปิด sidebar (☰)
378
+ - ✅ กดโปรไฟล์ผู้ใช้ (avatar + ชื่อ) → `onProfile`
379
+ - ✅ รองรับ Dark Mode
380
+
381
+ ---
382
+
383
+ ## 3. UserSidebar (ผู้ใช้ทั่วไป)
384
+
385
+ Sidebar ฝั่งขวาแบบ slide-in + overlay
386
+
387
+ ```tsx
388
+ import { UserSidebar } from '@biza-gov/layout';
389
+
390
+ <UserSidebar
391
+ isOpen={isSidebarOpen}
392
+ onClose={() => setIsSidebarOpen(false)}
393
+ user={{ firstName: 'สมหญิง', lastName: 'ใจดี', pictureUrl: '/avatar.jpg' }}
394
+ roleLabel="ผู้สูงอายุ"
395
+ menuItems={[
396
+ { id: 'profile', title: 'ข้อมูลส่วนตัว', path: '/profile' },
397
+ { id: 'services', title: 'บริการหลัก', path: '/services' },
398
+ { id: 'settings', title: 'ตั้งค่าระบบ', path: '/settings' },
399
+ ]}
400
+ onNavigate={(path) => router.push(path)}
401
+ onLogout={() => signOut()}
402
+ onProfile={() => router.push('/profile')}
403
+ />
404
+ ```
405
+
406
+ > **หมายเหตุ:** `roleLabel` แต่ละระบบส่งค่าเองได้ เช่น "ผู้สูงอายุ", "ผู้ใช้ปกติ", "อาสาสมัคร"
407
+
408
+ ---
409
+
410
+ ## 4. SettingsPanel (ตั้งค่าระบบ) 🆕
411
+
412
+ ปรับขนาดตัวอักษร (5 ระดับ) + โหมดสว่าง/มืด — ค่าจำใน localStorage
413
+
414
+ ### ขั้นตอนที่ 1: ครอบ SettingsProvider
415
+
416
+ ```tsx
417
+ // app/providers.tsx ← ต้องเป็น 'use client'
418
+ 'use client';
419
+ import { SettingsProvider } from '@biza-gov/layout';
420
+
421
+ export default function Providers({ children }: { children: React.ReactNode }) {
422
+ return <SettingsProvider>{children}</SettingsProvider>;
423
+ }
424
+ ```
425
+
426
+ ```tsx
427
+ // app/layout.tsx
428
+ import Providers from './providers';
429
+
430
+ export default function RootLayout({ children }) {
431
+ return (
432
+ <html lang="th">
433
+ <body>
434
+ <Providers>{children}</Providers>
435
+ </body>
436
+ </html>
437
+ );
438
+ }
439
+ ```
440
+
441
+ ### ขั้นตอนที่ 2: วาง SettingsPanel
442
+
443
+ ```tsx
444
+ import { SettingsPanel } from '@biza-gov/layout';
445
+
446
+ // ผู้ใช้ทั่วไป → ทั้ง font + theme
447
+ <SettingsPanel />
448
+
449
+ // เจ้าหน้าที่ → แค่ปรับขนาดฟอนต์
450
+ <SettingsPanel showTheme={false} />
451
+ ```
452
+
453
+ | Prop | Type | Default | คำอธิบาย |
454
+ |------|------|---------|----------|
455
+ | `showTheme` | `boolean?` | `true` | แสดงตัวเลือกโหมดสว่าง/มืด |
456
+ | `className` | `string?` | - | className เพิ่มเติม |
457
+
458
+ ### ขั้นตอนที่ 3: ใช้ useSettings() hook (ถ้าต้องการ)
459
+
460
+ ```tsx
461
+ import { useSettings } from '@biza-gov/layout';
462
+
463
+ function MyComponent() {
464
+ const { theme, toggleTheme, fontSize, setFontSize, fontSizeOption } = useSettings();
465
+
466
+ return (
467
+ <div>
468
+ <p>ธีม: {theme}</p>
469
+ <p>ฟอนต์: {fontSize} (×{fontSizeOption.scale})</p>
470
+ <button onClick={toggleTheme}>สลับธีม</button>
471
+ <button onClick={() => setFontSize('large')}>ฟอนต์ใหญ่</button>
472
+ </div>
473
+ );
474
+ }
475
+ ```
476
+
477
+ ### ขนาดตัวอักษร (5 ระดับ)
478
+
479
+ | ค่า | Label | Scale | ผลลัพธ์ |
480
+ |-----|-------|-------|---------|
481
+ | `xsmall` | เล็กมาก | ×0.8 | ย่อทุกอย่าง 80% |
482
+ | `small` | เล็ก | ×0.9 | ย่อเล็กน้อย |
483
+ | `medium` | กลาง | ×1.0 | ค่าเริ่มต้น |
484
+ | `large` | ใหญ่ | ×1.2 | ขยาย 120% |
485
+ | `xlarge` | ใหญ่มาก | ×1.4 | ขยาย 140% |
486
+
487
+ ### หลักการทำงาน
488
+
489
+ - **Theme** — เพิ่ม/ลบ class `dark` บน `<html>` ➜ ใช้ CSS `html.dark` จัดสี
490
+ - **Font size** — ปรับ `body.style.zoom` + CSS variables ตาม scale
491
+ - **Persistence** — เก็บใน localStorage (`app-theme`, `app-font-size`)
492
+
493
+ ### Dark mode CSS ที่ต้องเพิ่ม
494
+
495
+ ```css
496
+ /* globals.css — เพิ่มสำหรับ dark mode */
497
+ html.dark body { background-color: #0f172a; color: #f1f5f9; }
498
+ html.dark aside { background-color: #1e293b !important; }
499
+ html.dark header { background-color: #1e293b !important; }
500
+ html.dark h1,
501
+ html.dark h2,
502
+ html.dark h3 { color: #f1f5f9 !important; }
503
+ html.dark p { color: #94a3b8 !important; }
504
+ ```
505
+
506
+ ---
507
+
508
+ ## 5. LINE Connection (LIFF Login) 🆕
509
+
510
+ Library ให้บริการ Custom Hook และคำสั่งสำหรับทำระบบเชื่อมต่อ LINE Login โดยจัดการ Callback และการเปิด LIFF SDK ให้อัตโนมัติ
511
+
512
+ ### 1. เรียกใช้งาน Callback Hook ในระดับ Layout
513
+
514
+ นำ `useLineConnectCallback` ไปใส่ไว้ในระดับ Layout (เช่น `layout.tsx`) เพื่อดักการ redirect กลับมาจาก LINE:
515
+
516
+ ```tsx
517
+ import { useLineConnectCallback } from '@biza-gov/layout';
518
+
519
+ export default function CitizenLayout({ children }) {
520
+ useLineConnectCallback({
521
+ liffId: process.env.NEXT_PUBLIC_LINE_LIFF_ID || "",
522
+ onLineConnected: async (lineId) => {
523
+ // ตัวอย่าง: ยิง API เพื่อบันทึก lineId ผูกกับ User ใน Database
524
+ await fetch("/api/user/settings", {
525
+ method: "PUT",
526
+ headers: { "Content-Type": "application/json" },
527
+ body: JSON.stringify({ lineId, lineNotifEnabled: true })
528
+ });
529
+ alert("เชื่อมต่อบัญชี LINE สำเร็จ!");
530
+ },
531
+ onConnectError: (err) => console.error("เชื่อมต่อล้มเหลว", err)
532
+ });
533
+
534
+ return <div>{children}</div>;
535
+ }
536
+ ```
537
+
538
+ ### 2. สร้างปุ่มสำหรับ "เชื่อมต่อ LINE"
539
+
540
+ ในหน้าตั้งค่า หรือหน้าที่ต้องการให้ผู้ใช้กด ให้เรียกใช้ `startLineConnection`:
541
+
542
+ ```tsx
543
+ import { startLineConnection } from '@biza-gov/layout';
544
+
545
+ export default function SettingsPage() {
546
+ return (
547
+ <button
548
+ onClick={() => startLineConnection(process.env.NEXT_PUBLIC_LINE_LIFF_ID)}
549
+ >
550
+ เชื่อมต่อ LINE เพื่อรับการแจ้งเตือน
551
+ </button>
552
+ );
553
+ }
554
+ ```
555
+
556
+ ---
557
+
558
+ ## 📐 Types
559
+
560
+ ```ts
561
+ // เมนู
562
+ interface MenuItem {
563
+ id: string;
564
+ title: string;
565
+ path?: string; // path สำหรับ navigate
566
+ icon?: React.ReactNode; // icon component
567
+ children?: MenuItem[]; // submenu → แสดงเป็น dropdown
568
+ dividerAfter?: boolean; // เส้นคั่นด้านล่าง
569
+ }
570
+
571
+ // ผู้ใช้
572
+ interface User {
573
+ id?: string | number;
574
+ firstName?: string;
575
+ lastName?: string;
576
+ pictureUrl?: string;
577
+ role?: string;
578
+ }
579
+
580
+ // การแจ้งเตือน
581
+ type NotificationCategory = 'action' | 'general';
582
+
583
+ interface NotificationItem {
584
+ id: string | number;
585
+ title: string;
586
+ description: string;
587
+ date: string;
588
+ type: 'info' | 'success' | 'warning' | 'error' | 'reminder';
589
+ isRead: boolean;
590
+ category?: NotificationCategory; // 🆕 หมวดหมู่: 'action' | 'general'
591
+ }
592
+
593
+ // ตั้งค่า
594
+ type Theme = 'light' | 'dark';
595
+ type FontSizeKey = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge';
596
+ ```
597
+
598
+ ---
599
+
600
+ ## 📁 Layout Examples
601
+
602
+ ### Staff Layout (เจ้าหน้าที่)
603
+
604
+ ```tsx
605
+ 'use client';
606
+ import { useState, useEffect } from 'react';
607
+ import { StaffSidebar, SettingsPanel } from '@biza-gov/layout';
608
+
609
+ // Hook ตรวจจับมือถือ (ใช้ breakpoint เดียวกับ StaffSidebar)
610
+ function useIsMobile(breakpoint = 768) {
611
+ const [isMobile, setIsMobile] = useState(false);
612
+ useEffect(() => {
613
+ const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
614
+ setIsMobile(mql.matches);
615
+ const handler = (e: MediaQueryListEvent) => setIsMobile(e.matches);
616
+ mql.addEventListener('change', handler);
617
+ return () => mql.removeEventListener('change', handler);
618
+ }, [breakpoint]);
619
+ return isMobile;
620
+ }
621
+
622
+ export default function AdminLayout({ children }) {
623
+ const [currentPath, setCurrentPath] = useState('/');
624
+ const isMobile = useIsMobile();
625
+
626
+ return (
627
+ <div style={{ display: 'flex' }}>
628
+ <StaffSidebar
629
+ orgLogo="/logo.png"
630
+ orgName="เทศบาลตำบล Biza"
631
+ orgSubtitle="จังหวัดราชบุรี"
632
+ menuItems={menuItems}
633
+ user={user}
634
+ roleLabel="เจ้าหน้าที่"
635
+ currentPath={currentPath}
636
+ onNavigate={(path) => setCurrentPath(path)}
637
+ onLogout={() => signOut()}
638
+ onProfile={() => setCurrentPath('/profile')}
639
+ collapsible
640
+ />
641
+ {/* มือถือ: marginLeft=0 เพราะ sidebar เป็น drawer */}
642
+ <main style={{ marginLeft: isMobile ? 0 : 280, flex: 1, padding: 32 }}>
643
+ {currentPath === '/settings' ? (
644
+ <SettingsPanel showTheme={false} />
645
+ ) : (
646
+ children
647
+ )}
648
+ </main>
649
+ </div>
650
+ );
651
+ }
652
+ ```
653
+
654
+ ### User Layout (ผู้ใช้ทั่วไป)
655
+
656
+ ```tsx
657
+ 'use client';
658
+ import { UserHeader, UserSidebar, SettingsPanel } from '@biza-gov/layout';
659
+
660
+ export default function UserLayout({ children }) {
661
+ const [open, setOpen] = useState(false);
662
+ const [currentPath, setCurrentPath] = useState('/');
663
+
664
+ return (
665
+ <>
666
+ <UserHeader
667
+ user={{ ...user, subtitle: 'ผู้สูงอายุ' }}
668
+ notifications={notifications}
669
+ onToggleSidebar={() => setOpen(true)}
670
+ onNotificationClick={(notif) => setCurrentPath(`/notifications/${notif.id}`)}
671
+ onProfile={() => setCurrentPath('/profile')}
672
+ />
673
+ <UserSidebar
674
+ isOpen={open}
675
+ onClose={() => setOpen(false)}
676
+ user={user}
677
+ roleLabel="ผู้ใช้ทั่วไป"
678
+ menuItems={menuItems}
679
+ onNavigate={(path) => setCurrentPath(path)}
680
+ onLogout={() => signOut()}
681
+ onProfile={() => setCurrentPath('/profile')}
682
+ />
683
+ <main style={{ padding: 32 }}>
684
+ {currentPath === '/settings' ? (
685
+ <SettingsPanel showTheme={true} />
686
+ ) : (
687
+ children
688
+ )}
689
+ </main>
690
+ </>
691
+ );
692
+ }
693
+ ```
694
+
695
+ ---
696
+
697
+ ## 🔧 Sub-Components
698
+
699
+ ใช้แยกกันได้ถ้าต้องการ customize เฉพาะส่วน
700
+
701
+ ```tsx
702
+ import {
703
+ SidebarHeader, // logo + ชื่อองค์กร
704
+ SidebarMenu, // เมนู dropdown
705
+ SidebarUserProfile, // avatar + logout
706
+ ThemeSettings, // UI เลือก theme อย่างเดียว
707
+ FontSizeSettings, // UI เลือก font size อย่างเดียว
708
+ } from '@biza-gov/layout';
709
+ ```
710
+
711
+ ---
712
+
713
+ ## 🎨 Styling
714
+
715
+ - Components ใช้ **inline styles** + CSS variables จาก `@biza-gov/token-css`
716
+ - ถ้าไม่ได้ import `@biza-gov/token-css` จะใช้สี **fallback** อัตโนมัติ
717
+ - Dark mode ต้องเพิ่ม CSS เอง (ดู section Dark mode CSS ด้านบน)
718
+ - Font size ใช้ `body.style.zoom` → scale ทุกอย่างรวมถึง inline `px`