@aleph-alpha/ui-library 5.9.0 → 5.10.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 +157 -4
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
- package/dist/system/components/UiFileType/types.d.ts +2 -1
- package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
- package/dist/system/components/UiSwitch/types.d.ts +12 -0
- package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
- package/dist/system/components/core/switch/index.d.ts +8 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/scrollbar.d.ts +37 -0
- package/dist/system/lib/useAnchorFloat.d.ts +0 -2
- package/dist/system/lib/useIsTruncated.d.ts +15 -0
- package/dist/system/lib.js +15052 -14843
- package/dist/system/patterns/UiFloatActions/types.d.ts +0 -1
- package/dist/system/story-sidebar-icons.json +4 -1
- package/docs/public-docs/foundations.md +17 -15
- package/package.json +3 -3
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
- package/src/components/UiFileItem/UiFileItem.vue +17 -4
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
- package/src/components/UiFileType/UiFileType.stories.ts +13 -2
- package/src/components/UiFileType/UiFileType.vue +8 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
- package/src/components/UiFileType/types.ts +3 -1
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
- package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
- package/src/components/UiSwitch/UiSwitch.vue +1 -0
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
- package/src/components/UiSwitch/types.ts +13 -0
- package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/switch/Switch.vue +23 -17
- package/src/components/core/switch/index.ts +36 -0
- package/src/index.ts +3 -0
- package/src/lib/scrollbar.ts +295 -0
- package/src/lib/useAnchorFloat.ts +0 -2
- package/src/lib/useIsTruncated.test.ts +174 -0
- package/src/lib/useIsTruncated.ts +75 -0
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.vue +1 -2
- package/src/patterns/UiFloatActions/types.ts +0 -1
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +132 -117
- package/src/theme/Background.stories.ts +27 -1
- package/src/theme/BorderRadius.stories.ts +5 -0
- package/src/theme/Overlay.stories.ts +12 -1
- package/src/theme/Scrollbar.stories.ts +260 -0
- package/tokens.json +224 -2
- package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { render } from '@testing-library/vue';
|
|
1
|
+
import { render, screen } from '@testing-library/vue';
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
4
4
|
import UiFileItem from '../UiFileItem.vue';
|
|
5
5
|
|
|
6
|
+
// jsdom has no layout, so the truncation probe is driven directly: what is
|
|
7
|
+
// under test is that the tooltip follows it, not how the measurement works.
|
|
8
|
+
// Hoisted because `vi.mock`'s factory is lifted above ordinary declarations.
|
|
9
|
+
const { isTruncated } = vi.hoisted(() => ({ isTruncated: { value: false } }));
|
|
10
|
+
vi.mock('@/lib/useIsTruncated', () => ({
|
|
11
|
+
useIsTruncated: () => isTruncated,
|
|
12
|
+
}));
|
|
13
|
+
|
|
6
14
|
describe('UiFileItem', () => {
|
|
15
|
+
// Interaction, keyboard, and accessibility behavior lives in the play stories
|
|
16
|
+
// in `src/patterns/UiFileUpload/UiFileItem.stories.ts`: the remove event and
|
|
17
|
+
// its disabled guard, the omitted control when `removable` is false, the error
|
|
18
|
+
// alert region, progress and error taking precedence over the type|size meta,
|
|
19
|
+
// and the extension-derived `UiFileType` tone. Those need a real browser for
|
|
20
|
+
// focus order, touch-target size, and accessible-name computation, so they are
|
|
21
|
+
// not duplicated here.
|
|
22
|
+
|
|
7
23
|
test('renders the basename (without extension) and the type | size meta', () => {
|
|
8
24
|
const { container, getByText, getByLabelText } = render(UiFileItem, {
|
|
9
25
|
props: {
|
|
@@ -23,108 +39,51 @@ describe('UiFileItem', () => {
|
|
|
23
39
|
);
|
|
24
40
|
});
|
|
25
41
|
|
|
26
|
-
test('
|
|
27
|
-
|
|
28
|
-
props: { filename: '.gitignore' },
|
|
29
|
-
});
|
|
30
|
-
expect(getByText('.gitignore')).toBeInTheDocument();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test('emits remove when remove control is activated', async () => {
|
|
42
|
+
test('keeps the name tooltip closed while the name fits', async () => {
|
|
43
|
+
isTruncated.value = false;
|
|
34
44
|
const user = userEvent.setup();
|
|
35
|
-
|
|
36
|
-
props: {
|
|
37
|
-
filename: 'x.txt',
|
|
38
|
-
removeLabel: 'Remove file',
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
await user.click(getByRole('button', { name: 'Remove file' }));
|
|
42
|
-
expect(emitted('remove')).toHaveLength(1);
|
|
43
|
-
});
|
|
45
|
+
render(UiFileItem, { props: { filename: 'doc.pdf' } });
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
filename: 'x.txt',
|
|
49
|
-
removeLabel: 'Remove file',
|
|
50
|
-
removable: false,
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
expect(queryByRole('button', { name: 'Remove file' })).toBeNull();
|
|
54
|
-
});
|
|
47
|
+
await user.hover(screen.getByText('doc'));
|
|
48
|
+
// Past the tooltip's open delay, so this is a real absence, not a race.
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
props: {
|
|
59
|
-
filename: 'bad.exe',
|
|
60
|
-
error: 'Unsupported file type',
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
expect(getByText('Unsupported file type')).toBeInTheDocument();
|
|
64
|
-
expect(getByRole('alert')).toHaveTextContent('Unsupported file type');
|
|
51
|
+
// The tooltip portals to the body, so it is searched document-wide.
|
|
52
|
+
expect(screen.queryByRole('tooltip')).toBeNull();
|
|
65
53
|
});
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
typeLabel: 'EXE',
|
|
72
|
-
sizeLabel: '2 MB',
|
|
73
|
-
error: 'Unsupported',
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
// Error state replaces the meta line.
|
|
77
|
-
expect(queryByText('EXE')).toBeNull();
|
|
78
|
-
expect(queryByText('2 MB')).toBeNull();
|
|
79
|
-
expect(getByText('Unsupported')).toBeInTheDocument();
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('renders a progress bar when progress is between 0 and 100', () => {
|
|
83
|
-
const { container } = render(UiFileItem, {
|
|
84
|
-
props: {
|
|
85
|
-
filename: 'upload.zip',
|
|
86
|
-
progress: 35,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
expect(
|
|
90
|
-
container.querySelector('[data-slot="progress"]'),
|
|
91
|
-
).toBeInTheDocument();
|
|
92
|
-
});
|
|
55
|
+
// The positive case (a clipped name opening the tooltip) needs real layout
|
|
56
|
+
// and pointer handling, which jsdom does not provide: reka never opens. It is
|
|
57
|
+
// covered by the `TruncatedName` story in
|
|
58
|
+
// `src/patterns/UiFileUpload/UiFileItem.stories.ts`.
|
|
93
59
|
|
|
94
|
-
test('
|
|
95
|
-
const {
|
|
96
|
-
props: {
|
|
97
|
-
filename: 'upload.zip',
|
|
98
|
-
typeLabel: 'ZIP',
|
|
99
|
-
sizeLabel: '12 MB',
|
|
100
|
-
progress: 35,
|
|
101
|
-
},
|
|
60
|
+
test('leaves dotfile names without extension segment unchanged', () => {
|
|
61
|
+
const { getByText } = render(UiFileItem, {
|
|
62
|
+
props: { filename: '.gitignore' },
|
|
102
63
|
});
|
|
103
|
-
|
|
104
|
-
expect(queryByText('ZIP')).toBeNull();
|
|
105
|
-
expect(queryByText('12 MB')).toBeNull();
|
|
64
|
+
expect(getByText('.gitignore')).toBeInTheDocument();
|
|
106
65
|
});
|
|
107
66
|
|
|
108
|
-
test('
|
|
109
|
-
const
|
|
110
|
-
const { getByRole, emitted } = render(UiFileItem, {
|
|
67
|
+
test('small size tightens the row padding and the title scale', () => {
|
|
68
|
+
const { container, getByLabelText } = render(UiFileItem, {
|
|
111
69
|
props: {
|
|
112
|
-
filename: '
|
|
113
|
-
|
|
114
|
-
disabled: true,
|
|
70
|
+
filename: 'doc.pdf',
|
|
71
|
+
size: 'small',
|
|
115
72
|
},
|
|
116
73
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
expect(
|
|
74
|
+
expect(container.querySelector('[data-slot="file-item"]')).toHaveClass(
|
|
75
|
+
'p-2',
|
|
76
|
+
);
|
|
77
|
+
expect(getByLabelText('doc.pdf')).toHaveClass('label-12-medium');
|
|
121
78
|
});
|
|
122
79
|
|
|
123
|
-
test('
|
|
124
|
-
const { container } = render(UiFileItem, {
|
|
125
|
-
props: { filename: '
|
|
80
|
+
test('default size keeps the roomier padding and title scale', () => {
|
|
81
|
+
const { container, getByLabelText } = render(UiFileItem, {
|
|
82
|
+
props: { filename: 'doc.pdf' },
|
|
126
83
|
});
|
|
127
|
-
|
|
128
|
-
|
|
84
|
+
expect(container.querySelector('[data-slot="file-item"]')).toHaveClass(
|
|
85
|
+
'p-3',
|
|
86
|
+
);
|
|
87
|
+
expect(getByLabelText('doc.pdf')).toHaveClass('body-14-medium');
|
|
129
88
|
});
|
|
130
89
|
});
|
|
@@ -27,9 +27,10 @@ const meta: Meta<typeof UiFileType> = {
|
|
|
27
27
|
'accent-pink',
|
|
28
28
|
'accent-soft',
|
|
29
29
|
'accent-yellow',
|
|
30
|
+
'accent-orange',
|
|
30
31
|
],
|
|
31
32
|
description:
|
|
32
|
-
'Color tone override. Leave undefined to auto-derive from the filename extension (pdf/docx/txt → pink, html/md → soft, csv/xls/tsv → yellow).',
|
|
33
|
+
'Color tone override. Leave undefined to auto-derive from the filename extension (pdf/docx/txt → pink, html/md → soft, csv/xls/tsv → yellow, mp4/mov/webm → orange).',
|
|
33
34
|
},
|
|
34
35
|
icon: {
|
|
35
36
|
control: 'text',
|
|
@@ -105,6 +106,7 @@ import { UiFileType } from '@aleph-alpha/ui-library'
|
|
|
105
106
|
<UiFileType filename="report.pdf" />
|
|
106
107
|
<UiFileType filename="README.md" />
|
|
107
108
|
<UiFileType filename="data.csv" />
|
|
109
|
+
<UiFileType filename="trailer.mp4" />
|
|
108
110
|
<UiFileType filename="archive.zip" />
|
|
109
111
|
<UiFileType filename="data.csv" :error="true" />
|
|
110
112
|
</div>
|
|
@@ -126,6 +128,7 @@ export const AllTypes: Story = {
|
|
|
126
128
|
<UiFileType filename="report.pdf" />
|
|
127
129
|
<UiFileType filename="README.md" />
|
|
128
130
|
<UiFileType filename="data.csv" />
|
|
131
|
+
<UiFileType filename="trailer.mp4" />
|
|
129
132
|
<UiFileType filename="archive.zip" />
|
|
130
133
|
<UiFileType filename="data.csv" :error="true" />
|
|
131
134
|
</div>
|
|
@@ -155,12 +158,16 @@ import { UiFileType } from '@aleph-alpha/ui-library'
|
|
|
155
158
|
<UiFileType tone="accent-yellow" icon="table-2" />
|
|
156
159
|
<span class="body-14-regular text-content-on-surface-secondary">accent-yellow</span>
|
|
157
160
|
</div>
|
|
161
|
+
<div class="flex items-center gap-3">
|
|
162
|
+
<UiFileType tone="accent-orange" icon="image-play" />
|
|
163
|
+
<span class="body-14-regular text-content-on-surface-secondary">accent-orange</span>
|
|
164
|
+
</div>
|
|
158
165
|
</div>
|
|
159
166
|
</template>`;
|
|
160
167
|
|
|
161
168
|
/**
|
|
162
169
|
* Explicit tone overrides for checking the token-backed badge colors,
|
|
163
|
-
* including the pink and
|
|
170
|
+
* including the pink, yellow, and orange accent tokens.
|
|
164
171
|
*/
|
|
165
172
|
export const ToneOverrides: Story = {
|
|
166
173
|
parameters: {
|
|
@@ -187,6 +194,10 @@ export const ToneOverrides: Story = {
|
|
|
187
194
|
<UiFileType tone="accent-yellow" icon="table-2" />
|
|
188
195
|
<span class="body-14-regular text-content-on-surface-secondary">accent-yellow</span>
|
|
189
196
|
</div>
|
|
197
|
+
<div class="flex items-center gap-3">
|
|
198
|
+
<UiFileType tone="accent-orange" icon="image-play" />
|
|
199
|
+
<span class="body-14-regular text-content-on-surface-secondary">accent-orange</span>
|
|
200
|
+
</div>
|
|
190
201
|
</div>
|
|
191
202
|
`,
|
|
192
203
|
}),
|
|
@@ -48,6 +48,13 @@ const FILE_TYPE_PRESETS: Record<string, FileTypePreset> = {
|
|
|
48
48
|
tsv: { tone: 'accent-yellow', icon: 'table-2' },
|
|
49
49
|
xls: { tone: 'accent-yellow', icon: 'table-2' },
|
|
50
50
|
xlsx: { tone: 'accent-yellow', icon: 'table-2' },
|
|
51
|
+
// Type=Media → accent-orange + image-play icon.
|
|
52
|
+
mp4: { tone: 'accent-orange', icon: 'image-play' },
|
|
53
|
+
m4v: { tone: 'accent-orange', icon: 'image-play' },
|
|
54
|
+
mov: { tone: 'accent-orange', icon: 'image-play' },
|
|
55
|
+
webm: { tone: 'accent-orange', icon: 'image-play' },
|
|
56
|
+
mkv: { tone: 'accent-orange', icon: 'image-play' },
|
|
57
|
+
avi: { tone: 'accent-orange', icon: 'image-play' },
|
|
51
58
|
};
|
|
52
59
|
|
|
53
60
|
const DEFAULT_PRESET: FileTypePreset = { tone: 'default', icon: 'file' };
|
|
@@ -85,6 +92,7 @@ const TONE_FILL: Record<UiFileTypeTone, string> = {
|
|
|
85
92
|
'accent-pink': 'bg-background-accent-pink',
|
|
86
93
|
'accent-soft': 'bg-background-accent-soft',
|
|
87
94
|
'accent-yellow': 'bg-background-accent-yellow',
|
|
95
|
+
'accent-orange': 'bg-background-accent-orange',
|
|
88
96
|
};
|
|
89
97
|
|
|
90
98
|
const badgeClass = computed(() =>
|
|
@@ -11,6 +11,16 @@ describe('UiFileType', () => {
|
|
|
11
11
|
{ filename: 'report.pdf', tone: 'accent-pink', icon: 'lucide-file' },
|
|
12
12
|
{ filename: 'README.md', tone: 'accent-soft', icon: 'lucide-code-xml' },
|
|
13
13
|
{ filename: 'data.csv', tone: 'accent-yellow', icon: 'lucide-table-2' },
|
|
14
|
+
{
|
|
15
|
+
filename: 'trailer.mp4',
|
|
16
|
+
tone: 'accent-orange',
|
|
17
|
+
icon: 'lucide-image-play',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
filename: 'clip.MOV',
|
|
21
|
+
tone: 'accent-orange',
|
|
22
|
+
icon: 'lucide-image-play',
|
|
23
|
+
},
|
|
14
24
|
{ filename: 'archive.zip', tone: 'default', icon: 'lucide-file' },
|
|
15
25
|
{ filename: undefined, tone: 'default', icon: 'lucide-file' },
|
|
16
26
|
])('$filename → $tone + $icon', ({ filename, tone, icon }) => {
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - `Type=Text` (`pdf` / `doc` / `docx` / `txt` / `rtf`) → `accent-pink` + `file`
|
|
7
7
|
* - `Type=Markdown` (`html` / `htm` / `md` / `mdx`) → `accent-soft` + `code-xml`
|
|
8
8
|
* - `Type=Tabular` (`csv` / `tsv` / `xls` / `xlsx`) → `accent-yellow` + `table-2`
|
|
9
|
+
* - `Type=Media` (`mp4` / `mov` / `webm` / `mkv` / …) → `accent-orange` + `image-play`
|
|
9
10
|
* - everything else → `default` + `file`
|
|
10
11
|
* @see {@link https://www.figma.com/design/SrZQ19QVN1sQkuAMnMC746/AA26--WIP-?node-id=26438-42144}
|
|
11
12
|
* @category Data Display
|
|
@@ -17,7 +18,8 @@ export type UiFileTypeTone =
|
|
|
17
18
|
| 'default'
|
|
18
19
|
| 'accent-pink'
|
|
19
20
|
| 'accent-soft'
|
|
20
|
-
| 'accent-yellow'
|
|
21
|
+
| 'accent-yellow'
|
|
22
|
+
| 'accent-orange';
|
|
21
23
|
|
|
22
24
|
export interface UiFileTypeProps {
|
|
23
25
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
+
import { fn } from 'storybook/test';
|
|
2
3
|
import { ref } from 'vue';
|
|
3
4
|
import { showSnackbar, showSnackbarPromise, UiSnackbar } from './index';
|
|
4
5
|
import { UiButton } from '../UiButton';
|
|
@@ -89,7 +90,7 @@ export const Default: Story = {
|
|
|
89
90
|
actionLabel: SNACKBAR_ACTION_LABEL,
|
|
90
91
|
actionMode: 'default',
|
|
91
92
|
iconMode: 'info',
|
|
92
|
-
onAction: ()
|
|
93
|
+
onAction: fn(),
|
|
93
94
|
toasterId,
|
|
94
95
|
});
|
|
95
96
|
return { args, show, toasterId };
|
|
@@ -192,7 +193,6 @@ const SNACKBAR_ICON_MODES = [
|
|
|
192
193
|
* Built-in status icons for success, info, warning, error, and loading.
|
|
193
194
|
*/
|
|
194
195
|
export const IconModes: Story = {
|
|
195
|
-
name: 'Icon Modes',
|
|
196
196
|
render: (args) => ({
|
|
197
197
|
components: { UiSnackbar, UiButton },
|
|
198
198
|
setup() {
|
|
@@ -263,7 +263,6 @@ const SNACKBAR_ACTION_MODES = ['default', 'secondary'] as const;
|
|
|
263
263
|
* Built-in action button modes: default (primary) and secondary.
|
|
264
264
|
*/
|
|
265
265
|
export const ActionModes: Story = {
|
|
266
|
-
name: 'Action Modes',
|
|
267
266
|
render: (args) => ({
|
|
268
267
|
components: { UiSnackbar, UiButton },
|
|
269
268
|
setup() {
|
|
@@ -273,7 +272,7 @@ export const ActionModes: Story = {
|
|
|
273
272
|
title: SNACKBAR_ACTION_TITLE,
|
|
274
273
|
actionLabel: SNACKBAR_ACTION_LABEL,
|
|
275
274
|
actionMode,
|
|
276
|
-
onAction: ()
|
|
275
|
+
onAction: fn(),
|
|
277
276
|
toasterId,
|
|
278
277
|
});
|
|
279
278
|
return { args, show, toasterId, modes: SNACKBAR_ACTION_MODES };
|
|
@@ -332,7 +331,7 @@ export const WithAction: Story = {
|
|
|
332
331
|
title: SNACKBAR_ACTION_TITLE,
|
|
333
332
|
actionLabel: SNACKBAR_ACTION_LABEL,
|
|
334
333
|
actionMode: 'default',
|
|
335
|
-
onAction: ()
|
|
334
|
+
onAction: fn(),
|
|
336
335
|
toasterId,
|
|
337
336
|
});
|
|
338
337
|
return { args, show, toasterId };
|