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

0% Statements 0/9
0% Branches 0/4
0% Functions 0/5
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                                                                                                                                 
import Component  from '@ember/component';
import layout     from '../templates/components/el-switch';
import {computed} from "@ember/object";
import {htmlSafe} from '@ember/template';
 
export default Component.extend({
  layout,
  classNames: ['el-switch'],
  tagName   : 'label',
 
  id               : '',
  name             : '',
  disabled         : false,
  width            : '',
  activeIconClass  : '',
  inactiveIconClass: '',
  activeText       : '',
  inactiveText     : '',
  activeValue      : true,
  inactiveValue    : false,
  validateEvent    : true,
  activeColor      : '',
  inactiveColor    : '',
  model            : false,
 
  isChecked: computed('model', function () {
    return !!this.get('model');
  }),
 
  notChecked: computed('model', function () {
    return !this.get('model');
  }),
 
  isInactive: computed.or('inactiveIconClass', 'inactiveText'),
 
  notInactiveIconClass: computed('inactiveIconClass', function () {
    return !this.get('inactiveIconClass');
  }),
 
  isInactiveText: computed.and('notInactiveIconClass', 'inactiveText'),
 
 
  isActive: computed.or('activeIconClass', 'activeText'),
 
  notActiveIconClass: computed('isActive', function () {
    return !this.get('activeIconClass');
  }),
 
  isActiveText: computed.and('notActiveIconClass', 'activeText'),
 
 
  spanStyle: computed("isChecked", "inactiveColor", "activeColor", 'width', function () {
    let color = this.get("model") ? this.get("activeColor") : this.get("inactiveColor");
    let width = this.get("width");
 
    if (width === '') {
      width = 40;
    }
 
    return htmlSafe(`background: ${color}; border-color: ${color}; width: ${width}px;`);
  }),
 
});