antares/src/renderer/components/BaseNotification.vue

100 lines
2.3 KiB
Vue
Raw Normal View History

2020-05-15 17:52:59 +02:00
<template>
<div class="toast mt-2" :class="notificationStatus.className">
<span class="p-vcentered text-left" :class="{'expanded': isExpanded}">
<i class="mdi mdi-24px mr-2" :class="notificationStatus.iconName" />
2020-05-15 17:52:59 +02:00
<span class="notification-message">{{ message }}</span>
</span>
<i
v-if="isExpandable"
class="mdi mdi-24px c-hand expand-btn"
:class="isExpanded ? 'mdi-chevron-up' : 'mdi-chevron-down'"
@click="toggleExpand"
/>
2020-05-18 18:06:32 +02:00
<button class="btn btn-clear ml-2" @click="hideToast" />
2020-05-15 17:52:59 +02:00
</div>
</template>
<script>
export default {
2020-05-15 17:52:59 +02:00
name: 'BaseNotification',
props: {
message: {
type: String,
default: ''
},
status: {
type: String,
default: ''
}
},
data () {
return {
isExpanded: false
};
},
2020-05-15 17:52:59 +02:00
computed: {
notificationStatus () {
let className = '';
let iconName = '';
switch (this.status) {
case 'success':
className = 'toast-success';
iconName = 'mdi-check';
2020-05-15 17:52:59 +02:00
break;
case 'error':
className = 'toast-error';
iconName = 'mdi-alert-rhombus';
2020-05-15 17:52:59 +02:00
break;
case 'warning':
className = 'toast-warning';
iconName = 'mdi-alert';
2020-05-15 17:52:59 +02:00
break;
case 'primary':
className = 'toast-primary';
iconName = 'mdi-information-outline';
2020-05-15 17:52:59 +02:00
break;
}
return { className, iconName };
},
isExpandable () {
return this.message.length > 80;
2020-05-15 17:52:59 +02:00
}
},
methods: {
hideToast () {
this.$emit('close');
},
toggleExpand () {
this.isExpanded = !this.isExpanded;
2020-05-15 17:52:59 +02:00
}
}
};
</script>
<style scoped>
2020-07-31 18:16:28 +02:00
.toast {
display: flex;
justify-content: space-between;
user-select: text;
word-break: break-all;
width: fit-content;
margin-left: auto;
}
2020-05-15 17:52:59 +02:00
2020-07-31 18:16:28 +02:00
.notification-message {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: inline-block;
max-width: 30rem;
}
.expand-btn {
align-items: initial;
}
2020-07-31 18:16:28 +02:00
.expanded .notification-message {
white-space: initial;
}
2020-05-15 17:52:59 +02:00
</style>