Skip to content
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

Dynamic modals #10

Closed
dominykasgithub opened this issue Oct 23, 2020 · 13 comments
Closed

Dynamic modals #10

dominykasgithub opened this issue Oct 23, 2020 · 13 comments
Assignees
Labels
beta enhancement New feature or request
Projects

Comments

@dominykasgithub
Copy link

dominykasgithub commented Oct 23, 2020

Hello,

I'm transitioning from vue2 to vue3 and I was using vue-js-modal, but owner won't update package for a year as you can see his reply here (euvl/vue-js-modal#626)

So I decided to use this modal but it lacks features, so I'll build them myself, but I want to suggest copying dynamic modals creations like:

methods: {
            createDynamicModal(){
                this.$modal.show(SideModalReadMore, //just imported component
                    { //component props
                        product: this.product,
                        locale: this.locale,
                        isInit: this.isInit,
                    },
                    { //modal props
                        name: 'side-page-modal',
                        style: 'z-index: 99999',
                        class: "side-page-modal",
                        transition: "scale"
                    },
                    {} //events
                )
            },
        },
@hunterliu1003 hunterliu1003 added the enhancement New feature or request label Oct 24, 2020
@hunterliu1003
Copy link
Member

Hi @dominykasgithub,

Glad to receive your feedback.
I already add your proposal to the roadmap project, but I cannot guarantee when the feature would be released (at least 2 weeks or more).

If this feature is necessary and urgent for you, maybe you should continue to use Vue 2 with vue-js-modal.

@dominykasgithub
Copy link
Author

@hunterliu1003 Thx, don't rush, make it good :)

@hunterliu1003 hunterliu1003 added this to In progress in Roadmap Nov 10, 2020
@hunterliu1003 hunterliu1003 self-assigned this Nov 13, 2020
hunterliu1003 added a commit that referenced this issue Dec 11, 2020
hunterliu1003 added a commit that referenced this issue Dec 11, 2020
@hunterliu1003 hunterliu1003 moved this from In progress to Done in Roadmap Jan 14, 2021
@hunterliu1003
Copy link
Member

hunterliu1003 commented Jan 14, 2021

@dominykasgithub

The feature of dynamic modal is finished, but still missing docs.
I released the beta version

I will keep testing the new feature, and officially release it until stable and document ready

@hunterliu1003 hunterliu1003 changed the title Dynamic modals [Release in beta] Dynamic modals Jan 14, 2021
@hunterliu1003 hunterliu1003 changed the title [Release in beta] Dynamic modals [Released beta version] Dynamic modals Jan 14, 2021
@hunterliu1003 hunterliu1003 changed the title [Released beta version] Dynamic modals Dynamic modals Jan 14, 2021
@hunterliu1003 hunterliu1003 pinned this issue Feb 4, 2021
@Saltibarsciai
Copy link

Thanks, I'm interested how good this works :) 👍

@Saltibarsciai
Copy link

@hunterliu1003 even without docs maybe you could provide basic usage example, I tried

                this.$vfm.show({
                    component: KittenModal
                });

but it's not right, I tried looking into this code snippet

case 'object':
            {
              const defaultModal = {
                component: options.componentName,
                bind: {},
                slots: {},
                on: {}
              }
              modal = Object.assign(defaultModal, modal)
              const id = generateId()
              const name = modal.bind.name || PREFIX + id
              this.dynamicModals.push(
                shallowReactive({
                  value: true,
                  id,
                  ...modal,
                  component: modal.component,
                  slots: modal.slots,
                  bind: { ...modal.bind, name },
                  params: args[0]
                })
              )
            }
            break

it looks that it should be something like from my first example

@hunterliu1003
Copy link
Member

@Saltibarsciai thanks for your advice. You can check out the docs from here temporarily.

https://github.com/vue-final/vue-final-modal/blob/feature%2Fzh-Hant/docs/content/en/dynamic-modal.md

You have to add ModalsContainer in App.vue

<div>
  ...
  <modals-container></modals-container>
</div>

@Saltibarsciai
Copy link

thanks!

@v1r0x
Copy link

v1r0x commented Feb 8, 2021

Thank you very much for your modal and dynamic modal feature!

On problem I have with dynamic modals:
I can't get params (neither using @beforeOpen nor v-slot="{params}").

Could you give me an example how I should do it?

Edit: I also can't find a way to close the modal again (set v-model to false does not work) and I don't know how else I could close it.

Thank you!

This is my current setup:

<template>
  <vue-final-modal
    @beforeOpen="open"
    v-model="state.show"
    name="user-info-modal">
    <template v-slot="{ params }">
      Hello {{ params }}
    </template>
  </vue-final-modal>
</template>
<script>
    import {
        onMounted,
        reactive,
    } from 'vue';

    export default {
        setup(props, context) {
            const state = reactive({
                show: false,
            });

            const open = e => {
                console.log(e.ref.params); // is empty proxy
            }

            onMounted(_ => {
                state.show = true;
            });

            return {
                open,
                state,
            }
        },
    }
</script>

and from another component I call

import MyModal from 'MyModal.vue';
$vfm.show({
    component: MyModal
}, {
    param1: 'Foo',
    param2: 'Bar',
})

@hunterliu1003
Copy link
Member

Hi @v1r0x,

Thanks for your feedback.

  • I am working on fixing params in event @beforeOpen issue.
  • However, I have no idea about how to support params in scoped-slot for dynamic modal.

In addition, I think params is not needed when using dynamic modal, because dynamic modal already provide huge flexibility for developers to bind props, events, slots.

In my opinion, using props not params in dynamic modal, you can get the benefit from the type check and validation by Vue.

I would pass props param1, param2 into MyModal component with key bind

import MyModal from 'MyModal.vue';

$vfm.show({
    component: MyModal,
    bind: {
        param1: 'Foo',
        param2: 'Bar',
    }
})

So that you can get these props in MyModal.vue:

<template>
  <vue-final-modal v-model="state.show" name="user-info-modal">
    <p>Hello {{ param1 }} and {{ param2 }}</p>
  </vue-final-modal>
</template>
<script>
import { onMounted, reactive } from 'vue'

export default {
  props: {
    param1: {
      type: String,
      default: ''
    }
    param2: {
      type: String,
      default: ''
    }
  },
  setup(props, context) {
    const state = reactive({
      show: false
    })

    return {
      open,
      state
    }
  }
}
</script>

I think this is a more concise way.

@v1r0x
Copy link

v1r0x commented Feb 9, 2021

Thanks for your reply.

I'm fine with props 👍 I just thought it was a bug 😉 I already used this way as workaround. Good to know it is the intended way 😊

Thanks again. Very happy with it so far! 🎉

@hunterliu1003
Copy link
Member

Yes, this is a bug 😂, and I’ll fix it as soon as posible.

@v1r0x
Copy link

v1r0x commented Feb 9, 2021

I prefer props over @before-open, so take your time 😉

@hunterliu1003 hunterliu1003 moved this from Done to Release in Roadmap Mar 7, 2021
@hunterliu1003
Copy link
Member

This feature has been officially released in

@hunterliu1003 hunterliu1003 unpinned this issue Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta enhancement New feature or request
Projects
No open projects
Roadmap
Release
Development

No branches or pull requests

4 participants