toolbar.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. import { Platform } from '@angular/cdk/platform';
  9. import { DOCUMENT } from '@angular/common';
  10. import { ChangeDetectionStrategy, Component, ContentChildren, Directive, ElementRef, Inject, isDevMode, ViewEncapsulation, NgModule } from '@angular/core';
  11. import { mixinColor, MatCommonModule } from '@angular/material/core';
  12. /**
  13. * @fileoverview added by tsickle
  14. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  15. */
  16. // Boilerplate for applying mixins to MatToolbar.
  17. /**
  18. * \@docs-private
  19. */
  20. class MatToolbarBase {
  21. /**
  22. * @param {?} _elementRef
  23. */
  24. constructor(_elementRef) {
  25. this._elementRef = _elementRef;
  26. }
  27. }
  28. /** @type {?} */
  29. const _MatToolbarMixinBase = mixinColor(MatToolbarBase);
  30. class MatToolbarRow {
  31. }
  32. MatToolbarRow.decorators = [
  33. { type: Directive, args: [{
  34. selector: 'mat-toolbar-row',
  35. exportAs: 'matToolbarRow',
  36. host: { 'class': 'mat-toolbar-row' },
  37. },] },
  38. ];
  39. class MatToolbar extends _MatToolbarMixinBase {
  40. /**
  41. * @param {?} elementRef
  42. * @param {?} _platform
  43. * @param {?=} document
  44. */
  45. constructor(elementRef, _platform, document) {
  46. super(elementRef);
  47. this._platform = _platform;
  48. // TODO: make the document a required param when doing breaking changes.
  49. this._document = document;
  50. }
  51. /**
  52. * @return {?}
  53. */
  54. ngAfterViewInit() {
  55. if (!isDevMode() || !this._platform.isBrowser) {
  56. return;
  57. }
  58. this._checkToolbarMixedModes();
  59. this._toolbarRows.changes.subscribe((/**
  60. * @return {?}
  61. */
  62. () => this._checkToolbarMixedModes()));
  63. }
  64. /**
  65. * Throws an exception when developers are attempting to combine the different toolbar row modes.
  66. * @private
  67. * @return {?}
  68. */
  69. _checkToolbarMixedModes() {
  70. if (!this._toolbarRows.length) {
  71. return;
  72. }
  73. // Check if there are any other DOM nodes that can display content but aren't inside of
  74. // a <mat-toolbar-row> element.
  75. /** @type {?} */
  76. const isCombinedUsage = Array.from(this._elementRef.nativeElement.childNodes)
  77. .filter((/**
  78. * @param {?} node
  79. * @return {?}
  80. */
  81. node => !(node.classList && node.classList.contains('mat-toolbar-row'))))
  82. .filter((/**
  83. * @param {?} node
  84. * @return {?}
  85. */
  86. node => node.nodeType !== (this._document ? this._document.COMMENT_NODE : 8)))
  87. .some((/**
  88. * @param {?} node
  89. * @return {?}
  90. */
  91. node => !!(node.textContent && node.textContent.trim())));
  92. if (isCombinedUsage) {
  93. throwToolbarMixedModesError();
  94. }
  95. }
  96. }
  97. MatToolbar.decorators = [
  98. { type: Component, args: [{selector: 'mat-toolbar',
  99. exportAs: 'matToolbar',
  100. template: "<ng-content></ng-content><ng-content select=\"mat-toolbar-row\"></ng-content>",
  101. styles: ["@media (-ms-high-contrast:active){.mat-toolbar{outline:solid 1px}}.mat-toolbar-row,.mat-toolbar-single-row{display:flex;box-sizing:border-box;padding:0 16px;width:100%;flex-direction:row;align-items:center;white-space:nowrap}.mat-toolbar-multiple-rows{display:flex;box-sizing:border-box;flex-direction:column;width:100%}.mat-toolbar-multiple-rows{min-height:64px}.mat-toolbar-row,.mat-toolbar-single-row{height:64px}@media (max-width:599px){.mat-toolbar-multiple-rows{min-height:56px}.mat-toolbar-row,.mat-toolbar-single-row{height:56px}}"],
  102. inputs: ['color'],
  103. host: {
  104. 'class': 'mat-toolbar',
  105. '[class.mat-toolbar-multiple-rows]': '_toolbarRows.length > 0',
  106. '[class.mat-toolbar-single-row]': '_toolbarRows.length === 0',
  107. },
  108. changeDetection: ChangeDetectionStrategy.OnPush,
  109. encapsulation: ViewEncapsulation.None,
  110. },] },
  111. ];
  112. /** @nocollapse */
  113. MatToolbar.ctorParameters = () => [
  114. { type: ElementRef },
  115. { type: Platform },
  116. { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
  117. ];
  118. MatToolbar.propDecorators = {
  119. _toolbarRows: [{ type: ContentChildren, args: [MatToolbarRow,] }]
  120. };
  121. /**
  122. * Throws an exception when attempting to combine the different toolbar row modes.
  123. * \@docs-private
  124. * @return {?}
  125. */
  126. function throwToolbarMixedModesError() {
  127. throw Error('MatToolbar: Attempting to combine different toolbar modes. ' +
  128. 'Either specify multiple `<mat-toolbar-row>` elements explicitly or just place content ' +
  129. 'inside of a `<mat-toolbar>` for a single row.');
  130. }
  131. /**
  132. * @fileoverview added by tsickle
  133. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  134. */
  135. class MatToolbarModule {
  136. }
  137. MatToolbarModule.decorators = [
  138. { type: NgModule, args: [{
  139. imports: [MatCommonModule],
  140. exports: [MatToolbar, MatToolbarRow, MatCommonModule],
  141. declarations: [MatToolbar, MatToolbarRow],
  142. },] },
  143. ];
  144. /**
  145. * @fileoverview added by tsickle
  146. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  147. */
  148. /**
  149. * @fileoverview added by tsickle
  150. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  151. */
  152. export { MatToolbarModule, throwToolbarMixedModesError, MatToolbarRow, MatToolbar };
  153. //# sourceMappingURL=toolbar.js.map