Profectus/src/features/trees/TreeNode.vue

123 lines
3.3 KiB
Vue
Raw Normal View History

2022-01-13 22:25:47 -06:00
<template>
2022-04-23 15:23:38 -05:00
<div
v-if="isVisible(visibility)"
:style="{ visibility: isHidden(visibility) ? 'hidden' : undefined }"
2022-01-13 22:25:47 -06:00
:class="{
treeNode: true,
2022-01-24 22:25:34 -06:00
can: unref(canClick),
...unref(classes)
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
>
2022-03-27 10:25:14 -05:00
<div
2022-01-13 22:25:47 -06:00
:style="[
{
2022-01-24 22:25:34 -06:00
backgroundColor: unref(color),
boxShadow: `-4px -4px 4px rgba(0, 0, 0, 0.25) inset, 0 0 20px ${unref(
glowColor
)}`
2022-01-13 22:25:47 -06:00
},
2022-01-24 22:25:34 -06:00
unref(style) ?? []
2022-01-13 22:25:47 -06:00
]"
>
<component :is="unref(comp)" />
2022-03-27 10:25:14 -05:00
</div>
2022-01-24 22:25:34 -06:00
<MarkNode :mark="unref(mark)" />
<Node :id="id" />
2022-04-23 15:23:38 -05:00
</div>
2022-01-13 22:25:47 -06:00
</template>
2022-01-24 22:25:34 -06:00
<script lang="ts">
2022-03-03 21:39:48 -06:00
import MarkNode from "components/MarkNode.vue";
2022-06-26 19:17:22 -05:00
import Node from "components/Node.vue";
import type { CoercableComponent, StyleValue } from "features/feature";
import { isHidden, isVisible, Visibility } from "features/feature";
2022-01-24 22:25:34 -06:00
import {
computeOptionalComponent,
isCoercableComponent,
processedPropType,
2022-04-23 15:23:38 -05:00
setupHoldToClick
2022-03-03 21:39:48 -06:00
} from "util/vue";
2022-06-26 19:17:22 -05:00
import type { PropType } from "vue";
import { defineComponent, toRefs, unref } from "vue";
2022-01-24 22:25:34 -06:00
export default defineComponent({
props: {
display: processedPropType<CoercableComponent>(Object, String, Function),
2022-01-24 22:25:34 -06:00
visibility: {
type: processedPropType<Visibility | boolean>(Number, Boolean),
2022-01-24 22:25:34 -06:00
required: true
},
style: processedPropType<StyleValue>(String, Object, Array),
classes: processedPropType<Record<string, boolean>>(Object),
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>,
color: processedPropType<string>(String),
glowColor: processedPropType<string>(String),
2022-01-24 22:25:34 -06:00
canClick: {
type: processedPropType<boolean>(Boolean),
2022-01-24 22:25:34 -06:00
required: true
},
mark: processedPropType<boolean | string>(Boolean, String),
2022-01-24 22:25:34 -06:00
id: {
type: String,
2022-01-24 22:25:34 -06:00
required: true
2022-04-23 14:28:48 -05:00
}
},
components: {
MarkNode,
Node
2022-01-24 22:25:34 -06:00
},
setup(props) {
2022-04-23 15:23:38 -05:00
const { onClick, onHold, display } = toRefs(props);
2022-01-13 22:25:47 -06:00
const comp = computeOptionalComponent(display);
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
return {
start,
stop,
comp,
2022-01-24 22:25:34 -06:00
unref,
Visibility,
isCoercableComponent,
isVisible,
isHidden
2022-01-24 22:25:34 -06:00
};
}
});
2022-01-13 22:25:47 -06:00
</script>
<style scoped>
.treeNode {
height: 100px;
width: 100px;
border-radius: 50%;
padding: 0;
margin: 0 10px 0 10px;
}
2022-03-27 10:25:14 -05:00
.treeNode > *:first-child {
2022-01-13 22:25:47 -06:00
width: 100%;
height: 100%;
border: 2px solid rgba(0, 0, 0, 0.125);
border-radius: inherit;
font-size: 40px;
color: rgba(0, 0, 0, 0.5);
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.25);
box-shadow: -4px -4px 4px rgba(0, 0, 0, 0.25) inset, 0px 0px 20px var(--background);
2022-03-27 10:25:14 -05:00
display: flex;
2022-01-13 22:25:47 -06:00
}
.treeNode > *:first-child > * {
pointer-events: none;
}
2022-01-13 22:25:47 -06:00
</style>