@xds/svelte 0.0.0-stage → 0.2.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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/Accordion.svelte +89 -0
  4. package/dist/Accordion.svelte.d.ts +43 -0
  5. package/dist/AccordionPanel.svelte +40 -0
  6. package/dist/AccordionPanel.svelte.d.ts +15 -0
  7. package/dist/Avatar.svelte +45 -0
  8. package/dist/Avatar.svelte.d.ts +11 -0
  9. package/dist/AvatarStack.svelte +49 -0
  10. package/dist/AvatarStack.svelte.d.ts +10 -0
  11. package/dist/Badge.svelte +36 -0
  12. package/dist/Badge.svelte.d.ts +15 -0
  13. package/dist/Banner.svelte +88 -0
  14. package/dist/Banner.svelte.d.ts +25 -0
  15. package/dist/Button.svelte +90 -0
  16. package/dist/Button.svelte.d.ts +16 -0
  17. package/dist/Card.svelte +99 -0
  18. package/dist/Card.svelte.d.ts +20 -0
  19. package/dist/Checkbox.svelte +68 -0
  20. package/dist/Checkbox.svelte.d.ts +12 -0
  21. package/dist/Chip.svelte +43 -0
  22. package/dist/Chip.svelte.d.ts +14 -0
  23. package/dist/ChipBar.svelte +32 -0
  24. package/dist/ChipBar.svelte.d.ts +14 -0
  25. package/dist/CountBadge.svelte +50 -0
  26. package/dist/CountBadge.svelte.d.ts +14 -0
  27. package/dist/DatePicker.svelte +178 -0
  28. package/dist/DatePicker.svelte.d.ts +22 -0
  29. package/dist/DateRangePicker.svelte +264 -0
  30. package/dist/DateRangePicker.svelte.d.ts +25 -0
  31. package/dist/Defaults.svelte +29 -0
  32. package/dist/Defaults.svelte.d.ts +17 -0
  33. package/dist/Dialog.svelte +104 -0
  34. package/dist/Dialog.svelte.d.ts +22 -0
  35. package/dist/Divider.svelte +17 -0
  36. package/dist/Divider.svelte.d.ts +6 -0
  37. package/dist/EmptyState.svelte +34 -0
  38. package/dist/EmptyState.svelte.d.ts +14 -0
  39. package/dist/Icon.svelte +38 -0
  40. package/dist/Icon.svelte.d.ts +10 -0
  41. package/dist/IconButton.svelte +67 -0
  42. package/dist/IconButton.svelte.d.ts +13 -0
  43. package/dist/ListRow.svelte +29 -0
  44. package/dist/ListRow.svelte.d.ts +15 -0
  45. package/dist/MediaCard.svelte +112 -0
  46. package/dist/MediaCard.svelte.d.ts +22 -0
  47. package/dist/Menu.svelte +156 -0
  48. package/dist/Menu.svelte.d.ts +19 -0
  49. package/dist/PlaceRow.svelte +66 -0
  50. package/dist/PlaceRow.svelte.d.ts +12 -0
  51. package/dist/Portal.svelte +27 -0
  52. package/dist/Portal.svelte.d.ts +15 -0
  53. package/dist/ProgressBar.svelte +37 -0
  54. package/dist/ProgressBar.svelte.d.ts +10 -0
  55. package/dist/RadioGroup.svelte +114 -0
  56. package/dist/RadioGroup.svelte.d.ts +38 -0
  57. package/dist/SearchField.svelte +93 -0
  58. package/dist/SearchField.svelte.d.ts +17 -0
  59. package/dist/SectionHeader.svelte +56 -0
  60. package/dist/SectionHeader.svelte.d.ts +16 -0
  61. package/dist/SegmentedControl.svelte +70 -0
  62. package/dist/SegmentedControl.svelte.d.ts +35 -0
  63. package/dist/Select.svelte +214 -0
  64. package/dist/Select.svelte.d.ts +40 -0
  65. package/dist/Sidebar.svelte +125 -0
  66. package/dist/Sidebar.svelte.d.ts +43 -0
  67. package/dist/SidebarRailButton.svelte +29 -0
  68. package/dist/SidebarRailButton.svelte.d.ts +14 -0
  69. package/dist/Skeleton.svelte +34 -0
  70. package/dist/Skeleton.svelte.d.ts +13 -0
  71. package/dist/Slider.svelte +111 -0
  72. package/dist/Slider.svelte.d.ts +15 -0
  73. package/dist/Spinner.svelte +35 -0
  74. package/dist/Spinner.svelte.d.ts +11 -0
  75. package/dist/Switch.svelte +60 -0
  76. package/dist/Switch.svelte.d.ts +15 -0
  77. package/dist/Tabs.svelte +65 -0
  78. package/dist/Tabs.svelte.d.ts +36 -0
  79. package/dist/Text.svelte +36 -0
  80. package/dist/Text.svelte.d.ts +11 -0
  81. package/dist/TextField.svelte +163 -0
  82. package/dist/TextField.svelte.d.ts +23 -0
  83. package/dist/Thumbnail.svelte +81 -0
  84. package/dist/Thumbnail.svelte.d.ts +11 -0
  85. package/dist/Toast.svelte +83 -0
  86. package/dist/Toast.svelte.d.ts +17 -0
  87. package/dist/Tooltip.svelte +40 -0
  88. package/dist/Tooltip.svelte.d.ts +19 -0
  89. package/dist/TooltipOverlay.svelte +66 -0
  90. package/dist/TooltipOverlay.svelte.d.ts +17 -0
  91. package/dist/controlled.d.ts +4 -0
  92. package/dist/controlled.js +23 -0
  93. package/dist/defaults.svelte.d.ts +12 -0
  94. package/dist/defaults.svelte.js +25 -0
  95. package/dist/index.d.ts +41 -0
  96. package/dist/index.js +47 -0
  97. package/dist/modal-popover.svelte.d.ts +8 -0
  98. package/dist/modal-popover.svelte.js +22 -0
  99. package/dist/picture.svelte.d.ts +19 -0
  100. package/dist/picture.svelte.js +18 -0
  101. package/dist/presence.svelte.d.ts +6 -0
  102. package/dist/presence.svelte.js +19 -0
  103. package/dist/preview/Component.svelte +56 -0
  104. package/dist/preview/Component.svelte.d.ts +15 -0
  105. package/dist/preview/Draw.svelte +65 -0
  106. package/dist/preview/Draw.svelte.d.ts +15 -0
  107. package/dist/preview/Preview.svelte +41 -0
  108. package/dist/preview/Preview.svelte.d.ts +13 -0
  109. package/dist/preview/Snippets.svelte +36 -0
  110. package/dist/preview/Snippets.svelte.d.ts +19 -0
  111. package/dist/preview/components.js +48 -0
  112. package/dist/preview/index.d.ts +2 -0
  113. package/dist/preview/index.js +4 -0
  114. package/dist/root.d.ts +11 -0
  115. package/dist/root.js +1 -0
  116. package/dist/styles/index.css +5 -0
  117. package/dist/trigger.svelte.d.ts +21 -0
  118. package/dist/trigger.svelte.js +48 -0
  119. package/package.json +62 -4
  120. package/page.css +20 -0
  121. package/styles.css +3354 -0
  122. package/tailwind.css +2665 -0
@@ -0,0 +1,163 @@
1
+ <!--
2
+ @component
3
+ A labelled text field, of one line or several. The label, the description and the error message
4
+ are tied to the input for assistive technology, and the error is announced when it appears.
5
+
6
+ An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
7
+ the person edits the value.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { TextFieldBaseProps } from "@xds/core";
11
+ import type { Snippet } from "svelte";
12
+ import type { RootProps } from "./root.js";
13
+
14
+ export type TextFieldProps = TextFieldBaseProps &
15
+ RootProps & {
16
+ onChange: (value: string) => void;
17
+ /**
18
+ * Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
19
+ * unless it sets its own.
20
+ */
21
+ leading?: Snippet;
22
+ /** Inside the box, after the text: an icon, a unit, a small button. */
23
+ trailing?: Snippet;
24
+ };
25
+ </script>
26
+
27
+ <script lang="ts">
28
+ import { classes } from "@xds/core";
29
+ import { untrack } from "svelte";
30
+ import type { Attachment } from "svelte/attachments";
31
+ import { keepValue } from "./controlled.js";
32
+
33
+ let {
34
+ label,
35
+ value,
36
+ description,
37
+ error,
38
+ placeholder,
39
+ multiline,
40
+ rows = 3,
41
+ maxLength,
42
+ name,
43
+ type = "text",
44
+ inputMode,
45
+ autoComplete,
46
+ autoFocus,
47
+ required,
48
+ disabled,
49
+ onChange,
50
+ leading,
51
+ trailing,
52
+ class: className,
53
+ style,
54
+ }: TextFieldProps = $props();
55
+
56
+ const id = $props.id();
57
+ const descriptionId = `${id}-description`;
58
+ const errorId = `${id}-error`;
59
+ const invalid = $derived(error !== undefined);
60
+ const describedBy = $derived(invalid ? errorId : description ? descriptionId : undefined);
61
+
62
+ // Once the field is on the page.
63
+ const settle: Attachment<HTMLInputElement | HTMLTextAreaElement> = (input) => {
64
+ // The value is set as a property, which leaves a text area's caret after the last line,
65
+ // and keyboard focus would then scroll to it. React renders the first value as the text
66
+ // area's own text, with the caret before the first line.
67
+ if (input instanceof HTMLTextAreaElement) input.setSelectionRange(0, 0);
68
+ if (untrack(() => autoFocus)) input.focus();
69
+ };
70
+
71
+ function oninput(event: Event & { currentTarget: HTMLInputElement | HTMLTextAreaElement }) {
72
+ onChange(event.currentTarget.value);
73
+ // While a composition is open the text belongs to the input method; it ends with
74
+ // compositionend.
75
+ if (!(event instanceof InputEvent && event.isComposing))
76
+ keepValue(event.currentTarget, () => value);
77
+ }
78
+
79
+ function oncompositionend(
80
+ event: CompositionEvent & { currentTarget: HTMLInputElement | HTMLTextAreaElement },
81
+ ) {
82
+ keepValue(event.currentTarget, () => value);
83
+ }
84
+ </script>
85
+
86
+ <!-- The input draws the box itself until something sits inside the box beside the text. -->
87
+ {#snippet field(box: boolean)}
88
+ {#if multiline}
89
+ <textarea
90
+ {@attach settle}
91
+ {rows}
92
+ {id}
93
+ class={box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input"}
94
+ {value}
95
+ defaultValue={value}
96
+ {placeholder}
97
+ {name}
98
+ maxlength={maxLength}
99
+ inputmode={inputMode}
100
+ autocomplete={autoComplete as HTMLTextAreaElement["autocomplete"]}
101
+ {required}
102
+ {disabled}
103
+ aria-invalid={invalid ? "true" : undefined}
104
+ aria-errormessage={invalid ? errorId : undefined}
105
+ aria-describedby={describedBy}
106
+ {oninput}
107
+ {oncompositionend}></textarea>
108
+ {:else}
109
+ <input
110
+ {@attach settle}
111
+ {type}
112
+ {id}
113
+ class={box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input"}
114
+ {value}
115
+ defaultValue={value}
116
+ {placeholder}
117
+ {name}
118
+ maxlength={maxLength}
119
+ inputmode={inputMode}
120
+ autocomplete={autoComplete as HTMLInputElement["autocomplete"]}
121
+ {required}
122
+ {disabled}
123
+ aria-invalid={invalid ? "true" : undefined}
124
+ aria-errormessage={invalid ? errorId : undefined}
125
+ aria-describedby={describedBy}
126
+ {oninput}
127
+ {oncompositionend}
128
+ />
129
+ {/if}
130
+ {/snippet}
131
+
132
+ <div class={classes("xds-text-field", className)} {style}>
133
+ <label for={id} class="xds-text-field__label">{label}</label>
134
+ {#if leading || trailing}
135
+ <div class="xds-text-field__control xds-text-field__group">
136
+ {#if leading}
137
+ <span class="xds-text-field__slot xds-text-field__slot--leading">{@render leading()}</span
138
+ >
139
+ {/if}
140
+ {@render field(false)}
141
+ {#if trailing}
142
+ <span class="xds-text-field__slot xds-text-field__slot--trailing"
143
+ >{@render trailing()}</span
144
+ >
145
+ {/if}
146
+ </div>
147
+ {:else}
148
+ {@render field(true)}
149
+ {/if}
150
+ <!-- One line under the box: the help or the error at the start edge, the count at the end.
151
+ The error is a live region, so it is announced when it appears. -->
152
+ <div class="xds-text-field__footer">
153
+ {#if !invalid && description}
154
+ <span id={descriptionId} class="xds-text-field__description">{description}</span>
155
+ {/if}
156
+ <span id={errorId} class="xds-text-field__error" aria-live="polite">{error}</span>
157
+ {#if maxLength !== undefined}
158
+ <span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums"
159
+ >{value.length}/{maxLength}</span
160
+ >
161
+ {/if}
162
+ </div>
163
+ </div>
@@ -0,0 +1,23 @@
1
+ import type { TextFieldBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type TextFieldProps = TextFieldBaseProps & RootProps & {
5
+ onChange: (value: string) => void;
6
+ /**
7
+ * Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
8
+ * unless it sets its own.
9
+ */
10
+ leading?: Snippet;
11
+ /** Inside the box, after the text: an icon, a unit, a small button. */
12
+ trailing?: Snippet;
13
+ };
14
+ /**
15
+ * A labelled text field, of one line or several. The label, the description and the error message
16
+ * are tied to the input for assistive technology, and the error is announced when it appears.
17
+ *
18
+ * An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
19
+ * the person edits the value.
20
+ */
21
+ declare const TextField: import("svelte").Component<TextFieldProps, {}, "">;
22
+ type TextField = ReturnType<typeof TextField>;
23
+ export default TextField;
@@ -0,0 +1,81 @@
1
+ <!--
2
+ @component
3
+ A picture in a fixed shape, for a video, an article or a product. It fills the width it is
4
+ given and takes its height from `ratio`, and crops the picture to fill it.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { ThumbnailBaseProps } from "@xds/core";
8
+ import type { RootProps } from "./root.js";
9
+
10
+ export type { ThumbnailRatio } from "@xds/core";
11
+
12
+ export type ThumbnailProps = ThumbnailBaseProps & RootProps;
13
+ </script>
14
+
15
+ <script lang="ts">
16
+ import {
17
+ classes,
18
+ pictureClass,
19
+ rootPart,
20
+ THUMBNAIL_PARTS,
21
+ thumbnailBadgeClass,
22
+ thumbnailClass,
23
+ thumbnailWatched,
24
+ } from "@xds/core";
25
+ import Badge from "./Badge.svelte";
26
+ import { useDefaults } from "./defaults.svelte.js";
27
+ import Icon from "./Icon.svelte";
28
+ import { createPicture } from "./picture.svelte.js";
29
+
30
+ let {
31
+ src,
32
+ alt,
33
+ ratio: ownRatio,
34
+ badge,
35
+ progress,
36
+ class: className,
37
+ style,
38
+ }: ThumbnailProps = $props();
39
+
40
+ const defaults = useDefaults("Thumbnail");
41
+ const ratio = $derived(ownRatio ?? defaults().ratio);
42
+
43
+ const picture = createPicture(() => src);
44
+ const watched = $derived(thumbnailWatched(progress));
45
+ </script>
46
+
47
+ <span class={classes(rootPart("Thumbnail"), thumbnailClass(ratio), className)} {style}>
48
+ <!-- The placeholder is the picture's stand-in for assistive technology too, so the description
49
+ is on the box that always shows, not on the picture that may not. -->
50
+ <span
51
+ class={THUMBNAIL_PARTS.placeholder}
52
+ role={alt ? "img" : undefined}
53
+ aria-label={alt || undefined}
54
+ aria-hidden={alt ? undefined : "true"}
55
+ >
56
+ {#if picture.loaded() !== true}
57
+ <Icon name="image" size="lg" />
58
+ {/if}
59
+ {#if picture.loaded() !== false && src}
60
+ {@const address = src}
61
+ <img
62
+ src={address}
63
+ alt=""
64
+ aria-hidden="true"
65
+ class={pictureClass(picture.loaded() === true)}
66
+ onload={() => picture.onLoad(address)}
67
+ onerror={() => picture.onError(address)}
68
+ />
69
+ {/if}
70
+ </span>
71
+ {#if badge}
72
+ <span class={thumbnailBadgeClass(watched)}><Badge tone="overlay">{badge}</Badge></span>
73
+ {/if}
74
+ {#if watched > 0}
75
+ <!-- Decoration: what was watched is for the eye, and a list that needs it said says it in
76
+ words. -->
77
+ <span aria-hidden="true" class={THUMBNAIL_PARTS.track}>
78
+ <span class={THUMBNAIL_PARTS.fill} style:width="{watched * 100}%"></span>
79
+ </span>
80
+ {/if}
81
+ </span>
@@ -0,0 +1,11 @@
1
+ import type { ThumbnailBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type { ThumbnailRatio } from "@xds/core";
4
+ export type ThumbnailProps = ThumbnailBaseProps & RootProps;
5
+ /**
6
+ * A picture in a fixed shape, for a video, an article or a product. It fills the width it is
7
+ * given and takes its height from `ratio`, and crops the picture to fill it.
8
+ */
9
+ declare const Thumbnail: import("svelte").Component<ThumbnailProps, {}, "">;
10
+ type Thumbnail = ReturnType<typeof Thumbnail>;
11
+ export default Thumbnail;
@@ -0,0 +1,83 @@
1
+ <!--
2
+ @component
3
+ A short message about what just happened, which leaves on its own. It sits at the bottom center
4
+ of the window, above everything else, and is announced politely without taking focus. The time
5
+ does not run while the pointer is over it or focus is inside it.
6
+
7
+ Do not put the only way to do something in a toast: it is gone in a few seconds.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { ToastBaseProps } from "@xds/core";
11
+ import type { RootProps } from "./root.js";
12
+
13
+ /** Its root is the toast, while it is open, not the region it appears in. */
14
+ export type ToastProps = ToastBaseProps &
15
+ RootProps & {
16
+ /** Called when the time is up and after the action. Set `open` to false in it. */
17
+ onClose: () => void;
18
+ };
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { motion } from "@xds/tokens";
23
+ import { classes, rootPart, TOAST_PARTS } from "@xds/core";
24
+ import type { Attachment } from "svelte/attachments";
25
+
26
+ let {
27
+ open,
28
+ message,
29
+ action,
30
+ duration = motion.duration.toast,
31
+ onClose,
32
+ class: className,
33
+ style,
34
+ }: ToastProps = $props();
35
+
36
+ // The toast the pointer is over and the one focus is in. A toast that closed under the pointer
37
+ // gets no event to say that the pointer left, so only one still in the page counts.
38
+ let hovered = $state<Element>();
39
+ let focused = $state<Element>();
40
+ const inPage = (toast: Element | undefined) => toast?.isConnected === true;
41
+
42
+ // The region is in the top layer for as long as the component is mounted, empty or not: a
43
+ // screen reader only announces what is added to a region it already knows.
44
+ const showRegion: Attachment<HTMLDivElement> = (region) => {
45
+ if (!region.showPopover) return;
46
+ region.showPopover();
47
+ return () => region.hidePopover();
48
+ };
49
+
50
+ $effect(() => {
51
+ if (!open || inPage(hovered) || inPage(focused) || duration <= 0) return;
52
+ // `onClose` is read when the time is up, so a new function does not restart it.
53
+ const timer = setTimeout(() => onClose(), duration);
54
+ return () => clearTimeout(timer);
55
+ });
56
+ </script>
57
+
58
+ <div {@attach showRegion} role="status" popover="manual" class={TOAST_PARTS.region}>
59
+ {#if open}
60
+ <!-- Hover and focus only pause the timer; the action inside is a real button. -->
61
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
62
+ <div
63
+ onpointerenter={(event) => (hovered = event.currentTarget)}
64
+ onpointerleave={() => (hovered = undefined)}
65
+ onfocusin={(event) => (focused = event.currentTarget)}
66
+ onfocusout={() => (focused = undefined)}
67
+ class={classes(rootPart("Toast"), TOAST_PARTS.toast, className)}
68
+ {style}
69
+ >
70
+ <span class={TOAST_PARTS.message}>{message}</span>
71
+ {#if action}
72
+ <button
73
+ type="button"
74
+ onclick={() => {
75
+ action.onPress();
76
+ onClose();
77
+ }}
78
+ class={TOAST_PARTS.action}>{action.label}</button
79
+ >
80
+ {/if}
81
+ </div>
82
+ {/if}
83
+ </div>
@@ -0,0 +1,17 @@
1
+ import type { ToastBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ /** Its root is the toast, while it is open, not the region it appears in. */
4
+ export type ToastProps = ToastBaseProps & RootProps & {
5
+ /** Called when the time is up and after the action. Set `open` to false in it. */
6
+ onClose: () => void;
7
+ };
8
+ /**
9
+ * A short message about what just happened, which leaves on its own. It sits at the bottom center
10
+ * of the window, above everything else, and is announced politely without taking focus. The time
11
+ * does not run while the pointer is over it or focus is inside it.
12
+ *
13
+ * Do not put the only way to do something in a toast: it is gone in a few seconds.
14
+ */
15
+ declare const Toast: import("svelte").Component<ToastProps, {}, "">;
16
+ type Toast = ReturnType<typeof Toast>;
17
+ export default Toast;
@@ -0,0 +1,40 @@
1
+ <!--
2
+ @component
3
+ Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
4
+ short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
5
+ focus leaves, or Escape is pressed.
6
+
7
+ It describes the control and is not its name: an IconButton still needs its `label`. It never
8
+ holds anything pressable, and touch input has no hover, so nothing may depend on it.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { TooltipBaseProps } from "@xds/core";
12
+ import type { Snippet } from "svelte";
13
+ import type { RootProps } from "./root.js";
14
+
15
+ /** Its root is the tooltip, while it shows, not the control it describes. */
16
+ export type TooltipProps = TooltipBaseProps &
17
+ RootProps & {
18
+ /** The control it describes: a Button or an IconButton. */
19
+ children: Snippet;
20
+ };
21
+ </script>
22
+
23
+ <script lang="ts">
24
+ import TooltipOverlay from "./TooltipOverlay.svelte";
25
+
26
+ let {
27
+ label,
28
+ shortcut,
29
+ placement = "top",
30
+ class: className,
31
+ style,
32
+ children,
33
+ }: TooltipProps = $props();
34
+ </script>
35
+
36
+ <!-- The overlay gives the root part, `xds-tooltip`, to every tooltip, a collapsed Sidebar's
37
+ too. -->
38
+ <TooltipOverlay {label} {shortcut} placement={() => placement} class={className} {style}
39
+ >{@render children()}</TooltipOverlay
40
+ >
@@ -0,0 +1,19 @@
1
+ import type { TooltipBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ /** Its root is the tooltip, while it shows, not the control it describes. */
5
+ export type TooltipProps = TooltipBaseProps & RootProps & {
6
+ /** The control it describes: a Button or an IconButton. */
7
+ children: Snippet;
8
+ };
9
+ /**
10
+ * Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
11
+ * short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
12
+ * focus leaves, or Escape is pressed.
13
+ *
14
+ * It describes the control and is not its name: an IconButton still needs its `label`. It never
15
+ * holds anything pressable, and touch input has no hover, so nothing may depend on it.
16
+ */
17
+ declare const Tooltip: import("svelte").Component<TooltipProps, {}, "">;
18
+ type Tooltip = ReturnType<typeof Tooltip>;
19
+ export default Tooltip;
@@ -0,0 +1,66 @@
1
+ <!--
2
+ @component
3
+ What Tooltip draws, at the placement it is given: a collapsed Sidebar names its icons at the
4
+ end edge, on the side of the content, where they do not cover their neighbours. Only for this
5
+ package's own components: the index does not export it.
6
+ -->
7
+ <script lang="ts">
8
+ import { motion, space } from "@xds/tokens";
9
+ import { classes } from "@xds/core";
10
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
11
+ import * as tooltip from "@zag-js/tooltip";
12
+ import type { Snippet } from "svelte";
13
+ import Portal from "./Portal.svelte";
14
+ import { createPresence } from "./presence.svelte.js";
15
+ import type { RootProps } from "./root.js";
16
+ import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
17
+
18
+ let {
19
+ label,
20
+ shortcut,
21
+ placement,
22
+ class: className,
23
+ style,
24
+ children,
25
+ }: RootProps & {
26
+ label: string;
27
+ shortcut?: string | undefined;
28
+ placement: () => tooltip.Placement;
29
+ children: Snippet;
30
+ } = $props();
31
+
32
+ const id = $props.id();
33
+ const service = useMachine(tooltip.machine, () => ({
34
+ id,
35
+ openDelay: motion.duration.tooltipDelay,
36
+ closeDelay: 0,
37
+ // It stays and follows its control when the page scrolls, for as long as the control keeps
38
+ // focus or the pointer. Tabbing to a control out of view scrolls the page, and a tooltip
39
+ // closed by that scroll would never show for it.
40
+ closeOnScroll: false,
41
+ positioning: { placement: placement(), gutter: space[1] },
42
+ }));
43
+ const api = $derived(tooltip.connect(service, normalizeProps));
44
+ provideTrigger(() => api.getTriggerProps() as TriggerProps);
45
+ let content = $state<HTMLDivElement>();
46
+ const present = createPresence(
47
+ () => api.open,
48
+ () => [content],
49
+ );
50
+ </script>
51
+
52
+ {@render children()}
53
+ {#if present()}
54
+ <Portal>
55
+ <div {...api.getPositionerProps()} class="xds-tooltip__positioner">
56
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
57
+ <div
58
+ {...mergeProps(api.getContentProps(), { class: classes("xds-tooltip", className), style })}
59
+ bind:this={content}
60
+ hidden={false}
61
+ >
62
+ {label}{#if shortcut}<kbd class="xds-tooltip__shortcut">{shortcut}</kbd>{/if}
63
+ </div>
64
+ </div>
65
+ </Portal>
66
+ {/if}
@@ -0,0 +1,17 @@
1
+ import * as tooltip from "@zag-js/tooltip";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ type $$ComponentProps = RootProps & {
5
+ label: string;
6
+ shortcut?: string | undefined;
7
+ placement: () => tooltip.Placement;
8
+ children: Snippet;
9
+ };
10
+ /**
11
+ * What Tooltip draws, at the placement it is given: a collapsed Sidebar names its icons at the
12
+ * end edge, on the side of the content, where they do not cover their neighbours. Only for this
13
+ * package's own components: the index does not export it.
14
+ */
15
+ declare const TooltipOverlay: import("svelte").Component<$$ComponentProps, {}, "">;
16
+ type TooltipOverlay = ReturnType<typeof TooltipOverlay>;
17
+ export default TooltipOverlay;
@@ -0,0 +1,4 @@
1
+ /** After `onChange`: puts the owner's value back into a field that did not take the edit. */
2
+ export declare function keepValue(element: HTMLInputElement | HTMLTextAreaElement, value: () => string): void;
3
+ /** After `onChange`: puts the owner's state back into a checkbox or radio that did not take it. */
4
+ export declare function keepChecked(element: HTMLInputElement, checked: () => boolean): void;
@@ -0,0 +1,23 @@
1
+ // A native input shows what was typed whether or not its owner took it: Svelte writes `value`
2
+ // and `checked` only when the prop changes, and `$bindable` does not undo an edit its owner
3
+ // refused. The web libraries' fields are controlled, as React's are, so a field whose owner
4
+ // keeps the old value puts it back. These do that, once the owner's update has run.
5
+ //
6
+ // Svelte writes `value` and `checked` as properties only, which leave a field's default (the
7
+ // `value` or `checked` attribute) empty, and a form's reset puts every field back to its
8
+ // default. So each field also gives its value as `defaultValue` or `defaultChecked`, and a
9
+ // reset leaves it showing what its owner gives it. React and Vue keep the default value so;
10
+ // Vue keeps the default checked state so too, React only its first.
11
+ import { flushSync } from "svelte";
12
+ /** After `onChange`: puts the owner's value back into a field that did not take the edit. */
13
+ export function keepValue(element, value) {
14
+ flushSync();
15
+ if (element.value !== value())
16
+ element.value = value();
17
+ }
18
+ /** After `onChange`: puts the owner's state back into a checkbox or radio that did not take it. */
19
+ export function keepChecked(element, checked) {
20
+ flushSync();
21
+ if (element.checked !== checked())
22
+ element.checked = checked();
23
+ }
@@ -0,0 +1,12 @@
1
+ import { type ComponentDefaults, type DefaultedComponent } from "@xds/core";
2
+ /**
3
+ * For Defaults: gives the components inside it the defaults around it, with those of `own`
4
+ * replaced, option by option. Call it while the component is set up.
5
+ */
6
+ export declare function provideDefaults(own: () => ComponentDefaults): void;
7
+ /**
8
+ * For a component with defaultable options: what the closest Defaults gives it, which it takes
9
+ * for each option its own props leave out, before its built-in default. Call it while the
10
+ * component is set up; the result follows the providers' values.
11
+ */
12
+ export declare function useDefaults<N extends DefaultedComponent>(component: N): () => NonNullable<ComponentDefaults[N]>;
@@ -0,0 +1,25 @@
1
+ // The defaults that a Defaults provider gives the components inside it. They reach a component
2
+ // through context, so that a provider far up the tree applies without each screen passing them
3
+ // along, and each provider merges its own over the ones around it.
4
+ import { mergeDefaults } from "@xds/core";
5
+ import { createContext } from "svelte";
6
+ // Not exported from the package: apps give defaults with the Defaults component.
7
+ const [getDefaults, setDefaults, hasDefaults] = createContext();
8
+ /**
9
+ * For Defaults: gives the components inside it the defaults around it, with those of `own`
10
+ * replaced, option by option. Call it while the component is set up.
11
+ */
12
+ export function provideDefaults(own) {
13
+ const outer = hasDefaults() ? getDefaults() : undefined;
14
+ const merged = $derived(mergeDefaults(outer?.(), own()));
15
+ setDefaults(() => merged);
16
+ }
17
+ /**
18
+ * For a component with defaultable options: what the closest Defaults gives it, which it takes
19
+ * for each option its own props leave out, before its built-in default. Call it while the
20
+ * component is set up; the result follows the providers' values.
21
+ */
22
+ export function useDefaults(component) {
23
+ const defaults = hasDefaults() ? getDefaults() : undefined;
24
+ return () => defaults?.()[component] ?? {};
25
+ }
@@ -0,0 +1,41 @@
1
+ export type { IconName, IconSize, TextTone, TextVariant } from "@xds/core";
2
+ export { default as Accordion, type AccordionItem, type AccordionProps } from "./Accordion.svelte";
3
+ export { default as Avatar, type AvatarProps, type AvatarSize } from "./Avatar.svelte";
4
+ export { default as AvatarStack, type AvatarStackProps } from "./AvatarStack.svelte";
5
+ export { default as Badge, type BadgeProps, type BadgeTone } from "./Badge.svelte";
6
+ export { default as Banner, type BannerProps, type BannerTone } from "./Banner.svelte";
7
+ export { default as Button, type ButtonProps, type ButtonVariant, type ControlSize, } from "./Button.svelte";
8
+ export { default as Card, type CardProps } from "./Card.svelte";
9
+ export { default as Checkbox, type CheckboxProps } from "./Checkbox.svelte";
10
+ export { default as Chip, type ChipProps } from "./Chip.svelte";
11
+ export { default as ChipBar, type ChipBarProps } from "./ChipBar.svelte";
12
+ export { default as CountBadge, type CountBadgeProps } from "./CountBadge.svelte";
13
+ export { default as DatePicker, type DatePickerProps, type IsoDate } from "./DatePicker.svelte";
14
+ export { type DateRange, default as DateRangePicker, type DateRangePickerProps, } from "./DateRangePicker.svelte";
15
+ export { type ComponentDefaults, default as Defaults, type DefaultsProps } from "./Defaults.svelte";
16
+ export { default as Dialog, type DialogProps } from "./Dialog.svelte";
17
+ export { default as Divider, type DividerProps } from "./Divider.svelte";
18
+ export { default as EmptyState, type EmptyStateProps } from "./EmptyState.svelte";
19
+ export { default as Icon, type IconProps } from "./Icon.svelte";
20
+ export { default as IconButton, type IconButtonProps } from "./IconButton.svelte";
21
+ export { default as ListRow, type ListRowProps } from "./ListRow.svelte";
22
+ export { default as MediaCard, type MediaCardProps } from "./MediaCard.svelte";
23
+ export { default as Menu, type MenuItem, type MenuProps } from "./Menu.svelte";
24
+ export { default as ProgressBar, type ProgressBarProps } from "./ProgressBar.svelte";
25
+ export { default as RadioGroup, type RadioGroupProps, type RadioOption } from "./RadioGroup.svelte";
26
+ export type { RootProps } from "./root.js";
27
+ export { default as SearchField, type SearchFieldProps } from "./SearchField.svelte";
28
+ export { default as SectionHeader, type SectionHeaderProps } from "./SectionHeader.svelte";
29
+ export { default as SegmentedControl, type SegmentedControlProps } from "./SegmentedControl.svelte";
30
+ export { default as Select, type SelectOption, type SelectProps } from "./Select.svelte";
31
+ export { default as Sidebar, type SidebarItem, type SidebarProps, type SidebarSection, } from "./Sidebar.svelte";
32
+ export { default as Skeleton, type SkeletonProps } from "./Skeleton.svelte";
33
+ export { default as Slider, type SliderProps } from "./Slider.svelte";
34
+ export { default as Spinner, type SpinnerProps } from "./Spinner.svelte";
35
+ export { default as Switch, type SwitchProps } from "./Switch.svelte";
36
+ export { default as Tabs, type TabsProps } from "./Tabs.svelte";
37
+ export { default as Text, type TextProps } from "./Text.svelte";
38
+ export { default as TextField, type TextFieldProps } from "./TextField.svelte";
39
+ export { default as Thumbnail, type ThumbnailProps, type ThumbnailRatio } from "./Thumbnail.svelte";
40
+ export { default as Toast, type ToastProps } from "./Toast.svelte";
41
+ export { default as Tooltip, type TooltipProps } from "./Tooltip.svelte";