File size: 2,769 Bytes
fef669d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);