feat: add interactive floating profile dropdown menu with Profil Saya and Keluar Sistem

This commit is contained in:
Wahyudin
2026-10-13 15:47:04 +07:00
parent 97b69e42f1
commit 02770356ae
+73 -5
View File
@@ -405,10 +405,15 @@
</h1> </h1>
</div> </div>
<!-- Sisi Kanan: Profil Pengguna (Avatar Bulat + Nama + Role Huruf Kapital) Sesuai Gambar IT All Role --> <!-- Sisi Kanan: Profil Pengguna (Avatar Bulat + Nama + Role Huruf Kapital + Menu Melayang) Sesuai Gambar IT All Role -->
<div class="flex items-center space-x-3"> <div id="userProfileContainer" class="relative">
<a href="{{ route('profile.index') }}" class="flex items-center space-x-3 pl-3 hover:opacity-80 transition group" title="Buka Profil Saya"> <button type="button"
<div class="w-9 h-9 rounded-full bg-[#1b5e20] text-white font-bold text-sm flex items-center justify-center shadow-sm group-hover:ring-2 ring-emerald-500/30"> id="userProfileDropdownBtn"
onclick="toggleProfileDropdown()"
class="flex items-center space-x-2.5 p-1 sm:px-2.5 sm:py-1.5 rounded-xl hover:bg-slate-50 transition group focus:outline-none cursor-pointer"
aria-expanded="false"
aria-haspopup="true">
<div class="w-9 h-9 rounded-full bg-[#1b5e20] text-white font-bold text-sm flex items-center justify-center shadow-sm group-hover:ring-2 ring-emerald-500/30 flex-shrink-0">
{{ strtoupper(substr(auth()->user()->name, 0, 1)) }} {{ strtoupper(substr(auth()->user()->name, 0, 1)) }}
</div> </div>
<div class="text-left hidden sm:block"> <div class="text-left hidden sm:block">
@@ -417,7 +422,29 @@
{{ str_replace('_', ' ', auth()->user()->role) }} {{ str_replace('_', ' ', auth()->user()->role) }}
</p> </p>
</div> </div>
</a> <i id="userProfileChevron" class="fa-solid fa-chevron-down text-slate-400 text-[11px] ml-1 transition-transform duration-200 group-hover:text-slate-600"></i>
</button>
<!-- Menu Melayang (Dropdown Menu) Sesuai Referensi Gambar -->
<div id="userProfileDropdownMenu"
class="hidden absolute right-0 top-full mt-2 w-52 bg-white rounded-2xl shadow-xl border border-slate-100 py-1.5 z-50 transform origin-top-right transition-all">
<a href="{{ route('profile.index') }}"
class="flex items-center space-x-3 px-4 py-2.5 text-xs font-semibold text-slate-700 hover:text-slate-900 hover:bg-slate-50 transition">
<i class="fa-regular fa-user text-sm text-slate-400 w-4 text-center"></i>
<span>Profil Saya</span>
</a>
<div class="border-t border-slate-100 my-1"></div>
<form method="POST" action="{{ route('logout') }}" class="w-full">
@csrf
<button type="submit"
class="w-full flex items-center space-x-3 px-4 py-2.5 text-xs font-bold text-rose-600 hover:text-rose-700 hover:bg-rose-50/70 transition text-left cursor-pointer">
<i class="fa-solid fa-arrow-right-from-bracket text-sm w-4 text-center text-rose-500"></i>
<span>Keluar Sistem</span>
</button>
</form>
</div>
</div> </div>
</header> </header>
@@ -600,6 +627,47 @@
chevron.classList.toggle('rotate-180'); chevron.classList.toggle('rotate-180');
} }
} }
// Toggle Dropdown Menu Profil Pengguna di Pojok Kanan Atas
function toggleProfileDropdown() {
const dropdown = document.getElementById('userProfileDropdownMenu');
const chevron = document.getElementById('userProfileChevron');
const btn = document.getElementById('userProfileDropdownBtn');
if (dropdown) {
const isHidden = dropdown.classList.toggle('hidden');
if (btn) btn.setAttribute('aria-expanded', !isHidden);
}
if (chevron) {
chevron.classList.toggle('rotate-180');
}
}
// Tutup dropdown profil jika mengklik di luar area
document.addEventListener('click', function(event) {
const container = document.getElementById('userProfileContainer');
const dropdown = document.getElementById('userProfileDropdownMenu');
const chevron = document.getElementById('userProfileChevron');
const btn = document.getElementById('userProfileDropdownBtn');
if (container && dropdown && !container.contains(event.target)) {
dropdown.classList.add('hidden');
if (chevron) chevron.classList.remove('rotate-180');
if (btn) btn.setAttribute('aria-expanded', 'false');
}
});
// Tutup dropdown profil jika menekan tombol Escape
document.addEventListener('keydown', function(event) {
if (event.key === 'Escape') {
const dropdown = document.getElementById('userProfileDropdownMenu');
const chevron = document.getElementById('userProfileChevron');
const btn = document.getElementById('userProfileDropdownBtn');
if (dropdown && !dropdown.classList.contains('hidden')) {
dropdown.classList.add('hidden');
if (chevron) chevron.classList.remove('rotate-180');
if (btn) btn.setAttribute('aria-expanded', 'false');
}
}
});
</script> </script>
@yield('scripts') @yield('scripts')