| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- /**
- * @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
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/a11y'), require('@angular/cdk/coercion'), require('@angular/core'), require('@angular/material/core'), require('@angular/platform-browser/animations')) :
- typeof define === 'function' && define.amd ? define('@angular/material/badge', ['exports', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/core', '@angular/material/core', '@angular/platform-browser/animations'], factory) :
- (factory((global.ng = global.ng || {}, global.ng.material = global.ng.material || {}, global.ng.material.badge = {}),global.ng.cdk.a11y,global.ng.cdk.coercion,global.ng.core,global.ng.material.core,global.ng.platformBrowser.animations));
- }(this, (function (exports,a11y,coercion,core,core$1,animations) { 'use strict';
- /*! *****************************************************************************
- Copyright (c) Microsoft Corporation. All rights reserved.
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
- this file except in compliance with the License. You may obtain a copy of the
- License at http://www.apache.org/licenses/LICENSE-2.0
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
- MERCHANTABLITY OR NON-INFRINGEMENT.
- See the Apache Version 2.0 License for specific language governing permissions
- and limitations under the License.
- ***************************************************************************** */
- /* global Reflect, Promise */
- var extendStatics = function(d, b) {
- extendStatics = Object.setPrototypeOf ||
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
- return extendStatics(d, b);
- };
- function __extends(d, b) {
- extendStatics(d, b);
- function __() { this.constructor = d; }
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
- }
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- /** @type {?} */
- var nextId = 0;
- // Boilerplate for applying mixins to MatBadge.
- /**
- * \@docs-private
- */
- var
- // Boilerplate for applying mixins to MatBadge.
- /**
- * \@docs-private
- */
- MatBadgeBase = /** @class */ (function () {
- function MatBadgeBase() {
- }
- return MatBadgeBase;
- }());
- /** @type {?} */
- var _MatBadgeMixinBase = core$1.mixinDisabled(MatBadgeBase);
- /**
- * Directive to display a text badge.
- */
- var MatBadge = /** @class */ (function (_super) {
- __extends(MatBadge, _super);
- function MatBadge(_ngZone, _elementRef, _ariaDescriber, _renderer, _animationMode) {
- var _this = _super.call(this) || this;
- _this._ngZone = _ngZone;
- _this._elementRef = _elementRef;
- _this._ariaDescriber = _ariaDescriber;
- _this._renderer = _renderer;
- _this._animationMode = _animationMode;
- /**
- * Whether the badge has any content.
- */
- _this._hasContent = false;
- _this._color = 'primary';
- _this._overlap = true;
- /**
- * Position the badge should reside.
- * Accepts any combination of 'above'|'below' and 'before'|'after'
- */
- _this.position = 'above after';
- /**
- * Size of the badge. Can be 'small', 'medium', or 'large'.
- */
- _this.size = 'medium';
- /**
- * Unique id for the badge
- */
- _this._id = nextId++;
- if (core.isDevMode()) {
- /** @type {?} */
- var nativeElement = _elementRef.nativeElement;
- if (nativeElement.nodeType !== nativeElement.ELEMENT_NODE) {
- throw Error('matBadge must be attached to an element node.');
- }
- }
- return _this;
- }
- Object.defineProperty(MatBadge.prototype, "color", {
- /** The color of the badge. Can be `primary`, `accent`, or `warn`. */
- get: /**
- * The color of the badge. Can be `primary`, `accent`, or `warn`.
- * @return {?}
- */
- function () { return this._color; },
- set: /**
- * @param {?} value
- * @return {?}
- */
- function (value) {
- this._setColor(value);
- this._color = value;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(MatBadge.prototype, "overlap", {
- /** Whether the badge should overlap its contents or not */
- get: /**
- * Whether the badge should overlap its contents or not
- * @return {?}
- */
- function () { return this._overlap; },
- set: /**
- * @param {?} val
- * @return {?}
- */
- function (val) {
- this._overlap = coercion.coerceBooleanProperty(val);
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(MatBadge.prototype, "description", {
- /** Message used to describe the decorated element via aria-describedby */
- get: /**
- * Message used to describe the decorated element via aria-describedby
- * @return {?}
- */
- function () { return this._description; },
- set: /**
- * @param {?} newDescription
- * @return {?}
- */
- function (newDescription) {
- if (newDescription !== this._description) {
- /** @type {?} */
- var badgeElement = this._badgeElement;
- this._updateHostAriaDescription(newDescription, this._description);
- this._description = newDescription;
- if (badgeElement) {
- newDescription ? badgeElement.setAttribute('aria-label', newDescription) :
- badgeElement.removeAttribute('aria-label');
- }
- }
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(MatBadge.prototype, "hidden", {
- /** Whether the badge is hidden. */
- get: /**
- * Whether the badge is hidden.
- * @return {?}
- */
- function () { return this._hidden; },
- set: /**
- * @param {?} val
- * @return {?}
- */
- function (val) {
- this._hidden = coercion.coerceBooleanProperty(val);
- },
- enumerable: true,
- configurable: true
- });
- /** Whether the badge is above the host or not */
- /**
- * Whether the badge is above the host or not
- * @return {?}
- */
- MatBadge.prototype.isAbove = /**
- * Whether the badge is above the host or not
- * @return {?}
- */
- function () {
- return this.position.indexOf('below') === -1;
- };
- /** Whether the badge is after the host or not */
- /**
- * Whether the badge is after the host or not
- * @return {?}
- */
- MatBadge.prototype.isAfter = /**
- * Whether the badge is after the host or not
- * @return {?}
- */
- function () {
- return this.position.indexOf('before') === -1;
- };
- /**
- * @param {?} changes
- * @return {?}
- */
- MatBadge.prototype.ngOnChanges = /**
- * @param {?} changes
- * @return {?}
- */
- function (changes) {
- /** @type {?} */
- var contentChange = changes['content'];
- if (contentChange) {
- /** @type {?} */
- var value = contentChange.currentValue;
- this._hasContent = value != null && ("" + value).trim().length > 0;
- this._updateTextContent();
- }
- };
- /**
- * @return {?}
- */
- MatBadge.prototype.ngOnDestroy = /**
- * @return {?}
- */
- function () {
- /** @type {?} */
- var badgeElement = this._badgeElement;
- if (badgeElement) {
- if (this.description) {
- this._ariaDescriber.removeDescription(badgeElement, this.description);
- }
- // When creating a badge through the Renderer, Angular will keep it in an index.
- // We have to destroy it ourselves, otherwise it'll be retained in memory.
- if (this._renderer.destroyNode) {
- this._renderer.destroyNode(badgeElement);
- }
- }
- };
- /**
- * Gets the element into which the badge's content is being rendered.
- * Undefined if the element hasn't been created (e.g. if the badge doesn't have content).
- */
- /**
- * Gets the element into which the badge's content is being rendered.
- * Undefined if the element hasn't been created (e.g. if the badge doesn't have content).
- * @return {?}
- */
- MatBadge.prototype.getBadgeElement = /**
- * Gets the element into which the badge's content is being rendered.
- * Undefined if the element hasn't been created (e.g. if the badge doesn't have content).
- * @return {?}
- */
- function () {
- return this._badgeElement;
- };
- /** Injects a span element into the DOM with the content. */
- /**
- * Injects a span element into the DOM with the content.
- * @private
- * @return {?}
- */
- MatBadge.prototype._updateTextContent = /**
- * Injects a span element into the DOM with the content.
- * @private
- * @return {?}
- */
- function () {
- if (!this._badgeElement) {
- this._badgeElement = this._createBadgeElement();
- }
- else {
- this._badgeElement.textContent = this.content;
- }
- return this._badgeElement;
- };
- /** Creates the badge element */
- /**
- * Creates the badge element
- * @private
- * @return {?}
- */
- MatBadge.prototype._createBadgeElement = /**
- * Creates the badge element
- * @private
- * @return {?}
- */
- function () {
- /** @type {?} */
- var badgeElement = this._renderer.createElement('span');
- /** @type {?} */
- var activeClass = 'mat-badge-active';
- /** @type {?} */
- var contentClass = 'mat-badge-content';
- // Clear any existing badges which may have persisted from a server-side render.
- this._clearExistingBadges(contentClass);
- badgeElement.setAttribute('id', "mat-badge-content-" + this._id);
- badgeElement.classList.add(contentClass);
- badgeElement.textContent = this.content;
- if (this._animationMode === 'NoopAnimations') {
- badgeElement.classList.add('_mat-animation-noopable');
- }
- if (this.description) {
- badgeElement.setAttribute('aria-label', this.description);
- }
- this._elementRef.nativeElement.appendChild(badgeElement);
- // animate in after insertion
- if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {
- this._ngZone.runOutsideAngular((/**
- * @return {?}
- */
- function () {
- requestAnimationFrame((/**
- * @return {?}
- */
- function () {
- badgeElement.classList.add(activeClass);
- }));
- }));
- }
- else {
- badgeElement.classList.add(activeClass);
- }
- return badgeElement;
- };
- /** Sets the aria-label property on the element */
- /**
- * Sets the aria-label property on the element
- * @private
- * @param {?} newDescription
- * @param {?} oldDescription
- * @return {?}
- */
- MatBadge.prototype._updateHostAriaDescription = /**
- * Sets the aria-label property on the element
- * @private
- * @param {?} newDescription
- * @param {?} oldDescription
- * @return {?}
- */
- function (newDescription, oldDescription) {
- // ensure content available before setting label
- /** @type {?} */
- var content = this._updateTextContent();
- if (oldDescription) {
- this._ariaDescriber.removeDescription(content, oldDescription);
- }
- if (newDescription) {
- this._ariaDescriber.describe(content, newDescription);
- }
- };
- /** Adds css theme class given the color to the component host */
- /**
- * Adds css theme class given the color to the component host
- * @private
- * @param {?} colorPalette
- * @return {?}
- */
- MatBadge.prototype._setColor = /**
- * Adds css theme class given the color to the component host
- * @private
- * @param {?} colorPalette
- * @return {?}
- */
- function (colorPalette) {
- if (colorPalette !== this._color) {
- if (this._color) {
- this._elementRef.nativeElement.classList.remove("mat-badge-" + this._color);
- }
- if (colorPalette) {
- this._elementRef.nativeElement.classList.add("mat-badge-" + colorPalette);
- }
- }
- };
- /** Clears any existing badges that might be left over from server-side rendering. */
- /**
- * Clears any existing badges that might be left over from server-side rendering.
- * @private
- * @param {?} cssClass
- * @return {?}
- */
- MatBadge.prototype._clearExistingBadges = /**
- * Clears any existing badges that might be left over from server-side rendering.
- * @private
- * @param {?} cssClass
- * @return {?}
- */
- function (cssClass) {
- /** @type {?} */
- var element = this._elementRef.nativeElement;
- /** @type {?} */
- var childCount = element.children.length;
- // Use a reverse while, because we'll be removing elements from the list as we're iterating.
- while (childCount--) {
- /** @type {?} */
- var currentChild = element.children[childCount];
- if (currentChild.classList.contains(cssClass)) {
- element.removeChild(currentChild);
- }
- }
- };
- MatBadge.decorators = [
- { type: core.Directive, args: [{
- selector: '[matBadge]',
- inputs: ['disabled: matBadgeDisabled'],
- host: {
- 'class': 'mat-badge',
- '[class.mat-badge-overlap]': 'overlap',
- '[class.mat-badge-above]': 'isAbove()',
- '[class.mat-badge-below]': '!isAbove()',
- '[class.mat-badge-before]': '!isAfter()',
- '[class.mat-badge-after]': 'isAfter()',
- '[class.mat-badge-small]': 'size === "small"',
- '[class.mat-badge-medium]': 'size === "medium"',
- '[class.mat-badge-large]': 'size === "large"',
- '[class.mat-badge-hidden]': 'hidden || !_hasContent',
- '[class.mat-badge-disabled]': 'disabled',
- },
- },] },
- ];
- /** @nocollapse */
- MatBadge.ctorParameters = function () { return [
- { type: core.NgZone },
- { type: core.ElementRef },
- { type: a11y.AriaDescriber },
- { type: core.Renderer2 },
- { type: String, decorators: [{ type: core.Optional }, { type: core.Inject, args: [animations.ANIMATION_MODULE_TYPE,] }] }
- ]; };
- MatBadge.propDecorators = {
- color: [{ type: core.Input, args: ['matBadgeColor',] }],
- overlap: [{ type: core.Input, args: ['matBadgeOverlap',] }],
- position: [{ type: core.Input, args: ['matBadgePosition',] }],
- content: [{ type: core.Input, args: ['matBadge',] }],
- description: [{ type: core.Input, args: ['matBadgeDescription',] }],
- size: [{ type: core.Input, args: ['matBadgeSize',] }],
- hidden: [{ type: core.Input, args: ['matBadgeHidden',] }]
- };
- return MatBadge;
- }(_MatBadgeMixinBase));
- /**
- * @fileoverview added by tsickle
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
- */
- var MatBadgeModule = /** @class */ (function () {
- function MatBadgeModule() {
- }
- MatBadgeModule.decorators = [
- { type: core.NgModule, args: [{
- imports: [
- a11y.A11yModule,
- core$1.MatCommonModule
- ],
- exports: [MatBadge],
- declarations: [MatBadge],
- },] },
- ];
- return MatBadgeModule;
- }());
- exports.MatBadgeModule = MatBadgeModule;
- exports.MatBadge = MatBadge;
- Object.defineProperty(exports, '__esModule', { value: true });
- })));
- //# sourceMappingURL=material-badge.umd.js.map
|