@surdeddd/bottom-sheet 0.3.0 → 0.4.0

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.
Files changed (45) hide show
  1. package/dist/{BottomSheetEngine-CAymrH-P.d.cts → BottomSheetEngine-BJrH7qY3.d.cts} +39 -3
  2. package/dist/{BottomSheetEngine-DcqcuudN.d.ts → BottomSheetEngine-L05jGZvU.d.ts} +39 -3
  3. package/dist/element.cjs +480 -89
  4. package/dist/element.d.cts +23 -4
  5. package/dist/element.d.ts +23 -4
  6. package/dist/element.iife.global.js +2 -2
  7. package/dist/element.js +480 -89
  8. package/dist/index.cjs +341 -80
  9. package/dist/index.d.cts +3 -2
  10. package/dist/index.d.ts +3 -2
  11. package/dist/index.js +341 -80
  12. package/dist/integrations/formik.d.cts +1 -1
  13. package/dist/integrations/formik.d.ts +1 -1
  14. package/dist/integrations/react-hook-form.d.cts +1 -1
  15. package/dist/integrations/react-hook-form.d.ts +1 -1
  16. package/dist/overlay.cjs +13 -2
  17. package/dist/overlay.js +13 -2
  18. package/dist/preact.d.cts +1 -1
  19. package/dist/preact.d.ts +1 -1
  20. package/dist/qwik.cjs +352 -81
  21. package/dist/qwik.d.cts +4 -2
  22. package/dist/qwik.d.ts +4 -2
  23. package/dist/qwik.js +352 -81
  24. package/dist/react.cjs +427 -87
  25. package/dist/react.d.cts +29 -4
  26. package/dist/react.d.ts +29 -4
  27. package/dist/react.js +427 -87
  28. package/dist/solid.cjs +341 -80
  29. package/dist/solid.d.cts +38 -2
  30. package/dist/solid.d.ts +38 -2
  31. package/dist/solid.js +341 -80
  32. package/dist/solid.source.jsx +341 -80
  33. package/dist/styles.css +57 -56
  34. package/dist/svelte-core.cjs +346 -80
  35. package/dist/svelte-core.js +346 -80
  36. package/dist/svelte-src/BottomSheet.svelte +103 -5
  37. package/dist/svelte.cjs +421 -88
  38. package/dist/svelte.d.cts +21 -0
  39. package/dist/svelte.d.ts +21 -0
  40. package/dist/svelte.js +421 -88
  41. package/dist/vue.cjs +584 -91
  42. package/dist/vue.d.cts +51 -2
  43. package/dist/vue.d.ts +51 -2
  44. package/dist/vue.js +585 -92
  45. package/package.json +6 -6
@@ -8,6 +8,7 @@
8
8
  ScrimUpdate,
9
9
  ScrimOverlayOptions,
10
10
  EngineOptions,
11
+ SheetEventMap,
11
12
  } from "@surdeddd/bottom-sheet";
12
13
 
13
14
  type Props = {
@@ -25,6 +26,17 @@
25
26
  backdropRange?: [number, number];
26
27
  backdrop?: boolean;
27
28
  closeOnBackdrop?: boolean;
29
+ persistent?: boolean;
30
+ disableClose?: boolean;
31
+ disableDrag?: boolean;
32
+ closeOnRouteChange?: boolean;
33
+ radius?: string | number;
34
+ maxHeight?: string | number;
35
+ backdropColor?: string;
36
+ backdropOpacity?: number;
37
+ open?: boolean;
38
+ snap?: TId;
39
+ returnFocusTo?: HTMLElement | string | (() => HTMLElement | null);
28
40
  ariaLabel?: string;
29
41
  header?: Snippet<[EngineState & { activeId: TId }]>;
30
42
  leftButton?: Snippet;
@@ -34,6 +46,11 @@
34
46
  onsnap?: (id: TId) => void;
35
47
  onopen?: (id: TId) => void;
36
48
  onclose?: () => void;
49
+ onbeforeclose?: (payload: SheetEventMap["before-close"]) => void;
50
+ onopened?: (id: TId) => void;
51
+ onclosed?: () => void;
52
+ ondragstart?: () => void;
53
+ ondragend?: () => void;
37
54
  onchange?: (state: EngineState & { activeId: TId }) => void;
38
55
  };
39
56
 
@@ -52,6 +69,17 @@
52
69
  backdropRange,
53
70
  backdrop = true,
54
71
  closeOnBackdrop = true,
72
+ persistent = false,
73
+ disableClose = false,
74
+ disableDrag = false,
75
+ closeOnRouteChange = false,
76
+ radius,
77
+ maxHeight,
78
+ backdropColor,
79
+ backdropOpacity,
80
+ open: openProp = $bindable(),
81
+ snap = $bindable(),
82
+ returnFocusTo,
55
83
  ariaLabel = "Bottom sheet",
56
84
  header,
57
85
  leftButton,
@@ -61,6 +89,11 @@
61
89
  onsnap,
62
90
  onopen,
63
91
  onclose,
92
+ onbeforeclose,
93
+ onopened,
94
+ onclosed,
95
+ ondragstart,
96
+ ondragend,
64
97
  onchange,
65
98
  }: Props = $props();
66
99
 
@@ -102,6 +135,13 @@
102
135
  lockBodyScroll,
103
136
  rubberBand,
104
137
  backdropRange,
138
+ persistent,
139
+ disableClose,
140
+ disableDrag,
141
+ closeOnRouteChange,
142
+ radius,
143
+ maxHeight,
144
+ returnFocusTo,
105
145
  });
106
146
  const sync = () => {
107
147
  if (!engine) return;
@@ -109,14 +149,33 @@
109
149
  onchange?.(viewState);
110
150
  };
111
151
  sync();
152
+ if (backdropColor !== undefined) engine.setScrimColor(backdropColor);
153
+ if (backdropOpacity !== undefined)
154
+ engine.setBackdropRange([0, backdropOpacity]);
112
155
  engine.on("snap", payload => {
113
156
  sync();
157
+ snap = payload.id as TId;
114
158
  onsnap?.(payload.id as TId);
115
159
  });
116
- engine.on("open", payload => onopen?.(payload.id as TId));
117
- engine.on("close", () => onclose?.());
118
- engine.on("dragstart", sync);
119
- engine.on("dragend", sync);
160
+ engine.on("open", payload => {
161
+ openProp = true;
162
+ onopen?.(payload.id as TId);
163
+ });
164
+ engine.on("close", () => {
165
+ openProp = false;
166
+ onclose?.();
167
+ });
168
+ engine.on("before-close", payload => onbeforeclose?.(payload));
169
+ engine.on("opened", payload => onopened?.(payload.id as TId));
170
+ engine.on("closed", () => onclosed?.());
171
+ engine.on("dragstart", () => {
172
+ sync();
173
+ ondragstart?.();
174
+ });
175
+ engine.on("dragend", () => {
176
+ sync();
177
+ ondragend?.();
178
+ });
120
179
  });
121
180
 
122
181
  onDestroy(() => {
@@ -129,6 +188,10 @@
129
188
  export const open = (id?: TId) =>
130
189
  engine?.open(id) ?? Promise.resolve();
131
190
  export const close = () => engine?.close() ?? Promise.resolve();
191
+ export const expand = () => engine?.expand() ?? Promise.resolve();
192
+ export const collapse = () => engine?.collapse() ?? Promise.resolve();
193
+ export const isTop = (): boolean => engine?.isTop() ?? false;
194
+ export const depth = (): number => engine?.depth() ?? 0;
132
195
  export const setAllowed = (ids: TId[], snap?: TId) =>
133
196
  engine?.setAllowed(ids as unknown as string[], snap);
134
197
  export const setSnapPoints = (
@@ -138,10 +201,41 @@
138
201
  export const setScrim = (opts: ScrimUpdate) => engine?.setScrim(opts);
139
202
  export const setScrimOverlay = (opts: ScrimOverlayOptions): (() => void) =>
140
203
  engine?.setScrimOverlay(opts) ?? (() => {});
204
+ export const setRadius = (r: string | number) => engine?.setRadius(r);
205
+ export const setMaxHeight = (h: string | number) => engine?.setMaxHeight(h);
206
+ export const canDismiss = (): boolean => engine?.canDismiss() ?? false;
141
207
  export const getState = (): EngineState & { activeId: TId } =>
142
208
  (engine?.state ?? viewState) as EngineState & { activeId: TId };
143
209
  export const getEngine = (): BottomSheetEngine | null => engine;
144
210
 
211
+ $effect(() => {
212
+ if (radius !== undefined) engine?.setRadius(radius);
213
+ });
214
+ $effect(() => {
215
+ if (maxHeight !== undefined) engine?.setMaxHeight(maxHeight);
216
+ });
217
+ $effect(() => {
218
+ if (backdropColor !== undefined) engine?.setScrimColor(backdropColor);
219
+ });
220
+ $effect(() => {
221
+ if (backdropOpacity !== undefined)
222
+ engine?.setBackdropRange([0, backdropOpacity]);
223
+ });
224
+ $effect(() => {
225
+ if (snap === undefined) return;
226
+ const next = snap;
227
+ if (!engine || untrack(() => viewState.activeId) === next) return;
228
+ void engine.snapTo(next);
229
+ });
230
+ $effect(() => {
231
+ if (openProp === undefined) return;
232
+ const next = openProp;
233
+ if (!engine) return;
234
+ const isOpen = untrack(() => viewState.size) > 0;
235
+ if (next && !isOpen) void engine.open();
236
+ else if (!next && isOpen) void engine.close();
237
+ });
238
+
145
239
  let allowedIds = $derived(
146
240
  allowed && allowed.length > 0
147
241
  ? allowed
@@ -159,7 +253,11 @@
159
253
  class="bs-backdrop"
160
254
  bind:this={backdropEl}
161
255
  aria-hidden="true"
162
- onclick={closeOnBackdrop ? () => engine?.close() : undefined}
256
+ onclick={closeOnBackdrop
257
+ ? () => {
258
+ if (engine?.canDismiss()) void engine.close("backdrop");
259
+ }
260
+ : undefined}
163
261
  ></div>
164
262
  {/if}
165
263
  <div class="bs-screen" bind:this={screenEl}>