@samatli/ngx-accordion
Version:
Simple accordion control for your angular applications using bootstrap.
95 lines (79 loc) • 2.38 kB
text/typescript
import {
Component,
Input,
Host,
forwardRef,
Inject,
ContentChild,
ElementRef,
ChangeDetectorRef,
Output,
EventEmitter
} from "@angular/core";
import {Accordion} from "./Accordion";
import {AccordionToggle} from "./AccordionToggle";
export class AccordionGroup {
heading: string;
isOpened: boolean = false;
onOpen = new EventEmitter();
onClose = new EventEmitter();
onToggle = new EventEmitter();
toggler: ElementRef;
disabled: boolean = false;
constructor( public accordion: Accordion,
private cdr: ChangeDetectorRef) {
}
checkAndToggle() {
// if custom toggle element is supplied, then do nothing, custom toggler will take care of it
if (this.toggler)
return;
this.toggle();
}
toggle() {
if (this.disabled)
return;
const isOpenedBeforeWeChange = this.isOpened;
if (this.accordion.closeOthers)
this.accordion.closeAll();
this.isOpened = !isOpenedBeforeWeChange;
if (this.isOpened) {
this.onOpen.emit();
} else {
this.onClose.emit();
}
this.onToggle.emit(this.isOpened);
}
openOnInitialization() {
this.isOpened = true;
this.cdr.detectChanges();
}
}