@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,417 @@
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
+ * `variant="mac"` draws the checkbox a Mac draws: a 14px box with 4px corners,
18
+ * sunk into the page when off and filled with the accent when on. It is the
19
+ * same <input type="checkbox">, so the form value, the label and the keyboard
20
+ * are the browser's own; only the classes change, to `stx-mac-checkbox`,
21
+ * which this file's <style> block draws from the `--stx-mac-*` tokens.
22
+ */
23
+ export const mac = $props.variant === 'mac'
24
+
25
+ const sizeClasses = { sm: 'h-4 w-4', md: 'h-5 w-5', lg: 'h-6 w-6' }
26
+ const baseClasses = 'rounded border-line-strong text-accent focus:ring-accent focus:ring-2 focus:ring-offset-2 focus:ring-offset-panel transition-colors'
27
+ /*
28
+ * The two halves of the validity state, exported so the CLIENT can swap them
29
+ * (stacksjs/stx#2047). Toggled per class rather than as a whole string,
30
+ * because a reactive class string MERGES with the static one and the element
31
+ * would carry both rings at once.
32
+ */
33
+ export const stateInvalidClasses = 'border-danger-line text-danger focus:ring-danger-focus'
34
+ const stateClasses = error ? stateInvalidClasses : ''
35
+ const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'
36
+
37
+ /*
38
+ * On a native host ($native) the box is the platform's own control, tinted
39
+ * system blue (red while invalid), beside a label at the 17pt body size.
40
+ */
41
+ const nativeTint = error ? 'text-danger' : 'text-accent'
42
+ export const checkboxClasses = $native
43
+ ? `h-[22px] w-[22px] ${nativeTint} disabled:opacity-50`
44
+ : switchAppearance
45
+ ? `shrink-0 cursor-pointer ${disabledClasses}`.trim()
46
+ : `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses}`.trim()
47
+ export const labelClasses = $native
48
+ ? `text-[17px] ${error ? 'text-[#ff3b30] dark:text-[#ff453a]' : 'text-[#000000] dark:text-[#ffffff]'} ${disabled ? 'opacity-50' : ''}`.trim()
49
+ : `text-sm font-medium ${error ? 'text-danger' : 'text-fg'} ${disabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}`.trim()
50
+ export const descriptionClasses = $native
51
+ ? 'text-[15px] text-[#6d6d72] dark:text-[#8d8d93]'
52
+ : `text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
53
+ /*
54
+ * Ids unique to this instance.
55
+ *
56
+ * These were derived from the LABEL or hardcoded outright, so two of these on
57
+ * one page -- an ordinary form -- emitted the same id twice. `<label for>`
58
+ * then activated the FIRST field from every label, and `aria-describedby`
59
+ * pointed every field's description at the first one's helper text. A label
60
+ * containing a space also produced an invalid id, `input-First name`, which
61
+ * getElementById and querySelector cannot address at all.
62
+ *
63
+ * `$uid` is unique per instance and stable across renders, which is what an id
64
+ * has to be (utils.ts explains why a render that changes its own bytes is
65
+ * uncacheable). The `id` prop overrides it, for a caller that needs to point
66
+ * its own `for` or `aria-describedby` at this control.
67
+ */
68
+ export const inputId = $props.id || `checkbox-${$uid}`
69
+ export const descriptionId = `${inputId}-description`
70
+ /*
71
+ * `autocomplete` and `form`, alongside the `name` this already had
72
+ * (stacksjs/stx#2043). `autocomplete` is how the browser and a password
73
+ * manager identify a field; `form` lets a control live outside the <form>
74
+ * element it belongs to. Emitted only when given.
75
+ */
76
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
77
+ export const form = $props.form || ''
78
+ </script>
79
+
80
+ <script client>
81
+ const emit = defineEmits(['change'])
82
+ // Validity is live, for the same reason `disabled` is: a form posted with
83
+ // fetch learns it after the submit, and nothing re-renders (#2047).
84
+ const isError = useReactiveProp('error', {{ error }})
85
+ const isDisabled = useReactiveProp('disabled', {{ disabled }})
86
+ const isIndeterminate = useReactiveProp('indeterminate', {{ indeterminate }})
87
+ // Reactive prop binding so the parent can drive `checked` via signals.
88
+ // See stacksjs/stx#1704.
89
+ const isChecked = useReactiveProp('checked', {{ checked }})
90
+ const currentLabel = useReactiveProp('label', {{ label }}, { parse: value => value ?? '' })
91
+
92
+ function onInputChange(event) {
93
+ if (isDisabled()) {
94
+ event.target.checked = isChecked()
95
+ return
96
+ }
97
+ isChecked.set(event.target.checked)
98
+ emit('change', isChecked())
99
+ }
100
+
101
+ defineExpose({ isChecked })
102
+ </script>
103
+
104
+ @if(mac)
105
+ <div class="stx-mac-checkbox-row {{ className }}">
106
+ <span class="stx-mac-checkbox-box">
107
+ <input
108
+ data-stx-native-host-root
109
+ id="{{ inputId }}"
110
+ type="checkbox"
111
+ @if(switchAppearance)switch role="switch"@endif
112
+ name="{{ name }}"
113
+ @if(label)aria-label="{{ label }}"@endif
114
+ :aria-label="currentLabel() || null"
115
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
116
+ @if(form)form="{{ form }}"@endif
117
+ value="{{ value }}"
118
+ @if(checked)checked@endif
119
+ :checked="isChecked()"
120
+ @if(disabled)disabled@endif
121
+ :disabled="isDisabled()"
122
+ :indeterminate="isIndeterminate()"
123
+ @if(required)required@endif
124
+ class="stx-mac-checkbox"
125
+ @change="onInputChange($event)"
126
+ aria-invalid="{{ error ? 'true' : 'false' }}"
127
+ :aria-invalid="isError() ? 'true' : 'false'"
128
+ @if(description)aria-describedby="{{ descriptionId }}"@endif
129
+ />
130
+ {{-- The tick, and the dash of a mixed state. A sibling rather than a
131
+ pseudo-element of the input, which not every engine draws. --}}
132
+ <span class="stx-mac-checkbox-mark" aria-hidden="true"></span>
133
+ </span>
134
+
135
+ <div :if="currentLabel() || {{ !!description }}" class="stx-mac-checkbox-text">
136
+ <label :if="currentLabel()" for="{{ inputId }}" class="stx-mac-checkbox-label">
137
+ <span :text="currentLabel()">{{ label }}</span>
138
+ @if(required)
139
+ <span class="stx-mac-checkbox-required">*</span>
140
+ @endif
141
+ </label>
142
+ @if(description)
143
+ <p id="{{ descriptionId }}" class="stx-mac-checkbox-description">
144
+ {{ description }}
145
+ </p>
146
+ @endif
147
+ </div>
148
+ </div>
149
+ @else
150
+ <div class="relative flex items-start {{ className }}">
151
+ <div class="flex h-6 items-center">
152
+ <input
153
+ data-stx-native-host-root
154
+ id="{{ inputId }}"
155
+ type="checkbox"
156
+ @if(switchAppearance)switch role="switch"@endif
157
+ name="{{ name }}"
158
+ @if(label)aria-label="{{ label }}"@endif
159
+ :aria-label="currentLabel() || null"
160
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
161
+ @if(form)form="{{ form }}"@endif
162
+ value="{{ value }}"
163
+
164
+ {{-- The served checked state, alongside the binding that takes over on
165
+ hydration. `checked` as an attribute is defaultChecked: an UNCHECKED box
166
+ is not submitted at all, so with only `:checked` a server-rendered checked
167
+ control was absent from the POST entirely rather than merely empty. --}}
168
+ @if(checked)checked@endif
169
+ :checked="isChecked()"
170
+ @if(disabled)disabled@endif
171
+ :disabled="isDisabled()"
172
+ :indeterminate="isIndeterminate()"
173
+ @if(required)required@endif
174
+ class="{{ checkboxClasses }}"
175
+ @change="onInputChange($event)"
176
+ aria-invalid="{{ error ? 'true' : 'false' }}"
177
+ :aria-invalid="isError() ? 'true' : 'false'"
178
+ :class="{ '{{ stateInvalidClasses }}': isError(), 'opacity-50 cursor-not-allowed': isDisabled(), 'cursor-pointer': !isDisabled() }"
179
+ @if(description)aria-describedby="{{ descriptionId }}"@endif
180
+ />
181
+ </div>
182
+
183
+ <div :if="currentLabel() || {{ !!description }}" class="ml-3 text-sm leading-6">
184
+ <label :if="currentLabel()" for="{{ inputId }}" class="{{ labelClasses }} inline-flex flex-row items-center" :class="{ 'opacity-50 cursor-not-allowed': isDisabled(), 'cursor-pointer': !isDisabled() }">
185
+ <span :text="currentLabel()">{{ label }}</span>
186
+ @if(required)
187
+ <span class="text-danger ml-1">*</span>
188
+ @endif
189
+ </label>
190
+ @if(description)
191
+ <p id="{{ descriptionId }}" class="{{ descriptionClasses }}">
192
+ {{ description }}
193
+ </p>
194
+ @endif
195
+ </div>
196
+ </div>
197
+ @endif
198
+
199
+ <style data-native-exclude>
200
+ :where(:root) {
201
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
202
+ --stx-mac-font-size: 13px;
203
+ --stx-mac-font-size-small: 11px;
204
+ --stx-mac-hairline: 0.5px;
205
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
206
+ --stx-mac-card-radius: 12px;
207
+ --stx-mac-control-radius: 6px;
208
+ --stx-mac-row-height: 38px;
209
+ --stx-mac-row-inset: 10px;
210
+ --stx-mac-sidebar-width: 226px;
211
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
212
+ --stx-mac-accent-ink: #ffffff;
213
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
214
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
215
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
216
+ --stx-mac-window: #ffffff;
217
+ --stx-mac-sidebar: #f2f1f0;
218
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
219
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
220
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
221
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
222
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
223
+ --stx-mac-control: #ffffff;
224
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
225
+ --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);
226
+ --stx-mac-switch-on: #34c759;
227
+ --stx-mac-knob: #ffffff;
228
+ --stx-mac-danger: #ff3b30;
229
+ }
230
+ :where(.dark) {
231
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
232
+ --stx-mac-accent-ink: #ffffff;
233
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
234
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
235
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
236
+ --stx-mac-window: #1e1e1e;
237
+ --stx-mac-sidebar: #2a2a2a;
238
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
239
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
240
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
241
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
242
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
243
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
244
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
245
+ --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);
246
+ --stx-mac-switch-on: #30d158;
247
+ --stx-mac-knob: #ffffff;
248
+ --stx-mac-danger: #ff453a;
249
+ }
250
+ @media (max-resolution: 1.5dppx) {
251
+ :where(:root) {
252
+ --stx-mac-hairline: 1px;
253
+ }
254
+ }
255
+ @media (prefers-contrast: more) {
256
+ :where(:root) {
257
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
258
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
259
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
260
+ --stx-mac-hairline: 1px;
261
+ }
262
+ :where(.dark) {
263
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
264
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
265
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
266
+ }
267
+ }
268
+
269
+ .stx-mac-checkbox-row {
270
+ display: inline-flex;
271
+ align-items: flex-start;
272
+ gap: 8px;
273
+ line-height: 16px;
274
+ font-family: var(--stx-mac-font);
275
+ font-size: var(--stx-mac-font-size);
276
+ letter-spacing: -0.08px;
277
+ -webkit-font-smoothing: antialiased;
278
+ color: var(--stx-mac-ink);
279
+ cursor: default;
280
+ -webkit-user-select: none;
281
+ user-select: none;
282
+ }
283
+
284
+ .stx-mac-checkbox-box {
285
+ position: relative;
286
+ flex: none;
287
+ width: 14px;
288
+ height: 14px;
289
+ margin-top: 1px;
290
+ }
291
+
292
+ .stx-mac-checkbox {
293
+ --stx-mac-checkbox-inactive: color-mix(in srgb, var(--stx-mac-ink) 16%, transparent);
294
+ display: block;
295
+ box-sizing: border-box;
296
+ width: 14px;
297
+ height: 14px;
298
+ margin: 0;
299
+ padding: 0;
300
+ border: 0;
301
+ border-radius: 4px;
302
+ background: var(--stx-mac-well);
303
+ -webkit-appearance: none;
304
+ appearance: none;
305
+ cursor: default;
306
+ outline: none;
307
+ transition: background-color 150ms ease;
308
+ }
309
+
310
+ .stx-mac-checkbox:checked,
311
+ .stx-mac-checkbox:indeterminate {
312
+ background: var(--stx-mac-accent);
313
+ }
314
+
315
+ .stx-mac-checkbox-mark {
316
+ position: absolute;
317
+ inset: 0;
318
+ color: var(--stx-mac-accent-ink);
319
+ pointer-events: none;
320
+ }
321
+
322
+ .stx-mac-checkbox-mark::before {
323
+ content: '';
324
+ position: absolute;
325
+ top: 2px;
326
+ left: 4.75px;
327
+ box-sizing: border-box;
328
+ width: 4.5px;
329
+ height: 8px;
330
+ border: solid currentColor;
331
+ border-width: 0 1.5px 1.5px 0;
332
+ opacity: 0;
333
+ transform: rotate(45deg);
334
+ }
335
+
336
+ .stx-mac-checkbox:checked + .stx-mac-checkbox-mark::before {
337
+ opacity: 1;
338
+ }
339
+
340
+ .stx-mac-checkbox:indeterminate + .stx-mac-checkbox-mark::before {
341
+ top: 6.25px;
342
+ left: 3.5px;
343
+ width: 7px;
344
+ height: 1.5px;
345
+ border-width: 0 0 1.5px;
346
+ opacity: 1;
347
+ transform: none;
348
+ }
349
+
350
+ .stx-mac-checkbox:focus-visible {
351
+ box-shadow: var(--stx-mac-focus-ring);
352
+ }
353
+
354
+ .stx-mac-checkbox[aria-invalid='true'] {
355
+ box-shadow: inset 0 0 0 1px var(--stx-mac-danger);
356
+ }
357
+
358
+ .stx-mac-checkbox[aria-invalid='true']:focus-visible {
359
+ box-shadow: inset 0 0 0 1px var(--stx-mac-danger), var(--stx-mac-focus-ring);
360
+ }
361
+
362
+ .stx-mac-checkbox:disabled,
363
+ .stx-mac-checkbox:disabled + .stx-mac-checkbox-mark,
364
+ .stx-mac-checkbox-row:has(.stx-mac-checkbox:disabled) .stx-mac-checkbox-label {
365
+ opacity: 0.5;
366
+ }
367
+
368
+ .stx-mac-checkbox-text {
369
+ display: flex;
370
+ flex-direction: column;
371
+ gap: 1px;
372
+ min-width: 0;
373
+ }
374
+
375
+ .stx-mac-checkbox-label {
376
+ display: inline-flex;
377
+ gap: 3px;
378
+ cursor: default;
379
+ }
380
+
381
+ .stx-mac-checkbox-required {
382
+ color: var(--stx-mac-danger);
383
+ }
384
+
385
+ .stx-mac-checkbox-description {
386
+ margin: 0;
387
+ font-size: var(--stx-mac-font-size-small);
388
+ line-height: 14px;
389
+ letter-spacing: 0;
390
+ color: var(--stx-mac-ink-secondary);
391
+ }
392
+
393
+ /* A window that is not the key window draws its controls without colour. */
394
+ :where([data-stx-window-active='false']) .stx-mac-checkbox:checked,
395
+ :where([data-stx-window-active='false']) .stx-mac-checkbox:indeterminate,
396
+ :root[data-craft-window-active='false'] .stx-mac-checkbox:checked,
397
+ :root[data-craft-window-active='false'] .stx-mac-checkbox:indeterminate {
398
+ background: var(--stx-mac-checkbox-inactive);
399
+ }
400
+
401
+ :where([data-stx-window-active='false']) .stx-mac-checkbox-mark,
402
+ :root[data-craft-window-active='false'] .stx-mac-checkbox-mark {
403
+ color: var(--stx-mac-ink);
404
+ }
405
+
406
+ @media (prefers-reduced-motion: reduce) {
407
+ .stx-mac-checkbox {
408
+ transition: none;
409
+ }
410
+ }
411
+
412
+ @media (prefers-contrast: more) {
413
+ .stx-mac-checkbox:not(:checked):not(:indeterminate) {
414
+ box-shadow: inset 0 0 0 1px var(--stx-mac-control-line);
415
+ }
416
+ }
417
+ </style>
@@ -0,0 +1,287 @@
1
+ <script server>
2
+ /*
3
+ * <ColorSwatches>: a row of colour dots to pick one from, as System Settings
4
+ * draws its accent colours. The chosen dot has a ring around it and its name
5
+ * written underneath.
6
+ *
7
+ * <ColorSwatches v-model:value="accent" label="Accent colour" :options="[
8
+ * { value: 'multi', label: 'Multicolour', color: 'conic-gradient(red, orange, yellow, green, blue, purple, red)' },
9
+ * { value: 'blue', label: 'Blue', color: '#007aff' },
10
+ * ]" />
11
+ *
12
+ * `color` is any CSS colour or gradient. The dots are a radio group: one tab
13
+ * stop, the arrow keys move the choice, Home and End go to the ends.
14
+ * `change` is emitted with the new value.
15
+ */
16
+ export const value = $props.value == null ? '' : String($props.value)
17
+ export const options = Array.isArray($props.options) ? $props.options : []
18
+ export const label = $props.label || ''
19
+ export const disabled = $bool($props.disabled)
20
+ /* The chosen dot's name under it. Without it the row is only as tall as a dot. */
21
+ export const caption = $bool($props.caption, true)
22
+ export const swatchesId = $props.id || `color-swatches-${$uid}`
23
+ export const className = $props.className || ''
24
+ </script>
25
+
26
+ <script client>
27
+ const emit = defineEmits(['change'])
28
+ const chosen = useModel('value', { default: {{ value }}, parse: value => (value == null ? '' : String(value)) })
29
+ const choices = useReactiveProp('options', {{ options }})
30
+ const groupLabel = useReactiveProp('label', {{ label }})
31
+ const isDisabled = useReactiveProp('disabled', {{ disabled }})
32
+
33
+ /** A choice as `{ value, color, label, disabled }`. A bare string is a colour named after itself. */
34
+ function normalise(choice) {
35
+ if (choice !== null && typeof choice === 'object') {
36
+ const value = choice.value == null ? '' : String(choice.value)
37
+ return {
38
+ value,
39
+ color: String(choice.color ?? choice.colour ?? value),
40
+ label: choice.label == null ? value : String(choice.label),
41
+ disabled: choice.disabled === true,
42
+ }
43
+ }
44
+ const value = choice == null ? '' : String(choice)
45
+ return { value, color: value, label: value, disabled: false }
46
+ }
47
+
48
+ function swatches() {
49
+ const list = choices()
50
+ return Array.isArray(list) ? list.map(normalise) : []
51
+ }
52
+
53
+ const isOn = swatch => swatch.value === chosen()
54
+ const isOff = swatch => isDisabled() || swatch.disabled
55
+
56
+ /** The one dot Tab lands on: the chosen one, or the first that can be chosen. */
57
+ function isTabStop(swatch) {
58
+ const list = swatches()
59
+ const current = list.find(item => isOn(item) && !isOff(item)) || list.find(item => !isOff(item))
60
+ return Boolean(current) && current.value === swatch.value
61
+ }
62
+
63
+ function choose(swatch) {
64
+ if (isOff(swatch) || isOn(swatch)) return
65
+ chosen.set(swatch.value)
66
+ emit('change', swatch.value)
67
+ }
68
+
69
+ function onKey(event, swatch) {
70
+ if (event.metaKey || event.ctrlKey || event.altKey) return
71
+ if (event.key === ' ' || event.key === 'Enter') {
72
+ event.preventDefault()
73
+ choose(swatch)
74
+ return
75
+ }
76
+ const list = swatches()
77
+ const open = list.filter(item => !isOff(item))
78
+ const at = open.findIndex(item => item.value === swatch.value)
79
+ if (open.length === 0 || at === -1) return
80
+
81
+ let next = -1
82
+ if (event.key === 'ArrowRight' || event.key === 'ArrowDown') next = (at + 1) % open.length
83
+ else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') next = (at - 1 + open.length) % open.length
84
+ else if (event.key === 'Home') next = 0
85
+ else if (event.key === 'End') next = open.length - 1
86
+ if (next === -1) return
87
+
88
+ event.preventDefault()
89
+ const target = open[next]
90
+ choose(target)
91
+ const group = event.currentTarget.parentElement
92
+ const dots = group ? Array.from(group.querySelectorAll('[role="radio"]')) : []
93
+ const dot = dots.find(item => item.getAttribute('data-value') === target.value)
94
+ if (dot) dot.focus()
95
+ }
96
+
97
+ defineExpose({ value: chosen })
98
+ </script>
99
+
100
+ <div
101
+ id="{{ swatchesId }}"
102
+ role="radiogroup"
103
+ data-stx-color-swatches
104
+ @if(caption)data-caption@endif
105
+ @if(label)aria-label="{{ label }}"@endif
106
+ :aria-label="groupLabel() || null"
107
+ :aria-disabled="isDisabled() ? 'true' : null"
108
+ class="stx-color-swatches {{ className }}"
109
+ >
110
+ <button
111
+ :for="swatch in swatches()"
112
+ :key="swatch.value"
113
+ type="button"
114
+ role="radio"
115
+ class="stx-color-swatch"
116
+ :data-value="swatch.value"
117
+ :aria-checked="isOn(swatch) ? 'true' : 'false'"
118
+ :aria-label="swatch.label"
119
+ :tabindex="isTabStop(swatch) ? 0 : -1"
120
+ :disabled="isOff(swatch)"
121
+ :style="'--stx-swatch-color: ' + swatch.color"
122
+ @click="choose(swatch)"
123
+ @keydown="onKey($event, swatch)"
124
+ ><span class="stx-color-swatch-dot"></span><span class="stx-color-swatch-caption" aria-hidden="true" :text="swatch.label"></span></button>
125
+ </div>
126
+
127
+ <style data-native-exclude>
128
+ :where(:root) {
129
+ --stx-mac-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI Variable Text', 'Segoe UI', system-ui, Roboto, 'Helvetica Neue', sans-serif;
130
+ --stx-mac-font-size: 13px;
131
+ --stx-mac-font-size-small: 11px;
132
+ --stx-mac-hairline: 0.5px;
133
+ --stx-mac-focus-ring: 0 0 0 3px color-mix(in srgb, var(--stx-mac-accent) 35%, transparent);
134
+ --stx-mac-card-radius: 12px;
135
+ --stx-mac-control-radius: 6px;
136
+ --stx-mac-row-height: 38px;
137
+ --stx-mac-row-inset: 10px;
138
+ --stx-mac-sidebar-width: 226px;
139
+ --stx-mac-accent: var(--stx-accent, rgb(0, 122, 255));
140
+ --stx-mac-accent-ink: #ffffff;
141
+ --stx-mac-ink: rgba(0, 0, 0, 0.85);
142
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.5);
143
+ --stx-mac-ink-tertiary: rgba(0, 0, 0, 0.26);
144
+ --stx-mac-window: #ffffff;
145
+ --stx-mac-sidebar: #f2f1f0;
146
+ --stx-mac-card: rgba(0, 0, 0, 0.04);
147
+ --stx-mac-separator: rgba(0, 0, 0, 0.1);
148
+ --stx-mac-hover: rgba(0, 0, 0, 0.05);
149
+ --stx-mac-selection-inactive: rgba(0, 0, 0, 0.08);
150
+ --stx-mac-well: rgba(0, 0, 0, 0.07);
151
+ --stx-mac-control: #ffffff;
152
+ --stx-mac-control-line: rgba(0, 0, 0, 0.12);
153
+ --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);
154
+ --stx-mac-switch-on: #34c759;
155
+ --stx-mac-knob: #ffffff;
156
+ --stx-mac-danger: #ff3b30;
157
+ }
158
+ :where(.dark) {
159
+ --stx-mac-accent: var(--stx-accent, #0a84ff);
160
+ --stx-mac-accent-ink: #ffffff;
161
+ --stx-mac-ink: rgba(255, 255, 255, 0.85);
162
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.55);
163
+ --stx-mac-ink-tertiary: rgba(255, 255, 255, 0.25);
164
+ --stx-mac-window: #1e1e1e;
165
+ --stx-mac-sidebar: #2a2a2a;
166
+ --stx-mac-card: rgba(255, 255, 255, 0.05);
167
+ --stx-mac-separator: rgba(255, 255, 255, 0.1);
168
+ --stx-mac-hover: rgba(255, 255, 255, 0.06);
169
+ --stx-mac-selection-inactive: rgba(255, 255, 255, 0.1);
170
+ --stx-mac-well: rgba(255, 255, 255, 0.1);
171
+ --stx-mac-control: rgba(255, 255, 255, 0.14);
172
+ --stx-mac-control-line: rgba(255, 255, 255, 0.06);
173
+ --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);
174
+ --stx-mac-switch-on: #30d158;
175
+ --stx-mac-knob: #ffffff;
176
+ --stx-mac-danger: #ff453a;
177
+ }
178
+ @media (max-resolution: 1.5dppx) {
179
+ :where(:root) {
180
+ --stx-mac-hairline: 1px;
181
+ }
182
+ }
183
+ @media (prefers-contrast: more) {
184
+ :where(:root) {
185
+ --stx-mac-separator: rgba(0, 0, 0, 0.4);
186
+ --stx-mac-control-line: rgba(0, 0, 0, 0.5);
187
+ --stx-mac-ink-secondary: rgba(0, 0, 0, 0.75);
188
+ --stx-mac-hairline: 1px;
189
+ }
190
+ :where(.dark) {
191
+ --stx-mac-separator: rgba(255, 255, 255, 0.45);
192
+ --stx-mac-control-line: rgba(255, 255, 255, 0.5);
193
+ --stx-mac-ink-secondary: rgba(255, 255, 255, 0.8);
194
+ }
195
+ }
196
+
197
+ :where([data-stx-color-swatches]) {
198
+ --stx-swatch-size: 24px;
199
+ --stx-swatch-gap: 12px;
200
+ --stx-swatch-ring: 2px;
201
+ --stx-swatch-ring-gap: 2px;
202
+ --stx-swatch-ring-color: var(--stx-mac-accent);
203
+ --stx-swatch-caption-gap: 4px;
204
+ --stx-swatch-caption-height: 13px;
205
+ display: inline-flex;
206
+ flex-direction: row;
207
+ flex-wrap: wrap;
208
+ align-items: flex-start;
209
+ gap: var(--stx-swatch-gap);
210
+ box-sizing: border-box;
211
+ font-family: var(--stx-mac-font);
212
+ -webkit-font-smoothing: antialiased;
213
+ cursor: default;
214
+ -webkit-user-select: none;
215
+ user-select: none;
216
+ }
217
+ /* Room for the name of whichever dot is chosen, so choosing one moves nothing. */
218
+ :where([data-stx-color-swatches][data-caption]) { padding-bottom: calc(var(--stx-swatch-caption-gap) + var(--stx-swatch-caption-height)); }
219
+
220
+ :where([data-stx-color-swatches]) > .stx-color-swatch {
221
+ position: relative;
222
+ display: block;
223
+ flex: 0 0 auto;
224
+ box-sizing: border-box;
225
+ width: var(--stx-swatch-size);
226
+ height: var(--stx-swatch-size);
227
+ margin: 0;
228
+ padding: 0;
229
+ border: 0;
230
+ border-radius: 50%;
231
+ background: transparent;
232
+ color: inherit;
233
+ font: inherit;
234
+ cursor: default;
235
+ outline: none;
236
+ -webkit-appearance: none;
237
+ appearance: none;
238
+ }
239
+ :where([data-stx-color-swatches]) .stx-color-swatch-dot {
240
+ display: block;
241
+ width: 100%;
242
+ height: 100%;
243
+ border-radius: 50%;
244
+ background: var(--stx-swatch-color, var(--stx-mac-ink-tertiary));
245
+ box-shadow: inset 0 0 0 var(--stx-mac-hairline) rgba(0, 0, 0, 0.14);
246
+ }
247
+ :where(.dark) :where([data-stx-color-swatches]) .stx-color-swatch-dot { box-shadow: inset 0 0 0 var(--stx-mac-hairline) rgba(255, 255, 255, 0.16); }
248
+
249
+ /* The ring, a gap away from the dot, showing whatever the row is drawn on. */
250
+ :where([data-stx-color-swatches]) > .stx-color-swatch::before {
251
+ content: '';
252
+ position: absolute;
253
+ inset: calc((var(--stx-swatch-ring) + var(--stx-swatch-ring-gap)) * -1);
254
+ box-sizing: border-box;
255
+ border: var(--stx-swatch-ring) solid transparent;
256
+ border-radius: 50%;
257
+ pointer-events: none;
258
+ transition: border-color 150ms ease, box-shadow 150ms ease;
259
+ }
260
+ :where([data-stx-color-swatches]) > .stx-color-swatch[aria-checked="true"]::before { border-color: var(--stx-swatch-ring-color); }
261
+ :where([data-stx-color-swatches]) > .stx-color-swatch:focus-visible::before { box-shadow: var(--stx-mac-focus-ring); }
262
+ :where([data-stx-color-swatches]) > .stx-color-swatch:active:not(:disabled) .stx-color-swatch-dot { filter: brightness(0.92); }
263
+ :where([data-stx-color-swatches]) > .stx-color-swatch:disabled { opacity: 0.4; }
264
+
265
+ :where([data-stx-color-swatches]) .stx-color-swatch-caption {
266
+ position: absolute;
267
+ top: calc(100% + var(--stx-swatch-caption-gap));
268
+ left: 50%;
269
+ display: none;
270
+ transform: translateX(-50%);
271
+ font-size: var(--stx-mac-font-size-small);
272
+ line-height: var(--stx-swatch-caption-height);
273
+ white-space: nowrap;
274
+ color: var(--stx-mac-ink-secondary);
275
+ pointer-events: none;
276
+ }
277
+ :where([data-stx-color-swatches][data-caption]) > .stx-color-swatch[aria-checked="true"] .stx-color-swatch-caption { display: block; }
278
+
279
+ @media (prefers-reduced-motion: reduce) {
280
+ :where([data-stx-color-swatches]) > .stx-color-swatch::before { transition: none; }
281
+ }
282
+
283
+ @media (prefers-contrast: more) {
284
+ :where([data-stx-color-swatches]) { --stx-swatch-ring: 3px; }
285
+ :where([data-stx-color-swatches]) .stx-color-swatch-dot { box-shadow: inset 0 0 0 1px var(--stx-mac-ink-secondary); }
286
+ }
287
+ </style>