Skip to content

Commit 72b4707

Browse files
committed
Auto merge of #2816 - Turbo87:spinner, r=locks
Extract `LoadingSpinner` component and convert to CSS animation This PR first extracts a `LoadingSpinner` component, and then changes its internal implementation to use a CSS animation instead of loading and showing an animated GIF image. It also slightly improves the a11y, by adding a "Loading…" label for screenreader users. r? `@locks`
2 parents 3a76b14 + eaf1e37 commit 72b4707

File tree

10 files changed

+60
-8
lines changed

10 files changed

+60
-8
lines changed

app/components/api-token-row.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</button>
5555
{{/if}}
5656
{{#if this.api_token.isSaving}}
57-
<img src="/assets/ajax-loader.gif" alt="Loading Spinner" data-test-saving-spinner>
57+
<LoadingSpinner local-class="spinner" data-test-saving-spinner />
5858
{{/if}}
5959
</div>
6060
</div>

app/components/api-token-row.module.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
.actions {
4646
display: flex;
4747
align-items: center;
48-
img { margin-left: 10px }
48+
}
49+
50+
.spinner {
51+
margin-left: 10px
4952
}
5053

5154
.save-button {

app/components/follow-button.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<button type="button" local-class="button" {{on "click" (perform this.toggleFollowTask)}} data-test-follow-button>
22
{{#if (or this.followStateTask.isRunning this.toggleFollowTask.isRunning)}}
3-
<img src="/assets/ajax-loader.gif" alt="Loading Spinner" data-test-spinner>
3+
<LoadingSpinner data-test-spinner />
44
{{else}}
55
{{#if this.following}}
66
Unfollow

app/components/loading-spinner.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<div
2+
local-class="spinner"
3+
...attributes
4+
>
5+
<span local-class="message">Loading…</span>
6+
</div>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.spinner {
2+
--spinner-color: black;
3+
--spinner-bg-color: rgba(0, 0, 0, .2);
4+
5+
display: inline-block;
6+
height: 16px;
7+
width: 16px;
8+
9+
&:after {
10+
content: " ";
11+
display: block;
12+
box-sizing: border-box;
13+
width: 16px;
14+
height: 16px;
15+
border-radius: 50%;
16+
border: 3px solid var(--spinner-color);
17+
border-color: var(--spinner-bg-color) var(--spinner-bg-color) var(--spinner-color) var(--spinner-bg-color);
18+
animation: spinner 1.2s linear infinite;
19+
}
20+
}
21+
22+
.message {
23+
composes: sr-only from '../styles/shared/a11y.module.css';
24+
}
25+
26+
@keyframes spinner {
27+
0% {
28+
transform: rotate(0deg);
29+
}
30+
100% {
31+
transform: rotate(360deg);
32+
}
33+
}

app/components/page-header.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<small local-class="suffix">{{@suffix}}</small>
1010
{{/if}}
1111
{{#if @showSpinner}}
12-
<img src="/assets/ajax-loader.gif" alt="Loading Spinner" local-class="loading-spinner">
12+
<LoadingSpinner local-class="loading-spinner" />
1313
{{/if}}
1414
</h1>
1515
{{/if}}

app/styles/shared/a11y.module.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.sr-only {
2+
position: absolute;
3+
width: 1px;
4+
height: 1px;
5+
padding: 0;
6+
overflow: hidden;
7+
clip: rect(0, 0, 0, 0);
8+
white-space: nowrap;
9+
border: 0;
10+
}

app/templates/dashboard.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
{{#if this.loadMoreTask.isRunning}}
6464
<span local-class='load-more'>
65-
<img src="/assets/ajax-loader.gif" alt="Loading">
65+
<LoadingSpinner />
6666
</span>
6767
{{else}}
6868
{{#if this.hasMore}}

public/assets/ajax-loader.gif

-583 Bytes
Binary file not shown.

tests/acceptance/crate-following-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module('Acceptance | Crate following', function (hooks) {
3737

3838
visit('/crates/nanomsg');
3939
await waitFor('[data-test-follow-button] [data-test-spinner]');
40-
assert.dom('[data-test-follow-button]').hasText('');
40+
assert.dom('[data-test-follow-button]').hasText('Loading…');
4141
assert.dom('[data-test-follow-button] [data-test-spinner]').exists();
4242

4343
followingDeferred.resolve({ following: false });
@@ -50,7 +50,7 @@ module('Acceptance | Crate following', function (hooks) {
5050

5151
click('[data-test-follow-button]');
5252
await waitFor('[data-test-follow-button] [data-test-spinner]');
53-
assert.dom('[data-test-follow-button]').hasText('');
53+
assert.dom('[data-test-follow-button]').hasText('Loading…');
5454
assert.dom('[data-test-follow-button] [data-test-spinner]').exists();
5555

5656
followDeferred.resolve({ ok: true });
@@ -63,7 +63,7 @@ module('Acceptance | Crate following', function (hooks) {
6363

6464
click('[data-test-follow-button]');
6565
await waitFor('[data-test-follow-button] [data-test-spinner]');
66-
assert.dom('[data-test-follow-button]').hasText('');
66+
assert.dom('[data-test-follow-button]').hasText('Loading…');
6767
assert.dom('[data-test-follow-button] [data-test-spinner]').exists();
6868

6969
unfollowDeferred.resolve({ ok: true });

0 commit comments

Comments
 (0)