Skip to content

Commit

Permalink
Expose additional controls for the api for the bottom nav as well as …
Browse files Browse the repository at this point in the history
…allow the escape button to close the nav.
  • Loading branch information
GiantRobots committed Dec 10, 2024
1 parent c1117f3 commit 850bfd7
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/lib/components/bottom-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { writable } from 'svelte/store';
import { slide } from 'svelte/transition';
import { onDestroy, onMount } from 'svelte';
import { twMerge as merge } from 'tailwind-merge';
import { beforeNavigate } from '$app/navigation';
Expand All @@ -27,6 +28,33 @@
let viewNamespaces = writable(false);
let viewSettings = false;
const escHandler = new AbortController();
onMount(() => {
document.addEventListener(
'keydown',
(e) => {
if (
e.key === 'Escape' &&
[viewSettings, viewNamespaces, viewSettings].some((isOpen) => isOpen)
) {
closeMenu();
}
},
{
signal: escHandler.signal,
},
);
});
onDestroy(() => {
escHandler.abort();
});
beforeNavigate(() => {
closeMenu();
});
$: namespace = $page.params.namespace || $lastUsedNamespace;
$: namespaceExists = namespaceList.some(
(namespaceListItem) => namespaceListItem.namespace === namespace,
Expand All @@ -50,11 +78,11 @@
viewSettings = !viewSettings;
};
beforeNavigate(() => {
function closeMenu() {
viewLinks = false;
viewSettings = false;
$viewNamespaces = false;
});
}
$: menuIsOpen = viewLinks || $viewNamespaces || viewSettings;
Expand All @@ -74,7 +102,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 850bfd7

Please sign in to comment.