cdk-accordion.umd.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /**
  2. * @license
  3. * Copyright Google LLC All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/coercion'), require('@angular/core'), require('rxjs'), require('@angular/cdk/collections')) :
  10. typeof define === 'function' && define.amd ? define('@angular/cdk/accordion', ['exports', '@angular/cdk/coercion', '@angular/core', 'rxjs', '@angular/cdk/collections'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.cdk = global.ng.cdk || {}, global.ng.cdk.accordion = {}),global.ng.cdk.coercion,global.ng.core,global.rxjs,global.ng.cdk.collections));
  12. }(this, (function (exports,coercion,core,rxjs,collections) { 'use strict';
  13. /**
  14. * @fileoverview added by tsickle
  15. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  16. */
  17. /**
  18. * Used to generate unique ID for each accordion.
  19. * @type {?}
  20. */
  21. var nextId = 0;
  22. /**
  23. * Directive whose purpose is to manage the expanded state of CdkAccordionItem children.
  24. */
  25. var CdkAccordion = /** @class */ (function () {
  26. function CdkAccordion() {
  27. /**
  28. * Emits when the state of the accordion changes
  29. */
  30. this._stateChanges = new rxjs.Subject();
  31. /**
  32. * Stream that emits true/false when openAll/closeAll is triggered.
  33. */
  34. this._openCloseAllActions = new rxjs.Subject();
  35. /**
  36. * A readonly id value to use for unique selection coordination.
  37. */
  38. this.id = "cdk-accordion-" + nextId++;
  39. this._multi = false;
  40. }
  41. Object.defineProperty(CdkAccordion.prototype, "multi", {
  42. /** Whether the accordion should allow multiple expanded accordion items simultaneously. */
  43. get: /**
  44. * Whether the accordion should allow multiple expanded accordion items simultaneously.
  45. * @return {?}
  46. */
  47. function () { return this._multi; },
  48. set: /**
  49. * @param {?} multi
  50. * @return {?}
  51. */
  52. function (multi) { this._multi = coercion.coerceBooleanProperty(multi); },
  53. enumerable: true,
  54. configurable: true
  55. });
  56. /** Opens all enabled accordion items in an accordion where multi is enabled. */
  57. /**
  58. * Opens all enabled accordion items in an accordion where multi is enabled.
  59. * @return {?}
  60. */
  61. CdkAccordion.prototype.openAll = /**
  62. * Opens all enabled accordion items in an accordion where multi is enabled.
  63. * @return {?}
  64. */
  65. function () {
  66. this._openCloseAll(true);
  67. };
  68. /** Closes all enabled accordion items in an accordion where multi is enabled. */
  69. /**
  70. * Closes all enabled accordion items in an accordion where multi is enabled.
  71. * @return {?}
  72. */
  73. CdkAccordion.prototype.closeAll = /**
  74. * Closes all enabled accordion items in an accordion where multi is enabled.
  75. * @return {?}
  76. */
  77. function () {
  78. this._openCloseAll(false);
  79. };
  80. /**
  81. * @param {?} changes
  82. * @return {?}
  83. */
  84. CdkAccordion.prototype.ngOnChanges = /**
  85. * @param {?} changes
  86. * @return {?}
  87. */
  88. function (changes) {
  89. this._stateChanges.next(changes);
  90. };
  91. /**
  92. * @return {?}
  93. */
  94. CdkAccordion.prototype.ngOnDestroy = /**
  95. * @return {?}
  96. */
  97. function () {
  98. this._stateChanges.complete();
  99. };
  100. /**
  101. * @private
  102. * @param {?} expanded
  103. * @return {?}
  104. */
  105. CdkAccordion.prototype._openCloseAll = /**
  106. * @private
  107. * @param {?} expanded
  108. * @return {?}
  109. */
  110. function (expanded) {
  111. if (this.multi) {
  112. this._openCloseAllActions.next(expanded);
  113. }
  114. };
  115. CdkAccordion.decorators = [
  116. { type: core.Directive, args: [{
  117. selector: 'cdk-accordion, [cdkAccordion]',
  118. exportAs: 'cdkAccordion',
  119. },] },
  120. ];
  121. CdkAccordion.propDecorators = {
  122. multi: [{ type: core.Input }]
  123. };
  124. return CdkAccordion;
  125. }());
  126. /**
  127. * @fileoverview added by tsickle
  128. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  129. */
  130. /**
  131. * Used to generate unique ID for each accordion item.
  132. * @type {?}
  133. */
  134. var nextId$1 = 0;
  135. var ɵ0 = undefined;
  136. /**
  137. * An basic directive expected to be extended and decorated as a component. Sets up all
  138. * events and attributes needed to be managed by a CdkAccordion parent.
  139. */
  140. var CdkAccordionItem = /** @class */ (function () {
  141. function CdkAccordionItem(accordion, _changeDetectorRef, _expansionDispatcher) {
  142. var _this = this;
  143. this.accordion = accordion;
  144. this._changeDetectorRef = _changeDetectorRef;
  145. this._expansionDispatcher = _expansionDispatcher;
  146. /**
  147. * Subscription to openAll/closeAll events.
  148. */
  149. this._openCloseAllSubscription = rxjs.Subscription.EMPTY;
  150. /**
  151. * Event emitted every time the AccordionItem is closed.
  152. */
  153. this.closed = new core.EventEmitter();
  154. /**
  155. * Event emitted every time the AccordionItem is opened.
  156. */
  157. this.opened = new core.EventEmitter();
  158. /**
  159. * Event emitted when the AccordionItem is destroyed.
  160. */
  161. this.destroyed = new core.EventEmitter();
  162. /**
  163. * Emits whenever the expanded state of the accordion changes.
  164. * Primarily used to facilitate two-way binding.
  165. * \@docs-private
  166. */
  167. this.expandedChange = new core.EventEmitter();
  168. /**
  169. * The unique AccordionItem id.
  170. */
  171. this.id = "cdk-accordion-child-" + nextId$1++;
  172. this._expanded = false;
  173. this._disabled = false;
  174. /**
  175. * Unregister function for _expansionDispatcher.
  176. */
  177. this._removeUniqueSelectionListener = (/**
  178. * @return {?}
  179. */
  180. function () { });
  181. this._removeUniqueSelectionListener =
  182. _expansionDispatcher.listen((/**
  183. * @param {?} id
  184. * @param {?} accordionId
  185. * @return {?}
  186. */
  187. function (id, accordionId) {
  188. if (_this.accordion && !_this.accordion.multi &&
  189. _this.accordion.id === accordionId && _this.id !== id) {
  190. _this.expanded = false;
  191. }
  192. }));
  193. // When an accordion item is hosted in an accordion, subscribe to open/close events.
  194. if (this.accordion) {
  195. this._openCloseAllSubscription = this._subscribeToOpenCloseAllActions();
  196. }
  197. }
  198. Object.defineProperty(CdkAccordionItem.prototype, "expanded", {
  199. /** Whether the AccordionItem is expanded. */
  200. get: /**
  201. * Whether the AccordionItem is expanded.
  202. * @return {?}
  203. */
  204. function () { return this._expanded; },
  205. set: /**
  206. * @param {?} expanded
  207. * @return {?}
  208. */
  209. function (expanded) {
  210. expanded = coercion.coerceBooleanProperty(expanded);
  211. // Only emit events and update the internal value if the value changes.
  212. if (this._expanded !== expanded) {
  213. this._expanded = expanded;
  214. this.expandedChange.emit(expanded);
  215. if (expanded) {
  216. this.opened.emit();
  217. /**
  218. * In the unique selection dispatcher, the id parameter is the id of the CdkAccordionItem,
  219. * the name value is the id of the accordion.
  220. * @type {?}
  221. */
  222. var accordionId = this.accordion ? this.accordion.id : this.id;
  223. this._expansionDispatcher.notify(this.id, accordionId);
  224. }
  225. else {
  226. this.closed.emit();
  227. }
  228. // Ensures that the animation will run when the value is set outside of an `@Input`.
  229. // This includes cases like the open, close and toggle methods.
  230. this._changeDetectorRef.markForCheck();
  231. }
  232. },
  233. enumerable: true,
  234. configurable: true
  235. });
  236. Object.defineProperty(CdkAccordionItem.prototype, "disabled", {
  237. /** Whether the AccordionItem is disabled. */
  238. get: /**
  239. * Whether the AccordionItem is disabled.
  240. * @return {?}
  241. */
  242. function () { return this._disabled; },
  243. set: /**
  244. * @param {?} disabled
  245. * @return {?}
  246. */
  247. function (disabled) { this._disabled = coercion.coerceBooleanProperty(disabled); },
  248. enumerable: true,
  249. configurable: true
  250. });
  251. /** Emits an event for the accordion item being destroyed. */
  252. /**
  253. * Emits an event for the accordion item being destroyed.
  254. * @return {?}
  255. */
  256. CdkAccordionItem.prototype.ngOnDestroy = /**
  257. * Emits an event for the accordion item being destroyed.
  258. * @return {?}
  259. */
  260. function () {
  261. this.opened.complete();
  262. this.closed.complete();
  263. this.destroyed.emit();
  264. this.destroyed.complete();
  265. this._removeUniqueSelectionListener();
  266. this._openCloseAllSubscription.unsubscribe();
  267. };
  268. /** Toggles the expanded state of the accordion item. */
  269. /**
  270. * Toggles the expanded state of the accordion item.
  271. * @return {?}
  272. */
  273. CdkAccordionItem.prototype.toggle = /**
  274. * Toggles the expanded state of the accordion item.
  275. * @return {?}
  276. */
  277. function () {
  278. if (!this.disabled) {
  279. this.expanded = !this.expanded;
  280. }
  281. };
  282. /** Sets the expanded state of the accordion item to false. */
  283. /**
  284. * Sets the expanded state of the accordion item to false.
  285. * @return {?}
  286. */
  287. CdkAccordionItem.prototype.close = /**
  288. * Sets the expanded state of the accordion item to false.
  289. * @return {?}
  290. */
  291. function () {
  292. if (!this.disabled) {
  293. this.expanded = false;
  294. }
  295. };
  296. /** Sets the expanded state of the accordion item to true. */
  297. /**
  298. * Sets the expanded state of the accordion item to true.
  299. * @return {?}
  300. */
  301. CdkAccordionItem.prototype.open = /**
  302. * Sets the expanded state of the accordion item to true.
  303. * @return {?}
  304. */
  305. function () {
  306. if (!this.disabled) {
  307. this.expanded = true;
  308. }
  309. };
  310. /**
  311. * @private
  312. * @return {?}
  313. */
  314. CdkAccordionItem.prototype._subscribeToOpenCloseAllActions = /**
  315. * @private
  316. * @return {?}
  317. */
  318. function () {
  319. var _this = this;
  320. return this.accordion._openCloseAllActions.subscribe((/**
  321. * @param {?} expanded
  322. * @return {?}
  323. */
  324. function (expanded) {
  325. // Only change expanded state if item is enabled
  326. if (!_this.disabled) {
  327. _this.expanded = expanded;
  328. }
  329. }));
  330. };
  331. CdkAccordionItem.decorators = [
  332. { type: core.Directive, args: [{
  333. selector: 'cdk-accordion-item, [cdkAccordionItem]',
  334. exportAs: 'cdkAccordionItem',
  335. providers: [
  336. // Provide CdkAccordion as undefined to prevent nested accordion items from registering
  337. // to the same accordion.
  338. { provide: CdkAccordion, useValue: ɵ0 },
  339. ],
  340. },] },
  341. ];
  342. /** @nocollapse */
  343. CdkAccordionItem.ctorParameters = function () { return [
  344. { type: CdkAccordion, decorators: [{ type: core.Optional }, { type: core.SkipSelf }] },
  345. { type: core.ChangeDetectorRef },
  346. { type: collections.UniqueSelectionDispatcher }
  347. ]; };
  348. CdkAccordionItem.propDecorators = {
  349. closed: [{ type: core.Output }],
  350. opened: [{ type: core.Output }],
  351. destroyed: [{ type: core.Output }],
  352. expandedChange: [{ type: core.Output }],
  353. expanded: [{ type: core.Input }],
  354. disabled: [{ type: core.Input }]
  355. };
  356. return CdkAccordionItem;
  357. }());
  358. /**
  359. * @fileoverview added by tsickle
  360. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  361. */
  362. var CdkAccordionModule = /** @class */ (function () {
  363. function CdkAccordionModule() {
  364. }
  365. CdkAccordionModule.decorators = [
  366. { type: core.NgModule, args: [{
  367. exports: [CdkAccordion, CdkAccordionItem],
  368. declarations: [CdkAccordion, CdkAccordionItem],
  369. },] },
  370. ];
  371. return CdkAccordionModule;
  372. }());
  373. exports.CdkAccordionItem = CdkAccordionItem;
  374. exports.CdkAccordion = CdkAccordion;
  375. exports.CdkAccordionModule = CdkAccordionModule;
  376. Object.defineProperty(exports, '__esModule', { value: true });
  377. })));
  378. //# sourceMappingURL=cdk-accordion.umd.js.map