Skip to content

Commit 7096354

Browse files
Merge pull request #304 from vue-final/feature/enhance-use-modal
feat: `useModal()` slots allow passing components directly
2 parents d79d7f2 + cfe4632 commit 7096354

File tree

20 files changed

+91
-58
lines changed

20 files changed

+91
-58
lines changed

docs/components/content/BottomSheetPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import BottomSheet from './BottomSheet.vue'
44
55
const { open } = useModal({
6-
component: markRaw(BottomSheet),
6+
component: BottomSheet,
77
})
88
</script>
99

docs/components/content/DragResizeModalPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import DragResizeModal from './DragResizeModal.vue'
44
55
const { open } = useModal({
6-
component: markRaw(DragResizeModal),
6+
component: DragResizeModal,
77
})
88
</script>
99

docs/components/content/FullscreenPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import Fullscreen from './Fullscreen.vue'
44
55
const { open } = useModal({
6-
component: markRaw(Fullscreen),
6+
component: Fullscreen,
77
})
88
</script>
99

docs/components/content/LoginFormModalPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import LoginFormModal from './LoginFormModal.vue'
44
55
const { open, close } = useModal<InstanceType<typeof LoginFormModal>['$props']>({
6-
component: markRaw(LoginFormModal),
6+
component: LoginFormModal,
77
attrs: {
88
onSubmit(formData) {
99
alert(JSON.stringify(formData, null, 2))

docs/components/content/NestedModalPreview.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import ConfirmModal from './ConfirmModal.vue'
44
55
const confirm1 = useModal({
6-
component: markRaw(ConfirmModal),
6+
component: ConfirmModal,
77
attrs: {
88
title: 'The first confirm modal',
99
onConfirm() {
@@ -16,7 +16,7 @@ const confirm1 = useModal({
1616
})
1717
1818
const confirm2 = useModal({
19-
component: markRaw(ConfirmModal),
19+
component: ConfirmModal,
2020
attrs: {
2121
title: 'The second confirm modal',
2222
onConfirm() {

docs/components/content/PlainCssConfirmModalPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ModalsContainer, useModal } from 'vue-final-modal'
33
import PlainCssConfirmModal from './PlainCssConfirmModal.vue'
44
55
const { open, close } = useModal({
6-
component: markRaw(PlainCssConfirmModal),
6+
component: PlainCssConfirmModal,
77
attrs: {
88
title: 'Hello World!',
99
onConfirm() {

docs/components/content/UseModalPreview.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ConfirmModal from './ConfirmModal.vue'
55
const { open, close } = useModal<
66
InstanceType<typeof ConfirmModal>['$props']
77
>({
8-
component: markRaw(ConfirmModal),
8+
component: ConfirmModal,
99
attrs: {
1010
title: 'Hello World!',
1111
onConfirm() {

docs/content/2.get-started/1.guide/3.migration-guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ So this:
8181

8282
```ts
8383
this.$vfm.show({
84-
component: markRaw(ConfirmModal),
84+
component: ConfirmModal,
8585
bind: {
8686
name: 'ConfirmModalName'
8787
},
@@ -103,7 +103,7 @@ Will be re-written as this:
103103

104104
```ts
105105
const { open, close } = useModal<InstanceType<typeof ConfirmModal>['$props']>({
106-
component: markRaw(ConfirmModal),
106+
component: ConfirmModal,
107107
attrs: {
108108
title: 'Hello World!',
109109
onConfirm() {

docs/content/2.get-started/1.guide/4.types.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,28 @@ export type ModalId = number | string | symbol
2020
export type StyleValue = string | CSSProperties | (string | CSSProperties)[]
2121
```
2222
23+
## ModalSlot
24+
25+
```ts
26+
export type ModalSlot<T extends Record<string, any> = {}> = string | Component | {
27+
component: Component
28+
attrs?: T
29+
}
30+
```
31+
2332
## UseModalOptionsPrivate
2433
2534
```ts
2635
export type UseModalOptionsPrivate<
27-
ModalProps extends ComponentProps,
28-
DefaultSlotProps extends ComponentProps,
36+
ModalProps extends ComponentProps = {},
37+
DefaultSlotProps extends ComponentProps = {},
2938
> = {
3039
context?: Vfm
3140
component: Component
3241
attrs?: ModalProps
3342
slots?: {
34-
default: string | {
35-
component: Component
36-
attrs?: DefaultSlotProps
37-
}
38-
[key: string]: any
43+
default: ModalSlot<DefaultSlotProps>
44+
[key: string]: ModalSlot
3945
}
4046

4147
id?: symbol

docs/content/3.api/2.composables/1.use-modal.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ import { ModalsContainer } from 'vue-final-modal'
2424
## Usage
2525

2626
```ts
27-
import { markRaw } from 'vue'
2827
import { VueFinalModal, useModal } from 'vue-final-modal'
2928

3029
const modalInstance = useModal<
3130
InstanceType<typeof VueFinalModal>['$props']
3231
>({
33-
component: markRaw(VueFinalModal),
32+
component: VueFinalModal,
3433
attrs: {
3534
// Props
3635
displayDirective: 'if',
@@ -43,7 +42,7 @@ const modalInstance = useModal<
4342
onClosed() { /* on closed */ },
4443
},
4544
slots: {
46-
defaults: '<p>The content of the modal</p>'
45+
default: '<p>The content of the modal</p>'
4746
}
4847
})
4948

@@ -90,20 +89,19 @@ You have to manually calling `modalInstance.destroy()`{lang=ts} whenever you no
9089
- Then you can using `useModal()`{lang=ts} everywhere by given the same `vfm` instance to `options.context`{lang=ts}:
9190
```ts
9291
// Anywhere outside out script setup
93-
import { markRaw } from 'vue'
9492
import { VueFinalModal, useModal } from 'vue-final-modal'
9593
import { vfm } from '@/plugins/vue-final-modal'
9694

9795
export function openConfirmModal() {
9896
const modalInstance = useModal({
9997
context: vfm,
100-
component: markRaw(MyConfirmModal),
98+
component: MyConfirmModal,
10199
attrs: {
102100
onClosed() {
103101
modalInstance.destroy()
104102
},
105103
},
106-
slots: { defaults: '<p>The content of the modal</p>' }
104+
slots: { default: '<p>The content of the modal</p>' }
107105
})
108106

109107
modalInstance.open()
@@ -126,20 +124,19 @@ You have to manually calling `modalInstance.destroy()`{lang=ts} whenever you no
126124
- Then you can using `useModal()`{lang=ts} everywhere by given the same `vfm` instance to `options.context`{lang=ts}:
127125
```ts
128126
// Anywhere outside out script setup
129-
import { markRaw } from 'vue'
130127
import { VueFinalModal, useModal } from 'vue-final-modal'
131128
import { vfm } from '@/plugins/vue-final-modal'
132129

133130
export function openConfirmModal() {
134131
const modalInstance = useModal({
135132
context: vfm,
136-
component: markRaw(MyConfirmModal),
133+
component: MyConfirmModal,
137134
attrs: {
138135
onClosed() {
139136
modalInstance.destroy()
140137
},
141138
},
142-
slots: { defaults: '<p>The content of the modal</p>' }
139+
slots: { default: '<p>The content of the modal</p>' }
143140
})
144141

145142
modalInstance.open()

0 commit comments

Comments
 (0)