dssoca 0.19.0 → 0.21.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 (155) hide show
  1. package/README.md +3 -3
  2. package/dist/components/Accordion.svelte +30 -54
  3. package/dist/components/Badge.svelte +12 -7
  4. package/dist/components/Badge.svelte.d.ts +2 -1
  5. package/dist/components/BottomNav.svelte +18 -28
  6. package/dist/components/BoxPlot.svelte +34 -7
  7. package/dist/components/BumpChart.svelte +65 -26
  8. package/dist/components/Button.svelte +23 -1
  9. package/dist/components/Button.svelte.d.ts +5 -1
  10. package/dist/components/Card.svelte +32 -14
  11. package/dist/components/Card.svelte.d.ts +4 -1
  12. package/dist/components/Chart.svelte +166 -32
  13. package/dist/components/Chart.svelte.d.ts +13 -1
  14. package/dist/components/Checkbox.svelte +210 -0
  15. package/dist/components/Checkbox.svelte.d.ts +38 -0
  16. package/dist/components/DateField.svelte +1 -1
  17. package/dist/components/FileDrop.svelte +113 -77
  18. package/dist/components/FileDrop.svelte.d.ts +12 -2
  19. package/dist/components/Heatmap.svelte +128 -50
  20. package/dist/components/Heatmap.svelte.d.ts +2 -1
  21. package/dist/components/Icon.svelte +12 -3
  22. package/dist/components/Icon.svelte.d.ts +4 -0
  23. package/dist/components/Image.svelte +44 -44
  24. package/dist/components/Input.svelte +11 -6
  25. package/dist/components/Link.svelte +25 -14
  26. package/dist/components/LogStream.svelte +48 -33
  27. package/dist/components/Menu.svelte +81 -102
  28. package/dist/components/Menu.svelte.d.ts +8 -2
  29. package/dist/components/MetricTile.svelte +11 -1
  30. package/dist/components/MetricTile.svelte.d.ts +6 -0
  31. package/dist/components/Modal.svelte +108 -21
  32. package/dist/components/Modal.svelte.d.ts +18 -5
  33. package/dist/components/NumberField.svelte +44 -22
  34. package/dist/components/Pagination.svelte +54 -41
  35. package/dist/components/Pagination.svelte.d.ts +6 -2
  36. package/dist/components/Popover.svelte +247 -0
  37. package/dist/components/Popover.svelte.d.ts +36 -0
  38. package/dist/components/RadioGroup.svelte +227 -0
  39. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  40. package/dist/components/ScatterPlot.svelte +42 -7
  41. package/dist/components/SearchPalette.svelte +216 -136
  42. package/dist/components/SearchPalette.svelte.d.ts +11 -4
  43. package/dist/components/SegmentedControl.svelte +47 -59
  44. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  45. package/dist/components/Select.svelte +3 -4
  46. package/dist/components/ServiceCard.svelte +105 -68
  47. package/dist/components/ServiceCard.svelte.d.ts +8 -3
  48. package/dist/components/ShortcutsHelp.svelte +49 -48
  49. package/dist/components/Sidebar.svelte +88 -117
  50. package/dist/components/Switch.svelte +24 -18
  51. package/dist/components/Switch.svelte.d.ts +6 -2
  52. package/dist/components/Table.svelte +29 -44
  53. package/dist/components/Table.svelte.d.ts +6 -2
  54. package/dist/components/Tabs.svelte +223 -0
  55. package/dist/components/Tabs.svelte.d.ts +51 -0
  56. package/dist/components/Textarea.svelte +1 -1
  57. package/dist/components/TierList.svelte +45 -49
  58. package/dist/components/TierList.svelte.d.ts +7 -3
  59. package/dist/components/Toaster.svelte +154 -32
  60. package/dist/components/Tooltip.svelte +122 -18
  61. package/dist/components/Tooltip.svelte.d.ts +1 -1
  62. package/dist/components/Topbar.svelte +29 -49
  63. package/dist/core/accordion.d.ts +32 -0
  64. package/dist/core/accordion.js +53 -0
  65. package/dist/core/behaviors/focusable.d.ts +5 -0
  66. package/dist/core/behaviors/focusable.js +14 -0
  67. package/dist/core/behaviors/roving.d.ts +13 -0
  68. package/dist/core/behaviors/roving.js +29 -0
  69. package/dist/core/bottom-nav.d.ts +36 -0
  70. package/dist/core/bottom-nav.js +33 -0
  71. package/dist/core/chart-nav.d.ts +53 -0
  72. package/dist/core/chart-nav.js +62 -0
  73. package/dist/core/checkbox.d.ts +36 -0
  74. package/dist/core/checkbox.js +29 -0
  75. package/dist/core/file-drop.d.ts +75 -0
  76. package/dist/core/file-drop.js +101 -0
  77. package/dist/core/image.d.ts +59 -0
  78. package/dist/core/image.js +64 -0
  79. package/dist/core/input.d.ts +21 -0
  80. package/dist/core/input.js +17 -0
  81. package/dist/core/log-stream.d.ts +51 -0
  82. package/dist/core/log-stream.js +50 -0
  83. package/dist/core/menu.d.ts +70 -0
  84. package/dist/core/menu.js +84 -0
  85. package/dist/core/modal.d.ts +59 -0
  86. package/dist/core/modal.js +44 -0
  87. package/dist/core/number-field.d.ts +47 -0
  88. package/dist/core/number-field.js +64 -0
  89. package/dist/core/pagination.d.ts +59 -0
  90. package/dist/core/pagination.js +65 -0
  91. package/dist/core/popover.d.ts +68 -0
  92. package/dist/core/popover.js +55 -0
  93. package/dist/core/radio.d.ts +36 -0
  94. package/dist/core/radio.js +48 -0
  95. package/dist/core/search-palette.d.ts +124 -0
  96. package/dist/core/search-palette.js +149 -0
  97. package/dist/core/segmented.d.ts +46 -0
  98. package/dist/core/segmented.js +66 -0
  99. package/dist/core/shortcuts-help.d.ts +56 -0
  100. package/dist/core/shortcuts-help.js +50 -0
  101. package/dist/core/sidebar.d.ts +63 -0
  102. package/dist/core/sidebar.js +84 -0
  103. package/dist/core/switch.d.ts +19 -0
  104. package/dist/core/switch.js +11 -0
  105. package/dist/core/table.d.ts +40 -0
  106. package/dist/core/table.js +57 -0
  107. package/dist/core/tabs.d.ts +84 -0
  108. package/dist/core/tabs.js +90 -0
  109. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +77 -5
  110. package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
  111. package/dist/core/toast.d.ts +112 -0
  112. package/dist/{toast-core.js → core/toast.js} +48 -2
  113. package/dist/core/tooltip.d.ts +47 -0
  114. package/dist/core/tooltip.js +51 -0
  115. package/dist/core/topbar.d.ts +41 -0
  116. package/dist/core/topbar.js +52 -0
  117. package/dist/dssoca.config.d.ts +1 -1
  118. package/dist/dssoca.config.js +4 -0
  119. package/dist/icons.d.ts +19 -2
  120. package/dist/icons.js +42 -3
  121. package/dist/index.d.ts +15 -2
  122. package/dist/index.js +10 -2
  123. package/dist/theme.css +47 -0
  124. package/dist/toast.svelte.d.ts +2 -2
  125. package/dist/toast.svelte.js +1 -1
  126. package/dist/tokens.css +47 -0
  127. package/dist/vanilla/accordion.js +35 -32
  128. package/dist/vanilla/checkbox.d.ts +8 -0
  129. package/dist/vanilla/checkbox.js +43 -0
  130. package/dist/vanilla/delegate.d.ts +2 -0
  131. package/dist/vanilla/delegate.js +9 -0
  132. package/dist/vanilla/fields.js +46 -28
  133. package/dist/vanilla/index.d.ts +5 -1
  134. package/dist/vanilla/index.js +17 -4
  135. package/dist/vanilla/menu.js +101 -84
  136. package/dist/vanilla/modal.d.ts +7 -1
  137. package/dist/vanilla/modal.js +120 -15
  138. package/dist/vanilla/popover.d.ts +10 -0
  139. package/dist/vanilla/popover.js +129 -0
  140. package/dist/vanilla/radio.d.ts +3 -0
  141. package/dist/vanilla/radio.js +54 -0
  142. package/dist/vanilla/segmented.js +50 -43
  143. package/dist/vanilla/switch.d.ts +2 -1
  144. package/dist/vanilla/switch.js +13 -8
  145. package/dist/vanilla/tabs.d.ts +2 -0
  146. package/dist/vanilla/tabs.js +87 -0
  147. package/dist/vanilla/tierlist.d.ts +1 -1
  148. package/dist/vanilla/tierlist.js +34 -34
  149. package/dist/vanilla/toast.d.ts +13 -5
  150. package/dist/vanilla/toast.js +132 -16
  151. package/dist/vanilla/tooltip.d.ts +5 -1
  152. package/dist/vanilla/tooltip.js +78 -19
  153. package/dist/vanilla.css +675 -160
  154. package/package.json +1 -1
  155. package/dist/toast-core.d.ts +0 -61
@@ -40,6 +40,20 @@
40
40
  <script lang="ts">
41
41
  import Icon from './Icon.svelte'
42
42
  import { resolveComponentSize, type Size } from '../config.js'
43
+ import {
44
+ menuItemAttrs,
45
+ menuItemPress,
46
+ menuOutsidePress,
47
+ menuPanelAttrs,
48
+ menuPanelKey,
49
+ menuTriggerAttrs,
50
+ menuTriggerKey,
51
+ menuTriggerPress,
52
+ type MenuAction,
53
+ type MenuKeyResult,
54
+ type MenuOpenChangeDetails,
55
+ type MenuState,
56
+ } from '../core/menu.js'
43
57
 
44
58
  /** Where the panel attaches relative to the trigger. */
45
59
  type Align = 'start' | 'end'
@@ -55,13 +69,18 @@
55
69
  open?: boolean
56
70
  /** Fired when an item is activated, with its `id` (after `item.onSelect`). */
57
71
  onSelect?: (id: string) => void
72
+ /**
73
+ * Fired when the menu opens or closes itself, with the new state and why
74
+ * (`details.reason`: trigger · key · escape · tab · outside · item).
75
+ */
76
+ onOpenChange?: (open: boolean, details: MenuOpenChangeDetails) => void
58
77
  /** Horizontal edge the panel aligns to. */
59
78
  align?: Align
60
79
  /** Vertical side the panel opens toward. */
61
80
  side?: Side
62
81
  /**
63
- * Accessible label for the panel (`role="menu"`). Falls back to the
64
- * trigger's text when omitted.
82
+ * Accessible label for the panel (`role="menu"`). When omitted the
83
+ * panel is named by the trigger's text via `aria-labelledby`.
65
84
  */
66
85
  label?: string
67
86
  /** Token size (sm|md|lg); inherits the global size when unset. */
@@ -74,6 +93,7 @@
74
93
  items = [],
75
94
  open = $bindable(false),
76
95
  onSelect,
96
+ onOpenChange,
77
97
  align = 'start',
78
98
  side = 'bottom',
79
99
  label,
@@ -83,6 +103,7 @@
83
103
 
84
104
  const uid = $props.id()
85
105
  const panelId = `${uid}-panel`
106
+ const triggerId = `${uid}-trigger`
86
107
 
87
108
  // When any item carries a `selected` flag the menu is a selection group, so
88
109
  // rows become `menuitemradio` + `aria-checked` (WAI-ARIA). Otherwise plain
@@ -91,12 +112,16 @@
91
112
 
92
113
  let triggerEl = $state<HTMLButtonElement>()
93
114
  let panelEl = $state<HTMLElement>()
94
- // The roving focus index into the *enabled* items; -1 when none focused yet.
115
+ // The roving focus index into the items; -1 when none focused yet.
95
116
  let activeIndex = $state(-1)
96
117
 
97
- const enabledIndexes = $derived(
98
- items.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i >= 0),
99
- )
118
+ // Behaviour lives in `core/menu.ts` (shared with vanilla/menu.ts): events go in, a
119
+ // MenuAction comes out, and `run` applies it to this component's state.
120
+ const menu = $derived<MenuState>({
121
+ open,
122
+ active: activeIndex,
123
+ enabled: items.map((it, i) => (it.disabled ? -1 : i)).filter((i) => i >= 0),
124
+ })
100
125
 
101
126
  function focusItem(domIndex: number) {
102
127
  activeIndex = domIndex
@@ -104,99 +129,50 @@
104
129
  el?.focus()
105
130
  }
106
131
 
107
- function firstEnabled(): number {
108
- return enabledIndexes[0] ?? -1
109
- }
110
- function lastEnabled(): number {
111
- return enabledIndexes[enabledIndexes.length - 1] ?? -1
112
- }
113
- function nextEnabled(from: number): number {
114
- const after = enabledIndexes.find((i) => i > from)
115
- return after ?? firstEnabled()
116
- }
117
- function prevEnabled(from: number): number {
118
- const before = [...enabledIndexes].reverse().find((i) => i < from)
119
- return before ?? lastEnabled()
120
- }
121
-
122
- function openMenu(focus: 'first' | 'last' = 'first') {
123
- if (open) return
124
- open = true
125
- // Defer focus until the panel renders.
126
- queueMicrotask(() => focusItem(focus === 'first' ? firstEnabled() : lastEnabled()))
127
- }
128
-
129
- function closeMenu(returnFocus = true) {
130
- if (!open) return
131
- open = false
132
- activeIndex = -1
133
- if (returnFocus) triggerEl?.focus()
132
+ function run(action: MenuAction | null) {
133
+ if (!action) return
134
+ switch (action.type) {
135
+ case 'open':
136
+ open = true
137
+ onOpenChange?.(true, { reason: action.reason })
138
+ // Defer focus until the panel renders.
139
+ queueMicrotask(() => focusItem(action.focus))
140
+ break
141
+ case 'close':
142
+ open = false
143
+ activeIndex = -1
144
+ onOpenChange?.(false, { reason: action.reason })
145
+ if (action.returnFocus) triggerEl?.focus()
146
+ break
147
+ case 'focus':
148
+ focusItem(action.index)
149
+ break
150
+ }
134
151
  }
135
152
 
136
- function toggle() {
137
- if (open) closeMenu()
138
- else openMenu('first')
153
+ function onKey(result: MenuKeyResult | null, e: KeyboardEvent) {
154
+ if (!result) return
155
+ if (result.preventDefault) e.preventDefault()
156
+ run(result.action)
139
157
  }
140
158
 
141
- function activate(item: MenuItem) {
142
- if (item.disabled) return
159
+ function activate(item: MenuItem, index: number) {
160
+ const result = menuItemPress(menu, index)
161
+ if (!result) return
143
162
  item.onSelect?.(item.id)
144
163
  onSelect?.(item.id)
145
- closeMenu()
146
- }
147
-
148
- function onTriggerKeydown(e: KeyboardEvent) {
149
- if (e.key === 'ArrowDown') {
150
- e.preventDefault()
151
- openMenu('first')
152
- } else if (e.key === 'ArrowUp') {
153
- e.preventDefault()
154
- openMenu('last')
155
- } else if (e.key === 'Enter' || e.key === ' ') {
156
- e.preventDefault()
157
- openMenu('first')
158
- }
159
- }
160
-
161
- function onPanelKeydown(e: KeyboardEvent) {
162
- switch (e.key) {
163
- case 'ArrowDown':
164
- e.preventDefault()
165
- focusItem(activeIndex < 0 ? firstEnabled() : nextEnabled(activeIndex))
166
- break
167
- case 'ArrowUp':
168
- e.preventDefault()
169
- focusItem(activeIndex < 0 ? lastEnabled() : prevEnabled(activeIndex))
170
- break
171
- case 'Home':
172
- e.preventDefault()
173
- focusItem(firstEnabled())
174
- break
175
- case 'End':
176
- e.preventDefault()
177
- focusItem(lastEnabled())
178
- break
179
- case 'Escape':
180
- e.preventDefault()
181
- closeMenu()
182
- break
183
- case 'Tab':
184
- // Tabbing out dismisses the menu (focus moves naturally; don't trap).
185
- closeMenu(false)
186
- break
187
- }
164
+ run(result.action)
188
165
  }
189
166
 
190
167
  // Pointer-down outside the root closes the menu (click would fire after the
191
168
  // outside target already handled the event; pointerdown matches the website).
192
169
  function onDocPointerDown(e: PointerEvent) {
193
- if (!open) return
194
170
  const t = e.target as Node
195
171
  // DS-0067 / DS-0078: triggerEl/panelEl may be unbound (pre-mount, SSR-ish
196
172
  // eager evaluation) — null-check before .contains().
197
173
  if (triggerEl && triggerEl.contains(t)) return
198
174
  if (panelEl && panelEl.contains(t)) return
199
- closeMenu(false)
175
+ run(menuOutsidePress(menu))
200
176
  }
201
177
 
202
178
  // SSR safety (DS-0067): same guard pattern as toast.svelte.ts — effects
@@ -216,13 +192,13 @@
216
192
  <div class="ss-menu" data-size-variant={sizeAttr} data-align={align} data-side={side}>
217
193
  <button
218
194
  bind:this={triggerEl}
195
+ id={triggerId}
219
196
  type="button"
220
197
  class="trigger"
221
- aria-haspopup="menu"
222
- aria-expanded={open}
198
+ {...menuTriggerAttrs(open)}
223
199
  aria-controls={panelId}
224
- onclick={toggle}
225
- onkeydown={onTriggerKeydown}
200
+ onclick={() => run(menuTriggerPress(menu))}
201
+ onkeydown={(e) => onKey(menuTriggerKey(menu, e.key), e)}
226
202
  >
227
203
  {@render children?.()}
228
204
  </button>
@@ -232,11 +208,10 @@
232
208
  id={panelId}
233
209
  class="panel"
234
210
  class:open
235
- role="menu"
236
- aria-label={label}
237
- aria-hidden={!open}
238
- tabindex="-1"
239
- onkeydown={onPanelKeydown}
211
+ aria-label={label || undefined}
212
+ aria-labelledby={label ? undefined : triggerId}
213
+ {...menuPanelAttrs(open)}
214
+ onkeydown={(e) => onKey(menuPanelKey(menu, e.key), e)}
240
215
  >
241
216
  {#each items as item, i (item.id)}
242
217
  <button
@@ -244,12 +219,15 @@
244
219
  class="item"
245
220
  class:selected={item.selected}
246
221
  data-mi={i}
247
- role={selectable ? 'menuitemradio' : 'menuitem'}
248
- aria-checked={selectable ? Boolean(item.selected) : undefined}
249
- aria-disabled={item.disabled ? 'true' : undefined}
222
+ {...menuItemAttrs({
223
+ index: i,
224
+ active: activeIndex,
225
+ selectable,
226
+ selected: item.selected,
227
+ disabled: item.disabled,
228
+ })}
250
229
  disabled={item.disabled}
251
- tabindex={i === activeIndex ? 0 : -1}
252
- onclick={() => activate(item)}
230
+ onclick={() => activate(item, i)}
253
231
  >
254
232
  {#if item.leading}
255
233
  <span class="lead" aria-hidden="true">{@render item.leading()}</span>
@@ -291,9 +269,7 @@
291
269
  background: var(--ss-hover);
292
270
  }
293
271
  .trigger:focus-visible {
294
- outline: none;
295
272
  border-color: var(--ss-primary);
296
- box-shadow: 0 0 0 3px var(--ss-primary-soft);
297
273
  }
298
274
 
299
275
  .panel {
@@ -336,11 +312,11 @@
336
312
  }
337
313
 
338
314
  .ss-menu[data-align=start] .panel {
339
- left: 0;
315
+ inset-inline-start: 0;
340
316
  }
341
317
 
342
318
  .ss-menu[data-align=end] .panel {
343
- right: 0;
319
+ inset-inline-end: 0;
344
320
  }
345
321
 
346
322
  .item {
@@ -348,7 +324,7 @@
348
324
  align-items: center;
349
325
  gap: var(--ss-menu-item-gap);
350
326
  width: 100%;
351
- text-align: left;
327
+ text-align: start;
352
328
  font: 500 var(--ss-ui-md) var(--ss-font-mono);
353
329
  color: var(--ss-fg-muted);
354
330
  background: transparent;
@@ -367,6 +343,9 @@
367
343
  background: var(--ss-hover);
368
344
  box-shadow: inset 2px 0 0 0 var(--ss-primary);
369
345
  }
346
+ .item:focus-visible:dir(rtl) {
347
+ box-shadow: inset -2px 0 0 0 var(--ss-primary);
348
+ }
370
349
  .item.selected {
371
350
  color: var(--ss-fg);
372
351
  background: color-mix(in srgb, var(--ss-accent) 6%, transparent);
@@ -34,6 +34,7 @@ export interface MenuItem {
34
34
  onSelect?: (id: string) => void;
35
35
  }
36
36
  import { type Size } from '../config.js';
37
+ import { type MenuOpenChangeDetails } from '../core/menu.js';
37
38
  /** Where the panel attaches relative to the trigger. */
38
39
  type Align = 'start' | 'end';
39
40
  type Side = 'bottom' | 'top';
@@ -47,13 +48,18 @@ interface Props {
47
48
  open?: boolean;
48
49
  /** Fired when an item is activated, with its `id` (after `item.onSelect`). */
49
50
  onSelect?: (id: string) => void;
51
+ /**
52
+ * Fired when the menu opens or closes itself, with the new state and why
53
+ * (`details.reason`: trigger · key · escape · tab · outside · item).
54
+ */
55
+ onOpenChange?: (open: boolean, details: MenuOpenChangeDetails) => void;
50
56
  /** Horizontal edge the panel aligns to. */
51
57
  align?: Align;
52
58
  /** Vertical side the panel opens toward. */
53
59
  side?: Side;
54
60
  /**
55
- * Accessible label for the panel (`role="menu"`). Falls back to the
56
- * trigger's text when omitted.
61
+ * Accessible label for the panel (`role="menu"`). When omitted the
62
+ * panel is named by the trigger's text via `aria-labelledby`.
57
63
  */
58
64
  label?: string;
59
65
  /** Token size (sm|md|lg); inherits the global size when unset. */
@@ -26,6 +26,12 @@
26
26
  emphasis?: boolean
27
27
  /** Skeleton/loading state: hides the real value behind aria-hidden bars. */
28
28
  loading?: boolean
29
+ /**
30
+ * Announce updates to assistive tech. When `true` the whole tile is one polite, atomic
31
+ * live region, so a change is read as "label value delta" rather than a bare number.
32
+ * Off by default: a grid of always-live tiles would talk over each other (DS-0191).
33
+ */
34
+ live?: boolean
29
35
  /** Snippet slot below the delta — drop in a <Sparkline> here. */
30
36
  chart?: Snippet
31
37
  /** Token size (sm|md|lg); inherits the global size when unset. */
@@ -42,6 +48,7 @@
42
48
  deltaLabel,
43
49
  emphasis = false,
44
50
  loading = false,
51
+ live = false,
45
52
  chart,
46
53
  size,
47
54
  }: Props = $props()
@@ -59,6 +66,9 @@
59
66
  class="ss-metric"
60
67
  data-size-variant={resolveComponentSize('MetricTile', size)}
61
68
  aria-busy={loading ? 'true' : undefined}
69
+ role={live ? 'status' : undefined}
70
+ aria-live={live ? 'polite' : undefined}
71
+ aria-atomic={live ? 'true' : undefined}
62
72
  >
63
73
  <div class="label">{label}</div>
64
74
 
@@ -66,7 +76,7 @@
66
76
  <div class="skeleton skeleton-val" aria-hidden="true"></div>
67
77
  {#if delta}<div class="skeleton skeleton-delta" aria-hidden="true"></div>{/if}
68
78
  {:else}
69
- <div class="val" role="status" aria-live="polite">
79
+ <div class="val">
70
80
  {#if prefix}<span class="small">{prefix}</span>{/if}{value}{#if suffix}<span class="small"
71
81
  >{suffix}</span
72
82
  >{/if}
@@ -23,6 +23,12 @@ interface Props {
23
23
  emphasis?: boolean;
24
24
  /** Skeleton/loading state: hides the real value behind aria-hidden bars. */
25
25
  loading?: boolean;
26
+ /**
27
+ * Announce updates to assistive tech. When `true` the whole tile is one polite, atomic
28
+ * live region, so a change is read as "label value delta" rather than a bare number.
29
+ * Off by default: a grid of always-live tiles would talk over each other (DS-0191).
30
+ */
31
+ live?: boolean;
26
32
  /** Snippet slot below the delta — drop in a <Sparkline> here. */
27
33
  chart?: Snippet;
28
34
  /** Token size (sm|md|lg); inherits the global size when unset. */
@@ -7,9 +7,14 @@
7
7
  // showModal()/close(). The dialog's native `close` event syncs `open` back
8
8
  // to false and fires `onclose`. Esc is native; when `closeOnEsc` is false we
9
9
  // intercept the `cancel` event and preventDefault(). Backdrop click closes
10
- // when `closeOnBackdrop` by detecting a pointerdown whose target IS the
11
- // dialog itself (the inner .panel covers the dialog's content box, so any
12
- // hit on the dialog element is the surrounding backdrop area).
10
+ // when `closeOnBackdrop`: a press that starts on the dialog itself (the inner
11
+ // .panel covers the dialog's content box, so any hit on the dialog element is
12
+ // the surrounding backdrop area) closes it on the click that follows.
13
+ //
14
+ // Naming (DS-0178): a custom `header` snippet receives the title id so it can
15
+ // put `id={titleId}` on its heading; the dialog stays aria-labelledby that id.
16
+ // While open, page scroll is locked on <html> (ref-counted helper shared with
17
+ // the vanilla layer) and .body uses overscroll-behavior: contain.
13
18
  //
14
19
  // Zero radius; surface = --ss-bg-elev, border = --ss-line; tinted ::backdrop.
15
20
  // Component metrics are inline var(--ss-modal-*, fallback) so no global SCSS
@@ -17,11 +22,26 @@
17
22
  // ─────────────────────────────────────────────────────────────────────────
18
23
  import type { Snippet } from 'svelte'
19
24
  import { resolveComponentSize, type Size } from '../config.js'
25
+ import { lockScroll, unlockScroll } from '../vanilla/modal.js'
26
+ import {
27
+ modalBackdropPress,
28
+ modalCancel,
29
+ modalClosed,
30
+ modalDismissPress,
31
+ type ModalAction,
32
+ type ModalCloseDetails,
33
+ type ModalReason,
34
+ type ModalState,
35
+ } from '../core/modal.js'
20
36
 
21
37
  interface Props {
22
38
  /** Whether the modal is shown. Bindable — sync it from caller state. */
23
39
  open?: boolean
24
- /** Title rendered in the header; also wires `aria-labelledby`. */
40
+ /**
41
+ * Title rendered in the header; also wires `aria-labelledby`. With a custom `header`
42
+ * snippet the title is not rendered but still names the dialog (as `aria-label`) unless
43
+ * the snippet labels it via the `titleId` it receives.
44
+ */
25
45
  title?: string
26
46
  /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
27
47
  size?: Size
@@ -41,10 +61,18 @@
41
61
  danger?: boolean
42
62
  /** Accessible name when no `title` is set (maps to aria-label on the dialog). */
43
63
  'aria-label'?: string
44
- /** Called after the dialog has closed (any reason: Esc, backdrop, button). */
45
- onclose?: () => void
46
- /** Header content; replaces the default title row when provided. */
47
- header?: Snippet
64
+ /**
65
+ * Called after the dialog has closed, with why (`details.reason`: escape · backdrop ·
66
+ * button · programmatic — the last one covers the `open` prop, a direct `.close()` and a
67
+ * `<form method="dialog">`).
68
+ */
69
+ onclose?: (details: ModalCloseDetails) => void
70
+ /**
71
+ * Header content; replaces the default title row when provided. Receives the id the
72
+ * dialog's `aria-labelledby` points at — put it on your heading (`id={titleId}`) so the
73
+ * dialog keeps its accessible name.
74
+ */
75
+ header?: Snippet<[string]>
48
76
  /** Footer content (typically action buttons). */
49
77
  footer?: Snippet
50
78
  /** Body content. */
@@ -72,6 +100,31 @@
72
100
  const uid = $props.id()
73
101
  const titleId = $derived(`${uid}-title`)
74
102
 
103
+ // Naming. Default header: the <h2> carries titleId (no redundant aria-label).
104
+ // Custom header: aria-labelledby points at titleId (the snippet is handed it);
105
+ // `title` / `aria-label` ride along as aria-label, which accessible-name
106
+ // computation falls back to if the snippet never renders that id.
107
+ const labelledBy = $derived(title || (header && !ariaLabel) ? titleId : undefined)
108
+ const labelAttr = $derived(header ? (ariaLabel ?? title) : title ? undefined : ariaLabel)
109
+
110
+ // Dev aid: a custom header that neither uses titleId nor has a title/aria-label
111
+ // fallback leaves the dialog unnamed (same warn pattern as Button/Icon).
112
+ $effect(() => {
113
+ if (!open || !header || title || ariaLabel || !dialog) return
114
+ if (!dialog.querySelector(`[id="${titleId}"]`) && typeof console !== 'undefined') {
115
+ console.warn(
116
+ '[dssoca] Modal: a custom `header` must put the `titleId` it receives on its heading (or pass `title` / `aria-label`); this dialog has no accessible name.',
117
+ )
118
+ }
119
+ })
120
+
121
+ // Lock the page behind the dialog while it is open; release on close/unmount.
122
+ $effect(() => {
123
+ if (!open) return
124
+ lockScroll()
125
+ return unlockScroll
126
+ })
127
+
75
128
  // Mirror `open` onto the native dialog. showModal()/close() throw if called
76
129
  // in the wrong state, so guard on dialog.open before flipping it.
77
130
  $effect(() => {
@@ -81,23 +134,52 @@
81
134
  else if (!open && el.open) el.close()
82
135
  })
83
136
 
137
+ // The decisions (what closes the modal, and why) come from core/modal.ts; this file applies
138
+ // them. `pending` remembers the reason between the action and the native `close` it causes.
139
+ const modal = $derived<ModalState>({ open, closeOnEsc, closeOnBackdrop })
140
+ let pending: ModalReason | null = null
141
+
142
+ function run(action: ModalAction | null) {
143
+ if (action?.type !== 'close') return
144
+ pending = action.reason
145
+ open = false
146
+ }
147
+
148
+ // A reason left over from a close that never happened must not label the next one.
149
+ $effect(() => {
150
+ if (open) pending = null
151
+ })
152
+
84
153
  // Native `close` (Esc, form method=dialog, .close()) → sync state + notify.
85
154
  function onDialogClose() {
155
+ const details = modalClosed(pending)
156
+ pending = null
86
157
  if (open) open = false
87
- onclose?.()
158
+ onclose?.(details)
88
159
  }
89
160
 
90
161
  // Esc dispatches `cancel` before `close`; swallow it when Esc is disabled.
91
162
  function onCancel(e: Event) {
92
- if (!closeOnEsc) e.preventDefault()
163
+ const result = modalCancel(modal, e.cancelable)
164
+ if (result.preventDefault) e.preventDefault()
165
+ pending = result.reason
93
166
  }
94
167
 
95
- // A pointerdown landing on the <dialog> itself (not the inner .panel) is a
96
- // backdrop hit. Using pointerdown avoids closing on a drag that began inside
97
- // the panel and released on the backdrop.
168
+ // A press that starts on the <dialog> itself (not the inner .panel) is a
169
+ // backdrop hit. Remembering where the press began avoids closing on a drag that
170
+ // started inside the panel and was released on the backdrop.
171
+ //
172
+ // The dialog closes on the `click`, not on the pointerdown: closing hands focus
173
+ // back to the opener, and if that happened on pointerdown the same gesture's
174
+ // mousedown would then land on the page and blur it, leaving focus on <body>.
175
+ let pressedBackdrop = false
98
176
  function onPointerDown(e: PointerEvent) {
99
- if (!closeOnBackdrop) return
100
- if (e.target === dialog) open = false
177
+ pressedBackdrop = e.target === dialog
178
+ }
179
+ function onClick(e: MouseEvent) {
180
+ const hit = pressedBackdrop && e.target === dialog
181
+ pressedBackdrop = false
182
+ run(modalBackdropPress(modal, hit))
101
183
  }
102
184
  </script>
103
185
 
@@ -107,21 +189,25 @@
107
189
  class:danger
108
190
  data-size-variant={resolveComponentSize('Modal', size)}
109
191
  data-fullscreen={fullscreen ? '' : undefined}
110
- aria-labelledby={title ? titleId : undefined}
111
- aria-label={title ? undefined : ariaLabel}
192
+ aria-labelledby={labelledBy}
193
+ aria-label={labelAttr}
112
194
  onclose={onDialogClose}
113
195
  oncancel={onCancel}
114
196
  onpointerdown={onPointerDown}
197
+ onclick={onClick}
115
198
  >
116
199
  <div class="panel">
117
200
  <header class="head">
118
201
  {#if header}
119
- {@render header()}
202
+ {@render header(titleId)}
120
203
  {:else if title}
121
204
  <h2 class="title" id={titleId}>{title}</h2>
122
205
  {/if}
123
- <button type="button" class="close" aria-label="Close" onclick={() => (open = false)}
124
- >×</button
206
+ <button
207
+ type="button"
208
+ class="close"
209
+ aria-label="Close"
210
+ onclick={() => run(modalDismissPress(modal))}>×</button
125
211
  >
126
212
  </header>
127
213
 
@@ -218,7 +304,7 @@
218
304
 
219
305
  .close {
220
306
  flex: none;
221
- margin-left: auto;
307
+ margin-inline-start: auto;
222
308
  appearance: none;
223
309
  display: inline-flex;
224
310
  align-items: center;
@@ -247,6 +333,7 @@
247
333
  .body {
248
334
  padding: var(--ss-modal-pad-y, var(--ss-s-4)) var(--ss-modal-pad-x, var(--ss-s-5));
249
335
  overflow: auto;
336
+ overscroll-behavior: contain;
250
337
  color: var(--ss-fg);
251
338
  font-family: var(--ss-font-body);
252
339
  line-height: var(--ss-leading, 1.5);
@@ -1,9 +1,14 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import { type Size } from '../config.js';
3
+ import { type ModalCloseDetails } from '../core/modal.js';
3
4
  interface Props {
4
5
  /** Whether the modal is shown. Bindable — sync it from caller state. */
5
6
  open?: boolean;
6
- /** Title rendered in the header; also wires `aria-labelledby`. */
7
+ /**
8
+ * Title rendered in the header; also wires `aria-labelledby`. With a custom `header`
9
+ * snippet the title is not rendered but still names the dialog (as `aria-label`) unless
10
+ * the snippet labels it via the `titleId` it receives.
11
+ */
7
12
  title?: string;
8
13
  /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
9
14
  size?: Size;
@@ -23,10 +28,18 @@ interface Props {
23
28
  danger?: boolean;
24
29
  /** Accessible name when no `title` is set (maps to aria-label on the dialog). */
25
30
  'aria-label'?: string;
26
- /** Called after the dialog has closed (any reason: Esc, backdrop, button). */
27
- onclose?: () => void;
28
- /** Header content; replaces the default title row when provided. */
29
- header?: Snippet;
31
+ /**
32
+ * Called after the dialog has closed, with why (`details.reason`: escape · backdrop ·
33
+ * button · programmatic — the last one covers the `open` prop, a direct `.close()` and a
34
+ * `<form method="dialog">`).
35
+ */
36
+ onclose?: (details: ModalCloseDetails) => void;
37
+ /**
38
+ * Header content; replaces the default title row when provided. Receives the id the
39
+ * dialog's `aria-labelledby` points at — put it on your heading (`id={titleId}`) so the
40
+ * dialog keeps its accessible name.
41
+ */
42
+ header?: Snippet<[string]>;
30
43
  /** Footer content (typically action buttons). */
31
44
  footer?: Snippet;
32
45
  /** Body content. */