hplx-react-elements-dev 1.0.77 → 1.0.79
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/esm/index.js +129 -69
- package/dist/esm/inputTag/InputTag.d.ts +1 -1
- package/dist/esm/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -17694,28 +17694,30 @@ var InputTag = function InputTag(_a) {
|
|
|
17694
17694
|
// comma separated string which is created into separate tags
|
|
17695
17695
|
handleValChange = _f === void 0 ? function (_) {} : _f,
|
|
17696
17696
|
_g = _a.onDropdownClick,
|
|
17697
|
-
onDropdownClick = _g === void 0 ? function (_) {} : _g
|
|
17697
|
+
onDropdownClick = _g === void 0 ? function (_) {} : _g,
|
|
17698
|
+
_h = _a.allowDuplicates,
|
|
17699
|
+
allowDuplicates = _h === void 0 ? false : _h;
|
|
17698
17700
|
|
|
17699
|
-
var
|
|
17700
|
-
disabled =
|
|
17701
|
-
onFocus =
|
|
17702
|
-
onBlur =
|
|
17703
|
-
|
|
17704
|
-
var _j = useState(false),
|
|
17705
|
-
active = _j[0],
|
|
17706
|
-
setActive = _j[1];
|
|
17701
|
+
var _j = inputProps || {},
|
|
17702
|
+
disabled = _j.disabled,
|
|
17703
|
+
onFocus = _j.onFocus,
|
|
17704
|
+
onBlur = _j.onBlur;
|
|
17707
17705
|
|
|
17708
17706
|
var _k = useState(false),
|
|
17709
|
-
|
|
17710
|
-
|
|
17707
|
+
active = _k[0],
|
|
17708
|
+
setActive = _k[1];
|
|
17711
17709
|
|
|
17712
|
-
var _l = useState(
|
|
17713
|
-
|
|
17714
|
-
|
|
17710
|
+
var _l = useState(false),
|
|
17711
|
+
showDropdown = _l[0],
|
|
17712
|
+
setShowDropdown = _l[1];
|
|
17715
17713
|
|
|
17716
17714
|
var _m = useState(""),
|
|
17717
|
-
|
|
17718
|
-
|
|
17715
|
+
dropdownOffset = _m[0],
|
|
17716
|
+
setdropdownOffset = _m[1];
|
|
17717
|
+
|
|
17718
|
+
var _o = useState(""),
|
|
17719
|
+
value = _o[0],
|
|
17720
|
+
setValue = _o[1]; // tag string
|
|
17719
17721
|
|
|
17720
17722
|
|
|
17721
17723
|
var wrapperRef = useRef(null);
|
|
@@ -17724,58 +17726,69 @@ var InputTag = function InputTag(_a) {
|
|
|
17724
17726
|
var editRef = useRef(null);
|
|
17725
17727
|
var spanRef = useRef(null);
|
|
17726
17728
|
|
|
17727
|
-
var
|
|
17728
|
-
dropdownArr =
|
|
17729
|
-
setDropdownArr =
|
|
17729
|
+
var _p = useState([]),
|
|
17730
|
+
dropdownArr = _p[0],
|
|
17731
|
+
setDropdownArr = _p[1];
|
|
17730
17732
|
|
|
17731
|
-
var
|
|
17732
|
-
tagInputValue =
|
|
17733
|
-
setTagInputValue =
|
|
17733
|
+
var _q = useState(""),
|
|
17734
|
+
tagInputValue = _q[0],
|
|
17735
|
+
setTagInputValue = _q[1]; // input field state
|
|
17734
17736
|
|
|
17735
17737
|
|
|
17736
|
-
var
|
|
17738
|
+
var _r = useState(__spreadArray(__spreadArray([], tagList.filter(Boolean), true), tagString.split(",").filter(Boolean).map(function (item) {
|
|
17737
17739
|
return item.trim();
|
|
17738
17740
|
}), true)),
|
|
17739
|
-
tags =
|
|
17740
|
-
setTags =
|
|
17741
|
+
tags = _r[0],
|
|
17742
|
+
setTags = _r[1]; // tag array
|
|
17741
17743
|
|
|
17742
17744
|
|
|
17743
|
-
var
|
|
17744
|
-
focusIndex =
|
|
17745
|
-
setFocusIndex =
|
|
17745
|
+
var _s = useState(-1),
|
|
17746
|
+
focusIndex = _s[0],
|
|
17747
|
+
setFocusIndex = _s[1];
|
|
17746
17748
|
|
|
17747
|
-
var
|
|
17748
|
-
changeLeft =
|
|
17749
|
-
setChangeLeft =
|
|
17749
|
+
var _t = useState(true),
|
|
17750
|
+
changeLeft = _t[0],
|
|
17751
|
+
setChangeLeft = _t[1];
|
|
17750
17752
|
|
|
17751
|
-
var
|
|
17752
|
-
editIndex =
|
|
17753
|
-
setEditIndex =
|
|
17753
|
+
var _u = useState(-1),
|
|
17754
|
+
editIndex = _u[0],
|
|
17755
|
+
setEditIndex = _u[1];
|
|
17754
17756
|
|
|
17755
|
-
var
|
|
17756
|
-
editInputValue =
|
|
17757
|
-
setEditInputValue =
|
|
17757
|
+
var _v = useState(""),
|
|
17758
|
+
editInputValue = _v[0],
|
|
17759
|
+
setEditInputValue = _v[1];
|
|
17758
17760
|
|
|
17759
17761
|
var dropdownClickedRef = useRef(false);
|
|
17760
17762
|
|
|
17761
|
-
var
|
|
17762
|
-
content =
|
|
17763
|
-
setContent =
|
|
17763
|
+
var _w = useState(""),
|
|
17764
|
+
content = _w[0],
|
|
17765
|
+
setContent = _w[1];
|
|
17766
|
+
|
|
17767
|
+
var _x = useState(0),
|
|
17768
|
+
width = _x[0],
|
|
17769
|
+
setWidth = _x[1]; // Handle the change event of the input element
|
|
17764
17770
|
|
|
17765
|
-
var _w = useState(0),
|
|
17766
|
-
width = _w[0],
|
|
17767
|
-
setWidth = _w[1];
|
|
17768
17771
|
|
|
17769
17772
|
var handleValueChange = function handleValueChange(e) {
|
|
17770
|
-
var sug = [];
|
|
17773
|
+
var sug = []; // Show the dropdown list
|
|
17774
|
+
|
|
17771
17775
|
setShowDropdown(true);
|
|
17772
17776
|
|
|
17773
17777
|
if (options && options.length > 0) {
|
|
17778
|
+
// Filter options that contain the input value
|
|
17774
17779
|
sug = options === null || options === void 0 ? void 0 : options.filter(function (options) {
|
|
17775
17780
|
return options.label.toLowerCase().includes(e.target.value.toLowerCase());
|
|
17776
|
-
});
|
|
17781
|
+
}); // Filter out items that already exist in tags, unless allowDuplicates flag is true
|
|
17782
|
+
|
|
17783
|
+
if (!allowDuplicates) {
|
|
17784
|
+
sug = sug.filter(function (item) {
|
|
17785
|
+
return !tags.includes(item.value);
|
|
17786
|
+
});
|
|
17787
|
+
}
|
|
17788
|
+
|
|
17777
17789
|
setDropdownArr(sug);
|
|
17778
|
-
}
|
|
17790
|
+
} // Update the input value
|
|
17791
|
+
|
|
17779
17792
|
|
|
17780
17793
|
setTagInputValue(e.target.value);
|
|
17781
17794
|
};
|
|
@@ -17789,18 +17802,50 @@ var InputTag = function InputTag(_a) {
|
|
|
17789
17802
|
dropdownClickedRef.current = false;
|
|
17790
17803
|
};
|
|
17791
17804
|
|
|
17805
|
+
useEffect(function () {
|
|
17806
|
+
var _a; // Filter options based on whether duplicates are allowed or not
|
|
17807
|
+
|
|
17808
|
+
|
|
17809
|
+
if (options && options.length > 0) {
|
|
17810
|
+
var filteredOptions = options.filter(function (option) {
|
|
17811
|
+
return allowDuplicates || !tags.includes(option.value);
|
|
17812
|
+
});
|
|
17813
|
+
setDropdownArr(filteredOptions);
|
|
17814
|
+
} // Set the dropdown offset
|
|
17815
|
+
|
|
17816
|
+
|
|
17817
|
+
showDropdown && setdropdownOffset("".concat((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft, "px"));
|
|
17818
|
+
}, [options, tags, inputRef, allowDuplicates, showDropdown]); // This function handles the click event of a dropdown item
|
|
17819
|
+
|
|
17792
17820
|
var handleDropdownClick = function handleDropdownClick(selectedItem) {
|
|
17793
|
-
setTagInputValue("");
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17821
|
+
setTagInputValue(""); // Set a timeout to add the selected item to the tags after a certain time
|
|
17822
|
+
|
|
17823
|
+
var sto = setTimeout(function () {
|
|
17824
|
+
// If allowDuplicates flag is true or the selected item is not already in the tags, add the item to the tags
|
|
17825
|
+
if (allowDuplicates || !tags.includes(selectedItem.value)) {
|
|
17826
|
+
setTags(function (prev) {
|
|
17827
|
+
return __spreadArray(__spreadArray([], prev, true), [selectedItem.value], false);
|
|
17828
|
+
});
|
|
17829
|
+
} // Add the selected item to the input value and update the displayed value
|
|
17830
|
+
|
|
17831
|
+
|
|
17832
|
+
setValue(function (prev) {
|
|
17833
|
+
return prev.trim() + ", " + selectedItem.value;
|
|
17834
|
+
}); // Call onDropdownClick function if it is defined
|
|
17835
|
+
|
|
17836
|
+
onDropdownClick && onDropdownClick(selectedItem); // Call handleValChange function if it is defined
|
|
17837
|
+
|
|
17838
|
+
handleValChange && handleValChange(value); // Reset focus index and dropdown array
|
|
17839
|
+
|
|
17840
|
+
setFocusIndex(-1);
|
|
17841
|
+
setDropdownArr(options); // Clear the timeout
|
|
17842
|
+
|
|
17843
|
+
sto && clearTimeout(sto);
|
|
17844
|
+
}, 100); // Return a function to clear the timeout when the component unmounts or when a new dropdown item is clicked
|
|
17845
|
+
|
|
17846
|
+
return function () {
|
|
17847
|
+
return sto && clearTimeout(sto);
|
|
17848
|
+
};
|
|
17804
17849
|
};
|
|
17805
17850
|
|
|
17806
17851
|
useEffect(function () {
|
|
@@ -17831,24 +17876,35 @@ var InputTag = function InputTag(_a) {
|
|
|
17831
17876
|
};
|
|
17832
17877
|
|
|
17833
17878
|
var handleBlur = function handleBlur(event) {
|
|
17879
|
+
// create a setTimeout to handle tag input value after a delay
|
|
17834
17880
|
var sto = setTimeout(function () {
|
|
17881
|
+
// if the dropdown was clicked, reset the flag and return
|
|
17835
17882
|
if (dropdownClickedRef.current) {
|
|
17836
17883
|
dropdownClickedRef.current = false;
|
|
17837
17884
|
return;
|
|
17838
|
-
}
|
|
17885
|
+
} // if tag input value is valid and either allowDuplicates flag is true or tag input value is not already in tags, add the tag
|
|
17886
|
+
|
|
17839
17887
|
|
|
17840
|
-
if (Boolean(tagInputValue) && tagInputValue.trim())
|
|
17888
|
+
if (Boolean(tagInputValue) && tagInputValue.trim() && tagInputValue.trim().length > 1 && (allowDuplicates || !tags.includes(tagInputValue.trim())) // check if allowDuplicates flag is true or tagInputValue is not already in tags
|
|
17889
|
+
) {
|
|
17841
17890
|
setTags(__spreadArray(__spreadArray([], tags, true), [tagInputValue.trim()], false));
|
|
17842
17891
|
setValue(tags.filter(Boolean).join(", "));
|
|
17843
|
-
|
|
17844
|
-
|
|
17892
|
+
} // reset tag input value and focus index
|
|
17893
|
+
|
|
17845
17894
|
|
|
17895
|
+
setTagInputValue("");
|
|
17846
17896
|
setFocusIndex(-1);
|
|
17847
|
-
setActive(false);
|
|
17848
|
-
|
|
17897
|
+
setActive(false); // call onBlur function if it exists
|
|
17898
|
+
|
|
17899
|
+
onBlur && onBlur(event); // reset dropdown clicked flag and clear the timeout
|
|
17900
|
+
|
|
17849
17901
|
dropdownClickedRef.current = false;
|
|
17850
17902
|
sto && clearTimeout(sto);
|
|
17851
|
-
},
|
|
17903
|
+
}, 200); // return a cleanup function to clear the timeout if necessary
|
|
17904
|
+
|
|
17905
|
+
return function () {
|
|
17906
|
+
return sto && clearTimeout(sto);
|
|
17907
|
+
};
|
|
17852
17908
|
};
|
|
17853
17909
|
|
|
17854
17910
|
var addEditTags = function addEditTags(e) {
|
|
@@ -17879,12 +17935,16 @@ var InputTag = function InputTag(_a) {
|
|
|
17879
17935
|
var addTags = function addTags(e) {
|
|
17880
17936
|
var ITEM_HEIGHT = 40;
|
|
17881
17937
|
|
|
17882
|
-
if (e.keyCode === 13 && tagInputValue.trim())
|
|
17938
|
+
if (e.keyCode === 13 && tagInputValue.trim() && tagInputValue.trim().length > 1 && (allowDuplicates || !tags.includes(tagInputValue.trim())) // check if allowDuplicates flag is true or tagInputValue is not already in tags
|
|
17939
|
+
) {
|
|
17883
17940
|
setTags(__spreadArray(__spreadArray([], tags, true), [tagInputValue.trim()], false));
|
|
17884
17941
|
setValue(tags.filter(Boolean).join(", "));
|
|
17885
17942
|
setTagInputValue("");
|
|
17886
17943
|
setFocusIndex(-1);
|
|
17887
17944
|
handleValChange && handleValChange(value);
|
|
17945
|
+
} else if (e.keyCode === 13 && tagInputValue.trim().length <= 1) {
|
|
17946
|
+
setTagInputValue("");
|
|
17947
|
+
setFocusIndex(-1);
|
|
17888
17948
|
} //on backspace
|
|
17889
17949
|
|
|
17890
17950
|
|
|
@@ -17957,7 +18017,7 @@ var InputTag = function InputTag(_a) {
|
|
|
17957
18017
|
}
|
|
17958
18018
|
|
|
17959
18019
|
setdropdownOffset("".concat((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft, "px"));
|
|
17960
|
-
}, [editIndex]);
|
|
18020
|
+
}, [editIndex, dropdownArr]);
|
|
17961
18021
|
return jsxRuntime.exports.jsxs("div", __assign({
|
|
17962
18022
|
className: "inputTag hplxt-w-auto hplxt-h-auto hplxt-gap-1 hplxt-p-1.5 hplxt-flex hplxt-flex-wrap hplxt-border-1 hplxt-rounded-lg hplxt-border-Blue_gray-100 hover:hplxt-border-Primary-300 hover:hplxt-shadow-xs-primary ".concat(active ? "hplxt-border-Primary-300 hplxt-shadow-xs-primary" : "", " ").concat(disabled ? "hplxt-bg-Gray-50" : "", " ").concat(className)
|
|
17963
18023
|
}, {
|
|
@@ -17996,7 +18056,7 @@ var InputTag = function InputTag(_a) {
|
|
|
17996
18056
|
}, {
|
|
17997
18057
|
children: content
|
|
17998
18058
|
}))]
|
|
17999
|
-
}, item) : jsxRuntime.exports.jsxs("div", __assign({
|
|
18059
|
+
}, "".concat(item, "+").concat(index)) : jsxRuntime.exports.jsxs("div", __assign({
|
|
18000
18060
|
className: "hplxt-flex hplxt-items-center hplxt-bg-Primary-50 hplxt-border-1 hplxt-rounded hplxt-border-Primary-100 hplxt-py-1 hplxt-px-2"
|
|
18001
18061
|
}, {
|
|
18002
18062
|
children: [jsxRuntime.exports.jsx("button", __assign({
|
|
@@ -18019,7 +18079,7 @@ var InputTag = function InputTag(_a) {
|
|
|
18019
18079
|
return deleteTag(item, index);
|
|
18020
18080
|
}
|
|
18021
18081
|
})]
|
|
18022
|
-
}), item);
|
|
18082
|
+
}), "".concat(item, "+").concat(index));
|
|
18023
18083
|
}), jsxRuntime.exports.jsx("input", __assign({
|
|
18024
18084
|
type: "text",
|
|
18025
18085
|
value: tagInputValue,
|
|
@@ -18058,7 +18118,7 @@ var InputTag = function InputTag(_a) {
|
|
|
18058
18118
|
},
|
|
18059
18119
|
ddRef: ddRef,
|
|
18060
18120
|
setChangeLeft: setChangeLeft
|
|
18061
|
-
}));
|
|
18121
|
+
}), "".concat(option.value, "+").concat(index));
|
|
18062
18122
|
})
|
|
18063
18123
|
})
|
|
18064
18124
|
}))]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { InputTagProps } from "../types";
|
|
3
|
-
declare const InputTag: ({ inputProps, className, dropdownClassName, options, tagList, tagString, handleValChange, onDropdownClick, }: InputTagProps) => JSX.Element;
|
|
3
|
+
declare const InputTag: ({ inputProps, className, dropdownClassName, options, tagList, tagString, handleValChange, onDropdownClick, allowDuplicates, }: InputTagProps) => JSX.Element;
|
|
4
4
|
export default InputTag;
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -436,5 +436,6 @@ export interface InputTagProps {
|
|
|
436
436
|
options?: Array<DropdownItemsProps>;
|
|
437
437
|
inputProps?: React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
438
438
|
handleValChange?: (value: any) => void;
|
|
439
|
+
allowDuplicates?: boolean;
|
|
439
440
|
}
|
|
440
441
|
export {};
|