@aleph-alpha/ui-library 2.5.2 → 2.6.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 (28) hide show
  1. package/dist/system/components/UiFileItem/index.d.ts +1 -1
  2. package/dist/system/components/UiFileType/UiFileType.vue.d.ts +1 -0
  3. package/dist/system/components/UiFileType/types.d.ts +5 -0
  4. package/dist/system/lib.js +2430 -2441
  5. package/dist/system/patterns/UiDataTable/UiDataTableToolbar.vue.d.ts +23 -12
  6. package/dist/system/patterns/UiDataTable/constants.d.ts +0 -13
  7. package/dist/system/patterns/UiDataTable/index.d.ts +1 -0
  8. package/dist/system/patterns/UiDataTable/types.d.ts +1 -28
  9. package/package.json +5 -5
  10. package/src/components/UiCodeBlock/UiCodeBlock.vue +17 -3
  11. package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +21 -0
  12. package/src/components/UiFileItem/UiFileItem.stories.ts +16 -13
  13. package/src/components/UiFileItem/UiFileItem.vue +1 -0
  14. package/src/components/UiFileItem/index.ts +5 -1
  15. package/src/components/UiFileType/UiFileType.vue +2 -5
  16. package/src/components/UiFileType/__tests__/UiFileType.test.ts +9 -0
  17. package/src/components/UiFileType/types.ts +5 -0
  18. package/src/components/UiItem/UiItem.stories.ts +7 -10
  19. package/src/components/UiSelect/UiSelect.stories.ts +20 -20
  20. package/src/patterns/UiDataTable/UiDataTable.stories.ts +186 -118
  21. package/src/patterns/UiDataTable/UiDataTablePagination.vue +1 -1
  22. package/src/patterns/UiDataTable/UiDataTableToolbar.vue +17 -58
  23. package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +1 -1
  24. package/src/patterns/UiDataTable/__tests__/UiDataTableColumnFilter.test.ts +1 -1
  25. package/src/patterns/UiDataTable/__tests__/UiDataTableToolbar.test.ts +26 -201
  26. package/src/patterns/UiDataTable/constants.ts +0 -15
  27. package/src/patterns/UiDataTable/index.ts +1 -0
  28. package/src/patterns/UiDataTable/types.ts +0 -29
@@ -1,68 +1,27 @@
1
- <script setup lang="ts" generic="TData">
2
- import { UiInput } from '@/components/UiInput';
3
- import { computed } from 'vue';
4
- import { DATA_TABLE_LABELS } from './constants';
5
- import type { UiDataTableToolbarProps } from './types';
6
-
1
+ <script setup lang="ts">
7
2
  defineOptions({
8
3
  name: 'UiDataTableToolbar',
9
4
  });
10
5
 
11
- const props = withDefaults(defineProps<UiDataTableToolbarProps<TData>>(), {
12
- filterPlaceholder: DATA_TABLE_LABELS.filterPlaceholder,
13
- globalFilter: false,
14
- filterColumn: undefined,
15
- labels: undefined,
16
- });
17
-
18
- const labels = computed(() => ({
19
- searchAllColumns:
20
- props.labels?.searchAllColumns ?? DATA_TABLE_LABELS.searchAllColumns,
21
- filterByColumn:
22
- props.labels?.filterByColumn ?? DATA_TABLE_LABELS.filterByColumn,
23
- }));
24
-
25
- const showFilter = computed(() => props.globalFilter || props.filterColumn);
26
-
27
- const filterValue = computed({
28
- get: () => {
29
- if (props.globalFilter) {
30
- return (props.table.getState().globalFilter as string) ?? '';
31
- }
32
- if (props.filterColumn) {
33
- return (
34
- (props.table
35
- .getColumn(props.filterColumn)
36
- ?.getFilterValue() as string) ?? ''
37
- );
38
- }
39
- return '';
40
- },
41
- set: (value) => {
42
- if (props.globalFilter) {
43
- props.table.setGlobalFilter(value);
44
- } else if (props.filterColumn) {
45
- props.table.getColumn(props.filterColumn)?.setFilterValue(value);
46
- }
47
- },
48
- });
6
+ defineSlots<{
7
+ /** Primary controls, usually search and column filters. */
8
+ default(): unknown;
9
+ /** Trailing controls, usually view options or reset actions. */
10
+ actions(): unknown;
11
+ }>();
49
12
  </script>
50
13
 
51
14
  <template>
52
- <div class="flex items-center justify-between">
53
- <div class="flex flex-1 items-center gap-x-2">
54
- <UiInput
55
- v-if="showFilter"
56
- v-model="filterValue"
57
- name="filter"
58
- :placeholder="filterPlaceholder"
59
- :aria-label="
60
- globalFilter
61
- ? labels.searchAllColumns
62
- : labels.filterByColumn(filterColumn ?? '')
63
- "
64
- class="h-8 w-[150px] lg:w-[250px]"
65
- />
15
+ <div
16
+ class="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between"
17
+ >
18
+ <div
19
+ class="flex min-w-0 flex-1 flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center"
20
+ >
21
+ <slot />
22
+ </div>
23
+ <div v-if="$slots.actions" class="flex shrink-0 items-center gap-2">
24
+ <slot name="actions" />
66
25
  </div>
67
26
  </div>
68
27
  </template>
@@ -2,7 +2,7 @@ import { fireEvent, render, within } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import { describe, expect, test, vi } from 'vitest';
4
4
  import { h, ref, nextTick } from 'vue';
5
- import type { ColumnDef } from '@tanstack/vue-table';
5
+ import type { ColumnDef } from '@aleph-alpha/ui-library';
6
6
  import UiDataTable from '../UiDataTable.vue';
7
7
  import UiDataTableColumnFilter from '../UiDataTableColumnFilter.vue';
8
8
  import UiDataTableColumnHeader from '../UiDataTableColumnHeader.vue';
@@ -1,6 +1,6 @@
1
1
  import { render, screen } from '@testing-library/vue';
2
2
  import userEvent from '@testing-library/user-event';
3
- import type { Table } from '@tanstack/vue-table';
3
+ import type { Table } from '@aleph-alpha/ui-library';
4
4
  import { describe, expect, test, vi } from 'vitest';
5
5
  import UiDataTableColumnFilter from '../UiDataTableColumnFilter.vue';
6
6
 
@@ -1,228 +1,53 @@
1
1
  import { render } from '@testing-library/vue';
2
- import userEvent from '@testing-library/user-event';
3
- import { describe, expect, test, vi } from 'vitest';
2
+ import { describe, expect, test } from 'vitest';
4
3
  import UiDataTableToolbar from '../UiDataTableToolbar.vue';
5
4
 
6
- // Mock table object that mimics TanStack Table's Table interface
7
- /**
8
- *
9
- * @param options
10
- * @param options.globalFilter
11
- * @param options.columnFilter
12
- */
13
- function createMockTable(
14
- options: { globalFilter?: string; columnFilter?: string } = {},
15
- ) {
16
- const { globalFilter = '', columnFilter = '' } = options;
17
- const setFilterValue = vi.fn();
18
-
19
- return {
20
- getState: vi.fn(() => ({
21
- globalFilter,
22
- })),
23
- setGlobalFilter: vi.fn(),
24
- getColumn: vi.fn(() => ({
25
- getFilterValue: vi.fn(() => columnFilter),
26
- setFilterValue,
27
- })),
28
- _setFilterValue: setFilterValue,
29
- };
30
- }
31
-
32
5
  describe('UiDataTableToolbar', () => {
33
6
  describe('Rendering', () => {
34
- test('renders filter input when filtering is enabled', () => {
35
- const table = createMockTable();
36
-
37
- // Test with filterColumn
38
- const { getByRole: getByColumn, unmount: unmountColumn } = render(
39
- UiDataTableToolbar,
40
- {
41
- props: { table, filterColumn: 'name' },
42
- },
43
- );
44
- expect(getByColumn('textbox')).toBeInTheDocument();
45
- unmountColumn();
46
-
47
- // Test with globalFilter
48
- const { getByRole: getByGlobal } = render(UiDataTableToolbar, {
49
- props: { table, globalFilter: true },
50
- });
51
- expect(getByGlobal('textbox')).toBeInTheDocument();
52
- });
53
-
54
- test('does not render filter input when neither filterColumn nor globalFilter is set', () => {
55
- const table = createMockTable();
56
- const { queryByRole } = render(UiDataTableToolbar, {
57
- props: { table },
58
- });
59
-
60
- expect(queryByRole('textbox')).not.toBeInTheDocument();
61
- });
62
-
63
- test('applies custom placeholder to input', () => {
64
- const table = createMockTable();
65
- const { getByPlaceholderText } = render(UiDataTableToolbar, {
66
- props: {
67
- table,
68
- globalFilter: true,
69
- filterPlaceholder: 'Type to search...',
70
- },
71
- });
72
-
73
- expect(getByPlaceholderText('Type to search...')).toBeInTheDocument();
74
- });
75
-
76
- test('uses default placeholder when not provided', () => {
77
- const table = createMockTable();
78
- const { getByPlaceholderText } = render(UiDataTableToolbar, {
79
- props: { table, globalFilter: true },
80
- });
81
-
82
- expect(getByPlaceholderText('Search...')).toBeInTheDocument();
83
- });
84
- });
85
-
86
- describe('Column Filtering', () => {
87
- test('displays current column filter value in input', () => {
88
- const table = createMockTable({ columnFilter: 'John' });
89
- const { getByRole } = render(UiDataTableToolbar, {
90
- props: { table, filterColumn: 'name' },
91
- });
92
-
93
- expect(getByRole('textbox')).toHaveValue('John');
94
- });
95
-
96
- test('updates column filter when input value changes', async () => {
97
- const user = userEvent.setup();
98
- const table = createMockTable();
99
- const { getByRole } = render(UiDataTableToolbar, {
100
- props: { table, filterColumn: 'name' },
101
- });
102
-
103
- await user.type(getByRole('textbox'), 'test');
104
-
105
- expect(table._setFilterValue).toHaveBeenCalled();
106
- });
107
-
108
- test('clears column filter when input is emptied', async () => {
109
- const user = userEvent.setup();
110
- const table = createMockTable({ columnFilter: 'John' });
111
- const { getByRole } = render(UiDataTableToolbar, {
112
- props: { table, filterColumn: 'name' },
113
- });
114
-
115
- await user.clear(getByRole('textbox'));
116
-
117
- expect(table._setFilterValue).toHaveBeenCalledWith('');
118
- });
119
- });
120
-
121
- describe('Global Filtering', () => {
122
- test('displays current global filter value in input', () => {
123
- const table = createMockTable({ globalFilter: 'search term' });
124
- const { getByRole } = render(UiDataTableToolbar, {
125
- props: { table, globalFilter: true },
126
- });
127
-
128
- expect(getByRole('textbox')).toHaveValue('search term');
129
- });
130
-
131
- test('updates global filter when input value changes', async () => {
132
- const user = userEvent.setup();
133
- const table = createMockTable();
134
- const { getByRole } = render(UiDataTableToolbar, {
135
- props: { table, globalFilter: true },
136
- });
137
-
138
- await user.type(getByRole('textbox'), 'query');
139
-
140
- expect(table.setGlobalFilter).toHaveBeenCalled();
141
- });
142
-
143
- test('clears global filter when input is emptied', async () => {
144
- const user = userEvent.setup();
145
- const table = createMockTable({ globalFilter: 'existing' });
7
+ test('renders default slot controls', () => {
146
8
  const { getByRole } = render(UiDataTableToolbar, {
147
- props: { table, globalFilter: true },
148
- });
149
-
150
- await user.clear(getByRole('textbox'));
151
-
152
- expect(table.setGlobalFilter).toHaveBeenCalledWith('');
153
- });
154
-
155
- test('global filter takes precedence over column filter', () => {
156
- const table = createMockTable({
157
- globalFilter: 'global',
158
- columnFilter: 'column',
159
- });
160
- const { getByRole } = render(UiDataTableToolbar, {
161
- props: { table, globalFilter: true, filterColumn: 'name' },
162
- });
163
-
164
- // Global filter value should be displayed, not column filter
165
- expect(getByRole('textbox')).toHaveValue('global');
166
- });
167
- });
168
-
169
- describe('Accessibility', () => {
170
- test('input has aria-label for global search', () => {
171
- const table = createMockTable();
172
- const { getByRole } = render(UiDataTableToolbar, {
173
- props: { table, globalFilter: true },
9
+ slots: {
10
+ default:
11
+ '<input aria-label="Search payments" placeholder="Search..." />',
12
+ },
174
13
  });
175
14
 
176
- expect(getByRole('textbox')).toHaveAttribute(
177
- 'aria-label',
178
- 'Search all columns',
179
- );
15
+ expect(
16
+ getByRole('textbox', { name: 'Search payments' }),
17
+ ).toBeInTheDocument();
180
18
  });
181
19
 
182
- test('input has aria-label for column filter including column name', () => {
183
- const table = createMockTable();
20
+ test('renders trailing actions slot', () => {
184
21
  const { getByRole } = render(UiDataTableToolbar, {
185
- props: { table, filterColumn: 'email' },
22
+ slots: {
23
+ default: '<input aria-label="Search payments" />',
24
+ actions: '<button type="button">Columns</button>',
25
+ },
186
26
  });
187
27
 
188
- expect(getByRole('textbox')).toHaveAttribute(
189
- 'aria-label',
190
- 'Filter by email',
191
- );
28
+ expect(getByRole('button', { name: 'Columns' })).toBeInTheDocument();
192
29
  });
193
- });
194
30
 
195
- describe('i18n Support', () => {
196
- test('uses custom searchAllColumns label for global filter', () => {
197
- const table = createMockTable();
198
- const { getByRole } = render(UiDataTableToolbar, {
199
- props: {
200
- table,
201
- globalFilter: true,
202
- labels: { searchAllColumns: 'Alle Spalten durchsuchen' },
31
+ test('does not render actions container without actions slot', () => {
32
+ const { container } = render(UiDataTableToolbar, {
33
+ slots: {
34
+ default: '<input aria-label="Search payments" />',
203
35
  },
204
36
  });
205
37
 
206
- expect(getByRole('textbox')).toHaveAttribute(
207
- 'aria-label',
208
- 'Alle Spalten durchsuchen',
209
- );
38
+ expect(container.querySelectorAll('.shrink-0')).toHaveLength(0);
210
39
  });
211
40
 
212
- test('uses custom filterByColumn function for column filter', () => {
213
- const table = createMockTable();
41
+ test('renders custom filter controls without props', () => {
214
42
  const { getByRole } = render(UiDataTableToolbar, {
215
- props: {
216
- table,
217
- filterColumn: 'name',
218
- labels: { filterByColumn: (col: string) => `Nach ${col} filtern` },
43
+ slots: {
44
+ default: '<button type="button">Reset filters</button>',
219
45
  },
220
46
  });
221
47
 
222
- expect(getByRole('textbox')).toHaveAttribute(
223
- 'aria-label',
224
- 'Nach name filtern',
225
- );
48
+ expect(
49
+ getByRole('button', { name: 'Reset filters' }),
50
+ ).toBeInTheDocument();
226
51
  });
227
52
  });
228
53
  });
@@ -27,11 +27,6 @@ export const DATA_TABLE_LABELS = {
27
27
  rowsSelected: (selected: number, total: number) =>
28
28
  `${selected} of ${total} row(s) selected.`,
29
29
 
30
- /** UiDataTableToolbar */
31
- filterPlaceholder: 'Search...',
32
- searchAllColumns: 'Search all columns',
33
- filterByColumn: (column: string) => `Filter by ${column}`,
34
-
35
30
  /** UiDataTableColumnFilter */
36
31
  columns: 'Columns',
37
32
  toggleColumns: 'Toggle columns',
@@ -72,16 +67,6 @@ export interface PaginationLabels {
72
67
  rowsSelected?: (selected: number, total: number) => string;
73
68
  }
74
69
 
75
- /** Labels for UiDataTableToolbar */
76
- export interface ToolbarLabels {
77
- /** Placeholder text for filter input */
78
- filterPlaceholder?: string;
79
- /** Aria label for global search input */
80
- searchAllColumns?: string;
81
- /** Function to generate aria label for column filter */
82
- filterByColumn?: (column: string) => string;
83
- }
84
-
85
70
  /** Labels for UiDataTableColumnFilter */
86
71
  export interface ColumnFilterLabels {
87
72
  /** Visible label for the trigger button. */
@@ -3,6 +3,7 @@ export { default as UiDataTableColumnFilter } from './UiDataTableColumnFilter.vu
3
3
  export { default as UiDataTableColumnHeader } from './UiDataTableColumnHeader.vue';
4
4
  export { default as UiDataTablePagination } from './UiDataTablePagination.vue';
5
5
  export { default as UiDataTableToolbar } from './UiDataTableToolbar.vue';
6
+ export type { Column, ColumnDef, Row, Table } from '@tanstack/vue-table';
6
7
  export * from './types';
7
8
  export * from './constants';
8
9
  export * from '../../lib/useDrag';
@@ -3,7 +3,6 @@ import type {
3
3
  ColumnHeaderLabels,
4
4
  ColumnFilterLabels,
5
5
  PaginationLabels,
6
- ToolbarLabels,
7
6
  } from './constants';
8
7
 
9
8
  /**
@@ -113,34 +112,6 @@ export type UiDataTablePaginationProps<TData> = {
113
112
  labels?: PaginationLabels;
114
113
  };
115
114
 
116
- /**
117
- * Props for the UiDataTableToolbar component.
118
- */
119
- export type UiDataTableToolbarProps<TData> = {
120
- /**
121
- * The TanStack Table instance.
122
- * @internal
123
- */
124
- table: Table<TData>;
125
- /** Filter a specific column by its accessor key. */
126
- filterColumn?: string;
127
- /**
128
- * Enable global search across all columns (takes precedence over filterColumn).
129
- * @default false
130
- */
131
- globalFilter?: boolean;
132
- /**
133
- * Placeholder text for the filter input.
134
- * @default "Search..."
135
- */
136
- filterPlaceholder?: string;
137
- /**
138
- * Custom labels for i18n support.
139
- * Partial object that merges with defaults.
140
- */
141
- labels?: ToolbarLabels;
142
- };
143
-
144
115
  /**
145
116
  * Props for the UiDataTableColumnFilter component.
146
117
  */