-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement dropdown menu with delete button for nodes list
- Loading branch information
1 parent
aeb9df7
commit e8b2ce3
Showing
7 changed files
with
176 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<template> | ||
<div v-click-outside="{ handler: onClickOutsideMenu, capture: true }" class="relative inline-block text-left"> | ||
|
||
<!-- menu button --> | ||
<div ref="dropdown-button" @click.stop="toggleMenu"> | ||
<slot name="button"/> | ||
</div> | ||
|
||
<!-- drop down menu --> | ||
<Transition | ||
enter-active-class="transition ease-out duration-100" | ||
enter-from-class="transform opacity-0 scale-95" | ||
enter-to-class="transform opacity-100 scale-100" | ||
leave-active-class="transition ease-in duration-75" | ||
leave-from-class="transform opacity-100 scale-100" | ||
leave-to-class="transform opacity-0 scale-95"> | ||
<div v-if="isShowingMenu" @click.stop="hideMenu" class="overflow-hidden absolute right-0 z-10 mr-4 w-56 divide-y divide-gray-100 rounded-md bg-white shadow-lg ring-1 ring-black/5 focus:outline-none" :class="[ dropdownClass ]"> | ||
<slot name="items"/> | ||
</div> | ||
</Transition> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'DropDownMenu', | ||
data() { | ||
return { | ||
isShowingMenu: false, | ||
dropdownClass: null, | ||
}; | ||
}, | ||
methods: { | ||
toggleMenu() { | ||
if(this.isShowingMenu){ | ||
this.hideMenu(); | ||
} else { | ||
this.showMenu(); | ||
} | ||
}, | ||
showMenu() { | ||
this.isShowingMenu = true; | ||
this.adjustDropdownPosition(); | ||
}, | ||
hideMenu() { | ||
this.isShowingMenu = false; | ||
}, | ||
onClickOutsideMenu(event) { | ||
if(this.isShowingMenu){ | ||
event.preventDefault(); | ||
this.hideMenu(); | ||
} | ||
}, | ||
adjustDropdownPosition() { | ||
this.$nextTick(() => { | ||
// find button and dropdown | ||
const button = this.$refs["dropdown-button"]; | ||
const dropdown = button.nextElementSibling; | ||
// do nothing if not found | ||
if(!button || !dropdown){ | ||
return; | ||
} | ||
// get bounding box of button and dropdown | ||
const buttonRect = button.getBoundingClientRect(); | ||
const dropdownRect = dropdown.getBoundingClientRect(); | ||
// calculate how much space is under and above the button | ||
const spaceBelowButton = window.innerHeight - buttonRect.bottom; | ||
const spaceAboveButton = buttonRect.top; | ||
// calculate if there is enough space available to show dropdown | ||
const hasEnoughSpaceAboveButton = spaceAboveButton > dropdownRect.height; | ||
const hasEnoughSpaceBelowButton = spaceBelowButton > dropdownRect.height; | ||
// show dropdown above button | ||
if(hasEnoughSpaceAboveButton && !hasEnoughSpaceBelowButton){ | ||
this.dropdownClass = "bottom-0 mb-12"; | ||
return; | ||
} | ||
// otherwise fallback to showing dropdown below button | ||
this.dropdownClass = "top-0 mt-12"; | ||
}); | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<div class="group flex items-center p-2 text-sm text-gray-700 hover:bg-gray-100 hover:text-gray-900 hover:outline-none"> | ||
|
||
<!-- icon --> | ||
<div class="mr-2 text-gray-400 group-hover:text-gray-500"> | ||
<slot name="icon"/> | ||
</div> | ||
|
||
<!-- label --> | ||
<div> | ||
<slot name="label"/> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'DropDownMenuItem', | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters