Simple modal component.
Readme Contents
- Modal Features
- How to use
- Configuration Properties
- Two different modal states; Confirm or Notify types.
- Passes back options args back to parent vue instance, so that you can handle confirm modal.
- CSS transparency to dim screen when modal is shown.
Include the modal src in your project;
- Modal markup (src/modal-markup.html) into your projects HTML file.
- Modal styles (src/css/style.css) to your project.
- Modal JavaScript(src/modal.js) to your project.
Add the desired type of modal component node to your vue instance's template.
Notify:
<zaffri-modal v-bind:data="modalConfig"></zaffri-modal>
Confirm:
<zaffri-modal v-bind:data="modalConfig" v-on:hide_modal_emit="modalCallback"></zaffri-modal>
- modalConfig - will be the configuration for the modal.
- modalCallback - is the name of the method in the parent that will handle your confirm action.
Next you have to set up options in your vue instance to get the modal working.
var app = new Vue({
el: "#app",
data: {
modalConfig: {
// Modal visibility
visible: false,
// type: notify || confirm
type: "confirm",
// display data
title: "Confirmation",
messageBody: "This is just some example body text.",
confirmText: "Confirm",
// Only required for confirm modal
cancelText: "Cancel",
callbackData: {}
}
}
});
###### See "Configuration Properties" below for more details.
The last step is to set up an event handler to initiate your modal, and remember to define your callback if you are using the confirm modal.
methods: {
openModal: function(id) {
// Passing data through
this.modalConfig.callbackData = {
id: id
};
// Init modal
this.modalConfig.visible = true;
},
modalCallback: function(action) {
// Handle action
}
}
- modalConfig.visible is binded to the component, setting it to true will open up your modal.
- Accessing your parameters: this.modalConfig.callbackData is available inside your callback function (modalCallback).
- Action variable inside modalCallback is a boolean - true means the user accepted the modal action.
This is a boolean which determines if the modal is visible.
There are two types of modals currently; "confirm" and "notify".
Title is a string which will be displayed as the modal title.
Message body is the string displayed on the modal as the main text.
Confirm text is the string that is displayed on the modals confirm button.
Cancel text is the string that is displayed on the modals cancel button.
Callback data is data passed to the callback function - the second parameter.