next-recomponents 2.0.45 → 2.0.47

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
@@ -36748,6 +36748,29 @@ function Select({
36748
36748
  const [options, setOptions] = (0, import_react9.useState)(
36749
36749
  []
36750
36750
  );
36751
+ const [dropdownPos, setDropdownPos] = (0, import_react9.useState)({ left: 0, width: 0 });
36752
+ (0, import_react9.useEffect)(() => {
36753
+ if (isOpen && containerRef.current) {
36754
+ const rect = containerRef.current.getBoundingClientRect();
36755
+ const spaceBelow = window.innerHeight - rect.bottom;
36756
+ const spaceAbove = rect.top;
36757
+ if (spaceBelow < 200 && spaceAbove > spaceBelow) {
36758
+ setOpenUpwards(true);
36759
+ setDropdownPos({
36760
+ bottom: window.innerHeight - rect.top + 4,
36761
+ left: rect.left,
36762
+ width: rect.width
36763
+ });
36764
+ } else {
36765
+ setOpenUpwards(false);
36766
+ setDropdownPos({
36767
+ top: rect.bottom + 4,
36768
+ left: rect.left,
36769
+ width: rect.width
36770
+ });
36771
+ }
36772
+ }
36773
+ }, [isOpen]);
36751
36774
  const [filtered, setFiltered] = (0, import_react9.useState)(
36752
36775
  []
36753
36776
  );
@@ -36765,12 +36788,12 @@ function Select({
36765
36788
  }).map((child) => {
36766
36789
  return {
36767
36790
  value: child.props.value,
36768
- label: child.props.children
36791
+ label: import_react9.default.Children.toArray(child.props.children).join("")
36769
36792
  };
36770
36793
  });
36771
36794
  setOptions(parsedOptions);
36772
36795
  setFiltered(parsedOptions);
36773
- const value = (props == null ? void 0 : props.value) && ((_a = parsedOptions.find((opt) => opt.value == props.value)) == null ? void 0 : _a.label);
36796
+ const value = (props == null ? void 0 : props.value) ? ((_a = parsedOptions.find((opt) => opt.value == props.value)) == null ? void 0 : _a.label) || "" : "";
36774
36797
  setInputValue(value);
36775
36798
  }, [children]);
36776
36799
  (0, import_react9.useEffect)(() => {
@@ -36798,7 +36821,8 @@ function Select({
36798
36821
  }
36799
36822
  };
36800
36823
  const selectOption = (opt) => {
36801
- setInputValue(opt.label);
36824
+ const v = `${opt.label}`;
36825
+ setInputValue(v);
36802
36826
  setIsOpen(false);
36803
36827
  };
36804
36828
  const containerRef = (0, import_react9.useRef)(null);
@@ -36816,7 +36840,7 @@ function Select({
36816
36840
  }
36817
36841
  }, [isOpen]);
36818
36842
  return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { ref: containerRef, className: "w-full relative my-3", children: [
36819
- /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative flex items-center border rounded bg-white", children: [
36843
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "relative flex items-center border rounded bg-white ", children: [
36820
36844
  /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36821
36845
  "input",
36822
36846
  {
@@ -36858,7 +36882,10 @@ function Select({
36858
36882
  " ",
36859
36883
  (props == null ? void 0 : props.required) && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "text-red-500", children: "*" })
36860
36884
  ] }),
36861
- !isOpen && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "absolute top-0 right-0 flex flex-col justify-center items-center px-2 py-2 font-bold", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectIcon, {}) }),
36885
+ !isOpen && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "absolute top-0 right-0 flex justify-center items-center px-2 py-2 font-bold", children: [
36886
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "font-normal text-xs text-gray-400", children: filtered.length == 0 && "Loading..." }),
36887
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SelectIcon, {})
36888
+ ] }),
36862
36889
  isOpen && inputValue != "" && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36863
36890
  "button",
36864
36891
  {
@@ -36877,44 +36904,54 @@ function Select({
36877
36904
  children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CloseIcon, {})
36878
36905
  }
36879
36906
  ),
36880
- isOpen && filtered.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36907
+ isOpen && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
36881
36908
  "div",
36882
36909
  {
36883
- style: { zIndex: 9999999999 },
36884
- className: `absolute w-full border rounded shadow bg-white z-10 max-h-100 top-10 overflow-y-auto ${openUpwards ? "bottom-full mb-1" : "mt-1"}`,
36885
- children: filtered.map((opt, index) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36886
- "div",
36887
- {
36888
- className: `p-2 cursor-pointer ${index === highlightedIndex ? "bg-blue-100" : "hover:bg-gray-100"}`,
36889
- onClick: () => {
36890
- var _a;
36891
- try {
36892
- (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, {
36893
- target: { value: (opt == null ? void 0 : opt.value) || opt.label }
36894
- });
36895
- } catch (error) {
36896
- }
36897
- setHasEdition(false);
36898
- const item = validOption(opt.label);
36899
- if (inputRef == null ? void 0 : inputRef.current) {
36900
- if (!item) {
36901
- if (strictMode) {
36902
- inputRef.current.value = "";
36903
- inputRef.current.classList.remove("bg-green-200");
36904
- inputRef.current.classList.add("bg-red-200");
36905
- return;
36910
+ style: {
36911
+ zIndex: 999999,
36912
+ position: "fixed",
36913
+ top: dropdownPos.top,
36914
+ bottom: dropdownPos.bottom,
36915
+ left: dropdownPos.left,
36916
+ width: dropdownPos.width
36917
+ },
36918
+ className: "border rounded shadow bg-white max-h-100 overflow-y-auto",
36919
+ children: [
36920
+ filtered.length == 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "font-normal p-2 text-gray-400", children: "Loading options..." }),
36921
+ filtered.map((opt, index) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
36922
+ "div",
36923
+ {
36924
+ className: `p-2 cursor-pointer ${index === highlightedIndex ? "bg-blue-100" : "hover:bg-gray-100"}`,
36925
+ onClick: () => {
36926
+ var _a;
36927
+ try {
36928
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, {
36929
+ target: { value: (opt == null ? void 0 : opt.value) || opt.label }
36930
+ });
36931
+ } catch (error) {
36932
+ }
36933
+ setHasEdition(false);
36934
+ const item = validOption(opt.label);
36935
+ if (inputRef == null ? void 0 : inputRef.current) {
36936
+ if (!item) {
36937
+ if (strictMode) {
36938
+ inputRef.current.value = "";
36939
+ inputRef.current.classList.remove("bg-green-200");
36940
+ inputRef.current.classList.add("bg-red-200");
36941
+ return;
36942
+ }
36943
+ } else {
36944
+ inputRef.current.classList.add("bg-green-200");
36945
+ inputRef.current.classList.remove("bg-red-200");
36906
36946
  }
36907
- } else {
36908
- inputRef.current.classList.add("bg-green-200");
36909
- inputRef.current.classList.remove("bg-red-200");
36910
36947
  }
36911
- }
36912
- selectOption(opt);
36948
+ selectOption(opt);
36949
+ },
36950
+ children: opt.label
36913
36951
  },
36914
- children: opt.label
36915
- },
36916
- index
36917
- ))
36952
+ index
36953
+ ))
36954
+ ]
36918
36955
  }
36919
36956
  )
36920
36957
  ] }),
package/dist/index.mjs CHANGED
@@ -36733,6 +36733,29 @@ function Select({
36733
36733
  const [options, setOptions] = useState8(
36734
36734
  []
36735
36735
  );
36736
+ const [dropdownPos, setDropdownPos] = useState8({ left: 0, width: 0 });
36737
+ useEffect5(() => {
36738
+ if (isOpen && containerRef.current) {
36739
+ const rect = containerRef.current.getBoundingClientRect();
36740
+ const spaceBelow = window.innerHeight - rect.bottom;
36741
+ const spaceAbove = rect.top;
36742
+ if (spaceBelow < 200 && spaceAbove > spaceBelow) {
36743
+ setOpenUpwards(true);
36744
+ setDropdownPos({
36745
+ bottom: window.innerHeight - rect.top + 4,
36746
+ left: rect.left,
36747
+ width: rect.width
36748
+ });
36749
+ } else {
36750
+ setOpenUpwards(false);
36751
+ setDropdownPos({
36752
+ top: rect.bottom + 4,
36753
+ left: rect.left,
36754
+ width: rect.width
36755
+ });
36756
+ }
36757
+ }
36758
+ }, [isOpen]);
36736
36759
  const [filtered, setFiltered] = useState8(
36737
36760
  []
36738
36761
  );
@@ -36750,12 +36773,12 @@ function Select({
36750
36773
  }).map((child) => {
36751
36774
  return {
36752
36775
  value: child.props.value,
36753
- label: child.props.children
36776
+ label: React5.Children.toArray(child.props.children).join("")
36754
36777
  };
36755
36778
  });
36756
36779
  setOptions(parsedOptions);
36757
36780
  setFiltered(parsedOptions);
36758
- const value = (props == null ? void 0 : props.value) && ((_a = parsedOptions.find((opt) => opt.value == props.value)) == null ? void 0 : _a.label);
36781
+ const value = (props == null ? void 0 : props.value) ? ((_a = parsedOptions.find((opt) => opt.value == props.value)) == null ? void 0 : _a.label) || "" : "";
36759
36782
  setInputValue(value);
36760
36783
  }, [children]);
36761
36784
  useEffect5(() => {
@@ -36783,7 +36806,8 @@ function Select({
36783
36806
  }
36784
36807
  };
36785
36808
  const selectOption = (opt) => {
36786
- setInputValue(opt.label);
36809
+ const v = `${opt.label}`;
36810
+ setInputValue(v);
36787
36811
  setIsOpen(false);
36788
36812
  };
36789
36813
  const containerRef = useRef2(null);
@@ -36801,7 +36825,7 @@ function Select({
36801
36825
  }
36802
36826
  }, [isOpen]);
36803
36827
  return /* @__PURE__ */ jsxs7("div", { ref: containerRef, className: "w-full relative my-3", children: [
36804
- /* @__PURE__ */ jsxs7("div", { className: "relative flex items-center border rounded bg-white", children: [
36828
+ /* @__PURE__ */ jsxs7("div", { className: "relative flex items-center border rounded bg-white ", children: [
36805
36829
  /* @__PURE__ */ jsx10(
36806
36830
  "input",
36807
36831
  {
@@ -36843,7 +36867,10 @@ function Select({
36843
36867
  " ",
36844
36868
  (props == null ? void 0 : props.required) && /* @__PURE__ */ jsx10("span", { className: "text-red-500", children: "*" })
36845
36869
  ] }),
36846
- !isOpen && /* @__PURE__ */ jsx10("div", { className: "absolute top-0 right-0 flex flex-col justify-center items-center px-2 py-2 font-bold", children: /* @__PURE__ */ jsx10(SelectIcon, {}) }),
36870
+ !isOpen && /* @__PURE__ */ jsxs7("div", { className: "absolute top-0 right-0 flex justify-center items-center px-2 py-2 font-bold", children: [
36871
+ /* @__PURE__ */ jsx10("div", { className: "font-normal text-xs text-gray-400", children: filtered.length == 0 && "Loading..." }),
36872
+ /* @__PURE__ */ jsx10(SelectIcon, {})
36873
+ ] }),
36847
36874
  isOpen && inputValue != "" && /* @__PURE__ */ jsx10(
36848
36875
  "button",
36849
36876
  {
@@ -36862,44 +36889,54 @@ function Select({
36862
36889
  children: /* @__PURE__ */ jsx10(CloseIcon, {})
36863
36890
  }
36864
36891
  ),
36865
- isOpen && filtered.length > 0 && /* @__PURE__ */ jsx10(
36892
+ isOpen && /* @__PURE__ */ jsxs7(
36866
36893
  "div",
36867
36894
  {
36868
- style: { zIndex: 9999999999 },
36869
- className: `absolute w-full border rounded shadow bg-white z-10 max-h-100 top-10 overflow-y-auto ${openUpwards ? "bottom-full mb-1" : "mt-1"}`,
36870
- children: filtered.map((opt, index) => /* @__PURE__ */ jsx10(
36871
- "div",
36872
- {
36873
- className: `p-2 cursor-pointer ${index === highlightedIndex ? "bg-blue-100" : "hover:bg-gray-100"}`,
36874
- onClick: () => {
36875
- var _a;
36876
- try {
36877
- (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, {
36878
- target: { value: (opt == null ? void 0 : opt.value) || opt.label }
36879
- });
36880
- } catch (error) {
36881
- }
36882
- setHasEdition(false);
36883
- const item = validOption(opt.label);
36884
- if (inputRef == null ? void 0 : inputRef.current) {
36885
- if (!item) {
36886
- if (strictMode) {
36887
- inputRef.current.value = "";
36888
- inputRef.current.classList.remove("bg-green-200");
36889
- inputRef.current.classList.add("bg-red-200");
36890
- return;
36895
+ style: {
36896
+ zIndex: 999999,
36897
+ position: "fixed",
36898
+ top: dropdownPos.top,
36899
+ bottom: dropdownPos.bottom,
36900
+ left: dropdownPos.left,
36901
+ width: dropdownPos.width
36902
+ },
36903
+ className: "border rounded shadow bg-white max-h-100 overflow-y-auto",
36904
+ children: [
36905
+ filtered.length == 0 && /* @__PURE__ */ jsx10("div", { className: "font-normal p-2 text-gray-400", children: "Loading options..." }),
36906
+ filtered.map((opt, index) => /* @__PURE__ */ jsx10(
36907
+ "div",
36908
+ {
36909
+ className: `p-2 cursor-pointer ${index === highlightedIndex ? "bg-blue-100" : "hover:bg-gray-100"}`,
36910
+ onClick: () => {
36911
+ var _a;
36912
+ try {
36913
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, {
36914
+ target: { value: (opt == null ? void 0 : opt.value) || opt.label }
36915
+ });
36916
+ } catch (error) {
36917
+ }
36918
+ setHasEdition(false);
36919
+ const item = validOption(opt.label);
36920
+ if (inputRef == null ? void 0 : inputRef.current) {
36921
+ if (!item) {
36922
+ if (strictMode) {
36923
+ inputRef.current.value = "";
36924
+ inputRef.current.classList.remove("bg-green-200");
36925
+ inputRef.current.classList.add("bg-red-200");
36926
+ return;
36927
+ }
36928
+ } else {
36929
+ inputRef.current.classList.add("bg-green-200");
36930
+ inputRef.current.classList.remove("bg-red-200");
36891
36931
  }
36892
- } else {
36893
- inputRef.current.classList.add("bg-green-200");
36894
- inputRef.current.classList.remove("bg-red-200");
36895
36932
  }
36896
- }
36897
- selectOption(opt);
36933
+ selectOption(opt);
36934
+ },
36935
+ children: opt.label
36898
36936
  },
36899
- children: opt.label
36900
- },
36901
- index
36902
- ))
36937
+ index
36938
+ ))
36939
+ ]
36903
36940
  }
36904
36941
  )
36905
36942
  ] }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-recomponents",
3
- "version": "2.0.45",
3
+ "version": "2.0.47",
4
4
  "description": "description nueva",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,6 +32,37 @@ export default function Select({
32
32
  const [options, setOptions] = useState<{ value: string; label: string }[]>(
33
33
  [],
34
34
  );
35
+ const [dropdownPos, setDropdownPos] = useState<{
36
+ top?: number;
37
+ bottom?: number;
38
+ left: number;
39
+ width: number;
40
+ }>({ left: 0, width: 0 });
41
+
42
+ useEffect(() => {
43
+ if (isOpen && containerRef.current) {
44
+ const rect = containerRef.current.getBoundingClientRect();
45
+ const spaceBelow = window.innerHeight - rect.bottom;
46
+ const spaceAbove = rect.top;
47
+
48
+ if (spaceBelow < 200 && spaceAbove > spaceBelow) {
49
+ setOpenUpwards(true);
50
+ setDropdownPos({
51
+ bottom: window.innerHeight - rect.top + 4,
52
+ left: rect.left,
53
+ width: rect.width,
54
+ });
55
+ } else {
56
+ setOpenUpwards(false);
57
+ setDropdownPos({
58
+ top: rect.bottom + 4,
59
+ left: rect.left,
60
+ width: rect.width,
61
+ });
62
+ }
63
+ }
64
+ }, [isOpen]);
65
+
35
66
  const [filtered, setFiltered] = useState<{ value: string; label: string }[]>(
36
67
  [],
37
68
  );
@@ -56,14 +87,14 @@ export default function Select({
56
87
  .map((child: any) => {
57
88
  return {
58
89
  value: child.props.value,
59
- label: child.props.children,
90
+ label: React.Children.toArray(child.props.children).join(""),
60
91
  };
61
92
  });
62
93
  setOptions(parsedOptions);
63
94
  setFiltered(parsedOptions);
64
- const value =
65
- props?.value &&
66
- parsedOptions.find((opt) => opt.value == props.value)?.label;
95
+ const value = props?.value
96
+ ? parsedOptions.find((opt) => opt.value == props.value)?.label || ""
97
+ : "";
67
98
  setInputValue(value);
68
99
  }, [children]);
69
100
 
@@ -97,8 +128,9 @@ export default function Select({
97
128
  };
98
129
 
99
130
  const selectOption = (opt: { value: string; label: string }) => {
100
- // console.log(opt.label);
101
- setInputValue(opt.label);
131
+ const v = `${opt.label}`;
132
+
133
+ setInputValue(v);
102
134
  setIsOpen(false);
103
135
  };
104
136
 
@@ -120,7 +152,7 @@ export default function Select({
120
152
  }, [isOpen]);
121
153
  return (
122
154
  <div ref={containerRef} className="w-full relative my-3">
123
- <div className="relative flex items-center border rounded bg-white">
155
+ <div className="relative flex items-center border rounded bg-white ">
124
156
  <input
125
157
  autoComplete="off"
126
158
  ref={inputRef}
@@ -162,13 +194,17 @@ export default function Select({
162
194
  onFocus={() => setIsOpen(true)}
163
195
  onKeyDown={handleKeyDown}
164
196
  />
197
+
165
198
  {label && (
166
199
  <label className="absolute -top-2.5 left-2 text-xs font-bold px-1">
167
200
  {label} {props?.required && <span className="text-red-500">*</span>}
168
201
  </label>
169
202
  )}
170
203
  {!isOpen && (
171
- <div className="absolute top-0 right-0 flex flex-col justify-center items-center px-2 py-2 font-bold">
204
+ <div className="absolute top-0 right-0 flex justify-center items-center px-2 py-2 font-bold">
205
+ <div className="font-normal text-xs text-gray-400">
206
+ {filtered.length == 0 && "Loading..."}
207
+ </div>
172
208
  <SelectIcon />
173
209
  </div>
174
210
  )}
@@ -190,13 +226,23 @@ export default function Select({
190
226
  <CloseIcon />
191
227
  </button>
192
228
  )}
193
- {isOpen && filtered.length > 0 && (
229
+ {isOpen && (
194
230
  <div
195
- style={{ zIndex: 9999999999 }}
196
- className={`absolute w-full border rounded shadow bg-white z-10 max-h-100 top-10 overflow-y-auto ${
197
- openUpwards ? "bottom-full mb-1" : "mt-1"
198
- }`}
231
+ style={{
232
+ zIndex: 999999,
233
+ position: "fixed",
234
+ top: dropdownPos.top,
235
+ bottom: dropdownPos.bottom,
236
+ left: dropdownPos.left,
237
+ width: dropdownPos.width,
238
+ }}
239
+ className="border rounded shadow bg-white max-h-100 overflow-y-auto"
199
240
  >
241
+ {filtered.length == 0 && (
242
+ <div className="font-normal p-2 text-gray-400">
243
+ Loading options...
244
+ </div>
245
+ )}
200
246
  {filtered.map((opt, index) => (
201
247
  <div
202
248
  key={index}