Skip to content

Commit a085741

Browse files
committed
feat: Add CSS class to SVG images
1 parent de795ff commit a085741

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
[class.str-chat__message-attachment-with-actions]="
1515
attachment.actions && attachment.actions.length > 0
1616
"
17+
[class.str-chat__message-attachment--svg-image]="isSvg(attachment)"
1718
>
1819
<img
1920
*ngIf="isImage(attachment)"
@@ -48,6 +49,9 @@
4849
data-testclass="gallery-image"
4950
(click)="openImageModal(attachment.images!, index)"
5051
(keyup.enter)="openImageModal(attachment.images!, index)"
52+
[class.str-chat__message-attachment--svg-image]="
53+
isSvg(galleryImage)
54+
"
5155
>
5256
<img
5357
[src]="
@@ -65,6 +69,9 @@
6569
data-testclass="gallery-image"
6670
(click)="openImageModal(attachment.images!, index)"
6771
(keyup.enter)="openImageModal(attachment.images!, index)"
72+
[class.str-chat__message-attachment--svg-image]="
73+
isSvg(galleryImage)
74+
"
6875
[ngStyle]="{
6976
'background-image':
7077
'url(' +

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,28 @@ describe('AttachmentListComponent', () => {
407407

408408
expect(spy).toHaveBeenCalledWith(undefined);
409409
});
410+
411+
it('should display add necessary CSS class for SVG images', () => {
412+
component.attachments = [
413+
{ type: 'image', img_url: 'image/url', fallback: 'image.svg' },
414+
];
415+
component.ngOnChanges();
416+
fixture.detectChanges();
417+
418+
expect(
419+
nativeElement.querySelector('.str-chat__message-attachment--svg-image')
420+
).not.toBeNull();
421+
422+
component.attachments = [
423+
{ type: 'image', img_url: 'image/url', fallback: 'image.jpg' },
424+
];
425+
component.ngOnChanges();
426+
fixture.detectChanges();
427+
428+
expect(
429+
nativeElement.querySelector('.str-chat__message-attachment--svg-image')
430+
).toBeNull();
431+
});
410432
});
411433

412434
describe('should display file attachment', () => {

projects/stream-chat-angular/src/lib/attachment-list/attachment-list.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ export class AttachmentListComponent implements OnChanges {
7878
return isImageAttachment(attachment);
7979
}
8080

81+
isSvg(attachment: Attachment) {
82+
const filename = attachment.fallback || '';
83+
return !!filename.toLowerCase().endsWith('.svg');
84+
}
85+
8186
isFile(attachment: Attachment) {
8287
return attachment.type === 'file';
8388
}

0 commit comments

Comments
 (0)