Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default options #94

Merged
merged 1 commit into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import directive from './v-blur'

export const defaultOptions = {
opacity: 0.5,
filter: 'blur(1.5px)',
transition: 'all .2s linear'
}

const plugin = {
install (Vue) {
install (Vue, options) {
if (options && typeof options === 'object') {
Object.keys(defaultOptions).forEach((optionKey) => {
defaultOptions[optionKey] = options[optionKey] || defaultOptions[optionKey]
})
}
Vue.directive('blur', directive)
}
}
Expand Down
8 changes: 5 additions & 3 deletions lib/v-blur.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defaultOptions } from './index'

const directive = {}

directive.blur = function (el, bindingValue) {
Expand All @@ -12,9 +14,9 @@ directive.blur = function (el, bindingValue) {
bindingValue = { isBlurred: bindingValue }
}

const opacity = bindingValue.opacity || 0.5
const filter = bindingValue.filter || 'blur(1.5px)'
const transition = bindingValue.transition || 'all .2s linear'
const opacity = bindingValue.opacity || defaultOptions.opacity
const filter = bindingValue.filter || defaultOptions.filter
const transition = bindingValue.transition || defaultOptions.transition

el.style.opacity = bindingValue.isBlurred ? opacity : 1
el.style.filter = bindingValue.isBlurred ? filter : 'none'
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"rollup-plugin-filesize": "^6.2.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-uglify": "^6.0.3",
"standard": "^14.3.1"
"standard": "^14.3.1",
"vue": "^2.6.10"
},
"jest": {
"collectCoverage": true,
Expand Down
18 changes: 18 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* global describe, it, expect */

import plugin, { defaultOptions } from '../lib'
import Vue from 'vue'

describe('v-blur:index', () => {
it('should use if there has options parameter on install', () => {
const options = {
opacity: 0.2,
filter: 'blur(0.3px)'
}
Vue.use(plugin, options)

expect(typeof defaultOptions).toEqual('object')
expect(defaultOptions.opacity).toEqual(options.opacity)
expect(defaultOptions.filter).toEqual(options.filter)
})
})