Change flash mixin

This commit is contained in:
Dane Everitt 2018-12-29 19:24:09 -08:00
parent 96468ab4b3
commit f7ba30fbbe
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
4 changed files with 59 additions and 64 deletions

View file

@ -1,52 +1,57 @@
export const flash = {
methods: {
/**
* Flash a message to the event stream in the browser.
*/
flash: function (message: string, title: string, severity: string = 'info'): void {
severity = severity || 'info';
if (['danger', 'fatal', 'error'].includes(severity)) {
severity = 'error';
}
import {ComponentOptions} from "vue";
import {Vue} from "vue/types/vue";
// @ts-ignore
window.events.$emit('flash', { message, title, severity });
},
export interface FlashInterface {
flash(message: string, title: string, severity: string): void;
/**
* Clear all of the flash messages from the screen.
*/
clearFlashes: function (): void {
// @ts-ignore
window.events.$emit('clear-flashes');
},
clear(): void,
/**
* Helper function to flash a normal success message to the user.
*/
success: function (message: string): void {
this.flash(message, 'Success', 'success');
},
success(message: string): void,
/**
* Helper function to flash a normal info message to the user.
*/
info: function (message: string): void {
this.flash(message, 'Info', 'info');
},
info(message: string): void,
/**
* Helper function to flash a normal warning message to the user.
*/
warning: function (message: string): void {
this.flash(message, 'Warning', 'warning');
},
warning(message: string): void,
/**
* Helper function to flash a normal error message to the user.
*/
error: function (message: string): void {
this.flash(message, 'Error', 'danger');
},
error(message: string): void,
}
class Flash implements FlashInterface {
flash(message: string, title: string, severity: string = 'info'): void {
severity = severity || 'info';
if (['danger', 'fatal', 'error'].includes(severity)) {
severity = 'error';
}
// @ts-ignore
window.events.$emit('flash', {message, title, severity});
}
clear(): void {
// @ts-ignore
window.events.$emit('clear-flashes');
}
success(message: string): void {
this.flash(message, 'Success', 'success');
}
info(message: string): void {
this.flash(message, 'Info', 'info');
}
warning(message: string): void {
this.flash(message, 'Warning', 'warning');
}
error(message: string): void {
this.flash(message, 'Error', 'error');
}
}
export const FlashMixin: ComponentOptions<Vue> = {
methods: {
'$flash': function () {
return new Flash();
}
},
};