@stacksjs/components 0.2.368 → 0.2.370

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.
Files changed (81) hide show
  1. package/dist/{Accordion-py9ntmst.stx → Accordion-ehpymjam.stx} +1 -1
  2. package/dist/{AccordionItem-asmsqxz9.stx → AccordionItem-fc4ekdqf.stx} +1 -1
  3. package/dist/{Button-tcjt3m8s.stx → Button-k2q6811a.stx} +1 -1
  4. package/dist/Combobox-9xh1jgjr.stx +266 -0
  5. package/dist/{ComboboxButton-g76stp1e.stx → ComboboxButton-4r6a45s1.stx} +8 -1
  6. package/dist/{ComboboxInput-4jcpvw7e.stx → ComboboxInput-1gyfpnca.stx} +4 -1
  7. package/dist/{ComboboxOption-vnb67p8d.stx → ComboboxOption-wkw70js7.stx} +27 -1
  8. package/dist/{ComboboxOptions-nbndbrxz.stx → ComboboxOptions-zhr9b6rx.stx} +1 -1
  9. package/dist/{CommandPalette-6rjcgske.stx → CommandPalette-vvaqtqat.stx} +3 -3
  10. package/dist/CommandPaletteItem-7290ce1z.stx +40 -0
  11. package/dist/{DefaultPaymentMethod-r0hcjajr.stx → DefaultPaymentMethod-ss3x61tr.stx} +1 -1
  12. package/dist/{Drawer-jcdj3qk2.stx → Drawer-hc0jjpsw.stx} +1 -1
  13. package/dist/Dropdown-25160tc6.stx +204 -0
  14. package/dist/{DropdownButton-tx9hb2de.stx → DropdownButton-wxc25hsy.stx} +3 -1
  15. package/dist/{DropdownItem-wht1vcm5.stx → DropdownItem-af0vzc8a.stx} +15 -1
  16. package/dist/{DropdownItems-v12h6zpf.stx → DropdownItems-bkz7jkyz.stx} +1 -1
  17. package/dist/Listbox-32gzxace.stx +273 -0
  18. package/dist/{ListboxButton-t43pp03e.stx → ListboxButton-gan8e3nw.stx} +3 -1
  19. package/dist/{ListboxOption-9c9jpz1n.stx → ListboxOption-gpaqvk3s.stx} +14 -1
  20. package/dist/{ListboxOptions-qxrkrb8z.stx → ListboxOptions-2928864k.stx} +1 -1
  21. package/dist/{Login-j3pc04ka.stx → Login-3dsk93vm.stx} +4 -4
  22. package/dist/{Notification-7wgk0sw6.stx → Notification-2ws4ym4s.stx} +2 -2
  23. package/dist/{Pagination-z9jxnaeq.stx → Pagination-330ybzf1.stx} +2 -2
  24. package/dist/Popover-9m42pym0.stx +101 -0
  25. package/dist/{PopoverButton-70th24xc.stx → PopoverButton-3w6550hv.stx} +2 -1
  26. package/dist/{PopoverPanel-7771yf35.stx → PopoverPanel-d84gk1w1.stx} +1 -1
  27. package/dist/{RadioGroup-hzz4xep9.stx → RadioGroup-smqcqgds.stx} +15 -2
  28. package/dist/{RadioGroupOption-7fcgfsah.stx → RadioGroupOption-twcw1b2a.stx} +14 -2
  29. package/dist/{Select-sbr8dqzn.stx → Select-danh680d.stx} +1 -1
  30. package/dist/{Signup-77y9ea7t.stx → Signup-dh96kskd.stx} +2 -2
  31. package/dist/{StepperStep-34kwv0t0.stx → StepperStep-b78wmshd.stx} +1 -1
  32. package/dist/{SubscriptionCheckout-pggq5a4k.stx → SubscriptionCheckout-n3btqrzk.stx} +2 -2
  33. package/dist/{Switch-fxbw7s16.stx → Switch-27hp6pq5.stx} +1 -1
  34. package/dist/{TabBarItem-wv2r8496.stx → TabBarItem-kddfnhk3.stx} +1 -1
  35. package/dist/{Tabs-51vr631j.stx → Tabs-f1n3ggkw.stx} +1 -1
  36. package/dist/{TwoFactorChallenge-28px8pyk.stx → TwoFactorChallenge-ete7yk9y.stx} +1 -1
  37. package/dist/index.js +7 -7
  38. package/package.json +3 -3
  39. package/src/components/Footer.stx +2 -2
  40. package/src/components/Hero.stx +1 -1
  41. package/src/ui/accordion/Accordion.stx +1 -1
  42. package/src/ui/accordion/AccordionItem.stx +1 -1
  43. package/src/ui/auth/Login.stx +4 -4
  44. package/src/ui/auth/Signup.stx +2 -2
  45. package/src/ui/auth/TwoFactorChallenge.stx +1 -1
  46. package/src/ui/button/Button.stx +1 -1
  47. package/src/ui/combobox/Combobox.stx +174 -4
  48. package/src/ui/combobox/ComboboxButton.stx +8 -1
  49. package/src/ui/combobox/ComboboxInput.stx +4 -1
  50. package/src/ui/combobox/ComboboxOption.stx +27 -1
  51. package/src/ui/combobox/ComboboxOptions.stx +1 -1
  52. package/src/ui/command-palette/CommandPalette.stx +3 -3
  53. package/src/ui/command-palette/CommandPaletteItem.stx +14 -1
  54. package/src/ui/drawer/Drawer.stx +1 -1
  55. package/src/ui/dropdown/Dropdown.stx +122 -0
  56. package/src/ui/dropdown/DropdownButton.stx +3 -1
  57. package/src/ui/dropdown/DropdownItem.stx +15 -1
  58. package/src/ui/dropdown/DropdownItems.stx +1 -1
  59. package/src/ui/listbox/Listbox.stx +175 -3
  60. package/src/ui/listbox/ListboxButton.stx +3 -1
  61. package/src/ui/listbox/ListboxOption.stx +14 -1
  62. package/src/ui/listbox/ListboxOptions.stx +1 -1
  63. package/src/ui/mobile/TabBarItem.stx +1 -1
  64. package/src/ui/notification/Notification.stx +2 -2
  65. package/src/ui/pagination/Pagination.stx +2 -2
  66. package/src/ui/payment/DefaultPaymentMethod.stx +1 -1
  67. package/src/ui/payment/SubscriptionCheckout.stx +2 -2
  68. package/src/ui/popover/Popover.stx +43 -2
  69. package/src/ui/popover/PopoverButton.stx +2 -1
  70. package/src/ui/popover/PopoverPanel.stx +1 -1
  71. package/src/ui/radio-group/RadioGroup.stx +15 -2
  72. package/src/ui/radio-group/RadioGroupOption.stx +14 -2
  73. package/src/ui/select/Select.stx +1 -1
  74. package/src/ui/stepper/StepperStep.stx +1 -1
  75. package/src/ui/switch/Switch.stx +1 -1
  76. package/src/ui/tabs/Tabs.stx +1 -1
  77. package/dist/Combobox-06x0nywb.stx +0 -96
  78. package/dist/CommandPaletteItem-6rp133ta.stx +0 -27
  79. package/dist/Dropdown-cmwge7vx.stx +0 -82
  80. package/dist/Listbox-e5jreb0a.stx +0 -101
  81. package/dist/Popover-3g8rgxt1.stx +0 -60
@@ -3,7 +3,7 @@ export const className = $props.className || ''
3
3
  export const as = $props.as || 'button'
4
4
  export const disabled = $bool($props.disabled)
5
5
 
6
- const baseClasses = 'inline-flex justify-center items-center rounded-control focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-solid focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
6
+ const baseClasses = 'inline-flex justify-center items-center rounded-control focus:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
7
7
  export const buttonClasses = `${baseClasses} ${className}`.trim()
8
8
  </script>
9
9
 
@@ -22,6 +22,8 @@ function onClick(event) {
22
22
  :is="{{ as }}"
23
23
  class="{{ buttonClasses }}"
24
24
  data-stx-dropdown-button
25
+ aria-haspopup="menu"
26
+ aria-expanded="false"
25
27
  @if(disabled)disabled aria-disabled="true"@endif
26
28
  @click="onClick($event)"
27
29
  >
@@ -3,6 +3,7 @@ export const className = $props.className || ''
3
3
  export const as = $props.as || 'div'
4
4
  export const disabled = $bool($props.disabled)
5
5
  export const value = $props.value
6
+ export const valueJson = JSON.stringify(value === undefined ? null : value)
6
7
 
7
8
  const baseClasses = 'group flex w-full items-center px-2 py-2 text-sm transition-colors text-fg hover:bg-accent-solid hover:text-accent-ink'
8
9
  const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'
@@ -12,7 +13,19 @@ export const itemClasses = `${baseClasses} ${disabledClasses} ${className}`.trim
12
13
  <script client>
13
14
  const emit = defineEmits()
14
15
  const isDisabled = {{ disabled }}
15
- const itemValue = {{ value === undefined ? 'null' : value }}
16
+ /*
17
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
18
+ * through an ordinary interpolation.
19
+ *
20
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
21
+ * token null into the script. An interpolation QUOTES a string, so what it
22
+ * emitted was the four-character string "null" -- truthy, in the one place a
23
+ * value is meant to be absent. JSON.stringify produces the correct literal for
24
+ * every type, null included, and raw interpolation passes it through unquoted.
25
+ * Calendar and DateRangePicker already avoid this sentinel and say why
26
+ * (stacksjs/stx#1981).
27
+ */
28
+ const itemValue = {!! valueJson !!}
16
29
 
17
30
  function onClick(event) {
18
31
  if (isDisabled) return
@@ -28,6 +41,7 @@ function onClick(event) {
28
41
  class="{{ itemClasses }}"
29
42
  data-stx-dropdown-item
30
43
  role="menuitem"
44
+ tabindex="-1"
31
45
  @if(disabled)aria-disabled="true"@endif
32
46
  @click="onClick($event)"
33
47
  >
@@ -2,7 +2,7 @@
2
2
  export const className = $props.className || ''
3
3
  export const as = $props.as || 'div'
4
4
 
5
- const baseClasses = 'absolute z-10 mt-2 origin-top-right divide-y divide-line rounded-panel bg-panel shadow-lg ring-1 ring-black/5 focus:outline-none dark:ring-neutral-600'
5
+ const baseClasses = 'absolute z-10 mt-2 origin-top-right divide-y divide-line rounded-panel bg-panel shadow-lg ring-1 ring-line focus:outline-none'
6
6
  export const itemsClasses = `${baseClasses} ${className}`.trim()
7
7
  </script>
8
8
 
@@ -0,0 +1,273 @@
1
+ <script server>
2
+ export const value = $props.value
3
+ export const valueJson = JSON.stringify(value === undefined ? null : value)
4
+ export const multiple = $bool($props.multiple)
5
+ export const className = $props.className || ''
6
+ export const as = $props.as || 'div'
7
+
8
+ const baseClasses = 'relative'
9
+ export const listboxClasses = `${baseClasses} ${className}`.trim()
10
+ export const listboxInstanceId = $uid
11
+ </script>
12
+
13
+ <script client>
14
+ const emit = defineEmits()
15
+ const listboxInstanceId = {{ listboxInstanceId }}
16
+ const multiple = {{ multiple }}
17
+ /*
18
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
19
+ * through an ordinary interpolation.
20
+ *
21
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
22
+ * token null into the script. An interpolation QUOTES a string, so what it
23
+ * emitted was the four-character string "null" -- truthy, in the one place a
24
+ * value is meant to be absent. JSON.stringify produces the correct literal for
25
+ * every type, null included, and raw interpolation passes it through unquoted.
26
+ * Calendar and DateRangePicker already avoid this sentinel and say why
27
+ * (stacksjs/stx#1981).
28
+ */
29
+ const initialValue = {!! valueJson !!}
30
+
31
+ const isOpen = state(false)
32
+ const selected = state(initialValue)
33
+ let rootEl = null
34
+ let outsideHandler = null
35
+
36
+ function isSelectedValue(v) {
37
+ const cur = selected()
38
+ if (multiple && Array.isArray(cur)) return cur.includes(v)
39
+ return cur === v
40
+ }
41
+
42
+ function selectValue(v) {
43
+ if (multiple) {
44
+ const cur = Array.isArray(selected()) ? selected() : []
45
+ selected.set(cur.includes(v) ? cur.filter(x => x !== v) : [...cur, v])
46
+ }
47
+ else {
48
+ selected.set(v)
49
+ isOpen.set(false)
50
+ }
51
+ syncOptionStates()
52
+ // The single-select branch above closes the panel without going through
53
+ // close(), so the trigger's state has to be refreshed here too.
54
+ syncExpanded()
55
+ emit('change', selected())
56
+ }
57
+
58
+ function syncOptionStates() {
59
+ if (!rootEl) return
60
+ const options = rootEl.querySelectorAll('[data-stx-listbox-option]')
61
+ for (const opt of options) {
62
+ const raw = opt.dataset.optionValue
63
+ let v
64
+ try { v = JSON.parse(raw ?? 'null') }
65
+ catch { v = raw }
66
+ const sel = isSelectedValue(v)
67
+ opt.setAttribute('aria-selected', sel ? 'true' : 'false')
68
+ opt.setAttribute('data-selected', sel ? 'true' : 'false')
69
+ }
70
+ }
71
+
72
+ /*
73
+ * The trigger carries the open state for assistive tech. `isOpen` already
74
+ * drove `data-state` on the root, which styles the panel but says nothing to a
75
+ * screen reader: the button announced itself as a plain button, with no
76
+ * indication that it opens anything or whether it is open right now.
77
+ */
78
+ function syncExpanded() {
79
+ if (!rootEl) return
80
+ const trigger = rootEl.querySelector('[data-stx-listbox-button]')
81
+ if (!trigger) return
82
+ trigger.setAttribute('aria-expanded', isOpen() ? 'true' : 'false')
83
+ const panel = rootEl.querySelector('[data-stx-listbox-options]')
84
+ if (!panel) return
85
+ if (!panel.id) panel.id = 'stx-listbox-panel-' + listboxInstanceId
86
+ trigger.setAttribute('aria-controls', panel.id)
87
+ }
88
+
89
+ function open() { if (!isOpen()) { isOpen.set(true); emit('change', selected()); syncExpanded() } }
90
+ function close() { if (isOpen()) { isOpen.set(false); syncExpanded() } }
91
+ function toggle() { isOpen() ? close() : open() }
92
+
93
+ function onToggle(event) { event.stopPropagation(); toggle() }
94
+ function onSelect(event) {
95
+ event.stopPropagation()
96
+ selectValue(event.detail)
97
+ }
98
+
99
+ /*
100
+ * Escape dismisses it, from anywhere rather than only from inside the panel.
101
+ *
102
+ * Opening one of these does not move focus, so a keydown bound on the panel
103
+ * never sees the first Escape - focus is still on whatever opened it. Drawer
104
+ * reached the same conclusion and binds on the document; this follows it, and
105
+ * only acts while open so one open popup does not swallow Escape for the page.
106
+ *
107
+ * Focus goes back to the trigger, but only if it had moved into the panel:
108
+ * otherwise this would steal it from wherever the user actually is.
109
+ */
110
+ function onDocumentKey(event) {
111
+ if (event.key !== 'Escape' || !isOpen()) return
112
+ close()
113
+ if (!rootEl) return
114
+ const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
115
+ if (!active || !rootEl.contains(active)) return
116
+ const trigger = rootEl.querySelector('[data-stx-listbox-button]')
117
+ if (trigger && trigger.focus) trigger.focus()
118
+ }
119
+
120
+ /*
121
+ * Roving focus over the options.
122
+ *
123
+ * `role="option"` on an li is not focusable on its own, so the options carry
124
+ * tabindex="-1" and focus moves programmatically -- the same arrangement
125
+ * <Dropdown> uses for its menu items. APG allows either this or
126
+ * aria-activedescendant for a listbox; <Combobox> is the case that REQUIRES
127
+ * the latter, because focus has to stay in its input.
128
+ *
129
+ * Arrows move focus and do not change the selection. Selection following focus
130
+ * is a documented variant, and the quieter of the two: arrowing past an option
131
+ * should not commit a value the user was only passing over.
132
+ */
133
+ function optionElements() {
134
+ if (!rootEl) return []
135
+ const all = rootEl.querySelectorAll('[data-stx-listbox-option]')
136
+ return Array.prototype.filter.call(all, option => option.getAttribute('aria-disabled') !== 'true')
137
+ }
138
+
139
+ function focusOptionAt(index) {
140
+ const options = optionElements()
141
+ if (!options.length) return
142
+ const target = options[(index + options.length) % options.length]
143
+ if (target && target.focus) target.focus()
144
+ }
145
+
146
+ function focusedOptionIndex() {
147
+ const doc = rootEl && rootEl.ownerDocument
148
+ return doc ? optionElements().indexOf(doc.activeElement) : -1
149
+ }
150
+
151
+ /** Opening lands on what is already chosen, so the current value is in view. */
152
+ function focusSelectedOrFirst(fallbackToLast) {
153
+ const options = optionElements()
154
+ const chosen = options.findIndex(option => option.getAttribute('aria-selected') === 'true')
155
+ if (chosen !== -1) focusOptionAt(chosen)
156
+ else focusOptionAt(fallbackToLast ? options.length - 1 : 0)
157
+ }
158
+
159
+ /*
160
+ * Type-ahead: a printable character jumps to the next option whose label
161
+ * starts with it, wrapping, so a long list is reachable without arrowing
162
+ * through all of it.
163
+ */
164
+ function focusByTypeAhead(character) {
165
+ const options = optionElements()
166
+ if (!options.length) return false
167
+ const wanted = character.toLowerCase()
168
+ const from = focusedOptionIndex()
169
+ for (let step = 1; step <= options.length; step++) {
170
+ const candidate = options[(from + step + options.length) % options.length]
171
+ const label = (candidate.textContent || '').trim().toLowerCase()
172
+ if (label.startsWith(wanted)) {
173
+ if (candidate.focus) candidate.focus()
174
+ return true
175
+ }
176
+ }
177
+ return false
178
+ }
179
+
180
+ /*
181
+ * Gated on the event coming from inside this listbox. The handler is on the
182
+ * document so Escape works before focus has moved into the panel, which would
183
+ * otherwise make ArrowDown a page-wide scroll hijack.
184
+ */
185
+ function onListboxKey(event) {
186
+ if (!rootEl || !rootEl.contains(event.target)) return
187
+ const key = event.key
188
+
189
+ if (!isOpen()) {
190
+ if (key !== 'ArrowDown' && key !== 'ArrowUp') return
191
+ event.preventDefault()
192
+ open()
193
+ focusSelectedOrFirst(key === 'ArrowUp')
194
+ return
195
+ }
196
+
197
+ if (key === 'ArrowDown' || key === 'ArrowUp') {
198
+ event.preventDefault()
199
+ const current = focusedOptionIndex()
200
+ if (current === -1) focusSelectedOrFirst(key === 'ArrowUp')
201
+ else focusOptionAt(current + (key === 'ArrowDown' ? 1 : -1))
202
+ return
203
+ }
204
+
205
+ if (key === 'Home' || key === 'End') {
206
+ event.preventDefault()
207
+ focusOptionAt(key === 'Home' ? 0 : optionElements().length - 1)
208
+ return
209
+ }
210
+
211
+ if (key === 'Enter' || key === ' ') {
212
+ // An li does not activate on Enter, so the option is clicked and runs the
213
+ // handler it already has.
214
+ const current = focusedOptionIndex()
215
+ if (current === -1) return
216
+ event.preventDefault()
217
+ optionElements()[current].click()
218
+ return
219
+ }
220
+
221
+ if (key === 'Tab') {
222
+ close()
223
+ return
224
+ }
225
+
226
+ // A single printable character, so modifier combinations still reach the
227
+ // browser.
228
+ if (key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {
229
+ if (focusByTypeAhead(key)) event.preventDefault()
230
+ }
231
+ }
232
+
233
+ onMount(() => {
234
+ rootEl = document.querySelector(`[data-listbox-id="${listboxInstanceId}"]`)
235
+ syncExpanded()
236
+ syncOptionStates()
237
+ outsideHandler = (event) => {
238
+ if (!isOpen()) return
239
+ if (rootEl && !rootEl.contains(event.target)) close()
240
+ }
241
+ document.addEventListener('click', outsideHandler, true)
242
+ document.addEventListener('keydown', onDocumentKey)
243
+ document.addEventListener('keydown', onListboxKey)
244
+ })
245
+
246
+ onDestroy(() => {
247
+ if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
248
+ document.removeEventListener('keydown', onDocumentKey)
249
+ document.removeEventListener('keydown', onListboxKey)
250
+ })
251
+
252
+ const dataState = derived(() => isOpen() ? 'open' : 'closed')
253
+
254
+ defineExpose({ isOpen, selected, toggle, open, close, selectValue })
255
+ </script>
256
+
257
+ <component
258
+ :is="{{ as }}"
259
+ class="{{ listboxClasses }}"
260
+ data-stx-listbox
261
+ data-listbox-id="{{ listboxInstanceId }}"
262
+ :data-state="dataState()"
263
+ @stx:listbox-toggle="onToggle($event)"
264
+ @stx:listbox-select="onSelect($event)"
265
+ >
266
+ <slot />
267
+ </component>
268
+
269
+ <style>
270
+ [data-stx-listbox][data-state="closed"] [data-stx-listbox-options] {
271
+ display: none;
272
+ }
273
+ </style>
@@ -3,7 +3,7 @@ export const className = $props.className || ''
3
3
  export const as = $props.as || 'button'
4
4
  export const disabled = $bool($props.disabled)
5
5
 
6
- const baseClasses = 'relative w-full cursor-pointer rounded-panel bg-panel py-2 pl-3 pr-10 text-left shadow-md focus:outline-none focus-visible:border-accent-solid focus-visible:ring-2 focus-visible:ring-accent-solid focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
6
+ const baseClasses = 'relative w-full cursor-pointer rounded-panel bg-panel py-2 pl-3 pr-10 text-left shadow-md focus:outline-none focus-visible:border-accent-solid focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
7
7
  const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
8
8
  export const buttonClasses = `${baseClasses} ${disabledClasses} ${className}`.trim()
9
9
  </script>
@@ -21,6 +21,8 @@ function onClick(event) {
21
21
  :is="{{ as }}"
22
22
  class="{{ buttonClasses }}"
23
23
  data-stx-listbox-button
24
+ aria-haspopup="listbox"
25
+ aria-expanded="false"
24
26
  @if(disabled)disabled aria-disabled="true"@endif
25
27
  @click="onClick($event)"
26
28
  >
@@ -12,7 +12,19 @@ export const valueJson = JSON.stringify(value === undefined ? null : value)
12
12
 
13
13
  <script client>
14
14
  const isDisabled = {{ disabled }}
15
- const optionValue = {{ value === undefined ? 'null' : value }}
15
+ /*
16
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
17
+ * through an ordinary interpolation.
18
+ *
19
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
20
+ * token null into the script. An interpolation QUOTES a string, so what it
21
+ * emitted was the four-character string "null" -- truthy, in the one place a
22
+ * value is meant to be absent. JSON.stringify produces the correct literal for
23
+ * every type, null included, and raw interpolation passes it through unquoted.
24
+ * Calendar and DateRangePicker already avoid this sentinel and say why
25
+ * (stacksjs/stx#1981).
26
+ */
27
+ const optionValue = {!! valueJson !!}
16
28
 
17
29
  function onClick(event) {
18
30
  if (isDisabled) return
@@ -28,6 +40,7 @@ function onClick(event) {
28
40
  data-stx-listbox-option
29
41
  data-option-value="{{ valueJson }}"
30
42
  role="option"
43
+ tabindex="-1"
31
44
  aria-selected="false"
32
45
  @if(disabled)aria-disabled="true"@endif
33
46
  @click="onClick($event)"
@@ -2,7 +2,7 @@
2
2
  export const className = $props.className || ''
3
3
  export const as = $props.as || 'ul'
4
4
 
5
- const baseClasses = 'absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-panel bg-panel py-1 text-base shadow-lg ring-1 ring-black/5 focus:outline-none'
5
+ const baseClasses = 'absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-panel bg-panel py-1 text-base shadow-lg ring-1 ring-line focus:outline-none'
6
6
  export const optionsClasses = `${baseClasses} ${className}`.trim()
7
7
  </script>
8
8
 
@@ -106,7 +106,7 @@ function onSubmit(event) {
106
106
 
107
107
  @if(showForgotPassword)
108
108
  <div class="text-sm leading-6">
109
- <StxLink to="{{ forgotPasswordHref }}" class="text-accent font-semibold hover:text-accent">
109
+ <StxLink to="{{ forgotPasswordHref }}" class="text-link font-semibold hover:text-link-hover">
110
110
  Forgot password?
111
111
  </StxLink>
112
112
  </div>
@@ -140,7 +140,7 @@ function onSubmit(event) {
140
140
  <button
141
141
  type="button"
142
142
  @click="onSocial('google')"
143
- class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-transparent"
143
+ class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
144
144
  >
145
145
  <svg class="h-5 w-5" viewBox="0 0 24 24" aria-hidden="true">
146
146
  <path d="M12.0003 4.75C13.7703 4.75 15.3553 5.36002 16.6053 6.54998L20.0303 3.125C17.9502 1.19 15.2353 0 12.0003 0C7.31028 0 3.25527 2.69 1.28027 6.60998L5.27028 9.70498C6.21525 6.86002 8.87028 4.75 12.0003 4.75Z" fill="#EA4335" />
@@ -154,7 +154,7 @@ function onSubmit(event) {
154
154
  <button
155
155
  type="button"
156
156
  @click="onSocial('github')"
157
- class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-transparent"
157
+ class="w-full flex items-center justify-center gap-3 rounded-control bg-field px-3 py-2 text-sm text-fg font-semibold shadow-sm ring-1 ring-line-strong ring-inset hover:bg-field-hover focus-visible:ring-2 focus-visible:ring-accent"
158
158
  >
159
159
  <svg class="h-5 w-5 fill-[#24292F]" fill="currentColor" viewBox="0 0 20 20" aria-hidden="true">
160
160
  <path fill-rule="evenodd" d="M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z" clip-rule="evenodd" />
@@ -169,7 +169,7 @@ function onSubmit(event) {
169
169
  @if(showSignup)
170
170
  <p class="mt-10 text-center text-sm text-fg-soft">
171
171
  Not a member?
172
- <StxLink to="{{ signupHref }}" class="text-accent font-semibold leading-6 hover:text-accent">
172
+ <StxLink to="{{ signupHref }}" class="text-link font-semibold leading-6 hover:text-link-hover">
173
173
  {{ signupText }}
174
174
  </StxLink>
175
175
  </p>
@@ -37,7 +37,7 @@ const positions = {
37
37
  'bottom-center': 'bottom-0 left-1/2 -translate-x-1/2',
38
38
  }
39
39
 
40
- const baseClasses = 'fixed z-50 m-4 max-w-md w-full pointer-events-auto rounded-panel p-4 shadow-lg ring-1 ring-black/5 transition-all'
40
+ const baseClasses = 'fixed z-50 m-4 max-w-md w-full pointer-events-auto rounded-panel p-4 shadow-lg ring-1 ring-line transition-all'
41
41
  const extraClassName = {{ JSON.stringify(className) }}
42
42
 
43
43
  const notificationClasses = derived(() => {
@@ -106,7 +106,7 @@ defineExpose({
106
106
  <button
107
107
  type="button"
108
108
  @click="close()"
109
- class="ml-4 inline-flex rounded-panel focus:outline-none focus:ring-2 focus:ring-offset-2"
109
+ class="ml-4 inline-flex rounded-panel focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-panel"
110
110
  >
111
111
  <span class="sr-only">Close</span>
112
112
  <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
@@ -7,8 +7,8 @@ export const showPrevNext = $bool($props.showPrevNext, true)
7
7
  export const className = $props.className || ''
8
8
 
9
9
  export const paginationClasses = `flex items-center gap-1 ${className}`.trim()
10
- export const buttonClasses = `px-3 py-2 text-sm font-medium text-fg-strong bg-panel border border-line-strong rounded-control hover:bg-surface-hover focus:outline-none focus:ring-2 focus:ring-accent-solid focus:ring-offset-2 focus:ring-offset-panel disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-panel transition-colors duration-150`.trim()
11
- export const activeButtonClasses = `px-3 py-2 text-sm font-medium text-accent-ink bg-accent-solid border border-accent rounded-control focus:outline-none focus:ring-2 focus:ring-accent-solid focus:ring-offset-2 focus:ring-offset-panel`.trim()
10
+ export const buttonClasses = `px-3 py-2 text-sm font-medium text-fg-strong bg-panel border border-line-strong rounded-control hover:bg-surface-hover focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-panel transition-colors duration-150`.trim()
11
+ export const activeButtonClasses = `px-3 py-2 text-sm font-medium text-accent-ink bg-accent-solid border border-accent rounded-control focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel`.trim()
12
12
  export const ellipsisClasses = `px-3 py-2 text-sm font-medium text-fg-soft`.trim()
13
13
  export const iconClasses = `w-5 h-5`.trim()
14
14
  </script>
@@ -0,0 +1,101 @@
1
+ <script server>
2
+ export const className = $props.className || ''
3
+ export const as = $props.as || 'div'
4
+
5
+ const baseClasses = 'relative'
6
+ export const popoverClasses = `${baseClasses} ${className}`.trim()
7
+ export const popoverInstanceId = $uid
8
+ </script>
9
+
10
+ <script client>
11
+ const emit = defineEmits()
12
+ const popoverInstanceId = {{ popoverInstanceId }}
13
+ const isOpen = state(false)
14
+ let rootEl = null
15
+ let outsideHandler = null
16
+
17
+ /*
18
+ * The trigger carries the open state for assistive tech. `isOpen` already
19
+ * drove `data-state` on the root, which styles the panel but says nothing to a
20
+ * screen reader: the button announced itself as a plain button, with no
21
+ * indication that it opens anything or whether it is open right now.
22
+ */
23
+ function syncExpanded() {
24
+ if (!rootEl) return
25
+ const trigger = rootEl.querySelector('[data-stx-popover-button]')
26
+ if (!trigger) return
27
+ trigger.setAttribute('aria-expanded', isOpen() ? 'true' : 'false')
28
+ const panel = rootEl.querySelector('[data-stx-popover-panel]')
29
+ if (!panel) return
30
+ if (!panel.id) panel.id = 'stx-popover-panel-' + popoverInstanceId
31
+ trigger.setAttribute('aria-controls', panel.id)
32
+ }
33
+
34
+ function open() { if (!isOpen()) { isOpen.set(true); emit('change', true); syncExpanded() } }
35
+ function close() { if (isOpen()) { isOpen.set(false); emit('change', false); syncExpanded() } }
36
+ function toggle() { isOpen() ? close() : open() }
37
+
38
+ function onToggle(event) { event.stopPropagation(); toggle() }
39
+ function onClose(event) { event.stopPropagation(); close() }
40
+ function onOpen(event) { event.stopPropagation(); open() }
41
+
42
+ /*
43
+ * Escape dismisses it, from anywhere rather than only from inside the panel.
44
+ *
45
+ * Opening one of these does not move focus, so a keydown bound on the panel
46
+ * never sees the first Escape - focus is still on whatever opened it. Drawer
47
+ * reached the same conclusion and binds on the document; this follows it, and
48
+ * only acts while open so one open popup does not swallow Escape for the page.
49
+ *
50
+ * Focus goes back to the trigger, but only if it had moved into the panel:
51
+ * otherwise this would steal it from wherever the user actually is.
52
+ */
53
+ function onDocumentKey(event) {
54
+ if (event.key !== 'Escape' || !isOpen()) return
55
+ close()
56
+ if (!rootEl) return
57
+ const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
58
+ if (!active || !rootEl.contains(active)) return
59
+ const trigger = rootEl.querySelector('[data-stx-popover-button]')
60
+ if (trigger && trigger.focus) trigger.focus()
61
+ }
62
+
63
+ onMount(() => {
64
+ rootEl = document.querySelector(`[data-popover-id="${popoverInstanceId}"]`)
65
+ syncExpanded()
66
+ outsideHandler = (event) => {
67
+ if (!isOpen()) return
68
+ if (rootEl && !rootEl.contains(event.target)) close()
69
+ }
70
+ document.addEventListener('click', outsideHandler, true)
71
+ document.addEventListener('keydown', onDocumentKey)
72
+ })
73
+
74
+ onDestroy(() => {
75
+ if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
76
+ document.removeEventListener('keydown', onDocumentKey)
77
+ })
78
+
79
+ const dataState = derived(() => isOpen() ? 'open' : 'closed')
80
+
81
+ defineExpose({ isOpen, toggle, open, close })
82
+ </script>
83
+
84
+ <component
85
+ :is="{{ as }}"
86
+ class="{{ popoverClasses }}"
87
+ data-stx-popover
88
+ data-popover-id="{{ popoverInstanceId }}"
89
+ :data-state="dataState()"
90
+ @stx:popover-toggle="onToggle($event)"
91
+ @stx:popover-open="onOpen($event)"
92
+ @stx:popover-close="onClose($event)"
93
+ >
94
+ <slot />
95
+ </component>
96
+
97
+ <style>
98
+ [data-stx-popover][data-state="closed"] [data-stx-popover-panel] {
99
+ display: none;
100
+ }
101
+ </style>
@@ -3,7 +3,7 @@ export const className = $props.className || ''
3
3
  export const as = $props.as || 'button'
4
4
  export const disabled = $bool($props.disabled)
5
5
 
6
- const baseClasses = 'inline-flex items-center gap-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent-solid focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
6
+ const baseClasses = 'inline-flex items-center gap-2 focus:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
7
7
  export const buttonClasses = `${baseClasses} ${className}`.trim()
8
8
  </script>
9
9
 
@@ -22,6 +22,7 @@ function onClick(event) {
22
22
  :is="{{ as }}"
23
23
  class="{{ buttonClasses }}"
24
24
  data-stx-popover-button
25
+ aria-expanded="false"
25
26
  @if(disabled)disabled aria-disabled="true"@endif
26
27
  @click="onClick($event)"
27
28
  >
@@ -10,7 +10,7 @@ const positionClasses = {
10
10
  right: 'left-full ml-2',
11
11
  }
12
12
 
13
- const baseClasses = 'absolute z-10 rounded-panel bg-panel p-4 shadow-lg ring-1 ring-black/5 focus:outline-none'
13
+ const baseClasses = 'absolute z-10 rounded-panel bg-panel p-4 shadow-lg ring-1 ring-line focus:outline-none'
14
14
  export const panelClasses = `${baseClasses} ${positionClasses[position] || positionClasses.bottom} ${className}`.trim()
15
15
  </script>
16
16
 
@@ -1,5 +1,6 @@
1
1
  <script server>
2
2
  export const value = $props.value
3
+ export const valueJson = JSON.stringify(value === undefined ? null : value)
3
4
  export const className = $props.className || ''
4
5
  export const as = $props.as || 'div'
5
6
 
@@ -23,7 +24,7 @@ export const as = $props.as || 'div'
23
24
  export const options = Array.isArray($props.options) ? $props.options : []
24
25
  export const hasPropOptions = options.length > 0
25
26
 
26
- const optionBaseClasses = 'relative flex cursor-pointer rounded-panel px-5 py-4 shadow-md focus:outline-none transition-all bg-panel text-fg focus-visible:ring-2 focus-visible:ring-accent-solid focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
27
+ const optionBaseClasses = 'relative flex cursor-pointer rounded-panel px-5 py-4 shadow-md focus:outline-none transition-all bg-panel text-fg focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
27
28
  export const optionClasses = optionBaseClasses
28
29
  export const optionDisabledClasses = `${optionBaseClasses} opacity-50 cursor-not-allowed`
29
30
 
@@ -35,7 +36,19 @@ export const radioGroupInstanceId = $uid
35
36
  <script client>
36
37
  const emit = defineEmits()
37
38
  const radioGroupInstanceId = {{ radioGroupInstanceId }}
38
- const initialValue = {{ value === undefined ? 'null' : value }}
39
+ /*
40
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
41
+ * through an ordinary interpolation.
42
+ *
43
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
44
+ * token null into the script. An interpolation QUOTES a string, so what it
45
+ * emitted was the four-character string "null" -- truthy, in the one place a
46
+ * value is meant to be absent. JSON.stringify produces the correct literal for
47
+ * every type, null included, and raw interpolation passes it through unquoted.
48
+ * Calendar and DateRangePicker already avoid this sentinel and say why
49
+ * (stacksjs/stx#1981).
50
+ */
51
+ const initialValue = {!! valueJson !!}
39
52
  const selected = state(initialValue)
40
53
  let rootEl = null
41
54
 
@@ -4,7 +4,7 @@ export const disabled = $bool($props.disabled)
4
4
  export const className = $props.className || ''
5
5
  export const as = $props.as || 'div'
6
6
 
7
- const baseClasses = 'relative flex cursor-pointer rounded-panel px-5 py-4 shadow-md focus:outline-none transition-all bg-panel text-fg focus-visible:ring-2 focus-visible:ring-accent-solid focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
7
+ const baseClasses = 'relative flex cursor-pointer rounded-panel px-5 py-4 shadow-md focus:outline-none transition-all bg-panel text-fg focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
8
8
  const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
9
9
  export const optionClasses = `${baseClasses} ${disabledClasses} ${className}`.trim()
10
10
  export const valueJson = JSON.stringify(value === undefined ? null : value)
@@ -12,7 +12,19 @@ export const valueJson = JSON.stringify(value === undefined ? null : value)
12
12
 
13
13
  <script client>
14
14
  const isDisabled = {{ disabled }}
15
- const optionValue = {{ value === undefined ? 'null' : value }}
15
+ /*
16
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
17
+ * through an ordinary interpolation.
18
+ *
19
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
20
+ * token null into the script. An interpolation QUOTES a string, so what it
21
+ * emitted was the four-character string "null" -- truthy, in the one place a
22
+ * value is meant to be absent. JSON.stringify produces the correct literal for
23
+ * every type, null included, and raw interpolation passes it through unquoted.
24
+ * Calendar and DateRangePicker already avoid this sentinel and say why
25
+ * (stacksjs/stx#1981).
26
+ */
27
+ const optionValue = {!! valueJson !!}
16
28
 
17
29
  function onClick(event) {
18
30
  if (isDisabled) return