Skip to content

Commit cb04c40

Browse files
committed
AuLoader improvements
This tries to match the Webuniversum `<vl-ui-loader>` component as good as possible. It's now possible to display a visual text, making it more suited for page loading animations without having to create a custom component. We also support the inline version of the loading text. The existing options that weren't supported by the `<vl-ui-loader>` component are now deprecated.
1 parent 9ef3e00 commit cb04c40

File tree

6 files changed

+148
-21
lines changed

6 files changed

+148
-21
lines changed

addon/components/au-loader.gts

+69-6
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,94 @@
11
import Component from '@glimmer/component';
2+
import { deprecate } from '@ember/debug';
23

34
export interface AuLoaderSignature {
45
Args: {
6+
inline?: boolean;
7+
hiddenMessage?: boolean;
8+
// Deprecated arguments
59
disableMessage?: boolean;
610
message?: string;
711
padding?: 'small' | 'large';
812
};
13+
Blocks: {
14+
default: [];
15+
};
916
Element: HTMLDivElement;
1017
}
1118

1219
export default class AuLoader extends Component<AuLoaderSignature> {
1320
get padding() {
21+
deprecate('[AuLoader] `@padding` is deprecated.', !this.args.padding, {
22+
id: '@appuniversum/ember-appuniversum.au-loader-padding',
23+
until: '4.0.0',
24+
for: '@appuniversum/ember-appuniversum',
25+
since: {
26+
available: '3.1.0',
27+
enabled: '3.1.0',
28+
},
29+
});
30+
1431
if (this.args.padding == 'small') return 'au-c-loader--small';
1532
if (this.args.padding == 'large') return 'au-c-loader--large';
1633
else return '';
1734
}
1835

1936
get message() {
37+
deprecate(
38+
'[AuLoader] `@message` is deprecated. Provide it using the default block instead.',
39+
!this.args.message,
40+
{
41+
id: '@appuniversum/ember-appuniversum.au-loader-message',
42+
until: '4.0.0',
43+
for: '@appuniversum/ember-appuniversum',
44+
since: {
45+
available: '3.1.0',
46+
enabled: '3.1.0',
47+
},
48+
},
49+
);
2050
return this.args.message || 'Aan het laden';
2151
}
2252

53+
get disableMessage() {
54+
deprecate(
55+
'[AuLoader] `@disableMessage` is deprecated. A message should be provided for accessibility reasons.',
56+
!('disableMessage' in this.args),
57+
{
58+
id: '@appuniversum/ember-appuniversum.au-loader-disableMessage',
59+
until: '4.0.0',
60+
for: '@appuniversum/ember-appuniversum',
61+
since: {
62+
available: '3.1.0',
63+
enabled: '3.1.0',
64+
},
65+
},
66+
);
67+
return this.args.disableMessage;
68+
}
69+
2370
<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>
71+
{{#if (has-block)}}
72+
<div class="au-c-loader au-c-loader--new" ...attributes>
73+
<div class="au-c-loader__animation" aria-hidden="true"></div>
74+
{{#if @inline}}
75+
<span
76+
class="au-u-para {{if @hiddenMessage 'au-u-hidden-visually'}}"
77+
>{{~yield~}}</span>
78+
{{else}}
79+
<p
80+
class="au-u-para {{if @hiddenMessage 'au-u-hidden-visually'}}"
81+
>{{yield}}</p>
82+
{{/if}}
83+
</div>
84+
{{else}}
85+
{{!TODO: display a deprecation warning when the user isn't using the block version}}
86+
<div class="au-c-loader {{this.padding}}" ...attributes>
87+
<div class="au-c-loader__animation" aria-hidden="true"></div>
88+
{{#unless this.disableMessage}}
89+
<span class="au-u-hidden-visually">{{this.message}}</span>
90+
{{/unless}}
91+
</div>
92+
{{/if}}
3093
</template>
3194
}

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

+12-10
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ 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+
hiddenMessage: {
1615
control: 'boolean',
1716
description: 'Remove the loading text',
1817
},
@@ -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+
@hiddenMessage={{this.hiddenMessage}}
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+
hiddenMessage: false,
3638
};

styles/components/_c-loader.scss

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

12+
// Overrides for the default loader, to keep backwards compatibility.
13+
// merge these with the base styles when we drop support for the previous implementation.
14+
.au-c-loader--new {
15+
text-align: center;
16+
.au-c-loader__animation {
17+
display: inline-block;
18+
width: 3rem;
19+
height: 1.8rem;
20+
}
21+
}
22+
1223
.au-c-loader__animation {
1324
display: block;
1425
position: relative;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<AuLoader>Pagina is aan het laden</AuLoader>
2+
<AuLoader @inline={{true}}>Pagina is aan het laden</AuLoader>
3+
<AuLoader />

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,11 +1,43 @@
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+
});
22+
23+
test('it supports visually hiding the loading text', async function (assert) {
24+
await render(
25+
<template>
26+
<AuLoader @hiddenMessage={{true}}>
27+
Pagina is aan het laden
28+
</AuLoader>
29+
</template>,
30+
);
31+
32+
const root = getRootElement() as HTMLElement;
33+
const text = queryByText(root, 'Pagina is aan het laden') as HTMLElement;
34+
35+
// Hacky way to test if the text is visible.
36+
// `assert.dom(text).isNotVisible()` doesn't work here because of the styles we use for the au-u-hidden-visually class.
37+
assert.true(text.offsetHeight <= 1);
38+
assert.true(text.offsetWidth <= 1);
39+
});
40+
941
test('it renders a hidden loading text for screen readers', async function (assert) {
1042
await render(<template><AuLoader /></template>);
1143

@@ -16,11 +48,25 @@ module('Integration | Component | au-loader', function (hooks) {
1648
await render(<template><AuLoader @message="Loading" /></template>);
1749

1850
assert.dom().hasText('Loading');
51+
assert.true(
52+
hasDeprecationStartingWith('[AuLoader] `@message` is deprecated.'),
53+
);
1954
});
2055

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

2459
assert.dom().hasNoText();
60+
assert.true(
61+
hasDeprecationStartingWith('[AuLoader] `@disableMessage` is deprecated.'),
62+
);
63+
});
64+
65+
test('@padding shows a deprecation', async function (assert) {
66+
await render(<template><AuLoader @padding="small" /></template>);
67+
68+
assert.true(
69+
hasDeprecationStartingWith('[AuLoader] `@padding` is deprecated.'),
70+
);
2571
});
2672
});

0 commit comments

Comments
 (0)