-
-
Notifications
You must be signed in to change notification settings - Fork 594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default options #56
Comments
Hey @ciceropablo, after some consideration I think I will not implement this. |
I would like this feature very much, to set a default value globally. I could very much be mistaken, just starting to get to know vue |
You can pass draggable and other props by passing |
As I said, I'm just starting to learn vue. EDIT: OK, got it!
works like a charm! thank you! |
no worries man, its a very good approach to create HoCs[1] in vue. [1] https://reactjs.org/docs/higher-order-components.html (hocs in react) |
How would you approach this for dynamic modals? It would be simpler if the defaults could be exposed and modified globally. VueModal.setDefaults({...}); |
Totally agree with @adamreisnz. Please consider reopening this issue, @euvl. Or otherwise provide sample code for writing a HoC. |
Since @adamreisnz has been blocked from interacting with this repo, I'm posting this work around for those interested, given the thumbs up received above. This simple wrapper will allow you to specify default options for dynamic modals, so you don’t need to repeat yourself 50x in the same project. Would be great if this could be implemented in the actual plugin, but since @euvl has indicated he doesn’t want to implement support for default options, I hope this workaround will be of use to someone. Wrapper plugin file: import vueModal from 'vue-js-modal';
/**
* Modal service
*/
class ModalService {
/**
* Constructor
*/
constructor(defaults, service) {
this.service = service;
this.setDefaults(defaults);
}
/**
* Set defaults
*/
setDefaults(defaults = {}) {
this.defaults = defaults;
}
/**
* Show a modal
*/
show(modal, props, params, events) {
//Merge defaults into params
params = Object.assign({}, this.defaults, params || {});
//Call underlying service
this.service.show(modal, props, params, events);
}
/**
* Hide
*/
hide(name, params) {
this.service.hide(name, params);
}
/**
* Toggle
*/
toggle(name, params) {
this.service.toggle(name, params);
}
}
/**
* Modal plugin
*/
const Plugin = {
/**
* Install plugin
*/
install(Vue, options) {
//First, install the vue modal plugin and pass through the options
Vue.use(vueModal, options);
//Get defaults from options
const {defaults} = options;
//Override with own wrapper service
Vue.prototype.$modal = new ModalService(defaults, Vue.prototype.$modal);
},
};
/**
* Export plugin
*/
export default Plugin; Then, specify default params when installing in your main.js: import Modal from './plugins/modal/modal.plugin';
Vue.use(Modal, {
//Any options you pass in here will be passed through to vue-js-modal
dynamic: true,
//Specify your defaults for dynamic modals here
defaults: {
clickToClose: false,
scrollable: true,
height: 'auto',
},
}); Usage in your components: //No need to repeat params anymore
this.$modal.show(ContactEdit, {
contact, isEdit, onSave, onRemove,
}); Caveat: since you now no longer need to pass in params to every cc @kdekooter, @prookie, @raneio, @Landen13, @arpit9295, @PinkiNice, @jbrown0824, @tekook, @ciceropablo |
Hey, please check this feature here: |
Hey there, I'm also trying to set height: 'auto' for all dynamic modals. Thanks for your effort! |
Ah, should be https://github.com/euvl/vue-js-modal/releases/tag/1.3.31 Fixed comment |
Even with 1.3.31 :( |
It's not working with |
Not working here either. Settings in |
I made a this pull request #445 to solve this issue |
I was unable to make it work, more taking into account that the $modal property cannot be overriden. I think the best approach is still to modify the plugin so i will fork this and do it on my own. These defaults are for the static modal and not the dynamic one. |
Something like that:
The properties should overwrite default options:
What do you think?
The text was updated successfully, but these errors were encountered: