numori-ui 0.4.0 → 0.5.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 (72) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +18 -19
  3. package/dist/components/AppShell.js +234 -0
  4. package/dist/components/AppShell.js.map +1 -0
  5. package/dist/components/Checkbox.js +11 -2
  6. package/dist/components/Checkbox.js.map +1 -1
  7. package/dist/components/CopyField.js +195 -0
  8. package/dist/components/CopyField.js.map +1 -0
  9. package/dist/components/DescriptionList.js +116 -0
  10. package/dist/components/DescriptionList.js.map +1 -0
  11. package/dist/components/EmptyState.js +123 -0
  12. package/dist/components/EmptyState.js.map +1 -0
  13. package/dist/components/FormField.js +43 -13
  14. package/dist/components/FormField.js.map +1 -1
  15. package/dist/components/Input.js +15 -1
  16. package/dist/components/Input.js.map +1 -1
  17. package/dist/components/PageHeader.js +106 -0
  18. package/dist/components/PageHeader.js.map +1 -0
  19. package/dist/components/Pagination.js +236 -0
  20. package/dist/components/Pagination.js.map +1 -0
  21. package/dist/components/Segmented.js +10 -2
  22. package/dist/components/Segmented.js.map +1 -1
  23. package/dist/components/Select.js +10 -1
  24. package/dist/components/Select.js.map +1 -1
  25. package/dist/components/Sidebar.js +69 -0
  26. package/dist/components/Sidebar.js.map +1 -0
  27. package/dist/components/SidebarGroup.js +50 -0
  28. package/dist/components/SidebarGroup.js.map +1 -0
  29. package/dist/components/SidebarItem.js +167 -0
  30. package/dist/components/SidebarItem.js.map +1 -0
  31. package/dist/components/StatCard.js +185 -0
  32. package/dist/components/StatCard.js.map +1 -0
  33. package/dist/components/Table.js +182 -50
  34. package/dist/components/Table.js.map +1 -1
  35. package/dist/components/Tabs.js +216 -0
  36. package/dist/components/Tabs.js.map +1 -0
  37. package/dist/components/Toggle.js +11 -2
  38. package/dist/components/Toggle.js.map +1 -1
  39. package/dist/components/index.js +97 -80
  40. package/dist/components/index.js.map +1 -1
  41. package/dist/icons/mdi.js +10 -0
  42. package/dist/icons/mdi.js.map +1 -1
  43. package/dist/index.d.ts +12 -1
  44. package/dist/index.js +50 -39
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal/formField.js +26 -0
  47. package/dist/internal/formField.js.map +1 -0
  48. package/dist/manifest.js +11 -0
  49. package/dist/manifest.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/components/AppShell.vue +231 -0
  52. package/src/components/Checkbox.vue +5 -0
  53. package/src/components/CopyField.vue +178 -0
  54. package/src/components/DescriptionList.vue +114 -0
  55. package/src/components/EmptyState.vue +107 -0
  56. package/src/components/FormField.vue +37 -4
  57. package/src/components/Input.vue +9 -0
  58. package/src/components/PageHeader.vue +102 -0
  59. package/src/components/Pagination.vue +199 -0
  60. package/src/components/Segmented.vue +5 -0
  61. package/src/components/Select.vue +5 -0
  62. package/src/components/Sidebar.vue +61 -0
  63. package/src/components/SidebarGroup.vue +43 -0
  64. package/src/components/SidebarItem.vue +159 -0
  65. package/src/components/StatCard.vue +165 -0
  66. package/src/components/Table.vue +148 -18
  67. package/src/components/Tabs.vue +217 -0
  68. package/src/components/Toggle.vue +5 -0
  69. package/src/components/index.js +33 -5
  70. package/src/icons/mdi.js +10 -0
  71. package/src/internal/formField.js +23 -0
  72. package/src/manifest.js +11 -0
@@ -0,0 +1,159 @@
1
+ <template>
2
+ <component
3
+ :is="resolvedTag"
4
+ v-bind="{ ...linkAttrs, ...restAttrs }"
5
+ :class="mergedClasses"
6
+ :aria-current="active ? 'page' : undefined"
7
+ :aria-disabled="disabled ? 'true' : undefined"
8
+ @click="onClick"
9
+ >
10
+ <UiIcon
11
+ v-if="icon"
12
+ :name="icon"
13
+ class="size-[18px] shrink-0"
14
+ :class="
15
+ active
16
+ ? 'text-primary-600 dark:text-primary-400'
17
+ : 'text-gray-400 group-hover:text-gray-600 dark:text-gray-500 dark:group-hover:text-gray-300'
18
+ "
19
+ />
20
+ <span class="min-w-0 flex-1 truncate"><slot /></span>
21
+ <slot name="suffix">
22
+ <span
23
+ v-if="hasBadge"
24
+ class="ml-auto inline-flex min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold tabular-nums"
25
+ :class="
26
+ active
27
+ ? 'bg-primary-100 text-primary-700 dark:bg-primary-400/20 dark:text-primary-200'
28
+ : 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300'
29
+ "
30
+ >{{ badge }}</span
31
+ >
32
+ </slot>
33
+ </component>
34
+ </template>
35
+
36
+ <script setup>
37
+ /**
38
+ * UiSidebarItem — one navigation entry in a `UiSidebar`.
39
+ *
40
+ * Router-agnostic. Pass `to` to render through a globally registered
41
+ * `RouterLink` (or set `tag="NuxtLink"`), `href` for a plain anchor, or neither
42
+ * for a `<button>` that only emits `click`. The current page is marked with
43
+ * `active`, which also sets `aria-current="page"` — the item does not inspect
44
+ * the route itself, so any router (or none) works.
45
+ *
46
+ * Choosing an item inside a `UiAppShell` closes the shell's mobile drawer.
47
+ *
48
+ * @example With vue-router
49
+ * <UiSidebarItem icon="mdi:sync" to="/apps" :active="route.path.startsWith('/apps')">
50
+ * Apps
51
+ * </UiSidebarItem>
52
+ *
53
+ * @example With a count badge
54
+ * <UiSidebarItem icon="mdi:account-group" href="/users" :badge="3">Users</UiSidebarItem>
55
+ *
56
+ * @emits {MouseEvent} click — The item was chosen (not emitted while disabled).
57
+ *
58
+ * @slot default — Label.
59
+ * @slot suffix — Trailing content, replacing the badge.
60
+ */
61
+ import { computed, inject } from 'vue'
62
+ import UiIcon from '../icons/Icon.vue'
63
+ import { useMergedClasses } from '../composables/useMergedClasses.js'
64
+
65
+ const props = defineProps({
66
+ /**
67
+ * Element or component to render. Defaults to `RouterLink` when `to` is
68
+ * set, `a` when `href` is set, and `button` otherwise.
69
+ * @type {string}
70
+ * @default ''
71
+ */
72
+ tag: { type: String, default: '' },
73
+
74
+ /**
75
+ * Router location, passed to the link component.
76
+ * @type {string | object}
77
+ * @default undefined
78
+ */
79
+ to: { type: [String, Object], default: undefined },
80
+
81
+ /**
82
+ * Plain link target.
83
+ * @type {string}
84
+ * @default ''
85
+ */
86
+ href: { type: String, default: '' },
87
+
88
+ /**
89
+ * MDI icon shown before the label.
90
+ * @type {string}
91
+ * @default ''
92
+ */
93
+ icon: { type: String, default: '' },
94
+
95
+ /**
96
+ * Mark as the current page.
97
+ * @type {boolean}
98
+ * @default false
99
+ */
100
+ active: { type: Boolean, default: false },
101
+
102
+ /**
103
+ * Count or short label shown at the end of the row. Empty hides it.
104
+ * @type {string | number}
105
+ * @default ''
106
+ */
107
+ badge: { type: [String, Number], default: '' },
108
+
109
+ /**
110
+ * Dim the item and ignore clicks.
111
+ * @type {boolean}
112
+ * @default false
113
+ */
114
+ disabled: { type: Boolean, default: false },
115
+ })
116
+
117
+ const emit = defineEmits(['click'])
118
+
119
+ defineOptions({ inheritAttrs: false })
120
+
121
+ const shell = inject('numori-ui:app-shell', null)
122
+
123
+ const resolvedTag = computed(() => {
124
+ if (props.tag) return props.tag
125
+ if (props.to !== undefined) return 'RouterLink'
126
+ if (props.href) return 'a'
127
+ return 'button'
128
+ })
129
+
130
+ const linkAttrs = computed(() => {
131
+ if (resolvedTag.value === 'button') return { type: 'button', disabled: props.disabled }
132
+ if (resolvedTag.value === 'a') return { href: props.disabled ? undefined : props.href }
133
+ return { to: props.to }
134
+ })
135
+
136
+ const hasBadge = computed(() => props.badge !== '' && props.badge !== null)
137
+
138
+ function onClick(event) {
139
+ if (props.disabled) {
140
+ event.preventDefault()
141
+ return
142
+ }
143
+ emit('click', event)
144
+ shell?.close()
145
+ }
146
+
147
+ const internalClasses = computed(() =>
148
+ [
149
+ 'group flex w-full items-center gap-3 rounded-lg px-3 py-2 text-left text-sm font-medium transition-colors',
150
+ 'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 dark:focus-visible:outline-primary-400',
151
+ props.active
152
+ ? 'bg-primary-50 text-primary-700 dark:bg-primary-400/10 dark:text-primary-200'
153
+ : 'text-gray-700 hover:bg-gray-100 hover:text-gray-900 dark:text-gray-300 dark:hover:bg-gray-800 dark:hover:text-gray-100',
154
+ props.disabled ? 'pointer-events-none opacity-40' : 'cursor-pointer',
155
+ ].join(' '),
156
+ )
157
+
158
+ const { mergedClasses, restAttrs } = useMergedClasses(() => internalClasses.value)
159
+ </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>