@abhivarde/svelte-drawer 0.0.22 → 0.0.24
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.
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ A drawer component for Svelte 5, inspired by [Vaul](https://github.com/emilkowal
|
|
|
13
13
|
- ✅ Prebuilt variants (**default, sheet, dialog, minimal, sidebar**)
|
|
14
14
|
- ✅ **Drag handle component** with auto-adaptive orientation
|
|
15
15
|
- ✅ **Snap points** for iOS-like multi-height drawers
|
|
16
|
+
- ✅ **Portal rendering** to escape z-index conflicts
|
|
17
|
+
- ✅ **Optional header & footer** components for quick setup
|
|
16
18
|
- ✅ Nested drawer support
|
|
17
19
|
- ✅ Scrollable content areas
|
|
18
20
|
- ✅ Keyboard shortcuts (**Escape to close**, Tab navigation)
|
|
@@ -53,6 +55,42 @@ npm install @abhivarde/svelte-drawer
|
|
|
53
55
|
</Drawer>
|
|
54
56
|
```
|
|
55
57
|
|
|
58
|
+
|
|
59
|
+
### Backdrop Blur
|
|
60
|
+
|
|
61
|
+
Add a premium blur effect to the overlay background:
|
|
62
|
+
```svelte
|
|
63
|
+
<script>
|
|
64
|
+
import { Drawer, DrawerOverlay, DrawerContent, DrawerHandle } from '@abhivarde/svelte-drawer';
|
|
65
|
+
|
|
66
|
+
let open = $state(false);
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<Drawer bind:open>
|
|
70
|
+
<!-- Default medium blur -->
|
|
71
|
+
<DrawerOverlay blur class="fixed inset-0 bg-black/40" />
|
|
72
|
+
|
|
73
|
+
<!-- Or specify blur intensity -->
|
|
74
|
+
<!-- <DrawerOverlay blur="sm" class="fixed inset-0 bg-black/40" /> -->
|
|
75
|
+
<!-- <DrawerOverlay blur="lg" class="fixed inset-0 bg-black/40" /> -->
|
|
76
|
+
<!-- <DrawerOverlay blur="xl" class="fixed inset-0 bg-black/40" /> -->
|
|
77
|
+
|
|
78
|
+
<DrawerContent class="fixed bottom-0 left-0 right-0 bg-white rounded-t-lg p-4">
|
|
79
|
+
<DrawerHandle class="mb-8" />
|
|
80
|
+
<h2>Blurred Backdrop</h2>
|
|
81
|
+
<p>Notice the premium blur effect behind this drawer.</p>
|
|
82
|
+
</DrawerContent>
|
|
83
|
+
</Drawer>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Available blur intensities:**
|
|
87
|
+
- `blur={true}` or `blur="md"` - Medium blur (default)
|
|
88
|
+
- `blur="sm"` - Small blur
|
|
89
|
+
- `blur="lg"` - Large blur
|
|
90
|
+
- `blur="xl"` - Extra large blur
|
|
91
|
+
- `blur="2xl"` - 2x extra large blur
|
|
92
|
+
- `blur="3xl"` - 3x extra large blur
|
|
93
|
+
|
|
56
94
|
### Side Drawer
|
|
57
95
|
|
|
58
96
|
```svelte
|
|
@@ -401,6 +439,7 @@ Overlay component that appears behind the drawer.
|
|
|
401
439
|
**Props:**
|
|
402
440
|
|
|
403
441
|
- `class` (string, optional) - CSS classes for styling
|
|
442
|
+
- `blur` (boolean | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl', optional) - Enable backdrop blur effect
|
|
404
443
|
|
|
405
444
|
### DrawerContent
|
|
406
445
|
|
|
@@ -485,6 +524,10 @@ Optional pre-styled footer component.
|
|
|
485
524
|
|
|
486
525
|
Visit [drawer.abhivarde.in](https://drawer.abhivarde.in) to see live examples.
|
|
487
526
|
|
|
527
|
+
## Star History
|
|
528
|
+
|
|
529
|
+
[](https://star-history.com/#AbhiVarde/svelte-drawer&Date)
|
|
530
|
+
|
|
488
531
|
## License
|
|
489
532
|
|
|
490
533
|
This project is licensed under the MIT License.
|
|
@@ -492,4 +535,4 @@ See the [LICENSE](./LICENSE) file for details.
|
|
|
492
535
|
|
|
493
536
|
## Credits
|
|
494
537
|
|
|
495
|
-
Inspired by [Vaul](https://github.com/emilkowalski/vaul) by Emil Kowalski.
|
|
538
|
+
Inspired by [Vaul](https://github.com/emilkowalski/vaul) by Emil Kowalski.
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
} = $props();
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
|
-
<div class="
|
|
15
|
+
<div class="border-t border-gray-200 p-4 mt-auto {className}" {...restProps}>
|
|
16
16
|
{#if children}
|
|
17
17
|
{@render children()}
|
|
18
18
|
{:else if actions}
|
|
19
|
-
<div class="flex gap-3
|
|
19
|
+
<div class="flex justify-end gap-3">
|
|
20
20
|
{@render actions()}
|
|
21
21
|
</div>
|
|
22
22
|
{/if}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
|
|
2
4
|
let {
|
|
3
5
|
title,
|
|
4
6
|
description,
|
|
@@ -17,55 +19,49 @@
|
|
|
17
19
|
[key: string]: any;
|
|
18
20
|
} = $props();
|
|
19
21
|
|
|
20
|
-
import { getContext } from "svelte";
|
|
21
|
-
|
|
22
22
|
const drawer = getContext<any>("drawer");
|
|
23
23
|
|
|
24
24
|
function handleClose() {
|
|
25
|
-
if (onClose)
|
|
26
|
-
|
|
27
|
-
} else {
|
|
28
|
-
drawer?.closeDrawer();
|
|
29
|
-
}
|
|
25
|
+
if (onClose) onClose();
|
|
26
|
+
else drawer?.closeDrawer();
|
|
30
27
|
}
|
|
31
28
|
</script>
|
|
32
29
|
|
|
33
|
-
<div
|
|
34
|
-
class="flex items-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{/if}
|
|
47
|
-
</div>
|
|
30
|
+
<div class="border-b border-gray-200 p-4 {className}" {...restProps}>
|
|
31
|
+
<div class="flex items-start justify-between gap-4">
|
|
32
|
+
{#if children}
|
|
33
|
+
{@render children()}
|
|
34
|
+
{:else}
|
|
35
|
+
<div class="flex-1">
|
|
36
|
+
{#if title}
|
|
37
|
+
<h2 class="text-lg font-semibold text-gray-900">{title}</h2>
|
|
38
|
+
{/if}
|
|
39
|
+
{#if description}
|
|
40
|
+
<p class="text-sm text-gray-600 mt-1">{description}</p>
|
|
41
|
+
{/if}
|
|
42
|
+
</div>
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
>
|
|
55
|
-
<svg
|
|
56
|
-
class="w-5 h-5 text-gray-500"
|
|
57
|
-
fill="none"
|
|
58
|
-
stroke="currentColor"
|
|
59
|
-
viewBox="0 0 24 24"
|
|
44
|
+
{#if showCloseButton}
|
|
45
|
+
<button
|
|
46
|
+
onclick={handleClose}
|
|
47
|
+
class="p-2 rounded-md hover:bg-gray-100 transition-colors"
|
|
48
|
+
aria-label="Close drawer"
|
|
60
49
|
>
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
stroke
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
50
|
+
<svg
|
|
51
|
+
class="w-5 h-5 text-gray-500"
|
|
52
|
+
fill="none"
|
|
53
|
+
stroke="currentColor"
|
|
54
|
+
viewBox="0 0 24 24"
|
|
55
|
+
>
|
|
56
|
+
<path
|
|
57
|
+
stroke-linecap="round"
|
|
58
|
+
stroke-linejoin="round"
|
|
59
|
+
stroke-width="2"
|
|
60
|
+
d="M6 18L18 6M6 6l12 12"
|
|
61
|
+
/>
|
|
62
|
+
</svg>
|
|
63
|
+
</button>
|
|
64
|
+
{/if}
|
|
69
65
|
{/if}
|
|
70
|
-
|
|
66
|
+
</div>
|
|
71
67
|
</div>
|
|
@@ -1,33 +1,47 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
|
|
4
|
+
let { class: className = "", blur = false, ...restProps } = $props();
|
|
5
|
+
|
|
6
|
+
const drawer = getContext("drawer");
|
|
7
|
+
|
|
8
|
+
const blurClass = $derived(() => {
|
|
9
|
+
if (!blur) return "";
|
|
10
|
+
|
|
11
|
+
if (blur === true) return "backdrop-blur-md";
|
|
12
|
+
|
|
13
|
+
const blurMap = {
|
|
14
|
+
sm: "backdrop-blur-sm",
|
|
15
|
+
md: "backdrop-blur-md",
|
|
16
|
+
lg: "backdrop-blur-lg",
|
|
17
|
+
xl: "backdrop-blur-xl",
|
|
18
|
+
"2xl": "backdrop-blur-2xl",
|
|
19
|
+
"3xl": "backdrop-blur-3xl",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return blurMap[blur] || "backdrop-blur-md";
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {KeyboardEvent} e
|
|
27
|
+
*/
|
|
28
|
+
function handleKeydown(e) {
|
|
29
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
30
|
+
e.preventDefault();
|
|
31
|
+
drawer.closeDrawer();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
20
34
|
</script>
|
|
21
35
|
|
|
22
36
|
{#if drawer.open}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{/if}
|
|
37
|
+
<div
|
|
38
|
+
class="fixed inset-0 bg-black/40 cursor-pointer {blurClass()} {className}"
|
|
39
|
+
style="opacity: {drawer.overlayOpacity.current}; z-index: 40;"
|
|
40
|
+
onclick={drawer.closeDrawer}
|
|
41
|
+
onkeydown={handleKeydown}
|
|
42
|
+
role="button"
|
|
43
|
+
tabindex="0"
|
|
44
|
+
aria-label="Close drawer"
|
|
45
|
+
{...restProps}
|
|
46
|
+
></div>
|
|
47
|
+
{/if}
|
package/dist/types.d.ts
CHANGED