@stacksjs/components 0.2.865 → 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 (116) 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/preview-frame/preview-frame.js +58 -2
  24. package/dist/settings/settings.js +757 -0
  25. package/dist/ui/appearance-picker/AppearancePicker.d.ts +12 -0
  26. package/dist/ui/appearance-picker/index.d.ts +16 -0
  27. package/dist/ui/button/Button.d.ts +24 -1
  28. package/dist/ui/button/index.d.ts +1 -0
  29. package/dist/ui/checkbox/Checkbox.d.ts +9 -1
  30. package/dist/ui/checkbox/index.d.ts +1 -0
  31. package/dist/ui/color-swatches/ColorSwatches.d.ts +26 -0
  32. package/dist/ui/color-swatches/index.d.ts +18 -0
  33. package/dist/ui/input/NumberInput.d.ts +11 -1
  34. package/dist/ui/input/PasswordInput.d.ts +9 -1
  35. package/dist/ui/input/TextInput.d.ts +12 -1
  36. package/dist/ui/input/index.d.ts +7 -3
  37. package/dist/ui/preview-frame/core.d.ts +22 -0
  38. package/dist/ui/preview-frame/view.d.ts +9 -0
  39. package/dist/ui/radio-group/RadioGroup.d.ts +14 -2
  40. package/dist/ui/radio-group/RadioGroupOption.d.ts +6 -1
  41. package/dist/ui/radio-group/index.d.ts +2 -0
  42. package/dist/ui/segmented-control/SegmentedControl.d.ts +9 -1
  43. package/dist/ui/segmented-control/index.d.ts +1 -0
  44. package/dist/ui/select/Select.d.ts +10 -1
  45. package/dist/ui/select/index.d.ts +1 -0
  46. package/dist/ui/settings/SettingsGroup.d.ts +30 -0
  47. package/dist/ui/settings/SettingsPane.d.ts +19 -0
  48. package/dist/ui/settings/SettingsPaneHeader.d.ts +20 -0
  49. package/dist/ui/settings/SettingsRow.d.ts +53 -0
  50. package/dist/ui/settings/SettingsSidebarGroup.d.ts +11 -0
  51. package/dist/ui/settings/SettingsSidebarItem.d.ts +22 -0
  52. package/dist/ui/settings/SettingsWindow.d.ts +22 -0
  53. package/dist/ui/settings/core.d.ts +146 -0
  54. package/dist/ui/settings/index.d.ts +73 -0
  55. package/dist/ui/settings/settings.d.ts +8 -0
  56. package/dist/ui/settings/view.d.ts +36 -0
  57. package/dist/ui/slider/Slider.d.ts +24 -0
  58. package/dist/ui/slider/core.d.ts +33 -0
  59. package/dist/ui/slider/index.d.ts +20 -0
  60. package/dist/ui/switch/Switch.d.ts +10 -1
  61. package/dist/ui/switch/index.d.ts +2 -1
  62. package/dist/utils/mac-theme.d.ts +24 -0
  63. package/package.json +8 -3
  64. package/src/index.ts +6 -0
  65. package/src/ui/appearance-picker/AppearancePicker.stx +351 -0
  66. package/src/ui/appearance-picker/README.md +61 -0
  67. package/src/ui/appearance-picker/index.ts +22 -0
  68. package/src/ui/button/Button.stx +249 -0
  69. package/src/ui/button/README.md +21 -0
  70. package/src/ui/button/index.ts +8 -0
  71. package/src/ui/checkbox/Checkbox.stx +275 -0
  72. package/src/ui/checkbox/index.ts +2 -0
  73. package/src/ui/color-swatches/ColorSwatches.stx +287 -0
  74. package/src/ui/color-swatches/README.md +66 -0
  75. package/src/ui/color-swatches/index.ts +25 -0
  76. package/src/ui/input/NumberInput.stx +303 -0
  77. package/src/ui/input/PasswordInput.stx +315 -0
  78. package/src/ui/input/TextInput.stx +325 -0
  79. package/src/ui/input/index.ts +9 -3
  80. package/src/ui/preview-frame/README.md +16 -14
  81. package/src/ui/preview-frame/core.ts +50 -0
  82. package/src/ui/preview-frame/index.ts +4 -4
  83. package/src/ui/preview-frame/view.ts +61 -4
  84. package/src/ui/radio-group/README.md +17 -0
  85. package/src/ui/radio-group/RadioGroup.stx +184 -6
  86. package/src/ui/radio-group/RadioGroupOption.stx +178 -2
  87. package/src/ui/radio-group/index.ts +4 -0
  88. package/src/ui/segmented-control/SegmentedControl.stx +170 -1
  89. package/src/ui/segmented-control/index.ts +2 -0
  90. package/src/ui/select/README.md +12 -0
  91. package/src/ui/select/Select.stx +266 -0
  92. package/src/ui/select/index.ts +2 -0
  93. package/src/ui/settings/README.md +221 -0
  94. package/src/ui/settings/SettingsGroup.stx +200 -0
  95. package/src/ui/settings/SettingsPane.stx +50 -0
  96. package/src/ui/settings/SettingsPaneHeader.stx +188 -0
  97. package/src/ui/settings/SettingsRow.stx +424 -0
  98. package/src/ui/settings/SettingsSidebarGroup.stx +108 -0
  99. package/src/ui/settings/SettingsSidebarItem.stx +228 -0
  100. package/src/ui/settings/SettingsWindow.stx +537 -0
  101. package/src/ui/settings/core.ts +359 -0
  102. package/src/ui/settings/index.ts +111 -0
  103. package/src/ui/settings/settings.ts +8 -0
  104. package/src/ui/settings/view.ts +740 -0
  105. package/src/ui/slider/README.md +91 -0
  106. package/src/ui/slider/Slider.stx +377 -0
  107. package/src/ui/slider/core.ts +120 -0
  108. package/src/ui/slider/index.ts +34 -0
  109. package/src/ui/switch/README.md +11 -0
  110. package/src/ui/switch/Switch.stx +217 -0
  111. package/src/ui/switch/index.ts +4 -1
  112. package/src/utils/mac-theme.ts +95 -0
  113. package/dist/Checkbox-80myyzzm.stx +0 -142
  114. package/dist/RadioGroup-smqcqgds.stx +0 -151
  115. package/dist/RadioGroupOption-twcw1b2a.stx +0 -70
  116. package/dist/Switch-s8yf2rvm.stx +0 -157
@@ -0,0 +1,329 @@
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
+ /*
28
+ * `variant="mac"` draws the radio buttons a Mac draws: a 15px circle beside
29
+ * each label, sunk when off and the accent around a white dot when on, 22px
30
+ * from one row to the next. The roles, the values and the keys are the ones
31
+ * below; only the classes change, to `stx-mac-radio`, which this file's
32
+ * <style> block draws from the `--stx-mac-*` tokens. An option written as a
33
+ * <RadioGroupOption> child takes `variant="mac"` itself.
34
+ */
35
+ export const mac = $props.variant === 'mac'
36
+
37
+ 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'
38
+ export const optionClasses = mac ? 'stx-mac-radio' : optionBaseClasses
39
+ export const optionDisabledClasses = mac ? 'stx-mac-radio' : `${optionBaseClasses} opacity-50 cursor-not-allowed`
40
+ export const optionTextClasses = mac ? 'stx-mac-radio-text' : 'flex flex-col'
41
+ export const optionLabelClasses = mac ? 'stx-mac-radio-label' : 'text-sm font-medium'
42
+ export const optionDescriptionClasses = mac ? 'stx-mac-radio-description' : 'text-sm opacity-70'
43
+
44
+ const baseClasses = mac ? 'stx-mac-radio-group' : 'w-full'
45
+ export const groupClasses = `${baseClasses} ${className}`.trim()
46
+ export const radioGroupInstanceId = $uid
47
+ </script>
48
+
49
+ <script client>
50
+ const emit = defineEmits()
51
+ const radioGroupInstanceId = {{ radioGroupInstanceId }}
52
+ /*
53
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
54
+ * through an ordinary interpolation.
55
+ *
56
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
57
+ * token null into the script. An interpolation QUOTES a string, so what it
58
+ * emitted was the four-character string "null" -- truthy, in the one place a
59
+ * value is meant to be absent. JSON.stringify produces the correct literal for
60
+ * every type, null included, and raw interpolation passes it through unquoted.
61
+ * Calendar and DateRangePicker already avoid this sentinel and say why
62
+ * (stacksjs/stx#1981).
63
+ */
64
+ const initialValue = {!! valueJson !!}
65
+ const selected = state(initialValue)
66
+ let rootEl = null
67
+
68
+ function selectValue(v) {
69
+ selected.set(v)
70
+ syncOptionStates()
71
+ emit('change', v)
72
+ }
73
+
74
+ function syncOptionStates() {
75
+ if (!rootEl) return
76
+ const options = rootEl.querySelectorAll('[data-stx-radio-option]')
77
+ for (const opt of options) {
78
+ const raw = opt.dataset.optionValue
79
+ let v
80
+ try { v = JSON.parse(raw ?? 'null') }
81
+ catch { v = raw }
82
+ const checked = selected() === v
83
+ opt.setAttribute('aria-checked', checked ? 'true' : 'false')
84
+ opt.setAttribute('data-checked', checked ? 'true' : 'false')
85
+ }
86
+ }
87
+
88
+ function onSelect(event) {
89
+ event.stopPropagation()
90
+ selectValue(event.detail)
91
+ }
92
+
93
+ // Options rendered from the `options` prop have no <RadioGroupOption> behind
94
+ // them to dispatch stx:radio-select, so the group claims them by delegation.
95
+ // One listener on the root rather than a handler per option, which also means
96
+ // options added later are picked up with no re-binding.
97
+ function optionValueOf(el) {
98
+ try { return JSON.parse(el.dataset.optionValue ?? 'null') }
99
+ catch { return el.dataset.optionValue }
100
+ }
101
+
102
+ function onDelegatedActivate(event) {
103
+ const option = event.target.closest?.('[data-stx-radio-option]')
104
+ if (!option || !rootEl || !rootEl.contains(option)) return
105
+ if (option.getAttribute('aria-disabled') === 'true') return
106
+ // A <RadioGroupOption> dispatches its own event; claiming its click too would
107
+ // select twice and emit two change events.
108
+ if (option.dataset.stxRadioDelegated !== 'true') return
109
+ if (event.type === 'keydown' && event.key !== ' ' && event.key !== 'Enter') return
110
+ event.preventDefault()
111
+ selectValue(optionValueOf(option))
112
+ }
113
+
114
+ onMount(() => {
115
+ rootEl = document.querySelector(`[data-radio-group-id="${radioGroupInstanceId}"]`)
116
+ if (rootEl) {
117
+ rootEl.addEventListener('click', onDelegatedActivate)
118
+ rootEl.addEventListener('keydown', onDelegatedActivate)
119
+ }
120
+ syncOptionStates()
121
+ })
122
+
123
+ onDestroy(() => {
124
+ if (!rootEl) return
125
+ rootEl.removeEventListener('click', onDelegatedActivate)
126
+ rootEl.removeEventListener('keydown', onDelegatedActivate)
127
+ })
128
+
129
+ defineExpose({ selected, selectValue })
130
+ </script>
131
+
132
+ <component
133
+ :is="{{ as }}"
134
+ class="{{ groupClasses }}"
135
+ data-stx-radio-group
136
+ data-radio-group-id="{{ radioGroupInstanceId }}"
137
+ role="radiogroup"
138
+ @stx:radio-select="onSelect($event)"
139
+ >
140
+ @if(hasPropOptions)
141
+ @foreach(option in options)
142
+ <div
143
+ data-stx-radio-option
144
+ data-stx-radio-delegated="true"
145
+ data-option-value="{{ JSON.stringify(option.value === undefined ? null : option.value) }}"
146
+ role="radio"
147
+ aria-checked="{{ option.value === value ? 'true' : 'false' }}"
148
+ data-checked="{{ option.value === value ? 'true' : 'false' }}"
149
+ aria-disabled="{{ option.disabled ? 'true' : 'false' }}"
150
+ tabindex="{{ option.disabled ? '-1' : '0' }}"
151
+ class="{{ option.disabled ? optionDisabledClasses : optionClasses }}"
152
+ >
153
+ <span class="{{ optionTextClasses }}">
154
+ <span class="{{ optionLabelClasses }}">{{ option.label }}</span>
155
+ @if(option.description)
156
+ <span class="{{ optionDescriptionClasses }}">{{ option.description }}</span>
157
+ @endif
158
+ </span>
159
+ </div>
160
+ @endforeach
161
+ @else
162
+ <slot />
163
+ @endif
164
+ </component>
165
+
166
+ <style data-native-exclude>
167
+ :where(:root) {
168
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
169
+ --stx-mac-font-size: 13px;
170
+ --stx-mac-font-size-small: 11px;
171
+ --stx-mac-hairline: 0.5px;
172
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
173
+ --stx-mac-card-radius: 12px;
174
+ --stx-mac-control-radius: 6px;
175
+ --stx-mac-row-height: 38px;
176
+ --stx-mac-row-inset: 10px;
177
+ --stx-mac-sidebar-width: 226px;
178
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
179
+ --stx-mac-accent-ink: #ffffff;
180
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
181
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
182
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
183
+ --stx-mac-window: #ffffff;
184
+ --stx-mac-sidebar: #f2f1f0;
185
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
186
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
187
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
188
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
189
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
190
+ --stx-mac-control: #ffffff;
191
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
192
+ --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);
193
+ --stx-mac-switch-on: #34c759;
194
+ --stx-mac-knob: #ffffff;
195
+ --stx-mac-danger: #ff3b30;
196
+ }
197
+ :where(.dark) {
198
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
199
+ --stx-mac-accent-ink: #ffffff;
200
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
201
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
202
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
203
+ --stx-mac-window: #1e1e1e;
204
+ --stx-mac-sidebar: #2a2a2a;
205
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
206
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
207
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
208
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
209
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
210
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
211
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
212
+ --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);
213
+ --stx-mac-switch-on: #30d158;
214
+ --stx-mac-knob: #ffffff;
215
+ --stx-mac-danger: #ff453a;
216
+ }
217
+ @media (max-resolution: 1.5dppx) {
218
+ :where(:root) {
219
+ --stx-mac-hairline: 1px;
220
+ }
221
+ }
222
+ @media (prefers-contrast: more) {
223
+ :where(:root) {
224
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
225
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
226
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
227
+ --stx-mac-hairline: 1px;
228
+ }
229
+ :where(.dark) {
230
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
231
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
232
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
233
+ }
234
+ }
235
+
236
+ .stx-mac-radio-group {
237
+ display: flex;
238
+ flex-direction: column;
239
+ font-family: var(--stx-mac-font);
240
+ font-size: var(--stx-mac-font-size);
241
+ letter-spacing: -0.08px;
242
+ -webkit-font-smoothing: antialiased;
243
+ color: var(--stx-mac-ink);
244
+ cursor: default;
245
+ -webkit-user-select: none;
246
+ user-select: none;
247
+ }
248
+
249
+ .stx-mac-radio.stx-mac-radio {
250
+ --stx-mac-radio-inactive: color-mix(in srgb, var(--stx-mac-ink) 16%, transparent);
251
+ position: relative;
252
+ display: flex;
253
+ align-items: flex-start;
254
+ gap: 8px;
255
+ box-sizing: border-box;
256
+ min-height: 22px;
257
+ padding: 3px 0;
258
+ line-height: 16px;
259
+ background: transparent;
260
+ outline: none;
261
+ font-family: var(--stx-mac-font);
262
+ font-size: var(--stx-mac-font-size);
263
+ letter-spacing: -0.08px;
264
+ -webkit-font-smoothing: antialiased;
265
+ color: var(--stx-mac-ink);
266
+ cursor: default;
267
+ -webkit-user-select: none;
268
+ user-select: none;
269
+ }
270
+
271
+ /* The circle: sunk when off, the accent around a white dot when on. */
272
+ .stx-mac-radio::before {
273
+ content: '';
274
+ flex: none;
275
+ box-sizing: border-box;
276
+ width: 15px;
277
+ height: 15px;
278
+ margin-top: 0.5px;
279
+ border-radius: 50%;
280
+ background-color: var(--stx-mac-well);
281
+ transition: background-color 150ms ease;
282
+ }
283
+
284
+ .stx-mac-radio[aria-checked='true']::before {
285
+ background-color: var(--stx-mac-accent);
286
+ background-image: radial-gradient(circle, var(--stx-mac-accent-ink) 0 2.5px, transparent 3px);
287
+ }
288
+
289
+ .stx-mac-radio:focus-visible::before {
290
+ box-shadow: var(--stx-mac-focus-ring);
291
+ }
292
+
293
+ .stx-mac-radio[aria-disabled='true'] {
294
+ opacity: 0.5;
295
+ }
296
+
297
+ .stx-mac-radio-text {
298
+ display: flex;
299
+ flex-direction: column;
300
+ gap: 1px;
301
+ min-width: 0;
302
+ }
303
+
304
+ .stx-mac-radio-description {
305
+ font-size: var(--stx-mac-font-size-small);
306
+ line-height: 14px;
307
+ letter-spacing: 0;
308
+ color: var(--stx-mac-ink-secondary);
309
+ }
310
+
311
+ /* A window that is not the key window draws its controls without colour. */
312
+ :where([data-stx-window-active='false']) .stx-mac-radio[aria-checked='true']::before,
313
+ :root[data-craft-window-active='false'] .stx-mac-radio[aria-checked='true']::before {
314
+ background-color: var(--stx-mac-radio-inactive);
315
+ background-image: radial-gradient(circle, var(--stx-mac-ink) 0 2.5px, transparent 3px);
316
+ }
317
+
318
+ @media (prefers-reduced-motion: reduce) {
319
+ .stx-mac-radio::before {
320
+ transition: none;
321
+ }
322
+ }
323
+
324
+ @media (prefers-contrast: more) {
325
+ .stx-mac-radio:not([aria-checked='true'])::before {
326
+ box-shadow: inset 0 0 0 1px var(--stx-mac-control-line);
327
+ }
328
+ }
329
+ </style>
@@ -0,0 +1,246 @@
1
+ <script server>
2
+ export const value = $props.value
3
+ export const disabled = $bool($props.disabled)
4
+ export const className = $props.className || ''
5
+ export const as = $props.as || 'div'
6
+
7
+ const baseClasses = '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'
8
+ const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
9
+ /*
10
+ * `variant="mac"`: the radio button a Mac draws, a 15px circle beside the
11
+ * words. See RadioGroup, which takes the same prop for the group.
12
+ */
13
+ export const mac = $props.variant === 'mac'
14
+ export const optionClasses = mac
15
+ ? `stx-mac-radio ${className}`.trim()
16
+ : `${baseClasses} ${disabledClasses} ${className}`.trim()
17
+ export const valueJson = JSON.stringify(value === undefined ? null : value)
18
+ </script>
19
+
20
+ <script client>
21
+ const isDisabled = {{ disabled }}
22
+ /*
23
+ * JSON built on the server and emitted raw, rather than a 'null' sentinel
24
+ * through an ordinary interpolation.
25
+ *
26
+ * A `value === undefined ? 'null' : value` ternary was meant to put the bare
27
+ * token null into the script. An interpolation QUOTES a string, so what it
28
+ * emitted was the four-character string "null" -- truthy, in the one place a
29
+ * value is meant to be absent. JSON.stringify produces the correct literal for
30
+ * every type, null included, and raw interpolation passes it through unquoted.
31
+ * Calendar and DateRangePicker already avoid this sentinel and say why
32
+ * (stacksjs/stx#1981).
33
+ */
34
+ const optionValue = {!! valueJson !!}
35
+
36
+ function onClick(event) {
37
+ if (isDisabled) return
38
+ event.currentTarget.dispatchEvent(
39
+ new CustomEvent('stx:radio-select', { bubbles: true, detail: optionValue }),
40
+ )
41
+ }
42
+
43
+ function onKey(event) {
44
+ if (isDisabled) return
45
+ if (event.key === ' ' || event.key === 'Enter') {
46
+ event.preventDefault()
47
+ event.currentTarget.dispatchEvent(
48
+ new CustomEvent('stx:radio-select', { bubbles: true, detail: optionValue }),
49
+ )
50
+ }
51
+ }
52
+ </script>
53
+
54
+ <component
55
+ :is="{{ as }}"
56
+ class="{{ optionClasses }}"
57
+ data-stx-radio-option
58
+ data-option-value="{{ valueJson }}"
59
+ role="radio"
60
+ aria-checked="false"
61
+ @if(disabled)aria-disabled="true"@endif
62
+ tabindex="{{ disabled ? '-1' : '0' }}"
63
+ @click="onClick($event)"
64
+ @keydown="onKey($event)"
65
+ >
66
+ <slot :disabled="disabled" />
67
+ </component>
68
+
69
+ <style data-native-exclude>
70
+ :where(:root) {
71
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
72
+ --stx-mac-font-size: 13px;
73
+ --stx-mac-font-size-small: 11px;
74
+ --stx-mac-hairline: 0.5px;
75
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
76
+ --stx-mac-card-radius: 12px;
77
+ --stx-mac-control-radius: 6px;
78
+ --stx-mac-row-height: 38px;
79
+ --stx-mac-row-inset: 10px;
80
+ --stx-mac-sidebar-width: 226px;
81
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
82
+ --stx-mac-accent-ink: #ffffff;
83
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
84
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
85
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
86
+ --stx-mac-window: #ffffff;
87
+ --stx-mac-sidebar: #f2f1f0;
88
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
89
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
90
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
91
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
92
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
93
+ --stx-mac-control: #ffffff;
94
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
95
+ --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);
96
+ --stx-mac-switch-on: #34c759;
97
+ --stx-mac-knob: #ffffff;
98
+ --stx-mac-danger: #ff3b30;
99
+ }
100
+ :where(.dark) {
101
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
102
+ --stx-mac-accent-ink: #ffffff;
103
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
104
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
105
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
106
+ --stx-mac-window: #1e1e1e;
107
+ --stx-mac-sidebar: #2a2a2a;
108
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
109
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
110
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
111
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
112
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
113
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
114
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
115
+ --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);
116
+ --stx-mac-switch-on: #30d158;
117
+ --stx-mac-knob: #ffffff;
118
+ --stx-mac-danger: #ff453a;
119
+ }
120
+ @media (max-resolution: 1.5dppx) {
121
+ :where(:root) {
122
+ --stx-mac-hairline: 1px;
123
+ }
124
+ }
125
+ @media (prefers-contrast: more) {
126
+ :where(:root) {
127
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
128
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
129
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
130
+ --stx-mac-hairline: 1px;
131
+ }
132
+ :where(.dark) {
133
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
134
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
135
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
136
+ }
137
+ }
138
+
139
+ [data-stx-radio-option][data-checked="true"] {
140
+ background-color: rgb(30 58 138 / 0.75);
141
+ color: white;
142
+ }
143
+ .dark [data-stx-radio-option][data-checked="true"] {
144
+ background-color: rgb(30 64 175 / 1);
145
+ }
146
+
147
+ /* The chosen-card fill above is not a Mac radio's: the circle says it. */
148
+ .stx-mac-radio.stx-mac-radio[data-stx-radio-option][data-checked='true'] {
149
+ background-color: transparent;
150
+ color: var(--stx-mac-ink);
151
+ }
152
+
153
+ .stx-mac-radio-group {
154
+ display: flex;
155
+ flex-direction: column;
156
+ font-family: var(--stx-mac-font);
157
+ font-size: var(--stx-mac-font-size);
158
+ letter-spacing: -0.08px;
159
+ -webkit-font-smoothing: antialiased;
160
+ color: var(--stx-mac-ink);
161
+ cursor: default;
162
+ -webkit-user-select: none;
163
+ user-select: none;
164
+ }
165
+
166
+ .stx-mac-radio.stx-mac-radio {
167
+ --stx-mac-radio-inactive: color-mix(in srgb, var(--stx-mac-ink) 16%, transparent);
168
+ position: relative;
169
+ display: flex;
170
+ align-items: flex-start;
171
+ gap: 8px;
172
+ box-sizing: border-box;
173
+ min-height: 22px;
174
+ padding: 3px 0;
175
+ line-height: 16px;
176
+ background: transparent;
177
+ outline: none;
178
+ font-family: var(--stx-mac-font);
179
+ font-size: var(--stx-mac-font-size);
180
+ letter-spacing: -0.08px;
181
+ -webkit-font-smoothing: antialiased;
182
+ color: var(--stx-mac-ink);
183
+ cursor: default;
184
+ -webkit-user-select: none;
185
+ user-select: none;
186
+ }
187
+
188
+ /* The circle: sunk when off, the accent around a white dot when on. */
189
+ .stx-mac-radio::before {
190
+ content: '';
191
+ flex: none;
192
+ box-sizing: border-box;
193
+ width: 15px;
194
+ height: 15px;
195
+ margin-top: 0.5px;
196
+ border-radius: 50%;
197
+ background-color: var(--stx-mac-well);
198
+ transition: background-color 150ms ease;
199
+ }
200
+
201
+ .stx-mac-radio[aria-checked='true']::before {
202
+ background-color: var(--stx-mac-accent);
203
+ background-image: radial-gradient(circle, var(--stx-mac-accent-ink) 0 2.5px, transparent 3px);
204
+ }
205
+
206
+ .stx-mac-radio:focus-visible::before {
207
+ box-shadow: var(--stx-mac-focus-ring);
208
+ }
209
+
210
+ .stx-mac-radio[aria-disabled='true'] {
211
+ opacity: 0.5;
212
+ }
213
+
214
+ .stx-mac-radio-text {
215
+ display: flex;
216
+ flex-direction: column;
217
+ gap: 1px;
218
+ min-width: 0;
219
+ }
220
+
221
+ .stx-mac-radio-description {
222
+ font-size: var(--stx-mac-font-size-small);
223
+ line-height: 14px;
224
+ letter-spacing: 0;
225
+ color: var(--stx-mac-ink-secondary);
226
+ }
227
+
228
+ /* A window that is not the key window draws its controls without colour. */
229
+ :where([data-stx-window-active='false']) .stx-mac-radio[aria-checked='true']::before,
230
+ :root[data-craft-window-active='false'] .stx-mac-radio[aria-checked='true']::before {
231
+ background-color: var(--stx-mac-radio-inactive);
232
+ background-image: radial-gradient(circle, var(--stx-mac-ink) 0 2.5px, transparent 3px);
233
+ }
234
+
235
+ @media (prefers-reduced-motion: reduce) {
236
+ .stx-mac-radio::before {
237
+ transition: none;
238
+ }
239
+ }
240
+
241
+ @media (prefers-contrast: more) {
242
+ .stx-mac-radio:not([aria-checked='true'])::before {
243
+ box-shadow: inset 0 0 0 1px var(--stx-mac-control-line);
244
+ }
245
+ }
246
+ </style>