dssoca 0.9.0 → 0.11.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/Avatar.svelte +119 -0
- package/dist/components/Avatar.svelte.d.ts +18 -0
- package/dist/components/BoxPlot.svelte +427 -0
- package/dist/components/BoxPlot.svelte.d.ts +36 -0
- package/dist/components/BumpChart.svelte +351 -0
- package/dist/components/BumpChart.svelte.d.ts +32 -0
- package/dist/components/Chart.svelte +527 -0
- package/dist/components/Chart.svelte.d.ts +42 -0
- package/dist/components/DateField.svelte +188 -0
- package/dist/components/DateField.svelte.d.ts +37 -0
- package/dist/components/FileDrop.svelte +355 -0
- package/dist/components/FileDrop.svelte.d.ts +24 -0
- package/dist/components/Heatmap.svelte +333 -0
- package/dist/components/Heatmap.svelte.d.ts +30 -0
- package/dist/components/Modal.svelte +223 -0
- package/dist/components/Modal.svelte.d.ts +29 -0
- package/dist/components/NumberField.svelte +260 -0
- package/dist/components/NumberField.svelte.d.ts +35 -0
- package/dist/components/Pagination.svelte +193 -0
- package/dist/components/Pagination.svelte.d.ts +22 -0
- package/dist/components/ScatterPlot.svelte +401 -0
- package/dist/components/ScatterPlot.svelte.d.ts +55 -0
- package/dist/components/Select.svelte +224 -0
- package/dist/components/Select.svelte.d.ts +42 -0
- package/dist/components/Switch.svelte +144 -0
- package/dist/components/Switch.svelte.d.ts +22 -0
- package/dist/components/Table.svelte +267 -0
- package/dist/components/Table.svelte.d.ts +52 -0
- package/dist/components/Tooltip.svelte +162 -0
- package/dist/components/Tooltip.svelte.d.ts +17 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +11 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/package.json +9 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** A single selectable option. */
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** A labelled group of options, rendered as an <optgroup>. */
|
|
8
|
+
export interface SelectOptGroup {
|
|
9
|
+
label: string;
|
|
10
|
+
options: SelectOption[];
|
|
11
|
+
}
|
|
12
|
+
import { type Size } from '../config.js';
|
|
13
|
+
interface Props {
|
|
14
|
+
label?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
/** Flat options, or grouped options (detected by an `options` array on the first element). */
|
|
19
|
+
options?: SelectOption[] | SelectOptGroup[];
|
|
20
|
+
/** Renders a disabled, hidden first option, selected while the value is empty. */
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
25
|
+
size?: Size;
|
|
26
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
27
|
+
invalid?: boolean;
|
|
28
|
+
/** Supplementary helper text rendered under the select. */
|
|
29
|
+
hint?: string;
|
|
30
|
+
/** Error text rendered under the select; its presence implies aria-invalid and is announced. */
|
|
31
|
+
error?: string;
|
|
32
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
33
|
+
describedby?: string;
|
|
34
|
+
onchange?: (e: Event & {
|
|
35
|
+
currentTarget: HTMLSelectElement;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Any remaining native select attributes / event handlers are forwarded. */
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
declare const Select: import("svelte").Component<Props, {}, "value">;
|
|
41
|
+
type Select = ReturnType<typeof Select>;
|
|
42
|
+
export default Select;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// Switch — DS-0101. An accessible on/off toggle built on a native
|
|
4
|
+
// `<button role="switch">`, so Space and Enter toggle for free. House rule:
|
|
5
|
+
// zero border-radius (square track AND square thumb — no rounded pill). The
|
|
6
|
+
// thumb slides on the inline axis between the two ends of the track; the
|
|
7
|
+
// track fills with --ss-primary when on. Bindable `checked`, optional adjacent
|
|
8
|
+
// `label` (clicking it toggles too), size-token density.
|
|
9
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** On/off state (bindable). */
|
|
14
|
+
checked?: boolean
|
|
15
|
+
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
16
|
+
label?: string
|
|
17
|
+
/** Id for the underlying button (label `for`-style association uses it). */
|
|
18
|
+
id?: string
|
|
19
|
+
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
20
|
+
name?: string
|
|
21
|
+
/** Disable the switch: inert + non-toggling. */
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
24
|
+
size?: Size
|
|
25
|
+
/** Id of an element that further describes the switch (→ aria-describedby). */
|
|
26
|
+
describedby?: string
|
|
27
|
+
/** Fired after `checked` flips, with the new value. */
|
|
28
|
+
onchange?: (checked: boolean) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
checked = $bindable(false),
|
|
33
|
+
label,
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
disabled = false,
|
|
37
|
+
size,
|
|
38
|
+
describedby,
|
|
39
|
+
onchange,
|
|
40
|
+
}: Props = $props()
|
|
41
|
+
|
|
42
|
+
// Stable per-instance id so the visible label can be wired to the button as
|
|
43
|
+
// its accessible name (aria-labelledby). Falls back to `$props.id()` when no
|
|
44
|
+
// explicit `id` is supplied (SSR-stable, replaces a random default).
|
|
45
|
+
const uid = $props.id()
|
|
46
|
+
const buttonId = $derived(id ?? uid)
|
|
47
|
+
const labelId = $derived(`${buttonId}-label`)
|
|
48
|
+
|
|
49
|
+
function toggle() {
|
|
50
|
+
if (disabled) return
|
|
51
|
+
checked = !checked
|
|
52
|
+
onchange?.(checked)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const sizeAttr = $derived(resolveComponentSize('Switch', size))
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<span class="ss-switch" class:has-label={label != null} data-size-variant={sizeAttr}>
|
|
59
|
+
<button
|
|
60
|
+
id={buttonId}
|
|
61
|
+
type="button"
|
|
62
|
+
role="switch"
|
|
63
|
+
class="track"
|
|
64
|
+
class:on={checked}
|
|
65
|
+
aria-checked={checked}
|
|
66
|
+
aria-labelledby={label != null ? labelId : undefined}
|
|
67
|
+
aria-describedby={describedby}
|
|
68
|
+
data-name={name}
|
|
69
|
+
{disabled}
|
|
70
|
+
onclick={toggle}
|
|
71
|
+
>
|
|
72
|
+
<span class="thumb" aria-hidden="true"></span>
|
|
73
|
+
</button>
|
|
74
|
+
{#if label != null}
|
|
75
|
+
<!-- Clicking the label toggles the switch (a11y: same target as the control). -->
|
|
76
|
+
<span id={labelId} class="label" onclick={toggle} role="presentation">{label}</span>
|
|
77
|
+
{/if}
|
|
78
|
+
</span>
|
|
79
|
+
|
|
80
|
+
<style>.ss-switch {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
gap: var(--ss-switch-gap, var(--ss-gap-sm));
|
|
84
|
+
}
|
|
85
|
+
.ss-switch .track {
|
|
86
|
+
position: relative;
|
|
87
|
+
flex: 0 0 auto;
|
|
88
|
+
display: inline-block;
|
|
89
|
+
width: var(--ss-switch-w, 2.25rem);
|
|
90
|
+
height: var(--ss-switch-h, 1.25rem);
|
|
91
|
+
padding: var(--ss-switch-pad, 2px);
|
|
92
|
+
border-radius: 0;
|
|
93
|
+
border: 1px solid var(--ss-line);
|
|
94
|
+
background: var(--ss-bg-elev);
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
transition: background var(--ss-dur-fast) var(--ss-ease), border-color var(--ss-dur-fast) var(--ss-ease);
|
|
98
|
+
}
|
|
99
|
+
.ss-switch .track .thumb {
|
|
100
|
+
position: absolute;
|
|
101
|
+
top: var(--ss-switch-pad, 2px);
|
|
102
|
+
left: var(--ss-switch-pad, 2px);
|
|
103
|
+
width: var(--ss-switch-thumb, 1rem);
|
|
104
|
+
height: var(--ss-switch-thumb, 1rem);
|
|
105
|
+
border-radius: 0;
|
|
106
|
+
background: var(--ss-fg);
|
|
107
|
+
transition: transform var(--ss-dur-fast) var(--ss-ease);
|
|
108
|
+
}
|
|
109
|
+
.ss-switch .track.on {
|
|
110
|
+
background: var(--ss-primary);
|
|
111
|
+
border-color: var(--ss-primary);
|
|
112
|
+
}
|
|
113
|
+
.ss-switch .track.on .thumb {
|
|
114
|
+
background: var(--ss-bg);
|
|
115
|
+
transform: translateX(calc(var(--ss-switch-w, 2.25rem) - var(--ss-switch-thumb, 1rem) - 2 * var(--ss-switch-pad, 2px) - 2px));
|
|
116
|
+
}
|
|
117
|
+
.ss-switch .track:not(:disabled):hover {
|
|
118
|
+
border-color: var(--ss-line-strong);
|
|
119
|
+
}
|
|
120
|
+
.ss-switch .track:focus-visible {
|
|
121
|
+
outline: none;
|
|
122
|
+
box-shadow: 0 0 0 2px var(--ss-primary-soft);
|
|
123
|
+
}
|
|
124
|
+
.ss-switch .track:disabled {
|
|
125
|
+
cursor: not-allowed;
|
|
126
|
+
opacity: 0.45;
|
|
127
|
+
}
|
|
128
|
+
.ss-switch .label {
|
|
129
|
+
font: 500 var(--ss-control-font)/1 var(--ss-font-body);
|
|
130
|
+
color: var(--ss-fg);
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
user-select: none;
|
|
133
|
+
}
|
|
134
|
+
.ss-switch:has(.track:disabled) .label {
|
|
135
|
+
cursor: not-allowed;
|
|
136
|
+
opacity: 0.45;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@media (prefers-reduced-motion: reduce) {
|
|
140
|
+
.ss-switch .track,
|
|
141
|
+
.ss-switch .track .thumb {
|
|
142
|
+
transition: none;
|
|
143
|
+
}
|
|
144
|
+
}</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Size } from '../config.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** On/off state (bindable). */
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Id for the underlying button (label `for`-style association uses it). */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Disable the switch: inert + non-toggling. */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size;
|
|
15
|
+
/** Id of an element that further describes the switch (→ aria-describedby). */
|
|
16
|
+
describedby?: string;
|
|
17
|
+
/** Fired after `checked` flips, with the new value. */
|
|
18
|
+
onchange?: (checked: boolean) => void;
|
|
19
|
+
}
|
|
20
|
+
declare const Switch: import("svelte").Component<Props, {}, "checked">;
|
|
21
|
+
type Switch = ReturnType<typeof Switch>;
|
|
22
|
+
export default Switch;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A single table row passed to consumer callbacks and cell snippets. Typed as
|
|
6
|
+
* `any` so consumers can narrow the row shape in their own `format`, `cell`,
|
|
7
|
+
* and `getRowKey` definitions (Svelte `Snippet` params are contravariant, so
|
|
8
|
+
* a stricter row type here would reject narrowly-typed consumer snippets).
|
|
9
|
+
*/
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
export type TableRow = any
|
|
12
|
+
|
|
13
|
+
/** One column definition for a {@link Table}. */
|
|
14
|
+
export interface TableColumn {
|
|
15
|
+
/** Key into each row object — also the cell's value source. */
|
|
16
|
+
key: string
|
|
17
|
+
/** Header text. */
|
|
18
|
+
label: string
|
|
19
|
+
/** Text alignment of the body cells. Numeric columns default to `right`. */
|
|
20
|
+
align?: 'left' | 'right' | 'center'
|
|
21
|
+
/** Allow clicking the header to sort by this column. */
|
|
22
|
+
sortable?: boolean
|
|
23
|
+
/** Treat values as numbers — right-aligns, uses the mono font, sorts numerically. */
|
|
24
|
+
numeric?: boolean
|
|
25
|
+
/** Format the raw value for display (receives the value and the whole row). */
|
|
26
|
+
format?: (value: TableRow, row: TableRow) => string
|
|
27
|
+
/** Custom cell content as a Svelte 5 snippet — receives the row. */
|
|
28
|
+
cell?: Snippet<[TableRow]>
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Current sort state for a {@link Table}. */
|
|
32
|
+
export interface TableSort {
|
|
33
|
+
key: string
|
|
34
|
+
dir: 'asc' | 'desc'
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<script lang="ts">
|
|
39
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
40
|
+
|
|
41
|
+
interface Props {
|
|
42
|
+
/** Column definitions. */
|
|
43
|
+
columns: TableColumn[]
|
|
44
|
+
/** Row data; each row is an arbitrary object keyed by column `key`. */
|
|
45
|
+
rows: TableRow[]
|
|
46
|
+
/** Active sort ($bindable). Clicking a sortable header toggles asc/desc. */
|
|
47
|
+
sort?: TableSort
|
|
48
|
+
/** Notified when the sort changes (in addition to updating the bound `sort`). */
|
|
49
|
+
onsort?: (s: TableSort) => void
|
|
50
|
+
/** Optional table caption; rendered subtly above the grid. */
|
|
51
|
+
caption?: string
|
|
52
|
+
/** Content shown when `rows` is empty (replaces the default "No data" row). */
|
|
53
|
+
empty?: Snippet
|
|
54
|
+
/** Stable key per row for keyed iteration. Defaults to the row index. */
|
|
55
|
+
getRowKey?: (row: TableRow, i: number) => string | number
|
|
56
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
57
|
+
size?: Size
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let {
|
|
61
|
+
columns,
|
|
62
|
+
rows,
|
|
63
|
+
sort = $bindable(),
|
|
64
|
+
onsort,
|
|
65
|
+
caption,
|
|
66
|
+
empty,
|
|
67
|
+
getRowKey,
|
|
68
|
+
size,
|
|
69
|
+
}: Props = $props()
|
|
70
|
+
|
|
71
|
+
const resolvedSize = $derived(resolveComponentSize('Table', size))
|
|
72
|
+
|
|
73
|
+
// Sorted view: only sort when an active sort targets a known column.
|
|
74
|
+
const sortedRows = $derived.by(() => {
|
|
75
|
+
if (!sort) return rows
|
|
76
|
+
const col = columns.find((c) => c.key === sort!.key)
|
|
77
|
+
if (!col) return rows
|
|
78
|
+
const dir = sort.dir === 'desc' ? -1 : 1
|
|
79
|
+
const copy = [...rows]
|
|
80
|
+
copy.sort((a, b) => {
|
|
81
|
+
const av = a?.[sort!.key]
|
|
82
|
+
const bv = b?.[sort!.key]
|
|
83
|
+
if (col.numeric) return (Number(av) - Number(bv)) * dir
|
|
84
|
+
return String(av ?? '').localeCompare(String(bv ?? '')) * dir
|
|
85
|
+
})
|
|
86
|
+
return copy
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
function ariaSort(key: string): 'ascending' | 'descending' | 'none' {
|
|
90
|
+
if (!sort || sort.key !== key) return 'none'
|
|
91
|
+
return sort.dir === 'asc' ? 'ascending' : 'descending'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function toggleSort(key: string) {
|
|
95
|
+
// Same column → flip direction; new column → start ascending.
|
|
96
|
+
const next: TableSort =
|
|
97
|
+
sort && sort.key === key
|
|
98
|
+
? { key, dir: sort.dir === 'asc' ? 'desc' : 'asc' }
|
|
99
|
+
: { key, dir: 'asc' }
|
|
100
|
+
sort = next
|
|
101
|
+
onsort?.(next)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function display(col: TableColumn, row: TableRow): string {
|
|
105
|
+
const value = row?.[col.key]
|
|
106
|
+
return col.format ? col.format(value, row) : String(value ?? '')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function colAlign(col: TableColumn): 'left' | 'right' | 'center' {
|
|
110
|
+
return col.align ?? (col.numeric ? 'right' : 'left')
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const isEmpty = $derived(rows.length === 0)
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<table class="ss-table" data-size-variant={resolvedSize}>
|
|
117
|
+
{#if caption}<caption>{caption}</caption>{/if}
|
|
118
|
+
<thead>
|
|
119
|
+
<tr>
|
|
120
|
+
{#each columns as col (col.key)}
|
|
121
|
+
<th
|
|
122
|
+
scope="col"
|
|
123
|
+
class="head"
|
|
124
|
+
class:numeric={col.numeric}
|
|
125
|
+
data-align={colAlign(col)}
|
|
126
|
+
aria-sort={col.sortable ? ariaSort(col.key) : undefined}
|
|
127
|
+
>
|
|
128
|
+
{#if col.sortable}
|
|
129
|
+
<button type="button" class="sort" onclick={() => toggleSort(col.key)}>
|
|
130
|
+
<span class="label">{col.label}</span>
|
|
131
|
+
<span class="indicator" aria-hidden="true">
|
|
132
|
+
{#if sort && sort.key === col.key}{sort.dir === 'asc' ? '↑' : '↓'}{:else}↕{/if}
|
|
133
|
+
</span>
|
|
134
|
+
</button>
|
|
135
|
+
{:else}
|
|
136
|
+
<span class="label">{col.label}</span>
|
|
137
|
+
{/if}
|
|
138
|
+
</th>
|
|
139
|
+
{/each}
|
|
140
|
+
</tr>
|
|
141
|
+
</thead>
|
|
142
|
+
<tbody>
|
|
143
|
+
{#if isEmpty}
|
|
144
|
+
<tr class="empty-row">
|
|
145
|
+
<td class="cell empty" colspan={columns.length}>
|
|
146
|
+
{#if empty}{@render empty()}{:else}No data{/if}
|
|
147
|
+
</td>
|
|
148
|
+
</tr>
|
|
149
|
+
{:else}
|
|
150
|
+
{#each sortedRows as row, i (getRowKey ? getRowKey(row, i) : i)}
|
|
151
|
+
<tr class="row">
|
|
152
|
+
{#each columns as col (col.key)}
|
|
153
|
+
<td class="cell" class:numeric={col.numeric} data-align={colAlign(col)}>
|
|
154
|
+
{#if col.cell}{@render col.cell(row)}{:else}{display(col, row)}{/if}
|
|
155
|
+
</td>
|
|
156
|
+
{/each}
|
|
157
|
+
</tr>
|
|
158
|
+
{/each}
|
|
159
|
+
{/if}
|
|
160
|
+
</tbody>
|
|
161
|
+
</table>
|
|
162
|
+
|
|
163
|
+
<style>.ss-table {
|
|
164
|
+
width: 100%;
|
|
165
|
+
border-collapse: collapse;
|
|
166
|
+
font-family: var(--ss-font-body);
|
|
167
|
+
font-size: var(--ss-table-font, var(--ss-ui-xs));
|
|
168
|
+
color: var(--ss-fg);
|
|
169
|
+
background: var(--ss-bg);
|
|
170
|
+
}
|
|
171
|
+
.ss-table caption {
|
|
172
|
+
caption-side: top;
|
|
173
|
+
text-align: left;
|
|
174
|
+
font-family: var(--ss-font-mono);
|
|
175
|
+
font-size: var(--ss-ui-xs);
|
|
176
|
+
color: var(--ss-fg-muted);
|
|
177
|
+
letter-spacing: 0.04em;
|
|
178
|
+
padding-bottom: var(--ss-gap-sm);
|
|
179
|
+
}
|
|
180
|
+
.ss-table .head {
|
|
181
|
+
text-align: left;
|
|
182
|
+
font-family: var(--ss-font-mono);
|
|
183
|
+
font-size: var(--ss-ui-xs);
|
|
184
|
+
font-weight: 500;
|
|
185
|
+
text-transform: uppercase;
|
|
186
|
+
letter-spacing: 0.08em;
|
|
187
|
+
color: var(--ss-fg-muted);
|
|
188
|
+
background: var(--ss-bg-elev);
|
|
189
|
+
border-bottom: 1px solid var(--ss-line-strong);
|
|
190
|
+
padding: var(--ss-table-py, 8px) var(--ss-table-px, 12px);
|
|
191
|
+
white-space: nowrap;
|
|
192
|
+
}
|
|
193
|
+
.ss-table .head[data-align=right] {
|
|
194
|
+
text-align: right;
|
|
195
|
+
}
|
|
196
|
+
.ss-table .head[data-align=center] {
|
|
197
|
+
text-align: center;
|
|
198
|
+
}
|
|
199
|
+
.ss-table .head.numeric {
|
|
200
|
+
font-family: var(--ss-font-mono);
|
|
201
|
+
}
|
|
202
|
+
.ss-table .sort {
|
|
203
|
+
display: inline-flex;
|
|
204
|
+
align-items: center;
|
|
205
|
+
gap: var(--ss-gap-sm);
|
|
206
|
+
font: inherit;
|
|
207
|
+
letter-spacing: inherit;
|
|
208
|
+
text-transform: inherit;
|
|
209
|
+
color: inherit;
|
|
210
|
+
background: transparent;
|
|
211
|
+
border: none;
|
|
212
|
+
padding: 0;
|
|
213
|
+
margin: 0;
|
|
214
|
+
cursor: pointer;
|
|
215
|
+
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
216
|
+
}
|
|
217
|
+
.ss-table .sort:hover {
|
|
218
|
+
color: var(--ss-fg);
|
|
219
|
+
}
|
|
220
|
+
.ss-table .sort:focus-visible {
|
|
221
|
+
outline: none;
|
|
222
|
+
color: var(--ss-fg);
|
|
223
|
+
box-shadow: 0 0 0 2px var(--ss-primary-soft);
|
|
224
|
+
}
|
|
225
|
+
.ss-table .head[data-align=right] .sort {
|
|
226
|
+
flex-direction: row-reverse;
|
|
227
|
+
}
|
|
228
|
+
.ss-table .indicator {
|
|
229
|
+
color: var(--ss-fg-faint);
|
|
230
|
+
font-family: var(--ss-font-mono);
|
|
231
|
+
line-height: 1;
|
|
232
|
+
}
|
|
233
|
+
.ss-table th[aria-sort=ascending],
|
|
234
|
+
.ss-table th[aria-sort=descending] {
|
|
235
|
+
color: var(--ss-fg);
|
|
236
|
+
}
|
|
237
|
+
.ss-table th[aria-sort=ascending] .indicator,
|
|
238
|
+
.ss-table th[aria-sort=descending] .indicator {
|
|
239
|
+
color: var(--ss-primary);
|
|
240
|
+
}
|
|
241
|
+
.ss-table .row {
|
|
242
|
+
transition: background var(--ss-dur-fast) var(--ss-ease);
|
|
243
|
+
}
|
|
244
|
+
.ss-table .row:hover {
|
|
245
|
+
background: var(--ss-hover);
|
|
246
|
+
}
|
|
247
|
+
.ss-table .cell {
|
|
248
|
+
padding: var(--ss-table-py, 8px) var(--ss-table-px, 12px);
|
|
249
|
+
border-bottom: 1px solid var(--ss-line);
|
|
250
|
+
vertical-align: middle;
|
|
251
|
+
text-align: left;
|
|
252
|
+
}
|
|
253
|
+
.ss-table .cell[data-align=right] {
|
|
254
|
+
text-align: right;
|
|
255
|
+
}
|
|
256
|
+
.ss-table .cell[data-align=center] {
|
|
257
|
+
text-align: center;
|
|
258
|
+
}
|
|
259
|
+
.ss-table .cell.numeric {
|
|
260
|
+
font-family: var(--ss-font-mono);
|
|
261
|
+
}
|
|
262
|
+
.ss-table .cell.empty {
|
|
263
|
+
text-align: center;
|
|
264
|
+
color: var(--ss-fg-muted);
|
|
265
|
+
font-family: var(--ss-font-mono);
|
|
266
|
+
padding: var(--ss-table-empty-py, 24px) var(--ss-table-px, 12px);
|
|
267
|
+
}</style>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
/**
|
|
3
|
+
* A single table row passed to consumer callbacks and cell snippets. Typed as
|
|
4
|
+
* `any` so consumers can narrow the row shape in their own `format`, `cell`,
|
|
5
|
+
* and `getRowKey` definitions (Svelte `Snippet` params are contravariant, so
|
|
6
|
+
* a stricter row type here would reject narrowly-typed consumer snippets).
|
|
7
|
+
*/
|
|
8
|
+
export type TableRow = any;
|
|
9
|
+
/** One column definition for a {@link Table}. */
|
|
10
|
+
export interface TableColumn {
|
|
11
|
+
/** Key into each row object — also the cell's value source. */
|
|
12
|
+
key: string;
|
|
13
|
+
/** Header text. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** Text alignment of the body cells. Numeric columns default to `right`. */
|
|
16
|
+
align?: 'left' | 'right' | 'center';
|
|
17
|
+
/** Allow clicking the header to sort by this column. */
|
|
18
|
+
sortable?: boolean;
|
|
19
|
+
/** Treat values as numbers — right-aligns, uses the mono font, sorts numerically. */
|
|
20
|
+
numeric?: boolean;
|
|
21
|
+
/** Format the raw value for display (receives the value and the whole row). */
|
|
22
|
+
format?: (value: TableRow, row: TableRow) => string;
|
|
23
|
+
/** Custom cell content as a Svelte 5 snippet — receives the row. */
|
|
24
|
+
cell?: Snippet<[TableRow]>;
|
|
25
|
+
}
|
|
26
|
+
/** Current sort state for a {@link Table}. */
|
|
27
|
+
export interface TableSort {
|
|
28
|
+
key: string;
|
|
29
|
+
dir: 'asc' | 'desc';
|
|
30
|
+
}
|
|
31
|
+
import { type Size } from '../config.js';
|
|
32
|
+
interface Props {
|
|
33
|
+
/** Column definitions. */
|
|
34
|
+
columns: TableColumn[];
|
|
35
|
+
/** Row data; each row is an arbitrary object keyed by column `key`. */
|
|
36
|
+
rows: TableRow[];
|
|
37
|
+
/** Active sort ($bindable). Clicking a sortable header toggles asc/desc. */
|
|
38
|
+
sort?: TableSort;
|
|
39
|
+
/** Notified when the sort changes (in addition to updating the bound `sort`). */
|
|
40
|
+
onsort?: (s: TableSort) => void;
|
|
41
|
+
/** Optional table caption; rendered subtly above the grid. */
|
|
42
|
+
caption?: string;
|
|
43
|
+
/** Content shown when `rows` is empty (replaces the default "No data" row). */
|
|
44
|
+
empty?: Snippet;
|
|
45
|
+
/** Stable key per row for keyed iteration. Defaults to the row index. */
|
|
46
|
+
getRowKey?: (row: TableRow, i: number) => string | number;
|
|
47
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
48
|
+
size?: Size;
|
|
49
|
+
}
|
|
50
|
+
declare const Table: import("svelte").Component<Props, {}, "sort">;
|
|
51
|
+
type Table = ReturnType<typeof Table>;
|
|
52
|
+
export default Table;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
4
|
+
|
|
5
|
+
/** Side the tooltip attaches to relative to the trigger. */
|
|
6
|
+
type Placement = 'top' | 'bottom' | 'left' | 'right'
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
/** Tooltip text (the accessible description of the trigger). */
|
|
10
|
+
text: string
|
|
11
|
+
/** Where the tooltip attaches relative to the trigger. Default `top`. */
|
|
12
|
+
placement?: Placement
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size
|
|
15
|
+
/** Trigger content (wrapped in an inline-block container). */
|
|
16
|
+
children: Snippet
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let { text, placement = 'top', size, children }: Props = $props()
|
|
20
|
+
|
|
21
|
+
const tipId = $props.id()
|
|
22
|
+
|
|
23
|
+
let open = $state(false)
|
|
24
|
+
|
|
25
|
+
function show() {
|
|
26
|
+
open = true
|
|
27
|
+
}
|
|
28
|
+
function hide() {
|
|
29
|
+
open = false
|
|
30
|
+
}
|
|
31
|
+
function onKeydown(e: KeyboardEvent) {
|
|
32
|
+
// Escape dismisses the tooltip (WAI-ARIA tooltip pattern).
|
|
33
|
+
if (e.key === 'Escape' && open) {
|
|
34
|
+
open = false
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const sizeAttr = $derived(resolveComponentSize('Tooltip', size))
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<!--
|
|
42
|
+
Inline-block wrapper around the trigger snippet. Hover (mouseenter/leave) and
|
|
43
|
+
focus (focusin/out — bubbling, so a focusable child trigger counts) toggle the
|
|
44
|
+
tooltip; Escape dismisses it. While open the wrapper carries aria-describedby
|
|
45
|
+
pointing at the tooltip; the tip itself is kept in the DOM but hidden (and
|
|
46
|
+
given `hidden`) when closed so it is never announced.
|
|
47
|
+
-->
|
|
48
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -- the wrapper is a passive
|
|
49
|
+
container; the real interactive element is the trigger snippet inside it, and the
|
|
50
|
+
hover/focus/keydown handlers only react to that child's bubbling events. -->
|
|
51
|
+
<span
|
|
52
|
+
class="ss-tooltip"
|
|
53
|
+
data-size-variant={sizeAttr}
|
|
54
|
+
data-placement={placement}
|
|
55
|
+
aria-describedby={open ? tipId : undefined}
|
|
56
|
+
onmouseenter={show}
|
|
57
|
+
onmouseleave={hide}
|
|
58
|
+
onfocusin={show}
|
|
59
|
+
onfocusout={hide}
|
|
60
|
+
onkeydown={onKeydown}
|
|
61
|
+
>
|
|
62
|
+
<span class="trigger">{@render children()}</span>
|
|
63
|
+
<span id={tipId} class="tip" class:open role="tooltip" hidden={!open}>{text}</span>
|
|
64
|
+
</span>
|
|
65
|
+
|
|
66
|
+
<style>.ss-tooltip {
|
|
67
|
+
position: relative;
|
|
68
|
+
display: inline-block;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.trigger {
|
|
72
|
+
display: inline-flex;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.tip {
|
|
76
|
+
position: absolute;
|
|
77
|
+
z-index: 60;
|
|
78
|
+
width: max-content;
|
|
79
|
+
max-width: var(--ss-tooltip-max-w, 240px);
|
|
80
|
+
padding: var(--ss-tooltip-py, 4px) var(--ss-tooltip-px, 8px);
|
|
81
|
+
font: 500 var(--ss-ui-xs) var(--ss-font-mono);
|
|
82
|
+
color: var(--ss-fg);
|
|
83
|
+
background: var(--ss-bg-elev);
|
|
84
|
+
border: 1px solid var(--ss-line);
|
|
85
|
+
box-shadow: var(--ss-shadow-pop);
|
|
86
|
+
border-radius: 0;
|
|
87
|
+
opacity: 0;
|
|
88
|
+
visibility: hidden;
|
|
89
|
+
pointer-events: none;
|
|
90
|
+
transform: scale(0.98);
|
|
91
|
+
transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear var(--ss-dur);
|
|
92
|
+
}
|
|
93
|
+
.tip.open {
|
|
94
|
+
opacity: 1;
|
|
95
|
+
visibility: visible;
|
|
96
|
+
transform: scale(1);
|
|
97
|
+
transition: opacity var(--ss-dur) var(--ss-ease), transform var(--ss-dur) var(--ss-ease), visibility 0s linear 0s;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.ss-tooltip[data-placement=top] .tip {
|
|
101
|
+
bottom: calc(100% + var(--ss-tooltip-offset, 6px));
|
|
102
|
+
left: 50%;
|
|
103
|
+
transform: translateX(-50%) scale(0.98);
|
|
104
|
+
transform-origin: bottom center;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.ss-tooltip[data-placement=top] .tip.open {
|
|
108
|
+
transform: translateX(-50%) scale(1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.ss-tooltip[data-placement=bottom] .tip {
|
|
112
|
+
top: calc(100% + var(--ss-tooltip-offset, 6px));
|
|
113
|
+
left: 50%;
|
|
114
|
+
transform: translateX(-50%) scale(0.98);
|
|
115
|
+
transform-origin: top center;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.ss-tooltip[data-placement=bottom] .tip.open {
|
|
119
|
+
transform: translateX(-50%) scale(1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.ss-tooltip[data-placement=left] .tip {
|
|
123
|
+
right: calc(100% + var(--ss-tooltip-offset, 6px));
|
|
124
|
+
top: 50%;
|
|
125
|
+
transform: translateY(-50%) scale(0.98);
|
|
126
|
+
transform-origin: right center;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.ss-tooltip[data-placement=left] .tip.open {
|
|
130
|
+
transform: translateY(-50%) scale(1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.ss-tooltip[data-placement=right] .tip {
|
|
134
|
+
left: calc(100% + var(--ss-tooltip-offset, 6px));
|
|
135
|
+
top: 50%;
|
|
136
|
+
transform: translateY(-50%) scale(0.98);
|
|
137
|
+
transform-origin: left center;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.ss-tooltip[data-placement=right] .tip.open {
|
|
141
|
+
transform: translateY(-50%) scale(1);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@media (prefers-reduced-motion: reduce) {
|
|
145
|
+
.tip,
|
|
146
|
+
.tip.open {
|
|
147
|
+
transition: none;
|
|
148
|
+
transform: none;
|
|
149
|
+
}
|
|
150
|
+
.ss-tooltip[data-placement=top] .tip,
|
|
151
|
+
.ss-tooltip[data-placement=top] .tip.open,
|
|
152
|
+
.ss-tooltip[data-placement=bottom] .tip,
|
|
153
|
+
.ss-tooltip[data-placement=bottom] .tip.open {
|
|
154
|
+
transform: translateX(-50%);
|
|
155
|
+
}
|
|
156
|
+
.ss-tooltip[data-placement=left] .tip,
|
|
157
|
+
.ss-tooltip[data-placement=left] .tip.open,
|
|
158
|
+
.ss-tooltip[data-placement=right] .tip,
|
|
159
|
+
.ss-tooltip[data-placement=right] .tip.open {
|
|
160
|
+
transform: translateY(-50%);
|
|
161
|
+
}
|
|
162
|
+
}</style>
|