Browse Source

UI: tb-error move logic form PE, code style fix, enhacements

pull/9533/head
Dmitriymush 3 years ago
parent
commit
598d67c4f2
  1. 38
      ui-ngx/src/app/shared/components/tb-error.component.ts

38
ui-ngx/src/app/shared/components/tb-error.component.ts

@ -21,10 +21,10 @@ import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-error', selector: 'tb-error',
template: ` template: `
<div [@animation]="state" [ngStyle]="{marginTop: noMargin ? '0' : '0.5rem', fontSize: '.75rem'}"> <div [@animation]="state" [ngStyle]="{marginTop: noMargin ? '0' : '0.5rem', fontSize: '.75rem'}">
<mat-error > <mat-error>
{{message}} {{message}}
</mat-error> </mat-error>
</div> </div>
`, `,
styles: [` styles: [`
@ -36,21 +36,23 @@ import { coerceBoolean } from '@shared/decorators/coercion';
trigger('animation', [ trigger('animation', [
state('show', style({ state('show', style({
opacity: 1, opacity: 1,
transform: 'translateY(0)'
})), })),
state('hide', style({ state('hide', style({
opacity: 0, opacity: 0,
transform: 'translateY(-1rem)' transform: 'translateY(-1rem)'
})), })),
transition('show => hide', animate('200ms ease-out')), transition('* <=> *', animate('200ms ease-out'))
transition('* => show', animate('200ms ease-in'))
]), ]),
] ]
}) })
export class TbErrorComponent { export class TbErrorComponent {
errorValue: any; errorValue: string;
state: any; state = 'hide';
message; message: string;
constructor(private cd: ChangeDetectorRef) {
}
@Input() @Input()
@coerceBoolean() @coerceBoolean()
@ -58,19 +60,13 @@ export class TbErrorComponent {
@Input() @Input()
set error(value) { set error(value) {
if (value && !this.message) { if (this.errorValue !== value) {
this.message = value;
this.state = 'hide';
setTimeout(() => {
this.state = 'show';
this.cd.markForCheck();
});
} else {
this.errorValue = value; this.errorValue = value;
if (value) {
this.message = value;
}
this.state = value ? 'show' : 'hide'; this.state = value ? 'show' : 'hide';
this.cd.markForCheck();
} }
} }
constructor(private cd: ChangeDetectorRef) {}
} }

Loading…
Cancel
Save