@abhivarde/svelte-drawer 1.0.3 → 1.0.5
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 +49 -17
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ A drawer component for Svelte 5, inspired by [Vaul](https://github.com/emilkowal
|
|
|
21
21
|
- ✅ Fully accessible with keyboard navigation
|
|
22
22
|
- ✅ Full **TypeScript** support
|
|
23
23
|
- ✅ Customizable styling with **Tailwind CSS**
|
|
24
|
-
- ✅ **Auto height**
|
|
24
|
+
- ✅ **Auto height** for dynamic content (AI streaming, forms, dynamic lists)
|
|
25
25
|
|
|
26
26
|
## Installation
|
|
27
27
|
|
|
@@ -463,40 +463,72 @@ Automatically save and restore drawer state across page reloads.
|
|
|
463
463
|
|
|
464
464
|
### Auto Height (AI & Dynamic Content)
|
|
465
465
|
|
|
466
|
-
Use `autoHeight` on `DrawerContent` when your drawer content changes height at runtime
|
|
466
|
+
Use `autoHeight` on `DrawerContent` when your drawer content changes height at runtime like AI streaming responses, multi-step forms, search results, or dynamic lists.
|
|
467
467
|
|
|
468
468
|
```svelte
|
|
469
469
|
<script>
|
|
470
|
-
import {
|
|
470
|
+
import {
|
|
471
|
+
Drawer,
|
|
472
|
+
DrawerOverlay,
|
|
473
|
+
DrawerContent,
|
|
474
|
+
DrawerHandle
|
|
475
|
+
} from '@abhivarde/svelte-drawer';
|
|
471
476
|
|
|
472
477
|
let open = $state(false);
|
|
473
|
-
let
|
|
478
|
+
let streaming = $state(false);
|
|
479
|
+
let text = $state('');
|
|
474
480
|
|
|
475
|
-
|
|
476
|
-
function openAndStream() {
|
|
481
|
+
async function simulate() {
|
|
477
482
|
open = true;
|
|
478
|
-
|
|
483
|
+
streaming = true;
|
|
484
|
+
text = '';
|
|
485
|
+
|
|
486
|
+
const content =
|
|
487
|
+
'Sure! Here is what autoHeight does. It watches your content with a ResizeObserver. When content grows, the drawer follows automatically. No magic numbers, no hardcoded heights, it just works smoothly with streaming UI like AI chat apps.';
|
|
488
|
+
|
|
489
|
+
for (let i = 0; i < content.length; i++) {
|
|
490
|
+
text += content[i];
|
|
491
|
+
await new Promise(r => setTimeout(r, 18));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
streaming = false;
|
|
479
495
|
}
|
|
480
496
|
</script>
|
|
481
497
|
|
|
482
|
-
<button onclick={
|
|
498
|
+
<button onclick={simulate}>Ask AI</button>
|
|
483
499
|
|
|
484
500
|
<Drawer bind:open>
|
|
485
|
-
<DrawerOverlay
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
501
|
+
<DrawerOverlay />
|
|
502
|
+
|
|
503
|
+
<DrawerContent
|
|
504
|
+
autoHeight
|
|
505
|
+
class="bg-gray-100 flex flex-col rounded-t-[10px] fixed bottom-0 left-0 right-0 outline-none"
|
|
506
|
+
>
|
|
507
|
+
<div class="p-4 bg-white rounded-t-[10px]">
|
|
508
|
+
<DrawerHandle class="mb-8" />
|
|
509
|
+
|
|
510
|
+
<p class="font-medium mb-2 text-gray-900">
|
|
511
|
+
AI Response
|
|
512
|
+
</p>
|
|
513
|
+
|
|
514
|
+
{#if text}
|
|
515
|
+
<p class="text-sm text-gray-600 leading-relaxed">
|
|
516
|
+
{text}{streaming ? '▌' : ''}
|
|
517
|
+
</p>
|
|
518
|
+
{/if}
|
|
519
|
+
</div>
|
|
489
520
|
</DrawerContent>
|
|
490
521
|
</Drawer>
|
|
491
522
|
```
|
|
492
523
|
|
|
493
524
|
**How it works:**
|
|
494
525
|
|
|
495
|
-
-
|
|
496
|
-
-
|
|
497
|
-
-
|
|
498
|
-
-
|
|
499
|
-
-
|
|
526
|
+
- `height: auto` is applied to the drawer when `autoHeight` is true
|
|
527
|
+
- The drawer grows and shrinks naturally as content changes
|
|
528
|
+
- Perfect for AI streaming, dynamic lists, forms, and async content
|
|
529
|
+
- The slide animation remains smooth since it uses CSS transforms separately
|
|
530
|
+
- Fully compatible with snap points, portals, and existing props
|
|
531
|
+
- Zero impact on drawers that do not use `autoHeight` (opt-in, default `false`)
|
|
500
532
|
|
|
501
533
|
## Variants
|
|
502
534
|
|