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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
<script lang="ts">
import {defineComponent, PropType} from 'vue';
import {LayoutNode} from '../lib';
// Component holds a tree-node structure representing a tile or tile-group to be rendered
export default defineComponent({
name: 'tile', // Need this to use self in template
props: {
layoutNode: {type: Object as PropType<LayoutNode>, required: true},
isRoot: {type: Boolean, default: false},
// Settings passed in from parent component
transitionDuration: {type: Number, required: true},
headerSz: {type: Number, required: true},
tileSpacing: {type: Number, required: true},
},
data(){
return {
borderRadius: '5px',
leafHeaderHorzSpc: 4,
leafHeaderVertSpc: 2,
leafHeaderColor: '#fafaf9',
expandableLeafHeaderColor: 'greenyellow', //yellow, turquoise,
nonLeafBgColor: '#44403c',
nonLeafHeaderColor: '#fafaf9',
nonLeafHeaderBgColor: '#78716c',
// Used during transitions and to emulate/show an apparently-joined div
zIdx: 0,
overflow: this.isRoot ? 'hidden' : 'visible',
}
},
computed: {
isLeaf(){
return this.layoutNode.children.length == 0;
},
isExpandable(){
return this.layoutNode.tolNode.children.length > this.layoutNode.children;
},
showHeader(){
return (this.layoutNode.showHeader && !this.layoutNode.sepSweptArea) ||
(this.layoutNode.sepSweptArea && this.layoutNode.sepSweptArea.sweptLeft);
},
tileStyles(): Record<string,string> {
return {
// Places div using layoutNode, with centering if root
position: 'absolute',
left: this.isRoot ? '50%' : this.layoutNode.pos[0] + 'px',
top: this.isRoot ? '50%' : this.layoutNode.pos[1] + 'px',
transform: this.isRoot ? 'translate(-50%, -50%)' : 'none',
width: this.layoutNode.dims[0] + 'px',
height: this.layoutNode.dims[1] + 'px',
// Other bindings
transitionDuration: this.transitionDuration + 'ms',
zIndex: String(this.zIdx),
overflow: String(this.overflow),
// Static styles
transitionProperty: 'left, top, width, height',
transitionTimingFunction: 'ease-out',
// CSS variables
'--nonLeafBgColor': this.nonLeafBgColor,
};
},
leafStyles(): Record<string,string> {
return {
width: '100%',
height: '100%',
backgroundImage: 'url(\'/img/' + this.layoutNode.tolNode.name.replaceAll('\'', '\\\'') + '.png\')',
backgroundSize: 'cover',
borderRadius: this.borderRadius,
};
},
leafHeaderStyles(): Record<string,string> {
return {
position: 'absolute',
left: this.leafHeaderHorzSpc + 'px',
top: this.leafHeaderVertSpc + 'px',
maxWidth: (this.layoutNode.dims[0] - this.leafHeaderHorzSpc*2) + 'px',
height: this.headerSz + 'px',
lineHeight: this.headerSz + 'px',
color: this.isExpandable ? this.expandableLeafHeaderColor : this.leafHeaderColor,
// For ellipsis
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
},
nonLeafStyles(): Record<string,string> {
let temp = {
width: '100%',
height: '100%',
backgroundColor: this.nonLeafBgColor,
outline: this.isRoot ? '' : 'black solid 1px',
borderRadius: this.borderRadius,
};
if (this.layoutNode.sepSweptArea != null){
temp = this.layoutNode.sepSweptArea.sweptLeft ?
{...temp, borderRadius: `${this.borderRadius} ${this.borderRadius} ${this.borderRadius} 0`} :
{...temp, borderRadius: `${this.borderRadius} 0 ${this.borderRadius} ${this.borderRadius}`};
}
return temp;
},
nonLeafHeaderStyles(): Record<string,string> {
return {
height: this.headerSz + 'px',
lineHeight: this.headerSz + 'px',
textAlign: 'center',
color: this.nonLeafHeaderColor,
backgroundColor: this.nonLeafHeaderBgColor,
borderRadius: `${this.borderRadius} ${this.borderRadius} 0 0`,
// For ellipsis
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
};
},
sepSweptAreaStyles(): Record<string,string> {
let commonStyles = {
position: 'absolute',
backgroundColor: this.nonLeafBgColor,
outline: 'black solid 1px',
transitionDuration: this.transitionDuration + 'ms',
transitionProperty: 'left, top, width, height',
transitionTimingFunction: 'ease-out',
};
let area = this.layoutNode.sepSweptArea;
if (area == null){
return {
...commonStyles,
visibility: 'hidden',
left: '0',
top: this.headerSz + 'px',
width: '0',
height: '0',
};
} else {
return {
...commonStyles,
left: area.pos[0] + 'px',
top: area.pos[1] + 'px',
width: area.dims[0] + 'px',
height: area.dims[1] + 'px',
borderRadius: area.sweptLeft ?
`${this.borderRadius} 0 0 ${this.borderRadius}` :
`${this.borderRadius} ${this.borderRadius} 0 0`,
};
}
},
},
methods: {
onLeafClick(){
this.$emit('leaf-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);
},
onInnerLeafClicked(node: LayoutNode){
this.$emit('leaf-clicked', node);
},
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(node: LayoutNode){
this.$emit('header-clicked', node);
},
},
});
</script>
<template>
<div :style="tileStyles">
<div v-if="isLeaf" :style="leafStyles" :class="isExpandable ? 'hover:cursor-pointer' : ''" @click="onLeafClick">
<div :style="{borderRadius: this.borderRadius}" class="upper-scrim"/>
<div :style="leafHeaderStyles">{{layoutNode.tolNode.name}}</div>
</div>
<div v-else :style="nonLeafStyles">
<div v-if="showHeader" :style="nonLeafHeaderStyles" class="hover:cursor-pointer" @click="onHeaderClick">
{{layoutNode.tolNode.name}}
</div>
<div :style="sepSweptAreaStyles"
:class="layoutNode?.sepSweptArea?.sweptLeft ? 'hide-right-edge' : 'hide-top-edge'">
<div v-if="layoutNode?.sepSweptArea?.sweptLeft === false"
:style="nonLeafHeaderStyles" class="hover:cursor-pointer" @click="onHeaderClick">
{{layoutNode.tolNode.name}}
</div>
</div>
<tile v-for="child in layoutNode.children" :key="child.tolNode.name" :layoutNode="child"
:headerSz="headerSz" :tileSpacing="tileSpacing" :transitionDuration="transitionDuration"
@leaf-clicked="onInnerLeafClicked" @header-clicked="onInnerHeaderClicked"/>
</div>
</div>
</template>
<style>
.hide-right-edge::before {
content: '';
position: absolute;
background-color: var(--nonLeafBgColor);
right: -1px;
bottom: 0;
width: 1px;
height: 101%;
}
.hide-top-edge::before {
content: '';
position: absolute;
background-color: var(--nonLeafBgColor);
bottom: -1px;
right: 0;
width: 101%;
height: 1px;
}
.upper-scrim {
position: absolute;
top: 0;
height: 50%;
width: 100%;
background-image: linear-gradient(to top, rgba(0,0,0,0), rgba(0,0,0,0.4));
}
</style>
|