import { Component, Input, Output, EventEmitter, ContentChildren, TemplateRef, ContentChild, ViewChildren, AfterContentInit } from '@angular/core'; import { RdComponent } from '../../base/rdComponent'; @Component({ selector: 'rd-accordion-content', template: ` ` }) export class AccordionContent extends RdComponent { @Input("rd-text") text: string; @Input("rd-icon") icon: string; @Input("rd-icon-color") iconColor: string; @Output("rd-on-open") openEvent: EventEmitter = new EventEmitter(); @ContentChild(TemplateRef) template; active = false; } @Component({ selector: 'rd-accordion', template: `
{{item.text}}
` }) export class Accordion extends RdComponent implements AfterContentInit { constructor() { super(); this.id = Accordion.id; Accordion.id++; } @Input("rd-max-height") maxHeight: string = "23rem"; @ViewChildren("accordionBody") accordionBodys; @ContentChildren(AccordionContent) contents; id; public static id = 0; ngAfterContentInit() { if (this.contents._results.length) this.activateContent(this.contents._results[0]); } activeContent; activateContent(content) { if (this.activeContent) this.activeContent.active = false; this.activeContent = content; this.activeContent.active = true; this.activeContent.openEvent.emit(); } contentClicked(content, body, index) { if (content.active) { content.active = false; this.activeContent = null; this.jQuery(body).slideUp(300); } else { this.activateContent(content); this.jQuery(body).slideDown(300); } for (let i in this.accordionBodys._results) { if (i != index) this.jQuery(this.accordionBodys._results[i].nativeElement).slideUp(300); } } }