numori-ui 0.3.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 +148 -0
- package/README.md +36 -34
- package/dist/components/AppShell.js +234 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/Banner.js +29 -32
- package/dist/components/Banner.js.map +1 -1
- package/dist/components/Button.js +10 -19
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.js +15 -9
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Checkbox.js +13 -9
- 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/Dropdown.js +10 -3
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/DropdownSubmenu.js +5 -3
- package/dist/components/DropdownSubmenu.js.map +1 -1
- package/dist/components/EmptyState.js +123 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FileInput.js +12 -4
- package/dist/components/FileInput.js.map +1 -1
- package/dist/components/FormField.js +43 -13
- package/dist/components/FormField.js.map +1 -1
- package/dist/components/IconTile.js +5 -9
- package/dist/components/IconTile.js.map +1 -1
- package/dist/components/Input.js +21 -7
- package/dist/components/Input.js.map +1 -1
- package/dist/components/ListMenuItem.js +38 -31
- package/dist/components/ListMenuItem.js.map +1 -1
- package/dist/components/Numpad.js +4 -4
- package/dist/components/Numpad.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/Popup.js +9 -3
- package/dist/components/Popup.js.map +1 -1
- package/dist/components/Radio.js +2 -7
- package/dist/components/Radio.js.map +1 -1
- package/dist/components/Segmented.js +109 -27
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +16 -5
- 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 +306 -0
- package/dist/components/Table.js.map +1 -0
- 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 +91 -76
- package/dist/components/index.js.map +1 -1
- package/dist/composables/useMergedClasses.js +52 -0
- package/dist/composables/useMergedClasses.js.map +1 -0
- package/dist/icons/mdi.js +11 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.js +47 -37
- package/dist/index.js.map +1 -1
- package/dist/internal/controlSizes.js +21 -0
- package/dist/internal/controlSizes.js.map +1 -0
- package/dist/internal/formField.js +26 -0
- package/dist/internal/formField.js.map +1 -0
- package/dist/internal/menu.js +20 -0
- package/dist/internal/menu.js.map +1 -0
- package/dist/manifest.js +12 -2
- package/dist/manifest.js.map +1 -1
- package/package.json +2 -1
- package/src/components/AppShell.vue +231 -0
- package/src/components/Banner.vue +20 -9
- package/src/components/Button.vue +12 -19
- package/src/components/Card.vue +11 -12
- package/src/components/Checkbox.vue +7 -10
- package/src/components/CopyField.vue +178 -0
- package/src/components/DescriptionList.vue +114 -0
- package/src/components/Dropdown.vue +14 -2
- package/src/components/DropdownSubmenu.vue +4 -2
- package/src/components/EmptyState.vue +107 -0
- package/src/components/FileInput.vue +19 -4
- package/src/components/FormField.vue +37 -4
- package/src/components/IconTile.vue +4 -9
- package/src/components/Input.vue +15 -6
- package/src/components/ListMenuItem.vue +21 -5
- package/src/components/Numpad.vue +7 -4
- package/src/components/PageHeader.vue +102 -0
- package/src/components/Pagination.vue +199 -0
- package/src/components/Popup.vue +6 -2
- package/src/components/Radio.vue +2 -10
- package/src/components/Segmented.vue +113 -38
- package/src/components/Select.vue +16 -2
- 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 +323 -0
- package/src/components/Tabs.vue +217 -0
- package/src/components/Toggle.vue +5 -0
- package/src/components/index.js +36 -11
- package/src/composables/useMergedClasses.js +49 -0
- package/src/icons/mdi.js +11 -0
- package/src/internal/controlSizes.js +17 -0
- package/src/internal/formField.js +23 -0
- package/src/internal/menu.js +16 -0
- package/src/manifest.js +12 -2
- package/dist/components/ButtonsGroup.js +0 -153
- package/dist/components/ButtonsGroup.js.map +0 -1
- package/dist/components/ComparisonTable.js +0 -152
- package/dist/components/ComparisonTable.js.map +0 -1
- package/src/components/ButtonsGroup.vue +0 -140
- package/src/components/ComparisonTable.vue +0 -141
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
<template>
|
|
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
|
+
>
|
|
6
|
+
<table class="w-full border-collapse text-sm">
|
|
7
|
+
<caption
|
|
8
|
+
v-if="caption || $slots.caption"
|
|
9
|
+
:class="
|
|
10
|
+
hideCaption
|
|
11
|
+
? 'sr-only'
|
|
12
|
+
: 'caption-top px-5 py-4 text-left text-sm font-semibold text-gray-900 dark:text-gray-100'
|
|
13
|
+
"
|
|
14
|
+
>
|
|
15
|
+
<slot name="caption">{{ caption }}</slot>
|
|
16
|
+
</caption>
|
|
17
|
+
|
|
18
|
+
<thead>
|
|
19
|
+
<tr class="border-b border-gray-200 dark:border-gray-700">
|
|
20
|
+
<th
|
|
21
|
+
v-for="col in columns"
|
|
22
|
+
:key="col.key"
|
|
23
|
+
scope="col"
|
|
24
|
+
class="px-5 py-4 font-semibold"
|
|
25
|
+
:class="[
|
|
26
|
+
alignClass(col.align),
|
|
27
|
+
col.highlight
|
|
28
|
+
? 'bg-primary-50 text-primary-800 dark:bg-primary-400/10 dark:text-primary-200'
|
|
29
|
+
: 'text-gray-600 dark:text-gray-300',
|
|
30
|
+
col.width,
|
|
31
|
+
]"
|
|
32
|
+
:aria-sort="col.sortable ? ariaSort(col) : undefined"
|
|
33
|
+
>
|
|
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' : ''">{{
|
|
53
|
+
col.label
|
|
54
|
+
}}</span>
|
|
55
|
+
</th>
|
|
56
|
+
</tr>
|
|
57
|
+
</thead>
|
|
58
|
+
|
|
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>
|
|
68
|
+
<tr
|
|
69
|
+
v-for="(row, index) in rows"
|
|
70
|
+
:key="row[rowKey] ?? index"
|
|
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)"
|
|
80
|
+
>
|
|
81
|
+
<template v-for="col in columns" :key="col.key">
|
|
82
|
+
<!-- Header columns render as row headers (<th scope="row">), e.g. the
|
|
83
|
+
feature column of a comparison table. -->
|
|
84
|
+
<th
|
|
85
|
+
v-if="col.header"
|
|
86
|
+
scope="row"
|
|
87
|
+
class="px-5 py-4 font-medium text-gray-900 dark:text-gray-100"
|
|
88
|
+
:class="alignClass(col.align)"
|
|
89
|
+
>
|
|
90
|
+
<slot name="cell" :row="row" :column="col" :value="row[col.key]">
|
|
91
|
+
{{ row[col.key] }}
|
|
92
|
+
</slot>
|
|
93
|
+
</th>
|
|
94
|
+
<td
|
|
95
|
+
v-else
|
|
96
|
+
class="px-5 py-4"
|
|
97
|
+
:class="[
|
|
98
|
+
alignClass(col.align),
|
|
99
|
+
col.highlight
|
|
100
|
+
? 'bg-primary-50/50 text-gray-700 dark:bg-primary-400/5 dark:text-gray-200'
|
|
101
|
+
: 'text-gray-600 dark:text-gray-400',
|
|
102
|
+
]"
|
|
103
|
+
>
|
|
104
|
+
<slot name="cell" :row="row" :column="col" :value="row[col.key]">
|
|
105
|
+
<span :class="col.icon ? 'flex items-start gap-2' : ''">
|
|
106
|
+
<UiIcon
|
|
107
|
+
v-if="col.icon"
|
|
108
|
+
:name="col.icon"
|
|
109
|
+
class="mt-0.5 size-4 shrink-0"
|
|
110
|
+
:class="
|
|
111
|
+
col.highlight
|
|
112
|
+
? 'text-success-600 dark:text-success-400'
|
|
113
|
+
: 'text-gray-400 dark:text-gray-500'
|
|
114
|
+
"
|
|
115
|
+
/>
|
|
116
|
+
{{ row[col.key] }}
|
|
117
|
+
</span>
|
|
118
|
+
</slot>
|
|
119
|
+
</td>
|
|
120
|
+
</template>
|
|
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>
|
|
128
|
+
</tbody>
|
|
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>
|
|
139
|
+
</div>
|
|
140
|
+
</template>
|
|
141
|
+
|
|
142
|
+
<script setup>
|
|
143
|
+
/**
|
|
144
|
+
* UiTable — a data table with sensible defaults, sortable columns, empty and
|
|
145
|
+
* loading states, and a built-in comparison mode.
|
|
146
|
+
*
|
|
147
|
+
* Drive it with `columns` and `rows`: each column names a `key`, and each row
|
|
148
|
+
* is an object keyed by those column keys. It renders a real, accessible
|
|
149
|
+
* `<table>` (`<caption>`, `scope="col"` headers) that scrolls horizontally on
|
|
150
|
+
* narrow screens rather than crushing its columns.
|
|
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
|
+
*
|
|
161
|
+
* **Comparison** is just a configuration, not a separate component: mark the
|
|
162
|
+
* label column `header: true` (so it renders as a `<th scope="row">`), give the
|
|
163
|
+
* column you want to feature `highlight: true` (accent tint), and hand each
|
|
164
|
+
* value column an `icon` (e.g. a tick for the highlighted column, a dash for
|
|
165
|
+
* the others). For full control of a cell, use the `#cell` scoped slot.
|
|
166
|
+
*
|
|
167
|
+
* @example A plain data table
|
|
168
|
+
* <UiTable
|
|
169
|
+
* caption="Team"
|
|
170
|
+
* :columns="[
|
|
171
|
+
* { key: 'name', label: 'Name' },
|
|
172
|
+
* { key: 'role', label: 'Role' },
|
|
173
|
+
* { key: 'commits', label: 'Commits', align: 'right' },
|
|
174
|
+
* ]"
|
|
175
|
+
* :rows="[
|
|
176
|
+
* { name: 'Ada Lovelace', role: 'Engineer', commits: 128 },
|
|
177
|
+
* { name: 'Grace Hopper', role: 'Lead', commits: 342 },
|
|
178
|
+
* ]"
|
|
179
|
+
* />
|
|
180
|
+
*
|
|
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
|
|
195
|
+
* <UiTable
|
|
196
|
+
* caption="How Numori compares"
|
|
197
|
+
* :columns="[
|
|
198
|
+
* { key: 'feature', label: 'Feature', header: true },
|
|
199
|
+
* { key: 'numori', label: 'Numori', highlight: true, icon: 'mdi:check-circle' },
|
|
200
|
+
* { key: 'usual', label: 'The usual', icon: 'mdi:minus-circle-outline' },
|
|
201
|
+
* ]"
|
|
202
|
+
* :rows="[
|
|
203
|
+
* { feature: 'Open source', numori: 'Entire ecosystem', usual: 'The client, sometimes' },
|
|
204
|
+
* ]"
|
|
205
|
+
* />
|
|
206
|
+
*
|
|
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`).
|
|
209
|
+
*
|
|
210
|
+
* @slot caption — Rich caption content (overrides the `caption` prop).
|
|
211
|
+
* @slot cell — Custom cell content. Scope: `{ row, column, value }`.
|
|
212
|
+
* @slot empty — Content shown when there are no rows.
|
|
213
|
+
*/
|
|
214
|
+
import UiIcon from '../icons/Icon.vue'
|
|
215
|
+
|
|
216
|
+
const props = defineProps({
|
|
217
|
+
/**
|
|
218
|
+
* Column definitions, left to right. Each is
|
|
219
|
+
* `{ key, label?, align?, header?, highlight?, icon?, width?, sortable? }`:
|
|
220
|
+
* - `key` — the row field this column reads.
|
|
221
|
+
* - `label` — the column heading.
|
|
222
|
+
* - `align` — `'left'` (default) | `'center'` | `'right'`.
|
|
223
|
+
* - `header` — render this column's cells as row headers (`<th scope="row">`).
|
|
224
|
+
* - `highlight` — accent-tint the column (the featured column in a comparison).
|
|
225
|
+
* - `icon` — MDI icon shown before each value in the column.
|
|
226
|
+
* - `width` — optional width utility class, e.g. `'w-2/5'`.
|
|
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 }>}
|
|
229
|
+
*/
|
|
230
|
+
columns: { type: Array, required: true },
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Row objects, each keyed by the column `key`s.
|
|
234
|
+
* @type {Array<Record<string, unknown>>}
|
|
235
|
+
*/
|
|
236
|
+
rows: { type: Array, required: true },
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Table caption. Rendered as a real `<caption>` for accessibility; visible by
|
|
240
|
+
* default, or visually hidden with `hideCaption`.
|
|
241
|
+
* @type {string}
|
|
242
|
+
* @default ''
|
|
243
|
+
*/
|
|
244
|
+
caption: { type: String, default: '' },
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Keep the caption for assistive technology but hide it visually.
|
|
248
|
+
* @type {boolean}
|
|
249
|
+
* @default false
|
|
250
|
+
*/
|
|
251
|
+
hideCaption: { type: Boolean, default: false },
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Row field used as the `v-for` key; falls back to the row index.
|
|
255
|
+
* @type {string}
|
|
256
|
+
* @default 'key'
|
|
257
|
+
*/
|
|
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 },
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
const emit = defineEmits(['sort', 'row-click'])
|
|
305
|
+
|
|
306
|
+
const alignClass = (align) =>
|
|
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
|
+
}
|
|
323
|
+
</script>
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<div
|
|
4
|
+
role="tablist"
|
|
5
|
+
:aria-label="ariaLabel || undefined"
|
|
6
|
+
:class="listClass"
|
|
7
|
+
@keydown="onKeydown"
|
|
8
|
+
>
|
|
9
|
+
<button
|
|
10
|
+
v-for="(tab, index) in tabs"
|
|
11
|
+
:id="tabId(index)"
|
|
12
|
+
:key="tab.value"
|
|
13
|
+
:ref="(el) => (tabEls[index] = el)"
|
|
14
|
+
type="button"
|
|
15
|
+
role="tab"
|
|
16
|
+
:aria-selected="index === activeIndex ? 'true' : 'false'"
|
|
17
|
+
:aria-controls="panel ? panelId : undefined"
|
|
18
|
+
:tabindex="index === focusIndex ? 0 : -1"
|
|
19
|
+
:disabled="tab.disabled"
|
|
20
|
+
:class="tabClass(index, tab)"
|
|
21
|
+
@click="select(index)"
|
|
22
|
+
>
|
|
23
|
+
<UiIcon v-if="tab.icon" :name="tab.icon" class="size-4 shrink-0" />
|
|
24
|
+
<span>{{ tab.label }}</span>
|
|
25
|
+
<span
|
|
26
|
+
v-if="tab.badge !== undefined && tab.badge !== null && tab.badge !== ''"
|
|
27
|
+
class="inline-flex min-w-5 items-center justify-center rounded-full px-1.5 text-xs font-semibold tabular-nums"
|
|
28
|
+
:class="
|
|
29
|
+
index === activeIndex
|
|
30
|
+
? 'bg-primary-100 text-primary-700 dark:bg-primary-400/20 dark:text-primary-200'
|
|
31
|
+
: 'bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300'
|
|
32
|
+
"
|
|
33
|
+
>{{ tab.badge }}</span
|
|
34
|
+
>
|
|
35
|
+
</button>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
v-if="panel"
|
|
40
|
+
:id="panelId"
|
|
41
|
+
role="tabpanel"
|
|
42
|
+
:aria-labelledby="activeIndex >= 0 ? tabId(activeIndex) : undefined"
|
|
43
|
+
tabindex="0"
|
|
44
|
+
class="focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-primary-500"
|
|
45
|
+
:class="panelClass"
|
|
46
|
+
>
|
|
47
|
+
<slot :active="modelValue" />
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<script setup>
|
|
53
|
+
/**
|
|
54
|
+
* UiTabs — an accessible tab list, with an optional panel for the active tab.
|
|
55
|
+
*
|
|
56
|
+
* Implements the WAI-ARIA tabs pattern: `role="tablist"` / `"tab"` /
|
|
57
|
+
* `"tabpanel"`, a single tab stop (roving `tabindex`), and arrow keys, Home and
|
|
58
|
+
* End to move between tabs. Moving with the keyboard selects the tab
|
|
59
|
+
* (automatic activation), skipping disabled tabs.
|
|
60
|
+
*
|
|
61
|
+
* Render the panel through the default slot, which receives the active value.
|
|
62
|
+
* When the content lives elsewhere — a routed `<RouterView>` below the tabs,
|
|
63
|
+
* say — set `:panel="false"` and use the tabs as navigation only.
|
|
64
|
+
*
|
|
65
|
+
* Two looks: `line` (an underline under the active tab, for page sections) and
|
|
66
|
+
* `pill` (a segmented track, for compact switches inside cards).
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* <UiTabs
|
|
70
|
+
* v-model="tab"
|
|
71
|
+
* aria-label="App sections"
|
|
72
|
+
* :tabs="[
|
|
73
|
+
* { value: 'overview', label: 'Overview', icon: 'mdi:view-grid' },
|
|
74
|
+
* { value: 'keys', label: 'Keys', badge: 2 },
|
|
75
|
+
* { value: 'danger', label: 'Danger zone' },
|
|
76
|
+
* ]"
|
|
77
|
+
* >
|
|
78
|
+
* <template #default="{ active }">
|
|
79
|
+
* <OverviewPanel v-if="active === 'overview'" />
|
|
80
|
+
* <KeysPanel v-else-if="active === 'keys'" />
|
|
81
|
+
* </template>
|
|
82
|
+
* </UiTabs>
|
|
83
|
+
*
|
|
84
|
+
* @emits {string} update:modelValue — The selected tab's value.
|
|
85
|
+
*
|
|
86
|
+
* @slot default — Panel content. Scope: `{ active }`.
|
|
87
|
+
*/
|
|
88
|
+
import { computed, nextTick, useId } from 'vue'
|
|
89
|
+
import UiIcon from '../icons/Icon.vue'
|
|
90
|
+
|
|
91
|
+
const props = defineProps({
|
|
92
|
+
/**
|
|
93
|
+
* Value of the active tab.
|
|
94
|
+
* @type {string}
|
|
95
|
+
* @default ''
|
|
96
|
+
*/
|
|
97
|
+
modelValue: { type: String, default: '' },
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Tabs, left to right. Each is `{ value, label, icon?, badge?, disabled? }`.
|
|
101
|
+
* @type {Array<{ value: string, label: string, icon?: string, badge?: string | number, disabled?: boolean }>}
|
|
102
|
+
*/
|
|
103
|
+
tabs: { type: Array, required: true },
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Accessible name of the tab list.
|
|
107
|
+
* @type {string}
|
|
108
|
+
* @default ''
|
|
109
|
+
*/
|
|
110
|
+
ariaLabel: { type: String, default: '' },
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Visual style.
|
|
114
|
+
* @type {string}
|
|
115
|
+
* @default 'line'
|
|
116
|
+
* @values 'line' | 'pill'
|
|
117
|
+
*/
|
|
118
|
+
variant: { type: String, default: 'line' },
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Render a `tabpanel` holding the default slot. Turn off when the tabs only
|
|
122
|
+
* navigate and the content is rendered elsewhere.
|
|
123
|
+
* @type {boolean}
|
|
124
|
+
* @default true
|
|
125
|
+
*/
|
|
126
|
+
panel: { type: Boolean, default: true },
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Classes for the panel.
|
|
130
|
+
* @type {string}
|
|
131
|
+
* @default 'pt-6'
|
|
132
|
+
*/
|
|
133
|
+
panelClass: { type: String, default: 'pt-6' },
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const emit = defineEmits(['update:modelValue'])
|
|
137
|
+
|
|
138
|
+
const baseId = useId()
|
|
139
|
+
const panelId = `${baseId}-panel`
|
|
140
|
+
const tabId = (index) => `${baseId}-tab-${index}`
|
|
141
|
+
|
|
142
|
+
/** Template refs, written by the function ref on each button. */
|
|
143
|
+
const tabEls = []
|
|
144
|
+
|
|
145
|
+
const activeIndex = computed(() => props.tabs.findIndex((t) => t.value === props.modelValue))
|
|
146
|
+
|
|
147
|
+
/** The tab that holds the single tab stop: the active one, else the first enabled. */
|
|
148
|
+
const focusIndex = computed(() => {
|
|
149
|
+
if (activeIndex.value >= 0 && !props.tabs[activeIndex.value].disabled) return activeIndex.value
|
|
150
|
+
return props.tabs.findIndex((t) => !t.disabled)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
function select(index) {
|
|
154
|
+
const tab = props.tabs[index]
|
|
155
|
+
if (!tab || tab.disabled) return
|
|
156
|
+
if (tab.value !== props.modelValue) emit('update:modelValue', tab.value)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function step(from, delta) {
|
|
160
|
+
const count = props.tabs.length
|
|
161
|
+
for (let i = 1; i <= count; i++) {
|
|
162
|
+
const next = (from + delta * i + count * i) % count
|
|
163
|
+
if (!props.tabs[next].disabled) return next
|
|
164
|
+
}
|
|
165
|
+
return from
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function onKeydown(event) {
|
|
169
|
+
const current = tabEls.indexOf(event.target)
|
|
170
|
+
if (current < 0) return
|
|
171
|
+
let next = null
|
|
172
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') next = step(current, 1)
|
|
173
|
+
else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') next = step(current, -1)
|
|
174
|
+
else if (event.key === 'Home') next = props.tabs.findIndex((t) => !t.disabled)
|
|
175
|
+
else if (event.key === 'End') {
|
|
176
|
+
for (let i = props.tabs.length - 1; i >= 0; i--) {
|
|
177
|
+
if (!props.tabs[i].disabled) {
|
|
178
|
+
next = i
|
|
179
|
+
break
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (next === null || next < 0) return
|
|
184
|
+
event.preventDefault()
|
|
185
|
+
select(next)
|
|
186
|
+
nextTick(() => tabEls[next]?.focus())
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const listClass = computed(() =>
|
|
190
|
+
props.variant === 'pill'
|
|
191
|
+
? 'inline-flex max-w-full gap-1 overflow-x-auto rounded-xl bg-gray-100 p-1 dark:bg-gray-800'
|
|
192
|
+
: 'flex gap-6 overflow-x-auto border-b border-gray-200 dark:border-gray-800',
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
function tabClass(index, tab) {
|
|
196
|
+
const active = index === activeIndex.value
|
|
197
|
+
const base =
|
|
198
|
+
'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'
|
|
199
|
+
if (props.variant === 'pill') {
|
|
200
|
+
return [
|
|
201
|
+
base,
|
|
202
|
+
'rounded-lg px-3 py-1.5',
|
|
203
|
+
active
|
|
204
|
+
? 'bg-white text-gray-900 shadow-sm dark:bg-gray-900 dark:text-gray-100'
|
|
205
|
+
: 'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100',
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
return [
|
|
209
|
+
base,
|
|
210
|
+
'-mb-px border-b-2 px-1 py-3',
|
|
211
|
+
active
|
|
212
|
+
? 'border-primary-500 text-primary-600 dark:border-primary-400 dark:text-primary-300'
|
|
213
|
+
: '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',
|
|
214
|
+
tab.disabled ? 'hover:border-transparent' : '',
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
</script>
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<!-- Accessible toggle switch rendered as a button with role="switch" -->
|
|
3
3
|
<button
|
|
4
|
+
:id="field?.controlId.value"
|
|
4
5
|
type="button"
|
|
5
6
|
:disabled="disabled"
|
|
7
|
+
:aria-describedby="field?.describedBy.value"
|
|
6
8
|
class="relative inline-flex items-center shrink-0 rounded-full transition-colors"
|
|
7
9
|
:class="[
|
|
8
10
|
sizeClasses.track,
|
|
@@ -40,6 +42,7 @@
|
|
|
40
42
|
* @emits {boolean} update:modelValue — Emitted when the toggle is switched (v-model)
|
|
41
43
|
*/
|
|
42
44
|
import { computed } from 'vue'
|
|
45
|
+
import { useFormField } from '../internal/formField.js'
|
|
43
46
|
const props = defineProps({
|
|
44
47
|
/**
|
|
45
48
|
* Current on/off state (v-model).
|
|
@@ -82,6 +85,8 @@ const props = defineProps({
|
|
|
82
85
|
|
|
83
86
|
const emit = defineEmits(['update:modelValue'])
|
|
84
87
|
|
|
88
|
+
const field = useFormField()
|
|
89
|
+
|
|
85
90
|
// Active color uses different shade intensities per size for visual consistency
|
|
86
91
|
const activeColor = computed(() => {
|
|
87
92
|
if (props.size === 'sm') {
|