material-snack-bar.umd.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  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('rxjs'), require('@angular/core'), require('@angular/animations'), require('@angular/cdk/portal'), require('rxjs/operators'), require('@angular/cdk/overlay'), require('@angular/common'), require('@angular/material/core'), require('@angular/material/button'), require('@angular/cdk/a11y'), require('@angular/cdk/layout')) :
  10. typeof define === 'function' && define.amd ? define('@angular/material/snack-bar', ['exports', 'rxjs', '@angular/core', '@angular/animations', '@angular/cdk/portal', 'rxjs/operators', '@angular/cdk/overlay', '@angular/common', '@angular/material/core', '@angular/material/button', '@angular/cdk/a11y', '@angular/cdk/layout'], factory) :
  11. (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.snackBar = {}),global.rxjs,global.ng.core,global.ng.animations,global.ng.cdk.portal,global.rxjs.operators,global.ng.cdk.overlay,global.ng.common,global.ng.material.core,global.ng.material.button,global.ng.cdk.a11y,global.ng.cdk.layout));
  12. }(this, (function (exports,rxjs,core,animations,portal,operators,overlay,common,core$1,button,a11y,layout) { 'use strict';
  13. /*! *****************************************************************************
  14. Copyright (c) Microsoft Corporation. All rights reserved.
  15. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  16. this file except in compliance with the License. You may obtain a copy of the
  17. License at http://www.apache.org/licenses/LICENSE-2.0
  18. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  20. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  21. MERCHANTABLITY OR NON-INFRINGEMENT.
  22. See the Apache Version 2.0 License for specific language governing permissions
  23. and limitations under the License.
  24. ***************************************************************************** */
  25. /* global Reflect, Promise */
  26. var extendStatics = function(d, b) {
  27. extendStatics = Object.setPrototypeOf ||
  28. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  29. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  30. return extendStatics(d, b);
  31. };
  32. function __extends(d, b) {
  33. extendStatics(d, b);
  34. function __() { this.constructor = d; }
  35. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36. }
  37. var __assign = function() {
  38. __assign = Object.assign || function __assign(t) {
  39. for (var s, i = 1, n = arguments.length; i < n; i++) {
  40. s = arguments[i];
  41. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  42. }
  43. return t;
  44. };
  45. return __assign.apply(this, arguments);
  46. };
  47. /**
  48. * @fileoverview added by tsickle
  49. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  50. */
  51. /**
  52. * Reference to a snack bar dispatched from the snack bar service.
  53. * @template T
  54. */
  55. var /**
  56. * Reference to a snack bar dispatched from the snack bar service.
  57. * @template T
  58. */
  59. MatSnackBarRef = /** @class */ (function () {
  60. function MatSnackBarRef(containerInstance, _overlayRef) {
  61. var _this = this;
  62. this._overlayRef = _overlayRef;
  63. /**
  64. * Subject for notifying the user that the snack bar has been dismissed.
  65. */
  66. this._afterDismissed = new rxjs.Subject();
  67. /**
  68. * Subject for notifying the user that the snack bar has opened and appeared.
  69. */
  70. this._afterOpened = new rxjs.Subject();
  71. /**
  72. * Subject for notifying the user that the snack bar action was called.
  73. */
  74. this._onAction = new rxjs.Subject();
  75. /**
  76. * Whether the snack bar was dismissed using the action button.
  77. */
  78. this._dismissedByAction = false;
  79. this.containerInstance = containerInstance;
  80. // Dismiss snackbar on action.
  81. this.onAction().subscribe((/**
  82. * @return {?}
  83. */
  84. function () { return _this.dismiss(); }));
  85. containerInstance._onExit.subscribe((/**
  86. * @return {?}
  87. */
  88. function () { return _this._finishDismiss(); }));
  89. }
  90. /** Dismisses the snack bar. */
  91. /**
  92. * Dismisses the snack bar.
  93. * @return {?}
  94. */
  95. MatSnackBarRef.prototype.dismiss = /**
  96. * Dismisses the snack bar.
  97. * @return {?}
  98. */
  99. function () {
  100. if (!this._afterDismissed.closed) {
  101. this.containerInstance.exit();
  102. }
  103. clearTimeout(this._durationTimeoutId);
  104. };
  105. /** Marks the snackbar action clicked. */
  106. /**
  107. * Marks the snackbar action clicked.
  108. * @return {?}
  109. */
  110. MatSnackBarRef.prototype.dismissWithAction = /**
  111. * Marks the snackbar action clicked.
  112. * @return {?}
  113. */
  114. function () {
  115. if (!this._onAction.closed) {
  116. this._dismissedByAction = true;
  117. this._onAction.next();
  118. this._onAction.complete();
  119. }
  120. };
  121. /**
  122. * Marks the snackbar action clicked.
  123. * @deprecated Use `dismissWithAction` instead.
  124. * @breaking-change 8.0.0
  125. */
  126. /**
  127. * Marks the snackbar action clicked.
  128. * @deprecated Use `dismissWithAction` instead.
  129. * \@breaking-change 8.0.0
  130. * @return {?}
  131. */
  132. MatSnackBarRef.prototype.closeWithAction = /**
  133. * Marks the snackbar action clicked.
  134. * @deprecated Use `dismissWithAction` instead.
  135. * \@breaking-change 8.0.0
  136. * @return {?}
  137. */
  138. function () {
  139. this.dismissWithAction();
  140. };
  141. /** Dismisses the snack bar after some duration */
  142. /**
  143. * Dismisses the snack bar after some duration
  144. * @param {?} duration
  145. * @return {?}
  146. */
  147. MatSnackBarRef.prototype._dismissAfter = /**
  148. * Dismisses the snack bar after some duration
  149. * @param {?} duration
  150. * @return {?}
  151. */
  152. function (duration) {
  153. var _this = this;
  154. this._durationTimeoutId = setTimeout((/**
  155. * @return {?}
  156. */
  157. function () { return _this.dismiss(); }), duration);
  158. };
  159. /** Marks the snackbar as opened */
  160. /**
  161. * Marks the snackbar as opened
  162. * @return {?}
  163. */
  164. MatSnackBarRef.prototype._open = /**
  165. * Marks the snackbar as opened
  166. * @return {?}
  167. */
  168. function () {
  169. if (!this._afterOpened.closed) {
  170. this._afterOpened.next();
  171. this._afterOpened.complete();
  172. }
  173. };
  174. /** Cleans up the DOM after closing. */
  175. /**
  176. * Cleans up the DOM after closing.
  177. * @private
  178. * @return {?}
  179. */
  180. MatSnackBarRef.prototype._finishDismiss = /**
  181. * Cleans up the DOM after closing.
  182. * @private
  183. * @return {?}
  184. */
  185. function () {
  186. this._overlayRef.dispose();
  187. if (!this._onAction.closed) {
  188. this._onAction.complete();
  189. }
  190. this._afterDismissed.next({ dismissedByAction: this._dismissedByAction });
  191. this._afterDismissed.complete();
  192. this._dismissedByAction = false;
  193. };
  194. /** Gets an observable that is notified when the snack bar is finished closing. */
  195. /**
  196. * Gets an observable that is notified when the snack bar is finished closing.
  197. * @return {?}
  198. */
  199. MatSnackBarRef.prototype.afterDismissed = /**
  200. * Gets an observable that is notified when the snack bar is finished closing.
  201. * @return {?}
  202. */
  203. function () {
  204. return this._afterDismissed.asObservable();
  205. };
  206. /** Gets an observable that is notified when the snack bar has opened and appeared. */
  207. /**
  208. * Gets an observable that is notified when the snack bar has opened and appeared.
  209. * @return {?}
  210. */
  211. MatSnackBarRef.prototype.afterOpened = /**
  212. * Gets an observable that is notified when the snack bar has opened and appeared.
  213. * @return {?}
  214. */
  215. function () {
  216. return this.containerInstance._onEnter;
  217. };
  218. /** Gets an observable that is notified when the snack bar action is called. */
  219. /**
  220. * Gets an observable that is notified when the snack bar action is called.
  221. * @return {?}
  222. */
  223. MatSnackBarRef.prototype.onAction = /**
  224. * Gets an observable that is notified when the snack bar action is called.
  225. * @return {?}
  226. */
  227. function () {
  228. return this._onAction.asObservable();
  229. };
  230. return MatSnackBarRef;
  231. }());
  232. /**
  233. * @fileoverview added by tsickle
  234. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  235. */
  236. /**
  237. * Injection token that can be used to access the data that was passed in to a snack bar.
  238. * @type {?}
  239. */
  240. var MAT_SNACK_BAR_DATA = new core.InjectionToken('MatSnackBarData');
  241. /**
  242. * Configuration used when opening a snack-bar.
  243. * @template D
  244. */
  245. var /**
  246. * Configuration used when opening a snack-bar.
  247. * @template D
  248. */
  249. MatSnackBarConfig = /** @class */ (function () {
  250. function MatSnackBarConfig() {
  251. /**
  252. * The politeness level for the MatAriaLiveAnnouncer announcement.
  253. */
  254. this.politeness = 'assertive';
  255. /**
  256. * Message to be announced by the LiveAnnouncer. When opening a snackbar without a custom
  257. * component or template, the announcement message will default to the specified message.
  258. */
  259. this.announcementMessage = '';
  260. /**
  261. * The length of time in milliseconds to wait before automatically dismissing the snack bar.
  262. */
  263. this.duration = 0;
  264. /**
  265. * Data being injected into the child component.
  266. */
  267. this.data = null;
  268. /**
  269. * The horizontal position to place the snack bar.
  270. */
  271. this.horizontalPosition = 'center';
  272. /**
  273. * The vertical position to place the snack bar.
  274. */
  275. this.verticalPosition = 'bottom';
  276. }
  277. return MatSnackBarConfig;
  278. }());
  279. /**
  280. * @fileoverview added by tsickle
  281. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  282. */
  283. /**
  284. * A component used to open as the default snack bar, matching material spec.
  285. * This should only be used internally by the snack bar service.
  286. */
  287. var SimpleSnackBar = /** @class */ (function () {
  288. function SimpleSnackBar(snackBarRef, data) {
  289. this.snackBarRef = snackBarRef;
  290. this.data = data;
  291. }
  292. /** Performs the action on the snack bar. */
  293. /**
  294. * Performs the action on the snack bar.
  295. * @return {?}
  296. */
  297. SimpleSnackBar.prototype.action = /**
  298. * Performs the action on the snack bar.
  299. * @return {?}
  300. */
  301. function () {
  302. this.snackBarRef.dismissWithAction();
  303. };
  304. Object.defineProperty(SimpleSnackBar.prototype, "hasAction", {
  305. /** If the action button should be shown. */
  306. get: /**
  307. * If the action button should be shown.
  308. * @return {?}
  309. */
  310. function () {
  311. return !!this.data.action;
  312. },
  313. enumerable: true,
  314. configurable: true
  315. });
  316. SimpleSnackBar.decorators = [
  317. { type: core.Component, args: [{selector: 'simple-snack-bar',
  318. template: "<span>{{data.message}}</span><div class=\"mat-simple-snackbar-action\" *ngIf=\"hasAction\"><button mat-button (click)=\"action()\">{{data.action}}</button></div>",
  319. styles: [".mat-simple-snackbar{display:flex;justify-content:space-between;align-items:center;height:100%;line-height:20px;opacity:1}.mat-simple-snackbar-action{flex-shrink:0;margin:-8px -8px -8px 8px}.mat-simple-snackbar-action button{max-height:36px;min-width:0}[dir=rtl] .mat-simple-snackbar-action{margin-left:-8px;margin-right:8px}"],
  320. encapsulation: core.ViewEncapsulation.None,
  321. changeDetection: core.ChangeDetectionStrategy.OnPush,
  322. host: {
  323. 'class': 'mat-simple-snackbar',
  324. }
  325. },] },
  326. ];
  327. /** @nocollapse */
  328. SimpleSnackBar.ctorParameters = function () { return [
  329. { type: MatSnackBarRef },
  330. { type: undefined, decorators: [{ type: core.Inject, args: [MAT_SNACK_BAR_DATA,] }] }
  331. ]; };
  332. return SimpleSnackBar;
  333. }());
  334. /**
  335. * @fileoverview added by tsickle
  336. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  337. */
  338. /**
  339. * Animations used by the Material snack bar.
  340. * \@docs-private
  341. * @type {?}
  342. */
  343. var matSnackBarAnimations = {
  344. /**
  345. * Animation that shows and hides a snack bar.
  346. */
  347. snackBarState: animations.trigger('state', [
  348. animations.state('void, hidden', animations.style({
  349. transform: 'scale(0.8)',
  350. opacity: 0,
  351. })),
  352. animations.state('visible', animations.style({
  353. transform: 'scale(1)',
  354. opacity: 1,
  355. })),
  356. animations.transition('* => visible', animations.animate('150ms cubic-bezier(0, 0, 0.2, 1)')),
  357. animations.transition('* => void, * => hidden', animations.animate('75ms cubic-bezier(0.4, 0.0, 1, 1)', animations.style({
  358. opacity: 0
  359. }))),
  360. ])
  361. };
  362. /**
  363. * @fileoverview added by tsickle
  364. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  365. */
  366. /**
  367. * Internal component that wraps user-provided snack bar content.
  368. * \@docs-private
  369. */
  370. var MatSnackBarContainer = /** @class */ (function (_super) {
  371. __extends(MatSnackBarContainer, _super);
  372. function MatSnackBarContainer(_ngZone, _elementRef, _changeDetectorRef, snackBarConfig) {
  373. var _this = _super.call(this) || this;
  374. _this._ngZone = _ngZone;
  375. _this._elementRef = _elementRef;
  376. _this._changeDetectorRef = _changeDetectorRef;
  377. _this.snackBarConfig = snackBarConfig;
  378. /**
  379. * Whether the component has been destroyed.
  380. */
  381. _this._destroyed = false;
  382. /**
  383. * Subject for notifying that the snack bar has exited from view.
  384. */
  385. _this._onExit = new rxjs.Subject();
  386. /**
  387. * Subject for notifying that the snack bar has finished entering the view.
  388. */
  389. _this._onEnter = new rxjs.Subject();
  390. /**
  391. * The state of the snack bar animations.
  392. */
  393. _this._animationState = 'void';
  394. // Based on the ARIA spec, `alert` and `status` roles have an
  395. // implicit `assertive` and `polite` politeness respectively.
  396. if (snackBarConfig.politeness === 'assertive' && !snackBarConfig.announcementMessage) {
  397. _this._role = 'alert';
  398. }
  399. else if (snackBarConfig.politeness === 'off') {
  400. _this._role = null;
  401. }
  402. else {
  403. _this._role = 'status';
  404. }
  405. return _this;
  406. }
  407. /** Attach a component portal as content to this snack bar container. */
  408. /**
  409. * Attach a component portal as content to this snack bar container.
  410. * @template T
  411. * @param {?} portal
  412. * @return {?}
  413. */
  414. MatSnackBarContainer.prototype.attachComponentPortal = /**
  415. * Attach a component portal as content to this snack bar container.
  416. * @template T
  417. * @param {?} portal
  418. * @return {?}
  419. */
  420. function (portal$$1) {
  421. this._assertNotAttached();
  422. this._applySnackBarClasses();
  423. return this._portalOutlet.attachComponentPortal(portal$$1);
  424. };
  425. /** Attach a template portal as content to this snack bar container. */
  426. /**
  427. * Attach a template portal as content to this snack bar container.
  428. * @template C
  429. * @param {?} portal
  430. * @return {?}
  431. */
  432. MatSnackBarContainer.prototype.attachTemplatePortal = /**
  433. * Attach a template portal as content to this snack bar container.
  434. * @template C
  435. * @param {?} portal
  436. * @return {?}
  437. */
  438. function (portal$$1) {
  439. this._assertNotAttached();
  440. this._applySnackBarClasses();
  441. return this._portalOutlet.attachTemplatePortal(portal$$1);
  442. };
  443. /** Handle end of animations, updating the state of the snackbar. */
  444. /**
  445. * Handle end of animations, updating the state of the snackbar.
  446. * @param {?} event
  447. * @return {?}
  448. */
  449. MatSnackBarContainer.prototype.onAnimationEnd = /**
  450. * Handle end of animations, updating the state of the snackbar.
  451. * @param {?} event
  452. * @return {?}
  453. */
  454. function (event) {
  455. var fromState = event.fromState, toState = event.toState;
  456. if ((toState === 'void' && fromState !== 'void') || toState === 'hidden') {
  457. this._completeExit();
  458. }
  459. if (toState === 'visible') {
  460. // Note: we shouldn't use `this` inside the zone callback,
  461. // because it can cause a memory leak.
  462. /** @type {?} */
  463. var onEnter_1 = this._onEnter;
  464. this._ngZone.run((/**
  465. * @return {?}
  466. */
  467. function () {
  468. onEnter_1.next();
  469. onEnter_1.complete();
  470. }));
  471. }
  472. };
  473. /** Begin animation of snack bar entrance into view. */
  474. /**
  475. * Begin animation of snack bar entrance into view.
  476. * @return {?}
  477. */
  478. MatSnackBarContainer.prototype.enter = /**
  479. * Begin animation of snack bar entrance into view.
  480. * @return {?}
  481. */
  482. function () {
  483. if (!this._destroyed) {
  484. this._animationState = 'visible';
  485. this._changeDetectorRef.detectChanges();
  486. }
  487. };
  488. /** Begin animation of the snack bar exiting from view. */
  489. /**
  490. * Begin animation of the snack bar exiting from view.
  491. * @return {?}
  492. */
  493. MatSnackBarContainer.prototype.exit = /**
  494. * Begin animation of the snack bar exiting from view.
  495. * @return {?}
  496. */
  497. function () {
  498. // Note: this one transitions to `hidden`, rather than `void`, in order to handle the case
  499. // where multiple snack bars are opened in quick succession (e.g. two consecutive calls to
  500. // `MatSnackBar.open`).
  501. this._animationState = 'hidden';
  502. return this._onExit;
  503. };
  504. /** Makes sure the exit callbacks have been invoked when the element is destroyed. */
  505. /**
  506. * Makes sure the exit callbacks have been invoked when the element is destroyed.
  507. * @return {?}
  508. */
  509. MatSnackBarContainer.prototype.ngOnDestroy = /**
  510. * Makes sure the exit callbacks have been invoked when the element is destroyed.
  511. * @return {?}
  512. */
  513. function () {
  514. this._destroyed = true;
  515. this._completeExit();
  516. };
  517. /**
  518. * Waits for the zone to settle before removing the element. Helps prevent
  519. * errors where we end up removing an element which is in the middle of an animation.
  520. */
  521. /**
  522. * Waits for the zone to settle before removing the element. Helps prevent
  523. * errors where we end up removing an element which is in the middle of an animation.
  524. * @private
  525. * @return {?}
  526. */
  527. MatSnackBarContainer.prototype._completeExit = /**
  528. * Waits for the zone to settle before removing the element. Helps prevent
  529. * errors where we end up removing an element which is in the middle of an animation.
  530. * @private
  531. * @return {?}
  532. */
  533. function () {
  534. var _this = this;
  535. this._ngZone.onMicrotaskEmpty.asObservable().pipe(operators.take(1)).subscribe((/**
  536. * @return {?}
  537. */
  538. function () {
  539. _this._onExit.next();
  540. _this._onExit.complete();
  541. }));
  542. };
  543. /** Applies the various positioning and user-configured CSS classes to the snack bar. */
  544. /**
  545. * Applies the various positioning and user-configured CSS classes to the snack bar.
  546. * @private
  547. * @return {?}
  548. */
  549. MatSnackBarContainer.prototype._applySnackBarClasses = /**
  550. * Applies the various positioning and user-configured CSS classes to the snack bar.
  551. * @private
  552. * @return {?}
  553. */
  554. function () {
  555. /** @type {?} */
  556. var element = this._elementRef.nativeElement;
  557. /** @type {?} */
  558. var panelClasses = this.snackBarConfig.panelClass;
  559. if (panelClasses) {
  560. if (Array.isArray(panelClasses)) {
  561. // Note that we can't use a spread here, because IE doesn't support multiple arguments.
  562. panelClasses.forEach((/**
  563. * @param {?} cssClass
  564. * @return {?}
  565. */
  566. function (cssClass) { return element.classList.add(cssClass); }));
  567. }
  568. else {
  569. element.classList.add(panelClasses);
  570. }
  571. }
  572. if (this.snackBarConfig.horizontalPosition === 'center') {
  573. element.classList.add('mat-snack-bar-center');
  574. }
  575. if (this.snackBarConfig.verticalPosition === 'top') {
  576. element.classList.add('mat-snack-bar-top');
  577. }
  578. };
  579. /** Asserts that no content is already attached to the container. */
  580. /**
  581. * Asserts that no content is already attached to the container.
  582. * @private
  583. * @return {?}
  584. */
  585. MatSnackBarContainer.prototype._assertNotAttached = /**
  586. * Asserts that no content is already attached to the container.
  587. * @private
  588. * @return {?}
  589. */
  590. function () {
  591. if (this._portalOutlet.hasAttached()) {
  592. throw Error('Attempting to attach snack bar content after content is already attached');
  593. }
  594. };
  595. MatSnackBarContainer.decorators = [
  596. { type: core.Component, args: [{selector: 'snack-bar-container',
  597. template: "<ng-template cdkPortalOutlet></ng-template>",
  598. styles: [".mat-snack-bar-container{border-radius:4px;box-sizing:border-box;display:block;margin:24px;max-width:33vw;min-width:344px;padding:14px 16px;min-height:48px;transform-origin:center}@media (-ms-high-contrast:active){.mat-snack-bar-container{border:solid 1px}}.mat-snack-bar-handset{width:100%}.mat-snack-bar-handset .mat-snack-bar-container{margin:8px;max-width:100%;min-width:0;width:100%}"],
  599. // In Ivy embedded views will be change detected from their declaration place, rather than
  600. // where they were stamped out. This means that we can't have the snack bar container be OnPush,
  601. // because it might cause snack bars that were opened from a template not to be out of date.
  602. // tslint:disable-next-line:validate-decorators
  603. changeDetection: core.ChangeDetectionStrategy.Default,
  604. encapsulation: core.ViewEncapsulation.None,
  605. animations: [matSnackBarAnimations.snackBarState],
  606. host: {
  607. '[attr.role]': '_role',
  608. 'class': 'mat-snack-bar-container',
  609. '[@state]': '_animationState',
  610. '(@state.done)': 'onAnimationEnd($event)'
  611. },
  612. },] },
  613. ];
  614. /** @nocollapse */
  615. MatSnackBarContainer.ctorParameters = function () { return [
  616. { type: core.NgZone },
  617. { type: core.ElementRef },
  618. { type: core.ChangeDetectorRef },
  619. { type: MatSnackBarConfig }
  620. ]; };
  621. MatSnackBarContainer.propDecorators = {
  622. _portalOutlet: [{ type: core.ViewChild, args: [portal.CdkPortalOutlet, { static: true },] }]
  623. };
  624. return MatSnackBarContainer;
  625. }(portal.BasePortalOutlet));
  626. /**
  627. * @fileoverview added by tsickle
  628. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  629. */
  630. var MatSnackBarModule = /** @class */ (function () {
  631. function MatSnackBarModule() {
  632. }
  633. MatSnackBarModule.decorators = [
  634. { type: core.NgModule, args: [{
  635. imports: [
  636. overlay.OverlayModule,
  637. portal.PortalModule,
  638. common.CommonModule,
  639. button.MatButtonModule,
  640. core$1.MatCommonModule,
  641. ],
  642. exports: [MatSnackBarContainer, core$1.MatCommonModule],
  643. declarations: [MatSnackBarContainer, SimpleSnackBar],
  644. entryComponents: [MatSnackBarContainer, SimpleSnackBar],
  645. },] },
  646. ];
  647. return MatSnackBarModule;
  648. }());
  649. /**
  650. * @fileoverview added by tsickle
  651. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  652. */
  653. /**
  654. * Injection token that can be used to specify default snack bar.
  655. * @type {?}
  656. */
  657. var MAT_SNACK_BAR_DEFAULT_OPTIONS = new core.InjectionToken('mat-snack-bar-default-options', {
  658. providedIn: 'root',
  659. factory: MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY,
  660. });
  661. /**
  662. * \@docs-private
  663. * @return {?}
  664. */
  665. function MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY() {
  666. return new MatSnackBarConfig();
  667. }
  668. /**
  669. * Service to dispatch Material Design snack bar messages.
  670. */
  671. var MatSnackBar = /** @class */ (function () {
  672. function MatSnackBar(_overlay, _live, _injector, _breakpointObserver, _parentSnackBar, _defaultConfig) {
  673. this._overlay = _overlay;
  674. this._live = _live;
  675. this._injector = _injector;
  676. this._breakpointObserver = _breakpointObserver;
  677. this._parentSnackBar = _parentSnackBar;
  678. this._defaultConfig = _defaultConfig;
  679. /**
  680. * Reference to the current snack bar in the view *at this level* (in the Angular injector tree).
  681. * If there is a parent snack-bar service, all operations should delegate to that parent
  682. * via `_openedSnackBarRef`.
  683. */
  684. this._snackBarRefAtThisLevel = null;
  685. }
  686. Object.defineProperty(MatSnackBar.prototype, "_openedSnackBarRef", {
  687. /** Reference to the currently opened snackbar at *any* level. */
  688. get: /**
  689. * Reference to the currently opened snackbar at *any* level.
  690. * @return {?}
  691. */
  692. function () {
  693. /** @type {?} */
  694. var parent = this._parentSnackBar;
  695. return parent ? parent._openedSnackBarRef : this._snackBarRefAtThisLevel;
  696. },
  697. set: /**
  698. * @param {?} value
  699. * @return {?}
  700. */
  701. function (value) {
  702. if (this._parentSnackBar) {
  703. this._parentSnackBar._openedSnackBarRef = value;
  704. }
  705. else {
  706. this._snackBarRefAtThisLevel = value;
  707. }
  708. },
  709. enumerable: true,
  710. configurable: true
  711. });
  712. /**
  713. * Creates and dispatches a snack bar with a custom component for the content, removing any
  714. * currently opened snack bars.
  715. *
  716. * @param component Component to be instantiated.
  717. * @param config Extra configuration for the snack bar.
  718. */
  719. /**
  720. * Creates and dispatches a snack bar with a custom component for the content, removing any
  721. * currently opened snack bars.
  722. *
  723. * @template T
  724. * @param {?} component Component to be instantiated.
  725. * @param {?=} config Extra configuration for the snack bar.
  726. * @return {?}
  727. */
  728. MatSnackBar.prototype.openFromComponent = /**
  729. * Creates and dispatches a snack bar with a custom component for the content, removing any
  730. * currently opened snack bars.
  731. *
  732. * @template T
  733. * @param {?} component Component to be instantiated.
  734. * @param {?=} config Extra configuration for the snack bar.
  735. * @return {?}
  736. */
  737. function (component, config) {
  738. return (/** @type {?} */ (this._attach(component, config)));
  739. };
  740. /**
  741. * Creates and dispatches a snack bar with a custom template for the content, removing any
  742. * currently opened snack bars.
  743. *
  744. * @param template Template to be instantiated.
  745. * @param config Extra configuration for the snack bar.
  746. */
  747. /**
  748. * Creates and dispatches a snack bar with a custom template for the content, removing any
  749. * currently opened snack bars.
  750. *
  751. * @param {?} template Template to be instantiated.
  752. * @param {?=} config Extra configuration for the snack bar.
  753. * @return {?}
  754. */
  755. MatSnackBar.prototype.openFromTemplate = /**
  756. * Creates and dispatches a snack bar with a custom template for the content, removing any
  757. * currently opened snack bars.
  758. *
  759. * @param {?} template Template to be instantiated.
  760. * @param {?=} config Extra configuration for the snack bar.
  761. * @return {?}
  762. */
  763. function (template, config) {
  764. return this._attach(template, config);
  765. };
  766. /**
  767. * Opens a snackbar with a message and an optional action.
  768. * @param message The message to show in the snackbar.
  769. * @param action The label for the snackbar action.
  770. * @param config Additional configuration options for the snackbar.
  771. */
  772. /**
  773. * Opens a snackbar with a message and an optional action.
  774. * @param {?} message The message to show in the snackbar.
  775. * @param {?=} action The label for the snackbar action.
  776. * @param {?=} config Additional configuration options for the snackbar.
  777. * @return {?}
  778. */
  779. MatSnackBar.prototype.open = /**
  780. * Opens a snackbar with a message and an optional action.
  781. * @param {?} message The message to show in the snackbar.
  782. * @param {?=} action The label for the snackbar action.
  783. * @param {?=} config Additional configuration options for the snackbar.
  784. * @return {?}
  785. */
  786. function (message, action, config) {
  787. if (action === void 0) { action = ''; }
  788. /** @type {?} */
  789. var _config = __assign({}, this._defaultConfig, config);
  790. // Since the user doesn't have access to the component, we can
  791. // override the data to pass in our own message and action.
  792. _config.data = { message: message, action: action };
  793. if (!_config.announcementMessage) {
  794. _config.announcementMessage = message;
  795. }
  796. return this.openFromComponent(SimpleSnackBar, _config);
  797. };
  798. /**
  799. * Dismisses the currently-visible snack bar.
  800. */
  801. /**
  802. * Dismisses the currently-visible snack bar.
  803. * @return {?}
  804. */
  805. MatSnackBar.prototype.dismiss = /**
  806. * Dismisses the currently-visible snack bar.
  807. * @return {?}
  808. */
  809. function () {
  810. if (this._openedSnackBarRef) {
  811. this._openedSnackBarRef.dismiss();
  812. }
  813. };
  814. /**
  815. * @return {?}
  816. */
  817. MatSnackBar.prototype.ngOnDestroy = /**
  818. * @return {?}
  819. */
  820. function () {
  821. // Only dismiss the snack bar at the current level on destroy.
  822. if (this._snackBarRefAtThisLevel) {
  823. this._snackBarRefAtThisLevel.dismiss();
  824. }
  825. };
  826. /**
  827. * Attaches the snack bar container component to the overlay.
  828. */
  829. /**
  830. * Attaches the snack bar container component to the overlay.
  831. * @private
  832. * @param {?} overlayRef
  833. * @param {?} config
  834. * @return {?}
  835. */
  836. MatSnackBar.prototype._attachSnackBarContainer = /**
  837. * Attaches the snack bar container component to the overlay.
  838. * @private
  839. * @param {?} overlayRef
  840. * @param {?} config
  841. * @return {?}
  842. */
  843. function (overlayRef, config) {
  844. /** @type {?} */
  845. var userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
  846. /** @type {?} */
  847. var injector = new portal.PortalInjector(userInjector || this._injector, new WeakMap([
  848. [MatSnackBarConfig, config]
  849. ]));
  850. /** @type {?} */
  851. var containerPortal = new portal.ComponentPortal(MatSnackBarContainer, config.viewContainerRef, injector);
  852. /** @type {?} */
  853. var containerRef = overlayRef.attach(containerPortal);
  854. containerRef.instance.snackBarConfig = config;
  855. return containerRef.instance;
  856. };
  857. /**
  858. * Places a new component or a template as the content of the snack bar container.
  859. */
  860. /**
  861. * Places a new component or a template as the content of the snack bar container.
  862. * @private
  863. * @template T
  864. * @param {?} content
  865. * @param {?=} userConfig
  866. * @return {?}
  867. */
  868. MatSnackBar.prototype._attach = /**
  869. * Places a new component or a template as the content of the snack bar container.
  870. * @private
  871. * @template T
  872. * @param {?} content
  873. * @param {?=} userConfig
  874. * @return {?}
  875. */
  876. function (content, userConfig) {
  877. /** @type {?} */
  878. var config = __assign({}, new MatSnackBarConfig(), this._defaultConfig, userConfig);
  879. /** @type {?} */
  880. var overlayRef = this._createOverlay(config);
  881. /** @type {?} */
  882. var container = this._attachSnackBarContainer(overlayRef, config);
  883. /** @type {?} */
  884. var snackBarRef = new MatSnackBarRef(container, overlayRef);
  885. if (content instanceof core.TemplateRef) {
  886. /** @type {?} */
  887. var portal$$1 = new portal.TemplatePortal(content, (/** @type {?} */ (null)), (/** @type {?} */ ({
  888. $implicit: config.data,
  889. snackBarRef: snackBarRef
  890. })));
  891. snackBarRef.instance = container.attachTemplatePortal(portal$$1);
  892. }
  893. else {
  894. /** @type {?} */
  895. var injector = this._createInjector(config, snackBarRef);
  896. /** @type {?} */
  897. var portal$$1 = new portal.ComponentPortal(content, undefined, injector);
  898. /** @type {?} */
  899. var contentRef = container.attachComponentPortal(portal$$1);
  900. // We can't pass this via the injector, because the injector is created earlier.
  901. snackBarRef.instance = contentRef.instance;
  902. }
  903. // Subscribe to the breakpoint observer and attach the mat-snack-bar-handset class as
  904. // appropriate. This class is applied to the overlay element because the overlay must expand to
  905. // fill the width of the screen for full width snackbars.
  906. this._breakpointObserver.observe(layout.Breakpoints.Handset).pipe(operators.takeUntil(overlayRef.detachments().pipe(operators.take(1)))).subscribe((/**
  907. * @param {?} state
  908. * @return {?}
  909. */
  910. function (state$$1) {
  911. if (state$$1.matches) {
  912. overlayRef.overlayElement.classList.add('mat-snack-bar-handset');
  913. }
  914. else {
  915. overlayRef.overlayElement.classList.remove('mat-snack-bar-handset');
  916. }
  917. }));
  918. this._animateSnackBar(snackBarRef, config);
  919. this._openedSnackBarRef = snackBarRef;
  920. return this._openedSnackBarRef;
  921. };
  922. /** Animates the old snack bar out and the new one in. */
  923. /**
  924. * Animates the old snack bar out and the new one in.
  925. * @private
  926. * @param {?} snackBarRef
  927. * @param {?} config
  928. * @return {?}
  929. */
  930. MatSnackBar.prototype._animateSnackBar = /**
  931. * Animates the old snack bar out and the new one in.
  932. * @private
  933. * @param {?} snackBarRef
  934. * @param {?} config
  935. * @return {?}
  936. */
  937. function (snackBarRef, config) {
  938. var _this = this;
  939. // When the snackbar is dismissed, clear the reference to it.
  940. snackBarRef.afterDismissed().subscribe((/**
  941. * @return {?}
  942. */
  943. function () {
  944. // Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
  945. if (_this._openedSnackBarRef == snackBarRef) {
  946. _this._openedSnackBarRef = null;
  947. }
  948. if (config.announcementMessage) {
  949. _this._live.clear();
  950. }
  951. }));
  952. if (this._openedSnackBarRef) {
  953. // If a snack bar is already in view, dismiss it and enter the
  954. // new snack bar after exit animation is complete.
  955. this._openedSnackBarRef.afterDismissed().subscribe((/**
  956. * @return {?}
  957. */
  958. function () {
  959. snackBarRef.containerInstance.enter();
  960. }));
  961. this._openedSnackBarRef.dismiss();
  962. }
  963. else {
  964. // If no snack bar is in view, enter the new snack bar.
  965. snackBarRef.containerInstance.enter();
  966. }
  967. // If a dismiss timeout is provided, set up dismiss based on after the snackbar is opened.
  968. if (config.duration && config.duration > 0) {
  969. snackBarRef.afterOpened().subscribe((/**
  970. * @return {?}
  971. */
  972. function () { return snackBarRef._dismissAfter((/** @type {?} */ (config.duration))); }));
  973. }
  974. if (config.announcementMessage) {
  975. this._live.announce(config.announcementMessage, config.politeness);
  976. }
  977. };
  978. /**
  979. * Creates a new overlay and places it in the correct location.
  980. * @param config The user-specified snack bar config.
  981. */
  982. /**
  983. * Creates a new overlay and places it in the correct location.
  984. * @private
  985. * @param {?} config The user-specified snack bar config.
  986. * @return {?}
  987. */
  988. MatSnackBar.prototype._createOverlay = /**
  989. * Creates a new overlay and places it in the correct location.
  990. * @private
  991. * @param {?} config The user-specified snack bar config.
  992. * @return {?}
  993. */
  994. function (config) {
  995. /** @type {?} */
  996. var overlayConfig = new overlay.OverlayConfig();
  997. overlayConfig.direction = config.direction;
  998. /** @type {?} */
  999. var positionStrategy = this._overlay.position().global();
  1000. // Set horizontal position.
  1001. /** @type {?} */
  1002. var isRtl = config.direction === 'rtl';
  1003. /** @type {?} */
  1004. var isLeft = (config.horizontalPosition === 'left' ||
  1005. (config.horizontalPosition === 'start' && !isRtl) ||
  1006. (config.horizontalPosition === 'end' && isRtl));
  1007. /** @type {?} */
  1008. var isRight = !isLeft && config.horizontalPosition !== 'center';
  1009. if (isLeft) {
  1010. positionStrategy.left('0');
  1011. }
  1012. else if (isRight) {
  1013. positionStrategy.right('0');
  1014. }
  1015. else {
  1016. positionStrategy.centerHorizontally();
  1017. }
  1018. // Set horizontal position.
  1019. if (config.verticalPosition === 'top') {
  1020. positionStrategy.top('0');
  1021. }
  1022. else {
  1023. positionStrategy.bottom('0');
  1024. }
  1025. overlayConfig.positionStrategy = positionStrategy;
  1026. return this._overlay.create(overlayConfig);
  1027. };
  1028. /**
  1029. * Creates an injector to be used inside of a snack bar component.
  1030. * @param config Config that was used to create the snack bar.
  1031. * @param snackBarRef Reference to the snack bar.
  1032. */
  1033. /**
  1034. * Creates an injector to be used inside of a snack bar component.
  1035. * @private
  1036. * @template T
  1037. * @param {?} config Config that was used to create the snack bar.
  1038. * @param {?} snackBarRef Reference to the snack bar.
  1039. * @return {?}
  1040. */
  1041. MatSnackBar.prototype._createInjector = /**
  1042. * Creates an injector to be used inside of a snack bar component.
  1043. * @private
  1044. * @template T
  1045. * @param {?} config Config that was used to create the snack bar.
  1046. * @param {?} snackBarRef Reference to the snack bar.
  1047. * @return {?}
  1048. */
  1049. function (config, snackBarRef) {
  1050. /** @type {?} */
  1051. var userInjector = config && config.viewContainerRef && config.viewContainerRef.injector;
  1052. return new portal.PortalInjector(userInjector || this._injector, new WeakMap([
  1053. [MatSnackBarRef, snackBarRef],
  1054. [MAT_SNACK_BAR_DATA, config.data]
  1055. ]));
  1056. };
  1057. MatSnackBar.decorators = [
  1058. { type: core.Injectable, args: [{ providedIn: MatSnackBarModule },] },
  1059. ];
  1060. /** @nocollapse */
  1061. MatSnackBar.ctorParameters = function () { return [
  1062. { type: overlay.Overlay },
  1063. { type: a11y.LiveAnnouncer },
  1064. { type: core.Injector },
  1065. { type: layout.BreakpointObserver },
  1066. { type: MatSnackBar, decorators: [{ type: core.Optional }, { type: core.SkipSelf }] },
  1067. { type: MatSnackBarConfig, decorators: [{ type: core.Inject, args: [MAT_SNACK_BAR_DEFAULT_OPTIONS,] }] }
  1068. ]; };
  1069. /** @nocollapse */ MatSnackBar.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function MatSnackBar_Factory() { return new MatSnackBar(core.ɵɵinject(overlay.Overlay), core.ɵɵinject(a11y.LiveAnnouncer), core.ɵɵinject(core.INJECTOR), core.ɵɵinject(layout.BreakpointObserver), core.ɵɵinject(MatSnackBar, 12), core.ɵɵinject(MAT_SNACK_BAR_DEFAULT_OPTIONS)); }, token: MatSnackBar, providedIn: MatSnackBarModule });
  1070. return MatSnackBar;
  1071. }());
  1072. exports.MatSnackBarModule = MatSnackBarModule;
  1073. exports.MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY = MAT_SNACK_BAR_DEFAULT_OPTIONS_FACTORY;
  1074. exports.MAT_SNACK_BAR_DEFAULT_OPTIONS = MAT_SNACK_BAR_DEFAULT_OPTIONS;
  1075. exports.MatSnackBar = MatSnackBar;
  1076. exports.MatSnackBarContainer = MatSnackBarContainer;
  1077. exports.MAT_SNACK_BAR_DATA = MAT_SNACK_BAR_DATA;
  1078. exports.MatSnackBarConfig = MatSnackBarConfig;
  1079. exports.MatSnackBarRef = MatSnackBarRef;
  1080. exports.SimpleSnackBar = SimpleSnackBar;
  1081. exports.matSnackBarAnimations = matSnackBarAnimations;
  1082. Object.defineProperty(exports, '__esModule', { value: true });
  1083. })));
  1084. //# sourceMappingURL=material-snack-bar.umd.js.map