all files / addon/components/ el-badge.js

0% Statements 0/11
0% Branches 0/14
0% Functions 0/3
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                                                                                       
import Component from '@ember/component';
import layout from '../templates/components/el-badge';
import {computed, get} from "@ember/object";
 
export default Component.extend({
  layout,
 
  classNames: ['el-badge'],
  value: null,
  max: null,
  isDot: false,
  hidden: false,
  type: 'primary',
 
  isShow: computed('hidden', 'content', 'isDot', function(){
    return !get(this, 'hidden') && (get(this, 'content') || get(this, 'content') === 0 || get(this, 'isDot'));
  }),
 
  init(){
    this._super();
 
    let type = get(this,'type');
 
    if(['primary', 'success', 'warning', 'info', 'danger'].indexOf(type) === -1){
      // console.error('Provided type for el-badge is not valid. Please select one from [\'primary\', \'success\', \'warning\', \'info\', \'danger\']');
    }
 
    // set(this, 'value')
  },
 
  content: computed('isDot', 'value', 'max', function(){
    if(get(this, 'isDot')) return;
    const value = get(this, 'value');
    const max = get(this, 'max');
 
    if(typeof value === 'number' && typeof max === 'number'){
      return max < value ? `${max}+` : value;
    }
 
    return value;
  }),
});