Skip to content

Commit c9dc250

Browse files
committed
Merge branch 'dev' into next
2 parents cb48754 + 1c57ced commit c9dc250

File tree

15 files changed

+188
-131
lines changed

15 files changed

+188
-131
lines changed

README.md

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,23 @@ Changes API name from "$vfm" to any other string value. It is useful when you us
182182

183183
## **API**
184184

185-
Plugin API can be called within any component through `this.$vfm`.
186-
187-
### `$vfm.openedModals`
185+
- In Options API:
188186

189-
- Type: `Array`
190-
191-
A stack array store the opened modal's vue component instance.
187+
Plugin API can be called within any component through `this.$vfm`.
192188

193-
You can use:
194-
1. `$vfm.openedModals[0]` to get the first opened modal instance.
195-
2. `$vfm.openedModals.length` to get how many modals is opened.
189+
- In Composition API (Only in Vue 3 version):
196190

197-
### `$vfm.modals`
191+
> Only support in Vue 3
198192
199-
- Type: `Array`
193+
```js
194+
import { inject } from 'vue'
200195

201-
All modal instances include show and hide.
196+
export default {
197+
setup() {
198+
const $vfm = inject('$vfm')
199+
}
200+
}
201+
```
202202

203203
### `$vfm.show(name, params)`
204204

@@ -227,19 +227,22 @@ Or get `params` on `@beforeOpen` event:
227227

228228
```html
229229
<template>
230-
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
230+
<vue-final-modal v-model="show" name="example">
231+
<template v-slot="{ params }">
232+
Hi {{ params.userName }}
233+
</template>
234+
</vue-final-modal>
231235
</template>
232236

233237
<script>
234-
export default {
235-
name: 'MyComponent',
238+
export default {
236239
data: () => ({
237240
show: false
238241
}),
239-
mounted () {
240-
this.$vfm.show('example')
242+
mounted() {
243+
this.$vfm.show('example', { userName: 'vue-final-modal' })
241244
}
242-
}
245+
}
243246
</script>
244247
```
245248

@@ -257,7 +260,6 @@ export default {
257260

258261
<script>
259262
export default {
260-
name: 'MyComponent',
261263
data: () => ({
262264
show: true
263265
}),
@@ -298,6 +300,30 @@ Or get `params` on `@beforeOpen` event:
298300
299301
toggle modal by name.
300302

303+
### `$vfm.get(name)`
304+
305+
- Type: `Function`
306+
- Arguments:
307+
- name: `String` - Name of the modal
308+
309+
return the modal comopnent instance.
310+
311+
### `$vfm.openedModals`
312+
313+
- Type: `Array`
314+
315+
A stack array store the opened modal's vue component instance.
316+
317+
You can use:
318+
1. `$vfm.openedModals[0]` to get the first opened modal instance.
319+
2. `$vfm.openedModals.length` to get how many modals is opened.
320+
321+
### `$vfm.modals`
322+
323+
- Type: `Array`
324+
325+
All modal instances include show and hide.
326+
301327
## **Props**
302328

303329
```js

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/index.md

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ features:
3737
<a href="https://www.npmjs.com/package/vue-final-modal"><img src="https://badgen.net/badgesize/brotli/hunterliu1003/vue-final-modal/next/dist/VueFinalModal.umd.js" alt="Size"></a>
3838
</p>
3939

40-
4140
<p align="right">
4241
<a href="https://www.buymeacoffee.com/PL2qJIx" target="_blank" rel="noopener noreferrer">
4342
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-green.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" >
@@ -117,18 +116,16 @@ Vue.use(VueFinalModal())
117116

118117
```js[nuxt.config.js]
119118
export default {
120-
plugins: [
121-
'~plugins/vue-final-modal.js'
122-
],
119+
plugins: ['~plugins/vue-final-modal.js'],
123120
build: {
124-
transpile: ['vue-final-modal'],
121+
transpile: ['vue-final-modal']
125122
}
126123
}
127124
```
128125

129126
### CDN
130127

131-
> [Live demo](https://codepen.io/hunterliu1003/pen/ZEWoYeE)
128+
<alert>[Live demo](https://codepen.io/hunterliu1003/pen/ZEWoYeE)</alert>
132129

133130
- **jsDelivr**
134131

@@ -188,15 +185,15 @@ Changes component name from "VueFinalModal" to any other string value. It is use
188185
- Type: `String`
189186
- default: `'$vfm'`
190187

191-
Changes API name from "$vfm" to any other string value. It is useful when you use `vue-final-modal` as spinner, toast, notify, etc.
188+
Changes API name from "\$vfm" to any other string value. It is useful when you use `vue-final-modal` as spinner, toast, notify, etc.
192189

193190
## **API**
194191

195-
- In Options API:
192+
- **Options API**
196193

197194
Plugin API can be called within any component through `this.$vfm`.
198195

199-
- In Composition API:
196+
- **Composition API** <badge>Only in Vue 3 version</badge>
200197

201198
```js
202199
import { inject } from 'vue'
@@ -229,25 +226,28 @@ Or get `params` on `@beforeOpen` event:
229226
</vue-final-modal>
230227
```
231228

232-
> `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()`.
229+
<alert>`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()`.</alert>
233230

234231
- Example:
235232

236233
```html
237234
<template>
238-
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
235+
<vue-final-modal v-model="show" name="example">
236+
<template v-slot="{ params }">
237+
Hi {{ params.userName }}
238+
</template>
239+
</vue-final-modal>
239240
</template>
240241

241242
<script>
242-
export default {
243-
name: 'MyComponent',
243+
export default {
244244
data: () => ({
245245
show: false
246246
}),
247-
mounted () {
248-
this.$vfm.show('example')
247+
mounted() {
248+
this.$vfm.show('example', { userName: 'vue-final-modal' })
249249
}
250-
}
250+
}
251251
</script>
252252
```
253253

@@ -260,19 +260,18 @@ export default {
260260

261261
```html
262262
<template>
263-
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
263+
<vue-final-modal v-model="show" name="example">Vue Final Modal is awesome</vue-final-modal>
264264
</template>
265265

266266
<script>
267-
export default {
268-
name: 'MyComponent',
267+
export default {
269268
data: () => ({
270269
show: true
271270
}),
272-
mounted () {
273-
this.$vfm.hide('example')
271+
mounted() {
272+
this.$vfm.hide('example')
274273
}
275-
}
274+
}
276275
</script>
277276
```
278277

@@ -302,7 +301,7 @@ Or get `params` on `@beforeOpen` event:
302301
</vue-final-modal>
303302
```
304303

305-
> `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+
<alert>`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()`.</alert>
306305

307306
toggle modal by name.
308307

@@ -321,6 +320,7 @@ return the modal comopnent instance.
321320
A stack array store the opened modal's vue component instance.
322321

323322
You can use:
323+
324324
1. `$vfm.openedModals[0]` to get the first opened modal instance.
325325
2. `$vfm.openedModals.length` to get how many modals is opened.
326326

@@ -464,7 +464,7 @@ Set the root element of `vue-final-modal` style to `pointer-events: none;`.
464464

465465
Specifies which DOM element that this component should detach to.
466466

467-
1. Set `false` will disabled this feature.
467+
1. Set `false` will disabled this feature.
468468
2. String can be any valid `querySelector`, e.g. `'body'`, `'#app'`.
469469
3. Object can be any valid `Node`, e.g. `this.$refs.container`.
470470

@@ -513,21 +513,20 @@ Enables focus trap meaning that only inputs/buttons that are withing the modal w
513513

514514
```vue
515515
<template>
516-
<vue-final-modal
517-
@click-outside="clickOutside"
518-
@before-open="beforeOpen"
519-
@opened="opened"
520-
@before-close="beforeClose"
521-
@closed="closed"
522-
>
523-
...modal content
524-
</vue-final-modal>
516+
<vue-final-modal
517+
@click-outside="clickOutside"
518+
@before-open="beforeOpen"
519+
@opened="opened"
520+
@before-close="beforeClose"
521+
@closed="closed"
522+
>
523+
...modal content
524+
</vue-final-modal>
525525
</template>
526526
```
527527

528528
</show-code>
529529

530-
531530
### `@click-outside`
532531

533532
- Emits while modal container on click.
@@ -544,7 +543,7 @@ If prop `clickToClose` is `false`, the event will still be emitted.
544543

545544
### `@opened`
546545

547-
- Emits after modal became visible and transition ended.
546+
- Emits after modal became visible and transition ended.
548547

549548
### `@before-close`
550549

@@ -572,12 +571,11 @@ Or get `params` on `@beforeOpen` event:
572571
</vue-final-modal>
573572
```
574573

575-
> `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()`.
576-
574+
<alert>`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()`.</alert>
577575

578576
## **Contribution**
579577

580-
👋 Hi I'm Hunter, the author of `vue-final-modal`.
578+
👋 Hi I'm Hunter, the author of `vue-final-modal`.
581579

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

@@ -594,6 +592,6 @@ To develop vue-final-modal, I learn a lot from these awesome libraries:
594592
- [Bootstrap Vue](https://bootstrap-vue.org/)
595593
- lockScroll
596594

597-
> There is no perfect library even the `final` of vue modal.
595+
<alert>There is no perfect library even the `final` of vue modal.</alert>
598596

599-
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).
597+
🚀 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).

example/src/components/basic/BasicOptions.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
<v-modal
44
v-model="showModal"
55
:ssr="ssr"
6-
:lockScroll="lockScroll"
7-
:hideOverlay="hideOverlay"
8-
:clickToClose="clickToClose"
9-
:escToClose="escToClose"
10-
:preventClick="preventClick"
6+
:lock-scroll="lockScroll"
7+
:hide-overlay="hideOverlay"
8+
:click-to-close="clickToClose"
9+
:esc-to-close="escToClose"
10+
:prevent-click="preventClick"
1111
:transition="transition ? 'vfm' : ''"
1212
:overlay-transition="overlayTransition ? 'vfm' : ''"
1313
:z-index-auto="zIndexAuto"

example/yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5129,11 +5129,6 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
51295129
dependencies:
51305130
is-extglob "^2.1.1"
51315131

5132-
is-mobile@^2.2.2:
5133-
version "2.2.2"
5134-
resolved "https://registry.yarnpkg.com/is-mobile/-/is-mobile-2.2.2.tgz#f6c9c5d50ee01254ce05e739bdd835f1ed4e9954"
5135-
integrity sha512-wW/SXnYJkTjs++tVK5b6kVITZpAZPtUrt9SF80vvxGiF/Oywal+COk1jlRkiVq15RFNEQKQY31TkV24/1T5cVg==
5136-
51375132
is-negative-zero@^2.0.0:
51385133
version "2.0.0"
51395134
resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.0.tgz#9553b121b0fac28869da9ed459e20c7543788461"

lib/Plugin.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { bindPrototype, registComponent } from './PluginCore'
22
import { DUPLICATE_PLUGIN_COMPONENT, DUPLICATE_COMPONENT } from './utils/errors'
3-
import mobile from 'is-mobile'
43

54
const defaultOptions = {
65
componentName: 'VueFinalModal',
7-
key: '$vfm',
8-
isMobile: mobile()
6+
key: '$vfm'
97
}
108

119
const Plugin = () => ({

lib/PluginCore.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import VueFinalModal from './VueFinalModal.vue'
2-
import { setStyle, removeStyle } from './utils/dom.js'
32

4-
function createVfm(options) {
3+
function createVfm() {
54
let vfm
65

76
return function() {
@@ -23,27 +22,6 @@ function createVfm(options) {
2322
modal.toggle(...args)
2423
}
2524
},
26-
isScrollLocked: false,
27-
lockScroll() {
28-
if (this.isScrollLocked) return
29-
if (options.isMobile) {
30-
setStyle(document.body, 'overflow', 'hidden')
31-
} else {
32-
window.addEventListener('wheel', this.lockScrollListener, { passive: false })
33-
}
34-
this.isScrollLocked = true
35-
},
36-
unlockScroll() {
37-
if (options.isMobile) {
38-
removeStyle(document.body, 'overflow')
39-
} else {
40-
window.removeEventListener('wheel', this.lockScrollListener)
41-
}
42-
this.isScrollLocked = false
43-
},
44-
lockScrollListener(e) {
45-
e.preventDefault()
46-
},
4725
get(name) {
4826
return this.modals.find(modal => modal.props.name === name)
4927
},
@@ -57,7 +35,7 @@ function createVfm(options) {
5735
}
5836

5937
export function bindPrototype(app, options) {
60-
const vfm = createVfm(options)()
38+
const vfm = createVfm()()
6139
Object.defineProperty(app.config.globalProperties, options.key, {
6240
get() {
6341
return vfm

0 commit comments

Comments
 (0)