Skip to content
Snippets Groups Projects
Commit a2d9afd2 authored by OZGCloud's avatar OZGCloud
Browse files

fix file upload spinner

parent 8b82a227
No related branches found
No related tags found
No related merge requests found
<ng-container *ngIf="uploadInProgress$ | async as uploadInProgress">
<input data-test-id="file-upload-input" <input data-test-id="file-upload-input"
[id]="myId" type="file" [accept]="accept" [id]="myId" type="file" [accept]="accept"
(change)="onFileChanged($event)"> (change)="onFileChanged($event)">
<label [attr.for]="myId" matRipple aria-label="attachment icon"> <label [attr.for]="myId" matRipple aria-label="attachment icon">
<mat-icon>attach_file</mat-icon> <mat-icon *ngIf="!uploadInProgress.loading">attach_file</mat-icon>
<goofy-client-spinner
[stateResource]="uploadInProgress"
[diameter]="22"
padding="0">
</goofy-client-spinner>
</label> </label>
</ng-container>
...@@ -3,6 +3,7 @@ $size: 40px; ...@@ -3,6 +3,7 @@ $size: 40px;
:host { :host {
margin: 4px 0; margin: 4px 0;
display: block; display: block;
position: relative;
} }
input { input {
...@@ -27,3 +28,19 @@ label:hover, ...@@ -27,3 +28,19 @@ label:hover,
:host:focus-within label { :host:focus-within label {
background-color: rgba(#000, 0.16); background-color: rgba(#000, 0.16);
} }
[disabled] {
background-color: rgba(#000, 0.08);
}
goofy-client-spinner {
position: absolute;
top: 0;
left: 0;
display: flex;
height: 100%;
width: 100%;
justify-content: center;
align-items: center;
pointer-events: none;
}
...@@ -2,6 +2,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; ...@@ -2,6 +2,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FileUploadComponent } from './file-upload.component'; import { FileUploadComponent } from './file-upload.component';
import { MatIcon } from '@angular/material/icon'; import { MatIcon } from '@angular/material/icon';
import { MockComponent } from 'ng-mocks';
import { SpinnerComponent } from '@goofy-client/ui';
describe('FileUploadComponent', () => { describe('FileUploadComponent', () => {
let component: FileUploadComponent; let component: FileUploadComponent;
...@@ -11,7 +13,8 @@ describe('FileUploadComponent', () => { ...@@ -11,7 +13,8 @@ describe('FileUploadComponent', () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ declarations: [
FileUploadComponent, FileUploadComponent,
MatIcon MatIcon,
MockComponent(SpinnerComponent)
] ]
}) })
.compileComponents(); .compileComponents();
......
import { Component, EventEmitter, Input, Output } from '@angular/core'; import { Component, EventEmitter, Input, Output } from '@angular/core';
import { uniqueId } from 'lodash-es'; import { uniqueId } from 'lodash-es';
import { Observable } from 'rxjs';
import { StateResource } from '@goofy-client/tech-shared';
@Component({ @Component({
selector: 'goofy-client-file-upload', selector: 'goofy-client-file-upload',
...@@ -8,6 +10,7 @@ import { uniqueId } from 'lodash-es'; ...@@ -8,6 +10,7 @@ import { uniqueId } from 'lodash-es';
}) })
export class FileUploadComponent { export class FileUploadComponent {
@Input() accept: string = '*/*'; @Input() accept: string = '*/*';
@Input() uploadInProgress$: Observable<StateResource<any>>;
@Output() fileChanged: EventEmitter<File> = new EventEmitter(); @Output() fileChanged: EventEmitter<File> = new EventEmitter();
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
</goofy-client-spinner> </goofy-client-spinner>
</ng-container> </ng-container>
<goofy-client-spinner [stateResource]="uploadInProgress$ | async"> <goofy-client-file-upload data-test-id="wiedervorlage-file-upload"
<goofy-client-file-upload (fileChanged)="uploadFile($event)" data-test-id="wiedervorlage-file-upload"></goofy-client-file-upload> (fileChanged)="uploadFile($event)"
</goofy-client-spinner> [uploadInProgress$]="uploadInProgress$">
</goofy-client-file-upload>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment