Skip to content

Commit 59f5fb8

Browse files
authored
Merge pull request #6909 from nextcloud-libraries/refactor/nc-app-details-toggle-ts
refactor(NcAppDetailsToggle): migrate to Typescript
2 parents c1faff3 + 7bde0c2 commit 59f5fb8

File tree

1 file changed

+37
-63
lines changed

1 file changed

+37
-63
lines changed

src/components/NcAppContent/NcAppDetailsToggle.vue

+37-63
Original file line numberDiff line numberDiff line change
@@ -3,80 +3,54 @@
33
- SPDX-License-Identifier: AGPL-3.0-or-later
44
-->
55

6-
<template>
7-
<NcButton :aria-label="title"
8-
class="app-details-toggle"
9-
:class="{ 'app-details-toggle--mobile': isMobile }"
10-
:title
11-
variant="tertiary">
12-
<template #icon>
13-
<ArrowLeft v-if="isRtl" :size="20" />
14-
<ArrowRight v-else :size="20" />
15-
</template>
16-
</NcButton>
17-
</template>
18-
19-
<script>
6+
<script setup lang="ts">
7+
import { mdiArrowRight } from '@mdi/js'
208
import { emit } from '@nextcloud/event-bus'
9+
import { onBeforeUnmount, watch } from 'vue'
10+
import NcButton from '../NcButton/index.ts'
11+
import NcIconSvgWrapper from '../NcIconSvgWrapper/index.js'
2112
import { useIsMobile } from '../../composables/useIsMobile/index.js'
22-
import { isRtl } from '../../utils/rtl.ts'
2313
import { t } from '../../l10n.js'
2414

25-
import ArrowRight from 'vue-material-design-icons/ArrowRight.vue'
26-
import ArrowLeft from 'vue-material-design-icons/ArrowLeft.vue'
27-
import NcButton from '../NcButton/index.ts'
28-
29-
export default {
30-
name: 'NcAppDetailsToggle',
15+
const isMobile = useIsMobile()
16+
watch(isMobile, toggleAppNavigationButton, { immediate: true })
3117

32-
components: {
33-
ArrowRight,
34-
ArrowLeft,
35-
NcButton,
36-
},
37-
setup() {
38-
return {
39-
isRtl,
40-
isMobile: useIsMobile(),
41-
}
42-
},
18+
onBeforeUnmount(() => {
19+
if (isMobile.value) {
20+
toggleAppNavigationButton(false)
21+
}
22+
})
4323

44-
computed: {
45-
title() {
46-
return t('Go back to the list')
47-
},
48-
},
49-
watch: {
50-
isMobile: {
51-
immediate: true,
52-
handler() {
53-
this.toggleAppNavigationButton(this.isMobile)
54-
},
55-
},
56-
},
24+
/**
25+
* Toggle the app navigation button and hide it if needed.
26+
*
27+
* @param hide - if true the navigation toggle is visually hidden
28+
*/
29+
function toggleAppNavigationButton(hide = true) {
30+
const appNavigationToggle = document.querySelector<HTMLElement>('.app-navigation .app-navigation-toggle')
31+
if (appNavigationToggle) {
32+
appNavigationToggle.style.display = hide ? 'none' : ''
5733

58-
beforeUnmount() {
59-
if (this.isMobile) {
60-
this.toggleAppNavigationButton(false)
34+
// If we hide the NavigationToggle, we need to make sure the Navigation is also closed
35+
if (hide === true) {
36+
emit('toggle-navigation', { open: false })
6137
}
62-
},
63-
64-
methods: {
65-
toggleAppNavigationButton(hide = true) {
66-
const appNavigationToggle = document.querySelector('.app-navigation .app-navigation-toggle')
67-
if (appNavigationToggle) {
68-
appNavigationToggle.style.display = hide ? 'none' : null
69-
70-
// If we hide the NavigationToggle, we need to make sure the Navigation is also closed
71-
if (hide === true) {
72-
emit('toggle-navigation', { open: false })
73-
}
74-
}
75-
},
76-
},
38+
}
7739
}
7840
</script>
7941

42+
<template>
43+
<NcButton :aria-label="t('Go back to the list')"
44+
class="app-details-toggle"
45+
:class="{ 'app-details-toggle--mobile': isMobile }"
46+
:title="t('Go back to the list')"
47+
variant="tertiary">
48+
<template #icon>
49+
<NcIconSvgWrapper directional :path="mdiArrowRight" />
50+
</template>
51+
</NcButton>
52+
</template>
53+
8054
<style lang="scss" scoped>
8155
.app-details-toggle {
8256
position: sticky;

0 commit comments

Comments
 (0)