aboutsummaryrefslogtreecommitdiff
path: root/src/components/TileImg.vue
blob: 1d83b37bd80ec57d0fe773ee1fe262ce9343963c (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
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import {LayoutNode} from '../lib';

export default defineComponent({
	props: {
		layoutNode: {type: Object as PropType<LayoutNode>, required: true},
		tileSz: {type: Number, required: true}, //px (edge length)
		options: {type: Object, required: true},
	},
	data(){
		return {
			highlight: false,
			infoMouseOver: false,
		};
	},
	computed: {
		isExpandable(){
			return this.layoutNode.tolNode.children.length > 0;
		},
		styles(): Record<string,string> {
			return {
				// Sizing
				width: this.tileSz + 'px',
				height: this.tileSz + 'px',
				minWidth: this.tileSz + 'px',
				minHeight: this.tileSz + 'px',
				// Image
				backgroundImage:
					'linear-gradient(to bottom, rgba(0,0,0,0.4), rgba(0,0,0,0) 40%, rgba(0,0,0,0) 60%, rgba(0,0,0,0.4) 100%),' +
					'url(\'/img/' + this.layoutNode.tolNode.name.replaceAll('\'', '\\\'') + '.png\')',
				backgroundSize: 'cover',
				// Child layout
				display: 'flex',
				flexDirection: 'column',
				// Other
				borderRadius: this.options.borderRadius + 'px',
				boxShadow: this.highlight ? this.options.shadowHighlight : this.options.shadowNormal,
			};
		},
		headerStyles(): Record<string,string> {
			return {
				height: (this.options.imgTileFontSz + this.options.imgTilePadding * 2) + 'px',
				lineHeight: this.options.imgTileFontSz + 'px',
				fontSize: this.options.imgTileFontSz + 'px',
				padding: this.options.imgTilePadding + 'px',
				color: this.isExpandable ? this.options.expandableImgTileColor : this.options.imgTileColor,
				// For ellipsis
				overflow: 'hidden',
				textOverflow: 'ellipsis',
				whiteSpace: 'nowrap',
			};
		},
		infoIconStyles(): Record<string,string> {
			return {
				width: this.options.infoIconSz + 'px',
				height: this.options.infoIconSz + 'px',
				marginTop: 'auto',
				marginBottom: this.options.infoIconPadding + 'px',
				marginRight: this.options.infoIconPadding + 'px',
				alignSelf: 'flex-end',
				color: this.infoMouseOver ? this.options.infoIconHoverColor : this.options.infoIconColor,
			};
		},
	},
	methods: {
		onMouseEnter(evt: Event){
			if (this.isExpandable){
				this.highlight = true;
			}
		},
		onMouseLeave(evt: Event){
			if (this.isExpandable){
				this.highlight = false;
			}
		},
		onMouseDown(evt: Event){
			this.highlight = false;
		},
		onInfoMouseEnter(evt: Event){
			this.infoMouseOver = true;
		},
		onInfoMouseLeave(evt: Event){
			this.infoMouseOver = false;
		},
		onInfoClick(evt: Event){
			this.$emit('info-icon-clicked', this.layoutNode);
		},
	},
	emits: ['info-icon-clicked'],
});
</script>

<template>
<div :style="styles" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave" @mousedown="onMouseDown"
	:class="isExpandable ? ['hover:cursor-pointer'] : []">
	<h1 :style="headerStyles">{{layoutNode.tolNode.name}}</h1>
	<svg :style="infoIconStyles" class="hover:cursor-pointer"
		@mouseenter="onInfoMouseEnter" @mouseleave="onInfoMouseLeave"
		@click.stop="onInfoClick" @mousedown.stop @mouseup.stop
		xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
		stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
		<circle cx="12" cy="12" r="10"/>
		<line x1="12" y1="16" x2="12" y2="12"/>
		<line x1="12" y1="8" x2="12.01" y2="8"/>
	</svg>
</div>
</template>