numori-ui 0.5.0 → 0.7.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 +85 -0
- package/README.md +11 -3
- package/dist/components/Avatar.js +71 -19
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/ChipsInput.js +423 -0
- package/dist/components/ChipsInput.js.map +1 -0
- package/dist/components/Drawer.js +236 -0
- package/dist/components/Drawer.js.map +1 -0
- package/dist/components/Dropdown.js +4 -2
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/Modal.js +61 -4
- package/dist/components/Modal.js.map +1 -1
- package/dist/components/Prompt.js +11 -6
- package/dist/components/Prompt.js.map +1 -1
- package/dist/components/Select.js +1 -1
- package/dist/components/Select.js.map +1 -1
- 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/Toast.js +62 -16
- package/dist/components/Toast.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 +93 -82
- package/dist/components/index.js.map +1 -1
- package/dist/icons/mdi.js +3 -0
- package/dist/icons/mdi.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.js +49 -43
- package/dist/index.js.map +1 -1
- package/dist/internal/focusTrap.js +163 -0
- package/dist/internal/focusTrap.js.map +1 -0
- package/dist/manifest.js +7 -1
- package/dist/manifest.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Avatar.vue +69 -18
- package/src/components/ChipsInput.vue +387 -0
- package/src/components/Drawer.vue +213 -0
- package/src/components/Dropdown.vue +4 -1
- package/src/components/Modal.vue +51 -3
- package/src/components/Prompt.vue +14 -3
- package/src/components/Select.vue +1 -1
- package/src/components/Skeleton.vue +91 -0
- package/src/components/SplitPane.vue +264 -0
- package/src/components/Toast.vue +57 -13
- package/src/components/Tree.vue +428 -0
- package/src/components/VirtualList.vue +250 -0
- package/src/components/index.js +18 -1
- package/src/icons/mdi.js +3 -0
- package/src/internal/focusTrap.js +185 -0
- package/src/manifest.js +6 -0
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
max-width="sm"
|
|
5
5
|
:fullscreen-mobile="fullscreenMobile"
|
|
6
6
|
:panel-class="panelClass"
|
|
7
|
+
:labelledby="titleId"
|
|
7
8
|
@close="handleClose"
|
|
8
9
|
>
|
|
9
10
|
<div
|
|
@@ -15,11 +16,20 @@
|
|
|
15
16
|
<div class="flex items-center justify-between p-4 pb-0 mb-3 shrink-0">
|
|
16
17
|
<div class="flex items-center gap-2">
|
|
17
18
|
<UiIcon v-if="icon" :name="icon" class="w-5 h-5" :class="iconColorClass" />
|
|
18
|
-
<h2
|
|
19
|
+
<h2
|
|
20
|
+
:id="titleId"
|
|
21
|
+
class="text-sm font-semibold text-gray-900 dark:text-gray-200 leading-none"
|
|
22
|
+
>
|
|
19
23
|
{{ title }}
|
|
20
24
|
</h2>
|
|
21
25
|
</div>
|
|
22
|
-
<UiButton
|
|
26
|
+
<UiButton
|
|
27
|
+
variant="ghost"
|
|
28
|
+
color="gray"
|
|
29
|
+
icon-only
|
|
30
|
+
:aria-label="cancelLabel"
|
|
31
|
+
@click="handleClose"
|
|
32
|
+
>
|
|
23
33
|
<UiIcon name="mdi:close" class="block w-5 h-5" />
|
|
24
34
|
</UiButton>
|
|
25
35
|
</div>
|
|
@@ -87,7 +97,7 @@
|
|
|
87
97
|
* <UiInput v-model="name" @keydown.enter="save" />
|
|
88
98
|
* </UiPrompt>
|
|
89
99
|
*/
|
|
90
|
-
import { ref, computed, watch, nextTick, useSlots } from 'vue'
|
|
100
|
+
import { ref, computed, watch, nextTick, useSlots, useId } from 'vue'
|
|
91
101
|
import UiButton from './Button.vue'
|
|
92
102
|
import UiModal from './Modal.vue'
|
|
93
103
|
import UiIcon from '../icons/Icon.vue'
|
|
@@ -119,6 +129,7 @@ const props = defineProps({
|
|
|
119
129
|
const emit = defineEmits(['close', 'confirm'])
|
|
120
130
|
|
|
121
131
|
const confirmRef = ref(null)
|
|
132
|
+
const titleId = `${useId()}-title`
|
|
122
133
|
const hasCustomActions = computed(() => !!useSlots().actions)
|
|
123
134
|
|
|
124
135
|
const iconColorClass = computed(() => {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
type="text"
|
|
79
79
|
placeholder="Search..."
|
|
80
80
|
class="w-full px-2.5 py-1.5 text-sm border border-gray-200 dark:border-gray-700 rounded-md bg-gray-50 dark:bg-gray-900 text-gray-900 dark:text-gray-300 outline-none focus:ring-1 focus:ring-primary-500 placeholder-gray-400"
|
|
81
|
-
@keydown.escape="close"
|
|
81
|
+
@keydown.escape.prevent="close"
|
|
82
82
|
@keydown.enter.prevent="selectFirst"
|
|
83
83
|
/>
|
|
84
84
|
</div>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="variant === 'text'" :class="['flex flex-col', gapClass]" v-bind="a11yAttrs">
|
|
3
|
+
<span v-if="label" class="sr-only">{{ label }}</span>
|
|
4
|
+
<div
|
|
5
|
+
v-for="line in lines"
|
|
6
|
+
:key="line"
|
|
7
|
+
:class="[baseClass, 'h-3 rounded-md', line === lines && lines > 1 ? 'w-3/5' : 'w-full']"
|
|
8
|
+
aria-hidden="true"
|
|
9
|
+
/>
|
|
10
|
+
</div>
|
|
11
|
+
<div v-else :class="[baseClass, shapeClass]" v-bind="a11yAttrs">
|
|
12
|
+
<span v-if="label" class="sr-only">{{ label }}</span>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup>
|
|
17
|
+
/**
|
|
18
|
+
* UiSkeleton — a placeholder shaped like the content that is about to load.
|
|
19
|
+
*
|
|
20
|
+
* Three shapes: `text` (one or more lines, the last one shorter), `rect` and
|
|
21
|
+
* `circle`. Size the shape with ordinary classes — `class="h-24 w-full"`, or
|
|
22
|
+
* `class="size-9"` for an avatar-sized circle.
|
|
23
|
+
*
|
|
24
|
+
* The shimmer is a gentle pulse and stops for anyone who prefers reduced
|
|
25
|
+
* motion. Skeletons are decorative (`aria-hidden`) by default; give one a
|
|
26
|
+
* `label` and it becomes a polite status message instead, so a screen reader
|
|
27
|
+
* hears "Loading messages" once rather than nothing at all. Label one
|
|
28
|
+
* skeleton per region, not every line.
|
|
29
|
+
*
|
|
30
|
+
* @example A message row while it loads
|
|
31
|
+
* <div class="flex items-center gap-3">
|
|
32
|
+
* <UiSkeleton variant="circle" class="size-9" />
|
|
33
|
+
* <UiSkeleton :lines="2" class="flex-1" />
|
|
34
|
+
* </div>
|
|
35
|
+
*
|
|
36
|
+
* @example Announced to screen readers
|
|
37
|
+
* <UiSkeleton variant="rect" class="h-40" label="Loading message" />
|
|
38
|
+
*/
|
|
39
|
+
import { computed } from 'vue'
|
|
40
|
+
|
|
41
|
+
const props = defineProps({
|
|
42
|
+
/**
|
|
43
|
+
* Shape of the placeholder.
|
|
44
|
+
* @type {string}
|
|
45
|
+
* @default 'text'
|
|
46
|
+
* @values 'text' | 'rect' | 'circle'
|
|
47
|
+
*/
|
|
48
|
+
variant: { type: String, default: 'text' },
|
|
49
|
+
/**
|
|
50
|
+
* Number of lines for `variant="text"`.
|
|
51
|
+
* @type {number}
|
|
52
|
+
* @default 1
|
|
53
|
+
*/
|
|
54
|
+
lines: { type: Number, default: 1 },
|
|
55
|
+
/**
|
|
56
|
+
* Spacing between text lines.
|
|
57
|
+
* @type {string}
|
|
58
|
+
* @default 'md'
|
|
59
|
+
* @values 'sm' | 'md' | 'lg'
|
|
60
|
+
*/
|
|
61
|
+
gap: { type: String, default: 'md' },
|
|
62
|
+
/**
|
|
63
|
+
* Pulse while waiting. Always off under `prefers-reduced-motion`.
|
|
64
|
+
* @type {boolean}
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
animated: { type: Boolean, default: true },
|
|
68
|
+
/**
|
|
69
|
+
* Announce the placeholder as a loading status with this text. Empty keeps
|
|
70
|
+
* it hidden from assistive technology.
|
|
71
|
+
* @type {string}
|
|
72
|
+
* @default ''
|
|
73
|
+
*/
|
|
74
|
+
label: { type: String, default: '' },
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const baseClass = computed(() =>
|
|
78
|
+
[
|
|
79
|
+
'block bg-gray-200 dark:bg-gray-800',
|
|
80
|
+
props.animated ? 'animate-pulse motion-reduce:animate-none' : '',
|
|
81
|
+
].join(' '),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const shapeClass = computed(() => (props.variant === 'circle' ? 'rounded-full' : 'rounded-lg'))
|
|
85
|
+
|
|
86
|
+
const gapClass = computed(() => ({ sm: 'gap-1.5', md: 'gap-2', lg: 'gap-3' })[props.gap] ?? 'gap-2')
|
|
87
|
+
|
|
88
|
+
const a11yAttrs = computed(() =>
|
|
89
|
+
props.label ? { role: 'status', 'aria-live': 'polite' } : { 'aria-hidden': 'true' },
|
|
90
|
+
)
|
|
91
|
+
</script>
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="rootRef"
|
|
4
|
+
class="flex h-full w-full min-h-0 min-w-0"
|
|
5
|
+
:class="[isHorizontal ? 'flex-row' : 'flex-col', dragging ? 'select-none' : '']"
|
|
6
|
+
>
|
|
7
|
+
<div
|
|
8
|
+
:id="startId"
|
|
9
|
+
class="relative min-h-0 min-w-0 shrink-0 overflow-hidden"
|
|
10
|
+
:style="startStyle"
|
|
11
|
+
>
|
|
12
|
+
<slot name="start" :size="currentSize" />
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<!-- The splitter: the WAI-ARIA "window splitter" pattern. A 1px rule with
|
|
16
|
+
a wider invisible hit area, focusable and operable from the keyboard. -->
|
|
17
|
+
<div
|
|
18
|
+
role="separator"
|
|
19
|
+
tabindex="0"
|
|
20
|
+
:aria-label="label"
|
|
21
|
+
:aria-controls="startId"
|
|
22
|
+
:aria-orientation="isHorizontal ? 'vertical' : 'horizontal'"
|
|
23
|
+
:aria-valuenow="Math.round(currentSize)"
|
|
24
|
+
:aria-valuemin="min"
|
|
25
|
+
:aria-valuemax="effectiveMax"
|
|
26
|
+
:data-dragging="dragging ? 'true' : undefined"
|
|
27
|
+
class="group relative z-10 shrink-0 touch-none focus-visible:outline-none"
|
|
28
|
+
:class="isHorizontal ? 'w-px cursor-col-resize' : 'h-px cursor-row-resize'"
|
|
29
|
+
@pointerdown="onPointerDown"
|
|
30
|
+
@keydown="onKeydown"
|
|
31
|
+
@dblclick="reset"
|
|
32
|
+
>
|
|
33
|
+
<span
|
|
34
|
+
aria-hidden="true"
|
|
35
|
+
class="absolute bg-gray-200 transition-colors group-hover:bg-primary-400 group-focus-visible:bg-primary-500 group-data-[dragging=true]:bg-primary-500 dark:bg-gray-800 dark:group-hover:bg-primary-500"
|
|
36
|
+
:class="
|
|
37
|
+
isHorizontal
|
|
38
|
+
? 'inset-y-0 left-0 w-px group-focus-visible:-left-px group-focus-visible:w-[3px]'
|
|
39
|
+
: 'inset-x-0 top-0 h-px group-focus-visible:-top-px group-focus-visible:h-[3px]'
|
|
40
|
+
"
|
|
41
|
+
/>
|
|
42
|
+
<span
|
|
43
|
+
aria-hidden="true"
|
|
44
|
+
class="absolute"
|
|
45
|
+
:class="isHorizontal ? 'inset-y-0 -left-1.5 w-3' : 'inset-x-0 -top-1.5 h-3'"
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<div class="relative min-h-0 min-w-0 flex-1 overflow-hidden">
|
|
50
|
+
<slot name="end" />
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script setup>
|
|
56
|
+
/**
|
|
57
|
+
* UiSplitPane — two panes divided by a draggable, keyboard-operable splitter.
|
|
58
|
+
*
|
|
59
|
+
* The `start` pane has an explicit size in pixels; the `end` pane takes the
|
|
60
|
+
* rest. Drag the splitter with a mouse, finger or pen, or focus it and use the
|
|
61
|
+
* arrow keys (Shift for bigger steps), Home and End for the limits, and Enter
|
|
62
|
+
* to toggle between the current size and `min`. Double-click resets to
|
|
63
|
+
* `defaultSize`.
|
|
64
|
+
*
|
|
65
|
+
* Follows the WAI-ARIA window splitter pattern: the splitter is a focusable
|
|
66
|
+
* `role="separator"` whose `aria-valuenow` is the start pane's size and whose
|
|
67
|
+
* `aria-controls` points at it, so assistive technology can report and change
|
|
68
|
+
* the split.
|
|
69
|
+
*
|
|
70
|
+
* Bind `v-model` to persist the size (for example to local storage); leave it
|
|
71
|
+
* unbound and the component keeps its own state. `update:modelValue` fires on
|
|
72
|
+
* every change while dragging, and `resize-end` once when a drag or key press
|
|
73
|
+
* finishes — persist on the latter to avoid a write per pixel.
|
|
74
|
+
*
|
|
75
|
+
* The component fills its parent (`h-full w-full`), so give the parent a
|
|
76
|
+
* size. Panes can nest: put a second `UiSplitPane` in `#end` for three columns.
|
|
77
|
+
*
|
|
78
|
+
* @example Message list beside a reader
|
|
79
|
+
* <UiSplitPane v-model="listWidth" :min="280" :max="640" label="Resize message list">
|
|
80
|
+
* <template #start><MessageList /></template>
|
|
81
|
+
* <template #end><MessageReader /></template>
|
|
82
|
+
* </UiSplitPane>
|
|
83
|
+
*
|
|
84
|
+
* @example Stacked
|
|
85
|
+
* <UiSplitPane direction="vertical" :default-size="240" label="Resize preview">
|
|
86
|
+
* <template #start>Top</template>
|
|
87
|
+
* <template #end>Bottom</template>
|
|
88
|
+
* </UiSplitPane>
|
|
89
|
+
*
|
|
90
|
+
* @emits {number} update:modelValue — The start pane's new size, in pixels.
|
|
91
|
+
* @emits {number} resize-end — A drag or keyboard adjustment finished, with the final size.
|
|
92
|
+
*
|
|
93
|
+
* @slot start — The sized pane. Scope: `{ size }`.
|
|
94
|
+
* @slot end — The flexible pane.
|
|
95
|
+
*/
|
|
96
|
+
import { computed, onBeforeUnmount, onMounted, ref, useId } from 'vue'
|
|
97
|
+
|
|
98
|
+
const props = defineProps({
|
|
99
|
+
/**
|
|
100
|
+
* Size of the start pane in pixels, for `v-model`. Leave unset to let the
|
|
101
|
+
* component manage it from `defaultSize`.
|
|
102
|
+
* @type {number}
|
|
103
|
+
* @default undefined
|
|
104
|
+
*/
|
|
105
|
+
modelValue: { type: Number, default: undefined },
|
|
106
|
+
/**
|
|
107
|
+
* Initial size in pixels when uncontrolled, and the size double-click resets to.
|
|
108
|
+
* @type {number}
|
|
109
|
+
* @default 320
|
|
110
|
+
*/
|
|
111
|
+
defaultSize: { type: Number, default: 320 },
|
|
112
|
+
/**
|
|
113
|
+
* Smallest start pane size in pixels.
|
|
114
|
+
* @type {number}
|
|
115
|
+
* @default 160
|
|
116
|
+
*/
|
|
117
|
+
min: { type: Number, default: 160 },
|
|
118
|
+
/**
|
|
119
|
+
* Largest start pane size in pixels. The pane is also never allowed to push
|
|
120
|
+
* the end pane below `endMin`.
|
|
121
|
+
* @type {number}
|
|
122
|
+
* @default 800
|
|
123
|
+
*/
|
|
124
|
+
max: { type: Number, default: 800 },
|
|
125
|
+
/**
|
|
126
|
+
* Smallest size the end pane may be squeezed to, in pixels.
|
|
127
|
+
* @type {number}
|
|
128
|
+
* @default 240
|
|
129
|
+
*/
|
|
130
|
+
endMin: { type: Number, default: 240 },
|
|
131
|
+
/**
|
|
132
|
+
* Layout direction. `horizontal` puts the panes side by side.
|
|
133
|
+
* @type {string}
|
|
134
|
+
* @default 'horizontal'
|
|
135
|
+
* @values 'horizontal' | 'vertical'
|
|
136
|
+
*/
|
|
137
|
+
direction: { type: String, default: 'horizontal' },
|
|
138
|
+
/**
|
|
139
|
+
* Arrow-key step in pixels. Shift multiplies it by five.
|
|
140
|
+
* @type {number}
|
|
141
|
+
* @default 16
|
|
142
|
+
*/
|
|
143
|
+
step: { type: Number, default: 16 },
|
|
144
|
+
/**
|
|
145
|
+
* Accessible name for the splitter.
|
|
146
|
+
* @type {string}
|
|
147
|
+
* @default 'Resize panes'
|
|
148
|
+
*/
|
|
149
|
+
label: { type: String, default: 'Resize panes' },
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const emit = defineEmits(['update:modelValue', 'resize-end'])
|
|
153
|
+
|
|
154
|
+
const startId = `${useId()}-start`
|
|
155
|
+
const rootRef = ref(null)
|
|
156
|
+
const isHorizontal = computed(() => props.direction !== 'vertical')
|
|
157
|
+
|
|
158
|
+
// ── Size state (controlled or uncontrolled) ──
|
|
159
|
+
const internalSize = ref(props.defaultSize)
|
|
160
|
+
const currentSize = computed(() => props.modelValue ?? internalSize.value)
|
|
161
|
+
|
|
162
|
+
// The container's extent along the split axis, so `max` can respect `endMin`.
|
|
163
|
+
const extent = ref(0)
|
|
164
|
+
const effectiveMax = computed(() => {
|
|
165
|
+
if (!extent.value) return props.max
|
|
166
|
+
return Math.max(props.min, Math.min(props.max, extent.value - props.endMin))
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const clamp = (value) => Math.round(Math.min(effectiveMax.value, Math.max(props.min, value)))
|
|
170
|
+
|
|
171
|
+
const startStyle = computed(() => {
|
|
172
|
+
const size = `${clamp(currentSize.value)}px`
|
|
173
|
+
return isHorizontal.value ? { width: size } : { height: size }
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
function setSize(value) {
|
|
177
|
+
const next = clamp(value)
|
|
178
|
+
if (next === currentSize.value) return
|
|
179
|
+
internalSize.value = next
|
|
180
|
+
emit('update:modelValue', next)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const finish = () => emit('resize-end', clamp(currentSize.value))
|
|
184
|
+
|
|
185
|
+
// ── Pointer dragging ──
|
|
186
|
+
const dragging = ref(false)
|
|
187
|
+
let dragOrigin = 0
|
|
188
|
+
let sizeOrigin = 0
|
|
189
|
+
|
|
190
|
+
function onPointerDown(event) {
|
|
191
|
+
if (event.button !== 0) return
|
|
192
|
+
event.preventDefault()
|
|
193
|
+
event.currentTarget.setPointerCapture?.(event.pointerId)
|
|
194
|
+
event.currentTarget.focus({ preventScroll: true })
|
|
195
|
+
dragging.value = true
|
|
196
|
+
dragOrigin = isHorizontal.value ? event.clientX : event.clientY
|
|
197
|
+
sizeOrigin = clamp(currentSize.value)
|
|
198
|
+
event.currentTarget.addEventListener('pointermove', onPointerMove)
|
|
199
|
+
event.currentTarget.addEventListener('pointerup', onPointerUp, { once: true })
|
|
200
|
+
event.currentTarget.addEventListener('pointercancel', onPointerUp, { once: true })
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function onPointerMove(event) {
|
|
204
|
+
if (!dragging.value) return
|
|
205
|
+
const position = isHorizontal.value ? event.clientX : event.clientY
|
|
206
|
+
setSize(sizeOrigin + position - dragOrigin)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function onPointerUp(event) {
|
|
210
|
+
event.currentTarget.removeEventListener('pointermove', onPointerMove)
|
|
211
|
+
event.currentTarget.removeEventListener('pointerup', onPointerUp)
|
|
212
|
+
event.currentTarget.removeEventListener('pointercancel', onPointerUp)
|
|
213
|
+
if (!dragging.value) return
|
|
214
|
+
dragging.value = false
|
|
215
|
+
finish()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// ── Keyboard ──
|
|
219
|
+
let sizeBeforeCollapse = null
|
|
220
|
+
|
|
221
|
+
function onKeydown(event) {
|
|
222
|
+
const decrease = isHorizontal.value ? 'ArrowLeft' : 'ArrowUp'
|
|
223
|
+
const increase = isHorizontal.value ? 'ArrowRight' : 'ArrowDown'
|
|
224
|
+
const amount = event.shiftKey ? props.step * 5 : props.step
|
|
225
|
+
const now = clamp(currentSize.value)
|
|
226
|
+
let next = null
|
|
227
|
+
if (event.key === decrease) next = now - amount
|
|
228
|
+
else if (event.key === increase) next = now + amount
|
|
229
|
+
else if (event.key === 'Home') next = props.min
|
|
230
|
+
else if (event.key === 'End') next = effectiveMax.value
|
|
231
|
+
else if (event.key === 'Enter') {
|
|
232
|
+
if (now > props.min) {
|
|
233
|
+
sizeBeforeCollapse = now
|
|
234
|
+
next = props.min
|
|
235
|
+
} else {
|
|
236
|
+
next = sizeBeforeCollapse ?? props.defaultSize
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (next === null) return
|
|
240
|
+
event.preventDefault()
|
|
241
|
+
setSize(next)
|
|
242
|
+
finish()
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function reset() {
|
|
246
|
+
setSize(props.defaultSize)
|
|
247
|
+
finish()
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// ── Track the container size ──
|
|
251
|
+
let observer = null
|
|
252
|
+
onMounted(() => {
|
|
253
|
+
const measure = () => {
|
|
254
|
+
const rect = rootRef.value?.getBoundingClientRect()
|
|
255
|
+
if (rect) extent.value = isHorizontal.value ? rect.width : rect.height
|
|
256
|
+
}
|
|
257
|
+
measure()
|
|
258
|
+
if (typeof ResizeObserver !== 'undefined' && rootRef.value) {
|
|
259
|
+
observer = new ResizeObserver(measure)
|
|
260
|
+
observer.observe(rootRef.value)
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
264
|
+
</script>
|
package/src/components/Toast.vue
CHANGED
|
@@ -5,22 +5,42 @@
|
|
|
5
5
|
:class="positionClass"
|
|
6
6
|
>
|
|
7
7
|
<TransitionGroup
|
|
8
|
-
enter-active-class="transition-all duration-250 ease-out"
|
|
8
|
+
enter-active-class="transition-all duration-250 ease-out motion-reduce:transition-none"
|
|
9
9
|
enter-from-class="opacity-0 -translate-y-3 scale-95"
|
|
10
10
|
enter-to-class="opacity-100 translate-y-0 scale-100"
|
|
11
|
-
leave-active-class="transition-all duration-200 ease-in"
|
|
11
|
+
leave-active-class="transition-all duration-200 ease-in motion-reduce:transition-none"
|
|
12
12
|
leave-from-class="opacity-100 translate-y-0 scale-100"
|
|
13
13
|
leave-to-class="opacity-0 -translate-y-1 scale-95"
|
|
14
14
|
>
|
|
15
15
|
<div
|
|
16
16
|
v-for="toast in toasts"
|
|
17
17
|
:key="toast.id"
|
|
18
|
-
class="pointer-events-auto flex items-center gap-2
|
|
19
|
-
:class="
|
|
18
|
+
class="pointer-events-auto flex items-center gap-2 rounded-xl py-2.5 text-sm font-medium shadow-lg backdrop-blur-xs"
|
|
19
|
+
:class="[
|
|
20
|
+
toastClass(toast.type),
|
|
21
|
+
toast.action || toast.dismissible ? 'pl-4 pr-2' : 'px-4',
|
|
22
|
+
]"
|
|
20
23
|
role="status"
|
|
21
24
|
>
|
|
22
25
|
<UiIcon v-if="toast.icon" :name="toast.icon" class="w-4 h-4 shrink-0" />
|
|
23
26
|
<span>{{ toast.message }}</span>
|
|
27
|
+
<button
|
|
28
|
+
v-if="toast.action"
|
|
29
|
+
type="button"
|
|
30
|
+
class="-my-1 ml-1 rounded-lg px-2.5 py-1 text-sm font-semibold underline-offset-2 transition-colors hover:bg-white/15 hover:underline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-current dark:hover:bg-gray-900/10"
|
|
31
|
+
@click="$emit('action', toast)"
|
|
32
|
+
>
|
|
33
|
+
{{ toast.action }}
|
|
34
|
+
</button>
|
|
35
|
+
<button
|
|
36
|
+
v-if="toast.dismissible"
|
|
37
|
+
type="button"
|
|
38
|
+
class="-my-1 inline-flex size-7 items-center justify-center rounded-lg opacity-80 transition hover:bg-white/15 hover:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-current dark:hover:bg-gray-900/10"
|
|
39
|
+
:aria-label="dismissLabel"
|
|
40
|
+
@click="$emit('dismiss', toast)"
|
|
41
|
+
>
|
|
42
|
+
<UiIcon name="mdi:close" class="w-4 h-4" />
|
|
43
|
+
</button>
|
|
24
44
|
</div>
|
|
25
45
|
</TransitionGroup>
|
|
26
46
|
</div>
|
|
@@ -38,9 +58,14 @@
|
|
|
38
58
|
* worth announcing is application logic, not layout. Hand it a reactive array
|
|
39
59
|
* and mutate that array; the enter/leave transitions handle the rest.
|
|
40
60
|
*
|
|
41
|
-
* Each entry is `{ id, message, type?, icon? }`. `id`
|
|
42
|
-
* (it keys the transition); `type` picks the colour
|
|
43
|
-
* dark pill; `icon` is optional and drawn through
|
|
61
|
+
* Each entry is `{ id, message, type?, icon?, action?, dismissible? }`. `id`
|
|
62
|
+
* must be stable and unique (it keys the transition); `type` picks the colour
|
|
63
|
+
* and defaults to a neutral dark pill; `icon` is optional and drawn through
|
|
64
|
+
* `UiIcon`. `action` is the label of one button — "Undo", typically — and
|
|
65
|
+
* clicking it emits `action` with the toast; `dismissible` adds a close
|
|
66
|
+
* button that emits `dismiss`. Keep toasts with an action on screen long
|
|
67
|
+
* enough to reach (five seconds or more), and offer the same command from the
|
|
68
|
+
* keyboard elsewhere: a toast is never the only way to do something.
|
|
44
69
|
*
|
|
45
70
|
* The container does not capture pointer events, so it never blocks the UI
|
|
46
71
|
* underneath; only the pills themselves do. Each pill is a `role="status"`, so a
|
|
@@ -60,20 +85,29 @@
|
|
|
60
85
|
*
|
|
61
86
|
* <UiToast :toasts="toasts" />
|
|
62
87
|
* <UiButton @click="notify('Saved', 'success')">Save</UiButton>
|
|
88
|
+
*
|
|
89
|
+
* @example With an undo action
|
|
90
|
+
* <UiToast
|
|
91
|
+
* :toasts="[{ id: 1, message: 'Moved to Archive', icon: 'mdi:archive-outline', action: 'Undo' }]"
|
|
92
|
+
* @action="(toast) => undo(toast.id)"
|
|
93
|
+
* />
|
|
94
|
+
*
|
|
95
|
+
* @emits {object} action — The toast's action button was pressed (the toast).
|
|
96
|
+
* @emits {object} dismiss — The toast's close button was pressed (the toast).
|
|
63
97
|
*/
|
|
64
98
|
import { computed } from 'vue'
|
|
65
99
|
import UiIcon from '../icons/Icon.vue'
|
|
66
100
|
|
|
67
101
|
const props = defineProps({
|
|
68
102
|
/**
|
|
69
|
-
* The messages to show. Each is `{ id, message, type?, icon
|
|
70
|
-
* is stable and unique, `type` is one of the
|
|
71
|
-
*
|
|
72
|
-
*
|
|
103
|
+
* The messages to show. Each is `{ id, message, type?, icon?, action?,
|
|
104
|
+
* dismissible? }`, where `id` is stable and unique, `type` is one of the
|
|
105
|
+
* values below (default neutral), `icon` is an optional MDI name, `action`
|
|
106
|
+
* labels a button, and `dismissible` adds a close button.
|
|
107
|
+
* @type {Array<{ id: string|number, message: string, type?: string, icon?: string, action?: string, dismissible?: boolean }>}
|
|
73
108
|
* @default []
|
|
74
109
|
*/
|
|
75
110
|
toasts: { type: Array, default: () => [] },
|
|
76
|
-
|
|
77
111
|
/**
|
|
78
112
|
* Where the stack anchors on screen.
|
|
79
113
|
* @type {string}
|
|
@@ -81,9 +115,19 @@ const props = defineProps({
|
|
|
81
115
|
* @values 'top' | 'bottom'
|
|
82
116
|
*/
|
|
83
117
|
position: { type: String, default: 'top' },
|
|
118
|
+
/**
|
|
119
|
+
* Accessible name of the close button on dismissible toasts.
|
|
120
|
+
* @type {string}
|
|
121
|
+
* @default 'Dismiss'
|
|
122
|
+
*/
|
|
123
|
+
dismissLabel: { type: String, default: 'Dismiss' },
|
|
84
124
|
})
|
|
85
125
|
|
|
86
|
-
|
|
126
|
+
defineEmits(['action', 'dismiss'])
|
|
127
|
+
|
|
128
|
+
const positionClass = computed(() =>
|
|
129
|
+
props.position === 'bottom' ? 'bottom-[max(1.5rem,env(safe-area-inset-bottom))]' : 'top-6',
|
|
130
|
+
)
|
|
87
131
|
|
|
88
132
|
/**
|
|
89
133
|
* Toast colours are drawn from the design tokens (`success`/`warning`/`error`)
|