@xds/svelte 1.0.1 → 1.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 (207) hide show
  1. .diffend-unextracted-0 +2 -1
  2. package/dist/Accordion.svelte +7 -2
  3. package/dist/Avatar.svelte +10 -2
  4. package/dist/AvatarStack.svelte +11 -1
  5. package/dist/Badge.svelte +14 -3
  6. package/dist/Banner.svelte +6 -1
  7. package/dist/Breadcrumb.svelte +53 -0
  8. package/dist/Breadcrumb.svelte.d.ts +11 -0
  9. package/dist/Button.svelte +30 -2
  10. package/dist/Button.svelte.d.ts +10 -1
  11. package/dist/Card.svelte +16 -2
  12. package/dist/Checkbox.svelte +62 -10
  13. package/dist/Checkbox.svelte.d.ts +14 -3
  14. package/dist/Chip.svelte +3 -1
  15. package/dist/ChipBar.svelte +3 -2
  16. package/dist/Combobox.svelte +194 -0
  17. package/dist/Combobox.svelte.d.ts +37 -0
  18. package/dist/CountBadge.svelte +4 -2
  19. package/dist/DatePicker.svelte +16 -5
  20. package/dist/DateRangePicker.svelte +6 -1
  21. package/dist/Dialog.svelte +9 -2
  22. package/dist/Divider.svelte +7 -3
  23. package/dist/EmptyState.svelte +15 -3
  24. package/dist/Icon.svelte +11 -2
  25. package/dist/IconButton.svelte +30 -2
  26. package/dist/IconButton.svelte.d.ts +10 -1
  27. package/dist/Labels.svelte +29 -0
  28. package/dist/Labels.svelte.d.ts +17 -0
  29. package/dist/Link.svelte +86 -0
  30. package/dist/Link.svelte.d.ts +26 -0
  31. package/dist/MediaCard.svelte +4 -1
  32. package/dist/Menu.svelte +21 -2
  33. package/dist/Pagination.svelte +108 -0
  34. package/dist/Pagination.svelte.d.ts +14 -0
  35. package/dist/PlaceRow.svelte +6 -1
  36. package/dist/Popover.svelte +91 -0
  37. package/dist/Popover.svelte.d.ts +21 -0
  38. package/dist/PopoverSurface.svelte +77 -0
  39. package/dist/PopoverSurface.svelte.d.ts +21 -0
  40. package/dist/ProgressBar.svelte +3 -1
  41. package/dist/RadioGroup.svelte +23 -8
  42. package/dist/RadioGroup.svelte.d.ts +4 -2
  43. package/dist/SearchField.svelte +65 -18
  44. package/dist/SearchField.svelte.d.ts +14 -4
  45. package/dist/SectionHeader.svelte +7 -2
  46. package/dist/SegmentedControl.svelte +21 -7
  47. package/dist/SegmentedControl.svelte.d.ts +3 -2
  48. package/dist/Select.svelte +64 -12
  49. package/dist/Select.svelte.d.ts +9 -2
  50. package/dist/Sidebar.svelte +3 -0
  51. package/dist/Skeleton.svelte +10 -2
  52. package/dist/Slider.svelte +23 -7
  53. package/dist/Slider.svelte.d.ts +2 -2
  54. package/dist/Spinner.svelte +3 -2
  55. package/dist/Switch.svelte +53 -9
  56. package/dist/Switch.svelte.d.ts +13 -3
  57. package/dist/Table.svelte +92 -0
  58. package/dist/Table.svelte.d.ts +17 -0
  59. package/dist/Tabs.svelte +21 -6
  60. package/dist/Tabs.svelte.d.ts +2 -1
  61. package/dist/Text.svelte +3 -1
  62. package/dist/TextField.svelte +59 -14
  63. package/dist/TextField.svelte.d.ts +13 -3
  64. package/dist/Thumbnail.svelte +7 -1
  65. package/dist/TimePicker.svelte +222 -0
  66. package/dist/TimePicker.svelte.d.ts +20 -0
  67. package/dist/Toast.svelte +12 -2
  68. package/dist/ToastQueue.svelte +57 -0
  69. package/dist/ToastQueue.svelte.d.ts +20 -0
  70. package/dist/Tooltip.svelte +9 -2
  71. package/dist/TooltipOverlay.svelte +9 -2
  72. package/dist/base.d.ts +14 -0
  73. package/dist/base.js +27 -0
  74. package/dist/controllable.svelte.d.ts +28 -0
  75. package/dist/controllable.svelte.js +41 -0
  76. package/dist/index.d.ts +12 -2
  77. package/dist/index.js +12 -0
  78. package/dist/labels.svelte.d.ts +13 -0
  79. package/dist/labels.svelte.js +24 -0
  80. package/dist/modal-popover.svelte.js +5 -1
  81. package/dist/presence.svelte.js +5 -2
  82. package/dist/preview/Component.svelte +8 -3
  83. package/dist/preview/Preview.svelte +8 -2
  84. package/dist/preview/Preview.svelte.d.ts +2 -0
  85. package/dist/preview/components.d.ts +9 -2
  86. package/dist/preview/components.js +18 -1
  87. package/dist/preview/index.d.ts +1 -0
  88. package/dist/root.d.ts +4 -2
  89. package/eject/files/Accordion.svelte +100 -0
  90. package/eject/files/AccordionPanel.svelte +48 -0
  91. package/eject/files/Avatar.svelte +51 -0
  92. package/eject/files/AvatarStack.svelte +61 -0
  93. package/eject/files/Badge.svelte +52 -0
  94. package/eject/files/Banner.svelte +94 -0
  95. package/eject/files/Breadcrumb.svelte +52 -0
  96. package/eject/files/Button.svelte +126 -0
  97. package/eject/files/Card.svelte +112 -0
  98. package/eject/files/Checkbox.svelte +121 -0
  99. package/eject/files/Chip.svelte +51 -0
  100. package/eject/files/ChipBar.svelte +39 -0
  101. package/eject/files/Combobox.svelte +198 -0
  102. package/eject/files/CountBadge.svelte +51 -0
  103. package/eject/files/DatePicker.svelte +213 -0
  104. package/eject/files/DateRangePicker.svelte +294 -0
  105. package/eject/files/Dialog.svelte +119 -0
  106. package/eject/files/Divider.svelte +27 -0
  107. package/eject/files/EmptyState.svelte +52 -0
  108. package/eject/files/Icon.svelte +51 -0
  109. package/eject/files/IconButton.svelte +99 -0
  110. package/eject/files/Link.svelte +85 -0
  111. package/eject/files/ListRow.svelte +33 -0
  112. package/eject/files/MediaCard.svelte +117 -0
  113. package/eject/files/Menu.svelte +183 -0
  114. package/eject/files/Pagination.svelte +109 -0
  115. package/eject/files/PlaceRow.svelte +75 -0
  116. package/eject/files/Popover.svelte +100 -0
  117. package/eject/files/PopoverSurface.svelte +85 -0
  118. package/eject/files/ProgressBar.svelte +38 -0
  119. package/eject/files/RadioGroup.svelte +133 -0
  120. package/eject/files/SearchField.svelte +154 -0
  121. package/eject/files/SectionHeader.svelte +67 -0
  122. package/eject/files/SegmentedControl.svelte +85 -0
  123. package/eject/files/Select.svelte +276 -0
  124. package/eject/files/Sidebar.svelte +130 -0
  125. package/eject/files/SidebarRailButton.svelte +32 -0
  126. package/eject/files/Skeleton.svelte +55 -0
  127. package/eject/files/Slider.svelte +136 -0
  128. package/eject/files/Spinner.svelte +41 -0
  129. package/eject/files/Switch.svelte +105 -0
  130. package/eject/files/Table.svelte +90 -0
  131. package/eject/files/Tabs.svelte +85 -0
  132. package/eject/files/Text.svelte +43 -0
  133. package/eject/files/TextField.svelte +222 -0
  134. package/eject/files/Thumbnail.svelte +88 -0
  135. package/eject/files/TimePicker.svelte +237 -0
  136. package/eject/files/Toast.svelte +98 -0
  137. package/eject/files/ToastQueue.svelte +61 -0
  138. package/eject/files/Tooltip.svelte +51 -0
  139. package/eject/files/TooltipOverlay.svelte +88 -0
  140. package/eject/files/accordion.css +89 -0
  141. package/eject/files/accordion.ts +67 -0
  142. package/eject/files/avatar-stack.ts +57 -0
  143. package/eject/files/avatar.ts +42 -0
  144. package/eject/files/badge.ts +30 -0
  145. package/eject/files/banner.ts +71 -0
  146. package/eject/files/base.css +38 -0
  147. package/eject/files/breadcrumb.css +51 -0
  148. package/eject/files/breadcrumb.ts +42 -0
  149. package/eject/files/button.css +241 -0
  150. package/eject/files/button.ts +106 -0
  151. package/eject/files/card.ts +58 -0
  152. package/eject/files/checkbox.ts +52 -0
  153. package/eject/files/chip-bar.ts +16 -0
  154. package/eject/files/chip.ts +35 -0
  155. package/eject/files/combobox.css +269 -0
  156. package/eject/files/combobox.ts +85 -0
  157. package/eject/files/count-badge.ts +32 -0
  158. package/eject/files/date-picker.css +375 -0
  159. package/eject/files/date-picker.ts +280 -0
  160. package/eject/files/date-range-picker.ts +338 -0
  161. package/eject/files/dialog.css +139 -0
  162. package/eject/files/dialog.ts +15 -0
  163. package/eject/files/divider.ts +5 -0
  164. package/eject/files/empty-state.ts +22 -0
  165. package/eject/files/icon.ts +36 -0
  166. package/eject/files/link.css +64 -0
  167. package/eject/files/link.ts +63 -0
  168. package/eject/files/list-row.ts +66 -0
  169. package/eject/files/media-card.ts +66 -0
  170. package/eject/files/menu.css +192 -0
  171. package/eject/files/menu.ts +84 -0
  172. package/eject/files/overlay.css +40 -0
  173. package/eject/files/pagination.css +106 -0
  174. package/eject/files/pagination.ts +68 -0
  175. package/eject/files/parts.ts +17 -0
  176. package/eject/files/popover.css +101 -0
  177. package/eject/files/popover.ts +37 -0
  178. package/eject/files/progress-bar.ts +26 -0
  179. package/eject/files/radio-group.css +184 -0
  180. package/eject/files/radio-group.ts +30 -0
  181. package/eject/files/section-header.ts +32 -0
  182. package/eject/files/segmented-control.ts +33 -0
  183. package/eject/files/select.css +347 -0
  184. package/eject/files/select.ts +77 -0
  185. package/eject/files/sidebar.ts +75 -0
  186. package/eject/files/skeleton.ts +51 -0
  187. package/eject/files/slider.css +160 -0
  188. package/eject/files/slider.ts +80 -0
  189. package/eject/files/spinner.ts +22 -0
  190. package/eject/files/switch.ts +45 -0
  191. package/eject/files/table.css +107 -0
  192. package/eject/files/table.ts +84 -0
  193. package/eject/files/tabs.css +120 -0
  194. package/eject/files/tabs.ts +37 -0
  195. package/eject/files/text-field.css +225 -0
  196. package/eject/files/text-field.ts +64 -0
  197. package/eject/files/text.ts +38 -0
  198. package/eject/files/thumbnail.ts +51 -0
  199. package/eject/files/time-picker.ts +113 -0
  200. package/eject/files/toast-queue.ts +64 -0
  201. package/eject/files/toast.ts +31 -0
  202. package/eject/files/tooltip.css +111 -0
  203. package/eject/files/tooltip.ts +21 -0
  204. package/eject/manifest.json +1053 -0
  205. package/package.json +12 -4
  206. package/styles.css +1064 -169
  207. package/tailwind.css +1295 -218
@@ -0,0 +1,86 @@
1
+ <!--
2
+ @component
3
+ Text that takes the person somewhere, in the type of the text around it. It is underlined, so
4
+ it does not depend on color. With `href` it is a native link; without one, a button that
5
+ assistive technology hears as a link.
6
+
7
+ `focus()`, `blur()` and `element()` on the instance reach the native element.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { LinkBaseProps } from "@xds/core";
11
+ import type { Snippet } from "svelte";
12
+ import type { FocusEventHandler } from "svelte/elements";
13
+ import type { RootProps } from "./root.js";
14
+
15
+ export type LinkProps = LinkBaseProps &
16
+ RootProps & {
17
+ /** Called on a press, before the browser follows `href`. A disabled link never calls it. */
18
+ onPress?: () => void;
19
+ onFocus?: FocusEventHandler<HTMLElement>;
20
+ onBlur?: FocusEventHandler<HTMLElement>;
21
+ /** The text, which names the link. */
22
+ children: Snippet;
23
+ };
24
+ </script>
25
+
26
+ <script lang="ts">
27
+ import {
28
+ classes,
29
+ LINK_ICON,
30
+ LINK_PARTS,
31
+ linkElement,
32
+ rootAttributes,
33
+ rootPart,
34
+ } from "@xds/core";
35
+ import Icon from "./Icon.svelte";
36
+
37
+ let {
38
+ href,
39
+ external = false,
40
+ disabled = false,
41
+ onPress,
42
+ onFocus,
43
+ onBlur,
44
+ class: className,
45
+ style,
46
+ children,
47
+ ...rest
48
+ }: LinkProps = $props();
49
+
50
+ const shape = $derived(linkElement({ href, external, disabled }));
51
+ let root = $state<HTMLElement>();
52
+
53
+ /** Moves the focus to the native element. */
54
+ export function focus(options?: FocusOptions) {
55
+ root?.focus(options);
56
+ }
57
+
58
+ /** Takes the focus from the native element. */
59
+ export function blur() {
60
+ root?.blur();
61
+ }
62
+
63
+ /** The native element, an `<a>` or a `<button>`, once it is on the page. */
64
+ export function element(): HTMLElement | undefined {
65
+ return root;
66
+ }
67
+ </script>
68
+
69
+ <svelte:element
70
+ this={shape.tag}
71
+ bind:this={root}
72
+ {...rootAttributes(rest)}
73
+ {...shape.attributes}
74
+ class={classes(rootPart("Link"), className)}
75
+ {style}
76
+ onclick={() => {
77
+ if (!disabled) onPress?.();
78
+ }}
79
+ onfocus={onFocus}
80
+ onblur={onBlur}
81
+ >{@render children()}{#if external}<Icon
82
+ name={LINK_ICON.name}
83
+ size={LINK_ICON.size}
84
+ class={LINK_PARTS.icon}
85
+ />{/if}</svelte:element
86
+ >
@@ -0,0 +1,26 @@
1
+ import type { LinkBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { FocusEventHandler } from "svelte/elements";
4
+ import type { RootProps } from "./root.js";
5
+ export type LinkProps = LinkBaseProps & RootProps & {
6
+ /** Called on a press, before the browser follows `href`. A disabled link never calls it. */
7
+ onPress?: () => void;
8
+ onFocus?: FocusEventHandler<HTMLElement>;
9
+ onBlur?: FocusEventHandler<HTMLElement>;
10
+ /** The text, which names the link. */
11
+ children: Snippet;
12
+ };
13
+ /**
14
+ * Text that takes the person somewhere, in the type of the text around it. It is underlined, so
15
+ * it does not depend on color. With `href` it is a native link; without one, a button that
16
+ * assistive technology hears as a link.
17
+ *
18
+ * `focus()`, `blur()` and `element()` on the instance reach the native element.
19
+ */
20
+ declare const Link: import("svelte").Component<LinkProps, {
21
+ focus: (options?: FocusOptions) => void;
22
+ blur: () => void;
23
+ element: () => HTMLElement | undefined;
24
+ }, "">;
25
+ type Link = ReturnType<typeof Link>;
26
+ export default Link;
@@ -30,6 +30,7 @@
30
30
  mediaCardContentClass,
31
31
  mediaCardIds,
32
32
  mediaCardThumbnailClass,
33
+ rootAttributes,
33
34
  rootPart,
34
35
  } from "@xds/core";
35
36
  import { useDefaults } from "./defaults.svelte.js";
@@ -50,6 +51,7 @@
50
51
  onPress,
51
52
  class: className,
52
53
  style,
54
+ ...rest
53
55
  }: MediaCardProps = $props();
54
56
 
55
57
  const defaults = useDefaults("MediaCard");
@@ -89,7 +91,7 @@
89
91
  {/snippet}
90
92
 
91
93
  {#if pressable}
92
- <div class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
94
+ <div {...rootAttributes(rest)} class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
93
95
  <button
94
96
  type="button"
95
97
  onclick={() => onPress?.()}
@@ -102,6 +104,7 @@
102
104
  <!-- A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
103
105
  content, which would undo the ellipses. -->
104
106
  <div
107
+ {...rootAttributes(rest)}
105
108
  role="group"
106
109
  aria-labelledby={ids.names}
107
110
  class={classes(MEDIA_CARD_PARTS.group, root)}
package/dist/Menu.svelte CHANGED
@@ -25,6 +25,7 @@
25
25
  import { space } from "@xds/tokens";
26
26
  import {
27
27
  classes,
28
+ createItemPropsCache,
28
29
  firstMenuValue,
29
30
  keepListKeys,
30
31
  layoutRect,
@@ -32,6 +33,7 @@
32
33
  menuItemClass,
33
34
  opensOnPress,
34
35
  readCssPx,
36
+ rootAttributes,
35
37
  underlayLayerStyle,
36
38
  } from "@xds/core";
37
39
  import * as menu from "@zag-js/menu";
@@ -42,11 +44,21 @@
42
44
  import { createPresence } from "./presence.svelte.js";
43
45
  import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
44
46
 
45
- let { label, items, align = "start", trigger, class: className, style }: MenuProps = $props();
47
+ let {
48
+ label,
49
+ items,
50
+ align = "start",
51
+ trigger,
52
+ class: className,
53
+ style,
54
+ ...rest
55
+ }: MenuProps = $props();
46
56
 
47
57
  const id = $props.id();
48
58
  const service = useMachine(menu.machine, () => ({
49
59
  id,
60
+ // The app's id names the menu, and the trigger's aria-controls points there.
61
+ ids: rest.id === undefined ? undefined : { content: rest.id },
50
62
  "aria-label": label,
51
63
  positioning: {
52
64
  placement: `bottom-${align}` as const,
@@ -63,6 +75,9 @@
63
75
  loopFocus: true,
64
76
  }));
65
77
  const api = $derived(menu.connect(service, normalizeProps));
78
+ // The items' props as they last were while they draw the same, so that a step of the highlight
79
+ // sets the attributes and the handlers of the two items it moves between, not of every item.
80
+ const keep = createItemPropsCache();
66
81
  // Whether the last press on the trigger opened the menu, which its click must then not do.
67
82
  let pressOpened = false;
68
83
  provideTrigger(() => {
@@ -112,6 +127,7 @@
112
127
  );
113
128
  const content = $derived(
114
129
  mergeProps(api.getContentProps(), {
130
+ ...rootAttributes(rest),
115
131
  class: classes("xds-menu", className),
116
132
  style,
117
133
  // This handler runs before Zag's.
@@ -143,7 +159,10 @@
143
159
  <div {...api.getSeparatorProps()} class="xds-menu__separator"></div>
144
160
  {:else}
145
161
  <div
146
- {...api.getItemProps({ value: String(index), disabled: item.disabled })}
162
+ {...keep(
163
+ `item:${index}`,
164
+ api.getItemProps({ value: String(index), disabled: item.disabled }),
165
+ )}
147
166
  class={menuItemClass(item.danger)}
148
167
  >
149
168
  {#if item.icon}
@@ -0,0 +1,108 @@
1
+ <!--
2
+ @component
3
+ Moves through a list split into pages: a step back, the first and the last pages, the page
4
+ shown with an ellipsis for those left out, and a step on. A navigation landmark; the page shown
5
+ is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
6
+ -->
7
+ <script module lang="ts">
8
+ import type { PaginationBaseProps } from "@xds/core";
9
+ import type { RootProps } from "./root.js";
10
+
11
+ export type PaginationProps = PaginationBaseProps &
12
+ RootProps & {
13
+ /** Called with the page to show, from 1. */
14
+ onChange?: (value: number) => void;
15
+ };
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import {
20
+ clampPage,
21
+ classes,
22
+ PAGINATION_PARTS,
23
+ PAGINATION_STEPS,
24
+ paginationEntries,
25
+ rootAttributes,
26
+ rootPart,
27
+ } from "@xds/core";
28
+ import { controllable } from "./controllable.svelte.js";
29
+ import Icon from "./Icon.svelte";
30
+ import { useLabels } from "./labels.svelte.js";
31
+
32
+ // `value` stays in the rest, where whether it is given at all can be asked.
33
+ let {
34
+ count,
35
+ defaultValue,
36
+ label,
37
+ previousLabel,
38
+ nextLabel,
39
+ onChange,
40
+ class: className,
41
+ style,
42
+ ...rest
43
+ }: PaginationProps = $props();
44
+
45
+ const control = controllable<number | undefined, number>(
46
+ () => rest,
47
+ "value",
48
+ () => rest.value,
49
+ () => defaultValue ?? 1,
50
+ () => onChange,
51
+ );
52
+ const labels = useLabels();
53
+ const page = $derived(clampPage(control.current ?? 1, count));
54
+ const last = $derived(Math.max(1, Math.floor(count)));
55
+ const entries = $derived(paginationEntries(page, count));
56
+ const go = (next: number) => {
57
+ if (next !== page && next >= 1 && next <= last) control.set(next);
58
+ };
59
+ </script>
60
+
61
+ <nav
62
+ {...rootAttributes(rest)}
63
+ aria-label={label ?? labels().pagination}
64
+ class={classes(rootPart("Pagination"), className)}
65
+ {style}
66
+ >
67
+ <ul class={PAGINATION_PARTS.list}>
68
+ <li>
69
+ <button
70
+ type="button"
71
+ class={PAGINATION_PARTS.step}
72
+ aria-label={previousLabel ?? labels().previousPage}
73
+ aria-disabled={page <= 1 ? true : undefined}
74
+ onclick={() => go(page - 1)}
75
+ >
76
+ <Icon name={PAGINATION_STEPS.previous} size={PAGINATION_STEPS.size} />
77
+ </button>
78
+ </li>
79
+ <!-- A gap is known by where it is; a page by its number. -->
80
+ {#each entries as entry, index (entry === "gap" ? `gap-${index}` : entry)}
81
+ <li>
82
+ {#if entry === "gap"}
83
+ <span class={PAGINATION_PARTS.gap} aria-hidden="true">…</span>
84
+ {:else}
85
+ <button
86
+ type="button"
87
+ class={PAGINATION_PARTS.page}
88
+ aria-current={entry === page ? "page" : undefined}
89
+ onclick={() => go(entry)}
90
+ >
91
+ {entry}
92
+ </button>
93
+ {/if}
94
+ </li>
95
+ {/each}
96
+ <li>
97
+ <button
98
+ type="button"
99
+ class={PAGINATION_PARTS.step}
100
+ aria-label={nextLabel ?? labels().nextPage}
101
+ aria-disabled={page >= last ? true : undefined}
102
+ onclick={() => go(page + 1)}
103
+ >
104
+ <Icon name={PAGINATION_STEPS.next} size={PAGINATION_STEPS.size} />
105
+ </button>
106
+ </li>
107
+ </ul>
108
+ </nav>
@@ -0,0 +1,14 @@
1
+ import type { PaginationBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type PaginationProps = PaginationBaseProps & RootProps & {
4
+ /** Called with the page to show, from 1. */
5
+ onChange?: (value: number) => void;
6
+ };
7
+ /**
8
+ * Moves through a list split into pages: a step back, the first and the last pages, the page
9
+ * shown with an ellipsis for those left out, and a step on. A navigation landmark; the page shown
10
+ * is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
11
+ */
12
+ declare const Pagination: import("svelte").Component<PaginationProps, {}, "">;
13
+ type Pagination = ReturnType<typeof Pagination>;
14
+ export default Pagination;
@@ -11,6 +11,7 @@
11
11
  listRowClass,
12
12
  listRowDescriptionClass,
13
13
  listRowTitleClass,
14
+ rootAttributes,
14
15
  } from "@xds/core";
15
16
  import Icon from "./Icon.svelte";
16
17
  import type { ListRowProps } from "./ListRow.svelte";
@@ -28,6 +29,7 @@
28
29
  class: className,
29
30
  style,
30
31
  current: kind,
32
+ ...rest
31
33
  }: ListRowProps & { current: "true" | "page" } = $props();
32
34
 
33
35
  const current = $derived(selected ? kind : undefined);
@@ -52,6 +54,7 @@
52
54
 
53
55
  {#if onPress}
54
56
  <button
57
+ {...rootAttributes(rest)}
55
58
  aria-current={current}
56
59
  type="button"
57
60
  {disabled}
@@ -62,5 +65,7 @@
62
65
  {@render content()}
63
66
  </button>
64
67
  {:else}
65
- <div aria-current={current} class={row} {style}>{@render content()}</div>
68
+ <div {...rootAttributes(rest)} aria-current={current} class={row} {style}>
69
+ {@render content()}
70
+ </div>
66
71
  {/if}
@@ -0,0 +1,91 @@
1
+ <!--
2
+ @component
3
+ A surface that opens beside the control that opens it, for details or a short task that do not
4
+ need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
5
+ back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
6
+ behind it. Without `open` it keeps its own, from `defaultOpen`.
7
+ -->
8
+ <script module lang="ts">
9
+ import type { PopoverBaseProps } from "@xds/core";
10
+ import type { Snippet } from "svelte";
11
+ import type { RootProps } from "./root.js";
12
+
13
+ /** Its root is the surface, while it is open, not its trigger. */
14
+ export type PopoverProps = PopoverBaseProps &
15
+ RootProps & {
16
+ /** The control that opens it: a Button or an IconButton. */
17
+ trigger: Snippet;
18
+ /** Called with whether it is open, as it opens and closes. */
19
+ onOpenChange?: (open: boolean) => void;
20
+ /** What it holds: a few lines of text, a short form, actions. */
21
+ children?: Snippet;
22
+ };
23
+ </script>
24
+
25
+ <script lang="ts">
26
+ import { space } from "@xds/tokens";
27
+ import { leaveEscapeToFields, POPOVER_PARTS, readCssPx } from "@xds/core";
28
+ import * as popover from "@zag-js/popover";
29
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
30
+ import { controllable } from "./controllable.svelte.js";
31
+ import PopoverSurface from "./PopoverSurface.svelte";
32
+ import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
33
+
34
+ // `open` stays in the rest, where whether it is given at all can be asked.
35
+ let {
36
+ title,
37
+ placement,
38
+ closeLabel,
39
+ defaultOpen,
40
+ onOpenChange,
41
+ trigger,
42
+ children,
43
+ class: className,
44
+ style,
45
+ ...rest
46
+ }: PopoverProps = $props();
47
+
48
+ const control = controllable<boolean | undefined, boolean>(
49
+ () => rest,
50
+ "open",
51
+ () => rest.open,
52
+ () => defaultOpen ?? false,
53
+ () => onOpenChange,
54
+ );
55
+ const id = $props.id();
56
+ let content = $state<HTMLElement>();
57
+ const service = useMachine(popover.machine, () => ({
58
+ id,
59
+ // The app's id names the surface, and the trigger's aria-controls points there.
60
+ ids: rest.id === undefined ? undefined : { content: rest.id },
61
+ open: control.current ?? false,
62
+ onOpenChange: (details: popover.OpenChangeDetails) => control.set(details.open),
63
+ positioning: {
64
+ placement: placement ?? "bottom",
65
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
66
+ },
67
+ onEscapeKeyDown: leaveEscapeToFields,
68
+ // The surface itself rather than its first control: a screen reader then reads the title
69
+ // first, and the close button is the next stop.
70
+ initialFocusEl: () => content ?? null,
71
+ }));
72
+ const api = $derived(popover.connect(service, normalizeProps));
73
+ // Added to the control's own class; the trigger looks pressed while it is open.
74
+ provideTrigger(
75
+ () => mergeProps(api.getTriggerProps(), { class: POPOVER_PARTS.trigger }) as TriggerProps,
76
+ );
77
+ // What the app gives the root, without `open`, which is the machine's.
78
+ const { open: _open, ...attributes } = $derived(rest);
79
+ </script>
80
+
81
+ {@render trigger()}
82
+ <PopoverSurface
83
+ api={() => api}
84
+ {title}
85
+ {closeLabel}
86
+ class={className}
87
+ {style}
88
+ {attributes}
89
+ {children}
90
+ bind:content
91
+ />
@@ -0,0 +1,21 @@
1
+ import type { PopoverBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ /** Its root is the surface, while it is open, not its trigger. */
5
+ export type PopoverProps = PopoverBaseProps & RootProps & {
6
+ /** The control that opens it: a Button or an IconButton. */
7
+ trigger: Snippet;
8
+ /** Called with whether it is open, as it opens and closes. */
9
+ onOpenChange?: (open: boolean) => void;
10
+ /** What it holds: a few lines of text, a short form, actions. */
11
+ children?: Snippet;
12
+ };
13
+ /**
14
+ * A surface that opens beside the control that opens it, for details or a short task that do not
15
+ * need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
16
+ * back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
17
+ * behind it. Without `open` it keeps its own, from `defaultOpen`.
18
+ */
19
+ declare const Popover: import("svelte").Component<PopoverProps, {}, "">;
20
+ type Popover = ReturnType<typeof Popover>;
21
+ export default Popover;
@@ -0,0 +1,77 @@
1
+ <!--
2
+ @component
3
+ What a Popover draws while it is open: the surface, with its title, its close button and its
4
+ content. A component of its own so that the controls in it get none of the trigger props the
5
+ Popover gives its trigger. Only for Popover: the index does not export it.
6
+ -->
7
+ <script lang="ts">
8
+ import { classes, POPOVER_PARTS, rootAttributes } from "@xds/core";
9
+ import type * as popover from "@zag-js/popover";
10
+ import { mergeProps, type PropTypes } from "@zag-js/svelte";
11
+ import type { Snippet } from "svelte";
12
+ import IconButton from "./IconButton.svelte";
13
+ import { useLabels } from "./labels.svelte.js";
14
+ import Portal from "./Portal.svelte";
15
+ import { createPresence } from "./presence.svelte.js";
16
+ import { resetTrigger } from "./trigger.svelte.js";
17
+
18
+ let {
19
+ api,
20
+ title,
21
+ closeLabel,
22
+ class: className,
23
+ style,
24
+ attributes,
25
+ children,
26
+ content = $bindable(),
27
+ }: {
28
+ api: () => popover.Api<PropTypes>;
29
+ title: string;
30
+ closeLabel: string | undefined;
31
+ class: string | undefined;
32
+ style: string | undefined;
33
+ attributes: Record<string, unknown>;
34
+ children: Snippet | undefined;
35
+ content: HTMLElement | undefined;
36
+ } = $props();
37
+
38
+ // Nothing inside opens an overlay from a control outside it.
39
+ resetTrigger();
40
+ const labels = useLabels();
41
+ const present = createPresence(
42
+ () => api().open,
43
+ () => [content],
44
+ );
45
+ </script>
46
+
47
+ {#if present()}
48
+ <Portal>
49
+ <div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
50
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
51
+ <section
52
+ {...mergeProps(api().getContentProps(), {
53
+ ...rootAttributes(attributes),
54
+ class: classes("xds-popover", className),
55
+ style,
56
+ })}
57
+ bind:this={content}
58
+ hidden={false}
59
+ >
60
+ <div class={POPOVER_PARTS.header}>
61
+ <h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>{title}</h2>
62
+ <IconButton
63
+ icon="x"
64
+ label={closeLabel ?? labels().close}
65
+ variant="ghost"
66
+ size="sm"
67
+ class={POPOVER_PARTS.close}
68
+ onPress={() => api().setOpen(false)}
69
+ />
70
+ </div>
71
+ {#if children}
72
+ <div class={POPOVER_PARTS.body}>{@render children()}</div>
73
+ {/if}
74
+ </section>
75
+ </div>
76
+ </Portal>
77
+ {/if}
@@ -0,0 +1,21 @@
1
+ import type * as popover from "@zag-js/popover";
2
+ import { type PropTypes } from "@zag-js/svelte";
3
+ import type { Snippet } from "svelte";
4
+ type $$ComponentProps = {
5
+ api: () => popover.Api<PropTypes>;
6
+ title: string;
7
+ closeLabel: string | undefined;
8
+ class: string | undefined;
9
+ style: string | undefined;
10
+ attributes: Record<string, unknown>;
11
+ children: Snippet | undefined;
12
+ content: HTMLElement | undefined;
13
+ };
14
+ /**
15
+ * What a Popover draws while it is open: the surface, with its title, its close button and its
16
+ * content. A component of its own so that the controls in it get none of the trigger props the
17
+ * Popover gives its trigger. Only for Popover: the index does not export it.
18
+ */
19
+ declare const PopoverSurface: import("svelte").Component<$$ComponentProps, {}, "content">;
20
+ type PopoverSurface = ReturnType<typeof PopoverSurface>;
21
+ export default PopoverSurface;
@@ -16,15 +16,17 @@
16
16
  progressBarClass,
17
17
  progressBarFillClass,
18
18
  progressPercent,
19
+ rootAttributes,
19
20
  rootPart,
20
21
  } from "@xds/core";
21
22
 
22
- let { value, label, class: className, style }: ProgressBarProps = $props();
23
+ let { value, label, class: className, style, ...rest }: ProgressBarProps = $props();
23
24
 
24
25
  const percent = $derived(progressPercent(value));
25
26
  </script>
26
27
 
27
28
  <div
29
+ {...rootAttributes(rest)}
28
30
  role="progressbar"
29
31
  aria-label={label}
30
32
  aria-valuemin={0}
@@ -5,7 +5,9 @@
5
5
 
6
6
  The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
7
7
  options are native radio buttons, hidden and drawn beside, in a group named by the legend: the
8
- arrow keys move between them, and the error is tied to the group and announced.
8
+ arrow keys move between them, and the error is tied to the group and announced. Without
9
+ `value` it keeps its own choice, from `defaultValue`, and a reset of its form puts that back;
10
+ given `value`, even as `undefined`, it shows the app's.
9
11
  -->
10
12
  <script module lang="ts">
11
13
  import type { RadioGroupBaseProps } from "@xds/core";
@@ -15,34 +17,47 @@
15
17
 
16
18
  export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
17
19
  RootProps & {
18
- onChange: (value: Value) => void;
20
+ onChange?: (value: Value) => void;
19
21
  };
20
22
  </script>
21
23
 
22
24
  <script lang="ts" generics="Value extends string = string">
23
- import { classes } from "@xds/core";
25
+ import { classes, rootAttributes } from "@xds/core";
26
+ import { controllable, followFormReset } from "./controllable.svelte.js";
24
27
  import { keepChecked } from "./controlled.js";
25
28
 
29
+ // `value` stays in the rest, where whether it is given at all can be asked.
26
30
  let {
27
31
  label,
28
32
  options,
29
- value,
33
+ defaultValue,
30
34
  disabled,
31
35
  error,
32
36
  name,
33
37
  onChange,
34
38
  class: className,
35
39
  style,
40
+ ...rest
36
41
  }: RadioGroupProps<Value> = $props();
37
42
 
43
+ const control = controllable<Value | undefined, Value>(
44
+ () => rest,
45
+ "value",
46
+ () => rest.value,
47
+ () => defaultValue,
48
+ () => onChange,
49
+ );
50
+
38
51
  const id = $props.id();
39
52
  const labelId = `${id}-label`;
40
53
  const errorId = `${id}-error`;
41
54
  const invalid = $derived(error !== undefined);
42
55
  let group = $state<HTMLDivElement>();
56
+ followFormReset(() => group, control);
43
57
  </script>
44
58
 
45
59
  <div
60
+ {...rootAttributes(rest)}
46
61
  bind:this={group}
47
62
  role="radiogroup"
48
63
  aria-labelledby={labelId}
@@ -67,8 +82,8 @@
67
82
  class="xds-radio-group__input sr-only"
68
83
  name={name ?? id}
69
84
  value={option.value}
70
- checked={option.value === value}
71
- defaultChecked={option.value === value}
85
+ checked={option.value === control.current}
86
+ defaultChecked={option.value === (control.controlled ? control.current : defaultValue)}
72
87
  {disabled}
73
88
  aria-labelledby={`${id}-${index}`}
74
89
  aria-describedby={[
@@ -79,11 +94,11 @@
79
94
  .join(" ") || undefined}
80
95
  aria-invalid={invalid ? "true" : undefined}
81
96
  onchange={() => {
82
- onChange(option.value);
97
+ control.set(option.value);
83
98
  // The browser moved the dot already; where the owner kept the old value, it goes
84
99
  // back, on every radio of the group.
85
100
  for (const input of group?.querySelectorAll("input") ?? []) {
86
- keepChecked(input, () => input.value === value);
101
+ keepChecked(input, () => input.value === control.current);
87
102
  }
88
103
  }}
89
104
  />