@abhivarde/svelte-drawer 0.0.4 → 0.0.6
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 +65 -1
- package/dist/components/DrawerVariants.svelte +38 -0
- package/dist/components/DrawerVariants.svelte.d.ts +10 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -2
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,8 +4,9 @@ A drawer component for Svelte 5, inspired by [Vaul](https://github.com/emilkowal
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- ✅ Smooth animations using Svelte 5's
|
|
7
|
+
- ✅ Smooth animations using Svelte 5's Tween motion
|
|
8
8
|
- ✅ Multiple directions (bottom, top, left, right)
|
|
9
|
+
- ✅ Prebuilt variants (default, sheet, dialog, minimal, sidebar)
|
|
9
10
|
- ✅ Nested drawers support
|
|
10
11
|
- ✅ Scrollable content
|
|
11
12
|
- ✅ Keyboard shortcuts (Escape to close, Tab navigation)
|
|
@@ -111,6 +112,59 @@ npm install @abhivarde/svelte-drawer
|
|
|
111
112
|
</Drawer>
|
|
112
113
|
```
|
|
113
114
|
|
|
115
|
+
### Using Variants
|
|
116
|
+
|
|
117
|
+
```svelte
|
|
118
|
+
<script>
|
|
119
|
+
import { Drawer, DrawerOverlay, DrawerVariants } from '@abhivarde/svelte-drawer';
|
|
120
|
+
|
|
121
|
+
let open = $state(false);
|
|
122
|
+
</script>
|
|
123
|
+
|
|
124
|
+
<!-- Sheet variant (iOS-style bottom sheet) -->
|
|
125
|
+
<Drawer bind:open>
|
|
126
|
+
<DrawerOverlay class="fixed inset-0 bg-black/40" />
|
|
127
|
+
<DrawerVariants variant="sheet">
|
|
128
|
+
<div class="p-6">
|
|
129
|
+
<h2>iOS-style Sheet</h2>
|
|
130
|
+
<p>Clean and modern bottom sheet design</p>
|
|
131
|
+
</div>
|
|
132
|
+
</DrawerVariants>
|
|
133
|
+
</Drawer>
|
|
134
|
+
|
|
135
|
+
<!-- Dialog variant (center modal) -->
|
|
136
|
+
<Drawer bind:open>
|
|
137
|
+
<DrawerOverlay class="fixed inset-0 bg-black/40" />
|
|
138
|
+
<DrawerVariants variant="dialog">
|
|
139
|
+
<div class="p-6">
|
|
140
|
+
<h2>Dialog Style</h2>
|
|
141
|
+
<p>Center-positioned modal dialog</p>
|
|
142
|
+
</div>
|
|
143
|
+
</DrawerVariants>
|
|
144
|
+
</Drawer>
|
|
145
|
+
|
|
146
|
+
<!-- Sidebar variant (navigation drawer) -->
|
|
147
|
+
<Drawer bind:open direction="right">
|
|
148
|
+
<DrawerOverlay class="fixed inset-0 bg-black/40" />
|
|
149
|
+
<DrawerVariants variant="sidebar">
|
|
150
|
+
<div class="p-6">
|
|
151
|
+
<h2>Sidebar Navigation</h2>
|
|
152
|
+
<p>Side navigation drawer</p>
|
|
153
|
+
</div>
|
|
154
|
+
</DrawerVariants>
|
|
155
|
+
</Drawer>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Variants
|
|
159
|
+
|
|
160
|
+
Available variants for `DrawerVariants` component:
|
|
161
|
+
|
|
162
|
+
- `default` - Standard bottom drawer with gray background
|
|
163
|
+
- `sheet` - iOS-style bottom sheet (white, rounded, 85vh height)
|
|
164
|
+
- `dialog` - Center modal dialog style
|
|
165
|
+
- `minimal` - Simple bottom drawer without extra styling
|
|
166
|
+
- `sidebar` - Side navigation drawer (full height)
|
|
167
|
+
|
|
114
168
|
## Keyboard Shortcuts
|
|
115
169
|
|
|
116
170
|
- **Escape** - Close the drawer (can be disabled with `closeOnEscape={false}`)
|
|
@@ -147,6 +201,16 @@ Content container for the drawer.
|
|
|
147
201
|
- `class` (string, optional) - CSS classes for styling
|
|
148
202
|
- `trapFocus` (boolean, optional, default: true) - Whether to trap focus inside drawer
|
|
149
203
|
|
|
204
|
+
### DrawerVariants
|
|
205
|
+
|
|
206
|
+
Pre-styled drawer content with built-in variants.
|
|
207
|
+
|
|
208
|
+
**Props:**
|
|
209
|
+
|
|
210
|
+
- `variant` ('default' | 'sheet' | 'dialog' | 'minimal' | 'sidebar', default: 'default') - Preset style variant
|
|
211
|
+
- `class` (string, optional) - Additional CSS classes for styling
|
|
212
|
+
- `trapFocus` (boolean, optional, default: true) - Whether to trap focus inside drawer
|
|
213
|
+
|
|
150
214
|
## Demo
|
|
151
215
|
|
|
152
216
|
Visit [drawer.abhivarde.in](https://drawer.abhivarde.in) to see live examples.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import DrawerContent from "./DrawerContent.svelte";
|
|
3
|
+
|
|
4
|
+
type Variant = "default" | "sheet" | "dialog" | "minimal" | "sidebar";
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
variant = "default",
|
|
8
|
+
class: className = "",
|
|
9
|
+
children,
|
|
10
|
+
...restProps
|
|
11
|
+
}: {
|
|
12
|
+
variant?: Variant;
|
|
13
|
+
class?: string;
|
|
14
|
+
children?: any;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
} = $props();
|
|
17
|
+
|
|
18
|
+
const variantStyles: Record<Variant, string> = {
|
|
19
|
+
default:
|
|
20
|
+
"bg-gray-100 flex flex-col rounded-t-[10px] mt-24 h-fit fixed bottom-0 left-0 right-0 outline-none",
|
|
21
|
+
sheet:
|
|
22
|
+
"bg-white flex flex-col rounded-t-3xl h-[85vh] fixed bottom-0 left-0 right-0 outline-none shadow-2xl",
|
|
23
|
+
dialog:
|
|
24
|
+
"bg-white flex flex-col rounded-lg h-fit max-h-[90vh] fixed inset-0 m-auto max-w-lg outline-none shadow-xl",
|
|
25
|
+
minimal:
|
|
26
|
+
"bg-white flex flex-col h-fit fixed bottom-0 left-0 right-0 outline-none",
|
|
27
|
+
sidebar:
|
|
28
|
+
"bg-white h-full w-full max-w-sm fixed top-0 bottom-0 outline-none shadow-2xl",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const combinedClass = $derived(
|
|
32
|
+
`${variantStyles[variant]} ${className}`.trim()
|
|
33
|
+
);
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<DrawerContent class={combinedClass} {...restProps}>
|
|
37
|
+
{@render children?.()}
|
|
38
|
+
</DrawerContent>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Variant = "default" | "sheet" | "dialog" | "minimal" | "sidebar";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
variant?: Variant;
|
|
4
|
+
class?: string;
|
|
5
|
+
children?: any;
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
declare const DrawerVariants: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type DrawerVariants = ReturnType<typeof DrawerVariants>;
|
|
10
|
+
export default DrawerVariants;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as Drawer } from "./components/Drawer.svelte";
|
|
2
|
-
export { default as DrawerOverlay } from "./components/DrawerOverlay.svelte";
|
|
3
2
|
export { default as DrawerContent } from "./components/DrawerContent.svelte";
|
|
4
|
-
export
|
|
3
|
+
export { default as DrawerOverlay } from "./components/DrawerOverlay.svelte";
|
|
4
|
+
export { default as DrawerVariants } from "./components/DrawerVariants.svelte";
|
|
5
|
+
export type { DrawerProps, DrawerContentProps, DrawerOverlayProps, } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as Drawer } from "./components/Drawer.svelte";
|
|
2
|
-
export { default as DrawerOverlay } from "./components/DrawerOverlay.svelte";
|
|
3
2
|
export { default as DrawerContent } from "./components/DrawerContent.svelte";
|
|
4
|
-
export
|
|
3
|
+
export { default as DrawerOverlay } from "./components/DrawerOverlay.svelte";
|
|
4
|
+
export { default as DrawerVariants } from "./components/DrawerVariants.svelte";
|
package/dist/types.d.ts
CHANGED
|
@@ -11,3 +11,9 @@ export interface DrawerContentProps {
|
|
|
11
11
|
export interface DrawerOverlayProps {
|
|
12
12
|
class?: string;
|
|
13
13
|
}
|
|
14
|
+
export type DrawerVariant = "default" | "sheet" | "dialog" | "minimal" | "sidebar";
|
|
15
|
+
export interface DrawerVariantsProps {
|
|
16
|
+
variant?: DrawerVariant;
|
|
17
|
+
class?: string;
|
|
18
|
+
trapFocus?: boolean;
|
|
19
|
+
}
|