Skip to content

Commit

Permalink
Add an overlay when the app navigation is open
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Robitaille <mail@marcelrobitaille.me>
  • Loading branch information
MarcelRobitaille committed Oct 14, 2022
1 parent 8719b9b commit 5518486
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@nextcloud/axios": "^2.0.0",
"@nextcloud/event-bus": "3.0.2",
"@nextcloud/moment": "^1.1.1",
"@nextcloud/router": "^2.0.0",
"@nextcloud/vue": "^5.1.0",
Expand Down
82 changes: 82 additions & 0 deletions src/components/AppMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@
<router-view></router-view>
</div>
</div>
<div
v-if="isMobile"
class="navigation-overlay"
:class="{ 'stay-open': isNavigationOpen }"
@click="closeNavigation"
/>
</AppContent>
</Content>
</template>

<script>
import isMobile from "@nextcloud/vue/dist/Mixins/isMobile"
import AppContent from "@nextcloud/vue/dist/Components/AppContent"
import Content from "@nextcloud/vue/dist/Components/Content"
import AppControls from "cookbook/components/AppControls/AppControls.vue"
import { emit, subscribe, unsubscribe } from "@nextcloud/event-bus"
import AppNavi from "./AppNavi.vue"
export default {
Expand All @@ -27,13 +35,36 @@ export default {
// eslint-disable-next-line vue/no-reserved-component-names
Content,
},
mixins: [isMobile],
data() {
return {
isNavigationOpen: false,
}
},
watch: {
/* This is left here as an example in case the routes need to be debugged again
'$route' (to, from) {
console.log(this.$window.isSameBaseRoute(from.fullPath, to.fullPath))
},
*/
},
mounted() {
subscribe("navigation-toggled", this.updateAppNavigationOpen)
},
unmounted() {
unsubscribe("navigation-toggled", this.updateAppNavigationOpen)
},
methods: {
/**
* Listen for event-bus events about the app navigation opening and closing
*/
updateAppNavigationOpen({ open }) {
this.isNavigationOpen = open
},
closeNavigation() {
emit("toggle-navigation", { open: false })
},
},
}
</script>

Expand All @@ -47,6 +78,57 @@ export default {
position: relative;
z-index: 0;
}
/**
* The open event is only emitted when the animation stops
* In order to match their animation, we need to start fading in the overlay
* as soon as the .app-navigation--close` class goes away
* using a sibling selector
*
* We still need to listen for events to help us close the overlay.
* We cannot set `display: none` in an animation.
* We need to start fading out when the .app-navigation--close` class comes back,
* and use the close event that fired when the animation stops to reset
* `display: none`
*/
.navigation-overlay {
position: absolute;
/* Top bar has z-index 2 */
z-index: 3;
display: none;
animation: fade-out var(--animation-quick) forwards;
background: rgba(0, 0, 0, 0.5);
cursor: pointer;
inset: 0;
}
.navigation-overlay.stay-open {
display: block;
}
#app-navigation-vue:not(.app-navigation--close)
+ #app-content-vue
.navigation-overlay {
display: block;
animation: fade-in var(--animation-quick) forwards;
}
@keyframes fade-in {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
@keyframes fade-out {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
</style>

<style>
Expand Down

0 comments on commit 5518486

Please sign in to comment.