@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
|
@@ -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
|
|
@@ -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
|
|
@@ -3,6 +3,17 @@ export const headingText = $props.headingText || 'Sign up for Stacks'
|
|
|
3
3
|
export const showSocialSignup = $bool($props.showSocialSignup, true)
|
|
4
4
|
export const className = $props.className || ''
|
|
5
5
|
|
|
6
|
+
/*
|
|
7
|
+
* Field ids unique to this instance.
|
|
8
|
+
*
|
|
9
|
+
* They were `email`, `password` and the like -- names generic enough to
|
|
10
|
+
* collide with the host app's own ids, which breaks getElementById and
|
|
11
|
+
* `<label for>` for both. `name` deliberately stays generic: it is the key the
|
|
12
|
+
* form submits under, and it is what `autocomplete` and password managers read
|
|
13
|
+
* alongside `type`, so the autofill behaviour is unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export const fieldPrefix = $props.id || `signup-${$uid}`
|
|
16
|
+
|
|
6
17
|
export const containerClasses = `min-h-full flex flex-col justify-center py-12 lg:px-8 sm:px-6 bg-page ${className}`.trim()
|
|
7
18
|
</script>
|
|
8
19
|
|
|
@@ -33,8 +44,8 @@ function onSubmit(event) {
|
|
|
33
44
|
emit('submit', { name, email, password })
|
|
34
45
|
|
|
35
46
|
setTimeout(() => {
|
|
36
|
-
event.target.querySelector('
|
|
37
|
-
event.target.querySelector('
|
|
47
|
+
event.target.querySelector('input[name="password"]')?.setAttribute('value', '')
|
|
48
|
+
event.target.querySelector('input[name="confirm_email"]')?.setAttribute('value', '')
|
|
38
49
|
}, 1000)
|
|
39
50
|
}
|
|
40
51
|
</script>
|
|
@@ -50,12 +61,12 @@ function onSubmit(event) {
|
|
|
50
61
|
<div class="bg-panel px-6 py-12 shadow sm:rounded-panel sm:px-12">
|
|
51
62
|
<form class="space-y-6" @submit="onSubmit($event)">
|
|
52
63
|
<div>
|
|
53
|
-
<label for="name" class="block text-sm text-fg font-medium leading-6">
|
|
64
|
+
<label for="{{ fieldPrefix }}-name" class="block text-sm text-fg font-medium leading-6">
|
|
54
65
|
Full Name
|
|
55
66
|
</label>
|
|
56
67
|
<div class="mt-2">
|
|
57
68
|
<input
|
|
58
|
-
id="name"
|
|
69
|
+
id="{{ fieldPrefix }}-name"
|
|
59
70
|
name="name"
|
|
60
71
|
type="text"
|
|
61
72
|
autocomplete="name"
|
|
@@ -66,12 +77,12 @@ function onSubmit(event) {
|
|
|
66
77
|
</div>
|
|
67
78
|
|
|
68
79
|
<div>
|
|
69
|
-
<label for="email" class="block text-sm text-fg font-medium leading-6">
|
|
80
|
+
<label for="{{ fieldPrefix }}-email" class="block text-sm text-fg font-medium leading-6">
|
|
70
81
|
Email address
|
|
71
82
|
</label>
|
|
72
83
|
<div class="mt-2">
|
|
73
84
|
<input
|
|
74
|
-
id="email"
|
|
85
|
+
id="{{ fieldPrefix }}-email"
|
|
75
86
|
name="email"
|
|
76
87
|
type="email"
|
|
77
88
|
autocomplete="email"
|
|
@@ -82,12 +93,12 @@ function onSubmit(event) {
|
|
|
82
93
|
</div>
|
|
83
94
|
|
|
84
95
|
<div>
|
|
85
|
-
<label for="confirm_email" class="block text-sm text-fg font-medium leading-6">
|
|
96
|
+
<label for="{{ fieldPrefix }}-confirm_email" class="block text-sm text-fg font-medium leading-6">
|
|
86
97
|
Confirm Email
|
|
87
98
|
</label>
|
|
88
99
|
<div class="mt-2">
|
|
89
100
|
<input
|
|
90
|
-
id="confirm_email"
|
|
101
|
+
id="{{ fieldPrefix }}-confirm_email"
|
|
91
102
|
name="confirm_email"
|
|
92
103
|
type="email"
|
|
93
104
|
autocomplete="email"
|
|
@@ -98,12 +109,12 @@ function onSubmit(event) {
|
|
|
98
109
|
</div>
|
|
99
110
|
|
|
100
111
|
<div>
|
|
101
|
-
<label for="password" class="block text-sm text-fg font-medium leading-6">
|
|
112
|
+
<label for="{{ fieldPrefix }}-password" class="block text-sm text-fg font-medium leading-6">
|
|
102
113
|
Password
|
|
103
114
|
</label>
|
|
104
115
|
<div class="mt-2">
|
|
105
116
|
<input
|
|
106
|
-
id="password"
|
|
117
|
+
id="{{ fieldPrefix }}-password"
|
|
107
118
|
name="password"
|
|
108
119
|
type="password"
|
|
109
120
|
autocomplete="new-password"
|
|
@@ -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
|
>
|
|
@@ -44,7 +44,23 @@ export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.m
|
|
|
44
44
|
export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
|
|
45
45
|
export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
|
|
46
46
|
export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
|
|
47
|
-
|
|
47
|
+
/*
|
|
48
|
+
* Ids unique to this instance.
|
|
49
|
+
*
|
|
50
|
+
* These were derived from the LABEL or hardcoded outright, so two of these on
|
|
51
|
+
* one page -- an ordinary form -- emitted the same id twice. `<label for>`
|
|
52
|
+
* then activated the FIRST field from every label, and `aria-describedby`
|
|
53
|
+
* pointed every field's description at the first one's helper text. A label
|
|
54
|
+
* containing a space also produced an invalid id, `input-First name`, which
|
|
55
|
+
* getElementById and querySelector cannot address at all.
|
|
56
|
+
*
|
|
57
|
+
* `$uid` is unique per instance and stable across renders, which is what an id
|
|
58
|
+
* has to be (utils.ts explains why a render that changes its own bytes is
|
|
59
|
+
* uncacheable). The `id` prop overrides it, for a caller that needs to point
|
|
60
|
+
* its own `for` or `aria-describedby` at this control.
|
|
61
|
+
*/
|
|
62
|
+
export const inputId = $props.id || `input-${$uid}`
|
|
63
|
+
export const helperId = `${inputId}-helper`
|
|
48
64
|
</script>
|
|
49
65
|
|
|
50
66
|
<script client>
|
|
@@ -104,7 +120,7 @@ defineExpose({ value: inputValue, clear: onClear })
|
|
|
104
120
|
@input="onInput($event)"
|
|
105
121
|
@change="onChange($event)"
|
|
106
122
|
:aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
107
|
-
@if(helperText)aria-describedby="
|
|
123
|
+
@if(helperText)aria-describedby="{{ helperId }}"@endif
|
|
108
124
|
/>
|
|
109
125
|
|
|
110
126
|
@if(clearable)
|
|
@@ -131,7 +147,7 @@ defineExpose({ value: inputValue, clear: onClear })
|
|
|
131
147
|
@if(helperText || (showCount && maxLength))
|
|
132
148
|
<div class="flex items-center justify-between mt-2">
|
|
133
149
|
@if(helperText)
|
|
134
|
-
<p id="
|
|
150
|
+
<p id="{{ helperId }}" class="{{ helperClasses }}">
|
|
135
151
|
{{ helperText }}
|
|
136
152
|
</p>
|
|
137
153
|
@else
|
|
@@ -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
|
|
@@ -6,12 +6,32 @@ export const codeLength = $props.codeLength || 6
|
|
|
6
6
|
export const showRecoveryCode = $bool($props.showRecoveryCode, true)
|
|
7
7
|
export const className = $props.className || ''
|
|
8
8
|
|
|
9
|
+
/*
|
|
10
|
+
* The digit inputs' ids, unique to this instance.
|
|
11
|
+
*
|
|
12
|
+
* They were `code-0` ... `code-5`, and the focus management looks them up with
|
|
13
|
+
* `document.getElementById` -- a DOCUMENT-wide lookup on an id as generic as
|
|
14
|
+
* `code-1`. Any element in the host app with that id would take the focus
|
|
15
|
+
* instead, and two of these on a page would type into each other.
|
|
16
|
+
*
|
|
17
|
+
* `name` deliberately stays `code-<i>`: that is the key the form submits
|
|
18
|
+
* under, so namespacing it would change the payload a server sees. Only the
|
|
19
|
+
* id, which exists to connect the label and the focus moves, is instance-local.
|
|
20
|
+
*/
|
|
21
|
+
export const codeIdPrefix = $props.id || `code-${$uid}`
|
|
22
|
+
|
|
9
23
|
export const containerClasses = `py-32 bg-page ${className}`.trim()
|
|
10
24
|
</script>
|
|
11
25
|
|
|
12
26
|
<script client>
|
|
13
27
|
const emit = defineEmits()
|
|
14
28
|
const codeLength = {{ codeLength }}
|
|
29
|
+
const codeIdPrefix = {{ codeIdPrefix }}
|
|
30
|
+
|
|
31
|
+
/** The digit input at `index`, found by this instance's own id. */
|
|
32
|
+
function codeInput(index) {
|
|
33
|
+
return document.getElementById(codeIdPrefix + '-' + index)
|
|
34
|
+
}
|
|
15
35
|
|
|
16
36
|
function onCodeInput(event, index) {
|
|
17
37
|
const input = event.target
|
|
@@ -21,13 +41,13 @@ function onCodeInput(event, index) {
|
|
|
21
41
|
return
|
|
22
42
|
}
|
|
23
43
|
if (value.length === 1 && index < codeLength - 1) {
|
|
24
|
-
|
|
44
|
+
codeInput(index + 1)?.focus()
|
|
25
45
|
}
|
|
26
46
|
}
|
|
27
47
|
|
|
28
48
|
function onKeyDown(event, index) {
|
|
29
49
|
if (event.key === 'Backspace' && !event.target.value && index > 0) {
|
|
30
|
-
|
|
50
|
+
codeInput(index - 1)?.focus()
|
|
31
51
|
}
|
|
32
52
|
}
|
|
33
53
|
|
|
@@ -35,7 +55,7 @@ function onSubmit(event) {
|
|
|
35
55
|
event.preventDefault()
|
|
36
56
|
const code = []
|
|
37
57
|
for (let i = 0; i < codeLength; i++) {
|
|
38
|
-
const input =
|
|
58
|
+
const input = codeInput(i)
|
|
39
59
|
if (input?.value) code.push(input.value)
|
|
40
60
|
}
|
|
41
61
|
if (code.length === codeLength) {
|
|
@@ -59,14 +79,14 @@ function onRecoveryCode(event) {
|
|
|
59
79
|
<h3 class="text-center text-sm text-fg font-semibold">
|
|
60
80
|
{{ headingText }}
|
|
61
81
|
</h3>
|
|
62
|
-
<label for="
|
|
82
|
+
<label for="{{ codeIdPrefix }}-0" class="mt-4 block text-sm text-fg font-medium leading-6">
|
|
63
83
|
{{ labelText }}
|
|
64
84
|
</label>
|
|
65
85
|
<form @submit="onSubmit($event)">
|
|
66
86
|
<div class="mt-2 flex rounded-control shadow-sm space-x-2">
|
|
67
87
|
@for(let i = 0; i < codeLength; i++)
|
|
68
88
|
<input
|
|
69
|
-
id="
|
|
89
|
+
id="{{ codeIdPrefix }}-{{ i }}"
|
|
70
90
|
type="text"
|
|
71
91
|
maxlength="1"
|
|
72
92
|
name="code-{{ i }}"
|