aboutsummaryrefslogtreecommitdiff
path: root/src/components/TileImg.vue
blob: be6704c6f7be4187ac804232bf763dab66c57eac (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
<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,
		};
	},
	computed: {
		isExpandable(){
			return this.layoutNode.tolNode.children.length > 0;
		},
		styles(): Record<string,string> {
			return {
				border: '1px black solid',
				width: this.tileSz + 'px',
				height: this.tileSz + 'px',
				minWidth: this.tileSz + 'px',
				minHeight: this.tileSz + 'px',
				backgroundImage:
					'linear-gradient(to bottom, rgba(0,0,0,0.4), rgba(0,0,0,0) 40%),' +
					'url(\'/img/' + this.layoutNode.tolNode.name.replaceAll('\'', '\\\'') + '.png\')',
				backgroundSize: 'cover',
				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',
			};
		},
	},
	methods: {
		onMouseEnter(evt: Event){
			if (this.isExpandable){
				this.highlight = true;
			}
		},
		onMouseLeave(evt: Event){
			if (this.isExpandable){
				this.highlight = false; }
		},
		onClick(evt: Event){
			if (this.isExpandable){
				this.highlight = false;
			}
		},
	},
});
</script>

<template>
<div :style="styles" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave" @click="onClick"
	:class="isExpandable ? ['hover:cursor-pointer'] : []">
	<h1 :style="headerStyles">{{layoutNode.tolNode.name}}</h1>
</div>
</template>