@aleph-alpha/ui-library 6.4.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aleph-alpha/ui-library",
3
- "version": "6.4.0",
3
+ "version": "6.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "dist/system/lib.js",
@@ -89,8 +89,8 @@
89
89
  "wait-on": "9.0.3",
90
90
  "@aleph-alpha/eslint-config-frontend": "0.7.1",
91
91
  "@aleph-alpha/storybook-addon-filters": "0.0.1",
92
- "@aleph-alpha/storybook-addon-sidebar": "0.0.1",
93
92
  "@aleph-alpha/prettier-config-frontend": "2.1.1",
93
+ "@aleph-alpha/storybook-addon-sidebar": "0.0.1",
94
94
  "@aleph-alpha/storybook-addon-theming": "0.0.1",
95
95
  "@aleph-alpha/tsconfig-frontend": "0.7.3"
96
96
  },
@@ -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 payload is empty tuple */
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 vertical gap
83
- // shrinks for compact rows (small size or error/multi states).
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,5 +1,6 @@
1
1
  export { default as UiFileItem } from './UiFileItem.vue';
2
2
  export type {
3
+ UiFileItemGroupItem,
3
4
  UiFileItemMediaTone,
4
5
  UiFileItemProps,
5
6
  UiFileItemSize,
@@ -1,13 +1,15 @@
1
1
  /**
2
- * Row showing a selected or uploading file with optional progress and errors.
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, UiItem, UiButton, UiProgress
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 only in the success state. */
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
  */
@@ -10,6 +10,7 @@ const props = withDefaults(defineProps<UiPopoverContentProps>(), {
10
10
  side: 'bottom',
11
11
  sideOffset: 4,
12
12
  align: 'center',
13
+ compact: false,
13
14
  });
14
15
 
15
16
  const emit = defineEmits<UiPopoverContentEmits>();
@@ -20,6 +21,7 @@ const emit = defineEmits<UiPopoverContentEmits>();
20
21
  :side="props.side"
21
22
  :side-offset="props.sideOffset"
22
23
  :align="props.align"
24
+ :compact="props.compact"
23
25
  @escape-key-down="emit('escapeKeyDown', $event)"
24
26
  >
25
27
  <slot />
@@ -46,4 +46,52 @@ describe('UiPopoverContent', () => {
46
46
 
47
47
  expect(onEscapeKeyDown).toHaveBeenCalled();
48
48
  });
49
+
50
+ /**
51
+ * Renders an open popover and returns its panel.
52
+ * @param content The `UiPopoverContent` markup to render.
53
+ */
54
+ async function renderOpen(content: string) {
55
+ const { findByRole } = render({
56
+ components: { UiPopover, UiPopoverTrigger, UiPopoverContent },
57
+ template: `
58
+ <UiPopover :open="true">
59
+ <UiPopoverTrigger>Open</UiPopoverTrigger>
60
+ ${content}
61
+ </UiPopover>
62
+ `,
63
+ });
64
+ return findByRole('dialog');
65
+ }
66
+
67
+ test('uses the default padding and radius without compact', async () => {
68
+ const panel = await renderOpen(
69
+ '<UiPopoverContent>Content</UiPopoverContent>',
70
+ );
71
+ expect(panel).toHaveClass('p-4', 'rounded-md');
72
+ expect(panel).not.toHaveClass('p-2');
73
+ });
74
+
75
+ test('compact applies the dense padding and radius', async () => {
76
+ const panel = await renderOpen(
77
+ '<UiPopoverContent compact>Content</UiPopoverContent>',
78
+ );
79
+ expect(panel).toHaveClass('p-2', 'rounded-[14px]');
80
+ expect(panel).not.toHaveClass('p-4', 'rounded-md');
81
+ });
82
+
83
+ test('compact is not forwarded to the DOM as an attribute', async () => {
84
+ const panel = await renderOpen(
85
+ '<UiPopoverContent compact>Content</UiPopoverContent>',
86
+ );
87
+ expect(panel).not.toHaveAttribute('compact');
88
+ });
89
+
90
+ test('compact keeps the side and alignment props', async () => {
91
+ const panel = await renderOpen(
92
+ '<UiPopoverContent compact side="top" align="end">Content</UiPopoverContent>',
93
+ );
94
+ expect(panel).toHaveAttribute('data-side', 'top');
95
+ expect(panel).toHaveAttribute('data-align', 'end');
96
+ });
49
97
  });
@@ -84,6 +84,13 @@ export interface UiPopoverContentProps {
84
84
  * @default 'center'
85
85
  */
86
86
  align?: UiPopoverAlign;
87
+
88
+ /**
89
+ * Tighter padding (`p-2`) and a larger radius, for dense content such as
90
+ * lists or menus inside the panel.
91
+ * @default false
92
+ */
93
+ compact?: boolean;
87
94
  }
88
95
 
89
96
  /**
@@ -10,7 +10,12 @@ defineOptions({
10
10
  });
11
11
 
12
12
  const props = withDefaults(
13
- defineProps<PopoverContentProps & { class?: HTMLAttributes['class'] }>(),
13
+ defineProps<
14
+ PopoverContentProps & {
15
+ class?: HTMLAttributes['class'];
16
+ compact?: boolean;
17
+ }
18
+ >(),
14
19
  {
15
20
  sideOffset: 4,
16
21
  align: 'center',
@@ -18,7 +23,7 @@ const props = withDefaults(
18
23
  );
19
24
  const emits = defineEmits<PopoverContentEmits>();
20
25
 
21
- const delegatedProps = reactiveOmit(props, 'class');
26
+ const delegatedProps = reactiveOmit(props, 'class', 'compact');
22
27
 
23
28
  const forwarded = useForwardPropsEmits(delegatedProps, emits);
24
29
  </script>
@@ -30,7 +35,8 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
30
35
  v-bind="{ ...$attrs, ...forwarded }"
31
36
  :class="
32
37
  cn(
33
- 'bg-background-surface-floating text-content-on-surface-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--reka-popover-content-transform-origin) rounded-md border border-border-surface-default p-4 shadow-md outline-none',
38
+ 'bg-background-surface-floating text-content-on-surface-primary data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--reka-popover-content-transform-origin) border border-border-surface-default shadow-md outline-none',
39
+ props.compact ? 'p-2 rounded-[14px]' : 'rounded-md p-4',
34
40
  props.class,
35
41
  )
36
42
  "