advent22/ui/src/components/MultiModal.vue

80 lines
1.9 KiB
Vue
Raw Normal View History

2022-10-30 02:35:39 +00:00
<template>
<div v-if="state.show !== 'none'" class="modal is-active" @click="dismiss()">
2022-10-30 02:35:39 +00:00
<div class="modal-background" />
<div class="modal-content" style="max-height: 100vh; max-width: 95vw">
<template v-if="state.show === 'loading'">
2023-09-06 18:44:19 +00:00
<progress class="progress is-primary" max="100" />
</template>
<template v-else-if="state.show === 'image'">
2023-09-12 17:42:02 +00:00
<figure>
2023-09-14 03:36:42 +00:00
<figcaption class="tag is-primary">
{{ state.caption }}
2023-09-12 17:42:02 +00:00
</figcaption>
2023-09-20 22:03:32 +00:00
<div class="image is-square">
<img :src="state.src" alt="Kalender-Bild" />
2023-09-20 22:03:32 +00:00
</div>
2023-09-12 17:42:02 +00:00
</figure>
2023-09-06 18:44:19 +00:00
</template>
2022-10-30 02:35:39 +00:00
</div>
2023-11-05 21:37:05 +00:00
<button
v-if="state.show !== 'loading'"
2023-11-05 21:37:05 +00:00
class="modal-close is-large has-background-primary"
/>
2022-10-30 02:35:39 +00:00
</div>
</template>
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
2022-10-30 02:35:39 +00:00
type ModalState =
| { show: "none" }
| { show: "loading" }
| { show: "image"; src: string; caption: string };
2022-10-30 02:35:39 +00:00
const state = ref<ModalState>({ show: "none" });
2023-09-14 14:20:21 +00:00
export type HMultiModal = {
show_image(src: string, caption: string): void;
show_loading(): void;
hide(): void;
};
2023-09-11 23:37:37 +00:00
const emit = defineEmits<{
(event: "handle", handle: HMultiModal): void;
}>();
2022-10-30 02:35:39 +00:00
2025-12-28 16:35:10 +00:00
function hide(): void {
state.value = { show: "none" };
}
2023-11-01 02:00:23 +00:00
2025-12-28 16:35:10 +00:00
function dismiss(): void {
if (state.value.show !== "loading") {
hide();
2023-11-01 02:00:23 +00:00
}
}
2023-11-01 02:00:23 +00:00
onMounted(() => {
emit("handle", {
2025-12-28 16:35:10 +00:00
show_image(src: string, caption: string = ""): void {
state.value = { show: "image", src: src, caption: caption };
},
2025-12-28 16:35:10 +00:00
show_loading(): void {
state.value = { show: "loading" };
},
hide,
});
const on_keydown = (e: KeyboardEvent) => {
if (e.key === "Escape") dismiss();
};
2022-12-21 23:51:01 +00:00
window.addEventListener("keydown", on_keydown);
2023-09-06 18:44:19 +00:00
onBeforeUnmount(() => {
window.removeEventListener("keydown", on_keydown);
});
});
2022-10-30 02:35:39 +00:00
</script>