Skip to content

Commit

Permalink
Bottom Nav fixes for external control (#2469)
Browse files Browse the repository at this point in the history
* Expose additional controls for the api for the bottom nav as well as allow the escape button to close the nav.

* Use svelte:window to deal with the eventhandling instead
  • Loading branch information
GiantRobots authored Dec 11, 2024
1 parent f4425b3 commit bc32f5a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/lib/components/bottom-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,28 @@
let viewNamespaces = writable(false);
let viewSettings = false;
function escapeHandler(e: KeyboardEvent) {
if (
e.key === 'Escape' &&
[viewLinks, viewNamespaces, viewSettings].some((isOpen) => isOpen)
) {
closeMenu();
}
}
beforeNavigate(() => {
closeMenu();
});
$: namespace = $page.params.namespace || $lastUsedNamespace;
$: namespaceExists = namespaceList.some(
(namespaceListItem) => namespaceListItem.namespace === namespace,
);
const onLinksClick = () => {
viewSettings = false;
$viewNamespaces = false;
viewLinks = !viewLinks;
$viewNamespaces = false;
viewSettings = false;
};
const onNamespaceClick = () => {
Expand All @@ -50,11 +63,11 @@
viewSettings = !viewSettings;
};
beforeNavigate(() => {
function closeMenu() {
viewLinks = false;
viewSettings = false;
$viewNamespaces = false;
});
viewSettings = false;
}
$: menuIsOpen = viewLinks || $viewNamespaces || viewSettings;
Expand All @@ -66,6 +79,8 @@
};
</script>

<svelte:window on:keypress={escapeHandler} />

{#if menuIsOpen}
<div
class="group surface-primary fixed top-0 z-50 h-[calc(100%-64px)] w-full overflow-auto md:hidden"
Expand All @@ -74,7 +89,7 @@
out:slide={{ duration: 200, delay: 0 }}
>
<BottomNavLinks open={viewLinks} {linkList} />
<slot name="nsPicker" open={$viewNamespaces}>
<slot name="nsPicker" open={$viewNamespaces} {closeMenu}>
<BottomNavNamespaces open={$viewNamespaces} {namespaceList} />
</slot>
<BottomNavSettings open={viewSettings}>
Expand Down

0 comments on commit bc32f5a

Please sign in to comment.