design: improve tabnav
This commit is contained in:
8 files changed
+139
-131
No files matched your search
@@ -44,7 +44,7 @@
|
||||
|
||||
<nav
|
||||
aria-label={$t('aria.pagination.nav')}
|
||||
class="flex flex-row w-full gap-4 items-center justify-center"
|
||||
class="flex flex-row w-full gap-4 items-center justify-center backdrop-blur-xl border border-slate-200 dark:border-zinc-800 rounded-full overflow-hidden"
|
||||
>
|
||||
{#if children}
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||
@@ -58,9 +58,9 @@
|
||||
color="ghost"
|
||||
onclick={() => invalidate(pageData.url)}
|
||||
title={$t('common.back')}
|
||||
size="square-md"
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit disabled:opacity-20! disabled:bg-transparent!"
|
||||
rounding="none"
|
||||
size="custom"
|
||||
class="text-inherit dark:text-inherit border-0 border-r p-2"
|
||||
disabled={(cursor?.back == undefined && cursor?.next != undefined) ||
|
||||
page <= 1}
|
||||
data-sveltekit-preload-data="off"
|
||||
@@ -77,7 +77,7 @@
|
||||
<div
|
||||
in:fly={{ y: 8, easing: backOut, duration: 400, delay: 100 }}
|
||||
out:fly={{ y: 8, easing: backOut, duration: 400 }}
|
||||
class="text-md font-medium"
|
||||
class="text-lg font-medium"
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
>
|
||||
{page}
|
||||
@@ -91,9 +91,9 @@
|
||||
color="ghost"
|
||||
onclick={() => invalidate(pageData.url)}
|
||||
title={$t('common.next')}
|
||||
size="square-md"
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit"
|
||||
size="custom"
|
||||
rounding="none"
|
||||
class="text-inherit dark:text-inherit border-0 border-l p-2"
|
||||
disabled={!hasMore}
|
||||
data-sveltekit-preload-data="off"
|
||||
>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
routes: {
|
||||
href: string
|
||||
name: string
|
||||
}[]
|
||||
currentRoute?: string | undefined
|
||||
buildUrl?: (currentRoute: string | undefined, href: string) => string
|
||||
defaultRoute?: string | undefined
|
||||
currentRoute?: SvelteURL | undefined
|
||||
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
|
||||
class?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
@@ -18,27 +18,13 @@
|
||||
routes,
|
||||
currentRoute = undefined,
|
||||
buildUrl = (_, href) => href,
|
||||
defaultRoute = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
}: Props = $props()
|
||||
|
||||
function isSelected(
|
||||
url: URL,
|
||||
currentRoute: string | undefined,
|
||||
route: string,
|
||||
defaultRoute?: string,
|
||||
) {
|
||||
if (route.startsWith('?')) {
|
||||
const param = route.slice(1)
|
||||
const key = param.split(/(?<=[=])/g)[0]
|
||||
if (currentRoute?.includes(param)) {
|
||||
return true
|
||||
} else if (route == defaultRoute && !currentRoute?.includes(key)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return (currentRoute ?? url.pathname) == route
|
||||
function isSelected(url: URL, href?: SvelteURL) {
|
||||
if (href?.search != '') return href?.search == url.search
|
||||
else if (url.search == '') return href?.pathname == url.pathname
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -56,7 +42,7 @@
|
||||
transition-colors duration-100 relative z-0 shrink-0"
|
||||
>
|
||||
{route.name}
|
||||
{#if isSelected(page.url, currentRoute, route.href, defaultRoute)}
|
||||
{#if isSelected(page.url, new SvelteURL(`${page.url.origin}${route.href}`))}
|
||||
<div
|
||||
class="rounded-full bg-slate-200/60 dark:bg-zinc-700/60
|
||||
absolute inset-0 w-full h-full -z-10"
|
||||
|
||||
Reference in new issue
Block a user