infinity-ui-elements 1.14.16 → 1.14.18

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/dist/index.js CHANGED
@@ -3174,17 +3174,17 @@ const dropdownVariants = classVarianceAuthority.cva("bg-surface-fill-primary-nor
3174
3174
  size: "medium",
3175
3175
  },
3176
3176
  });
3177
- const Dropdown = React__namespace.forwardRef(({ className, trigger, items = [], customContent, customContentClassName, sectionHeading, isLoading = false, isEmpty = false, emptyTitle = "No Search Results Found", emptyDescription = "Add description of what the user can search for here.", emptyLinkText = "Link to support site", onEmptyLinkClick, primaryButtonText = "Primary", secondaryButtonText = "Secondary", onPrimaryClick, onSecondaryClick, size = "medium", open: controlledOpen, defaultOpen = false, onOpenChange, containerClassName, menuClassName, showChevron = false, emptyIcon, disableFooter = false, showFooter, ...props }, ref) => {
3177
+ const Dropdown = React__namespace.forwardRef(({ className, trigger, items = [], customContent, customContentClassName, sectionHeading, isLoading = false, isEmpty = false, emptyTitle = "No Search Results Found", emptyDescription = "Add description of what the user can search for here.", emptyLinkText = "Link to support site", onEmptyLinkClick, primaryButtonText = "Primary", secondaryButtonText = "Secondary", onPrimaryClick, onSecondaryClick, size = "medium", open: controlledOpen, defaultOpen = false, onOpenChange, containerClassName, menuClassName, showChevron = false, emptyIcon, disableFooter = false, showFooter, usePortal = true, ...props }, ref) => {
3178
3178
  const [uncontrolledOpen, setUncontrolledOpen] = React__namespace.useState(defaultOpen);
3179
3179
  const isOpen = controlledOpen !== undefined ? controlledOpen : uncontrolledOpen;
3180
3180
  const dropdownRef = React__namespace.useRef(null);
3181
3181
  const menuRef = React__namespace.useRef(null);
3182
3182
  const [menuPosition, setMenuPosition] = React__namespace.useState({
3183
- top: "100%",
3184
- bottom: "auto",
3185
- left: "0",
3186
- right: "auto",
3183
+ top: 0,
3184
+ left: 0,
3185
+ width: 0,
3187
3186
  maxHeight: "400px",
3187
+ position: "below",
3188
3188
  });
3189
3189
  // Detect if we're on mobile (< 768px)
3190
3190
  const [isMobile, setIsMobile] = React__namespace.useState(false);
@@ -3238,62 +3238,36 @@ const Dropdown = React__namespace.forwardRef(({ className, trigger, items = [],
3238
3238
  }, [isOpen]);
3239
3239
  // Calculate and adjust dropdown position to keep it within viewport
3240
3240
  React__namespace.useEffect(() => {
3241
- if (!isOpen || !dropdownRef.current || !menuRef.current)
3241
+ if (!isOpen || !dropdownRef.current)
3242
3242
  return;
3243
3243
  const calculatePosition = () => {
3244
3244
  const triggerRect = dropdownRef.current.getBoundingClientRect();
3245
3245
  const menuElement = menuRef.current;
3246
- // Get menu dimensions (use a temporary measurement if needed)
3247
- const menuRect = menuElement.getBoundingClientRect();
3248
- const menuHeight = menuRect.height || 400; // fallback to max-height
3249
- const menuWidth = menuRect.width;
3246
+ // Get menu dimensions
3247
+ const menuHeight = menuElement?.getBoundingClientRect().height || 400;
3248
+ triggerRect.width; // Match trigger width or use size variant
3250
3249
  const viewportHeight = window.innerHeight;
3251
- const viewportWidth = window.innerWidth;
3252
3250
  const spaceBelow = viewportHeight - triggerRect.bottom;
3253
3251
  const spaceAbove = triggerRect.top;
3254
- const spaceRight = viewportWidth - triggerRect.left;
3255
- const spaceLeft = triggerRect.right;
3256
3252
  const position = {
3257
- top: "auto",
3258
- bottom: "auto",
3259
- left: "auto",
3260
- right: "auto",
3253
+ top: 0,
3254
+ left: triggerRect.left + window.scrollX,
3255
+ width: triggerRect.width,
3261
3256
  maxHeight: "400px",
3257
+ position: "below",
3262
3258
  };
3263
3259
  // Vertical positioning
3264
3260
  if (spaceBelow >= menuHeight || spaceBelow >= spaceAbove) {
3265
3261
  // Position below trigger
3266
- position.top = "100%";
3267
- position.bottom = "auto";
3262
+ position.top = triggerRect.bottom + window.scrollY + 8; // 8px gap
3268
3263
  position.maxHeight = `${Math.min(400, spaceBelow - 16)}px`;
3264
+ position.position = "below";
3269
3265
  }
3270
3266
  else {
3271
3267
  // Position above trigger
3272
- position.top = "auto";
3273
- position.bottom = "100%";
3268
+ position.top = triggerRect.top + window.scrollY - menuHeight - 8; // 8px gap
3274
3269
  position.maxHeight = `${Math.min(400, spaceAbove - 16)}px`;
3275
- }
3276
- // Horizontal positioning
3277
- if (spaceRight >= menuWidth) {
3278
- // Align to left edge of trigger
3279
- position.left = "0";
3280
- position.right = "auto";
3281
- }
3282
- else if (spaceLeft >= menuWidth) {
3283
- // Align to right edge of trigger
3284
- position.left = "auto";
3285
- position.right = "0";
3286
- }
3287
- else {
3288
- // Not enough space on either side, try to center or align based on available space
3289
- if (triggerRect.left + menuWidth > viewportWidth) {
3290
- position.left = "auto";
3291
- position.right = "0";
3292
- }
3293
- else {
3294
- position.left = "0";
3295
- position.right = "auto";
3296
- }
3270
+ position.position = "above";
3297
3271
  }
3298
3272
  setMenuPosition(position);
3299
3273
  };
@@ -3316,16 +3290,29 @@ const Dropdown = React__namespace.forwardRef(({ className, trigger, items = [],
3316
3290
  };
3317
3291
  // Render dropdown menu content wrapped in BottomSheet for mobile
3318
3292
  const renderDropdownContent = () => (jsxRuntime.jsx(DropdownMenu, { ref: ref, items: items, customContent: customContent, customContentClassName: customContentClassName, sectionHeading: sectionHeading, isLoading: isLoading, isEmpty: isEmpty, emptyTitle: emptyTitle, emptyDescription: emptyDescription, emptyLinkText: emptyLinkText, onEmptyLinkClick: onEmptyLinkClick, primaryButtonText: primaryButtonText, secondaryButtonText: secondaryButtonText, onPrimaryClick: onPrimaryClick, onSecondaryClick: onSecondaryClick, showChevron: showChevron, emptyIcon: emptyIcon, disableFooter: disableFooter, showFooter: showFooter, onClose: () => handleOpenChange(false), className: className, width: isMobile ? "full" : sizeMap[size], maxHeight: menuPosition.maxHeight, unstyled: isMobile }));
3293
+ // Render the dropdown menu for desktop
3294
+ const renderDesktopDropdown = () => {
3295
+ if (!isOpen)
3296
+ return null;
3297
+ const dropdownMenu = (jsxRuntime.jsx("div", { ref: menuRef, className: cn("fixed z-[1000]", menuClassName), style: {
3298
+ top: `${menuPosition.top}px`,
3299
+ left: `${menuPosition.left}px`,
3300
+ width: `${menuPosition.width}px`,
3301
+ }, children: renderDropdownContent() }));
3302
+ // Use portal if enabled, otherwise render inline
3303
+ return usePortal && typeof document !== 'undefined'
3304
+ ? reactDom.createPortal(dropdownMenu, document.body)
3305
+ : (jsxRuntime.jsx("div", { ref: menuRef, className: cn("absolute z-[1000]", menuClassName), style: {
3306
+ top: menuPosition.position === "below" ? "100%" : "auto",
3307
+ bottom: menuPosition.position === "above" ? "100%" : "auto",
3308
+ left: "0",
3309
+ marginTop: menuPosition.position === "below" ? "0.5rem" : "0",
3310
+ marginBottom: menuPosition.position === "above" ? "0.5rem" : "0",
3311
+ }, children: renderDropdownContent() }));
3312
+ };
3319
3313
  return (jsxRuntime.jsxs("div", { ref: dropdownRef, className: cn("relative inline-block", containerClassName), ...props, children: [trigger && (jsxRuntime.jsx("div", { onClick: toggleOpen, className: "cursor-pointer", children: trigger })), isMobile ? (jsxRuntime.jsx(BottomSheet, { isOpen: isOpen, onClose: () => handleOpenChange(false), title: sectionHeading, variant: "default", showDragHandle: true, closeOnOverlayClick: true, closeOnEscape: true, closeOnSwipeDown: true, children: renderDropdownContent() })) : (
3320
- /* Desktop: Regular Dropdown Menu */
3321
- isOpen && (jsxRuntime.jsx("div", { ref: menuRef, className: cn("absolute z-[1000]", menuClassName), style: {
3322
- top: menuPosition.top,
3323
- bottom: menuPosition.bottom,
3324
- left: menuPosition.left,
3325
- right: menuPosition.right,
3326
- marginTop: menuPosition.top === "100%" ? "0.5rem" : "0",
3327
- marginBottom: menuPosition.bottom === "100%" ? "0.5rem" : "0",
3328
- }, children: renderDropdownContent() })))] }));
3314
+ /* Desktop: Regular Dropdown Menu with Portal */
3315
+ renderDesktopDropdown())] }));
3329
3316
  });
3330
3317
  Dropdown.displayName = "Dropdown";
3331
3318