/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { Directive, InjectionToken, Input } from '@angular/core'; import { Subject } from 'rxjs'; import * as i0 from "@angular/core"; /** Used to generate unique ID for each accordion. */ let nextId = 0; /** * Injection token that can be used to reference instances of `CdkAccordion`. It serves * as alternative token to the actual `CdkAccordion` class which could cause unnecessary * retention of the class and its directive metadata. */ export const CDK_ACCORDION = new InjectionToken('CdkAccordion'); /** * Directive whose purpose is to manage the expanded state of CdkAccordionItem children. */ export class CdkAccordion { constructor() { /** Emits when the state of the accordion changes */ this._stateChanges = new Subject(); /** Stream that emits true/false when openAll/closeAll is triggered. */ this._openCloseAllActions = new Subject(); /** A readonly id value to use for unique selection coordination. */ this.id = `cdk-accordion-${nextId++}`; this._multi = false; } /** Whether the accordion should allow multiple expanded accordion items simultaneously. */ get multi() { return this._multi; } set multi(multi) { this._multi = coerceBooleanProperty(multi); } /** Opens all enabled accordion items in an accordion where multi is enabled. */ openAll() { if (this._multi) { this._openCloseAllActions.next(true); } } /** Closes all enabled accordion items. */ closeAll() { this._openCloseAllActions.next(false); } ngOnChanges(changes) { this._stateChanges.next(changes); } ngOnDestroy() { this._stateChanges.complete(); this._openCloseAllActions.complete(); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkAccordion, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: CdkAccordion, selector: "cdk-accordion, [cdkAccordion]", inputs: { multi: "multi" }, providers: [{ provide: CDK_ACCORDION, useExisting: CdkAccordion }], exportAs: ["cdkAccordion"], usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: CdkAccordion, decorators: [{ type: Directive, args: [{ selector: 'cdk-accordion, [cdkAccordion]', exportAs: 'cdkAccordion', providers: [{ provide: CDK_ACCORDION, useExisting: CdkAccordion }], }] }], propDecorators: { multi: [{ type: Input }] } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3JkaW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9hY2NvcmRpb24vYWNjb3JkaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBZSxxQkFBcUIsRUFBQyxNQUFNLHVCQUF1QixDQUFDO0FBQzFFLE9BQU8sRUFBQyxTQUFTLEVBQUUsY0FBYyxFQUFFLEtBQUssRUFBc0MsTUFBTSxlQUFlLENBQUM7QUFDcEcsT0FBTyxFQUFDLE9BQU8sRUFBQyxNQUFNLE1BQU0sQ0FBQzs7QUFFN0IscURBQXFEO0FBQ3JELElBQUksTUFBTSxHQUFHLENBQUMsQ0FBQztBQUVmOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsTUFBTSxhQUFhLEdBQUcsSUFBSSxjQUFjLENBQWUsY0FBYyxDQUFDLENBQUM7QUFFOUU7O0dBRUc7QUFNSCxNQUFNLE9BQU8sWUFBWTtJQUx6QjtRQU1FLG9EQUFvRDtRQUMzQyxrQkFBYSxHQUFHLElBQUksT0FBTyxFQUFpQixDQUFDO1FBRXRELHVFQUF1RTtRQUM5RCx5QkFBb0IsR0FBcUIsSUFBSSxPQUFPLEVBQVcsQ0FBQztRQUV6RSxvRUFBb0U7UUFDM0QsT0FBRSxHQUFXLGlCQUFpQixNQUFNLEVBQUUsRUFBRSxDQUFDO1FBVTFDLFdBQU0sR0FBWSxLQUFLLENBQUM7S0FzQmpDO0lBOUJDLDJGQUEyRjtJQUMzRixJQUNJLEtBQUs7UUFDUCxPQUFPLElBQUksQ0FBQyx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