@stacksjs/components 0.2.369 → 0.2.371
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/{Checkbox-e7gn3w06.stx → Checkbox-tt8bze29.stx} +19 -3
- package/dist/Combobox-9xh1jgjr.stx +266 -0
- package/dist/{ComboboxButton-g76stp1e.stx → ComboboxButton-4r6a45s1.stx} +8 -1
- package/dist/{ComboboxInput-a5g0vn3e.stx → ComboboxInput-1gyfpnca.stx} +3 -0
- package/dist/{ComboboxOption-vnb67p8d.stx → ComboboxOption-wkw70js7.stx} +27 -1
- package/dist/{CommandPalette-y6t67rjj.stx → CommandPalette-vvaqtqat.stx} +2 -2
- package/dist/CommandPaletteItem-7290ce1z.stx +40 -0
- package/dist/Dropdown-25160tc6.stx +204 -0
- package/dist/{DropdownButton-6by2ybde.stx → DropdownButton-wxc25hsy.stx} +2 -0
- package/dist/{DropdownItem-wht1vcm5.stx → DropdownItem-af0vzc8a.stx} +15 -1
- package/dist/Listbox-32gzxace.stx +273 -0
- package/dist/{ListboxButton-3yc7tm8w.stx → ListboxButton-gan8e3nw.stx} +2 -0
- package/dist/{ListboxOption-9c9jpz1n.stx → ListboxOption-gpaqvk3s.stx} +14 -1
- package/dist/{Login-3dsk93vm.stx → Login-4666t7j4.stx} +18 -7
- package/dist/{NumberInput-awn66hfs.stx → NumberInput-g3jfy120.stx} +21 -4
- package/dist/{PasswordInput-hradj0xd.stx → PasswordInput-p2rt5926.stx} +21 -4
- package/dist/Popover-9m42pym0.stx +101 -0
- package/dist/{PopoverButton-htfypg00.stx → PopoverButton-3w6550hv.stx} +1 -0
- package/dist/{Radio-nr8rbb6g.stx → Radio-625byys2.stx} +19 -3
- package/dist/{RadioGroup-neej7522.stx → RadioGroup-smqcqgds.stx} +14 -1
- package/dist/{RadioGroupOption-c6xd0at9.stx → RadioGroupOption-twcw1b2a.stx} +13 -1
- package/dist/{Select-danh680d.stx → Select-1p9mcbsb.stx} +19 -3
- package/dist/{Signup-dh96kskd.stx → Signup-pm2r0f2m.stx} +21 -10
- package/dist/{SubscriptionCheckout-75x9mfv2.stx → SubscriptionCheckout-f1ev0ry8.stx} +27 -11
- package/dist/{TextInput-48ghmccm.stx → TextInput-t0a4ch49.stx} +19 -3
- package/dist/{Textarea-dndmk6ah.stx → Textarea-k1gf21kw.stx} +21 -4
- package/dist/{TwoFactorChallenge-ete7yk9y.stx → TwoFactorChallenge-st48qkzw.stx} +25 -5
- package/dist/index.js +7 -7
- package/package.json +3 -3
- package/src/components/Footer.stx +2 -2
- package/src/ui/auth/Login.stx +18 -7
- package/src/ui/auth/Signup.stx +21 -10
- package/src/ui/auth/TwoFactorChallenge.stx +25 -5
- package/src/ui/checkbox/Checkbox.stx +19 -3
- package/src/ui/combobox/Combobox.stx +174 -4
- package/src/ui/combobox/ComboboxButton.stx +8 -1
- package/src/ui/combobox/ComboboxInput.stx +3 -0
- package/src/ui/combobox/ComboboxOption.stx +27 -1
- package/src/ui/command-palette/CommandPalette.stx +2 -2
- package/src/ui/command-palette/CommandPaletteItem.stx +14 -1
- package/src/ui/dropdown/Dropdown.stx +122 -0
- package/src/ui/dropdown/DropdownButton.stx +2 -0
- package/src/ui/dropdown/DropdownItem.stx +15 -1
- package/src/ui/input/NumberInput.stx +21 -4
- package/src/ui/input/PasswordInput.stx +21 -4
- package/src/ui/input/TextInput.stx +19 -3
- package/src/ui/listbox/Listbox.stx +175 -3
- package/src/ui/listbox/ListboxButton.stx +2 -0
- package/src/ui/listbox/ListboxOption.stx +14 -1
- package/src/ui/payment/SubscriptionCheckout.stx +27 -11
- package/src/ui/popover/Popover.stx +43 -2
- package/src/ui/popover/PopoverButton.stx +1 -0
- package/src/ui/radio/Radio.stx +19 -3
- package/src/ui/radio-group/RadioGroup.stx +14 -1
- package/src/ui/radio-group/RadioGroupOption.stx +13 -1
- package/src/ui/select/Select.stx +19 -3
- package/src/ui/textarea/Textarea.stx +21 -4
- package/dist/Combobox-06x0nywb.stx +0 -96
- package/dist/CommandPaletteItem-6rp133ta.stx +0 -27
- package/dist/Dropdown-cmwge7vx.stx +0 -82
- package/dist/Listbox-e5jreb0a.stx +0 -101
- package/dist/Popover-3g8rgxt1.stx +0 -60
|
@@ -10,10 +10,26 @@ export const className = $props.className || ''
|
|
|
10
10
|
export const subtotal = products.reduce((sum, product) => sum + (product.price * (product.quantity || 1)), 0)
|
|
11
11
|
export const total = subtotal + shipping + taxes
|
|
12
12
|
|
|
13
|
+
/*
|
|
14
|
+
* Field ids unique to this instance.
|
|
15
|
+
*
|
|
16
|
+
* `email-address`, `card-name`, `credit-card` and `payment-element` were
|
|
17
|
+
* generic enough to collide with the host app's own ids, which breaks
|
|
18
|
+
* getElementById and `<label for>` for both. `name` stays generic: it is the
|
|
19
|
+
* key the form submits under and what autocomplete reads.
|
|
20
|
+
*
|
|
21
|
+
* `payment-element` matters most of the three, because it is not only a label
|
|
22
|
+
* target -- Stripe mounts into it BY SELECTOR (`#payment-element` below), so a
|
|
23
|
+
* second element with that id anywhere on the page could take the card form.
|
|
24
|
+
* Both sides read the same prefix, so they cannot drift apart.
|
|
25
|
+
*/
|
|
26
|
+
export const fieldPrefix = $props.id || `checkout-${$uid}`
|
|
27
|
+
|
|
13
28
|
export const containerClasses = `bg-page ${className}`.trim()
|
|
14
29
|
</script>
|
|
15
30
|
|
|
16
31
|
<script client>
|
|
32
|
+
const fieldPrefix = {{ fieldPrefix }}
|
|
17
33
|
const emit = defineEmits()
|
|
18
34
|
const stripePublicKey = {{ stripePublicKey }}
|
|
19
35
|
const apiUrl = {{ apiUrl }}
|
|
@@ -52,7 +68,7 @@ async function setupStripeElements() {
|
|
|
52
68
|
},
|
|
53
69
|
})
|
|
54
70
|
paymentElement = elements.create('payment')
|
|
55
|
-
paymentElement.mount('#payment-element')
|
|
71
|
+
paymentElement.mount('#' + fieldPrefix + '-payment-element')
|
|
56
72
|
}
|
|
57
73
|
catch (error) {
|
|
58
74
|
console.error('Error setting up Stripe elements:', error)
|
|
@@ -120,12 +136,12 @@ onMount(() => initializeStripe())
|
|
|
120
136
|
</h2>
|
|
121
137
|
|
|
122
138
|
<div class="mt-4">
|
|
123
|
-
<label for="email-address" class="block text-sm text-fg-strong font-medium">
|
|
139
|
+
<label for="{{ fieldPrefix }}-email-address" class="block text-sm text-fg-strong font-medium">
|
|
124
140
|
Email address
|
|
125
141
|
</label>
|
|
126
142
|
<div class="mt-1">
|
|
127
143
|
<input
|
|
128
|
-
id="email-address"
|
|
144
|
+
id="{{ fieldPrefix }}-email-address"
|
|
129
145
|
type="email"
|
|
130
146
|
name="email-address"
|
|
131
147
|
autocomplete="email"
|
|
@@ -144,13 +160,13 @@ onMount(() => initializeStripe())
|
|
|
144
160
|
|
|
145
161
|
<div class="mt-4 grid grid-cols-1 gap-y-6 sm:grid-cols-2 sm:gap-x-4">
|
|
146
162
|
<div class="sm:col-span-2">
|
|
147
|
-
<label for="card-name" class="block text-sm text-fg-strong font-medium">
|
|
163
|
+
<label for="{{ fieldPrefix }}-card-name" class="block text-sm text-fg-strong font-medium">
|
|
148
164
|
Name on card
|
|
149
165
|
</label>
|
|
150
166
|
<div class="mt-1">
|
|
151
167
|
<input
|
|
152
168
|
type="text"
|
|
153
|
-
id="card-name"
|
|
169
|
+
id="{{ fieldPrefix }}-card-name"
|
|
154
170
|
name="card-name"
|
|
155
171
|
autocomplete="cc-name"
|
|
156
172
|
required
|
|
@@ -161,7 +177,7 @@ onMount(() => initializeStripe())
|
|
|
161
177
|
|
|
162
178
|
<!-- Stripe Element Mount Point -->
|
|
163
179
|
<div class="sm:col-span-2">
|
|
164
|
-
<div id="payment-element" class="mt-2 border border-line-strong rounded-control bg-field p-3"></div>
|
|
180
|
+
<div id="{{ fieldPrefix }}-payment-element" class="mt-2 border border-line-strong rounded-control bg-field p-3"></div>
|
|
165
181
|
</div>
|
|
166
182
|
</div>
|
|
167
183
|
</div>
|
|
@@ -177,13 +193,13 @@ onMount(() => initializeStripe())
|
|
|
177
193
|
<div class="sm:flex sm:items-center space-y-4 sm:space-x-10 sm:space-y-0">
|
|
178
194
|
<div class="flex items-center">
|
|
179
195
|
<input
|
|
180
|
-
id="credit-card"
|
|
196
|
+
id="{{ fieldPrefix }}-credit-card"
|
|
181
197
|
name="payment-type"
|
|
182
198
|
type="radio"
|
|
183
199
|
checked
|
|
184
200
|
class="h-4 w-4 border-line-strong text-accent focus:ring-accent"
|
|
185
201
|
/>
|
|
186
|
-
<label for="credit-card" class="ml-3 block text-sm text-fg-strong font-medium">
|
|
202
|
+
<label for="{{ fieldPrefix }}-credit-card" class="ml-3 block text-sm text-fg-strong font-medium">
|
|
187
203
|
Credit card
|
|
188
204
|
</label>
|
|
189
205
|
</div>
|
|
@@ -210,7 +226,7 @@ onMount(() => initializeStripe())
|
|
|
210
226
|
<img src="{{ product.images }}" alt="{{ product.name }}" class="w-20 rounded-control" />
|
|
211
227
|
@else
|
|
212
228
|
<div class="w-20 h-20 bg-surface-sunken rounded-control flex items-center justify-center">
|
|
213
|
-
<svg class="h-8 w-8 text-
|
|
229
|
+
<svg class="h-8 w-8 text-fg-soft" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
214
230
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
|
215
231
|
</svg>
|
|
216
232
|
</div>
|
|
@@ -256,9 +272,9 @@ onMount(() => initializeStripe())
|
|
|
256
272
|
</p>
|
|
257
273
|
|
|
258
274
|
<div class="ml-4">
|
|
259
|
-
<label for="quantity-{{ product.id }}" class="sr-only">Quantity</label>
|
|
275
|
+
<label for="{{ fieldPrefix }}-quantity-{{ product.id }}" class="sr-only">Quantity</label>
|
|
260
276
|
<select
|
|
261
|
-
id="quantity-{{ product.id }}"
|
|
277
|
+
id="{{ fieldPrefix }}-quantity-{{ product.id }}"
|
|
262
278
|
name="quantity"
|
|
263
279
|
class="border border-line-strong rounded-control text-left text-base text-fg-strong font-medium shadow-sm bg-field focus:border-accent sm:text-sm focus:outline-none focus:ring-1 focus:ring-accent"
|
|
264
280
|
>
|
|
@@ -14,25 +14,66 @@ const isOpen = state(false)
|
|
|
14
14
|
let rootEl = null
|
|
15
15
|
let outsideHandler = null
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
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() } }
|
|
19
36
|
function toggle() { isOpen() ? close() : open() }
|
|
20
37
|
|
|
21
38
|
function onToggle(event) { event.stopPropagation(); toggle() }
|
|
22
39
|
function onClose(event) { event.stopPropagation(); close() }
|
|
23
40
|
function onOpen(event) { event.stopPropagation(); open() }
|
|
24
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
|
+
|
|
25
63
|
onMount(() => {
|
|
26
64
|
rootEl = document.querySelector(`[data-popover-id="${popoverInstanceId}"]`)
|
|
65
|
+
syncExpanded()
|
|
27
66
|
outsideHandler = (event) => {
|
|
28
67
|
if (!isOpen()) return
|
|
29
68
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
30
69
|
}
|
|
31
70
|
document.addEventListener('click', outsideHandler, true)
|
|
71
|
+
document.addEventListener('keydown', onDocumentKey)
|
|
32
72
|
})
|
|
33
73
|
|
|
34
74
|
onDestroy(() => {
|
|
35
75
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
76
|
+
document.removeEventListener('keydown', onDocumentKey)
|
|
36
77
|
})
|
|
37
78
|
|
|
38
79
|
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|
package/src/ui/radio/Radio.stx
CHANGED
|
@@ -18,7 +18,23 @@ const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-poi
|
|
|
18
18
|
export const radioClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses}`.trim()
|
|
19
19
|
export const labelClasses = `text-sm font-medium ${error ? 'text-danger' : 'text-fg'} ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`.trim()
|
|
20
20
|
export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
|
|
21
|
-
|
|
21
|
+
/*
|
|
22
|
+
* Ids unique to this instance.
|
|
23
|
+
*
|
|
24
|
+
* These were derived from the LABEL or hardcoded outright, so two of these on
|
|
25
|
+
* one page -- an ordinary form -- emitted the same id twice. `<label for>`
|
|
26
|
+
* then activated the FIRST field from every label, and `aria-describedby`
|
|
27
|
+
* pointed every field's description at the first one's helper text. A label
|
|
28
|
+
* containing a space also produced an invalid id, `input-First name`, which
|
|
29
|
+
* getElementById and querySelector cannot address at all.
|
|
30
|
+
*
|
|
31
|
+
* `$uid` is unique per instance and stable across renders, which is what an id
|
|
32
|
+
* has to be (utils.ts explains why a render that changes its own bytes is
|
|
33
|
+
* uncacheable). The `id` prop overrides it, for a caller that needs to point
|
|
34
|
+
* its own `for` or `aria-describedby` at this control.
|
|
35
|
+
*/
|
|
36
|
+
export const inputId = $props.id || `radio-${$uid}`
|
|
37
|
+
export const descriptionId = `${inputId}-description`
|
|
22
38
|
</script>
|
|
23
39
|
|
|
24
40
|
<script client>
|
|
@@ -53,7 +69,7 @@ defineExpose({ isChecked })
|
|
|
53
69
|
class="{{ radioClasses }}"
|
|
54
70
|
@change="onInputChange($event)"
|
|
55
71
|
:aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
56
|
-
@if(description)aria-describedby="
|
|
72
|
+
@if(description)aria-describedby="{{ descriptionId }}"@endif
|
|
57
73
|
/>
|
|
58
74
|
</div>
|
|
59
75
|
|
|
@@ -68,7 +84,7 @@ defineExpose({ isChecked })
|
|
|
68
84
|
</label>
|
|
69
85
|
@endif
|
|
70
86
|
@if(description)
|
|
71
|
-
<p id="
|
|
87
|
+
<p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
|
|
72
88
|
{{ description }}
|
|
73
89
|
</p>
|
|
74
90
|
@endif
|
|
@@ -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
|
|
|
@@ -35,7 +36,19 @@ export const radioGroupInstanceId = $uid
|
|
|
35
36
|
<script client>
|
|
36
37
|
const emit = defineEmits()
|
|
37
38
|
const radioGroupInstanceId = {{ radioGroupInstanceId }}
|
|
38
|
-
|
|
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
|
|
|
@@ -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
|
-
|
|
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
|
package/src/ui/select/Select.stx
CHANGED
|
@@ -32,7 +32,23 @@ const disabledClasses = disabled
|
|
|
32
32
|
export const selectClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses} ${className}`.trim()
|
|
33
33
|
export const labelClasses = `block text-sm font-medium leading-6 ${error ? 'text-danger' : 'text-fg'}`.trim()
|
|
34
34
|
export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
|
|
35
|
-
|
|
35
|
+
/*
|
|
36
|
+
* Ids unique to this instance.
|
|
37
|
+
*
|
|
38
|
+
* These were derived from the LABEL or hardcoded outright, so two of these on
|
|
39
|
+
* one page -- an ordinary form -- emitted the same id twice. `<label for>`
|
|
40
|
+
* then activated the FIRST field from every label, and `aria-describedby`
|
|
41
|
+
* pointed every field's description at the first one's helper text. A label
|
|
42
|
+
* containing a space also produced an invalid id, `input-First name`, which
|
|
43
|
+
* getElementById and querySelector cannot address at all.
|
|
44
|
+
*
|
|
45
|
+
* `$uid` is unique per instance and stable across renders, which is what an id
|
|
46
|
+
* has to be (utils.ts explains why a render that changes its own bytes is
|
|
47
|
+
* uncacheable). The `id` prop overrides it, for a caller that needs to point
|
|
48
|
+
* its own `for` or `aria-describedby` at this control.
|
|
49
|
+
*/
|
|
50
|
+
export const selectId = $props.id || `select-${$uid}`
|
|
51
|
+
export const helperId = `${selectId}-helper`
|
|
36
52
|
</script>
|
|
37
53
|
|
|
38
54
|
<script client>
|
|
@@ -67,7 +83,7 @@ defineExpose({ value: selectedValue })
|
|
|
67
83
|
@if(required)required@endif
|
|
68
84
|
@change="onChange($event)"
|
|
69
85
|
:aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
70
|
-
aria-describedby="{{ helperText ?
|
|
86
|
+
aria-describedby="{{ helperText ? helperId : '' }}"
|
|
71
87
|
>
|
|
72
88
|
@if(placeholder)
|
|
73
89
|
<option value="" disabled>{{ placeholder }}</option>
|
|
@@ -85,7 +101,7 @@ defineExpose({ value: selectedValue })
|
|
|
85
101
|
</div>
|
|
86
102
|
|
|
87
103
|
@if(helperText)
|
|
88
|
-
<p id="
|
|
104
|
+
<p id="{{ helperId }}" class="{{ helperClasses }}">
|
|
89
105
|
{{ helperText }}
|
|
90
106
|
</p>
|
|
91
107
|
@endif
|
|
@@ -8,6 +8,23 @@ export const autoResize = $bool($props.autoResize)
|
|
|
8
8
|
export const maxRows = $props.maxRows || 10
|
|
9
9
|
export const error = $bool($props.error)
|
|
10
10
|
export const label = $props.label || ''
|
|
11
|
+
/*
|
|
12
|
+
* Ids unique to this instance.
|
|
13
|
+
*
|
|
14
|
+
* These were derived from the LABEL or hardcoded outright, so two of these on
|
|
15
|
+
* one page -- an ordinary form -- emitted the same id twice. `<label for>`
|
|
16
|
+
* then activated the FIRST field from every label, and `aria-describedby`
|
|
17
|
+
* pointed every field's description at the first one's helper text. A label
|
|
18
|
+
* containing a space also produced an invalid id, `input-First name`, which
|
|
19
|
+
* getElementById and querySelector cannot address at all.
|
|
20
|
+
*
|
|
21
|
+
* `$uid` is unique per instance and stable across renders, which is what an id
|
|
22
|
+
* has to be (utils.ts explains why a render that changes its own bytes is
|
|
23
|
+
* uncacheable). The `id` prop overrides it, for a caller that needs to point
|
|
24
|
+
* its own `for` or `aria-describedby` at this control.
|
|
25
|
+
*/
|
|
26
|
+
export const inputId = $props.id || `textarea-input-${$uid}`
|
|
27
|
+
export const helperId = `${inputId}-helper`
|
|
11
28
|
export const helperText = $props.helperText || ''
|
|
12
29
|
export const required = $bool($props.required)
|
|
13
30
|
export const maxLength = $props.maxLength
|
|
@@ -68,7 +85,7 @@ defineExpose({ value: inputValue })
|
|
|
68
85
|
|
|
69
86
|
<div class="w-full">
|
|
70
87
|
@if(label)
|
|
71
|
-
<label for="
|
|
88
|
+
<label for="{{ inputId }}" class="{{ labelClasses }}">
|
|
72
89
|
{{ label }}
|
|
73
90
|
@if(required)
|
|
74
91
|
<span class="text-danger ml-1">*</span>
|
|
@@ -77,7 +94,7 @@ defineExpose({ value: inputValue })
|
|
|
77
94
|
@endif
|
|
78
95
|
|
|
79
96
|
<textarea
|
|
80
|
-
id="
|
|
97
|
+
id="{{ inputId }}"
|
|
81
98
|
class="{{ textareaClasses }}"
|
|
82
99
|
rows="{{ rows }}"
|
|
83
100
|
placeholder="{{ placeholder }}"
|
|
@@ -87,13 +104,13 @@ defineExpose({ value: inputValue })
|
|
|
87
104
|
@if(maxLength)maxlength="{{ maxLength }}"@endif
|
|
88
105
|
@input="onInput($event)"
|
|
89
106
|
:aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
90
|
-
@if(helperText)aria-describedby="
|
|
107
|
+
@if(helperText)aria-describedby="{{ helperId }}"@endif
|
|
91
108
|
>{{ value }}</textarea>
|
|
92
109
|
|
|
93
110
|
@if(helperText || (showCount && maxLength))
|
|
94
111
|
<div class="flex items-center justify-between mt-2">
|
|
95
112
|
@if(helperText)
|
|
96
|
-
<p id="
|
|
113
|
+
<p id="{{ helperId }}" class="{{ helperClasses }}">
|
|
97
114
|
{{ helperText }}
|
|
98
115
|
</p>
|
|
99
116
|
@else
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const value = $props.value
|
|
3
|
-
export const className = $props.className || ''
|
|
4
|
-
export const as = $props.as || 'div'
|
|
5
|
-
|
|
6
|
-
const baseClasses = 'relative'
|
|
7
|
-
export const comboboxClasses = `${baseClasses} ${className}`.trim()
|
|
8
|
-
export const comboboxInstanceId = $uid
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<script client>
|
|
12
|
-
const emit = defineEmits()
|
|
13
|
-
const comboboxInstanceId = {{ comboboxInstanceId }}
|
|
14
|
-
const initialValue = {{ value === undefined ? 'null' : value }}
|
|
15
|
-
|
|
16
|
-
const isOpen = state(false)
|
|
17
|
-
const selected = state(initialValue)
|
|
18
|
-
const query = state('')
|
|
19
|
-
let rootEl = null
|
|
20
|
-
let outsideHandler = null
|
|
21
|
-
|
|
22
|
-
function isSelectedValue(v) {
|
|
23
|
-
return selected() === v
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function selectValue(v) {
|
|
27
|
-
selected.set(v)
|
|
28
|
-
isOpen.set(false)
|
|
29
|
-
syncOptionStates()
|
|
30
|
-
emit('change', v)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function syncOptionStates() {
|
|
34
|
-
if (!rootEl) return
|
|
35
|
-
const options = rootEl.querySelectorAll('[data-stx-combobox-option]')
|
|
36
|
-
for (const opt of options) {
|
|
37
|
-
const raw = opt.dataset.optionValue
|
|
38
|
-
let v
|
|
39
|
-
try { v = JSON.parse(raw ?? 'null') }
|
|
40
|
-
catch { v = raw }
|
|
41
|
-
const sel = isSelectedValue(v)
|
|
42
|
-
opt.setAttribute('aria-selected', sel ? 'true' : 'false')
|
|
43
|
-
opt.setAttribute('data-selected', sel ? 'true' : 'false')
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function open() { if (!isOpen()) { isOpen.set(true) } }
|
|
48
|
-
function close() { if (isOpen()) isOpen.set(false) }
|
|
49
|
-
function toggle() { isOpen() ? close() : open() }
|
|
50
|
-
|
|
51
|
-
function onToggle(event) { event.stopPropagation(); toggle() }
|
|
52
|
-
function onSelect(event) { event.stopPropagation(); selectValue(event.detail) }
|
|
53
|
-
function onQuery(event) {
|
|
54
|
-
event.stopPropagation()
|
|
55
|
-
query.set(event.detail)
|
|
56
|
-
if (!isOpen()) open()
|
|
57
|
-
emit('query', event.detail)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
onMount(() => {
|
|
61
|
-
rootEl = document.querySelector(`[data-combobox-id="${comboboxInstanceId}"]`)
|
|
62
|
-
syncOptionStates()
|
|
63
|
-
outsideHandler = (event) => {
|
|
64
|
-
if (!isOpen()) return
|
|
65
|
-
if (rootEl && !rootEl.contains(event.target)) close()
|
|
66
|
-
}
|
|
67
|
-
document.addEventListener('click', outsideHandler, true)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
onDestroy(() => {
|
|
71
|
-
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|
|
75
|
-
|
|
76
|
-
defineExpose({ isOpen, selected, query, toggle, open, close, selectValue })
|
|
77
|
-
</script>
|
|
78
|
-
|
|
79
|
-
<component
|
|
80
|
-
:is="{{ as }}"
|
|
81
|
-
class="{{ comboboxClasses }}"
|
|
82
|
-
data-stx-combobox
|
|
83
|
-
data-combobox-id="{{ comboboxInstanceId }}"
|
|
84
|
-
:data-state="dataState()"
|
|
85
|
-
@stx:combobox-toggle="onToggle($event)"
|
|
86
|
-
@stx:combobox-select="onSelect($event)"
|
|
87
|
-
@stx:combobox-query="onQuery($event)"
|
|
88
|
-
>
|
|
89
|
-
<slot />
|
|
90
|
-
</component>
|
|
91
|
-
|
|
92
|
-
<style>
|
|
93
|
-
[data-stx-combobox][data-state="closed"] [data-stx-combobox-options] {
|
|
94
|
-
display: none;
|
|
95
|
-
}
|
|
96
|
-
</style>
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const className = $props.className || ''
|
|
3
|
-
export const value = $props.value
|
|
4
|
-
|
|
5
|
-
const baseClasses = 'flex cursor-pointer select-none items-center px-4 py-2 text-fg hover:bg-accent-solid hover:text-accent-ink'
|
|
6
|
-
export const itemClasses = `${baseClasses} ${className}`.trim()
|
|
7
|
-
</script>
|
|
8
|
-
|
|
9
|
-
<script client>
|
|
10
|
-
const emit = defineEmits()
|
|
11
|
-
const itemValue = {{ value === undefined ? 'null' : value }}
|
|
12
|
-
|
|
13
|
-
function onClick(event) {
|
|
14
|
-
emit('click', event)
|
|
15
|
-
event.currentTarget.dispatchEvent(
|
|
16
|
-
new CustomEvent('stx:command-select', { bubbles: true, detail: itemValue }),
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<div
|
|
22
|
-
class="{{ itemClasses }}"
|
|
23
|
-
data-stx-command-item
|
|
24
|
-
@click="onClick($event)"
|
|
25
|
-
>
|
|
26
|
-
<slot />
|
|
27
|
-
</div>
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const className = $props.className || ''
|
|
3
|
-
export const as = $props.as || 'div'
|
|
4
|
-
|
|
5
|
-
const baseClasses = 'relative inline-block text-left'
|
|
6
|
-
export const dropdownClasses = `${baseClasses} ${className}`.trim()
|
|
7
|
-
export const dropdownInstanceId = $uid
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<script client>
|
|
11
|
-
const emit = defineEmits()
|
|
12
|
-
const dropdownInstanceId = {{ dropdownInstanceId }}
|
|
13
|
-
const isOpen = state(false)
|
|
14
|
-
let rootEl = null
|
|
15
|
-
let outsideHandler = null
|
|
16
|
-
|
|
17
|
-
function toggle() {
|
|
18
|
-
isOpen.set(!isOpen())
|
|
19
|
-
emit('change', isOpen())
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function open() {
|
|
23
|
-
if (isOpen()) return
|
|
24
|
-
isOpen.set(true)
|
|
25
|
-
emit('change', true)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function close() {
|
|
29
|
-
if (!isOpen()) return
|
|
30
|
-
isOpen.set(false)
|
|
31
|
-
emit('change', false)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function onItemSelect(event) {
|
|
35
|
-
event.stopPropagation()
|
|
36
|
-
emit('select', event.detail)
|
|
37
|
-
close()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function onToggle(event) { event.stopPropagation(); toggle() }
|
|
41
|
-
function onOpen(event) { event.stopPropagation(); open() }
|
|
42
|
-
function onClose(event) { event.stopPropagation(); close() }
|
|
43
|
-
|
|
44
|
-
onMount(() => {
|
|
45
|
-
rootEl = document.querySelector(`[data-dropdown-id="${dropdownInstanceId}"]`)
|
|
46
|
-
outsideHandler = (event) => {
|
|
47
|
-
if (!isOpen()) return
|
|
48
|
-
if (rootEl && !rootEl.contains(event.target)) close()
|
|
49
|
-
}
|
|
50
|
-
document.addEventListener('click', outsideHandler, true)
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
onDestroy(() => {
|
|
54
|
-
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|
|
58
|
-
const dataExpanded = derived(() => isOpen() ? 'true' : 'false')
|
|
59
|
-
|
|
60
|
-
defineExpose({ isOpen, toggle, open, close })
|
|
61
|
-
</script>
|
|
62
|
-
|
|
63
|
-
<component
|
|
64
|
-
:is="{{ as }}"
|
|
65
|
-
class="{{ dropdownClasses }}"
|
|
66
|
-
data-stx-dropdown
|
|
67
|
-
data-dropdown-id="{{ dropdownInstanceId }}"
|
|
68
|
-
:data-state="dataState()"
|
|
69
|
-
:data-expanded="dataExpanded()"
|
|
70
|
-
@stx:dropdown-toggle="onToggle($event)"
|
|
71
|
-
@stx:dropdown-open="onOpen($event)"
|
|
72
|
-
@stx:dropdown-close="onClose($event)"
|
|
73
|
-
@stx:dropdown-select="onItemSelect($event)"
|
|
74
|
-
>
|
|
75
|
-
<slot />
|
|
76
|
-
</component>
|
|
77
|
-
|
|
78
|
-
<style>
|
|
79
|
-
[data-stx-dropdown][data-state="closed"] [data-stx-dropdown-items] {
|
|
80
|
-
display: none;
|
|
81
|
-
}
|
|
82
|
-
</style>
|