all files / src/avatar/ avatar.vue

0% Statements 0/3
0% Branches 0/4
100% Functions 0/0
0% Lines 0/3
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                                                                                                                                                                                               
<template>
  <div class="mu-avatar" @click="handleClick" :style="avatarStyle">
    <div class="mu-avatar-inner">
      <icon v-if="icon" :value="icon" :size="iconSize" :class="iconClass"></icon>
      <img :src="src" v-if="src" :class="imgClass" />
      <slot></slot>
    </div>
  </div>
</template>
 
<script>
import icon from '../icon'
import {getColor} from '../utils'
export default {
  name: 'mu-avatar',
  props: {
    backgroundColor: {
      type: String,
      default: ''
    },
    color: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: ''
    },
    iconClass: {
      type: [String, Object, Array]
    },
    src: {
      type: String,
      default: ''
    },
    imgClass: {
      type: [String, Object, Array]
    },
    size: {
      type: Number
    },
    iconSize: {
      type: Number
    }
  },
  computed: {
    avatarStyle () {
      return {
        width: this.size ? this.size + 'px' : '',
        height: this.size ? this.size + 'px' : '',
        color: getColor(this.color),
        'background-color': getColor(this.backgroundColor)
      }
    }
  },
  methods: {
    handleClick () {
      this.$emit('click')
    }
  },
  created () {
    this._isAvatar = true
  },
  components: {
    icon
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-avatar{
  display: inline-block;
  height: 40px;
  width: 40px;
  font-size: 20px;
  color: @alternateTextColor;
  background-color: darken(@alternateTextColor, 26%);
  text-align: center;
  border-radius: 50%;
  img {
    border-radius: 50%;
    width: 100%;
    height: 100%;
    display: block;
  }
}
.mu-avatar-inner{
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}
</style>