import { Component , Input , ContentChildren , AfterContentInit , QueryList } from '@angular/core' ; import { AccordionPanelComponent } from './accordion_panel' ; @ Component ( { selector : 'lsu-accordion' , template : `
    <div class="ui styled accordion" [ngClass]="getCls()">      
      <ng-content select="lsu-accordionPanel"></ng-content>
    </div>
  ` } ) export class AccordionComponent implements AfterContentInit { @ ContentChildren ( AccordionPanelComponent ) public accordions : QueryList < AccordionPanelComponent > ; @ Input ( ) option : any = { } ; _accordions : Array < AccordionPanelComponent > = [ ] ; constructor ( ) { } getCls ( ) { let cls = { "styled" : this . option . styled == undefined ? true : this . option . styled , "fluid" : this . option . fluid == undefined ? true : this . option . fluid , "inverted" : this . option . inverted == undefined ? false : this . option . inverted } ; return cls ; } setAccordion ( accordion ) { let isActive = accordion . active ; if ( ! this . option . allowMultiple ) { this . _accordions . forEach ( a => a . active = false ) ; } accordion . active = ! isActive ; } ngAfterContentInit ( ) { this . _accordions = this . accordions . toArray ( ) ; var self = this ; this . _accordions . forEach ( a => { a . onChange ( self ) ; } ) ; if ( ! this . option . allowMultiple ) { let finded = { } ; for ( var i = 0 ; i < this . _accordions . length ; i ++ ) { var item = this . _accordions [ i ] ; if ( item . active ) { item . active = false ; finded = item ; } } if ( finded . active !== undefined ) { finded . active = true ; } } } }