-
Notifications
You must be signed in to change notification settings - Fork 88
/
AppNavigation.vue
191 lines (164 loc) · 4.37 KB
/
AppNavigation.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!--
- @copyright Copyright (c) 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
-
- @author Christoph Wurst <christoph@winzerhof-wurst.at>
- @author John Molakvoæ <skjnldsv@protonmail.com>
- @author Marco Ambrosini <marcoambrosini@pm.me>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-->
<docs>
The navigation bar can be open and closed from anywhere in the app using the
nextcloud event bus.
### Install the event bus package
```bash
npm i -S @nextcloud/event-bus
```
### Usage
#### Open the navigation
```js static
import { emit } from '@nextcloud/event-bus'
emit('toggle-navigation', {
open: true,
})
```
#### Close the navigation
```js static
import { emit } from '@nextcloud/event-bus'
emit('toggle-navigation', {
open: false,
})
```
</docs>
<template>
<div id="app-navigation-vue"
class="app-navigation"
role="navigation"
:class="{'app-navigation--close':!open }">
<AppNavigationToggle :open="open" @update:open="toggleNavigation" />
<slot />
<!-- List for Navigation li-items -->
<ul class="app-navigation__list">
<slot name="list" />
</ul>
<!-- Footer for e.g. AppNavigationSettings -->
<slot name="footer" />
</div>
</template>
<script>
import AppNavigationToggle from '../AppNavigationToggle/index.js'
import isMobile from '../../mixins/isMobile/index.js'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
export default {
name: 'AppNavigation',
components: {
AppNavigationToggle,
},
mixins: [isMobile],
data() {
return {
open: true,
}
},
watch: {
isMobile() {
this.open = !this.isMobile
},
},
mounted() {
subscribe('toggle-navigation', this.toggleNavigationByEventBus)
// Emit an event with the initial state of the navigation
emit('navigation-toggled', {
open: this.open,
})
},
unmounted() {
this.mc.off('swipeleft swiperight')
this.mc.destroy()
unsubscribe('toggle-navigation', this.toggleNavigationByEventBus)
},
methods: {
/**
* Toggle the navigation
*
* @param {boolean} [state] set the state instead of inverting the current one
*/
toggleNavigation(state) {
this.open = (typeof state === 'undefined') ? !this.open : state
const bodyStyles = getComputedStyle(document.body)
const animationLength = parseInt(bodyStyles.getPropertyValue('--animation-quick')) || 100
setTimeout(() => {
emit('navigation-toggled', {
open: this.open,
})
// We wait for 1.5 times the animation length to give the animation time to really finish.
}, 1.5 * animationLength)
},
toggleNavigationByEventBus({ open }) {
this.toggleNavigation(open)
},
},
}
</script>
<style lang="scss" scoped>
.app-navigation {
will-change: transform;
transition: transform var(--animation-quick), margin var(--animation-quick);
width: $navigation-width;
position: sticky;
position: -webkit-sticky;
top: $header-height;
left: 0;
padding: 4px;
// Above appcontent
z-index: 1800;
height: calc(100vh - #{$header-height});
box-sizing: border-box;
background-color: var(--color-main-background);
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
border-right: 1px solid var(--color-border);
display: flex;
flex-direction: column;
flex-grow: 0;
flex-shrink: 0;
&--close {
margin-left: - $navigation-width;
transform: translateX(-100%);
}
//list of navigation items
ul,
&__list {
position: relative;
height: 100%;
width: 100%;
overflow-x: hidden;
overflow-y: auto;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
}
// When on mobile, we make the navigation slide over the appcontent
@media only screen and (max-width: $breakpoint-mobile) {
.app-navigation:not(.app-navigation--close) {
margin-left: - $navigation-width;
}
}
</style>