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

82 lines
2.6 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<transition name="p-message" appear>
2023-05-25 13:22:28 +00:00
<div v-show="visible" :class="cx('root')" role="alert" aria-live="assertive" aria-atomic="true" v-bind="ptm('root')">
<div :class="cx('wrapper')" v-bind="ptm('wrapper')">
<slot name="messageicon" class="p-message-icon">
2023-05-25 13:22:28 +00:00
<component :is="icon ? 'span' : iconComponent" :class="cx('icon')" v-bind="ptm('icon')"></component>
</slot>
2023-05-25 13:36:24 +00:00
<div class="p-message-text" :class="cx('text')" v-bind="ptm('text')">
2022-09-06 12:03:37 +00:00
<slot></slot>
</div>
2023-05-25 13:22:28 +00:00
<button v-if="closable" v-ripple :class="cx('button')" :aria-label="closeAriaLabel" type="button" @click="close($event)" v-bind="{ ...closeButtonProps, ...ptm('button') }">
<slot name="closeicon">
<i v-if="closeIcon" :class="cx('buttonIcon')" v-bind="ptm('buttonIcon')" />
<TimesIcon v-else :class="cx('buttonIcon')" v-bind="ptm('buttonIcon')" />
</slot>
2022-09-06 12:03:37 +00:00
</button>
</div>
</div>
</transition>
</template>
<script>
2023-05-25 13:22:28 +00:00
import BaseMessage from './BaseMessage.vue';
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',
2023-05-25 13:22:28 +00:00
extends: BaseMessage,
2022-09-06 12:03:37 +00:00
emits: ['close'],
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: {
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>