@aleph-alpha/ui-library 5.8.0 → 5.9.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/README.md +8 -7
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- 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/components/index.d.ts +1 -0
- package/dist/system/lib.js +22249 -21090
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -1
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +4 -1
- package/package.json +2 -1
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiListbox/UiListbox.stories.ts +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -5
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -11
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1064 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { expect, userEvent, within } from 'storybook/test';
|
|
3
|
+
import { ref, watch } from 'vue';
|
|
4
|
+
import { UiToggleGroup, UiToggleGroupItem } from '../UiToggleGroup';
|
|
5
|
+
import UiFadeMask from './UiFadeMask.vue';
|
|
6
|
+
import type { UiFadeMaskPosition } from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* UiFadeMask wraps content and lays a gradient band over one of its edges, so
|
|
10
|
+
* scrolling content dissolves towards that edge instead of ending on a hard cut.
|
|
11
|
+
* Put a scroll container in the slot and match `background` to the surface the
|
|
12
|
+
* content sits on.
|
|
13
|
+
*
|
|
14
|
+
* The band is responsive: switch the "Media breakpoint" toolbar between Desktop
|
|
15
|
+
* and Mobile to compare both renderings. Mobile uses a shorter band, and its
|
|
16
|
+
* bottom gradient turns opaque near the top of the band instead of ramping
|
|
17
|
+
* across the full height.
|
|
18
|
+
*/
|
|
19
|
+
const meta: Meta<typeof UiFadeMask> = {
|
|
20
|
+
title: 'Components/UiFadeMask',
|
|
21
|
+
component: UiFadeMask,
|
|
22
|
+
tags: ['autodocs'],
|
|
23
|
+
argTypes: {
|
|
24
|
+
background: {
|
|
25
|
+
control: 'select',
|
|
26
|
+
options: ['primary', 'secondary'],
|
|
27
|
+
description:
|
|
28
|
+
'Surface the gradient fades into. Match it to the background the wrapped content sits on.\n\n@default "secondary"',
|
|
29
|
+
},
|
|
30
|
+
position: {
|
|
31
|
+
control: 'select',
|
|
32
|
+
options: ['top', 'bottom'],
|
|
33
|
+
description:
|
|
34
|
+
'Edge the band is pinned to. `top` is opaque at the top and fades downwards, `bottom` is opaque at the bottom and fades upwards.\n\n@default "top"',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
args: {
|
|
38
|
+
background: 'secondary',
|
|
39
|
+
position: 'top',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default meta;
|
|
44
|
+
|
|
45
|
+
type Story = StoryObj<typeof UiFadeMask>;
|
|
46
|
+
|
|
47
|
+
const SCROLL_REGION_LABEL = 'Release notes';
|
|
48
|
+
|
|
49
|
+
/** Height the band should occupy below and from the `md` breakpoint, in pixels. */
|
|
50
|
+
const BAND_HEIGHT = { mobile: 64, desktop: 96 } as const;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* A scrollable region needs to be reachable by keyboard when it holds no
|
|
54
|
+
* focusable content of its own (WCAG 2.1.1), hence the role, label and
|
|
55
|
+
* `tabindex` on the scroll container in every story.
|
|
56
|
+
*/
|
|
57
|
+
const scrollRegionAttributes = `role="region" aria-label="${SCROLL_REGION_LABEL}" tabindex="0"`;
|
|
58
|
+
|
|
59
|
+
const scrollingParagraphs = `
|
|
60
|
+
<h4 class="body-14-medium text-content-on-surface-primary">Deployment boundaries</h4>
|
|
61
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
62
|
+
Sovereign AI keeps model weights, data and operations inside the boundary a
|
|
63
|
+
customer controls, which makes deployment topology part of the product rather
|
|
64
|
+
than an afterthought handled by whoever operates the cluster.
|
|
65
|
+
</p>
|
|
66
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
67
|
+
Scroll this panel: the band stays pinned to its edge while the text moves
|
|
68
|
+
underneath it, because the gradient sits in the wrapper rather than in the
|
|
69
|
+
scrolling element itself.
|
|
70
|
+
</p>
|
|
71
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
72
|
+
That is the whole point of wrapping the scroll container instead of placing
|
|
73
|
+
the gradient inside it. A gradient inside the scroll area would travel with
|
|
74
|
+
the content and drift out of view on the first swipe.
|
|
75
|
+
</p>
|
|
76
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
77
|
+
The band is decorative and lets pointer events through, so scrolling, text
|
|
78
|
+
selection and clicks on the content underneath all keep working while it is
|
|
79
|
+
on screen.
|
|
80
|
+
</p>
|
|
81
|
+
<h4 class="body-14-medium text-content-on-surface-primary">Responsive behaviour</h4>
|
|
82
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
83
|
+
Switch the Media breakpoint toolbar between Desktop and Mobile to compare
|
|
84
|
+
both renderings of the band. Mobile gets a shorter runway, and its bottom
|
|
85
|
+
gradient turns opaque much earlier.
|
|
86
|
+
</p>
|
|
87
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
88
|
+
Keep the wrapper background aligned with the surface the content sits on. A
|
|
89
|
+
mismatch is most obvious here, halfway through a scroll, where the fade ends
|
|
90
|
+
on a visible horizontal seam.
|
|
91
|
+
</p>
|
|
92
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
93
|
+
The fade covers a fixed strip of the container, so a taller panel shows more
|
|
94
|
+
unmasked content while the masked strip stays the same size.
|
|
95
|
+
</p>
|
|
96
|
+
<h4 class="body-14-medium text-content-on-surface-primary">Reaching the end</h4>
|
|
97
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
98
|
+
With a bottom band, the last line of a scroll area never sits flush against
|
|
99
|
+
the container edge, which is what tells a reader there is nothing more to
|
|
100
|
+
scroll to.
|
|
101
|
+
</p>
|
|
102
|
+
<p class="body-14-regular text-content-on-surface-primary">
|
|
103
|
+
This is the final paragraph, so a bottom-anchored band should be covering it
|
|
104
|
+
completely once you get here.
|
|
105
|
+
</p>
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
const scrollPanel = `<div
|
|
109
|
+
${scrollRegionAttributes}
|
|
110
|
+
class="flex h-80 flex-col gap-y-4 overflow-y-auto p-4"
|
|
111
|
+
>${scrollingParagraphs}</div>`;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Resolves the band element the component renders inside its wrapper.
|
|
115
|
+
* @param canvasElement Story canvas to search.
|
|
116
|
+
*/
|
|
117
|
+
function getBand(canvasElement: HTMLElement): HTMLElement {
|
|
118
|
+
const band = canvasElement.querySelector<HTMLElement>('.ui-fade-mask__band');
|
|
119
|
+
if (!band) throw new Error('UiFadeMask did not render a band.');
|
|
120
|
+
return band;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const defaultTemplateSource = `<script setup lang="ts">
|
|
124
|
+
import { UiFadeMask } from '@aleph-alpha/ui-library'
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<template>
|
|
128
|
+
<UiFadeMask
|
|
129
|
+
position="top"
|
|
130
|
+
background="secondary"
|
|
131
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
132
|
+
>
|
|
133
|
+
<!-- A scroll area without focusable content still has to be tabbable. -->
|
|
134
|
+
<div
|
|
135
|
+
role="region"
|
|
136
|
+
aria-label="Release notes"
|
|
137
|
+
tabindex="0"
|
|
138
|
+
class="flex h-80 flex-col gap-y-4 overflow-y-auto p-4"
|
|
139
|
+
>
|
|
140
|
+
<p>Long, scrollable content …</p>
|
|
141
|
+
</div>
|
|
142
|
+
</UiFadeMask>
|
|
143
|
+
</template>`;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The band pinned to the top edge: content fades out as it scrolls up under a
|
|
147
|
+
* header or the container edge.
|
|
148
|
+
*/
|
|
149
|
+
export const Default: Story = {
|
|
150
|
+
render: (args) => ({
|
|
151
|
+
components: { UiFadeMask },
|
|
152
|
+
setup() {
|
|
153
|
+
return { args };
|
|
154
|
+
},
|
|
155
|
+
template: `<UiFadeMask
|
|
156
|
+
v-bind="args"
|
|
157
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
158
|
+
>
|
|
159
|
+
${scrollPanel}
|
|
160
|
+
</UiFadeMask>`,
|
|
161
|
+
}),
|
|
162
|
+
parameters: {
|
|
163
|
+
docs: {
|
|
164
|
+
source: {
|
|
165
|
+
code: defaultTemplateSource,
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const directionTemplateSource = `<script setup lang="ts">
|
|
172
|
+
import { ref } from 'vue'
|
|
173
|
+
import { UiFadeMask, UiToggleGroup, UiToggleGroupItem } from '@aleph-alpha/ui-library'
|
|
174
|
+
import type { UiFadeMaskPosition } from '@aleph-alpha/ui-library'
|
|
175
|
+
|
|
176
|
+
const position = ref<UiFadeMaskPosition>('top')
|
|
177
|
+
|
|
178
|
+
/** The group allows deselecting the active item, which would clear the value. */
|
|
179
|
+
function setPosition(value: string | undefined) {
|
|
180
|
+
if (value === 'top' || value === 'bottom') position.value = value
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<template>
|
|
185
|
+
<div class="flex flex-col gap-y-4">
|
|
186
|
+
<UiToggleGroup
|
|
187
|
+
type="single"
|
|
188
|
+
variant="outline"
|
|
189
|
+
size="sm"
|
|
190
|
+
aria-label="Fade direction"
|
|
191
|
+
:model-value="position"
|
|
192
|
+
@update:model-value="setPosition"
|
|
193
|
+
>
|
|
194
|
+
<UiToggleGroupItem value="top">Top</UiToggleGroupItem>
|
|
195
|
+
<UiToggleGroupItem value="bottom">Bottom</UiToggleGroupItem>
|
|
196
|
+
</UiToggleGroup>
|
|
197
|
+
|
|
198
|
+
<UiFadeMask
|
|
199
|
+
:position="position"
|
|
200
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
201
|
+
>
|
|
202
|
+
<div
|
|
203
|
+
role="region"
|
|
204
|
+
aria-label="Release notes"
|
|
205
|
+
tabindex="0"
|
|
206
|
+
class="flex h-80 flex-col gap-y-4 overflow-y-auto p-4"
|
|
207
|
+
>
|
|
208
|
+
<p>Long, scrollable content …</p>
|
|
209
|
+
</div>
|
|
210
|
+
</UiFadeMask>
|
|
211
|
+
</div>
|
|
212
|
+
</template>`;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Flip the direction with the switch above the panel: `top` pins the opaque end
|
|
216
|
+
* to the top edge, `bottom` mirrors it. Combine it with the Media breakpoint
|
|
217
|
+
* toolbar to see that only the bottom gradient changes between mobile and
|
|
218
|
+
* desktop.
|
|
219
|
+
*/
|
|
220
|
+
export const Direction: Story = {
|
|
221
|
+
render: (args) => ({
|
|
222
|
+
components: { UiFadeMask, UiToggleGroup, UiToggleGroupItem },
|
|
223
|
+
setup() {
|
|
224
|
+
const position = ref<UiFadeMaskPosition>(args.position ?? 'top');
|
|
225
|
+
|
|
226
|
+
watch(
|
|
227
|
+
() => args.position,
|
|
228
|
+
(value) => {
|
|
229
|
+
if (value) position.value = value;
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
function setPosition(value: string | undefined) {
|
|
234
|
+
if (value === 'top' || value === 'bottom') position.value = value;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return { args, position, setPosition };
|
|
238
|
+
},
|
|
239
|
+
template: `<div class="flex flex-col gap-y-4">
|
|
240
|
+
<UiToggleGroup
|
|
241
|
+
type="single"
|
|
242
|
+
variant="outline"
|
|
243
|
+
size="sm"
|
|
244
|
+
aria-label="Fade direction"
|
|
245
|
+
:model-value="position"
|
|
246
|
+
@update:model-value="setPosition"
|
|
247
|
+
>
|
|
248
|
+
<UiToggleGroupItem value="top">Top</UiToggleGroupItem>
|
|
249
|
+
<UiToggleGroupItem value="bottom">Bottom</UiToggleGroupItem>
|
|
250
|
+
</UiToggleGroup>
|
|
251
|
+
|
|
252
|
+
<UiFadeMask
|
|
253
|
+
:position="position"
|
|
254
|
+
:background="args.background"
|
|
255
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
256
|
+
>
|
|
257
|
+
${scrollPanel}
|
|
258
|
+
</UiFadeMask>
|
|
259
|
+
</div>`,
|
|
260
|
+
}),
|
|
261
|
+
parameters: {
|
|
262
|
+
// The play function presses the toggle items, which leaves a focus ring.
|
|
263
|
+
chromatic: { disableSnapshot: true },
|
|
264
|
+
docs: {
|
|
265
|
+
source: {
|
|
266
|
+
code: directionTemplateSource,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
play: async ({ canvasElement, step }) => {
|
|
271
|
+
// Scenario (UiFadeMask): the switch re-pins the band to the chosen edge, and
|
|
272
|
+
// the band stays a decorative layer that never intercepts the content it
|
|
273
|
+
// covers.
|
|
274
|
+
const canvas = within(canvasElement);
|
|
275
|
+
const band = getBand(canvasElement);
|
|
276
|
+
|
|
277
|
+
await step('interaction: the band moves to the selected edge', async () => {
|
|
278
|
+
await expect(band).toHaveAttribute('data-position', 'top');
|
|
279
|
+
|
|
280
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Bottom' }));
|
|
281
|
+
await expect(band).toHaveAttribute('data-position', 'bottom');
|
|
282
|
+
|
|
283
|
+
await userEvent.click(canvas.getByRole('button', { name: 'Top' }));
|
|
284
|
+
await expect(band).toHaveAttribute('data-position', 'top');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
await step(
|
|
288
|
+
'interaction: pointer events pass through the band to the content underneath',
|
|
289
|
+
async () => {
|
|
290
|
+
const { left, top, width, height } = band.getBoundingClientRect();
|
|
291
|
+
const hit = document.elementFromPoint(
|
|
292
|
+
left + width / 2,
|
|
293
|
+
top + height / 2,
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
await expect(hit).not.toBe(band);
|
|
297
|
+
await expect(band.contains(hit)).toBe(false);
|
|
298
|
+
},
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
await step(
|
|
302
|
+
'screen-reader: the band is hidden and the scroll region keeps its name',
|
|
303
|
+
async () => {
|
|
304
|
+
await expect(band).toHaveAttribute('aria-hidden', 'true');
|
|
305
|
+
await expect(
|
|
306
|
+
canvas.getByRole('region', { name: SCROLL_REGION_LABEL }),
|
|
307
|
+
).toBeInTheDocument();
|
|
308
|
+
},
|
|
309
|
+
);
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const primaryTemplateSource = `<script setup lang="ts">
|
|
314
|
+
import { UiFadeMask } from '@aleph-alpha/ui-library'
|
|
315
|
+
</script>
|
|
316
|
+
|
|
317
|
+
<template>
|
|
318
|
+
<UiFadeMask
|
|
319
|
+
position="bottom"
|
|
320
|
+
background="primary"
|
|
321
|
+
class="overflow-hidden rounded-lg bg-background-surface-primary"
|
|
322
|
+
>
|
|
323
|
+
<div
|
|
324
|
+
role="region"
|
|
325
|
+
aria-label="Release notes"
|
|
326
|
+
tabindex="0"
|
|
327
|
+
class="flex h-80 flex-col gap-y-4 overflow-y-auto p-4"
|
|
328
|
+
>
|
|
329
|
+
<p>Long, scrollable content …</p>
|
|
330
|
+
</div>
|
|
331
|
+
</UiFadeMask>
|
|
332
|
+
</template>`;
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* On the base app layer, use `background="primary"`. A mismatched background
|
|
336
|
+
* leaves a visible seam where the gradient stops.
|
|
337
|
+
*/
|
|
338
|
+
export const OnPrimarySurface: Story = {
|
|
339
|
+
args: {
|
|
340
|
+
background: 'primary',
|
|
341
|
+
position: 'bottom',
|
|
342
|
+
},
|
|
343
|
+
render: (args) => ({
|
|
344
|
+
components: { UiFadeMask },
|
|
345
|
+
setup() {
|
|
346
|
+
return { args };
|
|
347
|
+
},
|
|
348
|
+
template: `<UiFadeMask
|
|
349
|
+
v-bind="args"
|
|
350
|
+
class="overflow-hidden rounded-lg bg-background-surface-primary"
|
|
351
|
+
>
|
|
352
|
+
${scrollPanel}
|
|
353
|
+
</UiFadeMask>`,
|
|
354
|
+
}),
|
|
355
|
+
parameters: {
|
|
356
|
+
docs: {
|
|
357
|
+
source: {
|
|
358
|
+
code: primaryTemplateSource,
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const allVariantsTemplateSource = `<script setup lang="ts">
|
|
365
|
+
import { UiFadeMask } from '@aleph-alpha/ui-library'
|
|
366
|
+
</script>
|
|
367
|
+
|
|
368
|
+
<template>
|
|
369
|
+
<div class="grid gap-4 md:grid-cols-2">
|
|
370
|
+
<UiFadeMask
|
|
371
|
+
position="top"
|
|
372
|
+
background="secondary"
|
|
373
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
374
|
+
>
|
|
375
|
+
<div class="h-40 p-4">…</div>
|
|
376
|
+
</UiFadeMask>
|
|
377
|
+
<UiFadeMask
|
|
378
|
+
position="bottom"
|
|
379
|
+
background="secondary"
|
|
380
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
381
|
+
>
|
|
382
|
+
<div class="h-40 p-4">…</div>
|
|
383
|
+
</UiFadeMask>
|
|
384
|
+
<UiFadeMask
|
|
385
|
+
position="top"
|
|
386
|
+
background="primary"
|
|
387
|
+
class="overflow-hidden rounded-lg bg-background-surface-primary"
|
|
388
|
+
>
|
|
389
|
+
<div class="h-40 p-4">…</div>
|
|
390
|
+
</UiFadeMask>
|
|
391
|
+
<UiFadeMask
|
|
392
|
+
position="bottom"
|
|
393
|
+
background="primary"
|
|
394
|
+
class="overflow-hidden rounded-lg bg-background-surface-primary"
|
|
395
|
+
>
|
|
396
|
+
<div class="h-40 p-4">…</div>
|
|
397
|
+
</UiFadeMask>
|
|
398
|
+
</div>
|
|
399
|
+
</template>`;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* All four combinations of `background` and `position`, each wrapping
|
|
403
|
+
* contrasting blocks so the gradient direction is visible. Toggle the Media
|
|
404
|
+
* breakpoint between Desktop and Mobile to see all eight modes.
|
|
405
|
+
*/
|
|
406
|
+
export const AllVariants: Story = {
|
|
407
|
+
render: () => ({
|
|
408
|
+
components: { UiFadeMask },
|
|
409
|
+
template: `<div class="grid gap-4 md:grid-cols-2">
|
|
410
|
+
<div
|
|
411
|
+
v-for="variant in [
|
|
412
|
+
{ background: 'secondary', position: 'top' },
|
|
413
|
+
{ background: 'secondary', position: 'bottom' },
|
|
414
|
+
{ background: 'primary', position: 'top' },
|
|
415
|
+
{ background: 'primary', position: 'bottom' },
|
|
416
|
+
]"
|
|
417
|
+
:key="variant.background + variant.position"
|
|
418
|
+
class="flex flex-col gap-y-2"
|
|
419
|
+
>
|
|
420
|
+
<span class="label-12-regular text-content-on-surface-muted">
|
|
421
|
+
{{ variant.background }} · {{ variant.position }}
|
|
422
|
+
</span>
|
|
423
|
+
<UiFadeMask
|
|
424
|
+
:background="variant.background"
|
|
425
|
+
:position="variant.position"
|
|
426
|
+
class="overflow-hidden rounded-lg"
|
|
427
|
+
:class="variant.background === 'primary' ? 'bg-background-surface-primary' : 'bg-background-surface-secondary'"
|
|
428
|
+
>
|
|
429
|
+
<div class="flex h-40 flex-col gap-y-2 p-4">
|
|
430
|
+
<div
|
|
431
|
+
v-for="bar in 9"
|
|
432
|
+
:key="bar"
|
|
433
|
+
class="h-4 shrink-0 rounded bg-background-surface-muted"
|
|
434
|
+
/>
|
|
435
|
+
</div>
|
|
436
|
+
</UiFadeMask>
|
|
437
|
+
</div>
|
|
438
|
+
</div>`,
|
|
439
|
+
}),
|
|
440
|
+
parameters: {
|
|
441
|
+
docs: {
|
|
442
|
+
source: {
|
|
443
|
+
code: allVariantsTemplateSource,
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Keyboard reachability of a masked scroll area. The region under the band is
|
|
451
|
+
* the only tab stop; the band itself must never take focus.
|
|
452
|
+
*/
|
|
453
|
+
export const KeyboardNavigation: Story = {
|
|
454
|
+
name: 'test - Keyboard Navigation',
|
|
455
|
+
tags: ['!dev', '!autodocs'],
|
|
456
|
+
parameters: {
|
|
457
|
+
// The play function moves focus, which would register as a visual diff.
|
|
458
|
+
chromatic: { disableSnapshot: true },
|
|
459
|
+
},
|
|
460
|
+
render: (args) => ({
|
|
461
|
+
components: { UiFadeMask },
|
|
462
|
+
setup() {
|
|
463
|
+
return { args };
|
|
464
|
+
},
|
|
465
|
+
template: `<UiFadeMask
|
|
466
|
+
v-bind="args"
|
|
467
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
468
|
+
>
|
|
469
|
+
${scrollPanel}
|
|
470
|
+
</UiFadeMask>`,
|
|
471
|
+
}),
|
|
472
|
+
play: async ({ canvasElement, step }) => {
|
|
473
|
+
// Scenario (UiFadeMask): a masked scroll area stays operable by keyboard —
|
|
474
|
+
// the region takes focus and the decorative band stays out of the tab order.
|
|
475
|
+
const canvas = within(canvasElement);
|
|
476
|
+
const band = getBand(canvasElement);
|
|
477
|
+
const region = canvas.getByRole('region', { name: SCROLL_REGION_LABEL });
|
|
478
|
+
|
|
479
|
+
await step(
|
|
480
|
+
'keyboard: the masked scroll region is reachable with Tab (WCAG 2.1.1)',
|
|
481
|
+
async () => {
|
|
482
|
+
await userEvent.tab();
|
|
483
|
+
await expect(region).toHaveFocus();
|
|
484
|
+
},
|
|
485
|
+
);
|
|
486
|
+
|
|
487
|
+
await step('keyboard: the band is not a tab stop', async () => {
|
|
488
|
+
await expect(band).not.toHaveAttribute('tabindex');
|
|
489
|
+
await userEvent.tab();
|
|
490
|
+
await expect(band).not.toHaveFocus();
|
|
491
|
+
});
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Rendered at the mobile (320px reflow) breakpoint via the Media breakpoint
|
|
497
|
+
* toolbar. The band switches to its shorter height and the masked panel reflows
|
|
498
|
+
* without sideways scrolling (WCAG 1.4.10).
|
|
499
|
+
*/
|
|
500
|
+
export const MobileBreakpoint: Story = {
|
|
501
|
+
name: 'test - Mobile Breakpoint',
|
|
502
|
+
tags: ['!dev', '!autodocs'],
|
|
503
|
+
globals: { mediaBreakpoint: 'reflow' },
|
|
504
|
+
args: {
|
|
505
|
+
position: 'bottom',
|
|
506
|
+
},
|
|
507
|
+
parameters: {
|
|
508
|
+
// Reflow snapshots are already covered by the accessible-reflow mode.
|
|
509
|
+
chromatic: { disableSnapshot: true },
|
|
510
|
+
docs: {
|
|
511
|
+
description: {
|
|
512
|
+
story:
|
|
513
|
+
'Switch the Media breakpoint toolbar to Mobile to preview the 320px layout.',
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
render: (args) => ({
|
|
518
|
+
components: { UiFadeMask },
|
|
519
|
+
setup() {
|
|
520
|
+
return { args };
|
|
521
|
+
},
|
|
522
|
+
template: `<UiFadeMask
|
|
523
|
+
v-bind="args"
|
|
524
|
+
class="overflow-hidden rounded-lg bg-background-surface-secondary"
|
|
525
|
+
>
|
|
526
|
+
${scrollPanel}
|
|
527
|
+
</UiFadeMask>`,
|
|
528
|
+
}),
|
|
529
|
+
play: async ({ canvasElement, step }) => {
|
|
530
|
+
// Scenario (UiFadeMask): at the 320px mobile breakpoint the band takes its
|
|
531
|
+
// shorter height and the masked panel still fits the viewport.
|
|
532
|
+
const band = getBand(canvasElement);
|
|
533
|
+
|
|
534
|
+
await step(
|
|
535
|
+
'mobile: the story renders at the 320px breakpoint (WCAG 1.4.10 Reflow)',
|
|
536
|
+
async () => {
|
|
537
|
+
await expect(document.documentElement.dataset.aaMediaBreakpoint).toBe(
|
|
538
|
+
'reflow',
|
|
539
|
+
);
|
|
540
|
+
},
|
|
541
|
+
);
|
|
542
|
+
|
|
543
|
+
await step('mobile: the band height follows the breakpoint', async () => {
|
|
544
|
+
// Derived from the same media query the component uses, so the assertion
|
|
545
|
+
// holds in both test runners regardless of their default viewport.
|
|
546
|
+
const isDesktop = window.matchMedia('(min-width: 768px)').matches;
|
|
547
|
+
const expected = isDesktop ? BAND_HEIGHT.desktop : BAND_HEIGHT.mobile;
|
|
548
|
+
|
|
549
|
+
await expect(band.getBoundingClientRect().height).toBeCloseTo(
|
|
550
|
+
expected,
|
|
551
|
+
0,
|
|
552
|
+
);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
await step(
|
|
556
|
+
'mobile: the masked panel fits without sideways scrolling',
|
|
557
|
+
async () => {
|
|
558
|
+
const { scrollWidth, clientWidth } = document.documentElement;
|
|
559
|
+
await expect(scrollWidth).toBeLessThanOrEqual(clientWidth + 1);
|
|
560
|
+
},
|
|
561
|
+
);
|
|
562
|
+
},
|
|
563
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { cn } from '@/lib/utils';
|
|
3
|
+
import type { UiFadeMaskProps } from './types';
|
|
4
|
+
|
|
5
|
+
defineOptions({
|
|
6
|
+
name: 'UiFadeMask',
|
|
7
|
+
inheritAttrs: false,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
withDefaults(defineProps<UiFadeMaskProps>(), {
|
|
11
|
+
background: 'secondary',
|
|
12
|
+
position: 'top',
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<div v-bind="$attrs" :class="cn('ui-fade-mask relative', $attrs.class ?? '')">
|
|
18
|
+
<slot />
|
|
19
|
+
<div
|
|
20
|
+
class="ui-fade-mask__band"
|
|
21
|
+
:data-background="background"
|
|
22
|
+
:data-position="position"
|
|
23
|
+
aria-hidden="true"
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<style scoped>
|
|
29
|
+
/* The band is styled entirely here rather than with utility classes: it is an
|
|
30
|
+
internal layer a consumer can never target, and keeping it out of the utility
|
|
31
|
+
layer means its geometry cannot shift with a consumer's preset setup.
|
|
32
|
+
Its height is the fade runway, driven by a custom property whose default sits
|
|
33
|
+
in the `var()` fallback so a consumer can retune it from the wrapper without
|
|
34
|
+
fighting the specificity of this scoped rule. */
|
|
35
|
+
.ui-fade-mask__band {
|
|
36
|
+
position: absolute;
|
|
37
|
+
right: 0;
|
|
38
|
+
left: 0;
|
|
39
|
+
height: var(--ui-fade-mask-height, 4rem);
|
|
40
|
+
pointer-events: none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.ui-fade-mask__band[data-background='secondary'] {
|
|
44
|
+
--ui-fade-mask-surface: var(--background-surface-secondary);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ui-fade-mask__band[data-background='primary'] {
|
|
48
|
+
--ui-fade-mask-surface: var(--background-surface-primary);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Surface tokens are published as bare oklch components (`L% C H`), so they can
|
|
52
|
+
only be used as a color — and faded to zero alpha — through `oklch()`. */
|
|
53
|
+
.ui-fade-mask__band[data-position='top'] {
|
|
54
|
+
--ui-fade-mask-stop: 49.3%;
|
|
55
|
+
|
|
56
|
+
top: 0;
|
|
57
|
+
background: linear-gradient(
|
|
58
|
+
0deg,
|
|
59
|
+
oklch(var(--ui-fade-mask-surface) / 0) 0%,
|
|
60
|
+
oklch(var(--ui-fade-mask-surface)) var(--ui-fade-mask-stop)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.ui-fade-mask__band[data-position='bottom'] {
|
|
65
|
+
--ui-fade-mask-stop: 20%;
|
|
66
|
+
|
|
67
|
+
bottom: 0;
|
|
68
|
+
background: linear-gradient(
|
|
69
|
+
180deg,
|
|
70
|
+
oklch(var(--ui-fade-mask-surface) / 0) 0%,
|
|
71
|
+
oklch(var(--ui-fade-mask-surface)) var(--ui-fade-mask-stop)
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* Desktop gets a taller band, and its bottom fade ramps across the full height
|
|
76
|
+
instead of turning opaque early. 768px mirrors the `md` breakpoint. */
|
|
77
|
+
@media (min-width: 768px) {
|
|
78
|
+
.ui-fade-mask__band {
|
|
79
|
+
height: var(--ui-fade-mask-height, 6rem);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.ui-fade-mask__band[data-position='bottom'] {
|
|
83
|
+
--ui-fade-mask-stop: 100%;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import UiFadeMask from '../UiFadeMask.vue';
|
|
4
|
+
|
|
5
|
+
const CONTENT = '<p>Wrapped content</p>';
|
|
6
|
+
|
|
7
|
+
function renderFadeMask(options?: Parameters<typeof render>[1]) {
|
|
8
|
+
const { container } = render(UiFadeMask, {
|
|
9
|
+
slots: { default: CONTENT },
|
|
10
|
+
...options,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
wrapper: container.firstElementChild,
|
|
15
|
+
band: container.querySelector('.ui-fade-mask__band'),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('UiFadeMask', () => {
|
|
20
|
+
test('defaults the band to a secondary surface pinned to the top', () => {
|
|
21
|
+
const { band } = renderFadeMask();
|
|
22
|
+
expect(band).toHaveAttribute('data-background', 'secondary');
|
|
23
|
+
expect(band).toHaveAttribute('data-position', 'top');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('exposes background and position as data attributes for the gradient', () => {
|
|
27
|
+
const { band } = renderFadeMask({
|
|
28
|
+
props: { background: 'primary', position: 'bottom' },
|
|
29
|
+
});
|
|
30
|
+
expect(band).toHaveAttribute('data-background', 'primary');
|
|
31
|
+
expect(band).toHaveAttribute('data-position', 'bottom');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('keeps the band decorative and empty', () => {
|
|
35
|
+
const { band } = renderFadeMask();
|
|
36
|
+
expect(band).toHaveAttribute('aria-hidden', 'true');
|
|
37
|
+
expect(band).toBeEmptyDOMElement();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('positions the wrapper so the band can anchor to its edges', () => {
|
|
41
|
+
const { wrapper } = renderFadeMask();
|
|
42
|
+
expect(wrapper).toHaveClass('relative');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('merges a consumer class into the wrapper', () => {
|
|
46
|
+
const { wrapper } = renderFadeMask({
|
|
47
|
+
attrs: { class: 'absolute rounded-lg' },
|
|
48
|
+
});
|
|
49
|
+
expect(wrapper).toHaveClass('absolute', 'rounded-lg');
|
|
50
|
+
expect(wrapper).not.toHaveClass('relative');
|
|
51
|
+
});
|
|
52
|
+
});
|