@academix-admin/selection-viewer 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Academix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @academix-admin/selection-viewer
2
+
3
+ An imperative **selection sheet** for React — search + pick one item from a list — with a
4
+ controller hook. Built on [`@academix-admin/modal-sheet`](../modal-sheet).
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ npm install @academix-admin/selection-viewer
10
+ # peer deps
11
+ npm install react react-dom
12
+ ```
13
+
14
+ > `@academix-admin/modal-sheet` is installed as a dependency automatically.
15
+
16
+ ## Usage
17
+
18
+ ```tsx
19
+ 'use client';
20
+ import SelectionViewer, { useSelectionController } from '@academix-admin/selection-viewer';
21
+
22
+ function Page() {
23
+ const [id, ops, isOpen, selectionState] = useSelectionController();
24
+
25
+ return (
26
+ <>
27
+ <button onClick={ops.open}>Choose a wallet</button>
28
+ <SelectionViewer
29
+ id={id}
30
+ isOpen={isOpen}
31
+ onClose={ops.close}
32
+ titleProp={{ text: 'Select wallet', textColor: '#000' }}
33
+ selectionState={selectionState}
34
+ >
35
+ {wallets.map((w) => (
36
+ <WalletItem key={w.id} wallet={w} onClick={() => { pick(w); ops.close(); }} />
37
+ ))}
38
+ </SelectionViewer>
39
+ </>
40
+ );
41
+ }
42
+ ```
43
+
44
+ ## Pagination
45
+
46
+ Pass `onPaginate` to fetch more items as the user nears the bottom of the list (fires once the
47
+ scroll container is within 20% of a viewport-height of its end):
48
+
49
+ ```tsx
50
+ <SelectionViewer
51
+ ...
52
+ onPaginate={async () => {
53
+ const more = await fetchNextPage();
54
+ return more.length > 0; // return false once there really is nothing left
55
+ }}
56
+ />
57
+ ```
58
+
59
+ ## `selectionState`
60
+
61
+ `"initial" | "loading" | "empty" | "error" | "data"` — drives which of `loadingProp` /
62
+ `noResultProp` / `errorProp` renders in place of `children`. You own fetching/filtering entirely;
63
+ the component only renders what you hand it via `children` and this state.
64
+
65
+ Exports: `SelectionViewer` (default), `useSelectionController`, plus every prop/type
66
+ (`SelectionViewerProps`, `SelectionState`, `TitleProps`, `SearchProps`, `LoadingProps`,
67
+ `NoResultProps`, `ErrorProps`, `CancelButtonProps`, `LayoutProps`, `Padding`, `SnapPoint`).
68
+
69
+ ## License
70
+
71
+ MIT © Academix
package/dist/index.cjs ADDED
@@ -0,0 +1,575 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var React = require('react');
7
+ var modalSheet = require('@academix-admin/modal-sheet');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var React__default = /*#__PURE__*/_interopDefault(React);
13
+
14
+ // src/SelectionViewer.tsx
15
+ var getStyles = (id) => `
16
+ #${id} .selection-viewer-header {
17
+ padding: 0px;
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ position: relative;
22
+ width: 100%;
23
+ }
24
+
25
+ #${id} .selection-viewer-drag-handle {
26
+ height: 5px;
27
+ border-radius: 3px;
28
+ margin-top: 16px;
29
+ }
30
+
31
+ #${id} .selection-viewer-container {
32
+ display: flex;
33
+ align-items: flex-start;
34
+ width: 100%;
35
+ }
36
+
37
+ #${id} .selection-viewer-title {
38
+ margin: 0px;
39
+ font-size: 18px;
40
+ font-weight: 600;
41
+ padding: 0px 16px 0px 16px;
42
+ word-break: break-word; /* break long words */
43
+ white-space: normal; /* allow wrapping */
44
+ }
45
+
46
+ #${id} .selection-viewer-search {
47
+ display: flex;
48
+ align-items: center;
49
+ margin: 16px 16px 4px 16px;
50
+ border-radius: 12px;
51
+ box-sizing: border-box;
52
+ border: 1px solid rgba(0, 0, 0, 0.1);
53
+ }
54
+
55
+ #${id} .selection-viewer-search-input {
56
+ flex: 1;
57
+ border: none;
58
+ background: transparent;
59
+ padding: 12px 8px;
60
+ outline: none;
61
+ font-size: 16px !important;
62
+ width: 100%;
63
+ }
64
+
65
+ #${id} .selection-viewer-content {
66
+ overflow-y: auto;
67
+ -webkit-overflow-scrolling: touch;
68
+ flex: 1;
69
+ min-height: 0;
70
+ }
71
+
72
+ #${id} .selection-viewer-content.vertical {
73
+ display: flex;
74
+ flex-direction: column;
75
+ gap: 8px;
76
+ }
77
+
78
+ #${id} .selection-viewer-content.horizontal {
79
+ display: flex;
80
+ flex-direction: row;
81
+ gap: 8px;
82
+ overflow-x: auto;
83
+ overflow-y: hidden;
84
+ }
85
+
86
+ #${id} .selection-viewer-no-results,
87
+ #${id} .selection-viewer-error,
88
+ #${id} .selection-viewer-loading {
89
+ display: flex;
90
+ justify-content: center;
91
+ align-items: center;
92
+ min-height: 120px;
93
+ }
94
+
95
+ #${id} .selection-viewer-default-no-results {
96
+ color: #666;
97
+ font-size: 14px;
98
+ }
99
+
100
+ #${id} .selection-viewer-default-error {
101
+ color: red;
102
+ font-size: 14px;
103
+ }
104
+
105
+ /* Full screen search mode */
106
+ #${id} .selection-viewer-fullscreen-search {
107
+ // position: fixed;
108
+ top: 0;
109
+ left: 0;
110
+ right: 0;
111
+ z-index: 10;
112
+ // padding-top: env(safe-area-inset-top);
113
+ width: 100%;
114
+ }
115
+
116
+ #${id} .selection-viewer-search-back-button {
117
+ background: none;
118
+ border: none;
119
+ padding: 8px;
120
+ margin-right: 4px;
121
+ display: flex;
122
+ align-items: center;
123
+ justify-content: center;
124
+ cursor: pointer;
125
+ transition: opacity 0.2s;
126
+ }
127
+
128
+ #${id} .selection-viewer-search-back-button:hover {
129
+ opacity: 0.7;
130
+ }
131
+
132
+ #${id} .selection-viewer-search-clear-button {
133
+ background: none;
134
+ border: none;
135
+ padding: 8px;
136
+ margin-left: 4px;
137
+ display: flex;
138
+ align-items: center;
139
+ justify-content: center;
140
+ cursor: pointer;
141
+ transition: opacity 0.2s;
142
+ }
143
+
144
+ #${id} .selection-viewer-search-clear-button:hover {
145
+ opacity: 0.7;
146
+ }
147
+
148
+ /* React Modal Sheet overrides */
149
+ #${id} .react-modal-sheet-container {
150
+ max-width: 500px;
151
+ margin: 0 auto;
152
+ border-top-left-radius: 16px;
153
+ border-top-right-radius: 16px;
154
+ }
155
+
156
+ #${id} .react-modal-sheet-backdrop {
157
+ background-color: rgba(0, 0, 0, 0.5) !important;
158
+ pointer-events: auto !important;
159
+ }
160
+
161
+ #${id} .react-modal-sheet-content {
162
+ padding: 0 0px 0px 0px;
163
+ height: 100%;
164
+ }
165
+
166
+
167
+ /* Mobile full-width behavior */
168
+ @media (max-width: 500px) {
169
+ #${id} .react-modal-sheet-container {
170
+ max-width: 100%;
171
+ border-radius: 0;
172
+ }
173
+ }
174
+
175
+ /* Prevent iOS zooming */
176
+ @media screen and (-webkit-min-device-pixel-ratio: 0) {
177
+ #${id} .selection-viewer-search-input {
178
+ font-size: 16px !important;
179
+ }
180
+ }
181
+ `;
182
+ var useInjectStyles = (id) => {
183
+ React.useEffect(() => {
184
+ const styleId = `selection-viewer-styles-${id}`;
185
+ let styleTag = document.getElementById(styleId);
186
+ if (!styleTag) {
187
+ styleTag = document.createElement("style");
188
+ styleTag.id = styleId;
189
+ styleTag.innerHTML = getStyles(id);
190
+ document.head.appendChild(styleTag);
191
+ }
192
+ return () => {
193
+ if (styleTag && document.head.contains(styleTag)) {
194
+ document.head.removeChild(styleTag);
195
+ }
196
+ };
197
+ }, [id]);
198
+ };
199
+ var SelectionViewer = ({
200
+ id: providedId,
201
+ isOpen,
202
+ backDrop = true,
203
+ onClose,
204
+ titleProp,
205
+ searchProp,
206
+ loadingProp,
207
+ noResultProp,
208
+ errorProp,
209
+ cancelButton,
210
+ layoutProp,
211
+ childrenDirection = "vertical",
212
+ children,
213
+ onPaginate,
214
+ snapPoints = [0, 1],
215
+ initialSnap = 1,
216
+ unmountOnClose = true,
217
+ zIndex = 1e3,
218
+ maxHeight = "90dvh",
219
+ minHeight = "65dvh",
220
+ selectionState = "initial",
221
+ closeThreshold = 0.2
222
+ }) => {
223
+ const [id] = React.useState(() => providedId || `selection-${Math.random().toString(36).substring(2, 11)}`);
224
+ const [searchValue, setSearchValue] = React.useState("");
225
+ const [isSearchFocused, setIsSearchFocused] = React.useState(false);
226
+ const [keyboardHeight, setKeyboardHeight] = React.useState(0);
227
+ const [inputKey, setInputKey] = React.useState(0);
228
+ const [shouldAutoFocus, setShouldAutoFocus] = React.useState(false);
229
+ const isPaginating = React.useRef(false);
230
+ const searchInputRef = React.useRef(null);
231
+ const sheetRef = React.useRef(null);
232
+ React.useRef(null);
233
+ useInjectStyles(id);
234
+ React.useEffect(() => {
235
+ if (typeof window === "undefined" || !window.visualViewport) return;
236
+ const handleResize = () => {
237
+ const vp = window.visualViewport;
238
+ const kbHeight = window.innerHeight - vp.height;
239
+ setKeyboardHeight(kbHeight > 0 ? kbHeight : 0);
240
+ };
241
+ window.visualViewport.addEventListener("resize", handleResize);
242
+ window.visualViewport.addEventListener("scroll", handleResize);
243
+ return () => {
244
+ window.visualViewport?.removeEventListener("resize", handleResize);
245
+ window.visualViewport?.removeEventListener("scroll", handleResize);
246
+ };
247
+ }, []);
248
+ React.useEffect(() => {
249
+ if (!isOpen) {
250
+ searchInputRef.current?.blur();
251
+ setSearchValue("");
252
+ searchProp?.onChange?.("");
253
+ setShouldAutoFocus(false);
254
+ return;
255
+ }
256
+ }, [isOpen, searchProp?.autoFocus]);
257
+ const handleOpenEnd = React.useCallback(() => {
258
+ if (searchProp?.autoFocus && searchInputRef.current) {
259
+ setInputKey((prev) => prev + 1);
260
+ setShouldAutoFocus(true);
261
+ searchInputRef.current.focus();
262
+ searchInputRef.current.click();
263
+ }
264
+ }, [searchProp?.autoFocus]);
265
+ const handleSearchChange = (e) => {
266
+ const value = e.target.value;
267
+ setSearchValue(value);
268
+ searchProp?.onChange?.(value);
269
+ };
270
+ const handleSearchFocus = () => {
271
+ setIsSearchFocused(true);
272
+ searchProp?.onFocus?.();
273
+ requestAnimationFrame(() => {
274
+ searchInputRef.current?.focus();
275
+ });
276
+ };
277
+ const handleSearchBlur = () => {
278
+ searchProp?.onBlur?.();
279
+ };
280
+ const handleBackFromSearch = () => {
281
+ setIsSearchFocused(false);
282
+ if (searchInputRef.current) {
283
+ searchInputRef.current.blur();
284
+ }
285
+ };
286
+ const clearSearch = () => {
287
+ setSearchValue("");
288
+ searchProp?.onChange?.("");
289
+ if (searchInputRef.current) {
290
+ searchInputRef.current.focus();
291
+ }
292
+ };
293
+ const handleScroll = React.useCallback(
294
+ async (e) => {
295
+ if (isPaginating.current || !onPaginate) return;
296
+ const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
297
+ const isNearBottom = scrollHeight - scrollTop <= clientHeight * 1.2;
298
+ if (isNearBottom) {
299
+ isPaginating.current = true;
300
+ const hasMore = await onPaginate();
301
+ if (!hasMore) {
302
+ isPaginating.current = false;
303
+ } else {
304
+ setTimeout(() => {
305
+ isPaginating.current = false;
306
+ }, 500);
307
+ }
308
+ }
309
+ },
310
+ [onPaginate]
311
+ );
312
+ if (!isOpen && unmountOnClose) return null;
313
+ return /* @__PURE__ */ jsxRuntime.jsxs(
314
+ modalSheet.Sheet,
315
+ {
316
+ ref: sheetRef,
317
+ isOpen,
318
+ onClose,
319
+ detent: "content",
320
+ style: { zIndex },
321
+ maxHeight,
322
+ onOpenEnd: handleOpenEnd,
323
+ children: [
324
+ /* @__PURE__ */ jsxRuntime.jsxs(
325
+ modalSheet.Sheet.Container,
326
+ {
327
+ id,
328
+ style: {
329
+ maxHeight,
330
+ minHeight: isSearchFocused ? "100dvh" : minHeight,
331
+ maxWidth: layoutProp?.maxWidth ?? "800px",
332
+ margin: "0 auto",
333
+ width: "100%",
334
+ left: 0,
335
+ right: 0,
336
+ paddingBottom: "calc(0px + env(safe-area-inset-bottom))",
337
+ background: isSearchFocused ? layoutProp?.fullScreenSearchBackground || layoutProp?.backgroundColor : layoutProp?.backgroundColor,
338
+ borderTopLeftRadius: isSearchFocused ? "0px" : "16px",
339
+ borderTopRightRadius: isSearchFocused ? "0px" : "16px"
340
+ },
341
+ children: [
342
+ isSearchFocused ? /* @__PURE__ */ jsxRuntime.jsx(modalSheet.Sheet.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(
343
+ "div",
344
+ {
345
+ className: "selection-viewer-fullscreen-search",
346
+ style: layoutProp?.fullScreenSearchHeaderStyle,
347
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "selection-viewer-search", style: {
348
+ ...searchProp?.containerStyle,
349
+ background: searchProp?.background,
350
+ padding: searchProp?.padding ? `${searchProp.padding.t} ${searchProp.padding.r} ${searchProp.padding.b} ${searchProp.padding.l}` : "16px"
351
+ }, children: [
352
+ /* @__PURE__ */ jsxRuntime.jsx(
353
+ "button",
354
+ {
355
+ className: "selection-viewer-search-back-button",
356
+ onClick: handleBackFromSearch,
357
+ "aria-label": "Exit search mode",
358
+ children: searchProp?.backIcon || /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M15 18L9 12L15 6", stroke: searchProp?.textColor || "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
359
+ }
360
+ ),
361
+ /* @__PURE__ */ jsxRuntime.jsx(
362
+ "input",
363
+ {
364
+ ref: searchInputRef,
365
+ type: "text",
366
+ placeholder: searchProp?.text,
367
+ value: searchValue,
368
+ onChange: handleSearchChange,
369
+ className: searchProp?.className || "selection-viewer-search-input",
370
+ style: {
371
+ color: searchProp?.textColor,
372
+ ...searchProp?.inputStyle
373
+ },
374
+ onFocus: handleSearchFocus,
375
+ onBlur: handleSearchBlur,
376
+ autoFocus: shouldAutoFocus
377
+ },
378
+ inputKey
379
+ ),
380
+ searchValue && /* @__PURE__ */ jsxRuntime.jsx(
381
+ "button",
382
+ {
383
+ className: "selection-viewer-search-clear-button",
384
+ onClick: clearSearch,
385
+ "aria-label": "Clear search",
386
+ children: searchProp?.clearIcon || /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6L18 18", stroke: searchProp?.textColor || "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
387
+ }
388
+ )
389
+ ] })
390
+ }
391
+ ) }) : /* @__PURE__ */ jsxRuntime.jsxs(modalSheet.Sheet.Header, { children: [
392
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "selection-viewer-header", children: [
393
+ cancelButton?.position === "left" && /* @__PURE__ */ jsxRuntime.jsx(
394
+ "button",
395
+ {
396
+ style: {
397
+ position: "absolute",
398
+ left: "0px",
399
+ top: "8px",
400
+ border: "none",
401
+ backgroundColor: "transparent",
402
+ ...cancelButton.style
403
+ },
404
+ onClick: cancelButton.onClick || onClose,
405
+ children: cancelButton.view || cancelButton.text || "Cancel"
406
+ }
407
+ ),
408
+ !isSearchFocused && /* @__PURE__ */ jsxRuntime.jsx(
409
+ "div",
410
+ {
411
+ className: "selection-viewer-drag-handle",
412
+ style: {
413
+ background: layoutProp?.handleColor || "#ccc",
414
+ width: layoutProp?.handleWidth || "40px",
415
+ marginBottom: layoutProp?.gapBetweenHandleAndTitle || "12px"
416
+ }
417
+ }
418
+ ),
419
+ cancelButton?.position === "right" && /* @__PURE__ */ jsxRuntime.jsx(
420
+ "button",
421
+ {
422
+ style: {
423
+ position: "absolute",
424
+ right: "0px",
425
+ top: "8px",
426
+ border: "none",
427
+ backgroundColor: "transparent",
428
+ ...cancelButton.style
429
+ },
430
+ onClick: cancelButton.onClick || onClose,
431
+ children: cancelButton.view || cancelButton.text || "Cancel"
432
+ }
433
+ ),
434
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: titleProp.containerClass || "selection-viewer-container", children: /* @__PURE__ */ jsxRuntime.jsx(
435
+ "h2",
436
+ {
437
+ id: `${id}-title`,
438
+ className: titleProp.className || "selection-viewer-title",
439
+ style: {
440
+ marginBottom: layoutProp?.gapBetweenTitleAndSearch || "8px",
441
+ color: titleProp?.textColor || "black",
442
+ ...titleProp.style
443
+ },
444
+ children: titleProp.text
445
+ }
446
+ ) })
447
+ ] }),
448
+ searchProp && /* @__PURE__ */ jsxRuntime.jsxs(
449
+ "div",
450
+ {
451
+ className: "selection-viewer-search",
452
+ style: {
453
+ background: searchProp.background,
454
+ padding: searchProp.padding ? `${searchProp.padding.t} ${searchProp.padding.r} ${searchProp.padding.b} ${searchProp.padding.l}` : "8px 16px",
455
+ marginBottom: layoutProp?.gapBetweenSearchAndContent,
456
+ ...searchProp.containerStyle
457
+ },
458
+ children: [
459
+ searchProp.prefixIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { marginRight: searchProp.prefixGap || "8px" }, children: searchProp.prefixIcon }),
460
+ /* @__PURE__ */ jsxRuntime.jsx(
461
+ "input",
462
+ {
463
+ ref: searchInputRef,
464
+ type: "text",
465
+ placeholder: searchProp.text,
466
+ value: searchValue,
467
+ onChange: handleSearchChange,
468
+ className: searchProp.className || "selection-viewer-search-input",
469
+ style: {
470
+ color: searchProp?.textColor,
471
+ ...searchProp.inputStyle
472
+ },
473
+ onFocus: handleSearchFocus,
474
+ onBlur: handleSearchBlur,
475
+ autoFocus: shouldAutoFocus
476
+ },
477
+ inputKey
478
+ ),
479
+ searchValue && /* @__PURE__ */ jsxRuntime.jsx(
480
+ "button",
481
+ {
482
+ className: "selection-viewer-search-clear-button",
483
+ onClick: clearSearch,
484
+ "aria-label": "Clear search",
485
+ style: { marginLeft: searchProp.suffixGap || "8px" },
486
+ children: searchProp.clearIcon || searchProp.suffixIcon || /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M18 6L6 18M6 6L18 18", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
487
+ }
488
+ ),
489
+ !searchValue && searchProp.suffixIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { marginLeft: searchProp.suffixGap || "8px" }, children: searchProp.suffixIcon })
490
+ ]
491
+ }
492
+ )
493
+ ] }),
494
+ /* @__PURE__ */ jsxRuntime.jsx(modalSheet.Sheet.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(
495
+ "div",
496
+ {
497
+ className: `selection-viewer-content ${childrenDirection}`,
498
+ onScroll: onPaginate ? handleScroll : void 0,
499
+ style: {
500
+ paddingTop: isSearchFocused ? layoutProp?.gapBetweenSearchAndContent : "0",
501
+ paddingBottom: keyboardHeight > 0 ? `${keyboardHeight + 16}px` : "16px"
502
+ },
503
+ children: React__default.default.Children.count(children) > 0 ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
504
+ children,
505
+ selectionState === "loading" && /* @__PURE__ */ jsxRuntime.jsx(
506
+ "div",
507
+ {
508
+ className: "selection-viewer-loading",
509
+ style: {
510
+ padding: loadingProp?.padding ? `${loadingProp.padding.t} ${loadingProp.padding.r} ${loadingProp.padding.b} ${loadingProp.padding.l}` : "16px",
511
+ ...loadingProp?.style
512
+ },
513
+ children: loadingProp?.view
514
+ }
515
+ )
516
+ ] }) : selectionState === "empty" || React__default.default.Children.count(children) <= 0 && (selectionState != "loading" && selectionState != "error") ? /* @__PURE__ */ jsxRuntime.jsx(
517
+ "div",
518
+ {
519
+ className: "selection-viewer-no-results",
520
+ style: {
521
+ padding: noResultProp?.padding ? `${noResultProp.padding.t} ${noResultProp.padding.r} ${noResultProp.padding.b} ${noResultProp.padding.l}` : "16px",
522
+ ...noResultProp?.style
523
+ },
524
+ children: noResultProp?.view || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "selection-viewer-default-no-results", children: noResultProp?.text || "No results found" })
525
+ }
526
+ ) : selectionState === "loading" ? /* @__PURE__ */ jsxRuntime.jsx(
527
+ "div",
528
+ {
529
+ className: "selection-viewer-loading",
530
+ style: {
531
+ padding: loadingProp?.padding ? `${loadingProp.padding.t} ${loadingProp.padding.r} ${loadingProp.padding.b} ${loadingProp.padding.l}` : "16px",
532
+ ...loadingProp?.style
533
+ },
534
+ children: loadingProp?.view
535
+ }
536
+ ) : selectionState === "error" ? /* @__PURE__ */ jsxRuntime.jsx(
537
+ "div",
538
+ {
539
+ className: "selection-viewer-error",
540
+ style: {
541
+ padding: errorProp?.padding ? `${errorProp.padding.t} ${errorProp.padding.r} ${errorProp.padding.b} ${errorProp.padding.l}` : "16px",
542
+ ...errorProp?.style
543
+ },
544
+ children: errorProp?.view || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "selection-viewer-default-error", children: errorProp?.text || "No results found" })
545
+ }
546
+ ) : null
547
+ }
548
+ ) })
549
+ ]
550
+ }
551
+ ),
552
+ /* @__PURE__ */ jsxRuntime.jsx(modalSheet.Sheet.Backdrop, { onTap: backDrop ? onClose : void 0 })
553
+ ]
554
+ }
555
+ );
556
+ };
557
+ var useSelectionController = (initialSelectionState) => {
558
+ const [isOpen, setIsOpen] = React.useState(false);
559
+ const [selectionState, setSelectionState] = React.useState(initialSelectionState || "initial");
560
+ const [selectionId] = React.useState(() => `selection-${Math.random().toString(36).substring(2, 11)}`);
561
+ const operations = React.useMemo(() => ({
562
+ open: () => setIsOpen(true),
563
+ close: () => setIsOpen(false),
564
+ toggle: () => setIsOpen((prev) => !prev),
565
+ setSelectionState
566
+ }), [setSelectionState]);
567
+ return [selectionId, operations, isOpen, selectionState];
568
+ };
569
+ var SelectionViewer_default = SelectionViewer;
570
+
571
+ exports.SelectionViewer = SelectionViewer_default;
572
+ exports.default = SelectionViewer_default;
573
+ exports.useSelectionController = useSelectionController;
574
+ //# sourceMappingURL=index.cjs.map
575
+ //# sourceMappingURL=index.cjs.map