From 7ba028a12e4ef6713d7309ae876443c7987c4254 Mon Sep 17 00:00:00 2001 From: mushka Date: Sun, 24 Jul 2022 23:46:02 +0300 Subject: [PATCH] upwork of tagInput dropdown --- .../sub-components/TagInput.js | 156 ++++++------------ 1 file changed, 55 insertions(+), 101 deletions(-) diff --git a/products/ASC.Files/Client/src/components/dialogs/CreateRoomDialog/sub-components/TagInput.js b/products/ASC.Files/Client/src/components/dialogs/CreateRoomDialog/sub-components/TagInput.js index 008da61186..3569b8f0d8 100644 --- a/products/ASC.Files/Client/src/components/dialogs/CreateRoomDialog/sub-components/TagInput.js +++ b/products/ASC.Files/Client/src/components/dialogs/CreateRoomDialog/sub-components/TagInput.js @@ -24,50 +24,18 @@ const StyledTagInput = styled.div` } `; -// const StyledTagDropdown = styled.div` -// display: ${(props) => (props.isOpen ? "flex" : "none")}; -// flex-direction: column; -// padding: 4px 0; -// background: #ffffff; -// border: 1px solid #d0d5da; -// box-shadow: 0px 12px 40px rgba(4, 15, 27, 0.12); -// border-radius: 3px; -// z-index: 400; -// position: absolute; - -// width: 100%; - -// .dropdown-tag { -// cursor: pointer; -// box-sizing: border-box; -// width: 100%; -// padding: 6px 8px; -// font-weight: 400; -// font-size: 13px; -// line-height: 20px; -// outline: none; -// color: #333333; -// &:hover { -// background: #f3f4f4; -// } - -// &-separator { -// height: 1px; -// width: calc(100% - 24px); -// box-sizing: border-box; -// background: #eceef1; -// margin: 3px 12px; -// } -// } -// `; - const TagInput = ({ t, tagHandler, setIsScrollLocked }) => { const [tagInput, setTagInput] = useState(""); const [isOpen, setIsOpen] = useState(false); - const fetchedTags = tagHandler.fetchedTags.filter((tag) => + const chosenTags = tagHandler.tags.map((tag) => tag.name); + const fetchedTags = tagHandler.fetchedTags; + const filteredFetchedTags = fetchedTags.filter((tag) => tag.toLowerCase().includes(tagInput.toLowerCase()) ); + const tagsForDropdown = filteredFetchedTags.filter( + (tag) => !chosenTags.includes(tag) + ); const onTagInputChange = (e) => setTagInput(e.target.value); const preventDefault = (e) => e.preventDefault(); @@ -82,6 +50,10 @@ const TagInput = ({ t, tagHandler, setIsScrollLocked }) => { }; const tagsInputElement = document.getElementById("tags-input"); + + const onClickOutside = () => { + tagsInputElement.blur(); + }; const addNewTag = () => { tagHandler.addTag(tagInput); tagsInputElement.blur(); @@ -93,9 +65,47 @@ const TagInput = ({ t, tagHandler, setIsScrollLocked }) => { const dropdownRef = useRef(null); - const showCreateNewTag = - tagInput && !fetchedTags.find((tag) => tagInput === tag); - const showCreateNewTagSeparator = showCreateNewTag && fetchedTags.length > 0; + let dropdownItems = tagsForDropdown.map((tag, i) => ( + { + addFetchedTag(tag); + console.log(tag); + }} + /> + )); + + if ( + tagInput && + ![...tagsForDropdown, ...chosenTags].find((tag) => tagInput === tag) + ) { + const dropdownItemNewTag = ( + + ); + + if (tagsForDropdown.length > 0) { + dropdownItems = [ + dropdownItemNewTag, + , + ...dropdownItems, + ]; + } else { + dropdownItems = [dropdownItemNewTag, ...dropdownItems]; + } + } + return (
@@ -126,71 +136,15 @@ const TagInput = ({ t, tagHandler, setIsScrollLocked }) => { - {showCreateNewTag && ( - - )} - - {showCreateNewTagSeparator && } - - {fetchedTags.map((fetchedTag, i) => ( - { - addFetchedTag(fetchedTag); - console.log(fetchedTag); - }} - /> - ))} + {dropdownItems} - - {/*
- - {tagInput && !fetchedTags.find((tag) => tagInput === tag) && ( - <> -
- Create tag “{tagInput}” -
- {fetchedTags.length > 0 && ( -
- )} - - )} - {fetchedTags.map((fetchedTag, i) => ( -
addFetchedTag(fetchedTag)} - > - {fetchedTag} -
- ))} -
-
*/} - );