dssoca 0.20.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.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +23 -52
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +7 -6
- package/dist/components/BumpChart.svelte +9 -12
- package/dist/components/Chart.svelte +9 -12
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/FileDrop.svelte +52 -83
- package/dist/components/FileDrop.svelte.d.ts +6 -2
- package/dist/components/Heatmap.svelte +8 -8
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +8 -3
- package/dist/components/LogStream.svelte +15 -25
- package/dist/components/Menu.svelte +69 -94
- package/dist/components/Menu.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +61 -14
- package/dist/components/Modal.svelte.d.ts +7 -2
- package/dist/components/NumberField.svelte +18 -19
- package/dist/components/Pagination.svelte +47 -37
- package/dist/components/Pagination.svelte.d.ts +6 -2
- package/dist/components/Popover.svelte +247 -0
- package/dist/components/Popover.svelte.d.ts +36 -0
- package/dist/components/RadioGroup.svelte +227 -0
- package/dist/components/RadioGroup.svelte.d.ts +42 -0
- package/dist/components/ScatterPlot.svelte +11 -13
- package/dist/components/SearchPalette.svelte +124 -120
- package/dist/components/SearchPalette.svelte.d.ts +6 -4
- package/dist/components/SegmentedControl.svelte +41 -62
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/ShortcutsHelp.svelte +48 -47
- package/dist/components/Sidebar.svelte +48 -60
- package/dist/components/Switch.svelte +20 -10
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +15 -37
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/TierList.svelte +38 -38
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +29 -29
- package/dist/components/Tooltip.svelte +37 -21
- package/dist/components/Topbar.svelte +13 -38
- package/dist/core/accordion.d.ts +32 -0
- package/dist/core/accordion.js +53 -0
- package/dist/core/behaviors/focusable.d.ts +5 -0
- package/dist/core/behaviors/focusable.js +14 -0
- package/dist/core/behaviors/roving.d.ts +13 -0
- package/dist/core/behaviors/roving.js +29 -0
- package/dist/core/bottom-nav.d.ts +36 -0
- package/dist/core/bottom-nav.js +33 -0
- package/dist/core/chart-nav.d.ts +53 -0
- package/dist/{chart-nav.js → core/chart-nav.js} +27 -0
- package/dist/core/checkbox.d.ts +36 -0
- package/dist/core/checkbox.js +29 -0
- package/dist/core/file-drop.d.ts +75 -0
- package/dist/core/file-drop.js +101 -0
- package/dist/core/image.d.ts +59 -0
- package/dist/core/image.js +64 -0
- package/dist/core/input.d.ts +21 -0
- package/dist/core/input.js +17 -0
- package/dist/core/log-stream.d.ts +51 -0
- package/dist/core/log-stream.js +50 -0
- package/dist/core/menu.d.ts +70 -0
- package/dist/core/menu.js +84 -0
- package/dist/core/modal.d.ts +59 -0
- package/dist/core/modal.js +44 -0
- package/dist/core/number-field.d.ts +47 -0
- package/dist/core/number-field.js +64 -0
- package/dist/core/pagination.d.ts +59 -0
- package/dist/core/pagination.js +65 -0
- package/dist/core/popover.d.ts +68 -0
- package/dist/core/popover.js +55 -0
- package/dist/core/radio.d.ts +36 -0
- package/dist/core/radio.js +48 -0
- package/dist/core/search-palette.d.ts +124 -0
- package/dist/core/search-palette.js +149 -0
- package/dist/core/segmented.d.ts +46 -0
- package/dist/core/segmented.js +66 -0
- package/dist/core/shortcuts-help.d.ts +56 -0
- package/dist/core/shortcuts-help.js +50 -0
- package/dist/core/sidebar.d.ts +63 -0
- package/dist/core/sidebar.js +84 -0
- package/dist/core/switch.d.ts +19 -0
- package/dist/core/switch.js +11 -0
- package/dist/core/table.d.ts +40 -0
- package/dist/core/table.js +57 -0
- package/dist/core/tabs.d.ts +84 -0
- package/dist/core/tabs.js +90 -0
- package/dist/{tierlist-core.d.ts → core/tierlist.d.ts} +62 -0
- package/dist/{tierlist-core.js → core/tierlist.js} +34 -0
- package/dist/core/toast.d.ts +112 -0
- package/dist/{toast-core.js → core/toast.js} +48 -2
- package/dist/core/tooltip.d.ts +47 -0
- package/dist/core/tooltip.js +51 -0
- package/dist/core/topbar.d.ts +41 -0
- package/dist/core/topbar.js +52 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +4 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.js +9 -1
- package/dist/theme.css +47 -0
- package/dist/toast.svelte.d.ts +2 -2
- package/dist/toast.svelte.js +1 -1
- package/dist/tokens.css +47 -0
- package/dist/vanilla/accordion.js +28 -29
- package/dist/vanilla/checkbox.d.ts +8 -0
- package/dist/vanilla/checkbox.js +43 -0
- package/dist/vanilla/delegate.d.ts +2 -0
- package/dist/vanilla/delegate.js +9 -0
- package/dist/vanilla/fields.js +37 -32
- package/dist/vanilla/index.d.ts +4 -0
- package/dist/vanilla/index.js +16 -3
- package/dist/vanilla/menu.js +92 -86
- package/dist/vanilla/modal.d.ts +3 -1
- package/dist/vanilla/modal.js +65 -15
- package/dist/vanilla/popover.d.ts +10 -0
- package/dist/vanilla/popover.js +129 -0
- package/dist/vanilla/radio.d.ts +3 -0
- package/dist/vanilla/radio.js +54 -0
- package/dist/vanilla/segmented.js +49 -51
- package/dist/vanilla/switch.d.ts +2 -1
- package/dist/vanilla/switch.js +13 -8
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +87 -0
- package/dist/vanilla/tierlist.d.ts +1 -1
- package/dist/vanilla/tierlist.js +29 -25
- package/dist/vanilla/toast.d.ts +2 -2
- package/dist/vanilla/toast.js +16 -14
- package/dist/vanilla/tooltip.js +35 -23
- package/dist/vanilla.css +349 -42
- package/package.json +1 -1
- package/dist/chart-nav.d.ts +0 -13
- package/dist/toast-core.d.ts +0 -61
|
@@ -0,0 +1,247 @@
|
|
|
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. Every decision is made in `core/popover.ts`, shared with
|
|
7
|
+
// vanilla/popover.ts. Placement is CSS-only (side / align), like Menu.
|
|
8
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
9
|
+
import { untrack, type Snippet } from 'svelte'
|
|
10
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
11
|
+
import { focusPopoverPanel } from '../vanilla/popover.js'
|
|
12
|
+
import {
|
|
13
|
+
popoverFocusOut,
|
|
14
|
+
popoverKey,
|
|
15
|
+
popoverOutsidePress,
|
|
16
|
+
popoverPanelAttrs,
|
|
17
|
+
popoverTriggerAttrs,
|
|
18
|
+
popoverTriggerPress,
|
|
19
|
+
type PopoverAction,
|
|
20
|
+
type PopoverOpenChangeDetails,
|
|
21
|
+
type PopoverState,
|
|
22
|
+
} from '../core/popover.js'
|
|
23
|
+
|
|
24
|
+
/** Where the panel attaches relative to the trigger. */
|
|
25
|
+
type Align = 'start' | 'end'
|
|
26
|
+
type Side = 'bottom' | 'top'
|
|
27
|
+
|
|
28
|
+
interface Props {
|
|
29
|
+
/**
|
|
30
|
+
* Open state. `bindable` so callers can control it; left alone it behaves
|
|
31
|
+
* as an uncontrolled popover (toggled by the trigger / dismissal).
|
|
32
|
+
*/
|
|
33
|
+
open?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* Fired when the popover opens or closes itself, with the new state and why
|
|
36
|
+
* (`details.reason`: trigger · escape · outside · tab).
|
|
37
|
+
*/
|
|
38
|
+
onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void
|
|
39
|
+
/** Vertical side the panel opens toward. */
|
|
40
|
+
side?: Side
|
|
41
|
+
/** Horizontal edge the panel aligns to. */
|
|
42
|
+
align?: Align
|
|
43
|
+
/**
|
|
44
|
+
* Accessible label for the panel (`role="dialog"`). When omitted the
|
|
45
|
+
* panel is named by the trigger's text via `aria-labelledby`.
|
|
46
|
+
*/
|
|
47
|
+
label?: string
|
|
48
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
49
|
+
size?: Size
|
|
50
|
+
/** Trigger content (rendered inside the toggle button). */
|
|
51
|
+
trigger?: Snippet
|
|
52
|
+
/** Panel content. */
|
|
53
|
+
children?: Snippet
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let {
|
|
57
|
+
open = $bindable(false),
|
|
58
|
+
onOpenChange,
|
|
59
|
+
side = 'bottom',
|
|
60
|
+
align = 'start',
|
|
61
|
+
label,
|
|
62
|
+
size,
|
|
63
|
+
trigger,
|
|
64
|
+
children,
|
|
65
|
+
}: Props = $props()
|
|
66
|
+
|
|
67
|
+
const uid = $props.id()
|
|
68
|
+
const panelId = `${uid}-panel`
|
|
69
|
+
const triggerId = `${uid}-trigger`
|
|
70
|
+
|
|
71
|
+
let rootEl = $state<HTMLElement>()
|
|
72
|
+
let triggerEl = $state<HTMLButtonElement>()
|
|
73
|
+
let panelEl = $state<HTMLElement>()
|
|
74
|
+
|
|
75
|
+
// Behaviour lives in `core/popover.ts` (shared with vanilla/popover.ts): events go in,
|
|
76
|
+
// a PopoverAction comes out, and `run` applies it to this component's state.
|
|
77
|
+
const popover = $derived<PopoverState>({ open })
|
|
78
|
+
|
|
79
|
+
function run(action: PopoverAction | null) {
|
|
80
|
+
if (!action) return
|
|
81
|
+
if (action.type === 'open') {
|
|
82
|
+
open = true
|
|
83
|
+
onOpenChange?.(true, { reason: action.reason })
|
|
84
|
+
} else {
|
|
85
|
+
open = false
|
|
86
|
+
onOpenChange?.(false, { reason: action.reason })
|
|
87
|
+
if (action.returnFocus) triggerEl?.focus()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Opening moves focus into the panel: its first focusable element, else the panel itself
|
|
92
|
+
// (`focusPopoverPanel`, shared with the vanilla path, which also covers content that is not
|
|
93
|
+
// focusable on the first frame). Runs after the DOM reflects `open` (the closed panel is inert), for an open the component
|
|
94
|
+
// made and for one the parent made through `bind:open` — but not for a popover that is
|
|
95
|
+
// rendered open, which must not grab focus on page load.
|
|
96
|
+
let wasOpen = untrack(() => open)
|
|
97
|
+
$effect(() => {
|
|
98
|
+
const isOpen = open
|
|
99
|
+
if (isOpen && !wasOpen && panelEl) focusPopoverPanel(panelEl)
|
|
100
|
+
wasOpen = isOpen
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
function onKeydown(e: KeyboardEvent) {
|
|
104
|
+
// Something inside (a nested Menu, say) already used this key.
|
|
105
|
+
if (e.defaultPrevented) return
|
|
106
|
+
const result = popoverKey(popover, e.key)
|
|
107
|
+
if (!result) return
|
|
108
|
+
if (result.preventDefault) e.preventDefault()
|
|
109
|
+
run(result.action)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function onFocusOut(e: FocusEvent) {
|
|
113
|
+
const to = e.relatedTarget as Node | null
|
|
114
|
+
run(popoverFocusOut(popover, !to ? 'nowhere' : rootEl?.contains(to) ? 'inside' : 'outside'))
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Pointer-down outside the root closes the popover (same model as Menu).
|
|
118
|
+
function onDocPointerDown(e: PointerEvent) {
|
|
119
|
+
if (rootEl && rootEl.contains(e.target as Node)) return
|
|
120
|
+
run(popoverOutsidePress(popover))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// SSR safety: same guard pattern as Menu.
|
|
124
|
+
const hasDocument = typeof document !== 'undefined'
|
|
125
|
+
|
|
126
|
+
$effect(() => {
|
|
127
|
+
if (!open || !hasDocument) return
|
|
128
|
+
document.addEventListener('pointerdown', onDocPointerDown, true)
|
|
129
|
+
return () => document.removeEventListener('pointerdown', onDocPointerDown, true)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const sizeAttr = $derived(resolveComponentSize('Popover', size))
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
136
|
+
<div
|
|
137
|
+
bind:this={rootEl}
|
|
138
|
+
class="ss-popover"
|
|
139
|
+
data-size-variant={sizeAttr}
|
|
140
|
+
data-align={align}
|
|
141
|
+
data-side={side}
|
|
142
|
+
onkeydown={onKeydown}
|
|
143
|
+
onfocusout={onFocusOut}
|
|
144
|
+
>
|
|
145
|
+
<button
|
|
146
|
+
bind:this={triggerEl}
|
|
147
|
+
id={triggerId}
|
|
148
|
+
type="button"
|
|
149
|
+
class="trigger"
|
|
150
|
+
{...popoverTriggerAttrs(open)}
|
|
151
|
+
aria-controls={panelId}
|
|
152
|
+
onclick={() => run(popoverTriggerPress(popover))}
|
|
153
|
+
>
|
|
154
|
+
{@render trigger?.()}
|
|
155
|
+
</button>
|
|
156
|
+
|
|
157
|
+
<div
|
|
158
|
+
bind:this={panelEl}
|
|
159
|
+
id={panelId}
|
|
160
|
+
class="panel"
|
|
161
|
+
class:open
|
|
162
|
+
aria-label={label || undefined}
|
|
163
|
+
aria-labelledby={label ? undefined : triggerId}
|
|
164
|
+
{...popoverPanelAttrs()}
|
|
165
|
+
inert={!open || undefined}
|
|
166
|
+
>
|
|
167
|
+
{@render children?.()}
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
<style>.ss-popover {
|
|
172
|
+
position: relative;
|
|
173
|
+
display: inline-block;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.trigger {
|
|
177
|
+
display: inline-flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
gap: var(--ss-gap-sm);
|
|
180
|
+
font: 500 var(--ss-control-font) var(--ss-font-mono);
|
|
181
|
+
color: var(--ss-fg);
|
|
182
|
+
background: transparent;
|
|
183
|
+
border: 1px solid var(--ss-line);
|
|
184
|
+
padding: var(--ss-control-py) var(--ss-control-px);
|
|
185
|
+
cursor: pointer;
|
|
186
|
+
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);
|
|
187
|
+
}
|
|
188
|
+
.trigger:hover, .trigger[aria-expanded=true] {
|
|
189
|
+
border-color: var(--ss-line-strong);
|
|
190
|
+
background: var(--ss-hover);
|
|
191
|
+
}
|
|
192
|
+
.trigger:focus-visible {
|
|
193
|
+
border-color: var(--ss-primary);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.panel {
|
|
197
|
+
position: absolute;
|
|
198
|
+
z-index: 50;
|
|
199
|
+
box-sizing: border-box;
|
|
200
|
+
width: max-content;
|
|
201
|
+
min-width: var(--ss-popover-min-w);
|
|
202
|
+
max-width: min(var(--ss-popover-max-w), 100vw - 2 * var(--ss-s-4));
|
|
203
|
+
padding: var(--ss-popover-pad);
|
|
204
|
+
font-size: var(--ss-ui-md);
|
|
205
|
+
color: var(--ss-fg);
|
|
206
|
+
text-align: start;
|
|
207
|
+
background: var(--ss-bg-elev);
|
|
208
|
+
border: 1px solid var(--ss-line);
|
|
209
|
+
box-shadow: var(--ss-shadow-pop);
|
|
210
|
+
opacity: 0;
|
|
211
|
+
visibility: hidden;
|
|
212
|
+
pointer-events: none;
|
|
213
|
+
transform: translateY(-6px) scale(0.98);
|
|
214
|
+
transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear var(--ss-dur);
|
|
215
|
+
}
|
|
216
|
+
.panel.open {
|
|
217
|
+
opacity: 1;
|
|
218
|
+
visibility: visible;
|
|
219
|
+
pointer-events: auto;
|
|
220
|
+
transform: translateY(0) scale(1);
|
|
221
|
+
transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear 0s;
|
|
222
|
+
}
|
|
223
|
+
.panel:focus-visible {
|
|
224
|
+
outline-offset: -2px;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.ss-popover[data-side=bottom] .panel {
|
|
228
|
+
top: calc(100% + var(--ss-popover-offset));
|
|
229
|
+
transform-origin: top;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.ss-popover[data-side=top] .panel {
|
|
233
|
+
bottom: calc(100% + var(--ss-popover-offset));
|
|
234
|
+
transform-origin: bottom;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.ss-popover[data-side=top] .panel:not(.open) {
|
|
238
|
+
transform: translateY(6px) scale(0.98);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.ss-popover[data-align=start] .panel {
|
|
242
|
+
inset-inline-start: 0;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.ss-popover[data-align=end] .panel {
|
|
246
|
+
inset-inline-end: 0;
|
|
247
|
+
}</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import { type Size } from '../config.js';
|
|
3
|
+
import { type PopoverOpenChangeDetails } 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).
|
|
16
|
+
*/
|
|
17
|
+
onOpenChange?: (open: boolean, details: PopoverOpenChangeDetails) => void;
|
|
18
|
+
/** Vertical side the panel opens toward. */
|
|
19
|
+
side?: Side;
|
|
20
|
+
/** Horizontal edge the panel aligns to. */
|
|
21
|
+
align?: Align;
|
|
22
|
+
/**
|
|
23
|
+
* Accessible label for the panel (`role="dialog"`). When omitted the
|
|
24
|
+
* panel is named by the trigger's text via `aria-labelledby`.
|
|
25
|
+
*/
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
28
|
+
size?: Size;
|
|
29
|
+
/** Trigger content (rendered inside the toggle button). */
|
|
30
|
+
trigger?: Snippet;
|
|
31
|
+
/** Panel content. */
|
|
32
|
+
children?: Snippet;
|
|
33
|
+
}
|
|
34
|
+
declare const Popover: import("svelte").Component<Props, {}, "open">;
|
|
35
|
+
type Popover = ReturnType<typeof Popover>;
|
|
36
|
+
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>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** One option in a {@link RadioGroup}. */
|
|
2
|
+
export interface RadioOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
import { type Size } from '../config.js';
|
|
8
|
+
interface Props {
|
|
9
|
+
/** Mutually-exclusive options: { value, label, disabled? }. */
|
|
10
|
+
options?: RadioOption[];
|
|
11
|
+
/** Selected option value (bindable); unset = nothing selected. */
|
|
12
|
+
value?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Form field name shared by the radios (the selected value is submitted
|
|
15
|
+
* with the form). Defaults to a generated per-instance name, which is what
|
|
16
|
+
* makes the inputs one native group.
|
|
17
|
+
*/
|
|
18
|
+
name?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Visible group label; names the radiogroup. Required (WCAG 2.2 AA): a
|
|
21
|
+
* radiogroup with no name leaves AT users without context for the choice.
|
|
22
|
+
*/
|
|
23
|
+
label: string;
|
|
24
|
+
/** Stack the options (`vertical`, default) or lay them out in a row. */
|
|
25
|
+
orientation?: 'vertical' | 'horizontal';
|
|
26
|
+
/**
|
|
27
|
+
* Disable the whole group: every radio is `disabled` and the group carries
|
|
28
|
+
* `aria-disabled="true"`. Per-option `disabled` still works on its own.
|
|
29
|
+
*/
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
32
|
+
size?: Size;
|
|
33
|
+
/**
|
|
34
|
+
* Fired when the selection changes (after `value` updates), with the new
|
|
35
|
+
* value. There is no `details.reason`: the native inputs report a press and
|
|
36
|
+
* an arrow key as the same event.
|
|
37
|
+
*/
|
|
38
|
+
onChange?: (value: string) => void;
|
|
39
|
+
}
|
|
40
|
+
declare const RadioGroup: import("svelte").Component<Props, {}, "value">;
|
|
41
|
+
type RadioGroup = ReturnType<typeof RadioGroup>;
|
|
42
|
+
export default RadioGroup;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { scaleLinear, scaleSqrt } from 'd3-scale'
|
|
17
17
|
import { extent, max } from 'd3-array'
|
|
18
18
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
19
|
-
import {
|
|
19
|
+
import { chartMarkKey, chartTabStop, chartWindowKey } from '../core/chart-nav.js'
|
|
20
20
|
|
|
21
21
|
interface Props {
|
|
22
22
|
/** One dot per datum. Two encoded axes (x, y), optional `size` and `color`. */
|
|
@@ -170,27 +170,25 @@
|
|
|
170
170
|
// Roving tabindex (DS-0161): the chart is ONE tab stop; arrow keys / Home / End move focus
|
|
171
171
|
// between points. The last-focused point keeps tabindex 0 (the first by default).
|
|
172
172
|
let focusIndex = $state(0)
|
|
173
|
-
const tabIndex = $derived(
|
|
173
|
+
const tabIndex = $derived(chartTabStop(focusIndex, marks.length))
|
|
174
174
|
let pointEls: (SVGCircleElement | null)[] = $state([])
|
|
175
175
|
|
|
176
176
|
function onPointKeydown(e: KeyboardEvent, i: number) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const next =
|
|
185
|
-
if (next === null) return
|
|
186
|
-
e.preventDefault()
|
|
177
|
+
const result = chartMarkKey(
|
|
178
|
+
{ index: i, count: marks.length, escape: 'consume', tooltipOpen: active !== null },
|
|
179
|
+
e.key,
|
|
180
|
+
)
|
|
181
|
+
if (!result) return
|
|
182
|
+
if (result.preventDefault) e.preventDefault()
|
|
183
|
+
if (result.action.type === 'dismiss') return hide()
|
|
184
|
+
const next = result.action.index
|
|
187
185
|
focusIndex = next
|
|
188
186
|
pointEls[next]?.focus()
|
|
189
187
|
}
|
|
190
188
|
|
|
191
189
|
// WCAG 1.4.13: Escape dismisses a hover-opened tooltip too, wherever focus is.
|
|
192
190
|
function onWindowKeydown(e: KeyboardEvent) {
|
|
193
|
-
if (e.key
|
|
191
|
+
if (chartWindowKey(active !== null, e.key)) hide()
|
|
194
192
|
}
|
|
195
193
|
function datumLabel(label: string, x: number, y: number): string {
|
|
196
194
|
return `${label}: ${fmtX(x)}, ${fmtY(y)}`
|