@@ -23,35 +23,114 @@ import { ModalsContainer } from 'vue-final-modal'
2323
2424## Usage
2525
26+ ### Passing Props and Events
27+
2628``` ts
2729import { VueFinalModal , useModal } from ' vue-final-modal'
2830
29- const modalInstance = useModal ({
31+ const { open, close, options, patchOptions } = useModal ({
32+ // `component` is optional and the default value is `<VueFinalModal>`.
3033 component: VueFinalModal ,
34+ // Open the modal or not when the modal was created, the default value is `false`.
35+ defaultModelValue: false ,
3136 attrs: {
32- // Props
33- displayDirective: ' if' ,
37+ // Bind props to the modal component (VueFinalModal in this case).
3438 clickToClose: true ,
3539 escToClose: true ,
36- // Events
40+ // Bind events to the modal component (VueFinalModal in this case).
3741 onBeforeOpen() { /* on before open */ },
3842 onOpened() { /* on opened */ },
3943 onBeforeClose() { /* on before close */ },
4044 onClosed() { /* on closed */ },
41- },
45+ }
46+ })
47+
48+ // Open the modal
49+ open ().then (() => { /* Do something after modal opened */ })
50+ // Close the modal
51+ close ().then (() => { /* Do something after modal closed */ })
52+ // Checkout the modal options
53+ options // the state of the dynamic modal
54+
55+ // Overwrite the modal options
56+ patchOptions ({
57+ attrs: {
58+ // Overwrite the modal's props
59+ clickToClose: false ,
60+ escToClose: false ,
61+ }
62+ })
63+ ```
64+
65+ ### Passing Slots
66+
67+ #### with ` String `
68+
69+
70+ ``` ts
71+ import { VueFinalModal , useModal } from ' vue-final-modal'
72+
73+ const modalInstance = useModal ({
74+ component: VueFinalModal ,
75+ attrs: { ... },
4276 slots: {
4377 default: ' <p>The content of the modal</p>'
4478 }
4579})
80+ ```
81+
82+ :: alert { type =warning }
83+ Security Note: https://vuejs.org/api/built-in-directives.html#v-html
84+ Dynamically rendering arbitrary HTML on your website can be very dangerousbecause it can easily lead to XSS attacks. Only use v-html on trusted content and never on user-provided content.
85+ ::
86+
87+ #### with ` Component `
4688
47- modalInstance .open ().then (() => { /* Do something after modal opened */ })
48- modalInstance .close ().then (() => { /* Do something after modal closed */ })
49- modalInstance .options // the state of the dynamic modal
5089
51- // Overwrite the dynamic modal options
52- modalInstance .patchOptions ({})
90+ ``` ts
91+ import { VueFinalModal , useModal } from ' vue-final-modal'
92+ // ModalContent is the component you want to put into the modal content
93+ import ModalContent from ' ./ModalContent.vue'
94+
95+
96+ const modalInstance = useModal ({
97+ component: VueFinalModal ,
98+ attrs: { ... },
99+ slots: {
100+ // You can import your own component as a slot and put it to `slots.default` without binding props and events.
101+ default: ModalContent
102+ }
103+ })
53104```
54105
106+ #### with ` Component ` , ` Props ` and ` Events `
107+
108+ ``` ts
109+ import { VueFinalModal , useModal , useModalSlot } from ' vue-final-modal'
110+ // ModalContent is the component you want to put into the modal content
111+ import ModalContent from ' ./ModalContent.vue'
112+
113+ const modalInstance = useModal ({
114+ component: VueFinalModal ,
115+ attrs: { ... },
116+ slots: {
117+ default: useModalSlot ({
118+ component: ModalContent ,
119+ attrs: {
120+ // Bind ModalContent props
121+ title: ' Hello world!'
122+ // Bind ModalContent events
123+ onConfirm () { }
124+ }
125+ })
126+ }
127+ })
128+ ```
129+
130+ :: alert { type =info }
131+ ` useModalSlot() ` is a function that provides better DX for type checking. It just returns the same object you passed in.
132+ ::
133+
55134## Edge Usage
56135
57136:: alert { type =danger }
0 commit comments