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,102 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="mergedClasses" v-bind="restAttrs">
|
|
3
|
+
<div v-if="$slots.breadcrumb" class="mb-3">
|
|
4
|
+
<slot name="breadcrumb" />
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<div class="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
|
8
|
+
<div class="min-w-0 flex-1">
|
|
9
|
+
<div class="flex flex-wrap items-center gap-x-3 gap-y-2">
|
|
10
|
+
<component
|
|
11
|
+
:is="headingTag"
|
|
12
|
+
class="min-w-0 truncate text-2xl font-semibold tracking-tight text-gray-900 dark:text-gray-50"
|
|
13
|
+
>
|
|
14
|
+
<slot name="title">{{ title }}</slot>
|
|
15
|
+
</component>
|
|
16
|
+
<slot name="meta" />
|
|
17
|
+
</div>
|
|
18
|
+
<p
|
|
19
|
+
v-if="description || $slots.description"
|
|
20
|
+
class="mt-1 max-w-3xl text-sm text-gray-600 dark:text-gray-400"
|
|
21
|
+
>
|
|
22
|
+
<slot name="description">{{ description }}</slot>
|
|
23
|
+
</p>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div v-if="$slots.actions" class="flex shrink-0 flex-wrap items-center gap-2">
|
|
27
|
+
<slot name="actions" />
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<script setup>
|
|
34
|
+
/**
|
|
35
|
+
* UiPageHeader — the title block at the top of an application page: optional
|
|
36
|
+
* breadcrumb, heading, badges, a line of description and the page's actions.
|
|
37
|
+
*
|
|
38
|
+
* Actions sit to the right on wide screens and wrap below the title on narrow
|
|
39
|
+
* ones. The heading is an `<h1>` by default; lower it with `level` when the
|
|
40
|
+
* header sits inside a section that already has one.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <UiPageHeader title="Apps" description="Every application that syncs through this service.">
|
|
44
|
+
* <template #actions>
|
|
45
|
+
* <UiButton><UiIcon name="mdi:plus" class="size-4" />New app</UiButton>
|
|
46
|
+
* </template>
|
|
47
|
+
* </UiPageHeader>
|
|
48
|
+
*
|
|
49
|
+
* @example With breadcrumb and a status badge
|
|
50
|
+
* <UiPageHeader title="notes">
|
|
51
|
+
* <template #breadcrumb><UiBreadcrumb :items="crumbs" /></template>
|
|
52
|
+
* <template #meta><UiBadge color="green">Active</UiBadge></template>
|
|
53
|
+
* </UiPageHeader>
|
|
54
|
+
*
|
|
55
|
+
* @slot title — Rich title content (overrides `title`).
|
|
56
|
+
* @slot meta — Inline content after the title, such as badges.
|
|
57
|
+
* @slot description — Rich description (overrides `description`).
|
|
58
|
+
* @slot breadcrumb — Content above the title, usually a `UiBreadcrumb`.
|
|
59
|
+
* @slot actions — Buttons for the page's primary actions.
|
|
60
|
+
*/
|
|
61
|
+
import { computed } from 'vue'
|
|
62
|
+
import { useMergedClasses } from '../composables/useMergedClasses.js'
|
|
63
|
+
|
|
64
|
+
const props = defineProps({
|
|
65
|
+
/**
|
|
66
|
+
* Page title.
|
|
67
|
+
* @type {string}
|
|
68
|
+
* @default ''
|
|
69
|
+
*/
|
|
70
|
+
title: { type: String, default: '' },
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* One line explaining the page.
|
|
74
|
+
* @type {string}
|
|
75
|
+
* @default ''
|
|
76
|
+
*/
|
|
77
|
+
description: { type: String, default: '' },
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Heading level of the title.
|
|
81
|
+
* @type {number}
|
|
82
|
+
* @default 1
|
|
83
|
+
* @values 1 | 2 | 3
|
|
84
|
+
*/
|
|
85
|
+
level: { type: Number, default: 1 },
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Draw a rule below the header.
|
|
89
|
+
* @type {boolean}
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
bordered: { type: Boolean, default: false },
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
defineOptions({ inheritAttrs: false })
|
|
96
|
+
|
|
97
|
+
const headingTag = computed(() => `h${[1, 2, 3].includes(props.level) ? props.level : 1}`)
|
|
98
|
+
|
|
99
|
+
const { mergedClasses, restAttrs } = useMergedClasses(() =>
|
|
100
|
+
props.bordered ? 'mb-6 border-b border-gray-200 pb-5 dark:border-gray-800' : 'mb-6',
|
|
101
|
+
)
|
|
102
|
+
</script>
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<nav :aria-label="ariaLabel" class="flex flex-col items-center justify-between gap-3 sm:flex-row">
|
|
3
|
+
<p v-if="showSummary" class="text-sm text-gray-500 tabular-nums dark:text-gray-400">
|
|
4
|
+
{{ summaryText }}
|
|
5
|
+
</p>
|
|
6
|
+
<span v-else />
|
|
7
|
+
|
|
8
|
+
<ul v-if="pageCount > 1" class="flex items-center gap-1">
|
|
9
|
+
<li>
|
|
10
|
+
<button
|
|
11
|
+
type="button"
|
|
12
|
+
:class="navClass"
|
|
13
|
+
:disabled="current <= 1"
|
|
14
|
+
:aria-label="previousLabel"
|
|
15
|
+
@click="go(current - 1)"
|
|
16
|
+
>
|
|
17
|
+
<UiIcon name="mdi:chevron-left" class="size-4" />
|
|
18
|
+
</button>
|
|
19
|
+
</li>
|
|
20
|
+
<li
|
|
21
|
+
v-for="item in items"
|
|
22
|
+
:key="item.key"
|
|
23
|
+
:class="item.page === current ? '' : 'hidden sm:block'"
|
|
24
|
+
>
|
|
25
|
+
<span
|
|
26
|
+
v-if="item.type === 'gap'"
|
|
27
|
+
class="inline-flex size-9 items-center justify-center text-sm text-gray-400 dark:text-gray-500"
|
|
28
|
+
aria-hidden="true"
|
|
29
|
+
>…</span
|
|
30
|
+
>
|
|
31
|
+
<button
|
|
32
|
+
v-else
|
|
33
|
+
type="button"
|
|
34
|
+
:class="pageClass(item.page)"
|
|
35
|
+
:aria-current="item.page === current ? 'page' : undefined"
|
|
36
|
+
:aria-label="formatPageLabel(item.page)"
|
|
37
|
+
@click="go(item.page)"
|
|
38
|
+
>
|
|
39
|
+
{{ item.page }}
|
|
40
|
+
</button>
|
|
41
|
+
</li>
|
|
42
|
+
<li>
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
:class="navClass"
|
|
46
|
+
:disabled="current >= pageCount"
|
|
47
|
+
:aria-label="nextLabel"
|
|
48
|
+
@click="go(current + 1)"
|
|
49
|
+
>
|
|
50
|
+
<UiIcon name="mdi:chevron-right" class="size-4" />
|
|
51
|
+
</button>
|
|
52
|
+
</li>
|
|
53
|
+
</ul>
|
|
54
|
+
</nav>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<script setup>
|
|
58
|
+
/**
|
|
59
|
+
* UiPagination — page controls for a long list, with a "21–40 of 134" summary.
|
|
60
|
+
*
|
|
61
|
+
* Shows the first and last page, the current page and `siblings` pages either
|
|
62
|
+
* side of it, collapsing the rest into gaps, so the control stays the same
|
|
63
|
+
* width however many pages there are. On narrow screens only the current page
|
|
64
|
+
* and the arrows remain.
|
|
65
|
+
*
|
|
66
|
+
* Bind `v-model:page`; the component never fetches anything. All visible text
|
|
67
|
+
* is configurable for localisation.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* <UiPagination v-model:page="page" :page-size="20" :total="134" />
|
|
71
|
+
*
|
|
72
|
+
* @example Localised
|
|
73
|
+
* <UiPagination
|
|
74
|
+
* v-model:page="page"
|
|
75
|
+
* :total="total"
|
|
76
|
+
* previous-label="Anterior"
|
|
77
|
+
* next-label="Siguiente"
|
|
78
|
+
* :format-summary="(from, to, total) => `${from}–${to} de ${total}`"
|
|
79
|
+
* />
|
|
80
|
+
*
|
|
81
|
+
* @emits {number} update:page — The requested page (1-based).
|
|
82
|
+
*/
|
|
83
|
+
import { computed } from 'vue'
|
|
84
|
+
import UiIcon from '../icons/Icon.vue'
|
|
85
|
+
|
|
86
|
+
const props = defineProps({
|
|
87
|
+
/**
|
|
88
|
+
* Current page, 1-based.
|
|
89
|
+
* @type {number}
|
|
90
|
+
* @default 1
|
|
91
|
+
*/
|
|
92
|
+
page: { type: Number, default: 1 },
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Items per page.
|
|
96
|
+
* @type {number}
|
|
97
|
+
* @default 20
|
|
98
|
+
*/
|
|
99
|
+
pageSize: { type: Number, default: 20 },
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Total number of items.
|
|
103
|
+
* @type {number}
|
|
104
|
+
*/
|
|
105
|
+
total: { type: Number, required: true },
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Pages shown either side of the current one.
|
|
109
|
+
* @type {number}
|
|
110
|
+
* @default 1
|
|
111
|
+
*/
|
|
112
|
+
siblings: { type: Number, default: 1 },
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Show the "from–to of total" summary.
|
|
116
|
+
* @type {boolean}
|
|
117
|
+
* @default true
|
|
118
|
+
*/
|
|
119
|
+
showSummary: { type: Boolean, default: true },
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Builds the summary text from the 1-based range shown and the total.
|
|
123
|
+
* @type {(from: number, to: number, total: number) => string}
|
|
124
|
+
*/
|
|
125
|
+
formatSummary: {
|
|
126
|
+
type: Function,
|
|
127
|
+
default: (from, to, total) => (total === 0 ? 'No items' : `${from}–${to} of ${total}`),
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Builds each page button's accessible label.
|
|
132
|
+
* @type {(page: number) => string}
|
|
133
|
+
*/
|
|
134
|
+
formatPageLabel: { type: Function, default: (page) => `Page ${page}` },
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Accessible label of the previous button.
|
|
138
|
+
* @type {string}
|
|
139
|
+
* @default 'Previous page'
|
|
140
|
+
*/
|
|
141
|
+
previousLabel: { type: String, default: 'Previous page' },
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Accessible label of the next button.
|
|
145
|
+
* @type {string}
|
|
146
|
+
* @default 'Next page'
|
|
147
|
+
*/
|
|
148
|
+
nextLabel: { type: String, default: 'Next page' },
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Accessible name of the navigation landmark.
|
|
152
|
+
* @type {string}
|
|
153
|
+
* @default 'Pagination'
|
|
154
|
+
*/
|
|
155
|
+
ariaLabel: { type: String, default: 'Pagination' },
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const emit = defineEmits(['update:page'])
|
|
159
|
+
|
|
160
|
+
const pageCount = computed(() =>
|
|
161
|
+
Math.max(1, Math.ceil(Math.max(0, props.total) / Math.max(1, props.pageSize))),
|
|
162
|
+
)
|
|
163
|
+
const current = computed(() => Math.min(Math.max(1, props.page), pageCount.value))
|
|
164
|
+
|
|
165
|
+
const summaryText = computed(() => {
|
|
166
|
+
const total = Math.max(0, props.total)
|
|
167
|
+
const from = total === 0 ? 0 : (current.value - 1) * props.pageSize + 1
|
|
168
|
+
const to = Math.min(total, current.value * props.pageSize)
|
|
169
|
+
return props.formatSummary(from, to, total)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
/** First, last, current ± siblings, with gaps where pages are skipped. */
|
|
173
|
+
const items = computed(() => {
|
|
174
|
+
const last = pageCount.value
|
|
175
|
+
const start = Math.max(2, current.value - props.siblings)
|
|
176
|
+
const end = Math.min(last - 1, current.value + props.siblings)
|
|
177
|
+
const out = [{ type: 'page', page: 1, key: 'p1' }]
|
|
178
|
+
if (start > 2) out.push({ type: 'gap', key: 'gap-start' })
|
|
179
|
+
for (let p = start; p <= end; p++) out.push({ type: 'page', page: p, key: `p${p}` })
|
|
180
|
+
if (end < last - 1) out.push({ type: 'gap', key: 'gap-end' })
|
|
181
|
+
if (last > 1) out.push({ type: 'page', page: last, key: `p${last}` })
|
|
182
|
+
return out
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
function go(page) {
|
|
186
|
+
const next = Math.min(Math.max(1, page), pageCount.value)
|
|
187
|
+
if (next !== current.value) emit('update:page', next)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const buttonBase =
|
|
191
|
+
'inline-flex size-9 items-center justify-center rounded-lg text-sm font-medium tabular-nums transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-500'
|
|
192
|
+
|
|
193
|
+
const navClass = `${buttonBase} text-gray-600 hover:bg-gray-100 hover:text-gray-900 disabled:cursor-not-allowed disabled:opacity-40 disabled:hover:bg-transparent dark:text-gray-400 dark:hover:bg-gray-800 dark:hover:text-gray-100`
|
|
194
|
+
|
|
195
|
+
const pageClass = (page) =>
|
|
196
|
+
page === current.value
|
|
197
|
+
? `${buttonBase} bg-primary-600 text-white dark:bg-primary-500 dark:text-gray-950`
|
|
198
|
+
: `${buttonBase} text-gray-700 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-800`
|
|
199
|
+
</script>
|
package/src/components/Popup.vue
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
<div
|
|
15
15
|
v-if="show"
|
|
16
16
|
ref="panelRef"
|
|
17
|
-
class="absolute
|
|
18
|
-
:class="[width, panelZ]"
|
|
17
|
+
class="absolute py-1"
|
|
18
|
+
:class="[MENU_PANEL_CLASS, width, panelZ]"
|
|
19
19
|
:style="positionStyle"
|
|
20
20
|
>
|
|
21
21
|
<slot />
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
* @slot default — Popup content
|
|
49
49
|
*/
|
|
50
50
|
import { ref, computed, watch, nextTick } from 'vue'
|
|
51
|
+
import { MENU_PANEL_CLASS } from '../internal/menu.js'
|
|
51
52
|
const props = defineProps({
|
|
52
53
|
/**
|
|
53
54
|
* Controls popup visibility.
|
|
@@ -107,6 +108,9 @@ const clampedPos = ref({ left: 0, top: 0 })
|
|
|
107
108
|
const positionStyle = computed(() => ({
|
|
108
109
|
left: clampedPos.value.left + 'px',
|
|
109
110
|
top: clampedPos.value.top + 'px',
|
|
111
|
+
// Inline (not a Tailwind class) so the popup reliably scales in from its
|
|
112
|
+
// top-left corner rather than drifting in from its centre.
|
|
113
|
+
transformOrigin: 'top left',
|
|
110
114
|
}))
|
|
111
115
|
|
|
112
116
|
// Clamp the panel position so it stays within the viewport (8px margin)
|
package/src/components/Radio.vue
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* <UiRadio v-model="selected" value="b" name="choice" />
|
|
24
24
|
*/
|
|
25
25
|
import { computed } from 'vue'
|
|
26
|
+
import { checkableSizeClass } from '../internal/controlSizes.js'
|
|
26
27
|
const props = defineProps({
|
|
27
28
|
modelValue: { type: [String, Number, Boolean], default: null },
|
|
28
29
|
value: { type: [String, Number, Boolean], required: true },
|
|
@@ -33,16 +34,7 @@ const props = defineProps({
|
|
|
33
34
|
|
|
34
35
|
const emit = defineEmits(['update:modelValue'])
|
|
35
36
|
|
|
36
|
-
const sizeClass = computed(() =>
|
|
37
|
-
switch (props.size) {
|
|
38
|
-
case 'sm':
|
|
39
|
-
return 'w-3.5 h-3.5'
|
|
40
|
-
case 'lg':
|
|
41
|
-
return 'w-5 h-5'
|
|
42
|
-
default:
|
|
43
|
-
return 'w-4 h-4'
|
|
44
|
-
}
|
|
45
|
-
})
|
|
37
|
+
const sizeClass = computed(() => checkableSizeClass(props.size))
|
|
46
38
|
|
|
47
39
|
function onChange() {
|
|
48
40
|
emit('update:modelValue', props.value)
|
|
@@ -2,40 +2,43 @@
|
|
|
2
2
|
<div
|
|
3
3
|
role="group"
|
|
4
4
|
:aria-label="ariaLabel"
|
|
5
|
-
|
|
6
|
-
:
|
|
7
|
-
|
|
5
|
+
:aria-labelledby="ariaLabel ? undefined : field?.labelId"
|
|
6
|
+
:aria-describedby="field?.describedBy.value"
|
|
7
|
+
class="relative p-1"
|
|
8
|
+
:class="[
|
|
9
|
+
block ? 'grid w-full' : 'inline-grid',
|
|
10
|
+
radiusClass,
|
|
11
|
+
'border border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-900',
|
|
12
|
+
]"
|
|
13
|
+
:style="gridStyle"
|
|
8
14
|
>
|
|
9
15
|
<!--
|
|
10
|
-
A single
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
A single indicator slides between segments, so changing the selection
|
|
17
|
+
animates in every variant. Segments are equal-width grid columns, so the
|
|
18
|
+
indicator is one column wide and translates by whole columns. The variant
|
|
19
|
+
only changes how the indicator looks (accent fill vs raised surface); the
|
|
20
|
+
sliding mechanism is shared.
|
|
15
21
|
-->
|
|
16
22
|
<span
|
|
17
23
|
aria-hidden="true"
|
|
18
|
-
class="pointer-events-none absolute bottom-1 left-1 top-1
|
|
19
|
-
:class="
|
|
20
|
-
:style="
|
|
24
|
+
class="pointer-events-none absolute bottom-1 left-1 top-1 shadow-sm transition-transform duration-300 ease-out motion-reduce:transition-none"
|
|
25
|
+
:class="[radiusClass, indicatorClass]"
|
|
26
|
+
:style="indicatorStyle"
|
|
21
27
|
/>
|
|
22
28
|
|
|
23
29
|
<button
|
|
24
|
-
v-for="
|
|
30
|
+
v-for="option in options"
|
|
25
31
|
:key="option.value"
|
|
26
32
|
type="button"
|
|
27
33
|
:aria-pressed="isActive(option) ? 'true' : 'false'"
|
|
28
34
|
:disabled="option.disabled"
|
|
35
|
+
:title="option.title || undefined"
|
|
29
36
|
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)"
|
|
37
|
+
:class="[buttonSizeClass, radiusClass, isActive(option) ? activeTextClass : idleTextClass]"
|
|
38
|
+
@click="select(option)"
|
|
36
39
|
>
|
|
37
40
|
<UiIcon v-if="option.icon" :name="option.icon" :class="iconSizeClass" />
|
|
38
|
-
{{ option.label }}
|
|
41
|
+
<span v-if="option.label">{{ option.label }}</span>
|
|
39
42
|
</button>
|
|
40
43
|
</div>
|
|
41
44
|
</template>
|
|
@@ -43,17 +46,32 @@
|
|
|
43
46
|
<script setup>
|
|
44
47
|
/**
|
|
45
48
|
* UiSegmented — a segmented control: pick one of a few named options from a row
|
|
46
|
-
* of
|
|
49
|
+
* of segments, with an indicator that slides to the active choice.
|
|
47
50
|
*
|
|
48
51
|
* This is a set of toggle buttons (`role="group"` + `aria-pressed`), not a
|
|
49
52
|
* switch, because the choice is between named options rather than on/off — "the
|
|
50
53
|
* second option is off" is not something a screen reader should say. Segments
|
|
51
|
-
* are equal width so the
|
|
54
|
+
* are equal width so the indicator can slide by whole columns, and the slide
|
|
55
|
+
* animates in both variants.
|
|
56
|
+
*
|
|
57
|
+
* The `variant` values match `UiButton`'s — `solid`, `outline`, `ghost` — so a
|
|
58
|
+
* segmented control sits alongside buttons as part of one visual family. The
|
|
59
|
+
* indicator slides (and animates) to the active choice in every variant.
|
|
60
|
+
*
|
|
61
|
+
* - `variant="solid"` (default) — a filled accent indicator; the active label
|
|
62
|
+
* goes white. Like a solid button.
|
|
63
|
+
* - `variant="outline"` — a bordered accent indicator; the active label takes
|
|
64
|
+
* the accent colour. Like an outline button.
|
|
65
|
+
* - `variant="ghost"` — a soft tinted indicator; the active label takes the
|
|
66
|
+
* accent colour. Like a ghost button.
|
|
67
|
+
*
|
|
68
|
+
* `shape` controls the corners — `pill`, `round`, or `square` (matching
|
|
69
|
+
* `UiButton`) — and the indicator matches the track's radius.
|
|
52
70
|
*
|
|
53
71
|
* For an on/off control use `UiToggle`; for many options or a searchable list
|
|
54
72
|
* use `UiSelect`.
|
|
55
73
|
*
|
|
56
|
-
* @example Billing period
|
|
74
|
+
* @example Billing period (solid, the default)
|
|
57
75
|
* <UiSegmented
|
|
58
76
|
* v-model="billing"
|
|
59
77
|
* :options="[
|
|
@@ -63,14 +81,26 @@
|
|
|
63
81
|
* aria-label="Billing period"
|
|
64
82
|
* />
|
|
65
83
|
*
|
|
66
|
-
* @example
|
|
67
|
-
* <
|
|
68
|
-
*
|
|
84
|
+
* @example Icon toolbar (outline, square corners)
|
|
85
|
+
* <UiSegmented
|
|
86
|
+
* v-model="view"
|
|
87
|
+
* variant="outline"
|
|
88
|
+
* shape="square"
|
|
89
|
+
* :options="[
|
|
90
|
+
* { value: 'grid', icon: 'mdi:view-grid', title: 'Grid' },
|
|
91
|
+
* { value: 'list', icon: 'mdi:view-list', title: 'List' },
|
|
92
|
+
* ]"
|
|
93
|
+
* aria-label="View"
|
|
94
|
+
* />
|
|
95
|
+
*
|
|
96
|
+
* @example Full-width ghost tabs
|
|
97
|
+
* <UiSegmented v-model="tab" variant="ghost" block :options="tabs" />
|
|
69
98
|
*
|
|
70
99
|
* @emits {string|number} update:modelValue — the chosen option's `value`
|
|
71
100
|
*/
|
|
72
101
|
import { computed } from 'vue'
|
|
73
102
|
import UiIcon from '../icons/Icon.vue'
|
|
103
|
+
import { useFormField } from '../internal/formField.js'
|
|
74
104
|
|
|
75
105
|
const props = defineProps({
|
|
76
106
|
/**
|
|
@@ -81,11 +111,25 @@ const props = defineProps({
|
|
|
81
111
|
modelValue: { type: [String, Number], default: undefined },
|
|
82
112
|
|
|
83
113
|
/**
|
|
84
|
-
* The options. Each is `{ value, label
|
|
85
|
-
*
|
|
114
|
+
* The options. Each is `{ value, label?, icon?, disabled?, title? }`. Provide
|
|
115
|
+
* `label` for text segments, `icon` for icon-only segments, or both. `title`
|
|
116
|
+
* sets the native tooltip (useful for icon-only segments).
|
|
117
|
+
* @type {Array<{ value: string|number, label?: string, icon?: string, disabled?: boolean, title?: string }>}
|
|
86
118
|
*/
|
|
87
119
|
options: { type: Array, required: true },
|
|
88
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Active-segment appearance, mirroring the equivalent `UiButton` variants so
|
|
123
|
+
* the two feel like one family. The sliding indicator animates in every case.
|
|
124
|
+
* - 'solid' — a filled accent indicator; the active label goes white (default).
|
|
125
|
+
* - 'outline' — a bordered accent indicator; the active label takes the accent.
|
|
126
|
+
* - 'ghost' — a soft tinted indicator; the active label takes the accent.
|
|
127
|
+
* @type {string}
|
|
128
|
+
* @default 'solid'
|
|
129
|
+
* @values 'solid' | 'outline' | 'ghost'
|
|
130
|
+
*/
|
|
131
|
+
variant: { type: String, default: 'solid' },
|
|
132
|
+
|
|
89
133
|
/**
|
|
90
134
|
* Size preset controlling padding and font size.
|
|
91
135
|
* @type {string}
|
|
@@ -95,13 +139,22 @@ const props = defineProps({
|
|
|
95
139
|
size: { type: String, default: 'md' },
|
|
96
140
|
|
|
97
141
|
/**
|
|
98
|
-
* Corner shape of the track and
|
|
142
|
+
* Corner shape of the track, indicator, and segments. Matches `UiButton`'s
|
|
143
|
+
* `shape` naming.
|
|
99
144
|
* @type {string}
|
|
100
145
|
* @default 'pill'
|
|
101
|
-
* @values 'pill' | '
|
|
146
|
+
* @values 'pill' | 'round' | 'square'
|
|
102
147
|
*/
|
|
103
148
|
shape: { type: String, default: 'pill' },
|
|
104
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Full-width mode — the control fills its container and segments share the
|
|
152
|
+
* width equally.
|
|
153
|
+
* @type {boolean}
|
|
154
|
+
* @default false
|
|
155
|
+
*/
|
|
156
|
+
block: { type: Boolean, default: false },
|
|
157
|
+
|
|
105
158
|
/**
|
|
106
159
|
* Accessible name for the group. Omit if you label it with an external
|
|
107
160
|
* heading via `aria-labelledby` (which falls through to the root).
|
|
@@ -113,6 +166,8 @@ const props = defineProps({
|
|
|
113
166
|
|
|
114
167
|
const emit = defineEmits(['update:modelValue'])
|
|
115
168
|
|
|
169
|
+
const field = useFormField()
|
|
170
|
+
|
|
116
171
|
const count = computed(() => props.options?.length || 1)
|
|
117
172
|
|
|
118
173
|
const isActive = (option) => option.value === props.modelValue
|
|
@@ -122,28 +177,48 @@ const activeIndex = computed(() => {
|
|
|
122
177
|
return i === -1 ? 0 : i
|
|
123
178
|
})
|
|
124
179
|
|
|
125
|
-
function select(option
|
|
180
|
+
function select(option) {
|
|
126
181
|
if (option.disabled) return
|
|
127
182
|
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
183
|
}
|
|
132
184
|
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
185
|
+
const gridStyle = computed(() => ({
|
|
186
|
+
gridTemplateColumns: `repeat(${count.value}, minmax(0, 1fr))`,
|
|
187
|
+
}))
|
|
188
|
+
|
|
189
|
+
// ── Shape ─────────────────────────────────────────────────
|
|
190
|
+
// The track, the sliding indicator, and the segments all share one radius so
|
|
191
|
+
// the indicator's corners match the holder's rather than reading as a tighter
|
|
192
|
+
// (or looser) curve inside it.
|
|
193
|
+
const radiusClass = computed(() => {
|
|
194
|
+
const map = { pill: 'rounded-full', round: 'rounded-lg', square: 'rounded-none' }
|
|
195
|
+
return map[props.shape] ?? map.pill
|
|
196
|
+
})
|
|
136
197
|
|
|
198
|
+
// ── Size ──────────────────────────────────────────────────
|
|
137
199
|
const buttonSizeClass = computed(() =>
|
|
138
200
|
props.size === 'sm' ? 'px-3 py-1 text-xs' : 'px-4 py-1.5 text-sm',
|
|
139
201
|
)
|
|
140
202
|
const iconSizeClass = computed(() => (props.size === 'sm' ? 'size-3.5' : 'size-4'))
|
|
141
203
|
|
|
142
|
-
|
|
204
|
+
// ── Variant: indicator look + active label colour ─────────
|
|
205
|
+
// These mirror UiButton's solid / outline / ghost variants (primary colour) so
|
|
206
|
+
// a segmented control reads as part of the same family as the buttons near it.
|
|
207
|
+
const indicatorClass = computed(() => {
|
|
208
|
+
const map = {
|
|
209
|
+
solid: 'bg-primary-600 shadow-sm',
|
|
210
|
+
outline: 'border border-primary-500',
|
|
211
|
+
ghost: 'bg-primary-50 dark:bg-primary-900/20',
|
|
212
|
+
}
|
|
213
|
+
return map[props.variant] ?? map.solid
|
|
214
|
+
})
|
|
215
|
+
const activeTextClass = computed(() =>
|
|
216
|
+
props.variant === 'solid' ? 'text-white' : 'text-primary-600 dark:text-primary-400',
|
|
217
|
+
)
|
|
143
218
|
const idleTextClass =
|
|
144
219
|
'text-gray-600 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100'
|
|
145
220
|
|
|
146
|
-
const
|
|
221
|
+
const indicatorStyle = computed(() => ({
|
|
147
222
|
// Track padding is p-1 (0.25rem) each side, so the usable width is
|
|
148
223
|
// `100% - 0.5rem`; one segment is that divided by the option count.
|
|
149
224
|
width: `calc((100% - 0.5rem) / ${count.value})`,
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
|
|
20
20
|
<!-- Trigger button: shows selected value, placeholder, or loading spinner -->
|
|
21
21
|
<button
|
|
22
|
+
:id="field?.controlId.value"
|
|
22
23
|
ref="triggerRef"
|
|
23
24
|
type="button"
|
|
25
|
+
:aria-describedby="field?.describedBy.value"
|
|
24
26
|
:disabled="disabled || loading"
|
|
25
27
|
:aria-label="ariaLabel"
|
|
26
28
|
:class="[triggerClasses, disabled || loading ? 'opacity-50 cursor-not-allowed' : '']"
|
|
@@ -64,7 +66,8 @@
|
|
|
64
66
|
<div
|
|
65
67
|
v-show="isOpen"
|
|
66
68
|
ref="panelRef"
|
|
67
|
-
class="fixed z-[60]
|
|
69
|
+
class="fixed z-[60] overflow-hidden"
|
|
70
|
+
:class="MENU_PANEL_CLASS"
|
|
68
71
|
:style="panelStyle"
|
|
69
72
|
>
|
|
70
73
|
<!-- Search input for filtering options -->
|
|
@@ -172,6 +175,8 @@
|
|
|
172
175
|
*/
|
|
173
176
|
import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
174
177
|
import UiIcon from '../icons/Icon.vue'
|
|
178
|
+
import { MENU_PANEL_CLASS } from '../internal/menu.js'
|
|
179
|
+
import { useFormField } from '../internal/formField.js'
|
|
175
180
|
const props = defineProps({
|
|
176
181
|
/**
|
|
177
182
|
* Currently selected value (v-model).
|
|
@@ -256,6 +261,8 @@ const props = defineProps({
|
|
|
256
261
|
|
|
257
262
|
const emit = defineEmits(['update:modelValue'])
|
|
258
263
|
|
|
264
|
+
const field = useFormField()
|
|
265
|
+
|
|
259
266
|
const containerRef = ref(null)
|
|
260
267
|
const triggerRef = ref(null)
|
|
261
268
|
const searchRef = ref(null)
|
|
@@ -275,7 +282,14 @@ const reposition = () => {
|
|
|
275
282
|
const rect = el.getBoundingClientRect()
|
|
276
283
|
const spaceBelow = window.innerHeight - rect.bottom
|
|
277
284
|
const openUp = spaceBelow < 260 && rect.top > spaceBelow
|
|
278
|
-
|
|
285
|
+
// Inline transform-origin (not a Tailwind class) so the panel reliably scales
|
|
286
|
+
// in from the edge nearest the trigger — top when dropping down, bottom when
|
|
287
|
+
// dropping up — instead of drifting in from its centre.
|
|
288
|
+
const style = {
|
|
289
|
+
left: `${rect.left}px`,
|
|
290
|
+
minWidth: `${rect.width}px`,
|
|
291
|
+
transformOrigin: openUp ? 'bottom center' : 'top center',
|
|
292
|
+
}
|
|
279
293
|
if (props.block) style.width = `${rect.width}px`
|
|
280
294
|
if (openUp) style.bottom = `${window.innerHeight - rect.top + 4}px`
|
|
281
295
|
else style.top = `${rect.bottom + 4}px`
|