@aleph-alpha/ui-library 2.4.4 → 2.5.2
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.d.ts +33 -2
- package/config.js +145 -47
- package/dist/system/components/UiAvatar/UiAvatar.vue.d.ts +4 -1
- package/dist/system/components/UiAvatar/UiAvatarGroup.vue.d.ts +18 -0
- package/dist/system/components/UiAvatar/index.d.ts +1 -0
- package/dist/system/components/UiAvatar/types.d.ts +12 -1
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +6 -1
- package/dist/system/components/UiFileItem/types.d.ts +30 -10
- package/dist/system/components/UiFileType/UiFileType.vue.d.ts +8 -0
- package/dist/system/components/UiFileType/index.d.ts +2 -0
- package/dist/system/components/UiFileType/types.d.ts +33 -0
- package/dist/system/components/UiItem/UiItem.vue.d.ts +8 -1
- package/dist/system/components/UiItem/constants.d.ts +4 -3
- package/dist/system/components/UiItem/index.d.ts +1 -1
- package/dist/system/components/UiItem/types.d.ts +53 -13
- package/dist/system/components/core/avatar/Avatar.vue.d.ts +2 -0
- package/dist/system/components/core/avatar/index.d.ts +1 -0
- package/dist/system/components/core/calendar/Calendar.vue.d.ts +247 -3
- package/dist/system/components/core/item/Item.vue.d.ts +1 -1
- package/dist/system/components/core/item/ItemAction.vue.d.ts +25 -0
- package/dist/system/components/core/item/index.d.ts +8 -4
- package/dist/system/components/core/popover/PopoverContent.vue.d.ts +1 -1
- package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +139 -2
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib/activeIndicator.d.ts +1 -0
- package/dist/system/lib.js +6700 -6448
- package/dist/system/patterns/UiSidebar/activeIndicator.d.ts +1 -15
- package/package.json +1 -1
- package/src/components/UiAvatar/UiAvatar.stories.ts +103 -12
- package/src/components/UiAvatar/UiAvatar.vue +6 -1
- package/src/components/UiAvatar/UiAvatarGroup.vue +16 -0
- package/src/components/UiAvatar/UiAvatarImage.vue +1 -1
- package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +86 -0
- package/src/components/UiAvatar/index.ts +1 -0
- package/src/components/UiAvatar/types.ts +15 -1
- package/src/components/UiButton/UiButton.stories.ts +60 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +7 -2
- package/src/components/UiField/UiField.stories.ts +15 -9
- package/src/components/UiFileItem/UiFileItem.stories.ts +344 -185
- package/src/components/UiFileItem/UiFileItem.vue +110 -70
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +64 -3
- package/src/components/UiFileItem/types.ts +33 -10
- package/src/components/UiFileType/UiFileType.stories.ts +193 -0
- package/src/components/UiFileType/UiFileType.vue +114 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +41 -0
- package/src/components/UiFileType/index.ts +2 -0
- package/src/components/UiFileType/types.ts +38 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +58 -56
- package/src/components/UiItem/UiItem.stories.ts +555 -855
- package/src/components/UiItem/UiItem.vue +59 -4
- package/src/components/UiItem/UiItemMedia.vue +1 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +432 -26
- package/src/components/UiItem/constants.ts +16 -2
- package/src/components/UiItem/index.ts +1 -1
- package/src/components/UiItem/types.ts +64 -13
- package/src/components/UiKbd/UiKbd.stories.ts +1 -1
- package/src/components/UiListbox/UiListbox.stories.ts +1 -1
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +4 -4
- package/src/components/UiSelect/UiSelectTrigger.vue +8 -2
- package/src/components/UiSelect/__tests__/UiSelectGroup.test.ts +2 -2
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +1 -0
- package/src/components/UiTable/UiTable.stories.ts +6 -2
- package/src/components/UiTable/__tests__/UiTableRow.test.ts +4 -2
- package/src/components/UiTabs/UiTabs.stories.ts +2 -2
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +12 -2
- package/src/components/core/avatar/Avatar.vue +17 -1
- package/src/components/core/avatar/AvatarFallback.vue +1 -1
- package/src/components/core/{item/ItemActions.vue → avatar/AvatarGroup.vue} +7 -2
- package/src/components/core/avatar/index.ts +1 -0
- package/src/components/core/button/index.ts +1 -1
- package/src/components/core/calendar/Calendar.vue +17 -1
- package/src/components/core/checkbox/Checkbox.vue +1 -0
- package/src/components/core/drawer/DrawerContent.vue +1 -1
- package/src/components/core/item/Item.vue +2 -2
- package/src/components/core/item/ItemAction.vue +30 -0
- package/src/components/core/item/ItemContent.vue +1 -1
- package/src/components/core/item/ItemDescription.vue +1 -1
- package/src/components/core/item/ItemGroup.vue +0 -1
- package/src/components/core/item/index.ts +32 -9
- package/src/components/core/kbd/Kbd.vue +1 -1
- package/src/components/core/listbox/ListboxContent.vue +1 -0
- package/src/components/core/native-select/NativeSelect.vue +6 -0
- package/src/components/core/range-calendar/RangeCalendar.vue +19 -0
- package/src/components/core/skeleton/Skeleton.vue +3 -1
- package/src/components/core/slider/Slider.vue +2 -1
- package/src/components/core/table/TableFooter.vue +4 -1
- package/src/components/core/table/TableRow.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/directives/vHover.stories.ts +16 -12
- package/src/lib/activeIndicator.ts +1 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +2 -2
- package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +2 -2
- package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +2 -2
- package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +2 -2
- package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +2 -2
- package/src/patterns/UiSidebar/__tests__/UiSidebarMenuButton.test.ts +33 -0
- package/src/patterns/UiSidebar/activeIndicator.ts +1 -16
- package/src/theme/Background.stories.ts +16 -0
- package/src/theme/BorderRadius.stories.ts +12 -12
- package/src/theme/Flex.stories.ts +1 -1
- package/src/theme/Theme.stories.ts +3 -3
- package/tokens.json +4273 -1152
- /package/dist/system/components/core/{item/ItemActions.vue.d.ts → avatar/AvatarGroup.vue.d.ts} +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
Item,
|
|
5
|
+
ItemAction,
|
|
6
|
+
ItemContent,
|
|
7
|
+
ItemDescription,
|
|
8
|
+
ItemMedia,
|
|
9
|
+
ItemTitle,
|
|
10
|
+
} from '@/components/core/item';
|
|
11
|
+
import { UiButton } from '@/components/UiButton';
|
|
12
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
13
|
+
import type { UiItemEmits, UiItemProps } from './types';
|
|
4
14
|
|
|
5
15
|
defineOptions({
|
|
6
16
|
name: 'UiItem',
|
|
@@ -10,8 +20,23 @@ const props = withDefaults(defineProps<UiItemProps>(), {
|
|
|
10
20
|
variant: 'default',
|
|
11
21
|
size: 'default',
|
|
12
22
|
asChild: false,
|
|
13
|
-
withListSemantics:
|
|
23
|
+
withListSemantics: false,
|
|
14
24
|
});
|
|
25
|
+
const emit = defineEmits<UiItemEmits>();
|
|
26
|
+
|
|
27
|
+
const itemDescription = computed(() => props.description ?? props.desc);
|
|
28
|
+
const defaultActionSize = computed(() =>
|
|
29
|
+
props.size === 'minimal' ? 'icon-xs' : 'icon-sm',
|
|
30
|
+
);
|
|
31
|
+
const defaultActionClass = computed(() =>
|
|
32
|
+
props.variant === 'hover-action'
|
|
33
|
+
? undefined
|
|
34
|
+
: 'hover:bg-transparent active:bg-transparent',
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
function onDefaultActionClick(event: MouseEvent) {
|
|
38
|
+
emit('action', event);
|
|
39
|
+
}
|
|
15
40
|
</script>
|
|
16
41
|
|
|
17
42
|
<template>
|
|
@@ -21,6 +46,36 @@ const props = withDefaults(defineProps<UiItemProps>(), {
|
|
|
21
46
|
:as-child="props.asChild"
|
|
22
47
|
:with-list-semantics="props.withListSemantics"
|
|
23
48
|
>
|
|
24
|
-
<slot
|
|
49
|
+
<slot>
|
|
50
|
+
<ItemMedia v-if="$slots.icon" variant="icon">
|
|
51
|
+
<slot name="icon" />
|
|
52
|
+
</ItemMedia>
|
|
53
|
+
|
|
54
|
+
<ItemContent v-if="props.title || itemDescription || $slots.content">
|
|
55
|
+
<ItemTitle v-if="props.title">
|
|
56
|
+
{{ props.title }}
|
|
57
|
+
</ItemTitle>
|
|
58
|
+
<ItemDescription v-if="props.size !== 'minimal' && itemDescription">
|
|
59
|
+
{{ itemDescription }}
|
|
60
|
+
</ItemDescription>
|
|
61
|
+
<slot name="content" />
|
|
62
|
+
</ItemContent>
|
|
63
|
+
|
|
64
|
+
<ItemAction
|
|
65
|
+
v-if="$slots.action || props.title || itemDescription || $slots.content"
|
|
66
|
+
>
|
|
67
|
+
<slot name="action">
|
|
68
|
+
<UiButton
|
|
69
|
+
variant="ghost"
|
|
70
|
+
:size="defaultActionSize"
|
|
71
|
+
aria-label="More actions"
|
|
72
|
+
:class="defaultActionClass"
|
|
73
|
+
@click="onDefaultActionClick"
|
|
74
|
+
>
|
|
75
|
+
<UiIcon name="more-vertical" />
|
|
76
|
+
</UiButton>
|
|
77
|
+
</slot>
|
|
78
|
+
</ItemAction>
|
|
79
|
+
</slot>
|
|
25
80
|
</Item>
|
|
26
81
|
</template>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { render } from '@testing-library/vue';
|
|
2
|
-
import { describe, expect, test } from 'vitest';
|
|
1
|
+
import { fireEvent, render } from '@testing-library/vue';
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
3
3
|
import {
|
|
4
4
|
UiItem,
|
|
5
5
|
UiItemGroup,
|
|
@@ -8,10 +8,11 @@ import {
|
|
|
8
8
|
UiItemContent,
|
|
9
9
|
UiItemTitle,
|
|
10
10
|
UiItemDescription,
|
|
11
|
-
|
|
11
|
+
UiItemAction,
|
|
12
12
|
UiItemHeader,
|
|
13
13
|
UiItemFooter,
|
|
14
14
|
} from '../index';
|
|
15
|
+
import { ItemActionVariants, ItemMediaVariants } from '../constants';
|
|
15
16
|
|
|
16
17
|
describe('UiItem', () => {
|
|
17
18
|
describe('Rendering', () => {
|
|
@@ -24,6 +25,21 @@ describe('UiItem', () => {
|
|
|
24
25
|
|
|
25
26
|
const element = container.querySelector('[data-slot="item"]');
|
|
26
27
|
expect(element?.tagName).toBe('DIV');
|
|
28
|
+
expect(element).not.toHaveAttribute('role');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('applies listitem role only when list semantics are requested', () => {
|
|
32
|
+
const { container } = render(UiItem, {
|
|
33
|
+
props: {
|
|
34
|
+
withListSemantics: true,
|
|
35
|
+
},
|
|
36
|
+
slots: {
|
|
37
|
+
default: 'Item content',
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
42
|
+
expect(element).toHaveAttribute('role', 'listitem');
|
|
27
43
|
});
|
|
28
44
|
|
|
29
45
|
test('renders slot content', () => {
|
|
@@ -45,6 +61,23 @@ describe('UiItem', () => {
|
|
|
45
61
|
|
|
46
62
|
const element = container.querySelector('[data-slot="item"]');
|
|
47
63
|
expect(element).toHaveClass('bg-transparent');
|
|
64
|
+
expect(element).not.toHaveClass('border');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('applies active variant classes', () => {
|
|
68
|
+
const { container } = render(UiItem, {
|
|
69
|
+
props: {
|
|
70
|
+
variant: 'active',
|
|
71
|
+
},
|
|
72
|
+
slots: {
|
|
73
|
+
default: 'Content',
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
78
|
+
expect(element).toHaveClass('ui-active-indicator');
|
|
79
|
+
expect(element).toHaveClass('ui-active-indicator-active');
|
|
80
|
+
expect(element).toHaveClass('bg-background-surface-muted-subtle');
|
|
48
81
|
});
|
|
49
82
|
|
|
50
83
|
test('applies outline variant classes', () => {
|
|
@@ -58,13 +91,31 @@ describe('UiItem', () => {
|
|
|
58
91
|
});
|
|
59
92
|
|
|
60
93
|
const element = container.querySelector('[data-slot="item"]');
|
|
61
|
-
expect(element).toHaveClass('
|
|
94
|
+
expect(element).toHaveClass('ring-1');
|
|
95
|
+
expect(element).toHaveClass('ring-inset');
|
|
96
|
+
expect(element).toHaveClass('ring-border-surface-default');
|
|
97
|
+
expect(element).not.toHaveClass('border');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('applies hover variant classes', () => {
|
|
101
|
+
const { container } = render(UiItem, {
|
|
102
|
+
props: {
|
|
103
|
+
variant: 'hover',
|
|
104
|
+
},
|
|
105
|
+
slots: {
|
|
106
|
+
default: 'Content',
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
111
|
+
expect(element).toHaveClass('cursor-pointer');
|
|
112
|
+
expect(element).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
62
113
|
});
|
|
63
114
|
|
|
64
|
-
test('applies
|
|
115
|
+
test('applies hover-action variant classes', () => {
|
|
65
116
|
const { container } = render(UiItem, {
|
|
66
117
|
props: {
|
|
67
|
-
variant: '
|
|
118
|
+
variant: 'hover-action',
|
|
68
119
|
},
|
|
69
120
|
slots: {
|
|
70
121
|
default: 'Content',
|
|
@@ -72,7 +123,32 @@ describe('UiItem', () => {
|
|
|
72
123
|
});
|
|
73
124
|
|
|
74
125
|
const element = container.querySelector('[data-slot="item"]');
|
|
75
|
-
expect(element).toHaveClass('
|
|
126
|
+
expect(element).toHaveClass('cursor-pointer');
|
|
127
|
+
expect(element).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
128
|
+
expect(element).toHaveClass('has-[button:hover]:hover:bg-transparent');
|
|
129
|
+
expect(element).toHaveClass(
|
|
130
|
+
'has-[[data-slot=item-action]:hover]:hover:bg-transparent',
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('does not apply action hover suppression outside hover-action variant', () => {
|
|
135
|
+
const { container, getByRole } = render(UiItem, {
|
|
136
|
+
props: {
|
|
137
|
+
title: 'Item title',
|
|
138
|
+
variant: 'hover',
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
143
|
+
expect(element).not.toHaveClass(
|
|
144
|
+
'has-[button:hover]:hover:bg-transparent',
|
|
145
|
+
);
|
|
146
|
+
expect(element).not.toHaveClass(
|
|
147
|
+
'has-[[data-slot=item-action]:hover]:hover:bg-transparent',
|
|
148
|
+
);
|
|
149
|
+
expect(getByRole('button', { name: 'More actions' })).toHaveClass(
|
|
150
|
+
'hover:bg-transparent',
|
|
151
|
+
);
|
|
76
152
|
});
|
|
77
153
|
|
|
78
154
|
test('applies size classes', () => {
|
|
@@ -86,8 +162,178 @@ describe('UiItem', () => {
|
|
|
86
162
|
});
|
|
87
163
|
|
|
88
164
|
const element = container.querySelector('[data-slot="item"]');
|
|
89
|
-
expect(element).toHaveClass('
|
|
90
|
-
|
|
165
|
+
expect(element).toHaveClass('p-2');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('renders convenience title and description props', () => {
|
|
169
|
+
const { getByRole, getByText, container } = render(UiItem, {
|
|
170
|
+
props: {
|
|
171
|
+
title: 'Item title',
|
|
172
|
+
description: 'Item description',
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
expect(getByText('Item title')).toBeInTheDocument();
|
|
177
|
+
expect(getByText('Item description')).toBeInTheDocument();
|
|
178
|
+
expect(
|
|
179
|
+
container.querySelector('[data-slot="item-content"]'),
|
|
180
|
+
).toBeInTheDocument();
|
|
181
|
+
expect(
|
|
182
|
+
container.querySelector('[data-slot="item-title"]'),
|
|
183
|
+
).toBeInTheDocument();
|
|
184
|
+
expect(
|
|
185
|
+
container.querySelector('[data-slot="item-description"]'),
|
|
186
|
+
).toBeInTheDocument();
|
|
187
|
+
expect(getByRole('button', { name: 'More actions' })).toBeInTheDocument();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('renders desc prop as description alias', () => {
|
|
191
|
+
const { getByText } = render(UiItem, {
|
|
192
|
+
props: {
|
|
193
|
+
title: 'Item title',
|
|
194
|
+
desc: 'Short description',
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(getByText('Short description')).toBeInTheDocument();
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('renders content slot inside convenience content area', () => {
|
|
202
|
+
const { getByText, container } = render(UiItem, {
|
|
203
|
+
props: {
|
|
204
|
+
title: 'Item title',
|
|
205
|
+
},
|
|
206
|
+
slots: {
|
|
207
|
+
content: '<span>Additional content</span>',
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(getByText('Additional content')).toBeInTheDocument();
|
|
212
|
+
expect(
|
|
213
|
+
container.querySelector('[data-slot="item-content"]'),
|
|
214
|
+
).toBeInTheDocument();
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('uses default slot as the structured content fallback wrapper', () => {
|
|
218
|
+
const { getByText, queryByText } = render(UiItem, {
|
|
219
|
+
props: {
|
|
220
|
+
title: 'Generated title',
|
|
221
|
+
},
|
|
222
|
+
slots: {
|
|
223
|
+
default: 'Custom content',
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
expect(getByText('Custom content')).toBeInTheDocument();
|
|
228
|
+
expect(queryByText('Generated title')).not.toBeInTheDocument();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test('renders icon and action slots with convenience content', () => {
|
|
232
|
+
const { getByTestId, container } = render(UiItem, {
|
|
233
|
+
props: {
|
|
234
|
+
title: 'Item title',
|
|
235
|
+
},
|
|
236
|
+
slots: {
|
|
237
|
+
icon: '<span data-testid="item-icon">Icon</span>',
|
|
238
|
+
action: '<button data-testid="item-action">Action</button>',
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
expect(getByTestId('item-icon')).toBeInTheDocument();
|
|
243
|
+
expect(getByTestId('item-action')).toBeInTheDocument();
|
|
244
|
+
expect(
|
|
245
|
+
container.querySelector('[data-slot="item-media"]'),
|
|
246
|
+
).toBeInTheDocument();
|
|
247
|
+
expect(
|
|
248
|
+
container.querySelector('[data-slot="item-action"]'),
|
|
249
|
+
).toBeInTheDocument();
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test('renders default ghost action with icon-sm for default and small sizes', () => {
|
|
253
|
+
const defaultItem = render(UiItem, {
|
|
254
|
+
props: {
|
|
255
|
+
title: 'Default item',
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
const defaultAction = defaultItem.getByRole('button', {
|
|
260
|
+
name: 'More actions',
|
|
261
|
+
});
|
|
262
|
+
expect(defaultAction).toHaveClass('text-foreground');
|
|
263
|
+
expect(defaultAction).toHaveClass('hover:bg-transparent');
|
|
264
|
+
expect(defaultAction.className).toContain('[&_svg]:size-4');
|
|
265
|
+
|
|
266
|
+
const smallItem = render(UiItem, {
|
|
267
|
+
props: {
|
|
268
|
+
title: 'Small item',
|
|
269
|
+
size: 'sm',
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
const smallAction = smallItem.container.querySelector(
|
|
274
|
+
'[aria-label="More actions"]',
|
|
275
|
+
);
|
|
276
|
+
expect(smallAction?.className).toContain('[&_svg]:size-4');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test('keeps action hover only for hover-action variant', () => {
|
|
280
|
+
const { container, getByRole } = render(UiItem, {
|
|
281
|
+
props: {
|
|
282
|
+
title: 'Item title',
|
|
283
|
+
variant: 'hover-action',
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
288
|
+
const action = getByRole('button', { name: 'More actions' });
|
|
289
|
+
|
|
290
|
+
expect(element).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
291
|
+
expect(element).toHaveClass('has-[button:hover]:hover:bg-transparent');
|
|
292
|
+
expect(action).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
293
|
+
expect(action).not.toHaveClass('hover:bg-transparent');
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('renders default ghost action with icon-xs for minimal size', () => {
|
|
297
|
+
const { getByRole } = render(UiItem, {
|
|
298
|
+
props: {
|
|
299
|
+
title: 'Minimal item',
|
|
300
|
+
size: 'minimal',
|
|
301
|
+
},
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const defaultAction = getByRole('button', { name: 'More actions' });
|
|
305
|
+
expect(defaultAction.className).toContain('[&_svg]:size-3');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('emits action when the default action is clicked', async () => {
|
|
309
|
+
const onAction = vi.fn();
|
|
310
|
+
const { getByRole } = render(UiItem, {
|
|
311
|
+
props: {
|
|
312
|
+
title: 'Item title',
|
|
313
|
+
onAction,
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await fireEvent.click(getByRole('button', { name: 'More actions' }));
|
|
318
|
+
|
|
319
|
+
expect(onAction).toHaveBeenCalledTimes(1);
|
|
320
|
+
expect(onAction.mock.calls[0]?.[0]).toBeInstanceOf(MouseEvent);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test('does not infer hover background when action slot is present', () => {
|
|
324
|
+
const { container } = render(UiItem, {
|
|
325
|
+
props: {
|
|
326
|
+
title: 'Item title',
|
|
327
|
+
},
|
|
328
|
+
slots: {
|
|
329
|
+
action: '<button>Action</button>',
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
334
|
+
expect(element).not.toHaveClass(
|
|
335
|
+
'hover:bg-background-surface-muted-subtle',
|
|
336
|
+
);
|
|
91
337
|
});
|
|
92
338
|
});
|
|
93
339
|
|
|
@@ -143,10 +389,9 @@ describe('UiItem', () => {
|
|
|
143
389
|
expect(element).toHaveClass('items-center');
|
|
144
390
|
expect(element).toHaveClass('rounded-md');
|
|
145
391
|
// Check variant classes are applied
|
|
146
|
-
expect(element).toHaveClass('border-
|
|
392
|
+
expect(element).toHaveClass('ring-border-surface-default');
|
|
147
393
|
// Check size classes are applied
|
|
148
|
-
expect(element).toHaveClass('
|
|
149
|
-
expect(element).toHaveClass('px-4');
|
|
394
|
+
expect(element).toHaveClass('p-2');
|
|
150
395
|
});
|
|
151
396
|
|
|
152
397
|
test('applies default variant classes to child element when asChild is true', () => {
|
|
@@ -162,7 +407,23 @@ describe('UiItem', () => {
|
|
|
162
407
|
const element = container.querySelector('[data-slot="item"]');
|
|
163
408
|
expect(element?.tagName).toBe('BUTTON');
|
|
164
409
|
expect(element).toHaveClass('bg-transparent');
|
|
165
|
-
expect(element).toHaveClass('p-
|
|
410
|
+
expect(element).toHaveClass('p-3');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
test('does not infer hover background when rendered as child', () => {
|
|
414
|
+
const { container } = render(UiItem, {
|
|
415
|
+
props: {
|
|
416
|
+
asChild: true,
|
|
417
|
+
},
|
|
418
|
+
slots: {
|
|
419
|
+
default: '<a href="/test">Link Item</a>',
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const element = container.querySelector('[data-slot="item"]');
|
|
424
|
+
expect(element).not.toHaveClass(
|
|
425
|
+
'hover:bg-background-surface-muted-subtle',
|
|
426
|
+
);
|
|
166
427
|
});
|
|
167
428
|
});
|
|
168
429
|
});
|
|
@@ -177,6 +438,7 @@ describe('UiItemGroup', () => {
|
|
|
177
438
|
|
|
178
439
|
const element = container.querySelector('[data-slot="item-group"]');
|
|
179
440
|
expect(element).toBeInTheDocument();
|
|
441
|
+
expect(element).not.toHaveAttribute('role');
|
|
180
442
|
});
|
|
181
443
|
|
|
182
444
|
test('renders children', () => {
|
|
@@ -238,7 +500,68 @@ describe('UiItemMedia', () => {
|
|
|
238
500
|
|
|
239
501
|
const element = container.querySelector('[data-slot="item-media"]');
|
|
240
502
|
expect(element).toHaveClass('size-10');
|
|
241
|
-
expect(element).toHaveClass('rounded-
|
|
503
|
+
expect(element).toHaveClass('rounded-full');
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
test('image variant can render avatar content', () => {
|
|
507
|
+
const { container } = render(UiItemMedia, {
|
|
508
|
+
props: {
|
|
509
|
+
variant: 'image',
|
|
510
|
+
},
|
|
511
|
+
slots: {
|
|
512
|
+
default: '<div data-slot="avatar">Avatar</div>',
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
expect(
|
|
517
|
+
container.querySelector('[data-slot="item-media"] [data-slot="avatar"]'),
|
|
518
|
+
).toBeInTheDocument();
|
|
519
|
+
expect(container.querySelector('[data-slot="item-media"]')).toHaveClass(
|
|
520
|
+
'size-10',
|
|
521
|
+
);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
test('renders with avatar group variant', () => {
|
|
525
|
+
const { container } = render(UiItemMedia, {
|
|
526
|
+
props: {
|
|
527
|
+
variant: 'avatar-group',
|
|
528
|
+
},
|
|
529
|
+
slots: {
|
|
530
|
+
default: 'Avatar group content',
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const element = container.querySelector('[data-slot="item-media"]');
|
|
535
|
+
expect(element).toHaveClass('rounded-none');
|
|
536
|
+
expect(element).toHaveClass('overflow-visible');
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
test('avatar group variant can render avatar group content', () => {
|
|
540
|
+
const { container } = render(UiItemMedia, {
|
|
541
|
+
props: {
|
|
542
|
+
variant: 'avatar-group',
|
|
543
|
+
},
|
|
544
|
+
slots: {
|
|
545
|
+
default: '<div data-slot="avatar-group">Avatar group</div>',
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
expect(
|
|
550
|
+
container.querySelector(
|
|
551
|
+
'[data-slot="item-media"] [data-slot="avatar-group"]',
|
|
552
|
+
),
|
|
553
|
+
).toBeInTheDocument();
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
test('media variants only include media-oriented variants', () => {
|
|
557
|
+
expect(ItemMediaVariants).toEqual([
|
|
558
|
+
'default',
|
|
559
|
+
'icon',
|
|
560
|
+
'image',
|
|
561
|
+
'avatar-group',
|
|
562
|
+
]);
|
|
563
|
+
expect(ItemMediaVariants).not.toContain('text');
|
|
564
|
+
expect(ItemMediaVariants).not.toContain('button');
|
|
242
565
|
});
|
|
243
566
|
});
|
|
244
567
|
|
|
@@ -331,33 +654,116 @@ describe('UiItemDescription', () => {
|
|
|
331
654
|
});
|
|
332
655
|
|
|
333
656
|
const element = container.querySelector('[data-slot="item-description"]');
|
|
334
|
-
expect(element).toHaveClass('text-muted
|
|
657
|
+
expect(element).toHaveClass('text-content-on-surface-muted');
|
|
335
658
|
});
|
|
336
659
|
});
|
|
337
660
|
|
|
338
|
-
describe('
|
|
661
|
+
describe('UiItemAction', () => {
|
|
339
662
|
test('renders with data-slot attribute', () => {
|
|
340
|
-
const { container } = render(
|
|
663
|
+
const { container } = render(UiItemAction, {
|
|
341
664
|
slots: {
|
|
342
|
-
default: '
|
|
665
|
+
default: 'Action content',
|
|
343
666
|
},
|
|
344
667
|
});
|
|
345
668
|
|
|
346
|
-
const element = container.querySelector('[data-slot="item-
|
|
669
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
347
670
|
expect(element).toBeInTheDocument();
|
|
348
671
|
});
|
|
349
672
|
|
|
350
673
|
test('has flex layout with gap', () => {
|
|
351
|
-
const { container } = render(
|
|
674
|
+
const { container } = render(UiItemAction, {
|
|
352
675
|
slots: {
|
|
353
|
-
default: '
|
|
676
|
+
default: 'Action',
|
|
354
677
|
},
|
|
355
678
|
});
|
|
356
679
|
|
|
357
|
-
const element = container.querySelector('[data-slot="item-
|
|
680
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
358
681
|
expect(element).toHaveClass('flex');
|
|
359
682
|
expect(element).toHaveClass('gap-2');
|
|
360
683
|
});
|
|
684
|
+
|
|
685
|
+
test('renders with tooltip wrapper when tooltip is provided', () => {
|
|
686
|
+
const { container } = render(UiItemAction, {
|
|
687
|
+
props: {
|
|
688
|
+
tooltip: 'Open actions',
|
|
689
|
+
},
|
|
690
|
+
slots: {
|
|
691
|
+
default: '<button type="button">Open</button>',
|
|
692
|
+
},
|
|
693
|
+
});
|
|
694
|
+
|
|
695
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
696
|
+
expect(element).toBeInTheDocument();
|
|
697
|
+
expect(element).toHaveTextContent('Open');
|
|
698
|
+
});
|
|
699
|
+
|
|
700
|
+
test('renders with text variant', () => {
|
|
701
|
+
const { container } = render(UiItemAction, {
|
|
702
|
+
props: {
|
|
703
|
+
variant: 'text',
|
|
704
|
+
},
|
|
705
|
+
slots: {
|
|
706
|
+
default: 'Updated today',
|
|
707
|
+
},
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
711
|
+
expect(element).toHaveClass('label-12-regular');
|
|
712
|
+
expect(element).toHaveClass('text-content-on-surface-muted');
|
|
713
|
+
expect(element).toHaveClass('gap-2');
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
test('renders with button variant', () => {
|
|
717
|
+
const { container } = render(UiItemAction, {
|
|
718
|
+
props: {
|
|
719
|
+
variant: 'button',
|
|
720
|
+
},
|
|
721
|
+
slots: {
|
|
722
|
+
default: 'Button action',
|
|
723
|
+
},
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
727
|
+
expect(element).toHaveClass('size-6');
|
|
728
|
+
expect(element).toHaveClass('rounded-sm');
|
|
729
|
+
expect(element).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
test('suppresses wrapper hover layer when button variant contains a button', () => {
|
|
733
|
+
const { container } = render(UiItemAction, {
|
|
734
|
+
props: {
|
|
735
|
+
variant: 'button',
|
|
736
|
+
},
|
|
737
|
+
slots: {
|
|
738
|
+
default: '<button type="button">Open</button>',
|
|
739
|
+
},
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
743
|
+
expect(element).toHaveClass('hover:bg-background-surface-muted-subtle');
|
|
744
|
+
expect(element).toHaveClass('has-[button]:hover:bg-transparent');
|
|
745
|
+
expect(element?.querySelector('button')).toBeInTheDocument();
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
test('applies variant classes inside tooltip wrapper', () => {
|
|
749
|
+
const { container } = render(UiItemAction, {
|
|
750
|
+
props: {
|
|
751
|
+
variant: 'button',
|
|
752
|
+
tooltip: 'Create item',
|
|
753
|
+
},
|
|
754
|
+
slots: {
|
|
755
|
+
default: '<button type="button">Create</button>',
|
|
756
|
+
},
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
const element = container.querySelector('[data-slot="item-action"]');
|
|
760
|
+
expect(element).toHaveClass('size-6');
|
|
761
|
+
expect(element).toHaveTextContent('Create');
|
|
762
|
+
});
|
|
763
|
+
|
|
764
|
+
test('action variants include text and button variants', () => {
|
|
765
|
+
expect(ItemActionVariants).toEqual(['default', 'text', 'button']);
|
|
766
|
+
});
|
|
361
767
|
});
|
|
362
768
|
|
|
363
769
|
describe('UiItemHeader', () => {
|
|
@@ -415,7 +821,7 @@ describe('Composed Item', () => {
|
|
|
415
821
|
UiItemContent,
|
|
416
822
|
UiItemTitle,
|
|
417
823
|
UiItemDescription,
|
|
418
|
-
|
|
824
|
+
UiItemAction,
|
|
419
825
|
},
|
|
420
826
|
template: `
|
|
421
827
|
<UiItem variant="outline">
|
|
@@ -426,9 +832,9 @@ describe('Composed Item', () => {
|
|
|
426
832
|
<UiItemTitle>Test Title</UiItemTitle>
|
|
427
833
|
<UiItemDescription>Test Description</UiItemDescription>
|
|
428
834
|
</UiItemContent>
|
|
429
|
-
<
|
|
835
|
+
<UiItemAction>
|
|
430
836
|
<button>Action</button>
|
|
431
|
-
</
|
|
837
|
+
</UiItemAction>
|
|
432
838
|
</UiItem>
|
|
433
839
|
`,
|
|
434
840
|
});
|
|
@@ -450,7 +856,7 @@ describe('Composed Item', () => {
|
|
|
450
856
|
container.querySelector('[data-slot="item-description"]'),
|
|
451
857
|
).toBeInTheDocument();
|
|
452
858
|
expect(
|
|
453
|
-
container.querySelector('[data-slot="item-
|
|
859
|
+
container.querySelector('[data-slot="item-action"]'),
|
|
454
860
|
).toBeInTheDocument();
|
|
455
861
|
});
|
|
456
862
|
});
|