numori-ui 0.4.0 → 0.6.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 +120 -0
- package/README.md +27 -20
- package/dist/components/AppShell.js +234 -0
- package/dist/components/AppShell.js.map +1 -0
- package/dist/components/Avatar.js +71 -19
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/Checkbox.js +11 -2
- package/dist/components/Checkbox.js.map +1 -1
- package/dist/components/CopyField.js +195 -0
- package/dist/components/CopyField.js.map +1 -0
- package/dist/components/DescriptionList.js +116 -0
- package/dist/components/DescriptionList.js.map +1 -0
- package/dist/components/Dropdown.js +3 -1
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/EmptyState.js +123 -0
- package/dist/components/EmptyState.js.map +1 -0
- package/dist/components/FormField.js +43 -13
- package/dist/components/FormField.js.map +1 -1
- package/dist/components/Input.js +15 -1
- package/dist/components/Input.js.map +1 -1
- package/dist/components/Modal.js +61 -4
- package/dist/components/Modal.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/Prompt.js +11 -6
- package/dist/components/Prompt.js.map +1 -1
- package/dist/components/Segmented.js +10 -2
- package/dist/components/Segmented.js.map +1 -1
- package/dist/components/Select.js +11 -2
- 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/Skeleton.js +122 -0
- package/dist/components/Skeleton.js.map +1 -0
- package/dist/components/SplitPane.js +264 -0
- package/dist/components/SplitPane.js.map +1 -0
- package/dist/components/StatCard.js +185 -0
- package/dist/components/StatCard.js.map +1 -0
- package/dist/components/Table.js +182 -50
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Tabs.js +216 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Toggle.js +11 -2
- package/dist/components/Toggle.js.map +1 -1
- package/dist/components/Tree.js +417 -0
- package/dist/components/Tree.js.map +1 -0
- package/dist/components/VirtualList.js +292 -0
- package/dist/components/VirtualList.js.map +1 -0
- package/dist/components/index.js +105 -81
- package/dist/components/index.js.map +1 -1
- package/dist/icons/mdi.js +12 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +54 -39
- package/dist/index.js.map +1 -1
- package/dist/internal/focusTrap.js +163 -0
- package/dist/internal/focusTrap.js.map +1 -0
- package/dist/internal/formField.js +26 -0
- package/dist/internal/formField.js.map +1 -0
- package/dist/manifest.js +16 -1
- package/dist/manifest.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AppShell.vue +231 -0
- package/src/components/Avatar.vue +69 -18
- package/src/components/Checkbox.vue +5 -0
- package/src/components/CopyField.vue +178 -0
- package/src/components/DescriptionList.vue +114 -0
- package/src/components/Dropdown.vue +4 -1
- package/src/components/EmptyState.vue +107 -0
- package/src/components/FormField.vue +37 -4
- package/src/components/Input.vue +9 -0
- package/src/components/Modal.vue +51 -3
- package/src/components/PageHeader.vue +102 -0
- package/src/components/Pagination.vue +199 -0
- package/src/components/Prompt.vue +14 -3
- package/src/components/Segmented.vue +5 -0
- package/src/components/Select.vue +6 -1
- package/src/components/Sidebar.vue +61 -0
- package/src/components/SidebarGroup.vue +43 -0
- package/src/components/SidebarItem.vue +159 -0
- package/src/components/Skeleton.vue +91 -0
- package/src/components/SplitPane.vue +264 -0
- package/src/components/StatCard.vue +165 -0
- package/src/components/Table.vue +148 -18
- package/src/components/Tabs.vue +217 -0
- package/src/components/Toggle.vue +5 -0
- package/src/components/Tree.vue +428 -0
- package/src/components/VirtualList.vue +250 -0
- package/src/components/index.js +45 -6
- package/src/icons/mdi.js +12 -0
- package/src/internal/focusTrap.js +185 -0
- package/src/internal/formField.js +23 -0
- package/src/manifest.js +15 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<dl :class="mergedClasses" v-bind="restAttrs">
|
|
3
|
+
<div v-for="(item, index) in items" :key="item.key ?? item.label ?? index" :class="rowClass">
|
|
4
|
+
<dt class="text-sm font-medium text-gray-500 dark:text-gray-400">
|
|
5
|
+
{{ item.label }}
|
|
6
|
+
<span
|
|
7
|
+
v-if="item.hint"
|
|
8
|
+
class="mt-0.5 block text-xs font-normal text-gray-400 dark:text-gray-500"
|
|
9
|
+
>{{ item.hint }}</span
|
|
10
|
+
>
|
|
11
|
+
</dt>
|
|
12
|
+
<dd
|
|
13
|
+
class="min-w-0 text-sm text-gray-900 dark:text-gray-100"
|
|
14
|
+
:class="[
|
|
15
|
+
item.mono ? 'font-mono text-[13px] break-all' : 'break-words',
|
|
16
|
+
layout === 'inline' ? 'mt-1 sm:col-span-2 sm:mt-0' : 'mt-1',
|
|
17
|
+
]"
|
|
18
|
+
>
|
|
19
|
+
<slot name="value" :item="item" :value="item.value">
|
|
20
|
+
<span v-if="isEmpty(item.value)" class="text-gray-400 dark:text-gray-500">{{
|
|
21
|
+
emptyText
|
|
22
|
+
}}</span>
|
|
23
|
+
<template v-else>{{ item.value }}</template>
|
|
24
|
+
</slot>
|
|
25
|
+
</dd>
|
|
26
|
+
</div>
|
|
27
|
+
</dl>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script setup>
|
|
31
|
+
/**
|
|
32
|
+
* UiDescriptionList — label / value pairs, such as a record's details or a
|
|
33
|
+
* service's settings, rendered as a real `<dl>`.
|
|
34
|
+
*
|
|
35
|
+
* Three layouts:
|
|
36
|
+
* - `inline` (default): label in a narrow left column, value beside it, one
|
|
37
|
+
* pair per row with dividers. Stacks on narrow screens.
|
|
38
|
+
* - `stacked`: label above value, one pair per row.
|
|
39
|
+
* - `grid`: label above value, pairs flowing into two columns.
|
|
40
|
+
*
|
|
41
|
+
* Empty values (`null`, `undefined`, `''`) render `emptyText` so a missing
|
|
42
|
+
* setting reads as deliberate rather than as a rendering bug. Use the `#value`
|
|
43
|
+
* slot to render badges, links or copy fields.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* <UiDescriptionList
|
|
47
|
+
* :items="[
|
|
48
|
+
* { label: 'App id', value: 'notes', mono: true },
|
|
49
|
+
* { label: 'Storage', value: 'postgres' },
|
|
50
|
+
* { label: 'Audience', value: null, hint: 'Optional app/aud claim' },
|
|
51
|
+
* ]"
|
|
52
|
+
* />
|
|
53
|
+
*
|
|
54
|
+
* @example Custom value rendering
|
|
55
|
+
* <UiDescriptionList :items="items">
|
|
56
|
+
* <template #value="{ item, value }">
|
|
57
|
+
* <UiBadge v-if="item.key === 'status'" color="green">{{ value }}</UiBadge>
|
|
58
|
+
* <template v-else>{{ value }}</template>
|
|
59
|
+
* </template>
|
|
60
|
+
* </UiDescriptionList>
|
|
61
|
+
*
|
|
62
|
+
* @slot value — Custom value content. Scope: `{ item, value }`.
|
|
63
|
+
*/
|
|
64
|
+
import { computed } from 'vue'
|
|
65
|
+
import { useMergedClasses } from '../composables/useMergedClasses.js'
|
|
66
|
+
|
|
67
|
+
const props = defineProps({
|
|
68
|
+
/**
|
|
69
|
+
* Pairs to show. Each is `{ label, value, key?, hint?, mono? }`; `mono`
|
|
70
|
+
* renders the value in a monospace font that breaks anywhere (ids, keys).
|
|
71
|
+
* @type {Array<{ label: string, value?: unknown, key?: string, hint?: string, mono?: boolean }>}
|
|
72
|
+
*/
|
|
73
|
+
items: { type: Array, required: true },
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Arrangement of each pair.
|
|
77
|
+
* @type {string}
|
|
78
|
+
* @default 'inline'
|
|
79
|
+
* @values 'inline' | 'stacked' | 'grid'
|
|
80
|
+
*/
|
|
81
|
+
layout: { type: String, default: 'inline' },
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Dividers between rows (ignored by `grid`).
|
|
85
|
+
* @type {boolean}
|
|
86
|
+
* @default true
|
|
87
|
+
*/
|
|
88
|
+
divided: { type: Boolean, default: true },
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Shown in place of an empty value.
|
|
92
|
+
* @type {string}
|
|
93
|
+
* @default '—'
|
|
94
|
+
*/
|
|
95
|
+
emptyText: { type: String, default: '—' },
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
defineOptions({ inheritAttrs: false })
|
|
99
|
+
|
|
100
|
+
const isEmpty = (value) => value === null || value === undefined || value === ''
|
|
101
|
+
|
|
102
|
+
const rowClass = computed(() => {
|
|
103
|
+
if (props.layout === 'grid') return ''
|
|
104
|
+
if (props.layout === 'stacked') return 'py-3 first:pt-0 last:pb-0'
|
|
105
|
+
return 'py-3 first:pt-0 last:pb-0 sm:grid sm:grid-cols-3 sm:gap-4'
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
const internalClasses = computed(() => {
|
|
109
|
+
if (props.layout === 'grid') return 'grid gap-x-6 gap-y-4 sm:grid-cols-2'
|
|
110
|
+
return props.divided ? 'divide-y divide-gray-100 dark:divide-gray-800' : ''
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
const { mergedClasses, restAttrs } = useMergedClasses(() => internalClasses.value)
|
|
114
|
+
</script>
|
|
@@ -155,7 +155,10 @@ const close = () => {
|
|
|
155
155
|
onClickOutside(containerRef, close)
|
|
156
156
|
|
|
157
157
|
useEventListener(globalThis.document, 'keydown', (e) => {
|
|
158
|
-
if (e.key
|
|
158
|
+
if (e.key !== 'Escape' || !isOpen.value) return
|
|
159
|
+
// Claim the key so an enclosing UiModal does not close too.
|
|
160
|
+
e.preventDefault()
|
|
161
|
+
close()
|
|
159
162
|
})
|
|
160
163
|
|
|
161
164
|
defineExpose({ isOpen, toggle, close })
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="mergedClasses" v-bind="restAttrs">
|
|
3
|
+
<div
|
|
4
|
+
class="mx-auto flex size-12 items-center justify-center rounded-2xl bg-gray-100 text-gray-400 dark:bg-gray-800 dark:text-gray-500"
|
|
5
|
+
aria-hidden="true"
|
|
6
|
+
>
|
|
7
|
+
<slot name="icon"><UiIcon :name="icon" class="size-6" /></slot>
|
|
8
|
+
</div>
|
|
9
|
+
<component :is="headingTag" class="mt-4 text-sm font-semibold text-gray-900 dark:text-gray-100">
|
|
10
|
+
{{ title }}
|
|
11
|
+
</component>
|
|
12
|
+
<p
|
|
13
|
+
v-if="description || $slots.description"
|
|
14
|
+
class="mx-auto mt-1 max-w-sm text-sm text-gray-500 dark:text-gray-400"
|
|
15
|
+
>
|
|
16
|
+
<slot name="description">{{ description }}</slot>
|
|
17
|
+
</p>
|
|
18
|
+
<div v-if="$slots.default" class="mt-5 flex flex-wrap justify-center gap-2">
|
|
19
|
+
<slot />
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script setup>
|
|
25
|
+
/**
|
|
26
|
+
* UiEmptyState — what a list, table or page shows when there is nothing in it
|
|
27
|
+
* yet: an icon, a short title, one line of explanation and the action that
|
|
28
|
+
* fixes it.
|
|
29
|
+
*
|
|
30
|
+
* Say why it is empty and what to do next, rather than only that it is empty.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* <UiEmptyState
|
|
34
|
+
* icon="mdi:sync"
|
|
35
|
+
* title="No apps yet"
|
|
36
|
+
* description="Register an app to give its clients a place to sync."
|
|
37
|
+
* >
|
|
38
|
+
* <UiButton><UiIcon name="mdi:plus" class="size-4" />New app</UiButton>
|
|
39
|
+
* </UiEmptyState>
|
|
40
|
+
*
|
|
41
|
+
* @slot default — Actions.
|
|
42
|
+
* @slot icon — Custom icon content.
|
|
43
|
+
* @slot description — Rich description (overrides `description`).
|
|
44
|
+
*/
|
|
45
|
+
import { computed } from 'vue'
|
|
46
|
+
import UiIcon from '../icons/Icon.vue'
|
|
47
|
+
import { useMergedClasses } from '../composables/useMergedClasses.js'
|
|
48
|
+
|
|
49
|
+
const props = defineProps({
|
|
50
|
+
/**
|
|
51
|
+
* Short statement of the state, e.g. "No apps yet".
|
|
52
|
+
* @type {string}
|
|
53
|
+
* @default ''
|
|
54
|
+
*/
|
|
55
|
+
title: { type: String, default: '' },
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* One line explaining why, or what to do.
|
|
59
|
+
* @type {string}
|
|
60
|
+
* @default ''
|
|
61
|
+
*/
|
|
62
|
+
description: { type: String, default: '' },
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* MDI icon.
|
|
66
|
+
* @type {string}
|
|
67
|
+
* @default 'mdi:inbox-outline'
|
|
68
|
+
*/
|
|
69
|
+
icon: { type: String, default: 'mdi:inbox-outline' },
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Tighter vertical padding, for use inside cards and tables.
|
|
73
|
+
* @type {boolean}
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
compact: { type: Boolean, default: false },
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Dashed outline around the state, for standalone use on a page.
|
|
80
|
+
* @type {boolean}
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
bordered: { type: Boolean, default: false },
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Element used for the title.
|
|
87
|
+
* @type {string}
|
|
88
|
+
* @default 'h3'
|
|
89
|
+
* @values 'h2' | 'h3' | 'h4' | 'p'
|
|
90
|
+
*/
|
|
91
|
+
headingTag: { type: String, default: 'h3' },
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
defineOptions({ inheritAttrs: false })
|
|
95
|
+
|
|
96
|
+
const internalClasses = computed(() =>
|
|
97
|
+
[
|
|
98
|
+
'text-center',
|
|
99
|
+
props.compact ? 'px-4 py-6' : 'px-6 py-12',
|
|
100
|
+
props.bordered ? 'rounded-2xl border-2 border-dashed border-gray-200 dark:border-gray-700' : '',
|
|
101
|
+
]
|
|
102
|
+
.filter(Boolean)
|
|
103
|
+
.join(' '),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
const { mergedClasses, restAttrs } = useMergedClasses(() => internalClasses.value)
|
|
107
|
+
</script>
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div>
|
|
3
|
-
<label v-if="label" :class="labelClasses">
|
|
3
|
+
<label v-if="label" :id="labelId" :for="controlId" :class="labelClasses">
|
|
4
4
|
{{ label }}
|
|
5
5
|
<span v-if="optional" class="font-normal text-gray-400 dark:text-gray-600">(optional)</span>
|
|
6
6
|
</label>
|
|
7
7
|
<slot />
|
|
8
|
-
<p v-if="hint" class="text-xs text-gray-500 dark:text-gray-500 mt-1">{{ hint }}</p>
|
|
9
|
-
<p v-if="error" class="text-xs text-red-600 dark:text-red-400 mt-1">
|
|
8
|
+
<p v-if="hint" :id="hintId" class="text-xs text-gray-500 dark:text-gray-500 mt-1">{{ hint }}</p>
|
|
9
|
+
<p v-if="error" :id="errorId" class="text-xs text-red-600 dark:text-red-400 mt-1">
|
|
10
|
+
{{ error }}
|
|
11
|
+
</p>
|
|
10
12
|
</div>
|
|
11
13
|
</template>
|
|
12
14
|
|
|
@@ -38,9 +40,15 @@
|
|
|
38
40
|
* <UiToggle v-model="ligatures" />
|
|
39
41
|
* </UiFormField>
|
|
40
42
|
*
|
|
43
|
+
* The label is associated with the control: UiInput, UiSelect, UiToggle,
|
|
44
|
+
* UiCheckbox and UiSegmented pick up the field's id, so the label, hint and
|
|
45
|
+
* error are announced by screen readers and clicking the label focuses the
|
|
46
|
+
* control. For any other control, give it the id passed as `for`.
|
|
47
|
+
*
|
|
41
48
|
* @slot default — Form control (e.g. UiInput, UiSelect, UiToggle)
|
|
42
49
|
*/
|
|
43
|
-
import { computed } from 'vue'
|
|
50
|
+
import { computed, provide, useId } from 'vue'
|
|
51
|
+
import { FORM_FIELD_KEY } from '../internal/formField.js'
|
|
44
52
|
const props = defineProps({
|
|
45
53
|
/**
|
|
46
54
|
* Label text displayed above the input.
|
|
@@ -76,6 +84,31 @@ const props = defineProps({
|
|
|
76
84
|
* @default false
|
|
77
85
|
*/
|
|
78
86
|
inline: { type: Boolean, default: false },
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Id of the control the label points at. Generated when omitted; set it
|
|
90
|
+
* when the control is not a Numori UI form component.
|
|
91
|
+
* @type {string}
|
|
92
|
+
* @default ''
|
|
93
|
+
*/
|
|
94
|
+
for: { type: String, default: '' },
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const uid = useId()
|
|
98
|
+
const controlId = computed(() => props.for || `${uid}-control`)
|
|
99
|
+
const labelId = `${uid}-label`
|
|
100
|
+
const hintId = `${uid}-hint`
|
|
101
|
+
const errorId = `${uid}-error`
|
|
102
|
+
|
|
103
|
+
provide(FORM_FIELD_KEY, {
|
|
104
|
+
controlId,
|
|
105
|
+
labelId,
|
|
106
|
+
describedBy: computed(
|
|
107
|
+
() =>
|
|
108
|
+
[props.hint ? hintId : null, props.error ? errorId : null].filter(Boolean).join(' ') ||
|
|
109
|
+
undefined,
|
|
110
|
+
),
|
|
111
|
+
invalid: computed(() => !!props.error),
|
|
79
112
|
})
|
|
80
113
|
|
|
81
114
|
const labelClasses = computed(() =>
|
package/src/components/Input.vue
CHANGED
|
@@ -43,7 +43,10 @@
|
|
|
43
43
|
<!-- Textarea mode: multi-line text input with custom scrollbar styling -->
|
|
44
44
|
<textarea
|
|
45
45
|
v-if="isTextarea"
|
|
46
|
+
:id="field?.controlId.value"
|
|
46
47
|
ref="inputRef"
|
|
48
|
+
:aria-describedby="field?.describedBy.value"
|
|
49
|
+
:aria-invalid="field?.invalid.value ? 'true' : undefined"
|
|
47
50
|
:value="modelValue"
|
|
48
51
|
:placeholder="placeholder"
|
|
49
52
|
:required="required"
|
|
@@ -71,7 +74,10 @@
|
|
|
71
74
|
|
|
72
75
|
<input
|
|
73
76
|
v-if="!isTextarea"
|
|
77
|
+
:id="field?.controlId.value"
|
|
74
78
|
ref="inputRef"
|
|
79
|
+
:aria-describedby="field?.describedBy.value"
|
|
80
|
+
:aria-invalid="field?.invalid.value ? 'true' : undefined"
|
|
75
81
|
:type="computedType"
|
|
76
82
|
:value="modelValue"
|
|
77
83
|
:placeholder="placeholder"
|
|
@@ -217,6 +223,7 @@
|
|
|
217
223
|
*/
|
|
218
224
|
import { ref, computed, watch, useSlots } from 'vue'
|
|
219
225
|
import UiIcon from '../icons/Icon.vue'
|
|
226
|
+
import { useFormField } from '../internal/formField.js'
|
|
220
227
|
const props = defineProps({
|
|
221
228
|
/**
|
|
222
229
|
* Bound value (v-model).
|
|
@@ -421,6 +428,8 @@ const props = defineProps({
|
|
|
421
428
|
|
|
422
429
|
const emit = defineEmits(['update:modelValue', 'validation'])
|
|
423
430
|
|
|
431
|
+
const field = useFormField()
|
|
432
|
+
|
|
424
433
|
const inputRef = ref(null)
|
|
425
434
|
const passwordVisible = ref(false)
|
|
426
435
|
const touched = ref(false)
|
package/src/components/Modal.vue
CHANGED
|
@@ -27,7 +27,13 @@
|
|
|
27
27
|
>
|
|
28
28
|
<div
|
|
29
29
|
v-if="show"
|
|
30
|
-
|
|
30
|
+
ref="panelRef"
|
|
31
|
+
role="dialog"
|
|
32
|
+
aria-modal="true"
|
|
33
|
+
:aria-label="labelledby ? undefined : label || undefined"
|
|
34
|
+
:aria-labelledby="labelledby || undefined"
|
|
35
|
+
tabindex="-1"
|
|
36
|
+
class="modal-panel bg-white dark:bg-gray-925 overflow-hidden flex flex-col focus:outline-none"
|
|
31
37
|
:class="[panelClass, maxWidthClass, roundedClass, mobileLayoutClass]"
|
|
32
38
|
@click.stop
|
|
33
39
|
>
|
|
@@ -47,6 +53,13 @@
|
|
|
47
53
|
* (xs through 5xl and full-screen), persistent mode to prevent backdrop-click dismissal,
|
|
48
54
|
* and customizable z-index and padding. The panel uses a scale+fade transition on enter/leave.
|
|
49
55
|
*
|
|
56
|
+
* The panel is a real dialog: `role="dialog"` and `aria-modal="true"`, named by
|
|
57
|
+
* `label` or `labelledby`. While open, focus moves into the panel (unless
|
|
58
|
+
* something inside already has it), Tab and Shift+Tab wrap within it, Escape
|
|
59
|
+
* closes it (unless `persistent` or `close-on-escape` is false), and focus
|
|
60
|
+
* returns to whatever opened it. Stacked modals behave: only the top one
|
|
61
|
+
* responds to Tab and Escape.
|
|
62
|
+
*
|
|
50
63
|
* @example Basic modal
|
|
51
64
|
* <UiModal :show="isOpen" @close="isOpen = false">
|
|
52
65
|
* <div class="p-6">Hello!</div>
|
|
@@ -68,12 +81,19 @@
|
|
|
68
81
|
* <div class="p-6">Centered on all screens</div>
|
|
69
82
|
* </UiModal>
|
|
70
83
|
*
|
|
71
|
-
* @
|
|
84
|
+
* @example Named by its heading
|
|
85
|
+
* <UiModal :show="isOpen" labelledby="settings-title" @close="isOpen = false">
|
|
86
|
+
* <h2 id="settings-title">Settings</h2>
|
|
87
|
+
* </UiModal>
|
|
88
|
+
*
|
|
89
|
+
* @emits {void} close — Emitted when the modal should close (backdrop click, Escape,
|
|
90
|
+
* the Android back button, or programmatic)
|
|
72
91
|
*
|
|
73
92
|
* @slot default — Modal content
|
|
74
93
|
*/
|
|
75
|
-
import { computed, watch, onBeforeUnmount } from 'vue'
|
|
94
|
+
import { computed, ref, watch, onBeforeUnmount } from 'vue'
|
|
76
95
|
import { useBackButton } from '../composables/useBackButton.js'
|
|
96
|
+
import { useFocusTrap } from '../internal/focusTrap.js'
|
|
77
97
|
const props = defineProps({
|
|
78
98
|
/**
|
|
79
99
|
* Controls modal visibility. Use with v-model or :show + @close.
|
|
@@ -125,10 +145,38 @@ const props = defineProps({
|
|
|
125
145
|
* @default 'md:p-4'
|
|
126
146
|
*/
|
|
127
147
|
padding: { type: String, default: 'md:p-4' },
|
|
148
|
+
/**
|
|
149
|
+
* Accessible name for the dialog. Prefer `labelledby` when the content has a
|
|
150
|
+
* visible heading.
|
|
151
|
+
* @type {string}
|
|
152
|
+
* @default ''
|
|
153
|
+
*/
|
|
154
|
+
label: { type: String, default: '' },
|
|
155
|
+
/**
|
|
156
|
+
* Id of the element that names the dialog, usually its heading.
|
|
157
|
+
* @type {string}
|
|
158
|
+
* @default ''
|
|
159
|
+
*/
|
|
160
|
+
labelledby: { type: String, default: '' },
|
|
161
|
+
/**
|
|
162
|
+
* Whether Escape closes the modal. Ignored (treated as false) when
|
|
163
|
+
* `persistent` is set.
|
|
164
|
+
* @type {boolean}
|
|
165
|
+
* @default true
|
|
166
|
+
*/
|
|
167
|
+
closeOnEscape: { type: Boolean, default: true },
|
|
128
168
|
})
|
|
129
169
|
|
|
130
170
|
const emit = defineEmits(['close'])
|
|
131
171
|
|
|
172
|
+
// ── Focus: move in, keep in, put back ──
|
|
173
|
+
const panelRef = ref(null)
|
|
174
|
+
useFocusTrap(() => panelRef.value, {
|
|
175
|
+
active: () => props.show,
|
|
176
|
+
escape: () => props.closeOnEscape && !props.persistent,
|
|
177
|
+
onEscape: () => emit('close'),
|
|
178
|
+
})
|
|
179
|
+
|
|
132
180
|
// ── Back-button interception (Capacitor) ──
|
|
133
181
|
const { register: registerBack, unregister: unregisterBack } = useBackButton()
|
|
134
182
|
let backHandlerId = null
|
|
@@ -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>
|