@aleph-alpha/ui-library 2.4.4 → 2.5.1

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.
Files changed (80) hide show
  1. package/config.js +78 -9
  2. package/dist/system/components/UiAvatar/UiAvatar.vue.d.ts +4 -1
  3. package/dist/system/components/UiAvatar/UiAvatarGroup.vue.d.ts +18 -0
  4. package/dist/system/components/UiAvatar/index.d.ts +1 -0
  5. package/dist/system/components/UiAvatar/types.d.ts +12 -1
  6. package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +6 -1
  7. package/dist/system/components/UiFileItem/types.d.ts +30 -10
  8. package/dist/system/components/UiFileType/UiFileType.vue.d.ts +8 -0
  9. package/dist/system/components/UiFileType/index.d.ts +2 -0
  10. package/dist/system/components/UiFileType/types.d.ts +33 -0
  11. package/dist/system/components/UiItem/UiItem.vue.d.ts +8 -1
  12. package/dist/system/components/UiItem/constants.d.ts +4 -3
  13. package/dist/system/components/UiItem/index.d.ts +1 -1
  14. package/dist/system/components/UiItem/types.d.ts +53 -13
  15. package/dist/system/components/core/avatar/Avatar.vue.d.ts +2 -0
  16. package/dist/system/components/core/avatar/index.d.ts +1 -0
  17. package/dist/system/components/core/item/Item.vue.d.ts +1 -1
  18. package/dist/system/components/core/item/ItemAction.vue.d.ts +25 -0
  19. package/dist/system/components/core/item/index.d.ts +8 -4
  20. package/dist/system/components/index.d.ts +1 -0
  21. package/dist/system/lib/activeIndicator.d.ts +1 -0
  22. package/dist/system/lib.js +6574 -6357
  23. package/dist/system/patterns/UiSidebar/activeIndicator.d.ts +1 -15
  24. package/package.json +1 -1
  25. package/src/components/UiAvatar/UiAvatar.stories.ts +103 -12
  26. package/src/components/UiAvatar/UiAvatar.vue +6 -1
  27. package/src/components/UiAvatar/UiAvatarGroup.vue +16 -0
  28. package/src/components/UiAvatar/UiAvatarImage.vue +1 -1
  29. package/src/components/UiAvatar/__tests__/UiAvatar.test.ts +86 -0
  30. package/src/components/UiAvatar/index.ts +1 -0
  31. package/src/components/UiAvatar/types.ts +15 -1
  32. package/src/components/UiButton/UiButton.stories.ts +60 -0
  33. package/src/components/UiCodeBlock/UiCodeBlock.vue +1 -1
  34. package/src/components/UiFileItem/UiFileItem.stories.ts +344 -185
  35. package/src/components/UiFileItem/UiFileItem.vue +110 -70
  36. package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +64 -3
  37. package/src/components/UiFileItem/types.ts +33 -10
  38. package/src/components/UiFileType/UiFileType.stories.ts +134 -0
  39. package/src/components/UiFileType/UiFileType.vue +116 -0
  40. package/src/components/UiFileType/__tests__/UiFileType.test.ts +41 -0
  41. package/src/components/UiFileType/index.ts +2 -0
  42. package/src/components/UiFileType/types.ts +38 -0
  43. package/src/components/UiItem/UiItem.stories.ts +555 -855
  44. package/src/components/UiItem/UiItem.vue +59 -4
  45. package/src/components/UiItem/UiItemMedia.vue +1 -1
  46. package/src/components/UiItem/__tests__/UiItem.test.ts +432 -26
  47. package/src/components/UiItem/constants.ts +16 -2
  48. package/src/components/UiItem/index.ts +1 -1
  49. package/src/components/UiItem/types.ts +64 -13
  50. package/src/components/UiKbd/UiKbd.stories.ts +1 -1
  51. package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +4 -4
  52. package/src/components/UiSelect/__tests__/UiSelectGroup.test.ts +2 -2
  53. package/src/components/UiTable/__tests__/UiTableRow.test.ts +4 -2
  54. package/src/components/core/avatar/Avatar.vue +17 -1
  55. package/src/components/core/avatar/AvatarFallback.vue +1 -1
  56. package/src/components/core/{item/ItemActions.vue → avatar/AvatarGroup.vue} +7 -2
  57. package/src/components/core/avatar/index.ts +1 -0
  58. package/src/components/core/button/index.ts +1 -1
  59. package/src/components/core/drawer/DrawerContent.vue +1 -1
  60. package/src/components/core/item/Item.vue +2 -2
  61. package/src/components/core/item/ItemAction.vue +30 -0
  62. package/src/components/core/item/ItemContent.vue +1 -1
  63. package/src/components/core/item/ItemDescription.vue +1 -1
  64. package/src/components/core/item/ItemGroup.vue +0 -1
  65. package/src/components/core/item/index.ts +32 -9
  66. package/src/components/core/kbd/Kbd.vue +1 -1
  67. package/src/components/core/skeleton/Skeleton.vue +3 -1
  68. package/src/components/core/slider/Slider.vue +1 -1
  69. package/src/components/core/table/TableFooter.vue +4 -1
  70. package/src/components/core/table/TableRow.vue +1 -1
  71. package/src/components/index.ts +1 -0
  72. package/src/lib/activeIndicator.ts +1 -0
  73. package/src/patterns/UiSidebar/UiSidebarMenuButton.vue +2 -2
  74. package/src/patterns/UiSidebar/UiSidebarMenuSubItem.vue +2 -2
  75. package/src/patterns/UiSidebar/UiSidebarPopoverMenuItem.vue +2 -2
  76. package/src/patterns/UiSidebar/UiSidebarPopoverTrigger.vue +2 -2
  77. package/src/patterns/UiSidebar/__tests__/UiSidebarMenuButton.test.ts +33 -0
  78. package/src/patterns/UiSidebar/activeIndicator.ts +1 -16
  79. package/src/theme/BorderRadius.stories.ts +12 -12
  80. /package/dist/system/components/core/{item/ItemActions.vue.d.ts → avatar/AvatarGroup.vue.d.ts} +0 -0
@@ -1,15 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { UiButton } from '@/components/UiButton';
3
+ import { UiFileType } from '@/components/UiFileType';
3
4
  import { UiIcon } from '@/components/UiIcon';
4
- import {
5
- UiItem,
6
- UiItemActions,
7
- UiItemContent,
8
- UiItemDescription,
9
- UiItemFooter,
10
- UiItemMedia,
11
- UiItemTitle,
12
- } from '@/components/UiItem';
13
5
  import { UiProgress } from '@/components/UiProgress';
14
6
  import { cn } from '@/lib/utils';
15
7
  import { computed } from 'vue';
@@ -26,7 +18,15 @@ const props = withDefaults(defineProps<UiFileItemProps>(), {
26
18
  progress: null,
27
19
  error: null,
28
20
  removeLabel: 'Remove file',
21
+ progressLabel: undefined,
22
+ removable: true,
29
23
  disabled: false,
24
+ size: 'default',
25
+ // `mediaTone` and `mediaIcon` are intentionally undefined by default so
26
+ // `UiFileType`'s extension-based auto-detection can decide both. Pass
27
+ // them explicitly to override.
28
+ mediaTone: undefined,
29
+ mediaIcon: undefined,
30
30
  });
31
31
 
32
32
  /* eslint-disable jsdoc/require-jsdoc -- emit payload is empty tuple */
@@ -49,75 +49,115 @@ const displayFilename = computed(() =>
49
49
  filenameWithoutExtension(props.filename),
50
50
  );
51
51
 
52
- const showProgress = computed(
53
- () => props.progress != null && props.progress >= 0 && props.progress <= 100,
52
+ const isError = computed(() => props.error != null && props.error !== '');
53
+
54
+ const isWithProgress = computed(
55
+ () =>
56
+ !isError.value &&
57
+ props.progress != null &&
58
+ props.progress >= 0 &&
59
+ props.progress < 100,
60
+ );
61
+
62
+ const showMeta = computed(
63
+ () =>
64
+ !isError.value &&
65
+ !isWithProgress.value &&
66
+ (props.typeLabel || props.sizeLabel),
67
+ );
68
+
69
+ const isSmall = computed(() => props.size === 'small');
70
+
71
+ const containerClass = computed(() =>
72
+ cn(
73
+ 'relative flex w-full max-w-full min-w-0 items-center overflow-hidden rounded-xl',
74
+ 'bg-background-surface-muted-subtle',
75
+ isSmall.value ? 'gap-3 p-2' : 'gap-3 p-3',
76
+ props.disabled && 'opacity-50',
77
+ ),
78
+ );
79
+
80
+ // Body column: title plus one of {progress, error, meta}. The vertical gap
81
+ // shrinks for compact rows (small size or error/multi states).
82
+ const contentClass = computed(() =>
83
+ cn(
84
+ 'flex min-w-0 flex-1 flex-col items-start',
85
+ isSmall.value || isError.value ? 'gap-0.5' : 'gap-1.5',
86
+ ),
87
+ );
88
+
89
+ const titleClass = computed(() =>
90
+ cn(
91
+ 'block w-full min-w-0 truncate text-content-on-surface-primary',
92
+ isSmall.value ? 'label-12-medium' : 'body-14-medium',
93
+ ),
94
+ );
95
+
96
+ const progressClass = computed(() =>
97
+ cn('w-full', isSmall.value ? 'h-1' : 'h-1.5'),
54
98
  );
55
99
  </script>
56
100
 
57
101
  <template>
58
- <UiItem
59
- variant="outline"
60
- size="sm"
61
- :with-list-semantics="false"
102
+ <div
103
+ data-slot="file-item"
104
+ :class="containerClass"
62
105
  :inert="disabled ? true : undefined"
63
- :class="
64
- cn(
65
- 'border-border-surface-default bg-background-surface-muted-subtle rounded-lg border shadow-none',
66
- disabled && 'opacity-50',
67
- )
68
- "
69
106
  >
70
- <UiItemMedia variant="icon">
71
- <UiIcon
72
- name="file"
73
- class="text-content-on-surface-primary shrink-0"
74
- :size="16"
75
- aria-hidden="true"
76
- />
77
- </UiItemMedia>
78
- <UiItemContent class="min-w-0 gap-0">
79
- <UiItemTitle
80
- class="body-14-medium text-content-on-surface-primary !line-clamp-none min-w-0 w-full truncate"
81
- :aria-label="filename"
82
- >
107
+ <UiFileType
108
+ :filename="filename"
109
+ :tone="mediaTone"
110
+ :icon="mediaIcon"
111
+ :error="isError"
112
+ />
113
+
114
+ <div data-slot="file-item-content" :class="contentClass">
115
+ <span :class="titleClass" :aria-label="filename">
83
116
  {{ displayFilename }}
84
- </UiItemTitle>
85
- <UiItemDescription
86
- v-if="typeLabel || sizeLabel"
87
- class="label-12-medium text-content-on-surface-muted !line-clamp-none flex flex-wrap items-center"
88
- >
89
- <template v-if="typeLabel && sizeLabel">
90
- <span>{{ typeLabel }}</span>
91
- <span class="text-content-on-surface-muted px-2" aria-hidden="true"
92
- >|</span
93
- >
94
- <span>{{ sizeLabel }}</span>
95
- </template>
96
- <template v-else>
97
- {{ typeLabel ?? sizeLabel }}
98
- </template>
99
- </UiItemDescription>
100
- </UiItemContent>
101
- <UiItemActions>
102
- <UiButton
103
- type="button"
104
- variant="ghost"
105
- class="size-8 shrink-0 p-0"
106
- :disabled="disabled"
107
- :aria-label="removeLabel"
108
- @click="emit('remove')"
117
+ </span>
118
+
119
+ <UiProgress
120
+ v-if="isWithProgress"
121
+ :model-value="progress!"
122
+ :class="progressClass"
123
+ :aria-label="progressLabel ?? filename"
124
+ />
125
+
126
+ <p
127
+ v-else-if="isError"
128
+ class="label-12-medium text-content-on-status-error-inverse w-full truncate"
129
+ role="alert"
109
130
  >
110
- <UiIcon name="x" :size="16" aria-hidden="true" />
111
- </UiButton>
112
- </UiItemActions>
113
- <UiItemFooter
114
- v-if="showProgress || error"
115
- class="flex w-full min-w-0 flex-col items-stretch gap-1"
116
- >
117
- <UiProgress v-if="showProgress" :model-value="progress!" class="w-full" />
118
- <p v-if="error" class="label-12-medium text-destructive" role="alert">
119
131
  {{ error }}
120
132
  </p>
121
- </UiItemFooter>
122
- </UiItem>
133
+
134
+ <div
135
+ v-else-if="showMeta"
136
+ data-slot="file-item-meta"
137
+ class="label-12-medium text-content-on-surface-muted flex w-full min-w-0 items-center gap-2"
138
+ >
139
+ <span v-if="typeLabel" class="truncate">{{ typeLabel }}</span>
140
+ <span
141
+ v-if="typeLabel && sizeLabel"
142
+ aria-hidden="true"
143
+ class="text-content-on-surface-muted shrink-0"
144
+ >|</span
145
+ >
146
+ <span v-if="sizeLabel" class="truncate">{{ sizeLabel }}</span>
147
+ </div>
148
+ </div>
149
+
150
+ <UiButton
151
+ v-if="removable"
152
+ type="button"
153
+ variant="ghost"
154
+ size="icon-sm"
155
+ class="shrink-0"
156
+ :disabled="disabled"
157
+ :aria-label="removeLabel"
158
+ @click="emit('remove')"
159
+ >
160
+ <UiIcon name="x" :size="16" aria-hidden="true" />
161
+ </UiButton>
162
+ </div>
123
163
  </template>
@@ -4,7 +4,7 @@ import { describe, expect, test } from 'vitest';
4
4
  import UiFileItem from '../UiFileItem.vue';
5
5
 
6
6
  describe('UiFileItem', () => {
7
- test('renders basename without extension and meta', () => {
7
+ test('renders the basename (without extension) and the type | size meta', () => {
8
8
  const { container, getByText, getByLabelText } = render(UiFileItem, {
9
9
  props: {
10
10
  filename: 'doc.pdf',
@@ -17,7 +17,8 @@ describe('UiFileItem', () => {
17
17
  expect(getByText('PDF')).toBeInTheDocument();
18
18
  expect(getByText('|')).toBeInTheDocument();
19
19
  expect(getByText('1 MB')).toBeInTheDocument();
20
- expect(container.querySelector('[data-slot="item"]')).toHaveClass(
20
+ // Container uses the muted-subtle surface from the design tokens.
21
+ expect(container.querySelector('[data-slot="file-item"]')).toHaveClass(
21
22
  'bg-background-surface-muted-subtle',
22
23
  );
23
24
  });
@@ -41,7 +42,18 @@ describe('UiFileItem', () => {
41
42
  expect(emitted('remove')).toHaveLength(1);
42
43
  });
43
44
 
44
- test('shows error text below the row like progress', () => {
45
+ test('does not render the remove control when removable is false', () => {
46
+ const { queryByRole } = render(UiFileItem, {
47
+ props: {
48
+ filename: 'x.txt',
49
+ removeLabel: 'Remove file',
50
+ removable: false,
51
+ },
52
+ });
53
+ expect(queryByRole('button', { name: 'Remove file' })).toBeNull();
54
+ });
55
+
56
+ test('shows error text in the destructive band when error is set', () => {
45
57
  const { getByText, getByRole } = render(UiFileItem, {
46
58
  props: {
47
59
  filename: 'bad.exe',
@@ -52,6 +64,47 @@ describe('UiFileItem', () => {
52
64
  expect(getByRole('alert')).toHaveTextContent('Unsupported file type');
53
65
  });
54
66
 
67
+ test('hides type/size meta in the error state even when both are set', () => {
68
+ const { queryByText, getByText } = render(UiFileItem, {
69
+ props: {
70
+ filename: 'bad.exe',
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
+ });
93
+
94
+ test('hides type/size meta while progress is in flight', () => {
95
+ const { queryByText } = render(UiFileItem, {
96
+ props: {
97
+ filename: 'upload.zip',
98
+ typeLabel: 'ZIP',
99
+ sizeLabel: '12 MB',
100
+ progress: 35,
101
+ },
102
+ });
103
+ // Meta is replaced by the progress bar; only the title and bar remain.
104
+ expect(queryByText('ZIP')).toBeNull();
105
+ expect(queryByText('12 MB')).toBeNull();
106
+ });
107
+
55
108
  test('does not emit remove when disabled', async () => {
56
109
  const user = userEvent.setup();
57
110
  const { getByRole, emitted } = render(UiFileItem, {
@@ -66,4 +119,12 @@ describe('UiFileItem', () => {
66
119
  await user.click(btn);
67
120
  expect(emitted('remove')).toBeFalsy();
68
121
  });
122
+
123
+ test('renders a UiFileType badge whose tone matches the filename extension', () => {
124
+ const { container } = render(UiFileItem, {
125
+ props: { filename: 'data.csv' },
126
+ });
127
+ const badge = container.querySelector('[data-slot="file-type"]');
128
+ expect(badge?.getAttribute('data-tone')).toBe('accent-yellow');
129
+ });
69
130
  });
@@ -2,26 +2,49 @@
2
2
  * Row showing a selected or uploading file with optional progress and errors.
3
3
  * @category Form Inputs
4
4
  * @useCases file upload list, attachment row
5
- * @keywords file, upload, attachment, progress
6
- * @related UiFileUploadBox, UiItem, UiButton
5
+ * @keywords file, upload, attachment, progress, success, error
6
+ * @related UiFileUploadBox, UiItem, UiButton, UiProgress
7
7
  */
8
+ export type UiFileItemSize = 'default' | 'small';
9
+
10
+ import type { UiFileTypeTone } from '@/components/UiFileType';
11
+
12
+ /**
13
+ * Media badge tone. Re-exported alias of `UiFileTypeTone` (the file-type
14
+ * badge is rendered via {@link UiFileType}). Auto-derived from the filename
15
+ * extension when omitted; see `UiFileType` for the mapping.
16
+ */
17
+ export type UiFileItemMediaTone = UiFileTypeTone;
18
+
8
19
  export interface UiFileItemProps {
9
- /**
10
- * Full file name (`file.name`). The title omits the final extension; the full name is still exposed to assistive tech.
11
- */
20
+ /** Full file name. The trailing extension is hidden from the title. */
12
21
  filename: string;
13
- /** Short type label, e.g. `PDF`. */
22
+ /** Short type label, e.g. `PDF`. Shown only in the success state. */
14
23
  typeLabel?: string;
15
- /** Size label, e.g. `1.2 MB`. */
24
+ /** Size label, e.g. `1.2 MB`. Shown only in the success state. */
16
25
  sizeLabel?: string;
17
- /** Upload progress 0–100; omit or `null` to hide the bar. */
26
+ /** Upload progress 0–100. Values `< 100` show a progress bar. */
18
27
  progress?: number | null;
19
- /** Validation or upload error message. */
28
+ /** Error message. When non-empty, the row enters the error state. */
20
29
  error?: string | null;
21
30
  /** Accessible label for the remove control. */
22
31
  removeLabel?: string;
32
+ /** Accessible label for the progress bar (i18n hook). Defaults to the `filename`. */
33
+ progressLabel?: string;
23
34
  /**
24
- * When true, the row is non-interactive (`inert`), visually de-emphasized, and remove is disabled.
35
+ * When `true`, renders a close icon that emits `remove`.
36
+ * @default true
25
37
  */
38
+ removable?: boolean;
39
+ /** When `true`, the row is `inert` and visually de-emphasized. */
26
40
  disabled?: boolean;
41
+ /**
42
+ * Visual size preset.
43
+ * @default 'default'
44
+ */
45
+ size?: UiFileItemSize;
46
+ /** Media badge tone. Auto-derived from the extension when omitted. */
47
+ mediaTone?: UiFileItemMediaTone;
48
+ /** Lucide icon name for the media badge. Auto-derived when omitted. */
49
+ mediaIcon?: string;
27
50
  }
@@ -0,0 +1,134 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3-vite';
2
+ import UiFileType from './UiFileType.vue';
3
+
4
+ /**
5
+ * `UiFileType` renders the round 32×32 file-type badge from the AA26
6
+ * design system. It auto-derives its color tone and Lucide icon from the
7
+ * filename extension (or accepts explicit `tone` / `icon` props), and
8
+ * forces a neutral `circle-alert` state when `error` is true. Used inside
9
+ * `UiFileItem`, but also available standalone for any file/attachment UI.
10
+ */
11
+ const meta: Meta<typeof UiFileType> = {
12
+ title: 'Components/UiFileType',
13
+ component: UiFileType,
14
+ tags: ['autodocs'],
15
+ args: {
16
+ filename: 'document.pdf',
17
+ tone: undefined,
18
+ icon: undefined,
19
+ error: false,
20
+ },
21
+ argTypes: {
22
+ tone: {
23
+ control: 'select',
24
+ options: [
25
+ undefined,
26
+ 'default',
27
+ 'accent-pink',
28
+ 'accent-soft',
29
+ 'accent-yellow',
30
+ ],
31
+ 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
+ },
34
+ icon: {
35
+ control: 'text',
36
+ description:
37
+ 'Lucide icon name override. Leave empty to auto-derive from the filename. Ignored in the error state.',
38
+ },
39
+ },
40
+ decorators: [
41
+ () => ({
42
+ template: '<div class="p-4"><story /></div>',
43
+ }),
44
+ ],
45
+ };
46
+
47
+ export default meta;
48
+ type Story = StoryObj<typeof UiFileType>;
49
+
50
+ const renderArgs = (args: Story['args']) => ({
51
+ components: { UiFileType },
52
+ setup() {
53
+ // Storybook's text controls emit `''` when cleared; the component
54
+ // treats that as "unset", so normalize here so the playground matches
55
+ // what consumers would actually pass.
56
+ const normalized = {
57
+ ...args,
58
+ tone: args?.tone || undefined,
59
+ icon: args?.icon || undefined,
60
+ };
61
+ return { args: normalized };
62
+ },
63
+ template: '<UiFileType v-bind="args" />',
64
+ });
65
+
66
+ const defaultTemplateSource = `<script setup lang="ts">
67
+ import { UiFileType } from '@aleph-alpha/ui-library'
68
+ </script>
69
+
70
+ <template>
71
+ <UiFileType filename="document.pdf" />
72
+ </template>`;
73
+
74
+ /** Interactive playground; toggle the controls to switch type and state. */
75
+ export const Default: Story = {
76
+ render: renderArgs,
77
+ parameters: {
78
+ docs: { source: { code: defaultTemplateSource } },
79
+ },
80
+ };
81
+
82
+ const errorTemplateSource = `<script setup lang="ts">
83
+ import { UiFileType } from '@aleph-alpha/ui-library'
84
+ </script>
85
+
86
+ <template>
87
+ <UiFileType filename="data.csv" :error="true" />
88
+ </template>`;
89
+
90
+ /** Error state — neutral badge + `circle-alert`, regardless of file type. */
91
+ export const ErrorState: Story = {
92
+ args: { filename: 'data.csv', error: true },
93
+ render: renderArgs,
94
+ parameters: {
95
+ docs: { source: { code: errorTemplateSource } },
96
+ },
97
+ };
98
+
99
+ const allTypesTemplateSource = `<script setup lang="ts">
100
+ import { UiFileType } from '@aleph-alpha/ui-library'
101
+ </script>
102
+
103
+ <template>
104
+ <div class="flex items-center gap-3">
105
+ <UiFileType filename="report.pdf" />
106
+ <UiFileType filename="README.md" />
107
+ <UiFileType filename="data.csv" />
108
+ <UiFileType filename="archive.zip" />
109
+ <UiFileType filename="data.csv" :error="true" />
110
+ </div>
111
+ </template>`;
112
+
113
+ /**
114
+ * All Figma `Filetype` variants in one row plus the `default` fallback and
115
+ * the error state for quick visual comparison.
116
+ */
117
+ export const AllTypes: Story = {
118
+ parameters: {
119
+ controls: { disable: true },
120
+ docs: { source: { code: allTypesTemplateSource } },
121
+ },
122
+ render: () => ({
123
+ components: { UiFileType },
124
+ template: `
125
+ <div class="flex items-center gap-3">
126
+ <UiFileType filename="report.pdf" />
127
+ <UiFileType filename="README.md" />
128
+ <UiFileType filename="data.csv" />
129
+ <UiFileType filename="archive.zip" />
130
+ <UiFileType filename="data.csv" :error="true" />
131
+ </div>
132
+ `,
133
+ }),
134
+ };
@@ -0,0 +1,116 @@
1
+ <script setup lang="ts">
2
+ import { UiIcon } from '@/components/UiIcon';
3
+ import { cn } from '@/lib/utils';
4
+ import { computed } from 'vue';
5
+ import type { UiFileTypeProps, UiFileTypeTone } from './types';
6
+
7
+ defineOptions({
8
+ name: 'UiFileType',
9
+ });
10
+
11
+ /** @see {@link UiFileTypeProps} */
12
+ const props = withDefaults(defineProps<UiFileTypeProps>(), {
13
+ filename: undefined,
14
+ tone: undefined,
15
+ icon: undefined,
16
+ error: false,
17
+ });
18
+
19
+ /** Visual preset (tone + icon) for a known file extension. */
20
+ interface FileTypePreset {
21
+ /** Background tone of the round badge. */
22
+ tone: UiFileTypeTone;
23
+ /** Lucide icon name rendered inside the badge. */
24
+ icon: string;
25
+ }
26
+
27
+ /**
28
+ * File-extension → (tone, icon) presets sourced from the Figma `Filetype`
29
+ * component. Keys are normalized to lower-case, dotless extensions; any
30
+ * extension not listed here falls through to the `default` preset.
31
+ * @see {@link https://www.figma.com/design/SrZQ19QVN1sQkuAMnMC746/AA26--WIP-?node-id=26438-42144}
32
+ */
33
+ const FILE_TYPE_PRESETS: Record<string, FileTypePreset> = {
34
+ // Type=Text → accent-pink + file icon.
35
+ pdf: { tone: 'accent-pink', icon: 'file' },
36
+ doc: { tone: 'accent-pink', icon: 'file' },
37
+ docx: { tone: 'accent-pink', icon: 'file' },
38
+ txt: { tone: 'accent-pink', icon: 'file' },
39
+ rtf: { tone: 'accent-pink', icon: 'file' },
40
+ // Type=Markdown → accent-soft + code-xml icon.
41
+ html: { tone: 'accent-soft', icon: 'code-xml' },
42
+ htm: { tone: 'accent-soft', icon: 'code-xml' },
43
+ md: { tone: 'accent-soft', icon: 'code-xml' },
44
+ mdx: { tone: 'accent-soft', icon: 'code-xml' },
45
+ // Type=Tabular → accent-yellow + table-2 icon.
46
+ csv: { tone: 'accent-yellow', icon: 'table-2' },
47
+ tsv: { tone: 'accent-yellow', icon: 'table-2' },
48
+ xls: { tone: 'accent-yellow', icon: 'table-2' },
49
+ xlsx: { tone: 'accent-yellow', icon: 'table-2' },
50
+ };
51
+
52
+ const DEFAULT_PRESET: FileTypePreset = { tone: 'default', icon: 'file' };
53
+
54
+ /**
55
+ * Lower-case, dotless extension. Returns `''` for files without an
56
+ * extension or for dotfiles like `.gitignore`.
57
+ * @param name - Full file name
58
+ */
59
+ function getFileExtension(name: string): string {
60
+ const i = name.lastIndexOf('.');
61
+ if (i <= 0 || i === name.length - 1) return '';
62
+ return name.slice(i + 1).toLowerCase();
63
+ }
64
+
65
+ const filePreset = computed<FileTypePreset>(() => {
66
+ if (!props.filename) return DEFAULT_PRESET;
67
+ const ext = getFileExtension(props.filename);
68
+ return FILE_TYPE_PRESETS[ext] ?? DEFAULT_PRESET;
69
+ });
70
+
71
+ // Resolved tone/icon: `error` short-circuits to the neutral preset; an
72
+ // explicit prop wins over the filename-derived preset. Truthy checks (`||`)
73
+ // rather than nullish (`??`) so empty strings from text-based controls
74
+ // (Storybook, form inputs) fall back to the auto-derived value.
75
+ const resolvedTone = computed<UiFileTypeTone>(() => {
76
+ if (props.error) return 'default';
77
+ return props.tone || filePreset.value.tone;
78
+ });
79
+
80
+ const resolvedIcon = computed<string>(() => {
81
+ if (props.error) return 'circle-alert';
82
+ return props.icon || filePreset.value.icon;
83
+ });
84
+
85
+ // `accent-pink` and `accent-yellow` are backed by static token vars defined
86
+ // in `config.js` (see `getStaticTokenVars`) until they're synced from Figma
87
+ // into `tokens.json`.
88
+ const TONE_FILL: Record<UiFileTypeTone, string> = {
89
+ default: 'bg-background-surface-muted-subtle',
90
+ 'accent-pink': 'bg-background-accent-pink',
91
+ 'accent-soft': 'bg-background-accent-soft',
92
+ 'accent-yellow': 'bg-background-accent-yellow',
93
+ };
94
+
95
+ const badgeClass = computed(() =>
96
+ cn(
97
+ 'flex size-8 shrink-0 items-center justify-center rounded-full text-content-on-surface-primary',
98
+ TONE_FILL[resolvedTone.value],
99
+ ),
100
+ );
101
+ </script>
102
+
103
+ <template>
104
+ <div
105
+ data-slot="file-type"
106
+ :data-tone="resolvedTone"
107
+ :class="badgeClass"
108
+ aria-hidden="true"
109
+ >
110
+ <UiIcon
111
+ :name="resolvedIcon"
112
+ :size="16"
113
+ :class="error ? 'text-content-on-status-error-inverse' : undefined"
114
+ />
115
+ </div>
116
+ </template>
@@ -0,0 +1,41 @@
1
+ import { render } from '@testing-library/vue';
2
+ import { describe, expect, test } from 'vitest';
3
+ import UiFileType from '../UiFileType.vue';
4
+
5
+ describe('UiFileType', () => {
6
+ describe('file-extension auto-detection', () => {
7
+ // Assert via the stable `data-tone` attribute on the badge rather than
8
+ // the underlying utility class, so refactors to the styling don't
9
+ // silently change which tone the component picks for a given file type.
10
+ test.each([
11
+ { filename: 'report.pdf', tone: 'accent-pink', icon: 'lucide-file' },
12
+ { filename: 'README.md', tone: 'accent-soft', icon: 'lucide-code-xml' },
13
+ { filename: 'data.csv', tone: 'accent-yellow', icon: 'lucide-table-2' },
14
+ { filename: 'archive.zip', tone: 'default', icon: 'lucide-file' },
15
+ { filename: undefined, tone: 'default', icon: 'lucide-file' },
16
+ ])('$filename → $tone + $icon', ({ filename, tone, icon }) => {
17
+ const { container } = render(UiFileType, { props: { filename } });
18
+ const badge = container.querySelector('[data-slot="file-type"]');
19
+ expect(badge?.getAttribute('data-tone')).toBe(tone);
20
+ expect(badge?.querySelector(`svg.${icon}`)).not.toBeNull();
21
+ });
22
+ });
23
+
24
+ test('error forces the neutral badge + circle-alert icon regardless of file type', () => {
25
+ const { container } = render(UiFileType, {
26
+ props: { filename: 'data.csv', error: true },
27
+ });
28
+ const badge = container.querySelector('[data-slot="file-type"]');
29
+ expect(badge?.getAttribute('data-tone')).toBe('default');
30
+ expect(badge?.querySelector('svg.lucide-circle-alert')).not.toBeNull();
31
+ });
32
+
33
+ test('explicit tone and icon props override the auto-derived values', () => {
34
+ const { container } = render(UiFileType, {
35
+ props: { filename: 'archive.zip', tone: 'accent-pink', icon: 'star' },
36
+ });
37
+ const badge = container.querySelector('[data-slot="file-type"]');
38
+ expect(badge?.getAttribute('data-tone')).toBe('accent-pink');
39
+ expect(badge?.querySelector('svg.lucide-star')).not.toBeNull();
40
+ });
41
+ });
@@ -0,0 +1,2 @@
1
+ export { default as UiFileType } from './UiFileType.vue';
2
+ export type { UiFileTypeProps, UiFileTypeTone } from './types';