dssoca 0.8.2 → 0.10.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 +22 -6
- package/dist/components/Accordion.svelte.d.ts +5 -1
- package/dist/components/Avatar.svelte +119 -0
- package/dist/components/Avatar.svelte.d.ts +18 -0
- package/dist/components/Badge.svelte +3 -5
- package/dist/components/BottomNav.svelte +57 -19
- package/dist/components/BottomNav.svelte.d.ts +2 -0
- package/dist/components/Card.svelte +7 -1
- package/dist/components/Chart.svelte +527 -0
- package/dist/components/Chart.svelte.d.ts +42 -0
- package/dist/components/Container.svelte +55 -0
- package/dist/components/Container.svelte.d.ts +16 -0
- package/dist/components/DateField.svelte +188 -0
- package/dist/components/DateField.svelte.d.ts +37 -0
- package/dist/components/EmptyState.svelte +9 -3
- package/dist/components/EmptyState.svelte.d.ts +6 -0
- package/dist/components/FileDrop.svelte +355 -0
- package/dist/components/FileDrop.svelte.d.ts +24 -0
- package/dist/components/Heading.svelte +83 -0
- package/dist/components/Heading.svelte.d.ts +17 -0
- package/dist/components/Icon.svelte +32 -23
- package/dist/components/Icon.svelte.d.ts +7 -0
- package/dist/components/Image.svelte +19 -21
- package/dist/components/Input.svelte +2 -3
- package/dist/components/Link.svelte +42 -7
- package/dist/components/Link.svelte.d.ts +7 -0
- package/dist/components/LogStream.svelte +46 -31
- package/dist/components/Menu.svelte +59 -6
- package/dist/components/Menu.svelte.d.ts +22 -2
- package/dist/components/MetricTile.svelte +4 -4
- 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/SegmentedControl.svelte +16 -4
- package/dist/components/SegmentedControl.svelte.d.ts +7 -0
- package/dist/components/Select.svelte +224 -0
- package/dist/components/Select.svelte.d.ts +42 -0
- package/dist/components/ServiceCard.svelte +15 -15
- package/dist/components/Sidebar.svelte +47 -21
- package/dist/components/Sparkline.svelte +15 -13
- package/dist/components/Spinner.svelte +124 -0
- package/dist/components/Spinner.svelte.d.ts +74 -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/Textarea.svelte +214 -0
- package/dist/components/Textarea.svelte.d.ts +38 -0
- package/dist/components/Toaster.svelte +20 -4
- package/dist/components/Tooltip.svelte +162 -0
- package/dist/components/Tooltip.svelte.d.ts +17 -0
- package/dist/components/Topbar.svelte +170 -50
- package/dist/components/Topbar.svelte.d.ts +30 -3
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +15 -0
- package/dist/index.d.ts +19 -1
- package/dist/index.js +19 -1
- package/dist/theme.css +177 -37
- package/dist/toast.svelte.js +3 -3
- package/dist/tokens.css +597 -0
- package/package.json +33 -4
|
@@ -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,214 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
label?: string
|
|
6
|
+
id?: string
|
|
7
|
+
name?: string
|
|
8
|
+
value?: string
|
|
9
|
+
placeholder?: string
|
|
10
|
+
required?: boolean
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
oninput?: (e: Event & { currentTarget: HTMLTextAreaElement }) => void
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size
|
|
15
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
16
|
+
invalid?: boolean
|
|
17
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
18
|
+
describedby?: string
|
|
19
|
+
/** Supplementary helper text rendered under the textarea. */
|
|
20
|
+
hint?: string
|
|
21
|
+
/** Error text rendered under the textarea; its presence implies aria-invalid and is announced to AT. */
|
|
22
|
+
error?: string
|
|
23
|
+
/** Native readonly — value visible but not editable; rendered muted. */
|
|
24
|
+
readonly?: boolean
|
|
25
|
+
/** Native maxlength. */
|
|
26
|
+
maxlength?: number
|
|
27
|
+
/** Visible rows; acts as the minimum height (also while autosizing). */
|
|
28
|
+
rows?: number
|
|
29
|
+
/** Grow with content: `field-sizing: content` where supported, JS fallback elsewhere. */
|
|
30
|
+
autosize?: boolean
|
|
31
|
+
/** Row cap while autosizing — the field scrolls beyond it. */
|
|
32
|
+
maxRows?: number
|
|
33
|
+
/** Any remaining native textarea attributes / event handlers are forwarded. */
|
|
34
|
+
[key: string]: unknown
|
|
35
|
+
}
|
|
36
|
+
let {
|
|
37
|
+
label,
|
|
38
|
+
id,
|
|
39
|
+
name,
|
|
40
|
+
value = $bindable(''),
|
|
41
|
+
placeholder = '',
|
|
42
|
+
required = false,
|
|
43
|
+
disabled = false,
|
|
44
|
+
oninput,
|
|
45
|
+
size,
|
|
46
|
+
invalid,
|
|
47
|
+
describedby,
|
|
48
|
+
hint,
|
|
49
|
+
error,
|
|
50
|
+
readonly = false,
|
|
51
|
+
maxlength,
|
|
52
|
+
rows = 3,
|
|
53
|
+
autosize = false,
|
|
54
|
+
maxRows = 10,
|
|
55
|
+
...rest
|
|
56
|
+
}: Props = $props()
|
|
57
|
+
|
|
58
|
+
// Guarantee a label↔textarea association even when no `id` is passed.
|
|
59
|
+
const uid = $props.id()
|
|
60
|
+
const fieldId = $derived(id ?? uid)
|
|
61
|
+
const hintId = $derived(`${fieldId}-hint`)
|
|
62
|
+
const errorId = $derived(`${fieldId}-error`)
|
|
63
|
+
|
|
64
|
+
// error wins, then hint, then any caller-supplied describedby — order matters for AT.
|
|
65
|
+
const describedBy = $derived(
|
|
66
|
+
[error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
|
|
67
|
+
undefined,
|
|
68
|
+
)
|
|
69
|
+
const isInvalid = $derived(invalid || Boolean(error) || undefined)
|
|
70
|
+
// 'Textarea' is not in the ComponentName union yet (manifest is owned by the
|
|
71
|
+
// integration step) — cast until dssoca.config.ts registers it.
|
|
72
|
+
const resolvedSize = $derived(resolveComponentSize('Textarea', size))
|
|
73
|
+
|
|
74
|
+
// Autosize: prefer native `field-sizing: content` (see the scoped CSS); fall
|
|
75
|
+
// back to syncing the height to scrollHeight when the engine lacks it. The
|
|
76
|
+
// CSS max-height (from maxRows) clamps both paths.
|
|
77
|
+
let el = $state<HTMLTextAreaElement>()
|
|
78
|
+
const supportsFieldSizing =
|
|
79
|
+
typeof CSS !== 'undefined' &&
|
|
80
|
+
typeof CSS.supports === 'function' &&
|
|
81
|
+
CSS.supports('field-sizing', 'content')
|
|
82
|
+
|
|
83
|
+
$effect(() => {
|
|
84
|
+
void value // re-run on every value change (including programmatic ones)
|
|
85
|
+
if (!autosize || supportsFieldSizing || !el) return
|
|
86
|
+
el.style.height = 'auto'
|
|
87
|
+
el.style.height = `${el.scrollHeight}px`
|
|
88
|
+
})
|
|
89
|
+
</script>
|
|
90
|
+
|
|
91
|
+
<div class="ss-textarea" data-size-variant={resolvedSize} class:invalid={isInvalid} class:disabled>
|
|
92
|
+
{#if label}
|
|
93
|
+
<label class="lbl" for={fieldId}>
|
|
94
|
+
{label}
|
|
95
|
+
{#if required}<span class="req" aria-hidden="true">*</span>{/if}
|
|
96
|
+
</label>
|
|
97
|
+
{/if}
|
|
98
|
+
|
|
99
|
+
<div class="control">
|
|
100
|
+
<textarea
|
|
101
|
+
bind:this={el}
|
|
102
|
+
class="field"
|
|
103
|
+
class:autosize
|
|
104
|
+
id={fieldId}
|
|
105
|
+
{name}
|
|
106
|
+
bind:value
|
|
107
|
+
{placeholder}
|
|
108
|
+
{required}
|
|
109
|
+
{disabled}
|
|
110
|
+
{readonly}
|
|
111
|
+
{maxlength}
|
|
112
|
+
{rows}
|
|
113
|
+
aria-invalid={isInvalid}
|
|
114
|
+
aria-describedby={describedBy}
|
|
115
|
+
style:max-height={autosize && maxRows
|
|
116
|
+
? `calc(${maxRows} * 1lh + 2 * var(--ss-input-py))`
|
|
117
|
+
: undefined}
|
|
118
|
+
{oninput}
|
|
119
|
+
{...rest}
|
|
120
|
+
></textarea>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
{#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
|
|
124
|
+
{#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<style>.ss-textarea {
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
gap: 6px;
|
|
131
|
+
}
|
|
132
|
+
.ss-textarea .lbl {
|
|
133
|
+
font-family: var(--ss-font-mono);
|
|
134
|
+
font-size: var(--ss-ui-xs);
|
|
135
|
+
color: var(--ss-fg-muted);
|
|
136
|
+
text-transform: uppercase;
|
|
137
|
+
letter-spacing: 0.08em;
|
|
138
|
+
}
|
|
139
|
+
.ss-textarea .lbl .req {
|
|
140
|
+
color: var(--ss-red);
|
|
141
|
+
margin-left: 2px;
|
|
142
|
+
}
|
|
143
|
+
.ss-textarea .control {
|
|
144
|
+
display: flex;
|
|
145
|
+
align-items: stretch;
|
|
146
|
+
background: transparent;
|
|
147
|
+
color: var(--ss-fg);
|
|
148
|
+
border: 1px solid var(--ss-line);
|
|
149
|
+
padding: 0 var(--ss-input-px);
|
|
150
|
+
transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
|
|
151
|
+
}
|
|
152
|
+
.ss-textarea .control:focus-within {
|
|
153
|
+
border-color: var(--ss-primary);
|
|
154
|
+
box-shadow: 0 0 0 3px var(--ss-primary-soft);
|
|
155
|
+
}
|
|
156
|
+
.ss-textarea.invalid .control {
|
|
157
|
+
border-color: var(--ss-red);
|
|
158
|
+
}
|
|
159
|
+
.ss-textarea.invalid .control:focus-within {
|
|
160
|
+
border-color: var(--ss-red);
|
|
161
|
+
box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
|
|
162
|
+
}
|
|
163
|
+
.ss-textarea.disabled .control {
|
|
164
|
+
border-color: var(--ss-line);
|
|
165
|
+
}
|
|
166
|
+
.ss-textarea .field {
|
|
167
|
+
font-family: var(--ss-font-body);
|
|
168
|
+
font-size: var(--ss-input-font);
|
|
169
|
+
line-height: 1.5;
|
|
170
|
+
background: transparent;
|
|
171
|
+
color: var(--ss-fg);
|
|
172
|
+
border: none;
|
|
173
|
+
padding: var(--ss-input-py) 0;
|
|
174
|
+
width: 100%;
|
|
175
|
+
min-width: 0;
|
|
176
|
+
resize: vertical;
|
|
177
|
+
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
178
|
+
}
|
|
179
|
+
.ss-textarea .field:focus {
|
|
180
|
+
outline: none;
|
|
181
|
+
}
|
|
182
|
+
.ss-textarea .field::placeholder {
|
|
183
|
+
font-style: italic;
|
|
184
|
+
color: var(--ss-fg-faint);
|
|
185
|
+
}
|
|
186
|
+
.ss-textarea .field[readonly] {
|
|
187
|
+
color: var(--ss-fg-muted);
|
|
188
|
+
cursor: default;
|
|
189
|
+
}
|
|
190
|
+
.ss-textarea .field:disabled {
|
|
191
|
+
color: var(--ss-fg-faint);
|
|
192
|
+
cursor: not-allowed;
|
|
193
|
+
-webkit-text-fill-color: var(--ss-fg-faint);
|
|
194
|
+
}
|
|
195
|
+
.ss-textarea .field.autosize {
|
|
196
|
+
resize: none;
|
|
197
|
+
overflow-y: auto;
|
|
198
|
+
}
|
|
199
|
+
@supports (field-sizing: content) {
|
|
200
|
+
.ss-textarea .field.autosize {
|
|
201
|
+
field-sizing: content;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
.ss-textarea .msg {
|
|
205
|
+
font-family: var(--ss-font-mono);
|
|
206
|
+
font-size: var(--ss-ui-xs);
|
|
207
|
+
letter-spacing: 0.02em;
|
|
208
|
+
}
|
|
209
|
+
.ss-textarea .msg.hint {
|
|
210
|
+
color: var(--ss-fg-faint);
|
|
211
|
+
}
|
|
212
|
+
.ss-textarea .msg.error {
|
|
213
|
+
color: var(--ss-red);
|
|
214
|
+
}</style>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type Size } from '../config.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
label?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
value?: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
oninput?: (e: Event & {
|
|
11
|
+
currentTarget: HTMLTextAreaElement;
|
|
12
|
+
}) => void;
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size;
|
|
15
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
18
|
+
describedby?: string;
|
|
19
|
+
/** Supplementary helper text rendered under the textarea. */
|
|
20
|
+
hint?: string;
|
|
21
|
+
/** Error text rendered under the textarea; its presence implies aria-invalid and is announced to AT. */
|
|
22
|
+
error?: string;
|
|
23
|
+
/** Native readonly — value visible but not editable; rendered muted. */
|
|
24
|
+
readonly?: boolean;
|
|
25
|
+
/** Native maxlength. */
|
|
26
|
+
maxlength?: number;
|
|
27
|
+
/** Visible rows; acts as the minimum height (also while autosizing). */
|
|
28
|
+
rows?: number;
|
|
29
|
+
/** Grow with content: `field-sizing: content` where supported, JS fallback elsewhere. */
|
|
30
|
+
autosize?: boolean;
|
|
31
|
+
/** Row cap while autosizing — the field scrolls beyond it. */
|
|
32
|
+
maxRows?: number;
|
|
33
|
+
/** Any remaining native textarea attributes / event handlers are forwarded. */
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
declare const Textarea: import("svelte").Component<Props, {}, "value">;
|
|
37
|
+
type Textarea = ReturnType<typeof Textarea>;
|
|
38
|
+
export default Textarea;
|
|
@@ -24,7 +24,24 @@
|
|
|
24
24
|
const glyph: Record<ToastKind, string> = { success: '✓', error: '✕', info: 'i', loading: '' }
|
|
25
25
|
// Honor prefers-reduced-motion: collapse the fly transition to an instant swap.
|
|
26
26
|
const reduce = $derived(prefersReducedMotion.current)
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
// Fly duration reads the motion token (DS-0068) — the JS transition tracks
|
|
29
|
+
// `--ss-dur-fast` so theme/motion overrides apply, instead of a hardcoded
|
|
30
|
+
// 180ms. Falls back to 180ms (the previous value) when the stylesheet isn't
|
|
31
|
+
// present (e.g. jsdom, or the token entry not loaded).
|
|
32
|
+
let rootEl = $state<HTMLElement>()
|
|
33
|
+
function parseMs(raw: string): number | undefined {
|
|
34
|
+
const v = raw.trim()
|
|
35
|
+
if (!v) return undefined
|
|
36
|
+
const n = parseFloat(v)
|
|
37
|
+
if (!Number.isFinite(n) || n < 0) return undefined
|
|
38
|
+
return v.endsWith('ms') ? n : v.endsWith('s') ? n * 1000 : n
|
|
39
|
+
}
|
|
40
|
+
const tokenDuration = $derived.by(() => {
|
|
41
|
+
if (!rootEl || typeof getComputedStyle !== 'function') return 180
|
|
42
|
+
return parseMs(getComputedStyle(rootEl).getPropertyValue('--ss-dur-fast')) ?? 180
|
|
43
|
+
})
|
|
44
|
+
const flyDuration = $derived(reduce ? 0 : tokenDuration)
|
|
28
45
|
// Bottom anchors slide in from below; centered ones come straight down/up.
|
|
29
46
|
const flyX = $derived(position.endsWith('center') ? 0 : position.endsWith('left') ? -16 : 16)
|
|
30
47
|
const flyY = $derived(position.endsWith('center') ? (position.startsWith('top') ? -16 : 16) : 0)
|
|
@@ -84,6 +101,7 @@
|
|
|
84
101
|
aria-label="Notifications"
|
|
85
102
|
data-position={position}
|
|
86
103
|
data-size-variant={resolveComponentSize('Toaster', size)}
|
|
104
|
+
bind:this={rootEl}
|
|
87
105
|
>
|
|
88
106
|
{#each toasts.items as t (t.id)}
|
|
89
107
|
<div
|
|
@@ -93,9 +111,7 @@
|
|
|
93
111
|
aria-live={t.kind === 'error' ? 'assertive' : 'polite'}
|
|
94
112
|
tabindex="-1"
|
|
95
113
|
style:transform={dragId === t.id ? `translateX(${dragDx}px)` : undefined}
|
|
96
|
-
style:opacity={dragId === t.id
|
|
97
|
-
? Math.max(0.3, 1 - Math.abs(dragDx) / 200)
|
|
98
|
-
: undefined}
|
|
114
|
+
style:opacity={dragId === t.id ? Math.max(0.3, 1 - Math.abs(dragDx) / 200) : undefined}
|
|
99
115
|
transition:fly={{ x: flyX, y: flyY, duration: flyDuration }}
|
|
100
116
|
onpointerenter={() => toasts.pause(t.id)}
|
|
101
117
|
onpointerleave={() => dragId !== t.id && toasts.resume(t.id)}
|