Skip to content

Commit 1c4790a

Browse files
committed
docs: dynamic modal
1 parent d444629 commit 1c4790a

File tree

10 files changed

+538
-264
lines changed

10 files changed

+538
-264
lines changed

README.md

Lines changed: 48 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ features:
5252

5353
**Vue 3.0**
5454

55+
version `1.x`, `3.x` is for Vue 3.x.
56+
5557
NPM:
5658

5759
```bash
@@ -66,16 +68,18 @@ yarn add vue-final-modal@next
6668

6769
**Vue 2.0**
6870

71+
version `0.x`, `2.x` is for Vue 2.x.
72+
6973
NPM:
7074

7175
```bash
72-
npm install vue-final-modal --save
76+
npm install vue-final-modal@latest --save
7377
```
7478

7579
Yarn:
7680

7781
```bash
78-
yarn add vue-final-modal
82+
yarn add vue-final-modal@latest
7983
```
8084

8185
## Registeration
@@ -104,9 +108,7 @@ Vue.use(VueFinalModal())
104108
```js
105109
// nuxt.config.js
106110
export default {
107-
plugins: [
108-
{ src: '~plugins/vue-final-modal.js' }
109-
],
111+
plugins: [{ src: '~plugins/vue-final-modal.js' }],
110112
build: {
111113
transpile: ['vue-final-modal']
112114
}
@@ -167,30 +169,17 @@ import VueFinalModal from 'vue-final-modal'
167169
Vue.use(VueFinalModal(), { ... })
168170
```
169171

170-
### `componentName`
171-
172-
- Type: `String`
173-
- default: `'VueFinalModal'`
174-
175-
Changes component name from "VueFinalModal" to any other string value. It is useful when there is already a global "modal" component.
176-
177-
### `key`
178-
179-
- Type: `String`
180-
- default: `'$vfm'`
181-
182-
Changes API name from "$vfm" to any other string value. It is useful when you use `vue-final-modal` as spinner, toast, notify, etc.
183-
172+
- `componentName`
173+
- `key`
174+
- `dynamicContainerName`
184175

185176
## **API**
186177

187178
- In Options API:
188179

189180
Plugin API can be called within any component through `this.$vfm`.
190181

191-
- In Composition API (Only in Vue 3 version):
192-
193-
> Only support in Vue 3
182+
- In Composition API (Vue 3 only):
194183

195184
```js
196185
import { inject } from 'vue'
@@ -202,184 +191,47 @@ export default {
202191
}
203192
```
204193

205-
### `$vfm.show(name, params)`
206-
207-
- Type: `Function`
208-
- Arguments:
209-
- name: `String` - Name of the modal
210-
- params: `?: object` - Any data that you would want to pass into the modal (@before-open event handler will contain `params` in the event). You can also using scoped-slot to get `params` in template:
211-
212-
```html
213-
<template v-slot="{ params }">
214-
<!-- modal content -->
215-
</template>
216-
```
217-
218-
Or get `params` on `@beforeOpen` event:
219-
220-
```html
221-
<vue-final-modal @beforeOpen="e => e.ref.params">
222-
<!-- modal content -->
223-
</vue-final-modal>
224-
```
225-
226-
> `parmas` will be reset to `{}` automatically after `closed` event. You can avoid the modal to reset the `params` to empty object by calling `event.stop()`.
227-
228-
- Example:
229-
230-
```html
231-
<template>
232-
<vue-final-modal v-model="show" name="example">
233-
<template v-slot="{ params }">
234-
Hi {{ params.userName }}
235-
</template>
236-
</vue-final-modal>
237-
</template>
238-
239-
<script>
240-
export default {
241-
data: () => ({
242-
show: false
243-
}),
244-
mounted() {
245-
this.$vfm.show('example', { userName: 'vue-final-modal' })
246-
}
247-
}
248-
</script>
249-
```
250-
251-
> `v-model` is necessary when you open a modal with `$vfm.show(name)` API.
252-
253-
### `$vfm.hide(name)`
254-
255-
- Type: `Function`
256-
- Arguments:
257-
- name: `String` - Name of the modal
258-
- Example:
259-
260-
```html
261-
<template>
262-
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
263-
</template>
264-
265-
<script>
266-
export default {
267-
data: () => ({
268-
show: true
269-
}),
270-
mounted () {
271-
this.$vfm.hide('example')
272-
}
273-
}
274-
</script>
275-
```
276-
277-
### `$vfm.hideAll()`
278-
279-
hide all modals.
280-
281-
### `$vfm.toggle(name, show, params)`
282-
283-
- Type: `Function`
284-
- Arguments:
285-
- name: `String` - Name of the modal
286-
- show: `?: Boolean` - Show modal or not
287-
- params: `?: object` - Any data that you would want to pass into the modal (@before-open event handler will contain params in the event). You can also using scoped-slot to get `params` in template:
288-
289-
```html
290-
<template v-slot="{ params }">
291-
<!-- modal content -->
292-
</template>
293-
```
294-
295-
Or get `params` on `@beforeOpen` event:
296-
297-
```html
298-
<vue-final-modal @beforeOpen="e => e.ref.params">
299-
<!-- modal content -->
300-
</vue-final-modal>
301-
```
302-
303-
> `parmas` will be reset to `{}` automatically after `closed` event. You can avoid the modal to reset the `params` to empty object by calling `event.stop()`.
304-
305-
toggle modals by name.
306-
307-
### `$vfm.get(name)`
308-
309-
- Type: `Function`
310-
- Arguments:
311-
- name: `String` - Name of the modal
312-
313-
return the modal instances.
314-
315-
### `$vfm.openedModals`
316-
317-
- Type: `Array`
318-
319-
A stack array store the opened modal's vue component instance.
320-
321-
You can use:
322-
1. `$vfm.openedModals[0]` to get the first opened modal instance.
323-
2. `$vfm.openedModals.length` to get how many modals is opened.
324-
325-
### `$vfm.modals`
326-
327-
- Type: `Array`
328-
329-
All modal instances include show and hide.
194+
- `$vfm.show(name, params)`
195+
- `$vfm.hide([names])`
196+
- `$vfm.hideAll()`
197+
- `$vfm.toggle(name, show, params)`
198+
- `$vfm.get([names])`
199+
- `$vfm.dynamicModals`
200+
- `$vfm.openedModals`
201+
- `$vfm.modals`
330202

331203
## **Props**
332204

333-
```js
334-
{
335-
value: { type: Boolean, default: false },
336-
name: { type: String, default: null },
337-
ssr: { type: Boolean, default: true },
338-
classes: { type: [String, Object, Array], default: '' },
339-
overlayClass: { type: [String, Object, Array], default: '' },
340-
contentClass: { type: [String, Object, Array], default: '' },
341-
styles: { type: [String, Object, Array], default: '' },
342-
overlayStyle: { type: [String, Object, Array], default: '' },
343-
contentStyle: { type: [String, Object, Array], default: '' },
344-
lockScroll: { type: Boolean, default: true },
345-
hideOverlay: { type: Boolean, default: false },
346-
clickToClose: { type: Boolean, default: true },
347-
escToClose: { type: Boolean, default: false },
348-
preventClick: { type: Boolean, default: false },
349-
attach: { type: null, default: false, validator: validateAttachTarget },
350-
transition: { type: String, default: 'vfm' },
351-
overlayTransition: { type: String, default: 'vfm' },
352-
zIndexAuto: { type: Boolean, default: true },
353-
zIndexBase: { type: [String, Number], default: 1000 },
354-
zIndex: { type: [Boolean, String, Number], default: false },
355-
focusRetain: { type: Boolean, default: true },
356-
focusTrap: { type: Boolean, default: false }
357-
}
358-
```
205+
- `value`
206+
- `name`
207+
- `ssr`
208+
- `classes`
209+
- `overlayClass`
210+
- `contentClass`
211+
- `styles`
212+
- `overlayStyle`
213+
- `contentStyle`
214+
- `lockScroll`
215+
- `hideOverlay`
216+
- `clickToClose`
217+
- `escToClose`
218+
- `preventClick`
219+
- `attach`
220+
- `transition`
221+
- `overlayTransition`
222+
- `zIndexAuto`
223+
- `zIndexBase`
224+
- `zIndex`
225+
- `focusRetain`
226+
- `focusTrap`
359227

360228
## **Events**
361229

362-
### `@click-outside`
363-
364-
- Emits while modal container on click.
365-
366-
> If prop `clickToClose` is `false`, the event will still be emitted.
367-
368-
### `@before-open`
369-
370-
- Emits while modal is still invisible, but before transition starting. Further opening of the modal can be blocked from this event listener by calling `event.stop()`.
371-
372-
### `@opened`
373-
374-
- Emits after modal became visible and transition ended.
375-
376-
### `@before-close`
377-
378-
- Emits before modal is going to be closed. Further closing of the modal can be blocked from this event listener by calling `event.stop()`.
379-
380-
### `@closed`
381-
382-
- Emits right before modal is destroyed. Further after the modal was closed, you can avoid the modal to reset the `params` to empty object by calling `event.stop()`.
230+
- `@click-outside`
231+
- `@before-open`
232+
- `@opened`
233+
- `@before-close`
234+
- `@closed`
383235

384236
## **Slots**
385237

@@ -403,7 +255,7 @@ Or get `params` on `@beforeOpen` event:
403255
404256
## **Contribution**
405257

406-
👋 Hi I'm Hunter, the author of `vue-final-modal`.
258+
👋 Hi I'm Hunter, the author of `vue-final-modal`.
407259

408260
To develop vue-final-modal, I learn a lot from these awesome libraries:
409261

@@ -420,6 +272,6 @@ To develop vue-final-modal, I learn a lot from these awesome libraries:
420272
- [Bootstrap Vue](https://bootstrap-vue.org/)
421273
- lockScroll
422274

423-
> There is no perfect library even the `final` of vue modal.
275+
> There is no perfect library even the `final` of vue modal.
424276
425277
If you have any ideas for optimization of `vue-final-modal`, feel free to open [issues](https://github.com/hunterliu1003/vue-final-modal/issues) or [pull requests](https://github.com/hunterliu1003/vue-final-modal/pulls).

0 commit comments

Comments
 (0)