website/src/lib/Nav.svelte

161 lines
3.1 KiB
Svelte
Raw Normal View History

<script lang="ts">
import ThemeToggle from "./ThemeToggle.svelte";
import { page } from "$app/stores";
$: currentPage = $page.url.pathname;
2022-12-27 17:28:47 +02:00
let showMenuButton = false;
let innerWidth: number = 0;
$: showMenuButton = innerWidth < 1030;
let menuOpen = false;
$: menuOpen = innerWidth > 1030;
let showThemeToggle: boolean = true;
const toggleMenu = () => {
menuOpen = !menuOpen;
};
const handleNavigation = () => {
if (showMenuButton) {
menuOpen = false;
} else {
menuOpen = true;
}
};
const menus = [
2022-09-10 18:58:19 +03:00
{ name: "Instances", url: "/instances" },
2022-08-08 08:20:03 +03:00
{ name: "Donate", url: "/donate" },
{ name: "Contact us", url: "/contact" },
{ name: "Our team", url: "/team" },
{ name: "Timeline", url: "/timeline" },
{ name: "Blog", url: "/blog" },
2022-08-08 08:20:03 +03:00
{ name: "Legal", url: "/legal" },
2022-12-27 17:28:47 +02:00
{
name: "Status",
url: "https://status.projectsegfau.lt/",
external: true
}
2022-08-08 08:20:03 +03:00
];
2022-07-27 19:45:53 +03:00
2022-12-27 17:28:47 +02:00
$: if (typeof Window === "undefined") {
menuOpen = true;
showMenuButton = false;
showThemeToggle = false;
}
</script>
2022-07-27 19:50:48 +03:00
2022-12-27 17:28:47 +02:00
<svelte:window bind:innerWidth />
2022-07-27 19:50:48 +03:00
2022-12-27 17:28:47 +02:00
<nav
2022-12-31 20:40:18 +02:00
class="bg-primary border-b border-b-solid border-b-grey flex p-2 flex-col justify-between nav:(flex-row items-center)"
2022-12-27 17:28:47 +02:00
>
<div class="flex flex-row items-center justify-between">
2022-10-01 16:11:54 +03:00
<a
2022-12-27 17:28:47 +02:00
class="flex items-center decoration-none text-text gap-2 transition-opacity duration-250 hover:opacity-80"
href="/"
2022-10-01 16:11:54 +03:00
>
2022-12-27 17:28:47 +02:00
<img
src="/logo.png"
alt="Project Segfault logo"
class="h-7"
/>
<span>Project Segfault</span>
2022-08-04 18:50:02 +03:00
</a>
2022-12-27 17:28:47 +02:00
{#if showMenuButton}
<button
on:click={toggleMenu}
class="i-fa6-solid:bars cursor-pointer mr-2"
/>
{/if}
2022-07-27 19:50:48 +03:00
</div>
2022-12-27 17:28:47 +02:00
{#if menuOpen}
<div
2022-12-31 21:24:03 +02:00
class="links"
class:hasJS={typeof Window !== "undefined"}
class:noJS={typeof Window === "undefined"}
2022-12-27 17:28:47 +02:00
>
{#each menus as { url, name, external }}
<a
class:active={url !== "/"
? currentPage.match(url)
: url === currentPage}
href={url}
on:click={handleNavigation}
>{#if external}
<div
class="i-fa6-solid:arrow-up-right-from-square mr-2"
/>
{/if}
{name}
</a>
{/each}
<a
href="https://matrix.to/#/#project-segfault:projectsegfau.lt/"
class="icon"
>
<div class="i-simple-icons:matrix" />
<span>Matrix</span>
</a>
<a
href="https://github.com/ProjectSegfault/"
class="icon"
>
<div class="i-simple-icons:github" />
<span>GitHub</span>
</a>
{#if showThemeToggle}
<div class="icon">
<ThemeToggle />
</div>
{/if}
</div>
{/if}
</nav>
2022-08-24 19:07:30 +03:00
<style>
a.active {
2022-12-27 17:28:47 +02:00
@apply text-accent;
2022-07-27 19:45:53 +03:00
}
.links > * {
2023-01-05 14:39:42 +02:00
@apply p-2 cursor-pointer text-text decoration-none transition-color duration-250 text-sm font-500 flex items-center hover\:text-accent;
}
2022-12-27 17:28:47 +02:00
.icon > span {
@apply flex nav\:hidden;
2022-07-27 19:45:53 +03:00
}
2022-12-27 17:28:47 +02:00
.icon {
@apply flex flex-row items-center gap-2;
}
2022-12-31 21:24:03 +02:00
.hasJS {
@apply flex flex-col pt-2 gap-2;
}
.noJS {
@apply grid grid-cols-2 gap-2 pt-2 w-fit;
2022-09-10 18:58:19 +03:00
}
2022-12-31 21:24:03 +02:00
@media (min-width: 1030px) {
.hasJS {
flex-direction: row;
padding-top: 0;
}
.noJS {
2022-07-27 19:45:53 +03:00
display: flex;
2022-09-10 18:58:19 +03:00
flex-direction: row;
2022-12-27 17:28:47 +02:00
padding-top: 0;
2022-09-10 18:58:19 +03:00
}
}
2022-07-27 19:50:48 +03:00
</style>