Skip to content

Commit 651f07f

Browse files
committed
feat: support v-on for slot component in dynamic modal
1 parent 44852e3 commit 651f07f

File tree

10 files changed

+33
-29
lines changed

10 files changed

+33
-29
lines changed

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/en/dynamic-modal.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ To show dynamic modal you can use the API `$vfm.show` function.
4545

4646
```ts
4747
type dynamicModalOptions = {
48-
component?: string | Component | AsyncComponent, // modal component
48+
component?: string | Component | AsyncComponent // modal component
4949
bind?: { [key: string]: any}, // bind props and attrs to modal
50-
on?: { [key: string]: Function | Function[] }, // register events to modal
50+
on?: { [key: string]: Function | Function[] } // register events to modal
5151
slots?: {
5252
[key: string]: { // slot name
5353
component: string | Component | AsyncComponent // slot component
54-
bind: { [key: string]: any } // bind props and attrs to slot component
54+
bind?: { [key: string]: any } // bind props and attrs to slot component
55+
on?: { [key: string]: Function | Function[] } // register events to slot component
5556
}
5657
}
5758
}
@@ -200,16 +201,16 @@ export default {
200201
close()
201202
},
202203
// event by vue-final-modal
203-
clickOutside() {
204+
'click-outside'() {
204205
console.log('@click-outside')
205206
},
206-
beforeOpen() {
207+
'before-open'() {
207208
console.log('@before-open')
208209
},
209210
opened() {
210211
console.log('@opened')
211212
},
212-
beforeClose() {
213+
'before-close'() {
213214
console.log('@before-close')
214215
},
215216
closed() {

docs/content/zh-Hant/dynamic-modal.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ To show dynamic modal you can use the API `$vfm.show` function.
4545

4646
```ts
4747
type dynamicModalOptions = {
48-
component?: string | Component | AsyncComponent, // modal component
48+
component?: string | Component | AsyncComponent // modal component
4949
bind?: { [key: string]: any}, // bind props and attrs to modal
50-
on?: { [key: string]: Function | Function[] }, // register events to modal
50+
on?: { [key: string]: Function | Function[] } // register events to modal
5151
slots?: {
5252
[key: string]: { // slot name
5353
component: string | Component | AsyncComponent // slot component
54-
bind: { [key: string]: any } // bind props and attrs to slot component
54+
bind?: { [key: string]: any } // bind props and attrs to slot component
55+
on?: { [key: string]: Function | Function[] } // register events to slot component
5556
}
5657
}
5758
}
@@ -200,16 +201,16 @@ export default {
200201
close()
201202
},
202203
// event by vue-final-modal
203-
clickOutside() {
204+
'click-outside'() {
204205
console.log('@click-outside')
205206
},
206-
beforeOpen() {
207+
'before-open'() {
207208
console.log('@before-open')
208209
},
209210
opened() {
210211
console.log('@opened')
211212
},
212-
beforeClose() {
213+
'before-close'() {
213214
console.log('@before-close')
214215
},
215216
closed() {

example/src/App.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<v-stop-before-open></v-stop-before-open>
2828
<h2 class="text-3xl py-2">Dynamic modal</h2>
2929
<v-dynamic></v-dynamic>
30+
<h2 class="text-3xl py-2">Advanced dynamic modal</h2>
31+
<v-dynamic-advanced></v-dynamic-advanced>
3032

3133
<modals-container></modals-container>
3234
<div v-for="i in 100" :key="i">{{ i }}</div>

example/src/components/basic/VDynamicAdvanced.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ export default {
2424
close()
2525
},
2626
// event by vue-final-modal
27-
clickOutside() {
27+
'click-outside'() {
2828
console.log('@click-outside')
2929
},
30-
beforeOpen() {
30+
'before-open'() {
3131
console.log('@before-open')
3232
},
3333
opened() {
3434
console.log('@opened')
3535
},
36-
beforeClose() {
36+
'before-close'() {
3737
console.log('@before-close')
3838
},
3939
closed() {

lib/ModalsContainer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@before-open="e => beforeOpen(e, modal)"
1212
>
1313
<template v-for="(slot, key) in modal.slots" v-slot:[key]>
14-
<component :key="key" :is="slot.component" v-bind="slot.bind" />
14+
<component :key="key" :is="slot.component" v-bind="slot.bind" v-on="slot.on" />
1515
</template>
1616
</component>
1717
</div>

types/index.d.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import './lib'
33

44
export class VueFinalModalComponant extends Vue {
55
$refs: {
6-
vfmContainer: HTMLDivElement,
6+
vfmContainer: HTMLDivElement
77
}
88
}
99

@@ -15,14 +15,14 @@ export interface DynamicModalOptions {
1515
/**
1616
* bind props and attrs to modal
1717
*/
18-
bind?: {[key: string]: any}
18+
bind?: { [key: string]: any }
1919
/**
2020
* register events to modal
2121
*/
2222
on?: VNodeData['on']
2323
/**
2424
* modal component slot
25-
*
25+
*
2626
* @example
2727
* ```js
2828
* {
@@ -40,7 +40,8 @@ export interface DynamicModalOptions {
4040
slots?: {
4141
[key: string]: {
4242
component: string | Component | AsyncComponent
43-
bind: {[key: string]: any}
43+
bind?: { [key: string]: any }
44+
on?: { [key: string]: Function | Function[] }
4445
}
4546
}
4647
}
@@ -54,7 +55,7 @@ interface DynamicModalData extends DynamicModalOptions {
5455
export interface VueFinalModalProperty {
5556
readonly dynamicModals: DynamicModalData[]
5657
readonly openedModals: VueFinalModalComponant[]
57-
readonly modals: VueFinalModalComponant[],
58+
readonly modals: VueFinalModalComponant[]
5859
get(...names: string[]): VueFinalModalComponant[]
5960

6061
show(name: string, params?: any): void
@@ -67,19 +68,18 @@ export interface VueFinalModalProperty {
6768
toggle(name: string | string[], show?: boolean, params?: any): void
6869
}
6970

70-
7171
declare module 'vue/types/vue' {
7272
interface Vue {
7373
readonly $vfm: VueFinalModalProperty
7474
}
7575
}
7676

7777
export interface VfmOptions {
78-
dynamicContainerName?: string,
79-
componentName?: string,
78+
dynamicContainerName?: string
79+
componentName?: string
8080
key?: string
8181
}
8282

8383
declare const VfmPlugin: () => PluginObject<VfmOptions>
8484

85-
export default VfmPlugin
85+
export default VfmPlugin

0 commit comments

Comments
 (0)