mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: tab selected function demo
This commit is contained in:
1 parent
c17dac8d6d
commit
2a9639b3dd
1 file changed
+23
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Cover>
|
||||
@@ -35,7 +54,7 @@
|
||||
</svelte:fragment>
|
||||
<Tabs>
|
||||
{#each tabs as tab}
|
||||
<Tab href={tab.href} selected={$page.url.pathname === tab.href}>
|
||||
<Tab href={tab.href} selected={isSelected(tab, $page.url.pathname, path)}>
|
||||
{tab.title}
|
||||
</Tab>
|
||||
{/each}
|
||||
|
||||
Reference in new issue
Block a user