@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
@@ -23,10 +23,12 @@ The markup goes into an `<iframe srcdoc>` with a `sandbox` attribute.
23
23
  navigation and popups are never granted. Links are sent to a new window,
24
24
  which the sandbox refuses, so a click cannot navigate the preview away.
25
25
  - **Colour scheme.** The scheme is set on the frame element, as its
26
- `color-scheme`, on the host's side. An engine that hands a frame's
27
- `color-scheme` to the page inside gives that page its
28
- `prefers-color-scheme` from it, with no script and no cooperation, and a
29
- change does not reload it. Chromium does. WebKit does not: see Limits.
26
+ `color-scheme`, on the host's side. Chromium hands a frame's `color-scheme`
27
+ to the page inside as its `prefers-color-scheme`, so there the page follows
28
+ with no script and no cooperation, and a change does not reload it. WebKit
29
+ (Safari, and a Craft window, which is a WKWebView) does not, so there the
30
+ scheme is written into the document instead: see Limits. Which of the two
31
+ an engine does is asked of it once, with a frame of the host's own.
30
32
  - **Viewport.** The frame is laid out at the device's real size and drawn
31
33
  smaller to fit, so the page's own media queries see 390 pixels for a phone
32
34
  whatever the box is. It is never enlarged.
@@ -103,13 +105,13 @@ the ground a device sits on), `--stx-preview-line` (`line`),
103
105
  its title or its errors. With `scripts` on, a page can `postMessage` its
104
106
  parent and the host can listen for it.
105
107
  - **No device chrome, pixel ratio or touch emulation.** A viewport is a size.
106
- - **The scheme reaches the page only where the engine passes it on.** In
107
- Chromium the page's `prefers-color-scheme` follows the frame, and a change
108
- fires the page's `change` listeners. In WebKit (Safari, and a Craft window,
109
- which is a WKWebView) the page always sees the system scheme: measured on
110
- macOS 26.3.1, a frame drawn `light` on a dark system reported dark at load
111
- and 1.5 seconds later, and a page that declares both schemes was still drawn
112
- dark. There the `scheme` prop, the toolbar button and the `@scheme` event
113
- change the frame element and nothing inside it. A preview that has to show
114
- one scheme on every engine needs markup that does not depend on the media
115
- query (stacksjs/stx#2186).
108
+ - **In WebKit the scheme is written into the page, with what that costs.**
109
+ Every `(prefers-color-scheme: …)` in the markup's style sheets, `media`
110
+ attributes and scripts is settled to the scheme asked for, and the root is
111
+ given that `color-scheme`. So: a change of scheme loads the page again
112
+ (its scroll position and anything typed into it are lost, and `@load` fires
113
+ again); a style sheet the page fetches from elsewhere is not rewritten and
114
+ still follows the system; and a script sees a `matchMedia` that never
115
+ changes. A preview left on `auto` under a host with no `dark` or `light`
116
+ class is not touched: its page follows the system by itself. Chromium needs
117
+ none of this and gets none of it (stacksjs/stx#2186).
@@ -146,6 +146,51 @@ const HAS_COLOR_SCHEME = /<meta[^>]+name\s*=\s*["']?color-scheme/i
146
146
  export interface DocumentOptions {
147
147
  /** The title of a document built around a fragment. */
148
148
  title?: string
149
+ /**
150
+ * Write this scheme into the document, for an engine that does not hand a
151
+ * frame's `color-scheme` to the page inside it. See `forceColorScheme`.
152
+ */
153
+ forceScheme?: 'light' | 'dark'
154
+ }
155
+
156
+ const SCHEME_FEATURE = /\(\s*prefers-color-scheme\s*:\s*(light|dark)\s*\)/gi
157
+ const STYLE_OR_SCRIPT = /(<(style|script)\b[^>]*>)([\s\S]*?)(<\/\2\s*>)/gi
158
+ const MEDIA_ATTRIBUTE = /(\smedia\s*=\s*)("[^"]*"|'[^']*')/gi
159
+ /** Always true, and always false in any frame wide enough to show a page. */
160
+ const ALWAYS = '(min-width: 0px)'
161
+ const NEVER = '(max-width: 0px)'
162
+
163
+ /**
164
+ * A document that answers for one colour scheme whatever the system prefers.
165
+ *
166
+ * Chromium hands a frame's `color-scheme` to its page; WebKit does not, so in
167
+ * Safari and in a Craft window the page keeps the system's scheme and a
168
+ * preview asked for `light` on a dark Mac was drawn dark (stacksjs/stx#2186).
169
+ * Nothing set on the frame from outside reaches a sandboxed page there, so the
170
+ * scheme is written into the page instead:
171
+ *
172
+ * - every `(prefers-color-scheme: …)` in a style sheet, a `media` attribute or
173
+ * a script is replaced by a condition that is always true or always false,
174
+ * so the page's own rules, and a `matchMedia` it calls, answer for the
175
+ * scheme asked for;
176
+ * - the root is given that `color-scheme`, so the canvas, form controls,
177
+ * system colours and `light-dark()` follow it too.
178
+ *
179
+ * Text is left alone: a page that shows the words "prefers-color-scheme" to
180
+ * its reader keeps them. A style sheet the page loads from elsewhere is not
181
+ * rewritten, since only the markup is in hand.
182
+ */
183
+ export function forceColorScheme(html: string, scheme: 'light' | 'dark'): string {
184
+ const settle = (text: string): string => text.replace(SCHEME_FEATURE, (_, asked: string) => asked.toLowerCase() === scheme ? ALWAYS : NEVER)
185
+ const rewritten = html
186
+ .replace(STYLE_OR_SCRIPT, (_, open: string, _tag: string, body: string, close: string) => open + settle(body) + close)
187
+ .replace(MEDIA_ATTRIBUTE, (_, name: string, value: string) => name + settle(value))
188
+ const rule = `<style data-stx-preview-scheme>:root{color-scheme:${scheme} !important}</style>`
189
+ if (HEAD_OPEN.test(rewritten))
190
+ return rewritten.replace(HEAD_OPEN, match => match + rule)
191
+ if (HTML_OPEN.test(rewritten))
192
+ return rewritten.replace(HTML_OPEN, match => `${match}<head>${rule}</head>`)
193
+ return rule + rewritten
149
194
  }
150
195
 
151
196
  function escapeHtml(text: string): string {
@@ -165,6 +210,11 @@ function escapeHtml(text: string): string {
165
210
  * click cannot navigate the preview away from what is being previewed.
166
211
  */
167
212
  export function buildDocument(html: string | null | undefined, options: DocumentOptions = {}): string {
213
+ const built = wrapDocument(html, options)
214
+ return options.forceScheme ? forceColorScheme(built, options.forceScheme) : built
215
+ }
216
+
217
+ function wrapDocument(html: string | null | undefined, options: DocumentOptions): string {
168
218
  const source = html == null ? '' : String(html)
169
219
  const base = '<base target="_blank">'
170
220
 
@@ -15,10 +15,10 @@ export interface PreviewFrameProps {
15
15
  /** Turn a phone or tablet on its side. */
16
16
  landscape?: boolean
17
17
  /**
18
- * The colour scheme the frame is drawn with, which is what the page's
19
- * `prefers-color-scheme` reports in an engine that passes a frame's scheme
20
- * to its page (Chromium; WebKit reports the system's). `auto` (default)
21
- * follows the host page.
18
+ * What the page's `prefers-color-scheme` reports. `auto` (default) follows
19
+ * the host page. Carried by the frame where the engine allows it and
20
+ * written into the page where it does not (WebKit), where a change loads
21
+ * the page again.
22
22
  */
23
23
  scheme?: PreviewScheme
24
24
  /** Let the page's own scripts run. They get an origin of their own and cannot reach the host. Default off. */
@@ -45,6 +45,41 @@ export interface PreviewFrameCallbacks {
45
45
 
46
46
  const STAGE_PADDING = 16
47
47
 
48
+ const PREFERS_DARK = '(prefers-color-scheme: dark)'
49
+ let framesFollow: boolean | undefined
50
+
51
+ /**
52
+ * Whether this engine hands a frame's `color-scheme` to the page inside it.
53
+ *
54
+ * Asked of the engine once, with a frame of this page's own origin drawn in
55
+ * the scheme the system does not prefer: its page either reports that scheme
56
+ * (Chromium) or the system's (WebKit). An environment with no layout to ask,
57
+ * a DOM emulator, is taken at its word and left alone.
58
+ */
59
+ export function framePassesColorScheme(): boolean {
60
+ if (framesFollow !== undefined)
61
+ return framesFollow
62
+ try {
63
+ if (typeof matchMedia !== 'function' || !document.body)
64
+ return true
65
+ const systemDark = matchMedia(PREFERS_DARK).matches
66
+ const probe = document.createElement('iframe')
67
+ probe.setAttribute('aria-hidden', 'true')
68
+ probe.tabIndex = -1
69
+ probe.style.cssText = `position:absolute;width:1px;height:1px;border:0;opacity:0;pointer-events:none;color-scheme:${systemDark ? 'light' : 'dark'}`
70
+ document.body.appendChild(probe)
71
+ // Read after a layout, which is when the frame's style is settled.
72
+ void probe.offsetWidth
73
+ const seen = probe.contentWindow?.matchMedia?.(PREFERS_DARK).matches
74
+ probe.remove()
75
+ framesFollow = typeof seen === 'boolean' ? seen !== systemDark : true
76
+ }
77
+ catch {
78
+ framesFollow = true
79
+ }
80
+ return framesFollow
81
+ }
82
+
48
83
  export class PreviewFrameView {
49
84
  private html: string
50
85
  private viewportName: string
@@ -58,6 +93,8 @@ export class PreviewFrameView {
58
93
  private viewport: ResolvedViewport
59
94
  private scale = 1
60
95
  private frame: HTMLIFrameElement | null = null
96
+ /** The scheme written into the document on show, where the engine needs it written. */
97
+ private written: 'light' | 'dark' | undefined
61
98
  private readonly stage: HTMLElement
62
99
  private readonly device: HTMLElement
63
100
  private observer: ResizeObserver | null = null
@@ -142,7 +179,12 @@ export class PreviewFrameView {
142
179
  if (next === this.scheme)
143
180
  return
144
181
  this.scheme = next
145
- this.applyScheme()
182
+ // Where the scheme is written into the page, a different one is a
183
+ // different page: it is loaded again. Elsewhere the page is told in place.
184
+ if (this.schemeToWrite() !== this.written)
185
+ this.load()
186
+ else
187
+ this.applyScheme()
146
188
  this.reflect()
147
189
  this.callbacks.onScheme?.(this.getState())
148
190
  }
@@ -199,6 +241,19 @@ export class PreviewFrameView {
199
241
  return typeof matchMedia === 'function' && matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
200
242
  }
201
243
 
244
+ /**
245
+ * The scheme the document has to carry itself, or nothing when the engine
246
+ * carries it or the page already has it: a preview left on `auto` under a
247
+ * host with no scheme of its own follows the system, as its page does anyway.
248
+ */
249
+ private schemeToWrite(): 'light' | 'dark' | undefined {
250
+ if (framePassesColorScheme())
251
+ return undefined
252
+ if (this.scheme === 'auto' && !this.root.closest('.dark, .light'))
253
+ return undefined
254
+ return this.effectiveScheme()
255
+ }
256
+
202
257
  private load(): void {
203
258
  const frame = document.createElement('iframe')
204
259
  // Written before the frame is in the document and before it has content:
@@ -212,7 +267,8 @@ export class PreviewFrameView {
212
267
  if (frame === this.frame)
213
268
  this.callbacks.onLoad?.(this.getState())
214
269
  })
215
- frame.srcdoc = buildDocument(this.html, { title: this.title })
270
+ this.written = this.schemeToWrite()
271
+ frame.srcdoc = buildDocument(this.html, { title: this.title, forceScheme: this.written })
216
272
 
217
273
  this.frame?.remove()
218
274
  this.frame = frame
@@ -225,8 +281,9 @@ export class PreviewFrameView {
225
281
  * The scheme is set here, on the host's side, as the frame element's
226
282
  * `color-scheme`. Chromium hands that to the page as its
227
283
  * `prefers-color-scheme`, so the page follows with no script and no
228
- * cooperation. WebKit does not hand it over: there the page keeps the
229
- * system's scheme whatever is set here (stacksjs/stx#2186).
284
+ * cooperation. WebKit does not hand it over, so there the scheme is also
285
+ * written into the document when it is loaded (`schemeToWrite`,
286
+ * stacksjs/stx#2186).
230
287
  */
231
288
  private applyScheme(): void {
232
289
  const scheme = this.effectiveScheme()
@@ -137,3 +137,20 @@ function handleChange(plan) {
137
137
  - Disabled state support
138
138
  - Active state on focus
139
139
  - Customizable styling
140
+
141
+ ## Mac look
142
+
143
+ `variant="mac"` draws the radio buttons a Mac draws: a 15px circle beside each label, sunk when off and the accent around a white dot when on, 22px from one row to the next. Set it on the group, and on each `RadioGroupOption` written as a child (an option does not learn its look from the group).
144
+
145
+ ```html
146
+ <RadioGroup variant="mac" value="auto" :options="[{ value: 'auto', label: 'Automatically' }, { value: 'always', label: 'Always' }]" />
147
+
148
+ <RadioGroup variant="mac" value="page">
149
+ <RadioGroupOption variant="mac" value="page">Jump to the next page</RadioGroupOption>
150
+ <RadioGroupOption variant="mac" value="spot">Jump to the spot that's clicked</RadioGroupOption>
151
+ </RadioGroup>
152
+ ```
153
+
154
+ Roles, values, `@change` and the keys (Space or Enter chooses the focused option) are unchanged. `RadioGroupLabel` and `RadioGroupDescription` have no Mac look; under it an option's words are plain text.
155
+
156
+ Colours and type come from the `--stx-mac-*` custom properties (`src/utils/mac-theme.ts`), light and dark, so an app re-themes it by setting a variable. A window that is not the key window (`data-stx-window-active="false"` on an ancestor, or Craft's `data-craft-window-active`) draws it without colour. The inactive fill is `--stx-mac-radio-inactive`.
@@ -24,11 +24,24 @@ export const as = $props.as || 'div'
24
24
  export const options = Array.isArray($props.options) ? $props.options : []
25
25
  export const hasPropOptions = options.length > 0
26
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
+
27
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'
28
- export const optionClasses = optionBaseClasses
29
- export const optionDisabledClasses = `${optionBaseClasses} opacity-50 cursor-not-allowed`
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'
30
43
 
31
- const baseClasses = 'w-full'
44
+ const baseClasses = mac ? 'stx-mac-radio-group' : 'w-full'
32
45
  export const groupClasses = `${baseClasses} ${className}`.trim()
33
46
  export const radioGroupInstanceId = $uid
34
47
  </script>
@@ -137,10 +150,10 @@ defineExpose({ selected, selectValue })
137
150
  tabindex="{{ option.disabled ? '-1' : '0' }}"
138
151
  class="{{ option.disabled ? optionDisabledClasses : optionClasses }}"
139
152
  >
140
- <span class="flex flex-col">
141
- <span class="text-sm font-medium">{{ option.label }}</span>
153
+ <span class="{{ optionTextClasses }}">
154
+ <span class="{{ optionLabelClasses }}">{{ option.label }}</span>
142
155
  @if(option.description)
143
- <span class="text-sm opacity-70">{{ option.description }}</span>
156
+ <span class="{{ optionDescriptionClasses }}">{{ option.description }}</span>
144
157
  @endif
145
158
  </span>
146
159
  </div>
@@ -149,3 +162,168 @@ defineExpose({ selected, selectValue })
149
162
  <slot />
150
163
  @endif
151
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>
@@ -6,7 +6,14 @@ export const as = $props.as || 'div'
6
6
 
7
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
8
  const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
9
- export const optionClasses = `${baseClasses} ${disabledClasses} ${className}`.trim()
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()
10
17
  export const valueJson = JSON.stringify(value === undefined ? null : value)
11
18
  </script>
12
19
 
@@ -59,7 +66,76 @@ function onKey(event) {
59
66
  <slot :disabled="disabled" />
60
67
  </component>
61
68
 
62
- <style>
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
+
63
139
  [data-stx-radio-option][data-checked="true"] {
64
140
  background-color: rgb(30 58 138 / 0.75);
65
141
  color: white;
@@ -67,4 +143,104 @@ function onKey(event) {
67
143
  .dark [data-stx-radio-option][data-checked="true"] {
68
144
  background-color: rgb(30 64 175 / 1);
69
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
+ }
70
246
  </style>
@@ -8,6 +8,8 @@ export interface RadioGroupProps {
8
8
  onChange?: (value: any) => void
9
9
  className?: string
10
10
  as?: string
11
+ /** `'mac'` draws Mac radio buttons from the `--stx-mac-*` tokens. Child options take it too. */
12
+ variant?: 'mac'
11
13
  }
12
14
 
13
15
  export interface RadioGroupLabelProps {
@@ -18,6 +20,8 @@ export interface RadioGroupLabelProps {
18
20
  export interface RadioGroupOptionProps {
19
21
  value: any
20
22
  disabled?: boolean
23
+ /** `'mac'` draws the Mac radio button; set it on the group as well. */
24
+ variant?: 'mac'
21
25
  className?: string
22
26
  as?: string
23
27
  currentValue?: any