Skip to content

Commit 891c916

Browse files
committed
Improve thumbnail loading animation
- Minimize content shift by leaving space around the animation (same as the placeholder) - Replace animation with more compact spinner to prevent wrapping when the thumbnail is very narrow
1 parent 13d33d8 commit 891c916

7 files changed

Lines changed: 33 additions & 10 deletions

src/app/shared/loading/loading.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div>
1+
<div *ngIf="!spinner">
22
<label *ngIf="showMessage && message">{{ message }}</label>
33
<div class="loader">
44
<span class="l-1"></span>
@@ -13,3 +13,6 @@
1313
<span class="l-10"></span>
1414
</div>
1515
</div>
16+
<div *ngIf='spinner' class="spinner spinner-border" role="status">
17+
<span class="sr-only">{{ message }}</span>
18+
</div>

src/app/shared/loading/loading.component.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
}
44

55
span {
6-
display: block;
6+
display: block;
77
margin: 0 auto;
88
}
99

@@ -13,11 +13,11 @@ span[class*="l-"] {
1313
background: #000;
1414
display: inline-block;
1515
margin: 12px 2px;
16-
16+
1717
border-radius: 100%;
1818
-webkit-border-radius: 100%;
1919
-moz-border-radius: 100%;
20-
20+
2121
-webkit-animation: loader 2s infinite;
2222
-webkit-animation-timing-function: cubic-bezier(0.030, 0.615, 0.995, 0.415);
2323
-webkit-animation-fill-mode: both;
@@ -71,3 +71,7 @@ span.l-10 {-webkit-animation-delay: 0s;animation-delay: 0s;-ms-animation-delay:
7171
50% {-ms-transform: translateX(30px); opacity: 0;}
7272
100% {opacity: 0;}
7373
}
74+
75+
.spinner {
76+
color: var(--bs-gray-600);
77+
}

src/app/shared/loading/loading.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export class LoadingComponent implements OnDestroy, OnInit {
1515
@Input() message: string;
1616
@Input() showMessage = true;
1717

18+
/**
19+
* Show a more compact spinner animation instead of the default one
20+
*/
21+
@Input() spinner = false;
22+
1823
private subscription: Subscription;
1924

2025
constructor(private translate: TranslateService) {

src/app/shared/loading/themed-loading.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ export class ThemedLoadingComponent extends ThemedComponent<LoadingComponent> {
1515

1616
@Input() message: string;
1717
@Input() showMessage = true;
18+
@Input() spinner = false;
1819

19-
protected inAndOutputNames: (keyof LoadingComponent & keyof this)[] = ['message', 'showMessage'];
20+
protected inAndOutputNames: (keyof LoadingComponent & keyof this)[] = ['message', 'showMessage', 'spinner'];
2021

2122
constructor(
2223
protected resolver: ComponentFactoryResolver,

src/app/thumbnail/thumbnail.component.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<div class="thumbnail" [class.limit-width]="limitWidth" *ngVar="(isLoading$ | async) as isLoading">
2-
<ds-themed-loading *ngIf="isLoading" class="thumbnail-content" [showMessage]="false">
3-
text-content
4-
</ds-themed-loading>
2+
<div *ngIf="isLoading" class="thumbnail-content outer">
3+
<div class="inner">
4+
<div class="centered">
5+
<ds-themed-loading [spinner]="true"></ds-themed-loading>
6+
</div>
7+
</div>
8+
</div>
59
<ng-container *ngVar="(src$ | async) as src">
610
<!-- don't use *ngIf="!isLoading" so the thumbnail can load in while the animation is playing -->
711
<img *ngIf="src !== null" class="thumbnail-content img-fluid" [ngClass]="{'d-none': isLoading}"
812
[src]="src | dsSafeUrl" [alt]="alt | translate" (error)="errorHandler()" (load)="successHandler()">
913
<div *ngIf="src === null && !isLoading" class="thumbnail-content outer">
1014
<div class="inner">
11-
<div class="thumbnail-placeholder w-100 h-100 p-3 lead">{{ placeholder | translate }}</div>
15+
<div class="thumbnail-placeholder centered p-3 lead">
16+
{{ placeholder | translate }}
17+
</div>
1218
</div>
1319
</div>
1420
</ng-container>

src/app/thumbnail/thumbnail.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ img {
2626
border: var(--ds-thumbnail-placeholder-border);
2727
color: var(--ds-thumbnail-placeholder-color);
2828
font-weight: bold;
29+
}
30+
> .centered {
31+
width: 100%;
32+
height: 100%;
2933
display: flex;
3034
justify-content: center;
3135
align-items: center;

src/app/thumbnail/thumbnail.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('ThumbnailComponent', () => {
244244

245245
fixture.detectChanges();
246246
const placeholder = fixture.debugElement.query(By.css('div.thumbnail-placeholder')).nativeElement;
247-
expect(placeholder.innerHTML).toBe('TRANSLATED ' + comp.placeholder);
247+
expect(placeholder.innerHTML).toContain('TRANSLATED ' + comp.placeholder);
248248
});
249249
});
250250
});

0 commit comments

Comments
 (0)