UNPKG

13.2 kBJavaScriptView Raw
1import * as i0 from '@angular/core';
2import { Directive, TemplateRef, Component, ViewChild, HostBinding, Input, HostListener, NgModule } from '@angular/core';
3import * as i1 from '@angular/common';
4import { CommonModule } from '@angular/common';
5import * as i2 from '@angular/material/icon';
6import { MatIconModule } from '@angular/material/icon';
7import { trigger, state, style, AUTO_STYLE, transition, group, query, animateChild, animate } from '@angular/animations';
8
9/**
10 * const tdCollapseAnimation
11 *
12 * Parameter Options:
13 * * duration: Duration the animation will run in milliseconds. Defaults to 150 ms.
14 * * delay: Delay before the animation will run in milliseconds. Defaults to 0 ms.
15 * * easeOnClose: Animation accelerates and decelerates when closing. Defaults to ease-in.
16 * * easeOnOpen: Animation accelerates and decelerates when opening. Defaults to ease-out.
17 *
18 * Returns an [AnimationTriggerMetadata] object with boolean states for a collapse/expand animation.
19 *
20 * usage: [@tdCollapse]="{ value: true | false, params: { duration: 500 }}"
21 */
22const tdCollapseAnimation = trigger('tdCollapse', [
23 state('1', style({
24 height: '0',
25 overflow: 'hidden',
26 })),
27 state('0', style({
28 height: AUTO_STYLE,
29 overflow: AUTO_STYLE,
30 })),
31 transition('0 => 1', [
32 style({
33 overflow: 'hidden',
34 height: AUTO_STYLE,
35 }),
36 group([
37 query('@*', animateChild(), { optional: true }),
38 animate('{{ duration }}ms {{ delay }}ms {{ ease }}', style({
39 height: '0',
40 overflow: 'hidden',
41 })),
42 ]),
43 ], { params: { duration: 150, delay: '0', ease: 'ease-in' } }),
44 transition('1 => 0', [
45 style({
46 height: '0',
47 overflow: 'hidden',
48 }),
49 group([
50 query('@*', animateChild(), { optional: true }),
51 animate('{{ duration }}ms {{ delay }}ms {{ ease }}', style({
52 overflow: 'hidden',
53 height: AUTO_STYLE,
54 })),
55 ]),
56 ], { params: { duration: 150, delay: '0', ease: 'ease-out' } }),
57]);
58
59class TdMessageContainerDirective {
60 viewContainer;
61 constructor(viewContainer) {
62 this.viewContainer = viewContainer;
63 }
64 static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdMessageContainerDirective, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
65 static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.2", type: TdMessageContainerDirective, selector: "[tdMessageContainer]", ngImport: i0 });
66}
67i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdMessageContainerDirective, decorators: [{
68 type: Directive,
69 args: [{
70 selector: '[tdMessageContainer]',
71 }]
72 }], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
73class TdMessageComponent {
74 _renderer;
75 _changeDetectorRef;
76 _elementRef;
77 _color;
78 _opened = true;
79 _hidden = false;
80 _animating = false;
81 _initialized = false;
82 _childElement;
83 _template;
84 /**
85 * Binding host to tdCollapse animation
86 */
87 get collapsedAnimation() {
88 return { value: !this._opened, duration: 100 };
89 }
90 /**
91 * Binding host to display style when hidden
92 */
93 get hidden() {
94 return this._hidden ? 'none' : '';
95 }
96 /**
97 * label: string
98 *
99 * Sets the label of the message.
100 */
101 label;
102 /**
103 * sublabel?: string
104 *
105 * Sets the sublabel of the message.
106 */
107 sublabel;
108 /**
109 * icon?: string
110 *
111 * The icon to be displayed before the title.
112 * Defaults to `info_outline` icon
113 */
114 icon = 'info_outline';
115 /**
116 * color?: primary | accent | warn
117 *
118 * Sets the color of the message.
119 * Can also use any material color: purple | light-blue, etc.
120 */
121 set color(color) {
122 this._renderer.removeClass(this._elementRef.nativeElement, 'mat-' + this._color);
123 this._renderer.removeClass(this._elementRef.nativeElement, 'bgc-' + this._color + '-100');
124 this._renderer.removeClass(this._elementRef.nativeElement, 'tc-' + this._color + '-700');
125 if (color === 'primary' || color === 'accent' || color === 'warn') {
126 this._renderer.addClass(this._elementRef.nativeElement, 'mat-' + color);
127 }
128 else {
129 this._renderer.addClass(this._elementRef.nativeElement, 'bgc-' + color + '-100');
130 this._renderer.addClass(this._elementRef.nativeElement, 'tc-' + color + '-700');
131 }
132 this._color = color;
133 this._changeDetectorRef.markForCheck();
134 }
135 get color() {
136 return this._color;
137 }
138 /**
139 * opened?: boolean
140 *
141 * Shows or hiddes the message depending on its value.
142 * Defaults to 'true'.
143 */
144 set opened(opened) {
145 if (this._initialized) {
146 if (opened) {
147 this.open();
148 }
149 else {
150 this.close();
151 }
152 }
153 else {
154 this._opened = opened;
155 }
156 }
157 get opened() {
158 return this._opened;
159 }
160 constructor(_renderer, _changeDetectorRef, _elementRef) {
161 this._renderer = _renderer;
162 this._changeDetectorRef = _changeDetectorRef;
163 this._elementRef = _elementRef;
164 this._renderer.addClass(this._elementRef.nativeElement, 'td-message');
165 }
166 /**
167 * Detach element when close animation is finished to set animating state to false
168 * hidden state to true and detach element from DOM
169 */
170 animationDoneListener() {
171 if (!this._opened) {
172 this._hidden = true;
173 this._detach();
174 }
175 this._animating = false;
176 this._changeDetectorRef.markForCheck();
177 }
178 /**
179 * Initializes the component and attaches the content.
180 */
181 ngAfterViewInit() {
182 Promise.resolve(undefined).then(() => {
183 if (this._opened) {
184 this._attach();
185 }
186 this._initialized = true;
187 });
188 }
189 /**
190 * Renders the message on screen
191 * Validates if there is an animation currently and if its already opened
192 */
193 open() {
194 if (!this._opened && !this._animating) {
195 this._opened = true;
196 this._attach();
197 this._startAnimationState();
198 }
199 }
200 /**
201 * Removes the message content from screen.
202 * Validates if there is an animation currently and if its already closed
203 */
204 close() {
205 if (this._opened && !this._animating) {
206 this._opened = false;
207 this._startAnimationState();
208 }
209 }
210 /**
211 * Toggles between open and close depending on state.
212 */
213 toggle() {
214 if (this._opened) {
215 this.close();
216 }
217 else {
218 this.open();
219 }
220 }
221 /**
222 * Method to set the state before starting an animation
223 */
224 _startAnimationState() {
225 this._animating = true;
226 this._hidden = false;
227 this._changeDetectorRef.markForCheck();
228 }
229 /**
230 * Method to attach template to DOM
231 */
232 _attach() {
233 this._childElement?.viewContainer.createEmbeddedView(this._template);
234 this._changeDetectorRef.markForCheck();
235 }
236 /**
237 * Method to detach template from DOM
238 */
239 _detach() {
240 this._childElement?.viewContainer.clear();
241 this._changeDetectorRef.markForCheck();
242 }
243 static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdMessageComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
244 static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.1.2", type: TdMessageComponent, selector: "td-message", inputs: { label: "label", sublabel: "sublabel", icon: "icon", color: "color", opened: "opened" }, host: { listeners: { "@tdCollapse.done": "animationDoneListener()" }, properties: { "@tdCollapse": "this.collapsedAnimation", "style.display": "this.hidden" } }, viewQueries: [{ propertyName: "_childElement", first: true, predicate: TdMessageContainerDirective, descendants: true, static: true }, { propertyName: "_template", first: true, predicate: TemplateRef, descendants: true }], ngImport: i0, template: "<div tdMessageContainer></div>\n<ng-template>\n <div class=\"td-message-wrapper\">\n <mat-icon class=\"td-message-icon\">{{ icon }}</mat-icon>\n <div class=\"td-message-labels\">\n <div *ngIf=\"label\" class=\"td-message-label\">{{ label }}</div>\n <div *ngIf=\"sublabel\" class=\"td-message-sublabel\">{{ sublabel }}</div>\n </div>\n <ng-content select=\"[td-message-actions]\"></ng-content>\n </div>\n</ng-template>\n", styles: [":host{display:block}:host .td-message-wrapper{padding:8px 16px;min-height:52px;box-sizing:border-box;display:flex;flex-direction:row;align-items:center;align-content:center;max-width:100%;justify-content:flex-start}:host .td-message-wrapper .td-message-labels{flex:1}.td-message-icon{margin-right:16px}::ng-deep [dir=rtl] .td-message-icon{margin-left:16px;margin-right:0}\n"], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: TdMessageContainerDirective, selector: "[tdMessageContainer]" }], animations: [tdCollapseAnimation] });
245}
246i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdMessageComponent, decorators: [{
247 type: Component,
248 args: [{ selector: 'td-message', animations: [tdCollapseAnimation], template: "<div tdMessageContainer></div>\n<ng-template>\n <div class=\"td-message-wrapper\">\n <mat-icon class=\"td-message-icon\">{{ icon }}</mat-icon>\n <div class=\"td-message-labels\">\n <div *ngIf=\"label\" class=\"td-message-label\">{{ label }}</div>\n <div *ngIf=\"sublabel\" class=\"td-message-sublabel\">{{ sublabel }}</div>\n </div>\n <ng-content select=\"[td-message-actions]\"></ng-content>\n </div>\n</ng-template>\n", styles: [":host{display:block}:host .td-message-wrapper{padding:8px 16px;min-height:52px;box-sizing:border-box;display:flex;flex-direction:row;align-items:center;align-content:center;max-width:100%;justify-content:flex-start}:host .td-message-wrapper .td-message-labels{flex:1}.td-message-icon{margin-right:16px}::ng-deep [dir=rtl] .td-message-icon{margin-left:16px;margin-right:0}\n"] }]
249 }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }], propDecorators: { _childElement: [{
250 type: ViewChild,
251 args: [TdMessageContainerDirective, { static: true }]
252 }], _template: [{
253 type: ViewChild,
254 args: [TemplateRef]
255 }], collapsedAnimation: [{
256 type: HostBinding,
257 args: ['@tdCollapse']
258 }], hidden: [{
259 type: HostBinding,
260 args: ['style.display']
261 }], label: [{
262 type: Input
263 }], sublabel: [{
264 type: Input
265 }], icon: [{
266 type: Input
267 }], color: [{
268 type: Input
269 }], opened: [{
270 type: Input
271 }], animationDoneListener: [{
272 type: HostListener,
273 args: ['@tdCollapse.done']
274 }] } });
275
276const TD_MESSAGE = [
277 TdMessageComponent,
278 TdMessageContainerDirective,
279];
280class CovalentMessageModule {
281 static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentMessageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
282 static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.1.2", ngImport: i0, type: CovalentMessageModule, declarations: [TdMessageComponent,
283 TdMessageContainerDirective], imports: [CommonModule, MatIconModule], exports: [TdMessageComponent,
284 TdMessageContainerDirective] });
285 static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentMessageModule, imports: [CommonModule, MatIconModule] });
286}
287i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentMessageModule, decorators: [{
288 type: NgModule,
289 args: [{
290 imports: [CommonModule, MatIconModule],
291 declarations: [TD_MESSAGE],
292 exports: [TD_MESSAGE],
293 }]
294 }] });
295
296/**
297 * Generated bundle index. Do not edit.
298 */
299
300export { CovalentMessageModule, TdMessageComponent, TdMessageContainerDirective };
301//# sourceMappingURL=covalent-core-message.mjs.map