@xerios/design-system 0.1.1 → 0.1.3

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 (47) hide show
  1. package/CHANGELOG.md +133 -0
  2. package/README.md +12 -8
  3. package/dist/components/Button.svelte +0 -7
  4. package/dist/components/Button.svelte.d.ts +1 -13
  5. package/dist/components/CollapsibleAdvanced.svelte +1 -1
  6. package/dist/components/Dialogs.svelte +12 -0
  7. package/dist/components/WorkingBorder.svelte +10 -8
  8. package/dist/components/empty/EmptyError.svelte +61 -12
  9. package/dist/components/empty/EmptyError.svelte.d.ts +2 -1
  10. package/dist/components/filters/FilterChip.svelte +2 -2
  11. package/dist/components/filters/OptionList.svelte +29 -13
  12. package/dist/components/filters/Panel.svelte +1 -1
  13. package/dist/components/icons.d.ts +3 -0
  14. package/dist/components/icons.js +3 -0
  15. package/dist/components/inputs/ButtonGroup.svelte +4 -1
  16. package/dist/components/inputs/Calendar.svelte +232 -172
  17. package/dist/components/inputs/Calendar.svelte.d.ts +2 -0
  18. package/dist/components/inputs/DateField.svelte +209 -92
  19. package/dist/components/inputs/DateField.svelte.d.ts +16 -10
  20. package/dist/components/inputs/DateInput.svelte +22 -9
  21. package/dist/components/inputs/DateInput.svelte.d.ts +3 -0
  22. package/dist/components/inputs/DatePicker.svelte +63 -38
  23. package/dist/components/inputs/DatePicker.svelte.d.ts +5 -2
  24. package/dist/components/inputs/DateRangePicker.svelte +69 -39
  25. package/dist/components/inputs/DateRangePicker.svelte.d.ts +5 -2
  26. package/dist/components/inputs/DateRangeSelect.svelte +26 -25
  27. package/dist/components/inputs/RadioGroup.svelte +3 -1
  28. package/dist/components/inputs/Segmented.svelte +4 -1
  29. package/dist/components/inputs/Select.svelte +18 -8
  30. package/dist/components/inputs/TextArea.svelte +1 -1
  31. package/dist/components/scroll/ScrollButton.svelte +260 -0
  32. package/dist/components/scroll/ScrollButton.svelte.d.ts +61 -0
  33. package/dist/components/scroll/ScrollMore.svelte +57 -0
  34. package/dist/components/scroll/ScrollMore.svelte.d.ts +28 -0
  35. package/dist/components/scroll/ScrollToTop.svelte +57 -0
  36. package/dist/components/scroll/ScrollToTop.svelte.d.ts +22 -0
  37. package/dist/css/atoms.css +13 -9
  38. package/dist/css/base.css +1 -2
  39. package/dist/css/effects.css +259 -16
  40. package/dist/css/tokens.css +99 -72
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.js +3 -0
  43. package/dist/lib/dates.d.ts +38 -5
  44. package/dist/lib/dates.js +88 -19
  45. package/dist/lib/edge-glow.d.ts +11 -0
  46. package/dist/lib/edge-glow.js +251 -0
  47. package/package.json +5 -3
@@ -208,9 +208,6 @@
208
208
  onpointerenter={() => (active = i)}
209
209
  onclick={() => choose(i)}
210
210
  >
211
- <span class="tick"
212
- >{#if o.value === value}<Icon name="check" size="sm" />{/if}</span
213
- >
214
211
  <span class="label" title={o.label}>{text(o)}</span>
215
212
  {#if o.hint}<span class="hint">{o.hint}</span>{/if}
216
213
  </li>
@@ -471,14 +468,18 @@
471
468
  .list {
472
469
  border-color: CanvasText;
473
470
  }
471
+ li[aria-selected='true'] {
472
+ background: Highlight;
473
+ color: HighlightText;
474
+ }
474
475
  }
475
476
  li {
476
477
  display: grid;
477
- grid-template-columns: 14px minmax(0, 1fr) auto;
478
+ grid-template-columns: minmax(0, 1fr) auto;
478
479
  gap: 6px;
479
480
  align-items: center;
480
481
  min-height: 32px;
481
- padding: 0 10px 0 8px;
482
+ padding: 0 10px;
482
483
  border-radius: var(--r-sm);
483
484
  font-size: 13px;
484
485
  color: var(--fg);
@@ -488,9 +489,18 @@
488
489
  li.active {
489
490
  background: var(--control-3);
490
491
  }
491
- .tick {
492
- display: inline-flex;
493
- color: var(--accent);
492
+ /* The chosen option is solid brand, as Calendar's chosen day, whether or not the keyboard is on it. With the keyboard
493
+ on it, a lighter brand line inside the edge keeps that visible. */
494
+ li[aria-selected='true'] {
495
+ background: var(--brand);
496
+ color: var(--accent-ink);
497
+ }
498
+ li[aria-selected='true'].active {
499
+ box-shadow: inset 0 0 0 2px color-mix(in lch, var(--brand), var(--accent-ink) 45%);
500
+ }
501
+ li[aria-selected='true'] .hint {
502
+ color: inherit;
503
+ opacity: 0.75;
494
504
  }
495
505
  /* Group headings: small muted labels, a hairline between groups. */
496
506
  /* Square, and widened over the list's 4px padding so the hairline runs edge to edge. */
@@ -1,7 +1,7 @@
1
1
  <script>
2
2
  /**
3
3
  * Multi-line text field matching TextField (Linear's composer): the shared .field-box (faint fill, inset hairline
4
- * with a lit top edge, 8px corners, indigo hairline and ring while focused). Grows with its content up to 40% of the window, then scrolls; resizable.
4
+ * with a lit top edge, 8px corners, accent hairline and ring while focused). Grows with its content up to 40% of the window, then scrolls; resizable.
5
5
  * Other props (placeholder, events, autofocus, data-*) go to the <textarea>. Call focus() to jump into it.
6
6
  * error: a message from the app; the field turns red and shows it in a bubble underneath, which can be dismissed. Native constraints (`required`,
7
7
  * `minlength`…) report the browser's own message the same way. See lib/validity.js.
@@ -0,0 +1,260 @@
1
+ <script>
2
+ /**
3
+ * Internal: the floating button that ScrollToTop and ScrollMore are made of. Not exported; use those two.
4
+ *
5
+ * It finds the scroll area it sits in (the nearest ancestor that scrolls, else the window, or `target`), watches its
6
+ * scroll position and size, and floats at that area's bottom edge while `shown(metrics)` says so. In a scroll
7
+ * container it is a zero-height sticky strip, so it has to be the container's last child (or the last child of a
8
+ * block running the whole length of the content); for the window it is portalled to <body> and fixed to the viewport.
9
+ *
10
+ * label: the button's name: its visible text with `showLabel`, else its aria-label and tooltip. icon: an Icon name.
11
+ * showLabel: a pill with the icon and the label, instead of the round icon-only button.
12
+ * align: 'end' (the bottom corner, default) | 'center' (the middle of the bottom edge).
13
+ * target: the scroll area, if it isn't the nearest scrolling ancestor (an element, or window).
14
+ * shown(metrics): whether to show it; metrics is { top, max, page } in px: the scroll offset, its largest value, and
15
+ * the visible height.
16
+ * go(scroller, metrics, button): what pressing it does.
17
+ * cue: the icon bobs, to draw the eye (stills under reduced motion).
18
+ * keepFocused: stays while it has keyboard focus even when `shown` turns false, so the focus isn't dropped.
19
+ */
20
+ import Icon from '../Icon.svelte'
21
+ import { portal } from '../../lib/dom.js'
22
+ import { tooltip } from '../../lib/tooltip.js'
23
+ import { fly } from '../../lib/motion.js'
24
+ import { observeSize } from '../../lib/observe.js'
25
+
26
+ /**
27
+ * @typedef {{ top: number, max: number, page: number }} Metrics
28
+ * @typedef {object} Props
29
+ * @property {string} label
30
+ * @property {string} icon
31
+ * @property {boolean} [showLabel]
32
+ * @property {'end' | 'center'} [align]
33
+ * @property {HTMLElement | Window} [target]
34
+ * @property {(metrics: Metrics) => boolean} shown
35
+ * @property {(scroller: HTMLElement | Window, metrics: Metrics, button: HTMLButtonElement) => void} go
36
+ * @property {boolean} [cue]
37
+ * @property {boolean} [keepFocused]
38
+ */
39
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
40
+ let {
41
+ label,
42
+ icon,
43
+ showLabel = false,
44
+ align = 'end',
45
+ target,
46
+ shown,
47
+ go,
48
+ cue = false,
49
+ keepFocused = false,
50
+ class: className,
51
+ ...rest
52
+ } = $props()
53
+
54
+ /** @type {HTMLElement | Window | undefined} */
55
+ let scroller = $state()
56
+ /** @type {Metrics} */
57
+ let metrics = $state({ top: 0, max: 0, page: 0 })
58
+ let focused = $state(false)
59
+ const inWindow = $derived(scroller === window)
60
+ const visible = $derived(!!scroller && (shown(metrics) || (keepFocused && focused)))
61
+
62
+ /** The nearest ancestor that scrolls vertically, else the window. */
63
+ function scrollParent(/** @type {HTMLElement} */ node) {
64
+ for (let el = node.parentElement; el && el !== document.body && el !== document.documentElement; el = el.parentElement) {
65
+ if (/auto|scroll|overlay/.test(getComputedStyle(el).overflowY)) return el
66
+ }
67
+ return window
68
+ }
69
+
70
+ /**
71
+ * Attachment on the in-place strip: finds the scroll area and keeps `metrics` up to date. Without `target` it looks
72
+ * again a frame after mounting, when the window resizes, and when an ancestor nearer than the one it follows scrolls:
73
+ * styles can arrive after the strip mounts (a hot reload, a lazily loaded sheet), and a layout can hand scrolling to
74
+ * another box at some widths.
75
+ */
76
+ function track(/** @type {HTMLElement} */ node) {
77
+ const given = target
78
+ /** @type {HTMLElement | Window | undefined} */
79
+ let el
80
+ let stop = () => {}
81
+ const resolve = () => {
82
+ let next = given ?? scrollParent(node)
83
+ if (next === document.body || next === document.documentElement || next === document.scrollingElement) next = window
84
+ if (next === el) return
85
+ stop()
86
+ el = next
87
+ scroller = next
88
+ stop = follow(next)
89
+ }
90
+ resolve()
91
+ if (given) return () => stop()
92
+
93
+ const again = requestAnimationFrame(resolve)
94
+ /** @param {Event} event */
95
+ const scrolled = (event) => {
96
+ const t = event.target
97
+ if (t instanceof Element && t !== el && t.contains(node) && (el === window || /** @type {HTMLElement} */ (el).contains(t))) resolve()
98
+ }
99
+ document.addEventListener('scroll', scrolled, { capture: true, passive: true })
100
+ window.addEventListener('resize', resolve)
101
+ return () => {
102
+ cancelAnimationFrame(again)
103
+ document.removeEventListener('scroll', scrolled, { capture: true })
104
+ window.removeEventListener('resize', resolve)
105
+ stop()
106
+ }
107
+ }
108
+
109
+ /** Follows one scroll area: its offset and size, and its content's size, into `metrics`. Returns the stop. */
110
+ function follow(/** @type {HTMLElement | Window} */ el) {
111
+ const win = el === window
112
+ const box = win ? document.documentElement : /** @type {HTMLElement} */ (el)
113
+
114
+ let frame = 0
115
+ const measure = () => {
116
+ frame = 0
117
+ const top = win ? window.scrollY : box.scrollTop
118
+ const page = box.clientHeight
119
+ metrics = { top, max: Math.max(0, box.scrollHeight - page), page }
120
+ }
121
+ const schedule = () => {
122
+ frame ||= requestAnimationFrame(measure)
123
+ }
124
+
125
+ // The content can grow without the box resizing, so watch what holds it too (and children added later).
126
+ const content = win ? document.body : box
127
+ /** @type {(() => void)[]} */
128
+ let sized = []
129
+ const watch = () => {
130
+ for (const stop of sized) stop()
131
+ sized = [box, content, ...content.children].map((child) => observeSize(child, schedule))
132
+ schedule()
133
+ }
134
+ const mutations = new MutationObserver(watch)
135
+ mutations.observe(content, { childList: true })
136
+ el.addEventListener('scroll', schedule, { passive: true })
137
+ window.addEventListener('resize', schedule)
138
+ watch()
139
+ measure()
140
+
141
+ return () => {
142
+ cancelAnimationFrame(frame)
143
+ for (const stop of sized) stop()
144
+ mutations.disconnect()
145
+ el.removeEventListener('scroll', schedule)
146
+ window.removeEventListener('resize', schedule)
147
+ }
148
+ }
149
+
150
+ /** @param {MouseEvent & { currentTarget: HTMLButtonElement }} event */
151
+ function press(event) {
152
+ if (scroller) go(scroller, metrics, event.currentTarget)
153
+ }
154
+ </script>
155
+
156
+ {#snippet button()}
157
+ <button
158
+ type="button"
159
+ class={['scroll-btn', align, showLabel && 'labelled', cue && 'cue', className]}
160
+ aria-label={showLabel ? undefined : label}
161
+ {@attach tooltip(showLabel ? '' : label)}
162
+ {...rest}
163
+ onclick={press}
164
+ onfocus={(e) => (focused = e.currentTarget.matches(':focus-visible'))}
165
+ onblur={() => (focused = false)}
166
+ transition:fly|global={{ y: 8 }}
167
+ >
168
+ <span class="glyph"><Icon name={icon} size={showLabel ? 'sm' : 'md'} /></span>
169
+ {#if showLabel}<span>{label}</span>{/if}
170
+ </button>
171
+ {/snippet}
172
+
173
+ <div class="scroll-strip" {@attach track}>
174
+ {#if visible && !inWindow}{@render button()}{/if}
175
+ </div>
176
+ {#if visible && inWindow}
177
+ <div class="scroll-strip fixed" data-floating {@attach portal}>{@render button()}</div>
178
+ {/if}
179
+
180
+ <style>
181
+ /* A zero-height strip along the scroll area's bottom edge, for the button to float from: sticky inside a scroll
182
+ container (so it adds no height to the content), fixed to the viewport for the window. */
183
+ .scroll-strip {
184
+ position: sticky;
185
+ bottom: 0;
186
+ z-index: var(--z-sticky);
187
+ height: 0;
188
+ user-select: none;
189
+ }
190
+ .scroll-strip.fixed {
191
+ position: fixed;
192
+ inset-inline: 0;
193
+ }
194
+
195
+ .scroll-btn {
196
+ position: absolute;
197
+ bottom: var(--space-4);
198
+ display: inline-flex;
199
+ align-items: center;
200
+ justify-content: center;
201
+ gap: var(--space-2);
202
+ min-width: 36px;
203
+ min-height: 36px;
204
+ padding: 0;
205
+ border: 1px solid var(--line-float);
206
+ border-radius: var(--r-pill);
207
+ /* Floating, so opaque underneath: the control tint goes over the elevated surface, not over the page. */
208
+ background: var(--elevated);
209
+ box-shadow: var(--shadow);
210
+ color: var(--fg);
211
+ font-size: 13px;
212
+ font-weight: var(--w-medium);
213
+ line-height: 1;
214
+ white-space: nowrap;
215
+ cursor: pointer;
216
+ scale: 1;
217
+ transition: scale var(--dur) var(--ease-out);
218
+ }
219
+ .scroll-btn.end {
220
+ inset-inline-end: var(--space-4);
221
+ }
222
+ .scroll-btn.center {
223
+ left: 50%;
224
+ translate: -50% 0;
225
+ }
226
+ .scroll-btn.labelled {
227
+ padding-inline: var(--space-3) var(--space-4);
228
+ }
229
+ .scroll-btn:hover {
230
+ background: linear-gradient(var(--control-3), var(--control-3)), var(--elevated);
231
+ }
232
+ .scroll-btn:active {
233
+ background: linear-gradient(var(--control-4), var(--control-4)), var(--elevated);
234
+ scale: 0.96;
235
+ }
236
+
237
+ .glyph {
238
+ display: inline-grid;
239
+ place-items: center;
240
+ color: var(--muted);
241
+ transition: color var(--dur) var(--ease-out);
242
+ }
243
+ .scroll-btn:hover .glyph {
244
+ color: var(--fg);
245
+ }
246
+
247
+ /* The cue: the arrow drifts down and back, the way it asks you to go. Reduced motion stills it (base.css). */
248
+ .cue .glyph {
249
+ animation: scroll-cue 1.6s var(--ease-out) infinite;
250
+ }
251
+ @keyframes scroll-cue {
252
+ 0%,
253
+ 100% {
254
+ translate: 0 -1px;
255
+ }
256
+ 50% {
257
+ translate: 0 3px;
258
+ }
259
+ }
260
+ </style>
@@ -0,0 +1,61 @@
1
+ export default ScrollButton;
2
+ type ScrollButton = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
5
+ };
6
+ declare const ScrollButton: import("svelte").Component<{
7
+ label: string;
8
+ icon: string;
9
+ showLabel?: boolean | undefined;
10
+ align?: "end" | "center" | undefined;
11
+ target?: HTMLElement | Window | undefined;
12
+ shown: (metrics: {
13
+ top: number;
14
+ max: number;
15
+ page: number;
16
+ }) => boolean;
17
+ go: (scroller: HTMLElement | Window, metrics: {
18
+ top: number;
19
+ max: number;
20
+ page: number;
21
+ }, button: HTMLButtonElement) => void;
22
+ cue?: boolean | undefined;
23
+ keepFocused?: boolean | undefined;
24
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
25
+ label: string;
26
+ icon: string;
27
+ showLabel?: boolean | undefined;
28
+ align?: "end" | "center" | undefined;
29
+ target?: HTMLElement | Window | undefined;
30
+ shown: (metrics: {
31
+ top: number;
32
+ max: number;
33
+ page: number;
34
+ }) => boolean;
35
+ go: (scroller: HTMLElement | Window, metrics: {
36
+ top: number;
37
+ max: number;
38
+ page: number;
39
+ }, button: HTMLButtonElement) => void;
40
+ cue?: boolean | undefined;
41
+ keepFocused?: boolean | undefined;
42
+ }>, {}, "">;
43
+ type Props = {
44
+ label: string;
45
+ icon: string;
46
+ showLabel?: boolean | undefined;
47
+ align?: "end" | "center" | undefined;
48
+ target?: HTMLElement | Window | undefined;
49
+ shown: (metrics: {
50
+ top: number;
51
+ max: number;
52
+ page: number;
53
+ }) => boolean;
54
+ go: (scroller: HTMLElement | Window, metrics: {
55
+ top: number;
56
+ max: number;
57
+ page: number;
58
+ }, button: HTMLButtonElement) => void;
59
+ cue?: boolean | undefined;
60
+ keepFocused?: boolean | undefined;
61
+ };
@@ -0,0 +1,57 @@
1
+ <script>
2
+ /**
3
+ * A floating cue that there is more below: a round button with a gently bobbing down arrow, at the middle of a scroll
4
+ * area's bottom edge, while content runs on past it. Pressing it scrolls on by most of a screenful (or to the end, with
5
+ * `toEnd`). `showLabel` makes it a pill with the label beside the arrow.
6
+ *
7
+ * <div class="pane" style="overflow: auto">…long content… <ScrollMore /></div>
8
+ * <div class="log" style="overflow: auto">…messages… <ScrollMore until="end" toEnd showLabel label="Latest" /></div>
9
+ *
10
+ * Put it last inside the area it scrolls. It watches the nearest scrolling ancestor, or the window when there is none
11
+ * (portalled to <body>, over the viewport's bottom edge); `target` names another. In a scroll container it floats from
12
+ * a zero-height sticky strip, so it adds nothing to the content's height (a gap, in a flex or grid container with one).
13
+ * For a quieter hint with no button, fade the area's edge with the `scrollFade` attachment instead.
14
+ *
15
+ * label: its name (default 'More below'): the visible text with `showLabel`, else its aria-label and tooltip.
16
+ * showLabel: the pill with the label (default: the round icon-only button).
17
+ * until: 'scrolled' (default) shows it only until the area has been scrolled a little, a cue for a first look;
18
+ * 'end' shows it whenever more is below (a log or chat, where it means "there is newer below").
19
+ * toEnd: pressing goes to the end rather than a screenful on.
20
+ * align: 'center' (default) | 'end' (the bottom corner).
21
+ * target: the scroll area (an element, or window), if not the nearest scrolling ancestor.
22
+ * Other attributes, class and attachments go to the <button>.
23
+ *
24
+ * Scrolling is smooth, or instant under reduced motion, which also stills the arrow. Keyboard: Tab to it, Enter or
25
+ * Space; while it has the keyboard focus it stays, so it can be pressed again, and goes once the focus moves on.
26
+ */
27
+ import ScrollButton from './ScrollButton.svelte'
28
+ import { prefersReducedMotion } from 'svelte/motion'
29
+
30
+ /**
31
+ * @typedef {object} Props
32
+ * @property {string} [label]
33
+ * @property {boolean} [showLabel]
34
+ * @property {'scrolled' | 'end'} [until]
35
+ * @property {boolean} [toEnd]
36
+ * @property {'end' | 'center'} [align]
37
+ * @property {HTMLElement | Window} [target]
38
+ */
39
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
40
+ let { label = 'More below', until = 'scrolled', toEnd = false, align = 'center', ...rest } = $props()
41
+
42
+ /** Whether there is more below, and (until: 'scrolled') nobody has scrolled yet beyond a nudge. */
43
+ const shown = (/** @type {{ top: number, max: number, page: number }} */ m) =>
44
+ m.max - m.top > 2 && (until === 'end' || m.top < Math.min(m.page / 4, 120))
45
+
46
+ /**
47
+ * @param {HTMLElement | Window} scroller
48
+ * @param {{ top: number, max: number, page: number }} m
49
+ */
50
+ function onward(scroller, m) {
51
+ // Most of a screenful, so the last lines seen stay in view to read on from.
52
+ const top = toEnd ? m.max : Math.min(m.max, m.top + m.page * 0.85)
53
+ scroller.scrollTo({ top, behavior: prefersReducedMotion.current ? 'instant' : 'smooth' })
54
+ }
55
+ </script>
56
+
57
+ <ScrollButton {label} icon="arrowDownBold" {align} cue keepFocused {shown} go={onward} {...rest} />
@@ -0,0 +1,28 @@
1
+ export default ScrollMore;
2
+ type ScrollMore = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
5
+ };
6
+ declare const ScrollMore: import("svelte").Component<{
7
+ label?: string | undefined;
8
+ showLabel?: boolean | undefined;
9
+ until?: "end" | "scrolled" | undefined;
10
+ toEnd?: boolean | undefined;
11
+ align?: "end" | "center" | undefined;
12
+ target?: HTMLElement | Window | undefined;
13
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
14
+ label?: string | undefined;
15
+ showLabel?: boolean | undefined;
16
+ until?: "end" | "scrolled" | undefined;
17
+ toEnd?: boolean | undefined;
18
+ align?: "end" | "center" | undefined;
19
+ target?: HTMLElement | Window | undefined;
20
+ }>, {}, "">;
21
+ type Props = {
22
+ label?: string | undefined;
23
+ showLabel?: boolean | undefined;
24
+ until?: "end" | "scrolled" | undefined;
25
+ toEnd?: boolean | undefined;
26
+ align?: "end" | "center" | undefined;
27
+ target?: HTMLElement | Window | undefined;
28
+ };
@@ -0,0 +1,57 @@
1
+ <script>
2
+ /**
3
+ * A floating "back to top" button. It rises in at the bottom corner of a scroll area once you are a screenful down
4
+ * (or `after` px), and scrolls back to the top when pressed. A pill with an up arrow and its label. (Always labelled:
5
+ * ad and annoyance blockers hide icon-only buttons named "Back to top", so a round one could vanish for some users.)
6
+ *
7
+ * <main class="page">…long content… <ScrollToTop /></main>
8
+ * <div class="list" style="overflow: auto">…rows… <ScrollToTop label="Back to the first row" /></div>
9
+ *
10
+ * Put it last inside the area it scrolls. It watches the nearest scrolling ancestor, or the window when there is none
11
+ * (it then floats over the viewport's bottom corner, portalled to <body>); `target` names another. In a scroll
12
+ * container it floats from a zero-height sticky strip, so it adds nothing to the content's height (a gap, in a flex or
13
+ * grid container with one).
14
+ *
15
+ * label: its visible text (default 'Back to top').
16
+ * after: how far down, in px, it appears (default: one screenful of the area).
17
+ * align: 'end' (the bottom corner, default) | 'center'.
18
+ * target: the scroll area (an element, or window), if not the nearest scrolling ancestor.
19
+ * Other attributes, class and attachments go to the <button>.
20
+ *
21
+ * Scrolling is smooth, or instant under reduced motion. Keyboard: Tab to it, Enter or Space. The focus then moves to
22
+ * the first thing you can tab to in the area (the page, for the window), so Tab carries on from the top instead of
23
+ * from a button that has gone.
24
+ */
25
+ import ScrollButton from './ScrollButton.svelte'
26
+ import { prefersReducedMotion } from 'svelte/motion'
27
+
28
+ /**
29
+ * @typedef {object} Props
30
+ * @property {string} [label]
31
+ * @property {number} [after]
32
+ * @property {'end' | 'center'} [align]
33
+ * @property {HTMLElement | Window} [target]
34
+ */
35
+ /** @type {Props & Omit<import('svelte/elements').HTMLButtonAttributes, keyof Props>} */
36
+ let { label = 'Back to top', after, ...rest } = $props()
37
+
38
+ const TABBABLE =
39
+ 'a[href], button:not(:disabled), input:not(:disabled, [type="hidden"]), select:not(:disabled), textarea:not(:disabled), summary, [contenteditable=""], [contenteditable="true"], [tabindex]:not([tabindex="-1"])'
40
+
41
+ /**
42
+ * @param {HTMLElement | Window} scroller
43
+ * @param {{ top: number, max: number, page: number }} _metrics
44
+ * @param {HTMLButtonElement} button
45
+ */
46
+ function toTop(scroller, _metrics, button) {
47
+ scroller.scrollTo({ top: 0, behavior: prefersReducedMotion.current ? 'instant' : 'smooth' })
48
+ const area = scroller === window ? document.body : /** @type {HTMLElement} */ (scroller)
49
+ const first = [...area.querySelectorAll(TABBABLE)].find(
50
+ (el) => el !== button && el instanceof HTMLElement && !el.closest('[inert]') && el.checkVisibility(),
51
+ )
52
+ if (first instanceof HTMLElement) first.focus({ preventScroll: true })
53
+ else button.blur()
54
+ }
55
+ </script>
56
+
57
+ <ScrollButton {label} icon="arrowUpBold" shown={(m) => m.top > (after ?? m.page)} go={toTop} {...rest} showLabel />
@@ -0,0 +1,22 @@
1
+ export default ScrollToTop;
2
+ type ScrollToTop = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLButtonAttributes, keyof Props>>): void;
5
+ };
6
+ declare const ScrollToTop: import("svelte").Component<{
7
+ label?: string | undefined;
8
+ after?: number | undefined;
9
+ align?: "end" | "center" | undefined;
10
+ target?: HTMLElement | Window | undefined;
11
+ } & Omit<import("svelte/elements").HTMLButtonAttributes, keyof {
12
+ label?: string | undefined;
13
+ after?: number | undefined;
14
+ align?: "end" | "center" | undefined;
15
+ target?: HTMLElement | Window | undefined;
16
+ }>, {}, "">;
17
+ type Props = {
18
+ label?: string | undefined;
19
+ after?: number | undefined;
20
+ align?: "end" | "center" | undefined;
21
+ target?: HTMLElement | Window | undefined;
22
+ };
@@ -1,10 +1,8 @@
1
1
  /* Shared atoms: buttons, data tables, counts, tones, label chips, field labels, dots and modal dialogs. Anything bigger is a component. */
2
2
 
3
3
  /* ---------- controls ---------- */
4
- /* Linear's pill buttons: secondary is a translucent fill with an inset hairline; primary is solid indigo; icon buttons are ghost circles.
5
- The solid buttons (primary, danger) are raised: their top inner edge catches the light.
6
- A toggled secondary button (aria-pressed="true", Button's `pressed`) is flat: just its usual hairline, no fill at rest. It
7
- still fills on hover and press (the rules below outrank it), and its text stays --fg. */
4
+ /* Linear's pill buttons: secondary is a translucent fill with an inset hairline; primary is solid teal; icon buttons are ghost circles.
5
+ The solid buttons (primary, danger) are raised: their top inner edge catches the light. */
8
6
  .btn {
9
7
  display: inline-flex;
10
8
  align-items: center;
@@ -34,11 +32,6 @@
34
32
  filter var(--dur) var(--ease-out);
35
33
  }
36
34
 
37
- .btn:where([aria-pressed='true']) {
38
- background: none;
39
- box-shadow: none;
40
- }
41
-
42
35
  .btn :where(.icon) {
43
36
  color: var(--muted);
44
37
  transition: color var(--dur) var(--ease-out);
@@ -591,6 +584,15 @@
591
584
  width: min(var(--dialog-width, 420px), calc(100% - var(--space-8)));
592
585
  }
593
586
 
587
+ /* On a phone a question sits at the bottom of the screen, within the thumb's reach, and the full width less the gutters. */
588
+ @media (max-width: 860px) {
589
+ .dialog.confirm {
590
+ width: calc(100% - var(--space-8));
591
+ max-height: calc(100dvh - var(--space-8));
592
+ margin: auto auto var(--space-4);
593
+ }
594
+ }
595
+
594
596
  /* Only `display` depends on [open]: it is held through the closing transition, so the layout can't change mid-fade. */
595
597
  .dialog[open] {
596
598
  display: flex;
@@ -602,6 +604,8 @@
602
604
  var(--grain) 0 0 / 256px 256px,
603
605
  var(--scrim);
604
606
  backdrop-filter: blur(2px);
607
+ -webkit-user-select: none;
608
+ user-select: none;
605
609
  }
606
610
 
607
611
  .dialog-head {
package/dist/css/base.css CHANGED
@@ -294,8 +294,7 @@ kbd {
294
294
  [role='radio'][aria-checked='true'],
295
295
  [role='option'].active,
296
296
  [role^='menuitem']:focus,
297
- .icon-btn:is([aria-pressed='true'], [aria-expanded='true']),
298
- .btn[aria-pressed='true'] {
297
+ .icon-btn:is([aria-pressed='true'], [aria-expanded='true']) {
299
298
  background: Highlight !important;
300
299
  color: HighlightText !important;
301
300
  }