UNPKG

11.9 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/cdk/collections'), require('@angular/cdk/coercion'), require('rxjs')) :
3 typeof define === 'function' && define.amd ? define('@angular/cdk/accordion', ['exports', '@angular/core', '@angular/cdk/collections', '@angular/cdk/coercion', 'rxjs'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.accordion = {}), global.ng.core, global.ng.cdk.collections, global.ng.cdk.coercion, global.rxjs));
5}(this, (function (exports, core, collections, coercion, rxjs) { 'use strict';
6
7 /**
8 * @license
9 * Copyright Google LLC All Rights Reserved.
10 *
11 * Use of this source code is governed by an MIT-style license that can be
12 * found in the LICENSE file at https://angular.io/license
13 */
14 /** Used to generate unique ID for each accordion. */
15 var nextId$1 = 0;
16 /**
17 * Injection token that can be used to reference instances of `CdkAccordion`. It serves
18 * as alternative token to the actual `CdkAccordion` class which could cause unnecessary
19 * retention of the class and its directive metadata.
20 */
21 var CDK_ACCORDION = new core.InjectionToken('CdkAccordion');
22 /**
23 * Directive whose purpose is to manage the expanded state of CdkAccordionItem children.
24 */
25 var CdkAccordion = /** @class */ (function () {
26 function CdkAccordion() {
27 /** Emits when the state of the accordion changes */
28 this._stateChanges = new rxjs.Subject();
29 /** Stream that emits true/false when openAll/closeAll is triggered. */
30 this._openCloseAllActions = new rxjs.Subject();
31 /** A readonly id value to use for unique selection coordination. */
32 this.id = "cdk-accordion-" + nextId$1++;
33 this._multi = false;
34 }
35 Object.defineProperty(CdkAccordion.prototype, "multi", {
36 /** Whether the accordion should allow multiple expanded accordion items simultaneously. */
37 get: function () { return this._multi; },
38 set: function (multi) { this._multi = coercion.coerceBooleanProperty(multi); },
39 enumerable: false,
40 configurable: true
41 });
42 /** Opens all enabled accordion items in an accordion where multi is enabled. */
43 CdkAccordion.prototype.openAll = function () {
44 if (this._multi) {
45 this._openCloseAllActions.next(true);
46 }
47 };
48 /** Closes all enabled accordion items in an accordion where multi is enabled. */
49 CdkAccordion.prototype.closeAll = function () {
50 this._openCloseAllActions.next(false);
51 };
52 CdkAccordion.prototype.ngOnChanges = function (changes) {
53 this._stateChanges.next(changes);
54 };
55 CdkAccordion.prototype.ngOnDestroy = function () {
56 this._stateChanges.complete();
57 this._openCloseAllActions.complete();
58 };
59 return CdkAccordion;
60 }());
61 CdkAccordion.decorators = [
62 { type: core.Directive, args: [{
63 selector: 'cdk-accordion, [cdkAccordion]',
64 exportAs: 'cdkAccordion',
65 providers: [{ provide: CDK_ACCORDION, useExisting: CdkAccordion }],
66 },] }
67 ];
68 CdkAccordion.propDecorators = {
69 multi: [{ type: core.Input }]
70 };
71
72 /**
73 * @license
74 * Copyright Google LLC All Rights Reserved.
75 *
76 * Use of this source code is governed by an MIT-style license that can be
77 * found in the LICENSE file at https://angular.io/license
78 */
79 /** Used to generate unique ID for each accordion item. */
80 var nextId = 0;
81 var ɵ0 = undefined;
82 /**
83 * An basic directive expected to be extended and decorated as a component. Sets up all
84 * events and attributes needed to be managed by a CdkAccordion parent.
85 */
86 var CdkAccordionItem = /** @class */ (function () {
87 function CdkAccordionItem(accordion, _changeDetectorRef, _expansionDispatcher) {
88 var _this = this;
89 this.accordion = accordion;
90 this._changeDetectorRef = _changeDetectorRef;
91 this._expansionDispatcher = _expansionDispatcher;
92 /** Subscription to openAll/closeAll events. */
93 this._openCloseAllSubscription = rxjs.Subscription.EMPTY;
94 /** Event emitted every time the AccordionItem is closed. */
95 this.closed = new core.EventEmitter();
96 /** Event emitted every time the AccordionItem is opened. */
97 this.opened = new core.EventEmitter();
98 /** Event emitted when the AccordionItem is destroyed. */
99 this.destroyed = new core.EventEmitter();
100 /**
101 * Emits whenever the expanded state of the accordion changes.
102 * Primarily used to facilitate two-way binding.
103 * @docs-private
104 */
105 this.expandedChange = new core.EventEmitter();
106 /** The unique AccordionItem id. */
107 this.id = "cdk-accordion-child-" + nextId++;
108 this._expanded = false;
109 this._disabled = false;
110 /** Unregister function for _expansionDispatcher. */
111 this._removeUniqueSelectionListener = function () { };
112 this._removeUniqueSelectionListener =
113 _expansionDispatcher.listen(function (id, accordionId) {
114 if (_this.accordion && !_this.accordion.multi &&
115 _this.accordion.id === accordionId && _this.id !== id) {
116 _this.expanded = false;
117 }
118 });
119 // When an accordion item is hosted in an accordion, subscribe to open/close events.
120 if (this.accordion) {
121 this._openCloseAllSubscription = this._subscribeToOpenCloseAllActions();
122 }
123 }
124 Object.defineProperty(CdkAccordionItem.prototype, "expanded", {
125 /** Whether the AccordionItem is expanded. */
126 get: function () { return this._expanded; },
127 set: function (expanded) {
128 expanded = coercion.coerceBooleanProperty(expanded);
129 // Only emit events and update the internal value if the value changes.
130 if (this._expanded !== expanded) {
131 this._expanded = expanded;
132 this.expandedChange.emit(expanded);
133 if (expanded) {
134 this.opened.emit();
135 /**
136 * In the unique selection dispatcher, the id parameter is the id of the CdkAccordionItem,
137 * the name value is the id of the accordion.
138 */
139 var accordionId = this.accordion ? this.accordion.id : this.id;
140 this._expansionDispatcher.notify(this.id, accordionId);
141 }
142 else {
143 this.closed.emit();
144 }
145 // Ensures that the animation will run when the value is set outside of an `@Input`.
146 // This includes cases like the open, close and toggle methods.
147 this._changeDetectorRef.markForCheck();
148 }
149 },
150 enumerable: false,
151 configurable: true
152 });
153 Object.defineProperty(CdkAccordionItem.prototype, "disabled", {
154 /** Whether the AccordionItem is disabled. */
155 get: function () { return this._disabled; },
156 set: function (disabled) { this._disabled = coercion.coerceBooleanProperty(disabled); },
157 enumerable: false,
158 configurable: true
159 });
160 /** Emits an event for the accordion item being destroyed. */
161 CdkAccordionItem.prototype.ngOnDestroy = function () {
162 this.opened.complete();
163 this.closed.complete();
164 this.destroyed.emit();
165 this.destroyed.complete();
166 this._removeUniqueSelectionListener();
167 this._openCloseAllSubscription.unsubscribe();
168 };
169 /** Toggles the expanded state of the accordion item. */
170 CdkAccordionItem.prototype.toggle = function () {
171 if (!this.disabled) {
172 this.expanded = !this.expanded;
173 }
174 };
175 /** Sets the expanded state of the accordion item to false. */
176 CdkAccordionItem.prototype.close = function () {
177 if (!this.disabled) {
178 this.expanded = false;
179 }
180 };
181 /** Sets the expanded state of the accordion item to true. */
182 CdkAccordionItem.prototype.open = function () {
183 if (!this.disabled) {
184 this.expanded = true;
185 }
186 };
187 CdkAccordionItem.prototype._subscribeToOpenCloseAllActions = function () {
188 var _this = this;
189 return this.accordion._openCloseAllActions.subscribe(function (expanded) {
190 // Only change expanded state if item is enabled
191 if (!_this.disabled) {
192 _this.expanded = expanded;
193 }
194 });
195 };
196 return CdkAccordionItem;
197 }());
198 CdkAccordionItem.decorators = [
199 { type: core.Directive, args: [{
200 selector: 'cdk-accordion-item, [cdkAccordionItem]',
201 exportAs: 'cdkAccordionItem',
202 providers: [
203 // Provide `CDK_ACCORDION` as undefined to prevent nested accordion items from
204 // registering to the same accordion.
205 { provide: CDK_ACCORDION, useValue: ɵ0 },
206 ],
207 },] }
208 ];
209 CdkAccordionItem.ctorParameters = function () { return [
210 { type: CdkAccordion, decorators: [{ type: core.Optional }, { type: core.Inject, args: [CDK_ACCORDION,] }, { type: core.SkipSelf }] },
211 { type: core.ChangeDetectorRef },
212 { type: collections.UniqueSelectionDispatcher }
213 ]; };
214 CdkAccordionItem.propDecorators = {
215 closed: [{ type: core.Output }],
216 opened: [{ type: core.Output }],
217 destroyed: [{ type: core.Output }],
218 expandedChange: [{ type: core.Output }],
219 expanded: [{ type: core.Input }],
220 disabled: [{ type: core.Input }]
221 };
222
223 /**
224 * @license
225 * Copyright Google LLC All Rights Reserved.
226 *
227 * Use of this source code is governed by an MIT-style license that can be
228 * found in the LICENSE file at https://angular.io/license
229 */
230 var CdkAccordionModule = /** @class */ (function () {
231 function CdkAccordionModule() {
232 }
233 return CdkAccordionModule;
234 }());
235 CdkAccordionModule.decorators = [
236 { type: core.NgModule, args: [{
237 exports: [CdkAccordion, CdkAccordionItem],
238 declarations: [CdkAccordion, CdkAccordionItem],
239 },] }
240 ];
241
242 /**
243 * @license
244 * Copyright Google LLC All Rights Reserved.
245 *
246 * Use of this source code is governed by an MIT-style license that can be
247 * found in the LICENSE file at https://angular.io/license
248 */
249
250 /**
251 * Generated bundle index. Do not edit.
252 */
253
254 exports.CdkAccordion = CdkAccordion;
255 exports.CdkAccordionItem = CdkAccordionItem;
256 exports.CdkAccordionModule = CdkAccordionModule;
257 exports.ɵangular_material_src_cdk_accordion_accordion_a = CDK_ACCORDION;
258
259 Object.defineProperty(exports, '__esModule', { value: true });
260
261})));
262//# sourceMappingURL=cdk-accordion.umd.js.map