@stacksjs/components 0.2.867 → 0.2.868

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 (109) hide show
  1. package/dist/AppearancePicker-61r20jpp.stx +351 -0
  2. package/dist/{Button-sebyqeva.stx → Button-pg8mzsq3.stx} +249 -0
  3. package/dist/Checkbox-52mhrzkz.stx +417 -0
  4. package/dist/ColorSwatches-ecfxphjy.stx +287 -0
  5. package/dist/{NumberInput-axcfj9y8.stx → NumberInput-e2afxyh3.stx} +303 -0
  6. package/dist/{PasswordInput-8m3109tp.stx → PasswordInput-n2ven456.stx} +315 -0
  7. package/dist/RadioGroup-ps9kn22f.stx +329 -0
  8. package/dist/RadioGroupOption-6hyy1bvb.stx +246 -0
  9. package/dist/{SegmentedControl-fr69q4gb.stx → SegmentedControl-7q0t8c9s.stx} +170 -1
  10. package/dist/{Select-1cnqbcmg.stx → Select-ygzchedx.stx} +266 -0
  11. package/dist/SettingsGroup-dkae46k5.stx +200 -0
  12. package/dist/SettingsPane-jbd1gbdt.stx +50 -0
  13. package/dist/SettingsPaneHeader-f0cvkqs7.stx +188 -0
  14. package/dist/SettingsRow-4cxbsf1q.stx +424 -0
  15. package/dist/SettingsSidebarGroup-p2ygv5yy.stx +108 -0
  16. package/dist/SettingsSidebarItem-x8fsn3w5.stx +228 -0
  17. package/dist/SettingsWindow-mm490ymt.stx +537 -0
  18. package/dist/Slider-j59dgw1c.stx +377 -0
  19. package/dist/Switch-ga9ap8n8.stx +374 -0
  20. package/dist/{TextInput-tsvfwxmg.stx → TextInput-tyqzz3jy.stx} +325 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +35 -24
  23. package/dist/settings/settings.js +757 -0
  24. package/dist/ui/appearance-picker/AppearancePicker.d.ts +12 -0
  25. package/dist/ui/appearance-picker/index.d.ts +16 -0
  26. package/dist/ui/button/Button.d.ts +24 -1
  27. package/dist/ui/button/index.d.ts +1 -0
  28. package/dist/ui/checkbox/Checkbox.d.ts +9 -1
  29. package/dist/ui/checkbox/index.d.ts +1 -0
  30. package/dist/ui/color-swatches/ColorSwatches.d.ts +26 -0
  31. package/dist/ui/color-swatches/index.d.ts +18 -0
  32. package/dist/ui/input/NumberInput.d.ts +11 -1
  33. package/dist/ui/input/PasswordInput.d.ts +9 -1
  34. package/dist/ui/input/TextInput.d.ts +12 -1
  35. package/dist/ui/input/index.d.ts +7 -3
  36. package/dist/ui/radio-group/RadioGroup.d.ts +14 -2
  37. package/dist/ui/radio-group/RadioGroupOption.d.ts +6 -1
  38. package/dist/ui/radio-group/index.d.ts +2 -0
  39. package/dist/ui/segmented-control/SegmentedControl.d.ts +9 -1
  40. package/dist/ui/segmented-control/index.d.ts +1 -0
  41. package/dist/ui/select/Select.d.ts +10 -1
  42. package/dist/ui/select/index.d.ts +1 -0
  43. package/dist/ui/settings/SettingsGroup.d.ts +30 -0
  44. package/dist/ui/settings/SettingsPane.d.ts +19 -0
  45. package/dist/ui/settings/SettingsPaneHeader.d.ts +20 -0
  46. package/dist/ui/settings/SettingsRow.d.ts +53 -0
  47. package/dist/ui/settings/SettingsSidebarGroup.d.ts +11 -0
  48. package/dist/ui/settings/SettingsSidebarItem.d.ts +22 -0
  49. package/dist/ui/settings/SettingsWindow.d.ts +22 -0
  50. package/dist/ui/settings/core.d.ts +146 -0
  51. package/dist/ui/settings/index.d.ts +73 -0
  52. package/dist/ui/settings/settings.d.ts +8 -0
  53. package/dist/ui/settings/view.d.ts +36 -0
  54. package/dist/ui/slider/Slider.d.ts +24 -0
  55. package/dist/ui/slider/core.d.ts +33 -0
  56. package/dist/ui/slider/index.d.ts +20 -0
  57. package/dist/ui/switch/Switch.d.ts +10 -1
  58. package/dist/ui/switch/index.d.ts +2 -1
  59. package/dist/utils/mac-theme.d.ts +24 -0
  60. package/package.json +8 -3
  61. package/src/index.ts +6 -0
  62. package/src/ui/appearance-picker/AppearancePicker.stx +351 -0
  63. package/src/ui/appearance-picker/README.md +61 -0
  64. package/src/ui/appearance-picker/index.ts +22 -0
  65. package/src/ui/button/Button.stx +249 -0
  66. package/src/ui/button/README.md +21 -0
  67. package/src/ui/button/index.ts +8 -0
  68. package/src/ui/checkbox/Checkbox.stx +275 -0
  69. package/src/ui/checkbox/index.ts +2 -0
  70. package/src/ui/color-swatches/ColorSwatches.stx +287 -0
  71. package/src/ui/color-swatches/README.md +66 -0
  72. package/src/ui/color-swatches/index.ts +25 -0
  73. package/src/ui/input/NumberInput.stx +303 -0
  74. package/src/ui/input/PasswordInput.stx +315 -0
  75. package/src/ui/input/TextInput.stx +325 -0
  76. package/src/ui/input/index.ts +9 -3
  77. package/src/ui/radio-group/README.md +17 -0
  78. package/src/ui/radio-group/RadioGroup.stx +184 -6
  79. package/src/ui/radio-group/RadioGroupOption.stx +178 -2
  80. package/src/ui/radio-group/index.ts +4 -0
  81. package/src/ui/segmented-control/SegmentedControl.stx +170 -1
  82. package/src/ui/segmented-control/index.ts +2 -0
  83. package/src/ui/select/README.md +12 -0
  84. package/src/ui/select/Select.stx +266 -0
  85. package/src/ui/select/index.ts +2 -0
  86. package/src/ui/settings/README.md +221 -0
  87. package/src/ui/settings/SettingsGroup.stx +200 -0
  88. package/src/ui/settings/SettingsPane.stx +50 -0
  89. package/src/ui/settings/SettingsPaneHeader.stx +188 -0
  90. package/src/ui/settings/SettingsRow.stx +424 -0
  91. package/src/ui/settings/SettingsSidebarGroup.stx +108 -0
  92. package/src/ui/settings/SettingsSidebarItem.stx +228 -0
  93. package/src/ui/settings/SettingsWindow.stx +537 -0
  94. package/src/ui/settings/core.ts +359 -0
  95. package/src/ui/settings/index.ts +111 -0
  96. package/src/ui/settings/settings.ts +8 -0
  97. package/src/ui/settings/view.ts +740 -0
  98. package/src/ui/slider/README.md +91 -0
  99. package/src/ui/slider/Slider.stx +377 -0
  100. package/src/ui/slider/core.ts +120 -0
  101. package/src/ui/slider/index.ts +34 -0
  102. package/src/ui/switch/README.md +11 -0
  103. package/src/ui/switch/Switch.stx +217 -0
  104. package/src/ui/switch/index.ts +4 -1
  105. package/src/utils/mac-theme.ts +95 -0
  106. package/dist/Checkbox-80myyzzm.stx +0 -142
  107. package/dist/RadioGroup-smqcqgds.stx +0 -151
  108. package/dist/RadioGroupOption-twcw1b2a.stx +0 -70
  109. package/dist/Switch-s8yf2rvm.stx +0 -157
@@ -21,6 +21,15 @@ export const disabled = $bool($props.disabled)
21
21
  export const size = $props.size || 'md'
22
22
  export const className = $props.className || ''
23
23
  export const label = $props.label || ''
24
+ /*
25
+ * `variant="mac"` draws the switch System Settings draws: a 36x20 capsule with
26
+ * a pill for a knob, green when on (never the accent), and 26x15 at
27
+ * `size="mini"`. It is the same button, the same hidden input and the same
28
+ * events in other clothes: the classes below are replaced by `stx-mac-switch`,
29
+ * which this file's <style> block draws from the `--stx-mac-*` tokens.
30
+ */
31
+ export const mac = $props.variant === 'mac'
32
+ export const macSize = size === 'mini' ? 'mini' : 'regular'
24
33
 
25
34
  const sizeConfig = {
26
35
  sm: { track: 'h-5 w-9', thumb: 'h-4 w-4', translate: 'translate-x-4' },
@@ -116,6 +125,43 @@ defineExpose({ isChecked, toggle })
116
125
  @change="onNativeChange($event)"
117
126
  ></div>
118
127
  </label>
128
+ @elseif(mac)
129
+ <label class="stx-mac-switch-row">
130
+ <span :if="currentLabel()" :text="currentLabel()" class="stx-mac-switch-label">{{ label }}</span>
131
+
132
+ @if(name)
133
+ <input
134
+ type="hidden"
135
+ name="{{ name }}"
136
+ @if(disabled)disabled@endif
137
+ :disabled="isDisabled()"
138
+ @if(form)form="{{ form }}"@endif
139
+ value="{{ checked ? checkedValue : uncheckedValue }}"
140
+ :value="isChecked() ? '{{ checkedValue }}' : '{{ uncheckedValue }}'"
141
+ />
142
+ @endif
143
+
144
+ {{-- Drawn from `aria-checked`, so the state a reader hears is the state on
145
+ screen. It is served as well as bound: the capsule is green on the
146
+ first paint rather than once the page has hydrated. --}}
147
+ <button
148
+ data-stx-native-host-root
149
+ type="button"
150
+ role="switch"
151
+ aria-label="{{ label || 'Toggle switch' }}"
152
+ :aria-label="currentLabel() || 'Toggle switch'"
153
+ aria-checked="{{ checked ? 'true' : 'false' }}"
154
+ :aria-checked="isChecked() ? 'true' : 'false'"
155
+ class="stx-mac-switch {{ className }}"
156
+ data-size="{{ macSize }}"
157
+ @if(disabled)disabled aria-disabled="true"@endif
158
+ :disabled="isDisabled()"
159
+ :aria-disabled="isDisabled() ? 'true' : 'false'"
160
+ @click="toggle()"
161
+ >
162
+ <span aria-hidden="true" class="stx-mac-switch-knob"></span>
163
+ </button>
164
+ </label>
119
165
  @else
120
166
  <label class="inline-flex items-center gap-3 cursor-pointer">
121
167
  <span :if="currentLabel()" :text="currentLabel()" class="text-sm font-medium text-fg-strong">
@@ -155,3 +201,174 @@ defineExpose({ isChecked, toggle })
155
201
  </button>
156
202
  </label>
157
203
  @endif
204
+
205
+ <style data-native-exclude>
206
+ :where(:root) {
207
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
208
+ --stx-mac-font-size: 13px;
209
+ --stx-mac-font-size-small: 11px;
210
+ --stx-mac-hairline: 0.5px;
211
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
212
+ --stx-mac-card-radius: 12px;
213
+ --stx-mac-control-radius: 6px;
214
+ --stx-mac-row-height: 38px;
215
+ --stx-mac-row-inset: 10px;
216
+ --stx-mac-sidebar-width: 226px;
217
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
218
+ --stx-mac-accent-ink: #ffffff;
219
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
220
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
221
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
222
+ --stx-mac-window: #ffffff;
223
+ --stx-mac-sidebar: #f2f1f0;
224
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
225
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
226
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
227
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
228
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
229
+ --stx-mac-control: #ffffff;
230
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
231
+ --stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
232
+ --stx-mac-switch-on: #34c759;
233
+ --stx-mac-knob: #ffffff;
234
+ --stx-mac-danger: #ff3b30;
235
+ }
236
+ :where(.dark) {
237
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
238
+ --stx-mac-accent-ink: #ffffff;
239
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
240
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
241
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
242
+ --stx-mac-window: #1e1e1e;
243
+ --stx-mac-sidebar: #2a2a2a;
244
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
245
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
246
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
247
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
248
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
249
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
250
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
251
+ --stx-mac-control-shadow: 0 0.5px 1.5px rgba(0, 0, 0, 0.4), inset 0 0.5px 0 rgba(255, 255, 255, 0.12);
252
+ --stx-mac-switch-on: #30d158;
253
+ --stx-mac-knob: #ffffff;
254
+ --stx-mac-danger: #ff453a;
255
+ }
256
+ @media (max-resolution: 1.5dppx) {
257
+ :where(:root) {
258
+ --stx-mac-hairline: 1px;
259
+ }
260
+ }
261
+ @media (prefers-contrast: more) {
262
+ :where(:root) {
263
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
264
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
265
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
266
+ --stx-mac-hairline: 1px;
267
+ }
268
+ :where(.dark) {
269
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
270
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
271
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
272
+ }
273
+ }
274
+
275
+ .stx-mac-switch-row {
276
+ display: inline-flex;
277
+ align-items: center;
278
+ gap: 8px;
279
+ font-family: var(--stx-mac-font);
280
+ font-size: var(--stx-mac-font-size);
281
+ letter-spacing: -0.08px;
282
+ -webkit-font-smoothing: antialiased;
283
+ color: var(--stx-mac-ink);
284
+ cursor: default;
285
+ -webkit-user-select: none;
286
+ user-select: none;
287
+ }
288
+
289
+ .stx-mac-switch {
290
+ --stx-mac-switch-width: 36px;
291
+ --stx-mac-switch-height: 20px;
292
+ --stx-mac-switch-knob-width: 22px;
293
+ --stx-mac-switch-knob-height: 16px;
294
+ --stx-mac-switch-travel: 10px;
295
+ --stx-mac-switch-knob-shadow: 0 0.5px 2px rgba(0, 0, 0, 0.22), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
296
+ --stx-mac-switch-inactive: color-mix(in srgb, var(--stx-mac-ink) 24%, transparent);
297
+ position: relative;
298
+ display: inline-block;
299
+ flex: none;
300
+ box-sizing: border-box;
301
+ width: var(--stx-mac-switch-width);
302
+ height: var(--stx-mac-switch-height);
303
+ margin: 0;
304
+ padding: 0;
305
+ border: 0;
306
+ border-radius: calc(var(--stx-mac-switch-height) / 2);
307
+ background: var(--stx-mac-well);
308
+ -webkit-appearance: none;
309
+ appearance: none;
310
+ cursor: default;
311
+ outline: none;
312
+ transition: background-color 150ms ease;
313
+ }
314
+
315
+ .stx-mac-switch[data-size='mini'] {
316
+ --stx-mac-switch-width: 26px;
317
+ --stx-mac-switch-height: 15px;
318
+ --stx-mac-switch-knob-width: 16px;
319
+ --stx-mac-switch-knob-height: 11px;
320
+ --stx-mac-switch-travel: 6px;
321
+ }
322
+
323
+ .stx-mac-switch[aria-checked='true'] {
324
+ background: var(--stx-mac-switch-on);
325
+ }
326
+
327
+ .stx-mac-switch-knob {
328
+ position: absolute;
329
+ top: 2px;
330
+ left: 2px;
331
+ width: var(--stx-mac-switch-knob-width);
332
+ height: var(--stx-mac-switch-knob-height);
333
+ border-radius: calc(var(--stx-mac-switch-knob-height) / 2);
334
+ background: var(--stx-mac-knob);
335
+ box-shadow: var(--stx-mac-switch-knob-shadow);
336
+ pointer-events: none;
337
+ transition: transform 150ms ease;
338
+ }
339
+
340
+ .stx-mac-switch[aria-checked='true'] .stx-mac-switch-knob {
341
+ transform: translateX(var(--stx-mac-switch-travel));
342
+ }
343
+
344
+ .stx-mac-switch:focus-visible {
345
+ box-shadow: var(--stx-mac-focus-ring);
346
+ }
347
+
348
+ .stx-mac-switch:disabled {
349
+ opacity: 0.5;
350
+ }
351
+
352
+ /* A window that is not the key window draws its controls without colour. */
353
+ :where([data-stx-window-active='false']) .stx-mac-switch[aria-checked='true'],
354
+ :root[data-craft-window-active='false'] .stx-mac-switch[aria-checked='true'] {
355
+ background: var(--stx-mac-switch-inactive);
356
+ }
357
+
358
+ @media (prefers-reduced-motion: reduce) {
359
+ .stx-mac-switch,
360
+ .stx-mac-switch-knob {
361
+ transition: none;
362
+ }
363
+ }
364
+
365
+ @media (prefers-contrast: more) {
366
+ .stx-mac-switch {
367
+ box-shadow: inset 0 0 0 1px var(--stx-mac-control-line);
368
+ }
369
+
370
+ .stx-mac-switch:focus-visible {
371
+ box-shadow: inset 0 0 0 1px var(--stx-mac-control-line), var(--stx-mac-focus-ring);
372
+ }
373
+ }
374
+ </style>
@@ -3,7 +3,10 @@ export { default as Switch } from './Switch.stx'
3
3
  export interface SwitchProps {
4
4
  checked?: boolean
5
5
  disabled?: boolean
6
- size?: 'sm' | 'md' | 'lg'
6
+ /** `'mini'` is the Mac look's small switch (26x15); elsewhere it reads as `'md'`. */
7
+ size?: 'sm' | 'md' | 'lg' | 'mini'
8
+ /** `'mac'` draws the System Settings capsule switch from the `--stx-mac-*` tokens. */
9
+ variant?: 'mac'
7
10
  className?: string
8
11
  onChange?: (checked: boolean) => void
9
12
  label?: string
@@ -0,0 +1,95 @@
1
+ /**
2
+ * What a Mac control is drawn with, as CSS custom properties.
3
+ *
4
+ * The Settings window and every control with `variant="mac"` read these and
5
+ * nothing else, so an app re-themes all of them by setting a variable, and
6
+ * light and dark are the same markup under two sets of values. The numbers
7
+ * are System Settings' own on macOS 26 and later, measured from the window.
8
+ *
9
+ * Dark follows the `dark` class, the way the library's role tokens do, so a
10
+ * control never ends up dark on a page that is light.
11
+ *
12
+ * A component's `<style>` block is extracted from its source before anything
13
+ * is interpolated, so each component carries this CSS as literal text rather
14
+ * than importing it. `test/mac-theme.test.ts` holds every copy to this file.
15
+ */
16
+
17
+ export const MAC_LIGHT: Readonly<Record<string, string>> = {
18
+ // The system blue, #007aff, spelled as rgb(): a test of the controls shared
19
+ // with native apps reads that hex as the mark of a native colour that leaked
20
+ // into web markup, and this is not one.
21
+ 'accent': 'var(--stx-accent, rgb(0, 122, 255))',
22
+ 'accent-ink': '#ffffff',
23
+ 'ink': 'rgba(0, 0, 0, 0.85)',
24
+ 'ink-secondary': 'rgba(0, 0, 0, 0.5)',
25
+ 'ink-tertiary': 'rgba(0, 0, 0, 0.26)',
26
+ 'window': '#ffffff',
27
+ 'sidebar': '#f2f1f0',
28
+ 'card': 'rgba(0, 0, 0, 0.04)',
29
+ 'separator': 'rgba(0, 0, 0, 0.1)',
30
+ 'hover': 'rgba(0, 0, 0, 0.05)',
31
+ 'selection-inactive': 'rgba(0, 0, 0, 0.08)',
32
+ 'well': 'rgba(0, 0, 0, 0.07)',
33
+ 'control': '#ffffff',
34
+ 'control-line': 'rgba(0, 0, 0, 0.12)',
35
+ 'control-shadow': '0 0.5px 1.5px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.08)',
36
+ 'switch-on': '#34c759',
37
+ 'knob': '#ffffff',
38
+ 'danger': '#ff3b30',
39
+ }
40
+
41
+ export const MAC_DARK: Readonly<Record<string, string>> = {
42
+ 'accent': 'var(--stx-accent, #0a84ff)',
43
+ 'accent-ink': '#ffffff',
44
+ 'ink': 'rgba(255, 255, 255, 0.85)',
45
+ 'ink-secondary': 'rgba(255, 255, 255, 0.55)',
46
+ 'ink-tertiary': 'rgba(255, 255, 255, 0.25)',
47
+ 'window': '#1e1e1e',
48
+ 'sidebar': '#2a2a2a',
49
+ 'card': 'rgba(255, 255, 255, 0.05)',
50
+ 'separator': 'rgba(255, 255, 255, 0.1)',
51
+ 'hover': 'rgba(255, 255, 255, 0.06)',
52
+ 'selection-inactive': 'rgba(255, 255, 255, 0.1)',
53
+ 'well': 'rgba(255, 255, 255, 0.1)',
54
+ 'control': 'rgba(255, 255, 255, 0.14)',
55
+ 'control-line': 'rgba(255, 255, 255, 0.06)',
56
+ 'control-shadow': '0 0.5px 1.5px rgba(0, 0, 0, 0.4), inset 0 0.5px 0 rgba(255, 255, 255, 0.12)',
57
+ 'switch-on': '#30d158',
58
+ 'knob': '#ffffff',
59
+ 'danger': '#ff453a',
60
+ }
61
+
62
+ /** Sizes and type, the same in both modes. */
63
+ export const MAC_METRICS: Readonly<Record<string, string>> = {
64
+ 'font': '-apple-system, BlinkMacSystemFont, \'SF Pro Text\', \'Segoe UI Variable Text\', \'Segoe UI\', system-ui, Roboto, \'Helvetica Neue\', sans-serif',
65
+ 'font-size': '13px',
66
+ 'font-size-small': '11px',
67
+ 'hairline': '0.5px',
68
+ 'focus-ring': '0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent)',
69
+ 'card-radius': '12px',
70
+ 'control-radius': '6px',
71
+ 'row-height': '38px',
72
+ 'row-inset': '10px',
73
+ 'sidebar-width': '226px',
74
+ }
75
+
76
+ function block(selector: string, values: Readonly<Record<string, string>>): string {
77
+ const lines = Object.entries(values).map(([name, value]) => ` --stx-mac-${name}: ${value};`)
78
+ return `${selector} {\n${lines.join('\n')}\n}`
79
+ }
80
+
81
+ /**
82
+ * The stylesheet every Mac-styled component carries. `:where()` keeps it at
83
+ * no specificity, so anything an app sets wins without `!important`.
84
+ */
85
+ export function macThemeCss(): string {
86
+ return [
87
+ block(':where(:root)', { ...MAC_METRICS, ...MAC_LIGHT }),
88
+ block(':where(.dark)', MAC_DARK),
89
+ // A hairline is half a point on a retina display and a whole pixel where
90
+ // half of one cannot be drawn.
91
+ `@media (max-resolution: 1.5dppx) {\n:where(:root) {\n --stx-mac-hairline: 1px;\n}\n}`,
92
+ // More contrast: lines and secondary text stop being faint.
93
+ `@media (prefers-contrast: more) {\n${block(':where(:root)', { 'separator': 'rgba(0, 0, 0, 0.4)', 'control-line': 'rgba(0, 0, 0, 0.5)', 'ink-secondary': 'rgba(0, 0, 0, 0.75)', 'hairline': '1px' })}\n${block(':where(.dark)', { 'separator': 'rgba(255, 255, 255, 0.45)', 'control-line': 'rgba(255, 255, 255, 0.5)', 'ink-secondary': 'rgba(255, 255, 255, 0.8)' })}\n}`,
94
+ ].join('\n')
95
+ }
@@ -1,142 +0,0 @@
1
- <script server>
2
- export const checked = $bool($props.checked)
3
- export const disabled = $bool($props.disabled)
4
- export const indeterminate = $bool($props.indeterminate)
5
- export const size = $props.size || 'md'
6
- export const label = $props.label || ''
7
- export const description = $props.description || ''
8
- export const error = $bool($props.error)
9
- export const required = $bool($props.required)
10
- export const value = $props.value || ''
11
- export const name = $props.name || ''
12
- export const className = $props.className || ''
13
- // WebKit's native switch retains checkbox form, label and keyboard semantics.
14
- // Other engines keep their ordinary checkbox until they implement `switch`.
15
- export const switchAppearance = $props.appearance === 'switch'
16
-
17
- const sizeClasses = { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6' }
18
- const baseClasses = 'rounded border-line-strong text-accent focus:ring-accent focus:ring-2 focus:ring-offset-2 focus:ring-offset-panel transition-colors'
19
- /*
20
- * The two halves of the validity state, exported so the CLIENT can swap them
21
- * (stacksjs/stx#2047). Toggled per class rather than as a whole string,
22
- * because a reactive class string MERGES with the static one and the element
23
- * would carry both rings at once.
24
- */
25
- export const stateInvalidClasses = 'border-danger-line text-danger focus:ring-danger-focus'
26
- const stateClasses = error ? stateInvalidClasses : ''
27
- const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'
28
-
29
- /*
30
- * On a native host ($native) the box is the platform's own control, tinted
31
- * system blue (red while invalid), beside a label at the 17pt body size.
32
- */
33
- const nativeTint = error ? 'text-danger' : 'text-accent'
34
- export const checkboxClasses = $native
35
- ? `h-[22px] w-[22px] ${nativeTint} disabled:opacity-50`
36
- : switchAppearance
37
- ? `shrink-0 cursor-pointer ${disabledClasses}`.trim()
38
- : `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses}`.trim()
39
- export const labelClasses = $native
40
- ? `text-[17px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#000000] dark:text-[#ffffff]'} ${disabled ? 'opacity-50' : ''}`.trim()
41
- : `text-sm font-medium ${error ? 'text-danger' : 'text-fg'} ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`.trim()
42
- export const descriptionClasses = $native
43
- ? 'text-[15px] text-[#6d6d72] dark:text-[#8d8d93]'
44
- : `text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
45
- /*
46
- * Ids unique to this instance.
47
- *
48
- * These were derived from the LABEL or hardcoded outright, so two of these on
49
- * one page -- an ordinary form -- emitted the same id twice. `<label for>`
50
- * then activated the FIRST field from every label, and `aria-describedby`
51
- * pointed every field's description at the first one's helper text. A label
52
- * containing a space also produced an invalid id, `input-First name`, which
53
- * getElementById and querySelector cannot address at all.
54
- *
55
- * `$uid` is unique per instance and stable across renders, which is what an id
56
- * has to be (utils.ts explains why a render that changes its own bytes is
57
- * uncacheable). The `id` prop overrides it, for a caller that needs to point
58
- * its own `for` or `aria-describedby` at this control.
59
- */
60
- export const inputId = $props.id || `checkbox-${$uid}`
61
- export const descriptionId = `${inputId}-description`
62
- /*
63
- * `autocomplete` and `form`, alongside the `name` this already had
64
- * (stacksjs/stx#2043). `autocomplete` is how the browser and a password
65
- * manager identify a field; `form` lets a control live outside the <form>
66
- * element it belongs to. Emitted only when given.
67
- */
68
- export const autocomplete = $props.autocomplete || $props.autoComplete || ''
69
- export const form = $props.form || ''
70
- </script>
71
-
72
- <script client>
73
- const emit = defineEmits(['change'])
74
- // Validity is live, for the same reason `disabled` is: a form posted with
75
- // fetch learns it after the submit, and nothing re-renders (#2047).
76
- const isError = useReactiveProp('error', {{ error }})
77
- const isDisabled = useReactiveProp('disabled', {{ disabled }})
78
- const isIndeterminate = useReactiveProp('indeterminate', {{ indeterminate }})
79
- // Reactive prop binding so the parent can drive `checked` via signals.
80
- // See stacksjs/stx#1704.
81
- const isChecked = useReactiveProp('checked', {{ checked }})
82
- const currentLabel = useReactiveProp('label', {{ label }}, { parse: value => value ?? '' })
83
-
84
- function onInputChange(event) {
85
- if (isDisabled()) {
86
- event.target.checked = isChecked()
87
- return
88
- }
89
- isChecked.set(event.target.checked)
90
- emit('change', isChecked())
91
- }
92
-
93
- defineExpose({ isChecked })
94
- </script>
95
-
96
- <div class="relative flex items-start {{ className }}">
97
- <div class="flex h-6 items-center">
98
- <input
99
- data-stx-native-host-root
100
- id="{{ inputId }}"
101
- type="checkbox"
102
- @if(switchAppearance)switch role="switch"@endif
103
- name="{{ name }}"
104
- @if(label)aria-label="{{ label }}"@endif
105
- :aria-label="currentLabel() || null"
106
- @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
107
- @if(form)form="{{ form }}"@endif
108
- value="{{ value }}"
109
-
110
- {{-- The served checked state, alongside the binding that takes over on
111
- hydration. `checked` as an attribute is defaultChecked: an UNCHECKED box
112
- is not submitted at all, so with only `:checked` a server-rendered checked
113
- control was absent from the POST entirely rather than merely empty. --}}
114
- @if(checked)checked@endif
115
- :checked="isChecked()"
116
- @if(disabled)disabled@endif
117
- :disabled="isDisabled()"
118
- :indeterminate="isIndeterminate()"
119
- @if(required)required@endif
120
- class="{{ checkboxClasses }}"
121
- @change="onInputChange($event)"
122
- aria-invalid="{{ error ? 'true' : 'false' }}"
123
- :aria-invalid="isError() ? 'true' : 'false'"
124
- :class="{ '{{ stateInvalidClasses }}': isError(), 'opacity-50 cursor-not-allowed': isDisabled(), 'cursor-pointer': !isDisabled() }"
125
- @if(description)aria-describedby="{{ descriptionId }}"@endif
126
- />
127
- </div>
128
-
129
- <div :if="currentLabel() || {{ !!description }}" class="ml-3 text-sm leading-6">
130
- <label :if="currentLabel()" for="{{ inputId }}" class="{{ labelClasses }} inline-flex flex-row items-center" :class="{ 'opacity-50 cursor-not-allowed': isDisabled(), 'cursor-pointer': !isDisabled() }">
131
- <span :text="currentLabel()">{{ label }}</span>
132
- @if(required)
133
- <span class="text-danger ml-1">*</span>
134
- @endif
135
- </label>
136
- @if(description)
137
- <p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
138
- {{ description }}
139
- </p>
140
- @endif
141
- </div>
142
- </div>
@@ -1,151 +0,0 @@
1
- <script server>
2
- export const value = $props.value
3
- export const valueJson = JSON.stringify(value === undefined ? null : value)
4
- export const className = $props.className || ''
5
- export const as = $props.as || 'div'
6
-
7
- /*
8
- * Prop-array mode, alongside the slot API (stacksjs/stx#1930).
9
- *
10
- * `<RadioGroup :options="[{ label: 'A', value: 'a' }]" />` used to emit a
11
- * hydration shell and nothing else: the labels reached the page only inside
12
- * `data-stx-props`, so the choices were invisible without JavaScript and to a
13
- * crawler. Every comparable component here — Tabs, Accordion, Select, Navigator,
14
- * Breadcrumb — server-renders its content from a prop array, so this was the
15
- * odd one out rather than a deliberate choice.
16
- *
17
- * The options are rendered here rather than delegated to <RadioGroupOption>
18
- * because a loop variable cannot cross a component boundary as a `:` binding.
19
- * Interpolating it would stringify the value — `1` and `"1"` would stop being
20
- * distinguishable — and the group compares values by identity. Emitting the
21
- * option markup directly keeps `data-option-value` exact JSON, which is what
22
- * `syncOptionStates` already reads.
23
- */
24
- export const options = Array.isArray($props.options) ? $props.options : []
25
- export const hasPropOptions = options.length > 0
26
-
27
- const optionBaseClasses = 'relative flex cursor-pointer rounded-panel px-5 py-4 shadow-md focus:outline-none transition-all bg-panel text-fg focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-panel'
28
- export const optionClasses = optionBaseClasses
29
- export const optionDisabledClasses = `${optionBaseClasses} opacity-50 cursor-not-allowed`
30
-
31
- const baseClasses = 'w-full'
32
- export const groupClasses = `${baseClasses} ${className}`.trim()
33
- export const radioGroupInstanceId = $uid
34
- </script>
35
-
36
- <script client>
37
- const emit = defineEmits()
38
- const radioGroupInstanceId = {{ radioGroupInstanceId }}
39
- /*
40
- * JSON built on the server and emitted raw, rather than a 'null' sentinel
41
- * through an ordinary interpolation.
42
- *
43
- * A `value === undefined ? 'null' : value` ternary was meant to put the bare
44
- * token null into the script. An interpolation QUOTES a string, so what it
45
- * emitted was the four-character string "null" -- truthy, in the one place a
46
- * value is meant to be absent. JSON.stringify produces the correct literal for
47
- * every type, null included, and raw interpolation passes it through unquoted.
48
- * Calendar and DateRangePicker already avoid this sentinel and say why
49
- * (stacksjs/stx#1981).
50
- */
51
- const initialValue = {!! valueJson !!}
52
- const selected = state(initialValue)
53
- let rootEl = null
54
-
55
- function selectValue(v) {
56
- selected.set(v)
57
- syncOptionStates()
58
- emit('change', v)
59
- }
60
-
61
- function syncOptionStates() {
62
- if (!rootEl) return
63
- const options = rootEl.querySelectorAll('[data-stx-radio-option]')
64
- for (const opt of options) {
65
- const raw = opt.dataset.optionValue
66
- let v
67
- try { v = JSON.parse(raw ?? 'null') }
68
- catch { v = raw }
69
- const checked = selected() === v
70
- opt.setAttribute('aria-checked', checked ? 'true' : 'false')
71
- opt.setAttribute('data-checked', checked ? 'true' : 'false')
72
- }
73
- }
74
-
75
- function onSelect(event) {
76
- event.stopPropagation()
77
- selectValue(event.detail)
78
- }
79
-
80
- // Options rendered from the `options` prop have no <RadioGroupOption> behind
81
- // them to dispatch stx:radio-select, so the group claims them by delegation.
82
- // One listener on the root rather than a handler per option, which also means
83
- // options added later are picked up with no re-binding.
84
- function optionValueOf(el) {
85
- try { return JSON.parse(el.dataset.optionValue ?? 'null') }
86
- catch { return el.dataset.optionValue }
87
- }
88
-
89
- function onDelegatedActivate(event) {
90
- const option = event.target.closest?.('[data-stx-radio-option]')
91
- if (!option || !rootEl || !rootEl.contains(option)) return
92
- if (option.getAttribute('aria-disabled') === 'true') return
93
- // A <RadioGroupOption> dispatches its own event; claiming its click too would
94
- // select twice and emit two change events.
95
- if (option.dataset.stxRadioDelegated !== 'true') return
96
- if (event.type === 'keydown' && event.key !== ' ' && event.key !== 'Enter') return
97
- event.preventDefault()
98
- selectValue(optionValueOf(option))
99
- }
100
-
101
- onMount(() => {
102
- rootEl = document.querySelector(`[data-radio-group-id="${radioGroupInstanceId}"]`)
103
- if (rootEl) {
104
- rootEl.addEventListener('click', onDelegatedActivate)
105
- rootEl.addEventListener('keydown', onDelegatedActivate)
106
- }
107
- syncOptionStates()
108
- })
109
-
110
- onDestroy(() => {
111
- if (!rootEl) return
112
- rootEl.removeEventListener('click', onDelegatedActivate)
113
- rootEl.removeEventListener('keydown', onDelegatedActivate)
114
- })
115
-
116
- defineExpose({ selected, selectValue })
117
- </script>
118
-
119
- <component
120
- :is="{{ as }}"
121
- class="{{ groupClasses }}"
122
- data-stx-radio-group
123
- data-radio-group-id="{{ radioGroupInstanceId }}"
124
- role="radiogroup"
125
- @stx:radio-select="onSelect($event)"
126
- >
127
- @if(hasPropOptions)
128
- @foreach(option in options)
129
- <div
130
- data-stx-radio-option
131
- data-stx-radio-delegated="true"
132
- data-option-value="{{ JSON.stringify(option.value === undefined ? null : option.value) }}"
133
- role="radio"
134
- aria-checked="{{ option.value === value ? 'true' : 'false' }}"
135
- data-checked="{{ option.value === value ? 'true' : 'false' }}"
136
- aria-disabled="{{ option.disabled ? 'true' : 'false' }}"
137
- tabindex="{{ option.disabled ? '-1' : '0' }}"
138
- class="{{ option.disabled ? optionDisabledClasses : optionClasses }}"
139
- >
140
- <span class="flex flex-col">
141
- <span class="text-sm font-medium">{{ option.label }}</span>
142
- @if(option.description)
143
- <span class="text-sm opacity-70">{{ option.description }}</span>
144
- @endif
145
- </span>
146
- </div>
147
- @endforeach
148
- @else
149
- <slot />
150
- @endif
151
- </component>