blob: 683c469ee2de0528054d9841806405ec93e37967 [file] [log] [blame]
{"version":3,"file":"covalent-core-message.js","sources":["../../../../src/platform/core/message/message.component.ts","../../../../src/platform/core/message/message.module.ts"],"sourcesContent":["import {\n Component,\n Directive,\n Input,\n Renderer2,\n ElementRef,\n AfterViewInit,\n ViewContainerRef,\n TemplateRef,\n ViewChild,\n HostBinding,\n HostListener,\n ChangeDetectorRef,\n} from '@angular/core';\n\nimport { tdCollapseAnimation } from '@covalent/core/common';\n\n@Directive({\n selector: '[tdMessageContainer]',\n})\nexport class TdMessageContainerDirective {\n constructor(public viewContainer: ViewContainerRef) {}\n}\n\n@Component({\n selector: 'td-message',\n templateUrl: './message.component.html',\n styleUrls: ['./message.component.scss'],\n animations: [tdCollapseAnimation],\n})\nexport class TdMessageComponent implements AfterViewInit {\n private _color: string;\n private _opened: boolean = true;\n private _hidden: boolean = false;\n private _animating: boolean = false;\n private _initialized: boolean = false;\n\n @ViewChild(TdMessageContainerDirective, { static: true }) _childElement: TdMessageContainerDirective;\n @ViewChild(TemplateRef) _template: TemplateRef<any>;\n\n /**\n * Binding host to tdCollapse animation\n */\n @HostBinding('@tdCollapse')\n get collapsedAnimation(): any {\n return { value: !this._opened, duration: 100 };\n }\n\n /**\n * Binding host to display style when hidden\n */\n @HostBinding('style.display')\n get hidden(): string {\n return this._hidden ? 'none' : undefined;\n }\n\n /**\n * label: string\n *\n * Sets the label of the message.\n */\n @Input() label: string;\n\n /**\n * sublabel?: string\n *\n * Sets the sublabel of the message.\n */\n @Input() sublabel: string;\n\n /**\n * icon?: string\n *\n * The icon to be displayed before the title.\n * Defaults to `info_outline` icon\n */\n @Input() icon: string = 'info_outline';\n\n /**\n * color?: primary | accent | warn\n *\n * Sets the color of the message.\n * Can also use any material color: purple | light-blue, etc.\n */\n @Input('color')\n set color(color: string) {\n this._renderer.removeClass(this._elementRef.nativeElement, 'mat-' + this._color);\n this._renderer.removeClass(this._elementRef.nativeElement, 'bgc-' + this._color + '-100');\n this._renderer.removeClass(this._elementRef.nativeElement, 'tc-' + this._color + '-700');\n if (color === 'primary' || color === 'accent' || color === 'warn') {\n this._renderer.addClass(this._elementRef.nativeElement, 'mat-' + color);\n } else {\n this._renderer.addClass(this._elementRef.nativeElement, 'bgc-' + color + '-100');\n this._renderer.addClass(this._elementRef.nativeElement, 'tc-' + color + '-700');\n }\n this._color = color;\n this._changeDetectorRef.markForCheck();\n }\n get color(): string {\n return this._color;\n }\n\n /**\n * opened?: boolean\n *\n * Shows or hiddes the message depending on its value.\n * Defaults to 'true'.\n */\n @Input('opened')\n set opened(opened: boolean) {\n if (this._initialized) {\n if (opened) {\n this.open();\n } else {\n this.close();\n }\n } else {\n this._opened = opened;\n }\n }\n get opened(): boolean {\n return this._opened;\n }\n\n constructor(\n private _renderer: Renderer2,\n private _changeDetectorRef: ChangeDetectorRef,\n private _elementRef: ElementRef,\n ) {\n this._renderer.addClass(this._elementRef.nativeElement, 'td-message');\n }\n\n /**\n * Detach element when close animation is finished to set animating state to false\n * hidden state to true and detach element from DOM\n */\n @HostListener('@tdCollapse.done')\n animationDoneListener(): void {\n if (!this._opened) {\n this._hidden = true;\n this._detach();\n }\n this._animating = false;\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * Initializes the component and attaches the content.\n */\n ngAfterViewInit(): void {\n Promise.resolve(undefined).then(() => {\n if (this._opened) {\n this._attach();\n }\n this._initialized = true;\n });\n }\n\n /**\n * Renders the message on screen\n * Validates if there is an animation currently and if its already opened\n */\n open(): void {\n if (!this._opened && !this._animating) {\n this._opened = true;\n this._attach();\n this._startAnimationState();\n }\n }\n\n /**\n * Removes the message content from screen.\n * Validates if there is an animation currently and if its already closed\n */\n close(): void {\n if (this._opened && !this._animating) {\n this._opened = false;\n this._startAnimationState();\n }\n }\n\n /**\n * Toggles between open and close depending on state.\n */\n toggle(): void {\n if (this._opened) {\n this.close();\n } else {\n this.open();\n }\n }\n\n /**\n * Method to set the state before starting an animation\n */\n private _startAnimationState(): void {\n this._animating = true;\n this._hidden = false;\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * Method to attach template to DOM\n */\n private _attach(): void {\n this._childElement.viewContainer.createEmbeddedView(this._template);\n this._changeDetectorRef.markForCheck();\n }\n\n /**\n * Method to detach template from DOM\n */\n private _detach(): void {\n this._childElement.viewContainer.clear();\n this._changeDetectorRef.markForCheck();\n }\n}\n","import { Type } from '@angular/core';\nimport { NgModule } from '@angular/core';\n\nimport { CommonModule } from '@angular/common';\nimport { MatIconModule } from '@angular/material/icon';\n\nimport { TdMessageComponent, TdMessageContainerDirective } from './message.component';\n\nconst TD_MESSAGE: Type<any>[] = [TdMessageComponent, TdMessageContainerDirective];\n\n@NgModule({\n imports: [CommonModule, MatIconModule],\n declarations: [TD_MESSAGE],\n exports: [TD_MESSAGE],\n})\nexport class CovalentMessageModule {}\n"],"names":[],"mappings":";;;;;;;;;;MAoBa,2BAA2B;;;;IACtC,YAAmB,aAA+B;QAA/B,kBAAa,GAAb,aAAa,CAAkB;KAAI;;;YAJvD,SAAS,SAAC;gBACT,QAAQ,EAAE,sBAAsB;aACjC;;;;YAZC,gBAAgB;;;;IAcJ,oDAAsC;;MASvC,kBAAkB;;;;;;IA8F7B,YACU,SAAoB,EACpB,kBAAqC,EACrC,WAAuB;QAFvB,cAAS,GAAT,SAAS,CAAW;QACpB,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,gBAAW,GAAX,WAAW,CAAY;QA/FzB,YAAO,GAAY,IAAI,CAAC;QACxB,YAAO,GAAY,KAAK,CAAC;QACzB,eAAU,GAAY,KAAK,CAAC;QAC5B,iBAAY,GAAY,KAAK,CAAC;;;;;;;QAyC7B,SAAI,GAAW,cAAc,CAAC;QAqDrC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;KACvE;;;;;IAvFD,IACI,kBAAkB;QACpB,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,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