@aleph-alpha/ui-library 7.2.1 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.js +6 -0
- package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
- package/dist/system/components/UiSpinner/UiSpinner.vue.d.ts +1 -3
- package/dist/system/components/UiSpinner/index.d.ts +1 -1
- package/dist/system/components/UiSpinner/types.d.ts +19 -6
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/icons/story-sidebar-icons.json +2 -0
- package/dist/system/lib.js +7081 -6851
- package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
- package/dist/system/patterns/UiHeadline/UiHeadline.vue.d.ts +204 -0
- package/dist/system/patterns/UiHeadline/index.d.ts +2 -0
- package/dist/system/patterns/UiHeadline/types.d.ts +64 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +2 -0
- package/package.json +1 -1
- package/src/components/UiField/UiField.stories.ts +302 -0
- package/src/components/UiSpinner/UiSpinner.stories.ts +579 -6
- package/src/components/UiSpinner/UiSpinner.vue +76 -4
- package/src/components/UiSpinner/__tests__/UiSpinner.test.ts +79 -0
- package/src/components/UiSpinner/index.ts +1 -1
- package/src/components/UiSpinner/types.ts +21 -6
- package/src/components/core/input/Input.vue +1 -1
- package/src/components/core/input-group/InputGroupInput.vue +1 -1
- package/src/components/core/native-select/NativeSelect.vue +1 -1
- package/src/patterns/UiHeadline/UiHeadline.guidance.md +53 -0
- package/src/patterns/UiHeadline/UiHeadline.stories.ts +915 -0
- package/src/patterns/UiHeadline/UiHeadline.vue +203 -0
- package/src/patterns/UiHeadline/__tests__/UiHeadline.test.ts +204 -0
- package/src/patterns/UiHeadline/index.ts +2 -0
- package/src/patterns/UiHeadline/types.ts +73 -0
- package/src/patterns/index.ts +1 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
-
import {
|
|
2
|
+
import { ref, type Ref } from 'vue';
|
|
3
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
3
4
|
import UiSpinner from './UiSpinner.vue';
|
|
5
|
+
import type { UiSpinnerStatus } from './types';
|
|
6
|
+
import {
|
|
7
|
+
UiField,
|
|
8
|
+
UiFieldDescription,
|
|
9
|
+
UiFieldError,
|
|
10
|
+
UiFieldLabel,
|
|
11
|
+
} from '../UiField';
|
|
12
|
+
import { UiInput } from '../UiInput';
|
|
4
13
|
import {
|
|
5
14
|
accessibilityStory,
|
|
6
15
|
designNotesStory,
|
|
@@ -12,18 +21,28 @@ import guidanceMarkdown from './UiSpinner.guidance.md?raw';
|
|
|
12
21
|
const guidance = parseGuidance(guidanceMarkdown);
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
|
-
* UiSpinner is a circular
|
|
16
|
-
*
|
|
24
|
+
* UiSpinner is a circular indicator for indeterminate work, and for the
|
|
25
|
+
* outcome of an inline save. Omit `status` for the compact spinner inside a
|
|
26
|
+
* button or beside text. Set `status` for the 24px indicator inside a field:
|
|
27
|
+
* it fades from the spinner to a circle icon. Success needs no message.
|
|
28
|
+
* Warning and error are accompanied by a message below the input.
|
|
29
|
+
* For percentage-known progress, use `UiProgress`.
|
|
17
30
|
*/
|
|
18
31
|
const meta: Meta<typeof UiSpinner> = {
|
|
19
32
|
title: 'Components/UiSpinner',
|
|
20
33
|
component: UiSpinner,
|
|
21
34
|
tags: ['autodocs'],
|
|
22
35
|
argTypes: {
|
|
36
|
+
status: {
|
|
37
|
+
control: 'select',
|
|
38
|
+
options: ['loading', 'success', 'warning', 'error'],
|
|
39
|
+
description:
|
|
40
|
+
'Field indicator. Loading is a 24px spinner. Success, warning, and error replace it with a circle icon and fade between them. Omit it for the compact spinner.',
|
|
41
|
+
},
|
|
23
42
|
ariaLabel: {
|
|
24
43
|
control: 'text',
|
|
25
44
|
description:
|
|
26
|
-
'Accessible
|
|
45
|
+
'Accessible name for the current status. Defaults to Loading, or to Success, Warning, or Error when status is set. Update it when the status changes so the announcement matches the outcome.',
|
|
27
46
|
},
|
|
28
47
|
class: {
|
|
29
48
|
control: 'text',
|
|
@@ -59,7 +78,8 @@ export const Default: Story = {
|
|
|
59
78
|
setup() {
|
|
60
79
|
return { args };
|
|
61
80
|
},
|
|
62
|
-
template:
|
|
81
|
+
template:
|
|
82
|
+
'<UiSpinner :status="args.status" :aria-label="args.ariaLabel" :class="args.class" />',
|
|
63
83
|
}),
|
|
64
84
|
parameters: {
|
|
65
85
|
docs: {
|
|
@@ -99,10 +119,36 @@ export const DesignNotes: Story = {
|
|
|
99
119
|
export const Accessibility: Story = {
|
|
100
120
|
...accessibilityStory({
|
|
101
121
|
requirements: guidance.accessibility,
|
|
122
|
+
implementation: [
|
|
123
|
+
'Omit status for the compact spinner. Set status for the 24px field indicator, whose accessible name changes with the status.',
|
|
124
|
+
'Icons for a set status are decorative. Pass ariaLabel when Loading, Success, Warning, or Error is not specific enough, and change it together with status.',
|
|
125
|
+
'The loading spin and the fade to the next status are removed when the user prefers reduced motion.',
|
|
126
|
+
'Associate a warning or error message with the input through aria-describedby. Mark an error invalid with aria-invalid and data-invalid="true" on the field.',
|
|
127
|
+
],
|
|
102
128
|
example: {
|
|
103
129
|
components: { UiSpinner },
|
|
104
130
|
template: `
|
|
105
|
-
<
|
|
131
|
+
<div class="flex flex-col items-center gap-6">
|
|
132
|
+
<UiSpinner aria-label="Loading results" />
|
|
133
|
+
<div class="flex flex-wrap items-end justify-center gap-6">
|
|
134
|
+
<div class="flex flex-col items-center gap-2">
|
|
135
|
+
<UiSpinner status="loading" />
|
|
136
|
+
<span class="label-xs-regular text-content-on-surface-muted">Loading</span>
|
|
137
|
+
</div>
|
|
138
|
+
<div class="flex flex-col items-center gap-2">
|
|
139
|
+
<UiSpinner status="success" />
|
|
140
|
+
<span class="label-xs-regular text-content-on-surface-muted">Success</span>
|
|
141
|
+
</div>
|
|
142
|
+
<div class="flex flex-col items-center gap-2">
|
|
143
|
+
<UiSpinner status="warning" />
|
|
144
|
+
<span class="label-xs-regular text-content-on-surface-muted">Warning</span>
|
|
145
|
+
</div>
|
|
146
|
+
<div class="flex flex-col items-center gap-2">
|
|
147
|
+
<UiSpinner status="error" />
|
|
148
|
+
<span class="label-xs-regular text-content-on-surface-muted">Error</span>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</div>
|
|
106
152
|
`,
|
|
107
153
|
},
|
|
108
154
|
}),
|
|
@@ -199,6 +245,533 @@ export const InlineWithText: Story = {
|
|
|
199
245
|
},
|
|
200
246
|
};
|
|
201
247
|
|
|
248
|
+
const successStatus = ref<UiSpinnerStatus>('loading');
|
|
249
|
+
const warningStatus = ref<UiSpinnerStatus>('loading');
|
|
250
|
+
const errorStatus = ref<UiSpinnerStatus>('loading');
|
|
251
|
+
const outcomeTimers = new Map<
|
|
252
|
+
Ref<UiSpinnerStatus>,
|
|
253
|
+
ReturnType<typeof setTimeout>
|
|
254
|
+
>();
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Shows the spinner, then fades to the outcome. The play function restarts
|
|
258
|
+
* the same sequence so the assertion always sees the loading state first.
|
|
259
|
+
* @param status - Status ref the story renders.
|
|
260
|
+
* @param next - Outcome that replaces the spinner.
|
|
261
|
+
*/
|
|
262
|
+
function showLoadingThen(
|
|
263
|
+
status: Ref<UiSpinnerStatus>,
|
|
264
|
+
next: Exclude<UiSpinnerStatus, 'loading'>,
|
|
265
|
+
) {
|
|
266
|
+
clearTimeout(outcomeTimers.get(status));
|
|
267
|
+
status.value = 'loading';
|
|
268
|
+
outcomeTimers.set(
|
|
269
|
+
status,
|
|
270
|
+
setTimeout(() => {
|
|
271
|
+
status.value = next;
|
|
272
|
+
}, 600),
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const fieldLoadingTemplateSource = `<script setup lang="ts">
|
|
277
|
+
import { ref } from 'vue'
|
|
278
|
+
import { UiField, UiFieldLabel, UiInput, UiSpinner } from '@aleph-alpha/ui-library'
|
|
279
|
+
|
|
280
|
+
const name = ref('Ada Lovelace')
|
|
281
|
+
</script>
|
|
282
|
+
|
|
283
|
+
<template>
|
|
284
|
+
<UiField class="max-w-sm">
|
|
285
|
+
<UiFieldLabel for="display-name">Display name</UiFieldLabel>
|
|
286
|
+
<UiInput id="display-name" v-model="name" name="display-name" aria-busy="true">
|
|
287
|
+
<template #end>
|
|
288
|
+
<UiSpinner status="loading" />
|
|
289
|
+
</template>
|
|
290
|
+
</UiInput>
|
|
291
|
+
</UiField>
|
|
292
|
+
</template>`;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 24px spinner inside the field while the value is saving.
|
|
296
|
+
*/
|
|
297
|
+
export const FieldLoading: Story = {
|
|
298
|
+
name: 'status spinner - Loading',
|
|
299
|
+
args: { status: 'loading' },
|
|
300
|
+
render: (args) => ({
|
|
301
|
+
components: { UiField, UiFieldLabel, UiInput, UiSpinner },
|
|
302
|
+
setup() {
|
|
303
|
+
const name = ref('Ada Lovelace');
|
|
304
|
+
return { args, name };
|
|
305
|
+
},
|
|
306
|
+
template: `
|
|
307
|
+
<UiField class="max-w-sm">
|
|
308
|
+
<UiFieldLabel for="display-name">Display name</UiFieldLabel>
|
|
309
|
+
<UiInput
|
|
310
|
+
id="display-name"
|
|
311
|
+
v-model="name"
|
|
312
|
+
name="display-name"
|
|
313
|
+
:aria-busy="args.status === 'loading'"
|
|
314
|
+
>
|
|
315
|
+
<template #end>
|
|
316
|
+
<UiSpinner :status="args.status" :aria-label="args.ariaLabel" />
|
|
317
|
+
</template>
|
|
318
|
+
</UiInput>
|
|
319
|
+
</UiField>
|
|
320
|
+
`,
|
|
321
|
+
}),
|
|
322
|
+
parameters: {
|
|
323
|
+
docs: {
|
|
324
|
+
source: {
|
|
325
|
+
code: fieldLoadingTemplateSource,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
play: async ({ canvasElement, step }) => {
|
|
330
|
+
// Scenario (UiSpinner): a field that is still saving exposes a busy
|
|
331
|
+
// textbox and a 24px spinner named for the wait.
|
|
332
|
+
const canvas = within(canvasElement);
|
|
333
|
+
const input = canvas.getByRole('textbox', { name: 'Display name' });
|
|
334
|
+
const status = canvas.getByRole('status', { name: 'Loading' });
|
|
335
|
+
|
|
336
|
+
await step(
|
|
337
|
+
'interaction: the field is busy and the spinner is a 24px status',
|
|
338
|
+
async () => {
|
|
339
|
+
await expect(input).toHaveAttribute('aria-busy', 'true');
|
|
340
|
+
await expect(status).toHaveAttribute('data-status', 'loading');
|
|
341
|
+
const icon = status.querySelector('svg');
|
|
342
|
+
await expect(icon).not.toBeNull();
|
|
343
|
+
if (!icon) return;
|
|
344
|
+
const { width, height } = icon.getBoundingClientRect();
|
|
345
|
+
await expect(Math.round(width)).toBe(24);
|
|
346
|
+
await expect(Math.round(height)).toBe(24);
|
|
347
|
+
await expect(icon).toHaveClass('animate-spin');
|
|
348
|
+
},
|
|
349
|
+
);
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const successTemplateSource = `<script setup lang="ts">
|
|
354
|
+
import { onMounted, ref } from 'vue'
|
|
355
|
+
import { UiField, UiFieldLabel, UiInput, UiSpinner } from '@aleph-alpha/ui-library'
|
|
356
|
+
|
|
357
|
+
const name = ref('Ada Lovelace')
|
|
358
|
+
const status = ref<'loading' | 'success'>('loading')
|
|
359
|
+
const label = ref('Saving')
|
|
360
|
+
|
|
361
|
+
onMounted(() => {
|
|
362
|
+
window.setTimeout(() => {
|
|
363
|
+
status.value = 'success'
|
|
364
|
+
label.value = 'Saved'
|
|
365
|
+
}, 600)
|
|
366
|
+
})
|
|
367
|
+
</script>
|
|
368
|
+
|
|
369
|
+
<template>
|
|
370
|
+
<UiField class="max-w-sm">
|
|
371
|
+
<UiFieldLabel for="display-name-saved">Display name</UiFieldLabel>
|
|
372
|
+
<UiInput id="display-name-saved" v-model="name" name="display-name">
|
|
373
|
+
<template #end>
|
|
374
|
+
<UiSpinner :status="status" :aria-label="label" />
|
|
375
|
+
</template>
|
|
376
|
+
</UiInput>
|
|
377
|
+
</UiField>
|
|
378
|
+
</template>`;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Loads after a standard loading spinner. No message required.
|
|
382
|
+
*/
|
|
383
|
+
export const Success: Story = {
|
|
384
|
+
name: 'status spinner - Success',
|
|
385
|
+
render: () => ({
|
|
386
|
+
components: { UiField, UiFieldLabel, UiInput, UiSpinner },
|
|
387
|
+
setup() {
|
|
388
|
+
const name = ref('Ada Lovelace');
|
|
389
|
+
showLoadingThen(successStatus, 'success');
|
|
390
|
+
return { name, successStatus };
|
|
391
|
+
},
|
|
392
|
+
template: `
|
|
393
|
+
<UiField class="max-w-sm">
|
|
394
|
+
<UiFieldLabel for="display-name-saved">Display name</UiFieldLabel>
|
|
395
|
+
<UiInput id="display-name-saved" v-model="name" name="display-name">
|
|
396
|
+
<template #end>
|
|
397
|
+
<UiSpinner
|
|
398
|
+
:status="successStatus"
|
|
399
|
+
:aria-label="successStatus === 'loading' ? 'Saving' : 'Saved'"
|
|
400
|
+
/>
|
|
401
|
+
</template>
|
|
402
|
+
</UiInput>
|
|
403
|
+
</UiField>
|
|
404
|
+
`,
|
|
405
|
+
}),
|
|
406
|
+
parameters: {
|
|
407
|
+
controls: { disable: true },
|
|
408
|
+
docs: {
|
|
409
|
+
source: {
|
|
410
|
+
code: successTemplateSource,
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
play: async ({ canvasElement, step }) => {
|
|
415
|
+
// Scenario (UiSpinner): saving starts as a spinner, then fades to
|
|
416
|
+
// success. The field stays valid and no message is added below it.
|
|
417
|
+
showLoadingThen(successStatus, 'success');
|
|
418
|
+
const canvas = within(canvasElement);
|
|
419
|
+
const input = canvas.getByRole('textbox', { name: 'Display name' });
|
|
420
|
+
|
|
421
|
+
await step(
|
|
422
|
+
'interaction: saving starts as the loading spinner',
|
|
423
|
+
async () => {
|
|
424
|
+
const status = canvas.getByRole('status', { name: 'Saving' });
|
|
425
|
+
await expect(status).toHaveAttribute('data-status', 'loading');
|
|
426
|
+
await expect(status.querySelector('svg')).toHaveClass('animate-spin');
|
|
427
|
+
await expect(input).not.toHaveAttribute('aria-invalid');
|
|
428
|
+
await expect(canvas.queryByRole('alert')).not.toBeInTheDocument();
|
|
429
|
+
},
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
await step(
|
|
433
|
+
'interaction: the spinner fades to success with no message below the input',
|
|
434
|
+
async () => {
|
|
435
|
+
await waitFor(
|
|
436
|
+
() => {
|
|
437
|
+
const status = canvas.getByRole('status', { name: 'Saved' });
|
|
438
|
+
const icon = status.querySelector('.lucide-circle-check');
|
|
439
|
+
expect(icon).not.toBeNull();
|
|
440
|
+
expect(getComputedStyle(icon as Element).opacity).toBe('1');
|
|
441
|
+
expect(status.querySelector('.animate-spin')).toBeNull();
|
|
442
|
+
},
|
|
443
|
+
{ timeout: 2000 },
|
|
444
|
+
);
|
|
445
|
+
await expect(input).not.toHaveAttribute('aria-invalid');
|
|
446
|
+
await expect(canvas.queryByRole('alert')).not.toBeInTheDocument();
|
|
447
|
+
await expect(canvas.queryByRole('status')).toHaveAttribute(
|
|
448
|
+
'data-status',
|
|
449
|
+
'success',
|
|
450
|
+
);
|
|
451
|
+
},
|
|
452
|
+
);
|
|
453
|
+
},
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
const warningTemplateSource = `<script setup lang="ts">
|
|
457
|
+
import { onMounted, ref } from 'vue'
|
|
458
|
+
import {
|
|
459
|
+
UiField,
|
|
460
|
+
UiFieldDescription,
|
|
461
|
+
UiFieldLabel,
|
|
462
|
+
UiInput,
|
|
463
|
+
UiSpinner,
|
|
464
|
+
} from '@aleph-alpha/ui-library'
|
|
465
|
+
|
|
466
|
+
const name = ref('Ada Lovelace')
|
|
467
|
+
const status = ref<'loading' | 'warning'>('loading')
|
|
468
|
+
const label = ref('Saving')
|
|
469
|
+
|
|
470
|
+
onMounted(() => {
|
|
471
|
+
window.setTimeout(() => {
|
|
472
|
+
status.value = 'warning'
|
|
473
|
+
label.value = 'Warning'
|
|
474
|
+
}, 600)
|
|
475
|
+
})
|
|
476
|
+
</script>
|
|
477
|
+
|
|
478
|
+
<template>
|
|
479
|
+
<UiField class="max-w-sm">
|
|
480
|
+
<UiFieldLabel for="display-name-warning">Display name</UiFieldLabel>
|
|
481
|
+
<UiInput
|
|
482
|
+
id="display-name-warning"
|
|
483
|
+
v-model="name"
|
|
484
|
+
name="display-name"
|
|
485
|
+
:aria-describedby="status === 'warning' ? 'display-name-warning-message' : undefined"
|
|
486
|
+
>
|
|
487
|
+
<template #end>
|
|
488
|
+
<UiSpinner :status="status" :aria-label="label" />
|
|
489
|
+
</template>
|
|
490
|
+
</UiInput>
|
|
491
|
+
<UiFieldDescription
|
|
492
|
+
v-if="status === 'warning'"
|
|
493
|
+
id="display-name-warning-message"
|
|
494
|
+
class="text-background-status-warning"
|
|
495
|
+
>
|
|
496
|
+
This name is already used by another workspace.
|
|
497
|
+
</UiFieldDescription>
|
|
498
|
+
</UiField>
|
|
499
|
+
</template>`;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Loads after a standard loading spinner. Use for a warning status
|
|
503
|
+
* accompanied by a message below the input.
|
|
504
|
+
*/
|
|
505
|
+
export const Warning: Story = {
|
|
506
|
+
name: 'status spinner - Warning',
|
|
507
|
+
render: () => ({
|
|
508
|
+
components: {
|
|
509
|
+
UiField,
|
|
510
|
+
UiFieldDescription,
|
|
511
|
+
UiFieldLabel,
|
|
512
|
+
UiInput,
|
|
513
|
+
UiSpinner,
|
|
514
|
+
},
|
|
515
|
+
setup() {
|
|
516
|
+
const name = ref('Ada Lovelace');
|
|
517
|
+
showLoadingThen(warningStatus, 'warning');
|
|
518
|
+
return { name, warningStatus };
|
|
519
|
+
},
|
|
520
|
+
template: `
|
|
521
|
+
<UiField class="max-w-sm">
|
|
522
|
+
<UiFieldLabel for="display-name-warning">Display name</UiFieldLabel>
|
|
523
|
+
<UiInput
|
|
524
|
+
id="display-name-warning"
|
|
525
|
+
v-model="name"
|
|
526
|
+
name="display-name"
|
|
527
|
+
:aria-describedby="warningStatus === 'warning' ? 'display-name-warning-message' : undefined"
|
|
528
|
+
>
|
|
529
|
+
<template #end>
|
|
530
|
+
<UiSpinner
|
|
531
|
+
:status="warningStatus"
|
|
532
|
+
:aria-label="warningStatus === 'loading' ? 'Saving' : 'Warning'"
|
|
533
|
+
/>
|
|
534
|
+
</template>
|
|
535
|
+
</UiInput>
|
|
536
|
+
<UiFieldDescription
|
|
537
|
+
v-if="warningStatus === 'warning'"
|
|
538
|
+
id="display-name-warning-message"
|
|
539
|
+
class="text-background-status-warning"
|
|
540
|
+
>
|
|
541
|
+
This name is already used by another workspace.
|
|
542
|
+
</UiFieldDescription>
|
|
543
|
+
</UiField>
|
|
544
|
+
`,
|
|
545
|
+
}),
|
|
546
|
+
parameters: {
|
|
547
|
+
controls: { disable: true },
|
|
548
|
+
docs: {
|
|
549
|
+
source: {
|
|
550
|
+
code: warningTemplateSource,
|
|
551
|
+
},
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
play: async ({ canvasElement, step }) => {
|
|
555
|
+
// Scenario (UiSpinner): saving starts as a spinner, then fades to a
|
|
556
|
+
// warning with a message under the input. The field stays editable.
|
|
557
|
+
showLoadingThen(warningStatus, 'warning');
|
|
558
|
+
const canvas = within(canvasElement);
|
|
559
|
+
const input = canvas.getByRole('textbox', { name: 'Display name' });
|
|
560
|
+
const warningMessage = 'This name is already used by another workspace.';
|
|
561
|
+
|
|
562
|
+
await step(
|
|
563
|
+
'interaction: saving starts as the loading spinner',
|
|
564
|
+
async () => {
|
|
565
|
+
const status = canvas.getByRole('status', { name: 'Saving' });
|
|
566
|
+
await expect(status).toHaveAttribute('data-status', 'loading');
|
|
567
|
+
await expect(status.querySelector('svg')).toHaveClass('animate-spin');
|
|
568
|
+
await expect(
|
|
569
|
+
canvas.queryByText(warningMessage),
|
|
570
|
+
).not.toBeInTheDocument();
|
|
571
|
+
await expect(input).not.toHaveAttribute('aria-invalid', 'true');
|
|
572
|
+
},
|
|
573
|
+
);
|
|
574
|
+
|
|
575
|
+
await step(
|
|
576
|
+
'interaction: the spinner fades to a warning with a message below the input',
|
|
577
|
+
async () => {
|
|
578
|
+
await waitFor(
|
|
579
|
+
() => {
|
|
580
|
+
const status = canvas.getByRole('status', { name: 'Warning' });
|
|
581
|
+
const icon = status.querySelector('.lucide-circle-alert');
|
|
582
|
+
expect(icon).not.toBeNull();
|
|
583
|
+
expect(getComputedStyle(icon as Element).opacity).toBe('1');
|
|
584
|
+
expect(status.querySelector('.animate-spin')).toBeNull();
|
|
585
|
+
expect(canvas.getByText(warningMessage)).toBeVisible();
|
|
586
|
+
},
|
|
587
|
+
{ timeout: 2000 },
|
|
588
|
+
);
|
|
589
|
+
const icon = canvas
|
|
590
|
+
.getByRole('status', { name: 'Warning' })
|
|
591
|
+
.querySelector('svg');
|
|
592
|
+
await expect(icon).not.toBeNull();
|
|
593
|
+
if (!icon) return;
|
|
594
|
+
const { width, height } = icon.getBoundingClientRect();
|
|
595
|
+
await expect(Math.round(width)).toBe(24);
|
|
596
|
+
await expect(Math.round(height)).toBe(24);
|
|
597
|
+
await expect(input).toHaveAttribute(
|
|
598
|
+
'aria-describedby',
|
|
599
|
+
'display-name-warning-message',
|
|
600
|
+
);
|
|
601
|
+
await expect(input).not.toHaveAttribute('aria-invalid', 'true');
|
|
602
|
+
},
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
await step(
|
|
606
|
+
'screen-reader: the warning status and its message are available to the field (WCAG 1.3.1)',
|
|
607
|
+
async () => {
|
|
608
|
+
await expect(
|
|
609
|
+
canvas.getByRole('status', { name: 'Warning' }),
|
|
610
|
+
).toHaveAccessibleName('Warning');
|
|
611
|
+
await expect(canvas.getByText(warningMessage)).toHaveAttribute(
|
|
612
|
+
'id',
|
|
613
|
+
'display-name-warning-message',
|
|
614
|
+
);
|
|
615
|
+
},
|
|
616
|
+
);
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
const errorTemplateSource = `<script setup lang="ts">
|
|
621
|
+
import { onMounted, ref } from 'vue'
|
|
622
|
+
import {
|
|
623
|
+
UiField,
|
|
624
|
+
UiFieldError,
|
|
625
|
+
UiFieldLabel,
|
|
626
|
+
UiInput,
|
|
627
|
+
UiSpinner,
|
|
628
|
+
} from '@aleph-alpha/ui-library'
|
|
629
|
+
|
|
630
|
+
const name = ref('Ada Lovelace')
|
|
631
|
+
const status = ref<'loading' | 'error'>('loading')
|
|
632
|
+
const label = ref('Saving')
|
|
633
|
+
|
|
634
|
+
onMounted(() => {
|
|
635
|
+
window.setTimeout(() => {
|
|
636
|
+
status.value = 'error'
|
|
637
|
+
label.value = 'Failed to save'
|
|
638
|
+
}, 600)
|
|
639
|
+
})
|
|
640
|
+
</script>
|
|
641
|
+
|
|
642
|
+
<template>
|
|
643
|
+
<UiField class="max-w-sm" :data-invalid="status === 'error' ? 'true' : undefined">
|
|
644
|
+
<UiFieldLabel for="display-name-error">Display name</UiFieldLabel>
|
|
645
|
+
<UiInput
|
|
646
|
+
id="display-name-error"
|
|
647
|
+
v-model="name"
|
|
648
|
+
name="display-name"
|
|
649
|
+
:aria-invalid="status === 'error'"
|
|
650
|
+
:aria-describedby="status === 'error' ? 'display-name-error-message' : undefined"
|
|
651
|
+
>
|
|
652
|
+
<template #end>
|
|
653
|
+
<UiSpinner :status="status" :aria-label="label" />
|
|
654
|
+
</template>
|
|
655
|
+
</UiInput>
|
|
656
|
+
<UiFieldError v-if="status === 'error'" id="display-name-error-message">
|
|
657
|
+
<span class="block">Failed to save</span>
|
|
658
|
+
Check your connection and try again.
|
|
659
|
+
</UiFieldError>
|
|
660
|
+
</UiField>
|
|
661
|
+
</template>`;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Loads after a standard loading spinner. Use for an error status, for
|
|
665
|
+
* example "Failed to save", accompanied by an error message below the input.
|
|
666
|
+
*/
|
|
667
|
+
export const ErrorStatus: Story = {
|
|
668
|
+
name: 'status spinner - Error',
|
|
669
|
+
render: () => ({
|
|
670
|
+
components: {
|
|
671
|
+
UiField,
|
|
672
|
+
UiFieldError,
|
|
673
|
+
UiFieldLabel,
|
|
674
|
+
UiInput,
|
|
675
|
+
UiSpinner,
|
|
676
|
+
},
|
|
677
|
+
setup() {
|
|
678
|
+
const name = ref('Ada Lovelace');
|
|
679
|
+
showLoadingThen(errorStatus, 'error');
|
|
680
|
+
return { name, errorStatus };
|
|
681
|
+
},
|
|
682
|
+
template: `
|
|
683
|
+
<UiField class="max-w-sm" :data-invalid="errorStatus === 'error' ? 'true' : undefined">
|
|
684
|
+
<UiFieldLabel for="display-name-error">Display name</UiFieldLabel>
|
|
685
|
+
<UiInput
|
|
686
|
+
id="display-name-error"
|
|
687
|
+
v-model="name"
|
|
688
|
+
name="display-name"
|
|
689
|
+
:aria-invalid="errorStatus === 'error'"
|
|
690
|
+
:aria-describedby="errorStatus === 'error' ? 'display-name-error-message' : undefined"
|
|
691
|
+
>
|
|
692
|
+
<template #end>
|
|
693
|
+
<UiSpinner
|
|
694
|
+
:status="errorStatus"
|
|
695
|
+
:aria-label="errorStatus === 'loading' ? 'Saving' : 'Failed to save'"
|
|
696
|
+
/>
|
|
697
|
+
</template>
|
|
698
|
+
</UiInput>
|
|
699
|
+
<UiFieldError v-if="errorStatus === 'error'" id="display-name-error-message">
|
|
700
|
+
<span class="block">Failed to save</span>
|
|
701
|
+
Check your connection and try again.
|
|
702
|
+
</UiFieldError>
|
|
703
|
+
</UiField>
|
|
704
|
+
`,
|
|
705
|
+
}),
|
|
706
|
+
parameters: {
|
|
707
|
+
controls: { disable: true },
|
|
708
|
+
docs: {
|
|
709
|
+
source: {
|
|
710
|
+
code: errorTemplateSource,
|
|
711
|
+
},
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
play: async ({ canvasElement, step }) => {
|
|
715
|
+
// Scenario (UiSpinner): saving starts as a spinner, then fades to a
|
|
716
|
+
// failure. The field becomes invalid and the reason appears under it.
|
|
717
|
+
showLoadingThen(errorStatus, 'error');
|
|
718
|
+
const canvas = within(canvasElement);
|
|
719
|
+
const input = canvas.getByRole('textbox', { name: 'Display name' });
|
|
720
|
+
|
|
721
|
+
await step(
|
|
722
|
+
'interaction: saving starts as the loading spinner',
|
|
723
|
+
async () => {
|
|
724
|
+
const status = canvas.getByRole('status', { name: 'Saving' });
|
|
725
|
+
await expect(status).toHaveAttribute('data-status', 'loading');
|
|
726
|
+
await expect(status.querySelector('svg')).toHaveClass('animate-spin');
|
|
727
|
+
await expect(canvas.queryByRole('alert')).not.toBeInTheDocument();
|
|
728
|
+
await expect(input).not.toHaveAttribute('aria-invalid', 'true');
|
|
729
|
+
},
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
await step(
|
|
733
|
+
'interaction: the spinner fades to an error, "Failed to save", and a message below the input',
|
|
734
|
+
async () => {
|
|
735
|
+
await waitFor(
|
|
736
|
+
() => {
|
|
737
|
+
const status = canvas.getByRole('status', {
|
|
738
|
+
name: 'Failed to save',
|
|
739
|
+
});
|
|
740
|
+
const icon = status.querySelector('.lucide-circle-x');
|
|
741
|
+
expect(icon).not.toBeNull();
|
|
742
|
+
expect(getComputedStyle(icon as Element).opacity).toBe('1');
|
|
743
|
+
expect(status.querySelector('.animate-spin')).toBeNull();
|
|
744
|
+
expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
745
|
+
'Failed to save',
|
|
746
|
+
);
|
|
747
|
+
},
|
|
748
|
+
{ timeout: 2000 },
|
|
749
|
+
);
|
|
750
|
+
await expect(input).toHaveAttribute('aria-invalid', 'true');
|
|
751
|
+
await expect(input).toHaveAttribute(
|
|
752
|
+
'aria-describedby',
|
|
753
|
+
'display-name-error-message',
|
|
754
|
+
);
|
|
755
|
+
await expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
756
|
+
'Check your connection and try again.',
|
|
757
|
+
);
|
|
758
|
+
},
|
|
759
|
+
);
|
|
760
|
+
|
|
761
|
+
await step(
|
|
762
|
+
'screen-reader: the error is announced and tied to the invalid field (WCAG 3.3.1)',
|
|
763
|
+
async () => {
|
|
764
|
+
await expect(
|
|
765
|
+
canvas.getByRole('status', { name: 'Failed to save' }),
|
|
766
|
+
).toBeVisible();
|
|
767
|
+
await expect(canvas.getByRole('alert')).toHaveTextContent(
|
|
768
|
+
'Failed to save',
|
|
769
|
+
);
|
|
770
|
+
},
|
|
771
|
+
);
|
|
772
|
+
},
|
|
773
|
+
};
|
|
774
|
+
|
|
202
775
|
const renderTestSpinners = () => ({
|
|
203
776
|
components: { UiSpinner },
|
|
204
777
|
template: `
|