Profectus-Demo/src/features/milestones/Milestone.vue

125 lines
3.5 KiB
Vue
Raw Normal View History

2021-06-12 04:38:16 +00:00
<template>
<div
v-if="unref(visibility) !== Visibility.None"
:style="[
{
visibility: unref(visibility) === Visibility.Hidden ? 'hidden' : undefined
},
unref(style) ?? {}
]"
:class="{ feature: true, milestone: true, done: unref(earned), ...unref(classes) }"
>
<component :is="unref(comp)" />
<Node :id="id" />
</div>
2021-06-12 04:38:16 +00:00
</template>
2022-01-25 04:25:34 +00:00
<script lang="tsx">
2022-03-04 03:39:48 +00:00
import "components/common/features.css";
import { jsx, StyleValue, Visibility } from "features/feature";
import { GenericMilestone } from "features/milestones/milestone";
import { coerceComponent, isCoercableComponent, processedPropType, unwrapRef } from "util/vue";
import { Component, defineComponent, shallowRef, toRefs, unref, UnwrapRef, watchEffect } from "vue";
import Node from "../../components/Node.vue";
2021-06-12 04:38:16 +00:00
2022-01-25 04:25:34 +00:00
export default defineComponent({
props: {
visibility: {
type: processedPropType<Visibility>(Number),
2022-01-25 04:25:34 +00:00
required: true
},
display: {
type: processedPropType<UnwrapRef<GenericMilestone["display"]>>(
String,
Object,
Function
),
2022-01-25 04:25:34 +00:00
required: true
},
style: processedPropType<StyleValue>(String, Object, Array),
classes: processedPropType<Record<string, boolean>>(Object),
2022-01-25 04:25:34 +00:00
earned: {
type: processedPropType<boolean>(Boolean),
2022-01-25 04:25:34 +00:00
required: true
},
id: {
type: String,
required: true
}
},
components: {
Node
},
2022-01-25 04:25:34 +00:00
setup(props) {
const { display } = toRefs(props);
2022-01-14 04:25:47 +00:00
const comp = shallowRef<Component | string>("");
watchEffect(() => {
const currDisplay = unwrapRef(display);
2022-01-25 04:25:34 +00:00
if (currDisplay == null) {
comp.value = "";
return;
2022-01-25 04:25:34 +00:00
}
if (isCoercableComponent(currDisplay)) {
comp.value = coerceComponent(currDisplay);
return;
2022-01-25 04:25:34 +00:00
}
const Requirement = coerceComponent(currDisplay.requirement, "h3");
const EffectDisplay = coerceComponent(currDisplay.effectDisplay || "", "b");
const OptionsDisplay = coerceComponent(currDisplay.optionsDisplay || "", "span");
comp.value = coerceComponent(
jsx(() => (
<span>
<Requirement />
{currDisplay.effectDisplay ? (
<div>
<EffectDisplay />
</div>
) : null}
{currDisplay.optionsDisplay ? (
<div class="equal-spaced">
<OptionsDisplay />
</div>
) : null}
</span>
))
2022-01-25 04:25:34 +00:00
);
});
return {
comp,
unref,
2022-01-25 04:25:34 +00:00
Visibility
};
}
});
2021-06-12 04:38:16 +00:00
</script>
<style scoped>
.milestone {
width: calc(100% - 10px);
min-width: 120px;
padding-left: 5px;
padding-right: 5px;
background-color: var(--locked);
border-width: 4px;
border-radius: 5px;
color: rgba(0, 0, 0, 0.5);
}
.milestone.done {
background-color: var(--bought);
cursor: default;
2021-06-12 04:38:16 +00:00
}
2022-03-27 18:32:40 +00:00
.milestone :deep(.equal-spaced) {
display: flex;
justify-content: center;
}
2022-03-27 18:32:40 +00:00
.milestone :deep(.equal-spaced > *) {
margin: auto;
}
2021-06-12 04:38:16 +00:00
</style>