Skip to content

Commit db08eec

Browse files
committed
💄 update icon files uploaded
1 parent 78eed3c commit db08eec

File tree

6 files changed

+77
-12
lines changed

6 files changed

+77
-12
lines changed

src/app/core/constants/file.constant.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ export const ALLOWED_FILE_TYPES = [
33
'image/png',
44
'image/jpeg',
55
'image/jpg',
6-
'image/gif',
7-
'application/pdf'
6+
'application/pdf',
7+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', // .docx
8+
];
9+
10+
export const ICONS = {
11+
png: 'bxs-file-png',
12+
jpg: 'bxs-file-jpg',
13+
jpeg: 'bxs-file-image',
14+
pdf: 'bxs-file-pdf',
15+
} as const;
16+
17+
export const ALLOWED_FILE_EXTENSIONS = [
18+
'png',
19+
'jpg',
20+
'jpeg',
21+
'pdf',
22+
'docx',
823
];

src/app/core/utils/icon-file.util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ICONS } from "@constants/file.constant";
2+
3+
export const getIconFile = (type: string): string => {
4+
const [category, extension] = type.split('/');
5+
if (category === 'image') {
6+
return ICONS[extension as keyof typeof ICONS] || 'bxs-file-image';
7+
}
8+
return ICONS[extension as keyof typeof ICONS] || 'bxs-file';
9+
};

src/app/shared/modals/upload-files/upload-files.component.html

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div class="file" *ngFor="let file of files; let i = index">
1818
<div class="file-info">
1919
<div class="file-icon">
20-
<i class="bx bx-file"></i>
20+
<i class="bx" [ngClass]="getIcon(file)"></i>
2121
</div>
2222
<span class="file-name">{{ file.name }}</span>
2323
<span class="file-size">{{ file.size | fileSize }}</span>
@@ -28,9 +28,14 @@
2828
</div>
2929
</div>
3030
</div>
31-
<span class="warning">
32-
Peso máximo por archivo: 2MB
33-
</span>
31+
<div class="messages">
32+
<span class="message">
33+
Peso máximo por archivo: 2MB
34+
</span>
35+
<span class="message">
36+
Formatos permitidos: {{ allowedFormats() }}
37+
</span>
38+
</div>
3439
<div class="actions">
3540
<button class="btn btn-primary" *ngIf="files && files.length > 0" type="file" (click)="selectFiles()">
3641
Subir más archivos

src/app/shared/modals/upload-files/upload-files.component.scss

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
flex: 1;
5656

5757
& .file-icon {
58-
font-size: 1.5rem;
58+
@include fs-1;
5959
color: var(--fc-purple);
6060
}
6161

@@ -92,10 +92,16 @@
9292
}
9393
}
9494

95-
.warning {
96-
@include fs-6;
97-
@include fw-500;
98-
color: var(--fc-purple);
95+
.messages {
96+
display: flex;
97+
flex-direction: column;
98+
gap: 1rem;
99+
100+
& .message {
101+
@include fs-6;
102+
@include fw-500;
103+
color: var(--fc-purple);
104+
}
99105
}
100106

101107
.actions {

src/app/shared/modals/upload-files/upload-files.component.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import { Subscription } from 'rxjs';
55
import { FileService } from '@services/file.service';
66
import { ModalService } from '@services/modal.service';
77

8-
import { ALLOWED_FILE_TYPES, MAX_FILE_SIZE } from '@constants/file.constant';
8+
import { getIconFile } from '@utils/icon-file.util';
9+
10+
import {
11+
ALLOWED_FILE_EXTENSIONS,
12+
ALLOWED_FILE_TYPES,
13+
MAX_FILE_SIZE
14+
} from '@constants/file.constant';
915

1016
@Component({
1117
selector: 'app-upload-files',
@@ -67,6 +73,14 @@ export class UploadFilesComponent implements OnInit, OnDestroy {
6773
this.files = [...this.files, ...files];
6874
}
6975

76+
getIcon(file: File): string {
77+
return getIconFile(file.type);
78+
}
79+
80+
allowedFormats(): string {
81+
return ALLOWED_FILE_EXTENSIONS.map((extension) => `.${extension}`).join(' ');
82+
}
83+
7084
validateFiles(): boolean {
7185
return this.files.length > 0 && this.files.every((file) => file.size < MAX_FILE_SIZE
7286
&& ALLOWED_FILE_TYPES.includes(file.type));

src/styles.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,19 @@ input {
391391
color: var(--fc-primary);
392392
}
393393
}
394+
395+
.bx {
396+
&.bxs-file-png,
397+
&.bxs-file-jpg,
398+
&.bxs-file-image {
399+
color: $green;
400+
}
401+
402+
&.bxs-file-pdf {
403+
color: $red;
404+
}
405+
406+
&.bxs-file {
407+
color: $blue;
408+
}
409+
}

0 commit comments

Comments
 (0)