Greg Claude Opus 4.7 (1M context) commited on
Commit
c16d5c1
·
1 Parent(s): 55f0bbf

feat(ta-01): responsive layout with mobile hamburger drawer

Browse files

- Mobile topbar (< md) with hamburger button on the left, brand on right
- Sidebar slides in from the left as a drawer on mobile; static on md+
- Backdrop overlay closes the drawer on click
- Auto-close on route change (useLocation effect) and after tapping a NavLink
- Close button (X) inside the sidebar header on mobile
- main-content pads for the topbar on mobile (pt-[4.5rem]) and the sidebar
offset only applies on md+ (ml-0 md:ml-64)

Sidebar receives optional mobileOpen + onClose props so the drawer state
lives in Layout. The desktop experience is unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

frontend/src/components/Layout.tsx CHANGED
@@ -1,10 +1,44 @@
1
- import { Outlet } from 'react-router-dom';
 
 
2
  import Sidebar from './Sidebar';
3
 
4
  export default function Layout() {
 
 
 
 
 
 
 
 
5
  return (
6
  <div className="app-layout">
7
- <Sidebar />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  <main className="main-content">
9
  <Outlet />
10
  </main>
 
1
+ import { Outlet, useLocation } from 'react-router-dom';
2
+ import { useState, useEffect } from 'react';
3
+ import { Menu } from 'lucide-react';
4
  import Sidebar from './Sidebar';
5
 
6
  export default function Layout() {
7
+ const [mobileOpen, setMobileOpen] = useState(false);
8
+ const location = useLocation();
9
+
10
+ // Close drawer whenever the route changes.
11
+ useEffect(() => {
12
+ setMobileOpen(false);
13
+ }, [location.pathname]);
14
+
15
  return (
16
  <div className="app-layout">
17
+ {/* Mobile top bar (only < md) */}
18
+ <header className="mobile-topbar md:hidden">
19
+ <button
20
+ type="button"
21
+ onClick={() => setMobileOpen(true)}
22
+ aria-label="Abrir menú"
23
+ className="p-2 rounded-lg hover:bg-gray-800 text-white"
24
+ >
25
+ <Menu size={22} />
26
+ </button>
27
+ <span className="font-bold text-white">Talos Access</span>
28
+ <span className="w-9" />{/* spacer to keep title centered */}
29
+ </header>
30
+
31
+ {/* Backdrop for mobile drawer */}
32
+ {mobileOpen && (
33
+ <div
34
+ className="fixed inset-0 bg-black/50 z-30 md:hidden"
35
+ onClick={() => setMobileOpen(false)}
36
+ aria-hidden="true"
37
+ />
38
+ )}
39
+
40
+ <Sidebar mobileOpen={mobileOpen} onClose={() => setMobileOpen(false)} />
41
+
42
  <main className="main-content">
43
  <Outlet />
44
  </main>
frontend/src/components/Sidebar.tsx CHANGED
@@ -1,7 +1,12 @@
1
  import { NavLink } from 'react-router-dom';
2
  import { useAuthStore } from '../store/authStore';
3
  import { translateRole } from '../utils/roles';
4
- import { Users, LayoutDashboard, BookOpen, ClipboardCheck, LogOut, GraduationCap, BarChart3, Settings, CreditCard, Clock, Code2, IdCard, Heart, Calendar, Search, FileText } from 'lucide-react';
 
 
 
 
 
5
 
6
  const navItems = [
7
  { to: '/dashboard', label: 'Dashboard', icon: LayoutDashboard, roles: ['admin', 'teacher', 'representative', 'student', 'administrativo', 'obrero'] },
@@ -29,7 +34,7 @@ function hasAdminAccess(user: { role: string; permissions: string[] } | null): b
29
  return user?.role === 'admin' || user?.role === 'developer' || (user?.permissions ?? []).includes('admin.full');
30
  }
31
 
32
- export default function Sidebar() {
33
  const user = useAuthStore((s) => s.user);
34
  const clearAuth = useAuthStore((s) => s.clearAuth);
35
  const isAdmin = hasAdminAccess(user);
@@ -46,14 +51,32 @@ export default function Sidebar() {
46
  });
47
 
48
  return (
49
- <aside className="sidebar">
50
  <div className="sidebar-header">
51
- <span className="text-xl font-bold">Talos Access</span>
52
- <span className="sidebar-role">{translateRole(user?.role)}</span>
 
 
 
 
 
 
 
 
 
 
 
 
53
  </div>
54
  <nav className="sidebar-nav">
55
  {visible.map((item) => (
56
- <NavLink key={item.to} to={item.to} end={item.to === '/dashboard'} className={({ isActive }) => `nav-item${isActive ? ' active' : ''}`}>
 
 
 
 
 
 
57
  <item.icon size={18} />
58
  <span>{item.label}</span>
59
  </NavLink>
 
1
  import { NavLink } from 'react-router-dom';
2
  import { useAuthStore } from '../store/authStore';
3
  import { translateRole } from '../utils/roles';
4
+ import { Users, LayoutDashboard, BookOpen, ClipboardCheck, LogOut, GraduationCap, BarChart3, Settings, CreditCard, Clock, Code2, IdCard, Heart, Calendar, Search, FileText, X } from 'lucide-react';
5
+
6
+ interface SidebarProps {
7
+ mobileOpen?: boolean;
8
+ onClose?: () => void;
9
+ }
10
 
11
  const navItems = [
12
  { to: '/dashboard', label: 'Dashboard', icon: LayoutDashboard, roles: ['admin', 'teacher', 'representative', 'student', 'administrativo', 'obrero'] },
 
34
  return user?.role === 'admin' || user?.role === 'developer' || (user?.permissions ?? []).includes('admin.full');
35
  }
36
 
37
+ export default function Sidebar({ mobileOpen = false, onClose }: SidebarProps) {
38
  const user = useAuthStore((s) => s.user);
39
  const clearAuth = useAuthStore((s) => s.clearAuth);
40
  const isAdmin = hasAdminAccess(user);
 
51
  });
52
 
53
  return (
54
+ <aside className={`sidebar${mobileOpen ? ' sidebar-open' : ''}`}>
55
  <div className="sidebar-header">
56
+ <div className="flex flex-col">
57
+ <span className="text-xl font-bold">Talos Access</span>
58
+ <span className="sidebar-role">{translateRole(user?.role)}</span>
59
+ </div>
60
+ {onClose && (
61
+ <button
62
+ type="button"
63
+ onClick={onClose}
64
+ aria-label="Cerrar menú"
65
+ className="md:hidden p-1.5 rounded-lg hover:bg-gray-800 text-gray-300"
66
+ >
67
+ <X size={18} />
68
+ </button>
69
+ )}
70
  </div>
71
  <nav className="sidebar-nav">
72
  {visible.map((item) => (
73
+ <NavLink
74
+ key={item.to}
75
+ to={item.to}
76
+ end={item.to === '/dashboard'}
77
+ onClick={onClose}
78
+ className={({ isActive }) => `nav-item${isActive ? ' active' : ''}`}
79
+ >
80
  <item.icon size={18} />
81
  <span>{item.label}</span>
82
  </NavLink>
frontend/src/styles/layout.css CHANGED
@@ -2,12 +2,21 @@
2
  @apply flex min-h-screen;
3
  }
4
 
 
 
 
 
5
  .sidebar {
6
- @apply w-64 flex flex-col fixed inset-y-0 left-0 z-30 bg-gray-900 text-white;
 
 
 
 
 
7
  }
8
 
9
  .sidebar-header {
10
- @apply flex items-center justify-between p-4 border-b border-gray-700 shrink-0;
11
  }
12
 
13
  .sidebar-header h2 {
@@ -36,5 +45,7 @@
36
  }
37
 
38
  .main-content {
39
- @apply flex-1 ml-64 p-4 md:p-6 overflow-y-auto min-h-screen;
 
 
40
  }
 
2
  @apply flex min-h-screen;
3
  }
4
 
5
+ .mobile-topbar {
6
+ @apply fixed top-0 inset-x-0 z-20 h-14 bg-gray-900 text-white flex items-center justify-between px-4 shadow-md;
7
+ }
8
+
9
  .sidebar {
10
+ @apply w-64 flex flex-col fixed inset-y-0 left-0 z-40 bg-gray-900 text-white
11
+ -translate-x-full md:translate-x-0 transition-transform duration-200;
12
+ }
13
+
14
+ .sidebar-open {
15
+ @apply translate-x-0;
16
  }
17
 
18
  .sidebar-header {
19
+ @apply flex items-start justify-between p-4 border-b border-gray-700 shrink-0;
20
  }
21
 
22
  .sidebar-header h2 {
 
45
  }
46
 
47
  .main-content {
48
+ @apply flex-1 p-4 md:p-6 overflow-y-auto min-h-screen
49
+ pt-[4.5rem] md:pt-6
50
+ ml-0 md:ml-64;
51
  }