@rovula/ui 0.0.65 → 0.0.66

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.
@@ -17,7 +17,7 @@ import { customInputVariant, dropdownIconVariant, iconWrapperVariant, } from "./
17
17
  import { ChevronDownIcon } from "@heroicons/react/16/solid";
18
18
  import { cn } from "@/utils/cn";
19
19
  const Dropdown = forwardRef((_a, ref) => {
20
- var { id, options = [], value, label, size = "md", rounded = "normal", variant = "outline", helperText, errorMessage, fullwidth = true, disabled = false, error = false, filterMode = false, required = true, modal = true, onChangeText, onSelect, renderOptions: customRenderOptions, optionContainerClassName, optionItemClassName, optionNotFoundItemClassName } = _a, props = __rest(_a, ["id", "options", "value", "label", "size", "rounded", "variant", "helperText", "errorMessage", "fullwidth", "disabled", "error", "filterMode", "required", "modal", "onChangeText", "onSelect", "renderOptions", "optionContainerClassName", "optionItemClassName", "optionNotFoundItemClassName"]);
20
+ var { id, options = [], value, label, size = "md", rounded = "normal", variant = "outline", helperText, errorMessage, fullwidth = true, disabled = false, error = false, filterMode = false, required = true, modal = false, onChangeText, onSelect, renderOptions: customRenderOptions, optionContainerClassName, optionItemClassName, optionNotFoundItemClassName } = _a, props = __rest(_a, ["id", "options", "value", "label", "size", "rounded", "variant", "helperText", "errorMessage", "fullwidth", "disabled", "error", "filterMode", "required", "modal", "onChangeText", "onSelect", "renderOptions", "optionContainerClassName", "optionItemClassName", "optionNotFoundItemClassName"]);
21
21
  const _id = id || `${label}-select`;
22
22
  const [isFocused, setIsFocused] = useState(false);
23
23
  const [selectedOption, setSelectedOption] = useState(null);
@@ -66,6 +66,7 @@ const Dropdown = forwardRef((_a, ref) => {
66
66
  ((_a = option.label) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(textValue === null || textValue === void 0 ? void 0 : textValue.toLowerCase()));
67
67
  });
68
68
  }, [options, filterMode, textValue]);
69
+ const usePortal = isInsideDialog ? false : modal;
69
70
  const updateDropdownPosition = useCallback(() => {
70
71
  if (inputRef.current && dropdownRef.current) {
71
72
  const rect = inputRef.current.getBoundingClientRect();
@@ -74,7 +75,6 @@ const Dropdown = forwardRef((_a, ref) => {
74
75
  const spaceAbove = rect.top;
75
76
  const shouldOpenAbove = spaceBelow < dropdownHeight && spaceAbove > spaceBelow;
76
77
  setIsAbove(shouldOpenAbove);
77
- const usePortal = isInsideDialog ? false : modal;
78
78
  if (usePortal) {
79
79
  setDropdownStyles({
80
80
  position: "absolute",
@@ -83,7 +83,7 @@ const Dropdown = forwardRef((_a, ref) => {
83
83
  : `${rect.bottom}px`,
84
84
  left: `${rect.left}px`,
85
85
  width: `${rect.width}px`,
86
- zIndex: 9999, // Ensure it's above everything
86
+ zIndex: 9999,
87
87
  });
88
88
  }
89
89
  else {
@@ -92,20 +92,18 @@ const Dropdown = forwardRef((_a, ref) => {
92
92
  top: shouldOpenAbove ? `-${dropdownHeight}px` : "100%",
93
93
  left: "0",
94
94
  width: "100%",
95
- zIndex: 10,
95
+ zIndex: 9999,
96
96
  });
97
97
  }
98
98
  }
99
- }, [modal, isInsideDialog]);
99
+ }, [modal, isInsideDialog, usePortal]);
100
100
  useEffect(() => {
101
101
  if (isFocused) {
102
102
  updateDropdownPosition();
103
103
  window.addEventListener("resize", updateDropdownPosition);
104
- window.addEventListener("scroll", updateDropdownPosition, true);
105
104
  }
106
105
  return () => {
107
106
  window.removeEventListener("resize", updateDropdownPosition);
108
- window.removeEventListener("scroll", updateDropdownPosition, true);
109
107
  };
110
108
  }, [isFocused, updateDropdownPosition]);
111
109
  const renderOptions = () => {
@@ -118,7 +116,7 @@ const Dropdown = forwardRef((_a, ref) => {
118
116
  dropdownRef,
119
117
  });
120
118
  }
121
- return (_jsxs("ul", { className: cn("absolute mt-1 w-full bg-base-popup border border-base-popup text-base-popup-foreground rounded-md shadow-md z-[9999] max-h-60 overflow-y-auto", isAbove ? "bottom-full mb-1" : "top-full mt-1", optionContainerClassName), style: dropdownStyles, ref: dropdownRef, children: [optionsFiltered.map((option) => {
119
+ return (_jsxs("ul", { className: cn("absolute mt-1 w-full bg-base-popup border border-base-popup text-base-popup-foreground rounded-md shadow-md z-[9999] max-h-60 overflow-y-auto", !usePortal && (isAbove ? "bottom-full mb-1" : "top-full mt-1"), optionContainerClassName), style: dropdownStyles, ref: dropdownRef, children: [optionsFiltered.map((option) => {
122
120
  if (option.renderLabel) {
123
121
  return (_jsx(Fragment, { children: option.renderLabel({
124
122
  value: option.value,
@@ -172,7 +170,7 @@ const Dropdown = forwardRef((_a, ref) => {
172
170
  keyCode.current = e.code;
173
171
  (_a = props === null || props === void 0 ? void 0 : props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, e);
174
172
  }, [props === null || props === void 0 ? void 0 : props.onKeyDown]);
175
- return (_jsxs("div", { className: `relative ${fullwidth ? "w-full" : ""}`, children: [_jsx(TextInput, Object.assign({ hasClearIcon: false, endIcon: _jsx("div", { className: iconWrapperVariant({ size }), children: _jsx(ChevronDownIcon, { className: dropdownIconVariant({ size, isFocus: isFocused }) }) }) }, props, { ref: inputRef, readOnly: !filterMode, value: textValue, onChange: handleOnChangeText, label: label, placeholder: " ", type: "text", autoComplete: "off", rounded: rounded, variant: variant, helperText: helperText, errorMessage: errorMessage, fullwidth: fullwidth, error: error, required: required, id: _id, disabled: disabled, size: size, className: customInputVariant({ size }), onFocus: handleOnFocus, onBlur: handleOnBlur, onKeyDown: handleOnKeyDown })), isFocused &&
176
- ((isInsideDialog ? false : modal) ? (_jsx(Portal.Root, { container: document.body, children: renderOptions() })) : (renderOptions()))] }));
173
+ return (_jsxs("div", { className: `relative ${fullwidth ? "w-full" : ""}`, children: [_jsx(TextInput, Object.assign({ hasClearIcon: false, endIcon: _jsx("div", { className: iconWrapperVariant({ size }), children: _jsx(ChevronDownIcon, { className: dropdownIconVariant({ size, isFocus: isFocused }) }) }) }, props, { ref: inputRef, readOnly: !filterMode, value: textValue, onChange: handleOnChangeText, label: label, placeholder: " ", type: "text", autoComplete: "off", rounded: rounded, variant: variant, helperText: helperText, errorMessage: errorMessage, fullwidth: fullwidth, error: error, required: required, id: _id, disabled: disabled, size: size, className: customInputVariant({ size }), onFocus: handleOnFocus, onBlur: handleOnBlur, onKeyDown: handleOnKeyDown })), isFocused &&
174
+ (usePortal ? (_jsx(Portal.Root, { container: document.body, children: renderOptions() })) : (renderOptions()))] }));
177
175
  });
178
176
  export default Dropdown;