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

95 lines
2.5 KiB
Vue
Raw Normal View History

<template>
<button
v-if="unref(visibility) !== Visibility.None"
:class="{ feature: true, tile: true, can: unref(canClick), locked: !unref(canClick) }"
:style="[
{
visibility: unref(visibility) === Visibility.Hidden ? 'hidden' : undefined
},
unref(style) ?? {}
]"
2022-01-13 22:25:47 -06:00
@click="onClick"
@mousedown="start"
@mouseleave="stop"
@mouseup="stop"
2022-05-02 21:10:18 -05:00
@touchstart.passive="start"
@touchend.passive="stop"
@touchcancel.passive="stop"
>
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" />
<Node :id="id" />
</button>
</template>
2022-01-24 22:25:34 -06:00
<script lang="ts">
2022-03-03 21:39:48 -06:00
import "components/common/features.css";
import Node from "components/Node.vue";
2022-03-03 21:39:48 -06:00
import { CoercableComponent, StyleValue, Visibility } from "features/feature";
import {
computeComponent,
computeOptionalComponent,
processedPropType,
setupHoldToClick
2022-03-03 21:39:48 -06:00
} from "util/vue";
import { defineComponent, PropType, toRefs, unref } from "vue";
2022-01-24 22:25:34 -06:00
export default defineComponent({
props: {
visibility: {
type: processedPropType<Visibility>(Number),
2022-01-24 22:25:34 -06:00
required: true
},
2022-03-27 00:14:35 -05:00
onClick: Function as PropType<(e?: MouseEvent | TouchEvent) => void>,
2022-01-24 22:25:34 -06:00
onHold: Function as PropType<VoidFunction>,
display: {
type: processedPropType<CoercableComponent>(Object, String, Function),
2022-01-24 22:25:34 -06:00
required: true
},
title: processedPropType<CoercableComponent>(Object, String, Function),
style: processedPropType<StyleValue>(String, Object, Array),
2022-01-24 22:25:34 -06:00
canClick: {
type: processedPropType<boolean>(Boolean),
2022-01-24 22:25:34 -06:00
required: true
},
id: {
type: String,
required: true
}
},
components: {
Node
},
2022-01-24 22:25:34 -06:00
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
const titleComponent = computeOptionalComponent(title);
const component = computeComponent(display);
2022-01-24 22:25:34 -06:00
return {
start,
stop,
titleComponent,
component,
Visibility,
unref
2022-01-24 22:25:34 -06:00
};
}
});
</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);
}
.tile > * {
pointer-events: none;
}
</style>