aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/components/FavoriteIcon.vue
blob: 4d48b11e579e1e2d88887a64a9f64278ffc2d0ce (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
<!--
  - @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  -
  - @author Ferdinand Thiessen <opensource@fthiessen.de>
  -
  - @license AGPL-3.0-or-later
  -
  - 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/>.
  -
  -->
<template>
	<CustomSvgIconRender class="favorite-marker-icon" :svg="StarSvg" />
</template>

<script>
import StarSvg from '@mdi/svg/svg/star.svg?raw'
import CustomSvgIconRender from './CustomSvgIconRender.vue'

/**
 * A favorite icon to be used for overlaying favorite entries like the file preview / icon
 * It has a stroke around the star icon to ensure enough contrast for accessibility.
 *
 * If the background has a hover state you might want to also apply it to the stroke like this:
 * ```scss
 * .parent:hover :deep(.favorite-marker-icon svg path) {
 *      stroke: var(--color-background-hover);
 * }
 * ```
 */
export default {
	name: 'FavoriteIcon',
	components: {
		CustomSvgIconRender,
	},
	data() {
		return {
			StarSvg,
		}
	},
	mounted() {
		// MDI default viewbox is "0 0 24 24" but we add a stroke of 10px so we must adjust it
		const el = this.$el.querySelector('svg')
		el.setAttribute('viewBox', '-4 -4 30 30')
		el.setAttribute('width', '25')
		el.setAttribute('height', '25')
	},
}
</script>
<style lang="scss" scoped>
.favorite-marker-icon {
	color: #a08b00;
	width: fit-content;
	height: fit-content;

	:deep() {
		svg {
			// We added a stroke for a11y so we must increase the size to include the stroke
			width: 26px;
			height: 26px;

			// Sow a border around the icon for better contrast
			path {
				stroke: var(--color-main-background);
				stroke-width: 8px;
				stroke-linejoin: round;
				paint-order: stroke;
			}
		}
	}
}
</style>