Git Product home page Git Product logo

Comments (16)

adamreisnz avatar adamreisnz commented on August 22, 2024 10

How would you approach this for dynamic modals?
The settings need to be specified every time when calling the this.$modal.show() method.

It would be simpler if the defaults could be exposed and modified globally.
Something as simple as:

VueModal.setDefaults({...});

from vue-js-modal.

euvl avatar euvl commented on August 22, 2024 3

Hey @ciceropablo, after some consideration I think I will not implement this.
One can easily make wrapper component for modal which will handle default values. That is something v-dialog implementation does and it is pretty easy.

from vue-js-modal.

JJBocanegra avatar JJBocanegra commented on August 22, 2024 3

It's not working with dynamicDefaults

from vue-js-modal.

chriswdmr avatar chriswdmr commented on August 22, 2024 2

Even with 1.3.31 :(
Could you please provide an example with dynamic modals and global defaults (like the height) for all dynamic modals?

from vue-js-modal.

kdekooter avatar kdekooter commented on August 22, 2024 2

Not working here either. Settings in dynamicDefaults have no effect whatsoever. Please reopen @euvl .

from vue-js-modal.

JJBocanegra avatar JJBocanegra commented on August 22, 2024 2

I made a this pull request #445 to solve this issue

from vue-js-modal.

liatreis avatar liatreis commented on August 22, 2024 1

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 .show() call, the method can’t differentiate between you passing in props or params when you only pass in two arguments. So the function signature assumes a fixed order of arguments, and assumes you always pass in both props and params. You can easily modify the function signature to your own needs though.

cc @kdekooter, @prookie, @raneio, @Landen13, @arpit9295, @PinkiNice, @jbrown0824, @tekook, @ciceropablo

from vue-js-modal.

euvl avatar euvl commented on August 22, 2024 1

Hey, please check this feature here:

https://github.com/euvl/vue-js-modal/releases/tag/1.3.31

from vue-js-modal.

tekook avatar tekook commented on August 22, 2024

I would like this feature very much, to set a default value globally.
If you work with a wrapper for then you loose all other props or have do declare them all again in the wrapper component.
E.G. I want all my Modals to have the transition "modal". If I now write a wrapper, I cannot set "draggable" anywhere, or need to write the prop "draggable" into the wrapper.

I could very much be mistaken, just starting to get to know vue

from vue-js-modal.

euvl avatar euvl commented on August 22, 2024

You can pass draggable and other props by passing $attrs and $listeners to wrapped component.

https://vuejs.org/v2/api/#vm-attrs

from vue-js-modal.

tekook avatar tekook commented on August 22, 2024

As I said, I'm just starting to learn vue.
Could you give me a small example?

EDIT: OK, got it!

<base-modal transition="pop-out" v-bind="$attrs">
  <slot/>
</base-modal>

works like a charm! thank you!

from vue-js-modal.

euvl avatar euvl commented on August 22, 2024

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)
[2] https://medium.com/tldr-tech/higher-order-components-in-vue-js-38b500c6d49f (hocs in vue)

from vue-js-modal.

kdekooter avatar kdekooter commented on August 22, 2024

Totally agree with @adamreisnz. Please consider reopening this issue, @euvl. Or otherwise provide sample code for writing a HoC.

from vue-js-modal.

chriswdmr avatar chriswdmr commented on August 22, 2024

Hey there, I'm also trying to set height: 'auto' for all dynamic modals.
@euvl you posted a link to the 1.3.30 tag, but there was no code change which enables this?

Thanks for your effort!

from vue-js-modal.

euvl avatar euvl commented on August 22, 2024

Ah, should be https://github.com/euvl/vue-js-modal/releases/tag/1.3.31

Fixed comment

from vue-js-modal.

vis97c avatar vis97c commented on August 22, 2024

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 .show() call, the method can’t differentiate between you passing in props or params when you only pass in two arguments. So the function signature assumes a fixed order of arguments, and assumes you always pass in both props and params. You can easily modify the function signature to your own needs though.

cc @kdekooter, @prookie, @raneio, @Landen13, @arpit9295, @PinkiNice, @jbrown0824, @tekook, @ciceropablo

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.

from vue-js-modal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.