Skip to content

Commit

Permalink
Merge pull request #8 from Tnifey/feature/body-scroll-options
Browse files Browse the repository at this point in the history
Add body-scroll options
  • Loading branch information
Pete Hegman authored May 18, 2020
2 parents c6ad5b5 + 6177f40 commit 5c96af4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ export default {
</script>
```

### [body-scroll-lock](https://github.com/willmcpo/body-scroll-lock#options) options

Options can be passed when installing the directive:

```js
import VScrollLock from 'v-scroll-lock'

Vue.use(VScrollLock, {
bodyScrollOptions: {
reserveScrollBarGap: true,
},
})
```

See [https://github.com/willmcpo/body-scroll-lock#options](https://github.com/willmcpo/body-scroll-lock#options) for full list of options.

### Providing Your Own Version of [body-scroll-lock](https://github.com/willmcpo/body-scroll-lock)

To make using this directive easier [body-scroll-lock](https://github.com/willmcpo/body-scroll-lock) is included in the package. In the case that you would like to use a version different than the packaged version this can be specified in the plugin options. Also note that `v-scroll-lock-no-dep.esm.js` should be imported to prevent duplicate code in your bundle. See example below:
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const VScrollLock: VScrollLockInterface = {
const {
enableBodyScroll: enableBodyScrollOption,
disableBodyScroll: disableBodyScrollOption,
bodyScrollOptions,
} = options

if (enableBodyScrollOption) {
Expand All @@ -25,6 +26,10 @@ const VScrollLock: VScrollLockInterface = {
if (disableBodyScrollOption) {
this.disableBodyScroll = disableBodyScrollOption
}

if (bodyScrollOptions) {
this.bodyScrollOptions = bodyScrollOptions
}
}
Vue.directive('scroll-lock', {
inserted: this.inserted.bind(this),
Expand All @@ -34,12 +39,12 @@ const VScrollLock: VScrollLockInterface = {
},
inserted(el, binding) {
if (binding.value) {
this.disableBodyScroll(el)
this.disableBodyScroll(el, this.bodyScrollOptions)
}
},
componentUpdated(el, binding) {
if (binding.value) {
this.disableBodyScroll(el)
this.disableBodyScroll(el, this.bodyScrollOptions)
} else {
this.enableBodyScroll(el)
}
Expand Down
7 changes: 6 additions & 1 deletion src/interfaces/plugin-options.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock'
import {
disableBodyScroll,
enableBodyScroll,
BodyScrollOptions,
} from 'body-scroll-lock'

export default interface PluginOptions {
disableBodyScroll?: typeof disableBodyScroll
enableBodyScroll?: typeof enableBodyScroll
bodyScrollOptions?: Partial<BodyScrollOptions>
}
7 changes: 6 additions & 1 deletion src/interfaces/v-scroll-lock.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import PluginOptions from './plugin-options.interface'
import { PluginFunction, DirectiveFunction } from 'vue'
import { enableBodyScroll, disableBodyScroll } from 'body-scroll-lock'
import {
enableBodyScroll,
disableBodyScroll,
BodyScrollOptions,
} from 'body-scroll-lock'

export default interface VScrollLock {
enableBodyScroll: typeof enableBodyScroll
Expand All @@ -9,4 +13,5 @@ export default interface VScrollLock {
inserted: DirectiveFunction
componentUpdated: DirectiveFunction
unbind: DirectiveFunction
bodyScrollOptions?: Partial<BodyScrollOptions>
}

0 comments on commit 5c96af4

Please sign in to comment.