UNPKG

ngx-bootstrap

Version:
240 lines (234 loc) 7.44 kB
import { Injectable, Component, Input, EventEmitter, Inject, Output, HostBinding, NgModule } from '@angular/core'; import { isBs3 } from 'ngx-bootstrap/utils'; import { CommonModule } from '@angular/common'; import { CollapseModule } from 'ngx-bootstrap/collapse'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Configuration service, provides default values for the AccordionComponent. */ class AccordionConfig { constructor() { /** * Whether the other panels should be closed when a panel is opened */ this.closeOthers = false; /** * turn on/off animation */ this.isAnimated = false; } } AccordionConfig.decorators = [ { type: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Displays collapsible content panels for presenting information in a limited amount of space. */ class AccordionComponent { /** * @param {?} config */ constructor(config) { /** * turn on/off animation */ this.isAnimated = false; this.groups = []; Object.assign(this, config); } /** * @param {?} openGroup * @return {?} */ closeOtherPanels(openGroup) { if (!this.closeOthers) { return; } this.groups.forEach((/** * @param {?} group * @return {?} */ (group) => { if (group !== openGroup) { group.isOpen = false; } })); } /** * @param {?} group * @return {?} */ addGroup(group) { group.isAnimated = this.isAnimated; this.groups.push(group); } /** * @param {?} group * @return {?} */ removeGroup(group) { /** @type {?} */ const index = this.groups.indexOf(group); if (index !== -1) { this.groups.splice(index, 1); } } } AccordionComponent.decorators = [ { type: Component, args: [{ selector: 'accordion', template: `<ng-content></ng-content>`, host: { '[attr.aria-multiselectable]': 'closeOthers', role: 'tablist', class: 'panel-group', style: 'display: block' } }] } ]; /** @nocollapse */ AccordionComponent.ctorParameters = () => [ { type: AccordionConfig } ]; AccordionComponent.propDecorators = { isAnimated: [{ type: Input }], closeOthers: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * ### Accordion heading * Instead of using `heading` attribute on the `accordion-group`, you can use * an `accordion-heading` attribute on `any` element inside of a group that * will be used as group's header template. */ class AccordionPanelComponent { /** * @param {?} accordion */ constructor(accordion) { /** * turn on/off animation */ this.isAnimated = false; /** * Emits when the opened state changes */ this.isOpenChange = new EventEmitter(); this._isOpen = false; this.accordion = accordion; } // Questionable, maybe .panel-open should be on child div.panel element? /** * Is accordion group open or closed. This property supports two-way binding * @return {?} */ get isOpen() { return this._isOpen; } /** * @param {?} value * @return {?} */ set isOpen(value) { if (value !== this.isOpen) { if (value) { this.accordion.closeOtherPanels(this); } this._isOpen = value; Promise.resolve(null).then((/** * @return {?} */ () => { this.isOpenChange.emit(value); })) .catch((/** * @param {?} error * @return {?} */ (error) => { /* tslint:disable: no-console */ console.log(error); })); } } /** * @return {?} */ get isBs3() { return isBs3(); } /** * @return {?} */ ngOnInit() { this.panelClass = this.panelClass || 'panel-default'; this.accordion.addGroup(this); } /** * @return {?} */ ngOnDestroy() { this.accordion.removeGroup(this); } /** * @return {?} */ toggleOpen() { if (!this.isDisabled) { this.isOpen = !this.isOpen; } } } AccordionPanelComponent.decorators = [ { type: Component, args: [{ selector: 'accordion-group, accordion-panel', template: "<div class=\"panel card\" [ngClass]=\"panelClass\">\n <div class=\"panel-heading card-header\" role=\"tab\"\n (click)=\"toggleOpen()\" \n [ngClass]=\"isDisabled ? 'panel-disabled' : 'panel-enabled'\">\n \n <div class=\"panel-title\">\n <div role=\"button\" class=\"accordion-toggle\"\n [attr.aria-expanded]=\"isOpen\">\n <button class=\"btn btn-link\" *ngIf=\"heading\" [ngClass]=\"{'text-muted': isDisabled}\">\n {{ heading }}\n </button>\n <ng-content select=\"[accordion-heading]\"></ng-content>\n </div>\n </div>\n </div>\n <div class=\"panel-collapse collapse\" role=\"tabpanel\" [collapse]=\"!isOpen\" [isAnimated]=\"isAnimated\">\n <div class=\"panel-body card-block card-body\">\n <ng-content></ng-content>\n </div>\n </div>\n</div>\n", host: { class: 'panel', style: 'display: block' }, styles: [":host .card-header.panel-enabled{cursor:pointer}:host .card-header.panel-disabled .btn.btn-link{cursor:default;text-decoration:none}"] }] } ]; /** @nocollapse */ AccordionPanelComponent.ctorParameters = () => [ { type: AccordionComponent, decorators: [{ type: Inject, args: [AccordionComponent,] }] } ]; AccordionPanelComponent.propDecorators = { heading: [{ type: Input }], panelClass: [{ type: Input }], isDisabled: [{ type: Input }], isOpenChange: [{ type: Output }], isOpen: [{ type: HostBinding, args: ['class.panel-open',] }, { type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class AccordionModule { /** * @return {?} */ static forRoot() { return { ngModule: AccordionModule, providers: [AccordionConfig] }; } } AccordionModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, CollapseModule], declarations: [AccordionComponent, AccordionPanelComponent], exports: [AccordionComponent, AccordionPanelComponent] },] } ]; export { AccordionComponent, AccordionConfig, AccordionModule, AccordionPanelComponent }; //# sourceMappingURL=ngx-bootstrap-accordion.js.map