buefy
Version:
Lightweight UI components for Vue.js based on Bulma
238 lines (209 loc) • 8.05 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var __chunk_1 = require('./chunk-9f6a8079.js');
var __chunk_2 = require('./chunk-59b91990.js');
var __chunk_3 = require('./chunk-545f01b1.js');
var __chunk_5 = require('./chunk-60061aa8.js');
var __chunk_6 = require('./chunk-13e039f5.js');
var Vue = _interopDefault(require('vue'));
var __chunk_14 = require('./chunk-e5de6583.js');
var script = {
name: 'BDialog',
components: __chunk_1._defineProperty({}, __chunk_5.Icon.name, __chunk_5.Icon),
extends: __chunk_14.Modal,
props: {
title: String,
message: String,
icon: String,
iconPack: String,
hasIcon: Boolean,
type: {
type: String,
default: 'is-primary'
},
size: String,
confirmText: {
type: String,
default: function _default() {
return __chunk_3.config.defaultDialogConfirmText ? __chunk_3.config.defaultDialogConfirmText : 'OK';
}
},
cancelText: {
type: String,
default: function _default() {
return __chunk_3.config.defaultDialogCancelText ? __chunk_3.config.defaultDialogCancelText : 'Cancel';
}
},
hasInput: Boolean,
// Used internally to know if it's prompt
inputAttrs: {
type: Object,
default: function _default() {
return {};
}
},
onConfirm: {
type: Function,
default: function _default() {}
},
focusOn: {
type: String,
default: 'confirm'
}
},
data: function data() {
var prompt = this.hasInput ? this.inputAttrs.value || '' : '';
return {
prompt: prompt,
isActive: false,
validationMessage: ''
};
},
computed: {
/**
* Icon name (MDI) based on the type.
*/
iconByType: function iconByType() {
switch (this.type) {
case 'is-info':
return 'information';
case 'is-success':
return 'check-circle';
case 'is-warning':
return 'alert';
case 'is-danger':
return 'alert-circle';
default:
return null;
}
},
showCancel: function showCancel() {
return this.cancelOptions.indexOf('button') >= 0;
}
},
methods: {
/**
* If it's a prompt Dialog, validate the input.
* Call the onConfirm prop (function) and close the Dialog.
*/
confirm: function confirm() {
var _this = this;
if (this.$refs.input !== undefined) {
if (!this.$refs.input.checkValidity()) {
this.validationMessage = this.$refs.input.validationMessage;
this.$nextTick(function () {
return _this.$refs.input.select();
});
return;
}
}
this.onConfirm(this.prompt);
this.close();
},
/**
* Close the Dialog.
*/
close: function close() {
var _this2 = this;
this.isActive = false; // Timeout for the animation complete before destroying
setTimeout(function () {
_this2.$destroy();
__chunk_2.removeElement(_this2.$el);
}, 150);
}
},
beforeMount: function beforeMount() {
var _this3 = this;
// Insert the Dialog component in body tag
if (typeof window !== 'undefined') {
this.$nextTick(function () {
document.body.appendChild(_this3.$el);
});
}
},
mounted: function mounted() {
var _this4 = this;
this.isActive = true;
if (typeof this.inputAttrs.required === 'undefined') {
this.$set(this.inputAttrs, 'required', true);
}
this.$nextTick(function () {
// Handle which element receives focus
if (_this4.hasInput) {
_this4.$refs.input.focus();
} else if (_this4.focusOn === 'cancel' && _this4.showCancel) {
_this4.$refs.cancelButton.focus();
} else {
_this4.$refs.confirmButton.focus();
}
});
}
};
/* script */
const __vue_script__ = script;
/* template */
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('transition',{attrs:{"name":_vm.animation}},[(_vm.isActive)?_c('div',{staticClass:"dialog modal is-active",class:_vm.size},[_c('div',{staticClass:"modal-background",on:{"click":function($event){_vm.cancel('outside');}}}),_vm._v(" "),_c('div',{staticClass:"modal-card animation-content"},[(_vm.title)?_c('header',{staticClass:"modal-card-head"},[_c('p',{staticClass:"modal-card-title"},[_vm._v(_vm._s(_vm.title))])]):_vm._e(),_vm._v(" "),_c('section',{staticClass:"modal-card-body",class:{ 'is-titleless': !_vm.title, 'is-flex': _vm.hasIcon }},[_c('div',{staticClass:"media"},[(_vm.hasIcon)?_c('div',{staticClass:"media-left"},[_c('b-icon',{attrs:{"icon":_vm.icon ? _vm.icon : _vm.iconByType,"pack":_vm.iconPack,"type":_vm.type,"both":!_vm.icon,"size":"is-large"}})],1):_vm._e(),_vm._v(" "),_c('div',{staticClass:"media-content"},[_c('p',{domProps:{"innerHTML":_vm._s(_vm.message)}}),_vm._v(" "),(_vm.hasInput)?_c('div',{staticClass:"field"},[_c('div',{staticClass:"control"},[_c('input',_vm._b({directives:[{name:"model",rawName:"v-model",value:(_vm.prompt),expression:"prompt"}],ref:"input",staticClass:"input",class:{ 'is-danger': _vm.validationMessage },domProps:{"value":(_vm.prompt)},on:{"keyup":function($event){if(!('button' in $event)&&_vm._k($event.keyCode,"enter",13,$event.key)){ return null; }_vm.confirm($event);},"input":function($event){if($event.target.composing){ return; }_vm.prompt=$event.target.value;}}},'input',_vm.inputAttrs,false))]),_vm._v(" "),_c('p',{staticClass:"help is-danger"},[_vm._v(_vm._s(_vm.validationMessage))])]):_vm._e()])])]),_vm._v(" "),_c('footer',{staticClass:"modal-card-foot"},[(_vm.showCancel)?_c('button',{ref:"cancelButton",staticClass:"button",on:{"click":function($event){_vm.cancel('button');}}},[_vm._v("\n "+_vm._s(_vm.cancelText)+"\n ")]):_vm._e(),_vm._v(" "),_c('button',{ref:"confirmButton",staticClass:"button",class:_vm.type,on:{"click":_vm.confirm}},[_vm._v("\n "+_vm._s(_vm.confirmText)+"\n ")])])])]):_vm._e()])};
var __vue_staticRenderFns__ = [];
/* style */
const __vue_inject_styles__ = undefined;
/* scoped */
const __vue_scope_id__ = undefined;
/* module identifier */
const __vue_module_identifier__ = undefined;
/* functional template */
const __vue_is_functional_template__ = false;
/* style inject */
/* style inject SSR */
var Dialog = __chunk_6.__vue_normalize__(
{ render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
__vue_inject_styles__,
__vue_script__,
__vue_scope_id__,
__vue_is_functional_template__,
__vue_module_identifier__,
undefined,
undefined
);
function open(propsData) {
var vm = typeof window !== 'undefined' && window.Vue ? window.Vue : Vue;
var DialogComponent = vm.extend(Dialog);
return new DialogComponent({
el: document.createElement('div'),
propsData: propsData
});
}
var DialogProgrammatic = {
alert: function alert(params) {
var message;
if (typeof params === 'string') message = params;
var defaultParam = {
canCancel: false,
message: message
};
var propsData = Object.assign(defaultParam, params);
return open(propsData);
},
confirm: function confirm(params) {
var defaultParam = {};
var propsData = Object.assign(defaultParam, params);
return open(propsData);
},
prompt: function prompt(params) {
var defaultParam = {
hasInput: true,
confirmText: 'Done'
};
var propsData = Object.assign(defaultParam, params);
return open(propsData);
}
};
var Plugin = {
install: function install(Vue) {
__chunk_6.registerComponent(Vue, Dialog);
__chunk_6.registerComponentProgrammatic(Vue, 'dialog', DialogProgrammatic);
}
};
__chunk_6.use(Plugin);
exports.DialogProgrammatic = DialogProgrammatic;
exports.default = Plugin;