Files
Modrinth-plus/src/components/NavRow.svelte

81 lines
1.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
2022-06-04 00:46:23 -07:00
import { page } from '$app/stores'
2022-06-04 00:46:23 -07:00
interface Link {
href: string
label: string
}
2022-06-04 00:46:23 -07:00
export let links: Link[]
2022-06-07 14:00:53 -07:00
/** Query param name to use (to not use queries, leave this prop blank) */
2022-06-04 00:46:23 -07:00
export let query = ''
2022-06-04 00:46:23 -07:00
export let resetScroll = false
2022-06-04 00:46:23 -07:00
/** Path level in URL, zero-indexed */
export let level = 0
2022-06-04 00:46:23 -07:00
let path: string[]
$: path = [
...$page.url.pathname
.substring(1)
.split('/')
.map((route) => '/' + route),
'/',
]
2022-06-04 00:46:23 -07:00
$: basePath = path.slice(0, level).join('')
</script>
<nav class="navigation">
2022-06-04 00:46:23 -07:00
{#each links as link}
<a
href={query
? link.href
? `?${query}=${link.href}`
: '?'
: level === 0
? link.href
: basePath + link.href}
on:click={() => {
if (resetScroll) document.body.scrollTo(0, 0)
}}
class="navigation__link"
class:is-active={query
? ($page.url.searchParams.get(query) || '') === link.href
: path[level] === link.href || path[level] === link.href.slice(0, -1)}
2022-06-13 12:48:43 -07:00
sveltekit:noscroll={!resetScroll || null}>{link.label}</a>
2022-06-04 00:46:23 -07:00
{/each}
</nav>
<style lang="postcss">
2022-06-04 00:46:23 -07:00
.navigation {
display: flex;
flex-direction: row;
align-items: center;
2022-06-07 14:00:53 -07:00
gap: 1rem;
2022-06-04 00:46:23 -07:00
flex-wrap: wrap;
2022-06-04 00:46:23 -07:00
&__link {
font-weight: var(--font-weight-bold);
color: var(--color-text-light);
2022-06-04 00:46:23 -07:00
&.is-active {
color: var(--color-text);
position: relative;
2022-06-04 00:46:23 -07:00
&::after {
content: '';
display: block;
position: absolute;
2022-06-18 15:40:17 -07:00
bottom: -1px;
2022-06-04 00:46:23 -07:00
width: 100%;
border-radius: var(--rounded-max);
2022-06-07 14:00:53 -07:00
height: 0.25rem;
2022-06-04 00:46:23 -07:00
background-color: var(--color-brand);
}
}
}
}
</style>