Skip to content

Commit

Permalink
Improve toast messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrl-escp committed Jul 7, 2024
1 parent 7e89304 commit 5578464
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
41 changes: 19 additions & 22 deletions src/components/ToasterMessage.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import {onMounted, ref} from 'vue';
import {onMounted, reactive, ref} from 'vue';
const props = defineProps({
text: {
Expand All @@ -12,29 +12,35 @@ const props = defineProps({
},
});
const messages = {};
const levels = [
'success',
'info',
'error'
];
const state = reactive({
visible: true,
startingStyle: {
display: 'block',
'@starting-style': 'display: none;',
},
});
const toasterMessage = ref(null);
function closeToast() {
state.visible = false;
toasterMessage.value.remove();
}
onMounted(() => {});
onMounted(() => {
setTimeout(closeToast, 2500);
});
</script>

<template>
<div ref="toasterMessage" class="toast" :class="'toast-' + level">
<button class="toast-close-message" @click="closeToast">x</button>
<div>{{ text }}</div>
</div>
<transition name="fade">
<div v-if="state.visible" ref="toasterMessage" class="toast" :class="'toast-' + level">
<button class="btn toast-close-message" @click="closeToast">x</button>
<span>{{ props.text }}</span>
</div>
</transition>
</template>

<style scoped>
Expand All @@ -55,29 +61,20 @@ onMounted(() => {});
text-overflow: ellipsis;
overflow: hidden;
}
.toast-close-message {
float: right;
font-size: larger;
margin-top: -8px;
background-color: transparent;
border: none;
}
.toast-close-message:active {
transform: translate(1px, 2px);
}
/*noinspection CssUnusedSymbol*/
.toast-error {
background-color: red;
}
/*noinspection CssUnusedSymbol*/
.toast-info {
background-color: yellow;
}
/*noinspection CssUnusedSymbol*/
.toast-success {
background-color: greenyellow;
Expand Down
8 changes: 0 additions & 8 deletions src/components/ToasterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function logMessage(text, level) {
onMounted(() => {
store.logMessage = logMessage;
window.store = store; // DEBUG
});
</script>
Expand All @@ -43,24 +42,20 @@ onMounted(() => {
animation: fadein 0.5s;
animation-fill-mode: forwards;
}
/*noinspection CssUnusedSymbol*/
.toast-disappear {
-webkit-animation: fadeout 0.5s;
animation: fadeout 0.5s;
animation-fill-mode: forwards;
}
.toaster {
justify-content: center;
position: fixed;
bottom: 30px;
}
toaster-message {
visibility: hidden;
}
@-webkit-keyframes fadein {
from {
bottom: 0;
Expand All @@ -71,7 +66,6 @@ toaster-message {
opacity: 1;
}
}
@keyframes fadein {
from {
bottom: 0;
Expand All @@ -82,7 +76,6 @@ toaster-message {
opacity: 1;
}
}
@-webkit-keyframes fadeout {
from {
bottom: 30px;
Expand All @@ -93,7 +86,6 @@ toaster-message {
opacity: 0;
}
}
@keyframes fadeout {
from {
bottom: 30px;
Expand Down
1 change: 1 addition & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ const store = reactive({
parseContent() {},
});

window.store = store; // DEBUG
export default store;

0 comments on commit 5578464

Please sign in to comment.