all files / addon/components/ polaris-list.js

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 10/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 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                                                                                                                           
import Component from '@ember/component';
import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
import { classify } from '@ember/string';
import layout from '../templates/components/polaris-list';
 
const allowedListTypes = [
  'bullet',
  'number'
];
const defaultListType = 'bullet';
 
export default Component.extend({
  tagName: '',
 
  layout,
 
  /**
   * Type of list to display
   *
   * @property type
   * @public
   * @type {String}
   * @default 'bullet'
   */
  type: defaultListType,
 
  /**
   * Flag to determine whether to render an ordered or unordered list
   *
   * @property isBulletListType
   * @private
   * @type {boolean}
   */
  isBulletListType: equal('listType', 'bullet').readOnly(),
 
  /**
   * Actual list type for internal use
   *
   * @property listType
   * @private
   * @type {String}
   */
  listType: computed('type', function() {
    let type = this.get('type');
    if (allowedListTypes.indexOf(type) === -1) {
      type = defaultListType;
    }
 
    return type;
  }).readOnly(),
 
  /**
   * Class for list element
   *
   * @property listElementClass
   * @private
   * @type {String}
   */
  listElementClass: computed('listType', function() {
    let classNames = [
      'Polaris-List'
    ];
 
    let type = this.get('listType');
    classNames.push(`Polaris-List--type${ classify(type) }`);
 
    return classNames.join(' ');
  }).readOnly(),
});