all files / src/datePicker/ yearButton.vue

0% Statements 0/9
0% Branches 0/6
100% Functions 0/0
0% Lines 0/7
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                                                                                                                                                                     
<template>
<button class="mu-year-button" @click="handleClick" @mouseenter="handleHover" @mouseleave="handleHoverExit" :class="{'selected': selected, 'hover': hover}">
  <span class="mu-year-button-text">{{year}}</span>
</button>
</template>
 
<script>
import {isPc} from '../utils'
export default {
  props: {
    year: {
      type: [String, Number]
    },
    selected: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      hover: false
    }
  },
  mounted () {
    if (this.selected) {
      this.$parent.scrollToSelectedYear(this.$el)
    }
  },
  methods: {
    handleHover () {
      if (isPc()) this.hover = true
    },
    handleHoverExit () {
      this.hover = false
    },
    handleClick (event) {
      this.$emit('click', event)
    }
  },
  watch: {
    selected (val) {
      if (val) this.$parent.scrollToSelectedYear(this.$el)
    }
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-year-button{
  position: relative;
  display: block;
  background: none;
  cursor: pointer;
  outline: none;
  text-decoration: none;
  margin: 0px auto;
  padding: 0px;
  border: 10px;
  font-size: 14px;
  font-weight: inherit;
  text-align: center;
  line-height: inherit;
}
 
.mu-year-button-text {
  align-self: center;
  color: @textColor;
  font-size: 17px;
  font-weight: 400;
  position: relative;
  top: -1px;
  .mu-year-button.selected &{
    color: @primaryColor;
    font-size: 26px;
    font-weight: 500;
  }
  .mu-year-button.hover &{
    color: @primaryColor;
  }
}
</style>