@stacksjs/components 0.2.466 → 0.2.468
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/{EmailInput-ffzwvp9r.stx → EmailInput-57626391.stx} +3 -0
- package/dist/{NumberInput-r2wsh8w9.stx → NumberInput-pq4k2k4k.stx} +31 -10
- package/dist/{PasswordInput-36bws0kf.stx → PasswordInput-dg41ktgd.stx} +8 -1
- package/dist/{Select-pv44ngbe.stx → Select-61zv5tr7.stx} +98 -17
- package/dist/Table-0a4y46vd.stx +43 -0
- package/dist/TableCell-jhvsxw8b.stx +17 -0
- package/dist/TableHeader-krzcx4sv.stx +62 -0
- package/dist/{TextInput-h9trj9f9.stx → TextInput-nknmz9md.stx} +57 -4
- package/dist/{Textarea-k8cjs4zs.stx → Textarea-9xmhjqp8.stx} +30 -7
- package/dist/index.js +5 -5
- package/dist/overlays/overlays.js +22 -0
- package/dist/ui/input/index.d.ts +18 -5
- package/dist/ui/select/index.d.ts +1 -1
- package/dist/ui/table/index.d.ts +4 -0
- package/dist/utils/overlays.d.ts +5 -1
- package/package.json +8 -3
- package/src/ui/input/EmailInput.stx +3 -0
- package/src/ui/input/NumberInput.stx +31 -10
- package/src/ui/input/PasswordInput.stx +8 -1
- package/src/ui/input/TextInput.stx +57 -4
- package/src/ui/input/index.ts +31 -5
- package/src/ui/select/README.md +59 -21
- package/src/ui/select/Select.stx +98 -17
- package/src/ui/select/index.ts +8 -1
- package/src/ui/table/README.md +69 -1
- package/src/ui/table/Table.stx +31 -2
- package/src/ui/table/TableCell.stx +8 -1
- package/src/ui/table/TableHeader.stx +47 -5
- package/src/ui/table/index.ts +9 -0
- package/src/ui/textarea/Textarea.stx +30 -7
- package/src/utils/overlays.ts +5 -1
- package/dist/Table-3ek3w95h.stx +0 -14
- package/dist/TableCell-8swtcq8s.stx +0 -10
- package/dist/TableHeader-qsc3e208.stx +0 -20
|
@@ -26,7 +26,10 @@ export const inputMode = $props.inputMode || $props.inputmode || ''
|
|
|
26
26
|
export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
|
|
27
27
|
</script>
|
|
28
28
|
|
|
29
|
+
{{-- type="email": served as text, an email field got no email keyboard on a
|
|
30
|
+
phone and no email check from the browser. --}}
|
|
29
31
|
<TextInput
|
|
32
|
+
type="email"
|
|
30
33
|
:name="name"
|
|
31
34
|
:autocomplete="autocomplete"
|
|
32
35
|
:form="form"
|
|
@@ -25,9 +25,13 @@ export const inputId = $props.id || `number-input-${$uid}`
|
|
|
25
25
|
export const helperId = `${inputId}-helper`
|
|
26
26
|
export const helperText = $props.helperText || ''
|
|
27
27
|
export const required = $bool($props.required)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/*
|
|
29
|
+
* Numbers, not the strings an attribute arrives as: `step="2"` reached the
|
|
30
|
+
* client script as "2", and the Increment button computed 10 + "2" = "102".
|
|
31
|
+
*/
|
|
32
|
+
export const min = $props.min == null || $props.min === '' ? undefined : $num($props.min)
|
|
33
|
+
export const max = $props.max == null || $props.max === '' ? undefined : $num($props.max)
|
|
34
|
+
export const step = $num($props.step, 1)
|
|
31
35
|
export const showControls = $bool($props.showControls, true)
|
|
32
36
|
export const className = $props.className || ''
|
|
33
37
|
export const inputClassName = $props.inputClassName || ''
|
|
@@ -42,7 +46,14 @@ export const inputClassName = $props.inputClassName || ''
|
|
|
42
46
|
* is 3.25rem of content inside a declared 3rem box - so py-2.5 lands on the
|
|
43
47
|
* 3rem it always claimed. sm and md were already exact.
|
|
44
48
|
*/
|
|
45
|
-
|
|
49
|
+
/*
|
|
50
|
+
* md -- the size nearly every form uses -- reads the density roles, so an
|
|
51
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
52
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
53
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
54
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
55
|
+
*/
|
|
56
|
+
const sizeClasses = { sm: 'px-3 py-1.5 text-sm', md: 'px-control-x py-control-y text-control', lg: 'px-5 py-2.5 text-lg' }
|
|
46
57
|
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset bg-field'
|
|
47
58
|
const stateClasses = error
|
|
48
59
|
? 'ring-danger-line text-danger-fg placeholder-danger focus:ring-danger-focus'
|
|
@@ -85,12 +96,21 @@ const emit = defineEmits()
|
|
|
85
96
|
const stepSize = {{ step }}
|
|
86
97
|
const minVal = {{ min === undefined ? 'undefined' : min }}
|
|
87
98
|
const maxVal = {{ max === undefined ? 'undefined' : max }}
|
|
88
|
-
|
|
89
|
-
|
|
99
|
+
/*
|
|
100
|
+
* Two-way, like TextInput (stacksjs/stx#2059): `v-model:value="qty"` keeps the
|
|
101
|
+
* page's signal in step -- typing and the steppers both write it -- and
|
|
102
|
+
* `.number` hands the page a number. `input` is still emitted.
|
|
103
|
+
*/
|
|
104
|
+
const inputValue = useModel('value', { default: {{ value }}, parse: (v) => v == null || v === '' ? '' : String(v) })
|
|
90
105
|
|
|
91
106
|
function onInput(event) {
|
|
92
|
-
inputValue.
|
|
93
|
-
emit('input', inputValue())
|
|
107
|
+
inputValue.input(event.target.value)
|
|
108
|
+
if (!inputValue.modifiers.lazy) emit('input', inputValue())
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function onChange(event) {
|
|
112
|
+
inputValue.change(event.target.value)
|
|
113
|
+
if (inputValue.modifiers.lazy) emit('input', inputValue())
|
|
94
114
|
}
|
|
95
115
|
|
|
96
116
|
function increment() {
|
|
@@ -98,7 +118,7 @@ function increment() {
|
|
|
98
118
|
const next = current + stepSize
|
|
99
119
|
if (maxVal !== undefined && next > maxVal) return
|
|
100
120
|
inputValue.set(String(next))
|
|
101
|
-
emit('input',
|
|
121
|
+
emit('input', inputValue())
|
|
102
122
|
}
|
|
103
123
|
|
|
104
124
|
function decrement() {
|
|
@@ -106,7 +126,7 @@ function decrement() {
|
|
|
106
126
|
const next = current - stepSize
|
|
107
127
|
if (minVal !== undefined && next < minVal) return
|
|
108
128
|
inputValue.set(String(next))
|
|
109
|
-
emit('input',
|
|
129
|
+
emit('input', inputValue())
|
|
110
130
|
}
|
|
111
131
|
|
|
112
132
|
defineExpose({ value: inputValue, increment, decrement })
|
|
@@ -153,6 +173,7 @@ defineExpose({ value: inputValue, increment, decrement })
|
|
|
153
173
|
@if(max !== undefined)max="{{ max }}"@endif
|
|
154
174
|
step="{{ step }}"
|
|
155
175
|
@input="onInput($event)"
|
|
176
|
+
@change="onChange($event)"
|
|
156
177
|
:aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
157
178
|
@if(helperText)aria-describedby="{{ helperId }}"@endif
|
|
158
179
|
/>
|
|
@@ -39,7 +39,14 @@ export const inputClassName = $props.inputClassName || ''
|
|
|
39
39
|
* is 3.25rem of content inside a declared 3rem box - so py-2.5 lands on the
|
|
40
40
|
* 3rem it always claimed. sm and md were already exact.
|
|
41
41
|
*/
|
|
42
|
-
|
|
42
|
+
/*
|
|
43
|
+
* md -- the size nearly every form uses -- reads the density roles, so an
|
|
44
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
45
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
46
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
47
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
48
|
+
*/
|
|
49
|
+
const sizeClasses = { sm: 'px-3 py-1.5 text-sm', md: 'px-control-x py-control-y text-control', lg: 'px-5 py-2.5 text-lg' }
|
|
43
50
|
const iconSizeClasses = { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6' }
|
|
44
51
|
|
|
45
52
|
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset bg-field pr-10'
|
|
@@ -1,7 +1,34 @@
|
|
|
1
1
|
<script server>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/*
|
|
3
|
+
* `??`, not `||`: a select whose chosen option is the id 0 is ordinary, and
|
|
4
|
+
* `||` served it as nothing selected.
|
|
5
|
+
*/
|
|
6
|
+
export const value = $props.value ?? ''
|
|
7
|
+
/*
|
|
8
|
+
* One shape for every option, whichever way it arrived (stacksjs/stx#2059).
|
|
9
|
+
*
|
|
10
|
+
* `{ value, label, disabled }` objects as before, plus bare strings or numbers
|
|
11
|
+
* (`['S', 'M', 'L']`), which are their own label. A string is parsed as JSON,
|
|
12
|
+
* because that is how a list written as a plain attribute arrives. The client
|
|
13
|
+
* script below applies the same rules to a list that arrives later.
|
|
14
|
+
*/
|
|
15
|
+
function normaliseOptions(list) {
|
|
16
|
+
if (typeof list === 'string') {
|
|
17
|
+
try { list = JSON.parse(list) }
|
|
18
|
+
catch { list = [] }
|
|
19
|
+
}
|
|
20
|
+
if (!Array.isArray(list))
|
|
21
|
+
return []
|
|
22
|
+
return list.map(option => option !== null && typeof option === 'object'
|
|
23
|
+
? { value: option.value == null ? '' : String(option.value), label: String(option.label ?? option.value ?? ''), disabled: Boolean(option.disabled) }
|
|
24
|
+
: { value: String(option), label: String(option), disabled: false })
|
|
25
|
+
}
|
|
26
|
+
export const options = normaliseOptions($props.options)
|
|
27
|
+
/*
|
|
28
|
+
* `??`: `placeholder=""` means no placeholder option at all, which a select
|
|
29
|
+
* whose options are its children usually wants. Unset keeps the default.
|
|
30
|
+
*/
|
|
31
|
+
export const placeholder = $props.placeholder ?? 'Select an option'
|
|
5
32
|
export const disabled = $bool($props.disabled)
|
|
6
33
|
export const size = $props.size || 'md'
|
|
7
34
|
export const error = $bool($props.error)
|
|
@@ -20,7 +47,14 @@ export const className = $props.className || ''
|
|
|
20
47
|
* is 3.25rem of content inside a declared 3rem box - so py-2.5 lands on the
|
|
21
48
|
* 3rem it always claimed. sm and md were already exact.
|
|
22
49
|
*/
|
|
23
|
-
|
|
50
|
+
/*
|
|
51
|
+
* md -- the size nearly every form uses -- reads the density roles, so an
|
|
52
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
53
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
54
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
55
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
56
|
+
*/
|
|
57
|
+
const sizeClasses = { sm: 'px-3 py-1.5 text-sm', md: 'px-control-x py-control-y text-control', lg: 'px-5 py-2.5 text-lg' }
|
|
24
58
|
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset bg-field'
|
|
25
59
|
/*
|
|
26
60
|
* The two halves of the validity state, exported so the CLIENT can swap them
|
|
@@ -81,15 +115,43 @@ const emit = defineEmits()
|
|
|
81
115
|
// Validity is live, for the same reason `disabled` is: a form posted with
|
|
82
116
|
// fetch learns it after the submit, and nothing re-renders (#2047).
|
|
83
117
|
const isError = useReactiveProp('error', {{ error }})
|
|
84
|
-
|
|
85
|
-
|
|
118
|
+
/*
|
|
119
|
+
* Two-way, like TextInput (stacksjs/stx#2059): `v-model:value="group"` keeps
|
|
120
|
+
* the page's signal in step, so a call site no longer pairs `:value` with an
|
|
121
|
+
* `@change` that writes it back. `change` is still emitted for the callers
|
|
122
|
+
* that listen for it.
|
|
123
|
+
*/
|
|
124
|
+
const selectedValue = useModel('value', { default: {{ value }}, parse: v => v == null ? '' : String(v) })
|
|
125
|
+
|
|
126
|
+
function normaliseOptions(list) {
|
|
127
|
+
if (typeof list === 'string') {
|
|
128
|
+
try { list = JSON.parse(list) }
|
|
129
|
+
catch (e) { list = [] }
|
|
130
|
+
}
|
|
131
|
+
if (!Array.isArray(list)) return []
|
|
132
|
+
return list.map(option => option !== null && typeof option === 'object'
|
|
133
|
+
? { value: option.value == null ? '' : String(option.value), label: String(option.label ?? option.value ?? ''), disabled: Boolean(option.disabled) }
|
|
134
|
+
: { value: String(option), label: String(option), disabled: false })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/*
|
|
138
|
+
* The options are live (stacksjs/stx#2059).
|
|
139
|
+
*
|
|
140
|
+
* They were read once, in the server script, so a list that arrives with the
|
|
141
|
+
* page's data -- an athlete's groups, a coach's plans -- was not there to read
|
|
142
|
+
* and the select rendered its placeholder alone. Now the prop is a signal and
|
|
143
|
+
* the list below is drawn from it on the client, so a bound `:options` renders
|
|
144
|
+
* and re-renders when the parent's list changes.
|
|
145
|
+
*/
|
|
146
|
+
const optionSource = useReactiveProp('options', {{ options }}, { parse: v => normaliseOptions(v) })
|
|
147
|
+
const optionList = derived(() => normaliseOptions(optionSource()))
|
|
86
148
|
|
|
87
149
|
function onChange(event) {
|
|
88
150
|
selectedValue.set(event.target.value)
|
|
89
151
|
emit('change', selectedValue())
|
|
90
152
|
}
|
|
91
153
|
|
|
92
|
-
defineExpose({ value: selectedValue })
|
|
154
|
+
defineExpose({ value: selectedValue, options: optionList })
|
|
93
155
|
</script>
|
|
94
156
|
|
|
95
157
|
<div class="w-full">
|
|
@@ -114,26 +176,45 @@ defineExpose({ value: selectedValue })
|
|
|
114
176
|
@if(required)required@endif
|
|
115
177
|
@change="onChange($event)"
|
|
116
178
|
aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
aria-describedby="{{
|
|
179
|
+
:aria-invalid="isError() ? 'true' : 'false'"
|
|
180
|
+
:class="{ '{{ stateInvalidClasses }}': isError(), '{{ stateValidClasses }}': !isError() }"
|
|
181
|
+
@if(helperText)aria-describedby="{{ helperId }}"@endif
|
|
120
182
|
>
|
|
121
183
|
@if(placeholder)
|
|
122
184
|
<option value="" disabled>{{ placeholder }}</option>
|
|
123
185
|
@endif
|
|
124
186
|
|
|
187
|
+
{{-- First paint, and the whole list with JavaScript off.
|
|
188
|
+
|
|
189
|
+
Server-rendered from a list known at render time, with `selected` on
|
|
190
|
+
the served choice (defaultSelected: without it a select posted its
|
|
191
|
+
FIRST option no matter what `value` said). On hydration these step
|
|
192
|
+
aside for the live list below, which draws the same options from
|
|
193
|
+
the same prop -- `x-if="false"` removes them in the pass that renders
|
|
194
|
+
it, and `x-no-cloak` keeps them visible until then. `x-if` rather
|
|
195
|
+
than `:if` because @foreach pre-evaluates every `:name="…"` inside
|
|
196
|
+
it as a component prop, which turns `:if` into a dead attribute. --}}
|
|
125
197
|
@foreach(option in options)
|
|
126
198
|
<option
|
|
199
|
+
x-no-cloak
|
|
200
|
+
x-if="false"
|
|
127
201
|
value="{{ option.value }}"
|
|
128
202
|
@if(option.disabled)disabled@endif
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
no matter what `value` said. --}}
|
|
132
|
-
@if(String(option.value) === String(value))selected@endif
|
|
133
|
-
>
|
|
134
|
-
{{ option.label }}
|
|
135
|
-
</option>
|
|
203
|
+
@if(option.value === String(value))selected@endif
|
|
204
|
+
>{{ option.label }}</option>
|
|
136
205
|
@endforeach
|
|
206
|
+
|
|
207
|
+
{{-- The live list. A <template>, so nothing of it shows before the
|
|
208
|
+
runtime expands it -- an <option :for> would paint as an empty
|
|
209
|
+
entry first. The select's own `:value` re-applies itself when its
|
|
210
|
+
options change, so the chosen value is reflected once they arrive. --}}
|
|
211
|
+
<template :for="option in optionList()" :key="option.value">
|
|
212
|
+
<option :value="option.value" :disabled="option.disabled" x-text="option.label"></option>
|
|
213
|
+
</template>
|
|
214
|
+
|
|
215
|
+
{{-- Or the options as children, for a list the page draws itself:
|
|
216
|
+
<Select v-model:value="x"><option :for="o in list" :value="o.id">…</option></Select> --}}
|
|
217
|
+
<slot />
|
|
137
218
|
</select>
|
|
138
219
|
</div>
|
|
139
220
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
export const className = $props.className || ''
|
|
3
|
+
export const striped = $bool($props.striped)
|
|
4
|
+
export const hoverable = $bool($props.hoverable, true)
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* The table's accessible name (stacksjs/stx#2060).
|
|
8
|
+
*
|
|
9
|
+
* A table is named by its <caption>, and there was no way to give a library
|
|
10
|
+
* table one: no prop, and no slot ahead of <thead>. It is the table's first
|
|
11
|
+
* child, as HTML requires, and visually hidden unless `captionVisible` -- most
|
|
12
|
+
* tables sit under a heading that already says what they are, and a second
|
|
13
|
+
* visible title would repeat it.
|
|
14
|
+
*/
|
|
15
|
+
export const caption = $props.caption || ''
|
|
16
|
+
export const captionVisible = $bool($props.captionVisible)
|
|
17
|
+
export const captionClasses = captionVisible
|
|
18
|
+
? 'caption-top px-cell-x py-2 text-left text-sm font-semibold text-fg'
|
|
19
|
+
: 'sr-only'
|
|
20
|
+
|
|
21
|
+
const baseClasses = 'min-w-full divide-y divide-line'
|
|
22
|
+
export const tableClasses = `${baseClasses} ${className}`.trim()
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div class="overflow-x-auto">
|
|
26
|
+
<table class="{{ tableClasses }}" @if(caption)data-stx-caption@endif>
|
|
27
|
+
@if(caption)<caption class="{{ captionClasses }}">{{ caption }}</caption>@endif
|
|
28
|
+
<slot :striped="striped" :hoverable="hoverable" />
|
|
29
|
+
</table>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
/*
|
|
34
|
+
* `divide-y` borders every child after the first, and with a caption first
|
|
35
|
+
* that includes the header row: a captioned table grew a rule along its top
|
|
36
|
+
* edge that an uncaptioned one does not have. This takes it back off. The
|
|
37
|
+
* selector has to outrank divide-y's own (0,3,0) -- hence the table's
|
|
38
|
+
* :not([hidden]) -- or which one won would be stylesheet order again.
|
|
39
|
+
*/
|
|
40
|
+
table[data-stx-caption]:not([hidden]) > caption + :not([hidden]) {
|
|
41
|
+
border-top-width: 0;
|
|
42
|
+
}
|
|
43
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
export const className = $props.className || ''
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Padding and type read the density roles, so an app's tables take its own
|
|
6
|
+
* cell size from --stx-cell-px, --stx-cell-py, --stx-cell-text and
|
|
7
|
+
* --stx-cell-leading -- a className of py-2 ties with py-4 on
|
|
8
|
+
* specificity and wins only by stylesheet order. The fallbacks are px-6 /
|
|
9
|
+
* py-4 / text-sm, so nothing moves by default (stacksjs/stx#1993).
|
|
10
|
+
*/
|
|
11
|
+
const baseClasses = 'px-cell-x py-cell-y whitespace-nowrap text-cell text-fg'
|
|
12
|
+
const cellClasses = `${baseClasses} ${className}`.trim()
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<td class="{{ cellClasses }}">
|
|
16
|
+
<slot />
|
|
17
|
+
</td>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
export const className = $props.className || ''
|
|
3
|
+
export const sortable = $bool($props.sortable)
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Which cells this header heads (stacksjs/stx#2060).
|
|
7
|
+
*
|
|
8
|
+
* A <th> without `scope` leaves a screen reader to guess, and it guesses wrong
|
|
9
|
+
* in any table with row headers. `col` by default, because that is what a
|
|
10
|
+
* header in a <thead> is; `row` for a header at the start of a body row. An
|
|
11
|
+
* attribute written on <TableHeader> never reached the <th>, so there was no
|
|
12
|
+
* way to say it at all.
|
|
13
|
+
*/
|
|
14
|
+
const SCOPES = ['col', 'row', 'colgroup', 'rowgroup']
|
|
15
|
+
export const scope = SCOPES.includes(String($props.scope)) ? String($props.scope) : 'col'
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Which way the column is sorted now, as `aria-sort` on the <th> -- the one
|
|
19
|
+
* place a screen reader looks for it. `asc` / `desc`; anything else is
|
|
20
|
+
* unsorted, `none`. Served on every sortable header (and on any header given
|
|
21
|
+
* a `sort`), and live, so a page re-sorting a table moves it without a
|
|
22
|
+
* re-render.
|
|
23
|
+
*/
|
|
24
|
+
const SORTS = { asc: 'ascending', desc: 'descending' }
|
|
25
|
+
export const sortDirection = SORTS[String($props.sort)] ? String($props.sort) : ''
|
|
26
|
+
export const announcesSort = sortable || ($props.sort !== undefined && $props.sort !== null)
|
|
27
|
+
export const servedAriaSort = SORTS[sortDirection] || 'none'
|
|
28
|
+
|
|
29
|
+
const baseClasses = 'px-cell-x py-cell-head-y text-left text-cell-head font-medium text-fg-soft uppercase tracking-wider'
|
|
30
|
+
export const headerClasses = `${baseClasses} ${className}`.trim()
|
|
31
|
+
/*
|
|
32
|
+
* The control that sorts. A <th> is not focusable, so a click handler on it
|
|
33
|
+
* made sorting mouse-only (stacksjs/stx#2060); a <button> inside it is
|
|
34
|
+
* reachable by Tab and operated by Enter and Space, and it is what emits
|
|
35
|
+
* `click`. It takes on the header's type -- the preflight resets a button's
|
|
36
|
+
* text-transform, so `uppercase` is restated -- and draws a ring on keyboard
|
|
37
|
+
* focus only.
|
|
38
|
+
*/
|
|
39
|
+
export const buttonClasses = 'inline-flex items-center gap-1 uppercase tracking-wider text-left rounded-control cursor-pointer hover:text-fg-strong focus:outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<script client>
|
|
43
|
+
const emit = defineEmits()
|
|
44
|
+
const sortState = useReactiveProp('sort', {{ sortDirection }}, { parse: v => v === 'asc' || v === 'desc' ? v : '' })
|
|
45
|
+
const ariaSort = derived(() => sortState() === 'asc' ? 'ascending' : sortState() === 'desc' ? 'descending' : 'none')
|
|
46
|
+
|
|
47
|
+
function onClick() {
|
|
48
|
+
emit('click')
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<th
|
|
53
|
+
scope="{{ scope }}"
|
|
54
|
+
class="{{ headerClasses }}"
|
|
55
|
+
@if(announcesSort)aria-sort="{{ servedAriaSort }}" :aria-sort="ariaSort()"@endif
|
|
56
|
+
>
|
|
57
|
+
@if(sortable)
|
|
58
|
+
<button type="button" class="{{ buttonClasses }}" @click="onClick()"><slot /></button>
|
|
59
|
+
@else
|
|
60
|
+
<slot />
|
|
61
|
+
@endif
|
|
62
|
+
</th>
|
|
@@ -11,7 +11,7 @@ export const required = $bool($props.required)
|
|
|
11
11
|
export const leftIcon = $props.leftIcon || ''
|
|
12
12
|
export const rightIcon = $props.rightIcon || ''
|
|
13
13
|
export const clearable = $bool($props.clearable)
|
|
14
|
-
export const maxLength = $props.maxLength
|
|
14
|
+
export const maxLength = $props.maxLength ?? $props.maxlength
|
|
15
15
|
export const showCount = $bool($props.showCount)
|
|
16
16
|
export const className = $props.className || ''
|
|
17
17
|
export const inputClassName = $props.inputClassName || ''
|
|
@@ -26,7 +26,14 @@ export const inputClassName = $props.inputClassName || ''
|
|
|
26
26
|
* is 3.25rem of content inside a declared 3rem box - so py-2.5 lands on the
|
|
27
27
|
* 3rem it always claimed. sm and md were already exact.
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
/*
|
|
30
|
+
* md -- the size nearly every form uses -- reads the density roles, so an
|
|
31
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
32
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
33
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
34
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
35
|
+
*/
|
|
36
|
+
const sizeClasses = { sm: 'px-3 py-1.5 text-sm', md: 'px-control-x py-control-y text-control', lg: 'px-5 py-2.5 text-lg' }
|
|
30
37
|
const iconSizeClasses = { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6' }
|
|
31
38
|
|
|
32
39
|
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset bg-field'
|
|
@@ -98,6 +105,44 @@ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
|
|
|
98
105
|
export const form = $props.form || ''
|
|
99
106
|
export const inputMode = $props.inputMode || $props.inputmode || ''
|
|
100
107
|
export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
|
|
108
|
+
|
|
109
|
+
/*
|
|
110
|
+
* The text-like input types (stacksjs/stx#2059).
|
|
111
|
+
*
|
|
112
|
+
* `type` was hard-coded to text, so a form with a date, a time, a URL or a
|
|
113
|
+
* phone number in it had to mix library and native controls -- the
|
|
114
|
+
* inconsistency the library exists to remove. email, number and password have
|
|
115
|
+
* components of their own but are accepted here too. Anything else (checkbox,
|
|
116
|
+
* file, range...) is not a text field, and is served as text rather than as a
|
|
117
|
+
* control this markup was not drawn for.
|
|
118
|
+
*/
|
|
119
|
+
const TEXT_TYPES = ['text', 'date', 'time', 'datetime-local', 'month', 'week', 'url', 'tel', 'color', 'search', 'email', 'number', 'password']
|
|
120
|
+
export const type = TEXT_TYPES.includes(String($props.type)) ? String($props.type) : 'text'
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* The constraint attributes, each emitted only when given AND only on the
|
|
124
|
+
* types HTML applies it to, so a control renders exactly the markup it did
|
|
125
|
+
* before unless the caller asked for something it can use: min/max/step
|
|
126
|
+
* bound the date, time and number types; pattern, minlength, maxlength and
|
|
127
|
+
* size the free-text ones; list every type but password.
|
|
128
|
+
*/
|
|
129
|
+
const RANGED_TYPES = ['date', 'time', 'datetime-local', 'month', 'week', 'number']
|
|
130
|
+
const FREE_TEXT_TYPES = ['text', 'search', 'url', 'tel', 'email', 'password']
|
|
131
|
+
const given = (v) => v !== undefined && v !== null && v !== '' && v !== false
|
|
132
|
+
const ranged = RANGED_TYPES.includes(type)
|
|
133
|
+
export const freeText = FREE_TEXT_TYPES.includes(type)
|
|
134
|
+
export const min = ranged && given($props.min) ? String($props.min) : ''
|
|
135
|
+
export const max = ranged && given($props.max) ? String($props.max) : ''
|
|
136
|
+
export const step = ranged && given($props.step) ? String($props.step) : ''
|
|
137
|
+
export const pattern = freeText && given($props.pattern) ? String($props.pattern) : ''
|
|
138
|
+
export const minLength = freeText && given($props.minLength ?? $props.minlength) ? String($props.minLength ?? $props.minlength) : ''
|
|
139
|
+
/*
|
|
140
|
+
* The HTML `size` attribute (a width in characters). Not `size`, which is
|
|
141
|
+
* already this component's sm / md / lg.
|
|
142
|
+
*/
|
|
143
|
+
export const htmlSize = freeText && given($props.htmlSize) ? String($props.htmlSize) : ''
|
|
144
|
+
export const list = type !== 'password' && given($props.list) ? String($props.list) : ''
|
|
145
|
+
export const autofocus = $bool($props.autofocus)
|
|
101
146
|
</script>
|
|
102
147
|
|
|
103
148
|
<script client>
|
|
@@ -153,7 +198,15 @@ defineExpose({ value: inputValue, clear: onClear })
|
|
|
153
198
|
@if(form)form="{{ form }}"@endif
|
|
154
199
|
@if(inputMode)inputmode="{{ inputMode }}"@endif
|
|
155
200
|
@if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
|
|
156
|
-
type="
|
|
201
|
+
type="{{ type }}"
|
|
202
|
+
@if(min)min="{{ min }}"@endif
|
|
203
|
+
@if(max)max="{{ max }}"@endif
|
|
204
|
+
@if(step)step="{{ step }}"@endif
|
|
205
|
+
@if(pattern)pattern="{{ pattern }}"@endif
|
|
206
|
+
@if(minLength)minlength="{{ minLength }}"@endif
|
|
207
|
+
@if(htmlSize)size="{{ htmlSize }}"@endif
|
|
208
|
+
@if(list)list="{{ list }}"@endif
|
|
209
|
+
@if(autofocus)autofocus@endif
|
|
157
210
|
id="{{ inputId }}"
|
|
158
211
|
class="{{ inputClasses }}"
|
|
159
212
|
|
|
@@ -173,7 +226,7 @@ defineExpose({ value: inputValue, clear: onClear })
|
|
|
173
226
|
@if(disabled)disabled@endif
|
|
174
227
|
@if(readonly)readonly@endif
|
|
175
228
|
@if(required)required@endif
|
|
176
|
-
@if(maxLength)maxlength="{{ maxLength }}"@endif
|
|
229
|
+
@if(maxLength && freeText)maxlength="{{ maxLength }}"@endif
|
|
177
230
|
@input="onInput($event)"
|
|
178
231
|
@change="onChange($event)"
|
|
179
232
|
aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
@@ -33,7 +33,14 @@ export const resize = $props.resize || 'vertical'
|
|
|
33
33
|
export const className = $props.className || ''
|
|
34
34
|
|
|
35
35
|
const resizeClasses = { none: 'resize-none', vertical: 'resize-y', horizontal: 'resize-x', both: 'resize' }
|
|
36
|
-
|
|
36
|
+
/*
|
|
37
|
+
* The padding and type read the density roles, so an
|
|
38
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
39
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
40
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
41
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
42
|
+
*/
|
|
43
|
+
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset px-control-x py-control-y text-control bg-field'
|
|
37
44
|
/*
|
|
38
45
|
* The two halves of the validity state, exported so the CLIENT can swap them
|
|
39
46
|
* (stacksjs/stx#2047). Toggled per class rather than as a whole string,
|
|
@@ -82,8 +89,12 @@ const emit = defineEmits()
|
|
|
82
89
|
const isError = useReactiveProp('error', {{ error }})
|
|
83
90
|
const autoResize = {{ autoResize }}
|
|
84
91
|
const maxRows = {{ maxRows }}
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
/*
|
|
93
|
+
* Two-way, like TextInput (stacksjs/stx#2059): `v-model:value="bio"` keeps the
|
|
94
|
+
* page's signal in step, with `.lazy` and `.trim` honoured. `input` is still
|
|
95
|
+
* emitted for the callers that listen for it.
|
|
96
|
+
*/
|
|
97
|
+
const inputValue = useModel('value', { default: {{ value }}, parse: (v) => v == null ? '' : String(v) })
|
|
87
98
|
|
|
88
99
|
function resizeTextarea(el) {
|
|
89
100
|
if (!autoResize) return
|
|
@@ -96,19 +107,26 @@ function resizeTextarea(el) {
|
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
function onInput(event) {
|
|
99
|
-
inputValue.
|
|
110
|
+
inputValue.input(event.target.value)
|
|
100
111
|
resizeTextarea(event.target)
|
|
101
|
-
emit('input', inputValue())
|
|
112
|
+
if (!inputValue.modifiers.lazy) emit('input', inputValue())
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function onChange(event) {
|
|
116
|
+
inputValue.change(event.target.value)
|
|
117
|
+
if (inputValue.modifiers.lazy) emit('input', inputValue())
|
|
102
118
|
}
|
|
103
119
|
|
|
104
120
|
onMount(() => {
|
|
105
121
|
if (autoResize) {
|
|
106
|
-
|
|
122
|
+
// The instance's own id: a fixed 'textarea-input' stopped matching
|
|
123
|
+
// anything once ids became unique per instance.
|
|
124
|
+
const el = document.getElementById({{ inputId }})
|
|
107
125
|
if (el) resizeTextarea(el)
|
|
108
126
|
}
|
|
109
127
|
})
|
|
110
128
|
|
|
111
|
-
const charCount = derived(() => `${inputValue().length} / {{ maxLength || 0 }}`)
|
|
129
|
+
const charCount = derived(() => `${String(inputValue()).length} / {{ maxLength || 0 }}`)
|
|
112
130
|
|
|
113
131
|
defineExpose({ value: inputValue })
|
|
114
132
|
</script>
|
|
@@ -137,7 +155,12 @@ defineExpose({ value: inputValue })
|
|
|
137
155
|
@if(readonly)readonly@endif
|
|
138
156
|
@if(required)required@endif
|
|
139
157
|
@if(maxLength)maxlength="{{ maxLength }}"@endif
|
|
158
|
+
{{-- The live value. The served text between the tags is the default
|
|
159
|
+
value; this keeps the element in step when the page's signal moves,
|
|
160
|
+
which nothing did before -- the field had no binding at all. --}}
|
|
161
|
+
:value="inputValue()"
|
|
140
162
|
@input="onInput($event)"
|
|
163
|
+
@change="onChange($event)"
|
|
141
164
|
aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
142
165
|
:aria-invalid="isError() ? 'true' : 'false'"
|
|
143
166
|
:class="{ '{{ stateInvalidClasses }}': isError(), '{{ stateValidClasses }}': !isError() }"
|