@aleph-alpha/ui-library 7.2.0 → 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.
Files changed (32) hide show
  1. package/config.js +6 -0
  2. package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
  3. package/dist/system/components/UiSpinner/UiSpinner.vue.d.ts +1 -3
  4. package/dist/system/components/UiSpinner/index.d.ts +1 -1
  5. package/dist/system/components/UiSpinner/types.d.ts +19 -6
  6. package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
  7. package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
  8. package/dist/system/icons/story-sidebar-icons.json +2 -0
  9. package/dist/system/lib.js +7081 -6851
  10. package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
  11. package/dist/system/patterns/UiHeadline/UiHeadline.vue.d.ts +204 -0
  12. package/dist/system/patterns/UiHeadline/index.d.ts +2 -0
  13. package/dist/system/patterns/UiHeadline/types.d.ts +64 -0
  14. package/dist/system/patterns/index.d.ts +1 -0
  15. package/dist/system/story-sidebar-icons.json +2 -0
  16. package/package.json +10 -5
  17. package/src/components/UiField/UiField.stories.ts +302 -0
  18. package/src/components/UiSpinner/UiSpinner.stories.ts +579 -6
  19. package/src/components/UiSpinner/UiSpinner.vue +76 -4
  20. package/src/components/UiSpinner/__tests__/UiSpinner.test.ts +79 -0
  21. package/src/components/UiSpinner/index.ts +1 -1
  22. package/src/components/UiSpinner/types.ts +21 -6
  23. package/src/components/core/input/Input.vue +1 -1
  24. package/src/components/core/input-group/InputGroupInput.vue +1 -1
  25. package/src/components/core/native-select/NativeSelect.vue +1 -1
  26. package/src/patterns/UiHeadline/UiHeadline.guidance.md +53 -0
  27. package/src/patterns/UiHeadline/UiHeadline.stories.ts +915 -0
  28. package/src/patterns/UiHeadline/UiHeadline.vue +203 -0
  29. package/src/patterns/UiHeadline/__tests__/UiHeadline.test.ts +204 -0
  30. package/src/patterns/UiHeadline/index.ts +2 -0
  31. package/src/patterns/UiHeadline/types.ts +73 -0
  32. package/src/patterns/index.ts +1 -0
@@ -1,16 +1,88 @@
1
1
  <script setup lang="ts">
2
+ import { computed, useAttrs } from 'vue';
2
3
  import { Spinner as ShadcnSpinner } from '@/components/core/spinner';
3
- import type { UiSpinnerProps } from './types';
4
+ import { UiIcon } from '@/components/UiIcon';
5
+ import {
6
+ CircleAlertIcon,
7
+ CircleCheckIcon,
8
+ CircleXIcon,
9
+ LoaderCircleIcon,
10
+ } from '@/icons/lucide';
11
+ import type { ClassValue } from 'clsx';
12
+ import { cn, omitClass } from '@/lib/utils';
13
+ import type { UiSpinnerProps, UiSpinnerStatus } from './types';
4
14
 
5
15
  defineOptions({
6
16
  name: 'UiSpinner',
17
+ inheritAttrs: false,
7
18
  });
8
19
 
9
- const props = withDefaults(defineProps<UiSpinnerProps>(), {
10
- ariaLabel: 'Loading',
20
+ const props = defineProps<UiSpinnerProps>();
21
+ const attrs = useAttrs();
22
+
23
+ const STATUS_LABELS = {
24
+ loading: 'Loading',
25
+ success: 'Success',
26
+ warning: 'Warning',
27
+ error: 'Error',
28
+ } as const satisfies Record<UiSpinnerStatus, string>;
29
+
30
+ const STATUS_ICONS = {
31
+ loading: LoaderCircleIcon,
32
+ success: CircleCheckIcon,
33
+ warning: CircleAlertIcon,
34
+ error: CircleXIcon,
35
+ } as const satisfies Record<UiSpinnerStatus, unknown>;
36
+
37
+ const STATUS_ICON_CLASS = {
38
+ loading: 'animate-spin motion-reduce:animate-none',
39
+ success: 'text-background-status-success',
40
+ warning: 'text-background-status-warning',
41
+ error: 'text-background-status-error',
42
+ } as const satisfies Record<UiSpinnerStatus, string>;
43
+
44
+ const accessibleName = computed(() => {
45
+ const label = props.ariaLabel?.trim();
46
+ return label ? label : STATUS_LABELS[props.status ?? 'loading'];
11
47
  });
48
+
49
+ const icon = computed(() => STATUS_ICONS[props.status ?? 'loading']);
50
+ const iconClass = computed(() =>
51
+ cn(STATUS_ICON_CLASS[props.status ?? 'loading'], attrs.class as ClassValue),
52
+ );
53
+
54
+ const statusAttrs = computed(() => omitClass(attrs));
12
55
  </script>
13
56
 
14
57
  <template>
15
- <ShadcnSpinner :aria-label="props.ariaLabel" />
58
+ <ShadcnSpinner
59
+ v-if="props.status == null"
60
+ v-bind="$attrs"
61
+ :aria-label="accessibleName"
62
+ />
63
+ <span
64
+ v-else
65
+ v-bind="statusAttrs"
66
+ role="status"
67
+ aria-atomic="true"
68
+ :aria-label="accessibleName"
69
+ :data-status="props.status"
70
+ class="relative inline-flex shrink-0 items-center justify-center"
71
+ >
72
+ <!--
73
+ The leaving icon is pulled out of flow so the next one can fade in
74
+ on top of it. Reduced motion removes the fade.
75
+ -->
76
+ <Transition
77
+ enter-active-class="transition-opacity duration-300 ease-in-out motion-reduce:transition-none"
78
+ enter-from-class="opacity-0"
79
+ leave-active-class="pointer-events-none absolute inset-0 transition-opacity duration-300 ease-in-out motion-reduce:transition-none"
80
+ leave-to-class="opacity-0"
81
+ >
82
+ <span :key="props.status" class="inline-flex" aria-hidden="true">
83
+ <UiIcon :name="icon" size="l" :class="iconClass" />
84
+ </span>
85
+ </Transition>
86
+ <span class="sr-only">{{ accessibleName }}</span>
87
+ </span>
16
88
  </template>
@@ -1,5 +1,6 @@
1
1
  import { render } from '@testing-library/vue';
2
2
  import { describe, expect, test } from 'vitest';
3
+ import { nextTick } from 'vue';
3
4
  import UiSpinner from '../UiSpinner.vue';
4
5
 
5
6
  describe('UiSpinner', () => {
@@ -8,6 +9,8 @@ describe('UiSpinner', () => {
8
9
  const spinner = getByRole('status');
9
10
  expect(spinner).toBeInTheDocument();
10
11
  expect(spinner).toHaveAttribute('aria-label', 'Loading');
12
+ expect(spinner).toHaveAttribute('width', '16');
13
+ expect(spinner).not.toHaveAttribute('data-status');
11
14
  });
12
15
 
13
16
  test('accepts custom aria-label', () => {
@@ -19,4 +22,80 @@ describe('UiSpinner', () => {
19
22
  'Submitting form',
20
23
  );
21
24
  });
25
+
26
+ test('renders a 24px spinner when status is loading', () => {
27
+ const { getByRole } = render(UiSpinner, {
28
+ props: { status: 'loading' },
29
+ });
30
+ const status = getByRole('status');
31
+ const icon = status.querySelector('svg');
32
+
33
+ expect(status).toHaveAttribute('data-status', 'loading');
34
+ expect(status).toHaveAccessibleName('Loading');
35
+ expect(icon).toHaveAttribute('width', '24');
36
+ expect(icon).toHaveAttribute('height', '24');
37
+ expect(icon).toHaveClass('animate-spin', 'motion-reduce:animate-none');
38
+ expect(icon).toHaveAttribute('aria-hidden', 'true');
39
+ });
40
+
41
+ test.each([
42
+ [
43
+ 'success',
44
+ 'Success',
45
+ 'lucide-circle-check',
46
+ 'text-background-status-success',
47
+ ],
48
+ [
49
+ 'warning',
50
+ 'Warning',
51
+ 'lucide-circle-alert',
52
+ 'text-background-status-warning',
53
+ ],
54
+ ['error', 'Error', 'lucide-circle-x', 'text-background-status-error'],
55
+ ] as const)(
56
+ 'renders the %s circle icon with its default name',
57
+ (status, name, iconClass, colorClass) => {
58
+ const { getByRole } = render(UiSpinner, {
59
+ props: { status },
60
+ });
61
+ const indicator = getByRole('status', { name });
62
+ const icon = indicator.querySelector('svg');
63
+
64
+ expect(indicator).toHaveAttribute('data-status', status);
65
+ expect(icon).toHaveClass(iconClass, colorClass);
66
+ expect(icon).not.toHaveClass('animate-spin');
67
+ expect(icon).toHaveAttribute('width', '24');
68
+ expect(icon).toHaveAttribute('height', '24');
69
+ },
70
+ );
71
+
72
+ test('uses ariaLabel for the current status and ignores a blank label', async () => {
73
+ const { getByRole, rerender } = render(UiSpinner, {
74
+ props: { status: 'error', ariaLabel: 'Failed to save' },
75
+ });
76
+
77
+ expect(getByRole('status')).toHaveAccessibleName('Failed to save');
78
+
79
+ await rerender({ status: 'error', ariaLabel: ' ' });
80
+ expect(getByRole('status')).toHaveAccessibleName('Error');
81
+ });
82
+
83
+ test('updates the announced status when loading resolves', async () => {
84
+ const { getByRole, rerender } = render(UiSpinner, {
85
+ props: { status: 'loading', ariaLabel: 'Saving' },
86
+ });
87
+
88
+ expect(getByRole('status')).toHaveAccessibleName('Saving');
89
+ expect(getByRole('status').querySelector('svg')).toHaveClass(
90
+ 'animate-spin',
91
+ );
92
+
93
+ await rerender({ status: 'success', ariaLabel: 'Saved' });
94
+ await nextTick();
95
+
96
+ const status = getByRole('status');
97
+ expect(status).toHaveAccessibleName('Saved');
98
+ expect(status).toHaveAttribute('data-status', 'success');
99
+ expect(status.querySelector('.lucide-circle-check')).toBeInTheDocument();
100
+ });
22
101
  });
@@ -1,2 +1,2 @@
1
1
  export { default as UiSpinner } from './UiSpinner.vue';
2
- export type { UiSpinnerProps } from './types';
2
+ export type { UiSpinnerProps, UiSpinnerStatus } from './types';
@@ -1,14 +1,29 @@
1
1
  /**
2
- * An animated loading indicator. Use while content is loading
3
- * or an action is processing.
2
+ * An animated loading indicator, and the outcome that follows a wait.
3
+ * Use the compact spinner while content is loading or an action is
4
+ * processing. Set `status` for the 24px indicator inside a field: it shows
5
+ * the spinner while saving, then fades to a circle icon for the outcome.
4
6
  * @category Feedback
5
- * @useCases loading state, processing, waiting, fetching data
6
- * @keywords spinner, loading, loader, wait, progress, animation
7
- * @related UiProgress
7
+ * @useCases loading state, processing, waiting, fetching data, inline save, save confirmation, save warning, save failure
8
+ * @keywords spinner, loading, loader, wait, progress, animation, success, warning, error, save
9
+ * @related UiProgress, UiInput, UiField
8
10
  */
11
+ export type UiSpinnerStatus = 'loading' | 'success' | 'warning' | 'error';
12
+
9
13
  export interface UiSpinnerProps {
10
14
  /**
11
- * Accessible label for the spinner.
15
+ * Outcome shown by the 24px field indicator.
16
+ * `loading` is the spinner. `success`, `warning`, and `error` are circle
17
+ * icons. Changing status fades from one to the next.
18
+ * Omit it for the compact spinner used in buttons and beside text.
19
+ */
20
+ status?: UiSpinnerStatus;
21
+
22
+ /**
23
+ * Accessible name announced for the spinner.
24
+ * Defaults to "Loading", or to "Success", "Warning", or "Error" when
25
+ * `status` is one of those. Update it when the status changes so the
26
+ * announcement matches the outcome.
12
27
  * @default 'Loading'
13
28
  */
14
29
  ariaLabel?: string;
@@ -25,7 +25,7 @@ const modelValue = useVModel(props, 'modelValue', emits, {
25
25
  data-slot="input"
26
26
  :class="
27
27
  cn(
28
- 'file:text-foreground placeholder:text-content-on-surface-muted selection:bg-primary selection:text-primary-foreground border-input h-9 w-full min-w-0 rounded-md border bg-background-input-default px-3 py-1 label-m-regular transition-[color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:label-s-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:label-s-regular',
28
+ 'file:text-foreground placeholder:text-content-on-surface-muted border-input h-9 w-full min-w-0 rounded-md border bg-background-input-default px-3 py-1 label-m-regular transition-[color] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:label-s-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:label-s-regular',
29
29
  'ui-focus-ring',
30
30
  'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-border-input-error',
31
31
  // Cascaded error state from a `data-invalid` UiField (text color is
@@ -57,7 +57,7 @@ const forwardedAttrs = computed(() => {
57
57
  :aria-invalid="ariaInvalid"
58
58
  :class="
59
59
  cn(
60
- 'placeholder:text-content-on-surface-muted selection:bg-primary selection:text-primary-foreground w-full min-w-0 flex-1 rounded-none border-0 bg-transparent px-3 py-2.5 body-s-regular outline-none transition-[color] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
60
+ 'placeholder:text-content-on-surface-muted w-full min-w-0 flex-1 rounded-none border-0 bg-transparent px-3 py-2.5 body-s-regular outline-none transition-[color] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
61
61
  props.class,
62
62
  )
63
63
  "
@@ -44,7 +44,7 @@ const delegatedProps = reactiveOmit(props, 'class');
44
44
  data-slot="native-select"
45
45
  :class="
46
46
  cn(
47
- 'border-input placeholder:text-content-on-surface-muted selection:bg-primary selection:text-primary-foreground h-9 w-full min-w-0 appearance-none rounded-md border bg-background-input-default px-3 py-2 pr-9 label-s-regular shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',
47
+ 'border-input placeholder:text-content-on-surface-muted h-9 w-full min-w-0 appearance-none rounded-md border bg-background-input-default px-3 py-2 pr-9 label-s-regular shadow-xs transition-[color,box-shadow] outline-none disabled:pointer-events-none disabled:cursor-not-allowed',
48
48
  'ui-focus-ring',
49
49
  'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
50
50
  props.class,
@@ -0,0 +1,53 @@
1
+ ---
2
+ figma: '32388:4373'
3
+ ---
4
+
5
+ ## Usage
6
+
7
+ The Headline component titles a page or section and, where the user owns the name, lets them rename it in place. A short description can sit below the title.
8
+
9
+ Renaming starts from the menu next to the title. "Edit name" turns the title into a field with the current name selected, so typing replaces it straight away. The check saves the new name and the cross keeps the old one.
10
+
11
+ ### Renaming in place
12
+
13
+ Editing stays where the title is:
14
+
15
+ - The field takes the size and position of the title, so the page does not jump
16
+ - The current name is selected when the field opens
17
+ - Enter or the check saves, Escape or the cross cancels
18
+ - An empty name cannot be saved
19
+ - Focus returns to the menu button when editing ends
20
+
21
+ ### Consistency
22
+
23
+ Every headline is built from the same parts:
24
+
25
+ - Title, in the heading style
26
+ - Menu button, opening "Edit name" and any further actions
27
+ - Description, in the muted label style
28
+ - States: default, menu open, editing and text selected
29
+
30
+ ## Do
31
+
32
+ - Use one headline per page or section, at the heading level that fits the outline
33
+ - Keep the title short enough to read at a glance
34
+ - Put further actions for the same object in the headline menu
35
+ - Use the description for context the title cannot carry
36
+ - Hide the menu when the user cannot rename the object
37
+
38
+ ## Don't
39
+
40
+ - Use a headline for body text or labels
41
+ - Save a name on blur without the user confirming it
42
+ - Allow an empty name
43
+ - Pick the heading level for its size; the visual size is the same at every level
44
+ - Put unrelated actions in the headline menu
45
+
46
+ ## Accessibility
47
+
48
+ - The title is a real heading, so it appears in the page outline
49
+ - The menu button, check and cross each have a visible focus state and an accessible name
50
+ - The editing field keeps the focus ring while it is in use
51
+ - Touch targets for the menu button, check and cross are at least 24 by 24 pixels
52
+ - The description stays legible when it wraps
53
+ - Title and description text meet contrast on the surface behind them