dssoca 0.20.0 → 0.22.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 (133) hide show
  1. package/README.md +3 -3
  2. package/dist/components/Accordion.svelte +23 -52
  3. package/dist/components/BottomNav.svelte +18 -28
  4. package/dist/components/BoxPlot.svelte +7 -6
  5. package/dist/components/BumpChart.svelte +9 -12
  6. package/dist/components/Chart.svelte +9 -12
  7. package/dist/components/Checkbox.svelte +210 -0
  8. package/dist/components/Checkbox.svelte.d.ts +38 -0
  9. package/dist/components/FileDrop.svelte +52 -83
  10. package/dist/components/FileDrop.svelte.d.ts +6 -2
  11. package/dist/components/Heatmap.svelte +8 -8
  12. package/dist/components/Image.svelte +44 -44
  13. package/dist/components/Input.svelte +8 -3
  14. package/dist/components/LogStream.svelte +15 -25
  15. package/dist/components/Menu.svelte +69 -94
  16. package/dist/components/Menu.svelte.d.ts +6 -0
  17. package/dist/components/Modal.svelte +61 -14
  18. package/dist/components/Modal.svelte.d.ts +7 -2
  19. package/dist/components/NumberField.svelte +18 -19
  20. package/dist/components/Pagination.svelte +47 -37
  21. package/dist/components/Pagination.svelte.d.ts +6 -2
  22. package/dist/components/Popover.svelte +404 -0
  23. package/dist/components/Popover.svelte.d.ts +55 -0
  24. package/dist/components/RadioGroup.svelte +227 -0
  25. package/dist/components/RadioGroup.svelte.d.ts +42 -0
  26. package/dist/components/ScatterPlot.svelte +11 -13
  27. package/dist/components/SearchPalette.svelte +124 -120
  28. package/dist/components/SearchPalette.svelte.d.ts +6 -4
  29. package/dist/components/SegmentedControl.svelte +41 -62
  30. package/dist/components/SegmentedControl.svelte.d.ts +7 -2
  31. package/dist/components/ShortcutsHelp.svelte +48 -47
  32. package/dist/components/Sidebar.svelte +48 -60
  33. package/dist/components/Switch.svelte +20 -10
  34. package/dist/components/Switch.svelte.d.ts +6 -2
  35. package/dist/components/Table.svelte +15 -37
  36. package/dist/components/Tabs.svelte +223 -0
  37. package/dist/components/Tabs.svelte.d.ts +51 -0
  38. package/dist/components/TierList.svelte +41 -38
  39. package/dist/components/TierList.svelte.d.ts +7 -3
  40. package/dist/components/Toaster.svelte +29 -29
  41. package/dist/components/Tooltip.svelte +37 -21
  42. package/dist/components/Topbar.svelte +13 -38
  43. package/dist/core/accordion.d.ts +32 -0
  44. package/dist/core/accordion.js +53 -0
  45. package/dist/core/behaviors/focusable.d.ts +5 -0
  46. package/dist/core/behaviors/focusable.js +14 -0
  47. package/dist/core/behaviors/roving.d.ts +13 -0
  48. package/dist/core/behaviors/roving.js +29 -0
  49. package/dist/core/bottom-nav.d.ts +36 -0
  50. package/dist/core/bottom-nav.js +33 -0
  51. package/dist/core/chart-nav.d.ts +53 -0
  52. package/dist/{chart-nav.js → core/chart-nav.js} +27 -0
  53. package/dist/core/checkbox.d.ts +36 -0
  54. package/dist/core/checkbox.js +29 -0
  55. package/dist/core/file-drop.d.ts +75 -0
  56. package/dist/core/file-drop.js +101 -0
  57. package/dist/core/image.d.ts +59 -0
  58. package/dist/core/image.js +64 -0
  59. package/dist/core/input.d.ts +21 -0
  60. package/dist/core/input.js +17 -0
  61. package/dist/core/log-stream.d.ts +51 -0
  62. package/dist/core/log-stream.js +50 -0
  63. package/dist/core/menu.d.ts +70 -0
  64. package/dist/core/menu.js +84 -0
  65. package/dist/core/modal.d.ts +59 -0
  66. package/dist/core/modal.js +44 -0
  67. package/dist/core/number-field.d.ts +47 -0
  68. package/dist/core/number-field.js +64 -0
  69. package/dist/core/pagination.d.ts +59 -0
  70. package/dist/core/pagination.js +65 -0
  71. package/dist/core/popover.d.ts +111 -0
  72. package/dist/core/popover.js +86 -0
  73. package/dist/core/radio.d.ts +36 -0
  74. package/dist/core/radio.js +48 -0
  75. package/dist/core/search-palette.d.ts +124 -0
  76. package/dist/core/search-palette.js +149 -0
  77. package/dist/core/segmented.d.ts +46 -0
  78. package/dist/core/segmented.js +66 -0
  79. package/dist/core/shortcuts-help.d.ts +56 -0
  80. package/dist/core/shortcuts-help.js +50 -0
  81. package/dist/core/sidebar.d.ts +63 -0
  82. package/dist/core/sidebar.js +84 -0
  83. package/dist/core/switch.d.ts +19 -0
  84. package/dist/core/switch.js +11 -0
  85. package/dist/core/table.d.ts +40 -0
  86. package/dist/core/table.js +57 -0
  87. package/dist/core/tabs.d.ts +84 -0
  88. package/dist/core/tabs.js +90 -0
  89. package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +62 -0
  90. package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
  91. package/dist/core/toast.d.ts +112 -0
  92. package/dist/{toast-core.js → core/toast.js} +48 -2
  93. package/dist/core/tooltip.d.ts +47 -0
  94. package/dist/core/tooltip.js +51 -0
  95. package/dist/core/topbar.d.ts +41 -0
  96. package/dist/core/topbar.js +52 -0
  97. package/dist/dssoca.config.d.ts +1 -1
  98. package/dist/dssoca.config.js +4 -0
  99. package/dist/index.d.ts +14 -1
  100. package/dist/index.js +9 -1
  101. package/dist/theme.css +47 -0
  102. package/dist/toast.svelte.d.ts +2 -2
  103. package/dist/toast.svelte.js +1 -1
  104. package/dist/tokens.css +47 -0
  105. package/dist/vanilla/accordion.js +28 -29
  106. package/dist/vanilla/checkbox.d.ts +8 -0
  107. package/dist/vanilla/checkbox.js +43 -0
  108. package/dist/vanilla/delegate.d.ts +2 -0
  109. package/dist/vanilla/delegate.js +9 -0
  110. package/dist/vanilla/fields.js +37 -32
  111. package/dist/vanilla/index.d.ts +4 -0
  112. package/dist/vanilla/index.js +16 -3
  113. package/dist/vanilla/menu.js +92 -86
  114. package/dist/vanilla/modal.d.ts +3 -1
  115. package/dist/vanilla/modal.js +65 -15
  116. package/dist/vanilla/popover.d.ts +10 -0
  117. package/dist/vanilla/popover.js +199 -0
  118. package/dist/vanilla/radio.d.ts +3 -0
  119. package/dist/vanilla/radio.js +54 -0
  120. package/dist/vanilla/segmented.js +49 -51
  121. package/dist/vanilla/switch.d.ts +2 -1
  122. package/dist/vanilla/switch.js +13 -8
  123. package/dist/vanilla/tabs.d.ts +2 -0
  124. package/dist/vanilla/tabs.js +87 -0
  125. package/dist/vanilla/tierlist.d.ts +1 -1
  126. package/dist/vanilla/tierlist.js +32 -25
  127. package/dist/vanilla/toast.d.ts +2 -2
  128. package/dist/vanilla/toast.js +16 -14
  129. package/dist/vanilla/tooltip.js +35 -23
  130. package/dist/vanilla.css +364 -42
  131. package/package.json +1 -1
  132. package/dist/chart-nav.d.ts +0 -13
  133. package/dist/toast-core.d.ts +0 -61
@@ -0,0 +1,404 @@
1
+ <script lang="ts">
2
+ // ─────────────────────────────────────────────────────────────────────────
3
+ // Popover — DS-0197. A non-modal floating panel anchored to a trigger button:
4
+ // Menu's sibling for arbitrary content (filters, a short form, details).
5
+ // Opening moves focus into the panel; Escape, an outside press or tabbing out
6
+ // dismiss it. `openOn="hover"` makes it a hover card (DS-0206): hover or focus
7
+ // peeks it open without moving focus, a press runs `onactivate`. Every
8
+ // decision is made in `core/popover.ts`, shared with vanilla/popover.ts.
9
+ // Placement is side / align, kept inside the viewport by `avoidCollisions`.
10
+ // ─────────────────────────────────────────────────────────────────────────
11
+ import { tick, untrack, type Snippet } from 'svelte'
12
+ import { resolveComponentSize, type Size } from '../config.js'
13
+ import { focusPopoverPanel } from '../vanilla/popover.js'
14
+ import {
15
+ POPOVER_HOVER_CLOSE_DELAY,
16
+ POPOVER_HOVER_OPEN_DELAY,
17
+ popoverFocusIn,
18
+ popoverFocusOut,
19
+ popoverHoverEnter,
20
+ popoverHoverLeave,
21
+ popoverKey,
22
+ popoverOutsidePress,
23
+ popoverPanelAttrs,
24
+ popoverTriggerAttrs,
25
+ popoverTriggerPress,
26
+ type PopoverAction,
27
+ type PopoverOpenChangeDetails,
28
+ type PopoverOpenOn,
29
+ type PopoverState,
30
+ } from '../core/popover.js'
31
+
32
+ /** Where the panel attaches relative to the trigger. */
33
+ type Align = 'start' | 'end'
34
+ type Side = 'bottom' | 'top'
35
+
36
+ interface Props {
37
+ /**
38
+ * Open state. `bindable` so callers can control it; left alone it behaves
39
+ * as an uncontrolled popover (toggled by the trigger / dismissal).
40
+ */
41
+ open?: boolean
42
+ /**
43
+ * Fired when the popover opens or closes itself, with the new state and why
44
+ * (`details.reason`: trigger · escape · outside · tab, plus hover · focus · leave in
45
+ * hover mode).
46
+ */
47
+ onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void
48
+ /**
49
+ * What opens the panel. `press` (default): the trigger toggles it and focus moves in.
50
+ * `hover`: a hover card — hovering or focusing the trigger shows it without moving focus,
51
+ * the pointer can travel onto the panel, leaving both closes it; a touch tap shows it.
52
+ */
53
+ openOn?: PopoverOpenOn
54
+ /**
55
+ * Hover mode only: the trigger's own action, run when it is pressed (a click, Enter /
56
+ * Space, or a second tap on touch) — e.g. open a details view. Without it a press
57
+ * toggles the card.
58
+ */
59
+ onactivate?: (e: MouseEvent) => void
60
+ /**
61
+ * Keep the panel inside the viewport: flip to the other side / edge when the preferred
62
+ * one has no room, then shift along the inline axis. `false` pins `side` / `align`.
63
+ * Default `true`.
64
+ */
65
+ avoidCollisions?: boolean
66
+ /** Vertical side the panel opens toward. */
67
+ side?: Side
68
+ /** Horizontal edge the panel aligns to. */
69
+ align?: Align
70
+ /**
71
+ * Accessible label for the panel (`role="dialog"`). When omitted the
72
+ * panel is named by the trigger's text via `aria-labelledby`.
73
+ */
74
+ label?: string
75
+ /** Token size (sm|md|lg); inherits the global size when unset. */
76
+ size?: Size
77
+ /** Trigger content (rendered inside the toggle button). */
78
+ trigger?: Snippet
79
+ /** Panel content. */
80
+ children?: Snippet
81
+ }
82
+
83
+ let {
84
+ open = $bindable(false),
85
+ onOpenChange,
86
+ openOn = 'press',
87
+ onactivate,
88
+ avoidCollisions = true,
89
+ side = 'bottom',
90
+ align = 'start',
91
+ label,
92
+ size,
93
+ trigger,
94
+ children,
95
+ }: Props = $props()
96
+
97
+ const uid = $props.id()
98
+ const panelId = `${uid}-panel`
99
+ const triggerId = `${uid}-trigger`
100
+
101
+ let rootEl = $state<HTMLElement>()
102
+ let triggerEl = $state<HTMLButtonElement>()
103
+ let panelEl = $state<HTMLElement>()
104
+
105
+ // Behaviour lives in `core/popover.ts` (shared with vanilla/popover.ts): events go in,
106
+ // a PopoverAction comes out, and `run` applies it to this component's state.
107
+ const popover = $derived<PopoverState>({ open })
108
+
109
+ // A `peek` opens without moving focus (hover mode); a returned focus must not
110
+ // re-peek the card through the trigger's focusin.
111
+ let focusOnOpen = true
112
+ let quietFocus = false
113
+
114
+ function run(action: PopoverAction | null, e?: MouseEvent) {
115
+ if (!action) return
116
+ clearTimers()
117
+ if (action.type === 'activate') {
118
+ if (e) onactivate?.(e)
119
+ } else if (action.type === 'open' || action.type === 'peek') {
120
+ focusOnOpen = action.type === 'open'
121
+ open = true
122
+ onOpenChange?.(true, { reason: action.reason })
123
+ } else {
124
+ open = false
125
+ onOpenChange?.(false, { reason: action.reason })
126
+ if (action.returnFocus) {
127
+ quietFocus = true
128
+ triggerEl?.focus()
129
+ quietFocus = false
130
+ }
131
+ }
132
+ }
133
+
134
+ // --- hover mode -------------------------------------------------------------
135
+ let openTimer: ReturnType<typeof setTimeout> | undefined
136
+ let closeTimer: ReturnType<typeof setTimeout> | undefined
137
+ function clearTimers() {
138
+ clearTimeout(openTimer)
139
+ clearTimeout(closeTimer)
140
+ }
141
+ $effect(() => clearTimers)
142
+
143
+ function onPointerEnter(e: PointerEvent) {
144
+ if (openOn !== 'hover' || e.pointerType !== 'mouse') return
145
+ clearTimeout(closeTimer)
146
+ if (open) return
147
+ openTimer = setTimeout(() => run(popoverHoverEnter(popover)), POPOVER_HOVER_OPEN_DELAY)
148
+ }
149
+ function onPointerLeave(e: PointerEvent) {
150
+ if (openOn !== 'hover' || e.pointerType !== 'mouse') return
151
+ clearTimeout(openTimer)
152
+ closeTimer = setTimeout(() => run(popoverHoverLeave(popover)), POPOVER_HOVER_CLOSE_DELAY)
153
+ }
154
+ function onFocusIn(e: FocusEvent) {
155
+ if (quietFocus || e.target !== triggerEl) return
156
+ run(popoverFocusIn(popover, openOn))
157
+ }
158
+
159
+ // The pointer type of the press that becomes the next click ('' = keyboard).
160
+ // Listened on the trigger itself: a Svelte `onpointerdown` attribute would be
161
+ // delegated to the document, which must stay listener-free while closed.
162
+ let pressType = ''
163
+ $effect(() => {
164
+ const el = triggerEl
165
+ if (!el) return
166
+ const onDown = (e: PointerEvent) => (pressType = e.pointerType)
167
+ el.addEventListener('pointerdown', onDown)
168
+ return () => el.removeEventListener('pointerdown', onDown)
169
+ })
170
+ function onTriggerClick(e: MouseEvent) {
171
+ const action = popoverTriggerPress(popover, {
172
+ openOn,
173
+ pointerType: pressType,
174
+ hasAction: Boolean(onactivate),
175
+ })
176
+ pressType = ''
177
+ run(action, e)
178
+ }
179
+
180
+ // --- collision avoidance ------------------------------------------------------
181
+ // Measured when the panel opens: flip side / align toward the room, then shift
182
+ // along the inline axis so the panel never overhangs the viewport.
183
+ let flippedSide = $state<Side | null>(null)
184
+ let flippedAlign = $state<Align | null>(null)
185
+ let shift = $state(0)
186
+ const resolvedSide = $derived(flippedSide ?? side)
187
+ const resolvedAlign = $derived(flippedAlign ?? align)
188
+ const VIEWPORT_MARGIN = 8
189
+
190
+ async function place() {
191
+ flippedSide = null
192
+ flippedAlign = null
193
+ shift = 0
194
+ if (!avoidCollisions || !rootEl || !panelEl || typeof window === 'undefined') return
195
+ const r = rootEl.getBoundingClientRect()
196
+ const w = panelEl.offsetWidth
197
+ const h = panelEl.offsetHeight
198
+ const vw = window.innerWidth
199
+ const vh = window.innerHeight
200
+ const below = vh - r.bottom
201
+ const above = r.top
202
+ if (side === 'bottom' && below < h + VIEWPORT_MARGIN && above > below) flippedSide = 'top'
203
+ if (side === 'top' && above < h + VIEWPORT_MARGIN && below > above) flippedSide = 'bottom'
204
+ const rtl = getComputedStyle(rootEl).direction === 'rtl'
205
+ // Physical left edge of the panel for an inline alignment.
206
+ const leftFor = (a: Align) => ((a === 'start') !== rtl ? r.left : r.right - w)
207
+ const fits = (left: number) => left >= VIEWPORT_MARGIN && left + w <= vw - VIEWPORT_MARGIN
208
+ let a: Align = align
209
+ if (!fits(leftFor(a))) {
210
+ const other: Align = a === 'start' ? 'end' : 'start'
211
+ if (fits(leftFor(other))) {
212
+ a = other
213
+ flippedAlign = other
214
+ }
215
+ }
216
+ const left = leftFor(a)
217
+ const min = VIEWPORT_MARGIN
218
+ const max = vw - VIEWPORT_MARGIN - w
219
+ shift = left < min ? min - left : left > max ? Math.max(min, max) - left : 0
220
+ await tick()
221
+ }
222
+
223
+ // Opening moves focus into the panel: its first focusable element, else the panel itself
224
+ // (`focusPopoverPanel`, shared with the vanilla path, which also covers content that is not
225
+ // focusable on the first frame). Runs after the DOM reflects `open` (the closed panel is inert), for an open the component
226
+ // made and for one the parent made through `bind:open` — but not for a popover that is
227
+ // rendered open, which must not grab focus on page load.
228
+ let wasOpen = untrack(() => open)
229
+ $effect(() => {
230
+ const isOpen = open
231
+ if (isOpen && !wasOpen && panelEl) {
232
+ untrack(() => place())
233
+ if (focusOnOpen) focusPopoverPanel(panelEl)
234
+ }
235
+ focusOnOpen = true
236
+ wasOpen = isOpen
237
+ })
238
+
239
+ function onKeydown(e: KeyboardEvent) {
240
+ // Something inside (a nested Menu, say) already used this key.
241
+ if (e.defaultPrevented) return
242
+ const result = popoverKey(popover, e.key)
243
+ if (!result) return
244
+ if (result.preventDefault) e.preventDefault()
245
+ run(result.action)
246
+ }
247
+
248
+ function onFocusOut(e: FocusEvent) {
249
+ const to = e.relatedTarget as Node | null
250
+ run(popoverFocusOut(popover, !to ? 'nowhere' : rootEl?.contains(to) ? 'inside' : 'outside'))
251
+ }
252
+
253
+ // Pointer-down outside the root closes the popover (same model as Menu).
254
+ function onDocPointerDown(e: PointerEvent) {
255
+ if (rootEl && rootEl.contains(e.target as Node)) return
256
+ run(popoverOutsidePress(popover))
257
+ }
258
+
259
+ // SSR safety: same guard pattern as Menu.
260
+ const hasDocument = typeof document !== 'undefined'
261
+
262
+ $effect(() => {
263
+ if (!open || !hasDocument) return
264
+ document.addEventListener('pointerdown', onDocPointerDown, true)
265
+ return () => document.removeEventListener('pointerdown', onDocPointerDown, true)
266
+ })
267
+
268
+ const sizeAttr = $derived(resolveComponentSize('Popover', size))
269
+ </script>
270
+
271
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
272
+ <div
273
+ bind:this={rootEl}
274
+ class="ss-popover"
275
+ data-size-variant={sizeAttr}
276
+ data-align={resolvedAlign}
277
+ data-side={resolvedSide}
278
+ data-open-on={openOn}
279
+ onkeydown={onKeydown}
280
+ onfocusin={onFocusIn}
281
+ onfocusout={onFocusOut}
282
+ onpointerenter={onPointerEnter}
283
+ onpointerleave={onPointerLeave}
284
+ >
285
+ <button
286
+ bind:this={triggerEl}
287
+ id={triggerId}
288
+ type="button"
289
+ class="trigger"
290
+ {...popoverTriggerAttrs(open)}
291
+ aria-controls={panelId}
292
+ onclick={onTriggerClick}
293
+ >
294
+ {@render trigger?.()}
295
+ </button>
296
+
297
+ <div
298
+ bind:this={panelEl}
299
+ id={panelId}
300
+ class="panel"
301
+ class:open
302
+ aria-label={label || undefined}
303
+ aria-labelledby={label ? undefined : triggerId}
304
+ {...popoverPanelAttrs()}
305
+ inert={!open || undefined}
306
+ style:--ss-popover-shift={shift ? `${shift}px` : undefined}
307
+ >
308
+ {@render children?.()}
309
+ </div>
310
+ </div>
311
+
312
+ <style>.ss-popover {
313
+ position: relative;
314
+ display: inline-block;
315
+ }
316
+
317
+ .trigger {
318
+ display: inline-flex;
319
+ align-items: center;
320
+ gap: var(--ss-gap-sm);
321
+ font: 500 var(--ss-control-font) var(--ss-font-mono);
322
+ color: var(--ss-fg);
323
+ background: transparent;
324
+ border: 1px solid var(--ss-line);
325
+ padding: var(--ss-control-py) var(--ss-control-px);
326
+ cursor: pointer;
327
+ transition: border-color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease), color var(--ss-dur-fast) var(--ss-ease);
328
+ }
329
+ .trigger:hover, .trigger[aria-expanded=true] {
330
+ border-color: var(--ss-line-strong);
331
+ background: var(--ss-hover);
332
+ }
333
+ .trigger:focus-visible {
334
+ border-color: var(--ss-primary);
335
+ }
336
+
337
+ .panel {
338
+ position: absolute;
339
+ z-index: 50;
340
+ box-sizing: border-box;
341
+ width: max-content;
342
+ min-width: var(--ss-popover-min-w);
343
+ max-width: min(var(--ss-popover-max-w), 100vw - 2 * var(--ss-s-4));
344
+ padding: var(--ss-popover-pad);
345
+ font-size: var(--ss-ui-md);
346
+ color: var(--ss-fg);
347
+ text-align: start;
348
+ background: var(--ss-bg-elev);
349
+ border: 1px solid var(--ss-line);
350
+ box-shadow: var(--ss-shadow-pop);
351
+ translate: var(--ss-popover-shift, 0px) 0;
352
+ opacity: 0;
353
+ visibility: hidden;
354
+ pointer-events: none;
355
+ transform: translateY(-6px) scale(0.98);
356
+ transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear var(--ss-dur);
357
+ }
358
+ .panel.open {
359
+ opacity: 1;
360
+ visibility: visible;
361
+ pointer-events: auto;
362
+ transform: translateY(0) scale(1);
363
+ transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear 0s;
364
+ }
365
+ .panel:focus-visible {
366
+ outline-offset: -2px;
367
+ }
368
+
369
+ .ss-popover[data-side=bottom] .panel {
370
+ top: calc(100% + var(--ss-popover-offset));
371
+ transform-origin: top;
372
+ }
373
+
374
+ .ss-popover[data-side=top] .panel {
375
+ bottom: calc(100% + var(--ss-popover-offset));
376
+ transform-origin: bottom;
377
+ }
378
+
379
+ .ss-popover[data-side=top] .panel:not(.open) {
380
+ transform: translateY(6px) scale(0.98);
381
+ }
382
+
383
+ .ss-popover[data-align=start] .panel {
384
+ inset-inline-start: 0;
385
+ }
386
+
387
+ .ss-popover[data-align=end] .panel {
388
+ inset-inline-end: 0;
389
+ }
390
+
391
+ .ss-popover[data-open-on=hover] .panel.open::before {
392
+ content: "";
393
+ position: absolute;
394
+ inset-inline: 0;
395
+ height: var(--ss-popover-offset);
396
+ }
397
+
398
+ .ss-popover[data-open-on=hover][data-side=bottom] .panel.open::before {
399
+ bottom: 100%;
400
+ }
401
+
402
+ .ss-popover[data-open-on=hover][data-side=top] .panel.open::before {
403
+ top: 100%;
404
+ }</style>
@@ -0,0 +1,55 @@
1
+ import { type Snippet } from 'svelte';
2
+ import { type Size } from '../config.js';
3
+ import { type PopoverOpenChangeDetails, type PopoverOpenOn } from '../core/popover.js';
4
+ /** Where the panel attaches relative to the trigger. */
5
+ type Align = 'start' | 'end';
6
+ type Side = 'bottom' | 'top';
7
+ interface Props {
8
+ /**
9
+ * Open state. `bindable` so callers can control it; left alone it behaves
10
+ * as an uncontrolled popover (toggled by the trigger / dismissal).
11
+ */
12
+ open?: boolean;
13
+ /**
14
+ * Fired when the popover opens or closes itself, with the new state and why
15
+ * (`details.reason`: trigger · escape · outside · tab, plus hover · focus · leave in
16
+ * hover mode).
17
+ */
18
+ onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void;
19
+ /**
20
+ * What opens the panel. `press` (default): the trigger toggles it and focus moves in.
21
+ * `hover`: a hover card — hovering or focusing the trigger shows it without moving focus,
22
+ * the pointer can travel onto the panel, leaving both closes it; a touch tap shows it.
23
+ */
24
+ openOn?: PopoverOpenOn;
25
+ /**
26
+ * Hover mode only: the trigger's own action, run when it is pressed (a click, Enter /
27
+ * Space, or a second tap on touch) — e.g. open a details view. Without it a press
28
+ * toggles the card.
29
+ */
30
+ onactivate?: (e: MouseEvent) => void;
31
+ /**
32
+ * Keep the panel inside the viewport: flip to the other side / edge when the preferred
33
+ * one has no room, then shift along the inline axis. `false` pins `side` / `align`.
34
+ * Default `true`.
35
+ */
36
+ avoidCollisions?: boolean;
37
+ /** Vertical side the panel opens toward. */
38
+ side?: Side;
39
+ /** Horizontal edge the panel aligns to. */
40
+ align?: Align;
41
+ /**
42
+ * Accessible label for the panel (`role="dialog"`). When omitted the
43
+ * panel is named by the trigger's text via `aria-labelledby`.
44
+ */
45
+ label?: string;
46
+ /** Token size (sm|md|lg); inherits the global size when unset. */
47
+ size?: Size;
48
+ /** Trigger content (rendered inside the toggle button). */
49
+ trigger?: Snippet;
50
+ /** Panel content. */
51
+ children?: Snippet;
52
+ }
53
+ declare const Popover: import("svelte").Component<Props, {}, "open">;
54
+ type Popover = ReturnType<typeof Popover>;
55
+ export default Popover;
@@ -0,0 +1,227 @@
1
+ <script module lang="ts">
2
+ /** One option in a {@link RadioGroup}. */
3
+ export interface RadioOption {
4
+ value: string
5
+ label: string
6
+ disabled?: boolean
7
+ }
8
+ </script>
9
+
10
+ <script lang="ts">
11
+ // ─────────────────────────────────────────────────────────────────────────
12
+ // RadioGroup — DS-0197. Native `<input type="radio">` elements sharing a
13
+ // `name` inside a `role="radiogroup"` named by its visible label. Arrow keys
14
+ // (wrapping, skipping disabled, mirrored under RTL), Space and form
15
+ // submission come from the platform, so this file handles no key at all.
16
+ // House rule: square radios (zero radius) — a filled inner square marks the
17
+ // selected one. Each input IS its box (`appearance: none`), so the base focus
18
+ // ring lands on it.
19
+ // ─────────────────────────────────────────────────────────────────────────
20
+ import { resolveComponentSize, type Size } from '../config.js'
21
+ import {
22
+ radioEnabled,
23
+ radioGroupAttrs,
24
+ radioInputAttrs,
25
+ radioPress,
26
+ radioTabStop,
27
+ type RadioState,
28
+ } from '../core/radio.js'
29
+
30
+ interface Props {
31
+ /** Mutually-exclusive options: { value, label, disabled? }. */
32
+ options?: RadioOption[]
33
+ /** Selected option value (bindable); unset = nothing selected. */
34
+ value?: string
35
+ /**
36
+ * Form field name shared by the radios (the selected value is submitted
37
+ * with the form). Defaults to a generated per-instance name, which is what
38
+ * makes the inputs one native group.
39
+ */
40
+ name?: string
41
+ /**
42
+ * Visible group label; names the radiogroup. Required (WCAG 2.2 AA): a
43
+ * radiogroup with no name leaves AT users without context for the choice.
44
+ */
45
+ label: string
46
+ /** Stack the options (`vertical`, default) or lay them out in a row. */
47
+ orientation?: 'vertical' | 'horizontal'
48
+ /**
49
+ * Disable the whole group: every radio is `disabled` and the group carries
50
+ * `aria-disabled="true"`. Per-option `disabled` still works on its own.
51
+ */
52
+ disabled?: boolean
53
+ /** Token size (sm|md|lg); inherits the global size when unset. */
54
+ size?: Size
55
+ /**
56
+ * Fired when the selection changes (after `value` updates), with the new
57
+ * value. There is no `details.reason`: the native inputs report a press and
58
+ * an arrow key as the same event.
59
+ */
60
+ onChange?: (value: string) => void
61
+ }
62
+
63
+ let {
64
+ options = [],
65
+ value = $bindable(),
66
+ name,
67
+ label,
68
+ orientation = 'vertical',
69
+ disabled = false,
70
+ size,
71
+ onChange,
72
+ }: Props = $props()
73
+
74
+ const uid = $props.id()
75
+ const labelId = `${uid}-label`
76
+ // Radios only form a native group (one selection, arrow keys) when they share a name.
77
+ const groupName = $derived(name ?? `${uid}-radio`)
78
+
79
+ let inputs = $state<(HTMLInputElement | undefined)[]>([])
80
+
81
+ // The group's state as `core/radio.ts` sees it. Every decision that is ours
82
+ // (enabled options, what a pick selects, the tab stop) is made there, shared
83
+ // with vanilla/radio.ts.
84
+ const group = $derived<RadioState>({
85
+ selected: options.findIndex((o) => o.value === value),
86
+ enabled: radioEnabled(
87
+ options.map((o) => Boolean(o.disabled)),
88
+ disabled,
89
+ ),
90
+ })
91
+ const tabStop = $derived(radioTabStop(group))
92
+
93
+ // The browser has already checked the input (press, Space or arrow key); the
94
+ // core confirms the pick and the result is written back.
95
+ function onPick(index: number) {
96
+ const action = radioPress(group, index)
97
+ const opt = options[index]
98
+ if (!action || !opt) {
99
+ // Not ours to select: put the DOM back on the current selection.
100
+ inputs.forEach((el, i) => {
101
+ if (el) el.checked = i === group.selected
102
+ })
103
+ return
104
+ }
105
+ if (action.changed) {
106
+ value = opt.value
107
+ onChange?.(opt.value)
108
+ }
109
+ }
110
+
111
+ const sizeAttr = $derived(resolveComponentSize('RadioGroup', size))
112
+ </script>
113
+
114
+ <div
115
+ class="ss-radio-group"
116
+ aria-labelledby={labelId}
117
+ data-orientation={orientation}
118
+ data-size-variant={sizeAttr}
119
+ {...radioGroupAttrs(disabled)}
120
+ >
121
+ <span id={labelId} class="legend">{label}</span>
122
+ <div class="options">
123
+ {#each options as opt, i (opt.value)}
124
+ <label class="option">
125
+ <span class="control">
126
+ <input
127
+ bind:this={inputs[i]}
128
+ class="input"
129
+ type="radio"
130
+ name={groupName}
131
+ value={opt.value}
132
+ checked={i === group.selected}
133
+ disabled={disabled || Boolean(opt.disabled)}
134
+ {...radioInputAttrs(i, tabStop)}
135
+ onchange={() => onPick(i)}
136
+ />
137
+ <span class="dot" aria-hidden="true"></span>
138
+ </span>
139
+ <span class="label">{opt.label}</span>
140
+ </label>
141
+ {/each}
142
+ </div>
143
+ </div>
144
+
145
+ <style>.ss-radio-group {
146
+ display: inline-flex;
147
+ flex-direction: column;
148
+ gap: var(--ss-gap-xs);
149
+ max-inline-size: 100%;
150
+ }
151
+ .ss-radio-group .legend {
152
+ font: 500 var(--ss-ui-sm)/1.3 var(--ss-font-body);
153
+ color: var(--ss-fg-muted);
154
+ }
155
+ .ss-radio-group .options {
156
+ display: flex;
157
+ flex-direction: column;
158
+ gap: var(--ss-radio-gap, var(--ss-gap-xs));
159
+ }
160
+ .ss-radio-group[data-orientation=horizontal] .options {
161
+ flex-flow: row wrap;
162
+ column-gap: var(--ss-gap);
163
+ }
164
+ .ss-radio-group .option {
165
+ display: inline-flex;
166
+ align-items: center;
167
+ gap: var(--ss-gap-sm);
168
+ min-inline-size: var(--ss-s-6);
169
+ min-block-size: var(--ss-s-6);
170
+ cursor: pointer;
171
+ }
172
+ .ss-radio-group .control {
173
+ position: relative;
174
+ flex: 0 0 auto;
175
+ display: inline-grid;
176
+ inline-size: var(--ss-radio-size, calc(var(--ss-control-font) + 4px));
177
+ block-size: var(--ss-radio-size, calc(var(--ss-control-font) + 4px));
178
+ }
179
+ .ss-radio-group .input {
180
+ grid-area: 1/1;
181
+ appearance: none;
182
+ box-sizing: border-box;
183
+ inline-size: 100%;
184
+ block-size: 100%;
185
+ margin: 0;
186
+ border-radius: 0;
187
+ border: 1px solid var(--ss-fg-faint);
188
+ background: var(--ss-bg);
189
+ cursor: inherit;
190
+ transition: border-color var(--ss-dur-fast) var(--ss-ease);
191
+ }
192
+ .ss-radio-group .input:not(:disabled):hover {
193
+ border-color: var(--ss-fg);
194
+ }
195
+ .ss-radio-group .input:checked {
196
+ border-color: var(--ss-primary);
197
+ }
198
+ .ss-radio-group .dot {
199
+ grid-area: 1/1;
200
+ place-self: center;
201
+ display: none;
202
+ inline-size: calc(var(--ss-radio-size, calc(var(--ss-control-font) + 4px)) - 8px);
203
+ block-size: calc(var(--ss-radio-size, calc(var(--ss-control-font) + 4px)) - 8px);
204
+ background: var(--ss-primary);
205
+ pointer-events: none;
206
+ }
207
+ .ss-radio-group .input:checked + .dot {
208
+ display: block;
209
+ }
210
+ .ss-radio-group .label {
211
+ font: 500 var(--ss-control-font)/1.3 var(--ss-font-body);
212
+ color: var(--ss-fg);
213
+ user-select: none;
214
+ }
215
+ .ss-radio-group .option:has(.input:disabled) {
216
+ cursor: not-allowed;
217
+ }
218
+ .ss-radio-group .option:has(.input:disabled) .control,
219
+ .ss-radio-group .option:has(.input:disabled) .label {
220
+ opacity: 0.45;
221
+ }
222
+
223
+ @media (prefers-reduced-motion: reduce) {
224
+ .ss-radio-group .input {
225
+ transition: none;
226
+ }
227
+ }</style>