feat: fixing sidebar on mobile

This commit is contained in:
Carlos Gutierrez
2025-09-02 19:52:01 -04:00
parent 8f9e4f54df
commit 0f0da5fb8f
3 changed files with 30 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { Clock, BarChart3, Settings, Sun, Moon } from "lucide-react"; import { Clock, BarChart3, Settings, Sun, Moon, X } from "lucide-react";
import { Button } from "@/components/atoms/Button"; import { Button } from "@/components/atoms/Button";
import { useTheme } from "@/lib/theme"; import { useTheme } from "@/lib/theme";
import { useStore } from "@/lib/store"; import { useStore } from "@/lib/store";
@@ -10,12 +10,14 @@ interface SidebarProps {
className?: string; className?: string;
isMobile?: boolean; isMobile?: boolean;
onNavigate?: () => void; onNavigate?: () => void;
onClose?: () => void;
} }
export function Sidebar({ export function Sidebar({
className = "", className = "",
isMobile = false, isMobile = false,
onNavigate, onNavigate,
onClose,
}: SidebarProps) { }: SidebarProps) {
const { theme, toggleTheme } = useTheme(); const { theme, toggleTheme } = useTheme();
const [location] = useLocation(); const [location] = useLocation();
@@ -44,19 +46,30 @@ export function Sidebar({
return ( return (
<aside <aside
className={`w-64 bg-card border-r border-border flex-shrink-0 sidebar-transition ${ className={`w-64 bg-card border-r border-border flex-shrink-0 sidebar-transition h-screen ${
isMobile ? "sidebar-mobile" : "" isMobile ? "sidebar-mobile" : ""
} ${className}`} } ${className}`}
> >
<div className="flex flex-col h-full"> <div className="flex flex-col h-full">
{/* Logo/Brand */} {/* Logo/Brand */}
<div className="p-6 border-b border-border"> <div className="p-6 border-b border-border flex items-center justify-between">
<div className="flex items-center space-x-3"> <div className="flex items-center space-x-3">
<div className="w-8 h-8 bg-primary rounded-lg flex items-center justify-center"> <div className="w-8 h-8 bg-primary rounded-lg flex items-center justify-center">
<Clock className="text-primary-foreground text-sm" /> <Clock className="text-primary-foreground text-sm" />
</div> </div>
<h1 className="text-xl font-semibold">Pomodorian</h1> <h1 className="text-xl font-semibold">Pomodorian</h1>
</div> </div>
{isMobile && onClose && (
<Button
variant="ghost"
size="icon"
onClick={onClose}
className="md:hidden"
data-testid="button-sidebar-close"
>
<X className="w-5 h-5" />
</Button>
)}
</div> </div>
{/* Navigation Menu */} {/* Navigation Menu */}

View File

@@ -63,9 +63,10 @@ export function MainLayout({ children, title, subtitle }: MainLayoutProps) {
<div className="flex h-screen overflow-hidden"> <div className="flex h-screen overflow-hidden">
{/* Sidebar Navigation */} {/* Sidebar Navigation */}
<Sidebar <Sidebar
className={`md:translate-x-0 ${sidebarOpen ? 'open' : ''}`} className={`${sidebarOpen ? 'open' : ''}`}
isMobile={true} isMobile={true}
onNavigate={closeSidebar} onNavigate={closeSidebar}
onClose={closeSidebar}
/> />
{/* Mobile Sidebar Overlay */} {/* Mobile Sidebar Overlay */}

View File

@@ -113,15 +113,26 @@
transition: transform 0.3s ease-in-out; transition: transform 0.3s ease-in-out;
} }
@media (max-width: 768px) { @media (max-width: 767px) {
.sidebar-mobile { .sidebar-mobile {
transform: translateX(-100%); transform: translateX(-100%);
position: fixed;
z-index: 50;
height: 100vh;
top: 0;
left: 0;
} }
.sidebar-mobile.open { .sidebar-mobile.open {
transform: translateX(0); transform: translateX(0);
} }
} }
@media (min-width: 768px) {
.sidebar-mobile {
transform: translateX(0);
}
}
div, div,
p { p {
text-wrap: auto !important; text-wrap: auto !important;