chromatic-lattice/src/components/features/Clickable.vue

80 lines
1.9 KiB
Vue
Raw Normal View History

2021-06-12 04:38:16 +00:00
<template>
<div v-if="clickable.unlocked">
2021-06-25 03:15:10 +00:00
<button :style="style" @click="clickable.click" @mousedown="start" @mouseleave="stop" @mouseup="stop" @touchstart="start"
@touchend="stop" @touchcancel="stop" :disabled="!clickable.canClick"
:class="{ feature: true, [layer || tab.layer]: true, clickable: true, can: clickable.canClick, locked: !clickable.canClick }">
2021-07-02 09:50:44 +00:00
<div v-if="title">
<component :is="title" />
2021-06-12 04:38:16 +00:00
</div>
2021-07-02 09:50:44 +00:00
<component :is="display" style="white-space: pre-line;" />
2021-06-12 04:38:16 +00:00
<mark-node :mark="clickable.mark" />
<branch-node :branches="clickable.branches" :id="id" featureType="clickable" />
</button>
</div>
</template>
<script>
import { layers } from '../../store/layers';
import { coerceComponent } from '../../util/vue';
export default {
name: 'clickable',
inject: [ 'tab' ],
props: {
2021-06-25 03:15:10 +00:00
layer: String,
2021-06-12 04:38:16 +00:00
id: [ Number, String ],
size: {
type: [ Number, String ]
}
},
data() {
return {
interval: false,
time: 0
};
},
computed: {
clickable() {
return layers[this.layer || this.tab.layer].clickables[this.id];
},
style() {
return [
this.clickable.canClick ? { 'background-color': layers[this.layer || this.tab.layer].color } : {},
this.size ? {'height': this.size, 'width': this.size} : {},
layers[this.layer || this.tab.layer].componentStyles?.clickable,
this.clickable.style
];
},
2021-07-02 09:50:44 +00:00
title() {
if (this.clickable.title) {
return coerceComponent(this.clickable.title, 'h2');
2021-06-12 04:38:16 +00:00
}
return null;
},
2021-07-02 09:50:44 +00:00
display() {
return coerceComponent(this.clickable.display, 'div');
2021-06-12 04:38:16 +00:00
}
},
methods: {
start() {
if (!this.interval) {
this.interval = setInterval(this.clickable.click, 250);
}
},
stop() {
clearInterval(this.interval);
this.interval = false;
this.time = 0;
}
}
};
</script>
<style scoped>
2021-06-25 03:15:10 +00:00
.clickable {
min-height: 120px;
width: 120px;
font-size: 10px;
}
2021-06-12 04:38:16 +00:00
</style>