mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: implement mobile support for navbar
This commit is contained in:
@@ -3,7 +3,10 @@
|
|||||||
import { resolve } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { clearTokens } from '$lib/utils/auth';
|
import { clearTokens } from '$lib/utils/auth';
|
||||||
|
import logo from '$lib/assets/favicon.svg';
|
||||||
import type { PageData } from '../../routes/$types';
|
import type { PageData } from '../../routes/$types';
|
||||||
|
import { slide } from 'svelte/transition';
|
||||||
|
import { Menu, X } from '@lucide/svelte';
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
clearTokens();
|
clearTokens();
|
||||||
@@ -13,6 +16,8 @@
|
|||||||
|
|
||||||
export let data: PageData;
|
export let data: PageData;
|
||||||
|
|
||||||
|
let menuOpen = false;
|
||||||
|
|
||||||
let currentPath = page.url.pathname;
|
let currentPath = page.url.pathname;
|
||||||
let returnParam =
|
let returnParam =
|
||||||
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
|
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
|
||||||
@@ -21,7 +26,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="top-0 left-0 z-100 h-15 w-full bg-neutral-900">
|
<div class="top-0 left-0 z-100 h-15 w-full bg-neutral-900">
|
||||||
<div class="mx-auto flex h-15 w-[95%] max-w-7xl items-center py-2">
|
<div class="mx-auto md:flex h-15 hidden w-[95%] max-w-7xl items-center py-2">
|
||||||
<div>
|
<div>
|
||||||
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a
|
<a href={resolve('/')} class="text-xl font-bold text-white hover:text-neutral-300">Sharpbin</a
|
||||||
>
|
>
|
||||||
@@ -63,4 +68,70 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="mx-auto flex h-15 w-[90%] max-w-7xl items-center py-2 md:hidden">
|
||||||
|
<a href={resolve('/')} class="group">
|
||||||
|
<img src={logo} alt="Sharpbin Logo" class="h-8 w-8 group-hover:opacity-80" />
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
class="ml-auto p-2 flex items-center justify-center h-10 w-10 bg-neutral-800 rounded border border-neutral-700 hover:bg-neutral-700 focus:outline-none"
|
||||||
|
on:click={() => (menuOpen = !menuOpen)}
|
||||||
|
aria-label="Toggle Menu"
|
||||||
|
aria-expanded={menuOpen}
|
||||||
|
>
|
||||||
|
{#if menuOpen}
|
||||||
|
<X class="h-6 w-6 text-white" />
|
||||||
|
{:else}
|
||||||
|
<Menu class="h-6 w-6 text-white" />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{#if menuOpen}
|
||||||
|
<div
|
||||||
|
class="mx-auto mb-2 w-full px-2 py-3 md:hidden bg-neutral-900 border-b border-neutral-800 rounded-b"
|
||||||
|
in:slide={{ duration: 180 }}
|
||||||
|
out:slide={{ duration: 180 }}
|
||||||
|
style="z-index:1000;position:relative;"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href={resolve('/recent')}
|
||||||
|
class="block w-full rounded px-3 py-2 text-neutral-100 bg-neutral-800 hover:bg-neutral-700 transition-colors text-center"
|
||||||
|
on:click={() => (menuOpen = false)}
|
||||||
|
>Recent Pastes</a>
|
||||||
|
{#if $user}
|
||||||
|
{#if $user.roles.includes(1) || $user.roles.includes(255)}
|
||||||
|
<a
|
||||||
|
href={resolve('/reports')}
|
||||||
|
class="mt-1 block w-full rounded px-3 py-2 text-neutral-100 bg-neutral-800 hover:bg-neutral-700 transition-colors text-center"
|
||||||
|
on:click={() => (menuOpen = false)}
|
||||||
|
>Reports</a>
|
||||||
|
{/if}
|
||||||
|
<a
|
||||||
|
href={resolve(`/user/${$user.username}`)}
|
||||||
|
class="mt-1 block w-full rounded px-3 py-2 text-neutral-100 bg-neutral-800 hover:bg-neutral-700 transition-colors text-center"
|
||||||
|
on:click={() => (menuOpen = false)}
|
||||||
|
>Profile</a>
|
||||||
|
<button
|
||||||
|
on:click={() => {
|
||||||
|
logout();
|
||||||
|
menuOpen = false;
|
||||||
|
}}
|
||||||
|
class="mt-1 w-full rounded bg-neutral-800 px-3 py-2 text-neutral-100 hover:bg-neutral-700 transition-colors text-center"
|
||||||
|
>Logout</button>
|
||||||
|
{:else}
|
||||||
|
<a
|
||||||
|
href={resolve(`/login${returnParam}`)}
|
||||||
|
class="mt-1 block w-full rounded px-3 py-2 text-neutral-100 bg-neutral-800 hover:bg-neutral-700 transition-colors"
|
||||||
|
on:click={() => (menuOpen = false)}
|
||||||
|
>Login</a>
|
||||||
|
<!-- eslint-disable svelte/no-navigation-without-resolve -->
|
||||||
|
<a
|
||||||
|
href={data.options?.registration_enabled ? resolve(`/register${returnParam}`) : '#'}
|
||||||
|
class="mt-1 block w-full rounded px-3 py-2 text-neutral-100 hover:bg-neutral-700 transition-colors {data.options?.registration_enabled ? '' : 'cursor-not-allowed bg-neutral-900 text-neutral-500'}"
|
||||||
|
on:click={() => (menuOpen = false)}
|
||||||
|
>Register</a>
|
||||||
|
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user