all files / src/timePicker/ clockPointer.vue

0% Statements 0/11
0% Branches 0/6
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                                                                                                                                                                               
<script>
import {isInner} from './timeUtils'
export default {
  props: {
    hasSelected: {
      type: Boolean,
      default: false
    },
    type: {
      type: String,
      default: 'minute',
      validator (val) {
        return ['hour', 'minute'].indexOf(val) !== -1
      }
    },
    value: {
      type: Number
    }
  },
  computed: {
    isInner () {
      return isInner(this)
    },
    pointerStyle () {
      const {type, value, calcAngle} = this
      const angle = type === 'hour' ? calcAngle(value, 12) : calcAngle(value, 60)
      return {
        transform: `rotateZ(${angle}deg)`
      }
    }
  },
  methods: {
    calcAngle (value, base) {
      value %= base
      const angle = 360 / base * value
      return angle
    }
  },
  render (h) {
    if (this.value === undefined || this.value === null) return h('span', {})
    return h('div', {
      class: {
        'mu-clock-pointer': true,
        'inner': this.isInner
      },
      style: this.pointerStyle
    }, [h('div', {
      class: {
        'mu-clock-pointer-mark': true,
        'has-selected': this.hasSelected
      }
    })])
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-clock-pointer {
  height: 40%;
  background-color: @primaryColor;
  width: 2px;
  left: calc(50% - 1px);
  position: absolute;
  bottom: 50%;
  transform-origin: center bottom 0px;
  pointer-events: none;
  &.inner {
    height: 30%;
  }
}
 
.mu-clock-pointer-mark {
  box-sizing: content-box;
  background-color: @alternateTextColor;
  border: 4px solid @primaryColor;
  width: 7px;
  height: 7px;
  position: absolute;
  top: -5px;
  left: -6px;
  border-radius: 100%;
  &.has-selected {
    display: none;
  }
}
</style>