feat(admin): collapsible sidebar and responsive data tables with custom scroll
This commit is contained in:
1 parent
b98c6bb457
commit
8a3adacd38
7 files changed
+171
-49
No files matched your search
@@ -57,9 +57,10 @@ interface MenuGroup {
|
||||
interface SidebarProps {
|
||||
isOpen: boolean;
|
||||
setIsOpen: (val: boolean) => void;
|
||||
isCollapsed?: boolean;
|
||||
}
|
||||
|
||||
export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
export default function Sidebar({ isOpen, setIsOpen, isCollapsed = false }: SidebarProps) {
|
||||
const location = useLocation();
|
||||
const [newOrdersCount, setNewOrdersCount] = useState(0);
|
||||
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
@@ -239,34 +240,97 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
)}
|
||||
|
||||
<aside
|
||||
className={`w-64 bg-white border-l border-gray-200 h-screen h-[100dvh] fixed lg:fixed lg:right-0 lg:top-0 lg:bottom-0 flex flex-col font-vazir shadow-sm z-50 transform transition-transform duration-300 ease-in-out overscroll-contain ${
|
||||
className={`${
|
||||
isCollapsed ? 'w-64 lg:w-20' : 'w-64'
|
||||
} bg-white border-l border-gray-200 h-screen h-[100dvh] fixed lg:fixed lg:right-0 lg:top-0 lg:bottom-0 flex flex-col font-vazir shadow-sm z-50 transform transition-all duration-300 ease-in-out overscroll-contain ${
|
||||
isOpen ? 'translate-x-0' : 'translate-x-full lg:translate-x-0'
|
||||
}`}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="h-16 flex items-center justify-between px-5 border-b border-gray-200 shrink-0 bg-white">
|
||||
<div className={`h-16 flex items-center ${isCollapsed ? 'justify-center lg:px-2 px-5' : 'justify-between px-5'} border-b border-gray-200 shrink-0 bg-white`}>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-8 h-8 rounded-xl bg-purple-600 flex items-center justify-center text-white font-black text-sm italic shadow-md">
|
||||
<div className="w-8 h-8 rounded-xl bg-purple-600 flex items-center justify-center text-white font-black text-sm italic shadow-md shrink-0">
|
||||
C
|
||||
</div>
|
||||
<span className="text-base font-black text-gray-900">کنینا | ادمینپنل</span>
|
||||
{!isCollapsed && (
|
||||
<span className="text-base font-black text-gray-900 truncate">کنینا | ادمینپنل</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-[10px] bg-purple-50 text-purple-700 font-bold px-2 py-0.5 rounded-md border border-purple-200">
|
||||
v2.4
|
||||
</span>
|
||||
{!isCollapsed && (
|
||||
<span className="text-[10px] bg-purple-50 text-purple-700 font-bold px-2 py-0.5 rounded-md border border-purple-200 shrink-0">
|
||||
v2.4
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Menu Navigation - touch friendly & full scrolling */}
|
||||
<nav className="flex-1 overflow-y-auto overscroll-contain py-3 px-3 space-y-2 pb-16 lg:pb-6">
|
||||
<nav className="flex-1 overflow-y-auto overscroll-contain py-3 px-2 space-y-2 pb-16 lg:pb-6 custom-scrollbar">
|
||||
{menuGroups.map((group) => {
|
||||
const GroupIcon = group.icon;
|
||||
const isExpanded = activeGroupId === group.id;
|
||||
const isExpanded = isCollapsed ? false : activeGroupId === group.id;
|
||||
const hasActiveChild = group.items.some(
|
||||
(item) =>
|
||||
location.pathname === item.path ||
|
||||
(item.path !== '/' && location.pathname.startsWith(item.path))
|
||||
);
|
||||
|
||||
if (isCollapsed) {
|
||||
// In collapsed mode, render compact group buttons with first active item link or dropdown
|
||||
const firstItem = group.items[0];
|
||||
return (
|
||||
<div key={group.id} className="relative group/collapsed flex flex-col items-center">
|
||||
<Link
|
||||
to={firstItem.path}
|
||||
onClick={() => setIsOpen(false)}
|
||||
title={group.title}
|
||||
className={`w-12 h-12 flex items-center justify-center rounded-2xl transition-all ${
|
||||
hasActiveChild
|
||||
? 'bg-purple-600 text-white shadow-md shadow-purple-600/30'
|
||||
: 'text-gray-500 hover:bg-purple-50 hover:text-purple-700'
|
||||
}`}
|
||||
>
|
||||
<GroupIcon className="w-5 h-5 shrink-0" />
|
||||
</Link>
|
||||
|
||||
{/* Flyout Submenu on Hover in Collapsed Mode */}
|
||||
<div className="hidden lg:group-hover/collapsed:block absolute right-full top-0 mr-2 w-56 bg-white rounded-2xl shadow-xl border border-gray-100 p-2 z-50">
|
||||
<div className="text-[11px] font-black text-purple-700 px-3 py-1.5 border-b border-gray-100 mb-1">
|
||||
{group.title}
|
||||
</div>
|
||||
<div className="space-y-0.5">
|
||||
{group.items.map((subItem) => {
|
||||
const isSubActive =
|
||||
location.pathname === subItem.path ||
|
||||
(subItem.path !== '/' && location.pathname.startsWith(subItem.path));
|
||||
const SubIcon = subItem.icon;
|
||||
return (
|
||||
<Link
|
||||
key={subItem.path}
|
||||
to={subItem.path}
|
||||
className={`flex items-center justify-between px-3 py-2 rounded-xl text-xs font-bold transition-all ${
|
||||
isSubActive
|
||||
? 'bg-purple-600 text-white'
|
||||
: 'text-gray-700 hover:bg-purple-50 hover:text-purple-700'
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<SubIcon className={`w-4 h-4 ${isSubActive ? 'text-white' : 'text-gray-400'}`} />
|
||||
<span>{subItem.label}</span>
|
||||
</div>
|
||||
{subItem.badge !== undefined && (
|
||||
<span className="text-[10px] font-black px-1.5 py-0.5 rounded-full bg-purple-100 text-purple-700">
|
||||
{subItem.badge}
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={group.id} className="rounded-2xl overflow-hidden bg-gray-50/50 border border-gray-100 transition-colors">
|
||||
{/* Group Accordion Header */}
|
||||
|
||||
Reference in new issue
Block a user