@avenue-ticketing/ui 0.6.0 → 0.8.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.
@@ -203,6 +203,7 @@ Button.displayName = "Button";
203
203
  var DROPDOWN_PANEL_OPEN_EASING = "cubic-bezier(0,0.55,0.45,1)";
204
204
  var DROPDOWN_PANEL_CLOSE_EASING = "cubic-bezier(0.55,0,1,0.45)";
205
205
  var DROPDOWN_MENU_MIN_WIDTH_PX = 192;
206
+ var DROPDOWN_FLIP_MIN_SPACE_PX = 100;
206
207
  var DROPDOWN_MOBILE_SHEET_MAX_PX = 1024;
207
208
  var DROPDOWN_MOBILE_SHEET_MOTION_MS = 175;
208
209
  var DROPDOWN_MOBILE_SHEET_ENTRY_EASING = "cubic-bezier(0.85, 0, 0.15, 1)";
@@ -250,6 +251,7 @@ var DROPDOWN_CONTENT_HIDDEN = {
250
251
  function computePos(trigger, menu, side, align, offset, pad) {
251
252
  const tr = trigger.getBoundingClientRect();
252
253
  const mr = menu.getBoundingClientRect();
254
+ const contentHeight = menu.scrollHeight;
253
255
  const vw = window.innerWidth;
254
256
  const vh = window.innerHeight;
255
257
  const sx = window.scrollX;
@@ -257,19 +259,19 @@ function computePos(trigger, menu, side, align, offset, pad) {
257
259
  let top = 0;
258
260
  let left = 0;
259
261
  let effectiveSide = side;
260
- const calc = (s) => {
262
+ let maxHeight;
263
+ const placeVertical = (s, height) => {
264
+ if (s === "bottom") top = tr.bottom + sy + offset;
265
+ else top = tr.top + sy - height - offset;
266
+ if (align === "start") left = tr.left + sx;
267
+ else if (align === "end") left = tr.right + sx - mr.width;
268
+ else left = tr.left + sx + tr.width / 2 - mr.width / 2;
269
+ };
270
+ const calc = (s, height = contentHeight) => {
261
271
  switch (s) {
262
272
  case "bottom":
263
- top = tr.bottom + sy + offset;
264
- if (align === "start") left = tr.left + sx;
265
- else if (align === "end") left = tr.right + sx - mr.width;
266
- else left = tr.left + sx + tr.width / 2 - mr.width / 2;
267
- break;
268
273
  case "top":
269
- top = tr.top + sy - mr.height - offset;
270
- if (align === "start") left = tr.left + sx;
271
- else if (align === "end") left = tr.right + sx - mr.width;
272
- else left = tr.left + sx + tr.width / 2 - mr.width / 2;
274
+ placeVertical(s, height);
273
275
  break;
274
276
  case "right":
275
277
  left = tr.right + sx + offset;
@@ -286,17 +288,20 @@ function computePos(trigger, menu, side, align, offset, pad) {
286
288
  }
287
289
  };
288
290
  calc(side);
289
- if (side === "bottom" && top + mr.height > vh + sy - pad) {
290
- const ft = tr.top + sy - mr.height - offset;
291
- if (ft >= sy + pad) {
292
- effectiveSide = "top";
293
- top = ft;
291
+ const spaceBelow = Math.max(0, vh - pad - tr.bottom - offset);
292
+ const spaceAbove = Math.max(0, tr.top - offset - pad);
293
+ if (side === "bottom" || side === "top") {
294
+ const primarySpace = side === "bottom" ? spaceBelow : spaceAbove;
295
+ const alternateSpace = side === "bottom" ? spaceAbove : spaceBelow;
296
+ const alternateSide = side === "bottom" ? "top" : "bottom";
297
+ if (contentHeight > primarySpace) {
298
+ maxHeight = Math.min(contentHeight, primarySpace);
299
+ calc(side, maxHeight);
294
300
  }
295
- } else if (side === "top" && top < sy + pad) {
296
- const ft = tr.bottom + sy + offset;
297
- if (ft + mr.height <= vh + sy - pad) {
298
- effectiveSide = "bottom";
299
- top = ft;
301
+ if (contentHeight > primarySpace && primarySpace < DROPDOWN_FLIP_MIN_SPACE_PX && alternateSpace > primarySpace) {
302
+ effectiveSide = alternateSide;
303
+ maxHeight = Math.min(contentHeight, alternateSpace);
304
+ calc(alternateSide, maxHeight);
300
305
  }
301
306
  } else if (side === "right" && left + mr.width > vw + sx - pad) {
302
307
  const fl = tr.left + sx - mr.width - offset;
@@ -311,9 +316,10 @@ function computePos(trigger, menu, side, align, offset, pad) {
311
316
  left = fl;
312
317
  }
313
318
  }
319
+ const layoutHeight = maxHeight ?? contentHeight;
314
320
  left = Math.max(sx + pad, Math.min(left, vw + sx - mr.width - pad));
315
- top = Math.max(sy + pad, Math.min(top, vh + sy - mr.height - pad));
316
- return { top, left, side: effectiveSide };
321
+ top = Math.max(sy + pad, Math.min(top, vh + sy - layoutHeight - pad));
322
+ return { top, left, side: effectiveSide, maxHeight };
317
323
  }
318
324
  function useIsMobile(breakpoint = 1025) {
319
325
  const [isMobile, setIsMobile] = useState(() => {
@@ -760,16 +766,18 @@ var DropdownContent = ({
760
766
  "aria-orientation": "vertical",
761
767
  tabIndex: -1,
762
768
  className: cn(
763
- "bg-background border-primary/8 absolute z-50 overflow-hidden rounded-xl border py-1.5 outline-none",
769
+ "bg-background border-primary/8 absolute z-50 rounded-xl border py-1.5 outline-none",
764
770
  DROPDOWN_PANEL_SHADOW,
765
771
  DROPDOWN_PANEL_SCROLL,
766
- className
772
+ className,
773
+ pos.maxHeight != null ? "overflow-y-auto" : "overflow-hidden"
767
774
  ),
768
775
  style: {
769
776
  position: "absolute",
770
777
  top: pos.top,
771
778
  left: pos.left,
772
779
  minWidth: resolvedMinW,
780
+ maxHeight: pos.maxHeight,
773
781
  transformOrigin: DROPDOWN_CONTENT_ORIGIN[pos.side],
774
782
  transform: isAnimating ? "none" : DROPDOWN_CONTENT_HIDDEN[pos.side],
775
783
  opacity: isAnimating ? 1 : 0,