UNPKG

@ishitatsuyuki/oruga-next

Version:

UI components for Vue.js and CSS framework agnostic

75 lines (71 loc) 3.36 kB
'use strict'; var vue = require('vue'); var helpers = require('./helpers.js'); var config = require('./config.js'); const _defaultSuffixProcessor = (input, suffix) => { return helpers.blankIfUndefined(input) .split(' ') .filter((cls) => cls.length > 0) .map((cls) => cls + suffix) .join(' '); }; const _getContext = (vm) => { const computedNames = vm.$options.computed ? Object.keys(vm.$options.computed) : []; const computed = computedNames.filter(e => !helpers.endsWith(e, 'Classes')).reduce((o, key) => { o[key] = vm[key]; return o; }, {}); return { props: vm.$props, data: vm.$data, computed }; }; var BaseComponentMixin = vue.defineComponent({ isOruga: true, props: { override: Boolean }, methods: { computedClass(field, defaultValue, suffix = '') { const config$1 = this.$props.override === true ? {} : config.getOptions(); const override = this.$props.override || helpers.getValueByPath(config$1, `${this.$options.configField}.override`, false); const overrideClass = helpers.getValueByPath(config$1, `${this.$options.configField}.${field}.override`, override); const globalTransformClasses = helpers.getValueByPath(config$1, `transformClasses`, undefined); const localTransformClasses = helpers.getValueByPath(config$1, `${this.$options.configField}.transformClasses`, undefined); let globalClass = helpers.getValueByPath(config$1, `${this.$options.configField}.${field}.class`, '') || helpers.getValueByPath(config$1, `${this.$options.configField}.${field}`, ''); let currentClass = helpers.getValueByPath(this.$props, field); if (Array.isArray(currentClass)) { currentClass = currentClass.join(' '); } if (defaultValue.search("{*}") !== -1) { defaultValue = defaultValue.replace(/\{\*\}/g, suffix); } else { defaultValue = defaultValue + suffix; } let context = null; if (typeof currentClass === "function") { context = _getContext(this); currentClass = currentClass(suffix, context); } else { currentClass = _defaultSuffixProcessor(currentClass, suffix); } if (typeof globalClass === "function") { globalClass = globalClass(suffix, context || _getContext(this)); } else { globalClass = _defaultSuffixProcessor(globalClass, suffix); } let appliedClasses = (`${(override && !overrideClass) || (!override && !overrideClass) ? defaultValue : ''} ` + `${helpers.blankIfUndefined(globalClass)} ` + `${helpers.blankIfUndefined(currentClass)}`).trim().replace(/\s\s+/g, ' '); if (localTransformClasses) { appliedClasses = localTransformClasses(appliedClasses); } if (globalTransformClasses) { appliedClasses = globalTransformClasses(appliedClasses); } return appliedClasses; } } }); exports.BaseComponentMixin = BaseComponentMixin;