|
1 | 1 | <script lang="ts">
|
2 |
| - import { CupertinoPane } from 'cupertino-pane'; |
3 |
| - import { type Snippet } from 'svelte'; |
4 |
| - import type { HTMLAttributes } from 'svelte/elements'; |
5 |
| - import { swipe } from 'svelte-gestures'; |
6 |
| - import { clickOutside, cn } from '$lib/utils'; |
| 2 | + import { CupertinoPane } from 'cupertino-pane' |
| 3 | + import { type Snippet } from 'svelte' |
| 4 | + import type { HTMLAttributes } from 'svelte/elements' |
| 5 | + import { swipe } from 'svelte-gestures' |
| 6 | + import { clickOutside, cn } from '$lib/utils' |
7 | 7 |
|
8 |
| - interface IDrawerProps extends HTMLAttributes<HTMLDivElement> { |
9 |
| - isPaneOpen?: boolean; |
10 |
| - isCancelRequired?: boolean; |
11 |
| - children?: Snippet; |
12 |
| - handleSwipe?: (isOpen: boolean | undefined) => void; |
13 |
| - } |
| 8 | + interface IDrawerProps extends HTMLAttributes<HTMLDivElement> { |
| 9 | + isPaneOpen?: boolean |
| 10 | + isCancelRequired?: boolean |
| 11 | + children?: Snippet |
| 12 | + handleSwipe?: (isOpen: boolean | undefined) => void |
| 13 | + } |
14 | 14 |
|
15 |
| - let drawerElem: HTMLDivElement; |
16 |
| - let pane: CupertinoPane; |
| 15 | + let drawerElem: HTMLDivElement |
| 16 | + let pane: CupertinoPane |
17 | 17 |
|
18 |
| - let { |
19 |
| - isPaneOpen = $bindable(), |
20 |
| - isCancelRequired = false, |
21 |
| - children = undefined, |
22 |
| - handleSwipe, |
23 |
| - ...restProps |
24 |
| - }: IDrawerProps = $props(); |
| 18 | + let { |
| 19 | + isPaneOpen = $bindable(), |
| 20 | + isCancelRequired = false, |
| 21 | + children = undefined, |
| 22 | + handleSwipe, |
| 23 | + ...restProps |
| 24 | + }: IDrawerProps = $props() |
25 | 25 |
|
26 |
| - const handleClickOutside = () => { |
27 |
| - pane?.destroy({ animate: true }); |
28 |
| - isPaneOpen = false; |
29 |
| - }; |
| 26 | + const handleClickOutside = () => { |
| 27 | + pane?.destroy({ animate: true }) |
| 28 | + isPaneOpen = false |
| 29 | + } |
30 | 30 |
|
31 |
| - $effect(() => { |
32 |
| - if (!drawerElem) return; |
33 |
| - pane = new CupertinoPane(drawerElem, { |
34 |
| - fitHeight:true, |
35 |
| - backdrop: true, |
36 |
| - backdropOpacity: 0.5, |
37 |
| - backdropBlur: true, |
38 |
| - bottomClose: true, |
39 |
| - buttonDestroy: isCancelRequired, |
40 |
| - showDraggable: true, |
41 |
| - upperThanTop: true, |
42 |
| - breaks: { |
43 |
| - bottom: { enabled: true, height: 250 }, |
44 |
| - }, |
45 |
| - initialBreak: 'bottom', |
46 |
| - }); |
| 31 | + $effect(() => { |
| 32 | + if (!drawerElem) return |
| 33 | + pane = new CupertinoPane(drawerElem, { |
| 34 | + fitHeight: true, |
| 35 | + backdrop: true, |
| 36 | + backdropOpacity: 0.5, |
| 37 | + backdropBlur: true, |
| 38 | + bottomClose: true, |
| 39 | + buttonDestroy: isCancelRequired, |
| 40 | + showDraggable: true, |
| 41 | + upperThanTop: true, |
| 42 | + breaks: { |
| 43 | + bottom: { enabled: true, height: 250 }, |
| 44 | + }, |
| 45 | + initialBreak: 'bottom', |
| 46 | + }) |
47 | 47 |
|
48 |
| - if (isPaneOpen) { |
49 |
| - pane.present({ animate: true }); |
50 |
| - } else { |
51 |
| - pane.destroy({ animate: true }); |
52 |
| - } |
| 48 | + if (isPaneOpen) { |
| 49 | + pane.present({ animate: true }) |
| 50 | + } else { |
| 51 | + pane.destroy({ animate: true }) |
| 52 | + } |
53 | 53 |
|
54 |
| - return () => pane.destroy(); |
55 |
| - }); |
| 54 | + return () => pane.destroy() |
| 55 | + }) |
56 | 56 |
|
57 |
| - $effect(() => { |
58 |
| - if (isPaneOpen) { |
59 |
| - pane.present({ animate: true }); |
60 |
| - } else { |
61 |
| - pane.destroy({ animate: true }); |
62 |
| - } |
63 |
| - drawerElem.addEventListener('click_outside', () => { |
64 |
| - handleClickOutside(); |
65 |
| - }); |
66 |
| - }); |
| 57 | + $effect(() => { |
| 58 | + if (isPaneOpen) { |
| 59 | + pane.present({ animate: true }) |
| 60 | + } else { |
| 61 | + pane.destroy({ animate: true }) |
| 62 | + } |
| 63 | + drawerElem.addEventListener('click_outside', () => { |
| 64 | + handleClickOutside() |
| 65 | + }) |
| 66 | + }) |
67 | 67 | </script>
|
68 | 68 |
|
69 | 69 | <div
|
70 |
| - {...restProps} |
71 |
| - use:swipe={() => ({ |
72 |
| - timeframe: 300, |
73 |
| - minSwipeDistance: 60 |
74 |
| - })} |
75 |
| - onswipe={() => handleSwipe?.(isPaneOpen)} |
76 |
| - bind:this={drawerElem} |
77 |
| - use:clickOutside |
78 |
| - class={cn(restProps.class)} |
| 70 | + {...restProps} |
| 71 | + use:swipe={() => ({ |
| 72 | + timeframe: 300, |
| 73 | + minSwipeDistance: 60, |
| 74 | + })} |
| 75 | + onswipe={() => handleSwipe?.(isPaneOpen)} |
| 76 | + bind:this={drawerElem} |
| 77 | + use:clickOutside |
| 78 | + class={cn(restProps.class)} |
79 | 79 | >
|
80 |
| - <div class="px-6"> |
81 |
| - {@render children?.()} |
82 |
| - </div> |
| 80 | + <div class="px-6"> |
| 81 | + {@render children?.()} |
| 82 | + </div> |
83 | 83 | </div>
|
84 | 84 |
|
85 | 85 | <style>
|
86 |
| - :global(.pane) { |
87 |
| - width: 95% !important; |
88 |
| - max-height: 600px !important; |
89 |
| - min-height: 250px !important; |
90 |
| - height: auto !important; |
91 |
| - position: fixed !important; |
92 |
| - bottom: 30px !important; |
93 |
| - left: 50% !important; |
94 |
| - transform: translateX(-50%) !important; |
95 |
| - border-radius: 32px !important; |
96 |
| - padding-block-start: 50px !important; |
97 |
| - padding-block-end: 20px !important; |
98 |
| - background-color: var(--color-white-900) !important; |
99 |
| - overflow: hidden !important; /* Prevents content overflow */ |
100 |
| -} |
| 86 | + :global(.pane) { |
| 87 | + width: 95% !important; |
| 88 | + max-height: 600px !important; |
| 89 | + min-height: 250px !important; |
| 90 | + height: auto !important; |
| 91 | + position: fixed !important; |
| 92 | + bottom: 30px !important; |
| 93 | + left: 50% !important; |
| 94 | + transform: translateX(-50%) !important; |
| 95 | + border-radius: 32px !important; |
| 96 | + padding-block-start: 50px !important; |
| 97 | + padding-block-end: 20px !important; |
| 98 | + background-color: var(--color-white) !important; |
| 99 | + overflow: hidden !important; /* Prevents content overflow */ |
| 100 | + } |
101 | 101 |
|
102 |
| - :global(.move) { |
103 |
| - margin-block: 6px !important; |
104 |
| - } |
| 102 | + :global(.move) { |
| 103 | + margin-block: 6px !important; |
| 104 | + } |
105 | 105 | </style>
|
106 |
| - |
107 |
| - |
0 commit comments