UNPKG

quasar-framework

Version:

Simultaneously build desktop/mobile SPA websites & phone/tablet apps with VueJS

58 lines (50 loc) 1.05 kB
import Utils from '../../utils' import Toast from './Toast.vue' let toast, types = [ { name: 'positive', defaults: {icon: 'check', classes: 'bg-positive'} }, { name: 'negative', defaults: {icon: 'whatshot', classes: 'bg-negative'} }, { name: 'info', defaults: {icon: 'info', classes: 'bg-info'} }, { name: 'warning', defaults: {icon: 'warning', classes: 'bg-warning'} } ] function create (opts, defaults) { if (!opts) { throw new Error('Missing toast options.') } if (defaults) { opts = Utils.extend( true, typeof opts === 'string' ? {html: opts} : opts, defaults ) } toast.create(opts) } types.forEach(type => { create[type.name] = opts => create(opts, type.defaults) }) export function install (_Vue) { let node = document.createElement('div') document.body.appendChild(node) toast = new _Vue(Toast).$mount(node) } export default { create, setDefaults (opts) { toast.setDefaults(opts) }, install }