blob: aec08b87f8eabe9227724c56dc9250e7e31b6186 [file] [log] [blame]
{"version":3,"file":"badge.js","sources":["../../../../../../src/material/badge/badge.ts","../../../../../../src/material/badge/badge-module.ts","../../../../../../src/material/badge/public-api.ts","../../../../../../src/material/badge/index.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {AriaDescriber} from '@angular/cdk/a11y';\nimport {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n Directive,\n ElementRef,\n Inject,\n Input,\n NgZone,\n OnChanges,\n OnDestroy,\n Optional,\n Renderer2,\n SimpleChanges,\n} from '@angular/core';\nimport {CanDisable, CanDisableCtor, mixinDisabled, ThemePalette} from '@angular/material/core';\nimport {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';\n\n\nlet nextId = 0;\n\n// Boilerplate for applying mixins to MatBadge.\n/** @docs-private */\nclass MatBadgeBase {}\n\nconst _MatBadgeMixinBase:\n CanDisableCtor & typeof MatBadgeBase = mixinDisabled(MatBadgeBase);\n\n/** Allowed position options for matBadgePosition */\nexport type MatBadgePosition =\n 'above after' | 'above before' | 'below before' | 'below after' |\n 'before' | 'after' | 'above' | 'below';\n\n/** Allowed size options for matBadgeSize */\nexport type MatBadgeSize = 'small' | 'medium' | 'large';\n\n/** Directive to display a text badge. */\n@Directive({\n selector: '[matBadge]',\n inputs: ['disabled: matBadgeDisabled'],\n host: {\n 'class': 'mat-badge',\n '[class.mat-badge-overlap]': 'overlap',\n '[class.mat-badge-above]': 'isAbove()',\n '[class.mat-badge-below]': '!isAbove()',\n '[class.mat-badge-before]': '!isAfter()',\n '[class.mat-badge-after]': 'isAfter()',\n '[class.mat-badge-small]': 'size === \"small\"',\n '[class.mat-badge-medium]': 'size === \"medium\"',\n '[class.mat-badge-large]': 'size === \"large\"',\n '[class.mat-badge-hidden]': 'hidden || !_hasContent',\n '[class.mat-badge-disabled]': 'disabled',\n },\n})\nexport class MatBadge extends _MatBadgeMixinBase implements OnDestroy, OnChanges, CanDisable {\n /** Whether the badge has any content. */\n _hasContent = false;\n\n /** The color of the badge. Can be `primary`, `accent`, or `warn`. */\n @Input('matBadgeColor')\n get color(): ThemePalette { return this._color; }\n set color(value: ThemePalette) {\n this._setColor(value);\n this._color = value;\n }\n private _color: ThemePalette = 'primary';\n\n /** Whether the badge should overlap its contents or not */\n @Input('matBadgeOverlap')\n get overlap(): boolean { return this._overlap; }\n set overlap(val: boolean) {\n this._overlap = coerceBooleanProperty(val);\n }\n private _overlap: boolean = true;\n\n /**\n * Position the badge should reside.\n * Accepts any combination of 'above'|'below' and 'before'|'after'\n */\n @Input('matBadgePosition') position: MatBadgePosition = 'above after';\n\n /** The content for the badge */\n @Input('matBadge') content: string | number | undefined | null;\n\n /** Message used to describe the decorated element via aria-describedby */\n @Input('matBadgeDescription')\n get description(): string { return this._description; }\n set description(newDescription: string) {\n if (newDescription !== this._description) {\n const badgeElement = this._badgeElement;\n this._updateHostAriaDescription(newDescription, this._description);\n this._description = newDescription;\n\n if (badgeElement) {\n newDescription ? badgeElement.setAttribute('aria-label', newDescription) :\n badgeElement.removeAttribute('aria-label');\n }\n }\n }\n private _description: string;\n\n /** Size of the badge. Can be 'small', 'medium', or 'large'. */\n @Input('matBadgeSize') size: MatBadgeSize = 'medium';\n\n /** Whether the badge is hidden. */\n @Input('matBadgeHidden')\n get hidden(): boolean { return this._hidden; }\n set hidden(val: boolean) {\n this._hidden = coerceBooleanProperty(val);\n }\n private _hidden: boolean;\n\n /** Unique id for the badge */\n _id: number = nextId++;\n\n private _badgeElement: HTMLElement | undefined;\n\n constructor(\n private _ngZone: NgZone,\n private _elementRef: ElementRef<HTMLElement>,\n private _ariaDescriber: AriaDescriber,\n private _renderer: Renderer2,\n @Optional() @Inject(ANIMATION_MODULE_TYPE) private _animationMode?: string) {\n super();\n\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n const nativeElement = _elementRef.nativeElement;\n if (nativeElement.nodeType !== nativeElement.ELEMENT_NODE) {\n throw Error('matBadge must be attached to an element node.');\n }\n }\n }\n\n /** Whether the badge is above the host or not */\n isAbove(): boolean {\n return this.position.indexOf('below') === -1;\n }\n\n /** Whether the badge is after the host or not */\n isAfter(): boolean {\n return this.position.indexOf('before') === -1;\n }\n\n ngOnChanges(changes: SimpleChanges) {\n const contentChange = changes['content'];\n\n if (contentChange) {\n const value = contentChange.currentValue;\n this._hasContent = value != null && `${value}`.trim().length > 0;\n this._updateTextContent();\n }\n }\n\n ngOnDestroy() {\n const badgeElement = this._badgeElement;\n\n if (badgeElement) {\n if (this.description) {\n this._ariaDescriber.removeDescription(badgeElement, this.description);\n }\n\n // When creating a badge through the Renderer, Angular will keep it in an index.\n // We have to destroy it ourselves, otherwise it'll be retained in memory.\n if (this._renderer.destroyNode) {\n this._renderer.destroyNode(badgeElement);\n }\n }\n }\n\n /**\n * Gets the element into which the badge's content is being rendered.\n * Undefined if the element hasn't been created (e.g. if the badge doesn't have content).\n */\n getBadgeElement(): HTMLElement | undefined {\n return this._badgeElement;\n }\n\n /** Injects a span element into the DOM with the content. */\n private _updateTextContent(): HTMLSpanElement {\n if (!this._badgeElement) {\n this._badgeElement = this._createBadgeElement();\n } else {\n this._badgeElement.textContent = this._stringifyContent();\n }\n return this._badgeElement;\n }\n\n /** Creates the badge element */\n private _createBadgeElement(): HTMLElement {\n const badgeElement = this._renderer.createElement('span');\n const activeClass = 'mat-badge-active';\n const contentClass = 'mat-badge-content';\n\n // Clear any existing badges which may have persisted from a server-side render.\n this._clearExistingBadges(contentClass);\n badgeElement.setAttribute('id', `mat-badge-content-${this._id}`);\n badgeElement.classList.add(contentClass);\n badgeElement.textContent = this._stringifyContent();\n\n if (this._animationMode === 'NoopAnimations') {\n badgeElement.classList.add('_mat-animation-noopable');\n }\n\n if (this.description) {\n badgeElement.setAttribute('aria-label', this.description);\n }\n\n this._elementRef.nativeElement.appendChild(badgeElement);\n\n // animate in after insertion\n if (typeof requestAnimationFrame === 'function' && this._animationMode !== 'NoopAnimations') {\n this._ngZone.runOutsideAngular(() => {\n requestAnimationFrame(() => {\n badgeElement.classList.add(activeClass);\n });\n });\n } else {\n badgeElement.classList.add(activeClass);\n }\n\n return badgeElement;\n }\n\n /** Sets the aria-label property on the element */\n private _updateHostAriaDescription(newDescription: string, oldDescription: string): void {\n // ensure content available before setting label\n const content = this._updateTextContent();\n\n if (oldDescription) {\n this._ariaDescriber.removeDescription(content, oldDescription);\n }\n\n if (newDescription) {\n this._ariaDescriber.describe(content, newDescription);\n }\n }\n\n /** Adds css theme class given the color to the component host */\n private _setColor(colorPalette: ThemePalette) {\n if (colorPalette !== this._color) {\n const classList = this._elementRef.nativeElement.classList;\n if (this._color) {\n classList.remove(`mat-badge-${this._color}`);\n }\n if (colorPalette) {\n classList.add(`mat-badge-${colorPalette}`);\n }\n }\n }\n\n /** Clears any existing badges that might be left over from server-side rendering. */\n private _clearExistingBadges(cssClass: string) {\n const element = this._elementRef.nativeElement;\n let childCount = element.children.length;\n\n // Use a reverse while, because we'll be removing elements from the list as we're iterating.\n while (childCount--) {\n const currentChild = element.children[childCount];\n\n if (currentChild.classList.contains(cssClass)) {\n element.removeChild(currentChild);\n }\n }\n }\n\n /** Gets the string representation of the badge content. */\n private _stringifyContent(): string {\n // Convert null and undefined to an empty string which is consistent\n // with how Angular handles them in inside template interpolations.\n const content = this.content;\n return content == null ? '' : `${content}`;\n }\n\n static ngAcceptInputType_disabled: BooleanInput;\n static ngAcceptInputType_hidden: BooleanInput;\n static ngAcceptInputType_overlap: BooleanInput;\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {NgModule} from '@angular/core';\nimport {MatCommonModule} from '@angular/material/core';\nimport {A11yModule} from '@angular/cdk/a11y';\nimport {MatBadge} from './badge';\n\n\n@NgModule({\n imports: [\n A11yModule,\n MatCommonModule\n ],\n exports: [MatBadge, MatCommonModule],\n declarations: [MatBadge],\n})\nexport class MatBadgeModule {}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nexport * from './badge-module';\nexport * from './badge';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAQA,AAkBA,IAAI,MAAM,GAAG,CAAC,CAAC;;;AAIf,MAAM,YAAY;CAAG;AAErB,MAAM,kBAAkB,GACmB,aAAa,CAAC,YAAY,CAAC,CAAC;;AA4BvE,MAAa,QAAS,SAAQ,kBAAkB;IA+D9C,YACY,OAAe,EACf,WAAoC,EACpC,cAA6B,EAC7B,SAAoB,EACuB,cAAuB;QAC1E,KAAK,EAAE,CAAC;QALA,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAyB;QACpC,mBAAc,GAAd,cAAc,CAAe;QAC7B,cAAS,GAAT,SAAS,CAAW;QACuB,mBAAc,GAAd,cAAc,CAAS;;QAlE9E,gBAAW,GAAG,KAAK,CAAC;QASZ,WAAM,GAAiB,SAAS,CAAC;QAQjC,aAAQ,GAAY,IAAI,CAAC;;;;;QAMN,aAAQ,GAAqB,aAAa,CAAC;;QAuB/C,SAAI,GAAiB,QAAQ,CAAC;;QAWrD,QAAG,GAAW,MAAM,EAAE,CAAC;QAYnB,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,EAAE;YACjD,MAAM,aAAa,GAAG,WAAW,CAAC,aAAa,CAAC;YAChD,IAAI,aAAa,CAAC,QAAQ,KAAK,aAAa,CAAC,YAAY,EAAE;gBACzD,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAC;aAC9D;SACF;KACF;;IAxEH,IACI,KAAK,KAAmB,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE;IACjD,IAAI,KAAK,CAA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