all files / src/components/ MobiledocButton.vue

100% Statements 17/17
100% Branches 10/10
100% Functions 6/6
100% Lines 11/11
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                      12×                                                    
//
//
//
//
//
//
//
//
//
 
import titlelize, { capitalize } from "../utils/titlelize"
 
function isLink(tag) {
  return tag === "a" || capitalize(tag) === capitalize("link")
}
 
export default {
  props: {
    type: { type: String, required: true },
    for: { type: String, required: true }
  },
 
  computed: {
    typeName() {
      if (isLink(this.for)) { return "Link" }
      return titlelize(this.type)
    },
 
    tagName() {
      if (isLink(this.for)) { return "a" }
      return titlelize(this.for)
    },
 
    isActive() {
      let typeState = `active${this.typeName}Tags`
      return `this.$parent.${typeState}.indexOf(${this.tagName}) > 1`
    }
  },
 
  methods: {
    toggle() {
      this.$root.$emit(`toggle${this.typeName}`, this.tagName)
    }
  }
}