@stacksjs/components 0.2.464 → 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
|
@@ -72,8 +72,8 @@ function onClose(event) { event.stopPropagation(); close() }
|
|
|
72
72
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
73
73
|
* otherwise this would steal it from wherever the user actually is.
|
|
74
74
|
*/
|
|
75
|
-
function
|
|
76
|
-
if (
|
|
75
|
+
function onEscape() {
|
|
76
|
+
if (!isOpen()) return
|
|
77
77
|
close()
|
|
78
78
|
if (!rootEl) return
|
|
79
79
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -166,13 +166,25 @@ onMount(() => {
|
|
|
166
166
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
167
167
|
}
|
|
168
168
|
document.addEventListener('click', outsideHandler, true)
|
|
169
|
-
document.addEventListener('keydown', onDocumentKey)
|
|
170
169
|
document.addEventListener('keydown', onMenuKey)
|
|
171
170
|
})
|
|
172
171
|
|
|
172
|
+
/*
|
|
173
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
174
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
175
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
176
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
177
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
178
|
+
* trap Tab or move focus.
|
|
179
|
+
*/
|
|
180
|
+
effect(() => {
|
|
181
|
+
if (isOpen()) window.stx.overlays.open(dropdownInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
182
|
+
else window.stx.overlays.close(dropdownInstanceId)
|
|
183
|
+
})
|
|
184
|
+
|
|
173
185
|
onDestroy(() => {
|
|
186
|
+
window.stx.overlays.close(dropdownInstanceId)
|
|
174
187
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
175
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
176
188
|
document.removeEventListener('keydown', onMenuKey)
|
|
177
189
|
})
|
|
178
190
|
|
|
@@ -107,8 +107,8 @@ function onSelect(event) {
|
|
|
107
107
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
108
108
|
* otherwise this would steal it from wherever the user actually is.
|
|
109
109
|
*/
|
|
110
|
-
function
|
|
111
|
-
if (
|
|
110
|
+
function onEscape() {
|
|
111
|
+
if (!isOpen()) return
|
|
112
112
|
close()
|
|
113
113
|
if (!rootEl) return
|
|
114
114
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -239,13 +239,25 @@ onMount(() => {
|
|
|
239
239
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
240
240
|
}
|
|
241
241
|
document.addEventListener('click', outsideHandler, true)
|
|
242
|
-
document.addEventListener('keydown', onDocumentKey)
|
|
243
242
|
document.addEventListener('keydown', onListboxKey)
|
|
244
243
|
})
|
|
245
244
|
|
|
245
|
+
/*
|
|
246
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
247
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
248
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
249
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
250
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
251
|
+
* trap Tab or move focus.
|
|
252
|
+
*/
|
|
253
|
+
effect(() => {
|
|
254
|
+
if (isOpen()) window.stx.overlays.open(listboxInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
255
|
+
else window.stx.overlays.close(listboxInstanceId)
|
|
256
|
+
})
|
|
257
|
+
|
|
246
258
|
onDestroy(() => {
|
|
259
|
+
window.stx.overlays.close(listboxInstanceId)
|
|
247
260
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
248
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
249
261
|
document.removeEventListener('keydown', onListboxKey)
|
|
250
262
|
})
|
|
251
263
|
|
|
@@ -50,8 +50,8 @@ function onOpen(event) { event.stopPropagation(); open() }
|
|
|
50
50
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
51
51
|
* otherwise this would steal it from wherever the user actually is.
|
|
52
52
|
*/
|
|
53
|
-
function
|
|
54
|
-
if (
|
|
53
|
+
function onEscape() {
|
|
54
|
+
if (!isOpen()) return
|
|
55
55
|
close()
|
|
56
56
|
if (!rootEl) return
|
|
57
57
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -68,12 +68,24 @@ onMount(() => {
|
|
|
68
68
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
69
69
|
}
|
|
70
70
|
document.addEventListener('click', outsideHandler, true)
|
|
71
|
-
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
75
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
76
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
77
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
78
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
79
|
+
* trap Tab or move focus.
|
|
80
|
+
*/
|
|
81
|
+
effect(() => {
|
|
82
|
+
if (isOpen()) window.stx.overlays.open(popoverInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
83
|
+
else window.stx.overlays.close(popoverInstanceId)
|
|
72
84
|
})
|
|
73
85
|
|
|
74
86
|
onDestroy(() => {
|
|
87
|
+
window.stx.overlays.close(popoverInstanceId)
|
|
75
88
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
76
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
77
89
|
})
|
|
78
90
|
|
|
79
91
|
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* One tab in a <TabList>. A plain button with the role, its value and the
|
|
4
|
+
* panel it controls; the list keeps `aria-selected` and `tabindex` on it.
|
|
5
|
+
*
|
|
6
|
+
* No client script, so no scope of its own: it is a button in the strip,
|
|
7
|
+
* nothing around it, and `@click` or bound attributes written on it land on
|
|
8
|
+
* the button in the caller's scope. Style the selected state with
|
|
9
|
+
* `aria-selected:` utilities, which outrank the base classes.
|
|
10
|
+
*/
|
|
11
|
+
export const value = $props.value ?? ''
|
|
12
|
+
export const controls = $props.controls || ''
|
|
13
|
+
export const disabled = $bool($props.disabled)
|
|
14
|
+
export const variant = $props.variant || 'line'
|
|
15
|
+
export const className = $props.className || ''
|
|
16
|
+
|
|
17
|
+
const focusRing = 'focus:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
|
|
18
|
+
const variantClasses = {
|
|
19
|
+
line: `-mb-px px-4 py-2 font-medium text-sm border-b-2 border-transparent text-fg-muted hover:text-fg aria-selected:border-accent aria-selected:text-accent transition-colors ${focusRing}`,
|
|
20
|
+
pills: `px-3 py-1.5 font-medium text-sm rounded-control text-fg-muted hover:text-fg aria-selected:bg-field aria-selected:text-fg aria-selected:shadow-sm transition-colors ${focusRing}`,
|
|
21
|
+
none: '',
|
|
22
|
+
}
|
|
23
|
+
export const tabClasses = `${variantClasses[variant] ?? variantClasses.line} ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`.replace(/\s+/g, ' ').trim()
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
role="tab"
|
|
29
|
+
data-value="{{ value }}"
|
|
30
|
+
aria-selected="false"
|
|
31
|
+
tabindex="-1"
|
|
32
|
+
@if(controls)aria-controls="{{ controls }}"@endif
|
|
33
|
+
@if(disabled)disabled@endif
|
|
34
|
+
class="{{ tabClasses }}"
|
|
35
|
+
><slot /></button>
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* A tab strip whose selection and panels belong to the page (stacksjs/stx#2058).
|
|
4
|
+
*
|
|
5
|
+
* <Tabs> owns both its selection and its panels: it renders every panel inside
|
|
6
|
+
* itself and remembers the tab it was told to start on. That suits a settings
|
|
7
|
+
* card. It does not suit tabs that switch between whole sections of a page,
|
|
8
|
+
* where the selection is kept in the URL or a store and each section is behind
|
|
9
|
+
* its own `:if`, so a section nobody opened never fetches its data.
|
|
10
|
+
*
|
|
11
|
+
* TabList is the behaviour alone. Its children are `role="tab"` elements, a
|
|
12
|
+
* `<Tab>` or any element with `role="tab"` and `data-value` (a `:for` row
|
|
13
|
+
* works), and it gives them what the role promises: one tab stop on the
|
|
14
|
+
* selected tab, the arrow keys, Home and End moving between them and selecting
|
|
15
|
+
* as they go, and `aria-selected` kept true on exactly one. The selection is a
|
|
16
|
+
* `v-model:value`, or `:value` with `@change`.
|
|
17
|
+
*
|
|
18
|
+
* <TabList v-model:value="tab" label="Store sections" variant="line">
|
|
19
|
+
* <Tab value="products" controls="products-panel">Products</Tab>
|
|
20
|
+
* <Tab value="sales" controls="sales-panel">Sales</Tab>
|
|
21
|
+
* </TabList>
|
|
22
|
+
* <section :if="tab === 'products'" id="products-panel" role="tabpanel">…</section>
|
|
23
|
+
*/
|
|
24
|
+
export const value = $props.value ?? ''
|
|
25
|
+
export const label = $props.label || ''
|
|
26
|
+
export const labelledby = $props.labelledby || ''
|
|
27
|
+
export const orientation = $props.orientation === 'vertical' ? 'vertical' : 'horizontal'
|
|
28
|
+
export const variant = $props.variant || 'line'
|
|
29
|
+
export const className = $props.className || ''
|
|
30
|
+
|
|
31
|
+
const variantClasses = {
|
|
32
|
+
line: 'flex gap-1 border-b border-line',
|
|
33
|
+
pills: 'inline-flex gap-1 p-1 bg-surface-raised rounded-panel',
|
|
34
|
+
none: '',
|
|
35
|
+
}
|
|
36
|
+
const directionClasses = orientation === 'vertical' ? 'flex-col' : ''
|
|
37
|
+
export const listClasses = `${variantClasses[variant] ?? variantClasses.line} ${directionClasses} ${className}`.replace(/\s+/g, ' ').trim()
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<script client>
|
|
41
|
+
const emit = defineEmits()
|
|
42
|
+
const orientation = {{ orientation }}
|
|
43
|
+
const selected = useModel('value', { default: {{ value }}, parse: v => v == null ? '' : String(v) })
|
|
44
|
+
const listRef = useRef('listRef')
|
|
45
|
+
const mounted = state(false)
|
|
46
|
+
let observer = null
|
|
47
|
+
|
|
48
|
+
/** This list's own tabs: not a nested list's, and not a disabled one. */
|
|
49
|
+
function ownTabs(includeDisabled) {
|
|
50
|
+
const root = listRef.value
|
|
51
|
+
if (!root) return []
|
|
52
|
+
return Array.from(root.querySelectorAll('[role="tab"]')).filter(tab =>
|
|
53
|
+
tab.closest('[role="tablist"]') === root
|
|
54
|
+
&& (includeDisabled || (!tab.hasAttribute('disabled') && tab.getAttribute('aria-disabled') !== 'true')))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function valueOf(tab, index) {
|
|
58
|
+
const value = tab.getAttribute('data-value')
|
|
59
|
+
return value == null ? String(index) : value
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* One stop in the tab order, on the selected tab; the first enabled tab when
|
|
64
|
+
* nothing is selected yet, so the strip can still be reached. Run on every
|
|
65
|
+
* change of selection and of the tabs themselves, because a `:for` adds and
|
|
66
|
+
* removes them after mount.
|
|
67
|
+
*/
|
|
68
|
+
function sync() {
|
|
69
|
+
const tabs = ownTabs(true)
|
|
70
|
+
const current = selected()
|
|
71
|
+
let any = false
|
|
72
|
+
tabs.forEach((tab, index) => {
|
|
73
|
+
const on = valueOf(tab, index) === current
|
|
74
|
+
if (on) any = true
|
|
75
|
+
tab.setAttribute('aria-selected', on ? 'true' : 'false')
|
|
76
|
+
tab.setAttribute('tabindex', on ? '0' : '-1')
|
|
77
|
+
})
|
|
78
|
+
if (!any) {
|
|
79
|
+
const first = ownTabs(false)[0]
|
|
80
|
+
if (first) first.setAttribute('tabindex', '0')
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function select(tab) {
|
|
85
|
+
const index = ownTabs(true).indexOf(tab)
|
|
86
|
+
const value = valueOf(tab, index)
|
|
87
|
+
if (value === selected()) return
|
|
88
|
+
selected.set(value)
|
|
89
|
+
emit('change', value)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function onClick(event) {
|
|
93
|
+
const tab = event.target && event.target.closest ? event.target.closest('[role="tab"]') : null
|
|
94
|
+
if (!tab || !ownTabs(false).includes(tab)) return
|
|
95
|
+
select(tab)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/*
|
|
99
|
+
* The keys the role announces. Selection follows focus (automatic
|
|
100
|
+
* activation), which is what a tab that switches a section of the page wants.
|
|
101
|
+
*/
|
|
102
|
+
function onKey(event) {
|
|
103
|
+
const tabs = ownTabs(false)
|
|
104
|
+
const from = event.target && event.target.closest ? event.target.closest('[role="tab"]') : null
|
|
105
|
+
const index = tabs.indexOf(from)
|
|
106
|
+
if (index === -1) return
|
|
107
|
+
const forward = orientation === 'vertical' ? 'ArrowDown' : 'ArrowRight'
|
|
108
|
+
const back = orientation === 'vertical' ? 'ArrowUp' : 'ArrowLeft'
|
|
109
|
+
let next = -1
|
|
110
|
+
if (event.key === forward) next = (index + 1) % tabs.length
|
|
111
|
+
else if (event.key === back) next = (index - 1 + tabs.length) % tabs.length
|
|
112
|
+
else if (event.key === 'Home') next = 0
|
|
113
|
+
else if (event.key === 'End') next = tabs.length - 1
|
|
114
|
+
if (next === -1) return
|
|
115
|
+
event.preventDefault()
|
|
116
|
+
tabs[next].focus()
|
|
117
|
+
select(tabs[next])
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
effect(() => {
|
|
121
|
+
selected()
|
|
122
|
+
if (mounted()) sync()
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
onMount(() => {
|
|
126
|
+
mounted.set(true)
|
|
127
|
+
sync()
|
|
128
|
+
const root = listRef.value
|
|
129
|
+
if (root && typeof MutationObserver !== 'undefined') {
|
|
130
|
+
observer = new MutationObserver(() => sync())
|
|
131
|
+
observer.observe(root, { childList: true, subtree: true })
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
onDestroy(() => {
|
|
136
|
+
if (observer) observer.disconnect()
|
|
137
|
+
observer = null
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
defineExpose({ selected })
|
|
141
|
+
</script>
|
|
142
|
+
|
|
143
|
+
<div
|
|
144
|
+
x-ref="listRef"
|
|
145
|
+
role="tablist"
|
|
146
|
+
aria-orientation="{{ orientation }}"
|
|
147
|
+
@if(label)aria-label="{{ label }}"@endif
|
|
148
|
+
@if(labelledby)aria-labelledby="{{ labelledby }}"@endif
|
|
149
|
+
class="{{ listClasses }}"
|
|
150
|
+
@click="onClick($event)"
|
|
151
|
+
@keydown="onKey($event)"
|
|
152
|
+
>
|
|
153
|
+
<slot />
|
|
154
|
+
</div>
|
package/src/ui/tabs/Tabs.stx
CHANGED
|
@@ -167,7 +167,10 @@ function onTabKey(event, index) {
|
|
|
167
167
|
else if (event.key === 'End') { event.preventDefault(); next = tabCount - 1 }
|
|
168
168
|
if (next !== index) {
|
|
169
169
|
selectTab(next)
|
|
170
|
-
|
|
170
|
+
// Slot mode numbers its tabs per instance; `tab-N` is the prop mode's id,
|
|
171
|
+
// so arrowing in slot mode moved the selection and left focus behind.
|
|
172
|
+
const id = hasPropTabs ? `tab-${next}` : discoveredTabs()[next]?.tabId
|
|
173
|
+
if (id) document.getElementById(id)?.focus()
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
176
|
|
package/src/ui/tabs/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { default as Tab } from './Tab.stx'
|
|
2
|
+
export { default as TabList } from './TabList.stx'
|
|
1
3
|
export { default as TabPanel } from './TabPanel.stx'
|
|
2
4
|
export { default as Tabs } from './Tabs.stx'
|
|
3
5
|
|
|
@@ -8,7 +10,8 @@ export { default as Tabs } from './Tabs.stx'
|
|
|
8
10
|
*
|
|
9
11
|
* See stacksjs/stx#1703.
|
|
10
12
|
*/
|
|
11
|
-
|
|
13
|
+
/** One tab of the legacy prop API. Named apart from the `<Tab>` component. */
|
|
14
|
+
export interface TabDefinition {
|
|
12
15
|
label: string
|
|
13
16
|
content: string
|
|
14
17
|
icon?: string
|
|
@@ -16,11 +19,11 @@ export interface Tab {
|
|
|
16
19
|
|
|
17
20
|
export interface TabsProps {
|
|
18
21
|
/** Legacy: array of tab definitions with string content. */
|
|
19
|
-
tabs?:
|
|
22
|
+
tabs?: TabDefinition[]
|
|
20
23
|
defaultTab?: number
|
|
21
24
|
orientation?: 'horizontal' | 'vertical'
|
|
22
25
|
variant?: 'line' | 'pills' | 'enclosed'
|
|
23
|
-
onChange?: (index: number, tab:
|
|
26
|
+
onChange?: (index: number, tab: TabDefinition) => void
|
|
24
27
|
className?: string
|
|
25
28
|
}
|
|
26
29
|
|
|
@@ -48,3 +51,34 @@ export interface TabPanelProps {
|
|
|
48
51
|
icon?: string
|
|
49
52
|
className?: string
|
|
50
53
|
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A tab strip whose selection and panels belong to the page: `<TabList>` with
|
|
57
|
+
* `<Tab>` children (or any `role="tab"` element with `data-value`). The list
|
|
58
|
+
* keeps one tab stop, the arrow keys, Home and End, and `aria-selected`; the
|
|
59
|
+
* page keeps its panels, behind its own `:if`. See stacksjs/stx#2058.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```html
|
|
63
|
+
* <TabList v-model:value="tab" label="Store sections">
|
|
64
|
+
* <Tab value="products" controls="products-panel">Products</Tab>
|
|
65
|
+
* <Tab value="sales" controls="sales-panel">Sales</Tab>
|
|
66
|
+
* </TabList>
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export interface TabListProps {
|
|
70
|
+
value?: string
|
|
71
|
+
label?: string
|
|
72
|
+
labelledby?: string
|
|
73
|
+
orientation?: 'horizontal' | 'vertical'
|
|
74
|
+
variant?: 'line' | 'pills' | 'none'
|
|
75
|
+
className?: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface TabProps {
|
|
79
|
+
value: string
|
|
80
|
+
controls?: string
|
|
81
|
+
disabled?: boolean
|
|
82
|
+
variant?: 'line' | 'pills' | 'none'
|
|
83
|
+
className?: string
|
|
84
|
+
}
|
|
@@ -133,9 +133,19 @@ function hideTooltip() {
|
|
|
133
133
|
* unless this tooltip is the one showing. useEventListener drops it on
|
|
134
134
|
* teardown, so a page of tooltips does not leak one apiece.
|
|
135
135
|
*/
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
/*
|
|
137
|
+
* While it shows, the tooltip is a popup layer on the page's overlay stack, so
|
|
138
|
+
* Escape dismisses it first: a tooltip over a dialog's field goes, and the
|
|
139
|
+
* dialog stays (stacksjs/stx#2057). It listened on the document itself, where
|
|
140
|
+
* the dialog's listener could take the same Escape.
|
|
141
|
+
*/
|
|
142
|
+
effect(() => {
|
|
143
|
+
if (isVisible()) window.stx.overlays.open(tooltipId, { modal: false, panel: null, onEscape: hideTooltip })
|
|
144
|
+
else window.stx.overlays.close(tooltipId)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
onDestroy(() => {
|
|
148
|
+
window.stx.overlays.close(tooltipId)
|
|
139
149
|
})
|
|
140
150
|
|
|
141
151
|
/*
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's overlay stack, for an overlay the app draws itself.
|
|
3
|
+
*
|
|
4
|
+
* Dialog, Drawer and stxConfirm/stxAlert all go on one stack in the stx
|
|
5
|
+
* runtime (`window.stx.overlays`): the topmost overlay answers Escape and owns
|
|
6
|
+
* Tab, the page stays locked from the first open to the last close, and focus
|
|
7
|
+
* moves into an overlay and back to whatever opened it. An app's own slide-over
|
|
8
|
+
* or full-screen panel joins the same stack through these, so it nests with the
|
|
9
|
+
* library's dialogs instead of competing with them (stacksjs/stx#2057).
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { closeOverlay, openOverlay } from '@stacksjs/components'
|
|
13
|
+
*
|
|
14
|
+
* effect(() => {
|
|
15
|
+
* if (panelOpen()) openOverlay('workout-panel', { panel: '#wp-panel', onEscape: close })
|
|
16
|
+
* else closeOverlay('workout-panel')
|
|
17
|
+
* })
|
|
18
|
+
* onDestroy(() => closeOverlay('workout-panel'))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Every call is a no-op where there is no runtime (server rendering, tests
|
|
22
|
+
* without a DOM), so shared code can call them unguarded.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export interface OverlayOptions {
|
|
26
|
+
/** Where focus is kept while this overlay is on top: an element, a selector, or a function returning one. A selector or function is looked up each time, since the panel may not be rendered yet when the overlay opens. */
|
|
27
|
+
panel: Element | string | null | (() => Element | null)
|
|
28
|
+
/** The overlay's outermost element, when it is not the panel. An overlay that is a direct child of `<body>` makes the rest of the page inert while it is on top. */
|
|
29
|
+
root?: Element | null
|
|
30
|
+
/** Escape while this overlay is on top. Leave it out for one that must be answered rather than dismissed. */
|
|
31
|
+
onEscape?: (() => void) | null
|
|
32
|
+
/** Where focus goes first. Defaults to `[autofocus]`, then the first focusable element, then the panel. */
|
|
33
|
+
initialFocus?: HTMLElement | null | (() => HTMLElement | null)
|
|
34
|
+
/** Where focus goes back to on close. Defaults to whatever had focus when it opened. */
|
|
35
|
+
opener?: Element | null
|
|
36
|
+
/** Give focus back on close. Default true. */
|
|
37
|
+
restoreFocus?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface OverlayStack {
|
|
41
|
+
open: (id: string, options: OverlayOptions) => void
|
|
42
|
+
close: (id: string) => void
|
|
43
|
+
isTop: (id: string) => boolean
|
|
44
|
+
list: () => string[]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function stack(): OverlayStack | undefined {
|
|
48
|
+
return (globalThis as { stx?: { overlays?: OverlayStack } }).stx?.overlays
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Put an overlay on top. Calling it again for an open id only updates its options. */
|
|
52
|
+
export function openOverlay(id: string, options: OverlayOptions): void {
|
|
53
|
+
stack()?.open(id, options)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Take an overlay off the stack, wherever it is in it. */
|
|
57
|
+
export function closeOverlay(id: string): void {
|
|
58
|
+
stack()?.close(id)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Whether this overlay is the one that has the keyboard. */
|
|
62
|
+
export function isTopOverlay(id: string): boolean {
|
|
63
|
+
return stack()?.isTop(id) ?? false
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Open overlay ids, outermost first. */
|
|
67
|
+
export function openOverlays(): string[] {
|
|
68
|
+
return stack()?.list() ?? []
|
|
69
|
+
}
|