@wearegenki/vue-directive-view
Version:
Vue custom directive to show/hide elements using opacity
43 lines (36 loc) • 1.12 kB
JavaScript
/**
* @wearegenki/vue-directive-view
* @author: Max Milton <max@wearegenki.com>
*
* Copyright 2018 We Are Genki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let className = 'hide';
const vView = (el, { value, oldValue }) => {
if (value === oldValue) return;
if (value) {
el.classList.remove(className);
} else {
el.classList.add(className);
}
};
function install(Vue, options = {}) {
const name = options.name || 'view';
className = options.class || className;
Vue.directive(name, vView);
}
export default {
install, // for global install
vView, // for local install
};