@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
|
@@ -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>
|
|
@@ -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
|
|
|
@@ -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
|
/*
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export { default as Hero } from './components/Hero.stx';
|
|
|
34
34
|
export { default as Installation } from './components/Installation.stx';
|
|
35
35
|
// Export composables
|
|
36
36
|
export * from './composables/index';
|
|
37
|
+
// The page's overlay stack, for overlays an app draws itself (stacksjs/stx#2057).
|
|
38
|
+
export * from './utils/overlays';
|
|
37
39
|
// Theme seam — see src/theme for how an app redirects the components' colours.
|
|
38
40
|
export * from './theme/index';
|
|
39
41
|
// Export UI components
|