@stacksjs/components 0.2.465 → 0.2.467
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ChatLauncher-pc9nqh43.stx → ChatLauncher-3zph4trh.stx} +10 -2
- package/dist/{Combobox-9xh1jgjr.stx → Combobox-9n04ec5w.stx} +16 -4
- package/dist/{CommandPalette-vvaqtqat.stx → CommandPalette-qqjdbcyg.stx} +33 -8
- package/dist/{DateRangePicker-z64qqw84.stx → DateRangePicker-4zmf34e4.stx} +13 -9
- package/dist/Dialog-pdq8rxvy.stx +162 -0
- package/dist/{Drawer-hc0jjpsw.stx → Drawer-nmq100vy.stx} +24 -128
- package/dist/{Dropdown-25160tc6.stx → Dropdown-hb8ks69x.stx} +16 -4
- package/dist/{EmailInput-ffzwvp9r.stx → EmailInput-57626391.stx} +3 -0
- package/dist/{Listbox-32gzxace.stx → Listbox-83j2q4x6.stx} +16 -4
- package/dist/{NumberInput-r2wsh8w9.stx → NumberInput-pq4k2k4k.stx} +31 -10
- package/dist/{PasswordInput-36bws0kf.stx → PasswordInput-dg41ktgd.stx} +8 -1
- package/dist/{Popover-9m42pym0.stx → Popover-khtvagcs.stx} +16 -4
- package/dist/{Select-pv44ngbe.stx → Select-61zv5tr7.stx} +98 -17
- package/dist/Tab-46mxm7f8.stx +35 -0
- package/dist/TabList-76bpx5fp.stx +154 -0
- package/dist/Table-0a4y46vd.stx +43 -0
- package/dist/TableCell-jhvsxw8b.stx +17 -0
- package/dist/TableHeader-krzcx4sv.stx +62 -0
- package/dist/{Tabs-3j2h0jjn.stx → Tabs-1swcxmfb.stx} +4 -1
- package/dist/{TextInput-h9trj9f9.stx → TextInput-nknmz9md.stx} +57 -4
- package/dist/{Textarea-k8cjs4zs.stx → Textarea-9xmhjqp8.stx} +30 -7
- package/dist/{Tooltip-z13bn0pv.stx → Tooltip-rg1c2zrc.stx} +13 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -7
- package/dist/ui/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/ui/tabs/index.d.ts +35 -3
- package/dist/utils/overlays.d.ts +39 -0
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/ui/chat/ChatLauncher.stx +10 -2
- package/src/ui/combobox/Combobox.stx +16 -4
- package/src/ui/command-palette/CommandPalette.stx +33 -8
- package/src/ui/date-range-picker/DateRangePicker.stx +13 -9
- package/src/ui/dialog/Dialog.stx +29 -169
- package/src/ui/dialog/README.md +5 -0
- package/src/ui/drawer/Drawer.stx +24 -128
- package/src/ui/drawer/README.md +4 -0
- package/src/ui/dropdown/Dropdown.stx +16 -4
- package/src/ui/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/listbox/Listbox.stx +16 -4
- package/src/ui/popover/Popover.stx +16 -4
- 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/tabs/Tab.stx +35 -0
- package/src/ui/tabs/TabList.stx +154 -0
- package/src/ui/tabs/Tabs.stx +4 -1
- package/src/ui/tabs/index.ts +37 -3
- package/src/ui/textarea/Textarea.stx +30 -7
- package/src/ui/tooltip/Tooltip.stx +13 -3
- package/src/utils/overlays.ts +69 -0
- package/dist/Dialog-e9a4r6d0.stx +0 -302
- package/dist/Table-3ek3w95h.stx +0 -14
- package/dist/TableCell-8swtcq8s.stx +0 -10
- package/dist/TableHeader-qsc3e208.stx +0 -20
package/src/ui/drawer/Drawer.stx
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
export const open = $bool($props.open)
|
|
3
3
|
export const position = $props.position || 'right'
|
|
4
4
|
export const title = $props.title || ''
|
|
5
|
+
/** Set `closeOnEscape="false"` for a drawer that must be answered, not dismissed. */
|
|
6
|
+
export const closeOnEscape = $bool($props.closeOnEscape, true)
|
|
7
|
+
/** The same, for a click on the backdrop. */
|
|
8
|
+
export const closeOnBackdrop = $bool($props.closeOnBackdrop, true)
|
|
5
9
|
export const className = $props.className || ''
|
|
6
10
|
|
|
7
11
|
/*
|
|
@@ -122,153 +126,45 @@ const drawerInstanceId = {{ drawerInstanceId }}
|
|
|
122
126
|
// See stacksjs/stx#1704.
|
|
123
127
|
const isOpen = useReactiveProp('open', {{ open }})
|
|
124
128
|
|
|
129
|
+
const closeOnEscape = {{ closeOnEscape }}
|
|
130
|
+
const closeOnBackdrop = {{ closeOnBackdrop }}
|
|
131
|
+
|
|
125
132
|
function close() {
|
|
126
133
|
isOpen.set(false)
|
|
127
134
|
emit('close')
|
|
128
135
|
}
|
|
129
136
|
|
|
130
137
|
function onBackdropClick() {
|
|
131
|
-
close()
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function onPanelKey(event) {
|
|
135
|
-
if (event.key === 'Escape') close()
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/*
|
|
139
|
-
* Escape closes it from anywhere, not just from inside the panel.
|
|
140
|
-
*
|
|
141
|
-
* The keydown handler on the panel only fires when focus is already in it, and
|
|
142
|
-
* opening a drawer does not move focus - so the very first Escape, pressed
|
|
143
|
-
* while focus is still on whatever opened it, did nothing. Bound on the
|
|
144
|
-
* document instead, and only while open.
|
|
145
|
-
*/
|
|
146
|
-
function onDocumentKey(event) {
|
|
147
|
-
if (event.key === 'Escape' && isOpen()) close()
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/*
|
|
151
|
-
* Hold the page still behind the drawer.
|
|
152
|
-
*
|
|
153
|
-
* Without this the page scrolls under an open drawer, which on a phone means a
|
|
154
|
-
* drag inside the cart scrolls the restaurant behind it and the cart stays
|
|
155
|
-
* put. The scrollbar's width is replaced as padding so the page does not jump
|
|
156
|
-
* sideways when it disappears.
|
|
157
|
-
*/
|
|
158
|
-
let restoreScroll = null
|
|
159
|
-
|
|
160
|
-
function lockScroll() {
|
|
161
|
-
if (restoreScroll) return
|
|
162
|
-
|
|
163
|
-
const gap = window.innerWidth - document.documentElement.clientWidth
|
|
164
|
-
const previous = { overflow: document.body.style.overflow, paddingRight: document.body.style.paddingRight }
|
|
165
|
-
|
|
166
|
-
document.body.style.overflow = 'hidden'
|
|
167
|
-
if (gap > 0) document.body.style.paddingRight = `${gap}px`
|
|
168
|
-
|
|
169
|
-
restoreScroll = () => {
|
|
170
|
-
document.body.style.overflow = previous.overflow
|
|
171
|
-
document.body.style.paddingRight = previous.paddingRight
|
|
172
|
-
restoreScroll = null
|
|
173
|
-
}
|
|
138
|
+
if (closeOnBackdrop && window.stx.overlays.isTop(drawerInstanceId)) close()
|
|
174
139
|
}
|
|
175
140
|
|
|
176
|
-
function
|
|
177
|
-
|
|
141
|
+
function panelEl() {
|
|
142
|
+
return document.querySelector(`[data-stx-drawer-panel="${drawerInstanceId}"]`)
|
|
178
143
|
}
|
|
179
144
|
|
|
180
145
|
/*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
146
|
+
* Open means on the page's overlay stack (window.stx.overlays), shared with
|
|
147
|
+
* Dialog, stxConfirm and the app's own overlays: the page held still from the
|
|
148
|
+
* first overlay to the last, focus moved in and back out, Escape for the
|
|
149
|
+
* topmost only, and Tab trapped in the panel - which this drawer did not do at
|
|
150
|
+
* all before, so Tab walked out of an aria-modal panel into the page behind
|
|
151
|
+
* it. It also bound its own Escape, so one Escape closed a drawer and the
|
|
152
|
+
* dialog over it together (stacksjs/stx#2057).
|
|
187
153
|
*/
|
|
188
|
-
let opener = null
|
|
189
|
-
|
|
190
|
-
/*
|
|
191
|
-
* Retried across frames, because focus is refused before the panel is shown.
|
|
192
|
-
*
|
|
193
|
-
* `:show` toggles the drawer's display, and that has not happened yet on the
|
|
194
|
-
* frame the effect runs: `focus()` on a `display: none` element is a silent
|
|
195
|
-
* no-op, so a single attempt left focus on the body every time. Nothing
|
|
196
|
-
* throws, and the drawer looks right - it is only unreachable by keyboard.
|
|
197
|
-
*
|
|
198
|
-
* So the attempt repeats until `document.activeElement` proves it landed,
|
|
199
|
-
* rather than assuming any one frame is late enough. Bounded, so a panel with
|
|
200
|
-
* nothing focusable in it cannot spin; the panel itself carries `tabindex=-1`
|
|
201
|
-
* and takes focus in that case. It also stops if the drawer closed in the
|
|
202
|
-
* meantime, so a drawer opened and shut inside those few frames does not
|
|
203
|
-
* pull focus back afterwards.
|
|
204
|
-
*/
|
|
205
|
-
/*
|
|
206
|
-
* The next chance to try, whichever comes first.
|
|
207
|
-
*
|
|
208
|
-
* `requestAnimationFrame` is the right signal when the page is painting, and
|
|
209
|
-
* it is suspended entirely when the page is not - a background tab, or a
|
|
210
|
-
* window the compositor has parked. A drawer opened in that state would never
|
|
211
|
-
* take focus, and would still not have it when the reader came back, because
|
|
212
|
-
* the one scheduled callback fires long after everything else has moved on.
|
|
213
|
-
* So a timer races the frame and the first to arrive wins.
|
|
214
|
-
*/
|
|
215
|
-
function soon(callback) {
|
|
216
|
-
let done = false
|
|
217
|
-
|
|
218
|
-
const once = () => {
|
|
219
|
-
if (done) return
|
|
220
|
-
done = true
|
|
221
|
-
callback()
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
requestAnimationFrame(once)
|
|
225
|
-
setTimeout(once, 32)
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function focusFirst(attempts) {
|
|
229
|
-
if (!isOpen()) return
|
|
230
|
-
|
|
231
|
-
const panel = document.querySelector(`[data-stx-drawer-panel="${drawerInstanceId}"]`)
|
|
232
|
-
if (!panel) return
|
|
233
|
-
|
|
234
|
-
const target = panel.querySelector('[autofocus]') || panel.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') || panel
|
|
235
|
-
|
|
236
|
-
target.focus?.()
|
|
237
|
-
|
|
238
|
-
if (document.activeElement === target) return
|
|
239
|
-
if (attempts > 0) soon(() => focusFirst(attempts - 1))
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function captureFocus() {
|
|
243
|
-
opener = document.activeElement
|
|
244
|
-
|
|
245
|
-
soon(() => focusFirst(10))
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function releaseFocus() {
|
|
249
|
-
const target = opener
|
|
250
|
-
opener = null
|
|
251
|
-
if (target && typeof target.focus === 'function') target.focus()
|
|
252
|
-
}
|
|
253
|
-
|
|
254
154
|
effect(() => {
|
|
255
155
|
if (isOpen()) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
156
|
+
window.stx.overlays.open(drawerInstanceId, {
|
|
157
|
+
panel: panelEl,
|
|
158
|
+
onEscape: closeOnEscape ? close : null,
|
|
159
|
+
})
|
|
259
160
|
}
|
|
260
161
|
else {
|
|
261
|
-
|
|
262
|
-
releaseFocus()
|
|
263
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
162
|
+
window.stx.overlays.close(drawerInstanceId)
|
|
264
163
|
}
|
|
265
164
|
})
|
|
266
165
|
|
|
267
166
|
onDestroy(() => {
|
|
268
|
-
|
|
269
|
-
// drawer left to unlock it.
|
|
270
|
-
unlockScroll()
|
|
271
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
167
|
+
window.stx.overlays.close(drawerInstanceId)
|
|
272
168
|
})
|
|
273
169
|
|
|
274
170
|
defineExpose({
|
|
@@ -286,7 +182,7 @@ defineExpose({
|
|
|
286
182
|
@click="onBackdropClick()"
|
|
287
183
|
></div>
|
|
288
184
|
|
|
289
|
-
<div class="fixed inset-0 z-50 overflow-hidden"
|
|
185
|
+
<div class="fixed inset-0 z-50 overflow-hidden">
|
|
290
186
|
<div class="absolute inset-0 overflow-hidden">
|
|
291
187
|
<div class="{{ containerClasses }}">
|
|
292
188
|
<div
|
package/src/ui/drawer/README.md
CHANGED
|
@@ -43,6 +43,10 @@ let drawerOpen = false
|
|
|
43
43
|
| `position` | `'right' \| 'left' \| 'top' \| 'bottom'` | `'right'` | Position of the drawer |
|
|
44
44
|
| `title` | `string` | `''` | Optional title for the drawer |
|
|
45
45
|
| `className` | `string` | `''` | Additional CSS classes |
|
|
46
|
+
| `closeOnEscape` | `boolean` | `true` | `false` for a drawer that must be answered rather than dismissed |
|
|
47
|
+
| `closeOnBackdrop` | `boolean` | `true` | `false` to keep it open on a backdrop click |
|
|
48
|
+
|
|
49
|
+
An open drawer is a modal layer on the page's overlay stack (`window.stx.overlays`): the page held still, focus moved in and back, Tab trapped in the panel, and Escape for whichever overlay is on top. See the Dialog README.
|
|
46
50
|
|
|
47
51
|
## Positions
|
|
48
52
|
|
|
@@ -72,8 +72,8 @@ function onClose(event) { event.stopPropagation(); close() }
|
|
|
72
72
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
73
73
|
* otherwise this would steal it from wherever the user actually is.
|
|
74
74
|
*/
|
|
75
|
-
function
|
|
76
|
-
if (
|
|
75
|
+
function onEscape() {
|
|
76
|
+
if (!isOpen()) return
|
|
77
77
|
close()
|
|
78
78
|
if (!rootEl) return
|
|
79
79
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -166,13 +166,25 @@ onMount(() => {
|
|
|
166
166
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
167
167
|
}
|
|
168
168
|
document.addEventListener('click', outsideHandler, true)
|
|
169
|
-
document.addEventListener('keydown', onDocumentKey)
|
|
170
169
|
document.addEventListener('keydown', onMenuKey)
|
|
171
170
|
})
|
|
172
171
|
|
|
172
|
+
/*
|
|
173
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
174
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
175
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
176
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
177
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
178
|
+
* trap Tab or move focus.
|
|
179
|
+
*/
|
|
180
|
+
effect(() => {
|
|
181
|
+
if (isOpen()) window.stx.overlays.open(dropdownInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
182
|
+
else window.stx.overlays.close(dropdownInstanceId)
|
|
183
|
+
})
|
|
184
|
+
|
|
173
185
|
onDestroy(() => {
|
|
186
|
+
window.stx.overlays.close(dropdownInstanceId)
|
|
174
187
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
175
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
176
188
|
document.removeEventListener('keydown', onMenuKey)
|
|
177
189
|
})
|
|
178
190
|
|
|
@@ -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'
|
|
@@ -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' }}"
|
package/src/ui/input/index.ts
CHANGED
|
@@ -22,12 +22,32 @@ export interface BaseInputProps {
|
|
|
22
22
|
inputClassName?: string
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
/** The text-like input types `TextInput` renders; anything else is served as `text`. */
|
|
26
|
+
export type TextInputType = 'text' | 'date' | 'time' | 'datetime-local' | 'month' | 'week' | 'url' | 'tel' | 'color' | 'search' | 'email' | 'number' | 'password'
|
|
27
|
+
|
|
25
28
|
export interface TextInputProps extends BaseInputProps {
|
|
29
|
+
type?: TextInputType
|
|
26
30
|
leftIcon?: string
|
|
27
31
|
rightIcon?: string
|
|
28
32
|
clearable?: boolean
|
|
29
33
|
maxLength?: number
|
|
34
|
+
maxlength?: number
|
|
35
|
+
minLength?: number
|
|
36
|
+
minlength?: number
|
|
30
37
|
showCount?: boolean
|
|
38
|
+
/** date, time, datetime-local, month, week and number only. */
|
|
39
|
+
min?: string | number
|
|
40
|
+
/** date, time, datetime-local, month, week and number only. */
|
|
41
|
+
max?: string | number
|
|
42
|
+
/** date, time, datetime-local, month, week and number only; `'any'` allowed. */
|
|
43
|
+
step?: string | number
|
|
44
|
+
/** text, search, url, tel, email and password only. */
|
|
45
|
+
pattern?: string
|
|
46
|
+
/** The id of a `<datalist>`; every type but password. */
|
|
47
|
+
list?: string
|
|
48
|
+
/** The HTML `size` attribute (width in characters); `size` is sm / md / lg. */
|
|
49
|
+
htmlSize?: number
|
|
50
|
+
autofocus?: boolean
|
|
31
51
|
}
|
|
32
52
|
|
|
33
53
|
export interface EmailInputProps extends Omit<BaseInputProps, 'placeholder'> {
|
|
@@ -91,6 +111,12 @@ export const textInputPropSchema: PropSchema = {
|
|
|
91
111
|
clearable: PropTypes.boolean,
|
|
92
112
|
maxLength: PropTypes.number,
|
|
93
113
|
showCount: PropTypes.boolean,
|
|
114
|
+
type: PropTypes.oneOf(['text', 'date', 'time', 'datetime-local', 'month', 'week', 'url', 'tel', 'color', 'search', 'email', 'number', 'password']),
|
|
115
|
+
pattern: PropTypes.string,
|
|
116
|
+
list: PropTypes.string,
|
|
117
|
+
minLength: PropTypes.number,
|
|
118
|
+
htmlSize: PropTypes.number,
|
|
119
|
+
autofocus: PropTypes.boolean,
|
|
94
120
|
}
|
|
95
121
|
|
|
96
122
|
/**
|
|
@@ -157,24 +183,24 @@ const searchInputPropSchema: PropSchema = {
|
|
|
157
183
|
/**
|
|
158
184
|
* Validate TextInput component props
|
|
159
185
|
*/
|
|
160
|
-
export const validateTextInputProps: (props: Record<string,
|
|
186
|
+
export const validateTextInputProps: (props: Record<string, unknown>) => ValidationResult = createPropValidator('TextInput', textInputPropSchema)
|
|
161
187
|
|
|
162
188
|
/**
|
|
163
189
|
* Validate EmailInput component props
|
|
164
190
|
*/
|
|
165
|
-
export const validateEmailInputProps: (props: Record<string,
|
|
191
|
+
export const validateEmailInputProps: (props: Record<string, unknown>) => ValidationResult = createPropValidator('EmailInput', baseInputPropSchema)
|
|
166
192
|
|
|
167
193
|
/**
|
|
168
194
|
* Validate PasswordInput component props
|
|
169
195
|
*/
|
|
170
|
-
export const validatePasswordInputProps: (props: Record<string,
|
|
196
|
+
export const validatePasswordInputProps: (props: Record<string, unknown>) => ValidationResult = createPropValidator('PasswordInput', passwordInputPropSchema)
|
|
171
197
|
|
|
172
198
|
/**
|
|
173
199
|
* Validate NumberInput component props
|
|
174
200
|
*/
|
|
175
|
-
export const validateNumberInputProps: (props: Record<string,
|
|
201
|
+
export const validateNumberInputProps: (props: Record<string, unknown>) => ValidationResult = createPropValidator('NumberInput', numberInputPropSchema)
|
|
176
202
|
|
|
177
203
|
/**
|
|
178
204
|
* Validate SearchInput component props
|
|
179
205
|
*/
|
|
180
|
-
export const validateSearchInputProps: (props: Record<string,
|
|
206
|
+
export const validateSearchInputProps: (props: Record<string, unknown>) => ValidationResult = createPropValidator('SearchInput', searchInputPropSchema)
|
|
@@ -107,8 +107,8 @@ function onSelect(event) {
|
|
|
107
107
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
108
108
|
* otherwise this would steal it from wherever the user actually is.
|
|
109
109
|
*/
|
|
110
|
-
function
|
|
111
|
-
if (
|
|
110
|
+
function onEscape() {
|
|
111
|
+
if (!isOpen()) return
|
|
112
112
|
close()
|
|
113
113
|
if (!rootEl) return
|
|
114
114
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -239,13 +239,25 @@ onMount(() => {
|
|
|
239
239
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
240
240
|
}
|
|
241
241
|
document.addEventListener('click', outsideHandler, true)
|
|
242
|
-
document.addEventListener('keydown', onDocumentKey)
|
|
243
242
|
document.addEventListener('keydown', onListboxKey)
|
|
244
243
|
})
|
|
245
244
|
|
|
245
|
+
/*
|
|
246
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
247
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
248
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
249
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
250
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
251
|
+
* trap Tab or move focus.
|
|
252
|
+
*/
|
|
253
|
+
effect(() => {
|
|
254
|
+
if (isOpen()) window.stx.overlays.open(listboxInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
255
|
+
else window.stx.overlays.close(listboxInstanceId)
|
|
256
|
+
})
|
|
257
|
+
|
|
246
258
|
onDestroy(() => {
|
|
259
|
+
window.stx.overlays.close(listboxInstanceId)
|
|
247
260
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
248
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
249
261
|
document.removeEventListener('keydown', onListboxKey)
|
|
250
262
|
})
|
|
251
263
|
|
|
@@ -50,8 +50,8 @@ function onOpen(event) { event.stopPropagation(); open() }
|
|
|
50
50
|
* Focus goes back to the trigger, but only if it had moved into the panel:
|
|
51
51
|
* otherwise this would steal it from wherever the user actually is.
|
|
52
52
|
*/
|
|
53
|
-
function
|
|
54
|
-
if (
|
|
53
|
+
function onEscape() {
|
|
54
|
+
if (!isOpen()) return
|
|
55
55
|
close()
|
|
56
56
|
if (!rootEl) return
|
|
57
57
|
const active = rootEl.ownerDocument && rootEl.ownerDocument.activeElement
|
|
@@ -68,12 +68,24 @@ onMount(() => {
|
|
|
68
68
|
if (rootEl && !rootEl.contains(event.target)) close()
|
|
69
69
|
}
|
|
70
70
|
document.addEventListener('click', outsideHandler, true)
|
|
71
|
-
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
/*
|
|
74
|
+
* Open means a layer on the page's overlay stack (window.stx.overlays), as a
|
|
75
|
+
* popup: while it is on top it takes Escape, so inside a dialog one Escape
|
|
76
|
+
* closes this and leaves the dialog open. It used to listen for Escape on the
|
|
77
|
+
* document itself, and whichever of its listener and the dialog's had been
|
|
78
|
+
* added first won (stacksjs/stx#2057). Not modal: it does not lock the page,
|
|
79
|
+
* trap Tab or move focus.
|
|
80
|
+
*/
|
|
81
|
+
effect(() => {
|
|
82
|
+
if (isOpen()) window.stx.overlays.open(popoverInstanceId, { modal: false, panel: () => rootEl, onEscape })
|
|
83
|
+
else window.stx.overlays.close(popoverInstanceId)
|
|
72
84
|
})
|
|
73
85
|
|
|
74
86
|
onDestroy(() => {
|
|
87
|
+
window.stx.overlays.close(popoverInstanceId)
|
|
75
88
|
if (outsideHandler) document.removeEventListener('click', outsideHandler, true)
|
|
76
|
-
document.removeEventListener('keydown', onDocumentKey)
|
|
77
89
|
})
|
|
78
90
|
|
|
79
91
|
const dataState = derived(() => isOpen() ? 'open' : 'closed')
|