all files / src/linearProgress/ linearProgress.vue

0% Statements 0/5
0% Branches 0/4
100% Functions 0/0
0% Lines 0/5
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                                                                                                                                                                                                         
<template>
<div class="mu-linear-progress" :style="{'height': size + 'px', 'border-radius': (size ? size / 2 : '') + 'px'}">
  <div :style="linearStyle" :class="linearClass"></div>
</div>
</template>
 
<script>
import {getColor} from '../utils'
export default {
  name: 'mu-linear-progress',
  props: {
    max: {
      type: Number,
      default: 100
    },
    min: {
      type: Number,
      default: 0
    },
    mode: {
      type: String,
      default: 'indeterminate',
      validator (val) {
        return ['indeterminate', 'determinate'].indexOf(val) !== -1
      }
    },
    value: {
      type: Number,
      default: 0
    },
    color: {
      type: String
    },
    size: {
      type: Number
    }
  },
  computed: {
    percent () {
      return (this.value - this.min) / (this.max - this.min) * 100
    },
    linearStyle () {
      const {size, color, mode, percent} = this
      return {
        height: size + 'px',
        'background-color': getColor(color),
        'border-radius': (size ? size / 2 : '') + 'px',
        width: mode === 'determinate' ? percent + '%' : ''
      }
    },
    linearClass () {
      return 'mu-linear-progress-' + this.mode
    }
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-linear-progress{
  position: relative;
  height: 4px;
  display: block;
  width: 100%;
  background-color: @lighterPrimaryColor;
  border-radius: 2px;
  margin: 0px;
  overflow: hidden;
}
 
.mu-linear-progress-indeterminate{
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  border-radius: 2px;
  background-color: @primaryColor;
  animation: mu-linear-progress-animate 840ms @easeInOutFunction;
  animation-iteration-count: infinite;
}
 
.mu-linear-progress-determinate{
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  background-color: @primaryColor;
  transition: width .3s linear;
  border-radius: 2px;
}
 
@keyframes mu-linear-progress-animate {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}
</style>