@stacksjs/components 0.2.655 → 0.2.661

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 (59) 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/{ListRow-8d3e1yxh.stx → ListRow-nvyg2fwb.stx} +32 -8
  12. package/dist/{PasswordInput-dg41ktgd.stx → PasswordInput-r51qzgc0.stx} +64 -0
  13. package/dist/{SectionCard-8ctdacjr.stx → SectionCard-8b5fyrjd.stx} +16 -4
  14. package/dist/{SegmentedControl-yvkjtc7y.stx → SegmentedControl-z9gk2fpn.stx} +23 -5
  15. package/dist/{Select-61zv5tr7.stx → Select-1cnqbcmg.stx} +39 -0
  16. package/dist/{Switch-rbxpzn5g.stx → Switch-nay7zdee.stx} +46 -0
  17. package/dist/{Tab-46mxm7f8.stx → Tab-j9f4t166.stx} +5 -1
  18. package/dist/{TabList-5xwk2zmz.stx → TabList-r1pc87xs.stx} +8 -1
  19. package/dist/{Tabs-bp03efe6.stx → Tabs-psm5wj7c.stx} +16 -1
  20. package/dist/{TextInput-9bm9gy8j.stx → TextInput-9x2gwera.stx} +64 -0
  21. package/dist/index.js +10 -10
  22. package/dist/ui/button/Button.d.ts +61 -0
  23. package/dist/ui/checkbox/Checkbox.d.ts +8 -1
  24. package/dist/ui/checkbox/index.d.ts +1 -0
  25. package/dist/ui/dialog/Dialog.d.ts +7 -1
  26. package/dist/ui/dialog/DialogPanel.d.ts +10 -0
  27. package/dist/ui/grouped-list/GroupedList.d.ts +8 -1
  28. package/dist/ui/grouped-list/GroupedListRow.d.ts +10 -2
  29. package/dist/ui/input/EmailInput.d.ts +8 -0
  30. package/dist/ui/input/PasswordInput.d.ts +10 -0
  31. package/dist/ui/input/TextInput.d.ts +11 -0
  32. package/dist/ui/mobile/ListRow.d.ts +13 -0
  33. package/dist/ui/mobile/SectionCard.d.ts +10 -0
  34. package/dist/ui/segmented-control/SegmentedControl.d.ts +10 -2
  35. package/dist/ui/tabs/Tab.d.ts +1 -1
  36. package/dist/ui/tabs/TabList.d.ts +6 -1
  37. package/dist/ui/tabs/Tabs.d.ts +8 -0
  38. package/package.json +3 -3
  39. package/src/ui/button/Button.stx +53 -0
  40. package/src/ui/checkbox/Checkbox.stx +20 -3
  41. package/src/ui/checkbox/index.ts +2 -0
  42. package/src/ui/dialog/Dialog.stx +8 -0
  43. package/src/ui/dialog/DialogDescription.stx +2 -1
  44. package/src/ui/dialog/DialogPanel.stx +24 -0
  45. package/src/ui/dialog/DialogTitle.stx +2 -1
  46. package/src/ui/drawer/Drawer.stx +31 -0
  47. package/src/ui/grouped-list/GroupedList.stx +13 -3
  48. package/src/ui/grouped-list/GroupedListRow.stx +42 -15
  49. package/src/ui/input/EmailInput.stx +11 -2
  50. package/src/ui/input/PasswordInput.stx +64 -0
  51. package/src/ui/input/TextInput.stx +64 -0
  52. package/src/ui/mobile/ListRow.stx +32 -8
  53. package/src/ui/mobile/SectionCard.stx +16 -4
  54. package/src/ui/segmented-control/SegmentedControl.stx +23 -5
  55. package/src/ui/select/Select.stx +39 -0
  56. package/src/ui/switch/Switch.stx +46 -0
  57. package/src/ui/tabs/Tab.stx +5 -1
  58. package/src/ui/tabs/TabList.stx +8 -1
  59. package/src/ui/tabs/Tabs.stx +16 -1
@@ -84,6 +84,17 @@ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
84
84
  export const form = $props.form || ''
85
85
  export const inputMode = $props.inputMode || $props.inputmode || ''
86
86
  export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
87
+
88
+ /*
89
+ * The field on a native host ($native), as TextInput draws it there: 48pt,
90
+ * filled, the system placeholder grey. Secure entry follows the reveal
91
+ * button through `:type` (text-entry.ts), and a field that names no
92
+ * autocomplete is the sign-in password, so the platform offers the saved one.
93
+ */
94
+ export const nativeAutocomplete = autocomplete || 'current-password'
95
+ export const nativeFieldClasses = `h-12 pl-4 pr-11 text-[17px] text-[#000000] dark:text-[#ffffff] bg-[#767680]/12 dark:bg-[#767680]/24 rounded-[10px] border-0 ${error ? 'border border-[#ff3b30] dark:border-[#ff453a]' : ''} ${disabled ? 'opacity-50' : ''} ${inputClassName}`.replace(/\s+/g, ' ').trim()
96
+ export const nativeLabelClasses = 'mb-1.5 px-4 text-[13px] uppercase text-[#6d6d72] dark:text-[#8d8d93]'
97
+ export const nativeHelperClasses = `mt-1.5 px-4 text-[13px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#6d6d72] dark:text-[#8d8d93]'}`
87
98
  </script>
88
99
 
89
100
  <script client>
@@ -131,6 +142,58 @@ const toggleAriaLabel = derived(() => showPassword() ? 'Hide password' : 'Show p
131
142
  defineExpose({ value: inputValue })
132
143
  </script>
133
144
 
145
+ @if($native)
146
+ <div class="w-full {{ className }}">
147
+ @if(label)
148
+ <label for="{{ inputId }}" class="{{ nativeLabelClasses }}">{{ label }}</label>
149
+ @endif
150
+ <div class="relative justify-center">
151
+ <input
152
+ data-stx-native-host-root
153
+ @if(name)name="{{ name }}"@endif
154
+ autocomplete="{{ nativeAutocomplete }}"
155
+ @if(form)form="{{ form }}"@endif
156
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
157
+ type="password"
158
+ :type="inputType()"
159
+ id="{{ inputId }}"
160
+ class="{{ nativeFieldClasses }}"
161
+ placeholderTextColor="#8e8e93"
162
+ value="{{ value }}"
163
+ :value="inputValue()"
164
+ placeholder="{{ placeholder }}"
165
+ @if(disabled)disabled@endif
166
+ @if(readonly)readonly@endif
167
+ @if(required)required@endif
168
+ @input="onInput($event)"
169
+ aria-invalid="{{ error ? 'true' : 'false' }}"
170
+ />
171
+ <button
172
+ type="button"
173
+ @click="toggleVisibility()"
174
+ class="absolute top-0 right-0 h-12 w-11 items-center justify-center"
175
+ :aria-label="toggleAriaLabel()"
176
+ >
177
+ <i :show="showPassword()" class="i-lucide-eye-off h-5 w-5 text-[#8e8e93]"></i>
178
+ <i :show="!showPassword()" class="i-lucide-eye h-5 w-5 text-[#8e8e93]"></i>
179
+ </button>
180
+ </div>
181
+ @if(showStrength)
182
+ <div :show="inputValue().length > 0" class="mt-2 px-4">
183
+ <div class="flex-row items-center justify-between mb-1">
184
+ <span class="text-[13px] text-[#6d6d72] dark:text-[#8d8d93]">Password strength</span>
185
+ <span class="text-[13px] font-medium" :class="strengthLabelColor()" :text="strengthText()"></span>
186
+ </div>
187
+ <div class="w-full h-1.5 bg-[#767680]/12 dark:bg-[#767680]/24 rounded-full overflow-hidden">
188
+ <div class="h-full rounded-full" :class="strengthColor()" :style="`width: ${strength()}%`"></div>
189
+ </div>
190
+ </div>
191
+ @endif
192
+ @if(helperText)
193
+ <p id="{{ helperId }}" class="{{ nativeHelperClasses }}">{{ helperText }}</p>
194
+ @endif
195
+ </div>
196
+ @else
134
197
  <div class="w-full {{ className }}">
135
198
  @if(label)
136
199
  <label for="{{ inputId }}" class="{{ labelClasses }}">
@@ -213,3 +276,4 @@ defineExpose({ value: inputValue })
213
276
  </p>
214
277
  @endif
215
278
  </div>
279
+ @endif
@@ -143,6 +143,18 @@ 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>
@@ -186,6 +198,57 @@ const charCount = derived(() => `${String(inputValue()).length} / {{ maxLength |
186
198
  defineExpose({ value: inputValue, clear: onClear })
187
199
  </script>
188
200
 
201
+ @if($native)
202
+ <div class="w-full {{ className }}">
203
+ @if(label)
204
+ <label for="{{ inputId }}" class="{{ nativeLabelClasses }}">{{ label }}</label>
205
+ @endif
206
+ <div class="relative justify-center">
207
+ <input
208
+ data-stx-native-host-root
209
+ @if(name)name="{{ name }}"@endif
210
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
211
+ @if(form)form="{{ form }}"@endif
212
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
213
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
214
+ type="{{ type }}"
215
+ @if(autofocus)autofocus@endif
216
+ id="{{ inputId }}"
217
+ class="{{ nativeFieldClasses }}"
218
+ placeholderTextColor="#8e8e93"
219
+ value="{{ value }}"
220
+ :value="inputValue()"
221
+ placeholder="{{ placeholder }}"
222
+ @if(disabled)disabled@endif
223
+ :disabled="isDisabled()"
224
+ @if(readonly)readonly@endif
225
+ @if(required)required@endif
226
+ @if(maxLength && freeText)maxlength="{{ maxLength }}"@endif
227
+ @input="onInput($event)"
228
+ @change="onChange($event)"
229
+ aria-invalid="{{ error ? 'true' : 'false' }}"
230
+ :aria-invalid="isError() ? 'true' : 'false'"
231
+ :class="{ 'border border-[#ff3b30] dark:border-[#ff453a]': isError(), 'opacity-50': isDisabled() }"
232
+ @if(clearable)style="padding-right: 40px"@endif
233
+ />
234
+ @if(clearable)
235
+ <button
236
+ type="button"
237
+ :show="hasValue() && !isDisabled() && !{{ readonly }}"
238
+ @click="onClear()"
239
+ class="absolute top-0 right-0 h-12 w-10 items-center justify-center"
240
+ aria-label="Clear input"
241
+ ><i class="i-lucide-circle-x h-[17px] w-[17px] text-[#c4c4c7] dark:text-[#5b5b5f]"></i></button>
242
+ @endif
243
+ </div>
244
+ @if(helperText)
245
+ <p id="{{ helperId }}" class="{{ nativeHelperClasses }}">{{ helperText }}</p>
246
+ @endif
247
+ @if(showCount && maxLength)
248
+ <p class="mt-1.5 px-4 text-right text-[13px] text-[#6d6d72] dark:text-[#8d8d93]" :text="charCount()"></p>
249
+ @endif
250
+ </div>
251
+ @else
189
252
  <div class="w-full {{ className }}">
190
253
  @if(label)
191
254
  <label for="{{ inputId }}" class="{{ labelClasses }}">
@@ -285,3 +348,4 @@ defineExpose({ value: inputValue, clear: onClear })
285
348
  </div>
286
349
  @endif
287
350
  </div>
351
+ @endif
@@ -31,11 +31,32 @@ export const className = $props.className || ''
31
31
  export const interactive = href !== ''
32
32
  export const tag = interactive ? 'a' : 'div'
33
33
 
34
- export const rowClasses = `
34
+ export const rowClasses = $native
35
+ ? `flex-row w-full items-start gap-3 px-4 py-3 ${className}`.replace(/\s+/g, ' ').trim()
36
+ : `
35
37
  flex w-full items-start gap-3 px-4 py-3 text-left
36
38
  ${interactive ? 'transition-colors active:bg-surface-sunken' : ''}
37
39
  ${className}
38
40
  `.replace(/\s+/g, ' ').trim()
41
+
42
+ /*
43
+ * On a native host ($native): the label and secondary-label colours, the
44
+ * title clamped to two lines as a native Text clamps, and a link row that
45
+ * highlights grey while pressed, as a table cell does.
46
+ */
47
+ const secondary = $native ? 'text-[#8a8a8e] dark:text-[#98989f]' : 'text-fg-muted'
48
+ export const eyebrowClasses = $native ? `text-[13px] ${secondary}` : 'block truncate text-sm text-fg-muted'
49
+ export const titleClasses = $native
50
+ ? 'text-[15px] font-semibold text-[#000000] dark:text-[#ffffff] line-clamp-2'
51
+ : 'block text-[15px] font-semibold leading-snug text-fg-strong [display:-webkit-box] [-webkit-box-orient:vertical] [-webkit-line-clamp:2] overflow-hidden'
52
+ export const detailClasses = $native ? `mt-0.5 text-[13px] ${secondary} truncate` : 'mt-0.5 block truncate text-sm text-fg-muted'
53
+ export const metaClasses = $native ? `text-[13px] ${secondary}` : 'text-sm text-fg-muted'
54
+ export const trailingClasses = $native
55
+ ? `rounded-[6px] bg-[#767680]/12 dark:bg-[#767680]/24 px-1.5 py-0.5 text-[12px] font-medium ${secondary}`
56
+ : 'rounded-control bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted'
57
+ // A column natively: a span holding spans is otherwise one run of text there.
58
+ export const bodyClasses = $native ? 'flex flex-col min-w-0 flex-1' : 'min-w-0 flex-1'
59
+ export const unreadClasses = $native ? 'h-2 w-2 rounded-full bg-[#007aff] dark:bg-[#0a84ff]' : 'h-2 w-2 rounded-full bg-accent'
39
60
  </script>
40
61
 
41
62
  <{{ tag }}
@@ -44,6 +65,9 @@ export const rowClasses = `
44
65
  @if (interactive)
45
66
  href="{{ href }}"
46
67
  @endif
68
+ @if (interactive && $native)
69
+ data-native="TouchableHighlight" underlayColor="#7676803d"
70
+ @endif
47
71
  >
48
72
  @if (icon || unread)
49
73
  <span class="flex w-6 shrink-0 flex-col items-center gap-1.5 pt-0.5" aria-hidden="true">
@@ -55,14 +79,14 @@ export const rowClasses = `
55
79
  hierarchy, and an unread list rendered entirely in bold has no
56
80
  hierarchy left to spend.
57
81
  --}}
58
- <span class="h-2 w-2 rounded-full bg-accent"></span>
82
+ <span class="{{ unreadClasses }}"></span>
59
83
  @endif
60
84
  </span>
61
85
  @endif
62
86
 
63
- <span class="min-w-0 flex-1">
87
+ <span class="{{ bodyClasses }}">
64
88
  @if (eyebrow)
65
- <span class="block truncate text-sm text-fg-muted">{{ eyebrow }}</span>
89
+ <span class="{{ eyebrowClasses }}">{{ eyebrow }}</span>
66
90
  @endif
67
91
 
68
92
  {{--
@@ -70,12 +94,12 @@ export const rowClasses = `
70
94
  title; unbounded lets a single pasted stack trace push the rest of the
71
95
  list off the screen.
72
96
  --}}
73
- <span class="block text-[15px] font-semibold leading-snug text-fg-strong [display:-webkit-box] [-webkit-box-orient:vertical] [-webkit-line-clamp:2] overflow-hidden">
97
+ <span class="{{ titleClasses }}">
74
98
  {{ title }}
75
99
  </span>
76
100
 
77
101
  @if (detail)
78
- <span class="mt-0.5 block truncate text-sm text-fg-muted">{{ detail }}</span>
102
+ <span class="{{ detailClasses }}">{{ detail }}</span>
79
103
  @endif
80
104
  </span>
81
105
 
@@ -87,11 +111,11 @@ export const rowClasses = `
87
111
  --}}
88
112
  <span class="flex shrink-0 flex-col items-end gap-2 pt-0.5">
89
113
  @if (meta)
90
- <span class="text-sm text-fg-muted">{{ meta }}</span>
114
+ <span class="{{ metaClasses }}">{{ meta }}</span>
91
115
  @endif
92
116
 
93
117
  @if (trailing)
94
- <span class="rounded-control bg-surface-sunken px-1.5 py-0.5 text-xs font-medium text-fg-muted">{{ trailing }}</span>
118
+ <span class="{{ trailingClasses }}">{{ trailing }}</span>
95
119
  @endif
96
120
  </span>
97
121
  @endif
@@ -17,10 +17,22 @@ export const action = $props.action || ''
17
17
  export const actionHref = $props.actionHref || ''
18
18
  export const className = $props.className || ''
19
19
 
20
- export const cardClasses = `
20
+ /*
21
+ * On a native host ($native) the card is iOS's inset group: white
22
+ * (#1c1c1e in dark) with 10pt corners and no outline, its rows parted by
23
+ * the system separator through the same `divide-y` (the host gives the
24
+ * border to every row shown after the first), under the large bold header a
25
+ * Today-style list heads a group with.
26
+ */
27
+ export const cardClasses = $native
28
+ ? 'overflow-hidden rounded-[10px] bg-[#ffffff] dark:bg-[#1c1c1e] divide-y-[0.5px] divide-[#c6c6c8] dark:divide-[#38383a]'
29
+ : `
21
30
  overflow-hidden rounded-2xl border border-line bg-surface-raised
22
31
  divide-y divide-line
23
32
  `.replace(/\s+/g, ' ').trim()
33
+ export const headerClasses = $native ? 'flex-row items-baseline justify-between px-1 pb-2' : 'flex items-baseline justify-between px-1 pb-2'
34
+ export const titleClasses = $native ? 'text-[22px] font-bold text-[#000000] dark:text-[#ffffff]' : 'text-2xl font-bold tracking-tight text-fg-strong'
35
+ export const actionClasses = $native ? 'text-[17px] text-[#007aff] dark:text-[#0a84ff]' : 'text-sm font-medium text-accent'
24
36
 
25
37
  /*
26
38
  * Whether the router should own this link.
@@ -46,15 +58,15 @@ export const actionRouterOwned = routerOwns(actionHref)
46
58
 
47
59
  <section class="{{ className }}" data-stx-section-card>
48
60
  @if (title || action)
49
- <header class="flex items-baseline justify-between px-1 pb-2">
61
+ <header class="{{ headerClasses }}">
50
62
  @if (title)
51
- <h2 class="text-2xl font-bold tracking-tight text-fg-strong">{{ title }}</h2>
63
+ <h2 class="{{ titleClasses }}">{{ title }}</h2>
52
64
  @endif
53
65
 
54
66
  @if (action)
55
67
  <a
56
68
  href="{{ actionHref }}"
57
- class="text-sm font-medium text-accent"
69
+ class="{{ actionClasses }}"
58
70
  @if (actionRouterOwned)
59
71
  data-stx-link
60
72
  @endif
@@ -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'