From 1041e6109bf609724f5c8a16dc6a11bc2608fc93 Mon Sep 17 00:00:00 2001 From: mlackner Date: Fri, 21 Nov 2025 00:20:57 +0100 Subject: [PATCH] feat(ui): implement mobile hamburger navigation menu Add responsive mobile navigation with hamburger menu toggle for smaller screens. The menu provides access to main navigation, dashboard, and authentication actions. Includes animated transitions and proper state management for improved mobile user experience. --- assets/tailwind.css | 80 +++++++++++++++++++++++++++++++++++++++ src/components/navbar.rs | 81 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/assets/tailwind.css b/assets/tailwind.css index 4d805d3..2757d9f 100644 --- a/assets/tailwind.css +++ b/assets/tailwind.css @@ -90,6 +90,7 @@ --radius-lg: 0.5rem; --radius-xl: 0.75rem; --radius-2xl: 1rem; + --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1); --animate-spin: spin 1s linear infinite; --blur-sm: 8px; --blur-md: 12px; @@ -246,24 +247,36 @@ } } @layer utilities { + .pointer-events-none { + pointer-events: none; + } .visible { visibility: visible; } .absolute { position: absolute; } + .fixed { + position: fixed; + } .relative { position: relative; } .inset-0 { inset: calc(var(--spacing) * 0); } + .inset-x-0 { + inset-inline: calc(var(--spacing) * 0); + } .-top-2 { top: calc(var(--spacing) * -2); } .top-0 { top: calc(var(--spacing) * 0); } + .top-16 { + top: calc(var(--spacing) * 16); + } .-right-2 { right: calc(var(--spacing) * -2); } @@ -288,6 +301,9 @@ .z-10 { z-index: 10; } + .z-40 { + z-index: 40; + } .z-50 { z-index: 50; } @@ -375,6 +391,9 @@ .inline-flex { display: inline-flex; } + .h-0\.5 { + height: calc(var(--spacing) * 0.5); + } .h-4 { height: calc(var(--spacing) * 4); } @@ -487,6 +506,28 @@ --tw-translate-x: calc(calc(1/2 * 100%) * -1); translate: var(--tw-translate-x) var(--tw-translate-y); } + .-translate-y-1\.5 { + --tw-translate-y: calc(var(--spacing) * -1.5); + translate: var(--tw-translate-x) var(--tw-translate-y); + } + .-translate-y-full { + --tw-translate-y: -100%; + translate: var(--tw-translate-x) var(--tw-translate-y); + } + .translate-y-0 { + --tw-translate-y: calc(var(--spacing) * 0); + translate: var(--tw-translate-x) var(--tw-translate-y); + } + .translate-y-1\.5 { + --tw-translate-y: calc(var(--spacing) * 1.5); + translate: var(--tw-translate-x) var(--tw-translate-y); + } + .-rotate-45 { + rotate: calc(45deg * -1); + } + .rotate-45 { + rotate: 45deg; + } .transform { transform: var(--tw-rotate-x,) var(--tw-rotate-y,) var(--tw-rotate-z,) var(--tw-skew-x,) var(--tw-skew-y,); } @@ -761,6 +802,9 @@ .bg-slate-50 { background-color: var(--color-slate-50); } + .bg-slate-300 { + background-color: var(--color-slate-300); + } .bg-slate-600 { background-color: var(--color-slate-600); } @@ -791,6 +835,12 @@ background-color: color-mix(in oklab, var(--color-slate-900) 80%, transparent); } } + .bg-slate-900\/95 { + background-color: color-mix(in srgb, oklch(20.8% 0.042 265.755) 95%, transparent); + @supports (color: color-mix(in lab, red, red)) { + background-color: color-mix(in oklab, var(--color-slate-900) 95%, transparent); + } + } .bg-transparent { background-color: transparent; } @@ -938,6 +988,9 @@ .py-24 { padding-block: calc(var(--spacing) * 24); } + .pt-4 { + padding-top: calc(var(--spacing) * 4); + } .pt-6 { padding-top: calc(var(--spacing) * 6); } @@ -950,6 +1003,9 @@ .text-center { text-align: center; } + .text-left { + text-align: left; + } .font-mono { font-family: var(--font-mono); } @@ -1106,6 +1162,16 @@ color: var(--color-slate-500); } } + .opacity-0 { + opacity: 0%; + } + .opacity-100 { + opacity: 100%; + } + .shadow-2xl { + --tw-shadow: 0 25px 50px -12px var(--tw-shadow-color, rgb(0 0 0 / 0.25)); + box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); + } .shadow-lg { --tw-shadow: 0 10px 15px -3px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 4px 6px -4px var(--tw-shadow-color, rgb(0 0 0 / 0.1)); box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); @@ -1179,6 +1245,10 @@ --tw-duration: 300ms; transition-duration: 300ms; } + .ease-in-out { + --tw-ease: var(--ease-in-out); + transition-timing-function: var(--ease-in-out); + } .outline-none { --tw-outline-style: none; outline-style: none; @@ -1542,6 +1612,11 @@ display: flex; } } + .sm\:hidden { + @media (width >= 40rem) { + display: none; + } + } .sm\:space-x-8 { @media (width >= 40rem) { :where(& > :not(:last-child)) { @@ -1867,6 +1942,10 @@ syntax: "*"; inherits: false; } +@property --tw-ease { + syntax: "*"; + inherits: false; +} @property --tw-outline-style { syntax: "*"; inherits: false; @@ -1954,6 +2033,7 @@ --tw-backdrop-saturate: initial; --tw-backdrop-sepia: initial; --tw-duration: initial; + --tw-ease: initial; --tw-outline-style: solid; --tw-scale-x: 1; --tw-scale-y: 1; diff --git a/src/components/navbar.rs b/src/components/navbar.rs index 8c2f5fd..4fd5d41 100644 --- a/src/components/navbar.rs +++ b/src/components/navbar.rs @@ -6,6 +6,7 @@ use dioxus::prelude::*; pub fn Navbar() -> Element { let mut user_state = use_context::>>(); let navigator = use_navigator(); + let mut mobile_menu_open = use_signal(|| false); rsx! { div { @@ -42,6 +43,33 @@ pub fn Navbar() -> Element { } } } + + // Hamburger menu button (visible on small screens) + div { + class: "sm:hidden flex items-center", + button { + class: "text-slate-300 hover:text-white p-2 rounded-md transition-all", + onclick: move |_| mobile_menu_open.set(!mobile_menu_open()), + aria_label: "Toggle navigation menu", + aria_expanded: "{mobile_menu_open()}", + // Hamburger icon (three horizontal lines) + div { + class: "w-6 h-6 flex flex-col justify-center space-y-1", + div { + class: "w-6 h-0.5 bg-slate-300 transition-all", + class: if mobile_menu_open() { "rotate-45 translate-y-1.5" } else { "" } + } + div { + class: "w-6 h-0.5 bg-slate-300 transition-all", + class: if mobile_menu_open() { "opacity-0" } else { "" } + } + div { + class: "w-6 h-0.5 bg-slate-300 transition-all", + class: if mobile_menu_open() { "-rotate-45 -translate-y-1.5" } else { "" } + } + } + } + } } div { class: "flex items-center", @@ -72,6 +100,59 @@ pub fn Navbar() -> Element { } } + // Mobile menu dropdown (visible when hamburger is clicked) + div { + class: "sm:hidden", + div { + class: "fixed inset-x-0 top-16 bg-slate-900/95 backdrop-blur-md border-b border-white/10 shadow-2xl z-40 transform transition-all duration-300 ease-in-out", + class: if mobile_menu_open() { "translate-y-0 opacity-100" } else { "-translate-y-full opacity-0 pointer-events-none" }, + div { + class: "px-4 py-4 space-y-2", + Link { + to: Route::Home {}, + class: "block text-slate-300 hover:text-white hover:bg-white/5 px-3 py-2 rounded-md text-base font-medium transition-all", + onclick: move |_| mobile_menu_open.set(false), + "Startseite" + } + if let Some(_user) = user_state() { + Link { + to: Route::Dashboard {}, + class: "block text-slate-300 hover:text-white hover:bg-white/5 px-3 py-2 rounded-md text-base font-medium transition-all", + onclick: move |_| mobile_menu_open.set(false), + "Dashboard" + } + } + if let Some(user) = user_state() { + div { + class: "pt-4 border-t border-white/10", + div { + class: "px-3 py-2 text-slate-400 text-sm", + "Willkommen, {user.username}!" + } + button { + class: "w-full text-left text-slate-300 hover:text-white hover:bg-white/5 px-3 py-2 rounded-md text-base font-medium transition-all", + onclick: move |_| async move { + mobile_menu_open.set(false); + if auth::logout().await.is_ok() { + user_state.set(None); + navigator.push(Route::Home {}); + } + }, + "Abmelden" + } + } + } else { + Link { + to: Route::Auth {}, + class: "block bg-indigo-600 text-white px-3 py-2 rounded-md text-base font-medium hover:bg-indigo-500 transition-all text-center mt-4", + onclick: move |_| mobile_menu_open.set(false), + "Anmelden" + } + } + } + } + } + div { class: "flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-slate-700 scrollbar-track-transparent", Outlet:: {}