talib12's picture
clear
827ace5 verified
Raw History Blame Contribute Delete
5.07 kB
class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
.header {
height: 4rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.dark .header {
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
.avatar {
width: 2.5rem;
height: 2.5rem;
}
.dropdown {
transition: all 0.3s ease;
transform-origin: top right;
}
</style>
<header class="header fixed top-0 left-0 right-0 z-30 bg-white dark:bg-secondary-500 flex items-center justify-between px-4">
<div class="flex items-center space-x-4">
<button id="sidebarToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
<i data-feather="menu"></i>
</button>
<h1 class="text-xl font-bold text-primary-500">ChatFusion Pro</h1>
</div>
<div class="flex items-center space-x-4">
<button id="themeToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
<i data-feather="moon"></i>
</button>
<button id="messengerToggle" class="p-2 rounded-full hover:bg-gray-100 dark:hover:bg-secondary-600">
<i data-feather="message-square"></i>
</button>
<div class="relative">
<button id="profileToggle" class="flex items-center space-x-2 focus:outline-none">
<div class="avatar rounded-full bg-primary-500 flex items-center justify-center text-white">
<i data-feather="user"></i>
</div>
<span class="hidden md:inline font-medium text-gray-700 dark:text-gray-300">User</span>
<i data-feather="chevron-down" class="w-4 h-4 text-gray-500"></i>
</button>
<div id="profileDropdown" class="dropdown absolute right-0 mt-2 w-48 bg-white dark:bg-secondary-500 rounded-md shadow-lg py-1 z-40 hidden origin-top-right">
<a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Profile</a>
<a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Settings</a>
<a href="#" class="block px-4 py-2 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-secondary-600">Log out</a>
</div>
</div>
</div>
</header>
`;
// Add event listeners
this.shadowRoot.getElementById('themeToggle').addEventListener('click', () => {
document.dispatchEvent(new CustomEvent('themeToggle'));
feather.replace();
});
this.shadowRoot.getElementById('sidebarToggle').addEventListener('click', () => {
const currentState = localStorage.getItem('sidebarState') || 'expanded';
const newState = currentState === 'expanded' ? 'collapsed' : 'expanded';
localStorage.setItem('sidebarState', newState);
document.dispatchEvent(new CustomEvent('sidebarStateChange', { detail: newState }));
});
this.shadowRoot.getElementById('messengerToggle').addEventListener('click', () => {
const currentState = localStorage.getItem('messengerState') || 'expanded';
const newState = currentState === 'expanded' ? 'collapsed' : 'expanded';
localStorage.setItem('messengerState', newState);
document.dispatchEvent(new CustomEvent('messengerStateChange', { detail: newState }));
});
// Profile dropdown toggle
const profileToggle = this.shadowRoot.getElementById('profileToggle');
const profileDropdown = this.shadowRoot.getElementById('profileDropdown');
profileToggle.addEventListener('click', () => {
const isHidden = profileDropdown.classList.toggle('hidden');
profileDropdown.classList.toggle('scale-95', !isHidden);
profileDropdown.classList.toggle('scale-100', isHidden);
profileDropdown.classList.toggle('opacity-0', !isHidden);
});
// Close dropdown when clicking outside
document.addEventListener('click', (event) => {
if (!this.shadowRoot.contains(event.target)) {
profileDropdown.classList.add('hidden');
}
});
}
}
customElements.define('custom-header', CustomHeader);