dssoca 0.5.0 → 0.9.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 +39 -13
- package/dist/components/Accordion.svelte +297 -0
- package/dist/components/Accordion.svelte.d.ts +51 -0
- package/dist/components/Badge.svelte +113 -18
- package/dist/components/Badge.svelte.d.ts +28 -2
- package/dist/components/BottomNav.svelte +254 -0
- package/dist/components/BottomNav.svelte.d.ts +32 -0
- package/dist/components/Button.svelte +147 -10
- package/dist/components/Button.svelte.d.ts +21 -4
- package/dist/components/Card.svelte +173 -8
- package/dist/components/Card.svelte.d.ts +16 -1
- package/dist/components/Container.svelte +55 -0
- package/dist/components/Container.svelte.d.ts +16 -0
- package/dist/components/EmptyState.svelte +91 -9
- package/dist/components/EmptyState.svelte.d.ts +20 -3
- package/dist/components/Heading.svelte +83 -0
- package/dist/components/Heading.svelte.d.ts +17 -0
- package/dist/components/Icon.svelte +199 -24
- package/dist/components/Icon.svelte.d.ts +70 -2
- package/dist/components/Image.svelte +428 -0
- package/dist/components/Image.svelte.d.ts +49 -0
- package/dist/components/Input.svelte +173 -39
- package/dist/components/Input.svelte.d.ts +22 -0
- package/dist/components/Link.svelte +183 -0
- package/dist/components/Link.svelte.d.ts +29 -0
- package/dist/components/LogStream.svelte +403 -47
- package/dist/components/LogStream.svelte.d.ts +35 -7
- package/dist/components/Menu.svelte +408 -0
- package/dist/components/Menu.svelte.d.ts +66 -0
- package/dist/components/MetricTile.svelte +124 -12
- package/dist/components/MetricTile.svelte.d.ts +20 -0
- package/dist/components/SegmentedControl.svelte +220 -0
- package/dist/components/SegmentedControl.svelte.d.ts +37 -0
- package/dist/components/ServiceCard.svelte +226 -30
- package/dist/components/ServiceCard.svelte.d.ts +13 -1
- package/dist/components/Sidebar.svelte +377 -40
- package/dist/components/Sidebar.svelte.d.ts +18 -7
- package/dist/components/Sparkline.svelte +198 -13
- package/dist/components/Sparkline.svelte.d.ts +20 -1
- package/dist/components/Spinner.svelte +124 -0
- package/dist/components/Spinner.svelte.d.ts +74 -0
- package/dist/components/Textarea.svelte +214 -0
- package/dist/components/Textarea.svelte.d.ts +38 -0
- package/dist/components/Toaster.svelte +209 -12
- package/dist/components/Toaster.svelte.d.ts +3 -0
- package/dist/components/Topbar.svelte +293 -42
- package/dist/components/Topbar.svelte.d.ts +48 -1
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +10 -0
- package/dist/index.d.ts +16 -3
- package/dist/index.js +18 -2
- package/dist/theme.css +406 -24
- package/dist/toast.svelte.d.ts +49 -5
- package/dist/toast.svelte.js +165 -9
- package/dist/tokens.css +597 -0
- package/package.json +25 -4
package/README.md
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
A Svelte 5 design system — **signal green on near-black, monospace-forward, zero border-radius**
|
|
8
8
|
everywhere. Configured along two orthogonal axes:
|
|
9
9
|
|
|
10
|
-
| Axis
|
|
11
|
-
|
|
12
|
-
| **Color**
|
|
13
|
-
| **Size**
|
|
10
|
+
| Axis | Attribute | Values | Default |
|
|
11
|
+
| --------- | ------------------- | ------------------ | ------- |
|
|
12
|
+
| **Color** | `data-theme` | `dark` · `light` | `dark` |
|
|
13
|
+
| **Size** | `data-size-variant` | `sm` · `md` · `lg` | `md` |
|
|
14
14
|
|
|
15
15
|
Each component styles itself in a scoped block and consumes token-driven CSS custom properties;
|
|
16
16
|
flip an axis on any ancestor (usually `<html>`) and everything below rescales/recolors. Components
|
|
@@ -44,15 +44,23 @@ Import the stylesheet once (global tokens + base styles), then use components:
|
|
|
44
44
|
</Card>
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
+
Apps that own their global styles can import **tokens only** — every `--ss-*`
|
|
48
|
+
custom property (both themes, all size tiers, reduced-motion zeroing) with no
|
|
49
|
+
element styles and no webfont loading:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import 'dssoca/tokens.css'
|
|
53
|
+
```
|
|
54
|
+
|
|
47
55
|
### Configure the axes from code
|
|
48
56
|
|
|
49
57
|
```ts
|
|
50
58
|
import { applyDesignConfig, designAttributes } from 'dssoca'
|
|
51
59
|
|
|
52
60
|
// flip axes; merges over current config; writes to <html>
|
|
53
|
-
applyDesignConfig({ sizeVariant: 'sm' })
|
|
54
|
-
applyDesignConfig({ theme: 'light' })
|
|
55
|
-
applyDesignConfig({ componentsSize: { Button: 'lg' } })
|
|
61
|
+
applyDesignConfig({ sizeVariant: 'sm' }) // global: everything small
|
|
62
|
+
applyDesignConfig({ theme: 'light' }) // keeps size
|
|
63
|
+
applyDesignConfig({ componentsSize: { Button: 'lg' } }) // per-component default
|
|
56
64
|
```
|
|
57
65
|
|
|
58
66
|
Per instance, just set the `size` prop: `<Button size="lg">`.
|
|
@@ -69,15 +77,24 @@ SSR / no-flash — spread the attributes directly in markup instead of mutating
|
|
|
69
77
|
|
|
70
78
|
## What's in the box
|
|
71
79
|
|
|
72
|
-
**Components:** `Icon`, `Badge`, `Button`, `Input`, `Card`, `Sparkline`,
|
|
73
|
-
`ServiceCard`, `MetricTile`, `Topbar`, `Sidebar`, `
|
|
80
|
+
**Components (23):** `Icon`, `Badge`, `Button`, `Input`, `Textarea`, `Card`, `Sparkline`,
|
|
81
|
+
`ServiceCard`, `MetricTile`, `Topbar`, `Sidebar`, `BottomNav`, `Menu`, `Link`,
|
|
82
|
+
`SegmentedControl`, `Accordion`, `LogStream`, `Toaster`, `EmptyState`, `Image`,
|
|
83
|
+
`Heading`, `Container`, `Spinner`.
|
|
74
84
|
|
|
75
|
-
**Toasts:** `toast` (`.success` / `.error` / `.info`) + the `toasts`
|
|
76
|
-
|
|
85
|
+
**Toasts:** `toast` (`.success` / `.error` / `.info` / `.loading` / `.promise`) + the `toasts`
|
|
86
|
+
store (`update` / `dismiss` / `pause` / `resume` / `clear`, `max` cap) — render once with
|
|
87
|
+
`<Toaster />`. Types: `Toast`, `ToastKind`, `ToastAction`, `ToastOptions`, `ToastPatch`,
|
|
88
|
+
`PromiseMessages`.
|
|
77
89
|
|
|
78
90
|
**Config:** `dssocaConfig` (the manifest), `applyDesignConfig`, `designAttributes`,
|
|
79
91
|
`getDesignConfig`, `resolveComponentSize`, `defaultDesignConfig`, and the `ColorTheme` / `Size` /
|
|
80
|
-
`DesignConfig` / `ComponentsSize` types.
|
|
92
|
+
`DesignConfig` / `ComponentsSize` / `DesignAxis` / `ComponentName` / `DssocaConfig` types.
|
|
93
|
+
|
|
94
|
+
**Component types:** `IconName` (+ `registerIcon`), `TopbarTab`, `TopbarServices`, `SideItem` /
|
|
95
|
+
`SideGroup` / `SideStatus`, `LogLevel` / `LogLine`, `MenuItem`, `AccordionItem`,
|
|
96
|
+
`SegmentOption`, `BottomNavItem`, `ImageSource`, and `SpinnerVariant` / `SpinnerFrames`
|
|
97
|
+
(+ `SPINNER_VARIANTS` / `SPINNER_VARIANT_NAMES`).
|
|
81
98
|
|
|
82
99
|
## Accessibility
|
|
83
100
|
|
|
@@ -104,7 +121,16 @@ pnpm docs:dev # docs site (run `pnpm storybook` alongside for the live demo
|
|
|
104
121
|
pnpm docs:build # static build of the docs site
|
|
105
122
|
```
|
|
106
123
|
|
|
107
|
-
The docs app is
|
|
124
|
+
The docs app is **not** part of the published npm package.
|
|
125
|
+
|
|
126
|
+
### Deployment (maintainers)
|
|
127
|
+
|
|
128
|
+
The docs site and Storybook deploy to **Vercel as two projects** from this one repo; the
|
|
129
|
+
repo-root `vercel.json` branches its `buildCommand` on a `VERCEL_DEPLOY_TARGET=storybook` env
|
|
130
|
+
var. The per-component Storybook embeds on the deployed docs default to
|
|
131
|
+
`http://localhost:6006` — set **`VITE_STORYBOOK_URL`** (Vercel env var on the **docs**
|
|
132
|
+
project) to the deployed Storybook URL and redeploy, or the iframes stay blank. Full setup:
|
|
133
|
+
[`documentation/CLAUDE.md`](./documentation/CLAUDE.md) → _Deployment_.
|
|
108
134
|
|
|
109
135
|
## Develop
|
|
110
136
|
|
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
/**
|
|
49
|
+
* Base id used to namespace the generated header/panel ids. Defaults to a
|
|
50
|
+
* stable per-instance id from `$props.id()` so server- and client-rendered
|
|
51
|
+
* IDs match (SSR-safe, DS-0067).
|
|
52
|
+
*/
|
|
53
|
+
idBase?: string
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Stable instance id — consistent between server and client renders, unlike
|
|
57
|
+
// the previous Math.random() default (DS-0067).
|
|
58
|
+
const uid = $props.id()
|
|
59
|
+
|
|
60
|
+
let {
|
|
61
|
+
items,
|
|
62
|
+
panel,
|
|
63
|
+
header,
|
|
64
|
+
multiple = false,
|
|
65
|
+
value = $bindable(),
|
|
66
|
+
defaultValue,
|
|
67
|
+
onChange,
|
|
68
|
+
size,
|
|
69
|
+
headingLevel = 3,
|
|
70
|
+
idBase = `ss-acc-${uid}`,
|
|
71
|
+
}: Props = $props()
|
|
72
|
+
|
|
73
|
+
// --- open-state model ----------------------------------------------------
|
|
74
|
+
// Normalise whatever `value`/`defaultValue` shape we were handed into a Set.
|
|
75
|
+
function toSet(v: AccordionValue): Set<string> {
|
|
76
|
+
if (v == null) return new Set()
|
|
77
|
+
return new Set(Array.isArray(v) ? v : [v])
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Uncontrolled fallback store, seeded once from defaultValue. `untrack`
|
|
81
|
+
// marks the read as an intentional one-time snapshot (not a live binding),
|
|
82
|
+
// silencing the "referenced locally" reactivity warning.
|
|
83
|
+
let internal = $state<Set<string>>(untrack(() => toSet(defaultValue)))
|
|
84
|
+
|
|
85
|
+
// Controlled when the consumer passes `value` (incl. bound); else internal.
|
|
86
|
+
const controlled = $derived(value !== undefined)
|
|
87
|
+
const open = $derived(controlled ? toSet(value) : internal)
|
|
88
|
+
|
|
89
|
+
const isOpen = (item: AccordionItem): boolean => open.has(item.id)
|
|
90
|
+
|
|
91
|
+
/** Project a Set back to the public value shape for `value`/`onChange`. */
|
|
92
|
+
function project(next: Set<string>): AccordionValue {
|
|
93
|
+
if (multiple) return [...next]
|
|
94
|
+
return next.size ? [...next][0] : undefined
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function toggle(item: AccordionItem) {
|
|
98
|
+
if (item.disabled) return
|
|
99
|
+
const next = new Set(open)
|
|
100
|
+
if (next.has(item.id)) {
|
|
101
|
+
next.delete(item.id)
|
|
102
|
+
} else {
|
|
103
|
+
if (!multiple) next.clear() // single-open: opening one closes others
|
|
104
|
+
next.add(item.id)
|
|
105
|
+
}
|
|
106
|
+
if (controlled) {
|
|
107
|
+
value = project(next) // keep the bound value in sync
|
|
108
|
+
} else {
|
|
109
|
+
internal = next
|
|
110
|
+
}
|
|
111
|
+
onChange?.(project(next))
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// --- roving keyboard nav across headers (WAI-ARIA Accordion pattern) -----
|
|
115
|
+
let headerEls = $state<Array<HTMLButtonElement | null>>([])
|
|
116
|
+
|
|
117
|
+
function focusHeader(index: number) {
|
|
118
|
+
const n = items.length
|
|
119
|
+
if (n === 0) return
|
|
120
|
+
const i = ((index % n) + n) % n // wrap
|
|
121
|
+
headerEls[i]?.focus()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function onHeaderKeydown(e: KeyboardEvent, index: number) {
|
|
125
|
+
switch (e.key) {
|
|
126
|
+
case 'ArrowDown':
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
focusHeader(index + 1)
|
|
129
|
+
break
|
|
130
|
+
case 'ArrowUp':
|
|
131
|
+
e.preventDefault()
|
|
132
|
+
focusHeader(index - 1)
|
|
133
|
+
break
|
|
134
|
+
case 'Home':
|
|
135
|
+
e.preventDefault()
|
|
136
|
+
focusHeader(0)
|
|
137
|
+
break
|
|
138
|
+
case 'End':
|
|
139
|
+
e.preventDefault()
|
|
140
|
+
focusHeader(items.length - 1)
|
|
141
|
+
break
|
|
142
|
+
// Enter / Space activate the native <button>; no extra handling needed.
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const headerId = (item: AccordionItem) => `${idBase}-h-${item.id}`
|
|
147
|
+
const panelId = (item: AccordionItem) => `${idBase}-p-${item.id}`
|
|
148
|
+
</script>
|
|
149
|
+
|
|
150
|
+
<div class="ss-accordion" data-size-variant={resolveComponentSize('Accordion', size)}>
|
|
151
|
+
{#each items as item, i (item.id)}
|
|
152
|
+
{@const expanded = isOpen(item)}
|
|
153
|
+
<div class="item" class:open={expanded} class:disabled={item.disabled}>
|
|
154
|
+
<div role="heading" aria-level={headingLevel} class="heading">
|
|
155
|
+
<button
|
|
156
|
+
bind:this={headerEls[i]}
|
|
157
|
+
type="button"
|
|
158
|
+
class="head"
|
|
159
|
+
id={headerId(item)}
|
|
160
|
+
aria-expanded={expanded}
|
|
161
|
+
aria-controls={panelId(item)}
|
|
162
|
+
aria-disabled={item.disabled || undefined}
|
|
163
|
+
onclick={() => toggle(item)}
|
|
164
|
+
onkeydown={(e) => onHeaderKeydown(e, i)}
|
|
165
|
+
>
|
|
166
|
+
{#if header}
|
|
167
|
+
{@render header(item)}
|
|
168
|
+
{:else}
|
|
169
|
+
<span class="title">{item.label}</span>
|
|
170
|
+
{#if item.hint}<span class="hint">{item.hint}</span>{/if}
|
|
171
|
+
{/if}
|
|
172
|
+
<span class="chevron" aria-hidden="true"></span>
|
|
173
|
+
</button>
|
|
174
|
+
</div>
|
|
175
|
+
<div
|
|
176
|
+
class="panel"
|
|
177
|
+
id={panelId(item)}
|
|
178
|
+
role="region"
|
|
179
|
+
aria-labelledby={headerId(item)}
|
|
180
|
+
hidden={!expanded}
|
|
181
|
+
>
|
|
182
|
+
<div class="panel-inner">
|
|
183
|
+
{@render panel(item)}
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</div>
|
|
187
|
+
{/each}
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<style>.ss-accordion {
|
|
191
|
+
--ss-acc-head-py: var(--ss-row-py);
|
|
192
|
+
--ss-acc-head-px: var(--ss-row-px);
|
|
193
|
+
--ss-acc-body-py: var(--ss-s-3);
|
|
194
|
+
--ss-acc-body-px: var(--ss-row-px);
|
|
195
|
+
--ss-acc-chevron: 9px;
|
|
196
|
+
--ss-acc-gap: var(--ss-s-3);
|
|
197
|
+
}
|
|
198
|
+
.ss-accordion[data-size-variant=sm] {
|
|
199
|
+
--ss-acc-head-py: var(--ss-s-1);
|
|
200
|
+
--ss-acc-head-px: var(--ss-s-2);
|
|
201
|
+
--ss-acc-body-py: var(--ss-s-2);
|
|
202
|
+
--ss-acc-body-px: var(--ss-s-2);
|
|
203
|
+
--ss-acc-chevron: 7px;
|
|
204
|
+
--ss-acc-gap: var(--ss-s-2);
|
|
205
|
+
}
|
|
206
|
+
.ss-accordion[data-size-variant=lg] {
|
|
207
|
+
--ss-acc-head-py: var(--ss-s-3);
|
|
208
|
+
--ss-acc-head-px: var(--ss-s-4);
|
|
209
|
+
--ss-acc-body-py: var(--ss-s-4);
|
|
210
|
+
--ss-acc-body-px: var(--ss-s-4);
|
|
211
|
+
--ss-acc-chevron: 11px;
|
|
212
|
+
--ss-acc-gap: var(--ss-s-4);
|
|
213
|
+
}
|
|
214
|
+
.ss-accordion {
|
|
215
|
+
display: flex;
|
|
216
|
+
flex-direction: column;
|
|
217
|
+
border: 1px solid var(--ss-line);
|
|
218
|
+
background: var(--ss-bg);
|
|
219
|
+
}
|
|
220
|
+
.ss-accordion .item + .item {
|
|
221
|
+
border-top: 1px solid var(--ss-line);
|
|
222
|
+
}
|
|
223
|
+
.ss-accordion .heading {
|
|
224
|
+
margin: 0;
|
|
225
|
+
font: inherit;
|
|
226
|
+
}
|
|
227
|
+
.ss-accordion .head {
|
|
228
|
+
display: flex;
|
|
229
|
+
align-items: center;
|
|
230
|
+
gap: var(--ss-acc-gap);
|
|
231
|
+
width: 100%;
|
|
232
|
+
box-sizing: border-box;
|
|
233
|
+
padding: var(--ss-acc-head-py) var(--ss-acc-head-px);
|
|
234
|
+
background: none;
|
|
235
|
+
border: 0;
|
|
236
|
+
text-align: left;
|
|
237
|
+
cursor: pointer;
|
|
238
|
+
color: var(--ss-fg);
|
|
239
|
+
font: 500 var(--ss-ui-md) var(--ss-font-mono);
|
|
240
|
+
transition: background var(--ss-dur-fast) var(--ss-ease), color var(--ss-dur-fast) var(--ss-ease);
|
|
241
|
+
}
|
|
242
|
+
.ss-accordion .head:hover:not([aria-disabled=true]) {
|
|
243
|
+
background: var(--ss-hover);
|
|
244
|
+
}
|
|
245
|
+
.ss-accordion .head:focus-visible {
|
|
246
|
+
outline: 2px solid var(--ss-primary);
|
|
247
|
+
outline-offset: -2px;
|
|
248
|
+
}
|
|
249
|
+
.ss-accordion .head[aria-disabled=true] {
|
|
250
|
+
cursor: not-allowed;
|
|
251
|
+
color: var(--ss-fg-faint);
|
|
252
|
+
}
|
|
253
|
+
.ss-accordion .head .title {
|
|
254
|
+
flex: 1 1 auto;
|
|
255
|
+
min-width: 0;
|
|
256
|
+
}
|
|
257
|
+
.ss-accordion .head .hint {
|
|
258
|
+
flex: 0 0 auto;
|
|
259
|
+
color: var(--ss-fg-faint);
|
|
260
|
+
font-size: var(--ss-ui-sm);
|
|
261
|
+
}
|
|
262
|
+
.ss-accordion .head .chevron {
|
|
263
|
+
flex: 0 0 auto;
|
|
264
|
+
width: var(--ss-acc-chevron);
|
|
265
|
+
height: var(--ss-acc-chevron);
|
|
266
|
+
border-right: 1.5px solid currentColor;
|
|
267
|
+
border-bottom: 1.5px solid currentColor;
|
|
268
|
+
transform: rotate(45deg);
|
|
269
|
+
transform-origin: center;
|
|
270
|
+
transition: transform var(--ss-dur) var(--ss-ease);
|
|
271
|
+
color: var(--ss-fg-muted);
|
|
272
|
+
}
|
|
273
|
+
.ss-accordion .item.open .head .chevron {
|
|
274
|
+
transform: rotate(225deg);
|
|
275
|
+
}
|
|
276
|
+
.ss-accordion .panel {
|
|
277
|
+
display: grid;
|
|
278
|
+
grid-template-rows: 0fr;
|
|
279
|
+
transition: grid-template-rows var(--ss-dur) var(--ss-ease);
|
|
280
|
+
}
|
|
281
|
+
.ss-accordion .panel[hidden] {
|
|
282
|
+
display: grid;
|
|
283
|
+
grid-template-rows: 0fr;
|
|
284
|
+
}
|
|
285
|
+
.ss-accordion .panel:not([hidden]) {
|
|
286
|
+
grid-template-rows: 1fr;
|
|
287
|
+
}
|
|
288
|
+
.ss-accordion .panel-inner {
|
|
289
|
+
overflow: hidden;
|
|
290
|
+
min-height: 0;
|
|
291
|
+
}
|
|
292
|
+
.ss-accordion .panel:not([hidden]) .panel-inner {
|
|
293
|
+
padding: var(--ss-acc-body-py) var(--ss-acc-body-px);
|
|
294
|
+
color: var(--ss-fg-muted);
|
|
295
|
+
font-size: var(--ss-ui-md);
|
|
296
|
+
line-height: var(--ss-leading);
|
|
297
|
+
}</style>
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
/**
|
|
43
|
+
* Base id used to namespace the generated header/panel ids. Defaults to a
|
|
44
|
+
* stable per-instance id from `$props.id()` so server- and client-rendered
|
|
45
|
+
* IDs match (SSR-safe, DS-0067).
|
|
46
|
+
*/
|
|
47
|
+
idBase?: string;
|
|
48
|
+
}
|
|
49
|
+
declare const Accordion: import("svelte").Component<Props, {}, "value">;
|
|
50
|
+
type Accordion = ReturnType<typeof Accordion>;
|
|
51
|
+
export default Accordion;
|
|
@@ -2,20 +2,85 @@
|
|
|
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(count === undefined ? '' : count > max ? `${max}+` : `${count}`)
|
|
54
|
+
|
|
55
|
+
const hasLabel = $derived(children !== undefined)
|
|
56
|
+
// Dot-only / count-only badges have no visible text → carry an aria-label so
|
|
57
|
+
// the status isn't conveyed by colour alone (WCAG 1.4.1).
|
|
58
|
+
const ariaLabel = $derived(!hasLabel ? label : undefined)
|
|
59
|
+
// `live` wins (role=status). Otherwise a label-less badge needs a role for
|
|
60
|
+
// its aria-label to be valid (a bare span + aria-label is prohibited); use
|
|
61
|
+
// `img` so AT announces it as a single named status indicator.
|
|
62
|
+
const role = $derived(live ? 'status' : !hasLabel ? 'img' : undefined)
|
|
14
63
|
</script>
|
|
15
64
|
|
|
16
|
-
<span
|
|
17
|
-
|
|
18
|
-
{
|
|
65
|
+
<span
|
|
66
|
+
class="ss-badge {tone}"
|
|
67
|
+
class:label-less={!hasLabel}
|
|
68
|
+
data-size-variant={resolveComponentSize('Badge', size)}
|
|
69
|
+
{role}
|
|
70
|
+
aria-live={live ? 'polite' : undefined}
|
|
71
|
+
aria-label={ariaLabel}
|
|
72
|
+
>
|
|
73
|
+
{#if dot}<span class="dot" aria-hidden="true"></span>{/if}
|
|
74
|
+
{#if hasLabel}{@render children?.()}{/if}
|
|
75
|
+
{#if showCount}<span class="count">{countText}</span>{/if}
|
|
76
|
+
{#if ondismiss}
|
|
77
|
+
<button
|
|
78
|
+
class="x"
|
|
79
|
+
type="button"
|
|
80
|
+
aria-label={label ? `Remove ${label}` : 'Remove'}
|
|
81
|
+
onclick={ondismiss}>×</button
|
|
82
|
+
>
|
|
83
|
+
{/if}
|
|
19
84
|
</span>
|
|
20
85
|
|
|
21
86
|
<style>.ss-badge {
|
|
@@ -25,32 +90,62 @@
|
|
|
25
90
|
letter-spacing: 0.05em;
|
|
26
91
|
display: inline-flex;
|
|
27
92
|
align-items: center;
|
|
28
|
-
gap:
|
|
93
|
+
gap: var(--ss-badge-gap);
|
|
29
94
|
text-transform: lowercase;
|
|
30
95
|
border: 1px solid var(--ss-line);
|
|
31
96
|
}
|
|
32
97
|
.ss-badge.up {
|
|
33
|
-
background:
|
|
98
|
+
background: var(--ss-badge-up-bg);
|
|
34
99
|
color: var(--ss-primary);
|
|
35
|
-
border-color:
|
|
100
|
+
border-color: var(--ss-badge-up-border);
|
|
36
101
|
}
|
|
37
102
|
.ss-badge.deg {
|
|
38
|
-
background:
|
|
103
|
+
background: var(--ss-badge-deg-bg);
|
|
39
104
|
color: var(--ss-yellow);
|
|
40
|
-
border-color:
|
|
105
|
+
border-color: var(--ss-badge-deg-border);
|
|
41
106
|
}
|
|
42
107
|
.ss-badge.down {
|
|
43
|
-
background:
|
|
108
|
+
background: var(--ss-badge-down-bg);
|
|
44
109
|
color: var(--ss-red);
|
|
45
|
-
border-color:
|
|
110
|
+
border-color: var(--ss-badge-down-border);
|
|
111
|
+
}
|
|
112
|
+
.ss-badge.maint {
|
|
113
|
+
background: var(--ss-badge-maint-bg);
|
|
114
|
+
color: var(--ss-blue);
|
|
115
|
+
border-color: var(--ss-badge-maint-border);
|
|
46
116
|
}
|
|
47
117
|
.ss-badge.info {
|
|
48
|
-
background:
|
|
118
|
+
background: var(--ss-badge-info-bg);
|
|
49
119
|
color: var(--ss-cyan);
|
|
50
|
-
border-color:
|
|
120
|
+
border-color: var(--ss-badge-info-border);
|
|
121
|
+
}
|
|
122
|
+
.ss-badge.neutral {
|
|
123
|
+
background: var(--ss-badge-neutral-bg);
|
|
124
|
+
color: var(--ss-fg-muted);
|
|
125
|
+
border-color: var(--ss-badge-neutral-border);
|
|
51
126
|
}
|
|
52
127
|
.ss-badge .dot {
|
|
53
|
-
width:
|
|
54
|
-
height:
|
|
128
|
+
width: var(--ss-badge-dot);
|
|
129
|
+
height: var(--ss-badge-dot);
|
|
55
130
|
background: currentColor;
|
|
131
|
+
flex: none;
|
|
132
|
+
}
|
|
133
|
+
.ss-badge .count {
|
|
134
|
+
text-transform: none;
|
|
135
|
+
font-variant-numeric: tabular-nums;
|
|
136
|
+
}
|
|
137
|
+
.ss-badge .x {
|
|
138
|
+
flex: none;
|
|
139
|
+
background: none;
|
|
140
|
+
border: none;
|
|
141
|
+
color: currentColor;
|
|
142
|
+
cursor: pointer;
|
|
143
|
+
font-size: var(--ss-size-sm);
|
|
144
|
+
line-height: 1;
|
|
145
|
+
padding: 0;
|
|
146
|
+
margin-inline-start: calc(var(--ss-badge-gap) * -0.25);
|
|
147
|
+
opacity: 0.8;
|
|
148
|
+
}
|
|
149
|
+
.ss-badge .x:hover, .ss-badge .x:focus-visible {
|
|
150
|
+
opacity: 1;
|
|
56
151
|
}</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>;
|