@urbicon-ui/table 6.1.4

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 (154) hide show
  1. package/README.md +153 -0
  2. package/dist/cells/ActionButtons.svelte +224 -0
  3. package/dist/cells/ActionButtons.svelte.d.ts +74 -0
  4. package/dist/cells/CopyButton.svelte +89 -0
  5. package/dist/cells/CopyButton.svelte.d.ts +33 -0
  6. package/dist/cells/CustomCell.svelte +136 -0
  7. package/dist/cells/CustomCell.svelte.d.ts +44 -0
  8. package/dist/cells/DateCell.svelte +194 -0
  9. package/dist/cells/DateCell.svelte.d.ts +39 -0
  10. package/dist/cells/LinkCell.svelte +240 -0
  11. package/dist/cells/LinkCell.svelte.d.ts +42 -0
  12. package/dist/cells/NumberCell.svelte +225 -0
  13. package/dist/cells/NumberCell.svelte.d.ts +47 -0
  14. package/dist/cells/StatusBadge.svelte +121 -0
  15. package/dist/cells/StatusBadge.svelte.d.ts +44 -0
  16. package/dist/cells/UserAvatar.svelte +71 -0
  17. package/dist/cells/UserAvatar.svelte.d.ts +37 -0
  18. package/dist/cells/index.d.ts +8 -0
  19. package/dist/cells/index.js +9 -0
  20. package/dist/core/EmptyState.svelte +161 -0
  21. package/dist/core/EmptyState.svelte.d.ts +16 -0
  22. package/dist/core/ErrorState.svelte +158 -0
  23. package/dist/core/ErrorState.svelte.d.ts +15 -0
  24. package/dist/core/GroupedRow.svelte +239 -0
  25. package/dist/core/GroupedRow.svelte.d.ts +18 -0
  26. package/dist/core/LoadingState.svelte +75 -0
  27. package/dist/core/LoadingState.svelte.d.ts +14 -0
  28. package/dist/core/MobileCard.svelte +151 -0
  29. package/dist/core/MobileCard.svelte.d.ts +15 -0
  30. package/dist/core/TableCell.svelte +105 -0
  31. package/dist/core/TableCell.svelte.d.ts +14 -0
  32. package/dist/core/TableDesktop.svelte +480 -0
  33. package/dist/core/TableDesktop.svelte.d.ts +26 -0
  34. package/dist/core/TableHead.svelte +314 -0
  35. package/dist/core/TableHead.svelte.d.ts +7 -0
  36. package/dist/core/TableMobile.svelte +112 -0
  37. package/dist/core/TableMobile.svelte.d.ts +13 -0
  38. package/dist/core/TableProvider.svelte +271 -0
  39. package/dist/core/TableProvider.svelte.d.ts +40 -0
  40. package/dist/core/TableRow.svelte +171 -0
  41. package/dist/core/TableRow.svelte.d.ts +16 -0
  42. package/dist/core/index.d.ts +17 -0
  43. package/dist/core/index.js +14 -0
  44. package/dist/core/sticky-context.svelte.d.ts +48 -0
  45. package/dist/core/sticky-context.svelte.js +88 -0
  46. package/dist/core/table/Table.svelte +304 -0
  47. package/dist/core/table/Table.svelte.d.ts +26 -0
  48. package/dist/core/table/index.d.ts +448 -0
  49. package/dist/core/table/index.js +1 -0
  50. package/dist/core/table-style-context.d.ts +66 -0
  51. package/dist/core/table-style-context.js +26 -0
  52. package/dist/factories/ColumnValidation.d.ts +49 -0
  53. package/dist/factories/ColumnValidation.js +188 -0
  54. package/dist/factories/TableColumns.d.ts +97 -0
  55. package/dist/factories/TableColumns.js +262 -0
  56. package/dist/factories/TypedColumnBuilder.d.ts +41 -0
  57. package/dist/factories/TypedColumnBuilder.js +72 -0
  58. package/dist/factories/index.d.ts +12 -0
  59. package/dist/factories/index.js +13 -0
  60. package/dist/features/HeaderMenu.svelte +236 -0
  61. package/dist/features/HeaderMenu.svelte.d.ts +8 -0
  62. package/dist/features/LiveUpdateBanner.svelte +66 -0
  63. package/dist/features/LiveUpdateBanner.svelte.d.ts +6 -0
  64. package/dist/features/SearchHighlight.svelte +21 -0
  65. package/dist/features/SearchHighlight.svelte.d.ts +8 -0
  66. package/dist/features/SmartFilterBar/ChipsField.svelte +104 -0
  67. package/dist/features/SmartFilterBar/ChipsField.svelte.d.ts +5 -0
  68. package/dist/features/SmartFilterBar/ColumnVisibilityMenu.svelte +84 -0
  69. package/dist/features/SmartFilterBar/ColumnVisibilityMenu.svelte.d.ts +3 -0
  70. package/dist/features/SmartFilterBar/FilterMenu.svelte +367 -0
  71. package/dist/features/SmartFilterBar/FilterMenu.svelte.d.ts +3 -0
  72. package/dist/features/SmartFilterBar/GroupingMenu.svelte +82 -0
  73. package/dist/features/SmartFilterBar/GroupingMenu.svelte.d.ts +3 -0
  74. package/dist/features/SmartFilterBar/SmartFilterBar.svelte +109 -0
  75. package/dist/features/SmartFilterBar/SmartFilterBar.svelte.d.ts +11 -0
  76. package/dist/features/SmartFilterBar/SummaryMenu.svelte +118 -0
  77. package/dist/features/SmartFilterBar/SummaryMenu.svelte.d.ts +3 -0
  78. package/dist/features/SummaryRow.svelte +97 -0
  79. package/dist/features/SummaryRow.svelte.d.ts +8 -0
  80. package/dist/features/index.d.ts +4 -0
  81. package/dist/features/index.js +4 -0
  82. package/dist/i18n/index.d.ts +366 -0
  83. package/dist/i18n/index.js +21 -0
  84. package/dist/index.d.ts +28 -0
  85. package/dist/index.js +41 -0
  86. package/dist/stores/TableStore.svelte.d.ts +192 -0
  87. package/dist/stores/TableStore.svelte.js +362 -0
  88. package/dist/stores/concerns/index.d.ts +15 -0
  89. package/dist/stores/concerns/index.js +14 -0
  90. package/dist/stores/concerns/types.d.ts +31 -0
  91. package/dist/stores/concerns/types.js +1 -0
  92. package/dist/stores/concerns/useColumnOrder.svelte.d.ts +16 -0
  93. package/dist/stores/concerns/useColumnOrder.svelte.js +81 -0
  94. package/dist/stores/concerns/useColumnVisibility.svelte.d.ts +16 -0
  95. package/dist/stores/concerns/useColumnVisibility.svelte.js +58 -0
  96. package/dist/stores/concerns/useExpansion.svelte.d.ts +9 -0
  97. package/dist/stores/concerns/useExpansion.svelte.js +32 -0
  98. package/dist/stores/concerns/useFiltering.svelte.d.ts +20 -0
  99. package/dist/stores/concerns/useFiltering.svelte.js +109 -0
  100. package/dist/stores/concerns/useFocusManagement.svelte.d.ts +15 -0
  101. package/dist/stores/concerns/useFocusManagement.svelte.js +52 -0
  102. package/dist/stores/concerns/useGrouping.svelte.d.ts +15 -0
  103. package/dist/stores/concerns/useGrouping.svelte.js +86 -0
  104. package/dist/stores/concerns/useLiveUpdates.svelte.d.ts +45 -0
  105. package/dist/stores/concerns/useLiveUpdates.svelte.js +175 -0
  106. package/dist/stores/concerns/usePagination.svelte.d.ts +18 -0
  107. package/dist/stores/concerns/usePagination.svelte.js +54 -0
  108. package/dist/stores/concerns/usePersistence.svelte.d.ts +36 -0
  109. package/dist/stores/concerns/usePersistence.svelte.js +167 -0
  110. package/dist/stores/concerns/useRemoteData.svelte.d.ts +21 -0
  111. package/dist/stores/concerns/useRemoteData.svelte.js +64 -0
  112. package/dist/stores/concerns/useSearch.svelte.d.ts +8 -0
  113. package/dist/stores/concerns/useSearch.svelte.js +16 -0
  114. package/dist/stores/concerns/useSelection.svelte.d.ts +21 -0
  115. package/dist/stores/concerns/useSelection.svelte.js +110 -0
  116. package/dist/stores/concerns/useSorting.svelte.d.ts +11 -0
  117. package/dist/stores/concerns/useSorting.svelte.js +70 -0
  118. package/dist/stores/concerns/useSummary.svelte.d.ts +18 -0
  119. package/dist/stores/concerns/useSummary.svelte.js +96 -0
  120. package/dist/stores/index.d.ts +1 -0
  121. package/dist/stores/index.js +1 -0
  122. package/dist/style/index.css +137 -0
  123. package/dist/style/index.d.ts +2 -0
  124. package/dist/style/index.js +2 -0
  125. package/dist/style/table-theme.css +131 -0
  126. package/dist/style/themes/comfortable.css +20 -0
  127. package/dist/style/themes/compact.css +20 -0
  128. package/dist/translations/de.d.ts +177 -0
  129. package/dist/translations/de.js +176 -0
  130. package/dist/translations/en.d.ts +177 -0
  131. package/dist/translations/en.js +176 -0
  132. package/dist/types/index.d.ts +1 -0
  133. package/dist/types/index.js +1 -0
  134. package/dist/types/tableTypes.d.ts +262 -0
  135. package/dist/types/tableTypes.js +1 -0
  136. package/dist/utils/index.d.ts +165 -0
  137. package/dist/utils/index.js +330 -0
  138. package/dist/utils/sticky-measure.d.ts +54 -0
  139. package/dist/utils/sticky-measure.js +107 -0
  140. package/dist/utils/virtualizer.d.ts +43 -0
  141. package/dist/utils/virtualizer.js +43 -0
  142. package/dist/variants/index.d.ts +11 -0
  143. package/dist/variants/index.js +15 -0
  144. package/dist/variants/table-cells.variants.d.ts +827 -0
  145. package/dist/variants/table-cells.variants.js +627 -0
  146. package/dist/variants/table-features.variants.d.ts +547 -0
  147. package/dist/variants/table-features.variants.js +412 -0
  148. package/dist/variants/table-states.variants.d.ts +594 -0
  149. package/dist/variants/table-states.variants.js +394 -0
  150. package/dist/variants/table.system.d.ts +301 -0
  151. package/dist/variants/table.system.js +314 -0
  152. package/dist/variants/table.variants.d.ts +428 -0
  153. package/dist/variants/table.variants.js +360 -0
  154. package/package.json +93 -0
package/README.md ADDED
@@ -0,0 +1,153 @@
1
+ # @urbicon-ui/table
2
+
3
+ Feature-complete data table for Svelte 5 — zero runtime dependencies, part of the Urbicon UI monorepo.
4
+
5
+ > **Maturity:** stable since `v1.0.0` (2026-05-12). `v2.0.0` (2026-05-15) refactored the Column API to separate `accessor` (value extraction) from `id` (state-targeting), eliminating the `"[object Object]"`-search trap; see `CHANGELOG.md`. All nine implementation phases are closed; 185 unit tests cover every concern.
6
+
7
+ ## Installation
8
+
9
+ This package ships inside the Urbicon UI monorepo. Install from repo root:
10
+
11
+ ```bash
12
+ bun install
13
+ ```
14
+
15
+ Peer dependencies: `svelte` (^5), `@urbicon-ui/blocks`, `@urbicon-ui/i18n`.
16
+
17
+ ## Capability Overview
18
+
19
+ | Area | Highlights |
20
+ | ------------------- | --------------------------------------------------------------------------------------------------------------------------- |
21
+ | Data pipeline | `$derived`-chain `items → filteredItems → sortedItems → grouped → paginatedItems`; all stages reactive |
22
+ | Sorting & Filtering | Column sort (asc/desc/none tri-state), smart filter bar, column-level filters, search highlighting |
23
+ | Selection | Single / multi, `onSelectionChange`, indeterminate header, keyboard toggle (`Space`) |
24
+ | Keyboard | Roving tabindex, ARIA-Grid role, arrow keys, `Home`/`End`/`PageUp`/`PageDown`, Skip-Link |
25
+ | Grouping | `groupByKey`, collapsible group headers, grouped summary rows |
26
+ | Pagination | Built-in paginator, auto-disable on grouping, mobile-friendly controls |
27
+ | Virtualization | `computeVirtualItems` for 10k+ rows (custom, zero deps); `virtualHeight` prop; falls back to normal rendering when inactive |
28
+ | Column ordering | Pointer-event drag-and-drop + `Shift+ArrowLeft/Right` keyboard reorder via shared `createDraggable` action |
29
+ | Column visibility | Header menu + persistence API |
30
+ | Remote mode | `mode: 'server'` + `queryFn` (managed fetch with `AbortSignal`) or `onQueryChange` (manual), debounced, cancellation-safe |
31
+ | Live updates | `pushInsert/Update/Delete` pending-buffer, `LiveUpdateBanner`, auto-apply on navigation |
32
+ | Styling | `unstyled`, `slotClasses`, `TableStyleContext` — every subcomponent respects the 17-slot map |
33
+ | Cells | `LinkCell`, `NumberCell`, `DateCell`, `UserAvatar`, `StatusBadge`, `CustomCell`, Fill-Cell |
34
+ | i18n | Package-scoped namespace `table.*`, EN + DE |
35
+
36
+ ## Quick Start
37
+
38
+ ```svelte
39
+ <script lang="ts">
40
+ import { Table, TableColumns } from '@urbicon-ui/table';
41
+
42
+ let items = $state([
43
+ { id: 1, name: 'Alice', role: 'Admin' },
44
+ { id: 2, name: 'Bob', role: 'User' }
45
+ ]);
46
+
47
+ const columns = [
48
+ TableColumns.text('name', 'Name', { sortable: true }),
49
+ TableColumns.text('role', 'Role')
50
+ ];
51
+ </script>
52
+
53
+ <Table {items} {columns} selectionMode="multi" onSelectionChange={(rows) => console.log(rows)} />
54
+ ```
55
+
56
+ ### Server-mode with managed fetch
57
+
58
+ ```svelte
59
+ <Table
60
+ mode="server"
61
+ serverTotalItems={total}
62
+ queryFn={async (query, { signal }) => {
63
+ const res = await fetch(`/api/users?${new URLSearchParams(query)}`, { signal });
64
+ return res.json(); // { items, totalItems }
65
+ }}
66
+ {columns}
67
+ />
68
+ ```
69
+
70
+ ### Live updates
71
+
72
+ ```svelte
73
+ <Table {items} {columns} enableLiveUpdates>
74
+ {#snippet aboveTable({ ctx })}
75
+ <button onclick={() => ctx.pushInsert({ id: crypto.randomUUID(), name: 'New' })}>
76
+ + row
77
+ </button>
78
+ {/snippet}
79
+ </Table>
80
+ ```
81
+
82
+ ## State Persistence
83
+
84
+ `persistenceConfig={{ tableId: 'foo' }}` is enough to make filters, search, group-by, summaries, sort, column visibility and column order survive a page reload. Every axis is on by default and stored under a `tableId`-scoped key in `localStorage`. Pagination is intentionally **not** persisted — page 1 on navigation is standard UX.
85
+
86
+ ```svelte
87
+ <Table {items} {columns} persistenceConfig={{ tableId: 'expenses' }} />
88
+ ```
89
+
90
+ Disable individual axes (e.g. always start filter-free, but keep the column layout the user picked):
91
+
92
+ ```svelte
93
+ <Table
94
+ {items}
95
+ {columns}
96
+ persistenceConfig={{
97
+ tableId: 'expenses',
98
+ persistFilters: false,
99
+ persistSearch: false
100
+ }}
101
+ />
102
+ ```
103
+
104
+ Storage keys are namespaced by `tableId` (`urbicon_table_filters_expenses_v1`, …); pick a stable, unique `tableId` per table — two tables sharing one id will overwrite each other.
105
+
106
+ `storage: 'sessionStorage'` limits persistence to the current tab (lost on tab close). The `clearAllPersistentData` and `forceSavePersistentData` methods on the table context let you reset or flush state imperatively.
107
+
108
+ ## Subcomponent Styling
109
+
110
+ Every structural subcomponent (`EmptyState`, `ErrorState`, `LoadingState`, `GroupedRow`, `SummaryRow`, `MobileCard`, `SmartFilterBar`) consumes `TableStyleContext` — pass `slotClasses` at the `<Table>` root and it reaches the leaves.
111
+
112
+ ```svelte
113
+ <Table
114
+ {items}
115
+ {columns}
116
+ unstyled
117
+ slotClasses={{
118
+ container: 'rounded-2xl bg-surface-elevated',
119
+ headerCell: 'text-text-tertiary uppercase tracking-wider text-xs',
120
+ row: 'hover:bg-surface-hover'
121
+ }}
122
+ />
123
+ ```
124
+
125
+ ## i18n
126
+
127
+ Namespace: `table.*`. Resolve typed keys via the context hook `useTableI18n` — call it during component init and alias the result `tt`:
128
+
129
+ ```svelte
130
+ <script>
131
+ import { useTableI18n } from '@urbicon-ui/table';
132
+ const tt = useTableI18n();
133
+ </script>
134
+
135
+ <span>{tt('data.loading')}</span>
136
+ <!-- "Loading data…" -->
137
+ <span>{tt('pagination.showing', { start: 1, end: 10, total: 100 })}</span>
138
+ ```
139
+
140
+ Resolves against the request-scoped locale from `<I18nProvider>` (or the base locale `en` without one). Add a locale: register a new package via `@urbicon-ui/i18n`'s `createPackageI18n`, or extend the existing bundles in `src/lib/translations/`.
141
+
142
+ ## Development
143
+
144
+ ```bash
145
+ bun --filter='@urbicon-ui/table' run dev # svelte-package watch
146
+ bun --filter='@urbicon-ui/table' run build # svelte-package
147
+ bun --filter='@urbicon-ui/table' run check # svelte-check
148
+ bunx --bun vitest run # unit tests (from package root)
149
+ ```
150
+
151
+ ## Related
152
+
153
+ - [docs/ARCHITECTURE.md](../../docs/ARCHITECTURE.md) — remote-data architecture
@@ -0,0 +1,224 @@
1
+ <script lang="ts" generics="Item">
2
+ import type { Component } from 'svelte';
3
+ import {
4
+ Button,
5
+ resolveIcon,
6
+ EditIcon as EditIconDefault,
7
+ TrashIcon as TrashIconDefault,
8
+ EyeIcon as EyeIconDefault
9
+ } from '@urbicon-ui/blocks';
10
+
11
+ const EditIcon = resolveIcon('edit', EditIconDefault);
12
+ const TrashIcon = resolveIcon('trash', TrashIconDefault);
13
+ const EyeIcon = resolveIcon('eye', EyeIconDefault);
14
+ import { useTableI18n } from '../i18n';
15
+ import { actionCellVariants, type ActionCellVariantProps } from '../variants';
16
+
17
+ const tt = useTableI18n();
18
+
19
+ /**
20
+ * Extra action descriptor for `ActionButtons`. Renders an additional ghost
21
+ * Button next to the built-in view/edit/delete trio so callers don't have to
22
+ * fall back to a custom cell snippet for one extra action.
23
+ */
24
+ export type ExtraAction<Item> = {
25
+ /** Icon component (e.g. the imported `ActivityIcon`). */
26
+ icon: Component<{ class?: string; [key: string]: unknown }>;
27
+ /** Accessible label and tooltip — used for `aria-label`. */
28
+ label: string;
29
+ /** Click handler. Receives the row item. */
30
+ onClick: (item: Item) => void;
31
+ /** Button intent. @default 'secondary' */
32
+ intent?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'neutral';
33
+ /** Predicate that disables this action for a given item. @default () => false */
34
+ disabled?: (item: Item) => boolean;
35
+ /** Predicate that hides this action for a given item entirely. @default () => true */
36
+ show?: (item: Item) => boolean;
37
+ /** Optional `data-testid` suffix; defaults to a slugified label. */
38
+ testIdSuffix?: string;
39
+ };
40
+
41
+ export type ActionButtonsProps<Item> = {
42
+ onEdit?: (item: Item) => void;
43
+ onDelete?: (item: Item) => void;
44
+ onView?: (item: Item) => void;
45
+ canEdit?: (item: Item) => boolean;
46
+ canDelete?: (item: Item) => boolean;
47
+ showEdit?: boolean;
48
+ showDelete?: boolean;
49
+ showView?: boolean;
50
+ /**
51
+ * Extra actions rendered before the built-in view/edit/delete buttons.
52
+ * Use this for app-specific actions (e.g. "Show readings", "Duplicate")
53
+ * instead of writing a custom cell snippet.
54
+ */
55
+ extraActions?: ExtraAction<Item>[];
56
+ item: Item;
57
+ idProperty?: keyof Item;
58
+ size?: ActionCellVariantProps['size'];
59
+ variant?: ActionCellVariantProps['variant'];
60
+ className?: string;
61
+ testId?: string;
62
+ align?: 'left' | 'center' | 'right';
63
+ maxWidth?: string;
64
+ };
65
+
66
+ let {
67
+ item,
68
+ showEdit = true,
69
+ showDelete = true,
70
+ showView = false,
71
+ extraActions = [],
72
+ onEdit = () => {},
73
+ onDelete = () => {},
74
+ onView = () => {},
75
+ canEdit = () => true,
76
+ canDelete = () => true,
77
+ idProperty = 'id' as keyof Item,
78
+ size = 'sm',
79
+ variant = 'ghost',
80
+ className = '',
81
+ testId = undefined,
82
+ align = 'right',
83
+ maxWidth = '7rem'
84
+ }: ActionButtonsProps<Item> = $props();
85
+
86
+ function slugify(label: string): string {
87
+ return label
88
+ .toLowerCase()
89
+ .replace(/[^a-z0-9]+/g, '-')
90
+ .replace(/^-+|-+$/g, '');
91
+ }
92
+
93
+ function makeExtraHandler(action: ExtraAction<Item>) {
94
+ return (event: MouseEvent) => {
95
+ event.stopPropagation();
96
+ if (action.disabled?.(item)) return;
97
+ action.onClick(item);
98
+ };
99
+ }
100
+
101
+ const id = $derived((item[idProperty] ?? '').toString());
102
+
103
+ const computedTestId = $derived(() => {
104
+ if (testId) return testId;
105
+ return `action-buttons-${id}`;
106
+ });
107
+
108
+ // Container styling for consistent layout
109
+ const containerStyles = $derived(
110
+ actionCellVariants({
111
+ size,
112
+ variant
113
+ })
114
+ );
115
+
116
+ // Count visible buttons
117
+ const visibleButtonsCount = $derived(() => {
118
+ let count = 0;
119
+ if (showView) count++;
120
+ if (showEdit) count++;
121
+ if (showDelete) count++;
122
+ return count;
123
+ });
124
+
125
+ function handleEdit(event: MouseEvent) {
126
+ event.stopPropagation();
127
+ if (canEdit(item)) {
128
+ onEdit(item);
129
+ }
130
+ }
131
+
132
+ function handleDelete(event: MouseEvent) {
133
+ event.stopPropagation();
134
+ if (canDelete(item)) {
135
+ onDelete(item);
136
+ }
137
+ }
138
+
139
+ function handleView(event: MouseEvent) {
140
+ event.stopPropagation();
141
+ onView(item);
142
+ }
143
+ </script>
144
+
145
+ <!-- Container with fixed width and alignment -->
146
+ <div
147
+ class="flex min-h-10 items-center px-2 py-1 {align === 'center'
148
+ ? 'justify-center'
149
+ : align === 'right'
150
+ ? 'justify-end'
151
+ : 'justify-start'} {className}"
152
+ style="max-width: {maxWidth}; width: {maxWidth};"
153
+ data-testid={computedTestId()}
154
+ >
155
+ <!-- Button container -->
156
+ <div class="{containerStyles.container()} w-full">
157
+ {#if showView}
158
+ <Button
159
+ variant="ghost"
160
+ size="xs"
161
+ intent="secondary"
162
+ onclick={handleView}
163
+ aria-label={tt('actions.showDetails')}
164
+ data-testid={`view-${id}`}
165
+ class="{containerStyles.button()} flex-shrink-0"
166
+ >
167
+ <EyeIcon class={containerStyles.icon()} />
168
+ </Button>
169
+ {/if}
170
+
171
+ {#each extraActions as action (action.testIdSuffix ?? action.label)}
172
+ {#if action.show?.(item) ?? true}
173
+ {@const ExtraIcon = action.icon}
174
+ {@const isDisabled = action.disabled?.(item) ?? false}
175
+ <Button
176
+ variant="ghost"
177
+ size="xs"
178
+ intent={action.intent ?? 'secondary'}
179
+ onclick={makeExtraHandler(action)}
180
+ disabled={isDisabled}
181
+ aria-disabled={isDisabled}
182
+ aria-label={action.label}
183
+ title={action.label}
184
+ data-testid={`${action.testIdSuffix ?? slugify(action.label)}-${id}`}
185
+ class="{containerStyles.button()} flex-shrink-0"
186
+ >
187
+ <ExtraIcon class={containerStyles.icon()} />
188
+ </Button>
189
+ {/if}
190
+ {/each}
191
+
192
+ {#if showEdit}
193
+ <Button
194
+ variant="ghost"
195
+ size="xs"
196
+ intent="primary"
197
+ onclick={handleEdit}
198
+ disabled={!canEdit(item)}
199
+ aria-disabled={!canEdit(item)}
200
+ aria-label={tt('actions.edit')}
201
+ data-testid={`edit-${id}`}
202
+ class="{containerStyles.button()} flex-shrink-0"
203
+ >
204
+ <EditIcon class={containerStyles.icon()} />
205
+ </Button>
206
+ {/if}
207
+
208
+ {#if showDelete}
209
+ <Button
210
+ variant="ghost"
211
+ size="xs"
212
+ intent="danger"
213
+ onclick={handleDelete}
214
+ disabled={!canDelete(item)}
215
+ aria-disabled={!canDelete(item)}
216
+ aria-label={tt('actions.delete')}
217
+ data-testid={`delete-${id}`}
218
+ class="{containerStyles.button()} flex-shrink-0"
219
+ >
220
+ <TrashIcon class={containerStyles.icon()} />
221
+ </Button>
222
+ {/if}
223
+ </div>
224
+ </div>
@@ -0,0 +1,74 @@
1
+ import type { Component } from 'svelte';
2
+ import { type ActionCellVariantProps } from '../variants';
3
+ /**
4
+ * Extra action descriptor for `ActionButtons`. Renders an additional ghost
5
+ * Button next to the built-in view/edit/delete trio so callers don't have to
6
+ * fall back to a custom cell snippet for one extra action.
7
+ */
8
+ export type ExtraAction<Item> = {
9
+ /** Icon component (e.g. the imported `ActivityIcon`). */
10
+ icon: Component<{
11
+ class?: string;
12
+ [key: string]: unknown;
13
+ }>;
14
+ /** Accessible label and tooltip — used for `aria-label`. */
15
+ label: string;
16
+ /** Click handler. Receives the row item. */
17
+ onClick: (item: Item) => void;
18
+ /** Button intent. @default 'secondary' */
19
+ intent?: 'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'neutral';
20
+ /** Predicate that disables this action for a given item. @default () => false */
21
+ disabled?: (item: Item) => boolean;
22
+ /** Predicate that hides this action for a given item entirely. @default () => true */
23
+ show?: (item: Item) => boolean;
24
+ /** Optional `data-testid` suffix; defaults to a slugified label. */
25
+ testIdSuffix?: string;
26
+ };
27
+ export type ActionButtonsProps<Item> = {
28
+ onEdit?: (item: Item) => void;
29
+ onDelete?: (item: Item) => void;
30
+ onView?: (item: Item) => void;
31
+ canEdit?: (item: Item) => boolean;
32
+ canDelete?: (item: Item) => boolean;
33
+ showEdit?: boolean;
34
+ showDelete?: boolean;
35
+ showView?: boolean;
36
+ /**
37
+ * Extra actions rendered before the built-in view/edit/delete buttons.
38
+ * Use this for app-specific actions (e.g. "Show readings", "Duplicate")
39
+ * instead of writing a custom cell snippet.
40
+ */
41
+ extraActions?: ExtraAction<Item>[];
42
+ item: Item;
43
+ idProperty?: keyof Item;
44
+ size?: ActionCellVariantProps['size'];
45
+ variant?: ActionCellVariantProps['variant'];
46
+ className?: string;
47
+ testId?: string;
48
+ align?: 'left' | 'center' | 'right';
49
+ maxWidth?: string;
50
+ };
51
+ declare function $$render<Item>(): {
52
+ props: ActionButtonsProps<Item>;
53
+ exports: {};
54
+ bindings: "";
55
+ slots: {};
56
+ events: {};
57
+ };
58
+ declare class __sveltets_Render<Item> {
59
+ props(): ReturnType<typeof $$render<Item>>['props'];
60
+ events(): ReturnType<typeof $$render<Item>>['events'];
61
+ slots(): ReturnType<typeof $$render<Item>>['slots'];
62
+ bindings(): "";
63
+ exports(): {};
64
+ }
65
+ interface $$IsomorphicComponent {
66
+ new <Item>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Item>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Item>['props']>, ReturnType<__sveltets_Render<Item>['events']>, ReturnType<__sveltets_Render<Item>['slots']>> & {
67
+ $$bindings?: ReturnType<__sveltets_Render<Item>['bindings']>;
68
+ } & ReturnType<__sveltets_Render<Item>['exports']>;
69
+ <Item>(internal: unknown, props: ReturnType<__sveltets_Render<Item>['props']> & {}): ReturnType<__sveltets_Render<Item>['exports']>;
70
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
71
+ }
72
+ declare const ActionButtons: $$IsomorphicComponent;
73
+ type ActionButtons<Item> = InstanceType<typeof ActionButtons<Item>>;
74
+ export default ActionButtons;
@@ -0,0 +1,89 @@
1
+ <script lang="ts" generics="Item">
2
+ import {
3
+ Button,
4
+ resolveIcon,
5
+ CheckCircleIcon as CheckCircleIconDefault,
6
+ CopyIcon as CopyIconDefault
7
+ } from '@urbicon-ui/blocks';
8
+
9
+ const CheckCircleIcon = resolveIcon('checkCircle', CheckCircleIconDefault);
10
+ const CopyIcon = resolveIcon('copy', CopyIconDefault);
11
+ import { useTableI18n } from '../i18n';
12
+ import { type CopyButtonVariantProps, copyButtonVariants } from '../variants';
13
+
14
+ const tt = useTableI18n();
15
+
16
+ export type CopyButtonProps<Item> = {
17
+ item: Item;
18
+ valueKey?: keyof Item;
19
+ label?: string;
20
+ size?: CopyButtonVariantProps['size'];
21
+ responsive?: CopyButtonVariantProps['responsive'];
22
+ className?: string;
23
+ };
24
+
25
+ let {
26
+ item,
27
+ valueKey = 'email' as keyof Item,
28
+ label: labelProp = undefined as string | undefined,
29
+ size = 'xs',
30
+ responsive = true,
31
+ className = ''
32
+ }: CopyButtonProps<Item> = $props();
33
+
34
+ const label = $derived(labelProp ?? tt('copy.button'));
35
+
36
+ let copied = $state(false);
37
+ let failed = $state(false);
38
+
39
+ // Reactive value extraction
40
+ const value = $derived(item[valueKey] || '');
41
+
42
+ // Tailwind-Variants styling
43
+ const styles = $derived(copyButtonVariants({ size, responsive }));
44
+
45
+ async function copyToClipboard(event: MouseEvent) {
46
+ event.stopPropagation();
47
+ try {
48
+ await navigator.clipboard.writeText(String(value));
49
+ copied = true;
50
+ failed = false;
51
+ setTimeout(() => (copied = false), 2000);
52
+ } catch (err) {
53
+ console.error('Copy failed:', err);
54
+ failed = true;
55
+ setTimeout(() => (failed = false), 2000);
56
+ }
57
+ }
58
+
59
+ function handleKeyDown(event: KeyboardEvent) {
60
+ if (event.key === 'Enter' || event.key === ' ') {
61
+ event.preventDefault();
62
+ copyToClipboard(event as unknown as MouseEvent);
63
+ }
64
+ }
65
+ </script>
66
+
67
+ <div class="{styles.container()} {className}">
68
+ <Button
69
+ variant="ghost"
70
+ size="xs"
71
+ intent={copied ? 'success' : failed ? 'danger' : 'secondary'}
72
+ onclick={copyToClipboard}
73
+ onkeydown={handleKeyDown}
74
+ title={copied ? tt('copy.copied') : failed ? tt('copy.failed') : `${label}: ${value}`}
75
+ class={styles.button()}
76
+ aria-label={copied ? tt('copy.copied') : failed ? tt('copy.failed') : label}
77
+ >
78
+ {#if copied}
79
+ <CheckCircleIcon class={styles.icon()} />
80
+ <span class={styles.textSuccess()}>{tt('copy.copied')}</span>
81
+ {:else if failed}
82
+ <CopyIcon class={styles.icon()} />
83
+ <span class={styles.text()}>{tt('copy.failed')}</span>
84
+ {:else}
85
+ <CopyIcon class={styles.icon()} />
86
+ <span class={styles.text()}>{label}</span>
87
+ {/if}
88
+ </Button>
89
+ </div>
@@ -0,0 +1,33 @@
1
+ import { type CopyButtonVariantProps } from '../variants';
2
+ export type CopyButtonProps<Item> = {
3
+ item: Item;
4
+ valueKey?: keyof Item;
5
+ label?: string;
6
+ size?: CopyButtonVariantProps['size'];
7
+ responsive?: CopyButtonVariantProps['responsive'];
8
+ className?: string;
9
+ };
10
+ declare function $$render<Item>(): {
11
+ props: CopyButtonProps<Item>;
12
+ exports: {};
13
+ bindings: "";
14
+ slots: {};
15
+ events: {};
16
+ };
17
+ declare class __sveltets_Render<Item> {
18
+ props(): ReturnType<typeof $$render<Item>>['props'];
19
+ events(): ReturnType<typeof $$render<Item>>['events'];
20
+ slots(): ReturnType<typeof $$render<Item>>['slots'];
21
+ bindings(): "";
22
+ exports(): {};
23
+ }
24
+ interface $$IsomorphicComponent {
25
+ new <Item>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Item>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Item>['props']>, ReturnType<__sveltets_Render<Item>['events']>, ReturnType<__sveltets_Render<Item>['slots']>> & {
26
+ $$bindings?: ReturnType<__sveltets_Render<Item>['bindings']>;
27
+ } & ReturnType<__sveltets_Render<Item>['exports']>;
28
+ <Item>(internal: unknown, props: ReturnType<__sveltets_Render<Item>['props']> & {}): ReturnType<__sveltets_Render<Item>['exports']>;
29
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
30
+ }
31
+ declare const CopyButton: $$IsomorphicComponent;
32
+ type CopyButton<Item> = InstanceType<typeof CopyButton<Item>>;
33
+ export default CopyButton;