Skip to content

Commit 6d87697

Browse files
committed
feat: add useC2v API
1 parent 184dd46 commit 6d87697

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

packages/vue-final-modal/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export { vueFinalModalProps } from './components/VueFinalModal/VueFinalModalProp
2121
export type { VueFinalModalEmits } from './components/VueFinalModal/VueFinalModal.vue'
2222

2323
/** Composables */
24-
export { useVfm, useModal, useVfmAttrs, c2v } from './useApi'
24+
export { useVfm, useModal, useVfmAttrs, useC2v, c2v } from './useApi'
2525

2626
declare module '@vue/runtime-core' {
2727
export interface ComponentCustomProperties {

packages/vue-final-modal/src/useApi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ function withMarkRaw<T extends Component>(options: Partial<UseModalOptions<T>>,
5252
}
5353
}
5454

55+
/**
56+
* Create a dynamic vNode.
57+
*/
58+
export function useC2v<T extends Component>(_options: C2VOptions<T>) {
59+
const id = Symbol(__DEV__ ? 'useC2v' : '')
60+
61+
const vNode = h(_options.component, { key: id, ..._options.attrs }, _options.slots)
62+
63+
tryOnUnmounted(() => {
64+
removeVNode(vNode)
65+
})
66+
67+
return {
68+
open: () => pushVNode(vNode),
69+
close: () => removeVNode(vNode),
70+
}
71+
}
72+
5573
/**
5674
* Create a dynamic modal.
5775
*/

viteplay/src/components/VueFinalModal/Basic.example.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { ref } from 'vue'
3-
import { ModalsContainer, VueFinalModal, c2v, useModal, useVfm } from 'vue-final-modal'
3+
import { ModalsContainer, VueFinalModal, c2v, useC2v, useModal, useVfm } from 'vue-final-modal'
44
import DefaultSlot from '../DefaultSlot.vue'
55
import { modal } from './modalsHelpers'
66
import TestModal from './TestModal.vue'
@@ -79,6 +79,31 @@ function clickOutside() {
7979
// onMounted(() => {
8080
// show.value = true
8181
// })
82+
83+
const { open } = useC2v({
84+
component: DefaultSlot,
85+
attrs: {
86+
text: 'c2v',
87+
},
88+
// slots: {
89+
// default: c2v({
90+
// component: DefaultSlot,
91+
// attrs: {
92+
// text: '456',
93+
// },
94+
// slots: {
95+
// default: c2v({
96+
// component: DefaultSlot,
97+
// attrs: {
98+
// text: '789',
99+
// },
100+
// }),
101+
// },
102+
// }),
103+
// },
104+
})
105+
106+
open()
82107
</script>
83108

84109
<template>

0 commit comments

Comments
 (0)