@aleph-alpha/ui-library 7.0.2 → 7.2.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.
Files changed (64) hide show
  1. package/dist/system/components/UiPagination/UiPagination.vue.d.ts +19 -0
  2. package/dist/system/components/UiPagination/constants.d.ts +6 -0
  3. package/dist/system/components/UiPagination/index.d.ts +3 -0
  4. package/dist/system/components/UiPagination/types.d.ts +81 -0
  5. package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
  6. package/dist/system/components/UiSlider/types.d.ts +28 -0
  7. package/dist/system/components/core/pagination/Pagination.vue.d.ts +29 -0
  8. package/dist/system/components/core/pagination/PaginationContent.vue.d.ts +29 -0
  9. package/dist/system/components/core/pagination/PaginationEllipsis.vue.d.ts +22 -0
  10. package/dist/system/components/core/pagination/PaginationFirst.vue.d.ts +22 -0
  11. package/dist/system/components/core/pagination/PaginationItem.vue.d.ts +26 -0
  12. package/dist/system/components/core/pagination/PaginationLast.vue.d.ts +22 -0
  13. package/dist/system/components/core/pagination/PaginationNext.vue.d.ts +22 -0
  14. package/dist/system/components/core/pagination/PaginationPrevious.vue.d.ts +22 -0
  15. package/dist/system/components/core/pagination/index.d.ts +8 -0
  16. package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
  17. package/dist/system/components/index.d.ts +1 -0
  18. package/dist/system/icons/story-sidebar-icons.json +4 -0
  19. package/dist/system/lib.js +11762 -10952
  20. package/dist/system/patterns/UiBulkAction/UiBulkAction.vue.d.ts +43 -0
  21. package/dist/system/patterns/UiBulkAction/index.d.ts +3 -0
  22. package/dist/system/patterns/UiBulkAction/types.d.ts +109 -0
  23. package/dist/system/patterns/UiBulkAction/useBulkAction.d.ts +7 -0
  24. package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
  25. package/dist/system/patterns/index.d.ts +1 -0
  26. package/dist/system/story-sidebar-icons.json +4 -0
  27. package/package.json +8 -8
  28. package/src/components/UiPagination/UiPagination.guidance.md +60 -0
  29. package/src/components/UiPagination/UiPagination.stories.ts +1070 -0
  30. package/src/components/UiPagination/UiPagination.vue +109 -0
  31. package/src/components/UiPagination/__tests__/UiPagination.test.ts +203 -0
  32. package/src/components/UiPagination/constants.ts +17 -0
  33. package/src/components/UiPagination/index.ts +3 -0
  34. package/src/components/UiPagination/types.ts +82 -0
  35. package/src/components/UiSlider/UiSlider.stories.ts +710 -2
  36. package/src/components/UiSlider/UiSlider.vue +109 -1
  37. package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
  38. package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
  39. package/src/components/UiSlider/step-marks.ts +96 -0
  40. package/src/components/UiSlider/types.ts +32 -0
  41. package/src/components/core/pagination/Pagination.vue +26 -0
  42. package/src/components/core/pagination/PaginationContent.vue +24 -0
  43. package/src/components/core/pagination/PaginationEllipsis.vue +30 -0
  44. package/src/components/core/pagination/PaginationFirst.vue +30 -0
  45. package/src/components/core/pagination/PaginationItem.vue +39 -0
  46. package/src/components/core/pagination/PaginationLast.vue +30 -0
  47. package/src/components/core/pagination/PaginationNext.vue +35 -0
  48. package/src/components/core/pagination/PaginationPrevious.vue +35 -0
  49. package/src/components/core/pagination/index.ts +8 -0
  50. package/src/components/core/slider/Slider.vue +16 -6
  51. package/src/components/index.ts +1 -0
  52. package/src/patterns/UiBulkAction/UiBulkAction.guidance.md +59 -0
  53. package/src/patterns/UiBulkAction/UiBulkAction.stories.ts +2238 -0
  54. package/src/patterns/UiBulkAction/UiBulkAction.vue +62 -0
  55. package/src/patterns/UiBulkAction/__tests__/useBulkAction.test.ts +78 -0
  56. package/src/patterns/UiBulkAction/index.ts +3 -0
  57. package/src/patterns/UiBulkAction/types.ts +126 -0
  58. package/src/patterns/UiBulkAction/useBulkAction.ts +50 -0
  59. package/src/patterns/UiDataTable/UiDataTable.stories.ts +375 -1
  60. package/src/patterns/UiDataTable/UiDataTablePagination.vue +43 -60
  61. package/src/patterns/UiDataTable/__tests__/UiDataTablePagination.test.ts +58 -29
  62. package/src/patterns/UiDataTable/constants.ts +10 -0
  63. package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +12 -12
  64. package/src/patterns/index.ts +1 -0
@@ -0,0 +1,62 @@
1
+ <script setup lang="ts">
2
+ import { useId } from 'vue';
3
+ import { UiCheckbox } from '@/components/UiCheckbox';
4
+ import { RefreshCwIcon } from '@/icons/lucide';
5
+ import { UiFloatActionItems } from '../UiFloatActions';
6
+ import type { UiBulkActionCheckedState, UiBulkActionProps } from './types';
7
+
8
+ defineOptions({
9
+ name: 'UiBulkAction',
10
+ });
11
+
12
+ const props = withDefaults(defineProps<UiBulkActionProps>(), {
13
+ selectedCount: 0,
14
+ ariaLabel: 'Bulk actions',
15
+ selectAllLabel: 'Select all rows on this page',
16
+ resetLabel: 'Reset selection',
17
+ });
18
+
19
+ const emit = defineEmits<{
20
+ /** Emitted when the reset button is activated. */
21
+ reset: [];
22
+ }>();
23
+
24
+ defineSlots<{
25
+ /** Custom actions, rendered between the select-all checkbox and reset. */
26
+ default?(props: {
27
+ /** Number of currently selected items. */
28
+ selectedCount: number;
29
+ }): unknown;
30
+ }>();
31
+
32
+ const checked = defineModel<UiBulkActionCheckedState>('checked', {
33
+ default: false,
34
+ });
35
+
36
+ const checkboxName = `bulk-select-all-${useId()}`;
37
+ </script>
38
+
39
+ <template>
40
+ <UiFloatActionItems :aria-label="props.ariaLabel" class="w-fit">
41
+ <!-- The label widens the 16px checkbox to a 32px touch target (WCAG 2.5.8). -->
42
+ <label
43
+ :for="checkboxName"
44
+ class="inline-flex h-8 w-8 cursor-pointer items-center justify-center"
45
+ >
46
+ <UiCheckbox
47
+ :id="checkboxName"
48
+ v-model="checked"
49
+ :name="checkboxName"
50
+ :aria-label="props.selectAllLabel"
51
+ />
52
+ </label>
53
+ <slot :selected-count="props.selectedCount" />
54
+ <UiFloatActionItems type="separator" />
55
+ <UiFloatActionItems
56
+ type="icon"
57
+ :icon="RefreshCwIcon"
58
+ :aria-label="props.resetLabel"
59
+ @click="emit('reset')"
60
+ />
61
+ </UiFloatActionItems>
62
+ </template>
@@ -0,0 +1,78 @@
1
+ import { describe, expect, test, vi } from 'vitest';
2
+ import { useBulkAction } from '../useBulkAction';
3
+
4
+ describe('useBulkAction', () => {
5
+ test('applies a single action to the selected items', async () => {
6
+ const archive = vi.fn();
7
+ const { apply, selectedItems } = useBulkAction<number>({
8
+ actions: [{ key: 'archive', action: archive }],
9
+ });
10
+
11
+ selectedItems.value = [1, 2];
12
+ await apply('archive');
13
+
14
+ expect(archive).toHaveBeenCalledExactlyOnceWith([1, 2]);
15
+ });
16
+
17
+ test('applies a group of actions in order', async () => {
18
+ const calls: string[] = [];
19
+ const { apply, selectedItems } = useBulkAction<number>({
20
+ actions: [
21
+ {
22
+ key: 'export',
23
+ action: async () => {
24
+ await Promise.resolve();
25
+ calls.push('export');
26
+ },
27
+ },
28
+ {
29
+ key: 'archive',
30
+ action: () => {
31
+ calls.push('archive');
32
+ },
33
+ },
34
+ ],
35
+ });
36
+
37
+ selectedItems.value = [1];
38
+ await apply(['export', 'archive']);
39
+
40
+ expect(calls).toEqual(['export', 'archive']);
41
+ });
42
+
43
+ test('passes every action in a group the selection from when apply was called', async () => {
44
+ const archive = vi.fn();
45
+ const { apply, selectedItems, clearSelection } = useBulkAction<number>({
46
+ actions: [
47
+ { key: 'delete', action: () => clearSelection() },
48
+ { key: 'archive', action: archive },
49
+ ],
50
+ });
51
+
52
+ selectedItems.value = [1, 2];
53
+ await apply(['delete', 'archive']);
54
+
55
+ expect(archive).toHaveBeenCalledWith([1, 2]);
56
+ });
57
+
58
+ test('rejects when an action key is not registered', async () => {
59
+ const { apply } = useBulkAction<number, string>({ actions: [] });
60
+
61
+ await expect(apply('missing')).rejects.toThrow('"missing"');
62
+ });
63
+
64
+ test('reset clears the selection and calls onReset', () => {
65
+ const onReset = vi.fn();
66
+ const { reset, selectedItems, hasSelection } = useBulkAction<number>({
67
+ actions: [],
68
+ onReset,
69
+ initialSelection: [1],
70
+ });
71
+
72
+ expect(hasSelection.value).toBe(true);
73
+ reset();
74
+
75
+ expect(selectedItems.value).toEqual([]);
76
+ expect(onReset).toHaveBeenCalledOnce();
77
+ });
78
+ });
@@ -0,0 +1,3 @@
1
+ export { default as UiBulkAction } from './UiBulkAction.vue';
2
+ export { useBulkAction } from './useBulkAction';
3
+ export * from './types';
@@ -0,0 +1,126 @@
1
+ import type { ComputedRef, Ref } from 'vue';
2
+
3
+ /**
4
+ * State of the select-all checkbox. `'indeterminate'` when only some rows
5
+ * are selected.
6
+ */
7
+ export type UiBulkActionCheckedState = boolean | 'indeterminate';
8
+
9
+ /**
10
+ * A bar of actions applied to every currently selected item at once.
11
+ * Always starts with the select-all checkbox and ends with the reset button;
12
+ * custom actions go in the default slot between them.
13
+ * @category Data Display
14
+ * @useCases bulk delete, bulk edit, multi-select actions, table selection toolbar
15
+ * @keywords bulk, batch, selection, multi-select, actions, toolbar
16
+ * @related UiDataTable, UiFloatActionItems
17
+ */
18
+ export interface UiBulkActionProps {
19
+ /**
20
+ * State of the select-all checkbox. Use `v-model:checked`.
21
+ * @default false
22
+ */
23
+ checked?: UiBulkActionCheckedState;
24
+
25
+ /**
26
+ * Number of currently selected items, exposed to the default slot.
27
+ * @default 0
28
+ */
29
+ selectedCount?: number;
30
+
31
+ /**
32
+ * Accessible name of the toolbar.
33
+ * @default 'Bulk actions'
34
+ */
35
+ ariaLabel?: string;
36
+
37
+ /**
38
+ * Accessible name of the select-all checkbox.
39
+ * @default 'Select all rows on this page'
40
+ */
41
+ selectAllLabel?: string;
42
+
43
+ /**
44
+ * Accessible name of the reset button.
45
+ * @default 'Reset selection'
46
+ */
47
+ resetLabel?: string;
48
+ }
49
+
50
+ /**
51
+ * An action that can be applied to the selected items.
52
+ */
53
+ export interface UiBulkActionDefinition<TItem, TKey extends string = string> {
54
+ /**
55
+ * Unique identifier used to run the action through `apply`.
56
+ */
57
+ key: TKey;
58
+
59
+ /**
60
+ * Runs the action. Receives the items selected when `apply` was called.
61
+ */
62
+ action: (items: TItem[]) => void | Promise<void>;
63
+ }
64
+
65
+ /**
66
+ * Options for the `useBulkAction` composable.
67
+ */
68
+ export interface UseBulkActionOptions<TItem, TKey extends string = string> {
69
+ /**
70
+ * Actions that can be applied to the selection, identified by `key`.
71
+ */
72
+ actions: UiBulkActionDefinition<TItem, TKey>[];
73
+
74
+ /**
75
+ * Called by `reset` after the selection is cleared, e.g. to reset the
76
+ * selection state of a table.
77
+ */
78
+ onReset?: () => void;
79
+
80
+ /**
81
+ * Items that are initially selected.
82
+ */
83
+ initialSelection?: TItem[];
84
+ }
85
+
86
+ /**
87
+ * State and helpers returned by the `useBulkAction` composable.
88
+ */
89
+ export interface UseBulkActionReturn<TItem, TKey extends string = string> {
90
+ /**
91
+ * Runs the action with the given key, or each action in the given array of
92
+ * keys in order, on the currently selected items. Resolves once every action
93
+ * has finished.
94
+ * @example
95
+ * ```ts
96
+ * await apply('delete');
97
+ * await apply(['archive', 'notify']);
98
+ * ```
99
+ */
100
+ apply: (keys: TKey | TKey[]) => Promise<void>;
101
+
102
+ /**
103
+ * Clears the selection and calls `onReset`.
104
+ */
105
+ reset: () => void;
106
+
107
+ /**
108
+ * Currently selected items.
109
+ */
110
+ selectedItems: Ref<TItem[]>;
111
+
112
+ /**
113
+ * Number of currently selected items.
114
+ */
115
+ selectedCount: ComputedRef<number>;
116
+
117
+ /**
118
+ * Whether at least one item is selected.
119
+ */
120
+ hasSelection: ComputedRef<boolean>;
121
+
122
+ /**
123
+ * Remove every item from the selection.
124
+ */
125
+ clearSelection: () => void;
126
+ }
@@ -0,0 +1,50 @@
1
+ import { computed, ref, type Ref } from 'vue';
2
+ import type { UseBulkActionOptions, UseBulkActionReturn } from './types';
3
+
4
+ /**
5
+ * Selection state and action runner for applying actions to many items at once.
6
+ * @param options - Available actions, reset callback, and initial selection
7
+ * @returns Reactive selection state, `apply` to run actions, and `reset`
8
+ */
9
+ export function useBulkAction<TItem, TKey extends string = string>(
10
+ options: UseBulkActionOptions<TItem, TKey>,
11
+ ): UseBulkActionReturn<TItem, TKey> {
12
+ const selectedItems = ref([...(options.initialSelection ?? [])]) as Ref<
13
+ TItem[]
14
+ >;
15
+
16
+ const selectedCount = computed(() => selectedItems.value.length);
17
+ const hasSelection = computed(() => selectedCount.value > 0);
18
+
19
+ async function apply(keys: TKey | TKey[]): Promise<void> {
20
+ // Snapshot so every action in a group sees the same items, even if one
21
+ // of them changes the selection.
22
+ const items = [...selectedItems.value];
23
+
24
+ for (const key of Array.isArray(keys) ? keys : [keys]) {
25
+ const entry = options.actions.find((candidate) => candidate.key === key);
26
+ if (!entry) {
27
+ throw new Error(`useBulkAction: no action registered for "${key}"`);
28
+ }
29
+ await entry.action(items);
30
+ }
31
+ }
32
+
33
+ function clearSelection(): void {
34
+ selectedItems.value = [];
35
+ }
36
+
37
+ function reset(): void {
38
+ clearSelection();
39
+ options.onReset?.();
40
+ }
41
+
42
+ return {
43
+ apply,
44
+ reset,
45
+ selectedItems,
46
+ selectedCount,
47
+ hasSelection,
48
+ clearSelection,
49
+ };
50
+ }