Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highlighted the current page item on navebar #303

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
31 changes: 27 additions & 4 deletions src/routes/(app)/_components/layout/navbar.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
<script>
// @ts-expect-error Import is as expected but throws error

import { page } from '$app/stores';

$: currentPage = $page.url.pathname;
const links = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the pages that are not ready, this is linking for a 404 page. Shouldn't it be better to redirect to "#", as it was before?

{ href: '/team/', label: 'Equipa', pageComp: '/team' },
{ href: '/projects/', label: 'Projetos', pageComp: '/projects' },
{ href: '/events/', label: 'Eventos', pageComp: '/events' },
{ href: '/contacts/', label: 'Contactos', pageComp: '/contacts' }
];
</script>

<nav
class="fixed hidden h-min w-full grid-cols-2 items-center justify-center px-7 py-2 font-raleway text-xs text-white sm:grid sm:text-base"
aria-label="Navigation Bar"
Expand All @@ -9,9 +23,18 @@
</a>
</div>
<div class="flex justify-end gap-7">
<a href="/#/">Equipa</a>
<a href="/#/">Projetos</a>
<a href="/#/">Eventos</a>
<a href="/contacts">Contactos</a>
{#each links as { href, label, pageComp }}
<a class:active={currentPage === pageComp} {href}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could use a svelte conditional or a ternary to render the different items on the navbar.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator
https://svelte.dev/tutorial/svelte/if-blocks

<p class="font-bold">{label}</p>
</a>
{/each}
</div>
</nav>

<style>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using Tailwind to define the style of html components, you should avoid using pure CSS.

.active {
background-color: theme('colors.muted-red.400');
padding: 2px 6px;
border-radius: 4px;
}
</style>
Loading