@xds/svelte 1.1.0 → 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 (155) hide show
  1. package/dist/Breadcrumb.svelte +53 -0
  2. package/dist/Breadcrumb.svelte.d.ts +11 -0
  3. package/dist/Checkbox.svelte +11 -3
  4. package/dist/Checkbox.svelte.d.ts +2 -1
  5. package/dist/Combobox.svelte +194 -0
  6. package/dist/Combobox.svelte.d.ts +37 -0
  7. package/dist/DatePicker.svelte +5 -4
  8. package/dist/Link.svelte +86 -0
  9. package/dist/Link.svelte.d.ts +26 -0
  10. package/dist/Menu.svelte +8 -1
  11. package/dist/Pagination.svelte +108 -0
  12. package/dist/Pagination.svelte.d.ts +14 -0
  13. package/dist/Popover.svelte +91 -0
  14. package/dist/Popover.svelte.d.ts +21 -0
  15. package/dist/PopoverSurface.svelte +77 -0
  16. package/dist/PopoverSurface.svelte.d.ts +21 -0
  17. package/dist/Select.svelte +40 -8
  18. package/dist/Select.svelte.d.ts +6 -0
  19. package/dist/Table.svelte +92 -0
  20. package/dist/Table.svelte.d.ts +17 -0
  21. package/dist/TimePicker.svelte +222 -0
  22. package/dist/TimePicker.svelte.d.ts +20 -0
  23. package/dist/ToastQueue.svelte +57 -0
  24. package/dist/ToastQueue.svelte.d.ts +20 -0
  25. package/dist/base.d.ts +14 -0
  26. package/dist/base.js +27 -0
  27. package/dist/index.d.ts +11 -2
  28. package/dist/index.js +11 -0
  29. package/dist/modal-popover.svelte.js +5 -1
  30. package/dist/presence.svelte.js +5 -2
  31. package/dist/preview/Component.svelte +6 -3
  32. package/dist/preview/Preview.svelte +8 -2
  33. package/dist/preview/Preview.svelte.d.ts +2 -0
  34. package/dist/preview/components.d.ts +9 -2
  35. package/dist/preview/components.js +18 -2
  36. package/dist/preview/index.d.ts +1 -0
  37. package/eject/files/Accordion.svelte +100 -0
  38. package/eject/files/AccordionPanel.svelte +48 -0
  39. package/eject/files/Avatar.svelte +51 -0
  40. package/eject/files/AvatarStack.svelte +61 -0
  41. package/eject/files/Badge.svelte +52 -0
  42. package/eject/files/Banner.svelte +94 -0
  43. package/eject/files/Breadcrumb.svelte +52 -0
  44. package/eject/files/Button.svelte +126 -0
  45. package/eject/files/Card.svelte +112 -0
  46. package/eject/files/Checkbox.svelte +121 -0
  47. package/eject/files/Chip.svelte +51 -0
  48. package/eject/files/ChipBar.svelte +39 -0
  49. package/eject/files/Combobox.svelte +198 -0
  50. package/eject/files/CountBadge.svelte +51 -0
  51. package/eject/files/DatePicker.svelte +213 -0
  52. package/eject/files/DateRangePicker.svelte +294 -0
  53. package/eject/files/Dialog.svelte +119 -0
  54. package/eject/files/Divider.svelte +27 -0
  55. package/eject/files/EmptyState.svelte +52 -0
  56. package/eject/files/Icon.svelte +51 -0
  57. package/eject/files/IconButton.svelte +99 -0
  58. package/eject/files/Link.svelte +85 -0
  59. package/eject/files/ListRow.svelte +33 -0
  60. package/eject/files/MediaCard.svelte +117 -0
  61. package/eject/files/Menu.svelte +183 -0
  62. package/eject/files/Pagination.svelte +109 -0
  63. package/eject/files/PlaceRow.svelte +75 -0
  64. package/eject/files/Popover.svelte +100 -0
  65. package/eject/files/PopoverSurface.svelte +85 -0
  66. package/eject/files/ProgressBar.svelte +38 -0
  67. package/eject/files/RadioGroup.svelte +133 -0
  68. package/eject/files/SearchField.svelte +154 -0
  69. package/eject/files/SectionHeader.svelte +67 -0
  70. package/eject/files/SegmentedControl.svelte +85 -0
  71. package/eject/files/Select.svelte +276 -0
  72. package/eject/files/Sidebar.svelte +130 -0
  73. package/eject/files/SidebarRailButton.svelte +32 -0
  74. package/eject/files/Skeleton.svelte +55 -0
  75. package/eject/files/Slider.svelte +136 -0
  76. package/eject/files/Spinner.svelte +41 -0
  77. package/eject/files/Switch.svelte +105 -0
  78. package/eject/files/Table.svelte +90 -0
  79. package/eject/files/Tabs.svelte +85 -0
  80. package/eject/files/Text.svelte +43 -0
  81. package/eject/files/TextField.svelte +222 -0
  82. package/eject/files/Thumbnail.svelte +88 -0
  83. package/eject/files/TimePicker.svelte +237 -0
  84. package/eject/files/Toast.svelte +98 -0
  85. package/eject/files/ToastQueue.svelte +61 -0
  86. package/eject/files/Tooltip.svelte +51 -0
  87. package/eject/files/TooltipOverlay.svelte +88 -0
  88. package/eject/files/accordion.css +89 -0
  89. package/eject/files/accordion.ts +67 -0
  90. package/eject/files/avatar-stack.ts +57 -0
  91. package/eject/files/avatar.ts +42 -0
  92. package/eject/files/badge.ts +30 -0
  93. package/eject/files/banner.ts +71 -0
  94. package/eject/files/base.css +38 -0
  95. package/eject/files/breadcrumb.css +51 -0
  96. package/eject/files/breadcrumb.ts +42 -0
  97. package/eject/files/button.css +241 -0
  98. package/eject/files/button.ts +106 -0
  99. package/eject/files/card.ts +58 -0
  100. package/eject/files/checkbox.ts +52 -0
  101. package/eject/files/chip-bar.ts +16 -0
  102. package/eject/files/chip.ts +35 -0
  103. package/eject/files/combobox.css +269 -0
  104. package/eject/files/combobox.ts +85 -0
  105. package/eject/files/count-badge.ts +32 -0
  106. package/eject/files/date-picker.css +375 -0
  107. package/eject/files/date-picker.ts +280 -0
  108. package/eject/files/date-range-picker.ts +338 -0
  109. package/eject/files/dialog.css +139 -0
  110. package/eject/files/dialog.ts +15 -0
  111. package/eject/files/divider.ts +5 -0
  112. package/eject/files/empty-state.ts +22 -0
  113. package/eject/files/icon.ts +36 -0
  114. package/eject/files/link.css +64 -0
  115. package/eject/files/link.ts +63 -0
  116. package/eject/files/list-row.ts +66 -0
  117. package/eject/files/media-card.ts +66 -0
  118. package/eject/files/menu.css +192 -0
  119. package/eject/files/menu.ts +84 -0
  120. package/eject/files/overlay.css +40 -0
  121. package/eject/files/pagination.css +106 -0
  122. package/eject/files/pagination.ts +68 -0
  123. package/eject/files/parts.ts +17 -0
  124. package/eject/files/popover.css +101 -0
  125. package/eject/files/popover.ts +37 -0
  126. package/eject/files/progress-bar.ts +26 -0
  127. package/eject/files/radio-group.css +184 -0
  128. package/eject/files/radio-group.ts +30 -0
  129. package/eject/files/section-header.ts +32 -0
  130. package/eject/files/segmented-control.ts +33 -0
  131. package/eject/files/select.css +347 -0
  132. package/eject/files/select.ts +77 -0
  133. package/eject/files/sidebar.ts +75 -0
  134. package/eject/files/skeleton.ts +51 -0
  135. package/eject/files/slider.css +160 -0
  136. package/eject/files/slider.ts +80 -0
  137. package/eject/files/spinner.ts +22 -0
  138. package/eject/files/switch.ts +45 -0
  139. package/eject/files/table.css +107 -0
  140. package/eject/files/table.ts +84 -0
  141. package/eject/files/tabs.css +120 -0
  142. package/eject/files/tabs.ts +37 -0
  143. package/eject/files/text-field.css +225 -0
  144. package/eject/files/text-field.ts +64 -0
  145. package/eject/files/text.ts +38 -0
  146. package/eject/files/thumbnail.ts +51 -0
  147. package/eject/files/time-picker.ts +113 -0
  148. package/eject/files/toast-queue.ts +64 -0
  149. package/eject/files/toast.ts +31 -0
  150. package/eject/files/tooltip.css +111 -0
  151. package/eject/files/tooltip.ts +21 -0
  152. package/eject/manifest.json +1053 -0
  153. package/package.json +12 -4
  154. package/styles.css +1064 -169
  155. package/tailwind.css +1295 -218
@@ -0,0 +1,53 @@
1
+ <!--
2
+ @component
3
+ Where the current view sits in the app: the places above it, each a link, then the view
4
+ itself. A navigation landmark; the current place is marked as the page.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { BreadcrumbBaseProps } from "@xds/core";
8
+ import type { RootProps } from "./root.js";
9
+
10
+ export type { BreadcrumbItem } from "@xds/core";
11
+ export type BreadcrumbProps = BreadcrumbBaseProps & RootProps;
12
+ </script>
13
+
14
+ <script lang="ts">
15
+ import {
16
+ BREADCRUMB_PARTS,
17
+ BREADCRUMB_SEPARATOR,
18
+ classes,
19
+ rootAttributes,
20
+ rootPart,
21
+ } from "@xds/core";
22
+ import Icon from "./Icon.svelte";
23
+ import { useLabels } from "./labels.svelte.js";
24
+ import Link from "./Link.svelte";
25
+
26
+ let { items, label, class: className, style, ...rest }: BreadcrumbProps = $props();
27
+ const labels = useLabels();
28
+ </script>
29
+
30
+ <nav
31
+ {...rootAttributes(rest)}
32
+ aria-label={label ?? labels().breadcrumb}
33
+ class={classes(rootPart("Breadcrumb"), className)}
34
+ {style}
35
+ >
36
+ <ol class={BREADCRUMB_PARTS.list}>
37
+ <!-- Two places of a trail can share a label, so a place is known by where it is. -->
38
+ {#each items as item, index (index)}
39
+ <li class={BREADCRUMB_PARTS.item}>
40
+ {#if index === items.length - 1}
41
+ <span aria-current="page" class={BREADCRUMB_PARTS.current}>{item.label}</span>
42
+ {:else}
43
+ <Link href={item.href} onPress={item.onPress}>{item.label}</Link>
44
+ <Icon
45
+ name={BREADCRUMB_SEPARATOR.name}
46
+ size={BREADCRUMB_SEPARATOR.size}
47
+ class={BREADCRUMB_PARTS.separator}
48
+ />
49
+ {/if}
50
+ </li>
51
+ {/each}
52
+ </ol>
53
+ </nav>
@@ -0,0 +1,11 @@
1
+ import type { BreadcrumbBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type { BreadcrumbItem } from "@xds/core";
4
+ export type BreadcrumbProps = BreadcrumbBaseProps & RootProps;
5
+ /**
6
+ * Where the current view sits in the app: the places above it, each a link, then the view
7
+ * itself. A navigation landmark; the current place is marked as the page.
8
+ */
9
+ declare const Breadcrumb: import("svelte").Component<BreadcrumbProps, {}, "">;
10
+ type Breadcrumb = ReturnType<typeof Breadcrumb>;
11
+ export default Breadcrumb;
@@ -2,7 +2,8 @@
2
2
  @component
3
3
  A choice that is applied later, with the form it belongs to. A native checkbox: the input is
4
4
  hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
5
- `defaultChecked`, and a reset of its form puts that back.
5
+ `defaultChecked`, and a reset of its form puts that back. With `indeterminate` it shows a dash
6
+ and is reported as mixed.
6
7
 
7
8
  `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
8
9
  -->
@@ -21,10 +22,10 @@
21
22
 
22
23
  <script lang="ts">
23
24
  import {
24
- CHECKBOX_MARK,
25
25
  checkboxBoxClass,
26
26
  checkboxClass,
27
27
  checkboxLabelClass,
28
+ checkboxMark,
28
29
  checkboxMarkClass,
29
30
  classes,
30
31
  rootAttributes,
@@ -36,6 +37,7 @@
36
37
  // `checked` stays in the rest, where whether it is given at all can be asked.
37
38
  let {
38
39
  defaultChecked = false,
40
+ indeterminate = false,
39
41
  label,
40
42
  "aria-label": ariaLabel,
41
43
  name,
@@ -57,6 +59,10 @@
57
59
  );
58
60
  let input = $state<HTMLInputElement>();
59
61
  followFormReset(() => input, control);
62
+ // A property of the native input, with no attribute: it is what reports the box as mixed.
63
+ $effect(() => {
64
+ if (input) input.indeterminate = indeterminate;
65
+ });
60
66
 
61
67
  /** Moves the focus to the native checkbox. */
62
68
  export function focus(options?: FocusOptions) {
@@ -89,6 +95,8 @@
89
95
  {disabled}
90
96
  name={name || undefined}
91
97
  onchange={(event) => {
98
+ // A press clears it on the input; it stays until the app clears it.
99
+ event.currentTarget.indeterminate = indeterminate;
92
100
  control.set(event.currentTarget.checked);
93
101
  keepChecked(event.currentTarget, () => control.current);
94
102
  }}
@@ -98,7 +106,7 @@
98
106
  <span class={checkboxBoxClass}>
99
107
  <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
100
108
  <path
101
- d={CHECKBOX_MARK}
109
+ d={checkboxMark(indeterminate)}
102
110
  stroke="currentColor"
103
111
  stroke-width="2"
104
112
  stroke-linecap="round"
@@ -9,7 +9,8 @@ export type CheckboxProps = CheckboxBaseProps & RootProps & {
9
9
  /**
10
10
  * A choice that is applied later, with the form it belongs to. A native checkbox: the input is
11
11
  * hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
12
- * `defaultChecked`, and a reset of its form puts that back.
12
+ * `defaultChecked`, and a reset of its form puts that back. With `indeterminate` it shows a dash
13
+ * and is reported as mixed.
13
14
  *
14
15
  * `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
15
16
  */
@@ -0,0 +1,194 @@
1
+ <!--
2
+ @component
3
+ A field for choosing one option from a list by typing part of its name. As the person types, the
4
+ options whose label holds what was typed open under it, those that start with it first, and the
5
+ first is highlighted, so Enter chooses it. Choosing an option calls `onChange`, puts its label in
6
+ the field and closes the list. Text that names no option goes back to the chosen option's label
7
+ when the field is left. When nothing matches, the list says so. Without `value` it keeps its own
8
+ choice, from `defaultValue`.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { ComboboxBaseProps } from "@xds/core";
12
+ import type { RootProps } from "./root.js";
13
+
14
+ export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value> &
15
+ RootProps & {
16
+ onChange?: (value: Value) => void;
17
+ };
18
+ </script>
19
+
20
+ <script lang="ts" generics="Value extends string = string">
21
+ import { space } from "@xds/tokens";
22
+ import {
23
+ COMBOBOX_PARTS as PARTS,
24
+ classes,
25
+ createItemPropsCache,
26
+ matchOptions,
27
+ readCssPx,
28
+ rootAttributes,
29
+ type SelectOption,
30
+ selectOptionIds,
31
+ } from "@xds/core";
32
+ import * as combobox from "@zag-js/combobox";
33
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
34
+ import { controllable, followFormReset } from "./controllable.svelte.js";
35
+ import Icon from "./Icon.svelte";
36
+ import { useLabels } from "./labels.svelte.js";
37
+ import Portal from "./Portal.svelte";
38
+
39
+ let {
40
+ label,
41
+ options,
42
+ defaultValue,
43
+ placeholder,
44
+ description,
45
+ error,
46
+ name,
47
+ disabled,
48
+ onChange,
49
+ emptyLabel,
50
+ class: className,
51
+ style,
52
+ ...rest
53
+ }: ComboboxProps<Value> = $props();
54
+
55
+ const labels = useLabels();
56
+ const control = controllable<Value | undefined, Value>(
57
+ () => rest,
58
+ "value",
59
+ () => rest.value,
60
+ () => defaultValue,
61
+ () => onChange,
62
+ );
63
+ const value = $derived(control.current);
64
+ let root = $state<HTMLDivElement>();
65
+ followFormReset(() => root, control);
66
+
67
+ const id = $props.id();
68
+ const descriptionId = `${id}-description`;
69
+ const errorId = `${id}-error`;
70
+ const invalid = $derived(error !== undefined);
71
+ // What the person typed, which narrows the list. Choosing an option puts its label in the field
72
+ // without narrowing it, so the list opens on every option again.
73
+ let query = $state("");
74
+ const shown = $derived(matchOptions(options, query));
75
+ const collection = $derived(
76
+ combobox.collection<SelectOption<Value>>({
77
+ items: shown,
78
+ itemToValue: (option) => option.value,
79
+ itemToString: (option) => option.label,
80
+ }),
81
+ );
82
+ const service = useMachine(combobox.machine, () => ({
83
+ id,
84
+ collection,
85
+ value: value === undefined ? [] : [value],
86
+ onValueChange: (details: combobox.ValueChangeDetails<SelectOption<Value>>) => {
87
+ const next = details.value[0];
88
+ if (next !== undefined) control.set(next as Value);
89
+ },
90
+ onInputValueChange: (details: combobox.InputValueChangeDetails) => {
91
+ if (details.reason === "input-change") query = details.inputValue;
92
+ },
93
+ onOpenChange: (details: combobox.OpenChangeDetails) => {
94
+ if (!details.open) query = "";
95
+ },
96
+ // The first match is highlighted as the person types, so Enter chooses it.
97
+ inputBehavior: "autohighlight" as const,
98
+ selectionBehavior: "replace" as const,
99
+ openOnClick: true,
100
+ disabled,
101
+ invalid,
102
+ placeholder,
103
+ positioning: {
104
+ placement: "bottom-start" as const,
105
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
106
+ sameWidth: true,
107
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
108
+ },
109
+ }));
110
+ const api = $derived(combobox.connect(service, normalizeProps));
111
+ // The rows' props as they last were while they draw the same, so that a step of the highlight
112
+ // sets the attributes and the handlers of the two rows it moves between, not of every row.
113
+ const keep = createItemPropsCache();
114
+ // Zag puts the chosen label back only when the list closes by a press outside; after Escape,
115
+ // text that names no option would stay in a field that has left it.
116
+ const input = $derived(
117
+ mergeProps(api.getInputProps(), {
118
+ onblur: () => {
119
+ const chosen = options.find((option) => option.value === value)?.label ?? "";
120
+ const now = combobox.connect(service, normalizeProps);
121
+ if (now.inputValue !== chosen) now.setInputValue(chosen, "script");
122
+ },
123
+ }),
124
+ );
125
+ </script>
126
+
127
+ <!-- Merged, so that the app's style joins any the machine writes on the root. -->
128
+ <div
129
+ bind:this={root}
130
+ {...mergeProps(api.getRootProps(), {
131
+ ...rootAttributes(rest),
132
+ class: classes("xds-combobox", className),
133
+ style,
134
+ })}
135
+ >
136
+ <label {...api.getLabelProps()} class={PARTS.label}>{label}</label>
137
+ <div {...api.getControlProps()} class={PARTS.control}>
138
+ <input
139
+ {...input}
140
+ aria-describedby={invalid ? errorId : description ? descriptionId : undefined}
141
+ class={PARTS.input}
142
+ />
143
+ <Icon name="chevrons-up-down" size="sm" class={PARTS.icon} />
144
+ </div>
145
+ <div class={PARTS.footer}>
146
+ {#if !invalid && description}
147
+ <span id={descriptionId} class={PARTS.description}>{description}</span>
148
+ {/if}
149
+ <span id={errorId} class={PARTS.error} aria-live="polite">{error}</span>
150
+ </div>
151
+ <!-- What a form submits: the option's value, where the field holds its label. -->
152
+ {#if name !== undefined}
153
+ <input type="hidden" {name} value={value ?? ""} />
154
+ {/if}
155
+ <Portal>
156
+ <div {...api.getPositionerProps()} class={PARTS.positioner}>
157
+ <!-- Zag hides it while closed. It goes at once, with no animation out: it comes and goes as
158
+ the person types. -->
159
+ <div {...api.getContentProps()} class={PARTS.content}>
160
+ {#if shown.length === 0}
161
+ <div {...api.getEmptyProps()} class={PARTS.empty}>{emptyLabel ?? labels().noMatches}</div>
162
+ {:else}
163
+ <div {...api.getListProps()} class={PARTS.list}>
164
+ {#each shown as option, index (option.value)}
165
+ {@const ids = selectOptionIds(id, index)}
166
+ <div
167
+ {...keep(`item:${option.value}`, api.getItemProps({ item: option }))}
168
+ aria-labelledby={ids.label}
169
+ aria-describedby={option.description ? ids.description : undefined}
170
+ class={PARTS.item}
171
+ >
172
+ <span class={PARTS.itemWords}>
173
+ <span
174
+ {...keep(`text:${option.value}`, api.getItemTextProps({ item: option }))}
175
+ id={ids.label}
176
+ class={PARTS.itemLabel}>{option.label}</span
177
+ >
178
+ {#if option.description}
179
+ <span id={ids.description} class={PARTS.itemDescription}
180
+ >{option.description}</span
181
+ >
182
+ {/if}
183
+ </span>
184
+ {#if api.getItemState({ item: option }).selected}
185
+ <Icon name="check" size="sm" />
186
+ {/if}
187
+ </div>
188
+ {/each}
189
+ </div>
190
+ {/if}
191
+ </div>
192
+ </div>
193
+ </Portal>
194
+ </div>
@@ -0,0 +1,37 @@
1
+ import type { ComboboxBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type ComboboxProps<Value extends string = string> = ComboboxBaseProps<Value> & RootProps & {
4
+ onChange?: (value: Value) => void;
5
+ };
6
+ declare function $$render<Value extends string = string>(): {
7
+ props: ComboboxProps<Value>;
8
+ exports: {};
9
+ bindings: "";
10
+ slots: {};
11
+ events: {};
12
+ };
13
+ declare class __sveltets_Render<Value extends string = string> {
14
+ props(): ReturnType<typeof $$render<Value>>['props'];
15
+ events(): ReturnType<typeof $$render<Value>>['events'];
16
+ slots(): ReturnType<typeof $$render<Value>>['slots'];
17
+ bindings(): "";
18
+ exports(): {};
19
+ }
20
+ interface $$IsomorphicComponent {
21
+ new <Value extends string = string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Value>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Value>['props']>, ReturnType<__sveltets_Render<Value>['events']>, ReturnType<__sveltets_Render<Value>['slots']>> & {
22
+ $$bindings?: ReturnType<__sveltets_Render<Value>['bindings']>;
23
+ } & ReturnType<__sveltets_Render<Value>['exports']>;
24
+ <Value extends string = string>(internal: unknown, props: ReturnType<__sveltets_Render<Value>['props']> & {}): ReturnType<__sveltets_Render<Value>['exports']>;
25
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
26
+ }
27
+ /**
28
+ * A field for choosing one option from a list by typing part of its name. As the person types, the
29
+ * options whose label holds what was typed open under it, those that start with it first, and the
30
+ * first is highlighted, so Enter chooses it. Choosing an option calls `onChange`, puts its label in
31
+ * the field and closes the list. Text that names no option goes back to the chosen option's label
32
+ * when the field is left. When nothing matches, the list says so. Without `value` it keeps its own
33
+ * choice, from `defaultValue`.
34
+ */
35
+ declare const Combobox: $$IsomorphicComponent;
36
+ type Combobox<Value extends string = string> = InstanceType<typeof Combobox<Value>>;
37
+ export default Combobox;
@@ -80,15 +80,16 @@
80
80
  () => api.open,
81
81
  () => [surface],
82
82
  );
83
- // Strings, so that the effect below runs only when the focused day or the month changes, not
84
- // on every change of the machine.
83
+ // Derived, so that the effect below runs only when the calendar opens or closes or the focused
84
+ // day or the month changes, not on every change of the machine.
85
+ const open = $derived(api.open);
85
86
  const focused = $derived(api.focusedValue.toString());
86
87
  const month = $derived(api.visibleRange.start.toString());
87
88
  $effect(() => {
88
- const open = api.open;
89
+ const isOpen = open;
89
90
  void focused;
90
91
  void month;
91
- untrack(() => keepDayFocused(open, surface));
92
+ untrack(() => keepDayFocused(isOpen, surface));
92
93
  });
93
94
  </script>
94
95
 
@@ -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;
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,
@@ -74,6 +75,9 @@
74
75
  loopFocus: true,
75
76
  }));
76
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();
77
81
  // Whether the last press on the trigger opened the menu, which its click must then not do.
78
82
  let pressOpened = false;
79
83
  provideTrigger(() => {
@@ -155,7 +159,10 @@
155
159
  <div {...api.getSeparatorProps()} class="xds-menu__separator"></div>
156
160
  {:else}
157
161
  <div
158
- {...api.getItemProps({ value: String(index), disabled: item.disabled })}
162
+ {...keep(
163
+ `item:${index}`,
164
+ api.getItemProps({ value: String(index), disabled: item.disabled }),
165
+ )}
159
166
  class={menuItemClass(item.danger)}
160
167
  >
161
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;