Skip to content

Commit

Permalink
[#20] feat : Bookmark Menu 사라지게 하는 함수 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
choibumsu committed Feb 22, 2021
1 parent 7054d4b commit 0eca3df
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/common/Bookmark/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,29 @@ export type BookmarkProps = {
image: string
}

export const Bookmark: React.FC<BookmarkProps> = ({ name, url, image }) => {
export const Bookmark: React.FC<BookmarkProps> = ({ id, name, url, image }) => {
const menuContianer = useRef<HTMLDivElement>(null)
const [isShowMenu, setIsShowMenu] = useState(false)

const closeMenu = useCallback((e) => {
const bookmarkComponent = e.target.closest('.bookmark')
if (bookmarkComponent && +bookmarkComponent.dataset.component === id) {
return
}

setIsShowMenu(false)
window.removeEventListener('click', closeMenu)
window.removeEventListener('contextmenu', closeMenu)
}, [])

const toggleMenu = (e) => {
e.preventDefault()
if (!menuContianer.current) return

setIsShowMenu(true)
setElementAtCursor(menuContianer.current, e)
window.addEventListener('click', closeMenu)
window.addEventListener('contextmenu', closeMenu)
}

return (
Expand Down

0 comments on commit 0eca3df

Please sign in to comment.