@angular/material
Version:
Angular Material
314 lines (308 loc) • 10.7 kB
JavaScript
/**
* @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/common'), require('@angular/core'), require('@angular/material/core')) :
typeof define === 'function' && define.amd ? define('@angular/material/badge', ['exports', '@angular/cdk/a11y', '@angular/cdk/coercion', '@angular/common', '@angular/core', '@angular/material/core'], 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.common,global.ng.core,global.ng.material.core));
}(this, (function (exports,a11y,coercion,common,core,core$1) { 'use strict';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var /** @type {?} */ nextId = 0;
/**
* Directive to display a text badge.
*/
var MatBadge = /** @class */ (function () {
function MatBadge(_document, _ngZone, _elementRef, _ariaDescriber) {
this._document = _document;
this._ngZone = _ngZone;
this._elementRef = _elementRef;
this._ariaDescriber = _ariaDescriber;
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++;
}
Object.defineProperty(MatBadge.prototype, "color", {
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", {
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, "content", {
get: /**
* The content for the badge
* @return {?}
*/
function () { return this._content; },
set: /**
* @param {?} val
* @return {?}
*/
function (val) {
this._content = val;
this._updateTextContent();
},
enumerable: true,
configurable: true
});
Object.defineProperty(MatBadge.prototype, "description", {
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) {
this._updateHostAriaDescription(newDescription, this._description);
this._description = newDescription;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(MatBadge.prototype, "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;
};
/**
* @return {?}
*/
MatBadge.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.description && this._badgeElement) {
this._ariaDescriber.removeDescription(this._badgeElement, this.description);
}
};
/**
* Injects a span element into the DOM with the content.
* @return {?}
*/
MatBadge.prototype._updateTextContent = /**
* Injects a span element into the DOM with the content.
* @return {?}
*/
function () {
if (!this._badgeElement) {
this._badgeElement = this._createBadgeElement();
}
else {
this._badgeElement.textContent = this.content;
}
return this._badgeElement;
};
/**
* Creates the badge element
* @return {?}
*/
MatBadge.prototype._createBadgeElement = /**
* Creates the badge element
* @return {?}
*/
function () {
var /** @type {?} */ badgeElement = this._document.createElement('span');
var /** @type {?} */ activeClass = 'mat-badge-active';
badgeElement.setAttribute('id', "mat-badge-content-" + this._id);
badgeElement.classList.add('mat-badge-content');
badgeElement.textContent = this.content;
if (this.description) {
badgeElement.setAttribute('aria-label', this.description);
}
this._elementRef.nativeElement.appendChild(badgeElement);
// animate in after insertion
if (typeof requestAnimationFrame === 'function') {
this._ngZone.runOutsideAngular(function () {
requestAnimationFrame(function () {
badgeElement.classList.add(activeClass);
});
});
}
else {
badgeElement.classList.add(activeClass);
}
return badgeElement;
};
/**
* Sets the aria-label property on the element
* @param {?} newDescription
* @param {?} oldDescription
* @return {?}
*/
MatBadge.prototype._updateHostAriaDescription = /**
* Sets the aria-label property on the element
* @param {?} newDescription
* @param {?} oldDescription
* @return {?}
*/
function (newDescription, oldDescription) {
// ensure content available before setting label
var /** @type {?} */ 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
* @param {?} colorPalette
* @return {?}
*/
MatBadge.prototype._setColor = /**
* Adds css theme class given the color to the component host
* @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);
}
}
};
MatBadge.decorators = [
{ type: core.Directive, args: [{
selector: '[matBadge]',
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',
},
},] },
];
/** @nocollapse */
MatBadge.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [common.DOCUMENT,] },] },
{ type: core.NgZone, },
{ type: core.ElementRef, },
{ type: a11y.AriaDescriber, },
]; };
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;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var MatBadgeModule = /** @class */ (function () {
function MatBadgeModule() {
}
MatBadgeModule.decorators = [
{ type: core.NgModule, args: [{
imports: [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