Alexander1337's picture
<div class="language-switcher">
376562a verified
class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
background-color: white;
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
position: sticky;
top: 0;
z-index: 1000;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
max-width: 1200px;
margin: 0 auto;
}
.logo {
font-weight: 700;
font-size: 1.25rem;
color: #EF4444;
}
nav ul {
display: flex;
gap: 1.5rem;
list-style: none;
margin: 0;
padding: 0;
}
nav a {
font-weight: 500;
color: #333;
transition: color 0.2s;
position: relative;
}
nav a:hover {
color: #EF4444;
}
nav a::after {
content: '';
position: absolute;
bottom: -4px;
left: 0;
width: 0;
height: 2px;
background-color: #EF4444;
transition: width 0.2s;
}
nav a:hover::after {
width: 100%;
}
.lang-switcher {
display: flex;
gap: 0.5rem;
align-items: center;
}
.lang-switcher a {
font-weight: 600;
color: #6B7280;
font-size: 1.2rem;
text-decoration: none;
transition: color 0.2s;
}
.lang-switcher a:hover {
color: #EF4444;
}
.lang-switcher a.active {
color: #EF4444;
transform: scale(1.1);
}
.mobile-menu-button {
display: none;
background: none;
border: none;
cursor: pointer;
}
@media (max-width: 768px) {
nav {
position: fixed;
top: 70px;
left: 0;
width: 100%;
background-color: white;
padding: 1rem;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
transform: translateY(-150%);
transition: transform 0.3s ease;
}
nav.active {
transform: translateY(0);
}
nav ul {
flex-direction: column;
gap: 1rem;
}
.mobile-menu-button {
display: block;
}
.lang-switcher {
margin-top: 1rem;
justify-content: center;
}
}
</style>
<header>
<a href="#" class="logo">Alexander Adolfsson Coaching</a>
<button class="mobile-menu-button">
<i data-feather="menu"></i>
</button>
<nav>
<ul>
<li><a href="/">Hem</a></li>
<li><a href="/about.html">Om mig</a></li>
<li><a href="#services">Tjänster</a></li>
<li><a href="#pricing">Priser</a></li>
<li><a href="#booking">Boka</a></li>
<li><a href="#contact">Kontakt</a></li>
</ul>
<div class="lang-switcher">
<a href="?lang=sv" class="${window.location.search.includes('lang=sv') ? 'active' : ''}">🇸🇪</a>
<span>|</span>
<a href="?lang=en" class="${window.location.search.includes('lang=en') ? 'active' : ''}">🇬🇧</a>
<span>|</span>
<a href="?lang=es" class="${window.location.search.includes('lang=es') ? 'active' : ''}">🇪🇸</a>
</div>
</nav>
</header>
`;
// Mobile menu toggle
const mobileMenuButton = this.shadowRoot.querySelector('.mobile-menu-button');
const nav = this.shadowRoot.querySelector('nav');
mobileMenuButton.addEventListener('click', () => {
nav.classList.toggle('active');
});
// Close menu when clicking a link
const navLinks = this.shadowRoot.querySelectorAll('nav a');
navLinks.forEach(link => {
link.addEventListener('click', () => {
nav.classList.remove('active');
});
});
// Load Feather icons after component is rendered
if (window.feather) {
feather.replace();
} else {
document.addEventListener('DOMContentLoaded', () => {
if (window.feather) {
feather.replace();
}
});
}
}
}
customElements.define('custom-header', CustomHeader);