diff --git a/src/lib/common-ui.module.ts b/src/lib/common-ui.module.ts index c116fa3..d3cb898 100644 --- a/src/lib/common-ui.module.ts +++ b/src/lib/common-ui.module.ts @@ -32,6 +32,8 @@ import { MatDialogModule } from '@angular/material/dialog'; import { CapitalizePipe } from './utils/pipes/capitalize.pipe'; import { KeycloakAngularModule } from 'keycloak-angular'; import { MatCheckboxModule } from '@angular/material/checkbox'; +import { UploadFileComponent } from './upload-file/upload-file.component'; +import { DragDropFileUploadDirective } from './upload-file/drag-drop-file-upload.directive'; const matModules = [MatIconModule, MatProgressSpinnerModule, MatButtonModule, MatDialogModule, MatCheckboxModule]; const modules = [ @@ -57,9 +59,12 @@ const components = [ ToastComponent, SmallChipComponent, ProgressBarComponent, + UploadFileComponent, + DragDropFileUploadDirective, ]; -const pipes = [SortByPipe, HumanizePipe, CapitalizePipe, LogPipe]; + +const pipes = [SortByPipe, HumanizePipe, CapitalizePipe, LogPipe]; @NgModule({ declarations: [...components, ...pipes], imports: [CommonModule, ...matModules, ...modules, FormsModule, ReactiveFormsModule, KeycloakAngularModule], diff --git a/src/lib/help-mode/help-mode/help-mode.component.ts b/src/lib/help-mode/help-mode/help-mode.component.ts index 89a2663..bd6f46d 100644 --- a/src/lib/help-mode/help-mode/help-mode.component.ts +++ b/src/lib/help-mode/help-mode/help-mode.component.ts @@ -38,7 +38,7 @@ export class HelpModeComponent { } } - @HostListener('window:resize') onResize(event: any) { + @HostListener('window:resize') onResize() { if (this.helpModeService.isHelpModeActive) { this.helpModeService.updateHelperElements(); } diff --git a/src/lib/upload-file/drag-drop-file-upload.directive.ts b/src/lib/upload-file/drag-drop-file-upload.directive.ts new file mode 100644 index 0000000..060f21f --- /dev/null +++ b/src/lib/upload-file/drag-drop-file-upload.directive.ts @@ -0,0 +1,41 @@ +import { Directive, EventEmitter, Output, HostListener, HostBinding } from '@angular/core'; + +const DRAG_OVER_BACKGROUND_COLOR = '#e2eefd'; +const DEFAULT_BACKGROUND_COLOR = '#f4f5f7'; + +@Directive({ + selector: '[iqserDragDropFileUpload]', +}) +export class DragDropFileUploadDirective { + @Output() readonly fileDropped = new EventEmitter(); + @HostBinding('style.background-color') private _background = DEFAULT_BACKGROUND_COLOR; + + @HostListener('dragover', ['$event']) + onDragOver(event: DragEvent) { + event.preventDefault(); + event.stopPropagation(); + if (event.dataTransfer?.types.includes('Files')) { + this._background = DRAG_OVER_BACKGROUND_COLOR; + } + } + + @HostListener('dragleave', ['$event']) + onDragLeave(event: DragEvent) { + event.preventDefault(); + event.stopPropagation(); + this._background = DEFAULT_BACKGROUND_COLOR; + } + + @HostListener('drop', ['$event']) + onDrop(event: DragEvent) { + event.preventDefault(); + event.stopPropagation(); + if (event?.dataTransfer?.types.includes('Files')) { + this._background = DEFAULT_BACKGROUND_COLOR; + const files = event.dataTransfer.files; + if (files.length > 0) { + this.fileDropped.emit({ target: { files } }); + } + } + } +} diff --git a/src/lib/upload-file/upload-file.component.html b/src/lib/upload-file/upload-file.component.html new file mode 100644 index 0000000..039f67e --- /dev/null +++ b/src/lib/upload-file/upload-file.component.html @@ -0,0 +1,17 @@ +
{{ file.name }}
+