74 lines
1.9 KiB
Vue
74 lines
1.9 KiB
Vue
<template>
|
|
<div class="position-fixed bottom-0 end-0 p-3">
|
|
<div
|
|
ref="toastMessage"
|
|
:class="{
|
|
'toast': true,
|
|
'd-flex': !title,
|
|
'text-bg-body': type === ToastType.default,
|
|
'text-bg-success': type === ToastType.success,
|
|
'text-bg-danger': type === ToastType.error,
|
|
'text-bg-info': type === ToastType.info,
|
|
'text-bg-warning': type === ToastType.warning,
|
|
}"
|
|
role="alert"
|
|
aria-live="assertive"
|
|
aria-atomic="true"
|
|
>
|
|
<div v-if="title" class="toast-header">
|
|
<strong class="me-auto">{{ title }}</strong>
|
|
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Fermer" />
|
|
</div>
|
|
<div class="toast-body">
|
|
<span>{{ message }}</span>
|
|
</div>
|
|
<button
|
|
v-if="!title"
|
|
type="button"
|
|
:class="{
|
|
'btn-close me-2 m-auto': true,
|
|
'btn-close-white': [
|
|
ToastType.success,
|
|
ToastType.error
|
|
].find((toastType) => toastType === type)
|
|
}"
|
|
data-bs-dismiss="toast"
|
|
aria-label="Fermer"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { Toast } from "bootstrap";
|
|
import { defineComponent } from "vue";
|
|
import { ToastType } from "~/classes/Toast";
|
|
|
|
export default defineComponent({
|
|
name: "ToastContainer",
|
|
data(): {
|
|
ToastType: typeof ToastType;
|
|
type: ToastTypeEnum;
|
|
class: string;
|
|
title: string|null;
|
|
message: string;
|
|
} {
|
|
return {
|
|
ToastType,
|
|
type: ToastType.default,
|
|
class: "text-bg-body",
|
|
title: null,
|
|
message: "",
|
|
};
|
|
},
|
|
mounted() {
|
|
useState("toastMessage", () => (message:string, type:ToastTypeEnum, title: string|null = null) => {
|
|
const myToastEl = this.$refs.toastMessage as HTMLElement;
|
|
this.title = title;
|
|
this.type = type;
|
|
this.message = message;
|
|
Toast.getOrCreateInstance(myToastEl).show();
|
|
});
|
|
}
|
|
});
|
|
</script>
|