glasslikeui 1.9.0 → 1.10.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.
Files changed (128) hide show
  1. package/README.md +892 -24
  2. package/dist/actions/adaptiveTone.d.ts +50 -0
  3. package/dist/actions/adaptiveTone.js +569 -0
  4. package/dist/actions/alertLogic.d.ts +67 -0
  5. package/dist/actions/alertLogic.js +123 -0
  6. package/dist/actions/anchorPlacement.d.ts +92 -0
  7. package/dist/actions/anchorPlacement.js +137 -0
  8. package/dist/actions/dragSnap.d.ts +1 -1
  9. package/dist/actions/dragSnapMath.d.ts +70 -0
  10. package/dist/actions/dragSnapMath.js +115 -0
  11. package/dist/actions/glassToneLogic.d.ts +182 -0
  12. package/dist/actions/glassToneLogic.js +513 -0
  13. package/dist/actions/heightTransition.d.ts +32 -0
  14. package/dist/actions/heightTransition.js +64 -0
  15. package/dist/actions/index.d.ts +1 -0
  16. package/dist/actions/index.js +1 -0
  17. package/dist/actions/inertSiblings.js +20 -4
  18. package/dist/actions/menuLogic.d.ts +40 -0
  19. package/dist/actions/menuLogic.js +68 -0
  20. package/dist/actions/modalDialog.d.ts +19 -0
  21. package/dist/actions/modalDialog.js +48 -0
  22. package/dist/actions/popoverLogic.d.ts +25 -0
  23. package/dist/actions/popoverLogic.js +48 -0
  24. package/dist/actions/rovingIndex.d.ts +30 -0
  25. package/dist/actions/rovingIndex.js +49 -0
  26. package/dist/actions/scrollRunTracker.d.ts +36 -0
  27. package/dist/actions/scrollRunTracker.js +77 -0
  28. package/dist/actions/scrollUnder.d.ts +21 -0
  29. package/dist/actions/scrollUnder.js +29 -0
  30. package/dist/actions/segmentedLogic.d.ts +38 -0
  31. package/dist/actions/segmentedLogic.js +59 -0
  32. package/dist/actions/sheetLogic.d.ts +43 -0
  33. package/dist/actions/sheetLogic.js +71 -0
  34. package/dist/actions/sliderLogic.d.ts +29 -0
  35. package/dist/actions/sliderLogic.js +53 -0
  36. package/dist/actions/swipeActions.d.ts +46 -2
  37. package/dist/actions/swipeActions.js +267 -46
  38. package/dist/actions/tabBarMinimize.d.ts +31 -0
  39. package/dist/actions/tabBarMinimize.js +38 -0
  40. package/dist/actions/tabViewLogic.d.ts +47 -0
  41. package/dist/actions/tabViewLogic.js +71 -0
  42. package/dist/actions/toggleKnobLogic.d.ts +57 -0
  43. package/dist/actions/toggleKnobLogic.js +66 -0
  44. package/dist/actions/toolbarFocus.d.ts +44 -0
  45. package/dist/actions/toolbarFocus.js +228 -0
  46. package/dist/actions/topLayer.d.ts +12 -0
  47. package/dist/actions/topLayer.js +18 -0
  48. package/dist/components/dialog/ActionSheet.svelte +457 -0
  49. package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
  50. package/dist/components/dialog/Alert.svelte +337 -0
  51. package/dist/components/dialog/Alert.svelte.d.ts +28 -0
  52. package/dist/components/dialog/index.d.ts +6 -0
  53. package/dist/components/dialog/index.js +6 -0
  54. package/dist/components/glass/Glass.svelte +49 -17
  55. package/dist/components/glass/Glass.svelte.d.ts +8 -0
  56. package/dist/components/glass/GlassSection.svelte +9 -1
  57. package/dist/components/glass/LensFilters.svelte +4 -2
  58. package/dist/components/glass/Popover.svelte +379 -0
  59. package/dist/components/glass/Popover.svelte.d.ts +30 -0
  60. package/dist/components/glass/Sheet.svelte +470 -103
  61. package/dist/components/glass/Sheet.svelte.d.ts +55 -7
  62. package/dist/components/glass/index.d.ts +3 -0
  63. package/dist/components/glass/index.js +1 -0
  64. package/dist/components/index.d.ts +2 -0
  65. package/dist/components/index.js +4 -0
  66. package/dist/components/interactive/Badge.svelte +97 -6
  67. package/dist/components/interactive/Badge.svelte.d.ts +13 -2
  68. package/dist/components/interactive/Button.svelte +162 -20
  69. package/dist/components/interactive/Button.svelte.d.ts +14 -1
  70. package/dist/components/interactive/IconButton.svelte +214 -4
  71. package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
  72. package/dist/components/interactive/ProgressView.svelte +306 -0
  73. package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
  74. package/dist/components/interactive/Segment.d.ts +14 -0
  75. package/dist/components/interactive/Segment.js +1 -0
  76. package/dist/components/interactive/SegmentedControl.svelte +399 -0
  77. package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
  78. package/dist/components/interactive/Slider.svelte +299 -0
  79. package/dist/components/interactive/Slider.svelte.d.ts +23 -0
  80. package/dist/components/interactive/TabView.svelte +573 -41
  81. package/dist/components/interactive/TabView.svelte.d.ts +25 -0
  82. package/dist/components/interactive/Toggle.svelte +287 -16
  83. package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
  84. package/dist/components/interactive/index.d.ts +4 -0
  85. package/dist/components/interactive/index.js +3 -0
  86. package/dist/components/list/List.svelte +41 -17
  87. package/dist/components/list/List.svelte.d.ts +1 -0
  88. package/dist/components/list/ListRow.svelte +208 -47
  89. package/dist/components/list/ListRow.svelte.d.ts +16 -1
  90. package/dist/components/menu/Menu.svelte +51 -27
  91. package/dist/components/menu/Menu.svelte.d.ts +5 -0
  92. package/dist/components/menu/MenuItem.svelte +82 -25
  93. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  94. package/dist/components/menu/MenuSection.svelte +95 -0
  95. package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
  96. package/dist/components/menu/MenuSubmenu.svelte +196 -0
  97. package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
  98. package/dist/components/menu/index.d.ts +4 -1
  99. package/dist/components/menu/index.js +3 -1
  100. package/dist/components/navigation/NavigationBar.svelte +97 -15
  101. package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
  102. package/dist/components/toolbar/Toolbar.svelte +43 -0
  103. package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
  104. package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
  105. package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
  106. package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
  107. package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
  108. package/dist/components/toolbar/index.d.ts +7 -0
  109. package/dist/components/toolbar/index.js +7 -0
  110. package/dist/components/typography/Text.svelte +9 -1
  111. package/dist/constants/alertAction.d.ts +19 -0
  112. package/dist/constants/alertAction.js +1 -0
  113. package/dist/constants/badge.d.ts +32 -0
  114. package/dist/constants/badge.js +47 -0
  115. package/dist/constants/buttons.d.ts +45 -0
  116. package/dist/constants/buttons.js +52 -0
  117. package/dist/constants/colors.d.ts +9 -4
  118. package/dist/constants/colors.js +9 -4
  119. package/dist/constants/index.d.ts +3 -0
  120. package/dist/constants/index.js +3 -0
  121. package/dist/constants/progress.d.ts +56 -0
  122. package/dist/constants/progress.js +75 -0
  123. package/dist/constants/variants.d.ts +6 -2
  124. package/dist/constants/variants.js +2 -2
  125. package/dist/styles/glasslikeui.css +135 -1
  126. package/dist/styles/lens.css +21 -19
  127. package/dist/styles/squircle.css +17 -7
  128. package/package.json +1 -1
@@ -1,13 +1,21 @@
1
1
  import type { Snippet } from 'svelte';
2
- import { type SheetDetentName } from '../../actions/dragSnapMath';
3
- interface Props {
2
+ import type { SheetDetent, SheetDetentName, SheetLabels } from '../../actions/dragSnapMath';
3
+ export interface SheetProps<D extends SheetDetent = SheetDetentName> {
4
4
  isOpen?: boolean;
5
5
  title?: string;
6
6
  children: Snippet;
7
7
  onClose?: () => void;
8
- onDetentChange?: (name: SheetDetentName) => void;
9
- detents?: readonly SheetDetentName[];
10
- initialDetent?: SheetDetentName;
8
+ /** Called with the detent the sheet settles on after a drag or a key press. */
9
+ onDetentChange?: (detent: D) => void;
10
+ /**
11
+ * The sizes the sheet snaps to: the named sizes, or custom ones as
12
+ * `{ fraction }` (a share of the viewport height, like SwiftUI's
13
+ * `.fraction`) or `{ height }` (CSS pixels, like `.height`). Mix freely in
14
+ * any order: the sheet sorts them, and counts sizes that match once.
15
+ */
16
+ detents?: readonly D[];
17
+ /** The detent the sheet opens at. A custom one matches by value. */
18
+ initialDetent?: D;
11
19
  showHandle?: boolean;
12
20
  draggable?: boolean;
13
21
  /**
@@ -24,8 +32,48 @@ interface Props {
24
32
  * leads.
25
33
  */
26
34
  closePlacement?: 'leading' | 'trailing';
35
+ /**
36
+ * `false` shows a non-modal sheet, like a SwiftUI sheet with background
37
+ * interaction enabled: no dimmed backdrop, and the page behind stays
38
+ * usable. Focus is not trapped and the page is not made inert. Escape
39
+ * closes it only while focus is inside it. Default `true`.
40
+ */
41
+ modal?: boolean;
42
+ /**
43
+ * Floats the sheet in from the screen edges with rounded bottom corners, as
44
+ * iOS 26 shows sheets below full height. At a full height detent (`large`
45
+ * or taller) it meets the edges and turns more opaque. Default `true`.
46
+ */
47
+ inset?: boolean;
48
+ /**
49
+ * The grabber's spoken words, to translate them: its name (`size`), the
50
+ * named detents and `pixels(n)` for a height detent. Any left out stay
51
+ * in English.
52
+ */
53
+ labels?: Partial<SheetLabels>;
27
54
  class?: string;
28
55
  }
29
- declare const Sheet: import("svelte").Component<Props, {}, string>;
30
- type Sheet = ReturnType<typeof Sheet>;
56
+ declare function $$render<D extends SheetDetent = SheetDetentName>(): {
57
+ props: SheetProps<D>;
58
+ exports: {};
59
+ bindings: unknown;
60
+ slots: {};
61
+ events: {};
62
+ };
63
+ declare class __sveltets_Render<D extends SheetDetent = SheetDetentName> {
64
+ props(): ReturnType<typeof $$render<D>>['props'];
65
+ events(): ReturnType<typeof $$render<D>>['events'];
66
+ slots(): ReturnType<typeof $$render<D>>['slots'];
67
+ bindings(): unknown;
68
+ exports(): {};
69
+ }
70
+ interface $$IsomorphicComponent {
71
+ new <D extends SheetDetent = SheetDetentName>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<D>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<D>['props']>, ReturnType<__sveltets_Render<D>['events']>, ReturnType<__sveltets_Render<D>['slots']>> & {
72
+ $$bindings?: ReturnType<__sveltets_Render<D>['bindings']>;
73
+ } & ReturnType<__sveltets_Render<D>['exports']>;
74
+ <D extends SheetDetent = SheetDetentName>(internal: unknown, props: ReturnType<__sveltets_Render<D>['props']> & {}): ReturnType<__sveltets_Render<D>['exports']>;
75
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
76
+ }
77
+ declare const Sheet: $$IsomorphicComponent;
78
+ type Sheet<D extends SheetDetent = SheetDetentName> = InstanceType<typeof Sheet<D>>;
31
79
  export default Sheet;
@@ -6,3 +6,6 @@ export { default as LensFilters } from './LensFilters.svelte';
6
6
  export { default as GlassDimLayer } from './GlassDimLayer.svelte';
7
7
  export { default as GlassEffectContainer } from './GlassEffectContainer.svelte';
8
8
  export { default as GlassMorph } from './GlassMorph.svelte';
9
+ export { default as Popover } from './Popover.svelte';
10
+ export type { AnchorAlignment } from '../../actions/anchorPlacement';
11
+ export type { PopoverCompactAdaptation } from '../../actions/popoverLogic';
@@ -6,3 +6,4 @@ export { default as LensFilters } from './LensFilters.svelte';
6
6
  export { default as GlassDimLayer } from './GlassDimLayer.svelte';
7
7
  export { default as GlassEffectContainer } from './GlassEffectContainer.svelte';
8
8
  export { default as GlassMorph } from './GlassMorph.svelte';
9
+ export { default as Popover } from './Popover.svelte';
@@ -6,7 +6,9 @@ export * from './layout';
6
6
  export * from './glass';
7
7
  export * from './interactive';
8
8
  export * from './navigation';
9
+ export * from './toolbar';
9
10
  export * from './list';
10
11
  export * from './typography';
11
12
  export * from './media';
12
13
  export * from './menu';
14
+ export * from './dialog';
@@ -10,6 +10,8 @@ export * from './glass';
10
10
  export * from './interactive';
11
11
  // Navigation
12
12
  export * from './navigation';
13
+ // Toolbar
14
+ export * from './toolbar';
13
15
  // List
14
16
  export * from './list';
15
17
  // Typography
@@ -18,3 +20,5 @@ export * from './typography';
18
20
  export * from './media';
19
21
  // Menu
20
22
  export * from './menu';
23
+ // Dialog
24
+ export * from './dialog';
@@ -1,22 +1,59 @@
1
1
  <script lang="ts">
2
+ import { badgeDisplay, badgeSpokenText, DEFAULT_BADGE_MAX } from '../../constants/badge';
3
+
2
4
  interface Props {
3
- label: string;
4
- variant?: 'default' | 'accent';
5
+ /**
6
+ * The badge text. With `count` or `dot` it is the words assistive
7
+ * technology reads instead, such as "3 unread messages".
8
+ */
9
+ label?: string;
10
+ /** A count, shown in a compact pill. Below 1 hides the badge; above `max` reads "99+". */
11
+ count?: number;
12
+ /** The largest count shown before it reads as `max` and a plus. Defaults to 99. */
13
+ max?: number;
14
+ /** Shows a dot with no text. Give `label` for the words read aloud. */
15
+ dot?: boolean;
16
+ /** `notification` is the red, white text badge of tab bars and app icons. */
17
+ variant?: 'default' | 'accent' | 'notification';
5
18
  size?: 'sm' | 'md';
6
19
  class?: string;
7
20
  }
8
21
 
9
22
  let {
10
- label,
23
+ label = '',
24
+ count,
25
+ max = DEFAULT_BADGE_MAX,
26
+ dot = false,
11
27
  variant = 'default',
12
28
  size = 'md',
13
29
  class: className = ''
14
30
  }: Props = $props();
31
+
32
+ // A plain label keeps the text badge it always was. count and dot use the
33
+ // compact forms.
34
+ const compact = $derived(dot || count !== undefined);
35
+ const display = $derived(dot ? badgeDisplay(true) : badgeDisplay(count, max));
36
+ const spoken = $derived(badgeSpokenText(display, label));
15
37
  </script>
16
38
 
17
- <span class="badge variant-{variant} size-{size} {className}">
18
- {label}
19
- </span>
39
+ {#if !compact}
40
+ <span class="badge variant-{variant} size-{size} {className}">
41
+ {label}
42
+ </span>
43
+ {:else if display.kind === 'dot'}
44
+ <span class="badge form-dot variant-{variant} size-{size} {className}" data-badge-form="dot">
45
+ <span class="badge-sr">{spoken}</span>
46
+ </span>
47
+ {:else if display.kind === 'text'}
48
+ <span class="badge form-count variant-{variant} size-{size} {className}" data-badge-form="count">
49
+ {#if label.trim()}
50
+ <span aria-hidden="true">{display.text}</span>
51
+ <span class="badge-sr">{spoken}</span>
52
+ {:else}
53
+ {display.text}
54
+ {/if}
55
+ </span>
56
+ {/if}
20
57
 
21
58
  <style>
22
59
  .badge {
@@ -39,6 +76,38 @@
39
76
  font-size: 0.75rem;
40
77
  }
41
78
 
79
+ /* The compact count pill: as tall as it is wide for one digit, growing for
80
+ more. Tabular figures keep a changing count from shifting. */
81
+ .badge.form-count {
82
+ box-sizing: border-box;
83
+ min-width: 20px;
84
+ height: 20px;
85
+ padding: 0 6px;
86
+ font-size: 0.75rem;
87
+ font-weight: 600;
88
+ line-height: 1;
89
+ font-variant-numeric: tabular-nums;
90
+ }
91
+
92
+ .badge.form-count.size-sm {
93
+ min-width: 16px;
94
+ height: 16px;
95
+ padding: 0 4px;
96
+ font-size: 0.625rem;
97
+ }
98
+
99
+ .badge.form-dot {
100
+ box-sizing: border-box;
101
+ width: 10px;
102
+ height: 10px;
103
+ padding: 0;
104
+ }
105
+
106
+ .badge.form-dot.size-sm {
107
+ width: 8px;
108
+ height: 8px;
109
+ }
110
+
42
111
  .badge.variant-default {
43
112
  background: var(--glass-badge-bg);
44
113
  color: var(--color-text-secondary);
@@ -50,4 +119,26 @@
50
119
  color: var(--_accent-text);
51
120
  border: 1px solid var(--color-accent-25);
52
121
  }
122
+
123
+ /* White on the danger red (#d23c3c by default) is 4.7:1, above the 4.5:1
124
+ that small text needs. iOS's own system red would be 3.6:1. */
125
+ .badge.variant-notification {
126
+ background: var(--glass-badge-notification-bg, var(--color-danger));
127
+ color: var(--glass-badge-notification-text, #ffffff);
128
+ border: none;
129
+ }
130
+
131
+ /* Read by assistive technology, not drawn. */
132
+ .badge-sr {
133
+ position: absolute;
134
+ width: 1px;
135
+ height: 1px;
136
+ margin: -1px;
137
+ padding: 0;
138
+ overflow: hidden;
139
+ clip: rect(0 0 0 0);
140
+ clip-path: inset(50%);
141
+ white-space: nowrap;
142
+ border: 0;
143
+ }
53
144
  </style>
@@ -1,6 +1,17 @@
1
1
  interface Props {
2
- label: string;
3
- variant?: 'default' | 'accent';
2
+ /**
3
+ * The badge text. With `count` or `dot` it is the words assistive
4
+ * technology reads instead, such as "3 unread messages".
5
+ */
6
+ label?: string;
7
+ /** A count, shown in a compact pill. Below 1 hides the badge; above `max` reads "99+". */
8
+ count?: number;
9
+ /** The largest count shown before it reads as `max` and a plus. Defaults to 99. */
10
+ max?: number;
11
+ /** Shows a dot with no text. Give `label` for the words read aloud. */
12
+ dot?: boolean;
13
+ /** `notification` is the red, white text badge of tab bars and app icons. */
14
+ variant?: 'default' | 'accent' | 'notification';
4
15
  size?: 'sm' | 'md';
5
16
  class?: string;
6
17
  }
@@ -2,11 +2,33 @@
2
2
  import type { Snippet } from 'svelte';
3
3
  import { fitFocusRing } from '../../actions/focusRingFit';
4
4
  import { glassButtonVars, type ButtonVariant } from '../../constants/variants';
5
+ import {
6
+ DEFAULT_BUTTON_SHAPE,
7
+ buttonBlocked,
8
+ buttonBoxStyle,
9
+ resolveButtonRole,
10
+ type ButtonRoleInput,
11
+ type ButtonShape,
12
+ type ButtonSize
13
+ } from '../../constants/buttons';
14
+ import ProgressView from './ProgressView.svelte';
5
15
 
6
16
  interface Props {
7
17
  children: Snippet;
8
18
  variant?: ButtonVariant;
9
- size?: 'sm' | 'md' | 'lg';
19
+ /** `xl` is iOS 26's extra large control size. */
20
+ size?: ButtonSize;
21
+ /** Border shape, as SwiftUI's buttonBorderShape. `circle` suits an icon. */
22
+ shape?: ButtonShape;
23
+ /**
24
+ * As SwiftUI's ButtonRole. `destructive` turns the accent red; `confirm`
25
+ * (alias `primary`) sets the label in semibold; `cancel` has no look.
26
+ */
27
+ buttonRole?: ButtonRoleInput | undefined;
28
+ /** Shows a spinner in place of the label and blocks activation, keeping focus. */
29
+ loading?: boolean;
30
+ /** Spoken while loading, in place of the label. Defaults to the label. */
31
+ loadingLabel?: string | undefined;
10
32
  fullWidth?: boolean;
11
33
  disabled?: boolean;
12
34
  href?: string | undefined;
@@ -23,6 +45,10 @@
23
45
  children,
24
46
  variant = 'filled',
25
47
  size = 'md',
48
+ shape = DEFAULT_BUTTON_SHAPE,
49
+ buttonRole,
50
+ loading = false,
51
+ loadingLabel,
26
52
  fullWidth = false,
27
53
  disabled = false,
28
54
  href,
@@ -33,13 +59,25 @@
33
59
  class: className = ''
34
60
  }: Props = $props();
35
61
 
36
- const sizeStyles = {
37
- sm: { padding: '8px 16px', fontSize: '0.875rem' },
38
- md: { padding: '12px 24px', fontSize: '1rem' },
39
- lg: { padding: '16px 32px', fontSize: '1.0625rem' }
40
- };
62
+ const styles = $derived(buttonBoxStyle(size, shape));
63
+ const knownRole = $derived(resolveButtonRole(buttonRole));
64
+ const blocked = $derived(buttonBlocked(disabled, loading));
65
+ // Only a shape other than the default emits its box, so a default Button's
66
+ // inline style is unchanged.
67
+ const shapeStyle = $derived(
68
+ shape === DEFAULT_BUTTON_SHAPE
69
+ ? ''
70
+ : `--btn-radius: ${styles.radius};${styles.aspectRatio ? ` aspect-ratio: ${styles.aspectRatio};` : ''}`
71
+ );
41
72
 
42
- const styles = $derived(sizeStyles[size]);
73
+ // A loading button keeps focus but must not act, nor submit its form.
74
+ function handleClick(e: MouseEvent) {
75
+ if (loading) {
76
+ e.preventDefault();
77
+ return;
78
+ }
79
+ onclick?.(e);
80
+ }
43
81
 
44
82
  // null for the solid variants, so they emit no backdrop-filter layer.
45
83
  const glass = $derived(glassButtonVars(variant));
@@ -54,27 +92,38 @@
54
92
 
55
93
  {#if href}
56
94
  <!-- 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. -->
95
+ it cannot be focused or followed. The role keeps it announced as a link.
96
+ A loading link loses its destination too, but tabindex keeps it in the
97
+ Tab order, so a link that had focus keeps it. -->
58
98
  <a
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}
99
+ href={blocked ? undefined : href}
100
+ target={blocked ? undefined : target}
101
+ rel={blocked ? undefined : (rel ?? (target === '_blank' ? 'noopener noreferrer' : undefined))}
102
+ role={blocked ? 'link' : undefined}
103
+ aria-disabled={blocked ? 'true' : undefined}
104
+ tabindex={loading && !disabled ? 0 : undefined}
105
+ aria-busy={loading ? 'true' : undefined}
106
+ aria-label={loading && loadingLabel ? loadingLabel : undefined}
107
+ data-role={knownRole}
108
+ data-shape={shape === DEFAULT_BUTTON_SHAPE ? undefined : shape}
64
109
  class="button variant-{variant} size-{size} {className}"
65
110
  class:full-width={fullWidth}
66
111
  class:disabled
67
112
  class:is-glass={!!glass}
68
113
  class:is-tinted={glass?.tinted}
69
- onclick={disabled ? undefined : onclick}
114
+ class:is-loading={loading}
115
+ class:role-destructive={knownRole === 'destructive'}
116
+ class:role-confirm={knownRole === 'confirm'}
117
+ onclick={disabled ? undefined : loading ? handleClick : onclick}
70
118
  {@attach fitFocusRing}
71
119
  style="
72
120
  --btn-padding: {styles.padding};
73
121
  --btn-font-size: {styles.fontSize};
122
+ {shapeStyle}
74
123
  {glassStyle}
75
124
  "
76
125
  >
77
- {@render children()}
126
+ {@render content()}
78
127
  </a>
79
128
  {:else}
80
129
  <button
@@ -82,22 +131,45 @@
82
131
  class:full-width={fullWidth}
83
132
  class:is-glass={!!glass}
84
133
  class:is-tinted={glass?.tinted}
134
+ class:is-loading={loading}
135
+ class:role-destructive={knownRole === 'destructive'}
136
+ class:role-confirm={knownRole === 'confirm'}
137
+ data-role={knownRole}
138
+ data-shape={shape === DEFAULT_BUTTON_SHAPE ? undefined : shape}
139
+ aria-busy={loading ? 'true' : undefined}
140
+ aria-disabled={loading && !disabled ? 'true' : undefined}
141
+ aria-label={loading && loadingLabel ? loadingLabel : undefined}
85
142
  {disabled}
86
- {onclick}
143
+ onclick={loading ? handleClick : onclick}
87
144
  {type}
88
145
  {@attach fitFocusRing}
89
146
  style="
90
147
  --btn-padding: {styles.padding};
91
148
  --btn-font-size: {styles.fontSize};
149
+ {shapeStyle}
92
150
  {glassStyle}
93
151
  "
94
152
  >
95
- {@render children()}
153
+ {@render content()}
96
154
  </button>
97
155
  {/if}
98
156
 
157
+ <!-- Unchanged markup unless loading. While loading the label stays in the DOM,
158
+ transparent, so the button keeps its width and its accessible name. -->
159
+ {#snippet content()}
160
+ {#if loading}
161
+ <span class="button-spinner" aria-hidden="true"><ProgressView size="sm" /></span>
162
+ <span class="button-label">{@render children()}</span>
163
+ {:else}
164
+ {@render children()}
165
+ {/if}
166
+ {/snippet}
167
+
99
168
  <style>
100
169
  .button {
170
+ /* A <button> is border-box in the browser's own styles, an <a> is not.
171
+ Set for both, so a full width link keeps its padding inside its width. */
172
+ box-sizing: border-box;
101
173
  display: inline-flex;
102
174
  align-items: center;
103
175
  justify-content: center;
@@ -107,7 +179,7 @@
107
179
  font-weight: 500;
108
180
  font-family: inherit;
109
181
  border: none;
110
- border-radius: var(--glass-radius-full);
182
+ border-radius: var(--btn-radius, var(--glass-radius-full));
111
183
  cursor: pointer;
112
184
  text-decoration: none;
113
185
  transition: all var(--transition-fast);
@@ -122,6 +194,55 @@
122
194
  width: 100%;
123
195
  }
124
196
 
197
+ /* Loading: the spinner in the label's colour, centred over the label,
198
+ which turns transparent but keeps its space and its accessible name. */
199
+ .button.is-loading {
200
+ cursor: progress;
201
+ }
202
+
203
+ .button.is-loading > .button-label {
204
+ opacity: 0;
205
+ }
206
+
207
+ .button.is-loading > .button-spinner {
208
+ position: absolute;
209
+ inset: 0;
210
+ z-index: 3;
211
+ display: flex;
212
+ align-items: center;
213
+ justify-content: center;
214
+ --progress-spinner-color: currentColor;
215
+ }
216
+
217
+ /* The ProgressView sets its own text colour; inherit the label's instead,
218
+ so the spinner (currentColor) matches the label on every variant. */
219
+ .button.is-loading > .button-spinner > :global(.progress-view) {
220
+ color: inherit;
221
+ }
222
+
223
+ /* Confirm role: the emphasised, semibold label. */
224
+ .button.role-confirm {
225
+ font-weight: 600;
226
+ }
227
+
228
+ /* Destructive role: the variant keeps its shape, with danger in place of
229
+ the accent. Plain glass keeps its neutral label, which a red one could
230
+ not hold at 4.5:1 over every backdrop. */
231
+ .button.role-destructive {
232
+ --color-accent: var(--color-danger);
233
+ --color-accent-hover: var(--color-danger-hover);
234
+ --color-accent-active: var(--color-danger-active);
235
+ --color-accent-10: color-mix(in srgb, var(--color-danger) 10%, transparent);
236
+ --color-accent-15: color-mix(in srgb, var(--color-danger) 15%, transparent);
237
+ --color-accent-25: color-mix(in srgb, var(--color-danger) 25%, transparent);
238
+ --color-accent-50: color-mix(in srgb, var(--color-danger) 50%, transparent);
239
+ --color-on-accent: var(--color-on-danger, white);
240
+ /* Mixed with the accent text strengths, not the danger one: the label
241
+ also sits on a danger wash here, which needs the stronger shade. */
242
+ --_accent-text: var(--color-danger-text, color-mix(in srgb, var(--color-danger) var(--glass-accent-text-strength, 33%), var(--glass-text-toward, white)));
243
+ --_accent-text-hover: var(--color-danger-text, color-mix(in srgb, var(--color-danger) var(--glass-accent-text-strength-hover, 26%), var(--glass-text-toward, white)));
244
+ }
245
+
125
246
  /* Shared focus ring. :where keeps it at zero specificity, so a page's own
126
247
  focus rules win. */
127
248
  :where(.button:focus-visible) {
@@ -141,7 +262,10 @@
141
262
  outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
142
263
  }
143
264
 
144
- .button.disabled {
265
+ /* A disabled link carries .disabled; a disabled <button> has the
266
+ attribute. Both dim, as IconButton already does. */
267
+ .button.disabled,
268
+ .button:disabled {
145
269
  opacity: 0.5;
146
270
  pointer-events: none;
147
271
  }
@@ -209,7 +333,10 @@
209
333
  /* Glass variants (SwiftUI .glass / .glassProminent) */
210
334
  .button.is-glass {
211
335
  background: transparent;
212
- color: var(--color-text);
336
+ transition: all var(--transition-fast), scale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
337
+ /* The theme's text colour when the page sets no --color-text, rather than
338
+ whatever the page inherits, which may be dark on the dark glass. */
339
+ color: var(--glass-fg, var(--color-text, var(--glass-text-color-default, #f5f5f7)));
213
340
  isolation: isolate;
214
341
  }
215
342
 
@@ -259,6 +386,21 @@
259
386
  background: var(--glass-button-fill-active, var(--glass-button-fill, rgba(38, 38, 40, 0.75)));
260
387
  }
261
388
 
389
+ /* Pressed, glass grows a little and settles back with a small overshoot, as
390
+ iOS 26 glass scales and bounces (WWDC25 323). Not under reduced motion. */
391
+ .button.is-glass:active {
392
+ scale: 1.04;
393
+ }
394
+
395
+ @media (prefers-reduced-motion: reduce) {
396
+ .button.is-glass:active {
397
+ scale: none;
398
+ }
399
+ }
400
+ :global(:where([data-reduced-motion='true'])) .button.is-glass:active {
401
+ scale: none;
402
+ }
403
+
262
404
  /* The light theme has a dark label, so its white fill is opaque enough to hold
263
405
  it at 4.5:1 even over black, and brightens on hover and press. :where adds
264
406
  no specificity, so the prominent and reduced transparency rules below still
@@ -1,9 +1,22 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import { type ButtonVariant } from '../../constants/variants';
3
+ import { type ButtonRoleInput, type ButtonShape, type ButtonSize } from '../../constants/buttons';
3
4
  interface Props {
4
5
  children: Snippet;
5
6
  variant?: ButtonVariant;
6
- size?: 'sm' | 'md' | 'lg';
7
+ /** `xl` is iOS 26's extra large control size. */
8
+ size?: ButtonSize;
9
+ /** Border shape, as SwiftUI's buttonBorderShape. `circle` suits an icon. */
10
+ shape?: ButtonShape;
11
+ /**
12
+ * As SwiftUI's ButtonRole. `destructive` turns the accent red; `confirm`
13
+ * (alias `primary`) sets the label in semibold; `cancel` has no look.
14
+ */
15
+ buttonRole?: ButtonRoleInput | undefined;
16
+ /** Shows a spinner in place of the label and blocks activation, keeping focus. */
17
+ loading?: boolean;
18
+ /** Spoken while loading, in place of the label. Defaults to the label. */
19
+ loadingLabel?: string | undefined;
7
20
  fullWidth?: boolean;
8
21
  disabled?: boolean;
9
22
  href?: string | undefined;