Created
July 21, 2020 14:26
-
-
Save lpj145/2202036c38c3f02d45910ac90daa27cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue'; | |
import { VSnackbar, VBtn, VIcon } from 'vuetify/lib'; | |
const message = Vue.observable({ | |
show: false, | |
message: '', | |
color: 'default', | |
timeout: 3000, | |
}); | |
export { message }; | |
/** | |
* Show message to user | |
* @param {String} sentence | |
* @param {String} alertType | |
* @param {Number} timeToShow | |
*/ | |
export const alertUser = (sentence, alertType = 'dark', timeToShow = 3000) => { | |
message.message = sentence; | |
message.show = true; | |
message.color = alertType; | |
message.timeout = timeToShow; | |
}; | |
export const showAlert = alertUser; | |
export default { | |
name: 'FAlert', | |
render(h) { | |
const closeIcon = h(VIcon, {}, 'mdi-close-circle-outline'); | |
const closeButton = h(VBtn, { | |
props: { | |
icon: true, | |
flat: true, | |
}, | |
on: { | |
click (e) { //eslint-disable-line | |
message.show = false; | |
}, | |
}, | |
}, [closeIcon]); | |
const snackerOptions = { | |
props: { | |
timeout: message.timeout, | |
color: message.color, | |
right: true, | |
bottom: true, | |
value: message.show, | |
}, | |
on: { | |
input: (e) => { | |
message.show = e | |
if (!e) { | |
message.timeout = 3000 | |
} | |
} | |
}, | |
scopedSlots: { | |
action: () => closeButton | |
} | |
}; | |
return h(VSnackbar, snackerOptions, [message.message]); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment