aboutsummaryrefslogtreecommitdiffstats
path: root/core/src/components/AppMenuEntry.vue
blob: 9ea999ad1e0c594ec73a49f7902e9c717626646d (plain)
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
<!--
 - SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 - SPDX-License-Identifier: AGPL-3.0-or-later
 -->

<template>
	<li ref="containerElement"
		class="app-menu-entry"
		:class="{
			'app-menu-entry--active': app.active,
			'app-menu-entry--truncated': needsSpace,
		}">
		<a class="app-menu-entry__link"
			:href="app.href"
			:title="app.name"
			:aria-current="app.active ? 'page' : false"
			:target="app.target ? '_blank' : undefined"
			:rel="app.target ? 'noopener noreferrer' : undefined">
			<AppMenuIcon class="app-menu-entry__icon" :app="app" />
			<span ref="labelElement" class="app-menu-entry__label">
				{{ app.name }}
			</span>
		</a>
	</li>
</template>

<script setup lang="ts">
import type { INavigationEntry } from '../types/navigation'
import { onMounted, ref, watch } from 'vue'
import AppMenuIcon from './AppMenuIcon.vue'

const props = defineProps<{
	app: INavigationEntry
}>()

const containerElement = ref<HTMLLIElement>()
const labelElement = ref<HTMLSpanElement>()
const needsSpace = ref(false)

/** Update the space requirements of the app label */
function calculateSize() {
	const maxWidth = containerElement.value!.clientWidth
	// Also keep the 0.5px letter spacing in mind
	needsSpace.value = (maxWidth - props.app.name.length * 0.5) < (labelElement.value!.scrollWidth)
}
// Update size on mounted and when the app name changes
onMounted(calculateSize)
watch(() => props.app.name, calculateSize)
</script>

<style scoped lang="scss">
.app-menu-entry {
	--app-menu-entry-font-size: 12px;
	width: var(--header-height);
	height: var(--header-height);
	position: relative;

	&__link {
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		// Set color as this is shown directly on the background
		color: var(--color-background-plain-text);
		// Make space for focus-visible outline
		width: calc(100% - 4px);
		height: calc(100% - 4px);
		margin: 2px;
	}

	&__label {
		opacity: 0;
		position: absolute;
		font-size: var(--app-menu-entry-font-size);
		// this is shown directly on the background
		color: var(--color-background-plain-text);
		text-align: center;
		bottom: 0;
		inset-inline-start: 50%;
		top: 50%;
		display: block;
		transform: translateX(-50%);
		max-width: 100%;
		text-overflow: ellipsis;
		overflow: hidden;
		letter-spacing: -0.5px;
	}

	&__icon {
		font-size: var(--app-menu-entry-font-size);
	}

	&--active {
		// When hover or focus, show the label and make it bolder than the other entries
		.app-menu-entry__label {
			font-weight: bolder;
		}

		// When active show a line below the entry as an "active" indicator
		&::before {
			content: " ";
			position: absolute;
			pointer-events: none;
			border-bottom-color: var(--color-main-background);
			transform: translateX(-50%);
			width: 10px;
			height: 5px;
			border-radius: 3px;
			background-color: var(--color-background-plain-text);
			inset-inline-start: 50%;
			bottom: 8px;
			display: block;
			transition: all var(--animation-quick) ease-in-out;
			opacity: 1;
		}
	}

	&__icon,
	&__label {
		transition: all var(--animation-quick) ease-in-out;
	}

	// Make the hovered entry bold to see that it is hovered
	&:hover .app-menu-entry__label,
	&:focus-within .app-menu-entry__label {
		font-weight: bold;
	}

	// Adjust the width when an entry is focussed
	// The focussed / hovered entry should grow, while both neighbors need to shrink
	&--truncated:hover,
	&--truncated:focus-within {
		.app-menu-entry__label {
			max-width: calc(var(--header-height) + var(--app-menu-entry-growth));
		}

		// The next entry needs to shrink half the growth
		+ .app-menu-entry {
			.app-menu-entry__label {
				font-weight: normal;
				max-width: calc(var(--header-height) - var(--app-menu-entry-growth));
			}
		}
	}

	// The previous entry needs to shrink half the growth
	&:has(+ .app-menu-entry--truncated:hover),
	&:has(+ .app-menu-entry--truncated:focus-within) {
		.app-menu-entry__label {
			font-weight: normal;
			max-width: calc(var(--header-height) - var(--app-menu-entry-growth));
		}
	}
}
</style>

<style lang="scss">
// Showing the label
.app-menu-entry:hover,
.app-menu-entry:focus-within,
.app-menu__list:hover,
.app-menu__list:focus-within {
	// Move icon up so that the name does not overflow the icon
	.app-menu-entry__icon {
		margin-block-end: 1lh;
	}

	// Make the label visible
	.app-menu-entry__label {
		opacity: 1;
	}

	// Hide indicator when the text is shown
	.app-menu-entry--active::before {
		opacity: 0;
	}

	.app-menu-icon__unread {
		opacity: 0;
	}
}
</style>