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

Highlight active link in nav bar #2324

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/components/side-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
tooltip={item?.tooltip || item.label}
external={item?.external}
animate={item?.animate}
isActive={item.isActive}
/>
{/if}
{/each}
Expand Down
12 changes: 11 additions & 1 deletion src/lib/holocene/navigation/navigation-item.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';

import type { IconName } from '$lib/holocene/icon';
import { navOpen } from '$lib/stores/nav-open';

Expand All @@ -11,9 +13,11 @@
export let external = false;
export let animate = false;
export let disabled = false;
export let isActive: (path: string) => boolean | undefined = undefined;

$: rel = external ? 'noopener noreferrer' : '';
$: target = external ? '_blank' : '';
$: active = isActive && isActive($page.url.href);
</script>

<div
Expand All @@ -29,7 +33,8 @@
aria-disabled={disabled}
class:disabled
tabindex={disabled ? -1 : 0}
class="mb-1 flex items-center whitespace-nowrap rounded-lg p-1 pl-2 text-sm font-medium hover:bg-white hover:text-black group-[.surface-primary]:hover:bg-black group-[.surface-primary]:hover:text-white group-[.surface-primary]:dark:hover:bg-white group-[.surface-primary]:dark:hover:text-black"
class:active
class="mb-1 flex items-center whitespace-nowrap rounded-lg p-1 pl-2 text-sm font-medium"
class:text-disabled={disabled}
>
<div
Expand All @@ -53,4 +58,9 @@
a.disabled {
@apply pointer-events-none cursor-not-allowed opacity-50;
}

a:hover,
a.active {
@apply bg-white text-black group-[.surface-primary]:bg-black group-[.surface-primary]:text-white group-[.surface-primary]:dark:bg-white group-[.surface-primary]:dark:text-black;
}
</style>
1 change: 1 addition & 0 deletions src/lib/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ export type NavLinkListItem = {
enabled?: boolean;
hidden?: boolean;
animate?: boolean;
isActive?: (path: string) => boolean;
};
36 changes: 29 additions & 7 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,67 @@
namespace: string,
inProgressBatch: boolean,
): NavLinkListItem[] => {
const workflowsRoute = routeForWorkflows({ namespace });
const schedulesRoute = routeForSchedules({ namespace });
const batchOperationsRoute = routeForBatchOperations({ namespace });
const archivalRoute = routeForArchivalWorkfows({ namespace });
const namespacesRoute = routeForNamespaces();
const nexusRoute = routeForNexus();
const historyImportRoute = routeForEventHistoryImport();

Alex-Tideman marked this conversation as resolved.
Show resolved Hide resolved
return [
{
href: routeForWorkflows({ namespace }),
href: workflowsRoute,
icon: 'workflow',
label: translate('common.workflows'),
isActive: (path) => Boolean(path.includes(workflowsRoute)),
},
{
href: routeForSchedules({ namespace }),
href: schedulesRoute,
icon: 'schedules',
label: translate('common.schedules'),
isActive: (path) => Boolean(path.includes(schedulesRoute)),
},
{
href: routeForBatchOperations({ namespace }),
href: batchOperationsRoute,
icon: 'batch-operation',
label: translate('batch.nav-title'),
tooltip: translate('batch.list-page-title'),
animate: inProgressBatch,
isActive: (path) => Boolean(path.includes(batchOperationsRoute)),
},
{
href: routeForArchivalWorkfows({ namespace }),
href: archivalRoute,
icon: 'archives',
label: translate('common.archive'),
isActive: (path) => Boolean(path.includes(archivalRoute)),
},
{
href: routeForNamespaces(),
href: namespacesRoute,
icon: 'namespace',
label: translate('common.namespaces'),
divider: true,
isActive: (path) =>
Boolean(
path.includes(namespacesRoute) &&
!path.includes(workflowsRoute) &&
!path.includes(schedulesRoute) &&
!path.includes(batchOperationsRoute) &&
!path.includes(archivalRoute),
),
},
{
href: routeForNexus(),
href: nexusRoute,
icon: 'nexus',
label: translate('nexus.nexus'),
hidden: !$page.data?.systemInfo?.capabilities?.nexus,
isActive: (path) => Boolean(path.includes(nexusRoute)),
},
{
href: routeForEventHistoryImport(),
href: historyImportRoute,
icon: 'import',
label: translate('common.import'),
isActive: (path) => Boolean(path.includes(historyImportRoute)),
},
{
href: 'http://docs.temporal.io',
Expand Down
Loading