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.
Files changed (65) hide show
  1. package/README.md +39 -13
  2. package/dist/components/Accordion.svelte +22 -6
  3. package/dist/components/Accordion.svelte.d.ts +5 -1
  4. package/dist/components/Avatar.svelte +119 -0
  5. package/dist/components/Avatar.svelte.d.ts +18 -0
  6. package/dist/components/Badge.svelte +3 -5
  7. package/dist/components/BottomNav.svelte +57 -19
  8. package/dist/components/BottomNav.svelte.d.ts +2 -0
  9. package/dist/components/Card.svelte +7 -1
  10. package/dist/components/Chart.svelte +527 -0
  11. package/dist/components/Chart.svelte.d.ts +42 -0
  12. package/dist/components/Container.svelte +55 -0
  13. package/dist/components/Container.svelte.d.ts +16 -0
  14. package/dist/components/DateField.svelte +188 -0
  15. package/dist/components/DateField.svelte.d.ts +37 -0
  16. package/dist/components/EmptyState.svelte +9 -3
  17. package/dist/components/EmptyState.svelte.d.ts +6 -0
  18. package/dist/components/FileDrop.svelte +355 -0
  19. package/dist/components/FileDrop.svelte.d.ts +24 -0
  20. package/dist/components/Heading.svelte +83 -0
  21. package/dist/components/Heading.svelte.d.ts +17 -0
  22. package/dist/components/Icon.svelte +32 -23
  23. package/dist/components/Icon.svelte.d.ts +7 -0
  24. package/dist/components/Image.svelte +19 -21
  25. package/dist/components/Input.svelte +2 -3
  26. package/dist/components/Link.svelte +42 -7
  27. package/dist/components/Link.svelte.d.ts +7 -0
  28. package/dist/components/LogStream.svelte +46 -31
  29. package/dist/components/Menu.svelte +59 -6
  30. package/dist/components/Menu.svelte.d.ts +22 -2
  31. package/dist/components/MetricTile.svelte +4 -4
  32. package/dist/components/Modal.svelte +223 -0
  33. package/dist/components/Modal.svelte.d.ts +29 -0
  34. package/dist/components/NumberField.svelte +260 -0
  35. package/dist/components/NumberField.svelte.d.ts +35 -0
  36. package/dist/components/Pagination.svelte +193 -0
  37. package/dist/components/Pagination.svelte.d.ts +22 -0
  38. package/dist/components/SegmentedControl.svelte +16 -4
  39. package/dist/components/SegmentedControl.svelte.d.ts +7 -0
  40. package/dist/components/Select.svelte +224 -0
  41. package/dist/components/Select.svelte.d.ts +42 -0
  42. package/dist/components/ServiceCard.svelte +15 -15
  43. package/dist/components/Sidebar.svelte +47 -21
  44. package/dist/components/Sparkline.svelte +15 -13
  45. package/dist/components/Spinner.svelte +124 -0
  46. package/dist/components/Spinner.svelte.d.ts +74 -0
  47. package/dist/components/Switch.svelte +144 -0
  48. package/dist/components/Switch.svelte.d.ts +22 -0
  49. package/dist/components/Table.svelte +267 -0
  50. package/dist/components/Table.svelte.d.ts +52 -0
  51. package/dist/components/Textarea.svelte +214 -0
  52. package/dist/components/Textarea.svelte.d.ts +38 -0
  53. package/dist/components/Toaster.svelte +20 -4
  54. package/dist/components/Tooltip.svelte +162 -0
  55. package/dist/components/Tooltip.svelte.d.ts +17 -0
  56. package/dist/components/Topbar.svelte +170 -50
  57. package/dist/components/Topbar.svelte.d.ts +30 -3
  58. package/dist/dssoca.config.d.ts +1 -1
  59. package/dist/dssoca.config.js +15 -0
  60. package/dist/index.d.ts +19 -1
  61. package/dist/index.js +19 -1
  62. package/dist/theme.css +177 -37
  63. package/dist/toast.svelte.js +3 -3
  64. package/dist/tokens.css +597 -0
  65. package/package.json +33 -4
@@ -1,12 +1,33 @@
1
1
  <script module lang="ts">
2
+ import type { Snippet } from 'svelte'
2
3
  import type { IconName } from './Icon.svelte'
3
4
 
4
- /** One selectable row in a {@link Menu}. */
5
+ /**
6
+ * One selectable row in a {@link Menu}.
7
+ *
8
+ * Leading visual (decorative; the `label` carries the semantics). When more
9
+ * than one is set, precedence is `leading` → `swatch` → `emoji` → `icon`.
10
+ */
5
11
  export interface MenuItem {
6
12
  id: string
7
13
  label: string
8
14
  /** Optional leading glyph. */
9
15
  icon?: IconName
16
+ /**
17
+ * Custom leading content as a Svelte 5 snippet — arbitrary markup rendered
18
+ * in the icon slot (aria-hidden; keep it decorative).
19
+ */
20
+ leading?: Snippet
21
+ /**
22
+ * Convenience leading visual: any CSS color, rendered as a token-sized
23
+ * square color chip (zero radius) — e.g. a theme-picker swatch.
24
+ */
25
+ swatch?: string
26
+ /**
27
+ * Convenience leading visual: a text glyph (e.g. an emoji flag for a
28
+ * language picker), rendered in the icon slot.
29
+ */
30
+ emoji?: string
10
31
  /** Disabled rows are skipped by keyboard navigation and not selectable. */
11
32
  disabled?: boolean
12
33
  /** Marks the active/checked row (renders a check marker, `aria-checked`). */
@@ -17,7 +38,6 @@
17
38
  </script>
18
39
 
19
40
  <script lang="ts">
20
- import type { Snippet } from 'svelte'
21
41
  import Icon from './Icon.svelte'
22
42
  import { resolveComponentSize, type Size } from '../config.js'
23
43
 
@@ -172,12 +192,20 @@
172
192
  function onDocPointerDown(e: PointerEvent) {
173
193
  if (!open) return
174
194
  const t = e.target as Node
175
- if (triggerEl?.contains(t) || panelEl?.contains(t)) return
195
+ // DS-0067 / DS-0078: triggerEl/panelEl may be unbound (pre-mount, SSR-ish
196
+ // eager evaluation) — null-check before .contains().
197
+ if (triggerEl && triggerEl.contains(t)) return
198
+ if (panelEl && panelEl.contains(t)) return
176
199
  closeMenu(false)
177
200
  }
178
201
 
202
+ // SSR safety (DS-0067): same guard pattern as toast.svelte.ts — effects
203
+ // normally don't run on the server, but the guard is the house convention
204
+ // and protects against eager evaluation.
205
+ const hasDocument = typeof document !== 'undefined'
206
+
179
207
  $effect(() => {
180
- if (!open) return
208
+ if (!open || !hasDocument) return
181
209
  document.addEventListener('pointerdown', onDocPointerDown, true)
182
210
  return () => document.removeEventListener('pointerdown', onDocPointerDown, true)
183
211
  })
@@ -223,9 +251,19 @@
223
251
  tabindex={i === activeIndex ? 0 : -1}
224
252
  onclick={() => activate(item)}
225
253
  >
226
- {#if item.icon}<Icon name={item.icon} />{/if}
254
+ {#if item.leading}
255
+ <span class="lead" aria-hidden="true">{@render item.leading()}</span>
256
+ {:else if item.swatch}
257
+ <span class="lead swatch" style="background:{item.swatch}" aria-hidden="true"></span>
258
+ {:else if item.emoji}
259
+ <span class="lead emoji" aria-hidden="true">{item.emoji}</span>
260
+ {:else if item.icon}
261
+ <Icon name={item.icon} />
262
+ {/if}
227
263
  <span class="label">{item.label}</span>
228
- <span class="marker" aria-hidden="true">{#if item.selected}<Icon name="check" />{/if}</span>
264
+ <span class="marker" aria-hidden="true"
265
+ >{#if item.selected}<Icon name="check" />{/if}</span
266
+ >
229
267
  </button>
230
268
  {/each}
231
269
  </div>
@@ -341,6 +379,21 @@
341
379
  background: transparent;
342
380
  color: var(--ss-fg-faint);
343
381
  }
382
+ .item .lead {
383
+ flex: 0 0 auto;
384
+ display: inline-flex;
385
+ align-items: center;
386
+ justify-content: center;
387
+ width: var(--ss-icon);
388
+ height: var(--ss-icon);
389
+ }
390
+ .item .lead.swatch {
391
+ border: 1px solid var(--ss-line);
392
+ }
393
+ .item .lead.emoji {
394
+ font-size: var(--ss-icon);
395
+ line-height: 1;
396
+ }
344
397
  .item .label {
345
398
  flex: 1 1 auto;
346
399
  min-width: 0;
@@ -1,10 +1,31 @@
1
+ import type { Snippet } from 'svelte';
1
2
  import type { IconName } from './Icon.svelte';
2
- /** One selectable row in a {@link Menu}. */
3
+ /**
4
+ * One selectable row in a {@link Menu}.
5
+ *
6
+ * Leading visual (decorative; the `label` carries the semantics). When more
7
+ * than one is set, precedence is `leading` → `swatch` → `emoji` → `icon`.
8
+ */
3
9
  export interface MenuItem {
4
10
  id: string;
5
11
  label: string;
6
12
  /** Optional leading glyph. */
7
13
  icon?: IconName;
14
+ /**
15
+ * Custom leading content as a Svelte 5 snippet — arbitrary markup rendered
16
+ * in the icon slot (aria-hidden; keep it decorative).
17
+ */
18
+ leading?: Snippet;
19
+ /**
20
+ * Convenience leading visual: any CSS color, rendered as a token-sized
21
+ * square color chip (zero radius) — e.g. a theme-picker swatch.
22
+ */
23
+ swatch?: string;
24
+ /**
25
+ * Convenience leading visual: a text glyph (e.g. an emoji flag for a
26
+ * language picker), rendered in the icon slot.
27
+ */
28
+ emoji?: string;
8
29
  /** Disabled rows are skipped by keyboard navigation and not selectable. */
9
30
  disabled?: boolean;
10
31
  /** Marks the active/checked row (renders a check marker, `aria-checked`). */
@@ -12,7 +33,6 @@ export interface MenuItem {
12
33
  /** Fired when the row is activated. */
13
34
  onSelect?: (id: string) => void;
14
35
  }
15
- import type { Snippet } from 'svelte';
16
36
  import { type Size } from '../config.js';
17
37
  /** Where the panel attaches relative to the trigger. */
18
38
  type Align = 'start' | 'end';
@@ -51,9 +51,7 @@
51
51
 
52
52
  // Worded delta description so colour/arrow isn't the only signal (WCAG 1.4.1).
53
53
  const deltaDescription = $derived(
54
- [`${dir === 'up' ? 'increased' : 'decreased'} ${delta}`, deltaLabel]
55
- .filter(Boolean)
56
- .join(' '),
54
+ [`${dir === 'up' ? 'increased' : 'decreased'} ${delta}`, deltaLabel].filter(Boolean).join(' '),
57
55
  )
58
56
  </script>
59
57
 
@@ -69,7 +67,9 @@
69
67
  {#if delta}<div class="skeleton skeleton-delta" aria-hidden="true"></div>{/if}
70
68
  {:else}
71
69
  <div class="val" role="status" aria-live="polite">
72
- {#if prefix}<span class="small">{prefix}</span>{/if}{value}{#if suffix}<span class="small">{suffix}</span>{/if}
70
+ {#if prefix}<span class="small">{prefix}</span>{/if}{value}{#if suffix}<span class="small"
71
+ >{suffix}</span
72
+ >{/if}
73
73
  </div>
74
74
  {#if delta}
75
75
  <div class="delta {sentiment}" class:emphasis role="img" aria-label={deltaDescription}>
@@ -0,0 +1,223 @@
1
+ <script lang="ts">
2
+ // ─────────────────────────────────────────────────────────────────────────
3
+ // Modal (DS-0094). Built on the native <dialog> element so the platform
4
+ // hands us a focus trap, Esc-to-close and an inert ::backdrop for free.
5
+ //
6
+ // `open` is $bindable; an $effect mirrors it onto the dialog via
7
+ // showModal()/close(). The dialog's native `close` event syncs `open` back
8
+ // to false and fires `onclose`. Esc is native; when `closeOnEsc` is false we
9
+ // intercept the `cancel` event and preventDefault(). Backdrop click closes
10
+ // when `closeOnBackdrop` by detecting a pointerdown whose target IS the
11
+ // dialog itself (the inner .panel covers the dialog's content box, so any
12
+ // hit on the dialog element is the surrounding backdrop area).
13
+ //
14
+ // Zero radius; surface = --ss-bg-elev, border = --ss-line; tinted ::backdrop.
15
+ // Component metrics are inline var(--ss-modal-*, fallback) so no global SCSS
16
+ // is touched (DS-0094).
17
+ // ─────────────────────────────────────────────────────────────────────────
18
+ import type { Snippet } from 'svelte'
19
+ import { resolveComponentSize, type Size } from '../config.js'
20
+
21
+ interface Props {
22
+ /** Whether the modal is shown. Bindable — sync it from caller state. */
23
+ open?: boolean
24
+ /** Title rendered in the header; also wires `aria-labelledby`. */
25
+ title?: string
26
+ /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
27
+ size?: Size
28
+ /** Clicking the backdrop (outside the panel) closes the modal. @default true */
29
+ closeOnBackdrop?: boolean
30
+ /** Esc closes the modal. When false, Esc is swallowed (cancel prevented). @default true */
31
+ closeOnEsc?: boolean
32
+ /** Styling hint for destructive dialogs (tints the accent rail/title). @default false */
33
+ danger?: boolean
34
+ /** Accessible name when no `title` is set (maps to aria-label on the dialog). */
35
+ 'aria-label'?: string
36
+ /** Called after the dialog has closed (any reason: Esc, backdrop, button). */
37
+ onclose?: () => void
38
+ /** Header content; replaces the default title row when provided. */
39
+ header?: Snippet
40
+ /** Footer content (typically action buttons). */
41
+ footer?: Snippet
42
+ /** Body content. */
43
+ children: Snippet
44
+ }
45
+
46
+ let {
47
+ open = $bindable(false),
48
+ title,
49
+ size,
50
+ closeOnBackdrop = true,
51
+ closeOnEsc = true,
52
+ danger = false,
53
+ 'aria-label': ariaLabel,
54
+ onclose,
55
+ header,
56
+ footer,
57
+ children,
58
+ }: Props = $props()
59
+
60
+ let dialog = $state<HTMLDialogElement | null>(null)
61
+
62
+ // Stable id so the dialog's `aria-labelledby` can point at the title element.
63
+ const uid = $props.id()
64
+ const titleId = $derived(`${uid}-title`)
65
+
66
+ // Mirror `open` onto the native dialog. showModal()/close() throw if called
67
+ // in the wrong state, so guard on dialog.open before flipping it.
68
+ $effect(() => {
69
+ const el = dialog
70
+ if (!el) return
71
+ if (open && !el.open) el.showModal()
72
+ else if (!open && el.open) el.close()
73
+ })
74
+
75
+ // Native `close` (Esc, form method=dialog, .close()) → sync state + notify.
76
+ function onDialogClose() {
77
+ if (open) open = false
78
+ onclose?.()
79
+ }
80
+
81
+ // Esc dispatches `cancel` before `close`; swallow it when Esc is disabled.
82
+ function onCancel(e: Event) {
83
+ if (!closeOnEsc) e.preventDefault()
84
+ }
85
+
86
+ // A pointerdown landing on the <dialog> itself (not the inner .panel) is a
87
+ // backdrop hit. Using pointerdown avoids closing on a drag that began inside
88
+ // the panel and released on the backdrop.
89
+ function onPointerDown(e: PointerEvent) {
90
+ if (!closeOnBackdrop) return
91
+ if (e.target === dialog) open = false
92
+ }
93
+ </script>
94
+
95
+ <dialog
96
+ bind:this={dialog}
97
+ class="ss-modal"
98
+ class:danger
99
+ data-size-variant={resolveComponentSize('Modal', size)}
100
+ aria-labelledby={title ? titleId : undefined}
101
+ aria-label={title ? undefined : ariaLabel}
102
+ onclose={onDialogClose}
103
+ oncancel={onCancel}
104
+ onpointerdown={onPointerDown}
105
+ >
106
+ <div class="panel">
107
+ <header class="head">
108
+ {#if header}
109
+ {@render header()}
110
+ {:else if title}
111
+ <h2 class="title" id={titleId}>{title}</h2>
112
+ {/if}
113
+ <button type="button" class="close" aria-label="Close" onclick={() => (open = false)}
114
+ >×</button
115
+ >
116
+ </header>
117
+
118
+ <div class="body">
119
+ {@render children()}
120
+ </div>
121
+
122
+ {#if footer}
123
+ <footer class="foot">
124
+ {@render footer()}
125
+ </footer>
126
+ {/if}
127
+ </div>
128
+ </dialog>
129
+
130
+ <style>.ss-modal {
131
+ padding: 0;
132
+ border: 1px solid var(--ss-line);
133
+ background: var(--ss-bg-elev);
134
+ color: var(--ss-fg);
135
+ box-shadow: var(--ss-shadow-pop);
136
+ width: var(--ss-modal-w, 32rem);
137
+ max-width: var(--ss-modal-max, calc(100vw - var(--ss-s-8)));
138
+ max-height: var(--ss-modal-max-h, calc(100vh - var(--ss-s-16)));
139
+ margin: auto;
140
+ overflow: hidden;
141
+ }
142
+ .ss-modal::backdrop {
143
+ background: var(--ss-modal-backdrop, rgba(0, 0, 0, 0.62));
144
+ }
145
+ .ss-modal[data-size-variant=sm] {
146
+ --ss-modal-w: 24rem;
147
+ }
148
+ .ss-modal[data-size-variant=lg] {
149
+ --ss-modal-w: 48rem;
150
+ }
151
+
152
+ .panel {
153
+ display: flex;
154
+ flex-direction: column;
155
+ max-height: inherit;
156
+ }
157
+
158
+ .head {
159
+ display: flex;
160
+ align-items: center;
161
+ gap: var(--ss-modal-head-gap, var(--ss-s-3));
162
+ padding: var(--ss-modal-pad-y, var(--ss-s-4)) var(--ss-modal-pad-x, var(--ss-s-5));
163
+ border-bottom: 1px solid var(--ss-line);
164
+ }
165
+
166
+ .title {
167
+ flex: 1 1 auto;
168
+ margin: 0;
169
+ min-width: 0;
170
+ font-family: var(--ss-font-display, var(--ss-font-body));
171
+ font-size: var(--ss-modal-title, var(--ss-size-h3));
172
+ line-height: 1.2;
173
+ color: var(--ss-fg);
174
+ }
175
+
176
+ .ss-modal.danger .title {
177
+ color: var(--ss-danger);
178
+ }
179
+
180
+ .close {
181
+ flex: none;
182
+ margin-left: auto;
183
+ appearance: none;
184
+ display: inline-flex;
185
+ align-items: center;
186
+ justify-content: center;
187
+ width: var(--ss-modal-close, var(--ss-s-8));
188
+ height: var(--ss-modal-close, var(--ss-s-8));
189
+ padding: 0;
190
+ background: transparent;
191
+ border: 1px solid transparent;
192
+ color: var(--ss-fg-muted);
193
+ font-size: var(--ss-size-h3);
194
+ line-height: 1;
195
+ cursor: pointer;
196
+ transition: color var(--ss-dur-fast) var(--ss-ease), border-color var(--ss-dur-fast) var(--ss-ease);
197
+ }
198
+ .close:hover {
199
+ color: var(--ss-fg);
200
+ border-color: var(--ss-line-strong);
201
+ }
202
+ .close:focus-visible {
203
+ outline: 2px solid var(--ss-primary);
204
+ outline-offset: 2px;
205
+ color: var(--ss-fg);
206
+ }
207
+
208
+ .body {
209
+ padding: var(--ss-modal-pad-y, var(--ss-s-4)) var(--ss-modal-pad-x, var(--ss-s-5));
210
+ overflow: auto;
211
+ color: var(--ss-fg);
212
+ font-family: var(--ss-font-body);
213
+ line-height: var(--ss-leading, 1.5);
214
+ }
215
+
216
+ .foot {
217
+ display: flex;
218
+ align-items: center;
219
+ justify-content: flex-end;
220
+ gap: var(--ss-modal-foot-gap, var(--ss-s-2));
221
+ padding: var(--ss-modal-pad-y, var(--ss-s-4)) var(--ss-modal-pad-x, var(--ss-s-5));
222
+ border-top: 1px solid var(--ss-line);
223
+ }</style>
@@ -0,0 +1,29 @@
1
+ import type { Snippet } from 'svelte';
2
+ import { type Size } from '../config.js';
3
+ interface Props {
4
+ /** Whether the modal is shown. Bindable — sync it from caller state. */
5
+ open?: boolean;
6
+ /** Title rendered in the header; also wires `aria-labelledby`. */
7
+ title?: string;
8
+ /** Token size (sm|md|lg); controls max-width. Inherits the global size when unset. */
9
+ size?: Size;
10
+ /** Clicking the backdrop (outside the panel) closes the modal. @default true */
11
+ closeOnBackdrop?: boolean;
12
+ /** Esc closes the modal. When false, Esc is swallowed (cancel prevented). @default true */
13
+ closeOnEsc?: boolean;
14
+ /** Styling hint for destructive dialogs (tints the accent rail/title). @default false */
15
+ danger?: boolean;
16
+ /** Accessible name when no `title` is set (maps to aria-label on the dialog). */
17
+ 'aria-label'?: string;
18
+ /** Called after the dialog has closed (any reason: Esc, backdrop, button). */
19
+ onclose?: () => void;
20
+ /** Header content; replaces the default title row when provided. */
21
+ header?: Snippet;
22
+ /** Footer content (typically action buttons). */
23
+ footer?: Snippet;
24
+ /** Body content. */
25
+ children: Snippet;
26
+ }
27
+ declare const Modal: import("svelte").Component<Props, {}, "open">;
28
+ type Modal = ReturnType<typeof Modal>;
29
+ export default Modal;
@@ -0,0 +1,260 @@
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
+ /** Bindable current value; `null` when the input is empty. */
9
+ value?: number | null
10
+ min?: number
11
+ max?: number
12
+ /** Increment/decrement step for the steppers (and native arrows). */
13
+ step?: number
14
+ required?: boolean
15
+ disabled?: boolean
16
+ /** Native readonly — value visible but not editable; rendered muted. */
17
+ readonly?: boolean
18
+ /** Token size (sm|md|lg); inherits the global size when unset. */
19
+ size?: Size
20
+ /** Marks the field invalid for assistive tech (aria-invalid). */
21
+ invalid?: boolean
22
+ /** Supplementary helper text rendered under the input. */
23
+ hint?: string
24
+ /** Error text rendered under the input; its presence implies aria-invalid and is announced to AT. */
25
+ error?: string
26
+ /** id(s) of element(s) describing the field (aria-describedby) — e.g. hint/error text. */
27
+ describedby?: string
28
+ placeholder?: string
29
+ onchange?: (e: Event & { currentTarget: HTMLInputElement }) => void
30
+ /** Any remaining native input attributes / event handlers are forwarded. */
31
+ [key: string]: unknown
32
+ }
33
+ let {
34
+ label,
35
+ id,
36
+ name,
37
+ value = $bindable(null),
38
+ min,
39
+ max,
40
+ step = 1,
41
+ required = false,
42
+ disabled = false,
43
+ readonly = false,
44
+ size,
45
+ invalid,
46
+ hint,
47
+ error,
48
+ describedby,
49
+ placeholder = '',
50
+ onchange,
51
+ ...rest
52
+ }: Props = $props()
53
+
54
+ // Guarantee a label↔input association even when no `id` is passed.
55
+ const uid = $props.id()
56
+ const inputId = $derived(id ?? uid)
57
+ const hintId = $derived(`${inputId}-hint`)
58
+ const errorId = $derived(`${inputId}-error`)
59
+
60
+ // error wins, then hint, then any caller-supplied describedby — order matters for AT.
61
+ const describedBy = $derived(
62
+ [error ? errorId : null, hint ? hintId : null, describedby].filter(Boolean).join(' ') ||
63
+ undefined,
64
+ )
65
+ const isInvalid = $derived(invalid || Boolean(error) || undefined)
66
+ const resolvedSize = $derived(resolveComponentSize('NumberField', size))
67
+
68
+ // Steppers are inert at the bounds (and when the field can't be edited).
69
+ const atMin = $derived(value != null && min != null && value <= min)
70
+ const atMax = $derived(value != null && max != null && value >= max)
71
+ const decDisabled = $derived(disabled || readonly || atMin)
72
+ const incDisabled = $derived(disabled || readonly || atMax)
73
+
74
+ function clamp(n: number): number {
75
+ if (min != null && n < min) return min
76
+ if (max != null && n > max) return max
77
+ return n
78
+ }
79
+
80
+ function onInput(e: Event & { currentTarget: HTMLInputElement }) {
81
+ const raw = e.currentTarget.value
82
+ value = raw === '' ? null : e.currentTarget.valueAsNumber
83
+ if (value != null && Number.isNaN(value)) value = null
84
+ }
85
+
86
+ function nudge(dir: 1 | -1) {
87
+ const base = value ?? (dir > 0 ? (min ?? 0) : (max ?? 0))
88
+ value = clamp(base + dir * step)
89
+ }
90
+ </script>
91
+
92
+ <div
93
+ class="ss-numberfield"
94
+ data-size-variant={resolvedSize}
95
+ class:invalid={isInvalid}
96
+ class:disabled
97
+ >
98
+ {#if label}
99
+ <label class="lbl" for={inputId}>
100
+ {label}
101
+ {#if required}<span class="req" aria-hidden="true">*</span>{/if}
102
+ </label>
103
+ {/if}
104
+
105
+ <div class="control">
106
+ <button
107
+ type="button"
108
+ class="step dec"
109
+ aria-label="Decrease"
110
+ disabled={decDisabled}
111
+ onclick={() => nudge(-1)}
112
+ >
113
+ −
114
+ </button>
115
+ <input
116
+ class="ss-input"
117
+ id={inputId}
118
+ {name}
119
+ type="number"
120
+ inputmode="decimal"
121
+ value={value ?? ''}
122
+ {min}
123
+ {max}
124
+ {step}
125
+ {placeholder}
126
+ {required}
127
+ {disabled}
128
+ {readonly}
129
+ aria-invalid={isInvalid}
130
+ aria-describedby={describedBy}
131
+ oninput={onInput}
132
+ {onchange}
133
+ {...rest}
134
+ />
135
+ <button
136
+ type="button"
137
+ class="step inc"
138
+ aria-label="Increase"
139
+ disabled={incDisabled}
140
+ onclick={() => nudge(1)}
141
+ >
142
+ +
143
+ </button>
144
+ </div>
145
+
146
+ {#if error}<span class="msg error" id={errorId} role="alert">{error}</span>{/if}
147
+ {#if hint}<span class="msg hint" id={hintId}>{hint}</span>{/if}
148
+ </div>
149
+
150
+ <style>.ss-numberfield {
151
+ display: flex;
152
+ flex-direction: column;
153
+ gap: 6px;
154
+ }
155
+ .ss-numberfield .lbl {
156
+ font-family: var(--ss-font-mono);
157
+ font-size: var(--ss-ui-xs);
158
+ color: var(--ss-fg-muted);
159
+ text-transform: uppercase;
160
+ letter-spacing: 0.08em;
161
+ }
162
+ .ss-numberfield .lbl .req {
163
+ color: var(--ss-red);
164
+ margin-left: 2px;
165
+ }
166
+ .ss-numberfield .control {
167
+ display: flex;
168
+ align-items: stretch;
169
+ background: transparent;
170
+ color: var(--ss-fg);
171
+ border: 1px solid var(--ss-line);
172
+ transition: border-color var(--ss-dur-fast) var(--ss-ease), box-shadow var(--ss-dur-fast) var(--ss-ease);
173
+ }
174
+ .ss-numberfield .control:focus-within {
175
+ border-color: var(--ss-primary);
176
+ box-shadow: 0 0 0 3px var(--ss-primary-soft);
177
+ }
178
+ .ss-numberfield.invalid .control {
179
+ border-color: var(--ss-red);
180
+ }
181
+ .ss-numberfield.invalid .control:focus-within {
182
+ border-color: var(--ss-red);
183
+ box-shadow: 0 0 0 3px rgba(var(--ss-red-rgb), 0.22);
184
+ }
185
+ .ss-numberfield.disabled .control {
186
+ border-color: var(--ss-line);
187
+ }
188
+ .ss-numberfield .step {
189
+ display: inline-flex;
190
+ align-items: center;
191
+ justify-content: center;
192
+ flex: none;
193
+ width: var(--ss-numberfield-step-w, 2.25em);
194
+ font-family: var(--ss-font-mono);
195
+ font-size: var(--ss-input-font);
196
+ line-height: 1;
197
+ background: transparent;
198
+ border: none;
199
+ color: var(--ss-fg-muted);
200
+ cursor: pointer;
201
+ transition: color var(--ss-dur-fast) var(--ss-ease);
202
+ }
203
+ .ss-numberfield .step:hover:not(:disabled) {
204
+ color: var(--ss-fg);
205
+ }
206
+ .ss-numberfield .step:focus-visible {
207
+ outline: none;
208
+ color: var(--ss-fg);
209
+ box-shadow: 0 0 0 2px var(--ss-primary-soft);
210
+ }
211
+ .ss-numberfield .step:disabled {
212
+ color: var(--ss-fg-faint);
213
+ cursor: not-allowed;
214
+ }
215
+ .ss-numberfield .msg {
216
+ font-family: var(--ss-font-mono);
217
+ font-size: var(--ss-ui-xs);
218
+ letter-spacing: 0.02em;
219
+ }
220
+ .ss-numberfield .msg.hint {
221
+ color: var(--ss-fg-faint);
222
+ }
223
+ .ss-numberfield .msg.error {
224
+ color: var(--ss-red);
225
+ }
226
+
227
+ .ss-input {
228
+ font-family: var(--ss-font-mono);
229
+ font-size: var(--ss-input-font);
230
+ background: transparent;
231
+ color: var(--ss-fg);
232
+ border: none;
233
+ padding: var(--ss-input-py) var(--ss-input-px);
234
+ width: 100%;
235
+ min-width: 0;
236
+ text-align: center;
237
+ transition: color var(--ss-dur-fast) var(--ss-ease);
238
+ -moz-appearance: textfield;
239
+ appearance: textfield;
240
+ }
241
+ .ss-input::-webkit-outer-spin-button, .ss-input::-webkit-inner-spin-button {
242
+ -webkit-appearance: none;
243
+ margin: 0;
244
+ }
245
+ .ss-input:focus {
246
+ outline: none;
247
+ }
248
+ .ss-input::placeholder {
249
+ font-style: italic;
250
+ color: var(--ss-fg-faint);
251
+ }
252
+ .ss-input[readonly] {
253
+ color: var(--ss-fg-muted);
254
+ cursor: default;
255
+ }
256
+ .ss-input:disabled {
257
+ color: var(--ss-fg-faint);
258
+ cursor: not-allowed;
259
+ -webkit-text-fill-color: var(--ss-fg-faint);
260
+ }</style>