Spaces:
Running
Running
feat(nav): add swipe gesture to close mobile nav
Browse files- package-lock.json +8 -0
- package.json +1 -0
- src/lib/components/MobileNav.svelte +10 -4
package-lock.json
CHANGED
@@ -92,6 +92,7 @@
|
|
92 |
"prom-client": "^15.1.2",
|
93 |
"svelte": "^5.0.0",
|
94 |
"svelte-check": "^4.0.0",
|
|
|
95 |
"ts-node": "^10.9.1",
|
96 |
"tslib": "^2.4.1",
|
97 |
"typescript": "^5.5.0",
|
@@ -11908,6 +11909,13 @@
|
|
11908 |
}
|
11909 |
}
|
11910 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11911 |
"node_modules/svelte/node_modules/is-reference": {
|
11912 |
"version": "3.0.3",
|
11913 |
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.3.tgz",
|
|
|
92 |
"prom-client": "^15.1.2",
|
93 |
"svelte": "^5.0.0",
|
94 |
"svelte-check": "^4.0.0",
|
95 |
+
"svelte-gestures": "^5.1.3",
|
96 |
"ts-node": "^10.9.1",
|
97 |
"tslib": "^2.4.1",
|
98 |
"typescript": "^5.5.0",
|
|
|
11909 |
}
|
11910 |
}
|
11911 |
},
|
11912 |
+
"node_modules/svelte-gestures": {
|
11913 |
+
"version": "5.1.3",
|
11914 |
+
"resolved": "https://registry.npmjs.org/svelte-gestures/-/svelte-gestures-5.1.3.tgz",
|
11915 |
+
"integrity": "sha512-ELOlzuH9E4+S1biCCTfusRlvzFpnqRPlljEqayoBTu5STH42u0kTT45D1m3Py3E9UmIyZTgrSLw6Fus/fh75Dw==",
|
11916 |
+
"dev": true,
|
11917 |
+
"license": "MIT"
|
11918 |
+
},
|
11919 |
"node_modules/svelte/node_modules/is-reference": {
|
11920 |
"version": "3.0.3",
|
11921 |
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.3.tgz",
|
package.json
CHANGED
@@ -52,6 +52,7 @@
|
|
52 |
"prom-client": "^15.1.2",
|
53 |
"svelte": "^5.0.0",
|
54 |
"svelte-check": "^4.0.0",
|
|
|
55 |
"ts-node": "^10.9.1",
|
56 |
"tslib": "^2.4.1",
|
57 |
"typescript": "^5.5.0",
|
|
|
52 |
"prom-client": "^15.1.2",
|
53 |
"svelte": "^5.0.0",
|
54 |
"svelte-check": "^4.0.0",
|
55 |
+
"svelte-gestures": "^5.1.3",
|
56 |
"ts-node": "^10.9.1",
|
57 |
"tslib": "^2.4.1",
|
58 |
"typescript": "^5.5.0",
|
src/lib/components/MobileNav.svelte
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
import { fly } from "svelte/transition";
|
9 |
import CarbonClose from "~icons/carbon/close";
|
10 |
import CarbonTextAlignJustify from "~icons/carbon/text-align-justify";
|
11 |
-
|
12 |
interface Props {
|
13 |
isOpen?: boolean;
|
14 |
title: string | undefined;
|
@@ -62,19 +62,25 @@
|
|
62 |
|
63 |
{#if isOpen}
|
64 |
<nav
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,1fr,auto,auto] bg-white pt-4 dark:bg-gray-900"
|
66 |
in:fly={{ x: -window.innerWidth, duration: 250 }}
|
67 |
out:fly={{ x: -window.innerWidth, duration: 250 }}
|
68 |
>
|
69 |
-
|
70 |
<button
|
71 |
type="button"
|
72 |
-
class="-
|
73 |
onclick={() => dispatch("toggle", false)}
|
74 |
aria-label="Close menu"
|
75 |
bind:this={closeEl}><CarbonClose /></button
|
76 |
>
|
77 |
-
|
78 |
{@render children?.()}
|
79 |
</nav>
|
80 |
{/if}
|
|
|
8 |
import { fly } from "svelte/transition";
|
9 |
import CarbonClose from "~icons/carbon/close";
|
10 |
import CarbonTextAlignJustify from "~icons/carbon/text-align-justify";
|
11 |
+
import { swipe, type SwipeCustomEvent } from "svelte-gestures";
|
12 |
interface Props {
|
13 |
isOpen?: boolean;
|
14 |
title: string | undefined;
|
|
|
62 |
|
63 |
{#if isOpen}
|
64 |
<nav
|
65 |
+
use:swipe={() => ({ timeframe: 300, minSwipeDistance: 60 })}
|
66 |
+
onswipe={(ev: SwipeCustomEvent) => {
|
67 |
+
if (ev.detail.direction === "left") {
|
68 |
+
dispatch("toggle", false);
|
69 |
+
}
|
70 |
+
}}
|
71 |
class="fixed inset-0 z-30 grid max-h-screen grid-cols-1 grid-rows-[auto,1fr,auto,auto] bg-white pt-4 dark:bg-gray-900"
|
72 |
in:fly={{ x: -window.innerWidth, duration: 250 }}
|
73 |
out:fly={{ x: -window.innerWidth, duration: 250 }}
|
74 |
>
|
75 |
+
{#if page.url.pathname === base + "/"}
|
76 |
<button
|
77 |
type="button"
|
78 |
+
class="absolute right-0 top-0 z-10 flex size-12 items-center justify-center text-lg"
|
79 |
onclick={() => dispatch("toggle", false)}
|
80 |
aria-label="Close menu"
|
81 |
bind:this={closeEl}><CarbonClose /></button
|
82 |
>
|
83 |
+
{/if}
|
84 |
{@render children?.()}
|
85 |
</nav>
|
86 |
{/if}
|