-
Notifications
You must be signed in to change notification settings - Fork 90
/
NcAppNavigation.vue
202 lines (174 loc) · 4.93 KB
/
NcAppNavigation.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
192
193
194
195
196
197
198
199
200
201
202
<!--
- @copyright Copyright (c) 2019 Christoph Wurst <[email protected]>
-
- @author Christoph Wurst <[email protected]>
- @author John Molakvoæ <[email protected]>
- @author Marco Ambrosini <[email protected]>
-
- @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 }">
<NcAppNavigationToggle :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 NcAppNavigationToggle from '../NcAppNavigationToggle/index.js'
import isMobile from '../../mixins/isMobile/index.js'
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
export default {
name: 'NcAppNavigation',
components: {
NcAppNavigationToggle,
},
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 {
// Set scoped variable override
// Using --color-text-maxcontrast as a fallback evaluates to an invalid value as it references itself in this scope instead of the variable defined higher up
--color-text-maxcontrast: var(--color-text-maxcontrast-background-blur, var(--color-text-maxcontrast-default));
transition: transform var(--animation-quick), margin var(--animation-quick);
width: $navigation-width;
position: relative;
top: 0;
left: 0;
padding: 0px;
// Above appcontent
z-index: 1800;
height: 100%;
box-sizing: border-box;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
display: flex;
flex-direction: column;
flex-grow: 0;
flex-shrink: 0;
background-color: var(--color-main-background-blur, var(--color-main-background));
-webkit-backdrop-filter: var(--filter-background-blur, none);
backdrop-filter: var(--filter-background-blur, none);
&--close {
transform: translateX(-100%);
position: absolute;
}
//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;
gap: var(--default-grid-baseline, 4px);
padding: calc(var(--default-grid-baseline, 4px) * 2);
}
}
// 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) {
position: absolute;
}
}
// Put the toggle behind appsidebar on small screens
@media only screen and (max-width: math.div($breakpoint-mobile, 2)) {
.app-navigation {
z-index: 1400;
}
}
</style>