Profectus-Demo/src/components/features/GridCell.vue

82 lines
2.2 KiB
Vue
Raw Normal View History

<template>
<button
2022-01-13 22:25:47 -06:00
v-if="visibility !== Visibility.None"
v-show="visibility === Visibility.Visible"
:class="{ feature: true, tile: true, can: canClick, locked: !canClick }"
:style="style"
2022-01-13 22:25:47 -06:00
@click="onClick"
@mousedown="start"
@mouseleave="stop"
@mouseup="stop"
@touchstart="start"
@touchend="stop"
@touchcancel="stop"
:disabled="!canClick"
>
2022-01-13 22:25:47 -06:00
<div v-if="title"><component :is="titleComponent" /></div>
2022-01-24 22:23:30 -06:00
<component :is="component" style="white-space: pre-line" />
2022-01-13 22:25:47 -06:00
<LinkNode :id="id" />
</button>
</template>
2022-01-24 22:25:34 -06:00
<script lang="ts">
import { CoercableComponent, StyleValue, Visibility } from "@/features/feature";
2022-01-13 22:25:47 -06:00
import { coerceComponent, setupHoldToClick } from "@/util/vue";
2022-01-24 22:25:34 -06:00
import { computed, defineComponent, PropType, toRefs, unref } from "vue";
2022-01-13 22:25:47 -06:00
import LinkNode from "../system/LinkNode.vue";
2022-01-24 22:25:34 -06:00
export default defineComponent({
props: {
visibility: {
type: Object as PropType<Visibility>,
required: true
},
onClick: Function as PropType<VoidFunction>,
onHold: Function as PropType<VoidFunction>,
display: {
type: [Object, String] as PropType<CoercableComponent>,
required: true
},
title: [Object, String] as PropType<CoercableComponent>,
style: Object as PropType<StyleValue>,
canClick: {
type: Boolean,
required: true
},
id: {
type: String,
required: true
}
},
setup(props) {
const { onClick, onHold, title, display } = toRefs(props);
2022-01-13 22:25:47 -06:00
2022-01-24 22:25:34 -06:00
const { start, stop } = setupHoldToClick(onClick, onHold);
2022-01-13 22:25:47 -06:00
2022-01-24 22:25:34 -06:00
const titleComponent = computed(() => {
const currTitle = unref(title);
return currTitle && coerceComponent(currTitle);
});
const component = computed(() => coerceComponent(unref(display)));
return {
start,
stop,
titleComponent,
component,
Visibility,
LinkNode
};
}
});
</script>
<style scoped>
.tile {
min-height: 80px;
width: 80px;
font-size: 10px;
2022-01-13 22:25:47 -06:00
background-color: var(--layer-color);
}
</style>