Add custom flash library that works as expected
This commit is contained in:
parent
bab20812a0
commit
0a706d1b45
13 changed files with 233 additions and 37 deletions
62
resources/assets/scripts/mixins/flash.js
Normal file
62
resources/assets/scripts/mixins/flash.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
export const flash = {
|
||||
methods: {
|
||||
/**
|
||||
* Flash a message to the event stream in the browser.
|
||||
*
|
||||
* @param {string} message
|
||||
* @param {string} title
|
||||
* @param {string} severity
|
||||
*/
|
||||
flash: function (message, title, severity = 'info') {
|
||||
severity = severity || 'info';
|
||||
if (['danger', 'fatal', 'error'].includes(severity)) {
|
||||
severity = 'error';
|
||||
}
|
||||
|
||||
window.events.$emit('flash', { message, title, severity });
|
||||
},
|
||||
|
||||
/**
|
||||
* Clear all of the flash messages from the screen.
|
||||
*/
|
||||
clearFlashes: function () {
|
||||
window.events.$emit('clear-flashes');
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to flash a normal success message to the user.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
success: function (message) {
|
||||
this.flash(message, 'Success', 'success');
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to flash a normal info message to the user.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
info: function (message) {
|
||||
this.flash(message, 'Info', 'info');
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to flash a normal warning message to the user.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
warning: function (message) {
|
||||
this.flash(message, 'Warning', 'warning');
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to flash a normal error message to the user.
|
||||
*
|
||||
* @param {string} message
|
||||
*/
|
||||
error: function (message) {
|
||||
this.flash(message, 'Error', 'danger');
|
||||
},
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue