all files / src/tabs/ tab.vue

0% Statements 0/13
0% Branches 0/10
100% Functions 0/0
0% Lines 0/9
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                                                                                                                                                                                             
<template>
<abstract-button class="mu-tab-link" :href="href" :disabled="disabled"
  :center-ripple="false" :class="{'mu-tab-active': active}" @click="tabClick">
  <slot>
    <icon :value="icon" :class="iconClass"/>
  </slot>
  <div class="mu-tab-text" :class="textClass" v-if="title">{{title}}</div>
</abstract-button>
</template>
 
<script>
import abstractButton from '../internal/abstractButton'
import icon from '../icon'
import {isNotNull, convertClass} from '../utils'
export default {
  name: 'mu-tab',
  props: {
    icon: {
      type: String,
      default: ''
    },
    iconClass: {
      type: [String, Object, Array]
    },
    title: {
      type: String,
      default: ''
    },
    titleClass: {
      type: [String, Object, Array]
    },
    href: {
      type: String
    },
    disabled: {
      type: Boolean
    },
    value: {}
  },
  computed: {
    active () {
      return isNotNull(this.value) && this.$parent.value === this.value
    },
    textClass () {
      const {icon, titleClass} = this
      let classNames = []
      if (icon) classNames.push('has-icon')
      return classNames.concat(convertClass(titleClass))
    }
  },
  methods: {
    tabClick (e) {
      if (this.$parent.handleTabClick) this.$parent.handleTabClick(this.value, this)
      this.$emit('click', e)
    }
  },
  watch: {
    active (val, oldVal) {
      if (val === oldVal) return
      if (val) this.$emit('active')
    }
  },
  components: {
    'abstract-button': abstractButton,
    icon
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-tab-link{
  min-height: 48px;
  padding-top: 12px;
  padding-bottom: 12px;
  font-size: 14px;
  background: none;
  appearance: none;
  text-decoration: none;
  border: none;
  outline: none;
  flex: 1;
  color: inherit;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: normal;
  align-items: center;
  color: fade(@alternateTextColor, 70%);
  transition: all .45s @easeInOutFunction;
  cursor: pointer;
}
.mu-tab-active{
  color: @alternateTextColor;
}
.mu-tab-text{
  &.has-icon {
    margin-top: 8px;
  }
}
</style>