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.
- package/CHANGELOG.md +66 -0
- package/README.md +18 -19
- package/dist/components/AppShell.js +234 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/Checkbox.js +11 -2
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/CopyField.js +195 -0
- package/dist/components/CopyField.js.map +1 -0
- package/dist/components/DescriptionList.js +116 -0
- package/dist/components/DescriptionList.js.map +1 -0
- package/dist/components/EmptyState.js +123 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormField.js +43 -13
- package/dist/components/FormField.js.map +1 -1
- package/dist/components/Input.js +15 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/PageHeader.js +106 -0
- package/dist/components/PageHeader.js.map +1 -0
- package/dist/components/Pagination.js +236 -0
- package/dist/components/Pagination.js.map +1 -0
- package/dist/components/Segmented.js +10 -2
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +10 -1
- package/dist/components/Select.js.map +1 -1
- package/dist/components/Sidebar.js +69 -0
- package/dist/components/Sidebar.js.map +1 -0
- package/dist/components/SidebarGroup.js +50 -0
- package/dist/components/SidebarGroup.js.map +1 -0
- package/dist/components/SidebarItem.js +167 -0
- package/dist/components/SidebarItem.js.map +1 -0
- package/dist/components/StatCard.js +185 -0
- package/dist/components/StatCard.js.map +1 -0
- package/dist/components/Table.js +182 -50
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Tabs.js +216 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Toggle.js +11 -2
- package/dist/components/Toggle.js.map +1 -1
- package/dist/components/index.js +97 -80
- package/dist/components/index.js.map +1 -1
- package/dist/icons/mdi.js +10 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +50 -39
- package/dist/index.js.map +1 -1
- package/dist/internal/formField.js +26 -0
- package/dist/internal/formField.js.map +1 -0
- package/dist/manifest.js +11 -0
- package/dist/manifest.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppShell.vue +231 -0
- package/src/components/Checkbox.vue +5 -0
- package/src/components/CopyField.vue +178 -0
- package/src/components/DescriptionList.vue +114 -0
- package/src/components/EmptyState.vue +107 -0
- package/src/components/FormField.vue +37 -4
- package/src/components/Input.vue +9 -0
- package/src/components/PageHeader.vue +102 -0
- package/src/components/Pagination.vue +199 -0
- package/src/components/Segmented.vue +5 -0
- package/src/components/Select.vue +5 -0
- package/src/components/Sidebar.vue +61 -0
- package/src/components/SidebarGroup.vue +43 -0
- package/src/components/SidebarItem.vue +159 -0
- package/src/components/StatCard.vue +165 -0
- package/src/components/Table.vue +148 -18
- package/src/components/Tabs.vue +217 -0
- package/src/components/Toggle.vue +5 -0
- package/src/components/index.js +33 -5
- package/src/icons/mdi.js +10 -0
- package/src/internal/formField.js +23 -0
- package/src/manifest.js +11 -0
package/dist/components/Table.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import _sfc_main$1 from "../icons/Icon.js";
|
|
2
|
-
import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, normalizeClass, openBlock, renderList, renderSlot, toDisplayString } from "vue";
|
|
2
|
+
import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, normalizeClass, openBlock, renderList, renderSlot, toDisplayString, withKeys } from "vue";
|
|
3
3
|
//#region src/components/Table.vue
|
|
4
|
-
var _hoisted_1 =
|
|
4
|
+
var _hoisted_1 = ["aria-busy"];
|
|
5
5
|
var _hoisted_2 = { class: "w-full border-collapse text-sm" };
|
|
6
6
|
var _hoisted_3 = { class: "border-b border-gray-200 dark:border-gray-700" };
|
|
7
|
+
var _hoisted_4 = ["aria-sort"];
|
|
8
|
+
var _hoisted_5 = ["onClick"];
|
|
9
|
+
var _hoisted_6 = { key: 0 };
|
|
10
|
+
var _hoisted_7 = ["colspan"];
|
|
11
|
+
var _hoisted_8 = [
|
|
12
|
+
"tabindex",
|
|
13
|
+
"onClick",
|
|
14
|
+
"onKeydown"
|
|
15
|
+
];
|
|
16
|
+
var _hoisted_9 = { key: 1 };
|
|
17
|
+
var _hoisted_10 = ["colspan"];
|
|
18
|
+
var _hoisted_11 = { class: "sr-only" };
|
|
19
|
+
var _hoisted_12 = {
|
|
20
|
+
key: 0,
|
|
21
|
+
class: "absolute inset-0 flex items-center justify-center bg-white/60 dark:bg-gray-950/50"
|
|
22
|
+
};
|
|
23
|
+
var _hoisted_13 = { class: "sr-only" };
|
|
7
24
|
var _sfc_main = {
|
|
8
25
|
__name: "Table",
|
|
9
26
|
props: {
|
|
10
27
|
/**
|
|
11
28
|
* Column definitions, left to right. Each is
|
|
12
|
-
* `{ key, label?, align?, header?, highlight?, icon?, width? }`:
|
|
29
|
+
* `{ key, label?, align?, header?, highlight?, icon?, width?, sortable? }`:
|
|
13
30
|
* - `key` — the row field this column reads.
|
|
14
31
|
* - `label` — the column heading.
|
|
15
32
|
* - `align` — `'left'` (default) | `'center'` | `'right'`.
|
|
@@ -17,7 +34,8 @@ var _sfc_main = {
|
|
|
17
34
|
* - `highlight` — accent-tint the column (the featured column in a comparison).
|
|
18
35
|
* - `icon` — MDI icon shown before each value in the column.
|
|
19
36
|
* - `width` — optional width utility class, e.g. `'w-2/5'`.
|
|
20
|
-
*
|
|
37
|
+
* - `sortable` — make the heading a sort button.
|
|
38
|
+
* @type {Array<{ key: string, label?: string, align?: string, header?: boolean, highlight?: boolean, icon?: string, width?: string, sortable?: boolean }>}
|
|
21
39
|
*/
|
|
22
40
|
columns: {
|
|
23
41
|
type: Array,
|
|
@@ -58,23 +76,88 @@ var _sfc_main = {
|
|
|
58
76
|
rowKey: {
|
|
59
77
|
type: String,
|
|
60
78
|
default: "key"
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Key of the currently sorted column.
|
|
82
|
+
* @type {string}
|
|
83
|
+
* @default ''
|
|
84
|
+
*/
|
|
85
|
+
sortKey: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: ""
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Direction of the current sort.
|
|
91
|
+
* @type {string}
|
|
92
|
+
* @default 'asc'
|
|
93
|
+
* @values 'asc' | 'desc'
|
|
94
|
+
*/
|
|
95
|
+
sortDirection: {
|
|
96
|
+
type: String,
|
|
97
|
+
default: "asc"
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Show a loading state.
|
|
101
|
+
* @type {boolean}
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
loading: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: false
|
|
107
|
+
},
|
|
108
|
+
/**
|
|
109
|
+
* Text for screen readers while loading.
|
|
110
|
+
* @type {string}
|
|
111
|
+
* @default 'Loading'
|
|
112
|
+
*/
|
|
113
|
+
loadingText: {
|
|
114
|
+
type: String,
|
|
115
|
+
default: "Loading"
|
|
116
|
+
},
|
|
117
|
+
/**
|
|
118
|
+
* Shown when `rows` is empty.
|
|
119
|
+
* @type {string}
|
|
120
|
+
* @default 'Nothing to show'
|
|
121
|
+
*/
|
|
122
|
+
emptyText: {
|
|
123
|
+
type: String,
|
|
124
|
+
default: "Nothing to show"
|
|
125
|
+
},
|
|
126
|
+
/**
|
|
127
|
+
* Make rows focusable and emit `row-click` on click or Enter.
|
|
128
|
+
* @type {boolean}
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
clickableRows: {
|
|
132
|
+
type: Boolean,
|
|
133
|
+
default: false
|
|
61
134
|
}
|
|
62
135
|
},
|
|
63
|
-
|
|
136
|
+
emits: ["sort", "row-click"],
|
|
137
|
+
setup(__props, { emit: __emit }) {
|
|
64
138
|
/**
|
|
65
|
-
* UiTable — a data table with sensible defaults,
|
|
139
|
+
* UiTable — a data table with sensible defaults, sortable columns, empty and
|
|
140
|
+
* loading states, and a built-in comparison mode.
|
|
66
141
|
*
|
|
67
142
|
* Drive it with `columns` and `rows`: each column names a `key`, and each row
|
|
68
143
|
* is an object keyed by those column keys. It renders a real, accessible
|
|
69
144
|
* `<table>` (`<caption>`, `scope="col"` headers) that scrolls horizontally on
|
|
70
145
|
* narrow screens rather than crushing its columns.
|
|
71
146
|
*
|
|
147
|
+
* **Sorting** is controlled: mark columns `sortable`, pass the current
|
|
148
|
+
* `sort-key` / `sort-direction`, and handle the `sort` event — the table does
|
|
149
|
+
* not reorder rows itself, so server-side and client-side sorting work the
|
|
150
|
+
* same way. Sorted headers carry `aria-sort`.
|
|
151
|
+
*
|
|
152
|
+
* **Empty and loading.** With no rows, `emptyText` (or the `#empty` slot) is
|
|
153
|
+
* shown. `loading` shows a spinner in place of the rows, or dims the existing
|
|
154
|
+
* rows while they refresh.
|
|
155
|
+
*
|
|
72
156
|
* **Comparison** is just a configuration, not a separate component: mark the
|
|
73
157
|
* label column `header: true` (so it renders as a `<th scope="row">`), give the
|
|
74
158
|
* column you want to feature `highlight: true` (accent tint), and hand each
|
|
75
159
|
* value column an `icon` (e.g. a tick for the highlighted column, a dash for
|
|
76
|
-
* the others).
|
|
77
|
-
* component. For full control of a cell, use the `#cell` scoped slot.
|
|
160
|
+
* the others). For full control of a cell, use the `#cell` scoped slot.
|
|
78
161
|
*
|
|
79
162
|
* @example A plain data table
|
|
80
163
|
* <UiTable
|
|
@@ -90,7 +173,20 @@ var _sfc_main = {
|
|
|
90
173
|
* ]"
|
|
91
174
|
* />
|
|
92
175
|
*
|
|
93
|
-
* @example
|
|
176
|
+
* @example Sortable, clickable rows
|
|
177
|
+
* <UiTable
|
|
178
|
+
* :columns="[{ key: 'id', label: 'Id', sortable: true }, { key: 'size', label: 'Size', align: 'right', sortable: true }]"
|
|
179
|
+
* :rows="docs"
|
|
180
|
+
* :sort-key="sort.key"
|
|
181
|
+
* :sort-direction="sort.direction"
|
|
182
|
+
* :loading="pending"
|
|
183
|
+
* empty-text="No documents stored yet"
|
|
184
|
+
* clickable-rows
|
|
185
|
+
* @sort="sort = $event"
|
|
186
|
+
* @row-click="open($event)"
|
|
187
|
+
* />
|
|
188
|
+
*
|
|
189
|
+
* @example A comparison table
|
|
94
190
|
* <UiTable
|
|
95
191
|
* caption="How Numori compares"
|
|
96
192
|
* :columns="[
|
|
@@ -103,22 +199,30 @@ var _sfc_main = {
|
|
|
103
199
|
* ]"
|
|
104
200
|
* />
|
|
105
201
|
*
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
108
|
-
* <template #cell="{ column, value }">
|
|
109
|
-
* <UiBadge v-if="column.key === 'status'" :color="value === 'active' ? 'green' : 'gray'">
|
|
110
|
-
* {{ value }}
|
|
111
|
-
* </UiBadge>
|
|
112
|
-
* <template v-else>{{ value }}</template>
|
|
113
|
-
* </template>
|
|
114
|
-
* </UiTable>
|
|
202
|
+
* @emits {{ key: string, direction: 'asc' | 'desc' }} sort — A sortable header was clicked.
|
|
203
|
+
* @emits {object} row-click — A row was clicked or activated with Enter (`clickableRows`).
|
|
115
204
|
*
|
|
116
205
|
* @slot caption — Rich caption content (overrides the `caption` prop).
|
|
117
206
|
* @slot cell — Custom cell content. Scope: `{ row, column, value }`.
|
|
207
|
+
* @slot empty — Content shown when there are no rows.
|
|
118
208
|
*/
|
|
209
|
+
const props = __props;
|
|
210
|
+
const emit = __emit;
|
|
119
211
|
const alignClass = (align) => align === "right" ? "text-right" : align === "center" ? "text-center" : "text-left";
|
|
212
|
+
const ariaSort = (col) => props.sortKey === col.key ? props.sortDirection === "desc" ? "descending" : "ascending" : "none";
|
|
213
|
+
const sortIcon = (col) => props.sortKey !== col.key ? "mdi:unfold-more-horizontal" : props.sortDirection === "desc" ? "mdi:arrow-down" : "mdi:arrow-up";
|
|
214
|
+
function toggleSort(col) {
|
|
215
|
+
const direction = props.sortKey === col.key && props.sortDirection === "asc" ? "desc" : "asc";
|
|
216
|
+
emit("sort", {
|
|
217
|
+
key: col.key,
|
|
218
|
+
direction
|
|
219
|
+
});
|
|
220
|
+
}
|
|
120
221
|
return (_ctx, _cache) => {
|
|
121
|
-
return openBlock(), createElementBlock("div",
|
|
222
|
+
return openBlock(), createElementBlock("div", {
|
|
223
|
+
class: "relative overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700",
|
|
224
|
+
"aria-busy": __props.loading ? "true" : void 0
|
|
225
|
+
}, [createElementVNode("table", _hoisted_2, [
|
|
122
226
|
__props.caption || _ctx.$slots.caption ? (openBlock(), createElementBlock("caption", {
|
|
123
227
|
key: 0,
|
|
124
228
|
class: normalizeClass(__props.hideCaption ? "sr-only" : "caption-top px-5 py-4 text-left text-sm font-semibold text-gray-900 dark:text-gray-100")
|
|
@@ -131,40 +235,68 @@ var _sfc_main = {
|
|
|
131
235
|
alignClass(col.align),
|
|
132
236
|
col.highlight ? "bg-primary-50 text-primary-800 dark:bg-primary-400/10 dark:text-primary-200" : "text-gray-600 dark:text-gray-300",
|
|
133
237
|
col.width
|
|
134
|
-
]])
|
|
135
|
-
|
|
238
|
+
]]),
|
|
239
|
+
"aria-sort": col.sortable ? ariaSort(col) : void 0
|
|
240
|
+
}, [col.sortable ? (openBlock(), createElementBlock("button", {
|
|
136
241
|
key: 0,
|
|
242
|
+
type: "button",
|
|
243
|
+
class: normalizeClass(["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", col.align === "right" ? "flex-row-reverse" : ""]),
|
|
244
|
+
onClick: ($event) => toggleSort(col)
|
|
245
|
+
}, [createElementVNode("span", null, toDisplayString(col.label), 1), createVNode(_sfc_main$1, {
|
|
246
|
+
name: sortIcon(col),
|
|
247
|
+
class: normalizeClass(["size-3.5 shrink-0", __props.sortKey === col.key ? "text-gray-700 dark:text-gray-200" : "text-gray-300 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-400"])
|
|
248
|
+
}, null, 8, ["name", "class"])], 10, _hoisted_5)) : col.label ? (openBlock(), createElementBlock("span", {
|
|
249
|
+
key: 1,
|
|
137
250
|
class: normalizeClass(col.header && !col.label ? "sr-only" : "")
|
|
138
|
-
}, toDisplayString(col.label), 3)) : createCommentVNode("", true)],
|
|
251
|
+
}, toDisplayString(col.label), 3)) : createCommentVNode("", true)], 10, _hoisted_4);
|
|
139
252
|
}), 128))])]),
|
|
140
|
-
createElementVNode("tbody", null, [
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
class: "
|
|
144
|
-
}, [(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
class: normalizeClass(["
|
|
149
|
-
|
|
150
|
-
row,
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
key:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
253
|
+
createElementVNode("tbody", null, [
|
|
254
|
+
__props.rows.length === 0 && !__props.loading ? (openBlock(), createElementBlock("tr", _hoisted_6, [createElementVNode("td", {
|
|
255
|
+
colspan: __props.columns.length,
|
|
256
|
+
class: "px-5 py-10 text-center text-gray-500 dark:text-gray-400"
|
|
257
|
+
}, [renderSlot(_ctx.$slots, "empty", {}, () => [createTextVNode(toDisplayString(__props.emptyText), 1)])], 8, _hoisted_7)])) : createCommentVNode("", true),
|
|
258
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(__props.rows, (row, index) => {
|
|
259
|
+
return openBlock(), createElementBlock("tr", {
|
|
260
|
+
key: row[__props.rowKey] ?? index,
|
|
261
|
+
class: normalizeClass(["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", __props.clickableRows ? "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" : ""]),
|
|
262
|
+
tabindex: __props.clickableRows ? 0 : void 0,
|
|
263
|
+
onClick: ($event) => __props.clickableRows && emit("row-click", row),
|
|
264
|
+
onKeydown: withKeys(($event) => __props.clickableRows && emit("row-click", row), ["enter"])
|
|
265
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.columns, (col) => {
|
|
266
|
+
return openBlock(), createElementBlock(Fragment, { key: col.key }, [col.header ? (openBlock(), createElementBlock("th", {
|
|
267
|
+
key: 0,
|
|
268
|
+
scope: "row",
|
|
269
|
+
class: normalizeClass(["px-5 py-4 font-medium text-gray-900 dark:text-gray-100", alignClass(col.align)])
|
|
270
|
+
}, [renderSlot(_ctx.$slots, "cell", {
|
|
271
|
+
row,
|
|
272
|
+
column: col,
|
|
273
|
+
value: row[col.key]
|
|
274
|
+
}, () => [createTextVNode(toDisplayString(row[col.key]), 1)])], 2)) : (openBlock(), createElementBlock("td", {
|
|
275
|
+
key: 1,
|
|
276
|
+
class: normalizeClass(["px-5 py-4", [alignClass(col.align), col.highlight ? "bg-primary-50/50 text-gray-700 dark:bg-primary-400/5 dark:text-gray-200" : "text-gray-600 dark:text-gray-400"]])
|
|
277
|
+
}, [renderSlot(_ctx.$slots, "cell", {
|
|
278
|
+
row,
|
|
279
|
+
column: col,
|
|
280
|
+
value: row[col.key]
|
|
281
|
+
}, () => [createElementVNode("span", { class: normalizeClass(col.icon ? "flex items-start gap-2" : "") }, [col.icon ? (openBlock(), createBlock(_sfc_main$1, {
|
|
282
|
+
key: 0,
|
|
283
|
+
name: col.icon,
|
|
284
|
+
class: normalizeClass(["mt-0.5 size-4 shrink-0", col.highlight ? "text-success-600 dark:text-success-400" : "text-gray-400 dark:text-gray-500"])
|
|
285
|
+
}, null, 8, ["name", "class"])) : createCommentVNode("", true), createTextVNode(" " + toDisplayString(row[col.key]), 1)], 2)])], 2))], 64);
|
|
286
|
+
}), 128))], 42, _hoisted_8);
|
|
287
|
+
}), 128)),
|
|
288
|
+
__props.loading && __props.rows.length === 0 ? (openBlock(), createElementBlock("tr", _hoisted_9, [createElementVNode("td", {
|
|
289
|
+
colspan: __props.columns.length,
|
|
290
|
+
class: "px-5 py-10 text-center"
|
|
291
|
+
}, [createVNode(_sfc_main$1, {
|
|
292
|
+
name: "mdi:loading",
|
|
293
|
+
class: "inline size-5 animate-spin text-gray-400"
|
|
294
|
+
}), createElementVNode("span", _hoisted_11, toDisplayString(__props.loadingText), 1)], 8, _hoisted_10)])) : createCommentVNode("", true)
|
|
295
|
+
])
|
|
296
|
+
]), __props.loading && __props.rows.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_12, [createVNode(_sfc_main$1, {
|
|
297
|
+
name: "mdi:loading",
|
|
298
|
+
class: "size-5 animate-spin text-gray-500"
|
|
299
|
+
}), createElementVNode("span", _hoisted_13, toDisplayString(__props.loadingText), 1)])) : createCommentVNode("", true)], 8, _hoisted_1);
|
|
168
300
|
};
|
|
169
301
|
}
|
|
170
302
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.js","names":["$slots"],"sources":["../../src/components/Table.vue"],"sourcesContent":["<template>\n <div class=\"overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700\">\n <table class=\"w-full border-collapse text-sm\">\n <caption\n v-if=\"caption || $slots.caption\"\n :class=\"\n hideCaption\n ? 'sr-only'\n : 'caption-top px-5 py-4 text-left text-sm font-semibold text-gray-900 dark:text-gray-100'\n \"\n >\n <slot name=\"caption\">{{ caption }}</slot>\n </caption>\n\n <thead>\n <tr class=\"border-b border-gray-200 dark:border-gray-700\">\n <th\n v-for=\"col in columns\"\n :key=\"col.key\"\n scope=\"col\"\n class=\"px-5 py-4 font-semibold\"\n :class=\"[\n alignClass(col.align),\n col.highlight\n ? 'bg-primary-50 text-primary-800 dark:bg-primary-400/10 dark:text-primary-200'\n : 'text-gray-600 dark:text-gray-300',\n col.width,\n ]\"\n >\n <span v-if=\"col.label\" :class=\"col.header && !col.label ? 'sr-only' : ''\">{{\n col.label\n }}</span>\n </th>\n </tr>\n </thead>\n\n <tbody>\n <tr\n v-for=\"(row, index) in rows\"\n :key=\"row[rowKey] ?? index\"\n 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\"\n >\n <template v-for=\"col in columns\" :key=\"col.key\">\n <!-- Header columns render as row headers (<th scope=\"row\">), e.g. the\n feature column of a comparison table. -->\n <th\n v-if=\"col.header\"\n scope=\"row\"\n class=\"px-5 py-4 font-medium text-gray-900 dark:text-gray-100\"\n :class=\"alignClass(col.align)\"\n >\n <slot name=\"cell\" :row=\"row\" :column=\"col\" :value=\"row[col.key]\">\n {{ row[col.key] }}\n </slot>\n </th>\n <td\n v-else\n class=\"px-5 py-4\"\n :class=\"[\n alignClass(col.align),\n col.highlight\n ? 'bg-primary-50/50 text-gray-700 dark:bg-primary-400/5 dark:text-gray-200'\n : 'text-gray-600 dark:text-gray-400',\n ]\"\n >\n <slot name=\"cell\" :row=\"row\" :column=\"col\" :value=\"row[col.key]\">\n <span :class=\"col.icon ? 'flex items-start gap-2' : ''\">\n <UiIcon\n v-if=\"col.icon\"\n :name=\"col.icon\"\n class=\"mt-0.5 size-4 shrink-0\"\n :class=\"\n col.highlight\n ? 'text-success-600 dark:text-success-400'\n : 'text-gray-400 dark:text-gray-500'\n \"\n />\n {{ row[col.key] }}\n </span>\n </slot>\n </td>\n </template>\n </tr>\n </tbody>\n </table>\n </div>\n</template>\n\n<script setup>\n/**\n * UiTable — a data table with sensible defaults, and a built-in comparison mode.\n *\n * Drive it with `columns` and `rows`: each column names a `key`, and each row\n * is an object keyed by those column keys. It renders a real, accessible\n * `<table>` (`<caption>`, `scope=\"col\"` headers) that scrolls horizontally on\n * narrow screens rather than crushing its columns.\n *\n * **Comparison** is just a configuration, not a separate component: mark the\n * label column `header: true` (so it renders as a `<th scope=\"row\">`), give the\n * column you want to feature `highlight: true` (accent tint), and hand each\n * value column an `icon` (e.g. a tick for the highlighted column, a dash for\n * the others). That reproduces the \"us vs. the usual\" table without a bespoke\n * component. For full control of a cell, use the `#cell` scoped slot.\n *\n * @example A plain data table\n * <UiTable\n * caption=\"Team\"\n * :columns=\"[\n * { key: 'name', label: 'Name' },\n * { key: 'role', label: 'Role' },\n * { key: 'commits', label: 'Commits', align: 'right' },\n * ]\"\n * :rows=\"[\n * { name: 'Ada Lovelace', role: 'Engineer', commits: 128 },\n * { name: 'Grace Hopper', role: 'Lead', commits: 342 },\n * ]\"\n * />\n *\n * @example A comparison table (the old UiComparisonTable, now a configuration)\n * <UiTable\n * caption=\"How Numori compares\"\n * :columns=\"[\n * { key: 'feature', label: 'Feature', header: true },\n * { key: 'numori', label: 'Numori', highlight: true, icon: 'mdi:check-circle' },\n * { key: 'usual', label: 'The usual', icon: 'mdi:minus-circle-outline' },\n * ]\"\n * :rows=\"[\n * { feature: 'Open source', numori: 'Entire ecosystem', usual: 'The client, sometimes' },\n * ]\"\n * />\n *\n * @example Custom cell rendering\n * <UiTable :columns=\"cols\" :rows=\"rows\">\n * <template #cell=\"{ column, value }\">\n * <UiBadge v-if=\"column.key === 'status'\" :color=\"value === 'active' ? 'green' : 'gray'\">\n * {{ value }}\n * </UiBadge>\n * <template v-else>{{ value }}</template>\n * </template>\n * </UiTable>\n *\n * @slot caption — Rich caption content (overrides the `caption` prop).\n * @slot cell — Custom cell content. Scope: `{ row, column, value }`.\n */\nimport UiIcon from '../icons/Icon.vue'\n\ndefineProps({\n /**\n * Column definitions, left to right. Each is\n * `{ key, label?, align?, header?, highlight?, icon?, width? }`:\n * - `key` — the row field this column reads.\n * - `label` — the column heading.\n * - `align` — `'left'` (default) | `'center'` | `'right'`.\n * - `header` — render this column's cells as row headers (`<th scope=\"row\">`).\n * - `highlight` — accent-tint the column (the featured column in a comparison).\n * - `icon` — MDI icon shown before each value in the column.\n * - `width` — optional width utility class, e.g. `'w-2/5'`.\n * @type {Array<{ key: string, label?: string, align?: string, header?: boolean, highlight?: boolean, icon?: string, width?: string }>}\n */\n columns: { type: Array, required: true },\n\n /**\n * Row objects, each keyed by the column `key`s.\n * @type {Array<Record<string, unknown>>}\n */\n rows: { type: Array, required: true },\n\n /**\n * Table caption. Rendered as a real `<caption>` for accessibility; visible by\n * default, or visually hidden with `hideCaption`.\n * @type {string}\n * @default ''\n */\n caption: { type: String, default: '' },\n\n /**\n * Keep the caption for assistive technology but hide it visually.\n * @type {boolean}\n * @default false\n */\n hideCaption: { type: Boolean, default: false },\n\n /**\n * Row field used as the `v-for` key; falls back to the row index.\n * @type {string}\n * @default 'key'\n */\n rowKey: { type: String, default: 'key' },\n})\n\nconst alignClass = (align) =>\n align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left'\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8LA,MAAM,cAAc,UAClB,UAAU,UAAU,eAAe,UAAU,WAAW,gBAAgB;;GA9LxE,OAAA,UAAA,GAAA,mBAoFM,OApFN,YAoFM,CAnFJ,mBAkFQ,SAlFR,YAkFQ;IAhFE,QAAA,WAAWA,KAAAA,OAAO,WAD1B,UAAA,GAAA,mBASU,WAAA;;KAPP,OAAK,eAAa,QAAA,cAAA,YAAA,wFAAA;IAMnB,GAAA,CAAA,WAAyC,KAAA,QAAA,WAAA,CAAA,SAAA,CAAjB,gBAAA,gBAAA,QAAA,OAAO,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,KAAA,mBAAA,IAAA,IAAA;IAGjC,mBAoBQ,SAAA,MAAA,CAnBN,mBAkBK,MAlBL,YAkBK,EAjBH,UAAA,IAAA,GAAA,mBAgBK,UAAA,MAAA,WAfW,QAAA,UAAP,QAAG;KADZ,OAAA,UAAA,GAAA,mBAgBK,MAAA;MAdF,KAAK,IAAI;MACV,OAAM;MACN,OA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,GAAA,CAEZ,IAAI,QADZ,UAAA,GAAA,YASE,aAAA;;OAPC,MAAM,IAAI;OACX,OAAK,eAAA,CAAC,0BACyB,IAAI,YAAA,2CAAA,kCAAA,CAAA;MAKnC,GAAA,MAAA,GAAA,CAAA,QAAA,OAAA,CAAA,KAAA,mBAAA,IAAA,IAAA,GAAA,gBAAA,MACF,gBAAG,IAAI,IAAI,IAAG,GAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,EAAA,GAAA,EAAA"}
|
|
1
|
+
{"version":3,"file":"Table.js","names":["$slots"],"sources":["../../src/components/Table.vue"],"sourcesContent":["<template>\n <div\n class=\"relative overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700\"\n :aria-busy=\"loading ? 'true' : undefined\"\n >\n <table class=\"w-full border-collapse text-sm\">\n <caption\n v-if=\"caption || $slots.caption\"\n :class=\"\n hideCaption\n ? 'sr-only'\n : 'caption-top px-5 py-4 text-left text-sm font-semibold text-gray-900 dark:text-gray-100'\n \"\n >\n <slot name=\"caption\">{{ caption }}</slot>\n </caption>\n\n <thead>\n <tr class=\"border-b border-gray-200 dark:border-gray-700\">\n <th\n v-for=\"col in columns\"\n :key=\"col.key\"\n scope=\"col\"\n class=\"px-5 py-4 font-semibold\"\n :class=\"[\n alignClass(col.align),\n col.highlight\n ? 'bg-primary-50 text-primary-800 dark:bg-primary-400/10 dark:text-primary-200'\n : 'text-gray-600 dark:text-gray-300',\n col.width,\n ]\"\n :aria-sort=\"col.sortable ? ariaSort(col) : undefined\"\n >\n <button\n v-if=\"col.sortable\"\n type=\"button\"\n 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\"\n :class=\"col.align === 'right' ? 'flex-row-reverse' : ''\"\n @click=\"toggleSort(col)\"\n >\n <span>{{ col.label }}</span>\n <UiIcon\n :name=\"sortIcon(col)\"\n class=\"size-3.5 shrink-0\"\n :class=\"\n sortKey === col.key\n ? 'text-gray-700 dark:text-gray-200'\n : 'text-gray-300 group-hover:text-gray-500 dark:text-gray-600 dark:group-hover:text-gray-400'\n \"\n />\n </button>\n <span v-else-if=\"col.label\" :class=\"col.header && !col.label ? 'sr-only' : ''\">{{\n col.label\n }}</span>\n </th>\n </tr>\n </thead>\n\n <tbody>\n <tr v-if=\"rows.length === 0 && !loading\">\n <td\n :colspan=\"columns.length\"\n class=\"px-5 py-10 text-center text-gray-500 dark:text-gray-400\"\n >\n <slot name=\"empty\">{{ emptyText }}</slot>\n </td>\n </tr>\n <tr\n v-for=\"(row, index) in rows\"\n :key=\"row[rowKey] ?? index\"\n 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\"\n :class=\"\n clickableRows\n ? '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'\n : ''\n \"\n :tabindex=\"clickableRows ? 0 : undefined\"\n @click=\"clickableRows && emit('row-click', row)\"\n @keydown.enter=\"clickableRows && emit('row-click', row)\"\n >\n <template v-for=\"col in columns\" :key=\"col.key\">\n <!-- Header columns render as row headers (<th scope=\"row\">), e.g. the\n feature column of a comparison table. -->\n <th\n v-if=\"col.header\"\n scope=\"row\"\n class=\"px-5 py-4 font-medium text-gray-900 dark:text-gray-100\"\n :class=\"alignClass(col.align)\"\n >\n <slot name=\"cell\" :row=\"row\" :column=\"col\" :value=\"row[col.key]\">\n {{ row[col.key] }}\n </slot>\n </th>\n <td\n v-else\n class=\"px-5 py-4\"\n :class=\"[\n alignClass(col.align),\n col.highlight\n ? 'bg-primary-50/50 text-gray-700 dark:bg-primary-400/5 dark:text-gray-200'\n : 'text-gray-600 dark:text-gray-400',\n ]\"\n >\n <slot name=\"cell\" :row=\"row\" :column=\"col\" :value=\"row[col.key]\">\n <span :class=\"col.icon ? 'flex items-start gap-2' : ''\">\n <UiIcon\n v-if=\"col.icon\"\n :name=\"col.icon\"\n class=\"mt-0.5 size-4 shrink-0\"\n :class=\"\n col.highlight\n ? 'text-success-600 dark:text-success-400'\n : 'text-gray-400 dark:text-gray-500'\n \"\n />\n {{ row[col.key] }}\n </span>\n </slot>\n </td>\n </template>\n </tr>\n <tr v-if=\"loading && rows.length === 0\">\n <td :colspan=\"columns.length\" class=\"px-5 py-10 text-center\">\n <UiIcon name=\"mdi:loading\" class=\"inline size-5 animate-spin text-gray-400\" />\n <span class=\"sr-only\">{{ loadingText }}</span>\n </td>\n </tr>\n </tbody>\n </table>\n\n <!-- Refreshing existing rows: dim them rather than replacing them. -->\n <div\n v-if=\"loading && rows.length > 0\"\n class=\"absolute inset-0 flex items-center justify-center bg-white/60 dark:bg-gray-950/50\"\n >\n <UiIcon name=\"mdi:loading\" class=\"size-5 animate-spin text-gray-500\" />\n <span class=\"sr-only\">{{ loadingText }}</span>\n </div>\n </div>\n</template>\n\n<script setup>\n/**\n * UiTable — a data table with sensible defaults, sortable columns, empty and\n * loading states, and a built-in comparison mode.\n *\n * Drive it with `columns` and `rows`: each column names a `key`, and each row\n * is an object keyed by those column keys. It renders a real, accessible\n * `<table>` (`<caption>`, `scope=\"col\"` headers) that scrolls horizontally on\n * narrow screens rather than crushing its columns.\n *\n * **Sorting** is controlled: mark columns `sortable`, pass the current\n * `sort-key` / `sort-direction`, and handle the `sort` event — the table does\n * not reorder rows itself, so server-side and client-side sorting work the\n * same way. Sorted headers carry `aria-sort`.\n *\n * **Empty and loading.** With no rows, `emptyText` (or the `#empty` slot) is\n * shown. `loading` shows a spinner in place of the rows, or dims the existing\n * rows while they refresh.\n *\n * **Comparison** is just a configuration, not a separate component: mark the\n * label column `header: true` (so it renders as a `<th scope=\"row\">`), give the\n * column you want to feature `highlight: true` (accent tint), and hand each\n * value column an `icon` (e.g. a tick for the highlighted column, a dash for\n * the others). For full control of a cell, use the `#cell` scoped slot.\n *\n * @example A plain data table\n * <UiTable\n * caption=\"Team\"\n * :columns=\"[\n * { key: 'name', label: 'Name' },\n * { key: 'role', label: 'Role' },\n * { key: 'commits', label: 'Commits', align: 'right' },\n * ]\"\n * :rows=\"[\n * { name: 'Ada Lovelace', role: 'Engineer', commits: 128 },\n * { name: 'Grace Hopper', role: 'Lead', commits: 342 },\n * ]\"\n * />\n *\n * @example Sortable, clickable rows\n * <UiTable\n * :columns=\"[{ key: 'id', label: 'Id', sortable: true }, { key: 'size', label: 'Size', align: 'right', sortable: true }]\"\n * :rows=\"docs\"\n * :sort-key=\"sort.key\"\n * :sort-direction=\"sort.direction\"\n * :loading=\"pending\"\n * empty-text=\"No documents stored yet\"\n * clickable-rows\n * @sort=\"sort = $event\"\n * @row-click=\"open($event)\"\n * />\n *\n * @example A comparison table\n * <UiTable\n * caption=\"How Numori compares\"\n * :columns=\"[\n * { key: 'feature', label: 'Feature', header: true },\n * { key: 'numori', label: 'Numori', highlight: true, icon: 'mdi:check-circle' },\n * { key: 'usual', label: 'The usual', icon: 'mdi:minus-circle-outline' },\n * ]\"\n * :rows=\"[\n * { feature: 'Open source', numori: 'Entire ecosystem', usual: 'The client, sometimes' },\n * ]\"\n * />\n *\n * @emits {{ key: string, direction: 'asc' | 'desc' }} sort — A sortable header was clicked.\n * @emits {object} row-click — A row was clicked or activated with Enter (`clickableRows`).\n *\n * @slot caption — Rich caption content (overrides the `caption` prop).\n * @slot cell — Custom cell content. Scope: `{ row, column, value }`.\n * @slot empty — Content shown when there are no rows.\n */\nimport UiIcon from '../icons/Icon.vue'\n\nconst props = defineProps({\n /**\n * Column definitions, left to right. Each is\n * `{ key, label?, align?, header?, highlight?, icon?, width?, sortable? }`:\n * - `key` — the row field this column reads.\n * - `label` — the column heading.\n * - `align` — `'left'` (default) | `'center'` | `'right'`.\n * - `header` — render this column's cells as row headers (`<th scope=\"row\">`).\n * - `highlight` — accent-tint the column (the featured column in a comparison).\n * - `icon` — MDI icon shown before each value in the column.\n * - `width` — optional width utility class, e.g. `'w-2/5'`.\n * - `sortable` — make the heading a sort button.\n * @type {Array<{ key: string, label?: string, align?: string, header?: boolean, highlight?: boolean, icon?: string, width?: string, sortable?: boolean }>}\n */\n columns: { type: Array, required: true },\n\n /**\n * Row objects, each keyed by the column `key`s.\n * @type {Array<Record<string, unknown>>}\n */\n rows: { type: Array, required: true },\n\n /**\n * Table caption. Rendered as a real `<caption>` for accessibility; visible by\n * default, or visually hidden with `hideCaption`.\n * @type {string}\n * @default ''\n */\n caption: { type: String, default: '' },\n\n /**\n * Keep the caption for assistive technology but hide it visually.\n * @type {boolean}\n * @default false\n */\n hideCaption: { type: Boolean, default: false },\n\n /**\n * Row field used as the `v-for` key; falls back to the row index.\n * @type {string}\n * @default 'key'\n */\n rowKey: { type: String, default: 'key' },\n\n /**\n * Key of the currently sorted column.\n * @type {string}\n * @default ''\n */\n sortKey: { type: String, default: '' },\n\n /**\n * Direction of the current sort.\n * @type {string}\n * @default 'asc'\n * @values 'asc' | 'desc'\n */\n sortDirection: { type: String, default: 'asc' },\n\n /**\n * Show a loading state.\n * @type {boolean}\n * @default false\n */\n loading: { type: Boolean, default: false },\n\n /**\n * Text for screen readers while loading.\n * @type {string}\n * @default 'Loading'\n */\n loadingText: { type: String, default: 'Loading' },\n\n /**\n * Shown when `rows` is empty.\n * @type {string}\n * @default 'Nothing to show'\n */\n emptyText: { type: String, default: 'Nothing to show' },\n\n /**\n * Make rows focusable and emit `row-click` on click or Enter.\n * @type {boolean}\n * @default false\n */\n clickableRows: { type: Boolean, default: false },\n})\n\nconst emit = defineEmits(['sort', 'row-click'])\n\nconst alignClass = (align) =>\n align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left'\n\nconst ariaSort = (col) =>\n props.sortKey === col.key ? (props.sortDirection === 'desc' ? 'descending' : 'ascending') : 'none'\n\nconst sortIcon = (col) =>\n props.sortKey !== col.key\n ? 'mdi:unfold-more-horizontal'\n : props.sortDirection === 'desc'\n ? 'mdi:arrow-down'\n : 'mdi:arrow-up'\n\nfunction toggleSort(col) {\n const direction = props.sortKey === col.key && props.sortDirection === 'asc' ? 'desc' : 'asc'\n emit('sort', { key: col.key, direction })\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuNA,MAAM,QAAQ;EAwFd,MAAM,OAAO;EAEb,MAAM,cAAc,UAClB,UAAU,UAAU,eAAe,UAAU,WAAW,gBAAgB;EAE1E,MAAM,YAAY,QAChB,MAAM,YAAY,IAAI,MAAO,MAAM,kBAAkB,SAAS,eAAe,cAAe;EAE9F,MAAM,YAAY,QAChB,MAAM,YAAY,IAAI,MAClB,+BACA,MAAM,kBAAkB,SACtB,mBACA;EAER,SAAS,WAAW,KAAK;GACvB,MAAM,YAAY,MAAM,YAAY,IAAI,OAAO,MAAM,kBAAkB,QAAQ,SAAS;GACxF,KAAK,QAAQ;IAAE,KAAK,IAAI;IAAK;GAAU,CAAC;EAC1C;;GAhUE,OAAA,UAAA,GAAA,mBAyIM,OAAA;IAxIJ,OAAM;IACL,aAAW,QAAA,UAAO,SAAY,KAAA;GAE/B,GAAA,CAAA,mBA2HQ,SA3HR,YA2HQ;IAzHE,QAAA,WAAWA,KAAAA,OAAO,WAD1B,UAAA,GAAA,mBASU,WAAA;;KAPP,OAAK,eAAa,QAAA,cAAA,YAAA,wFAAA;IAMnB,GAAA,CAAA,WAAyC,KAAA,QAAA,WAAA,CAAA,SAAA,CAAjB,gBAAA,gBAAA,QAAA,OAAO,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,KAAA,mBAAA,IAAA,IAAA;IAGjC,mBAuCQ,SAAA,MAAA,C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QAPC,MAAM,IAAI;QACX,OAAK,eAAA,CAAC,0BACyB,IAAI,YAAA,2CAAA,kCAAA,CAAA;OAKnC,GAAA,MAAA,GAAA,CAAA,QAAA,OAAA,CAAA,KAAA,mBAAA,IAAA,IAAA,GAAA,gBAAA,MACF,gBAAG,IAAI,IAAI,IAAG,GAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,EAAA,GAAA,EAAA;;;KAMd,QAAA,WAAW,QAAA,KAAK,WAAM,KAAhC,UAAA,GAAA,mBAKK,MAAA,YAAA,CAJH,mBAGK,MAAA;MAHA,SAAS,QAAA,QAAQ;MAAQ,OAAM;KAClC,GAAA,CAAA,YAA8E,aAAA;MAAtE,MAAK;MAAc,OAAM;KACjC,CAAA,GAAA,mBAA8C,QAA9C,aAA8C,gBAArB,QAAA,WAAW,GAAA,CAAA,CAAA,GAAA,GAAA,WAAA,CAAA,CAAA,KAAA,mBAAA,IAAA,IAAA;;GAQpC,CAAA,GAAA,QAAA,WAAW,QAAA,KAAK,SAAM,KAD9B,UAAA,GAAA,mBAMM,OANN,aAMM,CAFJ,YAAuE,aAAA;IAA/D,MAAK;IAAc,OAAM;GACjC,CAAA,GAAA,mBAA8C,QAA9C,aAA8C,gBAArB,QAAA,WAAW,GAAA,CAAA,CAAA,CAAA,KAAA,mBAAA,IAAA,IAAA,CAAA,GAAA,GAAA,UAAA"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import _sfc_main$1 from "../icons/Icon.js";
|
|
2
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, nextTick, normalizeClass, openBlock, renderList, renderSlot, toDisplayString, useId } from "vue";
|
|
3
|
+
//#region src/components/Tabs.vue
|
|
4
|
+
var _hoisted_1 = ["aria-label"];
|
|
5
|
+
var _hoisted_2 = [
|
|
6
|
+
"id",
|
|
7
|
+
"aria-selected",
|
|
8
|
+
"aria-controls",
|
|
9
|
+
"tabindex",
|
|
10
|
+
"disabled",
|
|
11
|
+
"onClick"
|
|
12
|
+
];
|
|
13
|
+
var _hoisted_3 = ["aria-labelledby"];
|
|
14
|
+
var _sfc_main = {
|
|
15
|
+
__name: "Tabs",
|
|
16
|
+
props: {
|
|
17
|
+
/**
|
|
18
|
+
* Value of the active tab.
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @default ''
|
|
21
|
+
*/
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: ""
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Tabs, left to right. Each is `{ value, label, icon?, badge?, disabled? }`.
|
|
28
|
+
* @type {Array<{ value: string, label: string, icon?: string, badge?: string | number, disabled?: boolean }>}
|
|
29
|
+
*/
|
|
30
|
+
tabs: {
|
|
31
|
+
type: Array,
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Accessible name of the tab list.
|
|
36
|
+
* @type {string}
|
|
37
|
+
* @default ''
|
|
38
|
+
*/
|
|
39
|
+
ariaLabel: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: ""
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Visual style.
|
|
45
|
+
* @type {string}
|
|
46
|
+
* @default 'line'
|
|
47
|
+
* @values 'line' | 'pill'
|
|
48
|
+
*/
|
|
49
|
+
variant: {
|
|
50
|
+
type: String,
|
|
51
|
+
default: "line"
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* Render a `tabpanel` holding the default slot. Turn off when the tabs only
|
|
55
|
+
* navigate and the content is rendered elsewhere.
|
|
56
|
+
* @type {boolean}
|
|
57
|
+
* @default true
|
|
58
|
+
*/
|
|
59
|
+
panel: {
|
|
60
|
+
type: Boolean,
|
|
61
|
+
default: true
|
|
62
|
+
},
|
|
63
|
+
/**
|
|
64
|
+
* Classes for the panel.
|
|
65
|
+
* @type {string}
|
|
66
|
+
* @default 'pt-6'
|
|
67
|
+
*/
|
|
68
|
+
panelClass: {
|
|
69
|
+
type: String,
|
|
70
|
+
default: "pt-6"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
emits: ["update:modelValue"],
|
|
74
|
+
setup(__props, { emit: __emit }) {
|
|
75
|
+
/**
|
|
76
|
+
* UiTabs — an accessible tab list, with an optional panel for the active tab.
|
|
77
|
+
*
|
|
78
|
+
* Implements the WAI-ARIA tabs pattern: `role="tablist"` / `"tab"` /
|
|
79
|
+
* `"tabpanel"`, a single tab stop (roving `tabindex`), and arrow keys, Home and
|
|
80
|
+
* End to move between tabs. Moving with the keyboard selects the tab
|
|
81
|
+
* (automatic activation), skipping disabled tabs.
|
|
82
|
+
*
|
|
83
|
+
* Render the panel through the default slot, which receives the active value.
|
|
84
|
+
* When the content lives elsewhere — a routed `<RouterView>` below the tabs,
|
|
85
|
+
* say — set `:panel="false"` and use the tabs as navigation only.
|
|
86
|
+
*
|
|
87
|
+
* Two looks: `line` (an underline under the active tab, for page sections) and
|
|
88
|
+
* `pill` (a segmented track, for compact switches inside cards).
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* <UiTabs
|
|
92
|
+
* v-model="tab"
|
|
93
|
+
* aria-label="App sections"
|
|
94
|
+
* :tabs="[
|
|
95
|
+
* { value: 'overview', label: 'Overview', icon: 'mdi:view-grid' },
|
|
96
|
+
* { value: 'keys', label: 'Keys', badge: 2 },
|
|
97
|
+
* { value: 'danger', label: 'Danger zone' },
|
|
98
|
+
* ]"
|
|
99
|
+
* >
|
|
100
|
+
* <template #default="{ active }">
|
|
101
|
+
* <OverviewPanel v-if="active === 'overview'" />
|
|
102
|
+
* <KeysPanel v-else-if="active === 'keys'" />
|
|
103
|
+
* </template>
|
|
104
|
+
* </UiTabs>
|
|
105
|
+
*
|
|
106
|
+
* @emits {string} update:modelValue — The selected tab's value.
|
|
107
|
+
*
|
|
108
|
+
* @slot default — Panel content. Scope: `{ active }`.
|
|
109
|
+
*/
|
|
110
|
+
const props = __props;
|
|
111
|
+
const emit = __emit;
|
|
112
|
+
const baseId = useId();
|
|
113
|
+
const panelId = `${baseId}-panel`;
|
|
114
|
+
const tabId = (index) => `${baseId}-tab-${index}`;
|
|
115
|
+
/** Template refs, written by the function ref on each button. */
|
|
116
|
+
const tabEls = [];
|
|
117
|
+
const activeIndex = computed(() => props.tabs.findIndex((t) => t.value === props.modelValue));
|
|
118
|
+
/** The tab that holds the single tab stop: the active one, else the first enabled. */
|
|
119
|
+
const focusIndex = computed(() => {
|
|
120
|
+
if (activeIndex.value >= 0 && !props.tabs[activeIndex.value].disabled) return activeIndex.value;
|
|
121
|
+
return props.tabs.findIndex((t) => !t.disabled);
|
|
122
|
+
});
|
|
123
|
+
function select(index) {
|
|
124
|
+
const tab = props.tabs[index];
|
|
125
|
+
if (!tab || tab.disabled) return;
|
|
126
|
+
if (tab.value !== props.modelValue) emit("update:modelValue", tab.value);
|
|
127
|
+
}
|
|
128
|
+
function step(from, delta) {
|
|
129
|
+
const count = props.tabs.length;
|
|
130
|
+
for (let i = 1; i <= count; i++) {
|
|
131
|
+
const next = (from + delta * i + count * i) % count;
|
|
132
|
+
if (!props.tabs[next].disabled) return next;
|
|
133
|
+
}
|
|
134
|
+
return from;
|
|
135
|
+
}
|
|
136
|
+
function onKeydown(event) {
|
|
137
|
+
const current = tabEls.indexOf(event.target);
|
|
138
|
+
if (current < 0) return;
|
|
139
|
+
let next = null;
|
|
140
|
+
if (event.key === "ArrowRight" || event.key === "ArrowDown") next = step(current, 1);
|
|
141
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowUp") next = step(current, -1);
|
|
142
|
+
else if (event.key === "Home") next = props.tabs.findIndex((t) => !t.disabled);
|
|
143
|
+
else if (event.key === "End") {
|
|
144
|
+
for (let i = props.tabs.length - 1; i >= 0; i--) if (!props.tabs[i].disabled) {
|
|
145
|
+
next = i;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (next === null || next < 0) return;
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
select(next);
|
|
152
|
+
nextTick(() => tabEls[next]?.focus());
|
|
153
|
+
}
|
|
154
|
+
const listClass = computed(() => props.variant === "pill" ? "inline-flex max-w-full gap-1 overflow-x-auto rounded-xl bg-gray-100 p-1 dark:bg-gray-800" : "flex gap-6 overflow-x-auto border-b border-gray-200 dark:border-gray-800");
|
|
155
|
+
function tabClass(index, tab) {
|
|
156
|
+
const active = index === activeIndex.value;
|
|
157
|
+
const base = "inline-flex shrink-0 items-center gap-2 text-sm font-medium whitespace-nowrap transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 disabled:cursor-not-allowed disabled:opacity-40";
|
|
158
|
+
if (props.variant === "pill") return [
|
|
159
|
+
base,
|
|
160
|
+
"rounded-lg px-3 py-1.5",
|
|
161
|
+
active ? "bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100" : "text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100"
|
|
162
|
+
];
|
|
163
|
+
return [
|
|
164
|
+
base,
|
|
165
|
+
"-mb-px border-b-2 px-1 py-3",
|
|
166
|
+
active ? "border-primary-500 text-primary-600 dark:border-primary-400 dark:text-primary-300" : "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-800 dark:text-gray-400 dark:hover:border-gray-600 dark:hover:text-gray-200",
|
|
167
|
+
tab.disabled ? "hover:border-transparent" : ""
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
return (_ctx, _cache) => {
|
|
171
|
+
return openBlock(), createElementBlock("div", null, [createElementVNode("div", {
|
|
172
|
+
role: "tablist",
|
|
173
|
+
"aria-label": __props.ariaLabel || void 0,
|
|
174
|
+
class: normalizeClass(listClass.value),
|
|
175
|
+
onKeydown
|
|
176
|
+
}, [(openBlock(true), createElementBlock(Fragment, null, renderList(__props.tabs, (tab, index) => {
|
|
177
|
+
return openBlock(), createElementBlock("button", {
|
|
178
|
+
id: tabId(index),
|
|
179
|
+
key: tab.value,
|
|
180
|
+
ref_for: true,
|
|
181
|
+
ref: (el) => tabEls[index] = el,
|
|
182
|
+
type: "button",
|
|
183
|
+
role: "tab",
|
|
184
|
+
"aria-selected": index === activeIndex.value ? "true" : "false",
|
|
185
|
+
"aria-controls": __props.panel ? panelId : void 0,
|
|
186
|
+
tabindex: index === focusIndex.value ? 0 : -1,
|
|
187
|
+
disabled: tab.disabled,
|
|
188
|
+
class: normalizeClass(tabClass(index, tab)),
|
|
189
|
+
onClick: ($event) => select(index)
|
|
190
|
+
}, [
|
|
191
|
+
tab.icon ? (openBlock(), createBlock(_sfc_main$1, {
|
|
192
|
+
key: 0,
|
|
193
|
+
name: tab.icon,
|
|
194
|
+
class: "size-4 shrink-0"
|
|
195
|
+
}, null, 8, ["name"])) : createCommentVNode("", true),
|
|
196
|
+
createElementVNode("span", null, toDisplayString(tab.label), 1),
|
|
197
|
+
tab.badge !== void 0 && tab.badge !== null && tab.badge !== "" ? (openBlock(), createElementBlock("span", {
|
|
198
|
+
key: 1,
|
|
199
|
+
class: normalizeClass(["inline-flex min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold tabular-nums", index === activeIndex.value ? "bg-primary-100 text-primary-700 dark:bg-primary-400/20 dark:text-primary-200" : "bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300"])
|
|
200
|
+
}, toDisplayString(tab.badge), 3)) : createCommentVNode("", true)
|
|
201
|
+
], 10, _hoisted_2);
|
|
202
|
+
}), 128))], 42, _hoisted_1), __props.panel ? (openBlock(), createElementBlock("div", {
|
|
203
|
+
key: 0,
|
|
204
|
+
id: panelId,
|
|
205
|
+
role: "tabpanel",
|
|
206
|
+
"aria-labelledby": activeIndex.value >= 0 ? tabId(activeIndex.value) : void 0,
|
|
207
|
+
tabindex: "0",
|
|
208
|
+
class: normalizeClass(["focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary-500", __props.panelClass])
|
|
209
|
+
}, [renderSlot(_ctx.$slots, "default", { active: __props.modelValue })], 10, _hoisted_3)) : createCommentVNode("", true)]);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
//#endregion
|
|
214
|
+
export { _sfc_main as default };
|
|
215
|
+
|
|
216
|
+
//# sourceMappingURL=Tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tabs.js","names":[],"sources":["../../src/components/Tabs.vue"],"sourcesContent":["<template>\n <div>\n <div\n role=\"tablist\"\n :aria-label=\"ariaLabel || undefined\"\n :class=\"listClass\"\n @keydown=\"onKeydown\"\n >\n <button\n v-for=\"(tab, index) in tabs\"\n :id=\"tabId(index)\"\n :key=\"tab.value\"\n :ref=\"(el) => (tabEls[index] = el)\"\n type=\"button\"\n role=\"tab\"\n :aria-selected=\"index === activeIndex ? 'true' : 'false'\"\n :aria-controls=\"panel ? panelId : undefined\"\n :tabindex=\"index === focusIndex ? 0 : -1\"\n :disabled=\"tab.disabled\"\n :class=\"tabClass(index, tab)\"\n @click=\"select(index)\"\n >\n <UiIcon v-if=\"tab.icon\" :name=\"tab.icon\" class=\"size-4 shrink-0\" />\n <span>{{ tab.label }}</span>\n <span\n v-if=\"tab.badge !== undefined && tab.badge !== null && tab.badge !== ''\"\n class=\"inline-flex min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold tabular-nums\"\n :class=\"\n index === activeIndex\n ? 'bg-primary-100 text-primary-700 dark:bg-primary-400/20 dark:text-primary-200'\n : 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300'\n \"\n >{{ tab.badge }}</span\n >\n </button>\n </div>\n\n <div\n v-if=\"panel\"\n :id=\"panelId\"\n role=\"tabpanel\"\n :aria-labelledby=\"activeIndex >= 0 ? tabId(activeIndex) : undefined\"\n tabindex=\"0\"\n class=\"focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary-500\"\n :class=\"panelClass\"\n >\n <slot :active=\"modelValue\" />\n </div>\n </div>\n</template>\n\n<script setup>\n/**\n * UiTabs — an accessible tab list, with an optional panel for the active tab.\n *\n * Implements the WAI-ARIA tabs pattern: `role=\"tablist\"` / `\"tab\"` /\n * `\"tabpanel\"`, a single tab stop (roving `tabindex`), and arrow keys, Home and\n * End to move between tabs. Moving with the keyboard selects the tab\n * (automatic activation), skipping disabled tabs.\n *\n * Render the panel through the default slot, which receives the active value.\n * When the content lives elsewhere — a routed `<RouterView>` below the tabs,\n * say — set `:panel=\"false\"` and use the tabs as navigation only.\n *\n * Two looks: `line` (an underline under the active tab, for page sections) and\n * `pill` (a segmented track, for compact switches inside cards).\n *\n * @example\n * <UiTabs\n * v-model=\"tab\"\n * aria-label=\"App sections\"\n * :tabs=\"[\n * { value: 'overview', label: 'Overview', icon: 'mdi:view-grid' },\n * { value: 'keys', label: 'Keys', badge: 2 },\n * { value: 'danger', label: 'Danger zone' },\n * ]\"\n * >\n * <template #default=\"{ active }\">\n * <OverviewPanel v-if=\"active === 'overview'\" />\n * <KeysPanel v-else-if=\"active === 'keys'\" />\n * </template>\n * </UiTabs>\n *\n * @emits {string} update:modelValue — The selected tab's value.\n *\n * @slot default — Panel content. Scope: `{ active }`.\n */\nimport { computed, nextTick, useId } from 'vue'\nimport UiIcon from '../icons/Icon.vue'\n\nconst props = defineProps({\n /**\n * Value of the active tab.\n * @type {string}\n * @default ''\n */\n modelValue: { type: String, default: '' },\n\n /**\n * Tabs, left to right. Each is `{ value, label, icon?, badge?, disabled? }`.\n * @type {Array<{ value: string, label: string, icon?: string, badge?: string | number, disabled?: boolean }>}\n */\n tabs: { type: Array, required: true },\n\n /**\n * Accessible name of the tab list.\n * @type {string}\n * @default ''\n */\n ariaLabel: { type: String, default: '' },\n\n /**\n * Visual style.\n * @type {string}\n * @default 'line'\n * @values 'line' | 'pill'\n */\n variant: { type: String, default: 'line' },\n\n /**\n * Render a `tabpanel` holding the default slot. Turn off when the tabs only\n * navigate and the content is rendered elsewhere.\n * @type {boolean}\n * @default true\n */\n panel: { type: Boolean, default: true },\n\n /**\n * Classes for the panel.\n * @type {string}\n * @default 'pt-6'\n */\n panelClass: { type: String, default: 'pt-6' },\n})\n\nconst emit = defineEmits(['update:modelValue'])\n\nconst baseId = useId()\nconst panelId = `${baseId}-panel`\nconst tabId = (index) => `${baseId}-tab-${index}`\n\n/** Template refs, written by the function ref on each button. */\nconst tabEls = []\n\nconst activeIndex = computed(() => props.tabs.findIndex((t) => t.value === props.modelValue))\n\n/** The tab that holds the single tab stop: the active one, else the first enabled. */\nconst focusIndex = computed(() => {\n if (activeIndex.value >= 0 && !props.tabs[activeIndex.value].disabled) return activeIndex.value\n return props.tabs.findIndex((t) => !t.disabled)\n})\n\nfunction select(index) {\n const tab = props.tabs[index]\n if (!tab || tab.disabled) return\n if (tab.value !== props.modelValue) emit('update:modelValue', tab.value)\n}\n\nfunction step(from, delta) {\n const count = props.tabs.length\n for (let i = 1; i <= count; i++) {\n const next = (from + delta * i + count * i) % count\n if (!props.tabs[next].disabled) return next\n }\n return from\n}\n\nfunction onKeydown(event) {\n const current = tabEls.indexOf(event.target)\n if (current < 0) return\n let next = null\n if (event.key === 'ArrowRight' || event.key === 'ArrowDown') next = step(current, 1)\n else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') next = step(current, -1)\n else if (event.key === 'Home') next = props.tabs.findIndex((t) => !t.disabled)\n else if (event.key === 'End') {\n for (let i = props.tabs.length - 1; i >= 0; i--) {\n if (!props.tabs[i].disabled) {\n next = i\n break\n }\n }\n }\n if (next === null || next < 0) return\n event.preventDefault()\n select(next)\n nextTick(() => tabEls[next]?.focus())\n}\n\nconst listClass = computed(() =>\n props.variant === 'pill'\n ? 'inline-flex max-w-full gap-1 overflow-x-auto rounded-xl bg-gray-100 p-1 dark:bg-gray-800'\n : 'flex gap-6 overflow-x-auto border-b border-gray-200 dark:border-gray-800',\n)\n\nfunction tabClass(index, tab) {\n const active = index === activeIndex.value\n const base =\n 'inline-flex shrink-0 items-center gap-2 text-sm font-medium whitespace-nowrap transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500 disabled:cursor-not-allowed disabled:opacity-40'\n if (props.variant === 'pill') {\n return [\n base,\n 'rounded-lg px-3 py-1.5',\n active\n ? 'bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100'\n : 'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100',\n ]\n }\n return [\n base,\n '-mb-px border-b-2 px-1 py-3',\n active\n ? 'border-primary-500 text-primary-600 dark:border-primary-400 dark:text-primary-300'\n : 'border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-800 dark:text-gray-400 dark:hover:border-gray-600 dark:hover:text-gray-200',\n tab.disabled ? 'hover:border-transparent' : '',\n ]\n}\n</script>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0FA,MAAM,QAAQ;EA6Cd,MAAM,OAAO;EAEb,MAAM,SAAS,MAAM;EACrB,MAAM,UAAU,GAAG,OAAO;EAC1B,MAAM,SAAS,UAAU,GAAG,OAAO,OAAO;;EAG1C,MAAM,SAAS,CAAC;EAEhB,MAAM,cAAc,eAAe,MAAM,KAAK,WAAW,MAAM,EAAE,UAAU,MAAM,UAAU,CAAC;;EAG5F,MAAM,aAAa,eAAe;GAChC,IAAI,YAAY,SAAS,KAAK,CAAC,MAAM,KAAK,YAAY,MAAM,CAAC,UAAU,OAAO,YAAY;GAC1F,OAAO,MAAM,KAAK,WAAW,MAAM,CAAC,EAAE,QAAQ;EAChD,CAAC;EAED,SAAS,OAAO,OAAO;GACrB,MAAM,MAAM,MAAM,KAAK;GACvB,IAAI,CAAC,OAAO,IAAI,UAAU;GAC1B,IAAI,IAAI,UAAU,MAAM,YAAY,KAAK,qBAAqB,IAAI,KAAK;EACzE;EAEA,SAAS,KAAK,MAAM,OAAO;GACzB,MAAM,QAA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1
|
+
import { useFormField } from "../internal/formField.js";
|
|
2
|
+
import { computed, createElementBlock, createElementVNode, normalizeClass, openBlock, unref } from "vue";
|
|
2
3
|
//#region src/components/Toggle.vue
|
|
3
|
-
var _hoisted_1 = [
|
|
4
|
+
var _hoisted_1 = [
|
|
5
|
+
"id",
|
|
6
|
+
"disabled",
|
|
7
|
+
"aria-describedby",
|
|
8
|
+
"aria-checked"
|
|
9
|
+
];
|
|
4
10
|
var _sfc_main = {
|
|
5
11
|
__name: "Toggle",
|
|
6
12
|
props: {
|
|
@@ -75,6 +81,7 @@ var _sfc_main = {
|
|
|
75
81
|
*/
|
|
76
82
|
const props = __props;
|
|
77
83
|
const emit = __emit;
|
|
84
|
+
const field = useFormField();
|
|
78
85
|
const activeColor = computed(() => {
|
|
79
86
|
if (props.size === "sm") {
|
|
80
87
|
const map = {
|
|
@@ -113,8 +120,10 @@ var _sfc_main = {
|
|
|
113
120
|
};
|
|
114
121
|
return (_ctx, _cache) => {
|
|
115
122
|
return openBlock(), createElementBlock("button", {
|
|
123
|
+
id: unref(field)?.controlId.value,
|
|
116
124
|
type: "button",
|
|
117
125
|
disabled: __props.disabled,
|
|
126
|
+
"aria-describedby": unref(field)?.describedBy.value,
|
|
118
127
|
class: normalizeClass(["relative inline-flex items-center shrink-0 rounded-full transition-colors", [
|
|
119
128
|
sizeClasses.value.track,
|
|
120
129
|
__props.disabled ? "opacity-50 cursor-not-allowed" : "cursor-pointer",
|