2024-08-26 19:09:43 +00:00
|
|
|
<!-- eslint-disable vue/multi-word-component-names -->
|
2023-11-10 23:50:43 +00:00
|
|
|
<template>
|
|
|
|
|
<div style="display: none">
|
|
|
|
|
<div v-bind="$attrs" ref="message">
|
|
|
|
|
<slot name="default" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
<script setup lang="ts">
|
2025-12-05 02:12:33 +00:00
|
|
|
import { Options as ToastOptions, toast } from "bulma-toast";
|
2025-12-07 03:28:00 +00:00
|
|
|
import { onMounted, useTemplateRef } from "vue";
|
2024-08-26 19:09:43 +00:00
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
export type HBulmaToast = {
|
|
|
|
|
show(options: ToastOptions): void;
|
|
|
|
|
hide(): void;
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-26 19:09:43 +00:00
|
|
|
const emit = defineEmits<{
|
2025-12-05 02:12:33 +00:00
|
|
|
(event: "handle", handle: HBulmaToast): void;
|
2024-08-26 19:09:43 +00:00
|
|
|
}>();
|
|
|
|
|
|
2025-12-07 03:28:00 +00:00
|
|
|
const message = useTemplateRef("message");
|
2024-08-26 19:09:43 +00:00
|
|
|
|
|
|
|
|
onMounted(() =>
|
2025-12-05 02:12:33 +00:00
|
|
|
emit("handle", {
|
|
|
|
|
show(options: ToastOptions = {}) {
|
2024-08-26 19:09:43 +00:00
|
|
|
if (!(message.value instanceof HTMLElement)) return;
|
|
|
|
|
|
2025-12-05 02:12:33 +00:00
|
|
|
toast({
|
2024-08-26 19:09:43 +00:00
|
|
|
...options,
|
|
|
|
|
single: true,
|
|
|
|
|
message: message.value,
|
|
|
|
|
});
|
|
|
|
|
},
|
2025-12-05 02:12:33 +00:00
|
|
|
hide() {
|
2025-12-07 03:28:00 +00:00
|
|
|
if (message.value === null) return;
|
2024-08-26 19:09:43 +00:00
|
|
|
|
|
|
|
|
const toast_div = message.value.parentElement;
|
2025-12-07 03:28:00 +00:00
|
|
|
if (toast_div === null) return;
|
2024-08-26 19:09:43 +00:00
|
|
|
|
|
|
|
|
const dbutton = toast_div.querySelector("button.delete");
|
|
|
|
|
if (!(dbutton instanceof HTMLButtonElement)) return;
|
|
|
|
|
|
|
|
|
|
dbutton.click();
|
|
|
|
|
},
|
2025-12-05 02:12:33 +00:00
|
|
|
}),
|
2024-08-26 19:09:43 +00:00
|
|
|
);
|
2023-11-10 23:50:43 +00:00
|
|
|
</script>
|