Skip to content

Commit 2993795

Browse files
authored
Merge pull request #464 from appuniversum/feat/au-loader-improvements
`AuLoader` improvements
2 parents a613159 + d13bade commit 2993795

File tree

8 files changed

+149
-26
lines changed

8 files changed

+149
-26
lines changed

addon/components/au-button.gts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component from '@glimmer/component';
22
import AuIcon from './au-icon';
3-
import AuLoader from './au-loader';
3+
import { LoadingAnimation } from '../private/components/loading-animation';
44

55
const SKINS = [
66
'primary',
@@ -118,14 +118,14 @@ export default class AuButton extends Component<AuButtonSignature> {
118118
{{#if @hideText}}
119119
{{#if @loading}}
120120
<span class="au-u-hidden-visually">{{this.loadingMessage}}</span>
121-
<AuLoader @padding="small" />
121+
<LoadingAnimation />
122122
{{else}}
123123
<span class="au-u-hidden-visually">{{yield}}</span>
124124
{{/if}}
125125
{{else}}
126126
{{#if @loading}}
127127
{{this.loadingMessage}}
128-
<AuLoader @padding="small" />
128+
<LoadingAnimation />
129129
{{else}}
130130
{{yield}}
131131
{{/if}}

addon/components/au-loader.gts

+54-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
11
import Component from '@glimmer/component';
2+
import { deprecate } from '@ember/debug';
3+
import { LoadingAnimation } from '../private/components/loading-animation';
4+
import { modifier } from 'ember-modifier';
5+
6+
const deprecateOldVersion = modifier(function deprecateOldVersion() {
7+
deprecate(
8+
`[AuLoader] This version of the \`AuLoader\` component is deprecated.
9+
10+
Follow the migration guide to switch to the new version: https://github.com/appuniversum/ember-appuniversum/pull/464
11+
12+
`,
13+
false,
14+
{
15+
id: '@appuniversum/ember-appuniversum.au-loader-visible-by-default',
16+
until: '4.0.0',
17+
for: '@appuniversum/ember-appuniversum',
18+
since: {
19+
available: '3.1.0',
20+
enabled: '3.1.0',
21+
},
22+
},
23+
);
24+
});
225

326
export interface AuLoaderSignature {
427
Args: {
28+
inline?: boolean;
29+
hideMessage?: boolean;
30+
// Deprecated arguments
531
disableMessage?: boolean;
632
message?: string;
733
padding?: 'small' | 'large';
834
};
35+
Blocks: {
36+
default: [];
37+
};
938
Element: HTMLDivElement;
1039
}
1140

@@ -21,11 +50,30 @@ export default class AuLoader extends Component<AuLoaderSignature> {
2150
}
2251

2352
<template>
24-
<div class="au-c-loader {{this.padding}}" ...attributes>
25-
<div class="au-c-loader__animation" aria-hidden="true"></div>
26-
{{#unless @disableMessage}}
27-
<span class="au-u-hidden-visually">{{this.message}}</span>
28-
{{/unless}}
29-
</div>
53+
{{#if (has-block)}}
54+
<div class="au-c-loader au-u-text-center" role="status" ...attributes>
55+
<LoadingAnimation />
56+
{{#if @inline}}
57+
<span
58+
class="au-u-para {{if @hideMessage 'au-u-hidden-visually'}}"
59+
>{{~yield~}}</span>
60+
{{else}}
61+
<p
62+
class="au-u-para {{if @hideMessage 'au-u-hidden-visually'}}"
63+
>{{yield}}</p>
64+
{{/if}}
65+
</div>
66+
{{else}}
67+
<div
68+
class="au-c-loader {{this.padding}}"
69+
{{deprecateOldVersion}}
70+
...attributes
71+
>
72+
<div class="au-c-loader__animation" aria-hidden="true"></div>
73+
{{#unless @disableMessage}}
74+
<span class="au-u-hidden-visually">{{this.message}}</span>
75+
{{/unless}}
76+
</div>
77+
{{/if}}
3078
</template>
3179
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { TOC } from '@ember/component/template-only';
2+
3+
interface Signature {
4+
Element: HTMLDivElement;
5+
}
6+
7+
export const LoadingAnimation: TOC<Signature> = <template>
8+
<div class="au-p-c-loading-animation" aria-hidden="true" ...attributes></div>
9+
</template>;

stories/5-components/Notifications/AuLoader.stories.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ import { hbs } from 'ember-cli-htmlbars';
33
export default {
44
title: 'Components/Notifications/AuLoader',
55
argTypes: {
6-
padding: {
7-
control: 'select',
8-
options: ['default', 'small', 'large'],
9-
description: 'Set the padding of the loader',
10-
},
116
message: {
127
control: 'text',
13-
description: 'Set the hidden loading text',
8+
description: 'Set the loading text',
9+
},
10+
inline: {
11+
control: 'boolean',
12+
description: 'Use the inline version of the loader',
1413
},
15-
disableMessage: {
14+
hideMessage: {
1615
control: 'boolean',
17-
description: 'Remove the loading text',
16+
description: 'Hide the loading text',
1817
},
1918
},
2019
parameters: {
@@ -24,13 +23,16 @@ export default {
2423

2524
const Template = (args) => ({
2625
template: hbs`
27-
<AuLoader @padding={{this.padding}} @message={{this.message}} @disableMessage={{this.disableMessage}} />`,
26+
<AuLoader
27+
@inline={{this.inline}}
28+
@hideMessage={{this.hideMessage}}
29+
>{{this.message}}</AuLoader>`,
2830
context: args,
2931
});
3032

3133
export const Component = Template.bind({});
3234
Component.args = {
33-
padding: 'default',
3435
message: 'Aan het laden',
35-
disableMessage: false,
36+
inline: false,
37+
hideMessage: false,
3638
};

styles/components/_c-loader.scss

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
display: block;
1010
}
1111

12+
// .au-p- = private class
13+
.au-p-c-loading-animation {
14+
display: inline-block;
15+
position: relative;
16+
width: 3rem;
17+
height: 1.8rem;
18+
}
19+
20+
// TODO: Remove this once we drop support for the "old" AuLoader setup
1221
.au-c-loader__animation {
1322
display: block;
1423
position: relative;
@@ -24,7 +33,11 @@
2433
width: 3rem + $au-unit-large;
2534
height: 3rem + $au-unit-large;
2635
}
36+
}
2737

38+
.au-p-c-loading-animation,
39+
// TODO: Remove this once we drop support for the "old" AuLoader setup
40+
.au-c-loader__animation {
2841
&::before {
2942
content: "";
3043
display: block;

tests/helpers/deprecations.js tests/helpers/deprecations.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { getDeprecations } from '@ember/test-helpers';
22

3-
export function hasDeprecation(deprecationMessage) {
3+
export function hasDeprecation(deprecationMessage: string): boolean {
44
return getDeprecations().some(
55
(deprecation) => deprecation.message === deprecationMessage,
66
);
77
}
88

9-
export function hasDeprecationStartingWith(deprecationMessage) {
9+
export function hasDeprecationStartingWith(
10+
deprecationMessage: string,
11+
): boolean {
1012
return getDeprecations().some((deprecation) =>
1113
deprecation.message.startsWith(deprecationMessage),
1214
);
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,75 @@
1-
import { module, test } from 'qunit';
2-
import { setupRenderingTest } from 'ember-qunit';
3-
import { render } from '@ember/test-helpers';
41
import AuLoader from '@appuniversum/ember-appuniversum/components/au-loader';
2+
import { getRootElement, render } from '@ember/test-helpers';
3+
import { queryByText } from '@testing-library/dom';
4+
import { hasDeprecationStartingWith } from 'dummy/tests/helpers/deprecations';
5+
import { setupRenderingTest } from 'ember-qunit';
6+
import { module, test } from 'qunit';
57

68
module('Integration | Component | au-loader', function (hooks) {
79
setupRenderingTest(hooks);
810

11+
test('it uses the block contents as the loading message', async function (assert) {
12+
await render(
13+
<template>
14+
<AuLoader>
15+
Pagina is aan het laden
16+
</AuLoader>
17+
</template>,
18+
);
19+
20+
assert.dom().hasText('Pagina is aan het laden');
21+
assert.false(hasDeprecationStartingWith('[AuLoader]'));
22+
});
23+
24+
test('it supports visually hiding the loading text', async function (assert) {
25+
await render(
26+
<template>
27+
<AuLoader @hideMessage={{true}}>
28+
Pagina is aan het laden
29+
</AuLoader>
30+
</template>,
31+
);
32+
33+
const root = getRootElement() as HTMLElement;
34+
const text = queryByText(root, 'Pagina is aan het laden') as HTMLElement;
35+
36+
// Hacky way to test if the text is visible.
37+
// `assert.dom(text).isNotVisible()` doesn't work here because of the styles we use for the au-u-hidden-visually class.
38+
assert.true(text.offsetHeight <= 1);
39+
assert.true(text.offsetWidth <= 1);
40+
assert.false(hasDeprecationStartingWith('[AuLoader]'));
41+
});
42+
943
test('it renders a hidden loading text for screen readers', async function (assert) {
1044
await render(<template><AuLoader /></template>);
1145

1246
assert.dom().hasText('Aan het laden');
47+
assert.true(showsDeprecationMessage());
1348
});
1449

1550
test('it supports rendering a custom hidden loading text', async function (assert) {
1651
await render(<template><AuLoader @message="Loading" /></template>);
1752

1853
assert.dom().hasText('Loading');
54+
assert.true(showsDeprecationMessage());
1955
});
2056

2157
test('it supports disabling the hidden message', async function (assert) {
2258
await render(<template><AuLoader @disableMessage={{true}} /></template>);
2359

2460
assert.dom().hasNoText();
61+
assert.true(showsDeprecationMessage());
62+
});
63+
64+
test('@padding shows a deprecation', async function (assert) {
65+
await render(<template><AuLoader @padding="small" /></template>);
66+
67+
assert.true(showsDeprecationMessage());
2568
});
2669
});
70+
71+
function showsDeprecationMessage() {
72+
return hasDeprecationStartingWith(
73+
'[AuLoader] This version of the `AuLoader` component is deprecated',
74+
);
75+
}

tests/integration/components/loose-mode-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module('Integration | Component | Loose mode', function (hooks) {
135135

136136
test('`<AuLoader>` resolves in loose mode', async function (assert) {
137137
await render(hbs`
138-
<AuLoader data-test-loader />
138+
<AuLoader data-test-loader></AuLoader>
139139
`);
140140
assert.dom('[data-test-loader]').exists();
141141
});

0 commit comments

Comments
 (0)