Files
classroomio/apps/dashboard/src/lib/components/Navigation/index.svelte
T

126 lines
3.3 KiB
Svelte
Raw Normal View History

<script lang="ts">
import { page } from '$app/stores';
import { user } from '$lib/utils/store/user';
import { isCoursePage } from '$lib/utils/functions/app';
2024-04-19 05:45:48 +01:00
import { t } from '$lib/utils/functions/translations';
import type { TCustomLinks } from './types';
import Logo from './Logo.svelte';
import CustomLinks from './CustomLinks.svelte';
import AuthButtons from './AuthButtons.svelte';
import MobileMenu from './MobileMenu.svelte';
2021-04-05 07:12:51 +03:00
export let disableSignup = false;
export let logo: string | undefined = undefined;
export let orgName: string | undefined = undefined;
2023-08-14 06:22:03 +01:00
export let isOrgSite = false;
2023-09-26 11:23:54 +01:00
export let backgroundColor = 'bg-white dark:bg-black';
export let customLinks: TCustomLinks | undefined = undefined;
2021-08-18 19:47:02 +03:00
let navClass = '';
let mobileMenuOpen = false;
2021-07-27 22:53:51 +03:00
$: redirect = isCoursePage($page.url.pathname) ? `?redirect=${$page.url.pathname}` : '';
$: showLinks =
customLinks && customLinks.show && customLinks.links && customLinks.links.length > 0;
function toggleMobileMenu() {
mobileMenuOpen = !mobileMenuOpen;
}
2021-04-05 07:12:51 +03:00
</script>
2021-07-27 22:53:51 +03:00
<nav
class="{navClass} {backgroundColor} sticky top-0 z-50 flex w-full border-b border-l-0 border-r-0 border-t-0 border-gray-300 px-2 py-1"
2021-07-27 22:53:51 +03:00
>
<ul class="flex w-full items-center">
<Logo {logo} {orgName} />
2021-08-18 19:47:02 +03:00
2021-07-27 22:53:51 +03:00
<span class="flex-grow" />
2021-08-18 19:47:02 +03:00
<!-- Mobile Menu Button - Only show when custom links exist -->
{#if isOrgSite && showLinks}
<button
class="mobile-menu-btn hover:text-primary-600 rounded-md p-2 text-gray-700 transition-colors duration-200 hover:bg-gray-100 lg:hidden"
on:click={toggleMobileMenu}
aria-label="Toggle mobile menu"
>
<svg class="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M4 6h16M4 12h16M4 18h16"
></path>
</svg>
</button>
{/if}
{#if customLinks && showLinks}
<CustomLinks {customLinks} />
{/if}
{#if $user.isLoggedIn}
2023-08-14 06:22:03 +01:00
{#if isOrgSite}
2024-04-19 05:45:48 +01:00
<li><a class="block" href="/lms"> {$t('navigation.goto_lms')} </a></li>
{/if}
{:else if isOrgSite && !$page.url.pathname?.includes('/404')}
<!-- Hide login/signup buttons on mobile when custom links exist -->
<div class="hidden lg:block">
<AuthButtons {disableSignup} {redirect} />
</div>
{:else if !isOrgSite && !$page.url.pathname?.includes('/404')}
<AuthButtons {disableSignup} {redirect} />
{/if}
2021-06-01 07:19:19 +03:00
</ul>
{#if showLinks}
<MobileMenu bind:mobileMenuOpen {customLinks} {disableSignup} {redirect} />
{/if}
2021-06-01 07:19:19 +03:00
</nav>
2021-04-05 07:12:51 +03:00
<style>
ul {
margin: 0 auto;
padding: 0;
}
ul::after {
content: '';
2021-04-05 07:12:51 +03:00
display: block;
clear: both;
}
a {
text-decoration: none;
color: var(--main-primary-color);
2021-07-27 22:53:51 +03:00
padding: 0 1.5em;
2021-04-05 07:12:51 +03:00
font-weight: 700;
display: flex;
gap: 0.5rem;
2021-04-05 07:12:51 +03:00
align-items: center;
flex-direction: column;
2021-04-05 07:12:51 +03:00
}
/* Mobile menu button styles */
.mobile-menu-btn {
display: none;
}
@media only screen and (max-width: 1023px) {
2021-04-05 07:12:51 +03:00
nav.hide {
display: none;
}
ul {
align-items: center;
}
2021-11-07 01:31:59 +02:00
a {
padding: 0 0.5em;
}
.mobile-menu-btn {
display: block;
}
2021-04-05 07:12:51 +03:00
}
</style>