numori-ui 0.4.0 → 0.6.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 (99) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/README.md +27 -20
  3. package/dist/components/AppShell.js +234 -0
  4. package/dist/components/AppShell.js.map +1 -0
  5. package/dist/components/Avatar.js +71 -19
  6. package/dist/components/Avatar.js.map +1 -1
  7. package/dist/components/Checkbox.js +11 -2
  8. package/dist/components/Checkbox.js.map +1 -1
  9. package/dist/components/CopyField.js +195 -0
  10. package/dist/components/CopyField.js.map +1 -0
  11. package/dist/components/DescriptionList.js +116 -0
  12. package/dist/components/DescriptionList.js.map +1 -0
  13. package/dist/components/Dropdown.js +3 -1
  14. package/dist/components/Dropdown.js.map +1 -1
  15. package/dist/components/EmptyState.js +123 -0
  16. package/dist/components/EmptyState.js.map +1 -0
  17. package/dist/components/FormField.js +43 -13
  18. package/dist/components/FormField.js.map +1 -1
  19. package/dist/components/Input.js +15 -1
  20. package/dist/components/Input.js.map +1 -1
  21. package/dist/components/Modal.js +61 -4
  22. package/dist/components/Modal.js.map +1 -1
  23. package/dist/components/PageHeader.js +106 -0
  24. package/dist/components/PageHeader.js.map +1 -0
  25. package/dist/components/Pagination.js +236 -0
  26. package/dist/components/Pagination.js.map +1 -0
  27. package/dist/components/Prompt.js +11 -6
  28. package/dist/components/Prompt.js.map +1 -1
  29. package/dist/components/Segmented.js +10 -2
  30. package/dist/components/Segmented.js.map +1 -1
  31. package/dist/components/Select.js +11 -2
  32. package/dist/components/Select.js.map +1 -1
  33. package/dist/components/Sidebar.js +69 -0
  34. package/dist/components/Sidebar.js.map +1 -0
  35. package/dist/components/SidebarGroup.js +50 -0
  36. package/dist/components/SidebarGroup.js.map +1 -0
  37. package/dist/components/SidebarItem.js +167 -0
  38. package/dist/components/SidebarItem.js.map +1 -0
  39. package/dist/components/Skeleton.js +122 -0
  40. package/dist/components/Skeleton.js.map +1 -0
  41. package/dist/components/SplitPane.js +264 -0
  42. package/dist/components/SplitPane.js.map +1 -0
  43. package/dist/components/StatCard.js +185 -0
  44. package/dist/components/StatCard.js.map +1 -0
  45. package/dist/components/Table.js +182 -50
  46. package/dist/components/Table.js.map +1 -1
  47. package/dist/components/Tabs.js +216 -0
  48. package/dist/components/Tabs.js.map +1 -0
  49. package/dist/components/Toggle.js +11 -2
  50. package/dist/components/Toggle.js.map +1 -1
  51. package/dist/components/Tree.js +417 -0
  52. package/dist/components/Tree.js.map +1 -0
  53. package/dist/components/VirtualList.js +292 -0
  54. package/dist/components/VirtualList.js.map +1 -0
  55. package/dist/components/index.js +105 -81
  56. package/dist/components/index.js.map +1 -1
  57. package/dist/icons/mdi.js +12 -0
  58. package/dist/icons/mdi.js.map +1 -1
  59. package/dist/index.d.ts +16 -1
  60. package/dist/index.js +54 -39
  61. package/dist/index.js.map +1 -1
  62. package/dist/internal/focusTrap.js +163 -0
  63. package/dist/internal/focusTrap.js.map +1 -0
  64. package/dist/internal/formField.js +26 -0
  65. package/dist/internal/formField.js.map +1 -0
  66. package/dist/manifest.js +16 -1
  67. package/dist/manifest.js.map +1 -1
  68. package/package.json +1 -1
  69. package/src/components/AppShell.vue +231 -0
  70. package/src/components/Avatar.vue +69 -18
  71. package/src/components/Checkbox.vue +5 -0
  72. package/src/components/CopyField.vue +178 -0
  73. package/src/components/DescriptionList.vue +114 -0
  74. package/src/components/Dropdown.vue +4 -1
  75. package/src/components/EmptyState.vue +107 -0
  76. package/src/components/FormField.vue +37 -4
  77. package/src/components/Input.vue +9 -0
  78. package/src/components/Modal.vue +51 -3
  79. package/src/components/PageHeader.vue +102 -0
  80. package/src/components/Pagination.vue +199 -0
  81. package/src/components/Prompt.vue +14 -3
  82. package/src/components/Segmented.vue +5 -0
  83. package/src/components/Select.vue +6 -1
  84. package/src/components/Sidebar.vue +61 -0
  85. package/src/components/SidebarGroup.vue +43 -0
  86. package/src/components/SidebarItem.vue +159 -0
  87. package/src/components/Skeleton.vue +91 -0
  88. package/src/components/SplitPane.vue +264 -0
  89. package/src/components/StatCard.vue +165 -0
  90. package/src/components/Table.vue +148 -18
  91. package/src/components/Tabs.vue +217 -0
  92. package/src/components/Toggle.vue +5 -0
  93. package/src/components/Tree.vue +428 -0
  94. package/src/components/VirtualList.vue +250 -0
  95. package/src/components/index.js +45 -6
  96. package/src/icons/mdi.js +12 -0
  97. package/src/internal/focusTrap.js +185 -0
  98. package/src/internal/formField.js +23 -0
  99. package/src/manifest.js +15 -0
@@ -0,0 +1,264 @@
1
+ <template>
2
+ <div
3
+ ref="rootRef"
4
+ class="flex h-full w-full min-h-0 min-w-0"
5
+ :class="[isHorizontal ? 'flex-row' : 'flex-col', dragging ? 'select-none' : '']"
6
+ >
7
+ <div
8
+ :id="startId"
9
+ class="relative min-h-0 min-w-0 shrink-0 overflow-hidden"
10
+ :style="startStyle"
11
+ >
12
+ <slot name="start" :size="currentSize" />
13
+ </div>
14
+
15
+ <!-- The splitter: the WAI-ARIA "window splitter" pattern. A 1px rule with
16
+ a wider invisible hit area, focusable and operable from the keyboard. -->
17
+ <div
18
+ role="separator"
19
+ tabindex="0"
20
+ :aria-label="label"
21
+ :aria-controls="startId"
22
+ :aria-orientation="isHorizontal ? 'vertical' : 'horizontal'"
23
+ :aria-valuenow="Math.round(currentSize)"
24
+ :aria-valuemin="min"
25
+ :aria-valuemax="effectiveMax"
26
+ :data-dragging="dragging ? 'true' : undefined"
27
+ class="group relative z-10 shrink-0 touch-none focus-visible:outline-none"
28
+ :class="isHorizontal ? 'w-px cursor-col-resize' : 'h-px cursor-row-resize'"
29
+ @pointerdown="onPointerDown"
30
+ @keydown="onKeydown"
31
+ @dblclick="reset"
32
+ >
33
+ <span
34
+ aria-hidden="true"
35
+ class="absolute bg-gray-200 transition-colors group-hover:bg-primary-400 group-focus-visible:bg-primary-500 group-data-[dragging=true]:bg-primary-500 dark:bg-gray-800 dark:group-hover:bg-primary-500"
36
+ :class="
37
+ isHorizontal
38
+ ? 'inset-y-0 left-0 w-px group-focus-visible:-left-px group-focus-visible:w-[3px]'
39
+ : 'inset-x-0 top-0 h-px group-focus-visible:-top-px group-focus-visible:h-[3px]'
40
+ "
41
+ />
42
+ <span
43
+ aria-hidden="true"
44
+ class="absolute"
45
+ :class="isHorizontal ? 'inset-y-0 -left-1.5 w-3' : 'inset-x-0 -top-1.5 h-3'"
46
+ />
47
+ </div>
48
+
49
+ <div class="relative min-h-0 min-w-0 flex-1 overflow-hidden">
50
+ <slot name="end" />
51
+ </div>
52
+ </div>
53
+ </template>
54
+
55
+ <script setup>
56
+ /**
57
+ * UiSplitPane — two panes divided by a draggable, keyboard-operable splitter.
58
+ *
59
+ * The `start` pane has an explicit size in pixels; the `end` pane takes the
60
+ * rest. Drag the splitter with a mouse, finger or pen, or focus it and use the
61
+ * arrow keys (Shift for bigger steps), Home and End for the limits, and Enter
62
+ * to toggle between the current size and `min`. Double-click resets to
63
+ * `defaultSize`.
64
+ *
65
+ * Follows the WAI-ARIA window splitter pattern: the splitter is a focusable
66
+ * `role="separator"` whose `aria-valuenow` is the start pane's size and whose
67
+ * `aria-controls` points at it, so assistive technology can report and change
68
+ * the split.
69
+ *
70
+ * Bind `v-model` to persist the size (for example to local storage); leave it
71
+ * unbound and the component keeps its own state. `update:modelValue` fires on
72
+ * every change while dragging, and `resize-end` once when a drag or key press
73
+ * finishes — persist on the latter to avoid a write per pixel.
74
+ *
75
+ * The component fills its parent (`h-full w-full`), so give the parent a
76
+ * size. Panes can nest: put a second `UiSplitPane` in `#end` for three columns.
77
+ *
78
+ * @example Message list beside a reader
79
+ * <UiSplitPane v-model="listWidth" :min="280" :max="640" label="Resize message list">
80
+ * <template #start><MessageList /></template>
81
+ * <template #end><MessageReader /></template>
82
+ * </UiSplitPane>
83
+ *
84
+ * @example Stacked
85
+ * <UiSplitPane direction="vertical" :default-size="240" label="Resize preview">
86
+ * <template #start>Top</template>
87
+ * <template #end>Bottom</template>
88
+ * </UiSplitPane>
89
+ *
90
+ * @emits {number} update:modelValue — The start pane's new size, in pixels.
91
+ * @emits {number} resize-end — A drag or keyboard adjustment finished, with the final size.
92
+ *
93
+ * @slot start — The sized pane. Scope: `{ size }`.
94
+ * @slot end — The flexible pane.
95
+ */
96
+ import { computed, onBeforeUnmount, onMounted, ref, useId } from 'vue'
97
+
98
+ const props = defineProps({
99
+ /**
100
+ * Size of the start pane in pixels, for `v-model`. Leave unset to let the
101
+ * component manage it from `defaultSize`.
102
+ * @type {number}
103
+ * @default undefined
104
+ */
105
+ modelValue: { type: Number, default: undefined },
106
+ /**
107
+ * Initial size in pixels when uncontrolled, and the size double-click resets to.
108
+ * @type {number}
109
+ * @default 320
110
+ */
111
+ defaultSize: { type: Number, default: 320 },
112
+ /**
113
+ * Smallest start pane size in pixels.
114
+ * @type {number}
115
+ * @default 160
116
+ */
117
+ min: { type: Number, default: 160 },
118
+ /**
119
+ * Largest start pane size in pixels. The pane is also never allowed to push
120
+ * the end pane below `endMin`.
121
+ * @type {number}
122
+ * @default 800
123
+ */
124
+ max: { type: Number, default: 800 },
125
+ /**
126
+ * Smallest size the end pane may be squeezed to, in pixels.
127
+ * @type {number}
128
+ * @default 240
129
+ */
130
+ endMin: { type: Number, default: 240 },
131
+ /**
132
+ * Layout direction. `horizontal` puts the panes side by side.
133
+ * @type {string}
134
+ * @default 'horizontal'
135
+ * @values 'horizontal' | 'vertical'
136
+ */
137
+ direction: { type: String, default: 'horizontal' },
138
+ /**
139
+ * Arrow-key step in pixels. Shift multiplies it by five.
140
+ * @type {number}
141
+ * @default 16
142
+ */
143
+ step: { type: Number, default: 16 },
144
+ /**
145
+ * Accessible name for the splitter.
146
+ * @type {string}
147
+ * @default 'Resize panes'
148
+ */
149
+ label: { type: String, default: 'Resize panes' },
150
+ })
151
+
152
+ const emit = defineEmits(['update:modelValue', 'resize-end'])
153
+
154
+ const startId = `${useId()}-start`
155
+ const rootRef = ref(null)
156
+ const isHorizontal = computed(() => props.direction !== 'vertical')
157
+
158
+ // ── Size state (controlled or uncontrolled) ──
159
+ const internalSize = ref(props.defaultSize)
160
+ const currentSize = computed(() => props.modelValue ?? internalSize.value)
161
+
162
+ // The container's extent along the split axis, so `max` can respect `endMin`.
163
+ const extent = ref(0)
164
+ const effectiveMax = computed(() => {
165
+ if (!extent.value) return props.max
166
+ return Math.max(props.min, Math.min(props.max, extent.value - props.endMin))
167
+ })
168
+
169
+ const clamp = (value) => Math.round(Math.min(effectiveMax.value, Math.max(props.min, value)))
170
+
171
+ const startStyle = computed(() => {
172
+ const size = `${clamp(currentSize.value)}px`
173
+ return isHorizontal.value ? { width: size } : { height: size }
174
+ })
175
+
176
+ function setSize(value) {
177
+ const next = clamp(value)
178
+ if (next === currentSize.value) return
179
+ internalSize.value = next
180
+ emit('update:modelValue', next)
181
+ }
182
+
183
+ const finish = () => emit('resize-end', clamp(currentSize.value))
184
+
185
+ // ── Pointer dragging ──
186
+ const dragging = ref(false)
187
+ let dragOrigin = 0
188
+ let sizeOrigin = 0
189
+
190
+ function onPointerDown(event) {
191
+ if (event.button !== 0) return
192
+ event.preventDefault()
193
+ event.currentTarget.setPointerCapture?.(event.pointerId)
194
+ event.currentTarget.focus({ preventScroll: true })
195
+ dragging.value = true
196
+ dragOrigin = isHorizontal.value ? event.clientX : event.clientY
197
+ sizeOrigin = clamp(currentSize.value)
198
+ event.currentTarget.addEventListener('pointermove', onPointerMove)
199
+ event.currentTarget.addEventListener('pointerup', onPointerUp, { once: true })
200
+ event.currentTarget.addEventListener('pointercancel', onPointerUp, { once: true })
201
+ }
202
+
203
+ function onPointerMove(event) {
204
+ if (!dragging.value) return
205
+ const position = isHorizontal.value ? event.clientX : event.clientY
206
+ setSize(sizeOrigin + position - dragOrigin)
207
+ }
208
+
209
+ function onPointerUp(event) {
210
+ event.currentTarget.removeEventListener('pointermove', onPointerMove)
211
+ event.currentTarget.removeEventListener('pointerup', onPointerUp)
212
+ event.currentTarget.removeEventListener('pointercancel', onPointerUp)
213
+ if (!dragging.value) return
214
+ dragging.value = false
215
+ finish()
216
+ }
217
+
218
+ // ── Keyboard ──
219
+ let sizeBeforeCollapse = null
220
+
221
+ function onKeydown(event) {
222
+ const decrease = isHorizontal.value ? 'ArrowLeft' : 'ArrowUp'
223
+ const increase = isHorizontal.value ? 'ArrowRight' : 'ArrowDown'
224
+ const amount = event.shiftKey ? props.step * 5 : props.step
225
+ const now = clamp(currentSize.value)
226
+ let next = null
227
+ if (event.key === decrease) next = now - amount
228
+ else if (event.key === increase) next = now + amount
229
+ else if (event.key === 'Home') next = props.min
230
+ else if (event.key === 'End') next = effectiveMax.value
231
+ else if (event.key === 'Enter') {
232
+ if (now > props.min) {
233
+ sizeBeforeCollapse = now
234
+ next = props.min
235
+ } else {
236
+ next = sizeBeforeCollapse ?? props.defaultSize
237
+ }
238
+ }
239
+ if (next === null) return
240
+ event.preventDefault()
241
+ setSize(next)
242
+ finish()
243
+ }
244
+
245
+ function reset() {
246
+ setSize(props.defaultSize)
247
+ finish()
248
+ }
249
+
250
+ // ── Track the container size ──
251
+ let observer = null
252
+ onMounted(() => {
253
+ const measure = () => {
254
+ const rect = rootRef.value?.getBoundingClientRect()
255
+ if (rect) extent.value = isHorizontal.value ? rect.width : rect.height
256
+ }
257
+ measure()
258
+ if (typeof ResizeObserver !== 'undefined' && rootRef.value) {
259
+ observer = new ResizeObserver(measure)
260
+ observer.observe(rootRef.value)
261
+ }
262
+ })
263
+ onBeforeUnmount(() => observer?.disconnect())
264
+ </script>
@@ -0,0 +1,165 @@
1
+ <template>
2
+ <UiCard padding="sm" :aria-busy="loading ? 'true' : undefined">
3
+ <div class="flex items-start justify-between gap-3">
4
+ <div class="min-w-0">
5
+ <p class="truncate text-sm font-medium text-gray-500 dark:text-gray-400">{{ label }}</p>
6
+ <p
7
+ class="mt-1 text-2xl font-semibold tracking-tight text-gray-900 tabular-nums dark:text-gray-50"
8
+ >
9
+ <span
10
+ v-if="loading"
11
+ class="inline-block h-7 w-16 animate-pulse rounded-md bg-gray-200 align-middle motion-reduce:animate-none dark:bg-gray-800"
12
+ aria-hidden="true"
13
+ />
14
+ <slot v-else name="value">{{ value }}</slot>
15
+ </p>
16
+ </div>
17
+ <span
18
+ v-if="icon"
19
+ class="inline-flex size-9 shrink-0 items-center justify-center rounded-xl"
20
+ :class="toneClass"
21
+ aria-hidden="true"
22
+ >
23
+ <UiIcon :name="icon" class="size-5" />
24
+ </span>
25
+ </div>
26
+
27
+ <div
28
+ v-if="hint || delta || $slots.default"
29
+ class="mt-3 flex flex-wrap items-center gap-2 text-xs"
30
+ >
31
+ <span v-if="delta" class="inline-flex items-center gap-1 font-medium" :class="deltaClass">
32
+ <UiIcon :name="trendIcon" class="size-3.5" />
33
+ {{ delta }}
34
+ </span>
35
+ <span v-if="hint" class="text-gray-500 dark:text-gray-400">{{ hint }}</span>
36
+ <slot />
37
+ </div>
38
+ </UiCard>
39
+ </template>
40
+
41
+ <script setup>
42
+ /**
43
+ * UiStatCard — a single headline number for dashboards: label, value, an
44
+ * optional tinted icon, a trend delta and a hint line.
45
+ *
46
+ * Built on `UiCard`, so external classes merge onto the card surface. While
47
+ * `loading`, the value is replaced by a pulsing placeholder of the same height
48
+ * so a grid of cards doesn't jump when data arrives.
49
+ *
50
+ * The delta's colour follows `trend` (up is green, down is red) unless
51
+ * `deltaColor` says otherwise — for metrics where going up is bad, such as
52
+ * error counts, pass `delta-color="red"` with `trend="up"`.
53
+ *
54
+ * @example
55
+ * <div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
56
+ * <UiStatCard label="Connections" :value="128" icon="mdi:lan-connect" />
57
+ * <UiStatCard label="Documents" value="4,210" icon="mdi:file-document-outline" color="success" />
58
+ * <UiStatCard label="Access denials" :value="3" trend="up" delta="+2" delta-color="red" hint="last hour" />
59
+ * </div>
60
+ *
61
+ * @slot value — Rich value content (overrides `value`).
62
+ * @slot default — Extra content in the footer line.
63
+ */
64
+ import { computed } from 'vue'
65
+ import UiCard from './Card.vue'
66
+ import UiIcon from '../icons/Icon.vue'
67
+
68
+ const props = defineProps({
69
+ /**
70
+ * What the number measures.
71
+ * @type {string}
72
+ * @default ''
73
+ */
74
+ label: { type: String, default: '' },
75
+
76
+ /**
77
+ * The number (or pre-formatted string).
78
+ * @type {string | number}
79
+ * @default ''
80
+ */
81
+ value: { type: [String, Number], default: '' },
82
+
83
+ /**
84
+ * Secondary line, such as a time window or a unit.
85
+ * @type {string}
86
+ * @default ''
87
+ */
88
+ hint: { type: String, default: '' },
89
+
90
+ /**
91
+ * MDI icon in a tinted tile.
92
+ * @type {string}
93
+ * @default ''
94
+ */
95
+ icon: { type: String, default: '' },
96
+
97
+ /**
98
+ * Icon tile tint.
99
+ * @type {string}
100
+ * @default 'primary'
101
+ * @values 'primary' | 'success' | 'warning' | 'error' | 'gray'
102
+ */
103
+ color: { type: String, default: 'primary' },
104
+
105
+ /**
106
+ * Change to show next to the hint, e.g. `'+12%'`. Empty hides it.
107
+ * @type {string}
108
+ * @default ''
109
+ */
110
+ delta: { type: String, default: '' },
111
+
112
+ /**
113
+ * Direction of the change, which picks the arrow.
114
+ * @type {string}
115
+ * @default 'flat'
116
+ * @values 'up' | 'down' | 'flat'
117
+ */
118
+ trend: { type: String, default: 'flat' },
119
+
120
+ /**
121
+ * Delta colour. `'auto'` makes up green and down red.
122
+ * @type {string}
123
+ * @default 'auto'
124
+ * @values 'auto' | 'green' | 'red' | 'gray'
125
+ */
126
+ deltaColor: { type: String, default: 'auto' },
127
+
128
+ /**
129
+ * Show a placeholder instead of the value.
130
+ * @type {boolean}
131
+ * @default false
132
+ */
133
+ loading: { type: Boolean, default: false },
134
+ })
135
+
136
+ const toneClass = computed(
137
+ () =>
138
+ ({
139
+ primary: 'bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300',
140
+ success: 'bg-success-50 text-success-700 dark:bg-success-400/10 dark:text-success-300',
141
+ warning: 'bg-warning-50 text-warning-700 dark:bg-warning-400/10 dark:text-warning-300',
142
+ error: 'bg-red-50 text-red-600 dark:bg-red-400/10 dark:text-red-300',
143
+ gray: 'bg-gray-100 text-gray-500 dark:bg-gray-800 dark:text-gray-400',
144
+ })[props.color] ??
145
+ 'bg-primary-50 text-primary-600 dark:bg-primary-400/10 dark:text-primary-300',
146
+ )
147
+
148
+ const trendIcon = computed(
149
+ () =>
150
+ ({ up: 'mdi:trending-up', down: 'mdi:trending-down' })[props.trend] ?? 'mdi:trending-neutral',
151
+ )
152
+
153
+ const deltaClass = computed(() => {
154
+ const tone =
155
+ props.deltaColor === 'auto'
156
+ ? { up: 'green', down: 'red' }[props.trend] || 'gray'
157
+ : props.deltaColor
158
+ return (
159
+ {
160
+ green: 'text-success-700 dark:text-success-400',
161
+ red: 'text-red-600 dark:text-red-400',
162
+ }[tone] ?? 'text-gray-500 dark:text-gray-400'
163
+ )
164
+ })
165
+ </script>
@@ -1,5 +1,8 @@
1
1
  <template>
2
- <div class="overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700">
2
+ <div
3
+ class="relative overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700"
4
+ :aria-busy="loading ? 'true' : undefined"
5
+ >
3
6
  <table class="w-full border-collapse text-sm">
4
7
  <caption
5
8
  v-if="caption || $slots.caption"
@@ -26,8 +29,27 @@
26
29
  : 'text-gray-600 dark:text-gray-300',
27
30
  col.width,
28
31
  ]"
32
+ :aria-sort="col.sortable ? ariaSort(col) : undefined"
29
33
  >
30
- <span v-if="col.label" :class="col.header && !col.label ? 'sr-only' : ''">{{
34
+ <button
35
+ v-if="col.sortable"
36
+ type="button"
37
+ class="group inline-flex items-center gap-1 rounded hover:text-gray-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:hover:text-gray-100"
38
+ :class="col.align === 'right' ? 'flex-row-reverse' : ''"
39
+ @click="toggleSort(col)"
40
+ >
41
+ <span>{{ col.label }}</span>
42
+ <UiIcon
43
+ :name="sortIcon(col)"
44
+ class="size-3.5 shrink-0"
45
+ :class="
46
+ sortKey === col.key
47
+ ? 'text-gray-700 dark:text-gray-200'
48
+ : 'text-gray-300 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-400'
49
+ "
50
+ />
51
+ </button>
52
+ <span v-else-if="col.label" :class="col.header && !col.label ? 'sr-only' : ''">{{
31
53
  col.label
32
54
  }}</span>
33
55
  </th>
@@ -35,10 +57,26 @@
35
57
  </thead>
36
58
 
37
59
  <tbody>
60
+ <tr v-if="rows.length === 0 && !loading">
61
+ <td
62
+ :colspan="columns.length"
63
+ class="px-5 py-10 text-center text-gray-500 dark:text-gray-400"
64
+ >
65
+ <slot name="empty">{{ emptyText }}</slot>
66
+ </td>
67
+ </tr>
38
68
  <tr
39
69
  v-for="(row, index) in rows"
40
70
  :key="row[rowKey] ?? index"
41
71
  class="border-b border-gray-100 transition-colors duration-200 last:border-0 hover:bg-gray-50 dark:border-gray-800 dark:hover:bg-gray-900/60"
72
+ :class="
73
+ clickableRows
74
+ ? 'cursor-pointer focus-visible:bg-gray-50 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:bg-gray-900/60'
75
+ : ''
76
+ "
77
+ :tabindex="clickableRows ? 0 : undefined"
78
+ @click="clickableRows && emit('row-click', row)"
79
+ @keydown.enter="clickableRows && emit('row-click', row)"
42
80
  >
43
81
  <template v-for="col in columns" :key="col.key">
44
82
  <!-- Header columns render as row headers (<th scope="row">), e.g. the
@@ -81,26 +119,50 @@
81
119
  </td>
82
120
  </template>
83
121
  </tr>
122
+ <tr v-if="loading && rows.length === 0">
123
+ <td :colspan="columns.length" class="px-5 py-10 text-center">
124
+ <UiIcon name="mdi:loading" class="inline size-5 animate-spin text-gray-400" />
125
+ <span class="sr-only">{{ loadingText }}</span>
126
+ </td>
127
+ </tr>
84
128
  </tbody>
85
129
  </table>
130
+
131
+ <!-- Refreshing existing rows: dim them rather than replacing them. -->
132
+ <div
133
+ v-if="loading && rows.length > 0"
134
+ class="absolute inset-0 flex items-center justify-center bg-white/60 dark:bg-gray-950/50"
135
+ >
136
+ <UiIcon name="mdi:loading" class="size-5 animate-spin text-gray-500" />
137
+ <span class="sr-only">{{ loadingText }}</span>
138
+ </div>
86
139
  </div>
87
140
  </template>
88
141
 
89
142
  <script setup>
90
143
  /**
91
- * UiTable — a data table with sensible defaults, and a built-in comparison mode.
144
+ * UiTable — a data table with sensible defaults, sortable columns, empty and
145
+ * loading states, and a built-in comparison mode.
92
146
  *
93
147
  * Drive it with `columns` and `rows`: each column names a `key`, and each row
94
148
  * is an object keyed by those column keys. It renders a real, accessible
95
149
  * `<table>` (`<caption>`, `scope="col"` headers) that scrolls horizontally on
96
150
  * narrow screens rather than crushing its columns.
97
151
  *
152
+ * **Sorting** is controlled: mark columns `sortable`, pass the current
153
+ * `sort-key` / `sort-direction`, and handle the `sort` event — the table does
154
+ * not reorder rows itself, so server-side and client-side sorting work the
155
+ * same way. Sorted headers carry `aria-sort`.
156
+ *
157
+ * **Empty and loading.** With no rows, `emptyText` (or the `#empty` slot) is
158
+ * shown. `loading` shows a spinner in place of the rows, or dims the existing
159
+ * rows while they refresh.
160
+ *
98
161
  * **Comparison** is just a configuration, not a separate component: mark the
99
162
  * label column `header: true` (so it renders as a `<th scope="row">`), give the
100
163
  * column you want to feature `highlight: true` (accent tint), and hand each
101
164
  * value column an `icon` (e.g. a tick for the highlighted column, a dash for
102
- * the others). That reproduces the "us vs. the usual" table without a bespoke
103
- * component. For full control of a cell, use the `#cell` scoped slot.
165
+ * the others). For full control of a cell, use the `#cell` scoped slot.
104
166
  *
105
167
  * @example A plain data table
106
168
  * <UiTable
@@ -116,7 +178,20 @@
116
178
  * ]"
117
179
  * />
118
180
  *
119
- * @example A comparison table (the old UiComparisonTable, now a configuration)
181
+ * @example Sortable, clickable rows
182
+ * <UiTable
183
+ * :columns="[{ key: 'id', label: 'Id', sortable: true }, { key: 'size', label: 'Size', align: 'right', sortable: true }]"
184
+ * :rows="docs"
185
+ * :sort-key="sort.key"
186
+ * :sort-direction="sort.direction"
187
+ * :loading="pending"
188
+ * empty-text="No documents stored yet"
189
+ * clickable-rows
190
+ * @sort="sort = $event"
191
+ * @row-click="open($event)"
192
+ * />
193
+ *
194
+ * @example A comparison table
120
195
  * <UiTable
121
196
  * caption="How Numori compares"
122
197
  * :columns="[
@@ -129,25 +204,19 @@
129
204
  * ]"
130
205
  * />
131
206
  *
132
- * @example Custom cell rendering
133
- * <UiTable :columns="cols" :rows="rows">
134
- * <template #cell="{ column, value }">
135
- * <UiBadge v-if="column.key === 'status'" :color="value === 'active' ? 'green' : 'gray'">
136
- * {{ value }}
137
- * </UiBadge>
138
- * <template v-else>{{ value }}</template>
139
- * </template>
140
- * </UiTable>
207
+ * @emits {{ key: string, direction: 'asc' | 'desc' }} sort — A sortable header was clicked.
208
+ * @emits {object} row-click — A row was clicked or activated with Enter (`clickableRows`).
141
209
  *
142
210
  * @slot caption — Rich caption content (overrides the `caption` prop).
143
211
  * @slot cell — Custom cell content. Scope: `{ row, column, value }`.
212
+ * @slot empty — Content shown when there are no rows.
144
213
  */
145
214
  import UiIcon from '../icons/Icon.vue'
146
215
 
147
- defineProps({
216
+ const props = defineProps({
148
217
  /**
149
218
  * Column definitions, left to right. Each is
150
- * `{ key, label?, align?, header?, highlight?, icon?, width? }`:
219
+ * `{ key, label?, align?, header?, highlight?, icon?, width?, sortable? }`:
151
220
  * - `key` — the row field this column reads.
152
221
  * - `label` — the column heading.
153
222
  * - `align` — `'left'` (default) | `'center'` | `'right'`.
@@ -155,7 +224,8 @@ defineProps({
155
224
  * - `highlight` — accent-tint the column (the featured column in a comparison).
156
225
  * - `icon` — MDI icon shown before each value in the column.
157
226
  * - `width` — optional width utility class, e.g. `'w-2/5'`.
158
- * @type {Array<{ key: string, label?: string, align?: string, header?: boolean, highlight?: boolean, icon?: string, width?: string }>}
227
+ * - `sortable` — make the heading a sort button.
228
+ * @type {Array<{ key: string, label?: string, align?: string, header?: boolean, highlight?: boolean, icon?: string, width?: string, sortable?: boolean }>}
159
229
  */
160
230
  columns: { type: Array, required: true },
161
231
 
@@ -186,8 +256,68 @@ defineProps({
186
256
  * @default 'key'
187
257
  */
188
258
  rowKey: { type: String, default: 'key' },
259
+
260
+ /**
261
+ * Key of the currently sorted column.
262
+ * @type {string}
263
+ * @default ''
264
+ */
265
+ sortKey: { type: String, default: '' },
266
+
267
+ /**
268
+ * Direction of the current sort.
269
+ * @type {string}
270
+ * @default 'asc'
271
+ * @values 'asc' | 'desc'
272
+ */
273
+ sortDirection: { type: String, default: 'asc' },
274
+
275
+ /**
276
+ * Show a loading state.
277
+ * @type {boolean}
278
+ * @default false
279
+ */
280
+ loading: { type: Boolean, default: false },
281
+
282
+ /**
283
+ * Text for screen readers while loading.
284
+ * @type {string}
285
+ * @default 'Loading'
286
+ */
287
+ loadingText: { type: String, default: 'Loading' },
288
+
289
+ /**
290
+ * Shown when `rows` is empty.
291
+ * @type {string}
292
+ * @default 'Nothing to show'
293
+ */
294
+ emptyText: { type: String, default: 'Nothing to show' },
295
+
296
+ /**
297
+ * Make rows focusable and emit `row-click` on click or Enter.
298
+ * @type {boolean}
299
+ * @default false
300
+ */
301
+ clickableRows: { type: Boolean, default: false },
189
302
  })
190
303
 
304
+ const emit = defineEmits(['sort', 'row-click'])
305
+
191
306
  const alignClass = (align) =>
192
307
  align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left'
308
+
309
+ const ariaSort = (col) =>
310
+ props.sortKey === col.key ? (props.sortDirection === 'desc' ? 'descending' : 'ascending') : 'none'
311
+
312
+ const sortIcon = (col) =>
313
+ props.sortKey !== col.key
314
+ ? 'mdi:unfold-more-horizontal'
315
+ : props.sortDirection === 'desc'
316
+ ? 'mdi:arrow-down'
317
+ : 'mdi:arrow-up'
318
+
319
+ function toggleSort(col) {
320
+ const direction = props.sortKey === col.key && props.sortDirection === 'asc' ? 'desc' : 'asc'
321
+ emit('sort', { key: col.key, direction })
322
+ }
193
323
  </script>