@foundrykit/components 2.1.4 → 2.2.1

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 (107) hide show
  1. package/dist/chunk-4WYKNDYY.js +91 -0
  2. package/dist/chunk-4WYKNDYY.js.map +1 -0
  3. package/dist/chunk-5CXNMTIN.js +84 -0
  4. package/dist/chunk-5CXNMTIN.js.map +1 -0
  5. package/dist/chunk-B5ZTF5MZ.js +203 -0
  6. package/dist/chunk-B5ZTF5MZ.js.map +1 -0
  7. package/dist/chunk-EDNWBEKV.js +51 -0
  8. package/dist/chunk-EDNWBEKV.js.map +1 -0
  9. package/dist/chunk-ID7BFTID.js +248 -0
  10. package/dist/chunk-ID7BFTID.js.map +1 -0
  11. package/dist/chunk-IYBHXVCH.js +181 -0
  12. package/dist/chunk-IYBHXVCH.js.map +1 -0
  13. package/dist/chunk-KQZEF7PS.js +71 -0
  14. package/dist/chunk-KQZEF7PS.js.map +1 -0
  15. package/dist/chunk-P3GSYR7O.js +889 -0
  16. package/dist/chunk-P3GSYR7O.js.map +1 -0
  17. package/dist/chunk-PKSRYDN4.js +168 -0
  18. package/dist/chunk-PKSRYDN4.js.map +1 -0
  19. package/dist/chunk-SFM7ZMG2.js +104 -0
  20. package/dist/chunk-SFM7ZMG2.js.map +1 -0
  21. package/dist/chunk-TLQQZJUR.js +126 -0
  22. package/dist/chunk-TLQQZJUR.js.map +1 -0
  23. package/dist/chunk-UE7CDYEN.js +59 -0
  24. package/dist/chunk-UE7CDYEN.js.map +1 -0
  25. package/dist/chunk-UG7YS3D5.js +198 -0
  26. package/dist/chunk-UG7YS3D5.js.map +1 -0
  27. package/dist/components/advanced-search-bar/index.d.ts +308 -0
  28. package/dist/components/advanced-search-bar/index.js +34 -0
  29. package/dist/components/advanced-search-bar/index.js.map +1 -0
  30. package/dist/components/calendar/index.d.ts +20 -0
  31. package/dist/components/calendar/index.js +11 -0
  32. package/dist/components/calendar/index.js.map +1 -0
  33. package/dist/components/carousel/index.d.ts +40 -0
  34. package/dist/components/carousel/index.js +17 -0
  35. package/dist/components/carousel/index.js.map +1 -0
  36. package/dist/components/chart/index.d.ts +59 -0
  37. package/dist/components/chart/index.js +21 -0
  38. package/dist/components/chart/index.js.map +1 -0
  39. package/dist/components/combobox/index.d.ts +33 -0
  40. package/dist/components/combobox/index.js +10 -0
  41. package/dist/components/combobox/index.js.map +1 -0
  42. package/dist/components/command/index.d.ts +33 -0
  43. package/dist/components/command/index.js +25 -0
  44. package/dist/components/command/index.js.map +1 -0
  45. package/dist/components/data-table/index.d.ts +17 -0
  46. package/dist/components/data-table/index.js +9 -0
  47. package/dist/components/data-table/index.js.map +1 -0
  48. package/dist/components/date-picker/index.d.ts +17 -0
  49. package/dist/components/date-picker/index.js +9 -0
  50. package/dist/components/date-picker/index.js.map +1 -0
  51. package/dist/components/form/index.d.ts +37 -0
  52. package/dist/components/form/index.js +23 -0
  53. package/dist/components/form/index.js.map +1 -0
  54. package/dist/components/input-otp/index.d.ts +30 -0
  55. package/dist/components/input-otp/index.js +15 -0
  56. package/dist/components/input-otp/index.js.map +1 -0
  57. package/dist/components/pagination/index.d.ts +26 -0
  58. package/dist/components/pagination/index.js +20 -0
  59. package/dist/components/pagination/index.js.map +1 -0
  60. package/dist/components/search-bar/index.d.ts +17 -0
  61. package/dist/components/search-bar/index.js +9 -0
  62. package/dist/components/search-bar/index.js.map +1 -0
  63. package/dist/components/sidebar/index.d.ts +70 -0
  64. package/dist/components/sidebar/index.js +652 -0
  65. package/dist/components/sidebar/index.js.map +1 -0
  66. package/dist/components/theme-toggle/index.d.ts +20 -0
  67. package/dist/components/theme-toggle/index.js +9 -0
  68. package/dist/components/theme-toggle/index.js.map +1 -0
  69. package/dist/index.d.ts +27 -582
  70. package/dist/index.js +74 -2280
  71. package/dist/index.js.map +1 -1
  72. package/package.json +15 -8
  73. package/.turbo/turbo-build.log +0 -17
  74. package/.turbo/turbo-type-check.log +0 -4
  75. package/CHANGELOG.md +0 -351
  76. package/src/components/advanced-search-bar/config.ts +0 -223
  77. package/src/components/advanced-search-bar/index.tsx +0 -1415
  78. package/src/components/calendar/config.ts +0 -51
  79. package/src/components/calendar/index.tsx +0 -225
  80. package/src/components/carousel/config.ts +0 -28
  81. package/src/components/carousel/index.tsx +0 -258
  82. package/src/components/chart/config.ts +0 -28
  83. package/src/components/chart/index.tsx +0 -365
  84. package/src/components/combobox/config.ts +0 -28
  85. package/src/components/combobox/index.tsx +0 -101
  86. package/src/components/command/config.ts +0 -804
  87. package/src/components/command/index.tsx +0 -195
  88. package/src/components/data-table/config.ts +0 -28
  89. package/src/components/data-table/index.tsx +0 -124
  90. package/src/components/date-picker/config.ts +0 -55
  91. package/src/components/date-picker/index.tsx +0 -207
  92. package/src/components/form/config.ts +0 -21
  93. package/src/components/form/index.tsx +0 -150
  94. package/src/components/input-otp/config.ts +0 -28
  95. package/src/components/input-otp/index.tsx +0 -92
  96. package/src/components/pagination/config.ts +0 -367
  97. package/src/components/pagination/index.tsx +0 -135
  98. package/src/components/search-bar/config.ts +0 -58
  99. package/src/components/search-bar/index.tsx +0 -70
  100. package/src/components/sidebar/config.ts +0 -29
  101. package/src/components/sidebar/index.tsx +0 -723
  102. package/src/components/theme-toggle/config.ts +0 -58
  103. package/src/components/theme-toggle/index.tsx +0 -35
  104. package/src/index.ts +0 -82
  105. package/tsconfig.json +0 -12
  106. package/tsconfig.lint.json +0 -8
  107. package/tsup.config.ts +0 -11
@@ -0,0 +1,889 @@
1
+ 'use client';
2
+
3
+ // src/components/advanced-search-bar/index.tsx
4
+ import {
5
+ SearchContext,
6
+ useAdvancedSearch
7
+ } from "@foundrykit/hooks";
8
+ import {
9
+ Badge,
10
+ Button,
11
+ Input,
12
+ ScrollArea,
13
+ Separator
14
+ } from "@foundrykit/primitives";
15
+ import { cn } from "@foundrykit/utils";
16
+ import { Slot } from "@radix-ui/react-slot";
17
+ import { cva } from "class-variance-authority";
18
+ import { ChevronDown, Search, X } from "lucide-react";
19
+ import * as React from "react";
20
+ import { jsx, jsxs } from "react/jsx-runtime";
21
+ function AdvancedSearchProvider({
22
+ children,
23
+ onSearch,
24
+ onResultSelect,
25
+ debounceMs = 300,
26
+ minQueryLength = 1,
27
+ emptyStateBehaviour = "show-empty-message",
28
+ initialResults = [],
29
+ styles = {
30
+ results: {
31
+ maxHeight: "24rem"
32
+ },
33
+ width: "100%"
34
+ }
35
+ }) {
36
+ const inputId = React.useId();
37
+ const resultsId = React.useId();
38
+ const [query, setQuery] = React.useState("");
39
+ const [isOpen, setIsOpen] = React.useState(false);
40
+ const [results, setResults] = React.useState(initialResults);
41
+ const [isLoading, setIsLoading] = React.useState(false);
42
+ const [activeIndex, setActiveIndex] = React.useState(-1);
43
+ const timeoutRef = React.useRef(null);
44
+ const requestIdRef = React.useRef(0);
45
+ React.useEffect(() => {
46
+ return () => {
47
+ if (timeoutRef.current) {
48
+ clearTimeout(timeoutRef.current);
49
+ }
50
+ };
51
+ }, []);
52
+ const handleSearch = React.useCallback(
53
+ (searchQuery) => {
54
+ if (timeoutRef.current) {
55
+ clearTimeout(timeoutRef.current);
56
+ }
57
+ setActiveIndex(-1);
58
+ const trimmedQuery = searchQuery.trim();
59
+ const isEmptyQuery = trimmedQuery.length === 0;
60
+ const isTooShort = trimmedQuery.length < minQueryLength;
61
+ if (isEmptyQuery || isTooShort || !onSearch) {
62
+ requestIdRef.current += 1;
63
+ setIsLoading(false);
64
+ setResults(
65
+ emptyStateBehaviour === "show-all-results" && (isEmptyQuery || isTooShort) ? initialResults : []
66
+ );
67
+ return;
68
+ }
69
+ const requestId = requestIdRef.current + 1;
70
+ requestIdRef.current = requestId;
71
+ timeoutRef.current = setTimeout(async () => {
72
+ setIsLoading(true);
73
+ try {
74
+ const searchResults = await onSearch(trimmedQuery);
75
+ if (requestIdRef.current === requestId) {
76
+ setResults(searchResults);
77
+ }
78
+ } catch (error) {
79
+ if (requestIdRef.current === requestId) {
80
+ console.error("Search error:", error);
81
+ setResults([]);
82
+ }
83
+ } finally {
84
+ if (requestIdRef.current === requestId) {
85
+ setIsLoading(false);
86
+ }
87
+ }
88
+ }, debounceMs);
89
+ },
90
+ [debounceMs, emptyStateBehaviour, initialResults, minQueryLength, onSearch]
91
+ );
92
+ const handleResultSelect = React.useCallback(
93
+ (result) => {
94
+ onResultSelect?.(result);
95
+ setQuery(result.title);
96
+ setActiveIndex(-1);
97
+ setIsOpen(false);
98
+ },
99
+ [onResultSelect]
100
+ );
101
+ const value = React.useMemo(
102
+ () => ({
103
+ query,
104
+ setQuery,
105
+ isOpen,
106
+ setIsOpen,
107
+ inputId,
108
+ resultsId,
109
+ activeIndex,
110
+ setActiveIndex,
111
+ results,
112
+ setResults,
113
+ isLoading,
114
+ setIsLoading,
115
+ onSearch: handleSearch,
116
+ onResultSelect: handleResultSelect,
117
+ emptyStateBehaviour,
118
+ minQueryLength
119
+ }),
120
+ [
121
+ query,
122
+ isOpen,
123
+ inputId,
124
+ resultsId,
125
+ activeIndex,
126
+ results,
127
+ isLoading,
128
+ handleSearch,
129
+ handleResultSelect,
130
+ emptyStateBehaviour,
131
+ minQueryLength
132
+ ]
133
+ );
134
+ return /* @__PURE__ */ jsx(SearchContext.Provider, { value, children: /* @__PURE__ */ jsx(
135
+ "div",
136
+ {
137
+ style: {
138
+ "--results-max-height": styles.results?.maxHeight ?? "24rem",
139
+ width: styles.width
140
+ },
141
+ children
142
+ }
143
+ ) });
144
+ }
145
+ var searchInputWrapperVariants = cva("relative flex w-full items-center", {
146
+ variants: {
147
+ size: {
148
+ sm: "h-8",
149
+ md: "h-10",
150
+ lg: "h-12",
151
+ xl: "h-14"
152
+ },
153
+ variant: {
154
+ default: "border-input bg-background border",
155
+ ghost: "bg-transparent",
156
+ filled: "bg-muted"
157
+ }
158
+ },
159
+ defaultVariants: {
160
+ size: "md",
161
+ variant: "default"
162
+ }
163
+ });
164
+ var searchResultsVariants = cva("w-full", {
165
+ variants: {
166
+ size: {
167
+ sm: "max-w-sm",
168
+ md: "max-w-md",
169
+ lg: "max-w-lg",
170
+ xl: "max-w-xl",
171
+ "2xl": "max-w-2xl",
172
+ full: "max-w-full"
173
+ }
174
+ },
175
+ defaultVariants: {
176
+ size: "lg"
177
+ }
178
+ });
179
+ var SearchInput = React.forwardRef(
180
+ ({
181
+ className,
182
+ size,
183
+ variant,
184
+ placeholder = "Search...",
185
+ showSearchIcon = true,
186
+ showClearButton = true,
187
+ onClear,
188
+ asChild = false,
189
+ ...props
190
+ }, ref) => {
191
+ const {
192
+ query,
193
+ setQuery,
194
+ onSearch,
195
+ onResultSelect,
196
+ results,
197
+ isOpen,
198
+ setIsOpen,
199
+ inputId,
200
+ resultsId,
201
+ activeIndex,
202
+ setActiveIndex,
203
+ emptyStateBehaviour,
204
+ minQueryLength
205
+ } = useAdvancedSearch();
206
+ const Comp = asChild ? Slot : "div";
207
+ const handleChange = (e) => {
208
+ const value = e.target.value;
209
+ setQuery(value);
210
+ if (emptyStateBehaviour === "hide-until-min-chars") {
211
+ setIsOpen(value.length >= minQueryLength);
212
+ } else {
213
+ setIsOpen(true);
214
+ }
215
+ setTimeout(() => {
216
+ onSearch(value);
217
+ }, 0);
218
+ props.onChange?.(e);
219
+ };
220
+ const handleFocus = (e) => {
221
+ if (emptyStateBehaviour === "hide-until-min-chars") {
222
+ setIsOpen(query.length >= minQueryLength);
223
+ } else {
224
+ setIsOpen(true);
225
+ }
226
+ props.onFocus?.(e);
227
+ };
228
+ const handleClear = () => {
229
+ setQuery("");
230
+ setActiveIndex(-1);
231
+ setTimeout(() => {
232
+ onSearch("");
233
+ }, 0);
234
+ onClear?.();
235
+ };
236
+ const handleKeyDown = (e) => {
237
+ props.onKeyDown?.(e);
238
+ if (e.defaultPrevented) return;
239
+ if (e.key === "Escape") {
240
+ setIsOpen(false);
241
+ setActiveIndex(-1);
242
+ return;
243
+ }
244
+ if (e.key === "ArrowDown") {
245
+ e.preventDefault();
246
+ setIsOpen(true);
247
+ setActiveIndex(
248
+ results.length ? (activeIndex + 1) % results.length : -1
249
+ );
250
+ return;
251
+ }
252
+ if (e.key === "ArrowUp") {
253
+ e.preventDefault();
254
+ setIsOpen(true);
255
+ setActiveIndex(
256
+ results.length ? activeIndex <= 0 ? results.length - 1 : activeIndex - 1 : -1
257
+ );
258
+ return;
259
+ }
260
+ if (e.key === "Home") {
261
+ if (!results.length) return;
262
+ e.preventDefault();
263
+ setActiveIndex(0);
264
+ return;
265
+ }
266
+ if (e.key === "End") {
267
+ if (!results.length) return;
268
+ e.preventDefault();
269
+ setActiveIndex(results.length - 1);
270
+ return;
271
+ }
272
+ if (e.key === "Enter" && activeIndex >= 0 && results[activeIndex]) {
273
+ e.preventDefault();
274
+ onResultSelect(results[activeIndex]);
275
+ }
276
+ };
277
+ return /* @__PURE__ */ jsxs(
278
+ Comp,
279
+ {
280
+ className: cn(
281
+ searchInputWrapperVariants({ size, variant }),
282
+ "rounded-md",
283
+ className
284
+ ),
285
+ onClick: (e) => {
286
+ if (e.target !== e.currentTarget) return;
287
+ const input = e.currentTarget.querySelector("input");
288
+ input?.focus();
289
+ },
290
+ children: [
291
+ showSearchIcon && /* @__PURE__ */ jsx(Search, { className: "text-muted-foreground absolute left-3 h-4 w-4" }),
292
+ /* @__PURE__ */ jsx(
293
+ Input,
294
+ {
295
+ ref,
296
+ ...props,
297
+ id: inputId,
298
+ type: "search",
299
+ role: "combobox",
300
+ "aria-label": "Search",
301
+ "aria-autocomplete": "list",
302
+ "aria-expanded": isOpen,
303
+ "aria-controls": resultsId,
304
+ "aria-activedescendant": activeIndex >= 0 && results[activeIndex] ? `${resultsId}-option-${results[activeIndex].id}` : void 0,
305
+ placeholder,
306
+ value: query,
307
+ onChange: handleChange,
308
+ onFocus: handleFocus,
309
+ onKeyDown: handleKeyDown,
310
+ className: cn(
311
+ "border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0",
312
+ showSearchIcon && "pl-10",
313
+ showClearButton && query && "pr-10"
314
+ ),
315
+ size: void 0
316
+ }
317
+ ),
318
+ showClearButton && query && /* @__PURE__ */ jsx(
319
+ Button,
320
+ {
321
+ type: "button",
322
+ variant: "ghost",
323
+ size: "sm",
324
+ "aria-label": "Clear search",
325
+ className: "absolute right-1 h-6 w-6 p-0",
326
+ onClick: handleClear,
327
+ children: /* @__PURE__ */ jsx(X, { className: "h-3 w-3" })
328
+ }
329
+ )
330
+ ]
331
+ }
332
+ );
333
+ }
334
+ );
335
+ SearchInput.displayName = "SearchInput";
336
+ var SearchTrigger = React.forwardRef(({ className, asChild = false, children, onClick, ...props }, ref) => {
337
+ const { isOpen, setIsOpen, resultsId } = useAdvancedSearch();
338
+ const Comp = asChild ? Slot : Button;
339
+ return /* @__PURE__ */ jsx(
340
+ Comp,
341
+ {
342
+ ref,
343
+ ...props,
344
+ type: "button",
345
+ "aria-expanded": isOpen,
346
+ "aria-controls": resultsId,
347
+ className: cn(className),
348
+ onClick: (event) => {
349
+ onClick?.(event);
350
+ if (!event.defaultPrevented) {
351
+ setIsOpen(!isOpen);
352
+ }
353
+ },
354
+ children
355
+ }
356
+ );
357
+ });
358
+ SearchTrigger.displayName = "SearchTrigger";
359
+ var SearchResults = React.forwardRef(
360
+ ({
361
+ className,
362
+ size = "full",
363
+ sections,
364
+ showEmptyState = true,
365
+ emptyStateMessage = "No results found",
366
+ showLoadingState = true,
367
+ loadingBehaviour = "replace-results",
368
+ loadingState,
369
+ loadingMessage = "Searching...",
370
+ ...props
371
+ }, ref) => {
372
+ const {
373
+ results,
374
+ isLoading,
375
+ query,
376
+ onResultSelect,
377
+ resultsId,
378
+ activeIndex,
379
+ emptyStateBehaviour,
380
+ minQueryLength
381
+ } = useAdvancedSearch();
382
+ const shouldReplaceResultsWithLoading = loadingBehaviour === "replace-results" || results.length === 0;
383
+ if (isLoading && showLoadingState && shouldReplaceResultsWithLoading) {
384
+ return /* @__PURE__ */ jsx(
385
+ "div",
386
+ {
387
+ ref,
388
+ id: resultsId,
389
+ className: cn(
390
+ searchResultsVariants({ size }),
391
+ "text-muted-foreground p-4 text-center",
392
+ className
393
+ ),
394
+ role: "status",
395
+ "aria-live": "polite",
396
+ ...props,
397
+ children: loadingState ?? loadingMessage
398
+ }
399
+ );
400
+ }
401
+ const shouldShowEmptyState = results.length === 0 || !query && emptyStateBehaviour !== "show-all-results";
402
+ if (shouldShowEmptyState) {
403
+ if (!showEmptyState) return null;
404
+ if (emptyStateBehaviour === "hide-until-min-chars" && query.length < minQueryLength) {
405
+ return null;
406
+ }
407
+ return /* @__PURE__ */ jsx(
408
+ "div",
409
+ {
410
+ ref,
411
+ id: resultsId,
412
+ className: cn(
413
+ searchResultsVariants({ size }),
414
+ "text-muted-foreground p-4 text-center",
415
+ className
416
+ ),
417
+ role: "status",
418
+ "aria-live": "polite",
419
+ ...props,
420
+ children: emptyStateMessage
421
+ }
422
+ );
423
+ }
424
+ const displaySections = sections || [
425
+ {
426
+ id: "results",
427
+ title: "Results",
428
+ results
429
+ }
430
+ ];
431
+ return /* @__PURE__ */ jsx(
432
+ "div",
433
+ {
434
+ ref,
435
+ id: resultsId,
436
+ className: cn(
437
+ searchResultsVariants({ size }),
438
+ "max-h-[var(--results-max-height)]",
439
+ className
440
+ ),
441
+ role: "listbox",
442
+ "aria-label": "Search results",
443
+ "aria-busy": isLoading || void 0,
444
+ ...props,
445
+ children: /* @__PURE__ */ jsx(ScrollArea, { className: "h-fit max-h-[var(--results-max-height)] *:max-h-[var(--results-max-height)]", children: /* @__PURE__ */ jsx("div", { className: "space-y-4 p-4", children: displaySections.map((section, index) => /* @__PURE__ */ jsxs("div", { children: [
446
+ index > 0 && /* @__PURE__ */ jsx(Separator, { className: "my-4" }),
447
+ /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
448
+ /* @__PURE__ */ jsx("h3", { className: "text-muted-foreground text-sm font-semibold tracking-wide uppercase", children: section.title }),
449
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
450
+ section.results.map((result) => {
451
+ const resultIndex = results.findIndex(
452
+ (item) => item.id === result.id
453
+ );
454
+ return /* @__PURE__ */ jsx(
455
+ SearchResultItem,
456
+ {
457
+ id: `${resultsId}-option-${result.id}`,
458
+ result,
459
+ isActive: resultIndex === activeIndex,
460
+ onClick: () => onResultSelect(result)
461
+ },
462
+ result.id
463
+ );
464
+ }),
465
+ section.showMore && section.onShowMore && /* @__PURE__ */ jsxs(
466
+ Button,
467
+ {
468
+ variant: "ghost",
469
+ size: "sm",
470
+ className: "text-muted-foreground w-full justify-start",
471
+ onClick: section.onShowMore,
472
+ children: [
473
+ "Show more",
474
+ /* @__PURE__ */ jsx(ChevronDown, { className: "ml-2 h-3 w-3" })
475
+ ]
476
+ }
477
+ )
478
+ ] })
479
+ ] })
480
+ ] }, section.id)) }) })
481
+ }
482
+ );
483
+ }
484
+ );
485
+ SearchResults.displayName = "SearchResults";
486
+ var SearchResultItem = ({
487
+ id,
488
+ result,
489
+ isActive,
490
+ onClick
491
+ }) => {
492
+ const itemClasses = cn(
493
+ "hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full rounded-md text-left transition-colors outline-none focus-visible:ring-[3px]",
494
+ isActive && "bg-accent text-accent-foreground"
495
+ );
496
+ if (result.type === "category") {
497
+ return /* @__PURE__ */ jsx(
498
+ "div",
499
+ {
500
+ id,
501
+ role: "presentation",
502
+ className: "text-muted-foreground p-2 text-sm font-medium",
503
+ children: result.title
504
+ }
505
+ );
506
+ }
507
+ if (result.type === "suggestion") {
508
+ return /* @__PURE__ */ jsx(
509
+ "button",
510
+ {
511
+ id,
512
+ type: "button",
513
+ role: "option",
514
+ "aria-selected": isActive,
515
+ className: cn(itemClasses, "p-2 text-sm"),
516
+ onClick,
517
+ children: result.title
518
+ }
519
+ );
520
+ }
521
+ const content = /* @__PURE__ */ jsxs("div", { className: "flex gap-3 p-3", children: [
522
+ result.image && /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx(
523
+ "img",
524
+ {
525
+ src: result.image,
526
+ alt: result.title,
527
+ className: "h-12 w-12 rounded-md object-cover",
528
+ loading: "lazy"
529
+ }
530
+ ) }),
531
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
532
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
533
+ /* @__PURE__ */ jsx("h4", { className: "truncate text-sm font-semibold", children: result.title }),
534
+ result.badge && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
535
+ ] }),
536
+ result.description && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
537
+ ] })
538
+ ] });
539
+ if (result.href) {
540
+ return /* @__PURE__ */ jsx(
541
+ "a",
542
+ {
543
+ id,
544
+ role: "option",
545
+ "aria-selected": isActive,
546
+ href: result.href,
547
+ className: cn(itemClasses, "block"),
548
+ onClick,
549
+ children: content
550
+ }
551
+ );
552
+ }
553
+ return /* @__PURE__ */ jsx(
554
+ "button",
555
+ {
556
+ id,
557
+ type: "button",
558
+ role: "option",
559
+ "aria-selected": isActive,
560
+ className: itemClasses,
561
+ onClick,
562
+ children: content
563
+ }
564
+ );
565
+ };
566
+ var AdvancedSearchBar = React.forwardRef(
567
+ ({
568
+ className,
569
+ children,
570
+ open,
571
+ onOpenChange,
572
+ resultsMode = "popover",
573
+ triggerClassName,
574
+ resultsClassName,
575
+ ...props
576
+ }, ref) => {
577
+ const { isOpen, setIsOpen, setActiveIndex } = useAdvancedSearch();
578
+ const rootRef = React.useRef(null);
579
+ const previousOpenRef = React.useRef(isOpen);
580
+ const isControlled = open !== void 0;
581
+ const isOpenState = isControlled ? open : isOpen;
582
+ React.useEffect(() => {
583
+ if (previousOpenRef.current !== isOpen) {
584
+ previousOpenRef.current = isOpen;
585
+ onOpenChange?.(isOpen);
586
+ }
587
+ }, [isOpen, onOpenChange]);
588
+ React.useEffect(() => {
589
+ if (!isOpenState) return;
590
+ const handlePointerDown = (event) => {
591
+ if (!rootRef.current?.contains(event.target)) {
592
+ setActiveIndex(-1);
593
+ setIsOpen(false);
594
+ onOpenChange?.(false);
595
+ }
596
+ };
597
+ const handleKeyDown = (event) => {
598
+ if (event.key !== "Escape") return;
599
+ setActiveIndex(-1);
600
+ setIsOpen(false);
601
+ onOpenChange?.(false);
602
+ const focusTarget = rootRef.current?.querySelector(
603
+ 'input, button, [href], [tabindex]:not([tabindex="-1"])'
604
+ );
605
+ focusTarget?.focus();
606
+ };
607
+ document.addEventListener("pointerdown", handlePointerDown);
608
+ document.addEventListener("keydown", handleKeyDown);
609
+ return () => {
610
+ document.removeEventListener("pointerdown", handlePointerDown);
611
+ document.removeEventListener("keydown", handleKeyDown);
612
+ };
613
+ }, [isOpenState, onOpenChange, setActiveIndex, setIsOpen]);
614
+ const setRefs = React.useCallback(
615
+ (node) => {
616
+ rootRef.current = node;
617
+ if (typeof ref === "function") {
618
+ ref(node);
619
+ } else if (ref) {
620
+ ref.current = node;
621
+ }
622
+ },
623
+ [ref]
624
+ );
625
+ const isSearchResultsChild = (child) => {
626
+ if (!React.isValidElement(child)) return false;
627
+ const childType = child.type;
628
+ return child.type === SearchResults || childType.displayName === SearchResults.displayName;
629
+ };
630
+ const childrenArray = React.Children.toArray(children);
631
+ const resultsChildren = childrenArray.filter(isSearchResultsChild);
632
+ const triggerChildren = childrenArray.filter(
633
+ (child) => !isSearchResultsChild(child)
634
+ );
635
+ const triggerElement = triggerChildren.length ? triggerChildren : /* @__PURE__ */ jsx(SearchInput, {});
636
+ const resultsElement = resultsChildren.length ? resultsChildren : /* @__PURE__ */ jsx(SearchResults, {});
637
+ const resultsPanel = isOpenState ? resultsMode === "inline" ? /* @__PURE__ */ jsx("div", { className: cn("w-full overflow-hidden", resultsClassName), children: resultsElement }) : /* @__PURE__ */ jsx(
638
+ "div",
639
+ {
640
+ className: cn(
641
+ "bg-popover text-popover-foreground border-border absolute top-full left-0 z-50 mt-1 max-h-[min(var(--results-max-height),calc(100vh-8rem))] w-full overflow-hidden rounded-md border shadow-lg",
642
+ resultsClassName
643
+ ),
644
+ children: resultsElement
645
+ }
646
+ ) : null;
647
+ return /* @__PURE__ */ jsxs(
648
+ "div",
649
+ {
650
+ ref: setRefs,
651
+ "data-state": isOpenState ? "open" : "closed",
652
+ className: cn("relative w-full", className),
653
+ ...props,
654
+ children: [
655
+ /* @__PURE__ */ jsx("div", { className: cn("w-full", triggerClassName), children: triggerElement }),
656
+ resultsPanel
657
+ ]
658
+ }
659
+ );
660
+ }
661
+ );
662
+ AdvancedSearchBar.displayName = "AdvancedSearchBar";
663
+ var SearchSection = React.forwardRef(({ className, title, showMore, onShowMore, children, ...props }, ref) => {
664
+ return /* @__PURE__ */ jsxs("div", { ref, className: cn("space-y-2", className), ...props, children: [
665
+ title && /* @__PURE__ */ jsx("h3", { className: "text-muted-foreground text-sm font-semibold tracking-wide uppercase", children: title }),
666
+ /* @__PURE__ */ jsxs("div", { className: "space-y-1", children: [
667
+ children,
668
+ showMore && onShowMore && /* @__PURE__ */ jsxs(
669
+ Button,
670
+ {
671
+ variant: "ghost",
672
+ size: "sm",
673
+ className: "text-muted-foreground w-full justify-start",
674
+ onClick: onShowMore,
675
+ children: [
676
+ "Show more",
677
+ /* @__PURE__ */ jsx(ChevronDown, { className: "ml-2 h-3 w-3" })
678
+ ]
679
+ }
680
+ )
681
+ ] })
682
+ ] });
683
+ });
684
+ SearchSection.displayName = "SearchSection";
685
+ var SearchItem = React.forwardRef(
686
+ ({ className, result, onClick, children, ...props }, ref) => {
687
+ const { onResultSelect } = useAdvancedSearch();
688
+ const handleClick = () => {
689
+ if (result) {
690
+ onResultSelect(result);
691
+ }
692
+ onClick?.();
693
+ };
694
+ const handleKeyDown = (event) => {
695
+ if (event.key === "Enter" || event.key === " ") {
696
+ event.preventDefault();
697
+ handleClick();
698
+ }
699
+ };
700
+ if (children) {
701
+ return /* @__PURE__ */ jsx(
702
+ "div",
703
+ {
704
+ ref,
705
+ role: "button",
706
+ tabIndex: 0,
707
+ className: cn("cursor-pointer outline-none", className),
708
+ onClick: handleClick,
709
+ onKeyDown: handleKeyDown,
710
+ ...props,
711
+ children
712
+ }
713
+ );
714
+ }
715
+ if (!result) return null;
716
+ if (result.type === "category") {
717
+ return /* @__PURE__ */ jsx(
718
+ "div",
719
+ {
720
+ ref,
721
+ role: "presentation",
722
+ className: cn(
723
+ "text-muted-foreground p-2 text-sm font-medium",
724
+ className
725
+ ),
726
+ ...props,
727
+ children: result.title
728
+ }
729
+ );
730
+ }
731
+ if (result.type === "suggestion") {
732
+ return /* @__PURE__ */ jsx(
733
+ Button,
734
+ {
735
+ ref,
736
+ variant: "ghost",
737
+ size: "sm",
738
+ className: cn("h-auto w-full justify-start p-2", className),
739
+ onClick: handleClick,
740
+ ...props,
741
+ children: /* @__PURE__ */ jsx("span", { className: "text-sm", children: result.title })
742
+ }
743
+ );
744
+ }
745
+ return /* @__PURE__ */ jsx(
746
+ "button",
747
+ {
748
+ ref,
749
+ type: "button",
750
+ className: cn(
751
+ "hover:bg-accent hover:text-accent-foreground focus-visible:border-ring focus-visible:ring-ring/50 w-full cursor-pointer rounded-md text-left transition-colors outline-none focus-visible:ring-[3px]",
752
+ className
753
+ ),
754
+ onClick: handleClick,
755
+ ...props,
756
+ children: /* @__PURE__ */ jsxs("div", { className: "flex gap-3 p-3", children: [
757
+ result.image && /* @__PURE__ */ jsx("div", { className: "flex-shrink-0", children: /* @__PURE__ */ jsx(
758
+ "img",
759
+ {
760
+ src: result.image,
761
+ alt: result.title,
762
+ className: "h-12 w-12 rounded-md object-cover",
763
+ loading: "lazy"
764
+ }
765
+ ) }),
766
+ /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
767
+ /* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-2", children: [
768
+ /* @__PURE__ */ jsx("h4", { className: "truncate text-sm font-semibold", children: result.title }),
769
+ result.badge && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: result.badge })
770
+ ] }),
771
+ result.description && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1 line-clamp-2 text-xs", children: result.description })
772
+ ] })
773
+ ] })
774
+ }
775
+ );
776
+ }
777
+ );
778
+ SearchItem.displayName = "SearchItem";
779
+ function AdvancedSearchBarWrapper(props = {}) {
780
+ const {
781
+ minQueryLength = 1,
782
+ emptyStateBehaviour = "show-all-results",
783
+ size = "md",
784
+ variant = "default",
785
+ useCustomTrigger = false
786
+ } = props;
787
+ const mockSearchResults = [
788
+ {
789
+ id: "1",
790
+ title: "Beach Holidays",
791
+ description: "Relaxing beach destinations",
792
+ type: "result",
793
+ badge: "Popular"
794
+ },
795
+ {
796
+ id: "2",
797
+ title: "Adventure Trips",
798
+ description: "Exciting adventure experiences",
799
+ type: "result",
800
+ badge: "New"
801
+ },
802
+ {
803
+ id: "3",
804
+ title: "City Breaks",
805
+ description: "Urban exploration trips",
806
+ type: "result"
807
+ },
808
+ {
809
+ id: "4",
810
+ title: "Mountain Retreats",
811
+ description: "Peaceful mountain getaways",
812
+ type: "result"
813
+ },
814
+ {
815
+ id: "5",
816
+ title: "Cultural Tours",
817
+ description: "Explore local culture and history",
818
+ type: "result"
819
+ }
820
+ ];
821
+ const handleSearch = async (query) => {
822
+ await new Promise((resolve) => setTimeout(resolve, 300));
823
+ if (!query.trim()) {
824
+ return emptyStateBehaviour === "show-all-results" ? mockSearchResults : [];
825
+ }
826
+ return mockSearchResults.filter(
827
+ (result) => result.title.toLowerCase().includes(query.toLowerCase()) || result.description.toLowerCase().includes(query.toLowerCase())
828
+ );
829
+ };
830
+ const handleResultSelect = (result) => {
831
+ console.log("Selected result:", result);
832
+ };
833
+ const getPlaceholder = () => {
834
+ if (emptyStateBehaviour === "hide-until-min-chars") {
835
+ return `Type at least ${minQueryLength} characters...`;
836
+ }
837
+ return "Search destinations...";
838
+ };
839
+ return /* @__PURE__ */ jsx(
840
+ AdvancedSearchProvider,
841
+ {
842
+ onSearch: handleSearch,
843
+ onResultSelect: handleResultSelect,
844
+ debounceMs: 300,
845
+ minQueryLength,
846
+ emptyStateBehaviour,
847
+ initialResults: emptyStateBehaviour === "show-all-results" ? mockSearchResults : [],
848
+ children: /* @__PURE__ */ jsxs(AdvancedSearchBar, { children: [
849
+ useCustomTrigger ? /* @__PURE__ */ jsx(SearchTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "outline", className: "w-full justify-start", children: [
850
+ /* @__PURE__ */ jsx(Search, { className: "mr-2 h-4 w-4" }),
851
+ "Click to search..."
852
+ ] }) }) : /* @__PURE__ */ jsx(
853
+ SearchInput,
854
+ {
855
+ placeholder: getPlaceholder(),
856
+ size,
857
+ variant,
858
+ showSearchIcon: true,
859
+ showClearButton: true
860
+ }
861
+ ),
862
+ /* @__PURE__ */ jsx(
863
+ SearchResults,
864
+ {
865
+ size: size === "sm" ? "sm" : size === "lg" ? "lg" : "md",
866
+ showEmptyState: true,
867
+ emptyStateMessage: "No destinations found.",
868
+ showLoadingState: true,
869
+ loadingMessage: "Searching destinations..."
870
+ }
871
+ )
872
+ ] })
873
+ }
874
+ );
875
+ }
876
+
877
+ export {
878
+ AdvancedSearchProvider,
879
+ searchInputWrapperVariants,
880
+ searchResultsVariants,
881
+ SearchInput,
882
+ SearchTrigger,
883
+ SearchResults,
884
+ AdvancedSearchBar,
885
+ SearchSection,
886
+ SearchItem,
887
+ AdvancedSearchBarWrapper
888
+ };
889
+ //# sourceMappingURL=chunk-P3GSYR7O.js.map