infinity-ui-elements 1.15.1 → 1.15.3

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
@@ -5335,7 +5335,10 @@ var Content2 = HoverCardContent;
5335
5335
  var Arrow2 = HoverCardArrow;
5336
5336
 
5337
5337
  const tooltipVariants = classVarianceAuthority.cva("z-[9998] bg-popup-fill-intense text-action-ink-on-primary-normal border border-popup-outline-subtle flex flex-col p-4 rounded-xlarge min-w-[200px] max-w-[300px] shadow-[0_4px_20px_rgba(0,0,0,0.15)]");
5338
- const Tooltip = React__namespace.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, }, ref) => {
5338
+ const Tooltip = React__namespace.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, trigger = "hover", }, ref) => {
5339
+ const [open, setOpen] = React__namespace.useState(false);
5340
+ const triggerRef = React__namespace.useRef(null);
5341
+ const contentRef = React__namespace.useRef(null);
5339
5342
  const { side, align } = React__namespace.useMemo(() => {
5340
5343
  switch (placement) {
5341
5344
  case "top-start":
@@ -5353,10 +5356,65 @@ const Tooltip = React__namespace.forwardRef(({ children, heading, description, p
5353
5356
  return { side: "top", align: "center" };
5354
5357
  }
5355
5358
  }, [placement]);
5356
- if (disabled) {
5357
- return children;
5358
- }
5359
- return (jsxRuntime.jsxs(Root2, { openDelay: delay, closeDelay: 250, children: [jsxRuntime.jsx(Trigger, { asChild: true, children: children }), jsxRuntime.jsx(Portal, { children: jsxRuntime.jsxs(Content2, { ref: ref, role: "tooltip", side: side, align: align, sideOffset: 14, collisionPadding: 8, className: cn(tooltipVariants(), className), children: [showArrow && (jsxRuntime.jsx(Arrow2, { width: 12, height: 6, className: "fill-popup-fill-intense" })), jsxRuntime.jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsxRuntime.jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), jsxRuntime.jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })] })] }) })] }));
5359
+ const mergeRefs = (...refs) => {
5360
+ return (node) => {
5361
+ refs.forEach((currentRef) => {
5362
+ if (typeof currentRef === "function") {
5363
+ currentRef(node);
5364
+ return;
5365
+ }
5366
+ if (currentRef && typeof currentRef === "object") {
5367
+ currentRef.current = node;
5368
+ }
5369
+ });
5370
+ };
5371
+ };
5372
+ const triggerChild = React__namespace.cloneElement(children, {
5373
+ ref: mergeRefs(triggerRef, children.ref),
5374
+ onClick: (event) => {
5375
+ if (trigger === "click" && !disabled) {
5376
+ setOpen((prev) => !prev);
5377
+ }
5378
+ children.props.onClick?.(event);
5379
+ },
5380
+ });
5381
+ React__namespace.useEffect(() => {
5382
+ if (disabled || trigger !== "click" || !open)
5383
+ return;
5384
+ const handlePointerDownOutside = (event) => {
5385
+ const target = event.target;
5386
+ if (!target)
5387
+ return;
5388
+ if (triggerRef.current?.contains(target) ||
5389
+ contentRef.current?.contains(target)) {
5390
+ return;
5391
+ }
5392
+ setOpen(false);
5393
+ };
5394
+ const handleEscape = (event) => {
5395
+ if (event.key === "Escape") {
5396
+ setOpen(false);
5397
+ }
5398
+ };
5399
+ document.addEventListener("mousedown", handlePointerDownOutside);
5400
+ document.addEventListener("touchstart", handlePointerDownOutside);
5401
+ document.addEventListener("keydown", handleEscape);
5402
+ return () => {
5403
+ document.removeEventListener("mousedown", handlePointerDownOutside);
5404
+ document.removeEventListener("touchstart", handlePointerDownOutside);
5405
+ document.removeEventListener("keydown", handleEscape);
5406
+ };
5407
+ }, [disabled, open, trigger]);
5408
+ React__namespace.useEffect(() => {
5409
+ if (disabled) {
5410
+ setOpen(false);
5411
+ }
5412
+ }, [disabled]);
5413
+ return (jsxRuntime.jsxs(Root2, { open: trigger === "click" || disabled ? (disabled ? false : open) : undefined, onOpenChange: (nextOpen) => {
5414
+ if (!disabled && trigger === "hover") {
5415
+ setOpen(nextOpen);
5416
+ }
5417
+ }, openDelay: delay, closeDelay: 250, children: [jsxRuntime.jsx(Trigger, { asChild: true, children: triggerChild }), jsxRuntime.jsx(Portal, { children: jsxRuntime.jsxs(Content2, { ref: mergeRefs(contentRef, ref), role: "tooltip", side: side, align: align, sideOffset: 14, collisionPadding: 8, className: cn(tooltipVariants(), className), children: [showArrow && (jsxRuntime.jsx(Arrow2, { width: 12, height: 6, className: "fill-popup-fill-intense" })), jsxRuntime.jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsxRuntime.jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), typeof description === "string" ? (jsxRuntime.jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })) : (description)] })] }) })] }));
5360
5418
  });
5361
5419
  Tooltip.displayName = "Tooltip";
5362
5420
 
@@ -6837,7 +6895,7 @@ const TextField = React__namespace.forwardRef(({ label, helperText, errorText, s
6837
6895
  });
6838
6896
  TextField.displayName = "TextField";
6839
6897
 
6840
- const Select = React__namespace.forwardRef(({ className, options = [], value: controlledValue, defaultValue, onChange, placeholder = "Select an option", label, helperText, errorText, successText, validationState = "none", isDisabled = false, isRequired = false, isOptional = false, isLoading = false, size = "medium", prefix, suffix, showClearButton = false, onClear, showLeadingIcon = false, containerClassName, labelClassName, triggerClassName, menuClassName, menuWidth = "full", sectionHeading, emptyTitle = "No options available", emptyDescription = "There are no options to select from.", emptyIcon, infoHeading, infoDescription, LinkComponent, linkText, linkHref, onLinkClick, ...props }, ref) => {
6898
+ const Select = React__namespace.forwardRef(({ className, options = [], value: controlledValue, defaultValue, onChange, placeholder = "Select an option", label, helperText, errorText, successText, validationState = "none", isDisabled = false, isRequired = false, isOptional = false, isLoading = false, size = "medium", prefix, suffix, showClearButton = false, onClear, showLeadingIcon = false, containerClassName, labelClassName, triggerClassName, menuClassName, menuWidth = "full", sectionHeading, emptyTitle = "No options available", emptyDescription = "There are no options to select from.", emptyIcon, infoHeading, infoDescription, LinkComponent, linkText, linkHref, onLinkClick, onClick, ...props }, ref) => {
6841
6899
  const [uncontrolledValue, setUncontrolledValue] = React__namespace.useState(defaultValue);
6842
6900
  const [isOpen, setIsOpen] = React__namespace.useState(false);
6843
6901
  const [dropdownPlacement, setDropdownPlacement] = React__namespace.useState("bottom");
@@ -6866,16 +6924,31 @@ const Select = React__namespace.forwardRef(({ className, options = [], value: co
6866
6924
  setIsOpen(newOpen);
6867
6925
  }
6868
6926
  };
6869
- const handleTriggerContainerClick = (event) => {
6927
+ const shouldIgnoreOpenInteraction = (target) => {
6928
+ if (!(target instanceof HTMLElement))
6929
+ return true;
6930
+ if (dropdownContainerRef.current?.contains(target))
6931
+ return true;
6932
+ if (target.closest("button") || target.closest("a"))
6933
+ return true;
6934
+ return false;
6935
+ };
6936
+ /** Open dropdown from any pointer activation on the composite (label, helper, input row, icons). */
6937
+ const handleCompositePointerActivate = (target) => {
6870
6938
  if (isDisabled || isLoading)
6871
6939
  return;
6872
- const target = event.target;
6873
- // Let clear/other explicit buttons and links behave normally.
6874
- if (target.closest("button") || target.closest("a"))
6940
+ if (shouldIgnoreOpenInteraction(target))
6875
6941
  return;
6876
- // Open the dropdown when clicking anywhere on the trigger area.
6877
6942
  handleOpenChange(true);
6878
6943
  };
6944
+ const handleTriggerContainerPointerDownCapture = (event) => {
6945
+ if (event.button !== undefined && event.button !== 0)
6946
+ return;
6947
+ handleCompositePointerActivate(event.target);
6948
+ };
6949
+ const handleTriggerContainerClickCapture = (event) => {
6950
+ handleCompositePointerActivate(event.target);
6951
+ };
6879
6952
  const handleSelect = (option) => {
6880
6953
  if (controlledValue === undefined) {
6881
6954
  setUncontrolledValue(option.value);
@@ -7022,7 +7095,11 @@ const Select = React__namespace.forwardRef(({ className, options = [], value: co
7022
7095
  const displaySuffix = suffix ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [suffix, chevronIcon] })) : (chevronIcon);
7023
7096
  // Render dropdown menu content
7024
7097
  const renderDropdownContent = () => (jsxRuntime.jsx(DropdownMenu, { items: menuItems, sectionHeading: sectionHeading, isEmpty: options.length === 0, emptyTitle: emptyTitle, emptyDescription: emptyDescription, emptyIcon: emptyIcon, disableFooter: true, onClose: () => handleOpenChange(false), className: menuClassName, width: isMobile ? "full" : widthStyle, unstyled: isMobile }));
7025
- return (jsxRuntime.jsxs("div", { ref: containerRef, className: "relative w-full", onClickCapture: handleTriggerContainerClick, children: [jsxRuntime.jsx(TextField, { ref: inputRef, label: label, helperText: helperText, errorText: errorText, successText: successText, validationState: validationState, isDisabled: isDisabled, isRequired: isRequired, isOptional: isOptional, isLoading: isLoading, size: size, prefix: displayPrefix, suffix: displaySuffix, showClearButton: showClearButton && hasValue && !isLoading, onClear: handleClear, placeholder: placeholder, value: displayValue, readOnly: true, containerClassName: cn("w-full", containerClassName), labelClassName: labelClassName, className: cn("cursor-pointer", triggerClassName, className), inputClassName: "cursor-pointer", infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, onClick: () => handleOpenChange(true), onKeyDown: handleKeyDown, role: "combobox", "aria-haspopup": "listbox", "aria-expanded": isOpen, ...props }), isOpen && !isDisabled && !isLoading && (isMobile ? (jsxRuntime.jsx(BottomSheet, { isOpen: isOpen, onClose: () => handleOpenChange(false), title: sectionHeading || label, variant: "default", showDragHandle: true, closeOnOverlayClick: true, closeOnEscape: true, closeOnSwipeDown: true, children: renderDropdownContent() })) : (jsxRuntime.jsx("div", { ref: dropdownContainerRef, className: cn("absolute z-50 left-0 right-0", dropdownPlacement === "bottom"
7098
+ return (jsxRuntime.jsxs("div", { ref: containerRef, className: cn("relative w-full min-w-0", !isDisabled && !isLoading && "cursor-pointer"), onPointerDownCapture: handleTriggerContainerPointerDownCapture, onClickCapture: handleTriggerContainerClickCapture, children: [jsxRuntime.jsx(TextField, { ref: inputRef, label: label, helperText: helperText, errorText: errorText, successText: successText, validationState: validationState, isDisabled: isDisabled, isRequired: isRequired, isOptional: isOptional, isLoading: isLoading, size: size, prefix: displayPrefix, suffix: displaySuffix, showClearButton: showClearButton && hasValue && !isLoading, onClear: handleClear, placeholder: placeholder, value: displayValue, readOnly: true, containerClassName: cn("w-full", containerClassName), labelClassName: labelClassName, className: cn("cursor-pointer", triggerClassName, className), inputClassName: "cursor-pointer", infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, onClick: (event) => {
7099
+ onClick?.(event);
7100
+ if (!isDisabled && !isLoading)
7101
+ handleOpenChange(true);
7102
+ }, onKeyDown: handleKeyDown, role: "combobox", "aria-haspopup": "listbox", "aria-expanded": isOpen, ...props }), isOpen && !isDisabled && !isLoading && (isMobile ? (jsxRuntime.jsx(BottomSheet, { isOpen: isOpen, onClose: () => handleOpenChange(false), title: sectionHeading || label, variant: "default", showDragHandle: true, closeOnOverlayClick: true, closeOnEscape: true, closeOnSwipeDown: true, children: renderDropdownContent() })) : (jsxRuntime.jsx("div", { ref: dropdownContainerRef, className: cn("absolute z-50 left-0 right-0", dropdownPlacement === "bottom"
7026
7103
  ? "top-full mt-1"
7027
7104
  : "bottom-full mb-1"), children: renderDropdownContent() })))] }));
7028
7105
  });