all files / modules/ember-ticketfly-accordion/components/ tf-accordion-panel.js

100% Statements 14/14
100% Branches 0/0
100% Functions 10/10
100% Lines 14/14
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211                                                                                                                                                                                                                                                                      24×   24× 24× 24×             25×   25×                         24×                   24×                     24×                   24×           24×       24×       24×       25×        
import Component from 'ember-component';
import layout from '../templates/components/tf-accordion-panel';
import get from 'ember-metal/get';
import set from 'ember-metal/set';
import { guidFor } from 'ember-metal/utils';
 
/**
 * @module tf-accordion
 */
 
/**
 * @class TFAccordionPanelComponent
 * @namespace TFAccordion
 * @extends Ember.Component
 *
 * This component wraps a
 * `tf-accordion-panel-tab` and `tf-accordion-panel-body` component
 */
export default Component.extend({
  layout,
  classNames: ['tfa-panel'],
 
  /* ---------- API ---------- */
 
  /**
   * a unique ID for this panel's child tab, which will
   * be generated on init
   *
   * @property tabID
   * @type String
   */
  tabID: '',
 
  /**
   * a unique ID for this panel's child body, which will
   * be generated on init
   *
   * @property panelBodyID
   * @type String
   */
  panelBodyID: '',
 
  /**
   * An optional title that can be used as the content for
   * this panel's child tab text
   *
   * @property tabTitle
   * @type String
   */
  tabTitle: '',
 
  /**
   * An optional text content that can be used as the content for
   * this panel's child panel text
   *
   * @property bodyContent
   * @type String
   */
  bodyContent: '',
 
  /**
   * An optional className that can used in addition to the
   * built-in className for this panel's child tab
   *
   * @property tabClassName
   * @type String
   */
  tabClassName: '',
 
  /**
   * An optional className that can used in addition to the
   * built-in className for this panel's child body
   *
   * @property bodyClassName
   * @type String
   */
  bodyClassName: '',
 
  /**
   * The instance object of the `tf-accordion` component that
   * this panel belongs to.
   *
   * @property accordion
   * @type TFAccordion.TFAccordionComponent
   */
  accordion: null,
 
  /**
   * The instance object of the `tf-accordion-panel-tab` component
   * that this panel belongs to.
   *
   * @property tab
   * @type TFAccordion.TFAccordionPanelTabComponent
   */
  tab: null,
 
  /**
   * The instance object of the `tf-accordion-panel-body` component
   * that this panel belongs to.
   *
   * @property panelBody
   * @type TFAccordion.TFAccordionPanelBodyComponent
   */
  panelBody: null,
 
  /**
   * Tracks whether or not the body for this panel is expanded
   *
   * @property isExpanded
   * @type Boolean
   * @default false
   */
  isExpanded: false,
 
  /**
   * Tracks whether or not the body for this panel is "in motion",
   * i.e: whether or not its animating from an expanded state to
   * a collapsed state
   *
   * @property isInMotion
   * @type Boolean
   * @default false
   */
  isInMotion: false,
 
  /* ---------- LIFECYCLE ---------- */
 
  /**
   * @override
   */
  init() {
    this._super(...arguments);
 
    this._initTabID();
    this._initPanelBodyID();
    this._registerWithAccordion();
  },
 
  /**
   * @override
   */
  willDestroyElement() {
    this._super(...arguments);
 
    this._unRegisterWithAccordion();
  },
 
  /* ---------- PUBLIC METHODS ---------- */
 
  /**
   * Registers this panel's tab component
   *
   * @method registerTab
   * @param {TFAccordion.TFAccordionPanelTabComponent} tab
   * @public
   */
  registerTab(tab) {
    set(this, 'tab', tab);
  },
 
  /**
   * Un-registers this panel's tab component
   *
   * @method unRegisterTab
   * @public
   */
  unRegisterTab() {
    set(this, 'tab', null);
  },
 
  /**
   * registers this panel's body
   *
   * @method registerPanelBody
   * @param {TFAccordion.TFAccordionPanelBodyComponent} panelBody
   * @public
   */
  registerPanelBody(panelBody) {
    set(this, 'panelBody', panelBody);
  },
 
  /**
   * Un-registers this panel's body
   *
   * @method unRegisterPanelBody
   * @public
   */
  unRegisterPanelBody() {
    set(this, 'panelBody', null);
  },
 
  /* ---------- PRIVATE METHODS ---------- */
 
  _initTabID() {
    this.tabID = `tf-accordion-panel-tab--${guidFor(this)}`;
  },
 
  _initPanelBodyID() {
    this.panelBodyID = `tf-accordion-panel-body--${guidFor(this)}`;
  },
 
  _registerWithAccordion() {
    get(this, 'accordion').registerPanel(this);
  },
 
  _unRegisterWithAccordion() {
    get(this, 'accordion').unRegisterPanel(this);
  }
});