@avenue-ticketing/ui 0.5.0 → 0.7.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.
@@ -82,6 +82,22 @@ function resolveDropdownMobileSheet(mobileOptions) {
82
82
  };
83
83
  }
84
84
  var DROPDOWN_SUB_CONTENT_ATTR = "data-dropdown-sub-content";
85
+ var DROPDOWN_PANEL_SHADOW = "shadow-[0_12px_32px_-8px_rgba(0,0,0,0.18),0_2px_6px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_12px_32px_-8px_rgba(0,0,0,0.55),0_2px_6px_-2px_rgba(0,0,0,0.35)]";
86
+ var DROPDOWN_PANEL_SCROLL = "[&_*]:[scrollbar-width:none] [&_*::-webkit-scrollbar]:hidden [&_*]:overscroll-contain";
87
+ function preventMenuWheelChain(menu, e) {
88
+ let el = e.target;
89
+ while (el && menu.contains(el)) {
90
+ const oy = getComputedStyle(el).overflowY;
91
+ if ((oy === "auto" || oy === "scroll") && el.scrollHeight > el.clientHeight) {
92
+ const atTop = el.scrollTop <= 0;
93
+ const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight;
94
+ if (e.deltaY < 0 && !atTop || e.deltaY > 0 && !atBottom) return;
95
+ break;
96
+ }
97
+ el = el.parentElement;
98
+ }
99
+ e.preventDefault();
100
+ }
85
101
  var DROPDOWN_SHEET_MENU_TEXT = "max-[1024px]:text-base";
86
102
  var DROPDOWN_SHEET_MENU_SHORTCUT = "max-[1024px]:text-sm";
87
103
  var DROPDOWN_CONTENT_ORIGIN = {
@@ -165,10 +181,12 @@ function computePos(trigger, menu, side, align, offset, pad) {
165
181
  return { top, left, side: effectiveSide };
166
182
  }
167
183
  function useIsMobile(breakpoint = 1025) {
168
- const [isMobile, setIsMobile] = useState(false);
184
+ const [isMobile, setIsMobile] = useState(() => {
185
+ if (typeof window === "undefined") return false;
186
+ return window.matchMedia(`(max-width: ${breakpoint - 1}px)`).matches;
187
+ });
169
188
  useEffect(() => {
170
189
  const mq = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
171
- setIsMobile(mq.matches);
172
190
  const handler = (e) => setIsMobile(e.matches);
173
191
  mq.addEventListener("change", handler);
174
192
  return () => mq.removeEventListener("change", handler);
@@ -313,6 +331,7 @@ function DropdownMobileBottomSheetPortal({
313
331
  onRequestClose,
314
332
  menuRef,
315
333
  portalZClassName = "z-50",
334
+ isSubPortal = false,
316
335
  children,
317
336
  className,
318
337
  style,
@@ -324,6 +343,7 @@ function DropdownMobileBottomSheetPortal({
324
343
  /* @__PURE__ */ jsxs(
325
344
  "div",
326
345
  {
346
+ ...isSubPortal ? { [DROPDOWN_SUB_CONTENT_ATTR]: "" } : {},
327
347
  className: cn(
328
348
  "fixed inset-0 flex items-end justify-center p-0",
329
349
  portalZClassName
@@ -350,8 +370,9 @@ function DropdownMobileBottomSheetPortal({
350
370
  ...panelProps,
351
371
  ref: menuRef,
352
372
  className: cn(
353
- "bg-background border-primary/10 relative z-10 flex w-full max-h-[min(90dvh,calc(100dvh-env(safe-area-inset-bottom,0px)))] flex-col overflow-hidden shadow-2xl outline-none",
373
+ "bg-background border-primary/8 relative z-10 flex w-full max-h-[min(90dvh,calc(100dvh-env(safe-area-inset-bottom,0px)))] flex-col overflow-hidden shadow-2xl outline-none",
354
374
  "rounded-t-2xl rounded-b-none border-x-0 border-b-0 border-t",
375
+ DROPDOWN_PANEL_SCROLL,
355
376
  sheetExtraClassName,
356
377
  className
357
378
  ),
@@ -428,25 +449,25 @@ var DropdownContent = ({
428
449
  const [pos, setPos] = useState({ top: -9999, left: -9999, side });
429
450
  const [triggerW, setTriggerW] = useState(0);
430
451
  const menuRef = useRef(null);
431
- const resolvedMobile = useMemo(
432
- () => resolveDropdownMobileSheet(mobileOptions),
433
- [mobileOptions]
434
- );
435
- const slideOffsetPx = useMemo(
436
- () => slideEntranceOffsetPxProp ?? DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX,
437
- [slideEntranceOffsetPxProp]
438
- );
439
- const closeDuration = isMobile && resolvedMobile.sheet ? DROPDOWN_MOBILE_SHEET_MOTION_MS : duration;
440
- const closeMenu = useCallback(() => setOpen(false), [setOpen]);
452
+ const resolvedMobile = resolveDropdownMobileSheet(mobileOptions);
453
+ const isMobileSheet = isMobile && resolvedMobile.sheet;
454
+ const slideOffsetPx = slideEntranceOffsetPxProp ?? DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX;
441
455
  useEffect(() => {
442
456
  if (open) {
443
457
  setShouldRender(true);
444
- } else {
445
- setIsAnimating(false);
446
- const timer = setTimeout(() => setShouldRender(false), closeDuration);
447
- return () => clearTimeout(timer);
458
+ return;
459
+ }
460
+ if (!isMobileSheet) {
461
+ setShouldRender(false);
462
+ return;
448
463
  }
449
- }, [open, closeDuration]);
464
+ setIsAnimating(false);
465
+ const t = setTimeout(
466
+ () => setShouldRender(false),
467
+ DROPDOWN_MOBILE_SHEET_MOTION_MS
468
+ );
469
+ return () => clearTimeout(t);
470
+ }, [open, isMobileSheet]);
450
471
  useEffect(() => {
451
472
  if (!shouldRender || !open) return;
452
473
  let raf2 = 0;
@@ -476,12 +497,27 @@ var DropdownContent = ({
476
497
  };
477
498
  update();
478
499
  window.addEventListener("resize", update);
479
- window.addEventListener("scroll", update, true);
480
500
  return () => {
481
501
  window.removeEventListener("resize", update);
482
- window.removeEventListener("scroll", update, true);
483
502
  };
484
503
  }, [shouldRender, side, align, offset, viewportPadding]);
504
+ useEffect(() => {
505
+ if (!open || isMobileSheet) return;
506
+ const isInsideMenu = (t) => t instanceof Node && (!!menuRef.current?.contains(t) || !!triggerRef.current?.contains(t) || t instanceof Element && !!t.closest(`[${DROPDOWN_SUB_CONTENT_ATTR}]`));
507
+ const onScroll = (e) => {
508
+ if (!isInsideMenu(e.target)) setOpen(false);
509
+ };
510
+ window.addEventListener("scroll", onScroll, true);
511
+ return () => window.removeEventListener("scroll", onScroll, true);
512
+ }, [open, isMobileSheet, setOpen, triggerRef]);
513
+ useEffect(() => {
514
+ if (!shouldRender || isMobileSheet) return;
515
+ const menu = menuRef.current;
516
+ if (!menu) return;
517
+ const onWheel = (e) => preventMenuWheelChain(menu, e);
518
+ menu.addEventListener("wheel", onWheel, { passive: false });
519
+ return () => menu.removeEventListener("wheel", onWheel);
520
+ }, [shouldRender, isMobileSheet]);
485
521
  useEffect(() => {
486
522
  if (isAnimating && menuRef.current) {
487
523
  menuRef.current.focus();
@@ -547,15 +583,14 @@ var DropdownContent = ({
547
583
  return () => window.removeEventListener("keydown", handler);
548
584
  }, [open, closeOnEscape, loop, setOpen, triggerRef]);
549
585
  useEffect(() => {
550
- if (open && isMobile && resolvedMobile.sheet) {
551
- document.body.style.overflow = "hidden";
552
- }
586
+ if (!open || !isMobileSheet) return;
587
+ document.body.style.overflow = "hidden";
553
588
  return () => {
554
589
  document.body.style.overflow = "";
555
590
  };
556
- }, [open, isMobile, resolvedMobile.sheet]);
591
+ }, [open, isMobileSheet]);
557
592
  if (!shouldRender || typeof document === "undefined") return null;
558
- if (isMobile && resolvedMobile.sheet) {
593
+ if (isMobileSheet) {
559
594
  return /* @__PURE__ */ jsx(
560
595
  DropdownMobileBottomSheetPortal,
561
596
  {
@@ -567,7 +602,7 @@ var DropdownContent = ({
567
602
  sheetTitle: resolvedMobile.title,
568
603
  sheetExtraClassName: resolvedMobile.sheetExtraClassName,
569
604
  contentClassName: resolvedMobile.contentClassName,
570
- onRequestClose: closeMenu,
605
+ onRequestClose: () => setOpen(false),
571
606
  menuRef,
572
607
  portalZClassName: "z-50",
573
608
  className,
@@ -590,7 +625,9 @@ var DropdownContent = ({
590
625
  "aria-orientation": "vertical",
591
626
  tabIndex: -1,
592
627
  className: cn(
593
- "bg-background border-primary/10 absolute z-50 overflow-hidden rounded-xl border py-1.5 shadow-xl outline-none",
628
+ "bg-background border-primary/8 absolute z-50 overflow-hidden rounded-xl border py-1.5 outline-none",
629
+ DROPDOWN_PANEL_SHADOW,
630
+ DROPDOWN_PANEL_SCROLL,
594
631
  className
595
632
  ),
596
633
  style: {
@@ -666,7 +703,7 @@ var DropdownItem = ({
666
703
  ),
667
704
  children: [
668
705
  icon && /* @__PURE__ */ jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: icon }),
669
- /* @__PURE__ */ jsx("span", { className: "flex-1", children }),
706
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1", children }),
670
707
  shortcut ? /* @__PURE__ */ jsx(
671
708
  "span",
672
709
  {