File: /var/www/affiliate.casatrade/src/components/Header/Header.svelte
<script lang="ts">
import logo from '../../assets/images/logo.svg';
import burger from '../../assets/images/burger.svg';
import close from '../../assets/images/close.svg';
import Button from '../Button/Button.svelte';
import Dropdown from '../Dropdown/Dropdown.svelte';
import { showForm, menu, indicator } from '../../store.js';
import MenuMobile from './MenuMobile.svelte';
import Lang from './Lang.svelte';
import { goto } from '$app/navigation';
import { t, locale, defaultLocale } from '$lib/translations';
import { base } from '$app/paths';
let menuOpen = false;
let indicatorShow = false;
let onClick = () => {
menu.set(!menuOpen);
};
const buttonClickHandler = () => {
const url = new URL("https://partner.casatrade.com/auth/signin");
const urlParams = new URLSearchParams(url.search);
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i);
if (key && key.includes('param__')) {
urlParams.append(key.replace('param__', ''), localStorage.getItem(key) || '');
}
}
window.location.href = `https://partner.casatrade.com/auth/signin${urlParams.toString() ? '?'+urlParams.toString() : ''}`;
};
const signUpClickHandler = () => {
showForm.set(true);
}
</script>
<header class="header {menuOpen ? 'active' : ''}">
<div class="headerContainer">
<a
class="headerLogo"
href="{base}/{$locale}"
>
<img class="logo" alt="logo" src={logo} />
</a>
<nav class="headerNav">
<a class="headerNavElement" href="{base}/{$locale !== defaultLocale ? $locale : ''}#advantages">{$t('Advantages')}</a>
<a class="headerNavElement" href="{base}/{$locale !== defaultLocale ? $locale : ''}#payments">{$t('Payments')}</a>
<a class="headerNavElement" href="{base}/{$locale !== defaultLocale ? $locale : ''}#offers">{$t('Offers')}</a>
<a class="headerNavElement" href="{base}/{$locale !== defaultLocale ? $locale : ''}#reviews">{$t('Reviews')}</a>
</nav>
<div class="headerControls">
<div class="dropdown">
<Lang />
<!-- <Dropdown title="Language"
options={[
{ name: 'English' },
{ name: 'Русский'},
{ name: 'Italiano' },
]} /> -->
</div>
<span
class="headerControlElement"
role="button"
on:click={buttonClickHandler}
tabindex="0"
on:keydown={() => false}
>{$t('Log in')}
</span>
<div class="button">
<Button className="primary" text={$t('Sign up')} onClick={signUpClickHandler}/>
</div>
<div
class="headerBurger"
on:click={onClick}
on:keydown={() => false}
tabindex="0"
role="button"
aria-label="Burger"
>
{#if menuOpen}
<img src={close} alt="close menu icon" width="20" height="20" />
{:else}
<img src={burger} alt="burger menu icon" width="20" height="20" />
{/if}
</div>
</div>
</div>
<MenuMobile />
</header>
<style lang="scss">
@import 'src/scss/variables';
@import 'src/scss/media';
.header {
width: 100%;
position: sticky;
top: 0;
z-index: 15;
color: $blue100;
&.active {
background: #f0ede8;
.headerContainer {
position: relative;
z-index: 51;
}
}
}
.dropdown {
order: 1;
@include breakpoint-down('deskS') {
order: 3;
}
@include breakpoint-down('tabM') {
display: none;
}
}
.headerControlElement {
order: 2;
@include breakpoint-down('tabM') {
display: none;
}
}
.button {
order: 3;
}
.headerContainer {
max-width: 1254px;
margin-inline: auto;
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 0;
@include breakpoint-down('deskS') {
max-width: 960px;
}
@include breakpoint-down('tabM') {
padding: 20px 0;
max-width: 656px;
}
@include breakpoint-down('tabS') {
max-width: none;
padding: 12px 26px;
}
@include breakpoint-down('mobM') {
padding: 12px 20px;
}
}
.headerLogo {
width: 153px;
height: 32px;
display: flex;
cursor: pointer;
@include breakpoint-down('mobM') {
width: 95.63;
height: 20px;
img {
object-position: left;
}
}
img {
width: 100%;
height: 100%;
object-fit: contain;
}
}
.headerNav {
display: flex;
align-items: center;
gap: 8px;
.headerNavElement{
height: 48px;
padding: 14px 12px;
color: $blue100;
cursor: pointer;
font-weight: 500;
letter-spacing: 0.8px;
&:hover{
color: $blue200
}
}
@include breakpoint-down('tabM') {
display: none;
}
}
.headerControls {
display: flex;
align-items: center;
gap: 20px;
height: 48px;
@include breakpoint-down('tabS') {
gap: 12px;
height: 44px;
}
@include breakpoint-down('mobM') {
gap: 12px;
}
.headerControlElement {
padding: 14px 12px;
color: $blue100;
cursor: pointer;
@include breakpoint-down('tabS') {
height: 44px;
}
&:hover{
color: $blue200
}
}
}
.headerBurger {
display: none;
border-color: none;
width: 44px;
height: 44px;
align-items: center;
justify-content: center;
background: $blue500;
order: 4;
@include breakpoint-down('tabM') {
display: flex;
border-radius: 16px;
}
}
:global(.headerControls .lang) {
@include breakpoint-down('tabS') {
display: none;
}
}
:global(.header.active .headerControls .button) {
@include breakpoint-down('tabS') {
display: none;
}
}
:global(.header .headerControls .button) {
@include breakpoint-down('mobM') {
// display: none;
}
}
</style>