feat: add hamburger menu
This commit is contained in:
parent
6354336610
commit
9b454e0b34
9 changed files with 170 additions and 161 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
||||||
|
|
|
||||||
|
|
@ -1,97 +1,43 @@
|
||||||
<script>
|
<script>
|
||||||
import { t, locale, SUPPORTED_LOCALES } from '$lib/translations';
|
import { resolve } from '$app/paths';
|
||||||
|
import { page } from '$app/state';
|
||||||
import logo from '$lib/assets/logo.webp';
|
import logo from '$lib/assets/logo.webp';
|
||||||
import MediaQuery from './MediaQuery.svelte';
|
import MediaQuery from './MediaQuery.svelte';
|
||||||
import { resolve } from '$app/paths';
|
|
||||||
|
|
||||||
/**
|
let isOpen = $state(false);
|
||||||
*
|
let route = $derived(page.url.pathname);
|
||||||
* Returns logo image configuration based on the screen size match.
|
$effect(() => {
|
||||||
*
|
route; // track dependency
|
||||||
* @param {boolean} matches - The event that triggered the language switch.
|
isOpen = false;
|
||||||
*/
|
});
|
||||||
const configsFor = (matches) => {
|
|
||||||
return matches
|
|
||||||
? { src: logo, width: 150, height: 70 } // mobile
|
|
||||||
: { src: logo, width: 150, height: 100 }; // desktop
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Switches the current locale to the opposite language (EN_US <-> PT_BR).
|
|
||||||
* Prevents the default link behavior (e.g., page jump).
|
|
||||||
*
|
|
||||||
* @param {MouseEvent | KeyboardEvent} e - The event that triggered the language switch.
|
|
||||||
*/
|
|
||||||
const onSwitchToOppositeLang = (e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
$locale =
|
|
||||||
$locale === SUPPORTED_LOCALES.EN_US
|
|
||||||
? SUPPORTED_LOCALES.PT_BR
|
|
||||||
: SUPPORTED_LOCALES.EN_US;
|
|
||||||
};
|
|
||||||
|
|
||||||
let isMenuOpen = false;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<MediaQuery query="(max-width: 768px)" let:matches>
|
<MediaQuery query="(max-width: 768px)" let:matches>
|
||||||
{@const configs = configsFor(matches)}
|
|
||||||
<a href={resolve('/')}>
|
<a href={resolve('/')}>
|
||||||
<img
|
<img
|
||||||
src={configs.src}
|
src={logo}
|
||||||
alt="Embroidery viewer logo"
|
alt="Embroidery viewer logo"
|
||||||
width={configs.width}
|
width="150"
|
||||||
height={configs.height}
|
height={matches ? 70 : 100}
|
||||||
/>
|
/>
|
||||||
</a>
|
</a>
|
||||||
</MediaQuery>
|
</MediaQuery>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nav-container">
|
<nav class:active={route !== '/'} id="menuToggle">
|
||||||
<MediaQuery query="(max-width: 768px)" let:matches>
|
<input type="checkbox" bind:checked={isOpen} />
|
||||||
<slot let-matches>
|
<span></span>
|
||||||
{#if matches}
|
<span></span>
|
||||||
<button class="hamburger" onclick={() => (isMenuOpen = !isMenuOpen)}>
|
<span></span>
|
||||||
{#if isMenuOpen}x{:else}☰{/if}
|
|
||||||
</button>
|
|
||||||
{/if}
|
|
||||||
</slot>
|
|
||||||
</MediaQuery>
|
|
||||||
<nav class:is-open={isMenuOpen}>
|
|
||||||
<ul>
|
|
||||||
<li>
|
|
||||||
<a href={resolve('/')}>{$t('header.homeNav')}</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href={resolve('/viewer')}>{$t('header.viewerNav')}</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href={resolve('/about')}>{$t('header.aboutNav')}</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href={resolve('/donate')}>{$t('header.donateNav')}</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<button
|
<ul id="menu">
|
||||||
type="button"
|
<a href={resolve('/about')}><li>About</li></a>
|
||||||
class="common-switch {$locale === SUPPORTED_LOCALES.EN_US
|
<a href={resolve('/viewer')}><li>Viewer</li></a>
|
||||||
? 'portuguese-switch'
|
<a href={resolve('/donate')}><li>Donate</li></a>
|
||||||
: 'english-switch'}"
|
</ul>
|
||||||
onclick={onSwitchToOppositeLang}
|
</nav>
|
||||||
onkeydown={(e) => {
|
|
||||||
if (e.key === 'Enter' || e.key === ' ') {
|
|
||||||
onSwitchToOppositeLang(e);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div style="display: flex; width: fit-content;">
|
|
||||||
<span style="font-size: 20px;">{$t('header.languageSwitch')}</span>
|
|
||||||
</div>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
@ -102,10 +48,14 @@
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding: 10px 300px 10px 100px;
|
padding: 10px 30px 10px 100px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
.logo img {
|
.logo img {
|
||||||
height: auto;
|
height: auto;
|
||||||
max-height: 60px;
|
max-height: 60px;
|
||||||
|
|
@ -118,112 +68,159 @@
|
||||||
.logo a:hover {
|
.logo a:hover {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
#menuToggle {
|
||||||
.nav-container {
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 20px;
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Click area */
|
||||||
|
#menuToggle input {
|
||||||
|
display: block;
|
||||||
|
width: 40px;
|
||||||
|
height: 32px;
|
||||||
|
position: absolute;
|
||||||
|
top: -7px;
|
||||||
|
left: -5px;
|
||||||
|
cursor: pointer;
|
||||||
|
opacity: 0;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bars */
|
||||||
|
#menuToggle span {
|
||||||
|
display: block;
|
||||||
|
width: 30px;
|
||||||
|
height: 3px;
|
||||||
|
margin-bottom: 7px;
|
||||||
|
background: #ffffff;
|
||||||
|
border-radius: 2px;
|
||||||
|
transition: all 0.35s ease;
|
||||||
|
transform-origin: 4px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Adjust origins for rotation */
|
||||||
|
#menuToggle span:nth-child(2) {
|
||||||
|
transform-origin: 0% 0%;
|
||||||
|
width: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#menuToggle span:nth-child(4) {
|
||||||
|
transform-origin: 0% 100%;
|
||||||
|
width: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* === ANIMATION === */
|
||||||
|
|
||||||
|
/* Top bar → rotates */
|
||||||
|
#menuToggle input:checked ~ span:nth-child(2) {
|
||||||
|
transform: rotate(45deg) translate(-1px, -1px);
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Middle bar → fades out */
|
||||||
|
#menuToggle input:checked ~ span:nth-child(3) {
|
||||||
|
opacity: 0;
|
||||||
|
transform: scale(0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Bottom bar → rotates opposite */
|
||||||
|
#menuToggle input:checked ~ span:nth-child(4) {
|
||||||
|
transform: rotate(-45deg) translate(1px, -1px);
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#menu {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
position: absolute;
|
||||||
|
top: -80px;
|
||||||
|
width: 400px;
|
||||||
|
margin: -100px 0 0 0;
|
||||||
|
padding: 50px;
|
||||||
|
padding-top: 125px;
|
||||||
|
right: -100px;
|
||||||
|
background: var(--color-primary);
|
||||||
|
list-style-type: none;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
transform-origin: 0% 0%;
|
||||||
|
transform: translate(100%, 0);
|
||||||
|
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1);
|
||||||
|
z-index: -1;
|
||||||
|
|
||||||
|
margin: 30px;
|
||||||
|
border-radius: 70% 30% 30% 70% / 60% 40% 0 100%;
|
||||||
|
box-shadow:
|
||||||
|
0 2.8px 2.2px rgba(0, 0, 0, 0.02),
|
||||||
|
0 6.7px 5.3px rgba(0, 0, 0, 0.028),
|
||||||
|
0 12.5px 10px rgba(0, 0, 0, 0.035),
|
||||||
|
0 22.3px 17.9px rgba(0, 0, 0, 0.042),
|
||||||
|
0 41.8px 33.4px rgba(0, 0, 0, 0.05),
|
||||||
|
0 100px 80px rgba(0, 0, 0, 0.07);
|
||||||
}
|
}
|
||||||
|
|
||||||
nav ul {
|
#menu li {
|
||||||
list-style: none;
|
padding: 10px 0;
|
||||||
margin: 0;
|
font-size: 22px;
|
||||||
padding: 0;
|
color: white;
|
||||||
display: flex;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nav ul li {
|
#menu li:hover {
|
||||||
display: flex;
|
color: #adadad;
|
||||||
font-weight: bold;
|
transition: all 0.5s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hamburger {
|
#menuToggle input:checked ~ ul {
|
||||||
background: none;
|
transform: scale(1, 1);
|
||||||
border: none;
|
opacity: 1;
|
||||||
font-size: 35px;
|
|
||||||
width: 35px;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
cursor: pointer;
|
|
||||||
display: none;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.common-switch {
|
.active input:checked ~ span:nth-child(2),
|
||||||
border: none;
|
.active input:checked ~ span:nth-child(3),
|
||||||
background-color: unset;
|
.active input:checked ~ span:nth-child(4) {
|
||||||
width: fit-content;
|
background-color: white !important;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.portuguese-switch {
|
.active span {
|
||||||
color: #0c8f27;
|
background-color: var(--color-primary) !important;
|
||||||
border-bottom: 3px solid #0c8f27 !important;
|
|
||||||
fill: #0c8f27 !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.portuguese-switch:hover {
|
@media (max-width: 1339px) {
|
||||||
background: #0c8f27;
|
#menuToggle span {
|
||||||
color: #ffffff;
|
background-color: var(--color-primary);
|
||||||
fill: #ffffff !important;
|
}
|
||||||
}
|
/* Top bar → rotates */
|
||||||
|
#menuToggle input:checked ~ span:nth-child(2) {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
.english-switch {
|
/* Middle bar → fades out */
|
||||||
color: #be0a2f;
|
#menuToggle input:checked ~ span:nth-child(3) {
|
||||||
border-bottom: 3px solid #be0a2f;
|
background-color: white;
|
||||||
width: fit-content;
|
}
|
||||||
fill: #be0a2f !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.english-switch:hover {
|
/* Bottom bar → rotates opposite */
|
||||||
background: #be0a2f;
|
#menuToggle input:checked ~ span:nth-child(4) {
|
||||||
color: #ffffff;
|
background-color: white;
|
||||||
fill: #ffffff !important;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
header {
|
header {
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
}
|
}
|
||||||
.hamburger {
|
|
||||||
display: block;
|
|
||||||
width: 35px;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav {
|
#menu {
|
||||||
display: none;
|
width: 100vw;
|
||||||
flex-direction: column;
|
top: -80px;
|
||||||
gap: 10px;
|
margin: 0px 0 0 0;
|
||||||
background-color: #f8f9fa;
|
right: -20px;
|
||||||
position: absolute;
|
border-radius: 0;
|
||||||
top: 60px;
|
border-radius: 0% 0% 80% 80%;
|
||||||
right: 0;
|
transform: translate(0%, -100%);
|
||||||
border: 1px solid #ddd;
|
|
||||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
nav.is-open {
|
|
||||||
display: inline-block;
|
|
||||||
margin-top: 25px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav ul {
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav ul li {
|
|
||||||
text-align: center;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
nav ul li a {
|
|
||||||
display: inline-block;
|
|
||||||
width: 100%;
|
|
||||||
padding: 10px;
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,14 @@
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
position: relative;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|
|
||||||
|
|
@ -36,5 +36,6 @@
|
||||||
flex: 1; /* This pushes footer to bottom */
|
flex: 1; /* This pushes footer to bottom */
|
||||||
padding: 0;
|
padding: 0;
|
||||||
min-height: 90vh;
|
min-height: 90vh;
|
||||||
|
overflow-x: hidden;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
section {
|
section {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
margin-top: 130px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@
|
||||||
.donate-container {
|
.donate-container {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
margin-top: 130px;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
section {
|
section {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
margin-top: 130px;
|
||||||
}
|
}
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
section {
|
section {
|
||||||
width: 70%;
|
width: 70%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
margin-top: 130px;
|
||||||
}
|
}
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,7 @@
|
||||||
form {
|
form {
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
margin-top: 130px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.title-container {
|
.title-container {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue