@stacksjs/components 0.2.656 → 0.2.662

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/{Button-55ahz0j6.stx → Button-j7gjvpxz.stx} +53 -0
  2. package/dist/{Checkbox-m90hgax3.stx → Checkbox-0grmgne5.stx} +20 -3
  3. package/dist/{Dialog-gec1h2y7.stx → Dialog-bb8d6zav.stx} +8 -0
  4. package/dist/{DialogDescription-gth4c2kx.stx → DialogDescription-yd2jgt2m.stx} +2 -1
  5. package/dist/{DialogPanel-dj0qjfdq.stx → DialogPanel-efae92wv.stx} +24 -0
  6. package/dist/{DialogTitle-ke58hh68.stx → DialogTitle-nw0pw114.stx} +2 -1
  7. package/dist/{Drawer-4rqfcg4f.stx → Drawer-fzvxe2c3.stx} +31 -0
  8. package/dist/{EmailInput-57626391.stx → EmailInput-sf9jfrgz.stx} +11 -2
  9. package/dist/{GroupedList-mx0b5fe7.stx → GroupedList-j3sxv5pb.stx} +13 -3
  10. package/dist/{GroupedListRow-nz8b6vx4.stx → GroupedListRow-v52zmzpk.stx} +42 -15
  11. package/dist/{Image-71fhf8fg.stx → Image-nwxax17j.stx} +8 -1
  12. package/dist/{ListRow-8d3e1yxh.stx → ListRow-nvyg2fwb.stx} +32 -8
  13. package/dist/{PasswordInput-dg41ktgd.stx → PasswordInput-r51qzgc0.stx} +64 -0
  14. package/dist/{SectionCard-8ctdacjr.stx → SectionCard-8b5fyrjd.stx} +16 -4
  15. package/dist/{SegmentedControl-yvkjtc7y.stx → SegmentedControl-z9gk2fpn.stx} +23 -5
  16. package/dist/{Select-61zv5tr7.stx → Select-1cnqbcmg.stx} +39 -0
  17. package/dist/{Switch-rbxpzn5g.stx → Switch-nay7zdee.stx} +46 -0
  18. package/dist/{Tab-46mxm7f8.stx → Tab-j9f4t166.stx} +5 -1
  19. package/dist/{TabList-5xwk2zmz.stx → TabList-r1pc87xs.stx} +8 -1
  20. package/dist/{Tabs-bp03efe6.stx → Tabs-psm5wj7c.stx} +16 -1
  21. package/dist/{TextInput-9bm9gy8j.stx → TextInput-vy4qpncz.stx} +138 -6
  22. package/dist/index.js +10 -10
  23. package/dist/ui/button/Button.d.ts +61 -0
  24. package/dist/ui/checkbox/Checkbox.d.ts +8 -1
  25. package/dist/ui/checkbox/index.d.ts +1 -0
  26. package/dist/ui/dialog/Dialog.d.ts +7 -1
  27. package/dist/ui/dialog/DialogPanel.d.ts +10 -0
  28. package/dist/ui/grouped-list/GroupedList.d.ts +8 -1
  29. package/dist/ui/grouped-list/GroupedListRow.d.ts +10 -2
  30. package/dist/ui/image/Image.d.ts +3 -1
  31. package/dist/ui/input/EmailInput.d.ts +8 -0
  32. package/dist/ui/input/PasswordInput.d.ts +10 -0
  33. package/dist/ui/input/TextInput.d.ts +12 -1
  34. package/dist/ui/mobile/ListRow.d.ts +13 -0
  35. package/dist/ui/mobile/SectionCard.d.ts +10 -0
  36. package/dist/ui/segmented-control/SegmentedControl.d.ts +10 -2
  37. package/dist/ui/tabs/Tab.d.ts +1 -1
  38. package/dist/ui/tabs/TabList.d.ts +6 -1
  39. package/dist/ui/tabs/Tabs.d.ts +8 -0
  40. package/package.json +3 -3
  41. package/src/ui/button/Button.stx +53 -0
  42. package/src/ui/checkbox/Checkbox.stx +20 -3
  43. package/src/ui/checkbox/index.ts +2 -0
  44. package/src/ui/dialog/Dialog.stx +8 -0
  45. package/src/ui/dialog/DialogDescription.stx +2 -1
  46. package/src/ui/dialog/DialogPanel.stx +24 -0
  47. package/src/ui/dialog/DialogTitle.stx +2 -1
  48. package/src/ui/drawer/Drawer.stx +31 -0
  49. package/src/ui/grouped-list/GroupedList.stx +13 -3
  50. package/src/ui/grouped-list/GroupedListRow.stx +42 -15
  51. package/src/ui/image/Image.stx +8 -1
  52. package/src/ui/input/EmailInput.stx +11 -2
  53. package/src/ui/input/PasswordInput.stx +64 -0
  54. package/src/ui/input/TextInput.stx +138 -6
  55. package/src/ui/mobile/ListRow.stx +32 -8
  56. package/src/ui/mobile/SectionCard.stx +16 -4
  57. package/src/ui/segmented-control/SegmentedControl.stx +23 -5
  58. package/src/ui/select/Select.stx +39 -0
  59. package/src/ui/switch/Switch.stx +46 -0
  60. package/src/ui/tabs/Tab.stx +5 -1
  61. package/src/ui/tabs/TabList.stx +8 -1
  62. package/src/ui/tabs/Tabs.stx +16 -1
@@ -52,9 +52,23 @@ export const sizing = sizeClasses[size]
52
52
 
53
53
  // A block flex box already fills its column, so `stretch` needs no `w-full` -
54
54
  // which beside a margin (`mx-4`) ran the track off the screen's edge.
55
- export const trackClasses = `${stretch ? 'flex' : 'inline-flex'} flex-row gap-0.5 p-0.5 rounded-control bg-surface-sunken ${className}`.replace(/\s+/g, ' ').trim()
56
55
  const segmentSizing = stretch ? sizing.segment.replace(/\bpx-\S+/, stretchedPadding[size]) : sizing.segment
57
- export const segmentBase = `${stretch ? 'flex-1 min-w-0' : ''} items-center justify-center rounded-control transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${segmentSizing}`.replace(/\s+/g, ' ').trim()
56
+ /*
57
+ * On a native host ($native) the track and segments are UISegmentedControl's
58
+ * own: a translucent grey track with 9pt corners, the chosen segment raised
59
+ * white (#636366 in dark) with 7pt corners, every label in the label colour
60
+ * and the chosen one semibold.
61
+ */
62
+ export const trackClasses = $native
63
+ ? `${stretch ? 'flex' : 'self-start'} flex-row gap-0.5 p-0.5 rounded-[9px] bg-[#767680]/12 dark:bg-[#767680]/24 ${className}`.replace(/\s+/g, ' ').trim()
64
+ : `${stretch ? 'flex' : 'inline-flex'} flex-row gap-0.5 p-0.5 rounded-control bg-surface-sunken ${className}`.replace(/\s+/g, ' ').trim()
65
+ export const segmentBase = $native
66
+ ? `${stretch ? 'flex-1 min-w-0' : ''} items-center justify-center rounded-[7px] ${segmentSizing}`.replace(/\s+/g, ' ').trim()
67
+ : `${stretch ? 'flex-1 min-w-0' : ''} items-center justify-center rounded-control transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-accent ${segmentSizing}`.replace(/\s+/g, ' ').trim()
68
+ export const segmentOn = $native ? 'bg-[#ffffff] dark:bg-[#636366] shadow-sm' : 'bg-panel dark:bg-neutral-600 shadow-sm'
69
+ export const segmentOff = $native ? 'opacity-50' : 'opacity-50 cursor-not-allowed'
70
+ export const labelOn = $native ? 'font-semibold text-[#000000] dark:text-[#ffffff]' : 'font-semibold text-fg'
71
+ export const labelOff = $native ? 'font-medium text-[#000000] dark:text-[#ffffff]' : 'font-medium text-fg-muted'
58
72
  </script>
59
73
 
60
74
  <script client>
@@ -67,6 +81,10 @@ const isDisabled = useReactiveProp('disabled', {{ disabled }})
67
81
  const segmentBase = {{ segmentBase }}
68
82
  const textSize = {{ sizing.text }}
69
83
  const groupID = {{ testID }}
84
+ const segmentOn = {{ segmentOn }}
85
+ const segmentOff = {{ segmentOff }}
86
+ const labelOn = {{ labelOn }}
87
+ const labelOff = {{ labelOff }}
70
88
 
71
89
  /** A choice as `{ value, label, disabled }`, whichever way it was written. */
72
90
  function normalise(choice) {
@@ -102,12 +120,12 @@ function choose(segment) {
102
120
  }
103
121
 
104
122
  function segmentClasses(segment) {
105
- const state = isOn(segment) ? 'bg-panel dark:bg-neutral-600 shadow-sm' : 'bg-transparent'
106
- return `${segmentBase} ${state} ${isOff(segment) ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`
123
+ const state = isOn(segment) ? segmentOn : 'bg-transparent'
124
+ return `${segmentBase} ${state} ${isOff(segment) ? segmentOff : 'cursor-pointer'}`
107
125
  }
108
126
 
109
127
  function labelClasses(segment) {
110
- return `${textSize} ${isOn(segment) ? 'font-semibold text-fg' : 'font-medium text-fg-muted'}`
128
+ return `${textSize} ${isOn(segment) ? labelOn : labelOff}`
111
129
  }
112
130
 
113
131
  function segmentID(segment) {
@@ -146,6 +146,19 @@ function normaliseOptions(list) {
146
146
  const optionSource = useReactiveProp('options', {{ options }}, { parse: v => normaliseOptions(v) })
147
147
  const optionList = derived(() => normaliseOptions(optionSource()))
148
148
 
149
+ /*
150
+ * The choices as a native picker takes them (`items`), for a native host.
151
+ * Disabled choices are left out, since neither platform picker can show one
152
+ * it will not let you pick; the placeholder leads the list only while
153
+ * nothing in it is chosen, as the web's disabled first option does.
154
+ */
155
+ const placeholderText = {{ placeholder }}
156
+ const nativeItems = derived(() => {
157
+ const list = optionList().filter(option => !option.disabled).map(option => ({ value: option.value, label: option.label }))
158
+ const chosen = list.some(option => option.value === selectedValue())
159
+ return placeholderText && !chosen ? [{ value: '', label: placeholderText }, ...list] : list
160
+ })
161
+
149
162
  function onChange(event) {
150
163
  selectedValue.set(event.target.value)
151
164
  emit('change', selectedValue())
@@ -154,6 +167,31 @@ function onChange(event) {
154
167
  defineExpose({ value: selectedValue, options: optionList })
155
168
  </script>
156
169
 
170
+ @if($native)
171
+ {{-- On a native host the control is the platform's picker (UIPickerView,
172
+ Android's Spinner) fed with its items. Children are not something either
173
+ picker holds, so slotted <option>s are a web-only spelling. --}}
174
+ <div class="w-full {{ className }}">
175
+ @if(label)
176
+ <label for="{{ selectId }}" class="mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]">{{ label }}</label>
177
+ @endif
178
+ <div
179
+ data-native="Picker"
180
+ data-stx-native-host-root
181
+ id="{{ selectId }}"
182
+ :items="nativeItems()"
183
+ :value="selectedValue()"
184
+ @if(disabled)disabled@endif
185
+ class="w-full disabled:opacity-50"
186
+ @change="onChange($event)"
187
+ aria-invalid="{{ error ? 'true' : 'false' }}"
188
+ :aria-invalid="isError() ? 'true' : 'false'"
189
+ ></div>
190
+ @if(helperText)
191
+ <p id="{{ helperId }}" class="mt-1.5 px-4 text-[13px] {{ error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#6d6d72] dark:text-[#8d8d93]' }}">{{ helperText }}</p>
192
+ @endif
193
+ </div>
194
+ @else
157
195
  <div class="w-full">
158
196
  @if(label)
159
197
  <label for="{{ selectId }}" class="{{ labelClasses }}">
@@ -224,3 +262,4 @@ defineExpose({ value: selectedValue, options: optionList })
224
262
  </p>
225
263
  @endif
226
264
  </div>
265
+ @endif
@@ -63,6 +63,18 @@ function trackClasses() {
63
63
  return `${trackBase} ${stateClass} ${isDisabled() ? trackDisabled : ''} ${config.track} ${extraClass}`.trim()
64
64
  }
65
65
 
66
+ // The platform's switch reports its new value itself (a native host's
67
+ // value change); the web's button only says it was pressed.
68
+ function onNativeChange(event) {
69
+ if (isDisabled()) return
70
+ const next = event && typeof event === 'object'
71
+ ? (event.value ?? event.nativeEvent?.value ?? event.target?.value)
72
+ : event
73
+ if (typeof next !== 'boolean' || next === isChecked()) return
74
+ isChecked.set(next)
75
+ emit('change', isChecked())
76
+ }
77
+
66
78
  function thumbClasses() {
67
79
  const pos = isChecked() ? config.translate : 'translate-x-0'
68
80
  return `${thumbBase} ${pos} ${config.thumb}`.trim()
@@ -71,6 +83,39 @@ function thumbClasses() {
71
83
  defineExpose({ isChecked, toggle })
72
84
  </script>
73
85
 
86
+ @if($native)
87
+ {{-- On a native host the control is the platform's own switch (UISwitch,
88
+ Android's Switch), at the end of its row as a settings row puts it. --}}
89
+ <label class="flex-row items-center justify-between gap-3 {{ className }}">
90
+ <span :if="currentLabel()" :text="currentLabel()" class="flex-1 text-[17px] text-[#000000] dark:text-[#ffffff]">{{ label }}</span>
91
+ @if(name)
92
+ <input
93
+ type="hidden"
94
+ name="{{ name }}"
95
+ @if(disabled)disabled@endif
96
+ :disabled="isDisabled()"
97
+ @if(form)form="{{ form }}"@endif
98
+ value="{{ checked ? checkedValue : uncheckedValue }}"
99
+ :value="isChecked() ? '{{ checkedValue }}' : '{{ uncheckedValue }}'"
100
+ />
101
+ @endif
102
+ <div
103
+ data-native="Switch"
104
+ data-stx-native-host-root
105
+ role="switch"
106
+ value="{{ checked ? 'true' : 'false' }}"
107
+ :value="isChecked()"
108
+ aria-label="{{ label || 'Toggle switch' }}"
109
+ :aria-label="currentLabel() || 'Toggle switch'"
110
+ :aria-checked="isChecked() ? 'true' : 'false'"
111
+ @if(disabled)disabled@endif
112
+ :disabled="isDisabled()"
113
+ :aria-disabled="isDisabled() ? 'true' : 'false'"
114
+ class="disabled:opacity-50"
115
+ @change="onNativeChange($event)"
116
+ ></div>
117
+ </label>
118
+ @else
74
119
  <label class="inline-flex items-center gap-3 cursor-pointer">
75
120
  <span :if="currentLabel()" :text="currentLabel()" class="text-sm font-medium text-fg-strong">
76
121
  {{ label }}
@@ -108,3 +153,4 @@ defineExpose({ isChecked, toggle })
108
153
  <span aria-hidden="true" :class="thumbClasses()"></span>
109
154
  </button>
110
155
  </label>
156
+ @endif
@@ -20,7 +20,11 @@ const variantClasses = {
20
20
  pills: `px-3 py-1.5 font-medium text-sm rounded-control text-fg-muted hover:text-fg aria-selected:bg-field aria-selected:text-fg aria-selected:shadow-sm transition-colors ${focusRing}`,
21
21
  none: '',
22
22
  }
23
- export const tabClasses = `${variantClasses[variant] ?? variantClasses.line} ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`.replace(/\s+/g, ' ').trim()
23
+ // On a native host ($native), a segment of the list's segmented control.
24
+ const nativeSegment = 'flex-1 min-h-[30px] px-3 items-center justify-center rounded-[7px] text-[13px] font-medium text-[#000000] dark:text-[#ffffff] aria-selected:font-semibold aria-selected:bg-[#ffffff] dark:aria-selected:bg-[#636366] aria-selected:shadow-sm'
25
+ export const tabClasses = $native && variant !== 'none'
26
+ ? `${nativeSegment} ${disabled ? 'opacity-50' : ''} ${className}`.replace(/\s+/g, ' ').trim()
27
+ : `${variantClasses[variant] ?? variantClasses.line} ${disabled ? 'opacity-50 cursor-not-allowed' : ''} ${className}`.replace(/\s+/g, ' ').trim()
24
28
  </script>
25
29
 
26
30
  <button
@@ -34,7 +34,14 @@ const variantClasses = {
34
34
  none: '',
35
35
  }
36
36
  const directionClasses = orientation === 'vertical' ? 'flex-col' : ''
37
- export const listClasses = `${variantClasses[variant] ?? variantClasses.line} ${directionClasses} ${className}`.replace(/\s+/g, ' ').trim()
37
+ /*
38
+ * On a native host ($native) a horizontal strip is the phone's segmented
39
+ * control, the control iOS uses to switch a screen between views; its tabs
40
+ * draw the raised segment through `aria-selected:` (Tab.stx).
41
+ */
42
+ export const listClasses = $native && orientation === 'horizontal' && variant !== 'none'
43
+ ? `flex-row gap-0.5 p-0.5 rounded-[9px] bg-[#767680]/12 dark:bg-[#767680]/24 ${className}`.replace(/\s+/g, ' ').trim()
44
+ : `${variantClasses[variant] ?? variantClasses.line} ${directionClasses} ${className}`.replace(/\s+/g, ' ').trim()
38
45
  </script>
39
46
 
40
47
  <script client>
@@ -36,7 +36,17 @@ const variantClasses = {
36
36
  }
37
37
 
38
38
  export const containerClasses = `flex ${orientationClasses[orientation] || orientationClasses.horizontal} ${className}`.trim()
39
- export const tabListClasses = `flex ${tabListOrientationClasses[orientation] || tabListOrientationClasses.horizontal} ${variantClasses[variant] || variantClasses.line}`.trim()
39
+ /*
40
+ * On a native host ($native) a horizontal strip is the phone's segmented
41
+ * control: a grey track, the selected tab raised (getTabClasses).
42
+ */
43
+ export const nativeTabs = $native && orientation !== 'vertical'
44
+ // Empty on the web, so its stylesheet never meets them.
45
+ export const nativeTabBase = nativeTabs ? 'flex-1 min-h-[30px] px-3 items-center justify-center rounded-[7px]' : ''
46
+ export const nativeTabOn = nativeTabs ? 'bg-[#ffffff] dark:bg-[#636366] shadow-sm' : ''
47
+ export const tabListClasses = nativeTabs
48
+ ? 'flex-row gap-0.5 p-0.5 rounded-[9px] bg-[#767680]/12 dark:bg-[#767680]/24'
49
+ : `flex ${tabListOrientationClasses[orientation] || tabListOrientationClasses.horizontal} ${variantClasses[variant] || variantClasses.line}`.trim()
40
50
  export const tabPanelClasses = `p-4 focus:outline-none`.trim()
41
51
  // True when the parent passes a non-empty `tabs` array — switches to the
42
52
  // legacy render path, preserving the existing prop-array API.
@@ -50,6 +60,9 @@ const tabs = {{ tabs }}
50
60
  const variant = {{ variant }}
51
61
  const orientation = {{ orientation }}
52
62
  const hasPropTabs = {{ hasPropTabs }}
63
+ const nativeTabs = {{ nativeTabs }}
64
+ const nativeTabBase = {{ nativeTabBase }}
65
+ const nativeTabOn = {{ nativeTabOn }}
53
66
  // useRef takes the NAME the x-ref attribute uses. Called with no
54
67
  // argument it read $refs[undefined], which nothing ever fills, so
55
68
  // containerRef.value was null forever - the mount hook found no panels,
@@ -166,6 +179,8 @@ function isActive(index) {
166
179
 
167
180
  function getTabClasses(index) {
168
181
  const isActiveTab = isActive(index)
182
+ if (nativeTabs)
183
+ return `${nativeTabBase} ${isActiveTab ? nativeTabOn : ''}`
169
184
  const base = 'px-4 py-2 font-medium text-sm transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-panel'
170
185
  if (variant === 'line') {
171
186
  const border = orientation === 'horizontal' ? 'border-b-2' : 'border-r-2'
@@ -143,29 +143,99 @@ export const minLength = freeText && given($props.minLength ?? $props.minlength)
143
143
  export const htmlSize = freeText && given($props.htmlSize) ? String($props.htmlSize) : ''
144
144
  export const list = type !== 'password' && given($props.list) ? String($props.list) : ''
145
145
  export const autofocus = $bool($props.autofocus)
146
+
147
+ /*
148
+ * The field a phone app draws, for a native host ($native): 48pt tall, the
149
+ * 17pt body size, a filled rounded box that reads on a grouped background and
150
+ * a plain one alike, and the system's placeholder grey. The web's rings,
151
+ * shadow and density roles have nothing to draw on a device, and its icon
152
+ * slot is a web flourish iOS fields do without. An invalid field gets the
153
+ * system red outline, a disabled one dims as UIKit's do.
154
+ */
155
+ export const nativeFieldClasses = `h-12 px-4 text-[17px] text-[#000000] dark:text-[#ffffff] bg-[#767680]/12 dark:bg-[#767680]/24 rounded-[10px] border-0 ${inputClassName}`.trim()
156
+ export const nativeLabelClasses = 'mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]'
157
+ export const nativeHelperClasses = `mt-1.5 px-4 text-[13px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#6d6d72] dark:text-[#8d8d93]'}`
146
158
  </script>
147
159
 
148
160
  <script client>
149
- const emit = defineEmits()
161
+ // Reserve value events before the first edit: lazy input must not leak its
162
+ // bubbling DOM/native event object to a caller expecting the committed value.
163
+ const emit = defineEmits(['input', 'clear', 'focus', 'blur', 'submit', 'submit-editing'])
150
164
  // Validity is live, for the same reason `disabled` is: a form posted with
151
165
  // fetch learns it after the submit, and nothing re-renders (#2047).
152
166
  const isError = useReactiveProp('error', {{ error }})
153
167
  // Keep the physical control and its affordances live on both web and native.
154
168
  const isDisabled = useReactiveProp('disabled', {{ disabled }})
169
+ const isReadonly = useReactiveProp('readonly', {{ readonly }})
155
170
  // v-model:value supports modifiers; @input remains available to existing callers.
156
171
  const inputValue = useModel('value', { default: {{ value }}, parse: (v) => v == null ? '' : String(v) })
172
+ let lastNativeCommit = String(inputValue() ?? '')
173
+ let lastInputText = lastNativeCommit
174
+
175
+ function onNativeFocus(event) {
176
+ lastNativeCommit = String(event.text ?? event.target.value ?? '')
177
+ lastInputText = lastNativeCommit
178
+ onFocus(event)
179
+ }
180
+
181
+ // Focus/blur do not bubble from the physical input to the component scope.
182
+ // Forward the original event so browser FocusEvent methods and native payloads survive.
183
+ function onFocus(event) {
184
+ if (!isDisabled() && event.target.isConnected !== false) emit('focus', event)
185
+ }
186
+
187
+ function onBlur(event) {
188
+ if (event.target.isConnected !== false) emit('blur', event)
189
+ }
190
+
191
+ // Native return-key callbacks use submit-editing (with submit as an alias).
192
+ // Do not commit lazy models here: end-editing owns that, and browser form
193
+ // submission remains the form's event rather than a synthetic input event.
194
+ function onNativeSubmit(event) {
195
+ if (isDisabled() || event.target.isConnected === false) return
196
+ emit('submit-editing', event)
197
+ emit('submit', event)
198
+ }
199
+
200
+ function onNativeChange(event) {
201
+ if (isDisabled() || isReadonly()) {
202
+ event.target.value = inputValue()
203
+ return
204
+ }
205
+ lastNativeCommit = String(event.target.value ?? '')
206
+ onChange(event)
207
+ emit('change', { ...event, type: 'change' })
208
+ }
209
+
210
+ // Craft commits text with onEndEditing, not a picker's onValueChange.
211
+ // Keep the shared @change event-shaped and @input value-shaped; the legacy
212
+ // primitive still exposes its original native payload without this adapter.
213
+ function onNativeEndEditing(event) {
214
+ if (isDisabled() || isReadonly()) {
215
+ event.target.value = inputValue()
216
+ return
217
+ }
218
+ const text = String(event.text ?? event.nativeEvent?.text ?? event.target.value ?? '')
219
+ if (text === lastNativeCommit) return
220
+ lastNativeCommit = text
221
+ event.target.value = text
222
+ if (inputValue.modifiers.lazy) onChange(event)
223
+ else if (lastInputText !== text) onInput(event)
224
+ emit('change', { ...event, type: 'change' })
225
+ }
157
226
 
158
227
  function onInput(event) {
159
- if (isDisabled()) {
228
+ if (isDisabled() || isReadonly()) {
160
229
  event.target.value = inputValue()
161
230
  return
162
231
  }
232
+ lastInputText = String(event.target.value ?? '')
163
233
  inputValue.input(event.target.value)
164
234
  if (!inputValue.modifiers.lazy) emit('input', inputValue())
165
235
  }
166
236
 
167
237
  function onChange(event) {
168
- if (isDisabled()) {
238
+ if (isDisabled() || isReadonly()) {
169
239
  event.target.value = inputValue()
170
240
  return
171
241
  }
@@ -174,8 +244,10 @@ function onChange(event) {
174
244
  }
175
245
 
176
246
  function onClear() {
177
- if (isDisabled()) return
247
+ if (isDisabled() || isReadonly()) return
178
248
  inputValue.set('')
249
+ lastNativeCommit = ''
250
+ lastInputText = ''
179
251
  emit('input', '')
180
252
  emit('clear')
181
253
  }
@@ -186,6 +258,62 @@ const charCount = derived(() => `${String(inputValue()).length} / {{ maxLength |
186
258
  defineExpose({ value: inputValue, clear: onClear })
187
259
  </script>
188
260
 
261
+ @if($native)
262
+ <div class="w-full {{ className }}">
263
+ @if(label)
264
+ <label for="{{ inputId }}" class="{{ nativeLabelClasses }}">{{ label }}</label>
265
+ @endif
266
+ <div class="relative justify-center">
267
+ <input
268
+ data-stx-native-host-root
269
+ @if(name)name="{{ name }}"@endif
270
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
271
+ @if(form)form="{{ form }}"@endif
272
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
273
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
274
+ type="{{ type }}"
275
+ @if(autofocus)autofocus@endif
276
+ id="{{ inputId }}"
277
+ class="{{ nativeFieldClasses }}"
278
+ placeholderTextColor="#8e8e93"
279
+ value="{{ value }}"
280
+ :value="inputValue()"
281
+ placeholder="{{ placeholder }}"
282
+ @if(disabled)disabled@endif
283
+ :disabled="isDisabled()"
284
+ @if(readonly)readonly@endif
285
+ :readonly="isReadonly()"
286
+ @if(required)required@endif
287
+ @if(maxLength && freeText)maxlength="{{ maxLength }}"@endif
288
+ @input="onInput($event)"
289
+ @change="onNativeChange($event)"
290
+ @focus="onNativeFocus($event)"
291
+ @blur="onBlur($event)"
292
+ @submit-editing="onNativeSubmit($event)"
293
+ @end-editing="onNativeEndEditing($event)"
294
+ aria-invalid="{{ error ? 'true' : 'false' }}"
295
+ :aria-invalid="isError() ? 'true' : 'false'"
296
+ :class="{ 'border border-[#ff3b30] dark:border-[#ff453a]': isError(), 'opacity-50': isDisabled() }"
297
+ @if(clearable)style="padding-right: 40px"@endif
298
+ />
299
+ @if(clearable)
300
+ <button
301
+ type="button"
302
+ :show="hasValue() && !isDisabled() && !isReadonly()"
303
+ @click="onClear()"
304
+ class="absolute top-0 right-0 h-12 w-10 items-center justify-center"
305
+ aria-label="Clear input"
306
+ ><i class="i-lucide-circle-x h-[17px] w-[17px] text-[#c4c4c7] dark:text-[#5b5b5f]"></i></button>
307
+ @endif
308
+ </div>
309
+ @if(helperText)
310
+ <p id="{{ helperId }}" class="{{ nativeHelperClasses }}">{{ helperText }}</p>
311
+ @endif
312
+ @if(showCount && maxLength)
313
+ <p class="mt-1.5 px-4 text-right text-[13px] text-[#6d6d72] dark:text-[#8d8d93]" :text="charCount()"></p>
314
+ @endif
315
+ </div>
316
+ @else
189
317
  <div class="w-full {{ className }}">
190
318
  @if(label)
191
319
  <label for="{{ inputId }}" class="{{ labelClasses }}">
@@ -238,18 +366,21 @@ defineExpose({ value: inputValue, clear: onClear })
238
366
  @if(disabled)disabled@endif
239
367
  :disabled="isDisabled()"
240
368
  @if(readonly)readonly@endif
369
+ :readonly="isReadonly()"
241
370
  @if(required)required@endif
242
371
  @if(maxLength && freeText)maxlength="{{ maxLength }}"@endif
243
372
  @input="onInput($event)"
244
373
  @change="onChange($event)"
374
+ @focus="onFocus($event)"
375
+ @blur="onBlur($event)"
245
376
  aria-invalid="{{ error ? 'true' : 'false' }}"
246
377
  :aria-invalid="isError() ? 'true' : 'false'"
247
- :class="{ '{{ stateInvalidClasses }}': isError(), '{{ stateValidClasses }}': !isError(), 'opacity-50 cursor-not-allowed': isDisabled(), 'bg-surface': isDisabled() || {{ readonly }}, 'bg-field': !isDisabled() && !{{ readonly }}, 'cursor-default': !isDisabled() && {{ readonly }} }"
378
+ :class="{ '{{ stateInvalidClasses }}': isError(), '{{ stateValidClasses }}': !isError(), 'opacity-50 cursor-not-allowed': isDisabled(), 'bg-surface': isDisabled() || isReadonly(), 'bg-field': !isDisabled() && !isReadonly(), 'cursor-default': !isDisabled() && isReadonly() }"
248
379
  @if(helperText)aria-describedby="{{ helperId }}"@endif
249
380
  />
250
381
 
251
382
  @if(clearable)
252
- <div :show="hasValue() && !isDisabled() && !{{ readonly }}" class="absolute inset-y-0 right-0 flex items-center pr-3">
383
+ <div :show="hasValue() && !isDisabled() && !isReadonly()" class="absolute inset-y-0 right-0 flex items-center pr-3">
253
384
  <button
254
385
  type="button"
255
386
  @click="onClear()"
@@ -285,3 +416,4 @@ defineExpose({ value: inputValue, clear: onClear })
285
416
  </div>
286
417
  @endif
287
418
  </div>
419
+ @endif