From 4454ff974ea575d58699895e485016e3b03c0f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C4=B1l=20AR?= Date: Tue, 3 Dec 2019 14:01:48 +0300 Subject: [PATCH] added - default options #76 --- lib/index.js | 13 ++++++++++++- lib/v-blur.js | 8 +++++--- package-lock.json | 6 ++++++ package.json | 3 ++- test/index.test.js | 18 ++++++++++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 test/index.test.js diff --git a/lib/index.js b/lib/index.js index aeaa0d1..11417ba 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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) } } diff --git a/lib/v-blur.js b/lib/v-blur.js index e54393f..6a8fa53 100644 --- a/lib/v-blur.js +++ b/lib/v-blur.js @@ -1,3 +1,5 @@ +import { defaultOptions } from './index' + const directive = {} directive.blur = function (el, bindingValue) { @@ -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' diff --git a/package-lock.json b/package-lock.json index e8ddc8e..f5e4322 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8796,6 +8796,12 @@ "extsprintf": "^1.2.0" } }, + "vue": { + "version": "2.6.10", + "resolved": "https://registry.npmjs.org/vue/-/vue-2.6.10.tgz", + "integrity": "sha512-ImThpeNU9HbdZL3utgMCq0oiMzAkt1mcgy3/E6zWC/G6AaQoeuFdsl9nDhTDU3X1R6FK7nsIUuRACVcjI+A2GQ==", + "dev": true + }, "w3c-hr-time": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz", diff --git a/package.json b/package.json index 6667353..c1f22fa 100644 --- a/package.json +++ b/package.json @@ -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, diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 0000000..8d93ebd --- /dev/null +++ b/test/index.test.js @@ -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) + }) +})