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

147 lines
3.3 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">
<span :class="iconClass"></span>
<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">
<i :class="['p-message-close-icon', closeIcon]" />
2022-09-06 12:03:37 +00:00
</button>
</div>
</div>
</transition>
</template>
<script>
import Ripple from 'primevue/ripple';
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: null
2022-12-08 11:04:25 +00:00
},
closeIcon: {
type: String,
default: 'pi pi-times'
},
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) {
2022-12-08 14:13:16 +00:00
this.x();
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
},
x() {
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;
},
iconClass() {
2022-09-14 11:26:01 +00:00
return [
'p-message-icon pi',
this.icon
? this.icon
: {
'pi-info-circle': this.severity === 'info',
'pi-check': this.severity === 'success',
'pi-exclamation-triangle': this.severity === 'warn',
'pi-times-circle': this.severity === 'error'
}
];
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
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>