Spaces:
Running
Running
| class CustomHeader extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| nav { | |
| padding: 1rem 0; | |
| box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1); | |
| } | |
| .dark nav { | |
| box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.5); | |
| } | |
| .nav-link { | |
| transition: color 0.2s ease; | |
| } | |
| .nav-link:hover { | |
| color: #3B82F6; | |
| } | |
| .dark .nav-link:hover { | |
| color: #818CF8; | |
| } | |
| .theme-toggle { | |
| transition: transform 0.3s ease; | |
| } | |
| .theme-toggle:hover { | |
| transform: scale(1.1); | |
| } | |
| </style> | |
| <header class="bg-white dark:bg-gray-800 sticky top-0 z-50"> | |
| <nav class="container mx-auto px-4"> | |
| <div class="flex justify-between items-center"> | |
| <a href="/" class="flex items-center space-x-2"> | |
| <i data-feather="zap" class="text-primary-500 dark:text-secondary-500 w-6 h-6"></i> | |
| <span class="text-xl font-bold text-gray-800 dark:text-white">LightSwitch</span> | |
| </a> | |
| <div class="flex items-center space-x-4"> | |
| <a href="#" class="nav-link text-gray-600 dark:text-gray-300">Home</a> | |
| <a href="#" class="nav-link text-gray-600 dark:text-gray-300">Components</a> | |
| <a href="#" class="nav-link text-gray-600 dark:text-gray-300">About</a> | |
| <button onclick="toggleTheme()" class="theme-toggle p-2 rounded-full focus:outline-none"> | |
| <i data-feather="moon" class="text-gray-600 dark:text-yellow-300 w-5 h-5 hidden dark:block"></i> | |
| <i data-feather="sun" class="text-gray-600 dark:text-yellow-300 w-5 h-5 block dark:hidden"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </nav> | |
| </header> | |
| `; | |
| // We need to call feather.replace() after the component renders | |
| setTimeout(() => { | |
| if (window.feather) { | |
| window.feather.replace(); | |
| } | |
| }, 100); | |
| } | |
| } | |
| customElements.define('custom-header', CustomHeader); |