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

100% Statements 3/3
66.67% Branches 4/6
100% Functions 1/1
100% Lines 3/3
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                                                                                           
import Component from '@ember/component';
import { computed, get } from '@ember/object';
import layout from '../templates/components/polaris-breadcrumbs';
 
export default Component.extend({
  tagName: 'nav',
  attributeBindings: ['role'],
 
  layout,
 
  /**
   * Collection of breadcrumbs
   *
   * @property breadcrumbs
   * @public
   * @type {Array}
   * @default null
   */
  breadcrumbs: null,
 
  /**
   * Role attribute
   *
   * @property role
   * @private
   * @type {String}
   * @default 'navigation'
   */
  role: 'navigation',
 
  /**
   * The breadcrumb to render (the last of the list)
   * We're not always guaranteed to get an Ember array,
   * so we can't just use `breadcrumbs.lastObject` in the template.
   *
   * @property breadcrumb
   * @private
   * @type {Object}
   */
  breadcrumb: computed('breadcrumbs.[]', function() {
    let breadcrumbs = this.get('breadcrumbs') || [];
    let breadcrumbsCount = get(breadcrumbs, 'length');
    return breadcrumbsCount && breadcrumbsCount > 0 ?
      breadcrumbs[breadcrumbsCount - 1] :
      null;
  }).readOnly(),
});