File size: 3,864 Bytes
499a14d | 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
header {
background: rgba(17, 24, 39, 0.8);
backdrop-filter: blur(10px);
border-bottom: 1px solid rgba(55, 65, 81, 0.5);
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
}
nav {
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 0;
}
.logo {
font-weight: 700;
font-size: 1.5rem;
background: linear-gradient(135deg, #a855f7, #ec4899);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.nav-links {
display: flex;
align-items: center;
gap: 2rem;
}
.nav-link {
color: #d1d5db;
text-decoration: none;
transition: color 0.2s;
}
.nav-link:hover {
color: white;
}
.theme-toggle {
background: none;
border: none;
color: #d1d5db;
cursor: pointer;
padding: 0.5rem;
border-radius: 0.375rem;
transition: all 0.2s;
}
.theme-toggle:hover {
color: white;
background: rgba(55, 65, 81, 0.5);
}
@media (max-width: 768px) {
.nav-links {
gap: 1rem;
}
}
</style>
<header>
<div class="container">
<nav>
<a href="index.html" class="logo">ComponentForge</a>
<div class="nav-links">
<a href="index.html" class="nav-link">New Project</a>
<a href="#" class="nav-link">Templates</a>
<a href="#" class="nav-link">Docs</a>
<button class="theme-toggle" id="themeToggle">
<i data-feather="moon"></i>
</button>
</div>
</nav>
</div>
</header>
`;
// Initialize feather icons in shadow DOM
const featherScript = document.createElement('script');
featherScript.src = 'https://unpkg.com/feather-icons';
this.shadowRoot.appendChild(featherScript);
featherScript.onload = () => {
feather.replace();
// Theme toggle functionality
const themeToggle = this.shadowRoot.getElementById('themeToggle');
themeToggle.addEventListener('click', () => {
themeManager.toggleTheme();
this.updateThemeIcon();
});
};
}
updateThemeIcon() {
const themeIcon = this.shadowRoot.querySelector('#themeToggle i');
if (themeManager.currentTheme === 'dark') {
themeIcon.setAttribute('data-feather', 'sun');
} else {
themeIcon.setAttribute('data-feather', 'moon');
}
feather.replace();
}
}
customElements.define('custom-header', CustomHeader); |