Add an option to add additional classes to toasts
This commit is contained in:
parent
a95b97b3c0
commit
1d887967d9
|
@ -10,9 +10,10 @@
|
|||
|
||||
<template>
|
||||
<div class="bd-toasts">
|
||||
<Toast v-for="(toast, index) in toasts" :message="toast.message" :type="toast.type" :icon="toast.icon" :closing="toast.closing" :key="`${toast.id}`"></Toast>
|
||||
<Toast v-for="(toast, index) in toasts" :message="toast.message" :type="toast.type" :icon="toast.icon" :class="toast.additionalClasses" :closing="toast.closing" :key="toast.id"></Toast>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// Imports
|
||||
import { Toasts } from 'ui';
|
||||
|
|
|
@ -9,13 +9,13 @@
|
|||
*/
|
||||
|
||||
<template>
|
||||
<div :class="['bd-toast', 'bd-toast-' + type, {'bd-toast-has-icon': type != 'basic' || icon, 'bd-toast-closing': closing}]">
|
||||
<div class="bd-toast-icon" v-if="type != 'basic' || icon">
|
||||
<div :class="['bd-toast', 'bd-toast-' + type, {'bd-toast-has-icon': type !== 'basic' || icon, 'bd-toast-closing': closing}]">
|
||||
<div class="bd-toast-icon" v-if="type !== 'basic' || icon">
|
||||
<img v-if="icon" :src="icon" width="20" height="20" />
|
||||
<MiSuccess v-else-if="type == 'success'" size="20" />
|
||||
<MiWarning v-else-if="type == 'warning'" size="20" />
|
||||
<MiInfo v-else-if="type == 'info'" size="20" />
|
||||
<MiError v-else-if="type == 'error'" size="20" />
|
||||
<MiSuccess v-else-if="type === 'success'" size="20" />
|
||||
<MiWarning v-else-if="type === 'warning'" size="20" />
|
||||
<MiInfo v-else-if="type === 'info'" size="20" />
|
||||
<MiError v-else-if="type === 'error'" size="20" />
|
||||
</div>
|
||||
<div class="bd-toast-text">
|
||||
{{message}}
|
||||
|
@ -33,7 +33,7 @@
|
|||
icon: String,
|
||||
type: {
|
||||
default: 'basic',
|
||||
validator: function (value) {
|
||||
validator(value) {
|
||||
return ['success', 'warning', 'error', 'info', 'basic'].indexOf(value) !== -1
|
||||
}
|
||||
},
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
let toasts = 0;
|
||||
|
||||
export default class Toasts {
|
||||
|
||||
/**
|
||||
|
@ -17,12 +19,13 @@ export default class Toasts {
|
|||
* @param {Object} options Options object. Optional parameter.
|
||||
* @param {string} options.type Changes the type of the toast stylistically and semantically. Choices: "basic", "info", "success", "error", "warning". Default: "basic"
|
||||
* @param {string} options.icon URL to custom icon to show in the toast. Having this overrides the default icon for the toast type.
|
||||
* @param {string|Object|Array} options.additionalClasses Additional classes to add to the toast element. Can be used to style it. Optional.
|
||||
* @param {number} options.timeout Adjusts the time (in ms) the toast should be shown for before disappearing automatically. Default: 3000
|
||||
* @returns {Promise} This promise resolves when the toast is removed from the DOM.
|
||||
*/
|
||||
static async push(message, options = {}) {
|
||||
const {type = 'basic', icon, timeout = 3000} = options;
|
||||
const toast = {id: Math.random(), message, type, icon, closing: false};
|
||||
const {type = 'basic', icon, additionalClasses, timeout = 3000} = options;
|
||||
const toast = {id: toasts++, message, type, icon, additionalClasses, closing: false};
|
||||
this.stack.push(toast);
|
||||
await new Promise(resolve => setTimeout(resolve, timeout));
|
||||
toast.closing = true;
|
||||
|
|
Loading…
Reference in New Issue