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

100% Statements 8/8
100% Branches 4/4
100% Functions 2/2
100% Lines 8/8
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                                                                                                                       
import Component from '@ember/component';
import { computed } from '@ember/object';
import { gt } from '@ember/object/computed';
import { isPresent } from '@ember/utils';
import { isArray } from '@ember/array';
import { assert } from '@ember/debug';
import layout from '../templates/components/polaris-action-list';
 
/**
 * Polaris action list component.
 * See https://polaris.shopify.com/components/actions/action-list
 */
export default Component.extend({
  tagName: '',
 
  layout,
  /**
   * Collection of actions for list
   *
   * @property items
   * @public
   * @type {Array}
   * @default null
   */
  items: null,
 
  /**
   * Collection of sectioned action items
   *
   * @property sections
   * @public
   * @type {Array}
   * @default null
   */
  sections: null,
 
  /**
   * Callback when any item is clicked or keypressed
   *
   * @property onActionAnyItem
   * @public
   * @type {function}
   * @default no-op
   */
  onActionAnyItem() {},
 
  /*
   * Internal properties.
   */
  finalSections: computed('items', 'sections.[]', function() {
    let finalSections = [];
 
    let items = this.get('items');
    if (isPresent(items)) {
      finalSections.push({ items });
    }
 
    let sections = this.get('sections') || [];
    assert(`ember-polaris::polaris-action-list - sections must be an array, you passed ${ sections }`, isArray(sections));
    finalSections.push(...sections);
 
    return finalSections;
  }).readOnly(),
 
  hasMultipleSections: gt('finalSections.length', 1).readOnly(),
});