dssoca 0.10.0 → 0.12.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/dist/components/Accordion.svelte +35 -15
- package/dist/components/Accordion.svelte.d.ts +7 -0
- package/dist/components/Avatar.svelte +5 -9
- package/dist/components/Badge.svelte +27 -53
- package/dist/components/Badge.svelte.d.ts +2 -5
- package/dist/components/BottomNav.svelte +2 -2
- package/dist/components/BoxPlot.svelte +421 -0
- package/dist/components/BoxPlot.svelte.d.ts +36 -0
- package/dist/components/BumpChart.svelte +345 -0
- package/dist/components/BumpChart.svelte.d.ts +32 -0
- package/dist/components/Button.svelte +50 -34
- package/dist/components/Button.svelte.d.ts +8 -2
- package/dist/components/Chart.svelte +2 -8
- package/dist/components/DateField.svelte +1 -1
- package/dist/components/FileDrop.svelte +1 -1
- package/dist/components/Heatmap.svelte +333 -0
- package/dist/components/Heatmap.svelte.d.ts +30 -0
- package/dist/components/Icon.svelte +29 -7
- package/dist/components/Icon.svelte.d.ts +14 -2
- package/dist/components/Input.svelte +1 -1
- package/dist/components/LogStream.svelte +3 -3
- package/dist/components/Menu.svelte +1 -1
- package/dist/components/NumberField.svelte +1 -1
- package/dist/components/ScatterPlot.svelte +395 -0
- package/dist/components/ScatterPlot.svelte.d.ts +55 -0
- package/dist/components/Select.svelte +1 -1
- package/dist/components/ServiceCard.svelte +13 -2
- package/dist/components/Sidebar.svelte +1 -1
- package/dist/components/Spinner.svelte +26 -19
- package/dist/components/Spinner.svelte.d.ts +14 -4
- package/dist/components/Textarea.svelte +1 -1
- package/dist/components/Topbar.svelte +2 -2
- package/dist/config.d.ts +44 -3
- package/dist/config.js +52 -3
- package/dist/dssoca.config.d.ts +38 -1
- package/dist/dssoca.config.js +47 -0
- package/dist/index.d.ts +10 -5
- package/dist/index.js +11 -4
- package/dist/palette.d.ts +10 -0
- package/dist/palette.js +17 -0
- package/dist/theme.css +158 -158
- package/dist/tokens.css +158 -158
- package/package.json +3 -2
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export interface BumpSeries {
|
|
3
|
+
/** Competitor label shown at the last node and in the tooltip / accessible name. */
|
|
4
|
+
label: string
|
|
5
|
+
/** 1-based finishing ranks; `ranks[i]` is the rank at stage `i` (length must match `stages`). */
|
|
6
|
+
ranks: number[]
|
|
7
|
+
/** Optional per-series colour; falls back to the cycling palette. */
|
|
8
|
+
color?: string
|
|
9
|
+
}
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { CHART_PALETTE } from '../palette.js'
|
|
14
|
+
import { scalePoint, scaleLinear } from 'd3-scale'
|
|
15
|
+
import { line as shapeLine } from 'd3-shape'
|
|
16
|
+
import { max } from 'd3-array'
|
|
17
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
/** One series per competitor; each carries a `label`, `ranks` and optional `color`. */
|
|
21
|
+
series: BumpSeries[]
|
|
22
|
+
/** Ordered x-axis category labels (e.g. ['G1','G2','G3','G4']). */
|
|
23
|
+
stages: string[]
|
|
24
|
+
/** Draw each series label at its last node (direct labelling). Default true. */
|
|
25
|
+
showLabels?: boolean
|
|
26
|
+
/** Intrinsic drawing height in px. Default 280. */
|
|
27
|
+
height?: number
|
|
28
|
+
/** Intrinsic drawing width in px. Default 480. */
|
|
29
|
+
width?: number
|
|
30
|
+
/** Stretch to the container width via the viewBox (width:100%). */
|
|
31
|
+
fluid?: boolean
|
|
32
|
+
/** Reveal a tooltip on hover/focus of a node. Default true. */
|
|
33
|
+
tooltip?: boolean
|
|
34
|
+
/** SR summary + accessible name; auto-generated when absent. */
|
|
35
|
+
summary?: string
|
|
36
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
37
|
+
size?: Size
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
series,
|
|
42
|
+
stages,
|
|
43
|
+
showLabels = true,
|
|
44
|
+
height = 280,
|
|
45
|
+
width = 480,
|
|
46
|
+
fluid = false,
|
|
47
|
+
tooltip = true,
|
|
48
|
+
summary,
|
|
49
|
+
size,
|
|
50
|
+
}: Props = $props()
|
|
51
|
+
|
|
52
|
+
const PALETTE = CHART_PALETTE
|
|
53
|
+
|
|
54
|
+
const M = { top: 12, right: 56, bottom: 28, left: 32 }
|
|
55
|
+
|
|
56
|
+
const cleanSeries = $derived((series ?? []).filter((s) => s && Array.isArray(s.ranks)))
|
|
57
|
+
const cleanStages = $derived(stages ?? [])
|
|
58
|
+
const isEmpty = $derived(cleanSeries.length === 0 || cleanStages.length === 0)
|
|
59
|
+
|
|
60
|
+
function colorFor(s: BumpSeries, i: number): string {
|
|
61
|
+
return s.color ?? PALETTE[i % PALETTE.length]
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const innerW = $derived(Math.max(0, width - M.left - M.right))
|
|
65
|
+
const innerH = $derived(Math.max(0, height - M.top - M.bottom))
|
|
66
|
+
|
|
67
|
+
// Highest rank present across all series; default to the competitor count.
|
|
68
|
+
const maxRank = $derived(
|
|
69
|
+
max(cleanSeries.flatMap((s) => s.ranks.filter((r) => Number.isFinite(r)))) ??
|
|
70
|
+
cleanSeries.length,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
// x over stages; y maps rank 1 → top (0) and maxRank → bottom (innerH).
|
|
74
|
+
const xScaleObj = $derived(
|
|
75
|
+
scalePoint<string>().domain(cleanStages).range([0, innerW]).padding(0.5),
|
|
76
|
+
)
|
|
77
|
+
const yScaleObj = $derived(scaleLinear().domain([1, maxRank]).range([0, innerH]))
|
|
78
|
+
|
|
79
|
+
// Integer rank ticks 1..maxRank.
|
|
80
|
+
const rankTicks = $derived(
|
|
81
|
+
Array.from({ length: Math.max(1, Math.round(maxRank)) }, (_, i) => i + 1),
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
// One node per (series, stage) where the rank is finite.
|
|
85
|
+
const seriesNodes = $derived(
|
|
86
|
+
cleanSeries.map((s, i) => {
|
|
87
|
+
const color = colorFor(s, i)
|
|
88
|
+
const nodes = cleanStages
|
|
89
|
+
.map((stage, j) => {
|
|
90
|
+
const rank = s.ranks[j]
|
|
91
|
+
if (!Number.isFinite(rank)) return null
|
|
92
|
+
return {
|
|
93
|
+
cx: xScaleObj(stage) ?? 0,
|
|
94
|
+
cy: yScaleObj(rank),
|
|
95
|
+
stage,
|
|
96
|
+
rank,
|
|
97
|
+
label: s.label,
|
|
98
|
+
color,
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
.filter((n): n is NonNullable<typeof n> => n !== null)
|
|
102
|
+
return { label: s.label, color, nodes }
|
|
103
|
+
}),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
const lineGen = $derived(
|
|
107
|
+
shapeLine<{ cx: number; cy: number }>()
|
|
108
|
+
.x((n) => n.cx)
|
|
109
|
+
.y((n) => n.cy),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const linePaths = $derived(
|
|
113
|
+
seriesNodes.map((s) => ({
|
|
114
|
+
d: lineGen(s.nodes) ?? '',
|
|
115
|
+
color: s.color,
|
|
116
|
+
label: s.label,
|
|
117
|
+
})),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
// Last node of each series for direct labelling.
|
|
121
|
+
const endLabels = $derived.by(() => {
|
|
122
|
+
if (!showLabels) return [] as { x: number; y: number; color: string; label: string }[]
|
|
123
|
+
return seriesNodes
|
|
124
|
+
.filter((s) => s.nodes.length > 0)
|
|
125
|
+
.map((s) => {
|
|
126
|
+
const last = s.nodes[s.nodes.length - 1]
|
|
127
|
+
return { x: last.cx + 8, y: last.cy, color: s.color, label: s.label }
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const autoSummary = $derived.by(() => {
|
|
132
|
+
if (isEmpty) return 'No data'
|
|
133
|
+
const stageNames = cleanStages.join(', ')
|
|
134
|
+
return `Bump chart with ${cleanSeries.length} series over ${cleanStages.length} stages (${stageNames}).`
|
|
135
|
+
})
|
|
136
|
+
const srText = $derived(summary ?? autoSummary)
|
|
137
|
+
|
|
138
|
+
const resolvedSize = $derived(resolveComponentSize('Chart', size))
|
|
139
|
+
|
|
140
|
+
let active = $state<{
|
|
141
|
+
label: string
|
|
142
|
+
stage: string
|
|
143
|
+
rank: number
|
|
144
|
+
cx: number
|
|
145
|
+
cy: number
|
|
146
|
+
} | null>(null)
|
|
147
|
+
function show(label: string, stage: string, rank: number, cx: number, cy: number) {
|
|
148
|
+
if (tooltip) active = { label, stage, rank, cx, cy }
|
|
149
|
+
}
|
|
150
|
+
function hide() {
|
|
151
|
+
active = null
|
|
152
|
+
}
|
|
153
|
+
function nodeLabel(label: string, stage: string, rank: number): string {
|
|
154
|
+
return `${label}: ${stage}, rank ${rank}`
|
|
155
|
+
}
|
|
156
|
+
</script>
|
|
157
|
+
|
|
158
|
+
<div class="ss-bump" class:fluid data-size-variant={resolvedSize} role="group" aria-label={srText}>
|
|
159
|
+
{#if isEmpty}
|
|
160
|
+
<span class="empty" aria-hidden="true">—</span>
|
|
161
|
+
<span class="sr-only">No data</span>
|
|
162
|
+
{:else}
|
|
163
|
+
<div class="plot">
|
|
164
|
+
<svg
|
|
165
|
+
class="canvas"
|
|
166
|
+
viewBox="0 0 {width} {height}"
|
|
167
|
+
width={fluid ? undefined : width}
|
|
168
|
+
height={fluid ? undefined : height}
|
|
169
|
+
preserveAspectRatio="xMidYMid meet"
|
|
170
|
+
role="presentation"
|
|
171
|
+
>
|
|
172
|
+
<g transform="translate({M.left},{M.top})">
|
|
173
|
+
<!-- gridlines + y axis (rank ticks) -->
|
|
174
|
+
{#each rankTicks as t}
|
|
175
|
+
<line class="grid" x1="0" x2={innerW} y1={yScaleObj(t)} y2={yScaleObj(t)} />
|
|
176
|
+
<text class="tick y" x="-6" y={yScaleObj(t)} dy="0.32em" text-anchor="end">{t}</text>
|
|
177
|
+
{/each}
|
|
178
|
+
<line class="axis" x1="0" x2="0" y1="0" y2={innerH} />
|
|
179
|
+
<line class="axis" x1="0" x2={innerW} y1={innerH} y2={innerH} />
|
|
180
|
+
|
|
181
|
+
<!-- x axis (stage labels) -->
|
|
182
|
+
{#each cleanStages as stage}
|
|
183
|
+
<text class="tick x" x={xScaleObj(stage)} y={innerH + 16} text-anchor="middle"
|
|
184
|
+
>{stage}</text
|
|
185
|
+
>
|
|
186
|
+
{/each}
|
|
187
|
+
|
|
188
|
+
<!-- connecting lines -->
|
|
189
|
+
{#each linePaths as p}
|
|
190
|
+
<path class="line" d={p.d} style="stroke:{p.color}" />
|
|
191
|
+
{/each}
|
|
192
|
+
|
|
193
|
+
<!-- nodes -->
|
|
194
|
+
{#each seriesNodes as s}
|
|
195
|
+
{#each s.nodes as n}
|
|
196
|
+
<circle
|
|
197
|
+
class="node"
|
|
198
|
+
cx={n.cx}
|
|
199
|
+
cy={n.cy}
|
|
200
|
+
r="5"
|
|
201
|
+
style="fill:{n.color}"
|
|
202
|
+
tabindex="0"
|
|
203
|
+
role="button"
|
|
204
|
+
aria-label={nodeLabel(n.label, n.stage, n.rank)}
|
|
205
|
+
onfocus={() => show(n.label, n.stage, n.rank, n.cx, n.cy)}
|
|
206
|
+
onblur={hide}
|
|
207
|
+
onmouseenter={() => show(n.label, n.stage, n.rank, n.cx, n.cy)}
|
|
208
|
+
onmouseleave={hide}
|
|
209
|
+
/>
|
|
210
|
+
{/each}
|
|
211
|
+
{/each}
|
|
212
|
+
|
|
213
|
+
<!-- direct series labels -->
|
|
214
|
+
{#each endLabels as l}
|
|
215
|
+
<text class="series-label" x={l.x} y={l.y} dy="0.32em" style="fill:{l.color}"
|
|
216
|
+
>{l.label}</text
|
|
217
|
+
>
|
|
218
|
+
{/each}
|
|
219
|
+
</g>
|
|
220
|
+
</svg>
|
|
221
|
+
|
|
222
|
+
{#if tooltip && active}
|
|
223
|
+
<div
|
|
224
|
+
class="tooltip"
|
|
225
|
+
role="status"
|
|
226
|
+
style="left:{((active.cx + M.left) / width) * 100}%;top:{((active.cy + M.top) / height) *
|
|
227
|
+
100}%"
|
|
228
|
+
>
|
|
229
|
+
<span class="t-label">{active.label}</span>
|
|
230
|
+
<span class="t-val">{active.stage} · rank {active.rank}</span>
|
|
231
|
+
</div>
|
|
232
|
+
{/if}
|
|
233
|
+
</div>
|
|
234
|
+
{/if}
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<style>.ss-bump {
|
|
238
|
+
display: inline-flex;
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
gap: var(--ss-gap-sm);
|
|
241
|
+
font-family: var(--ss-font-body);
|
|
242
|
+
color: var(--ss-fg);
|
|
243
|
+
max-width: 100%;
|
|
244
|
+
}
|
|
245
|
+
.ss-bump.fluid {
|
|
246
|
+
display: flex;
|
|
247
|
+
width: 100%;
|
|
248
|
+
}
|
|
249
|
+
.ss-bump .plot {
|
|
250
|
+
position: relative;
|
|
251
|
+
width: 100%;
|
|
252
|
+
}
|
|
253
|
+
.ss-bump .canvas {
|
|
254
|
+
display: block;
|
|
255
|
+
max-width: 100%;
|
|
256
|
+
height: auto;
|
|
257
|
+
overflow: visible;
|
|
258
|
+
}
|
|
259
|
+
.ss-bump.fluid .canvas {
|
|
260
|
+
width: 100%;
|
|
261
|
+
}
|
|
262
|
+
.ss-bump .empty {
|
|
263
|
+
align-self: center;
|
|
264
|
+
margin: auto;
|
|
265
|
+
padding: var(--ss-gap-sm);
|
|
266
|
+
color: var(--ss-fg-muted);
|
|
267
|
+
font-family: var(--ss-font-mono);
|
|
268
|
+
line-height: 1;
|
|
269
|
+
min-height: var(--ss-chart-h, 240px);
|
|
270
|
+
display: flex;
|
|
271
|
+
align-items: center;
|
|
272
|
+
}
|
|
273
|
+
.ss-bump .sr-only {
|
|
274
|
+
position: absolute;
|
|
275
|
+
width: 1px;
|
|
276
|
+
height: 1px;
|
|
277
|
+
padding: 0;
|
|
278
|
+
margin: -1px;
|
|
279
|
+
overflow: hidden;
|
|
280
|
+
clip: rect(0, 0, 0, 0);
|
|
281
|
+
white-space: nowrap;
|
|
282
|
+
border: 0;
|
|
283
|
+
}
|
|
284
|
+
.ss-bump .grid {
|
|
285
|
+
stroke: var(--ss-line);
|
|
286
|
+
stroke-width: 1;
|
|
287
|
+
opacity: 0.5;
|
|
288
|
+
shape-rendering: crispEdges;
|
|
289
|
+
}
|
|
290
|
+
.ss-bump .axis {
|
|
291
|
+
stroke: var(--ss-line);
|
|
292
|
+
stroke-width: 1;
|
|
293
|
+
shape-rendering: crispEdges;
|
|
294
|
+
}
|
|
295
|
+
.ss-bump .tick {
|
|
296
|
+
font-family: var(--ss-font-mono);
|
|
297
|
+
font-size: var(--ss-ui-xs);
|
|
298
|
+
fill: var(--ss-fg-muted);
|
|
299
|
+
}
|
|
300
|
+
.ss-bump .line {
|
|
301
|
+
fill: none;
|
|
302
|
+
stroke-width: 2;
|
|
303
|
+
stroke-linejoin: round;
|
|
304
|
+
stroke-linecap: round;
|
|
305
|
+
}
|
|
306
|
+
.ss-bump .node {
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
transition: r var(--ss-dur-fast) var(--ss-ease);
|
|
309
|
+
}
|
|
310
|
+
.ss-bump .node:hover, .ss-bump .node:focus-visible {
|
|
311
|
+
outline: none;
|
|
312
|
+
r: 7;
|
|
313
|
+
}
|
|
314
|
+
.ss-bump .node:focus-visible {
|
|
315
|
+
stroke: var(--ss-fg);
|
|
316
|
+
stroke-width: 2;
|
|
317
|
+
}
|
|
318
|
+
.ss-bump .series-label {
|
|
319
|
+
font-family: var(--ss-font-mono);
|
|
320
|
+
font-size: var(--ss-ui-xs);
|
|
321
|
+
pointer-events: none;
|
|
322
|
+
}
|
|
323
|
+
.ss-bump .tooltip {
|
|
324
|
+
position: absolute;
|
|
325
|
+
transform: translate(-50%, calc(-100% - 8px));
|
|
326
|
+
pointer-events: none;
|
|
327
|
+
background: var(--ss-bg-elev);
|
|
328
|
+
border: 1px solid var(--ss-line-strong);
|
|
329
|
+
padding: var(--ss-gap-sm);
|
|
330
|
+
font-size: var(--ss-ui-xs);
|
|
331
|
+
line-height: 1.3;
|
|
332
|
+
white-space: nowrap;
|
|
333
|
+
display: flex;
|
|
334
|
+
flex-direction: column;
|
|
335
|
+
gap: 2px;
|
|
336
|
+
z-index: 2;
|
|
337
|
+
}
|
|
338
|
+
.ss-bump .tooltip .t-label {
|
|
339
|
+
font-family: var(--ss-font-mono);
|
|
340
|
+
color: var(--ss-fg);
|
|
341
|
+
}
|
|
342
|
+
.ss-bump .tooltip .t-val {
|
|
343
|
+
font-family: var(--ss-font-mono);
|
|
344
|
+
color: var(--ss-fg-muted);
|
|
345
|
+
}</style>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface BumpSeries {
|
|
2
|
+
/** Competitor label shown at the last node and in the tooltip / accessible name. */
|
|
3
|
+
label: string;
|
|
4
|
+
/** 1-based finishing ranks; `ranks[i]` is the rank at stage `i` (length must match `stages`). */
|
|
5
|
+
ranks: number[];
|
|
6
|
+
/** Optional per-series colour; falls back to the cycling palette. */
|
|
7
|
+
color?: string;
|
|
8
|
+
}
|
|
9
|
+
import { type Size } from '../config.js';
|
|
10
|
+
interface Props {
|
|
11
|
+
/** One series per competitor; each carries a `label`, `ranks` and optional `color`. */
|
|
12
|
+
series: BumpSeries[];
|
|
13
|
+
/** Ordered x-axis category labels (e.g. ['G1','G2','G3','G4']). */
|
|
14
|
+
stages: string[];
|
|
15
|
+
/** Draw each series label at its last node (direct labelling). Default true. */
|
|
16
|
+
showLabels?: boolean;
|
|
17
|
+
/** Intrinsic drawing height in px. Default 280. */
|
|
18
|
+
height?: number;
|
|
19
|
+
/** Intrinsic drawing width in px. Default 480. */
|
|
20
|
+
width?: number;
|
|
21
|
+
/** Stretch to the container width via the viewBox (width:100%). */
|
|
22
|
+
fluid?: boolean;
|
|
23
|
+
/** Reveal a tooltip on hover/focus of a node. Default true. */
|
|
24
|
+
tooltip?: boolean;
|
|
25
|
+
/** SR summary + accessible name; auto-generated when absent. */
|
|
26
|
+
summary?: string;
|
|
27
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
28
|
+
size?: Size;
|
|
29
|
+
}
|
|
30
|
+
declare const BumpChart: import("svelte").Component<Props, {}, "">;
|
|
31
|
+
type BumpChart = ReturnType<typeof BumpChart>;
|
|
32
|
+
export default BumpChart;
|
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte'
|
|
3
3
|
import type { HTMLButtonAttributes } from 'svelte/elements'
|
|
4
|
-
import { resolveComponentSize, type Size } from '../config.js'
|
|
4
|
+
import { resolveComponentSize, resolveSpinnerVariant, type Size } from '../config.js'
|
|
5
|
+
import type { SpinnerVariant } from '../config.js'
|
|
6
|
+
import Spinner from './Spinner.svelte'
|
|
5
7
|
|
|
6
8
|
interface Props extends HTMLButtonAttributes {
|
|
7
9
|
variant?: 'primary' | 'secondary' | 'ghost' | 'danger'
|
|
8
10
|
type?: 'button' | 'submit' | 'reset'
|
|
9
11
|
disabled?: boolean
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Loading state: shows a {@link Spinner}, blocks clicks, sets aria-busy;
|
|
14
|
+
* stays focusable. `true` uses the configured default spinner variant; pass
|
|
15
|
+
* a {@link SpinnerVariant} string to pick a specific glyph; `false`/omitted
|
|
16
|
+
* is not loading.
|
|
17
|
+
*/
|
|
18
|
+
loading?: boolean | SpinnerVariant
|
|
12
19
|
/** Accessible name while loading (keeps the name stable when the label is hidden). */
|
|
13
20
|
loadingLabel?: string
|
|
14
21
|
onclick?: (e: MouseEvent) => void
|
|
@@ -46,14 +53,25 @@
|
|
|
46
53
|
...rest
|
|
47
54
|
}: Props = $props()
|
|
48
55
|
|
|
56
|
+
// `loading` is a discriminated union: `true` → configured default variant; a
|
|
57
|
+
// SpinnerVariant string → that variant; `false`/undefined → not loading.
|
|
58
|
+
let isLoading = $derived(loading !== false && loading != null)
|
|
59
|
+
// The size Button paints on its root, threaded down to nested Icon/Spinner so
|
|
60
|
+
// the loading glyph tracks the button's tier (coordinated inner sizes).
|
|
61
|
+
let resolvedSize = $derived(resolveComponentSize('Button', size))
|
|
62
|
+
// An explicit variant string wins; `true` falls back to the house default.
|
|
63
|
+
let spinnerVariant = $derived(
|
|
64
|
+
typeof loading === 'string' ? loading : resolveSpinnerVariant(undefined),
|
|
65
|
+
)
|
|
66
|
+
|
|
49
67
|
// Soft-disable: keep the control focusable/announceable via aria-disabled while
|
|
50
68
|
// loading, but still emit native `disabled` so forms don't submit it.
|
|
51
|
-
let busy = $derived(
|
|
69
|
+
let busy = $derived(isLoading)
|
|
52
70
|
let ariaLabel = $derived(iconOnly ? label : rest['aria-label'])
|
|
53
|
-
let accessibleName = $derived(
|
|
71
|
+
let accessibleName = $derived(isLoading ? (loadingLabel ?? ariaLabel) : ariaLabel)
|
|
54
72
|
|
|
55
73
|
function handleClick(e: MouseEvent) {
|
|
56
|
-
if (
|
|
74
|
+
if (isLoading || disabled) {
|
|
57
75
|
e.preventDefault()
|
|
58
76
|
e.stopImmediatePropagation()
|
|
59
77
|
return
|
|
@@ -67,28 +85,36 @@
|
|
|
67
85
|
class="ss-btn {variant}"
|
|
68
86
|
class:icon-only={iconOnly}
|
|
69
87
|
class:full-width={fullWidth}
|
|
70
|
-
class:loading
|
|
88
|
+
class:loading={isLoading}
|
|
71
89
|
{type}
|
|
72
90
|
{disabled}
|
|
73
91
|
aria-busy={busy ? 'true' : undefined}
|
|
74
|
-
aria-disabled={
|
|
92
|
+
aria-disabled={isLoading ? 'true' : undefined}
|
|
75
93
|
aria-label={accessibleName}
|
|
76
|
-
data-size-variant={
|
|
94
|
+
data-size-variant={resolvedSize}
|
|
77
95
|
{...rest}
|
|
78
96
|
onclick={handleClick}
|
|
79
97
|
>
|
|
80
|
-
{#if
|
|
81
|
-
|
|
98
|
+
{#if isLoading}
|
|
99
|
+
<!-- Shared Spinner, sized to the button's tier. Its own role="status" is
|
|
100
|
+
suppressed (role/aria-hidden) so the button's name is the single
|
|
101
|
+
announcement — no double live-region. -->
|
|
102
|
+
<span class="affix" aria-hidden="true">
|
|
103
|
+
<Spinner variant={spinnerVariant} size={resolvedSize} role={undefined} aria-hidden="true" />
|
|
104
|
+
</span>
|
|
82
105
|
{/if}
|
|
83
106
|
{#if leading}<span class="affix" aria-hidden="true">{@render leading()}</span>{/if}
|
|
84
107
|
{#if children}<span class="label">{@render children()}</span>{/if}
|
|
85
108
|
{#if trailing}<span class="affix" aria-hidden="true">{@render trailing()}</span>{/if}
|
|
86
109
|
</button>
|
|
87
110
|
|
|
88
|
-
<style
|
|
111
|
+
<style>@charset "UTF-8";
|
|
112
|
+
.ss-btn {
|
|
89
113
|
font-family: var(--ss-font-body);
|
|
90
114
|
font-size: var(--ss-control-font);
|
|
91
115
|
line-height: 1;
|
|
116
|
+
min-height: calc(var(--ss-control-font) + var(--ss-control-py) * 2);
|
|
117
|
+
box-sizing: border-box;
|
|
92
118
|
font-weight: 500;
|
|
93
119
|
padding: var(--ss-control-py) var(--ss-control-px);
|
|
94
120
|
border: 1px solid var(--ss-line);
|
|
@@ -167,31 +193,21 @@
|
|
|
167
193
|
align-items: center;
|
|
168
194
|
}
|
|
169
195
|
|
|
196
|
+
/* Clamp the icon/spinner to the text line-box (1em of the control font) and
|
|
197
|
+
centre it, so a glyph sized to --ss-icon (taller than 1em) never enlarges
|
|
198
|
+
the line-box and grows the control (DS-0112). The icon stays visually
|
|
199
|
+
centred; overflow stays visible so a slightly-taller glyph is not cropped,
|
|
200
|
+
while the box's own height — what align-items:center measures — is the
|
|
201
|
+
line-box. `min-height: 0` / `min-width: 0` defang the flex auto-min-size: as
|
|
202
|
+
a flex ITEM of `.ss-btn`, `.affix` would otherwise take a content-based
|
|
203
|
+
automatic minimum from the (taller) icon, which could override the explicit
|
|
204
|
+
`height: 1em` and grow the control past its `min-height` floor. */
|
|
170
205
|
.affix {
|
|
171
206
|
display: inline-flex;
|
|
172
207
|
align-items: center;
|
|
173
208
|
justify-content: center;
|
|
174
|
-
line-height: 0;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/* em-sized spinner so it tracks the button font; reduced-motion safe. */
|
|
178
|
-
.spinner {
|
|
179
|
-
display: inline-block;
|
|
180
|
-
width: 1em;
|
|
181
209
|
height: 1em;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
animation: ss-btn-spin var(--ss-dur-xslow) linear infinite;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@keyframes ss-btn-spin {
|
|
189
|
-
to {
|
|
190
|
-
transform: rotate(360deg);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
@media (prefers-reduced-motion: reduce) {
|
|
194
|
-
.spinner {
|
|
195
|
-
animation: none;
|
|
196
|
-
}
|
|
210
|
+
min-height: 0;
|
|
211
|
+
min-width: 0;
|
|
212
|
+
line-height: 0;
|
|
197
213
|
}</style>
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
|
3
3
|
import { type Size } from '../config.js';
|
|
4
|
+
import type { SpinnerVariant } from '../config.js';
|
|
4
5
|
interface Props extends HTMLButtonAttributes {
|
|
5
6
|
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
6
7
|
type?: 'button' | 'submit' | 'reset';
|
|
7
8
|
disabled?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Loading state: shows a {@link Spinner}, blocks clicks, sets aria-busy;
|
|
11
|
+
* stays focusable. `true` uses the configured default spinner variant; pass
|
|
12
|
+
* a {@link SpinnerVariant} string to pick a specific glyph; `false`/omitted
|
|
13
|
+
* is not loading.
|
|
14
|
+
*/
|
|
15
|
+
loading?: boolean | SpinnerVariant;
|
|
10
16
|
/** Accessible name while loading (keeps the name stable when the label is hidden). */
|
|
11
17
|
loadingLabel?: string;
|
|
12
18
|
onclick?: (e: MouseEvent) => void;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
</script>
|
|
14
14
|
|
|
15
15
|
<script lang="ts">
|
|
16
|
+
import { CHART_PALETTE } from '../palette.js'
|
|
16
17
|
import { scaleLinear, scaleTime, scaleBand } from 'd3-scale'
|
|
17
18
|
import { line as shapeLine, area as shapeArea } from 'd3-shape'
|
|
18
19
|
import { extent, max } from 'd3-array'
|
|
@@ -62,14 +63,7 @@
|
|
|
62
63
|
size,
|
|
63
64
|
}: Props = $props()
|
|
64
65
|
|
|
65
|
-
const PALETTE =
|
|
66
|
-
'var(--ss-primary)',
|
|
67
|
-
'var(--ss-blue)',
|
|
68
|
-
'var(--ss-purple)',
|
|
69
|
-
'var(--ss-cyan)',
|
|
70
|
-
'var(--ss-yellow)',
|
|
71
|
-
'var(--ss-lime)',
|
|
72
|
-
]
|
|
66
|
+
const PALETTE = CHART_PALETTE
|
|
73
67
|
|
|
74
68
|
const M = { top: 8, right: 12, bottom: 24, left: 40 }
|
|
75
69
|
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
}
|
|
134
134
|
.ss-datefield.invalid .control:focus-within {
|
|
135
135
|
border-color: var(--ss-red);
|
|
136
|
-
box-shadow: 0 0 0 3px
|
|
136
|
+
box-shadow: 0 0 0 3px color-mix(in srgb, var(--ss-danger) 22%, transparent);
|
|
137
137
|
}
|
|
138
138
|
.ss-datefield.disabled .control {
|
|
139
139
|
border-color: var(--ss-line);
|