@mondarth/ui 0.0.0-stage → 0.8.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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/dist/AppShell.svelte +107 -0
  3. package/dist/AppShell.svelte.d.ts +14 -0
  4. package/dist/Badge.svelte +54 -0
  5. package/dist/Badge.svelte.d.ts +9 -0
  6. package/dist/Brand.svelte +62 -0
  7. package/dist/Brand.svelte.d.ts +14 -0
  8. package/dist/Button.svelte +73 -0
  9. package/dist/Button.svelte.d.ts +10 -0
  10. package/dist/Callout.svelte +40 -0
  11. package/dist/Callout.svelte.d.ts +9 -0
  12. package/dist/CalloutMark.svelte +104 -0
  13. package/dist/CalloutMark.svelte.d.ts +14 -0
  14. package/dist/Checkbox.svelte +60 -0
  15. package/dist/Checkbox.svelte.d.ts +15 -0
  16. package/dist/ContextMenu.svelte +151 -0
  17. package/dist/ContextMenu.svelte.d.ts +15 -0
  18. package/dist/Dialog.svelte +73 -0
  19. package/dist/Dialog.svelte.d.ts +14 -0
  20. package/dist/DrawerLayout.svelte +182 -0
  21. package/dist/DrawerLayout.svelte.d.ts +26 -0
  22. package/dist/DrawerToggle.svelte +66 -0
  23. package/dist/DrawerToggle.svelte.d.ts +11 -0
  24. package/dist/ExpandableList.svelte +164 -0
  25. package/dist/ExpandableList.svelte.d.ts +46 -0
  26. package/dist/Field.svelte +109 -0
  27. package/dist/Field.svelte.d.ts +28 -0
  28. package/dist/FooterLinks.svelte +54 -0
  29. package/dist/FooterLinks.svelte.d.ts +15 -0
  30. package/dist/LanguagePicker.svelte +48 -0
  31. package/dist/LanguagePicker.svelte.d.ts +33 -0
  32. package/dist/Logo.svelte +36 -0
  33. package/dist/Logo.svelte.d.ts +12 -0
  34. package/dist/Notice.svelte +116 -0
  35. package/dist/Notice.svelte.d.ts +13 -0
  36. package/dist/Panel.svelte +41 -0
  37. package/dist/Panel.svelte.d.ts +11 -0
  38. package/dist/Prose.svelte +23 -0
  39. package/dist/Prose.svelte.d.ts +8 -0
  40. package/dist/ReturnLink.svelte +50 -0
  41. package/dist/ReturnLink.svelte.d.ts +12 -0
  42. package/dist/SplitPanes.svelte +92 -0
  43. package/dist/SplitPanes.svelte.d.ts +21 -0
  44. package/dist/Splitter.svelte +160 -0
  45. package/dist/Splitter.svelte.d.ts +20 -0
  46. package/dist/Table.svelte +65 -0
  47. package/dist/Table.svelte.d.ts +12 -0
  48. package/dist/Toast.svelte +143 -0
  49. package/dist/Toast.svelte.d.ts +18 -0
  50. package/dist/TopBar.svelte +68 -0
  51. package/dist/TopBar.svelte.d.ts +19 -0
  52. package/dist/Tree.svelte +367 -0
  53. package/dist/Tree.svelte.d.ts +27 -0
  54. package/dist/UserMenu.svelte +209 -0
  55. package/dist/UserMenu.svelte.d.ts +10 -0
  56. package/dist/WarningMark.svelte +33 -0
  57. package/dist/WarningMark.svelte.d.ts +10 -0
  58. package/dist/context-menu.d.ts +41 -0
  59. package/dist/context-menu.js +80 -0
  60. package/dist/dates.d.ts +37 -0
  61. package/dist/dates.js +69 -0
  62. package/dist/index.d.ts +46 -0
  63. package/dist/index.js +42 -0
  64. package/dist/language.d.ts +7 -0
  65. package/dist/language.js +12 -0
  66. package/dist/remembered.d.ts +30 -0
  67. package/dist/remembered.js +50 -0
  68. package/dist/site.d.ts +7 -0
  69. package/dist/site.js +5 -0
  70. package/dist/theme.css +61 -0
  71. package/dist/top-bar.d.ts +29 -0
  72. package/dist/top-bar.js +2 -0
  73. package/dist/tree.d.ts +29 -0
  74. package/dist/tree.js +27 -0
  75. package/package.json +84 -3
  76. package/README.md +0 -3
@@ -0,0 +1,41 @@
1
+ <!--
2
+ A panel: a section of a page set apart on a surface, named by its heading, so that it is a landmark a screen reader
3
+ can go to. Use it for what needs setting apart, not for every block.
4
+ -->
5
+ <script lang="ts">
6
+ import type { Snippet } from 'svelte';
7
+
8
+ interface Props {
9
+ /** Its heading, which names it. */
10
+ heading: string;
11
+ /** The heading's level, under the page's title. */
12
+ level?: 2 | 3;
13
+ children: Snippet;
14
+ }
15
+
16
+ let { heading, level = 2, children }: Props = $props();
17
+ const headingId = $props.id();
18
+ </script>
19
+
20
+ <section class="panel" aria-labelledby={headingId}>
21
+ <svelte:element this={`h${String(level)}`} id={headingId}>{heading}</svelte:element>
22
+ {@render children()}
23
+ </section>
24
+
25
+ <style>
26
+ .panel {
27
+ display: grid;
28
+ gap: var(--mdr-space-3);
29
+ padding: var(--mdr-space-4) var(--mdr-space-5);
30
+ border: var(--mdr-border-width-thin) solid var(--mdr-color-border);
31
+ border-radius: var(--mdr-radius-small);
32
+ background: var(--mdr-color-surface);
33
+ }
34
+
35
+ .panel > :global(h2),
36
+ .panel > :global(h3) {
37
+ margin: 0;
38
+ font-size: var(--mdr-font-size-large);
39
+ line-height: var(--mdr-font-line-height-tight);
40
+ }
41
+ </style>
@@ -0,0 +1,11 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** Its heading, which names it. */
4
+ heading: string;
5
+ /** The heading's level, under the page's title. */
6
+ level?: 2 | 3;
7
+ children: Snippet;
8
+ }
9
+ declare const Panel: import("svelte").Component<Props, {}, "">;
10
+ type Panel = ReturnType<typeof Panel>;
11
+ export default Panel;
@@ -0,0 +1,23 @@
1
+ <!--
2
+ A page meant to be read, such as the Terms or what is stored: its text kept to a readable width (the tokens'
3
+ `layout.content`), in the middle of the application's full-width frame.
4
+ -->
5
+ <script lang="ts">
6
+ import type { Snippet } from 'svelte';
7
+
8
+ interface Props {
9
+ /** The text. */
10
+ children: Snippet;
11
+ }
12
+
13
+ let { children }: Props = $props();
14
+ </script>
15
+
16
+ <div class="prose">{@render children()}</div>
17
+
18
+ <style>
19
+ .prose {
20
+ max-width: var(--mdr-layout-content);
21
+ margin-inline: auto;
22
+ }
23
+ </style>
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** The text. */
4
+ children: Snippet;
5
+ }
6
+ declare const Prose: import("svelte").Component<Props, {}, "">;
7
+ type Prose = ReturnType<typeof Prose>;
8
+ export default Prose;
@@ -0,0 +1,50 @@
1
+ <!--
2
+ The way back to another Mondarth website, for a visitor who came from one: its logo and "Back to …", in the site's
3
+ colour as text, so that they know at once where it goes. It marks itself with its site, so that its colours are its
4
+ own wherever it is.
5
+ -->
6
+ <script lang="ts">
7
+ import type { Site } from './site.js';
8
+ import Logo from './Logo.svelte';
9
+
10
+ interface Props {
11
+ /** Where it goes. */
12
+ href: string;
13
+ /** Which site it goes back to. */
14
+ site: Site;
15
+ /** What it says, such as "Back to the Catalogue". */
16
+ label: string;
17
+ }
18
+
19
+ let { href, site, label }: Props = $props();
20
+ </script>
21
+
22
+ <a class="return" {href} data-site={site}>
23
+ <span class="arrow" aria-hidden="true">←</span>
24
+ <Logo {site} height="1.5rem" />
25
+ <span>{label}</span>
26
+ </a>
27
+
28
+ <style>
29
+ .return {
30
+ display: inline-flex;
31
+ gap: var(--mdr-space-2);
32
+ align-items: center;
33
+ padding: var(--mdr-space-1) var(--mdr-space-3) var(--mdr-space-1) var(--mdr-space-2);
34
+ border: var(--mdr-border-width-thin) solid var(--mdr-color-border-strong);
35
+ border-radius: var(--mdr-radius-pill);
36
+ color: var(--mdr-color-site-text);
37
+ font-weight: var(--mdr-font-weight-strong);
38
+ text-decoration: none;
39
+ }
40
+
41
+ .return:hover,
42
+ .return:focus-visible {
43
+ border-color: var(--mdr-color-site-text);
44
+ }
45
+
46
+ .return:focus-visible {
47
+ outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
48
+ outline-offset: 2px;
49
+ }
50
+ </style>
@@ -0,0 +1,12 @@
1
+ import type { Site } from './site.js';
2
+ interface Props {
3
+ /** Where it goes. */
4
+ href: string;
5
+ /** Which site it goes back to. */
6
+ site: Site;
7
+ /** What it says, such as "Back to the Catalogue". */
8
+ label: string;
9
+ }
10
+ declare const ReturnLink: import("svelte").Component<Props, {}, "">;
11
+ type ReturnLink = ReturnType<typeof ReturnLink>;
12
+ export default ReturnLink;
@@ -0,0 +1,92 @@
1
+ <!--
2
+ Two panes that share the space they are given, side by side (`columns`) or one above the other (`rows`), with a
3
+ splitter between them that the user drags, or moves from the keyboard, to share it otherwise: the parts of an
4
+ application's workspace. Nested, they make more. Without a first pane, the second has it all, with no splitter, as
5
+ while what goes in the first is not shown, such as what is only for those signed in. With a `storageKey`, the share is
6
+ remembered in this browser.
7
+ -->
8
+ <script lang="ts">
9
+ import { onMount } from 'svelte';
10
+
11
+ import { isNumber, recall, remember } from './remembered.js';
12
+ import Splitter from './Splitter.svelte';
13
+
14
+ import type { Snippet } from 'svelte';
15
+
16
+ interface Props {
17
+ /** `columns`, side by side, or `rows`, one above the other. */
18
+ direction: 'columns' | 'rows';
19
+ /** The first pane's share of the space, from 0 to 1. */
20
+ share?: number;
21
+ /** The least and most the first pane may have. */
22
+ min?: number;
23
+ max?: number;
24
+ /** What the splitter does, for assistive technology, such as "Resize the projects". */
25
+ label: string;
26
+ /** Where this browser remembers the share; none, and nothing is remembered. */
27
+ storageKey?: string | undefined;
28
+ /** The first pane: left, or above; none, and the second has all the space. */
29
+ first?: Snippet | undefined;
30
+ /** The second pane: right, or below. */
31
+ second: Snippet;
32
+ }
33
+
34
+ let { direction, share = $bindable(0.5), min = 0.15, max = 0.85, label, storageKey, first, second }: Props = $props();
35
+
36
+ const firstId = $props.id();
37
+ /** Whether what was remembered has been read: until then nothing is written, so it is not overwritten. */
38
+ let recalled = $state(false);
39
+
40
+ onMount(() => {
41
+ const kept = storageKey === undefined ? undefined : recall(`${storageKey}:share`, isNumber);
42
+ if (kept !== undefined) share = Math.min(max, Math.max(min, kept));
43
+ recalled = true;
44
+ });
45
+
46
+ $effect(() => {
47
+ if (recalled && storageKey !== undefined) remember(`${storageKey}:share`, share);
48
+ });
49
+ </script>
50
+
51
+ <div class={['panes', direction]}>
52
+ {#if first !== undefined}
53
+ <div class="pane" id={firstId} style:flex-basis="{share * 100}%">{@render first()}</div>
54
+ <Splitter
55
+ orientation={direction === 'columns' ? 'vertical' : 'horizontal'}
56
+ scale="share"
57
+ sizes="before"
58
+ value={share}
59
+ {min}
60
+ {max}
61
+ {label}
62
+ controls={firstId}
63
+ onChange={(size: number) => {
64
+ share = size;
65
+ }} />
66
+ {/if}
67
+ <div class={['pane', 'rest']}>{@render second()}</div>
68
+ </div>
69
+
70
+ <style>
71
+ .panes {
72
+ display: flex;
73
+ height: 100%;
74
+ min-width: 0;
75
+ min-height: 0;
76
+ }
77
+
78
+ .rows {
79
+ flex-direction: column;
80
+ }
81
+
82
+ .pane {
83
+ flex: none;
84
+ min-width: 0;
85
+ min-height: 0;
86
+ overflow: auto;
87
+ }
88
+
89
+ .rest {
90
+ flex: 1;
91
+ }
92
+ </style>
@@ -0,0 +1,21 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** `columns`, side by side, or `rows`, one above the other. */
4
+ direction: 'columns' | 'rows';
5
+ /** The first pane's share of the space, from 0 to 1. */
6
+ share?: number;
7
+ /** The least and most the first pane may have. */
8
+ min?: number;
9
+ max?: number;
10
+ /** What the splitter does, for assistive technology, such as "Resize the projects". */
11
+ label: string;
12
+ /** Where this browser remembers the share; none, and nothing is remembered. */
13
+ storageKey?: string | undefined;
14
+ /** The first pane: left, or above; none, and the second has all the space. */
15
+ first?: Snippet | undefined;
16
+ /** The second pane: right, or below. */
17
+ second: Snippet;
18
+ }
19
+ declare const SplitPanes: import("svelte").Component<Props, {}, "share">;
20
+ type SplitPanes = ReturnType<typeof SplitPanes>;
21
+ export default SplitPanes;
@@ -0,0 +1,160 @@
1
+ <!--
2
+ A handle between two parts of a layout that resizes them, by dragging it or from the keyboard, as the ARIA window
3
+ splitter pattern has it: the arrow keys move it a step (a bigger one with Shift), and Home and End to its limits. It
4
+ sizes the part before it (left or above) or after it (right or below), in one of two scales: a share of the element
5
+ it is in, so that panels keep their shares as the window is resized, or pixels, so that a drawer keeps its width.
6
+ -->
7
+ <script lang="ts">
8
+ interface Props {
9
+ /** `vertical` between parts side by side, resizing their widths; `horizontal` between parts one above the other. */
10
+ orientation: 'vertical' | 'horizontal';
11
+ /** The size of the part it sizes: a share of the element it is in, from 0 to 1, or pixels. */
12
+ value: number;
13
+ /** Which scale the value is in. */
14
+ scale: 'share' | 'pixels';
15
+ /** Whether the part it sizes is the one before it or the one after it. */
16
+ sizes: 'before' | 'after';
17
+ min: number;
18
+ max: number;
19
+ /** What it resizes, for assistive technology, such as "Resize the filters". */
20
+ label: string;
21
+ /** The id of the part it sizes, for assistive technology. */
22
+ controls?: string | undefined;
23
+ onChange: (value: number) => void;
24
+ }
25
+
26
+ let { orientation, value, scale, sizes, min, max, label, controls, onChange }: Props = $props();
27
+
28
+ /** How far an arrow key moves it, in each scale; Shift moves it four times as far. */
29
+ const STEPS = { share: 0.02, pixels: 16 } as const;
30
+
31
+ let dragging = $state(false);
32
+
33
+ /**
34
+ * Keep a value within the limits.
35
+ * @param size - The value
36
+ * @returns The value, within them
37
+ */
38
+ const clamp = (size: number): number => Math.min(max, Math.max(min, size));
39
+
40
+ /**
41
+ * The size a pointer at a point gives the part it sizes, in its scale.
42
+ * @param event - The pointer, on the handle
43
+ * @returns The size, or `undefined` if the element it is in has no size, as while it is hidden
44
+ */
45
+ function sizeAt(event: PointerEvent & { currentTarget: HTMLElement }): number | undefined {
46
+ const handle = event.currentTarget;
47
+ const rect = (handle.parentElement ?? handle).getBoundingClientRect();
48
+ const [at, start, size] =
49
+ orientation === 'vertical' ? [event.clientX, rect.left, rect.width] : [event.clientY, rect.top, rect.height];
50
+ if (size <= 0) return undefined;
51
+ const before = at - start;
52
+ const pixels = sizes === 'before' ? before : size - before;
53
+ return scale === 'pixels' ? pixels : pixels / size;
54
+ }
55
+
56
+ /**
57
+ * Follow the pointer while it drags the handle.
58
+ * @param event - The pointer
59
+ */
60
+ function onPointerMove(event: PointerEvent & { currentTarget: HTMLElement }): void {
61
+ if (!dragging) return;
62
+ const size = sizeAt(event);
63
+ if (size !== undefined) onChange(clamp(size));
64
+ }
65
+
66
+ /**
67
+ * Move the handle from the keyboard.
68
+ * @param event - The key
69
+ */
70
+ function onKeydown(event: KeyboardEvent): void {
71
+ const [less, more] = orientation === 'vertical' ? ['ArrowLeft', 'ArrowRight'] : ['ArrowUp', 'ArrowDown'];
72
+ // Moving the handle towards the end grows the part before it, and shrinks the one after it.
73
+ const grow = sizes === 'before' ? more : less;
74
+ const shrink = sizes === 'before' ? less : more;
75
+ const step = STEPS[scale] * (event.shiftKey ? 4 : 1);
76
+ let next: number | undefined;
77
+ if (event.key === grow) next = value + step;
78
+ else if (event.key === shrink) next = value - step;
79
+ else if (event.key === 'Home') next = min;
80
+ else if (event.key === 'End') next = max;
81
+ if (next === undefined) return;
82
+ event.preventDefault();
83
+ onChange(clamp(next));
84
+ }
85
+
86
+ /** The value as assistive technology reads it: a percentage for a share, pixels for pixels. */
87
+ const spoken = (size: number) => Math.round(scale === 'share' ? size * 100 : size);
88
+ </script>
89
+
90
+ <!--
91
+ A focusable separator is a widget, as the ARIA window splitter pattern has it, though Svelte counts the role as static.
92
+ -->
93
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex, a11y_no_noninteractive_element_interactions -->
94
+ <div
95
+ class={['splitter', orientation, { dragging }]}
96
+ role="separator"
97
+ tabindex="0"
98
+ aria-label={label}
99
+ aria-controls={controls}
100
+ aria-orientation={orientation}
101
+ aria-valuenow={spoken(value)}
102
+ aria-valuemin={spoken(min)}
103
+ aria-valuemax={spoken(max)}
104
+ onkeydown={onKeydown}
105
+ onpointerdown={event => {
106
+ event.preventDefault();
107
+ dragging = true;
108
+ // Captured, the handle follows the pointer off it; a pointer the browser does not know of drags it while over it.
109
+ try {
110
+ event.currentTarget.setPointerCapture(event.pointerId);
111
+ } catch {
112
+ // Dragging goes on without the capture.
113
+ }
114
+ }}
115
+ onpointermove={onPointerMove}
116
+ onpointerup={() => {
117
+ // The capture ends with the pointer's release.
118
+ dragging = false;
119
+ }}
120
+ onpointercancel={() => {
121
+ dragging = false;
122
+ }}>
123
+ </div>
124
+
125
+ <style>
126
+ /* A thin rule, with room around it to take the pointer; it shows the accent while hovered, focused or dragged. */
127
+ .splitter {
128
+ position: relative;
129
+ flex: none;
130
+ background: var(--mdr-color-border);
131
+ touch-action: none;
132
+ }
133
+
134
+ .splitter::after {
135
+ content: '';
136
+ position: absolute;
137
+ inset: calc(-1 * var(--mdr-space-1));
138
+ }
139
+
140
+ .splitter:hover,
141
+ .splitter.dragging {
142
+ background: var(--mdr-color-accent);
143
+ }
144
+
145
+ .splitter:focus-visible {
146
+ background: var(--mdr-color-accent);
147
+ outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
148
+ outline-offset: var(--mdr-border-width-thin);
149
+ }
150
+
151
+ .vertical {
152
+ width: var(--mdr-border-width-rule);
153
+ cursor: col-resize;
154
+ }
155
+
156
+ .horizontal {
157
+ height: var(--mdr-border-width-rule);
158
+ cursor: row-resize;
159
+ }
160
+ </style>
@@ -0,0 +1,20 @@
1
+ interface Props {
2
+ /** `vertical` between parts side by side, resizing their widths; `horizontal` between parts one above the other. */
3
+ orientation: 'vertical' | 'horizontal';
4
+ /** The size of the part it sizes: a share of the element it is in, from 0 to 1, or pixels. */
5
+ value: number;
6
+ /** Which scale the value is in. */
7
+ scale: 'share' | 'pixels';
8
+ /** Whether the part it sizes is the one before it or the one after it. */
9
+ sizes: 'before' | 'after';
10
+ min: number;
11
+ max: number;
12
+ /** What it resizes, for assistive technology, such as "Resize the filters". */
13
+ label: string;
14
+ /** The id of the part it sizes, for assistive technology. */
15
+ controls?: string | undefined;
16
+ onChange: (value: number) => void;
17
+ }
18
+ declare const Splitter: import("svelte").Component<Props, {}, "">;
19
+ type Splitter = ReturnType<typeof Splitter>;
20
+ export default Splitter;
@@ -0,0 +1,65 @@
1
+ <!--
2
+ A table of data: the page writes its rows and columns; this sets them out, and lets a wide one scroll sideways in
3
+ its own box rather than the page. Its caption names it, shown or for screen readers alone.
4
+ -->
5
+ <script lang="ts">
6
+ import type { Snippet } from 'svelte';
7
+
8
+ interface Props {
9
+ /** What the table is. */
10
+ caption: string;
11
+ /** Whether the caption is for screen readers alone, as where a heading says it already. */
12
+ hideCaption?: boolean;
13
+ /** Its `<thead>` and `<tbody>`. */
14
+ children: Snippet;
15
+ }
16
+
17
+ let { caption, hideCaption = false, children }: Props = $props();
18
+ </script>
19
+
20
+ <!--
21
+ A wide table scrolls in its own box, which a keyboard must reach to scroll it (axe's scrollable-region-focusable): in
22
+ the tab order, and named as the table is. A group, not a region: a landmark of the same name as the section it is in,
23
+ as where a heading names both, would be one a screen reader lists twice.
24
+ -->
25
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
26
+ <div class="scroll" role="group" aria-label={caption} tabindex="0">
27
+ <table>
28
+ <caption class:mdr-visually-hidden={hideCaption}>{caption}</caption>
29
+ {@render children()}
30
+ </table>
31
+ </div>
32
+
33
+ <style>
34
+ .scroll {
35
+ max-width: 100%;
36
+ overflow-x: auto;
37
+ }
38
+
39
+ table {
40
+ width: 100%;
41
+ border-collapse: collapse;
42
+ font-size: var(--mdr-font-size-small);
43
+ font-variant-numeric: tabular-nums;
44
+ }
45
+
46
+ caption {
47
+ padding-block-end: var(--mdr-space-2);
48
+ color: var(--mdr-color-text-muted);
49
+ text-align: start;
50
+ }
51
+
52
+ table :global(th),
53
+ table :global(td) {
54
+ padding: var(--mdr-space-2) var(--mdr-space-3);
55
+ border-bottom: var(--mdr-border-width-thin) solid var(--mdr-color-border);
56
+ text-align: start;
57
+ vertical-align: top;
58
+ }
59
+
60
+ table :global(thead th) {
61
+ background: var(--mdr-color-subtle);
62
+ font-weight: var(--mdr-font-weight-strong);
63
+ white-space: nowrap;
64
+ }
65
+ </style>
@@ -0,0 +1,12 @@
1
+ import type { Snippet } from 'svelte';
2
+ interface Props {
3
+ /** What the table is. */
4
+ caption: string;
5
+ /** Whether the caption is for screen readers alone, as where a heading says it already. */
6
+ hideCaption?: boolean;
7
+ /** Its `<thead>` and `<tbody>`. */
8
+ children: Snippet;
9
+ }
10
+ declare const Table: import("svelte").Component<Props, {}, "">;
11
+ type Table = ReturnType<typeof Table>;
12
+ export default Table;
@@ -0,0 +1,143 @@
1
+ <!--
2
+ A brief message at the foot of the window, for what was just done, with an action that undoes it, say: announced
3
+ politely, as a status, and gone by itself after a few seconds, unless the pointer or the focus is on it, or at once
4
+ when dismissed or its action is taken. Its words, its action's and its dismissing button's, are the application's.
5
+ -->
6
+ <script lang="ts">
7
+ interface Props {
8
+ /** Whether it shows. */
9
+ open?: boolean;
10
+ /** What it says, such as "Saved Filter 2 deleted". */
11
+ message: string;
12
+ /** What can be done about it, such as undoing it; it closes the toast. */
13
+ action?: { readonly label: string; readonly onAction: () => void } | undefined;
14
+ /** What the button that dismisses it says to a screen reader, such as "Dismiss". */
15
+ dismissLabel: string;
16
+ /** How long it shows, in milliseconds, while nothing is on it. */
17
+ duration?: number;
18
+ }
19
+
20
+ let { open = $bindable(false), message, action, dismissLabel, duration = 6000 }: Props = $props();
21
+
22
+ /** Whether the pointer or the focus is on it, which keeps it. */
23
+ let held = $state(false);
24
+
25
+ $effect(() => {
26
+ if (!open || held) return;
27
+ const timer = setTimeout(() => {
28
+ open = false;
29
+ }, duration);
30
+ return () => {
31
+ clearTimeout(timer);
32
+ };
33
+ });
34
+ </script>
35
+
36
+ <!-- The status is there before its message, so that a screen reader announces the message as it comes. -->
37
+ <div class="region" role="status">
38
+ {#if open}
39
+ <div
40
+ class="toast"
41
+ role="presentation"
42
+ onpointerenter={() => {
43
+ held = true;
44
+ }}
45
+ onpointerleave={() => {
46
+ held = false;
47
+ }}
48
+ onfocusin={() => {
49
+ held = true;
50
+ }}
51
+ onfocusout={() => {
52
+ held = false;
53
+ }}>
54
+ <span class="message">{message}</span>
55
+ {#if action}
56
+ <button
57
+ type="button"
58
+ class="action"
59
+ onclick={() => {
60
+ open = false;
61
+ held = false;
62
+ action.onAction();
63
+ }}>
64
+ {action.label}
65
+ </button>
66
+ {/if}
67
+ <button
68
+ type="button"
69
+ class="dismiss"
70
+ aria-label={dismissLabel}
71
+ title={dismissLabel}
72
+ onclick={() => {
73
+ open = false;
74
+ held = false;
75
+ }}>
76
+ <svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true">
77
+ <path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="1.75" />
78
+ </svg>
79
+ </button>
80
+ </div>
81
+ {/if}
82
+ </div>
83
+
84
+ <style>
85
+ /* At the foot of the window, in the middle, over the page. */
86
+ .region {
87
+ position: fixed;
88
+ z-index: 10;
89
+ inset-inline: 0;
90
+ bottom: var(--mdr-space-5);
91
+ display: flex;
92
+ justify-content: center;
93
+ pointer-events: none;
94
+ }
95
+
96
+ .toast {
97
+ display: flex;
98
+ gap: var(--mdr-space-3);
99
+ align-items: center;
100
+ max-width: min(32rem, calc(100% - 2 * var(--mdr-space-4)));
101
+ padding: var(--mdr-space-2) var(--mdr-space-2) var(--mdr-space-2) var(--mdr-space-4);
102
+ border-radius: var(--mdr-radius-small);
103
+ background: var(--mdr-color-text);
104
+ color: var(--mdr-color-background);
105
+ pointer-events: auto;
106
+ }
107
+
108
+ .message {
109
+ flex: 1;
110
+ }
111
+
112
+ .action,
113
+ .dismiss {
114
+ padding: var(--mdr-space-1) var(--mdr-space-2);
115
+ border: none;
116
+ border-radius: var(--mdr-radius-small);
117
+ background: none;
118
+ color: inherit;
119
+ font: inherit;
120
+ cursor: pointer;
121
+ }
122
+
123
+ .action {
124
+ font-weight: var(--mdr-font-weight-strong);
125
+ text-decoration: underline;
126
+ }
127
+
128
+ .dismiss {
129
+ display: inline-grid;
130
+ place-items: center;
131
+ }
132
+
133
+ .action:hover,
134
+ .dismiss:hover {
135
+ background: color-mix(in srgb, currentColor 15%, transparent);
136
+ }
137
+
138
+ .action:focus-visible,
139
+ .dismiss:focus-visible {
140
+ outline: var(--mdr-border-width-focus) solid var(--mdr-color-focus);
141
+ outline-offset: var(--mdr-border-width-thin);
142
+ }
143
+ </style>
@@ -0,0 +1,18 @@
1
+ interface Props {
2
+ /** Whether it shows. */
3
+ open?: boolean;
4
+ /** What it says, such as "Saved Filter 2 deleted". */
5
+ message: string;
6
+ /** What can be done about it, such as undoing it; it closes the toast. */
7
+ action?: {
8
+ readonly label: string;
9
+ readonly onAction: () => void;
10
+ } | undefined;
11
+ /** What the button that dismisses it says to a screen reader, such as "Dismiss". */
12
+ dismissLabel: string;
13
+ /** How long it shows, in milliseconds, while nothing is on it. */
14
+ duration?: number;
15
+ }
16
+ declare const Toast: import("svelte").Component<Props, {}, "open">;
17
+ type Toast = ReturnType<typeof Toast>;
18
+ export default Toast;