From 2a9639b3ddc9f18faf05d4549696d710a6ccafc9 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 27 Oct 2022 17:43:13 +0200 Subject: [PATCH] feat: tab selected function demo --- .../authentication/header.svelte | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/routes/console/project-[project]/authentication/header.svelte b/src/routes/console/project-[project]/authentication/header.svelte index 5879bca3d..c5251c825 100644 --- a/src/routes/console/project-[project]/authentication/header.svelte +++ b/src/routes/console/project-[project]/authentication/header.svelte @@ -5,14 +5,17 @@ const projectId = $page.params.project; const path = `/console/project-${projectId}/authentication`; - const tabs = [ + type TabElement = { href: string; title: string; hasChildren?: boolean }; + const tabs: TabElement[] = [ { href: path, - title: 'Users' + title: 'Users', + hasChildren: true }, { href: `${path}/teams`, - title: 'Teams' + title: 'Teams', + hasChildren: true }, { href: `${path}/usage`, @@ -27,6 +30,22 @@ title: 'Settings' } ]; + + function isSelected(tab: TabElement, pathname: string, basePath: string) { + if (!tab.hasChildren) { + return tab.href === pathname; + } else { + if (tab.href === pathname) return true; + + if (tab.href === basePath) { + if (!tabs.some((t) => pathname.includes(t.href) && t.href !== tab.href)) { + return pathname.includes(tab.href); + } + } else { + return pathname.includes(tab.href); + } + } + } @@ -35,7 +54,7 @@ {#each tabs as tab} - + {tab.title} {/each}