@charlesgomes/leafcode-shared-lib-react 1.0.91 → 1.0.92
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 +36 -3
- package/dist/index.mjs +36 -3
- package/dist/styles/input.css +15 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -789,6 +789,8 @@ function AutoCompleteInner(props, ref) {
|
|
|
789
789
|
...inputProps
|
|
790
790
|
} = props;
|
|
791
791
|
const theme = useLeafcodeTheme();
|
|
792
|
+
const inputRef = (0, import_react12.useRef)(null);
|
|
793
|
+
const [placement, setPlacement] = (0, import_react12.useState)("bottom");
|
|
792
794
|
const styleVars = {
|
|
793
795
|
// Fonts
|
|
794
796
|
"--label-font-family": theme.components.input.fonts.label,
|
|
@@ -813,6 +815,29 @@ function AutoCompleteInner(props, ref) {
|
|
|
813
815
|
const [search, setSearch] = (0, import_react12.useState)("");
|
|
814
816
|
const [isOpen, setIsOpen] = (0, import_react12.useState)(false);
|
|
815
817
|
const listRef = (0, import_react12.useRef)(null);
|
|
818
|
+
const calculatePlacement = () => {
|
|
819
|
+
const input = inputRef.current;
|
|
820
|
+
if (!input) return;
|
|
821
|
+
const rect = input.getBoundingClientRect();
|
|
822
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
823
|
+
const spaceAbove = rect.top;
|
|
824
|
+
const dropdownHeight = 180;
|
|
825
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
826
|
+
setPlacement("top");
|
|
827
|
+
} else {
|
|
828
|
+
setPlacement("bottom");
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
(0, import_react12.useEffect)(() => {
|
|
832
|
+
if (!isOpen) return;
|
|
833
|
+
calculatePlacement();
|
|
834
|
+
window.addEventListener("resize", calculatePlacement);
|
|
835
|
+
window.addEventListener("scroll", calculatePlacement, true);
|
|
836
|
+
return () => {
|
|
837
|
+
window.removeEventListener("resize", calculatePlacement);
|
|
838
|
+
window.removeEventListener("scroll", calculatePlacement, true);
|
|
839
|
+
};
|
|
840
|
+
}, [isOpen]);
|
|
816
841
|
const fetcher = () => {
|
|
817
842
|
if (service) {
|
|
818
843
|
return service({
|
|
@@ -883,7 +908,11 @@ function AutoCompleteInner(props, ref) {
|
|
|
883
908
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
884
909
|
"input",
|
|
885
910
|
{
|
|
886
|
-
ref
|
|
911
|
+
ref: (el) => {
|
|
912
|
+
inputRef.current = el;
|
|
913
|
+
if (typeof ref === "function") ref(el);
|
|
914
|
+
else if (ref) ref.current = el;
|
|
915
|
+
},
|
|
887
916
|
id: name,
|
|
888
917
|
name,
|
|
889
918
|
disabled,
|
|
@@ -893,9 +922,13 @@ function AutoCompleteInner(props, ref) {
|
|
|
893
922
|
value: value ?? "",
|
|
894
923
|
onChange: (e) => {
|
|
895
924
|
onChange?.(e.target.value);
|
|
925
|
+
calculatePlacement();
|
|
926
|
+
setIsOpen(true);
|
|
927
|
+
},
|
|
928
|
+
onFocus: () => {
|
|
929
|
+
calculatePlacement();
|
|
896
930
|
setIsOpen(true);
|
|
897
931
|
},
|
|
898
|
-
onFocus: () => setIsOpen(true),
|
|
899
932
|
...inputProps
|
|
900
933
|
}
|
|
901
934
|
),
|
|
@@ -912,7 +945,7 @@ function AutoCompleteInner(props, ref) {
|
|
|
912
945
|
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react11.X, { size: 16, color: "#bf1717" })
|
|
913
946
|
}
|
|
914
947
|
),
|
|
915
|
-
isOpen && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className:
|
|
948
|
+
isOpen && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: `dropdown-container dropdown-${placement}`, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
916
949
|
items.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
917
950
|
"li",
|
|
918
951
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -737,6 +737,8 @@ function AutoCompleteInner(props, ref) {
|
|
|
737
737
|
...inputProps
|
|
738
738
|
} = props;
|
|
739
739
|
const theme = useLeafcodeTheme();
|
|
740
|
+
const inputRef = useRef(null);
|
|
741
|
+
const [placement, setPlacement] = useState4("bottom");
|
|
740
742
|
const styleVars = {
|
|
741
743
|
// Fonts
|
|
742
744
|
"--label-font-family": theme.components.input.fonts.label,
|
|
@@ -761,6 +763,29 @@ function AutoCompleteInner(props, ref) {
|
|
|
761
763
|
const [search, setSearch] = useState4("");
|
|
762
764
|
const [isOpen, setIsOpen] = useState4(false);
|
|
763
765
|
const listRef = useRef(null);
|
|
766
|
+
const calculatePlacement = () => {
|
|
767
|
+
const input = inputRef.current;
|
|
768
|
+
if (!input) return;
|
|
769
|
+
const rect = input.getBoundingClientRect();
|
|
770
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
771
|
+
const spaceAbove = rect.top;
|
|
772
|
+
const dropdownHeight = 180;
|
|
773
|
+
if (spaceBelow < dropdownHeight && spaceAbove > spaceBelow) {
|
|
774
|
+
setPlacement("top");
|
|
775
|
+
} else {
|
|
776
|
+
setPlacement("bottom");
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
useEffect4(() => {
|
|
780
|
+
if (!isOpen) return;
|
|
781
|
+
calculatePlacement();
|
|
782
|
+
window.addEventListener("resize", calculatePlacement);
|
|
783
|
+
window.addEventListener("scroll", calculatePlacement, true);
|
|
784
|
+
return () => {
|
|
785
|
+
window.removeEventListener("resize", calculatePlacement);
|
|
786
|
+
window.removeEventListener("scroll", calculatePlacement, true);
|
|
787
|
+
};
|
|
788
|
+
}, [isOpen]);
|
|
764
789
|
const fetcher = () => {
|
|
765
790
|
if (service) {
|
|
766
791
|
return service({
|
|
@@ -831,7 +856,11 @@ function AutoCompleteInner(props, ref) {
|
|
|
831
856
|
/* @__PURE__ */ jsx10(
|
|
832
857
|
"input",
|
|
833
858
|
{
|
|
834
|
-
ref
|
|
859
|
+
ref: (el) => {
|
|
860
|
+
inputRef.current = el;
|
|
861
|
+
if (typeof ref === "function") ref(el);
|
|
862
|
+
else if (ref) ref.current = el;
|
|
863
|
+
},
|
|
835
864
|
id: name,
|
|
836
865
|
name,
|
|
837
866
|
disabled,
|
|
@@ -841,9 +870,13 @@ function AutoCompleteInner(props, ref) {
|
|
|
841
870
|
value: value ?? "",
|
|
842
871
|
onChange: (e) => {
|
|
843
872
|
onChange?.(e.target.value);
|
|
873
|
+
calculatePlacement();
|
|
874
|
+
setIsOpen(true);
|
|
875
|
+
},
|
|
876
|
+
onFocus: () => {
|
|
877
|
+
calculatePlacement();
|
|
844
878
|
setIsOpen(true);
|
|
845
879
|
},
|
|
846
|
-
onFocus: () => setIsOpen(true),
|
|
847
880
|
...inputProps
|
|
848
881
|
}
|
|
849
882
|
),
|
|
@@ -860,7 +893,7 @@ function AutoCompleteInner(props, ref) {
|
|
|
860
893
|
children: /* @__PURE__ */ jsx10(X3, { size: 16, color: "#bf1717" })
|
|
861
894
|
}
|
|
862
895
|
),
|
|
863
|
-
isOpen && /* @__PURE__ */ jsx10("div", { className:
|
|
896
|
+
isOpen && /* @__PURE__ */ jsx10("div", { className: `dropdown-container dropdown-${placement}`, children: /* @__PURE__ */ jsxs7("ul", { ref: listRef, onScroll: handleScroll, className: "dropdown-list", children: [
|
|
864
897
|
items.map((item, i) => /* @__PURE__ */ jsx10(
|
|
865
898
|
"li",
|
|
866
899
|
{
|
package/dist/styles/input.css
CHANGED
|
@@ -286,3 +286,18 @@ input:-webkit-autofill:focus {
|
|
|
286
286
|
background-color: var(--input-disabled-bg, #f3f4f6) !important;
|
|
287
287
|
cursor: not-allowed;
|
|
288
288
|
}
|
|
289
|
+
|
|
290
|
+
.dropdown-container {
|
|
291
|
+
position: absolute;
|
|
292
|
+
left: 0;
|
|
293
|
+
width: 100%;
|
|
294
|
+
z-index: 50;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.dropdown-bottom {
|
|
298
|
+
top: calc(100% + 4px);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.dropdown-top {
|
|
302
|
+
bottom: calc(100% + 4px);
|
|
303
|
+
}
|