diff --git a/.agents/admin-ui-pitfalls.md b/.agents/admin-ui-pitfalls.md new file mode 100644 index 0000000..35961c4 --- /dev/null +++ b/.agents/admin-ui-pitfalls.md @@ -0,0 +1,135 @@ +# Admin Panel UI Pitfalls & Patterns + +## 1. Dropdowns Inside Tables — Always Use Smart Positioning + +**❌ Đừng bao giờ viết cứng** `top-full mt-1` hoặc `bottom-full mb-1` cho dropdown trong table: + +```vue + +
+ + +
+``` + +**✅ Đúng — dùng computed position dựa trên index:** + +```ts +// Helper để dropdown luôn hiển thị bên trong vùng nhìn thấy +function getDropdownPosition(index: number) { + const total = items.value?.length || 0 + // Chỉ mở lên trên khi còn ít nhất 2 hàng phía dưới + if (total <= 2 || index < total - 2) { + return 'top-full mt-1' + } + return 'bottom-full mb-1' +} +``` + +```vue + +``` + +### Rule Checklist: +- [ ] Mỗi cell có dropdown cần `relative` wrapper +- [ ] Hàm `getDropdownPosition` nhận index từ `items.indexOf(item)` +- [ ] Dùng dynamic class binding, KHÔNG hardcode vị trí +- [ ] Kiểm tra khi item nằm ở hàng cuối cùng của bảng + +--- + +## 2. Table Clipping — Remove `overflow-hidden` on Card Wrappers + +Khi table có dropdown/menu, `.admin-card overflow-hidden` sẽ cắt mất dropdown khi nó mở ra ngoài vùng chứa. + +**✅ Luôn bỏ `overflow-hidden` hoặc override bằng `overflow-visible!`:** + +```vue + +
+``` + +> **Lưu ý Tailwind v4 syntax**: dùng `overflow-visible!` chứ KHÔNG phải `!overflow-visible`. Linter sẽ báo lỗi nếu viết sai. + +--- + +## 3. Admin Light Mode — Hardcoded Colors Need Override + +Các component admin dùng hardcode màu dark mode (`bg-[#131418]`, `text-white`, `border-white/6`) không tự động chuyển khi xem trong light mode. Cần xử lý theo thứ tự ưu tiên: + +### Thứ tự xử lý đúng: + +1. **Preference 1**: Đổi trực tiếp template sang light-mode colors (`bg-white`, `border-slate-200`, `text-slate-900`) +2. **Preference 2**: Thêm rule CSS vào `.agents/admin-light-palette.md` nếu nhiều nơi share style +3. **Last resort**: Dùng CSS selector override trong layout `