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

const TRANSITION_DURATION = 300;
export default defineComponent({
	name: 'tile',
	data(){
		return {
			zIdx: 0,
			transitionDuration: TRANSITION_DURATION,
			overFlow: 'visible',
		}
	},
	props: {
		layoutNode: {type: Object as PropType<LayoutNode>, required: true},
	},
	computed: {
		name(){return this.layoutNode.tolNode.name.replaceAll('\'', '\\\'')}
	},
	methods: {
		onImgClick(){
			this.$emit('tile-clicked', [this.layoutNode]);
			//increase z-index and hide overflow during transition
			this.zIdx = 1;
			this.overFlow = 'hidden';
			setTimeout(() => {this.zIdx = 0; this.overFlow = 'visible'}, this.transitionDuration);
		},
		onInnerTileClicked(nodeList: LayoutNode[]){
			this.$emit('tile-clicked', [...nodeList, this.layoutNode]);
		},
		onHeaderClick(){
			this.$emit('header-clicked', [this.layoutNode]);
			//increase z-index and hide overflow during transition
			this.zIdx = 1;
			this.overFlow = 'hidden';
			setTimeout(() => {this.zIdx = 0; this.overFlow = 'visible'}, this.transitionDuration);
		},
		onInnerHeaderClicked(nodeList: LayoutNode[]){
			this.$emit('header-clicked', [...nodeList, this.layoutNode]);
		}
	}
})
</script>

<template>
<div
	:style="{position: 'absolute',
		left: layoutNode.x+'px', top: layoutNode.y+'px', width: layoutNode.w+'px', height: layoutNode.h+'px',
		zIndex: zIdx, overflow: overFlow, transitionDuration: transitionDuration+'ms'}"
	class="transition-[left,top,width,height] ease-out border border-stone-900 bg-white">
	<div v-if="layoutNode.children.length == 0"
		:style="{backgroundImage: 'url(\'/img/' + name + '.jpg\')',
			opacity: (layoutNode.tolNode.children.length > 0 ? 1 : 0.7)}"
		class="hover:cursor-pointer w-full h-full bg-cover" @click="onImgClick"
		/>
	<div v-else>
		<div
			v-if="(layoutNode.headerSz && !layoutNode.sepSweptArea) || 
				(layoutNode.sepSweptArea && layoutNode.sepSweptArea.sweptLeft)"
			:style="{height: layoutNode.headerSz+'px'}"
			class="text-center hover:cursor-pointer bg-stone-300" @click="onHeaderClick">
			{{layoutNode.tolNode.name}}
		</div>
		<div v-if="layoutNode.sepSweptArea"
			:style="{position: 'absolute', left: layoutNode.sepSweptArea.x+'px', top: layoutNode.sepSweptArea.y+'px',
				width: (layoutNode.sepSweptArea.w +
					(layoutNode.sepSweptArea.sweptLeft ? layoutNode.sepSweptArea.tileSpacing+1 : 0))+'px',
				height: (layoutNode.sepSweptArea.h +
					(layoutNode.sepSweptArea.sweptLeft ? 0 : layoutNode.sepSweptArea.tileSpacing+1))+'px',
				borderRightColor: (layoutNode.sepSweptArea.sweptLeft ? 'white' : 'currentColor'),
				borderBottomColor: (layoutNode.sepSweptArea.sweptLeft ? 'currentColor' : 'white'),
				transitionDuration: transitionDuration+'ms'}"
			class="transition-[left,top,width,height] ease-out border border-stone-900 bg-white">
			<div v-if="!layoutNode.sepSweptArea.sweptLeft" :style="{height: layoutNode.headerSz+'px'}"
				class="text-center hover:cursor-pointer bg-stone-300" @click="onHeaderClick">
				{{layoutNode.tolNode.name}}
			</div>
		</div>
		<tile v-for="child in layoutNode.children" :key="child.tolNode.name" :layoutNode="child"
			@tile-clicked="onInnerTileClicked" @header-clicked="onInnerHeaderClicked"
			></tile>
	</div>
</div>
</template>