dssoca 0.5.0 → 0.8.2
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 +281 -0
- package/dist/components/Accordion.svelte.d.ts +47 -0
- package/dist/components/Badge.svelte +115 -18
- package/dist/components/Badge.svelte.d.ts +28 -2
- package/dist/components/BottomNav.svelte +216 -0
- package/dist/components/BottomNav.svelte.d.ts +30 -0
- package/dist/components/Button.svelte +147 -10
- package/dist/components/Button.svelte.d.ts +21 -4
- package/dist/components/Card.svelte +167 -8
- package/dist/components/Card.svelte.d.ts +16 -1
- package/dist/components/EmptyState.svelte +85 -9
- package/dist/components/EmptyState.svelte.d.ts +14 -3
- package/dist/components/Icon.svelte +179 -13
- package/dist/components/Icon.svelte.d.ts +63 -2
- package/dist/components/Image.svelte +430 -0
- package/dist/components/Image.svelte.d.ts +49 -0
- package/dist/components/Input.svelte +174 -39
- package/dist/components/Input.svelte.d.ts +22 -0
- package/dist/components/Link.svelte +148 -0
- package/dist/components/Link.svelte.d.ts +22 -0
- package/dist/components/LogStream.svelte +378 -37
- package/dist/components/LogStream.svelte.d.ts +35 -7
- package/dist/components/Menu.svelte +355 -0
- package/dist/components/Menu.svelte.d.ts +46 -0
- package/dist/components/MetricTile.svelte +124 -12
- package/dist/components/MetricTile.svelte.d.ts +20 -0
- package/dist/components/SegmentedControl.svelte +208 -0
- package/dist/components/SegmentedControl.svelte.d.ts +30 -0
- package/dist/components/ServiceCard.svelte +222 -26
- package/dist/components/ServiceCard.svelte.d.ts +13 -1
- package/dist/components/Sidebar.svelte +340 -29
- package/dist/components/Sidebar.svelte.d.ts +18 -7
- package/dist/components/Sparkline.svelte +196 -13
- package/dist/components/Sparkline.svelte.d.ts +20 -1
- package/dist/components/Toaster.svelte +193 -12
- package/dist/components/Toaster.svelte.d.ts +3 -0
- package/dist/components/Topbar.svelte +152 -21
- package/dist/components/Topbar.svelte.d.ts +20 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +6 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.js +12 -2
- package/dist/theme.css +242 -0
- package/dist/toast.svelte.d.ts +49 -5
- package/dist/toast.svelte.js +165 -9
- package/package.json +1 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
/** One collapsible section of the Accordion. */
|
|
3
|
+
export interface AccordionItem {
|
|
4
|
+
/** Stable identifier — used for open state, `value`, and ARIA wiring. */
|
|
5
|
+
id: string
|
|
6
|
+
/** Header text (also the accessible name of the toggle button). */
|
|
7
|
+
label: string
|
|
8
|
+
/** Optional secondary text shown faint after the label. */
|
|
9
|
+
hint?: string
|
|
10
|
+
/** Disable this section — the header is not togglable. */
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Controlled `value`: a single open id (single mode) or a list (`multiple`). */
|
|
15
|
+
export type AccordionValue = string | string[] | undefined
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { untrack, type Snippet } from 'svelte'
|
|
20
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
21
|
+
|
|
22
|
+
interface Props {
|
|
23
|
+
/** The collapsible sections, top to bottom. */
|
|
24
|
+
items: AccordionItem[]
|
|
25
|
+
/**
|
|
26
|
+
* Content renderer for each section's panel; receives the item.
|
|
27
|
+
* {#snippet panel(item)} … {/snippet}
|
|
28
|
+
*/
|
|
29
|
+
panel: Snippet<[AccordionItem]>
|
|
30
|
+
/** Optional header renderer; overrides the default label + hint markup. */
|
|
31
|
+
header?: Snippet<[AccordionItem]>
|
|
32
|
+
/** Allow several sections open at once. Default: single-open. */
|
|
33
|
+
multiple?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* Controlled open state (bindable). In single mode a `string` id (or
|
|
36
|
+
* `undefined`); in `multiple` mode a `string[]` of open ids. When omitted,
|
|
37
|
+
* the component manages its own (uncontrolled) state.
|
|
38
|
+
*/
|
|
39
|
+
value?: AccordionValue
|
|
40
|
+
/** Open these sections initially when uncontrolled. */
|
|
41
|
+
defaultValue?: AccordionValue
|
|
42
|
+
/** Fired with the new open value whenever a section toggles. */
|
|
43
|
+
onChange?: (value: AccordionValue) => void
|
|
44
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
45
|
+
size?: Size
|
|
46
|
+
/** Heading level wrapping each header button (for the document outline). */
|
|
47
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6
|
|
48
|
+
/** Base id used to namespace the generated header/panel ids. */
|
|
49
|
+
idBase?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let {
|
|
53
|
+
items,
|
|
54
|
+
panel,
|
|
55
|
+
header,
|
|
56
|
+
multiple = false,
|
|
57
|
+
value = $bindable(),
|
|
58
|
+
defaultValue,
|
|
59
|
+
onChange,
|
|
60
|
+
size,
|
|
61
|
+
headingLevel = 3,
|
|
62
|
+
idBase = `ss-acc-${Math.random().toString(36).slice(2, 8)}`,
|
|
63
|
+
}: Props = $props()
|
|
64
|
+
|
|
65
|
+
// --- open-state model ----------------------------------------------------
|
|
66
|
+
// Normalise whatever `value`/`defaultValue` shape we were handed into a Set.
|
|
67
|
+
function toSet(v: AccordionValue): Set<string> {
|
|
68
|
+
if (v == null) return new Set()
|
|
69
|
+
return new Set(Array.isArray(v) ? v : [v])
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Uncontrolled fallback store, seeded once from defaultValue. `untrack`
|
|
73
|
+
// marks the read as an intentional one-time snapshot (not a live binding),
|
|
74
|
+
// silencing the "referenced locally" reactivity warning.
|
|
75
|
+
let internal = $state<Set<string>>(untrack(() => toSet(defaultValue)))
|
|
76
|
+
|
|
77
|
+
// Controlled when the consumer passes `value` (incl. bound); else internal.
|
|
78
|
+
const controlled = $derived(value !== undefined)
|
|
79
|
+
const open = $derived(controlled ? toSet(value) : internal)
|
|
80
|
+
|
|
81
|
+
const isOpen = (item: AccordionItem): boolean => open.has(item.id)
|
|
82
|
+
|
|
83
|
+
/** Project a Set back to the public value shape for `value`/`onChange`. */
|
|
84
|
+
function project(next: Set<string>): AccordionValue {
|
|
85
|
+
if (multiple) return [...next]
|
|
86
|
+
return next.size ? [...next][0] : undefined
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function toggle(item: AccordionItem) {
|
|
90
|
+
if (item.disabled) return
|
|
91
|
+
const next = new Set(open)
|
|
92
|
+
if (next.has(item.id)) {
|
|
93
|
+
next.delete(item.id)
|
|
94
|
+
} else {
|
|
95
|
+
if (!multiple) next.clear() // single-open: opening one closes others
|
|
96
|
+
next.add(item.id)
|
|
97
|
+
}
|
|
98
|
+
if (controlled) {
|
|
99
|
+
value = project(next) // keep the bound value in sync
|
|
100
|
+
} else {
|
|
101
|
+
internal = next
|
|
102
|
+
}
|
|
103
|
+
onChange?.(project(next))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// --- roving keyboard nav across headers (WAI-ARIA Accordion pattern) -----
|
|
107
|
+
let headerEls = $state<Array<HTMLButtonElement | null>>([])
|
|
108
|
+
|
|
109
|
+
function focusHeader(index: number) {
|
|
110
|
+
const n = items.length
|
|
111
|
+
if (n === 0) return
|
|
112
|
+
const i = ((index % n) + n) % n // wrap
|
|
113
|
+
headerEls[i]?.focus()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function onHeaderKeydown(e: KeyboardEvent, index: number) {
|
|
117
|
+
switch (e.key) {
|
|
118
|
+
case 'ArrowDown':
|
|
119
|
+
e.preventDefault(); focusHeader(index + 1); break
|
|
120
|
+
case 'ArrowUp':
|
|
121
|
+
e.preventDefault(); focusHeader(index - 1); break
|
|
122
|
+
case 'Home':
|
|
123
|
+
e.preventDefault(); focusHeader(0); break
|
|
124
|
+
case 'End':
|
|
125
|
+
e.preventDefault(); focusHeader(items.length - 1); break
|
|
126
|
+
// Enter / Space activate the native <button>; no extra handling needed.
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const headerId = (item: AccordionItem) => `${idBase}-h-${item.id}`
|
|
131
|
+
const panelId = (item: AccordionItem) => `${idBase}-p-${item.id}`
|
|
132
|
+
</script>
|
|
133
|
+
|
|
134
|
+
<div class="ss-accordion" data-size-variant={resolveComponentSize('Accordion', size)}>
|
|
135
|
+
{#each items as item, i (item.id)}
|
|
136
|
+
{@const expanded = isOpen(item)}
|
|
137
|
+
<div class="item" class:open={expanded} class:disabled={item.disabled}>
|
|
138
|
+
<div role="heading" aria-level={headingLevel} class="heading">
|
|
139
|
+
<button
|
|
140
|
+
bind:this={headerEls[i]}
|
|
141
|
+
type="button"
|
|
142
|
+
class="head"
|
|
143
|
+
id={headerId(item)}
|
|
144
|
+
aria-expanded={expanded}
|
|
145
|
+
aria-controls={panelId(item)}
|
|
146
|
+
aria-disabled={item.disabled || undefined}
|
|
147
|
+
onclick={() => toggle(item)}
|
|
148
|
+
onkeydown={(e) => onHeaderKeydown(e, i)}
|
|
149
|
+
>
|
|
150
|
+
{#if header}
|
|
151
|
+
{@render header(item)}
|
|
152
|
+
{:else}
|
|
153
|
+
<span class="title">{item.label}</span>
|
|
154
|
+
{#if item.hint}<span class="hint">{item.hint}</span>{/if}
|
|
155
|
+
{/if}
|
|
156
|
+
<span class="chevron" aria-hidden="true"></span>
|
|
157
|
+
</button>
|
|
158
|
+
</div>
|
|
159
|
+
<div
|
|
160
|
+
class="panel"
|
|
161
|
+
id={panelId(item)}
|
|
162
|
+
role="region"
|
|
163
|
+
aria-labelledby={headerId(item)}
|
|
164
|
+
hidden={!expanded}
|
|
165
|
+
>
|
|
166
|
+
<div class="panel-inner">
|
|
167
|
+
{@render panel(item)}
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
{/each}
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<style>.ss-accordion {
|
|
175
|
+
--ss-acc-head-py: var(--ss-row-py);
|
|
176
|
+
--ss-acc-head-px: var(--ss-row-px);
|
|
177
|
+
--ss-acc-body-py: var(--ss-s-3);
|
|
178
|
+
--ss-acc-body-px: var(--ss-row-px);
|
|
179
|
+
--ss-acc-chevron: 9px;
|
|
180
|
+
--ss-acc-gap: var(--ss-s-3);
|
|
181
|
+
}
|
|
182
|
+
.ss-accordion[data-size-variant=sm] {
|
|
183
|
+
--ss-acc-head-py: var(--ss-s-1);
|
|
184
|
+
--ss-acc-head-px: var(--ss-s-2);
|
|
185
|
+
--ss-acc-body-py: var(--ss-s-2);
|
|
186
|
+
--ss-acc-body-px: var(--ss-s-2);
|
|
187
|
+
--ss-acc-chevron: 7px;
|
|
188
|
+
--ss-acc-gap: var(--ss-s-2);
|
|
189
|
+
}
|
|
190
|
+
.ss-accordion[data-size-variant=lg] {
|
|
191
|
+
--ss-acc-head-py: var(--ss-s-3);
|
|
192
|
+
--ss-acc-head-px: var(--ss-s-4);
|
|
193
|
+
--ss-acc-body-py: var(--ss-s-4);
|
|
194
|
+
--ss-acc-body-px: var(--ss-s-4);
|
|
195
|
+
--ss-acc-chevron: 11px;
|
|
196
|
+
--ss-acc-gap: var(--ss-s-4);
|
|
197
|
+
}
|
|
198
|
+
.ss-accordion {
|
|
199
|
+
display: flex;
|
|
200
|
+
flex-direction: column;
|
|
201
|
+
border: 1px solid var(--ss-line);
|
|
202
|
+
background: var(--ss-bg);
|
|
203
|
+
}
|
|
204
|
+
.ss-accordion .item + .item {
|
|
205
|
+
border-top: 1px solid var(--ss-line);
|
|
206
|
+
}
|
|
207
|
+
.ss-accordion .heading {
|
|
208
|
+
margin: 0;
|
|
209
|
+
font: inherit;
|
|
210
|
+
}
|
|
211
|
+
.ss-accordion .head {
|
|
212
|
+
display: flex;
|
|
213
|
+
align-items: center;
|
|
214
|
+
gap: var(--ss-acc-gap);
|
|
215
|
+
width: 100%;
|
|
216
|
+
box-sizing: border-box;
|
|
217
|
+
padding: var(--ss-acc-head-py) var(--ss-acc-head-px);
|
|
218
|
+
background: none;
|
|
219
|
+
border: 0;
|
|
220
|
+
text-align: left;
|
|
221
|
+
cursor: pointer;
|
|
222
|
+
color: var(--ss-fg);
|
|
223
|
+
font: 500 var(--ss-ui-md) var(--ss-font-mono);
|
|
224
|
+
transition: background var(--ss-dur-fast) var(--ss-ease), color var(--ss-dur-fast) var(--ss-ease);
|
|
225
|
+
}
|
|
226
|
+
.ss-accordion .head:hover:not([aria-disabled=true]) {
|
|
227
|
+
background: var(--ss-hover);
|
|
228
|
+
}
|
|
229
|
+
.ss-accordion .head:focus-visible {
|
|
230
|
+
outline: 2px solid var(--ss-primary);
|
|
231
|
+
outline-offset: -2px;
|
|
232
|
+
}
|
|
233
|
+
.ss-accordion .head[aria-disabled=true] {
|
|
234
|
+
cursor: not-allowed;
|
|
235
|
+
color: var(--ss-fg-faint);
|
|
236
|
+
}
|
|
237
|
+
.ss-accordion .head .title {
|
|
238
|
+
flex: 1 1 auto;
|
|
239
|
+
min-width: 0;
|
|
240
|
+
}
|
|
241
|
+
.ss-accordion .head .hint {
|
|
242
|
+
flex: 0 0 auto;
|
|
243
|
+
color: var(--ss-fg-faint);
|
|
244
|
+
font-size: var(--ss-ui-sm);
|
|
245
|
+
}
|
|
246
|
+
.ss-accordion .head .chevron {
|
|
247
|
+
flex: 0 0 auto;
|
|
248
|
+
width: var(--ss-acc-chevron);
|
|
249
|
+
height: var(--ss-acc-chevron);
|
|
250
|
+
border-right: 1.5px solid currentColor;
|
|
251
|
+
border-bottom: 1.5px solid currentColor;
|
|
252
|
+
transform: rotate(45deg);
|
|
253
|
+
transform-origin: center;
|
|
254
|
+
transition: transform var(--ss-dur) var(--ss-ease);
|
|
255
|
+
color: var(--ss-fg-muted);
|
|
256
|
+
}
|
|
257
|
+
.ss-accordion .item.open .head .chevron {
|
|
258
|
+
transform: rotate(225deg);
|
|
259
|
+
}
|
|
260
|
+
.ss-accordion .panel {
|
|
261
|
+
display: grid;
|
|
262
|
+
grid-template-rows: 0fr;
|
|
263
|
+
transition: grid-template-rows var(--ss-dur) var(--ss-ease);
|
|
264
|
+
}
|
|
265
|
+
.ss-accordion .panel[hidden] {
|
|
266
|
+
display: grid;
|
|
267
|
+
grid-template-rows: 0fr;
|
|
268
|
+
}
|
|
269
|
+
.ss-accordion .panel:not([hidden]) {
|
|
270
|
+
grid-template-rows: 1fr;
|
|
271
|
+
}
|
|
272
|
+
.ss-accordion .panel-inner {
|
|
273
|
+
overflow: hidden;
|
|
274
|
+
min-height: 0;
|
|
275
|
+
}
|
|
276
|
+
.ss-accordion .panel:not([hidden]) .panel-inner {
|
|
277
|
+
padding: var(--ss-acc-body-py) var(--ss-acc-body-px);
|
|
278
|
+
color: var(--ss-fg-muted);
|
|
279
|
+
font-size: var(--ss-ui-md);
|
|
280
|
+
line-height: var(--ss-leading);
|
|
281
|
+
}</style>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** One collapsible section of the Accordion. */
|
|
2
|
+
export interface AccordionItem {
|
|
3
|
+
/** Stable identifier — used for open state, `value`, and ARIA wiring. */
|
|
4
|
+
id: string;
|
|
5
|
+
/** Header text (also the accessible name of the toggle button). */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Optional secondary text shown faint after the label. */
|
|
8
|
+
hint?: string;
|
|
9
|
+
/** Disable this section — the header is not togglable. */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Controlled `value`: a single open id (single mode) or a list (`multiple`). */
|
|
13
|
+
export type AccordionValue = string | string[] | undefined;
|
|
14
|
+
import { type Snippet } from 'svelte';
|
|
15
|
+
import { type Size } from '../config.js';
|
|
16
|
+
interface Props {
|
|
17
|
+
/** The collapsible sections, top to bottom. */
|
|
18
|
+
items: AccordionItem[];
|
|
19
|
+
/**
|
|
20
|
+
* Content renderer for each section's panel; receives the item.
|
|
21
|
+
* {#snippet panel(item)} … {/snippet}
|
|
22
|
+
*/
|
|
23
|
+
panel: Snippet<[AccordionItem]>;
|
|
24
|
+
/** Optional header renderer; overrides the default label + hint markup. */
|
|
25
|
+
header?: Snippet<[AccordionItem]>;
|
|
26
|
+
/** Allow several sections open at once. Default: single-open. */
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Controlled open state (bindable). In single mode a `string` id (or
|
|
30
|
+
* `undefined`); in `multiple` mode a `string[]` of open ids. When omitted,
|
|
31
|
+
* the component manages its own (uncontrolled) state.
|
|
32
|
+
*/
|
|
33
|
+
value?: AccordionValue;
|
|
34
|
+
/** Open these sections initially when uncontrolled. */
|
|
35
|
+
defaultValue?: AccordionValue;
|
|
36
|
+
/** Fired with the new open value whenever a section toggles. */
|
|
37
|
+
onChange?: (value: AccordionValue) => void;
|
|
38
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
39
|
+
size?: Size;
|
|
40
|
+
/** Heading level wrapping each header button (for the document outline). */
|
|
41
|
+
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
42
|
+
/** Base id used to namespace the generated header/panel ids. */
|
|
43
|
+
idBase?: string;
|
|
44
|
+
}
|
|
45
|
+
declare const Accordion: import("svelte").Component<Props, {}, "value">;
|
|
46
|
+
type Accordion = ReturnType<typeof Accordion>;
|
|
47
|
+
export default Accordion;
|
|
@@ -2,20 +2,87 @@
|
|
|
2
2
|
import type { Snippet } from 'svelte'
|
|
3
3
|
import { resolveComponentSize, type Size } from '../config.js'
|
|
4
4
|
|
|
5
|
+
type Tone = 'up' | 'deg' | 'down' | 'maint' | 'info' | 'neutral'
|
|
6
|
+
|
|
5
7
|
interface Props {
|
|
6
|
-
tone
|
|
8
|
+
/** Semantic tone; `neutral` is the safe baseline for non-status labels. */
|
|
9
|
+
tone?: Tone
|
|
7
10
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
8
11
|
size?: Size
|
|
9
|
-
|
|
12
|
+
/** Render the leading status dot. Off by default — opt in per badge. */
|
|
13
|
+
dot?: boolean
|
|
14
|
+
/**
|
|
15
|
+
* Optional numeric badge. When set, renders the count (clamped to `max`).
|
|
16
|
+
* A `count` of 0 renders nothing.
|
|
17
|
+
*/
|
|
18
|
+
count?: number
|
|
19
|
+
/** Cap for `count`; values above render as `${max}+`. Defaults to 99. */
|
|
20
|
+
max?: number
|
|
21
|
+
/**
|
|
22
|
+
* When set, treats the badge as a live status region
|
|
23
|
+
* (`role="status"` + `aria-live="polite"`) so AT announces changes.
|
|
24
|
+
* Static category tags stay plain spans.
|
|
25
|
+
*/
|
|
26
|
+
live?: boolean
|
|
27
|
+
/**
|
|
28
|
+
* Accessible label. Required for dot-only / label-less badges so the
|
|
29
|
+
* status isn't conveyed by colour alone (WCAG 1.4.1). Also names the
|
|
30
|
+
* dismiss button's target.
|
|
31
|
+
*/
|
|
32
|
+
label?: string
|
|
33
|
+
/** When provided, renders a trailing, keyboard-focusable dismiss button. */
|
|
34
|
+
ondismiss?: () => void
|
|
35
|
+
/** Badge text. Optional: omit for a dot-only or count-only badge. */
|
|
36
|
+
children?: Snippet
|
|
10
37
|
}
|
|
11
|
-
let { tone = 'info', size, children }: Props = $props()
|
|
12
38
|
|
|
13
|
-
|
|
39
|
+
let {
|
|
40
|
+
tone = 'info',
|
|
41
|
+
size,
|
|
42
|
+
dot = false,
|
|
43
|
+
count,
|
|
44
|
+
max = 99,
|
|
45
|
+
live = false,
|
|
46
|
+
label,
|
|
47
|
+
ondismiss,
|
|
48
|
+
children,
|
|
49
|
+
}: Props = $props()
|
|
50
|
+
|
|
51
|
+
// Numeric badge: clamp to max, hide entirely when zero.
|
|
52
|
+
const showCount = $derived(count !== undefined && count !== 0)
|
|
53
|
+
const countText = $derived(
|
|
54
|
+
count === undefined ? '' : count > max ? `${max}+` : `${count}`,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const hasLabel = $derived(children !== undefined)
|
|
58
|
+
// Dot-only / count-only badges have no visible text → carry an aria-label so
|
|
59
|
+
// the status isn't conveyed by colour alone (WCAG 1.4.1).
|
|
60
|
+
const ariaLabel = $derived(!hasLabel ? label : undefined)
|
|
61
|
+
// `live` wins (role=status). Otherwise a label-less badge needs a role for
|
|
62
|
+
// its aria-label to be valid (a bare span + aria-label is prohibited); use
|
|
63
|
+
// `img` so AT announces it as a single named status indicator.
|
|
64
|
+
const role = $derived(live ? 'status' : !hasLabel ? 'img' : undefined)
|
|
14
65
|
</script>
|
|
15
66
|
|
|
16
|
-
<span
|
|
17
|
-
|
|
18
|
-
{
|
|
67
|
+
<span
|
|
68
|
+
class="ss-badge {tone}"
|
|
69
|
+
class:label-less={!hasLabel}
|
|
70
|
+
data-size-variant={resolveComponentSize('Badge', size)}
|
|
71
|
+
{role}
|
|
72
|
+
aria-live={live ? 'polite' : undefined}
|
|
73
|
+
aria-label={ariaLabel}
|
|
74
|
+
>
|
|
75
|
+
{#if dot}<span class="dot" aria-hidden="true"></span>{/if}
|
|
76
|
+
{#if hasLabel}{@render children?.()}{/if}
|
|
77
|
+
{#if showCount}<span class="count">{countText}</span>{/if}
|
|
78
|
+
{#if ondismiss}
|
|
79
|
+
<button
|
|
80
|
+
class="x"
|
|
81
|
+
type="button"
|
|
82
|
+
aria-label={label ? `Remove ${label}` : 'Remove'}
|
|
83
|
+
onclick={ondismiss}
|
|
84
|
+
>×</button>
|
|
85
|
+
{/if}
|
|
19
86
|
</span>
|
|
20
87
|
|
|
21
88
|
<style>.ss-badge {
|
|
@@ -25,32 +92,62 @@
|
|
|
25
92
|
letter-spacing: 0.05em;
|
|
26
93
|
display: inline-flex;
|
|
27
94
|
align-items: center;
|
|
28
|
-
gap:
|
|
95
|
+
gap: var(--ss-badge-gap);
|
|
29
96
|
text-transform: lowercase;
|
|
30
97
|
border: 1px solid var(--ss-line);
|
|
31
98
|
}
|
|
32
99
|
.ss-badge.up {
|
|
33
|
-
background:
|
|
100
|
+
background: var(--ss-badge-up-bg);
|
|
34
101
|
color: var(--ss-primary);
|
|
35
|
-
border-color:
|
|
102
|
+
border-color: var(--ss-badge-up-border);
|
|
36
103
|
}
|
|
37
104
|
.ss-badge.deg {
|
|
38
|
-
background:
|
|
105
|
+
background: var(--ss-badge-deg-bg);
|
|
39
106
|
color: var(--ss-yellow);
|
|
40
|
-
border-color:
|
|
107
|
+
border-color: var(--ss-badge-deg-border);
|
|
41
108
|
}
|
|
42
109
|
.ss-badge.down {
|
|
43
|
-
background:
|
|
110
|
+
background: var(--ss-badge-down-bg);
|
|
44
111
|
color: var(--ss-red);
|
|
45
|
-
border-color:
|
|
112
|
+
border-color: var(--ss-badge-down-border);
|
|
113
|
+
}
|
|
114
|
+
.ss-badge.maint {
|
|
115
|
+
background: var(--ss-badge-maint-bg);
|
|
116
|
+
color: var(--ss-blue);
|
|
117
|
+
border-color: var(--ss-badge-maint-border);
|
|
46
118
|
}
|
|
47
119
|
.ss-badge.info {
|
|
48
|
-
background:
|
|
120
|
+
background: var(--ss-badge-info-bg);
|
|
49
121
|
color: var(--ss-cyan);
|
|
50
|
-
border-color:
|
|
122
|
+
border-color: var(--ss-badge-info-border);
|
|
123
|
+
}
|
|
124
|
+
.ss-badge.neutral {
|
|
125
|
+
background: var(--ss-badge-neutral-bg);
|
|
126
|
+
color: var(--ss-fg-muted);
|
|
127
|
+
border-color: var(--ss-badge-neutral-border);
|
|
51
128
|
}
|
|
52
129
|
.ss-badge .dot {
|
|
53
|
-
width:
|
|
54
|
-
height:
|
|
130
|
+
width: var(--ss-badge-dot);
|
|
131
|
+
height: var(--ss-badge-dot);
|
|
55
132
|
background: currentColor;
|
|
133
|
+
flex: none;
|
|
134
|
+
}
|
|
135
|
+
.ss-badge .count {
|
|
136
|
+
text-transform: none;
|
|
137
|
+
font-variant-numeric: tabular-nums;
|
|
138
|
+
}
|
|
139
|
+
.ss-badge .x {
|
|
140
|
+
flex: none;
|
|
141
|
+
background: none;
|
|
142
|
+
border: none;
|
|
143
|
+
color: currentColor;
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
font-size: var(--ss-size-sm);
|
|
146
|
+
line-height: 1;
|
|
147
|
+
padding: 0;
|
|
148
|
+
margin-inline-start: calc(var(--ss-badge-gap) * -0.25);
|
|
149
|
+
opacity: 0.8;
|
|
150
|
+
}
|
|
151
|
+
.ss-badge .x:hover, .ss-badge .x:focus-visible {
|
|
152
|
+
opacity: 1;
|
|
56
153
|
}</style>
|
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import type { Snippet } from 'svelte';
|
|
2
2
|
import { type Size } from '../config.js';
|
|
3
|
+
type Tone = 'up' | 'deg' | 'down' | 'maint' | 'info' | 'neutral';
|
|
3
4
|
interface Props {
|
|
4
|
-
tone
|
|
5
|
+
/** Semantic tone; `neutral` is the safe baseline for non-status labels. */
|
|
6
|
+
tone?: Tone;
|
|
5
7
|
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
6
8
|
size?: Size;
|
|
7
|
-
|
|
9
|
+
/** Render the leading status dot. Off by default — opt in per badge. */
|
|
10
|
+
dot?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Optional numeric badge. When set, renders the count (clamped to `max`).
|
|
13
|
+
* A `count` of 0 renders nothing.
|
|
14
|
+
*/
|
|
15
|
+
count?: number;
|
|
16
|
+
/** Cap for `count`; values above render as `${max}+`. Defaults to 99. */
|
|
17
|
+
max?: number;
|
|
18
|
+
/**
|
|
19
|
+
* When set, treats the badge as a live status region
|
|
20
|
+
* (`role="status"` + `aria-live="polite"`) so AT announces changes.
|
|
21
|
+
* Static category tags stay plain spans.
|
|
22
|
+
*/
|
|
23
|
+
live?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Accessible label. Required for dot-only / label-less badges so the
|
|
26
|
+
* status isn't conveyed by colour alone (WCAG 1.4.1). Also names the
|
|
27
|
+
* dismiss button's target.
|
|
28
|
+
*/
|
|
29
|
+
label?: string;
|
|
30
|
+
/** When provided, renders a trailing, keyboard-focusable dismiss button. */
|
|
31
|
+
ondismiss?: () => void;
|
|
32
|
+
/** Badge text. Optional: omit for a dot-only or count-only badge. */
|
|
33
|
+
children?: Snippet;
|
|
8
34
|
}
|
|
9
35
|
declare const Badge: import("svelte").Component<Props, {}, "">;
|
|
10
36
|
type Badge = ReturnType<typeof Badge>;
|