dssoca 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/components/Accordion.svelte +30 -54
- package/dist/components/Badge.svelte +12 -7
- package/dist/components/Badge.svelte.d.ts +2 -1
- package/dist/components/BottomNav.svelte +18 -28
- package/dist/components/BoxPlot.svelte +34 -7
- package/dist/components/BumpChart.svelte +65 -26
- package/dist/components/Button.svelte +23 -1
- package/dist/components/Button.svelte.d.ts +5 -1
- package/dist/components/Card.svelte +32 -14
- package/dist/components/Card.svelte.d.ts +4 -1
- package/dist/components/Chart.svelte +166 -32
- package/dist/components/Chart.svelte.d.ts +13 -1
- package/dist/components/Checkbox.svelte +210 -0
- package/dist/components/Checkbox.svelte.d.ts +38 -0
- package/dist/components/DateField.svelte +1 -1
- package/dist/components/FileDrop.svelte +113 -77
- package/dist/components/FileDrop.svelte.d.ts +12 -2
- package/dist/components/Heatmap.svelte +128 -50
- package/dist/components/Heatmap.svelte.d.ts +2 -1
- package/dist/components/Icon.svelte +12 -3
- package/dist/components/Icon.svelte.d.ts +4 -0
- package/dist/components/Image.svelte +44 -44
- package/dist/components/Input.svelte +11 -6
- package/dist/components/Link.svelte +25 -14
- package/dist/components/LogStream.svelte +48 -33
- package/dist/components/Menu.svelte +81 -102
- package/dist/components/Menu.svelte.d.ts +8 -2
- package/dist/components/MetricTile.svelte +11 -1
- package/dist/components/MetricTile.svelte.d.ts +6 -0
- package/dist/components/Modal.svelte +108 -21
- package/dist/components/Modal.svelte.d.ts +18 -5
- package/dist/components/NumberField.svelte +44 -22
- package/dist/components/Pagination.svelte +54 -41
- 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 +42 -7
- package/dist/components/SearchPalette.svelte +216 -136
- package/dist/components/SearchPalette.svelte.d.ts +11 -4
- package/dist/components/SegmentedControl.svelte +47 -59
- package/dist/components/SegmentedControl.svelte.d.ts +7 -2
- package/dist/components/Select.svelte +3 -4
- package/dist/components/ServiceCard.svelte +105 -68
- package/dist/components/ServiceCard.svelte.d.ts +8 -3
- package/dist/components/ShortcutsHelp.svelte +49 -48
- package/dist/components/Sidebar.svelte +88 -117
- package/dist/components/Switch.svelte +24 -18
- package/dist/components/Switch.svelte.d.ts +6 -2
- package/dist/components/Table.svelte +29 -44
- package/dist/components/Table.svelte.d.ts +6 -2
- package/dist/components/Tabs.svelte +223 -0
- package/dist/components/Tabs.svelte.d.ts +51 -0
- package/dist/components/Textarea.svelte +1 -1
- package/dist/components/TierList.svelte +45 -49
- package/dist/components/TierList.svelte.d.ts +7 -3
- package/dist/components/Toaster.svelte +154 -32
- package/dist/components/Tooltip.svelte +122 -18
- package/dist/components/Tooltip.svelte.d.ts +1 -1
- package/dist/components/Topbar.svelte +29 -49
- 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/core/chart-nav.js +62 -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} +77 -5
- package/dist/{tierlist-core.js → core/tierlist.js} +64 -7
- 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/icons.d.ts +19 -2
- package/dist/icons.js +42 -3
- package/dist/index.d.ts +15 -2
- package/dist/index.js +10 -2
- 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 +35 -32
- 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 +46 -28
- package/dist/vanilla/index.d.ts +5 -1
- package/dist/vanilla/index.js +17 -4
- package/dist/vanilla/menu.js +101 -84
- package/dist/vanilla/modal.d.ts +7 -1
- package/dist/vanilla/modal.js +120 -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 +50 -43
- 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 +34 -34
- package/dist/vanilla/toast.d.ts +13 -5
- package/dist/vanilla/toast.js +132 -16
- package/dist/vanilla/tooltip.d.ts +5 -1
- package/dist/vanilla/tooltip.js +78 -19
- package/dist/vanilla.css +675 -160
- package/package.json +1 -1
- package/dist/toast-core.d.ts +0 -61
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
3
|
+
import {
|
|
4
|
+
numberFieldAnnouncement,
|
|
5
|
+
numberFieldParse,
|
|
6
|
+
numberFieldStep,
|
|
7
|
+
numberFieldStepperAttrs,
|
|
8
|
+
} from '../core/number-field.js'
|
|
3
9
|
|
|
4
10
|
interface Props {
|
|
5
11
|
label?: string
|
|
@@ -65,27 +71,29 @@
|
|
|
65
71
|
const isInvalid = $derived(invalid || Boolean(error) || undefined)
|
|
66
72
|
const resolvedSize = $derived(resolveComponentSize('NumberField', size))
|
|
67
73
|
|
|
68
|
-
// Steppers are
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
// Steppers are natively disabled only when the whole field can't be edited. At a bound
|
|
75
|
+
// they stay focusable and become `aria-disabled` no-ops, so a keyboard user who presses
|
|
76
|
+
// − down to `min` keeps focus on the button instead of dropping to <body>.
|
|
77
|
+
// Parsing, stepping and that stepper state are decided in core/number-field.ts (shared with
|
|
78
|
+
// vanilla.js); this file holds the value and applies the result.
|
|
79
|
+
const locked = $derived(disabled || readonly)
|
|
80
|
+
const field = $derived({ value, min, max, step, locked })
|
|
81
|
+
const decAttrs = $derived(numberFieldStepperAttrs(field, -1))
|
|
82
|
+
const incAttrs = $derived(numberFieldStepperAttrs(field, 1))
|
|
73
83
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return n
|
|
78
|
-
}
|
|
84
|
+
// Polite live region text: set only by the steppers (typing in the input is already
|
|
85
|
+
// voiced by AT). The region itself is always rendered so updates are announced.
|
|
86
|
+
let announcement = $state('')
|
|
79
87
|
|
|
80
88
|
function onInput(e: Event & { currentTarget: HTMLInputElement }) {
|
|
81
|
-
|
|
82
|
-
value = raw === '' ? null : e.currentTarget.valueAsNumber
|
|
83
|
-
if (value != null && Number.isNaN(value)) value = null
|
|
89
|
+
value = numberFieldParse(e.currentTarget.value, e.currentTarget.valueAsNumber)
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
function nudge(dir: 1 | -1) {
|
|
87
|
-
const
|
|
88
|
-
|
|
93
|
+
const next = numberFieldStep(field, dir)
|
|
94
|
+
if (next === null) return
|
|
95
|
+
value = next
|
|
96
|
+
announcement = numberFieldAnnouncement(next)
|
|
89
97
|
}
|
|
90
98
|
</script>
|
|
91
99
|
|
|
@@ -107,7 +115,8 @@
|
|
|
107
115
|
type="button"
|
|
108
116
|
class="step dec"
|
|
109
117
|
aria-label="Decrease"
|
|
110
|
-
|
|
118
|
+
aria-controls={inputId}
|
|
119
|
+
{...decAttrs}
|
|
111
120
|
onclick={() => nudge(-1)}
|
|
112
121
|
>
|
|
113
122
|
−
|
|
@@ -136,12 +145,14 @@
|
|
|
136
145
|
type="button"
|
|
137
146
|
class="step inc"
|
|
138
147
|
aria-label="Increase"
|
|
139
|
-
|
|
148
|
+
aria-controls={inputId}
|
|
149
|
+
{...incAttrs}
|
|
140
150
|
onclick={() => nudge(1)}
|
|
141
151
|
>
|
|
142
152
|
+
|
|
143
153
|
</button>
|
|
144
154
|
</div>
|
|
155
|
+
<span class="live" aria-live="polite" aria-atomic="true">{announcement}</span>
|
|
145
156
|
|
|
146
157
|
{#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
|
|
147
158
|
{#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
|
|
@@ -161,7 +172,7 @@
|
|
|
161
172
|
}
|
|
162
173
|
.ss-numberfield .lbl .req {
|
|
163
174
|
color: var(--ss-red);
|
|
164
|
-
margin-
|
|
175
|
+
margin-inline-start: 2px;
|
|
165
176
|
}
|
|
166
177
|
.ss-numberfield .control {
|
|
167
178
|
display: flex;
|
|
@@ -200,18 +211,29 @@
|
|
|
200
211
|
cursor: pointer;
|
|
201
212
|
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
202
213
|
}
|
|
203
|
-
.ss-numberfield .step:hover:not(:disabled) {
|
|
214
|
+
.ss-numberfield .step:hover:not(:disabled, [aria-disabled=true]) {
|
|
204
215
|
color: var(--ss-fg);
|
|
205
216
|
}
|
|
206
217
|
.ss-numberfield .step:focus-visible {
|
|
207
|
-
outline:
|
|
218
|
+
outline: 2px solid var(--ss-primary);
|
|
219
|
+
outline-offset: -2px;
|
|
208
220
|
color: var(--ss-fg);
|
|
209
|
-
box-shadow: 0 0 0 2px var(--ss-primary-soft);
|
|
210
221
|
}
|
|
211
|
-
.ss-numberfield .step:disabled {
|
|
222
|
+
.ss-numberfield .step:disabled, .ss-numberfield .step[aria-disabled=true] {
|
|
212
223
|
color: var(--ss-fg-faint);
|
|
213
224
|
cursor: not-allowed;
|
|
214
225
|
}
|
|
226
|
+
.ss-numberfield .live {
|
|
227
|
+
position: absolute;
|
|
228
|
+
width: 1px;
|
|
229
|
+
height: 1px;
|
|
230
|
+
padding: 0;
|
|
231
|
+
margin: -1px;
|
|
232
|
+
overflow: hidden;
|
|
233
|
+
clip: rect(0 0 0 0);
|
|
234
|
+
white-space: nowrap;
|
|
235
|
+
border: 0;
|
|
236
|
+
}
|
|
215
237
|
.ss-numberfield .msg {
|
|
216
238
|
font-family: var(--ss-font-mono);
|
|
217
239
|
font-size: var(--ss-ui-xs);
|
|
@@ -7,7 +7,21 @@
|
|
|
7
7
|
// density. The current page is `aria-current="page"`, visually active and
|
|
8
8
|
// inert (re-clicking it never re-fires). WCAG 2.2 AA.
|
|
9
9
|
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
import { tick } from 'svelte'
|
|
10
11
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
12
|
+
import {
|
|
13
|
+
paginationClamp,
|
|
14
|
+
paginationIsGap,
|
|
15
|
+
paginationPageAttrs,
|
|
16
|
+
paginationPageCount,
|
|
17
|
+
paginationPagePress,
|
|
18
|
+
paginationSlots,
|
|
19
|
+
paginationStep,
|
|
20
|
+
paginationStepperDisabled,
|
|
21
|
+
type PaginationChange,
|
|
22
|
+
type PaginationChangeDetails,
|
|
23
|
+
type PaginationState,
|
|
24
|
+
} from '../core/pagination.js'
|
|
11
25
|
|
|
12
26
|
interface Props {
|
|
13
27
|
/** Current page, 1-based (bindable). */
|
|
@@ -24,8 +38,11 @@
|
|
|
24
38
|
disabled?: boolean
|
|
25
39
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
26
40
|
size?: Size
|
|
27
|
-
/**
|
|
28
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Fired when the page changes (after `page` updates), with the new page and what changed
|
|
43
|
+
* it (`details.reason`: page · prev · next).
|
|
44
|
+
*/
|
|
45
|
+
onchange?: (page: number, details: PaginationChangeDetails) => void
|
|
29
46
|
}
|
|
30
47
|
|
|
31
48
|
let {
|
|
@@ -39,46 +56,40 @@
|
|
|
39
56
|
onchange,
|
|
40
57
|
}: Props = $props()
|
|
41
58
|
|
|
59
|
+
// Behaviour lives in `core/pagination.ts`: the page window, the bounds and what a press
|
|
60
|
+
// does are decided there; this file holds the state and applies the result.
|
|
61
|
+
|
|
42
62
|
// Total number of pages — explicit `pageCount` wins, else derived from the
|
|
43
63
|
// item count. Always at least 1 so the control never renders empty.
|
|
44
|
-
const pages = $derived(pageCount
|
|
64
|
+
const pages = $derived(paginationPageCount({ pageCount, total, pageSize }))
|
|
45
65
|
|
|
46
66
|
// Clamp the active page into [1, pages] for all rendering/decisions.
|
|
47
|
-
const current = $derived(
|
|
48
|
-
|
|
49
|
-
type Slot = number | 'gap-start' | 'gap-end'
|
|
67
|
+
const current = $derived(paginationClamp(page, pages))
|
|
50
68
|
|
|
51
69
|
// Windowed list of slots: first page, last page, the sibling window around
|
|
52
70
|
// the current page, and an ellipsis marker wherever a run of pages is hidden.
|
|
53
|
-
const slots = $derived
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const out: Slot[] = [1]
|
|
57
|
-
// A single hidden page is cheaper to show than an ellipsis — only collapse
|
|
58
|
-
// a run into `…` when it hides more than one page.
|
|
59
|
-
if (start > 3) out.push('gap-start')
|
|
60
|
-
else if (start === 3) out.push(2)
|
|
61
|
-
for (let p = start; p <= end; p++) out.push(p)
|
|
62
|
-
if (end < pages - 2) out.push('gap-end')
|
|
63
|
-
else if (end === pages - 2) out.push(pages - 1)
|
|
64
|
-
if (pages > 1) out.push(pages)
|
|
65
|
-
return out
|
|
66
|
-
})
|
|
71
|
+
const slots = $derived(paginationSlots(current, pages, siblingCount))
|
|
72
|
+
|
|
73
|
+
const pagination = $derived<PaginationState>({ current, pages, disabled })
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
const atLast = $derived(current >= pages)
|
|
75
|
+
let navEl = $state<HTMLElement>()
|
|
70
76
|
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
page
|
|
75
|
-
|
|
77
|
+
async function apply(change: PaginationChange | null) {
|
|
78
|
+
if (!change) return
|
|
79
|
+
page = change.page
|
|
80
|
+
onchange?.(change.page, { reason: change.reason })
|
|
81
|
+
if (change.focus === 'current') {
|
|
82
|
+
// The stepper just became disabled under the focus: hand it to the current page.
|
|
83
|
+
await tick()
|
|
84
|
+
navEl?.querySelector<HTMLElement>('[aria-current="page"]')?.focus()
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
const sizeAttr = $derived(resolveComponentSize('Pagination', size))
|
|
79
89
|
</script>
|
|
80
90
|
|
|
81
91
|
<nav
|
|
92
|
+
bind:this={navEl}
|
|
82
93
|
class="ss-pagination"
|
|
83
94
|
aria-label="Pagination"
|
|
84
95
|
data-size-variant={sizeAttr}
|
|
@@ -88,25 +99,27 @@
|
|
|
88
99
|
type="button"
|
|
89
100
|
class="page nav-btn"
|
|
90
101
|
aria-label="Previous page"
|
|
91
|
-
disabled={
|
|
92
|
-
onclick={() =>
|
|
102
|
+
disabled={paginationStepperDisabled(pagination, 'prev')}
|
|
103
|
+
onclick={() => apply(paginationStep(pagination, 'prev'))}
|
|
93
104
|
>
|
|
105
|
+
<!-- ‹ › are Bidi_Mirrored (UAX #9, rule L4): in an RTL context the browser
|
|
106
|
+
already draws them flipped, so no transform is needed (one would
|
|
107
|
+
double-mirror them back). -->
|
|
94
108
|
<span aria-hidden="true">‹</span>
|
|
95
109
|
</button>
|
|
96
110
|
|
|
97
111
|
{#each slots as slot (slot)}
|
|
98
|
-
{#if slot
|
|
112
|
+
{#if paginationIsGap(slot)}
|
|
99
113
|
<span class="ellipsis" aria-hidden="true">…</span>
|
|
100
114
|
{:else}
|
|
101
|
-
{@const
|
|
115
|
+
{@const attrs = paginationPageAttrs(slot, current)}
|
|
102
116
|
<button
|
|
103
117
|
type="button"
|
|
104
118
|
class="page"
|
|
105
|
-
class:active={
|
|
106
|
-
|
|
107
|
-
aria-label={`Page ${slot}`}
|
|
119
|
+
class:active={attrs['aria-current'] === 'page'}
|
|
120
|
+
{...attrs}
|
|
108
121
|
{disabled}
|
|
109
|
-
onclick={() =>
|
|
122
|
+
onclick={() => apply(paginationPagePress(pagination, slot))}
|
|
110
123
|
>
|
|
111
124
|
{slot}
|
|
112
125
|
</button>
|
|
@@ -117,8 +130,8 @@
|
|
|
117
130
|
type="button"
|
|
118
131
|
class="page nav-btn"
|
|
119
132
|
aria-label="Next page"
|
|
120
|
-
disabled={
|
|
121
|
-
onclick={() =>
|
|
133
|
+
disabled={paginationStepperDisabled(pagination, 'next')}
|
|
134
|
+
onclick={() => apply(paginationStep(pagination, 'next'))}
|
|
122
135
|
>
|
|
123
136
|
<span aria-hidden="true">›</span>
|
|
124
137
|
</button>
|
|
@@ -142,14 +155,14 @@
|
|
|
142
155
|
color: var(--ss-fg-muted);
|
|
143
156
|
background: transparent;
|
|
144
157
|
border: 0;
|
|
145
|
-
border-
|
|
158
|
+
border-inline-start: 1px solid var(--ss-line);
|
|
146
159
|
padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
|
|
147
160
|
cursor: pointer;
|
|
148
161
|
white-space: nowrap;
|
|
149
162
|
transition: color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease);
|
|
150
163
|
}
|
|
151
164
|
.ss-pagination .page:first-child {
|
|
152
|
-
border-
|
|
165
|
+
border-inline-start: 0;
|
|
153
166
|
}
|
|
154
167
|
.ss-pagination .page:hover:not(.active):not(:disabled) {
|
|
155
168
|
color: var(--ss-fg);
|
|
@@ -162,7 +175,7 @@
|
|
|
162
175
|
}
|
|
163
176
|
.ss-pagination .page:focus-visible {
|
|
164
177
|
outline: none;
|
|
165
|
-
box-shadow: inset 0 0 0 2px var(--ss-primary
|
|
178
|
+
box-shadow: inset 0 0 0 2px var(--ss-primary);
|
|
166
179
|
z-index: 1;
|
|
167
180
|
}
|
|
168
181
|
.ss-pagination .page.active:focus-visible {
|
|
@@ -185,7 +198,7 @@
|
|
|
185
198
|
justify-content: center;
|
|
186
199
|
min-width: var(--ss-pagination-min, 2.25em);
|
|
187
200
|
padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
|
|
188
|
-
border-
|
|
201
|
+
border-inline-start: 1px solid var(--ss-line);
|
|
189
202
|
color: var(--ss-fg-muted);
|
|
190
203
|
font-family: var(--ss-font-mono);
|
|
191
204
|
line-height: 1;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Size } from '../config.js';
|
|
2
|
+
import { type PaginationChangeDetails } from '../core/pagination.js';
|
|
2
3
|
interface Props {
|
|
3
4
|
/** Current page, 1-based (bindable). */
|
|
4
5
|
page?: number;
|
|
@@ -14,8 +15,11 @@ interface Props {
|
|
|
14
15
|
disabled?: boolean;
|
|
15
16
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
16
17
|
size?: Size;
|
|
17
|
-
/**
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Fired when the page changes (after `page` updates), with the new page and what changed
|
|
20
|
+
* it (`details.reason`: page · prev · next).
|
|
21
|
+
*/
|
|
22
|
+
onchange?: (page: number, details: PaginationChangeDetails) => void;
|
|
19
23
|
}
|
|
20
24
|
declare const Pagination: import("svelte").Component<Props, {}, "page">;
|
|
21
25
|
type Pagination = ReturnType<typeof Pagination>;
|
|
@@ -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;
|