2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
|
|
|
<div :class="containerClass" role="alert" aria-live="assertive" aria-atomic="true">
|
|
|
|
<div class="p-toast-message-content" :class="message.contentStyleClass">
|
2023-04-14 12:03:58 +00:00
|
|
|
<template v-if="!templates.message">
|
|
|
|
<component :is="templates.icon ? templates.icon : iconComponent.name ? iconComponent : 'span'" :class="iconClass" class="p-toast-message-icon" />
|
2022-09-06 12:03:37 +00:00
|
|
|
<div class="p-toast-message-text">
|
2022-09-14 11:26:01 +00:00
|
|
|
<span class="p-toast-summary">{{ message.summary }}</span>
|
|
|
|
<div class="p-toast-detail">{{ message.detail }}</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
2023-04-14 12:03:58 +00:00
|
|
|
<component v-else :is="templates.message" :message="message"></component>{{ message.closable }}
|
2022-12-08 11:04:25 +00:00
|
|
|
<div v-if="message.closable !== false">
|
|
|
|
<button v-ripple class="p-toast-icon-close p-link" type="button" :aria-label="closeAriaLabel" @click="onCloseClick" autofocus v-bind="closeButtonProps">
|
2023-04-14 12:36:08 +00:00
|
|
|
<component :is="templates.closeicon || 'TimesIcon'" :class="['p-toast-icon-close-icon', closeIcon]" />
|
2022-12-08 11:04:25 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-04-11 21:25:24 +00:00
|
|
|
import CheckIcon from 'primevue/icon/check';
|
|
|
|
import ExclamationTriangleIcon from 'primevue/icon/exclamationtriangle';
|
2023-04-14 06:18:22 +00:00
|
|
|
import InfoCircleIcon from 'primevue/icon/infocircle';
|
|
|
|
import TimesIcon from 'primevue/icon/times';
|
2023-04-11 21:25:24 +00:00
|
|
|
import TimesCircleIcon from 'primevue/icon/timescircle';
|
2023-04-14 06:18:22 +00:00
|
|
|
import Ripple from 'primevue/ripple';
|
|
|
|
|
2022-09-06 12:03:37 +00:00
|
|
|
export default {
|
|
|
|
name: 'ToastMessage',
|
|
|
|
emits: ['close'],
|
|
|
|
props: {
|
2022-12-08 11:04:25 +00:00
|
|
|
message: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
},
|
2023-04-14 12:03:58 +00:00
|
|
|
templates: {
|
|
|
|
type: Object,
|
2022-12-08 11:04:25 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
closeIcon: {
|
|
|
|
type: String,
|
2023-04-14 12:03:58 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
infoIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
2023-04-14 12:03:58 +00:00
|
|
|
warnIcon: {
|
2022-12-08 11:04:25 +00:00
|
|
|
type: String,
|
2023-04-14 12:03:58 +00:00
|
|
|
default: null
|
|
|
|
},
|
|
|
|
errorIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
successIcon: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
closeButtonProps: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
closeTimeout: null,
|
|
|
|
mounted() {
|
|
|
|
if (this.message.life) {
|
|
|
|
this.closeTimeout = setTimeout(() => {
|
2023-03-07 12:36:38 +00:00
|
|
|
this.close({ message: this.message, type: 'life-end' });
|
2022-09-14 11:26:01 +00:00
|
|
|
}, this.message.life);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
this.clearCloseTimeout();
|
|
|
|
},
|
|
|
|
methods: {
|
2023-03-07 12:36:38 +00:00
|
|
|
close(params) {
|
|
|
|
this.$emit('close', params);
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
onCloseClick() {
|
|
|
|
this.clearCloseTimeout();
|
2023-03-07 12:36:38 +00:00
|
|
|
this.close({ message: this.message, type: 'close' });
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
|
|
|
clearCloseTimeout() {
|
|
|
|
if (this.closeTimeout) {
|
|
|
|
clearTimeout(this.closeTimeout);
|
|
|
|
this.closeTimeout = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2022-09-14 11:26:01 +00:00
|
|
|
return [
|
|
|
|
'p-toast-message',
|
|
|
|
this.message.styleClass,
|
|
|
|
{
|
|
|
|
'p-toast-message-info': this.message.severity === 'info',
|
|
|
|
'p-toast-message-warn': this.message.severity === 'warn',
|
|
|
|
'p-toast-message-error': this.message.severity === 'error',
|
|
|
|
'p-toast-message-success': this.message.severity === 'success'
|
|
|
|
}
|
|
|
|
];
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2023-04-11 21:25:24 +00:00
|
|
|
iconComponent() {
|
|
|
|
return {
|
2023-04-14 12:03:58 +00:00
|
|
|
info: !this.infoIcon && InfoCircleIcon,
|
|
|
|
success: !this.successIcon && CheckIcon,
|
|
|
|
warn: !this.warnIcon && ExclamationTriangleIcon,
|
|
|
|
error: !this.errorIcon && TimesCircleIcon
|
2023-04-11 21:25:24 +00:00
|
|
|
}[this.message.severity];
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
2023-04-14 12:03:58 +00:00
|
|
|
iconClass() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
[this.infoIcon]: this.message.severity === 'info',
|
|
|
|
[this.warnIcon]: this.message.severity === 'warn',
|
|
|
|
[this.errorIcon]: this.message.severity === 'error',
|
|
|
|
[this.successIcon]: this.message.severity === 'success'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
closeAriaLabel() {
|
|
|
|
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.close : undefined;
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
2023-04-11 21:25:24 +00:00
|
|
|
components: {
|
2023-04-14 12:03:58 +00:00
|
|
|
TimesIcon: TimesIcon,
|
|
|
|
InfoCircleIcon: InfoCircleIcon,
|
|
|
|
CheckIcon: CheckIcon,
|
|
|
|
ExclamationTriangleIcon: ExclamationTriangleIcon,
|
|
|
|
TimesCircleIcon: TimesCircleIcon
|
2023-04-11 21:25:24 +00:00
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
directives: {
|
2022-09-14 11:26:01 +00:00
|
|
|
ripple: Ripple
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|