@aleph-alpha/ui-library 6.3.4 → 6.5.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 +2 -1
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
- package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
- package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
- package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
- package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +10 -1
- package/dist/system/components/UiFileItem/index.d.ts +1 -1
- package/dist/system/components/UiFileItem/types.d.ts +81 -5
- package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
- package/dist/system/components/UiPopover/UiPopoverContent.vue.d.ts +1 -0
- package/dist/system/components/UiPopover/types.d.ts +6 -0
- package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
- package/dist/system/components/UiToggle/types.d.ts +10 -2
- package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
- package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
- package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
- package/dist/system/components/core/popover/PopoverContent.vue.d.ts +1 -0
- package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
- package/dist/system/components/core/toggle/index.d.ts +47 -2
- package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
- package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
- package/dist/system/components/core/toggle-group/context.d.ts +1 -0
- package/dist/system/components/core/toggle-group/index.d.ts +10 -2
- package/dist/system/lib.js +10646 -10369
- package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +171 -12
- package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
- package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +9 -4
- package/package.json +2 -2
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
- package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
- package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
- package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
- package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
- package/src/components/UiDropdownMenu/types.ts +3 -0
- package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
- package/src/components/UiFileItem/UiFileItem.vue +111 -6
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +52 -0
- package/src/components/UiFileItem/index.ts +1 -0
- package/src/components/UiFileItem/types.ts +82 -5
- package/src/components/UiPopover/UiPopover.stories.ts +141 -0
- package/src/components/UiPopover/UiPopoverContent.vue +2 -0
- package/src/components/UiPopover/__tests__/UiPopover.test.ts +48 -0
- package/src/components/UiPopover/types.ts +7 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +104 -32
- package/src/components/UiToggle/UiToggle.stories.ts +386 -261
- package/src/components/UiToggle/UiToggle.vue +2 -0
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
- package/src/components/UiToggle/types.ts +10 -2
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
- package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
- package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
- package/src/components/UiToggleGroup/types.ts +12 -2
- package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
- package/src/components/core/popover/PopoverContent.vue +9 -3
- package/src/components/core/toggle/Toggle.vue +12 -5
- package/src/components/core/toggle/index.ts +47 -19
- package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
- package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
- package/src/components/core/toggle-group/context.ts +1 -0
- package/src/components/core/toggle-group/index.ts +10 -24
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +808 -22
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +188 -6
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
- package/src/patterns/UiTopBar/accessory-dropdown.ts +5 -3
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { onBeforeUnmount, onMounted } from 'vue';
|
|
2
|
+
import {
|
|
3
|
+
DROPDOWN_MENU_MOBILE_MEDIA,
|
|
4
|
+
DROPDOWN_MENU_SUBMENU_GAP_PX,
|
|
5
|
+
} from './menu-metrics';
|
|
6
|
+
import { placeMobileSubmenu } from './placeMobileSubmenu';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The row that opened the submenu, which labels the submenu panel.
|
|
10
|
+
* @param content The submenu panel.
|
|
11
|
+
* @returns The trigger row, or null when the panel is not labelled.
|
|
12
|
+
*/
|
|
13
|
+
function submenuTrigger(content: HTMLElement) {
|
|
14
|
+
const labelId = content.getAttribute('aria-labelledby');
|
|
15
|
+
return labelId ? document.getElementById(labelId) : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Caps the submenu's scroll area so the panel ends at the viewport edge. */
|
|
19
|
+
const SCROLL_MAX_HEIGHT_VAR = '--ui-dropdown-submenu-scroll-max-height';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The panel's vertical padding and borders: the part of its height that stays
|
|
23
|
+
* when the scroll area inside has to shrink.
|
|
24
|
+
* @param content The submenu panel.
|
|
25
|
+
*/
|
|
26
|
+
function verticalChrome(content: HTMLElement) {
|
|
27
|
+
const style = getComputedStyle(content);
|
|
28
|
+
return (
|
|
29
|
+
(Number.parseFloat(style.paddingTop) || 0) +
|
|
30
|
+
(Number.parseFloat(style.paddingBottom) || 0) +
|
|
31
|
+
(Number.parseFloat(style.borderTopWidth) || 0) +
|
|
32
|
+
(Number.parseFloat(style.borderBottomWidth) || 0)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Measures where an open submenu goes on a narrow screen and hands the result
|
|
38
|
+
* to the stylesheet.
|
|
39
|
+
*
|
|
40
|
+
* The panel gets `--ui-dropdown-submenu-top|left|width` and `data-mobile-side`
|
|
41
|
+
* (plus `--ui-dropdown-submenu-scroll-max-height` and `data-mobile-clamped`
|
|
42
|
+
* when the chosen side is too short for the whole panel), and the trigger row
|
|
43
|
+
* gets `data-mobile-submenu-side`; the CSS in
|
|
44
|
+
* `UiDropdownMenuSubContent` turns those into a fixed position and neutralises
|
|
45
|
+
* the side placement reka-ui writes to its wrapper. Keeping the override in
|
|
46
|
+
* the stylesheet means nothing here has to be reapplied when reka-ui
|
|
47
|
+
* repositions.
|
|
48
|
+
* @param getContent The open submenu panel, once it is in the document.
|
|
49
|
+
*/
|
|
50
|
+
export function useMobileSubmenuPlacement(
|
|
51
|
+
getContent: () => HTMLElement | null,
|
|
52
|
+
) {
|
|
53
|
+
let placedTrigger: HTMLElement | null = null;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Drops the side marker from the row that last opened the submenu.
|
|
57
|
+
*/
|
|
58
|
+
function clear() {
|
|
59
|
+
if (placedTrigger) {
|
|
60
|
+
delete placedTrigger.dataset.mobileSubmenuSide;
|
|
61
|
+
placedTrigger.style.removeProperty('--ui-dropdown-submenu-gap');
|
|
62
|
+
}
|
|
63
|
+
placedTrigger = null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Measures the trigger row and parent panel, and writes the placement.
|
|
68
|
+
*/
|
|
69
|
+
function apply() {
|
|
70
|
+
const content = getContent();
|
|
71
|
+
if (!content?.isConnected) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!window.matchMedia?.(DROPDOWN_MENU_MOBILE_MEDIA).matches) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const trigger = submenuTrigger(content);
|
|
79
|
+
const parent = trigger?.closest<HTMLElement>('[role="menu"]');
|
|
80
|
+
if (!trigger || !parent) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
85
|
+
const parentRect = parent.getBoundingClientRect();
|
|
86
|
+
// Measure the panel at its natural height, so a cap written on an earlier
|
|
87
|
+
// pass does not stick once there is room again. Layout height, not the
|
|
88
|
+
// bounding box: the panel is scaled while it animates in.
|
|
89
|
+
content.style.removeProperty(SCROLL_MAX_HEIGHT_VAR);
|
|
90
|
+
delete content.dataset.mobileClamped;
|
|
91
|
+
const submenuHeight =
|
|
92
|
+
content.offsetHeight || content.getBoundingClientRect().height;
|
|
93
|
+
if (parentRect.width === 0 || submenuHeight === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const placement = placeMobileSubmenu({
|
|
98
|
+
trigger: triggerRect,
|
|
99
|
+
parent: parentRect,
|
|
100
|
+
submenuHeight,
|
|
101
|
+
chrome: verticalChrome(content),
|
|
102
|
+
viewportHeight: window.innerHeight,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
if (placement.scrollMaxHeight !== null) {
|
|
106
|
+
content.style.setProperty(
|
|
107
|
+
SCROLL_MAX_HEIGHT_VAR,
|
|
108
|
+
`${placement.scrollMaxHeight}px`,
|
|
109
|
+
);
|
|
110
|
+
content.dataset.mobileClamped = '';
|
|
111
|
+
}
|
|
112
|
+
content.style.setProperty(
|
|
113
|
+
'--ui-dropdown-submenu-top',
|
|
114
|
+
`${placement.top}px`,
|
|
115
|
+
);
|
|
116
|
+
content.style.setProperty(
|
|
117
|
+
'--ui-dropdown-submenu-left',
|
|
118
|
+
`${placement.left}px`,
|
|
119
|
+
);
|
|
120
|
+
content.style.setProperty(
|
|
121
|
+
'--ui-dropdown-submenu-width',
|
|
122
|
+
`${placement.width}px`,
|
|
123
|
+
);
|
|
124
|
+
content.dataset.mobileSide = placement.side;
|
|
125
|
+
|
|
126
|
+
// The row carries the side and gap too, so its hit area can be extended
|
|
127
|
+
// across the gap toward the submenu.
|
|
128
|
+
if (placedTrigger !== trigger) {
|
|
129
|
+
clear();
|
|
130
|
+
placedTrigger = trigger;
|
|
131
|
+
}
|
|
132
|
+
trigger.dataset.mobileSubmenuSide = placement.side;
|
|
133
|
+
trigger.style.setProperty(
|
|
134
|
+
'--ui-dropdown-submenu-gap',
|
|
135
|
+
`${DROPDOWN_MENU_SUBMENU_GAP_PX}px`,
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let media: MediaQueryList | undefined;
|
|
140
|
+
|
|
141
|
+
onMounted(() => {
|
|
142
|
+
media = window.matchMedia?.(DROPDOWN_MENU_MOBILE_MEDIA);
|
|
143
|
+
media?.addEventListener('change', apply);
|
|
144
|
+
window.addEventListener('resize', apply);
|
|
145
|
+
// The trigger row moves when the parent list scrolls, and settles once
|
|
146
|
+
// the parent panel has finished animating open.
|
|
147
|
+
document.addEventListener('scroll', apply, {
|
|
148
|
+
capture: true,
|
|
149
|
+
passive: true,
|
|
150
|
+
});
|
|
151
|
+
document.addEventListener('animationend', apply, { capture: true });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
onBeforeUnmount(() => {
|
|
155
|
+
media?.removeEventListener('change', apply);
|
|
156
|
+
window.removeEventListener('resize', apply);
|
|
157
|
+
document.removeEventListener('scroll', apply, { capture: true });
|
|
158
|
+
document.removeEventListener('animationend', apply, { capture: true });
|
|
159
|
+
clear();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
return { apply, clear };
|
|
163
|
+
}
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
import { UiButton } from '@/components/UiButton';
|
|
3
3
|
import { UiFileType } from '@/components/UiFileType';
|
|
4
4
|
import { UiIcon } from '@/components/UiIcon';
|
|
5
|
+
import {
|
|
6
|
+
UiPopover,
|
|
7
|
+
UiPopoverContent,
|
|
8
|
+
UiPopoverTrigger,
|
|
9
|
+
} from '@/components/UiPopover';
|
|
5
10
|
import { UiProgress } from '@/components/UiProgress';
|
|
6
11
|
import { UiTooltip } from '@/components/UiTooltip';
|
|
7
12
|
import { cn } from '@/lib/utils';
|
|
8
13
|
import { useIsTruncated } from '@/lib/useIsTruncated';
|
|
9
|
-
import { computed, useTemplateRef } from 'vue';
|
|
10
|
-
import type { UiFileItemProps } from './types';
|
|
14
|
+
import { computed, ref, useTemplateRef } from 'vue';
|
|
15
|
+
import type { UiFileItemGroupItem, UiFileItemProps } from './types';
|
|
11
16
|
|
|
12
17
|
defineOptions({
|
|
13
18
|
name: 'UiFileItem',
|
|
@@ -24,19 +29,36 @@ const props = withDefaults(defineProps<UiFileItemProps>(), {
|
|
|
24
29
|
removable: true,
|
|
25
30
|
disabled: false,
|
|
26
31
|
size: 'default',
|
|
32
|
+
processing: false,
|
|
33
|
+
processingLabel: 'Processing…',
|
|
34
|
+
expandLabel: 'Show files',
|
|
35
|
+
listLabel: 'Attached files',
|
|
36
|
+
popoverSide: 'top',
|
|
37
|
+
popoverAlign: 'end',
|
|
27
38
|
// `mediaTone` and `mediaIcon` are intentionally undefined by default so
|
|
28
39
|
// `UiFileType`'s extension-based auto-detection can decide both. Pass
|
|
29
40
|
// them explicitly to override.
|
|
30
41
|
mediaTone: undefined,
|
|
31
42
|
mediaIcon: undefined,
|
|
43
|
+
items: undefined,
|
|
32
44
|
});
|
|
33
45
|
|
|
34
|
-
/* eslint-disable jsdoc/require-jsdoc -- emit
|
|
46
|
+
/* eslint-disable jsdoc/require-jsdoc -- emit payloads are tuples */
|
|
35
47
|
const emit = defineEmits<{
|
|
36
48
|
remove: [];
|
|
49
|
+
/** Fired when a file inside the multi-file list is removed. */
|
|
50
|
+
removeItem: [item: UiFileItemGroupItem];
|
|
37
51
|
}>();
|
|
38
52
|
/* eslint-enable jsdoc/require-jsdoc */
|
|
39
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Re-emits a nested row's remove so the parent can tell which file left the group.
|
|
56
|
+
* @param item - The file that was removed from the popover list
|
|
57
|
+
*/
|
|
58
|
+
function onRemoveItem(item: UiFileItemGroupItem) {
|
|
59
|
+
emit('removeItem', item);
|
|
60
|
+
}
|
|
61
|
+
|
|
40
62
|
/**
|
|
41
63
|
* Drops the last `.ext` segment; leaves `.gitignore`-style names unchanged.
|
|
42
64
|
* @param name - Full file name
|
|
@@ -53,9 +75,12 @@ const displayFilename = computed(() =>
|
|
|
53
75
|
|
|
54
76
|
const isError = computed(() => props.error != null && props.error !== '');
|
|
55
77
|
|
|
78
|
+
const isProcessing = computed(() => !isError.value && props.processing);
|
|
79
|
+
|
|
56
80
|
const isWithProgress = computed(
|
|
57
81
|
() =>
|
|
58
82
|
!isError.value &&
|
|
83
|
+
!isProcessing.value &&
|
|
59
84
|
props.progress != null &&
|
|
60
85
|
props.progress >= 0 &&
|
|
61
86
|
props.progress < 100,
|
|
@@ -65,9 +90,28 @@ const showMeta = computed(
|
|
|
65
90
|
() =>
|
|
66
91
|
!isError.value &&
|
|
67
92
|
!isWithProgress.value &&
|
|
93
|
+
!isProcessing.value &&
|
|
68
94
|
(props.typeLabel || props.sizeLabel),
|
|
69
95
|
);
|
|
70
96
|
|
|
97
|
+
const isMulti = computed(
|
|
98
|
+
() => Array.isArray(props.items) && props.items.length > 0,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const listOpen = ref(false);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Name announced when the processing status appears. Includes the file so a
|
|
105
|
+
* live region can tell rows apart, while the visible line stays
|
|
106
|
+
* `type | processingLabel`.
|
|
107
|
+
*/
|
|
108
|
+
const processingStatusName = computed(() => {
|
|
109
|
+
const parts = [props.filename];
|
|
110
|
+
if (props.typeLabel) parts.push(props.typeLabel);
|
|
111
|
+
parts.push(props.processingLabel);
|
|
112
|
+
return parts.join(', ');
|
|
113
|
+
});
|
|
114
|
+
|
|
71
115
|
const isSmall = computed(() => props.size === 'small');
|
|
72
116
|
|
|
73
117
|
const containerClass = computed(() =>
|
|
@@ -79,8 +123,8 @@ const containerClass = computed(() =>
|
|
|
79
123
|
),
|
|
80
124
|
);
|
|
81
125
|
|
|
82
|
-
// Body column: title plus one of {progress, error, meta}. The
|
|
83
|
-
// shrinks for compact rows (small size or error
|
|
126
|
+
// Body column: title plus one of {progress, error, processing, meta}. The
|
|
127
|
+
// vertical gap shrinks for compact rows (small size or error states).
|
|
84
128
|
const contentClass = computed(() =>
|
|
85
129
|
cn(
|
|
86
130
|
'flex min-w-0 flex-1 flex-col items-start',
|
|
@@ -116,7 +160,7 @@ const isTitleTruncated = useIsTruncated(titleRef, () => displayFilename.value);
|
|
|
116
160
|
:tone="mediaTone"
|
|
117
161
|
:icon="mediaIcon"
|
|
118
162
|
:error="isError"
|
|
119
|
-
:loading="isWithProgress"
|
|
163
|
+
:loading="isWithProgress || isProcessing"
|
|
120
164
|
/>
|
|
121
165
|
|
|
122
166
|
<div data-slot="file-item-content" :class="contentClass">
|
|
@@ -145,6 +189,24 @@ const isTitleTruncated = useIsTruncated(titleRef, () => displayFilename.value);
|
|
|
145
189
|
{{ error }}
|
|
146
190
|
</p>
|
|
147
191
|
|
|
192
|
+
<div
|
|
193
|
+
v-else-if="isProcessing"
|
|
194
|
+
data-slot="file-item-meta"
|
|
195
|
+
role="status"
|
|
196
|
+
:aria-label="processingStatusName"
|
|
197
|
+
:aria-busy="processing"
|
|
198
|
+
class="label-12-medium text-content-on-surface-muted flex w-full min-w-0 items-center gap-2"
|
|
199
|
+
>
|
|
200
|
+
<span v-if="typeLabel" class="truncate">{{ typeLabel }}</span>
|
|
201
|
+
<span
|
|
202
|
+
v-if="typeLabel"
|
|
203
|
+
aria-hidden="true"
|
|
204
|
+
class="text-content-on-surface-muted shrink-0"
|
|
205
|
+
>|</span
|
|
206
|
+
>
|
|
207
|
+
<span class="truncate">{{ processingLabel }}</span>
|
|
208
|
+
</div>
|
|
209
|
+
|
|
148
210
|
<div
|
|
149
211
|
v-else-if="showMeta"
|
|
150
212
|
data-slot="file-item-meta"
|
|
@@ -173,5 +235,48 @@ const isTitleTruncated = useIsTruncated(titleRef, () => displayFilename.value);
|
|
|
173
235
|
>
|
|
174
236
|
<UiIcon name="x" :size="16" aria-hidden="true" />
|
|
175
237
|
</UiButton>
|
|
238
|
+
|
|
239
|
+
<UiPopover v-if="isMulti" v-model:open="listOpen">
|
|
240
|
+
<UiPopoverTrigger as-child>
|
|
241
|
+
<UiButton
|
|
242
|
+
type="button"
|
|
243
|
+
variant="ghost"
|
|
244
|
+
size="icon-sm"
|
|
245
|
+
class="shrink-0"
|
|
246
|
+
:disabled="disabled"
|
|
247
|
+
:aria-label="expandLabel"
|
|
248
|
+
>
|
|
249
|
+
<UiIcon
|
|
250
|
+
:name="listOpen ? 'chevron-up' : 'chevron-down'"
|
|
251
|
+
:size="16"
|
|
252
|
+
aria-hidden="true"
|
|
253
|
+
/>
|
|
254
|
+
</UiButton>
|
|
255
|
+
</UiPopoverTrigger>
|
|
256
|
+
<UiPopoverContent
|
|
257
|
+
:side="popoverSide"
|
|
258
|
+
:align="popoverAlign"
|
|
259
|
+
compact
|
|
260
|
+
aria-label="listLabel"
|
|
261
|
+
>
|
|
262
|
+
<ul
|
|
263
|
+
data-slot="file-item-list"
|
|
264
|
+
class="flex max-h-[calc(var(--reka-popover-content-available-height)-2rem)] w-full flex-col gap-2 overflow-y-auto"
|
|
265
|
+
:aria-label="listLabel"
|
|
266
|
+
>
|
|
267
|
+
<li
|
|
268
|
+
v-for="(item, index) in items"
|
|
269
|
+
:key="item.id ?? `${item.filename}-${index}`"
|
|
270
|
+
>
|
|
271
|
+
<UiFileItem
|
|
272
|
+
v-bind="item"
|
|
273
|
+
:disabled="disabled || item.disabled"
|
|
274
|
+
size="small"
|
|
275
|
+
@remove="onRemoveItem(item)"
|
|
276
|
+
/>
|
|
277
|
+
</li>
|
|
278
|
+
</ul>
|
|
279
|
+
</UiPopoverContent>
|
|
280
|
+
</UiPopover>
|
|
176
281
|
</div>
|
|
177
282
|
</template>
|
|
@@ -77,6 +77,58 @@ describe('UiFileItem', () => {
|
|
|
77
77
|
expect(getByLabelText('doc.pdf')).toHaveClass('label-12-medium');
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
test('processing shows the status text and hides the size and progress bar', () => {
|
|
81
|
+
const { getByRole, getByText, queryByRole, queryByText } = render(
|
|
82
|
+
UiFileItem,
|
|
83
|
+
{
|
|
84
|
+
props: {
|
|
85
|
+
filename: 'doc.pdf',
|
|
86
|
+
typeLabel: 'PDF',
|
|
87
|
+
sizeLabel: '1 MB',
|
|
88
|
+
progress: 40,
|
|
89
|
+
processing: true,
|
|
90
|
+
processingLabel: 'Processing…',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
expect(getByText('PDF')).toBeInTheDocument();
|
|
95
|
+
expect(getByText('Processing…')).toBeInTheDocument();
|
|
96
|
+
expect(getByRole('status')).toHaveAccessibleName(
|
|
97
|
+
'doc.pdf, PDF, Processing…',
|
|
98
|
+
);
|
|
99
|
+
expect(queryByText('1 MB')).not.toBeInTheDocument();
|
|
100
|
+
expect(queryByRole('progressbar')).not.toBeInTheDocument();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('a group of files exposes a chevron that lists each file', async () => {
|
|
104
|
+
const user = userEvent.setup();
|
|
105
|
+
const { getByRole, queryByRole } = render(UiFileItem, {
|
|
106
|
+
props: {
|
|
107
|
+
filename: 'Attached documents',
|
|
108
|
+
typeLabel: '2 files',
|
|
109
|
+
expandLabel: 'Show attached documents',
|
|
110
|
+
items: [
|
|
111
|
+
{ filename: 'plan.pdf', typeLabel: 'PDF', sizeLabel: '12 MB' },
|
|
112
|
+
{ filename: 'notes.md', typeLabel: 'MD', sizeLabel: '4 KB' },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
const chevron = getByRole('button', { name: 'Show attached documents' });
|
|
117
|
+
expect(chevron).toHaveAttribute('aria-expanded', 'false');
|
|
118
|
+
expect(
|
|
119
|
+
queryByRole('list', { name: 'Attached files' }),
|
|
120
|
+
).not.toBeInTheDocument();
|
|
121
|
+
|
|
122
|
+
await user.click(chevron);
|
|
123
|
+
expect(
|
|
124
|
+
screen.getByRole('list', { name: 'Attached files' }),
|
|
125
|
+
).toBeInTheDocument();
|
|
126
|
+
expect(screen.getByText('plan')).toBeInTheDocument();
|
|
127
|
+
expect(screen.getByText('notes')).toBeInTheDocument();
|
|
128
|
+
expect(screen.getByText('PDF')).toBeInTheDocument();
|
|
129
|
+
expect(screen.getByText('MD')).toBeInTheDocument();
|
|
130
|
+
});
|
|
131
|
+
|
|
80
132
|
test('default size keeps the roomier padding and title scale', () => {
|
|
81
133
|
const { container, getByLabelText } = render(UiFileItem, {
|
|
82
134
|
props: { filename: 'doc.pdf' },
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Row showing a selected or
|
|
2
|
+
* Row showing a selected, uploading, or processing file, with an optional
|
|
3
|
+
* multi-file disclosure.
|
|
3
4
|
* @category Form Inputs
|
|
4
|
-
* @useCases file upload list, attachment row
|
|
5
|
-
* @keywords file, upload, attachment, progress, success, error
|
|
6
|
-
* @related UiFileUploadBox,
|
|
5
|
+
* @useCases file upload list, attachment row, grouped attachments
|
|
6
|
+
* @keywords file, upload, attachment, progress, processing, success, error, multi
|
|
7
|
+
* @related UiFileUploadBox, UiFileType, UiPopover, UiButton, UiProgress
|
|
7
8
|
*/
|
|
8
9
|
export type UiFileItemSize = 'default' | 'small';
|
|
9
10
|
|
|
10
11
|
import type { UiFileTypeTone } from '@/components/UiFileType';
|
|
12
|
+
import type { UiPopoverAlign, UiPopoverSide } from '@/components/UiPopover';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Media badge tone. Re-exported alias of `UiFileTypeTone` (the file-type
|
|
@@ -16,10 +18,47 @@ import type { UiFileTypeTone } from '@/components/UiFileType';
|
|
|
16
18
|
*/
|
|
17
19
|
export type UiFileItemMediaTone = UiFileTypeTone;
|
|
18
20
|
|
|
21
|
+
/**
|
|
22
|
+
* One file inside a multi-file popover. Icons come from the filename
|
|
23
|
+
* extension via `UiFileType` (text, markdown, tabular, media) unless
|
|
24
|
+
* `mediaTone` / `mediaIcon` override them.
|
|
25
|
+
*/
|
|
26
|
+
export interface UiFileItemGroupItem {
|
|
27
|
+
/** Stable id. Used as the list key; falls back to the filename. */
|
|
28
|
+
id?: string;
|
|
29
|
+
/** Full file name. The trailing extension is hidden from the title. */
|
|
30
|
+
filename: string;
|
|
31
|
+
/** Short type label, e.g. `PDF`. */
|
|
32
|
+
typeLabel?: string;
|
|
33
|
+
/** Size label, e.g. `1.2 MB`. Shown in the success state. */
|
|
34
|
+
sizeLabel?: string;
|
|
35
|
+
/** Upload progress 0–100. Values `< 100` show a progress bar. */
|
|
36
|
+
progress?: number | null;
|
|
37
|
+
/** Error message. When non-empty, the row enters the error state. */
|
|
38
|
+
error?: string | null;
|
|
39
|
+
/**
|
|
40
|
+
* When `true`, the row shows `typeLabel | processingLabel` instead of a
|
|
41
|
+
* progress bar or the file size.
|
|
42
|
+
*/
|
|
43
|
+
processing?: boolean;
|
|
44
|
+
/** Visible processing status. Also announced in the status region. */
|
|
45
|
+
processingLabel?: string;
|
|
46
|
+
/** When `false`, the nested row has no remove control. */
|
|
47
|
+
removable?: boolean;
|
|
48
|
+
/** When `true`, the nested row is inert. */
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
/** Accessible label for the nested remove control. */
|
|
51
|
+
removeLabel?: string;
|
|
52
|
+
/** Media badge tone. Auto-derived from the extension when omitted. */
|
|
53
|
+
mediaTone?: UiFileItemMediaTone;
|
|
54
|
+
/** Lucide icon name for the media badge. Auto-derived when omitted. */
|
|
55
|
+
mediaIcon?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
19
58
|
export interface UiFileItemProps {
|
|
20
59
|
/** Full file name. The trailing extension is hidden from the title. */
|
|
21
60
|
filename: string;
|
|
22
|
-
/** Short type label, e.g. `PDF`. Shown
|
|
61
|
+
/** Short type label, e.g. `PDF`. Shown in the success and processing states. */
|
|
23
62
|
typeLabel?: string;
|
|
24
63
|
/** Size label, e.g. `1.2 MB`. Shown only in the success state. */
|
|
25
64
|
sizeLabel?: string;
|
|
@@ -27,6 +66,18 @@ export interface UiFileItemProps {
|
|
|
27
66
|
progress?: number | null;
|
|
28
67
|
/** Error message. When non-empty, the row enters the error state. */
|
|
29
68
|
error?: string | null;
|
|
69
|
+
/**
|
|
70
|
+
* When `true`, the row is processing: a neutral file badge and
|
|
71
|
+
* `typeLabel | processingLabel`, with no progress bar.
|
|
72
|
+
* @default false
|
|
73
|
+
*/
|
|
74
|
+
processing?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Visible processing status, e.g. `Processing…`. Announced with the
|
|
77
|
+
* filename from a `status` region so it can be translated.
|
|
78
|
+
* @default 'Processing…'
|
|
79
|
+
*/
|
|
80
|
+
processingLabel?: string;
|
|
30
81
|
/** Accessible label for the remove control. */
|
|
31
82
|
removeLabel?: string;
|
|
32
83
|
/** Accessible label for the progress bar (i18n hook). Defaults to the `filename`. */
|
|
@@ -47,4 +98,30 @@ export interface UiFileItemProps {
|
|
|
47
98
|
mediaTone?: UiFileItemMediaTone;
|
|
48
99
|
/** Lucide icon name for the media badge. Auto-derived when omitted. */
|
|
49
100
|
mediaIcon?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Files revealed by the chevron. When the list has entries, the row is the
|
|
103
|
+
* multi variant: a chevron button opens a popover of single file rows.
|
|
104
|
+
* Each entry keeps the icon for its own file type.
|
|
105
|
+
*/
|
|
106
|
+
items?: UiFileItemGroupItem[];
|
|
107
|
+
/**
|
|
108
|
+
* Accessible name for the chevron that opens the file list.
|
|
109
|
+
* @default 'Show files'
|
|
110
|
+
*/
|
|
111
|
+
expandLabel?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Accessible name for the list inside the popover.
|
|
114
|
+
* @default 'Attached files'
|
|
115
|
+
*/
|
|
116
|
+
listLabel?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Which side of the row the file list opens on.
|
|
119
|
+
* @default 'bottom'
|
|
120
|
+
*/
|
|
121
|
+
popoverSide?: UiPopoverSide;
|
|
122
|
+
/**
|
|
123
|
+
* Alignment of the file list against the row.
|
|
124
|
+
* @default 'center'
|
|
125
|
+
*/
|
|
126
|
+
popoverAlign?: UiPopoverAlign;
|
|
50
127
|
}
|
|
@@ -368,6 +368,81 @@ export const Alignments: Story = {
|
|
|
368
368
|
},
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
+
const compactTemplateSource = `<script setup lang="ts">
|
|
372
|
+
import { UiPopover, UiPopoverTrigger, UiPopoverContent, UiButton } from '@aleph-alpha/ui-library'
|
|
373
|
+
import { ref } from 'vue'
|
|
374
|
+
|
|
375
|
+
const open = ref(true)
|
|
376
|
+
</script>
|
|
377
|
+
|
|
378
|
+
<template>
|
|
379
|
+
<UiPopover v-model:open="open">
|
|
380
|
+
<UiPopoverTrigger as-child>
|
|
381
|
+
<UiButton variant="outline">Attached files</UiButton>
|
|
382
|
+
</UiPopoverTrigger>
|
|
383
|
+
<UiPopoverContent compact side="top" align="end" aria-label="Attached files">
|
|
384
|
+
<ul class="flex flex-col gap-1">
|
|
385
|
+
<li class="body-14-regular">report.pdf</li>
|
|
386
|
+
<li class="body-14-regular">summary.docx</li>
|
|
387
|
+
<li class="body-14-regular">data.csv</li>
|
|
388
|
+
</ul>
|
|
389
|
+
</UiPopoverContent>
|
|
390
|
+
</UiPopover>
|
|
391
|
+
</template>`;
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Compact popover with tighter padding and a larger radius.
|
|
395
|
+
* Use `compact` on `UiPopoverContent` for dense content such as lists or
|
|
396
|
+
* menus, e.g. the file list in `UiFileItem`.
|
|
397
|
+
*/
|
|
398
|
+
export const Compact: Story = {
|
|
399
|
+
render: () => ({
|
|
400
|
+
components: { UiPopover, UiPopoverTrigger, UiPopoverContent, UiButton },
|
|
401
|
+
setup() {
|
|
402
|
+
const open = ref(true);
|
|
403
|
+
return { open };
|
|
404
|
+
},
|
|
405
|
+
template: `
|
|
406
|
+
<div class="flex min-h-50 items-end justify-end p-6">
|
|
407
|
+
<UiPopover v-model:open="open">
|
|
408
|
+
<UiPopoverTrigger as-child>
|
|
409
|
+
<UiButton variant="outline">Attached files</UiButton>
|
|
410
|
+
</UiPopoverTrigger>
|
|
411
|
+
<UiPopoverContent compact side="top" align="end">
|
|
412
|
+
<ul class="flex flex-col gap-1">
|
|
413
|
+
<li class="body-14-regular">report.pdf</li>
|
|
414
|
+
<li class="body-14-regular">summary.docx</li>
|
|
415
|
+
<li class="body-14-regular">data.csv</li>
|
|
416
|
+
</ul>
|
|
417
|
+
</UiPopoverContent>
|
|
418
|
+
</UiPopover>
|
|
419
|
+
</div>
|
|
420
|
+
`,
|
|
421
|
+
}),
|
|
422
|
+
parameters: {
|
|
423
|
+
controls: { disable: true },
|
|
424
|
+
docs: {
|
|
425
|
+
source: {
|
|
426
|
+
code: compactTemplateSource,
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
play: async ({ step }) => {
|
|
431
|
+
// Scenario (UiPopover): the compact panel renders with the dense spacing.
|
|
432
|
+
const body = within(document.body);
|
|
433
|
+
const popover = await expectOpenPopover(body);
|
|
434
|
+
|
|
435
|
+
await step(
|
|
436
|
+
'interaction: compact applies the dense padding and radius',
|
|
437
|
+
async () => {
|
|
438
|
+
await expect(popover).toHaveClass('p-2', 'rounded-[14px]');
|
|
439
|
+
await expect(popover).not.toHaveClass('p-4');
|
|
440
|
+
await expect(popover).not.toHaveAttribute('compact');
|
|
441
|
+
},
|
|
442
|
+
);
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
|
|
371
446
|
const openByDefaultTemplateSource = `<script setup lang="ts">
|
|
372
447
|
import { UiPopover, UiPopoverTrigger, UiPopoverContent, UiButton } from '@aleph-alpha/ui-library'
|
|
373
448
|
import { ref } from 'vue'
|
|
@@ -762,6 +837,72 @@ export const ScreenReader: Story = {
|
|
|
762
837
|
},
|
|
763
838
|
};
|
|
764
839
|
|
|
840
|
+
/**
|
|
841
|
+
* Screen-reader semantics of the compact panel: still a dialog, trigger
|
|
842
|
+
* expanded state, and its list content (WCAG 4.1.2). Hidden test-only story.
|
|
843
|
+
*/
|
|
844
|
+
export const CompactScreenReader: Story = {
|
|
845
|
+
name: 'test - Compact Screen Reader',
|
|
846
|
+
tags: ['!dev', '!autodocs'],
|
|
847
|
+
parameters: {
|
|
848
|
+
chromatic: { disableSnapshot: true },
|
|
849
|
+
docs: {
|
|
850
|
+
description: {
|
|
851
|
+
story:
|
|
852
|
+
'Verifies the compact panel keeps the dialog role, trigger expanded state, and announced list content.',
|
|
853
|
+
},
|
|
854
|
+
},
|
|
855
|
+
},
|
|
856
|
+
render: () => ({
|
|
857
|
+
components: { UiPopover, UiPopoverTrigger, UiPopoverContent, UiButton },
|
|
858
|
+
template: `
|
|
859
|
+
<div class="flex min-h-50 items-start p-6">
|
|
860
|
+
<UiPopover :modal="false">
|
|
861
|
+
<UiPopoverTrigger as-child>
|
|
862
|
+
<UiButton variant="outline">Attached files</UiButton>
|
|
863
|
+
</UiPopoverTrigger>
|
|
864
|
+
<UiPopoverContent compact>
|
|
865
|
+
<ul class="flex flex-col gap-1">
|
|
866
|
+
<li class="body-14-regular">report.pdf</li>
|
|
867
|
+
<li class="body-14-regular">summary.docx</li>
|
|
868
|
+
</ul>
|
|
869
|
+
</UiPopoverContent>
|
|
870
|
+
</UiPopover>
|
|
871
|
+
</div>
|
|
872
|
+
`,
|
|
873
|
+
}),
|
|
874
|
+
play: async ({ canvasElement, step }) => {
|
|
875
|
+
// Scenario (UiPopover): assistive tech hears the trigger open a compact
|
|
876
|
+
// dialog, then reads its list once it is open.
|
|
877
|
+
const canvas = within(canvasElement);
|
|
878
|
+
const body = within(document.body);
|
|
879
|
+
const trigger = canvas.getByRole('button', { name: 'Attached files' });
|
|
880
|
+
|
|
881
|
+
await step(
|
|
882
|
+
'screen-reader: the trigger starts collapsed (WCAG 4.1.2)',
|
|
883
|
+
async () => {
|
|
884
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'false');
|
|
885
|
+
},
|
|
886
|
+
);
|
|
887
|
+
|
|
888
|
+
await userEvent.click(trigger);
|
|
889
|
+
const popover = await expectOpenPopover(body);
|
|
890
|
+
|
|
891
|
+
await step(
|
|
892
|
+
'screen-reader: the compact panel is a dialog exposing its list and the trigger is expanded (WCAG 4.1.2)',
|
|
893
|
+
async () => {
|
|
894
|
+
await expect(trigger).toHaveAttribute('aria-expanded', 'true');
|
|
895
|
+
const list = within(popover).getByRole('list');
|
|
896
|
+
await expect(within(list).getAllByRole('listitem')).toHaveLength(2);
|
|
897
|
+
await expect(within(popover).getByText('report.pdf')).toBeVisible();
|
|
898
|
+
},
|
|
899
|
+
);
|
|
900
|
+
|
|
901
|
+
await userEvent.keyboard('{Escape}');
|
|
902
|
+
await expectClosedPopover(body);
|
|
903
|
+
},
|
|
904
|
+
};
|
|
905
|
+
|
|
765
906
|
/**
|
|
766
907
|
* Rendered at 200% page zoom (WCAG 1.4.4 Resize Text). Hidden test-only story.
|
|
767
908
|
*/
|