primevue-mirror/components/lib/message/Message.vue

159 lines
3.9 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<transition name="p-message" appear>
2022-12-08 11:04:25 +00:00
<div v-show="visible" :class="containerClass" role="alert" aria-live="assertive" aria-atomic="true">
2022-09-06 12:03:37 +00:00
<div class="p-message-wrapper">
<slot name="messageicon" class="p-message-icon">
2023-04-14 08:03:50 +00:00
<component :is="icon ? 'span' : iconComponent" :class="['p-message-icon', icon]"></component>
</slot>
2022-09-06 12:03:37 +00:00
<div class="p-message-text">
<slot></slot>
</div>
2022-12-08 11:04:25 +00:00
<button v-if="closable" v-ripple class="p-message-close p-link" :aria-label="closeAriaLabel" type="button" @click="close($event)" v-bind="closeButtonProps">
<slot name="closeicon" class="p-message-close-icon">
<i v-if="closeIcon" :class="['p-message-close-icon', closeIcon]" />
<TimesIcon v-else class="p-message-close-icon" />
</slot>
2022-09-06 12:03:37 +00:00
</button>
</div>
</div>
</transition>
</template>
<script>
import CheckIcon from 'primevue/icons/check';
import ExclamationTriangleIcon from 'primevue/icons/exclamationtriangle';
import InfoCircleIcon from 'primevue/icons/infocircle';
import TimesIcon from 'primevue/icons/times';
import TimesCircleIcon from 'primevue/icons/timescircle';
2023-04-14 08:03:50 +00:00
import Ripple from 'primevue/ripple';
2022-09-06 12:03:37 +00:00
export default {
name: 'Message',
emits: ['close'],
props: {
severity: {
type: String,
default: 'info'
},
closable: {
type: Boolean,
default: true
},
sticky: {
type: Boolean,
default: true
},
life: {
type: Number,
default: 3000
},
icon: {
type: String,
default: undefined
2022-12-08 11:04:25 +00:00
},
closeIcon: {
type: String,
default: undefined
2022-12-08 11:04:25 +00:00
},
closeButtonProps: {
type: null,
default: null
2022-09-14 11:26:01 +00:00
}
2022-09-06 12:03:37 +00:00
},
timeout: null,
data() {
return {
visible: true
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
mounted() {
if (!this.sticky) {
this.closeAfterDelay();
2022-09-06 12:03:37 +00:00
}
},
methods: {
close(event) {
this.visible = false;
this.$emit('close', event);
2022-12-08 14:13:16 +00:00
},
closeAfterDelay() {
2022-12-08 14:13:16 +00:00
setTimeout(() => {
this.visible = false;
}, this.life);
2022-09-06 12:03:37 +00:00
}
},
computed: {
containerClass() {
return 'p-message p-component p-message-' + this.severity;
},
iconComponent() {
return {
info: InfoCircleIcon,
success: CheckIcon,
warn: ExclamationTriangleIcon,
error: TimesCircleIcon
}[this.severity];
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
}
},
directives: {
2022-09-14 11:26:01 +00:00
ripple: Ripple
},
components: {
TimesIcon,
InfoCircleIcon,
CheckIcon,
ExclamationTriangleIcon,
TimesCircleIcon
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>
<style>
.p-message-wrapper {
display: flex;
align-items: center;
}
.p-message-close {
display: flex;
align-items: center;
justify-content: center;
}
.p-message-close.p-link {
margin-left: auto;
overflow: hidden;
position: relative;
}
.p-message-enter-from {
opacity: 0;
}
.p-message-enter-active {
2022-09-14 11:26:01 +00:00
transition: opacity 0.3s;
2022-09-06 12:03:37 +00:00
}
.p-message.p-message-leave-from {
max-height: 1000px;
}
.p-message.p-message-leave-to {
max-height: 0;
opacity: 0;
margin: 0 !important;
}
.p-message-leave-active {
overflow: hidden;
2022-09-14 11:26:01 +00:00
transition: max-height 0.3s cubic-bezier(0, 1, 0, 1), opacity 0.3s, margin 0.15s;
2022-09-06 12:03:37 +00:00
}
.p-message-leave-active .p-message-close {
display: none;
}
</style>