@citygro/vue-modal
v5.3.2
Published
reusable modal component for vue 2
Readme
@citygro/vue-modal
reusable modal component for vue 2; designed to work with bootstrap 3 styles.
see ./example for a working demonstration!
git clone https://gitlab.com/citygro/vue-modal
cd vue-modal
yarn
yarn startif you're impressed, you'll want to add this to your project immediately:
$ yarn add @citygro/vue-modalthe example project is a good reference.
overview
// App.vue
import Vue from 'vue'
import VueModal from 'vue-modal'
Vue.use(VueModal)
Vue.component('my-component', {
// ...
methods: {
showMyModal () {
const {result, mounted} = this.$openModal({
content: (resolve) => require(['Modal'], resolve),
props: { /* props go here */ },
title: 'My Title'
})
result.then(() => {
/* close */
}).catch(() => {
/* dismiss */
})
mounted.then((modal) => {
/* do what you want */
})
}
}
// ...
})
new Vue({
render (createElement) {
return createElement('div', null, [
createElement(MyComponent),
createElement('modal-view')
])
}
}).$mount('#root')
api
$openModal(options: Object): {mounted, result, instance, close, dismiss}
options
buttons: Object[]|booleanan array of objects describing buttons:
[
{label: 'Ok', key: 'ok', class: 'btn-primary', focus: true},
{label: 'Cancel', key: 'cancel', class: 'btn-default', reject: true}
]contenttakes one of- a callback function that returns a
VueComponent, this can be used to load modals asynchronously - a
VueComponentinstance - a
String
- a callback function that returns a
props: Objectprops to be passed to theVueComponentafter it is loaded, default:{}size: String|String[]|void(optional) specify modal size (one of:'sm','lg', or'full'); specify multiple options as an arraystatic: booleanforce interation to dismisstitle: String|nullmodal title, default:nullclass: Objectclass names to bind to.modal(see vue guide)
content is wrapped in div.modal-body if either title or buttons is defined, if neither are present content
is injected directly into div.modal-dialog.
return {mounted, result, instance, close, dismiss}
mounted: Promise<VueComponent, Error>a promise for the modal componentresult: Promise<void, Error>aPromisethat is resolved (close) or rejected (dismiss) depending on user inputinstance: Promise<VueComponent>a promise that resolves to the modal component instance that is created for that specific call of$openModal; It is not the vue component instance of the content, but of the modal which is$parentto the content.close: Function(options)<Promise<void>>a function which waits forinstanceto resolve, then runs theclosemethod of that instance with the providedoptions. Like runningcontent.$parent.close(options)from inside of the modal content component, but accessible from the context of where the modal was opened. Useful for closing progress/loading blockers.dismiss: Function(options)<Promise<void>>a function which waits forinstanceto resolve, then runs thedismissmethod of that instance with the providedoptions. Like runningcontent.$parent.dismiss(options)from inside of the modal content component, but accessible from the context of where the modal was opened. Useful for closing progress/loading blockers.
content.$parent.close(options: {key: String})
note that
$parentrefers to the modal itself, not the component calling$openModal()
close this modal (and resolve result).
content.$parent.dismiss(options: {key: String})
note that
$parentrefers to the modal itself, not the component calling$openModal()
dismiss this modal (and reject result)
content.$modalOptions: Object
optional static modal options which are merged with any options passed to $openModal(). options passed at the call
site will take precedence.
custom styles
modal components have bootstrap modal classes
issues?
if you get stuck, you can catch us on #citygro:matrix.org
found a bug? we'd be happy to fix it!.
