Responsive Sidebar Navigation Layout Component
A full-featured, responsive sidebar layout component for application dashboards. It includes an animated collapsible sidebar, a main content area that adjusts its margin accordingly, a mobile overlay, and separate open/close controls for a seamless user experience on both desktop and mobile devices.
LTR
RTL
<div class="flex min-h-screen">
<!-- Sidebar -->
<div
x-show="isSidebarOpen"
class="fixed inset-y-0 left-0 w-64 bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 shadow-lg transform transition-transform duration-300 ease-in-out z-50"
:class="{ 'translate-x-0': isSidebarOpen, '-translate-x-full': !isSidebarOpen }"
x-cloak
>
<div class="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700">
<h2 class="text-lg font-semibold">Dashboard</h2>
<button
@click="isSidebarOpen = false"
class="text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200"
>
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
</button>
</div>
<nav class="p-4 space-y-2">
<a href="#" class="flex items-center space-x-2 rtl:space-x-reverse p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors duration-200">
<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5">
<path d="M1 6V15H6V11C6 9.89543 6.89543 9 8 9C9.10457 9 10 9.89543 10 11V15H15V6L8 0L1 6Z" fill="#000000"/>
</svg>
<span>Dashboard</span>
</a>
<a href="#" class="flex items-center space-x-2 rtl:space-x-reverse p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors duration-200">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
</svg>
<span>Users</span>
</a>
<a href="#" class="flex items-center space-x-2 rtl:space-x-reverse p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors duration-200">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7h8m0 0v8m0-8l-8 8-4-4-6 6"></path>
</svg>
<span>Analytics</span>
</a>
<a href="#" class="flex items-center space-x-2 rtl:space-x-reverse p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors duration-200">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/>
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/>
</svg>
<span>Settings</span>
</a>
</nav>
</div>
<!-- Mobile Overlay -->
<div
x-show="isSidebarOpen"
@click="isSidebarOpen = false"
class="fixed inset-0 bg-black bg-opacity-50 z-40 md:hidden"
x-cloak
></div>
<!-- Main Content -->
<div class="flex-1 transition-all duration-300 ease-in-out" :class="{ 'md:ml-64': isSidebarOpen, 'md:ml-0': !isSidebarOpen }">
<div class="p-4">
<div class="flex items-center justify-between mb-4">
<button
@click="isSidebarOpen = !isSidebarOpen"
class="text-gray-900 dark:text-gray-100 hover:bg-gray-100 dark:hover:bg-gray-700 p-2 rounded-lg transition-colors duration-200"
>
<svg x-show="!isSidebarOpen" class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
<h1 class="text-xl font-semibold text-gray-900 dark:text-gray-100">Dashboard Content</h1>
<div class="w-6 h-6"></div> <!-- Spacer for alignment -->
</div>
<div class="bg-white dark:bg-gray-800 rounded-lg shadow p-6 mb-6">
<h2 class="text-lg font-semibold text-gray-900 dark:text-gray-100 mb-4">Welcome to your dashboard</h2>
<p class="text-gray-700 dark:text-gray-300 mb-4">Use the sidebar to navigate through different sections like Users, Analytics, and Settings. The sidebar now works on both mobile and desktop devices.</p>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mt-6">
<div class="bg-blue-50 dark:bg-blue-900/20 p-4 rounded-lg border border-blue-200 dark:border-blue-800">
<h3 class="font-semibold text-blue-900 dark:text-blue-100">Users</h3>
<p class="text-blue-700 dark:text-blue-300 text-sm mt-1">Manage user accounts and permissions</p>
</div>
<div class="bg-green-50 dark:bg-green-900/20 p-4 rounded-lg border border-green-200 dark:border-green-800">
<h3 class="font-semibold text-green-900 dark:text-green-100">Analytics</h3>
<p class="text-green-700 dark:text-green-300 text-sm mt-1">View detailed reports and statistics</p>
</div>
<div class="bg-purple-50 dark:bg-purple-900/20 p-4 rounded-lg border border-purple-200 dark:border-purple-800">
<h3 class="font-semibold text-purple-900 dark:text-purple-100">Settings</h3>
<p class="text-purple-700 dark:text-purple-300 text-sm mt-1">Configure your dashboard preferences</p>
</div>
</div>
</div>
</div>
</div>
</div>