all files / src/internal/ focusRipple.vue

0% Statements 0/12
0% Branches 0/2
100% Functions 0/0
0% Lines 0/12
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                                                                                                                                                                       
<template>
  <div class="mu-focus-ripple-wrapper">
    <div ref="innerCircle" :style="style" class="mu-focus-ripple"></div>
  </div>
</template>
 
<script>
export default {
  props: {
    color: {
      type: String,
      default: ''
    },
    opacity: {
      type: Number
    }
  },
  computed: {
    style () {
      return {
        color: this.color,
        opacity: this.opacity
      }
    }
  },
  methods: {
    setRippleSize () {
      const el = this.$refs.innerCircle
      const height = el.offsetHeight
      const width = el.offsetWidth
      const size = Math.max(height, width)
 
      let oldTop = 0
 
      if (el.style.top.indexOf('px', el.style.top.length - 2) !== -1) {
        oldTop = parseInt(el.style.top)
      }
 
      el.style.height = `${size}px`
      el.style.top = `${(height / 2) - (size / 2) + oldTop}px`
    }
  },
  mounted () {
    this.setRippleSize()
  },
  updated () {
    this.setRippleSize()
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-focus-ripple-wrapper{
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
}
 
.mu-focus-ripple{
  position: absolute;
  height: 100%;
  width: 100%;
  border-radius: 50%;
  opacity: 0.16;
  background-color: currentColor;
  animation: mu-pulsate 750ms @easeInOutFunction;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}
 
@keyframes mu-pulsate {
  0% {
    transform: scale(0.72);
  }
  100% {
    transform: scale(0.85);
  }
}
</style>