hplx-react-elements-dev 1.0.76 → 1.0.78
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 +135 -71
- 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,52 @@ 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
|
+
} // Focus on the input element
|
|
17815
|
+
|
|
17816
|
+
|
|
17817
|
+
inputRef.current && inputRef.current.focus(); // Set the dropdown offset
|
|
17818
|
+
|
|
17819
|
+
setdropdownOffset("".concat((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft, "px"));
|
|
17820
|
+
}, [options, tags, inputRef, allowDuplicates]); // This function handles the click event of a dropdown item
|
|
17821
|
+
|
|
17792
17822
|
var handleDropdownClick = function handleDropdownClick(selectedItem) {
|
|
17793
|
-
setTagInputValue("");
|
|
17794
|
-
|
|
17795
|
-
|
|
17796
|
-
|
|
17797
|
-
|
|
17798
|
-
|
|
17799
|
-
|
|
17800
|
-
|
|
17801
|
-
|
|
17802
|
-
|
|
17803
|
-
|
|
17823
|
+
setTagInputValue(""); // Set a timeout to add the selected item to the tags after a certain time
|
|
17824
|
+
|
|
17825
|
+
var sto = setTimeout(function () {
|
|
17826
|
+
// If allowDuplicates flag is true or the selected item is not already in the tags, add the item to the tags
|
|
17827
|
+
if (allowDuplicates || !tags.includes(selectedItem.value)) {
|
|
17828
|
+
setTags(function (prev) {
|
|
17829
|
+
return __spreadArray(__spreadArray([], prev, true), [selectedItem.value], false);
|
|
17830
|
+
});
|
|
17831
|
+
} // Add the selected item to the input value and update the displayed value
|
|
17832
|
+
|
|
17833
|
+
|
|
17834
|
+
setValue(function (prev) {
|
|
17835
|
+
return prev.trim() + ", " + selectedItem.value;
|
|
17836
|
+
}); // Call onDropdownClick function if it is defined
|
|
17837
|
+
|
|
17838
|
+
onDropdownClick && onDropdownClick(selectedItem); // Call handleValChange function if it is defined
|
|
17839
|
+
|
|
17840
|
+
handleValChange && handleValChange(value); // Reset focus index and dropdown array
|
|
17841
|
+
|
|
17842
|
+
setFocusIndex(-1);
|
|
17843
|
+
setDropdownArr(options); // Clear the timeout
|
|
17844
|
+
|
|
17845
|
+
sto && clearTimeout(sto);
|
|
17846
|
+
}, 100); // Return a function to clear the timeout when the component unmounts or when a new dropdown item is clicked
|
|
17847
|
+
|
|
17848
|
+
return function () {
|
|
17849
|
+
return sto && clearTimeout(sto);
|
|
17850
|
+
};
|
|
17804
17851
|
};
|
|
17805
17852
|
|
|
17806
17853
|
useEffect(function () {
|
|
@@ -17831,24 +17878,35 @@ var InputTag = function InputTag(_a) {
|
|
|
17831
17878
|
};
|
|
17832
17879
|
|
|
17833
17880
|
var handleBlur = function handleBlur(event) {
|
|
17881
|
+
// create a setTimeout to handle tag input value after a delay
|
|
17834
17882
|
var sto = setTimeout(function () {
|
|
17883
|
+
// if the dropdown was clicked, reset the flag and return
|
|
17835
17884
|
if (dropdownClickedRef.current) {
|
|
17836
17885
|
dropdownClickedRef.current = false;
|
|
17837
17886
|
return;
|
|
17838
|
-
}
|
|
17887
|
+
} // if tag input value is valid and either allowDuplicates flag is true or tag input value is not already in tags, add the tag
|
|
17839
17888
|
|
|
17840
|
-
|
|
17889
|
+
|
|
17890
|
+
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
|
|
17891
|
+
) {
|
|
17841
17892
|
setTags(__spreadArray(__spreadArray([], tags, true), [tagInputValue.trim()], false));
|
|
17842
17893
|
setValue(tags.filter(Boolean).join(", "));
|
|
17843
|
-
|
|
17844
|
-
}
|
|
17894
|
+
} // reset tag input value and focus index
|
|
17845
17895
|
|
|
17896
|
+
|
|
17897
|
+
setTagInputValue("");
|
|
17846
17898
|
setFocusIndex(-1);
|
|
17847
|
-
setActive(false);
|
|
17848
|
-
|
|
17899
|
+
setActive(false); // call onBlur function if it exists
|
|
17900
|
+
|
|
17901
|
+
onBlur && onBlur(event); // reset dropdown clicked flag and clear the timeout
|
|
17902
|
+
|
|
17849
17903
|
dropdownClickedRef.current = false;
|
|
17850
17904
|
sto && clearTimeout(sto);
|
|
17851
|
-
},
|
|
17905
|
+
}, 200); // return a cleanup function to clear the timeout if necessary
|
|
17906
|
+
|
|
17907
|
+
return function () {
|
|
17908
|
+
return sto && clearTimeout(sto);
|
|
17909
|
+
};
|
|
17852
17910
|
};
|
|
17853
17911
|
|
|
17854
17912
|
var addEditTags = function addEditTags(e) {
|
|
@@ -17877,12 +17935,18 @@ var InputTag = function InputTag(_a) {
|
|
|
17877
17935
|
};
|
|
17878
17936
|
|
|
17879
17937
|
var addTags = function addTags(e) {
|
|
17880
|
-
|
|
17938
|
+
var ITEM_HEIGHT = 40;
|
|
17939
|
+
|
|
17940
|
+
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
|
|
17941
|
+
) {
|
|
17881
17942
|
setTags(__spreadArray(__spreadArray([], tags, true), [tagInputValue.trim()], false));
|
|
17882
17943
|
setValue(tags.filter(Boolean).join(", "));
|
|
17883
17944
|
setTagInputValue("");
|
|
17884
17945
|
setFocusIndex(-1);
|
|
17885
17946
|
handleValChange && handleValChange(value);
|
|
17947
|
+
} else if (e.keyCode === 13 && tagInputValue.trim().length <= 1) {
|
|
17948
|
+
setTagInputValue("");
|
|
17949
|
+
setFocusIndex(-1);
|
|
17886
17950
|
} //on backspace
|
|
17887
17951
|
|
|
17888
17952
|
|
|
@@ -17898,7 +17962,7 @@ var InputTag = function InputTag(_a) {
|
|
|
17898
17962
|
var focusI = focusIndex + 1;
|
|
17899
17963
|
|
|
17900
17964
|
if (wrapperRef && wrapperRef.current) {
|
|
17901
|
-
wrapperRef.current.scrollBy(0,
|
|
17965
|
+
wrapperRef.current.scrollBy(0, ITEM_HEIGHT);
|
|
17902
17966
|
}
|
|
17903
17967
|
|
|
17904
17968
|
setFocusIndex(focusI);
|
|
@@ -17907,11 +17971,11 @@ var InputTag = function InputTag(_a) {
|
|
|
17907
17971
|
|
|
17908
17972
|
|
|
17909
17973
|
if (e.keyCode === 38) {
|
|
17910
|
-
if (focusIndex
|
|
17974
|
+
if (focusIndex > 0) {
|
|
17911
17975
|
var focusI = focusIndex - 1;
|
|
17912
17976
|
|
|
17913
17977
|
if (wrapperRef && wrapperRef.current) {
|
|
17914
|
-
wrapperRef.current.scrollBy(0, -
|
|
17978
|
+
wrapperRef.current.scrollBy(0, -ITEM_HEIGHT);
|
|
17915
17979
|
}
|
|
17916
17980
|
|
|
17917
17981
|
setFocusIndex(focusI);
|
|
@@ -17994,7 +18058,7 @@ var InputTag = function InputTag(_a) {
|
|
|
17994
18058
|
}, {
|
|
17995
18059
|
children: content
|
|
17996
18060
|
}))]
|
|
17997
|
-
}, item) : jsxRuntime.exports.jsxs("div", __assign({
|
|
18061
|
+
}, "".concat(item, "+").concat(index)) : jsxRuntime.exports.jsxs("div", __assign({
|
|
17998
18062
|
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"
|
|
17999
18063
|
}, {
|
|
18000
18064
|
children: [jsxRuntime.exports.jsx("button", __assign({
|
|
@@ -18017,7 +18081,7 @@ var InputTag = function InputTag(_a) {
|
|
|
18017
18081
|
return deleteTag(item, index);
|
|
18018
18082
|
}
|
|
18019
18083
|
})]
|
|
18020
|
-
}), item);
|
|
18084
|
+
}), "".concat(item, "+").concat(index));
|
|
18021
18085
|
}), jsxRuntime.exports.jsx("input", __assign({
|
|
18022
18086
|
type: "text",
|
|
18023
18087
|
value: tagInputValue,
|
|
@@ -18056,7 +18120,7 @@ var InputTag = function InputTag(_a) {
|
|
|
18056
18120
|
},
|
|
18057
18121
|
ddRef: ddRef,
|
|
18058
18122
|
setChangeLeft: setChangeLeft
|
|
18059
|
-
}));
|
|
18123
|
+
}), "".concat(option.value, "+").concat(index));
|
|
18060
18124
|
})
|
|
18061
18125
|
})
|
|
18062
18126
|
}))]
|
|
@@ -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 {};
|