numori-ui 0.2.0 → 0.4.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 +122 -0
- package/README.md +26 -21
- package/dist/components/Banner.js +176 -0
- package/dist/components/Banner.js.map +1 -0
- 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 +2 -7
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/CodeBlock.js +101 -0
- package/dist/components/CodeBlock.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/FileInput.js +12 -4
- package/dist/components/FileInput.js.map +1 -1
- package/dist/components/IconTile.js +5 -9
- package/dist/components/IconTile.js.map +1 -1
- package/dist/components/Input.js +6 -6
- 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/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 +100 -26
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +6 -4
- package/dist/components/Select.js.map +1 -1
- package/dist/components/Spinner.js +87 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/Table.js +174 -0
- package/dist/components/Table.js.map +1 -0
- package/dist/components/ThemeToggle.js +85 -0
- package/dist/components/ThemeToggle.js.map +1 -0
- package/dist/components/Toast.js +107 -0
- package/dist/components/Toast.js.map +1 -0
- package/dist/components/index.js +67 -57
- 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 +10 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +35 -30
- 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/menu.js +20 -0
- package/dist/internal/menu.js.map +1 -0
- package/dist/manifest.js +6 -1
- package/dist/manifest.js.map +1 -1
- package/package.json +2 -1
- package/src/components/Banner.vue +160 -0
- package/src/components/Button.vue +12 -19
- package/src/components/Card.vue +11 -12
- package/src/components/Checkbox.vue +2 -10
- package/src/components/CodeBlock.vue +99 -0
- package/src/components/Dropdown.vue +14 -2
- package/src/components/DropdownSubmenu.vue +4 -2
- package/src/components/FileInput.vue +19 -4
- package/src/components/IconTile.vue +4 -9
- package/src/components/Input.vue +6 -6
- package/src/components/ListMenuItem.vue +21 -5
- package/src/components/Numpad.vue +7 -4
- package/src/components/Popup.vue +6 -2
- package/src/components/Radio.vue +2 -10
- package/src/components/Segmented.vue +108 -38
- package/src/components/Select.vue +11 -2
- package/src/components/Spinner.vue +70 -0
- package/src/components/Table.vue +193 -0
- package/src/components/ThemeToggle.vue +81 -0
- package/src/components/Toast.vue +106 -0
- package/src/components/index.js +18 -3
- package/src/composables/useMergedClasses.js +49 -0
- package/src/icons/mdi.js +10 -0
- package/src/internal/controlSizes.js +17 -0
- package/src/internal/menu.js +16 -0
- package/src/manifest.js +6 -1
- package/dist/components/ButtonsGroup.js +0 -153
- package/dist/components/ButtonsGroup.js.map +0 -1
- package/src/components/ButtonsGroup.vue +0 -140
|
@@ -2,40 +2,41 @@
|
|
|
2
2
|
<div
|
|
3
3
|
role="group"
|
|
4
4
|
:aria-label="ariaLabel"
|
|
5
|
-
class="relative
|
|
6
|
-
:class="[
|
|
7
|
-
|
|
5
|
+
class="relative p-1"
|
|
6
|
+
:class="[
|
|
7
|
+
block ? 'grid w-full' : 'inline-grid',
|
|
8
|
+
radiusClass,
|
|
9
|
+
'border border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-900',
|
|
10
|
+
]"
|
|
11
|
+
:style="gridStyle"
|
|
8
12
|
>
|
|
9
13
|
<!--
|
|
10
|
-
A single
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
A single indicator slides between segments, so changing the selection
|
|
15
|
+
animates in every variant. Segments are equal-width grid columns, so the
|
|
16
|
+
indicator is one column wide and translates by whole columns. The variant
|
|
17
|
+
only changes how the indicator looks (accent fill vs raised surface); the
|
|
18
|
+
sliding mechanism is shared.
|
|
15
19
|
-->
|
|
16
20
|
<span
|
|
17
21
|
aria-hidden="true"
|
|
18
|
-
class="pointer-events-none absolute bottom-1 left-1 top-1
|
|
19
|
-
:class="
|
|
20
|
-
:style="
|
|
22
|
+
class="pointer-events-none absolute bottom-1 left-1 top-1 shadow-sm transition-transform duration-300 ease-out motion-reduce:transition-none"
|
|
23
|
+
:class="[radiusClass, indicatorClass]"
|
|
24
|
+
:style="indicatorStyle"
|
|
21
25
|
/>
|
|
22
26
|
|
|
23
27
|
<button
|
|
24
|
-
v-for="
|
|
28
|
+
v-for="option in options"
|
|
25
29
|
:key="option.value"
|
|
26
30
|
type="button"
|
|
27
31
|
:aria-pressed="isActive(option) ? 'true' : 'false'"
|
|
28
32
|
:disabled="option.disabled"
|
|
33
|
+
:title="option.title || undefined"
|
|
29
34
|
class="relative z-10 inline-flex items-center justify-center gap-1.5 font-semibold transition-colors disabled:cursor-not-allowed disabled:opacity-50"
|
|
30
|
-
:class="[
|
|
31
|
-
|
|
32
|
-
buttonShapeClass,
|
|
33
|
-
isActive(option) ? activeTextClass : idleTextClass,
|
|
34
|
-
]"
|
|
35
|
-
@click="select(option, index)"
|
|
35
|
+
:class="[buttonSizeClass, radiusClass, isActive(option) ? activeTextClass : idleTextClass]"
|
|
36
|
+
@click="select(option)"
|
|
36
37
|
>
|
|
37
38
|
<UiIcon v-if="option.icon" :name="option.icon" :class="iconSizeClass" />
|
|
38
|
-
{{ option.label }}
|
|
39
|
+
<span v-if="option.label">{{ option.label }}</span>
|
|
39
40
|
</button>
|
|
40
41
|
</div>
|
|
41
42
|
</template>
|
|
@@ -43,17 +44,32 @@
|
|
|
43
44
|
<script setup>
|
|
44
45
|
/**
|
|
45
46
|
* UiSegmented — a segmented control: pick one of a few named options from a row
|
|
46
|
-
* of
|
|
47
|
+
* of segments, with an indicator that slides to the active choice.
|
|
47
48
|
*
|
|
48
49
|
* This is a set of toggle buttons (`role="group"` + `aria-pressed`), not a
|
|
49
50
|
* switch, because the choice is between named options rather than on/off — "the
|
|
50
51
|
* second option is off" is not something a screen reader should say. Segments
|
|
51
|
-
* are equal width so the
|
|
52
|
+
* are equal width so the indicator can slide by whole columns, and the slide
|
|
53
|
+
* animates in both variants.
|
|
54
|
+
*
|
|
55
|
+
* The `variant` values match `UiButton`'s — `solid`, `outline`, `ghost` — so a
|
|
56
|
+
* segmented control sits alongside buttons as part of one visual family. The
|
|
57
|
+
* indicator slides (and animates) to the active choice in every variant.
|
|
58
|
+
*
|
|
59
|
+
* - `variant="solid"` (default) — a filled accent indicator; the active label
|
|
60
|
+
* goes white. Like a solid button.
|
|
61
|
+
* - `variant="outline"` — a bordered accent indicator; the active label takes
|
|
62
|
+
* the accent colour. Like an outline button.
|
|
63
|
+
* - `variant="ghost"` — a soft tinted indicator; the active label takes the
|
|
64
|
+
* accent colour. Like a ghost button.
|
|
65
|
+
*
|
|
66
|
+
* `shape` controls the corners — `pill`, `round`, or `square` (matching
|
|
67
|
+
* `UiButton`) — and the indicator matches the track's radius.
|
|
52
68
|
*
|
|
53
69
|
* For an on/off control use `UiToggle`; for many options or a searchable list
|
|
54
70
|
* use `UiSelect`.
|
|
55
71
|
*
|
|
56
|
-
* @example Billing period
|
|
72
|
+
* @example Billing period (solid, the default)
|
|
57
73
|
* <UiSegmented
|
|
58
74
|
* v-model="billing"
|
|
59
75
|
* :options="[
|
|
@@ -63,9 +79,20 @@
|
|
|
63
79
|
* aria-label="Billing period"
|
|
64
80
|
* />
|
|
65
81
|
*
|
|
66
|
-
* @example
|
|
67
|
-
* <
|
|
68
|
-
*
|
|
82
|
+
* @example Icon toolbar (outline, square corners)
|
|
83
|
+
* <UiSegmented
|
|
84
|
+
* v-model="view"
|
|
85
|
+
* variant="outline"
|
|
86
|
+
* shape="square"
|
|
87
|
+
* :options="[
|
|
88
|
+
* { value: 'grid', icon: 'mdi:view-grid', title: 'Grid' },
|
|
89
|
+
* { value: 'list', icon: 'mdi:view-list', title: 'List' },
|
|
90
|
+
* ]"
|
|
91
|
+
* aria-label="View"
|
|
92
|
+
* />
|
|
93
|
+
*
|
|
94
|
+
* @example Full-width ghost tabs
|
|
95
|
+
* <UiSegmented v-model="tab" variant="ghost" block :options="tabs" />
|
|
69
96
|
*
|
|
70
97
|
* @emits {string|number} update:modelValue — the chosen option's `value`
|
|
71
98
|
*/
|
|
@@ -81,11 +108,25 @@ const props = defineProps({
|
|
|
81
108
|
modelValue: { type: [String, Number], default: undefined },
|
|
82
109
|
|
|
83
110
|
/**
|
|
84
|
-
* The options. Each is `{ value, label
|
|
85
|
-
*
|
|
111
|
+
* The options. Each is `{ value, label?, icon?, disabled?, title? }`. Provide
|
|
112
|
+
* `label` for text segments, `icon` for icon-only segments, or both. `title`
|
|
113
|
+
* sets the native tooltip (useful for icon-only segments).
|
|
114
|
+
* @type {Array<{ value: string|number, label?: string, icon?: string, disabled?: boolean, title?: string }>}
|
|
86
115
|
*/
|
|
87
116
|
options: { type: Array, required: true },
|
|
88
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Active-segment appearance, mirroring the equivalent `UiButton` variants so
|
|
120
|
+
* the two feel like one family. The sliding indicator animates in every case.
|
|
121
|
+
* - 'solid' — a filled accent indicator; the active label goes white (default).
|
|
122
|
+
* - 'outline' — a bordered accent indicator; the active label takes the accent.
|
|
123
|
+
* - 'ghost' — a soft tinted indicator; the active label takes the accent.
|
|
124
|
+
* @type {string}
|
|
125
|
+
* @default 'solid'
|
|
126
|
+
* @values 'solid' | 'outline' | 'ghost'
|
|
127
|
+
*/
|
|
128
|
+
variant: { type: String, default: 'solid' },
|
|
129
|
+
|
|
89
130
|
/**
|
|
90
131
|
* Size preset controlling padding and font size.
|
|
91
132
|
* @type {string}
|
|
@@ -95,13 +136,22 @@ const props = defineProps({
|
|
|
95
136
|
size: { type: String, default: 'md' },
|
|
96
137
|
|
|
97
138
|
/**
|
|
98
|
-
* Corner shape of the track and
|
|
139
|
+
* Corner shape of the track, indicator, and segments. Matches `UiButton`'s
|
|
140
|
+
* `shape` naming.
|
|
99
141
|
* @type {string}
|
|
100
142
|
* @default 'pill'
|
|
101
|
-
* @values 'pill' | '
|
|
143
|
+
* @values 'pill' | 'round' | 'square'
|
|
102
144
|
*/
|
|
103
145
|
shape: { type: String, default: 'pill' },
|
|
104
146
|
|
|
147
|
+
/**
|
|
148
|
+
* Full-width mode — the control fills its container and segments share the
|
|
149
|
+
* width equally.
|
|
150
|
+
* @type {boolean}
|
|
151
|
+
* @default false
|
|
152
|
+
*/
|
|
153
|
+
block: { type: Boolean, default: false },
|
|
154
|
+
|
|
105
155
|
/**
|
|
106
156
|
* Accessible name for the group. Omit if you label it with an external
|
|
107
157
|
* heading via `aria-labelledby` (which falls through to the root).
|
|
@@ -122,28 +172,48 @@ const activeIndex = computed(() => {
|
|
|
122
172
|
return i === -1 ? 0 : i
|
|
123
173
|
})
|
|
124
174
|
|
|
125
|
-
function select(option
|
|
175
|
+
function select(option) {
|
|
126
176
|
if (option.disabled) return
|
|
127
177
|
emit('update:modelValue', option.value)
|
|
128
|
-
// index is accepted for symmetry with the template call site; the value is
|
|
129
|
-
// what identifies the option.
|
|
130
|
-
void index
|
|
131
178
|
}
|
|
132
179
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
180
|
+
const gridStyle = computed(() => ({
|
|
181
|
+
gridTemplateColumns: `repeat(${count.value}, minmax(0, 1fr))`,
|
|
182
|
+
}))
|
|
183
|
+
|
|
184
|
+
// ── Shape ─────────────────────────────────────────────────
|
|
185
|
+
// The track, the sliding indicator, and the segments all share one radius so
|
|
186
|
+
// the indicator's corners match the holder's rather than reading as a tighter
|
|
187
|
+
// (or looser) curve inside it.
|
|
188
|
+
const radiusClass = computed(() => {
|
|
189
|
+
const map = { pill: 'rounded-full', round: 'rounded-lg', square: 'rounded-none' }
|
|
190
|
+
return map[props.shape] ?? map.pill
|
|
191
|
+
})
|
|
136
192
|
|
|
193
|
+
// ── Size ──────────────────────────────────────────────────
|
|
137
194
|
const buttonSizeClass = computed(() =>
|
|
138
195
|
props.size === 'sm' ? 'px-3 py-1 text-xs' : 'px-4 py-1.5 text-sm',
|
|
139
196
|
)
|
|
140
197
|
const iconSizeClass = computed(() => (props.size === 'sm' ? 'size-3.5' : 'size-4'))
|
|
141
198
|
|
|
142
|
-
|
|
199
|
+
// ── Variant: indicator look + active label colour ─────────
|
|
200
|
+
// These mirror UiButton's solid / outline / ghost variants (primary colour) so
|
|
201
|
+
// a segmented control reads as part of the same family as the buttons near it.
|
|
202
|
+
const indicatorClass = computed(() => {
|
|
203
|
+
const map = {
|
|
204
|
+
solid: 'bg-primary-600 shadow-sm',
|
|
205
|
+
outline: 'border border-primary-500',
|
|
206
|
+
ghost: 'bg-primary-50 dark:bg-primary-900/20',
|
|
207
|
+
}
|
|
208
|
+
return map[props.variant] ?? map.solid
|
|
209
|
+
})
|
|
210
|
+
const activeTextClass = computed(() =>
|
|
211
|
+
props.variant === 'solid' ? 'text-white' : 'text-primary-600 dark:text-primary-400',
|
|
212
|
+
)
|
|
143
213
|
const idleTextClass =
|
|
144
214
|
'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100'
|
|
145
215
|
|
|
146
|
-
const
|
|
216
|
+
const indicatorStyle = computed(() => ({
|
|
147
217
|
// Track padding is p-1 (0.25rem) each side, so the usable width is
|
|
148
218
|
// `100% - 0.5rem`; one segment is that divided by the option count.
|
|
149
219
|
width: `calc((100% - 0.5rem) / ${count.value})`,
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
<div
|
|
65
65
|
v-show="isOpen"
|
|
66
66
|
ref="panelRef"
|
|
67
|
-
class="fixed z-[60]
|
|
67
|
+
class="fixed z-[60] overflow-hidden"
|
|
68
|
+
:class="MENU_PANEL_CLASS"
|
|
68
69
|
:style="panelStyle"
|
|
69
70
|
>
|
|
70
71
|
<!-- Search input for filtering options -->
|
|
@@ -172,6 +173,7 @@
|
|
|
172
173
|
*/
|
|
173
174
|
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
174
175
|
import UiIcon from '../icons/Icon.vue'
|
|
176
|
+
import { MENU_PANEL_CLASS } from '../internal/menu.js'
|
|
175
177
|
const props = defineProps({
|
|
176
178
|
/**
|
|
177
179
|
* Currently selected value (v-model).
|
|
@@ -275,7 +277,14 @@ const reposition = () => {
|
|
|
275
277
|
const rect = el.getBoundingClientRect()
|
|
276
278
|
const spaceBelow = window.innerHeight - rect.bottom
|
|
277
279
|
const openUp = spaceBelow < 260 && rect.top > spaceBelow
|
|
278
|
-
|
|
280
|
+
// Inline transform-origin (not a Tailwind class) so the panel reliably scales
|
|
281
|
+
// in from the edge nearest the trigger — top when dropping down, bottom when
|
|
282
|
+
// dropping up — instead of drifting in from its centre.
|
|
283
|
+
const style = {
|
|
284
|
+
left: `${rect.left}px`,
|
|
285
|
+
minWidth: `${rect.width}px`,
|
|
286
|
+
transformOrigin: openUp ? 'bottom center' : 'top center',
|
|
287
|
+
}
|
|
279
288
|
if (props.block) style.width = `${rect.width}px`
|
|
280
289
|
if (openUp) style.bottom = `${window.innerHeight - rect.top + 4}px`
|
|
281
290
|
else style.top = `${rect.bottom + 4}px`
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<UiIcon
|
|
3
|
+
:name="icon"
|
|
4
|
+
class="animate-spin"
|
|
5
|
+
:class="sizeClass"
|
|
6
|
+
:aria-hidden="label ? undefined : 'true'"
|
|
7
|
+
:aria-label="label || undefined"
|
|
8
|
+
:role="label ? 'status' : undefined"
|
|
9
|
+
/>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup>
|
|
13
|
+
/**
|
|
14
|
+
* UiSpinner — a spinning icon for loading and in-progress states.
|
|
15
|
+
*
|
|
16
|
+
* The same glyph `UiButton` shows while loading, pulled out as a standalone
|
|
17
|
+
* primitive so anything can signal work in progress without reaching for a
|
|
18
|
+
* button or hand-rolling `animate-spin`. Colour is inherited (`text-*`), exactly
|
|
19
|
+
* like `UiIcon`, so a spinner tints to match whatever surrounds it.
|
|
20
|
+
*
|
|
21
|
+
* By default it is decorative and hidden from assistive technology, which is
|
|
22
|
+
* right when a nearby label already says what is happening ("Saving…" next to
|
|
23
|
+
* it). Give it a `label` and it becomes a live `role="status"` region that
|
|
24
|
+
* announces on its own — use that when the spinner is the only thing on screen.
|
|
25
|
+
*
|
|
26
|
+
* @example Inline, decorative
|
|
27
|
+
* <UiSpinner />
|
|
28
|
+
*
|
|
29
|
+
* @example Larger, tinted, and self-announcing
|
|
30
|
+
* <UiSpinner size="lg" label="Syncing" class="text-primary-600 dark:text-primary-400" />
|
|
31
|
+
*/
|
|
32
|
+
import { computed } from 'vue'
|
|
33
|
+
import UiIcon from '../icons/Icon.vue'
|
|
34
|
+
|
|
35
|
+
const props = defineProps({
|
|
36
|
+
/**
|
|
37
|
+
* Diameter of the spinner.
|
|
38
|
+
* @type {string}
|
|
39
|
+
* @default 'md'
|
|
40
|
+
* @values 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
41
|
+
*/
|
|
42
|
+
size: { type: String, default: 'md' },
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Accessible label. When set, the spinner is announced as a live status
|
|
46
|
+
* region; when omitted, it is hidden from assistive technology as decorative.
|
|
47
|
+
* @type {string}
|
|
48
|
+
* @default ''
|
|
49
|
+
*/
|
|
50
|
+
label: { type: String, default: '' },
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* MDI icon to spin. The default is the same one `UiButton` uses; pass another
|
|
54
|
+
* (e.g. `'mdi:sync'`) for a different look.
|
|
55
|
+
* @type {string}
|
|
56
|
+
* @default 'mdi:loading'
|
|
57
|
+
*/
|
|
58
|
+
icon: { type: String, default: 'mdi:loading' },
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const SIZES = {
|
|
62
|
+
xs: 'w-3 h-3',
|
|
63
|
+
sm: 'w-3.5 h-3.5',
|
|
64
|
+
md: 'w-5 h-5',
|
|
65
|
+
lg: 'w-6 h-6',
|
|
66
|
+
xl: 'w-8 h-8',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const sizeClass = computed(() => SIZES[props.size] || SIZES.md)
|
|
70
|
+
</script>
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="overflow-x-auto rounded-2xl border border-gray-200 dark:border-gray-700">
|
|
3
|
+
<table class="w-full border-collapse text-sm">
|
|
4
|
+
<caption
|
|
5
|
+
v-if="caption || $slots.caption"
|
|
6
|
+
:class="
|
|
7
|
+
hideCaption
|
|
8
|
+
? 'sr-only'
|
|
9
|
+
: 'caption-top px-5 py-4 text-left text-sm font-semibold text-gray-900 dark:text-gray-100'
|
|
10
|
+
"
|
|
11
|
+
>
|
|
12
|
+
<slot name="caption">{{ caption }}</slot>
|
|
13
|
+
</caption>
|
|
14
|
+
|
|
15
|
+
<thead>
|
|
16
|
+
<tr class="border-b border-gray-200 dark:border-gray-700">
|
|
17
|
+
<th
|
|
18
|
+
v-for="col in columns"
|
|
19
|
+
:key="col.key"
|
|
20
|
+
scope="col"
|
|
21
|
+
class="px-5 py-4 font-semibold"
|
|
22
|
+
:class="[
|
|
23
|
+
alignClass(col.align),
|
|
24
|
+
col.highlight
|
|
25
|
+
? 'bg-primary-50 text-primary-800 dark:bg-primary-400/10 dark:text-primary-200'
|
|
26
|
+
: 'text-gray-600 dark:text-gray-300',
|
|
27
|
+
col.width,
|
|
28
|
+
]"
|
|
29
|
+
>
|
|
30
|
+
<span v-if="col.label" :class="col.header && !col.label ? 'sr-only' : ''">{{
|
|
31
|
+
col.label
|
|
32
|
+
}}</span>
|
|
33
|
+
</th>
|
|
34
|
+
</tr>
|
|
35
|
+
</thead>
|
|
36
|
+
|
|
37
|
+
<tbody>
|
|
38
|
+
<tr
|
|
39
|
+
v-for="(row, index) in rows"
|
|
40
|
+
:key="row[rowKey] ?? index"
|
|
41
|
+
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"
|
|
42
|
+
>
|
|
43
|
+
<template v-for="col in columns" :key="col.key">
|
|
44
|
+
<!-- Header columns render as row headers (<th scope="row">), e.g. the
|
|
45
|
+
feature column of a comparison table. -->
|
|
46
|
+
<th
|
|
47
|
+
v-if="col.header"
|
|
48
|
+
scope="row"
|
|
49
|
+
class="px-5 py-4 font-medium text-gray-900 dark:text-gray-100"
|
|
50
|
+
:class="alignClass(col.align)"
|
|
51
|
+
>
|
|
52
|
+
<slot name="cell" :row="row" :column="col" :value="row[col.key]">
|
|
53
|
+
{{ row[col.key] }}
|
|
54
|
+
</slot>
|
|
55
|
+
</th>
|
|
56
|
+
<td
|
|
57
|
+
v-else
|
|
58
|
+
class="px-5 py-4"
|
|
59
|
+
:class="[
|
|
60
|
+
alignClass(col.align),
|
|
61
|
+
col.highlight
|
|
62
|
+
? 'bg-primary-50/50 text-gray-700 dark:bg-primary-400/5 dark:text-gray-200'
|
|
63
|
+
: 'text-gray-600 dark:text-gray-400',
|
|
64
|
+
]"
|
|
65
|
+
>
|
|
66
|
+
<slot name="cell" :row="row" :column="col" :value="row[col.key]">
|
|
67
|
+
<span :class="col.icon ? 'flex items-start gap-2' : ''">
|
|
68
|
+
<UiIcon
|
|
69
|
+
v-if="col.icon"
|
|
70
|
+
:name="col.icon"
|
|
71
|
+
class="mt-0.5 size-4 shrink-0"
|
|
72
|
+
:class="
|
|
73
|
+
col.highlight
|
|
74
|
+
? 'text-success-600 dark:text-success-400'
|
|
75
|
+
: 'text-gray-400 dark:text-gray-500'
|
|
76
|
+
"
|
|
77
|
+
/>
|
|
78
|
+
{{ row[col.key] }}
|
|
79
|
+
</span>
|
|
80
|
+
</slot>
|
|
81
|
+
</td>
|
|
82
|
+
</template>
|
|
83
|
+
</tr>
|
|
84
|
+
</tbody>
|
|
85
|
+
</table>
|
|
86
|
+
</div>
|
|
87
|
+
</template>
|
|
88
|
+
|
|
89
|
+
<script setup>
|
|
90
|
+
/**
|
|
91
|
+
* UiTable — a data table with sensible defaults, and a built-in comparison mode.
|
|
92
|
+
*
|
|
93
|
+
* Drive it with `columns` and `rows`: each column names a `key`, and each row
|
|
94
|
+
* is an object keyed by those column keys. It renders a real, accessible
|
|
95
|
+
* `<table>` (`<caption>`, `scope="col"` headers) that scrolls horizontally on
|
|
96
|
+
* narrow screens rather than crushing its columns.
|
|
97
|
+
*
|
|
98
|
+
* **Comparison** is just a configuration, not a separate component: mark the
|
|
99
|
+
* label column `header: true` (so it renders as a `<th scope="row">`), give the
|
|
100
|
+
* column you want to feature `highlight: true` (accent tint), and hand each
|
|
101
|
+
* 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.
|
|
104
|
+
*
|
|
105
|
+
* @example A plain data table
|
|
106
|
+
* <UiTable
|
|
107
|
+
* caption="Team"
|
|
108
|
+
* :columns="[
|
|
109
|
+
* { key: 'name', label: 'Name' },
|
|
110
|
+
* { key: 'role', label: 'Role' },
|
|
111
|
+
* { key: 'commits', label: 'Commits', align: 'right' },
|
|
112
|
+
* ]"
|
|
113
|
+
* :rows="[
|
|
114
|
+
* { name: 'Ada Lovelace', role: 'Engineer', commits: 128 },
|
|
115
|
+
* { name: 'Grace Hopper', role: 'Lead', commits: 342 },
|
|
116
|
+
* ]"
|
|
117
|
+
* />
|
|
118
|
+
*
|
|
119
|
+
* @example A comparison table (the old UiComparisonTable, now a configuration)
|
|
120
|
+
* <UiTable
|
|
121
|
+
* caption="How Numori compares"
|
|
122
|
+
* :columns="[
|
|
123
|
+
* { key: 'feature', label: 'Feature', header: true },
|
|
124
|
+
* { key: 'numori', label: 'Numori', highlight: true, icon: 'mdi:check-circle' },
|
|
125
|
+
* { key: 'usual', label: 'The usual', icon: 'mdi:minus-circle-outline' },
|
|
126
|
+
* ]"
|
|
127
|
+
* :rows="[
|
|
128
|
+
* { feature: 'Open source', numori: 'Entire ecosystem', usual: 'The client, sometimes' },
|
|
129
|
+
* ]"
|
|
130
|
+
* />
|
|
131
|
+
*
|
|
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>
|
|
141
|
+
*
|
|
142
|
+
* @slot caption — Rich caption content (overrides the `caption` prop).
|
|
143
|
+
* @slot cell — Custom cell content. Scope: `{ row, column, value }`.
|
|
144
|
+
*/
|
|
145
|
+
import UiIcon from '../icons/Icon.vue'
|
|
146
|
+
|
|
147
|
+
defineProps({
|
|
148
|
+
/**
|
|
149
|
+
* Column definitions, left to right. Each is
|
|
150
|
+
* `{ key, label?, align?, header?, highlight?, icon?, width? }`:
|
|
151
|
+
* - `key` — the row field this column reads.
|
|
152
|
+
* - `label` — the column heading.
|
|
153
|
+
* - `align` — `'left'` (default) | `'center'` | `'right'`.
|
|
154
|
+
* - `header` — render this column's cells as row headers (`<th scope="row">`).
|
|
155
|
+
* - `highlight` — accent-tint the column (the featured column in a comparison).
|
|
156
|
+
* - `icon` — MDI icon shown before each value in the column.
|
|
157
|
+
* - `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 }>}
|
|
159
|
+
*/
|
|
160
|
+
columns: { type: Array, required: true },
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Row objects, each keyed by the column `key`s.
|
|
164
|
+
* @type {Array<Record<string, unknown>>}
|
|
165
|
+
*/
|
|
166
|
+
rows: { type: Array, required: true },
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Table caption. Rendered as a real `<caption>` for accessibility; visible by
|
|
170
|
+
* default, or visually hidden with `hideCaption`.
|
|
171
|
+
* @type {string}
|
|
172
|
+
* @default ''
|
|
173
|
+
*/
|
|
174
|
+
caption: { type: String, default: '' },
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Keep the caption for assistive technology but hide it visually.
|
|
178
|
+
* @type {boolean}
|
|
179
|
+
* @default false
|
|
180
|
+
*/
|
|
181
|
+
hideCaption: { type: Boolean, default: false },
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Row field used as the `v-for` key; falls back to the row index.
|
|
185
|
+
* @type {string}
|
|
186
|
+
* @default 'key'
|
|
187
|
+
*/
|
|
188
|
+
rowKey: { type: String, default: 'key' },
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
const alignClass = (align) =>
|
|
192
|
+
align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left'
|
|
193
|
+
</script>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<UiButton
|
|
3
|
+
variant="ghost"
|
|
4
|
+
color="gray"
|
|
5
|
+
icon-only
|
|
6
|
+
:title="label"
|
|
7
|
+
:aria-label="label"
|
|
8
|
+
class="group"
|
|
9
|
+
@click="emit('toggle')"
|
|
10
|
+
>
|
|
11
|
+
<!--
|
|
12
|
+
The two glyphs occupy the same grid cell and cross-fade with a quarter
|
|
13
|
+
turn, so flipping the theme reads as one control turning over rather than
|
|
14
|
+
an icon being swapped out.
|
|
15
|
+
-->
|
|
16
|
+
<span class="grid size-5 place-items-center">
|
|
17
|
+
<UiIcon
|
|
18
|
+
name="mdi:weather-sunny"
|
|
19
|
+
class="col-start-1 row-start-1 size-5 transition-all duration-300"
|
|
20
|
+
:class="isDark ? 'rotate-0 scale-100 opacity-100' : '-rotate-90 scale-50 opacity-0'"
|
|
21
|
+
/>
|
|
22
|
+
<UiIcon
|
|
23
|
+
name="mdi:weather-night"
|
|
24
|
+
class="col-start-1 row-start-1 size-5 transition-all duration-300"
|
|
25
|
+
:class="isDark ? 'rotate-90 scale-50 opacity-0' : 'rotate-0 scale-100 opacity-100'"
|
|
26
|
+
/>
|
|
27
|
+
</span>
|
|
28
|
+
</UiButton>
|
|
29
|
+
</template>
|
|
30
|
+
|
|
31
|
+
<script setup>
|
|
32
|
+
/**
|
|
33
|
+
* UiThemeToggle — an icon button that flips between light and dark.
|
|
34
|
+
*
|
|
35
|
+
* Deliberately presentational and stateless. Numori UI's dark mode is a `.dark`
|
|
36
|
+
* class on `<html>`, but *how* that class gets toggled and persisted is the
|
|
37
|
+
* host's decision — `@nuxtjs/color-mode`, VueUse's `useDark`, or two hand-written
|
|
38
|
+
* lines. So this component owns none of that: it takes the current state as
|
|
39
|
+
* `isDark` and emits `toggle`, and the parent does the flip.
|
|
40
|
+
*
|
|
41
|
+
* Because it is icon-only it carries both `title` (for pointer users) and
|
|
42
|
+
* `aria-label` (an icon has no accessible name otherwise), both from `label`.
|
|
43
|
+
* The sun and moon share one grid cell and cross-fade with a rotation.
|
|
44
|
+
*
|
|
45
|
+
* Under SSR the rendered theme is not known until the client reads the stored
|
|
46
|
+
* preference, so wrap it in whatever your framework uses to defer to the client
|
|
47
|
+
* (Nuxt's `<ClientOnly>`, for instance) if you render on the server, to avoid a
|
|
48
|
+
* hydration mismatch on the icon.
|
|
49
|
+
*
|
|
50
|
+
* @example With @nuxtjs/color-mode
|
|
51
|
+
* <script setup>
|
|
52
|
+
* const colorMode = useColorMode()
|
|
53
|
+
* const isDark = computed(() => colorMode.value === 'dark')
|
|
54
|
+
* const toggle = () => { colorMode.preference = isDark.value ? 'light' : 'dark' }
|
|
55
|
+
* <\/script>
|
|
56
|
+
*
|
|
57
|
+
* <UiThemeToggle :is-dark="isDark" :label="isDark ? 'Switch to light' : 'Switch to dark'"
|
|
58
|
+
* @toggle="toggle" />
|
|
59
|
+
*/
|
|
60
|
+
import UiButton from './Button.vue'
|
|
61
|
+
import UiIcon from '../icons/Icon.vue'
|
|
62
|
+
|
|
63
|
+
defineProps({
|
|
64
|
+
/**
|
|
65
|
+
* Whether the dark theme is currently active. Drives which glyph is shown.
|
|
66
|
+
* @type {boolean}
|
|
67
|
+
* @default false
|
|
68
|
+
*/
|
|
69
|
+
isDark: { type: Boolean, default: false },
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Accessible name and hover tooltip. Should describe the action the control
|
|
73
|
+
* performs, e.g. "Switch to dark mode".
|
|
74
|
+
* @type {string}
|
|
75
|
+
* @default 'Toggle theme'
|
|
76
|
+
*/
|
|
77
|
+
label: { type: String, default: 'Toggle theme' },
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const emit = defineEmits(['toggle'])
|
|
81
|
+
</script>
|