glasslikeui 1.7.0 → 1.9.0

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.
@@ -39,6 +39,14 @@
39
39
  * close button, Escape and the backdrop still close the sheet.
40
40
  */
41
41
  interactiveDismissDisabled?: boolean;
42
+ /**
43
+ * Which side of the header the close button sits on. 'leading' (the
44
+ * default, as on iOS 26 sheets) is the left in LTR and the right in RTL;
45
+ * 'trailing' is the opposite side, the placement before 1.9. The button
46
+ * moves in the DOM too, so it is first in the header's Tab order when it
47
+ * leads.
48
+ */
49
+ closePlacement?: 'leading' | 'trailing';
42
50
  class?: string;
43
51
  }
44
52
 
@@ -53,12 +61,15 @@
53
61
  showHandle = true,
54
62
  draggable = true,
55
63
  interactiveDismissDisabled = false,
64
+ closePlacement = 'leading',
56
65
  class: className = ''
57
66
  }: Props = $props();
58
67
 
59
68
  const uid = $props.id();
60
69
  const titleId = `${uid}-title`;
61
70
 
71
+ const closeLeads = $derived(closePlacement !== 'trailing');
72
+
62
73
  const fractions = $derived(detentFractions(detents));
63
74
  const initialIndex = $derived(Math.max(0, detents.indexOf(initialDetent)));
64
75
 
@@ -211,6 +222,26 @@
211
222
 
212
223
  <svelte:window onkeydown={handleKeydown} />
213
224
 
225
+ {#snippet closeButton()}
226
+ <button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
227
+ <svg
228
+ xmlns="http://www.w3.org/2000/svg"
229
+ width="16"
230
+ height="16"
231
+ viewBox="0 0 24 24"
232
+ fill="none"
233
+ stroke="currentColor"
234
+ stroke-width="2.5"
235
+ stroke-linecap="round"
236
+ stroke-linejoin="round"
237
+ aria-hidden="true"
238
+ focusable="false"
239
+ >
240
+ {@html getIconPath('xmark')}
241
+ </svg>
242
+ </button>
243
+ {/snippet}
244
+
214
245
  {#if present}
215
246
  <div
216
247
  class="sheet-backdrop"
@@ -223,6 +254,7 @@
223
254
  <div
224
255
  bind:this={sheetEl}
225
256
  class="sheet-container {className}"
257
+ style:--sheet-hidden-height={sheetYForFraction(detentAt(fractions, currentIndex))}
226
258
  class:open={isOpen}
227
259
  data-sheet-state={sheetState}
228
260
  role="dialog"
@@ -247,26 +279,18 @@
247
279
  {/if}
248
280
 
249
281
  {#if title}
250
- <header class="sheet-header">
251
- <div class="sheet-spacer"></div>
282
+ <header class="sheet-header" data-close-placement={closeLeads ? 'leading' : 'trailing'}>
283
+ {#if closeLeads}
284
+ {@render closeButton()}
285
+ {:else}
286
+ <div class="sheet-spacer"></div>
287
+ {/if}
252
288
  <h2 class="sheet-title" id={titleId}>{title}</h2>
253
- <button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
254
- <svg
255
- xmlns="http://www.w3.org/2000/svg"
256
- width="16"
257
- height="16"
258
- viewBox="0 0 24 24"
259
- fill="none"
260
- stroke="currentColor"
261
- stroke-width="2.5"
262
- stroke-linecap="round"
263
- stroke-linejoin="round"
264
- aria-hidden="true"
265
- focusable="false"
266
- >
267
- {@html getIconPath('xmark')}
268
- </svg>
269
- </button>
289
+ {#if closeLeads}
290
+ <div class="sheet-spacer"></div>
291
+ {:else}
292
+ {@render closeButton()}
293
+ {/if}
270
294
  </header>
271
295
  {/if}
272
296
 
@@ -312,6 +336,7 @@
312
336
  right: 0;
313
337
  top: 0;
314
338
  height: 100vh;
339
+ box-sizing: border-box;
315
340
  margin: 0 auto;
316
341
  background: var(--glass-sheet-bg);
317
342
  backdrop-filter: blur(var(--glass-blur-nav)) saturate(var(--glass-saturation));
@@ -348,8 +373,9 @@
348
373
  border-radius: 3px;
349
374
  }
350
375
 
351
- /* Title centred between an empty cell and the trailing close button, so the
352
- title stays centred whatever its length. The header is also a drag region. */
376
+ /* Title centred between the close button and an empty cell of the same
377
+ width, so the title stays centred whatever its length. The header is also a
378
+ drag region. */
353
379
  .sheet-header {
354
380
  padding: 0 var(--spacing-md);
355
381
  height: 56px;
@@ -360,6 +386,23 @@
360
386
  gap: var(--spacing-sm);
361
387
  }
362
388
 
389
+ /* Grid lines are logical: column 1 is the inline start, so a leading close
390
+ button sits on the left in LTR and on the right in RTL. The DOM order
391
+ matches, so Tab reaches the button on the side it is drawn. */
392
+ .sheet-title {
393
+ grid-column: 2;
394
+ }
395
+
396
+ .sheet-header[data-close-placement='leading'] .sheet-close-btn,
397
+ .sheet-header[data-close-placement='trailing'] .sheet-spacer {
398
+ grid-column: 1;
399
+ }
400
+
401
+ .sheet-header[data-close-placement='leading'] .sheet-spacer,
402
+ .sheet-header[data-close-placement='trailing'] .sheet-close-btn {
403
+ grid-column: 3;
404
+ }
405
+
363
406
  .sheet-close-btn {
364
407
  display: inline-flex;
365
408
  align-items: center;
@@ -384,9 +427,9 @@
384
427
  .sheet-close-btn:focus-visible {
385
428
  /* Two tones, so the ring holds 3:1 on a dark or a light sheet. The inner
386
429
  ring is the shadow hugging the button, the outer one the outline. */
387
- outline: 2px solid var(--sheet-focus-ring-outer, #3b8eea);
388
- outline-offset: 2px;
389
- box-shadow: 0 0 0 2px var(--sheet-focus-ring-inner, #ffffff);
430
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--sheet-focus-ring-outer, #3b8eea));
431
+ outline-offset: var(--glass-focus-ring-offset, 2px);
432
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--sheet-focus-ring-inner, #ffffff);
390
433
  }
391
434
 
392
435
  .sheet-title {
@@ -402,8 +445,13 @@
402
445
  width: 36px;
403
446
  }
404
447
 
448
+ /* The sheet is a viewport tall and pushed down to its detent, so that much of
449
+ it is below the screen. The content gives it up, or its end could never be
450
+ scrolled into view. It follows the settled detent, not the finger, so a drag
451
+ does not lay the content out again on every move. */
405
452
  .sheet-content {
406
453
  flex: 1;
454
+ margin-bottom: var(--sheet-hidden-height, 0px);
407
455
  overflow-y: auto;
408
456
  overflow-x: hidden;
409
457
  -webkit-overflow-scrolling: touch;
@@ -413,6 +461,14 @@
413
461
  touch-action: pan-x pan-y;
414
462
  }
415
463
 
464
+ /* On a phone 100vh can reach behind the browser bars, which hides that much
465
+ more of the sheet. */
466
+ @supports (height: 100dvh) {
467
+ .sheet-content {
468
+ margin-bottom: calc(var(--sheet-hidden-height, 0px) + 100vh - 100dvh);
469
+ }
470
+ }
471
+
416
472
  /* At the top, the browser keeps only the pan that scrolls the content down
417
473
  (a finger moving up), so a finger moving down reaches the drag handlers
418
474
  instead of becoming a pan and a pointercancel. Engines without directional
@@ -425,7 +481,7 @@
425
481
 
426
482
  @media (min-width: 769px) {
427
483
  .sheet-container {
428
- max-width: 900px;
484
+ max-width: var(--glass-sheet-max-width, 900px);
429
485
  }
430
486
  }
431
487
  </style>
@@ -16,6 +16,14 @@ interface Props {
16
16
  * close button, Escape and the backdrop still close the sheet.
17
17
  */
18
18
  interactiveDismissDisabled?: boolean;
19
+ /**
20
+ * Which side of the header the close button sits on. 'leading' (the
21
+ * default, as on iOS 26 sheets) is the left in LTR and the right in RTL;
22
+ * 'trailing' is the opposite side, the placement before 1.9. The button
23
+ * moves in the DOM too, so it is first in the header's Tab order when it
24
+ * leads.
25
+ */
26
+ closePlacement?: 'leading' | 'trailing';
19
27
  class?: string;
20
28
  }
21
29
  declare const Sheet: import("svelte").Component<Props, {}, string>;
@@ -26,6 +26,7 @@
26
26
  border-radius: var(--glass-radius-full);
27
27
  font-weight: 500;
28
28
  white-space: nowrap;
29
+ --_accent-text: var(--color-accent-text, color-mix(in srgb, var(--color-accent) var(--glass-accent-text-strength, 33%), var(--glass-text-toward, white)));
29
30
  }
30
31
 
31
32
  .badge.size-sm {
@@ -46,7 +47,7 @@
46
47
 
47
48
  .badge.variant-accent {
48
49
  background: var(--color-accent-15);
49
- color: var(--color-accent);
50
+ color: var(--_accent-text);
50
51
  border: 1px solid var(--color-accent-25);
51
52
  }
52
53
  </style>
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
+ import { fitFocusRing } from '../../actions/focusRingFit';
3
4
  import { glassButtonVars, type ButtonVariant } from '../../constants/variants';
4
5
 
5
6
  interface Props {
@@ -52,16 +53,21 @@
52
53
  </script>
53
54
 
54
55
  {#if href}
56
+ <!-- A disabled link keeps its element but loses its destination: with no href
57
+ it cannot be focused or followed. The role keeps it announced as a link. -->
55
58
  <a
56
- {href}
57
- {target}
58
- rel={rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined)}
59
+ href={disabled ? undefined : href}
60
+ target={disabled ? undefined : target}
61
+ rel={disabled ? undefined : (rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined))}
62
+ role={disabled ? 'link' : undefined}
63
+ aria-disabled={disabled ? 'true' : undefined}
59
64
  class="button variant-{variant} size-{size} {className}"
60
65
  class:full-width={fullWidth}
61
66
  class:disabled
62
67
  class:is-glass={!!glass}
63
68
  class:is-tinted={glass?.tinted}
64
- onclick={onclick}
69
+ onclick={disabled ? undefined : onclick}
70
+ {@attach fitFocusRing}
65
71
  style="
66
72
  --btn-padding: {styles.padding};
67
73
  --btn-font-size: {styles.fontSize};
@@ -79,6 +85,7 @@
79
85
  {disabled}
80
86
  {onclick}
81
87
  {type}
88
+ {@attach fitFocusRing}
82
89
  style="
83
90
  --btn-padding: {styles.padding};
84
91
  --btn-font-size: {styles.fontSize};
@@ -106,12 +113,34 @@
106
113
  transition: all var(--transition-fast);
107
114
  position: relative;
108
115
  overflow: hidden;
116
+ /* The accent as text, from this button's own accent colour. */
117
+ --_accent-text: var(--color-accent-text, color-mix(in srgb, var(--color-accent) var(--glass-accent-text-strength, 33%), var(--glass-text-toward, white)));
118
+ --_accent-text-hover: var(--color-accent-text-hover, var(--color-accent-text, color-mix(in srgb, var(--color-accent) var(--glass-accent-text-strength-hover, 26%), var(--glass-text-toward, white))));
109
119
  }
110
120
 
111
121
  .button.full-width {
112
122
  width: 100%;
113
123
  }
114
124
 
125
+ /* Shared focus ring. :where keeps it at zero specificity, so a page's own
126
+ focus rules win. */
127
+ :where(.button:focus-visible) {
128
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
129
+ outline-offset: var(--glass-focus-ring-offset, 2px);
130
+ }
131
+
132
+ /* The same ring moved inside, for a part flush in a container that would clip
133
+ it (see focusRingFit). The label colour stands out on the part's own fill. */
134
+ :where(.button:global([data-focus-ring='inset']):focus-visible) {
135
+ outline-color: var(--glass-focus-ring-color, currentColor);
136
+ }
137
+
138
+ /* A page's own :focus-visible rule must not push the ring back out, where
139
+ the container cuts it off. Only the offset outranks it. */
140
+ .button:global([data-focus-ring='inset']):where(:focus-visible) {
141
+ outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
142
+ }
143
+
115
144
  .button.disabled {
116
145
  opacity: 0.5;
117
146
  pointer-events: none;
@@ -120,7 +149,7 @@
120
149
  /* Filled variant */
121
150
  .button.variant-filled {
122
151
  background: var(--color-accent);
123
- color: white;
152
+ color: var(--color-on-accent, white);
124
153
  box-shadow: 0 4px 16px -4px var(--color-accent-50);
125
154
  }
126
155
 
@@ -137,14 +166,14 @@
137
166
  /* Outlined variant */
138
167
  .button.variant-outlined {
139
168
  background: transparent;
140
- color: var(--color-accent);
169
+ color: var(--_accent-text);
141
170
  border: 1.5px solid var(--color-accent);
142
171
  }
143
172
 
144
173
  .button.variant-outlined:hover {
145
174
  background: var(--color-accent-10);
146
175
  border-color: var(--color-accent-hover);
147
- color: var(--color-accent-hover);
176
+ color: var(--_accent-text-hover);
148
177
  }
149
178
 
150
179
  .button.variant-outlined:active {
@@ -154,23 +183,23 @@
154
183
  /* Plain variant */
155
184
  .button.variant-plain {
156
185
  background: transparent;
157
- color: var(--color-accent);
186
+ color: var(--_accent-text);
158
187
  }
159
188
 
160
189
  .button.variant-plain:hover {
161
- color: var(--color-accent-hover);
190
+ color: var(--_accent-text-hover);
162
191
  text-decoration: underline;
163
192
  }
164
193
 
165
194
  /* Tinted variant */
166
195
  .button.variant-tinted {
167
196
  background: var(--color-accent-15);
168
- color: var(--color-accent);
197
+ color: var(--_accent-text);
169
198
  }
170
199
 
171
200
  .button.variant-tinted:hover {
172
201
  background: var(--color-accent-25);
173
- color: var(--color-accent-hover);
202
+ color: var(--_accent-text-hover);
174
203
  }
175
204
 
176
205
  .button.variant-tinted:active {
@@ -184,6 +213,11 @@
184
213
  isolation: isolate;
185
214
  }
186
215
 
216
+ /* A page can restyle the fill with --glass-button-fill, and its hover and
217
+ pressed fills with --glass-button-fill-hover and -active. Unset, those two
218
+ follow --glass-button-fill if that is set. Reduced transparency reads none
219
+ of them. */
220
+
187
221
  /* Both layers sit at negative z-index inside the isolated button: behind the
188
222
  label, which is unpositioned and would otherwise be painted over. */
189
223
  .button.is-glass::before {
@@ -192,7 +226,9 @@
192
226
  inset: 0;
193
227
  z-index: -1;
194
228
  border-radius: inherit;
195
- background: rgba(255, 255, 255, var(--btn-glass-opacity));
229
+ /* Smoked glass: whatever is behind, even white, the fill stays dark enough
230
+ for a light label at 4.5:1. A white fill cannot over a bright backdrop. */
231
+ background: var(--glass-button-fill, rgba(62, 62, 64, 0.75));
196
232
  backdrop-filter: blur(var(--btn-glass-blur)) saturate(var(--btn-glass-saturation));
197
233
  -webkit-backdrop-filter: blur(var(--btn-glass-blur)) saturate(var(--btn-glass-saturation));
198
234
  pointer-events: none;
@@ -214,22 +250,41 @@
214
250
  z-index: 2;
215
251
  }
216
252
 
253
+ /* Deepens on hover and press: brightening would cost the label its contrast. */
217
254
  .button.is-glass:hover::before {
218
- background: rgba(255, 255, 255, calc(var(--btn-glass-opacity) * 1.35));
255
+ background: var(--glass-button-fill-hover, var(--glass-button-fill, rgba(50, 50, 52, 0.75)));
219
256
  }
220
257
 
221
258
  .button.is-glass:active::before {
222
- background: rgba(255, 255, 255, calc(var(--btn-glass-opacity) * 0.8));
259
+ background: var(--glass-button-fill-active, var(--glass-button-fill, rgba(38, 38, 40, 0.75)));
260
+ }
261
+
262
+ /* The light theme has a dark label, so its white fill is opaque enough to hold
263
+ it at 4.5:1 even over black, and brightens on hover and press. :where adds
264
+ no specificity, so the prominent and reduced transparency rules below still
265
+ win. */
266
+ :global(:where(:root[data-theme='light'])) .button.is-glass::before {
267
+ background: var(--glass-button-fill, rgba(255, 255, 255, 0.55));
268
+ }
269
+
270
+ :global(:where(:root[data-theme='light'])) .button.is-glass:hover::before {
271
+ background: var(--glass-button-fill-hover, var(--glass-button-fill, rgba(255, 255, 255, 0.65)));
272
+ }
273
+
274
+ :global(:where(:root[data-theme='light'])) .button.is-glass:active::before {
275
+ background: var(--glass-button-fill-active, var(--glass-button-fill, rgba(255, 255, 255, 0.75)));
223
276
  }
224
277
 
278
+ /* Prominent glass: a see-through accent fill, shaded so the label holds 4.5:1
279
+ whatever is behind it. An accent label on an accent wash could not. */
225
280
  .button.is-glass.is-tinted {
226
- color: var(--color-accent);
281
+ color: var(--color-on-accent, white);
227
282
  }
228
283
 
229
284
  .button.is-glass.is-tinted::before {
230
285
  background: color-mix(
231
286
  in srgb,
232
- var(--color-accent) calc(var(--btn-glass-opacity) * 100%),
287
+ color-mix(in srgb, var(--color-accent) 80%, black) 84%,
233
288
  transparent
234
289
  );
235
290
  }
@@ -237,15 +292,100 @@
237
292
  .button.is-glass.is-tinted:hover::before {
238
293
  background: color-mix(
239
294
  in srgb,
240
- var(--color-accent) calc(var(--btn-glass-opacity) * 135%),
295
+ color-mix(in srgb, var(--color-accent) 76%, black) 84%,
296
+ transparent
297
+ );
298
+ }
299
+
300
+ .button.is-glass.is-tinted:active::before {
301
+ background: color-mix(
302
+ in srgb,
303
+ color-mix(in srgb, var(--color-accent) 72%, black) 84%,
241
304
  transparent
242
305
  );
243
306
  }
244
307
 
308
+ /* Reduced transparency: no see-through layer, and a solid fill on the button
309
+ itself, where contrast checkers can read it and no fill or rule given to
310
+ ::before can cover it. Plain glass mixes its white fill into the surface
311
+ colour. Prominent glass becomes solid accent, shaded on hover and press from
312
+ the accent where the button is, so a wrapper's own accent carries through.
313
+ The attribute works on the root or on any ancestor. */
314
+ @media (prefers-reduced-transparency: reduce) {
315
+ .button.is-glass::before {
316
+ content: none;
317
+ }
318
+ .button.is-glass {
319
+ background: color-mix(
320
+ in srgb,
321
+ white calc(var(--btn-glass-opacity) * 93%),
322
+ rgb(var(--glass-surface-color, 28, 28, 30))
323
+ );
324
+ }
325
+ .button.is-glass:hover {
326
+ background: color-mix(
327
+ in srgb,
328
+ white calc(var(--btn-glass-opacity) * 76%),
329
+ rgb(var(--glass-surface-color, 28, 28, 30))
330
+ );
331
+ }
332
+ .button.is-glass:active {
333
+ background: color-mix(
334
+ in srgb,
335
+ white calc(var(--btn-glass-opacity) * 60%),
336
+ rgb(var(--glass-surface-color, 28, 28, 30))
337
+ );
338
+ }
339
+ .button.is-glass.is-tinted {
340
+ color: var(--color-on-accent, white);
341
+ background: var(--color-accent);
342
+ }
343
+ .button.is-glass.is-tinted:hover {
344
+ background: color-mix(in srgb, var(--color-accent) 85%, black);
345
+ }
346
+ .button.is-glass.is-tinted:active {
347
+ background: color-mix(in srgb, var(--color-accent) 85%, black);
348
+ }
349
+ }
350
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass::before {
351
+ content: none;
352
+ }
353
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass {
354
+ background: color-mix(
355
+ in srgb,
356
+ white calc(var(--btn-glass-opacity) * 93%),
357
+ rgb(var(--glass-surface-color, 28, 28, 30))
358
+ );
359
+ }
360
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass:hover {
361
+ background: color-mix(
362
+ in srgb,
363
+ white calc(var(--btn-glass-opacity) * 76%),
364
+ rgb(var(--glass-surface-color, 28, 28, 30))
365
+ );
366
+ }
367
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass:active {
368
+ background: color-mix(
369
+ in srgb,
370
+ white calc(var(--btn-glass-opacity) * 60%),
371
+ rgb(var(--glass-surface-color, 28, 28, 30))
372
+ );
373
+ }
374
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass.is-tinted {
375
+ color: var(--color-on-accent, white);
376
+ background: var(--color-accent);
377
+ }
378
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass.is-tinted:hover {
379
+ background: color-mix(in srgb, var(--color-accent) 85%, black);
380
+ }
381
+ :global(:where([data-reduced-transparency='true'])) .button.is-glass.is-tinted:active {
382
+ background: color-mix(in srgb, var(--color-accent) 85%, black);
383
+ }
384
+
245
385
  /* Destructive variant */
246
386
  .button.variant-destructive {
247
387
  background: var(--color-danger);
248
- color: white;
388
+ color: var(--color-on-danger, white);
249
389
  box-shadow: 0 4px 16px -4px color-mix(in srgb, var(--color-danger) 50%, transparent);
250
390
  }
251
391
 
@@ -258,4 +398,10 @@
258
398
  background: var(--color-danger-active);
259
399
  box-shadow: 0 2px 10px -4px color-mix(in srgb, var(--color-danger) 50%, transparent);
260
400
  }
401
+ /* The inner tone of the focus ring, filling the gap inside the outline. Two
402
+ tones hold 3:1 against any backdrop, which one cannot. Doubled and placed
403
+ last so the variant shadows do not hide it. */
404
+ .button.button:focus-visible {
405
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
406
+ }
261
407
  </style>
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
+ import { fitFocusRing } from '../../actions/focusRingFit';
3
4
 
4
5
  interface Props {
5
6
  children: Snippet;
@@ -38,6 +39,7 @@
38
39
  {onclick}
39
40
  {disabled}
40
41
  {type}
42
+ {@attach fitFocusRing}
41
43
  style="--btn-size: {sizeMap[size]}px"
42
44
  >
43
45
  {@render children()}
@@ -62,6 +64,26 @@
62
64
  color: var(--color-text);
63
65
  }
64
66
 
67
+ /* Shared focus ring. :where keeps it at zero specificity, so a page's own
68
+ focus rules win. */
69
+ :where(.icon-button:focus-visible) {
70
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
71
+ outline-offset: var(--glass-focus-ring-offset, 2px);
72
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
73
+ }
74
+
75
+ /* The same ring moved inside, for a part flush in a container that would clip
76
+ it (see focusRingFit). The label colour stands out on the part's own fill. */
77
+ :where(.icon-button:global([data-focus-ring='inset']):focus-visible) {
78
+ outline-color: var(--glass-focus-ring-color, currentColor);
79
+ }
80
+
81
+ /* A page's own :focus-visible rule must not push the ring back out, where
82
+ the container cuts it off. Only the offset outranks it. */
83
+ .icon-button:global([data-focus-ring='inset']):where(:focus-visible) {
84
+ outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
85
+ }
86
+
65
87
  .icon-button:disabled {
66
88
  opacity: 0.5;
67
89
  pointer-events: none;
@@ -77,7 +99,7 @@
77
99
 
78
100
  .icon-button.variant-filled {
79
101
  background: var(--color-accent);
80
- color: white;
102
+ color: var(--color-on-accent, white);
81
103
  }
82
104
 
83
105
  .icon-button.variant-filled:hover {
@@ -3,6 +3,7 @@
3
3
  import { onMount } from 'svelte';
4
4
  import { Glass } from '../glass';
5
5
  import { HStack } from '../layout';
6
+ import { fitFocusRing } from '../../actions/focusRingFit';
6
7
 
7
8
  interface Tab {
8
9
  id: string;
@@ -103,6 +104,7 @@
103
104
  class:active={activeTab === tab.id}
104
105
  onclick={() => selectTab(tab.id)}
105
106
  bind:this={buttonEls[tab.id]}
107
+ {@attach fitFocusRing}
106
108
  >
107
109
  {#if tab.icon}
108
110
  <span class="tab-icon">{@render tab.icon()}</span>
@@ -196,6 +198,27 @@
196
198
  font-weight: 500;
197
199
  cursor: pointer;
198
200
  transition: color var(--transition-fast);
201
+ --_accent-text: var(--color-accent-text, color-mix(in srgb, var(--color-accent) var(--glass-accent-text-strength, 33%), var(--glass-text-toward, white)));
202
+ }
203
+
204
+ /* Shared focus ring. :where keeps it at zero specificity, so a page's own
205
+ focus rules win. */
206
+ :where(.tab-item:focus-visible) {
207
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
208
+ outline-offset: var(--glass-focus-ring-offset, 2px);
209
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
210
+ }
211
+
212
+ /* The same ring moved inside, for a part flush in a container that would clip
213
+ it (see focusRingFit). The label colour stands out on the part's own fill. */
214
+ :where(.tab-item:global([data-focus-ring='inset']):focus-visible) {
215
+ outline-color: var(--glass-focus-ring-color, currentColor);
216
+ }
217
+
218
+ /* A page's own :focus-visible rule must not push the ring back out, where
219
+ the container cuts it off. Only the offset outranks it. */
220
+ .tab-item:global([data-focus-ring='inset']):where(:focus-visible) {
221
+ outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
199
222
  }
200
223
 
201
224
  .tab-item:not(.active):hover {
@@ -203,7 +226,7 @@
203
226
  }
204
227
 
205
228
  .tab-item.active {
206
- color: var(--color-accent);
229
+ color: var(--_accent-text);
207
230
  }
208
231
 
209
232
  .tab-icon,
@@ -1,4 +1,6 @@
1
1
  <script lang="ts">
2
+ import { fitFocusRing } from '../../actions/focusRingFit';
3
+
2
4
  interface Props {
3
5
  /** Two-way bound on/off state. */
4
6
  checked?: boolean;
@@ -39,6 +41,7 @@
39
41
  aria-checked={checked}
40
42
  {disabled}
41
43
  onchange={handleChange}
44
+ {@attach (input: HTMLInputElement) => fitFocusRing(input, (node) => node.nextElementSibling)}
42
45
  />
43
46
  <span class="toggle-track" aria-hidden="true">
44
47
  <span class="toggle-thumb"></span>
@@ -96,15 +99,30 @@
96
99
  }
97
100
 
98
101
  .toggle-input:checked ~ .toggle-track {
99
- background: var(--color-accent);
102
+ background: var(--glass-track-checked, var(--color-accent));
100
103
  }
101
104
 
102
105
  .toggle-input:checked ~ .toggle-track .toggle-thumb {
103
106
  transform: translateX(20px);
104
107
  }
105
108
 
106
- .toggle-input:focus-visible ~ .toggle-track {
107
- outline: 2px solid var(--color-accent);
108
- outline-offset: 2px;
109
+ /* Shared focus ring. :where keeps it at zero specificity, so a page's own
110
+ focus rules win. */
111
+ :where(.toggle-input:focus-visible ~ .toggle-track) {
112
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
113
+ outline-offset: var(--glass-focus-ring-offset, 2px);
114
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
115
+ }
116
+
117
+ /* The same ring moved inside, for a part flush in a container that would clip
118
+ it (see focusRingFit). The label colour stands out on the part's own fill. */
119
+ :where(.toggle-input:focus-visible ~ .toggle-track:global([data-focus-ring='inset'])) {
120
+ outline-color: var(--glass-focus-ring-color, currentColor);
121
+ }
122
+
123
+ /* A page's own :focus-visible rule must not push the ring back out, where
124
+ the container cuts it off. Only the offset outranks it. */
125
+ .toggle-input:where(:focus-visible) ~ .toggle-track:global([data-focus-ring='inset']) {
126
+ outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
109
127
  }
110
128
  </style>