infinity-ui-elements 1.7.3 → 1.7.4

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
@@ -1884,7 +1884,9 @@ const selectVariants = classVarianceAuthority.cva("relative flex items-center ga
1884
1884
  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, containerClassName, labelClassName, triggerClassName, menuClassName, menuWidth = "full", sectionHeading, emptyTitle = "No options available", emptyDescription = "There are no options to select from.", emptyIcon, infoHeading, infoDescription, linkText, linkHref, onLinkClick, ...props }, ref) => {
1885
1885
  const [uncontrolledValue, setUncontrolledValue] = React__namespace.useState(defaultValue);
1886
1886
  const [isOpen, setIsOpen] = React__namespace.useState(false);
1887
+ const [dropdownPlacement, setDropdownPlacement] = React__namespace.useState("bottom");
1887
1888
  const selectRef = React__namespace.useRef(null);
1889
+ const dropdownContainerRef = React__namespace.useRef(null);
1888
1890
  const value = controlledValue !== undefined ? controlledValue : uncontrolledValue;
1889
1891
  // Find the selected option
1890
1892
  const selectedOption = options.find((opt) => opt.value === value);
@@ -1923,6 +1925,55 @@ const Select = React__namespace.forwardRef(({ className, options = [], value: co
1923
1925
  onChange?.("", {});
1924
1926
  }
1925
1927
  };
1928
+ const updateDropdownPlacement = React__namespace.useCallback(() => {
1929
+ if (typeof window === "undefined")
1930
+ return;
1931
+ const trigger = selectRef.current;
1932
+ if (!trigger)
1933
+ return;
1934
+ const triggerRect = trigger.getBoundingClientRect();
1935
+ const spaceBelow = window.innerHeight - triggerRect.bottom;
1936
+ const spaceAbove = triggerRect.top;
1937
+ const dropdownHeight = dropdownContainerRef.current
1938
+ ? dropdownContainerRef.current.offsetHeight
1939
+ : 0;
1940
+ if (dropdownHeight === 0) {
1941
+ setDropdownPlacement(spaceBelow >= spaceAbove ? "bottom" : "top");
1942
+ return;
1943
+ }
1944
+ if (spaceBelow >= dropdownHeight || spaceBelow >= spaceAbove) {
1945
+ setDropdownPlacement("bottom");
1946
+ }
1947
+ else {
1948
+ setDropdownPlacement("top");
1949
+ }
1950
+ }, []);
1951
+ const attachDropdownListeners = React__namespace.useCallback(() => {
1952
+ if (!isOpen)
1953
+ return;
1954
+ if (typeof window === "undefined")
1955
+ return;
1956
+ let rafId = requestAnimationFrame(updateDropdownPlacement);
1957
+ const handleUpdate = () => updateDropdownPlacement();
1958
+ window.addEventListener("resize", handleUpdate);
1959
+ window.addEventListener("scroll", handleUpdate, true);
1960
+ return () => {
1961
+ cancelAnimationFrame(rafId);
1962
+ window.removeEventListener("resize", handleUpdate);
1963
+ window.removeEventListener("scroll", handleUpdate, true);
1964
+ };
1965
+ }, [isOpen, updateDropdownPlacement]);
1966
+ React__namespace.useEffect(() => {
1967
+ const detach = attachDropdownListeners();
1968
+ return () => {
1969
+ detach?.();
1970
+ };
1971
+ }, [attachDropdownListeners]);
1972
+ React__namespace.useEffect(() => {
1973
+ if (isOpen) {
1974
+ updateDropdownPlacement();
1975
+ }
1976
+ }, [isOpen, options.length, updateDropdownPlacement]);
1926
1977
  // Close dropdown when clicking outside
1927
1978
  React__namespace.useEffect(() => {
1928
1979
  const handleClickOutside = (event) => {
@@ -2023,7 +2074,9 @@ const Select = React__namespace.forwardRef(({ className, options = [], value: co
2023
2074
  ? "text-feedback-ink-positive-intense"
2024
2075
  : currentValidationState === "negative"
2025
2076
  ? "text-feedback-ink-negative-subtle"
2026
- : "text-surface-ink-neutral-muted", isOpen && "transform rotate-180") }), isOpen && !isDisabled && !isLoading && (jsxRuntime.jsx("div", { className: "absolute z-50 left-0 right-0 top-full mt-1", children: jsxRuntime.jsx(DropdownMenu, { ref: ref, items: menuItems, sectionHeading: sectionHeading, isEmpty: options.length === 0, emptyTitle: emptyTitle, emptyDescription: emptyDescription, emptyIcon: emptyIcon, disableFooter: true, onClose: () => handleOpenChange(false), className: menuClassName, width: widthStyle }) }))] }), jsxRuntime.jsx(FormFooter, { helperText: displayHelperText, validationState: currentValidationState === "none"
2077
+ : "text-surface-ink-neutral-muted", isOpen && "transform rotate-180") }), isOpen && !isDisabled && !isLoading && (jsxRuntime.jsx("div", { ref: dropdownContainerRef, className: cn("absolute z-50 left-0 right-0", dropdownPlacement === "bottom"
2078
+ ? "top-full mt-1"
2079
+ : "bottom-full mb-1"), children: jsxRuntime.jsx(DropdownMenu, { ref: ref, items: menuItems, sectionHeading: sectionHeading, isEmpty: options.length === 0, emptyTitle: emptyTitle, emptyDescription: emptyDescription, emptyIcon: emptyIcon, disableFooter: true, onClose: () => handleOpenChange(false), className: menuClassName, width: widthStyle }) }))] }), jsxRuntime.jsx(FormFooter, { helperText: displayHelperText, validationState: currentValidationState === "none"
2027
2080
  ? "default"
2028
2081
  : currentValidationState, size: size, isDisabled: isDisabled, className: "mt-1" })] }));
2029
2082
  });