all files / src/badge/ badge.vue

0% Statements 0/13
0% Branches 0/11
100% Functions 0/0
0% Lines 0/9
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 102 103                                                                                                                                                                                                             
<template>
  <div class="mu-badge-container">
    <slot></slot>
    <em class="mu-badge" :style="badgeStyle" :class="badgeInternalClass">
      <slot name="content">
        {{content}}
      </slot>
    </em>
  </div>
</template>
 
<script>
import {getColor, convertClass} from '../utils'
export default {
  name: 'mu-badge',
  props: {
    content: {
      type: String,
      default: ''
    },
    color: {
      type: String,
      default: ''
    },
    primary: {
      type: Boolean,
      default: false
    },
    secondary: {
      type: Boolean,
      default: false
    },
    circle: {
      type: Boolean,
      default: false
    },
    badgeClass: {
      type: [String, Object, Array]
    }
  },
  computed: {
    badgeStyle () {
      return {
        'background-color': getColor(this.color)
      }
    },
    badgeInternalClass () {
      const {circle, primary, secondary, badgeClass} = this
      const isFloat = this.$slots && this.$slots.default && this.$slots.default.length > 0
      const classNames = []
      if (circle) classNames.push('mu-badge-circle')
      if (primary) classNames.push('mu-badge-primary')
      if (secondary) classNames.push('mu-badge-secondary')
      if (isFloat) classNames.push('mu-badge-float')
      return classNames.concat(convertClass(badgeClass))
    }
  }
}
</script>
 
<style lang="less">
@import "../styles/import.less";
.mu-badge-container{
  display: inline-block;
  position: relative;
}
.mu-badge{
  font-size: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 6px;
  line-height: 1.5;
  font-size: 12px;
  font-style: normal;
  background-color: @lighterPrimaryColor;
  color: @alternateTextColor;
  border-radius: 3px;
  overflow: hidden;
}
 
.mu-badge-float {
  position: absolute;
  top: -12px;
  right: -12px;
}
.mu-badge-circle {
  border-radius: 50%;
  padding: 0;
  width: 24px;
  height: 24px;
  overflow: hidden;
}
.mu-badge-primary {
  background-color: @primaryColor;
}
 
.mu-badge-secondary {
  background-color: @accentColor;
}
 
</style>