all files / src/bottomNav/ bottomNavItem.vue

0% Statements 0/11
0% Branches 0/11
100% Functions 0/0
0% Lines 0/10
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156                                                                                                                                                                                                                                                                                                                       
<template>
  <abstract-button :href="href" :disableTouchRipple="shift" class="mu-buttom-item" :class="{'mu-bottom-item-active': active}" :center-ripple="false" wrapperClass="mu-buttom-item-wrapper" @click.native="handleClick">
    <icon v-if="icon" class="mu-bottom-item-icon" :class="iconClass" :value="icon"></icon>
    <slot></slot>
    <span v-if="title" class="mu-bottom-item-text" :class="titleClass">{{title}}</span>
  </abstract-button>
</template>
 
<script>
import abstractButton from '../internal/abstractButton'
import icon from '../icon'
import {isNotNull} from '../utils'
export default {
  name: 'mu-bottom-nav-item',
  props: {
    icon: {
      type: String,
      default: ''
    },
    iconClass: {
      type: [String, Object, Array]
    },
    title: {
      type: String,
      default: ''
    },
    titleClass: {
      type: [String, Object, Array]
    },
    href: {
      type: String
    },
    value: {}
  },
  data () {
    return {
      bottomNav: null
    }
  },
  created () {
    this.isBottomNavItem = true
  },
  computed: {
    active () {
      return this.bottomNav && isNotNull(this.value) && this.bottomNav.value === this.value
    },
    shift () {
      return this.bottomNav && this.bottomNav.shift
    }
  },
  methods: {
    handleClick () {
      if (this.bottomNav && this.bottomNav.handleItemClick) this.bottomNav.handleItemClick(this.value)
    }
  },
  mounted () {
    let children = this.$parent.$children
    for (let i = 0; i < children.length; i++) {
      if (children[i].$el === this.$el) {
        this.index = i
        break
      }
    }
  },
  components: {
    'abstract-button': abstractButton,
    icon
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-buttom-item {
  flex: 1;
  min-width: 80px;
  max-width: 168px;
  position: relative;
  height: 100%;
  color: @secondaryTextColor;
  padding: 0;
  background: none;
  appearance: none;
  text-decoration: none;
  border: none;
  outline: none;
  transition: all .4s @easeInOutFunction;
  user-select: none;
  .mu-bottom-nav-shift & {
    color: fade(@alternateTextColor, 70%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px 10px;
    min-width: 56px;
    max-width: 168px;
  }
}
.mu-buttom-item-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.mu-bottom-item-active {
  .mu-bottom-item-text{
    font-size: 14px;
  }
  .mu-bottom-nav-shift & {
    flex: 1.7;
    min-width: 96px;
    max-width: 168px;
  }
}
 
.mu-bottom-item-text{
  font-size: 12px;
  transition: all .4s @easeOutFunction, color 0.3s, font-size 0.3s;
  backface-visibility: hidden;
  .mu-bottom-item-active &{
    color: @primaryColor;
  }
  .mu-bottom-nav-shift .mu-bottom-item-active &{
    color: @alternateTextColor;
  }
  .mu-bottom-nav-shift & {
    opacity: 0;
    transform: scale(1) translate3d(0, 6px, 0);
  }
  .mu-bottom-nav-shift .mu-bottom-item-active & {
    transform: scale(1) translate3d(0, 2px, 0);
    opacity: 1;
  }
}
.mu-bottom-item-icon {
  transition: all .45s @easeOutFunction;
  backface-visibility: hidden;
  width: 24px;
  .mu-bottom-item-active &{
    color: @primaryColor;
  }
  .mu-bottom-nav-shift .mu-bottom-item-active & {
    color: @alternateTextColor;
  }
  .mu-bottom-nav-shift & {
    margin: auto;
    transform: translate3d(0, 8px, 0);
  }
  .mu-bottom-nav-shift .mu-bottom-item-active & {
    transform: scale(1) translateZ(0);
  }
}
</style>