Created
August 16, 2019 21:16
-
-
Save tinmegali/a71606e4b849677bef88d647e7e93c89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ | |
name: 'fileIcon' | |
}) | |
export class FileIconPipe implements PipeTransform { | |
transform(fileType: string): string { | |
switch (fileType) { | |
// images | |
case 'image/png': { | |
return 'file-image'; | |
} | |
case 'image/jpeg': { | |
return 'file-image'; | |
} | |
case 'image/bmp': { | |
return 'file-image'; | |
} | |
case 'image/svg+xml': { | |
return 'file-image'; | |
} | |
case 'image/tiff': { | |
return 'file-image'; | |
} | |
// audio | |
case 'audio/mpeg': { | |
return 'file-audio'; | |
} | |
case 'audio/ogg': { | |
return 'file-audio'; | |
} | |
case 'audio/wav': { | |
return 'file-audio'; | |
} | |
case 'audio/aac': { | |
return 'file-audio'; | |
} | |
// video | |
case 'video/x-msvideo': { | |
return 'file-video'; | |
} | |
case 'video/mpeg': { | |
return 'file-video'; | |
} | |
case 'video/3gpp': { | |
return 'file-video'; | |
} | |
// other | |
case 'application/pdf': { | |
return 'file-pdf'; | |
} | |
case 'application/msword': { | |
return 'file-word'; | |
} | |
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': { | |
return 'file-word'; | |
} | |
default: { | |
return 'file'; | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {FileIconPipe} from 'app/shared/file-icon.pipe'; | |
@NgModule({ | |
declarations: [ FileIconPipe], | |
exports: [FileIconPipe], | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fa-icon [icon]="file.fileType | fileIcon"></fa-icon> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment