dssoca 0.9.0 → 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/dist/components/Avatar.svelte +119 -0
- package/dist/components/Avatar.svelte.d.ts +18 -0
- package/dist/components/Chart.svelte +527 -0
- package/dist/components/Chart.svelte.d.ts +42 -0
- package/dist/components/DateField.svelte +188 -0
- package/dist/components/DateField.svelte.d.ts +37 -0
- package/dist/components/FileDrop.svelte +355 -0
- package/dist/components/FileDrop.svelte.d.ts +24 -0
- package/dist/components/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/Select.svelte +224 -0
- package/dist/components/Select.svelte.d.ts +42 -0
- package/dist/components/Switch.svelte +144 -0
- package/dist/components/Switch.svelte.d.ts +22 -0
- package/dist/components/Table.svelte +267 -0
- package/dist/components/Table.svelte.d.ts +52 -0
- package/dist/components/Tooltip.svelte +162 -0
- package/dist/components/Tooltip.svelte.d.ts +17 -0
- package/dist/dssoca.config.d.ts +1 -1
- package/dist/dssoca.config.js +11 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/package.json +9 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// Pagination — DS-0100. A windowed page navigator: a Prev button, a list of
|
|
4
|
+
// page-number buttons (first, last, and ±siblingCount around the current one,
|
|
5
|
+
// with `…` ellipses bridging the gaps), and a Next button. Bindable 1-based
|
|
6
|
+
// `page`, zero radius, mono numerals, `--ss-line` hairlines, size-token
|
|
7
|
+
// density. The current page is `aria-current="page"`, visually active and
|
|
8
|
+
// inert (re-clicking it never re-fires). WCAG 2.2 AA.
|
|
9
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** Current page, 1-based (bindable). */
|
|
14
|
+
page?: number
|
|
15
|
+
/** Total item count — used with `pageSize` to derive the page count. */
|
|
16
|
+
total?: number
|
|
17
|
+
/** Explicit page count; overrides the `total`/`pageSize` computation. */
|
|
18
|
+
pageCount?: number
|
|
19
|
+
/** Items per page when deriving the count from `total`. Default 10. */
|
|
20
|
+
pageSize?: number
|
|
21
|
+
/** Page-number buttons to show on each side of the current page. Default 1. */
|
|
22
|
+
siblingCount?: number
|
|
23
|
+
/** Disable the whole control: every button is inert. */
|
|
24
|
+
disabled?: boolean
|
|
25
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
26
|
+
size?: Size
|
|
27
|
+
/** Fired when the page changes (after `page` updates). */
|
|
28
|
+
onchange?: (page: number) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
page = $bindable(1),
|
|
33
|
+
total,
|
|
34
|
+
pageCount,
|
|
35
|
+
pageSize = 10,
|
|
36
|
+
siblingCount = 1,
|
|
37
|
+
disabled = false,
|
|
38
|
+
size,
|
|
39
|
+
onchange,
|
|
40
|
+
}: Props = $props()
|
|
41
|
+
|
|
42
|
+
// Total number of pages — explicit `pageCount` wins, else derived from the
|
|
43
|
+
// item count. Always at least 1 so the control never renders empty.
|
|
44
|
+
const pages = $derived(pageCount ?? Math.max(1, Math.ceil((total ?? 0) / pageSize)))
|
|
45
|
+
|
|
46
|
+
// Clamp the active page into [1, pages] for all rendering/decisions.
|
|
47
|
+
const current = $derived(Math.min(Math.max(1, page), pages))
|
|
48
|
+
|
|
49
|
+
type Slot = number | 'gap-start' | 'gap-end'
|
|
50
|
+
|
|
51
|
+
// Windowed list of slots: first page, last page, the sibling window around
|
|
52
|
+
// the current page, and an ellipsis marker wherever a run of pages is hidden.
|
|
53
|
+
const slots = $derived.by<Slot[]>(() => {
|
|
54
|
+
const start = Math.max(2, current - siblingCount)
|
|
55
|
+
const end = Math.min(pages - 1, current + siblingCount)
|
|
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
|
+
})
|
|
67
|
+
|
|
68
|
+
const atFirst = $derived(current <= 1)
|
|
69
|
+
const atLast = $derived(current >= pages)
|
|
70
|
+
|
|
71
|
+
function go(target: number) {
|
|
72
|
+
const next = Math.min(Math.max(1, target), pages)
|
|
73
|
+
if (disabled || next === current) return
|
|
74
|
+
page = next
|
|
75
|
+
onchange?.(next)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const sizeAttr = $derived(resolveComponentSize('Pagination', size))
|
|
79
|
+
</script>
|
|
80
|
+
|
|
81
|
+
<nav
|
|
82
|
+
class="ss-pagination"
|
|
83
|
+
aria-label="Pagination"
|
|
84
|
+
data-size-variant={sizeAttr}
|
|
85
|
+
data-disabled={disabled ? 'true' : undefined}
|
|
86
|
+
>
|
|
87
|
+
<button
|
|
88
|
+
type="button"
|
|
89
|
+
class="page nav-btn"
|
|
90
|
+
aria-label="Previous page"
|
|
91
|
+
disabled={disabled || atFirst}
|
|
92
|
+
onclick={() => go(current - 1)}
|
|
93
|
+
>
|
|
94
|
+
<span aria-hidden="true">‹</span>
|
|
95
|
+
</button>
|
|
96
|
+
|
|
97
|
+
{#each slots as slot (slot)}
|
|
98
|
+
{#if slot === 'gap-start' || slot === 'gap-end'}
|
|
99
|
+
<span class="ellipsis" aria-hidden="true">…</span>
|
|
100
|
+
{:else}
|
|
101
|
+
{@const isCurrent = slot === current}
|
|
102
|
+
<button
|
|
103
|
+
type="button"
|
|
104
|
+
class="page"
|
|
105
|
+
class:active={isCurrent}
|
|
106
|
+
aria-current={isCurrent ? 'page' : undefined}
|
|
107
|
+
aria-label={`Page ${slot}`}
|
|
108
|
+
{disabled}
|
|
109
|
+
onclick={() => go(slot)}
|
|
110
|
+
>
|
|
111
|
+
{slot}
|
|
112
|
+
</button>
|
|
113
|
+
{/if}
|
|
114
|
+
{/each}
|
|
115
|
+
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
class="page nav-btn"
|
|
119
|
+
aria-label="Next page"
|
|
120
|
+
disabled={disabled || atLast}
|
|
121
|
+
onclick={() => go(current + 1)}
|
|
122
|
+
>
|
|
123
|
+
<span aria-hidden="true">›</span>
|
|
124
|
+
</button>
|
|
125
|
+
</nav>
|
|
126
|
+
|
|
127
|
+
<style>.ss-pagination {
|
|
128
|
+
display: inline-flex;
|
|
129
|
+
align-items: center;
|
|
130
|
+
gap: 0;
|
|
131
|
+
border: 1px solid var(--ss-line);
|
|
132
|
+
background: var(--ss-bg);
|
|
133
|
+
width: max-content;
|
|
134
|
+
max-width: 100%;
|
|
135
|
+
}
|
|
136
|
+
.ss-pagination .page {
|
|
137
|
+
display: inline-flex;
|
|
138
|
+
align-items: center;
|
|
139
|
+
justify-content: center;
|
|
140
|
+
min-width: var(--ss-pagination-min, 2.25em);
|
|
141
|
+
font: 500 var(--ss-pagination-font, 0.875rem)/1 var(--ss-font-mono);
|
|
142
|
+
color: var(--ss-fg-muted);
|
|
143
|
+
background: transparent;
|
|
144
|
+
border: 0;
|
|
145
|
+
border-left: 1px solid var(--ss-line);
|
|
146
|
+
padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
|
|
147
|
+
cursor: pointer;
|
|
148
|
+
white-space: nowrap;
|
|
149
|
+
transition: color var(--ss-dur-fast) var(--ss-ease), background var(--ss-dur-fast) var(--ss-ease);
|
|
150
|
+
}
|
|
151
|
+
.ss-pagination .page:first-child {
|
|
152
|
+
border-left: 0;
|
|
153
|
+
}
|
|
154
|
+
.ss-pagination .page:hover:not(.active):not(:disabled) {
|
|
155
|
+
color: var(--ss-fg);
|
|
156
|
+
background: var(--ss-hover);
|
|
157
|
+
}
|
|
158
|
+
.ss-pagination .page.active {
|
|
159
|
+
color: var(--ss-fg-on-primary);
|
|
160
|
+
background: var(--ss-primary);
|
|
161
|
+
cursor: default;
|
|
162
|
+
}
|
|
163
|
+
.ss-pagination .page:focus-visible {
|
|
164
|
+
outline: none;
|
|
165
|
+
box-shadow: inset 0 0 0 2px var(--ss-primary-soft);
|
|
166
|
+
z-index: 1;
|
|
167
|
+
}
|
|
168
|
+
.ss-pagination .page.active:focus-visible {
|
|
169
|
+
box-shadow: inset 0 0 0 2px var(--ss-bg);
|
|
170
|
+
}
|
|
171
|
+
.ss-pagination .page:disabled {
|
|
172
|
+
cursor: not-allowed;
|
|
173
|
+
opacity: 0.45;
|
|
174
|
+
}
|
|
175
|
+
.ss-pagination .page.active:disabled {
|
|
176
|
+
opacity: 1;
|
|
177
|
+
cursor: default;
|
|
178
|
+
}
|
|
179
|
+
.ss-pagination .nav-btn {
|
|
180
|
+
font-size: var(--ss-pagination-nav-font, 1rem);
|
|
181
|
+
}
|
|
182
|
+
.ss-pagination .ellipsis {
|
|
183
|
+
display: inline-flex;
|
|
184
|
+
align-items: center;
|
|
185
|
+
justify-content: center;
|
|
186
|
+
min-width: var(--ss-pagination-min, 2.25em);
|
|
187
|
+
padding: var(--ss-pagination-py, 0.5em) var(--ss-pagination-px, 0.625em);
|
|
188
|
+
border-left: 1px solid var(--ss-line);
|
|
189
|
+
color: var(--ss-fg-muted);
|
|
190
|
+
font-family: var(--ss-font-mono);
|
|
191
|
+
line-height: 1;
|
|
192
|
+
user-select: none;
|
|
193
|
+
}</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Size } from '../config.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** Current page, 1-based (bindable). */
|
|
4
|
+
page?: number;
|
|
5
|
+
/** Total item count — used with `pageSize` to derive the page count. */
|
|
6
|
+
total?: number;
|
|
7
|
+
/** Explicit page count; overrides the `total`/`pageSize` computation. */
|
|
8
|
+
pageCount?: number;
|
|
9
|
+
/** Items per page when deriving the count from `total`. Default 10. */
|
|
10
|
+
pageSize?: number;
|
|
11
|
+
/** Page-number buttons to show on each side of the current page. Default 1. */
|
|
12
|
+
siblingCount?: number;
|
|
13
|
+
/** Disable the whole control: every button is inert. */
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
16
|
+
size?: Size;
|
|
17
|
+
/** Fired when the page changes (after `page` updates). */
|
|
18
|
+
onchange?: (page: number) => void;
|
|
19
|
+
}
|
|
20
|
+
declare const Pagination: import("svelte").Component<Props, {}, "page">;
|
|
21
|
+
type Pagination = ReturnType<typeof Pagination>;
|
|
22
|
+
export default Pagination;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
/** A single selectable option. */
|
|
3
|
+
export interface SelectOption {
|
|
4
|
+
value: string
|
|
5
|
+
label: string
|
|
6
|
+
disabled?: boolean
|
|
7
|
+
}
|
|
8
|
+
/** A labelled group of options, rendered as an <optgroup>. */
|
|
9
|
+
export interface SelectOptGroup {
|
|
10
|
+
label: string
|
|
11
|
+
options: SelectOption[]
|
|
12
|
+
}
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import type { HTMLSelectAttributes } from 'svelte/elements'
|
|
17
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
label?: string
|
|
21
|
+
id?: string
|
|
22
|
+
name?: string
|
|
23
|
+
value?: string
|
|
24
|
+
/** Flat options, or grouped options (detected by an `options` array on the first element). */
|
|
25
|
+
options?: SelectOption[] | SelectOptGroup[]
|
|
26
|
+
/** Renders a disabled, hidden first option, selected while the value is empty. */
|
|
27
|
+
placeholder?: string
|
|
28
|
+
required?: boolean
|
|
29
|
+
disabled?: boolean
|
|
30
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
31
|
+
size?: Size
|
|
32
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
33
|
+
invalid?: boolean
|
|
34
|
+
/** Supplementary helper text rendered under the select. */
|
|
35
|
+
hint?: string
|
|
36
|
+
/** Error text rendered under the select; its presence implies aria-invalid and is announced. */
|
|
37
|
+
error?: string
|
|
38
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
39
|
+
describedby?: string
|
|
40
|
+
onchange?: (e: Event & { currentTarget: HTMLSelectElement }) => void
|
|
41
|
+
/** Any remaining native select attributes / event handlers are forwarded. */
|
|
42
|
+
[key: string]: unknown
|
|
43
|
+
}
|
|
44
|
+
let {
|
|
45
|
+
label,
|
|
46
|
+
id,
|
|
47
|
+
name,
|
|
48
|
+
value = $bindable(''),
|
|
49
|
+
options = [],
|
|
50
|
+
placeholder,
|
|
51
|
+
required = false,
|
|
52
|
+
disabled = false,
|
|
53
|
+
size,
|
|
54
|
+
invalid,
|
|
55
|
+
hint,
|
|
56
|
+
error,
|
|
57
|
+
describedby,
|
|
58
|
+
onchange,
|
|
59
|
+
...rest
|
|
60
|
+
}: Props = $props()
|
|
61
|
+
|
|
62
|
+
// Guarantee a label↔select association even when no `id` is passed.
|
|
63
|
+
const uid = $props.id()
|
|
64
|
+
const selectId = $derived(id ?? uid)
|
|
65
|
+
const hintId = $derived(`${selectId}-hint`)
|
|
66
|
+
const errorId = $derived(`${selectId}-error`)
|
|
67
|
+
|
|
68
|
+
// error wins, then hint, then any caller-supplied describedby — order matters for AT.
|
|
69
|
+
const describedBy = $derived(
|
|
70
|
+
[error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
|
|
71
|
+
undefined,
|
|
72
|
+
)
|
|
73
|
+
const isInvalid = $derived(invalid || Boolean(error) || undefined)
|
|
74
|
+
const resolvedSize = $derived(resolveComponentSize('Select', size))
|
|
75
|
+
|
|
76
|
+
// Grouped input is detected by an `options` array on the first element.
|
|
77
|
+
const grouped = $derived(
|
|
78
|
+
options.length > 0 && Array.isArray((options[0] as SelectOptGroup).options),
|
|
79
|
+
)
|
|
80
|
+
const groups = $derived(grouped ? (options as SelectOptGroup[]) : [])
|
|
81
|
+
const flat = $derived(grouped ? [] : (options as SelectOption[]))
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<div class="ss-select" data-size-variant={resolvedSize} class:invalid={isInvalid} class:disabled>
|
|
85
|
+
{#if label}
|
|
86
|
+
<label class="lbl" for={selectId}>
|
|
87
|
+
{label}
|
|
88
|
+
{#if required}<span class="req" aria-hidden="true">*</span>{/if}
|
|
89
|
+
</label>
|
|
90
|
+
{/if}
|
|
91
|
+
|
|
92
|
+
<div class="control">
|
|
93
|
+
<select
|
|
94
|
+
class="select"
|
|
95
|
+
id={selectId}
|
|
96
|
+
{name}
|
|
97
|
+
bind:value
|
|
98
|
+
{required}
|
|
99
|
+
{disabled}
|
|
100
|
+
aria-invalid={isInvalid}
|
|
101
|
+
aria-describedby={describedBy}
|
|
102
|
+
{onchange}
|
|
103
|
+
{...rest}
|
|
104
|
+
>
|
|
105
|
+
{#if placeholder}
|
|
106
|
+
<option value="" disabled hidden selected={!value}>{placeholder}</option>
|
|
107
|
+
{/if}
|
|
108
|
+
{#if grouped}
|
|
109
|
+
{#each groups as group (group.label)}
|
|
110
|
+
<optgroup label={group.label}>
|
|
111
|
+
{#each group.options as opt (opt.value)}
|
|
112
|
+
<option value={opt.value} disabled={opt.disabled}>{opt.label}</option>
|
|
113
|
+
{/each}
|
|
114
|
+
</optgroup>
|
|
115
|
+
{/each}
|
|
116
|
+
{:else}
|
|
117
|
+
{#each flat as opt (opt.value)}
|
|
118
|
+
<option value={opt.value} disabled={opt.disabled}>{opt.label}</option>
|
|
119
|
+
{/each}
|
|
120
|
+
{/if}
|
|
121
|
+
</select>
|
|
122
|
+
<span class="chevron" aria-hidden="true"></span>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
{#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
|
|
126
|
+
{#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<style>.ss-select {
|
|
130
|
+
display: flex;
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
gap: 6px;
|
|
133
|
+
}
|
|
134
|
+
.ss-select .lbl {
|
|
135
|
+
font-family: var(--ss-font-mono);
|
|
136
|
+
font-size: var(--ss-ui-xs);
|
|
137
|
+
color: var(--ss-fg-muted);
|
|
138
|
+
text-transform: uppercase;
|
|
139
|
+
letter-spacing: 0.08em;
|
|
140
|
+
}
|
|
141
|
+
.ss-select .lbl .req {
|
|
142
|
+
color: var(--ss-red);
|
|
143
|
+
margin-left: 2px;
|
|
144
|
+
}
|
|
145
|
+
.ss-select .control {
|
|
146
|
+
position: relative;
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
background: transparent;
|
|
150
|
+
color: var(--ss-fg);
|
|
151
|
+
border: 1px solid var(--ss-line);
|
|
152
|
+
padding: 0 var(--ss-input-px);
|
|
153
|
+
transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
|
|
154
|
+
}
|
|
155
|
+
.ss-select .control:focus-within {
|
|
156
|
+
border-color: var(--ss-primary);
|
|
157
|
+
box-shadow: 0 0 0 3px var(--ss-primary-soft);
|
|
158
|
+
}
|
|
159
|
+
.ss-select.invalid .control {
|
|
160
|
+
border-color: var(--ss-red);
|
|
161
|
+
}
|
|
162
|
+
.ss-select.invalid .control:focus-within {
|
|
163
|
+
border-color: var(--ss-red);
|
|
164
|
+
box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
|
|
165
|
+
}
|
|
166
|
+
.ss-select.disabled .control {
|
|
167
|
+
border-color: var(--ss-line);
|
|
168
|
+
}
|
|
169
|
+
.ss-select .chevron {
|
|
170
|
+
flex: none;
|
|
171
|
+
pointer-events: none;
|
|
172
|
+
width: 0;
|
|
173
|
+
height: 0;
|
|
174
|
+
margin-left: var(--ss-gap-sm);
|
|
175
|
+
border-left: var(--ss-select-chevron, 5px) solid transparent;
|
|
176
|
+
border-right: var(--ss-select-chevron, 5px) solid transparent;
|
|
177
|
+
border-top: var(--ss-select-chevron, 5px) solid var(--ss-fg-muted);
|
|
178
|
+
transition: border-top-color var(--ss-dur-fast) var(--ss-ease);
|
|
179
|
+
}
|
|
180
|
+
.ss-select:not(.disabled) .control:focus-within .chevron {
|
|
181
|
+
border-top-color: var(--ss-fg);
|
|
182
|
+
}
|
|
183
|
+
.ss-select.disabled .chevron {
|
|
184
|
+
border-top-color: var(--ss-fg-faint);
|
|
185
|
+
}
|
|
186
|
+
.ss-select .msg {
|
|
187
|
+
font-family: var(--ss-font-mono);
|
|
188
|
+
font-size: var(--ss-ui-xs);
|
|
189
|
+
letter-spacing: 0.02em;
|
|
190
|
+
}
|
|
191
|
+
.ss-select .msg.hint {
|
|
192
|
+
color: var(--ss-fg-faint);
|
|
193
|
+
}
|
|
194
|
+
.ss-select .msg.error {
|
|
195
|
+
color: var(--ss-red);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.select {
|
|
199
|
+
appearance: none;
|
|
200
|
+
-webkit-appearance: none;
|
|
201
|
+
font-family: var(--ss-font-body);
|
|
202
|
+
font-size: var(--ss-input-font);
|
|
203
|
+
background: transparent;
|
|
204
|
+
color: var(--ss-fg);
|
|
205
|
+
border: none;
|
|
206
|
+
padding: var(--ss-input-py) 0;
|
|
207
|
+
width: 100%;
|
|
208
|
+
min-width: 0;
|
|
209
|
+
cursor: pointer;
|
|
210
|
+
transition: color var(--ss-dur-fast) var(--ss-ease);
|
|
211
|
+
}
|
|
212
|
+
.select:focus {
|
|
213
|
+
outline: none;
|
|
214
|
+
}
|
|
215
|
+
.select:disabled {
|
|
216
|
+
color: var(--ss-fg-faint);
|
|
217
|
+
cursor: not-allowed;
|
|
218
|
+
-webkit-text-fill-color: var(--ss-fg-faint);
|
|
219
|
+
}
|
|
220
|
+
.select option,
|
|
221
|
+
.select optgroup {
|
|
222
|
+
background: var(--ss-bg-elev);
|
|
223
|
+
color: var(--ss-fg);
|
|
224
|
+
}</style>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** A single selectable option. */
|
|
2
|
+
export interface SelectOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** A labelled group of options, rendered as an <optgroup>. */
|
|
8
|
+
export interface SelectOptGroup {
|
|
9
|
+
label: string;
|
|
10
|
+
options: SelectOption[];
|
|
11
|
+
}
|
|
12
|
+
import { type Size } from '../config.js';
|
|
13
|
+
interface Props {
|
|
14
|
+
label?: string;
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
value?: string;
|
|
18
|
+
/** Flat options, or grouped options (detected by an `options` array on the first element). */
|
|
19
|
+
options?: SelectOption[] | SelectOptGroup[];
|
|
20
|
+
/** Renders a disabled, hidden first option, selected while the value is empty. */
|
|
21
|
+
placeholder?: string;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
25
|
+
size?: Size;
|
|
26
|
+
/** Marks the field invalid for assistive tech (aria-invalid). */
|
|
27
|
+
invalid?: boolean;
|
|
28
|
+
/** Supplementary helper text rendered under the select. */
|
|
29
|
+
hint?: string;
|
|
30
|
+
/** Error text rendered under the select; its presence implies aria-invalid and is announced. */
|
|
31
|
+
error?: string;
|
|
32
|
+
/** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
|
|
33
|
+
describedby?: string;
|
|
34
|
+
onchange?: (e: Event & {
|
|
35
|
+
currentTarget: HTMLSelectElement;
|
|
36
|
+
}) => void;
|
|
37
|
+
/** Any remaining native select attributes / event handlers are forwarded. */
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
}
|
|
40
|
+
declare const Select: import("svelte").Component<Props, {}, "value">;
|
|
41
|
+
type Select = ReturnType<typeof Select>;
|
|
42
|
+
export default Select;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
3
|
+
// Switch — DS-0101. An accessible on/off toggle built on a native
|
|
4
|
+
// `<button role="switch">`, so Space and Enter toggle for free. House rule:
|
|
5
|
+
// zero border-radius (square track AND square thumb — no rounded pill). The
|
|
6
|
+
// thumb slides on the inline axis between the two ends of the track; the
|
|
7
|
+
// track fills with --ss-primary when on. Bindable `checked`, optional adjacent
|
|
8
|
+
// `label` (clicking it toggles too), size-token density.
|
|
9
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
10
|
+
import { resolveComponentSize, type Size } from '../config.js'
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
/** On/off state (bindable). */
|
|
14
|
+
checked?: boolean
|
|
15
|
+
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
16
|
+
label?: string
|
|
17
|
+
/** Id for the underlying button (label `for`-style association uses it). */
|
|
18
|
+
id?: string
|
|
19
|
+
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
20
|
+
name?: string
|
|
21
|
+
/** Disable the switch: inert + non-toggling. */
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
24
|
+
size?: Size
|
|
25
|
+
/** Id of an element that further describes the switch (→ aria-describedby). */
|
|
26
|
+
describedby?: string
|
|
27
|
+
/** Fired after `checked` flips, with the new value. */
|
|
28
|
+
onchange?: (checked: boolean) => void
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
checked = $bindable(false),
|
|
33
|
+
label,
|
|
34
|
+
id,
|
|
35
|
+
name,
|
|
36
|
+
disabled = false,
|
|
37
|
+
size,
|
|
38
|
+
describedby,
|
|
39
|
+
onchange,
|
|
40
|
+
}: Props = $props()
|
|
41
|
+
|
|
42
|
+
// Stable per-instance id so the visible label can be wired to the button as
|
|
43
|
+
// its accessible name (aria-labelledby). Falls back to `$props.id()` when no
|
|
44
|
+
// explicit `id` is supplied (SSR-stable, replaces a random default).
|
|
45
|
+
const uid = $props.id()
|
|
46
|
+
const buttonId = $derived(id ?? uid)
|
|
47
|
+
const labelId = $derived(`${buttonId}-label`)
|
|
48
|
+
|
|
49
|
+
function toggle() {
|
|
50
|
+
if (disabled) return
|
|
51
|
+
checked = !checked
|
|
52
|
+
onchange?.(checked)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const sizeAttr = $derived(resolveComponentSize('Switch', size))
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<span class="ss-switch" class:has-label={label != null} data-size-variant={sizeAttr}>
|
|
59
|
+
<button
|
|
60
|
+
id={buttonId}
|
|
61
|
+
type="button"
|
|
62
|
+
role="switch"
|
|
63
|
+
class="track"
|
|
64
|
+
class:on={checked}
|
|
65
|
+
aria-checked={checked}
|
|
66
|
+
aria-labelledby={label != null ? labelId : undefined}
|
|
67
|
+
aria-describedby={describedby}
|
|
68
|
+
data-name={name}
|
|
69
|
+
{disabled}
|
|
70
|
+
onclick={toggle}
|
|
71
|
+
>
|
|
72
|
+
<span class="thumb" aria-hidden="true"></span>
|
|
73
|
+
</button>
|
|
74
|
+
{#if label != null}
|
|
75
|
+
<!-- Clicking the label toggles the switch (a11y: same target as the control). -->
|
|
76
|
+
<span id={labelId} class="label" onclick={toggle} role="presentation">{label}</span>
|
|
77
|
+
{/if}
|
|
78
|
+
</span>
|
|
79
|
+
|
|
80
|
+
<style>.ss-switch {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
gap: var(--ss-switch-gap, var(--ss-gap-sm));
|
|
84
|
+
}
|
|
85
|
+
.ss-switch .track {
|
|
86
|
+
position: relative;
|
|
87
|
+
flex: 0 0 auto;
|
|
88
|
+
display: inline-block;
|
|
89
|
+
width: var(--ss-switch-w, 2.25rem);
|
|
90
|
+
height: var(--ss-switch-h, 1.25rem);
|
|
91
|
+
padding: var(--ss-switch-pad, 2px);
|
|
92
|
+
border-radius: 0;
|
|
93
|
+
border: 1px solid var(--ss-line);
|
|
94
|
+
background: var(--ss-bg-elev);
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
transition: background var(--ss-dur-fast) var(--ss-ease), border-color var(--ss-dur-fast) var(--ss-ease);
|
|
98
|
+
}
|
|
99
|
+
.ss-switch .track .thumb {
|
|
100
|
+
position: absolute;
|
|
101
|
+
top: var(--ss-switch-pad, 2px);
|
|
102
|
+
left: var(--ss-switch-pad, 2px);
|
|
103
|
+
width: var(--ss-switch-thumb, 1rem);
|
|
104
|
+
height: var(--ss-switch-thumb, 1rem);
|
|
105
|
+
border-radius: 0;
|
|
106
|
+
background: var(--ss-fg);
|
|
107
|
+
transition: transform var(--ss-dur-fast) var(--ss-ease);
|
|
108
|
+
}
|
|
109
|
+
.ss-switch .track.on {
|
|
110
|
+
background: var(--ss-primary);
|
|
111
|
+
border-color: var(--ss-primary);
|
|
112
|
+
}
|
|
113
|
+
.ss-switch .track.on .thumb {
|
|
114
|
+
background: var(--ss-bg);
|
|
115
|
+
transform: translateX(calc(var(--ss-switch-w, 2.25rem) - var(--ss-switch-thumb, 1rem) - 2 * var(--ss-switch-pad, 2px) - 2px));
|
|
116
|
+
}
|
|
117
|
+
.ss-switch .track:not(:disabled):hover {
|
|
118
|
+
border-color: var(--ss-line-strong);
|
|
119
|
+
}
|
|
120
|
+
.ss-switch .track:focus-visible {
|
|
121
|
+
outline: none;
|
|
122
|
+
box-shadow: 0 0 0 2px var(--ss-primary-soft);
|
|
123
|
+
}
|
|
124
|
+
.ss-switch .track:disabled {
|
|
125
|
+
cursor: not-allowed;
|
|
126
|
+
opacity: 0.45;
|
|
127
|
+
}
|
|
128
|
+
.ss-switch .label {
|
|
129
|
+
font: 500 var(--ss-control-font)/1 var(--ss-font-body);
|
|
130
|
+
color: var(--ss-fg);
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
user-select: none;
|
|
133
|
+
}
|
|
134
|
+
.ss-switch:has(.track:disabled) .label {
|
|
135
|
+
cursor: not-allowed;
|
|
136
|
+
opacity: 0.45;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
@media (prefers-reduced-motion: reduce) {
|
|
140
|
+
.ss-switch .track,
|
|
141
|
+
.ss-switch .track .thumb {
|
|
142
|
+
transition: none;
|
|
143
|
+
}
|
|
144
|
+
}</style>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Size } from '../config.js';
|
|
2
|
+
interface Props {
|
|
3
|
+
/** On/off state (bindable). */
|
|
4
|
+
checked?: boolean;
|
|
5
|
+
/** Visible label rendered adjacent to the track; becomes the accessible name. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** Id for the underlying button (label `for`-style association uses it). */
|
|
8
|
+
id?: string;
|
|
9
|
+
/** Form field name (mirrored onto a data attribute for form integration). */
|
|
10
|
+
name?: string;
|
|
11
|
+
/** Disable the switch: inert + non-toggling. */
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** Token size (sm|md|lg); inherits the global size when unset. */
|
|
14
|
+
size?: Size;
|
|
15
|
+
/** Id of an element that further describes the switch (→ aria-describedby). */
|
|
16
|
+
describedby?: string;
|
|
17
|
+
/** Fired after `checked` flips, with the new value. */
|
|
18
|
+
onchange?: (checked: boolean) => void;
|
|
19
|
+
}
|
|
20
|
+
declare const Switch: import("svelte").Component<Props, {}, "checked">;
|
|
21
|
+
type Switch = ReturnType<typeof Switch>;
|
|
22
|
+
export default Switch;
|