@stacksjs/components 0.2.465 → 0.2.466
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/dist/{ChatLauncher-pc9nqh43.stx → ChatLauncher-3zph4trh.stx} +10 -2
- package/dist/{Combobox-9xh1jgjr.stx → Combobox-9n04ec5w.stx} +16 -4
- package/dist/{CommandPalette-vvaqtqat.stx → CommandPalette-qqjdbcyg.stx} +33 -8
- package/dist/{DateRangePicker-z64qqw84.stx → DateRangePicker-4zmf34e4.stx} +13 -9
- package/dist/Dialog-pdq8rxvy.stx +162 -0
- package/dist/{Drawer-hc0jjpsw.stx → Drawer-nmq100vy.stx} +24 -128
- package/dist/{Dropdown-25160tc6.stx → Dropdown-hb8ks69x.stx} +16 -4
- package/dist/{Listbox-32gzxace.stx → Listbox-83j2q4x6.stx} +16 -4
- package/dist/{Popover-9m42pym0.stx → Popover-khtvagcs.stx} +16 -4
- package/dist/Tab-46mxm7f8.stx +35 -0
- package/dist/TabList-76bpx5fp.stx +154 -0
- package/dist/{Tabs-3j2h0jjn.stx → Tabs-1swcxmfb.stx} +4 -1
- package/dist/{Tooltip-z13bn0pv.stx → Tooltip-rg1c2zrc.stx} +13 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -7
- package/dist/ui/tabs/index.d.ts +35 -3
- package/dist/utils/overlays.d.ts +39 -0
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/ui/chat/ChatLauncher.stx +10 -2
- package/src/ui/combobox/Combobox.stx +16 -4
- package/src/ui/command-palette/CommandPalette.stx +33 -8
- package/src/ui/date-range-picker/DateRangePicker.stx +13 -9
- package/src/ui/dialog/Dialog.stx +29 -169
- package/src/ui/dialog/README.md +5 -0
- package/src/ui/drawer/Drawer.stx +24 -128
- package/src/ui/drawer/README.md +4 -0
- package/src/ui/dropdown/Dropdown.stx +16 -4
- package/src/ui/listbox/Listbox.stx +16 -4
- package/src/ui/popover/Popover.stx +16 -4
- package/src/ui/tabs/Tab.stx +35 -0
- package/src/ui/tabs/TabList.stx +154 -0
- package/src/ui/tabs/Tabs.stx +4 -1
- package/src/ui/tabs/index.ts +37 -3
- package/src/ui/tooltip/Tooltip.stx +13 -3
- package/src/utils/overlays.ts +69 -0
- package/dist/Dialog-e9a4r6d0.stx +0 -302
package/dist/Dialog-e9a4r6d0.stx
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const open = $bool($props.open)
|
|
3
|
-
export const className = $props.className || ''
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* The dialog's accessible name.
|
|
7
|
-
*
|
|
8
|
-
* `role="dialog"` with no name is announced as just "dialog", which tells a
|
|
9
|
-
* screen reader user nothing about what has taken over the page -- WCAG 4.1.2.
|
|
10
|
-
* The slot idiom puts the name in a <DialogTitle>, which the client script
|
|
11
|
-
* below associates on mount; this prop is the server-rendered half, so a
|
|
12
|
-
* dialog is named before hydration and without JavaScript at all. Emitted only
|
|
13
|
-
* when set: an empty aria-label is worse than none, because it suppresses the
|
|
14
|
-
* name the title would otherwise supply. Same idiom as Drawer.
|
|
15
|
-
*/
|
|
16
|
-
export const title = $props.title || ''
|
|
17
|
-
|
|
18
|
-
const baseClasses = 'relative z-50'
|
|
19
|
-
export const dialogClasses = `${baseClasses} ${className}`.trim()
|
|
20
|
-
|
|
21
|
-
/*
|
|
22
|
-
* This dialog's own id.
|
|
23
|
-
*
|
|
24
|
-
* Every lookup below is scoped to it, so two dialogs on one page - a list and
|
|
25
|
-
* the confirmation for deleting from it - do not take each other's panel or
|
|
26
|
-
* each other's Escape. Same idiom as Drawer, Dropdown and Popover.
|
|
27
|
-
*/
|
|
28
|
-
export const dialogInstanceId = $uid
|
|
29
|
-
</script>
|
|
30
|
-
|
|
31
|
-
<script client>
|
|
32
|
-
const emit = defineEmits()
|
|
33
|
-
const dialogInstanceId = {{ dialogInstanceId }}
|
|
34
|
-
// useReactiveProp wires `:open="parentSignal()"` from the parent into our
|
|
35
|
-
// local `isOpen` signal — when the parent's signal changes, bindAttr
|
|
36
|
-
// updates the root's `open` attribute, our MutationObserver picks it up,
|
|
37
|
-
// and isOpen flips. See stacksjs/stx#1704.
|
|
38
|
-
const isOpen = useReactiveProp('open', {{ open }})
|
|
39
|
-
const rootRef = useRef('rootRef')
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
* Whether hydration has run.
|
|
43
|
-
*
|
|
44
|
-
* Everything below reaches into the DOM through rootRef, and an effect's first
|
|
45
|
-
* run happens while this setup function is still executing - before x-ref is
|
|
46
|
-
* wired, when the ref can only be null. A dialog rendered open on first paint
|
|
47
|
-
* would otherwise get no scroll lock and no focus. See #1979 for the same
|
|
48
|
-
* mistake in Tabs.
|
|
49
|
-
*/
|
|
50
|
-
const mounted = state(false)
|
|
51
|
-
|
|
52
|
-
onMount(() => {
|
|
53
|
-
mounted.set(true)
|
|
54
|
-
labelFromTitle()
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
/*
|
|
58
|
-
* Name the dialog after its <DialogTitle>, when the server could not.
|
|
59
|
-
*
|
|
60
|
-
* The documented idiom puts the name in the slot, which the server cannot see
|
|
61
|
-
* from here -- it renders the title as opaque slot content. So a dialog
|
|
62
|
-
* without the `title` prop reaches the browser announced as bare "dialog".
|
|
63
|
-
* This associates the two once the slot content exists. Skipped when a name is
|
|
64
|
-
* already present, so the prop always wins.
|
|
65
|
-
*/
|
|
66
|
-
function labelFromTitle() {
|
|
67
|
-
const root = rootRef.value
|
|
68
|
-
if (!root) return
|
|
69
|
-
if (root.getAttribute('aria-label') || root.getAttribute('aria-labelledby')) return
|
|
70
|
-
const heading = root.querySelector('[data-stx-dialog-title]')
|
|
71
|
-
if (!heading) return
|
|
72
|
-
if (!heading.id) heading.id = `${dialogInstanceId}-title`
|
|
73
|
-
root.setAttribute('aria-labelledby', heading.id)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function close() {
|
|
77
|
-
isOpen.set(false)
|
|
78
|
-
emit('close')
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** The panel, or the dialog root if this dialog has no DialogPanel in it. */
|
|
82
|
-
function panelEl() {
|
|
83
|
-
const root = rootRef.value
|
|
84
|
-
if (!root) return null
|
|
85
|
-
return root.querySelector('[data-stx-dialog-panel]') || root
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function focusable() {
|
|
89
|
-
const panel = panelEl()
|
|
90
|
-
if (!panel) return []
|
|
91
|
-
return Array.from(panel.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))
|
|
92
|
-
.filter(el => el.offsetParent !== null || el === document.activeElement)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/*
|
|
96
|
-
* Escape closes it from anywhere, not just from inside the dialog.
|
|
97
|
-
*
|
|
98
|
-
* It used to be a @keydown on the root element, which only fires once focus is
|
|
99
|
-
* already inside - and nothing moved focus there on open. So in the ordinary
|
|
100
|
-
* case (click a trigger, dialog appears) Escape did nothing at all, and the
|
|
101
|
-
* two omissions hid each other: no initial focus made the handler unreachable,
|
|
102
|
-
* and the unreachable handler made the missing focus look harmless.
|
|
103
|
-
* stacksjs/stx#1973, #1978
|
|
104
|
-
*/
|
|
105
|
-
function onDocumentKey(event) {
|
|
106
|
-
if (!isOpen()) return
|
|
107
|
-
|
|
108
|
-
if (event.key === 'Escape') {
|
|
109
|
-
close()
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (event.key !== 'Tab') return
|
|
114
|
-
|
|
115
|
-
/*
|
|
116
|
-
* The focus trap.
|
|
117
|
-
*
|
|
118
|
-
* aria-modal="true" tells assistive technology that the rest of the page is
|
|
119
|
-
* inert. Without containment that is not a missing feature but an active
|
|
120
|
-
* misstatement to AT, so the attribute and this handler belong together: six
|
|
121
|
-
* Tab presses used to walk focus out of a delete-confirmation dialog and
|
|
122
|
-
* onto the page behind it.
|
|
123
|
-
*/
|
|
124
|
-
const items = focusable()
|
|
125
|
-
if (items.length === 0) {
|
|
126
|
-
// Nothing to land on inside: keep focus on the panel rather than letting
|
|
127
|
-
// Tab leave.
|
|
128
|
-
event.preventDefault()
|
|
129
|
-
panelEl()?.focus?.()
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const first = items[0]
|
|
134
|
-
const last = items[items.length - 1]
|
|
135
|
-
const active = document.activeElement
|
|
136
|
-
const inside = panelEl()?.contains(active)
|
|
137
|
-
|
|
138
|
-
if (!inside) {
|
|
139
|
-
event.preventDefault()
|
|
140
|
-
;(event.shiftKey ? last : first).focus()
|
|
141
|
-
return
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (event.shiftKey && active === first) {
|
|
145
|
-
event.preventDefault()
|
|
146
|
-
last.focus()
|
|
147
|
-
}
|
|
148
|
-
else if (!event.shiftKey && active === last) {
|
|
149
|
-
event.preventDefault()
|
|
150
|
-
first.focus()
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/*
|
|
155
|
-
* A click on the backdrop closes it.
|
|
156
|
-
*
|
|
157
|
-
* The backdrop is a child component, so this listens on the dialog root and
|
|
158
|
-
* asks whether the click landed on the marker DialogBackdrop renders. Checking
|
|
159
|
-
* the target rather than comparing against the panel means a click inside the
|
|
160
|
-
* panel is not a backdrop click even though the backdrop is behind it.
|
|
161
|
-
*/
|
|
162
|
-
function onRootClick(event) {
|
|
163
|
-
const target = event.target
|
|
164
|
-
if (target && target.closest && target.closest('[data-stx-dialog-backdrop]')) close()
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/*
|
|
168
|
-
* Hold the page still behind the dialog.
|
|
169
|
-
*
|
|
170
|
-
* Without this the page scrolls under the overlay, which on a phone means a
|
|
171
|
-
* drag anywhere over the dialog scrolls what is behind it. The scrollbar's
|
|
172
|
-
* width is replaced as padding so the page does not jump sideways when it
|
|
173
|
-
* disappears. Same implementation as Drawer.
|
|
174
|
-
*/
|
|
175
|
-
let restoreScroll = null
|
|
176
|
-
|
|
177
|
-
function lockScroll() {
|
|
178
|
-
if (restoreScroll) return
|
|
179
|
-
|
|
180
|
-
const gap = window.innerWidth - document.documentElement.clientWidth
|
|
181
|
-
const previous = { overflow: document.body.style.overflow, paddingRight: document.body.style.paddingRight }
|
|
182
|
-
|
|
183
|
-
document.body.style.overflow = 'hidden'
|
|
184
|
-
if (gap > 0) document.body.style.paddingRight = `${gap}px`
|
|
185
|
-
|
|
186
|
-
restoreScroll = () => {
|
|
187
|
-
document.body.style.overflow = previous.overflow
|
|
188
|
-
document.body.style.paddingRight = previous.paddingRight
|
|
189
|
-
restoreScroll = null
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function unlockScroll() {
|
|
194
|
-
if (restoreScroll) restoreScroll()
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/*
|
|
198
|
-
* Focus moves in on open and back on close.
|
|
199
|
-
*
|
|
200
|
-
* A dialog that leaves focus behind is unreachable by keyboard: Tab walks the
|
|
201
|
-
* page underneath it, and a screen reader never learns anything opened. Focus
|
|
202
|
-
* returns to whatever opened it on the way out, so closing does not dump the
|
|
203
|
-
* reader at the top of the document.
|
|
204
|
-
*/
|
|
205
|
-
let opener = null
|
|
206
|
-
|
|
207
|
-
/*
|
|
208
|
-
* The next chance to try, whichever comes first.
|
|
209
|
-
*
|
|
210
|
-
* requestAnimationFrame is the right signal when the page is painting and is
|
|
211
|
-
* suspended entirely when it is not - a background tab, a parked window - so a
|
|
212
|
-
* timer races it and the first to arrive wins.
|
|
213
|
-
*/
|
|
214
|
-
function soon(callback) {
|
|
215
|
-
let done = false
|
|
216
|
-
|
|
217
|
-
const once = () => {
|
|
218
|
-
if (done) return
|
|
219
|
-
done = true
|
|
220
|
-
callback()
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
requestAnimationFrame(once)
|
|
224
|
-
setTimeout(once, 32)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/*
|
|
228
|
-
* Retried across frames, because focus is refused before the dialog is shown.
|
|
229
|
-
*
|
|
230
|
-
* `:show` toggles display, and that has not happened yet on the frame the
|
|
231
|
-
* effect runs: focus() on a display:none element is a silent no-op, so a single
|
|
232
|
-
* attempt left focus on the body every time. Bounded, so a dialog with nothing
|
|
233
|
-
* focusable cannot spin - the panel carries tabindex=-1 and takes focus in that
|
|
234
|
-
* case - and it stops if the dialog closed in the meantime.
|
|
235
|
-
*/
|
|
236
|
-
function focusFirst(attempts) {
|
|
237
|
-
if (!isOpen()) return
|
|
238
|
-
|
|
239
|
-
const panel = panelEl()
|
|
240
|
-
if (!panel) return
|
|
241
|
-
|
|
242
|
-
const target = panel.querySelector('[autofocus]') || focusable()[0] || panel
|
|
243
|
-
|
|
244
|
-
target.focus?.()
|
|
245
|
-
|
|
246
|
-
if (document.activeElement === target) return
|
|
247
|
-
if (attempts > 0) soon(() => focusFirst(attempts - 1))
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function captureFocus() {
|
|
251
|
-
opener = document.activeElement
|
|
252
|
-
|
|
253
|
-
soon(() => focusFirst(10))
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function releaseFocus() {
|
|
257
|
-
const target = opener
|
|
258
|
-
opener = null
|
|
259
|
-
if (target && typeof target.focus === 'function') target.focus()
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
effect(() => {
|
|
263
|
-
if (!mounted()) return
|
|
264
|
-
|
|
265
|
-
if (isOpen()) {
|
|
266
|
-
lockScroll()
|
|
267
|
-
captureFocus()
|
|
268
|
-
document.addEventListener('keydown', onDocumentKey)
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
unlockScroll()
|
|
272
|
-
releaseFocus()
|
|
273
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
274
|
-
}
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
onDestroy(() => {
|
|
278
|
-
// A dialog removed while open would otherwise leave the page locked, with no
|
|
279
|
-
// dialog left to unlock it.
|
|
280
|
-
unlockScroll()
|
|
281
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
defineExpose({
|
|
285
|
-
open: () => isOpen.set(true),
|
|
286
|
-
close,
|
|
287
|
-
isOpen,
|
|
288
|
-
})
|
|
289
|
-
</script>
|
|
290
|
-
|
|
291
|
-
<div
|
|
292
|
-
x-ref="rootRef"
|
|
293
|
-
:show="isOpen()"
|
|
294
|
-
class="{{ dialogClasses }}"
|
|
295
|
-
data-stx-dialog="{{ dialogInstanceId }}"
|
|
296
|
-
role="dialog"
|
|
297
|
-
aria-modal="true"
|
|
298
|
-
@if(title)aria-label="{{ title }}"@endif
|
|
299
|
-
@click="onRootClick($event)"
|
|
300
|
-
>
|
|
301
|
-
<slot />
|
|
302
|
-
</div>
|