@abhivarde/svelte-drawer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getContext } from "svelte";
|
|
3
3
|
|
|
4
|
-
// Minimal inline type just to fix TypeScript
|
|
5
4
|
type DrawerContext = {
|
|
6
5
|
open: boolean;
|
|
7
6
|
overlayOpacity: { current: number; set: (v: number) => void };
|
|
@@ -12,7 +11,6 @@
|
|
|
12
11
|
|
|
13
12
|
let { class: className = "", children, ...restProps } = $props();
|
|
14
13
|
|
|
15
|
-
// Tell TypeScript that context has this shape
|
|
16
14
|
const drawer = getContext<DrawerContext>("drawer");
|
|
17
15
|
|
|
18
16
|
let startPos = 0;
|
|
@@ -36,6 +34,8 @@
|
|
|
36
34
|
|
|
37
35
|
function onPointerDown(e: PointerEvent | TouchEvent) {
|
|
38
36
|
dragging = true;
|
|
37
|
+
document.body.style.cursor = "grabbing";
|
|
38
|
+
|
|
39
39
|
startPos =
|
|
40
40
|
drawer.direction === "bottom" || drawer.direction === "top"
|
|
41
41
|
? "clientY" in e
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
|
|
52
52
|
function onPointerMove(e: PointerEvent | TouchEvent) {
|
|
53
53
|
if (!dragging) return;
|
|
54
|
+
|
|
54
55
|
const current =
|
|
55
56
|
drawer.direction === "bottom" || drawer.direction === "top"
|
|
56
57
|
? "clientY" in e
|
|
@@ -80,8 +81,16 @@
|
|
|
80
81
|
|
|
81
82
|
function onPointerUp() {
|
|
82
83
|
dragging = false;
|
|
83
|
-
|
|
84
|
-
|
|
84
|
+
document.body.style.cursor = "default";
|
|
85
|
+
|
|
86
|
+
const pos = drawer.drawerPosition.current;
|
|
87
|
+
const deltaThreshold = 30;
|
|
88
|
+
|
|
89
|
+
if (pos > deltaThreshold) {
|
|
90
|
+
drawer.closeDrawer();
|
|
91
|
+
} else {
|
|
92
|
+
drawer.drawerPosition.set(0);
|
|
93
|
+
}
|
|
85
94
|
|
|
86
95
|
window.removeEventListener("pointermove", onPointerMove);
|
|
87
96
|
window.removeEventListener("pointerup", onPointerUp);
|
|
@@ -91,7 +100,7 @@
|
|
|
91
100
|
{#if drawer.open}
|
|
92
101
|
<div
|
|
93
102
|
class={className}
|
|
94
|
-
style="transform: {getTransform()}; z-index: 50;"
|
|
103
|
+
style="transform: {getTransform()}; z-index: 50; cursor: grab;"
|
|
95
104
|
onpointerdown={onPointerDown}
|
|
96
105
|
{...restProps}
|
|
97
106
|
>
|