|
3 | 3 | - SPDX-License-Identifier: AGPL-3.0-or-later
|
4 | 4 | -->
|
5 | 5 |
|
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' |
20 | 8 | 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' |
21 | 12 | import { useIsMobile } from '../../composables/useIsMobile/index.js'
|
22 |
| -import { isRtl } from '../../utils/rtl.ts' |
23 | 13 | import { t } from '../../l10n.js'
|
24 | 14 |
|
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 }) |
31 | 17 |
|
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 | +}) |
43 | 23 |
|
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' : '' |
57 | 33 |
|
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 }) |
61 | 37 | }
|
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 | + } |
77 | 39 | }
|
78 | 40 | </script>
|
79 | 41 |
|
| 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 | + |
80 | 54 | <style lang="scss" scoped>
|
81 | 55 | .app-details-toggle {
|
82 | 56 | position: sticky;
|
|
0 commit comments