1.0.3 • Published 5 years ago

vue-modal-dialog-plugin v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

vue-modal-dialog-plugin

Version Downloads Issues License

A modal dialog plugin for mobile, integrated with Vue.js and Vuex.

Live demo

Features

  • Only 9.7KB minified while 2.8KB gzipped
  • Integrated with Vue.js as a plugin
  • Responsive Design
  • Show multiple dialogs meanwhile
  • Able to customize buttons and message with HTML supported
  • API interaction via Promise

Usage

Register the plugin first.

import Vue from 'vue'
import Vuex from 'vuex'
import vueModalDialogPlugin from 'vue-modal-dialog-plugin'

const store = new Vuex.Store({ strict: true })

Vue.use(vueModalDialogPlugin, { store })

new Vue({ store })

Then include plugin css and add the holder tag to your root Vue node.

<template>
  <div id="app">
    <vue-dialog-holder />
  </div>
</template>

<style>
@import '~vue-modal-dialog-plugin/dist/vue-modal-dialog-plugin.min.css';
</style>

Finally, use it anywhere.

Vue.extend({
  mounted () {
    this.$dialog.alert('Hello dialog!')
  }
})

API

Vue.use(vueModalDialogPlugin, options)

Integrate Vue Modal Dialog Plugin into current Vue runtime.

ParameterTypeDescriptionDefault
options.storeVuex.StoreA Vuex Store instance.
options.okButtonLabelstring|FunctionDefault label for the "OK" button.'OK'
options.cancelButtonLabelstring|FunctionDefault label for the "Cancel" button.'Cancel'
options.yesButtonLabelstring|FunctionDefault label for the "Yes" button.'Yes'
options.noButtonLabelstring|FunctionDefault label for the "No" button.'No'

vueModalDialogPlugin.alert(message, title, options)

Perform an alert dialog with an "OK" button.

The returned Promise instance will be resolved when user clicks "OK" button, or rejected when user clicks the background area.

ParameterTypeDescriptionDefault
messagestring|ErrorThe message.''
titlestringThe title.null
optionsobjectAdditional options (see open()).{}

vueModalDialogPlugin.confirm(message, title, options)

Perform an confirm dialog with "Yes" and "No" button.

The returned Promise instance will be resolved when user clicks "Yes" button, or rejected when user clicks the "No" button or the background area.

ParameterTypeDescriptionDefault
messagestring|ErrorThe message.''
titlestringThe title.null
optionsobjectAdditional options (see open()).{}

vueModalDialogPlugin.prompt(message, title, options)

Perform an prompt dialog with "OK" and "Cancel" button.

A single text input will be placed below the dialog content.

The returned Promise instance will be resolved with the values of inputs when user clicks "OK" button, or rejected when user clicks the background area.

ParameterTypeDescriptionDefault
messagestring|ErrorThe message.''
titlestringThe title.null
optionsobjectAdditional options (see open()).{}

vueModalDialogPlugin.open(options)

Perform a dialog using custom options.

ParameterTypeDescriptionDefault
optionsobject
options.messagestring|ErrorThe message.''
options.titlestringThe title.null
options.inputsstringHTML code below the title and message.If specified, the returned Promise instance will be resolved with the values of all inputs (including <input>, <textarea> and <select>) when user clicks a button with 'ok' value set.null
options.buttonsarrayThe buttons.[]
options.buttons[].valuestringThe value of this button.
options.buttons[].labelstringThe label of this button.
options.buttons[].secondarybooleanIf set to true, a secondary class will be added to the button node.false
options.buttons[].rejectbooleanIf set to true, the returned Promise instance will be rejected with the value of the button when user clicks the button.false
options.htmlbooleanSet to true to disable HTML escaping for title and message.false

vueModalDialogPlugin.close(options)

Close a dialog with specified ID.

ParameterTypeDescriptionDefault
optionsobject
options.idstringThe unique ID of the dialog.

License

MIT

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago