@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,100 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A surface that opens beside the control that opens it, for details or a short task that do not
8
+ need the whole screen: a press outside, Escape or its close button closes it, and the focus goes
9
+ back to the trigger. It is a dialog named by its title, and not modal: the page stays as it is
10
+ behind it. Without `open` it keeps its own, from `defaultOpen`.
11
+ -->
12
+ <script module lang="ts">
13
+ import type { RootProps } from "@xds/svelte/base";
14
+ import type { Snippet } from "svelte";
15
+ import type { PopoverBaseProps } from "./popover.ts";
16
+
17
+ /** Its root is the surface, while it is open, not its trigger. */
18
+ export type PopoverProps = PopoverBaseProps &
19
+ RootProps & {
20
+ /** The control that opens it: a Button or an IconButton. */
21
+ trigger: Snippet;
22
+ /** Called with whether it is open, as it opens and closes. */
23
+ onOpenChange?: (open: boolean) => void;
24
+ /** What it holds: a few lines of text, a short form, actions. */
25
+ children?: Snippet;
26
+ };
27
+ </script>
28
+
29
+ <script lang="ts">
30
+ import {
31
+ controllable,
32
+ leaveEscapeToFields,
33
+ provideTrigger,
34
+ readCssPx,
35
+ space,
36
+ type TriggerProps,
37
+ } from "@xds/svelte/base";
38
+ import * as popover from "@zag-js/popover";
39
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
40
+ import { POPOVER_PARTS } from "./popover.ts";
41
+ import PopoverSurface from "./PopoverSurface.svelte";
42
+
43
+ // `open` stays in the rest, where whether it is given at all can be asked.
44
+ let {
45
+ title,
46
+ placement,
47
+ closeLabel,
48
+ defaultOpen,
49
+ onOpenChange,
50
+ trigger,
51
+ children,
52
+ class: className,
53
+ style,
54
+ ...rest
55
+ }: PopoverProps = $props();
56
+
57
+ const control = controllable<boolean | undefined, boolean>(
58
+ () => rest,
59
+ "open",
60
+ () => rest.open,
61
+ () => defaultOpen ?? false,
62
+ () => onOpenChange,
63
+ );
64
+ const id = $props.id();
65
+ let content = $state<HTMLElement>();
66
+ const service = useMachine(popover.machine, () => ({
67
+ id,
68
+ // The app's id names the surface, and the trigger's aria-controls points there.
69
+ ids: rest.id === undefined ? undefined : { content: rest.id },
70
+ open: control.current ?? false,
71
+ onOpenChange: (details: popover.OpenChangeDetails) => control.set(details.open),
72
+ positioning: {
73
+ placement: placement ?? "bottom",
74
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
75
+ },
76
+ onEscapeKeyDown: leaveEscapeToFields,
77
+ // The surface itself rather than its first control: a screen reader then reads the title
78
+ // first, and the close button is the next stop.
79
+ initialFocusEl: () => content ?? null,
80
+ }));
81
+ const api = $derived(popover.connect(service, normalizeProps));
82
+ // Added to the control's own class; the trigger looks pressed while it is open.
83
+ provideTrigger(
84
+ () => mergeProps(api.getTriggerProps(), { class: POPOVER_PARTS.trigger }) as TriggerProps,
85
+ );
86
+ // What the app gives the root, without `open`, which is the machine's.
87
+ const { open: _open, ...attributes } = $derived(rest);
88
+ </script>
89
+
90
+ {@render trigger()}
91
+ <PopoverSurface
92
+ api={() => api}
93
+ {title}
94
+ {closeLabel}
95
+ class={className}
96
+ {style}
97
+ {attributes}
98
+ {children}
99
+ bind:content
100
+ />
@@ -0,0 +1,85 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ What a Popover draws while it is open: the surface, with its title, its close button and its
8
+ content. A component of its own so that the controls in it get none of the trigger props the
9
+ Popover gives its trigger. Only for Popover: the index does not export it.
10
+ -->
11
+ <script lang="ts">
12
+ import {
13
+ createPresence,
14
+ Portal,
15
+ resetTrigger,
16
+ rootAttributes,
17
+ useLabels,
18
+ } from "@xds/svelte/base";
19
+ import type * as popover from "@zag-js/popover";
20
+ import { mergeProps, type PropTypes } from "@zag-js/svelte";
21
+ import type { Snippet } from "svelte";
22
+ import IconButton from "./IconButton.svelte";
23
+ import { classes } from "./parts.ts";
24
+ import { POPOVER_PARTS } from "./popover.ts";
25
+
26
+ let {
27
+ api,
28
+ title,
29
+ closeLabel,
30
+ class: className,
31
+ style,
32
+ attributes,
33
+ children,
34
+ content = $bindable(),
35
+ }: {
36
+ api: () => popover.Api<PropTypes>;
37
+ title: string;
38
+ closeLabel: string | undefined;
39
+ class: string | undefined;
40
+ style: string | undefined;
41
+ attributes: Record<string, unknown>;
42
+ children: Snippet | undefined;
43
+ content: HTMLElement | undefined;
44
+ } = $props();
45
+
46
+ // Nothing inside opens an overlay from a control outside it.
47
+ resetTrigger();
48
+ const labels = useLabels();
49
+ const present = createPresence(
50
+ () => api().open,
51
+ () => [content],
52
+ );
53
+ </script>
54
+
55
+ {#if present()}
56
+ <Portal>
57
+ <div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
58
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
59
+ <section
60
+ {...mergeProps(api().getContentProps(), {
61
+ ...rootAttributes(attributes),
62
+ class: classes("{{prefix}}-popover", className),
63
+ style,
64
+ })}
65
+ bind:this={content}
66
+ hidden={false}
67
+ >
68
+ <div class={POPOVER_PARTS.header}>
69
+ <h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>{title}</h2>
70
+ <IconButton
71
+ icon="x"
72
+ label={closeLabel ?? labels().close}
73
+ variant="ghost"
74
+ size="sm"
75
+ class={POPOVER_PARTS.close}
76
+ onPress={() => api().setOpen(false)}
77
+ />
78
+ </div>
79
+ {#if children}
80
+ <div class={POPOVER_PARTS.body}>{@render children()}</div>
81
+ {/if}
82
+ </section>
83
+ </div>
84
+ </Portal>
85
+ {/if}
@@ -0,0 +1,38 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ How far along something is, from 0 to 1. For work of unknown length use a Spinner. `label` says
8
+ what is progressing; a screen reader reads it with the percentage.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { RootProps } from "@xds/svelte/base";
12
+ import type { ProgressBarBaseProps } from "./progress-bar.ts";
13
+
14
+ export type ProgressBarProps = ProgressBarBaseProps & RootProps;
15
+ </script>
16
+
17
+ <script lang="ts">
18
+ import { rootAttributes } from "@xds/svelte/base";
19
+ import { classes, rootPart } from "./parts.ts";
20
+ import { progressBarClass, progressBarFillClass, progressPercent } from "./progress-bar.ts";
21
+
22
+ let { value, label, class: className, style, ...rest }: ProgressBarProps = $props();
23
+
24
+ const percent = $derived(progressPercent(value));
25
+ </script>
26
+
27
+ <div
28
+ {...rootAttributes(rest)}
29
+ role="progressbar"
30
+ aria-label={label}
31
+ aria-valuemin={0}
32
+ aria-valuemax={100}
33
+ aria-valuenow={percent}
34
+ class={classes(rootPart("ProgressBar"), progressBarClass, className)}
35
+ {style}
36
+ >
37
+ <div class={progressBarFillClass} style:width="{percent}%"></div>
38
+ </div>
@@ -0,0 +1,133 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ One choice among a few, applied later with the form it belongs to. For a choice that takes
8
+ effect at once among two to four options, a SegmentedControl is the usual pick.
9
+
10
+ The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
11
+ options are native radio buttons, hidden and drawn beside, in a group named by the legend: the
12
+ arrow keys move between them, and the error is tied to the group and announced. Without
13
+ `value` it keeps its own choice, from `defaultValue`, and a reset of its form puts that back;
14
+ given `value`, even as `undefined`, it shows the app's.
15
+ -->
16
+ <script module lang="ts">
17
+ import type { RootProps } from "@xds/svelte/base";
18
+ import type { RadioGroupBaseProps } from "./radio-group.ts";
19
+
20
+ export type { RadioOption } from "./radio-group.ts";
21
+
22
+ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
23
+ RootProps & {
24
+ onChange?: (value: Value) => void;
25
+ };
26
+ </script>
27
+
28
+ <script lang="ts" generics="Value extends string = string">
29
+ import { controllable, followFormReset, keepChecked, rootAttributes } from "@xds/svelte/base";
30
+ import { classes } from "./parts.ts";
31
+
32
+ // `value` stays in the rest, where whether it is given at all can be asked.
33
+ let {
34
+ label,
35
+ options,
36
+ defaultValue,
37
+ disabled,
38
+ error,
39
+ name,
40
+ onChange,
41
+ class: className,
42
+ style,
43
+ ...rest
44
+ }: RadioGroupProps<Value> = $props();
45
+
46
+ const control = controllable<Value | undefined, Value>(
47
+ () => rest,
48
+ "value",
49
+ () => rest.value,
50
+ () => defaultValue,
51
+ () => onChange,
52
+ );
53
+
54
+ const id = $props.id();
55
+ const labelId = `${id}-label`;
56
+ const errorId = `${id}-error`;
57
+ const invalid = $derived(error !== undefined);
58
+ let group = $state<HTMLDivElement>();
59
+ followFormReset(() => group, control);
60
+ </script>
61
+
62
+ <div
63
+ {...rootAttributes(rest)}
64
+ bind:this={group}
65
+ role="radiogroup"
66
+ aria-labelledby={labelId}
67
+ aria-describedby={invalid ? errorId : undefined}
68
+ aria-invalid={invalid ? "true" : undefined}
69
+ aria-disabled={disabled ? "true" : undefined}
70
+ aria-orientation="vertical"
71
+ class={classes("{{prefix}}-radio-group", className)}
72
+ {style}
73
+ >
74
+ <span id={labelId} class="{{prefix}}-radio-group__label">{label}</span>
75
+ <div class="{{prefix}}-radio-group__options">
76
+ {#each options as option, index (option.value)}
77
+ <label class="{{prefix}}-radio-group__option">
78
+ <!-- The description is inside the pressable row, so the row's text would name the radio
79
+ together with it. The label alone names it; the description describes it.
80
+ aria-invalid is on each radio as well as the group, so it is heard on the radio that
81
+ has focus. -->
82
+ <!-- svelte-ignore a11y_role_supports_aria_props_implicit -->
83
+ <input
84
+ type="radio"
85
+ class="{{prefix}}-radio-group__input sr-only"
86
+ name={name ?? id}
87
+ value={option.value}
88
+ checked={option.value === control.current}
89
+ defaultChecked={option.value === (control.controlled ? control.current : defaultValue)}
90
+ {disabled}
91
+ aria-labelledby={`${id}-${index}`}
92
+ aria-describedby={[
93
+ option.description ? `${id}-${index}-description` : undefined,
94
+ invalid ? errorId : undefined,
95
+ ]
96
+ .filter(Boolean)
97
+ .join(" ") || undefined}
98
+ aria-invalid={invalid ? "true" : undefined}
99
+ onchange={() => {
100
+ control.set(option.value);
101
+ // The browser moved the dot already; where the owner kept the old value, it goes
102
+ // back, on every radio of the group.
103
+ for (const input of group?.querySelectorAll("input") ?? []) {
104
+ keepChecked(input, () => input.value === control.current);
105
+ }
106
+ }}
107
+ />
108
+ <span class="{{prefix}}-radio-group__row">
109
+ <span class="{{prefix}}-radio-group__circle-line">
110
+ <span class="{{prefix}}-radio-group__circle"
111
+ ><span class="{{prefix}}-radio-group__dot"></span></span
112
+ >
113
+ </span>
114
+ <span class="{{prefix}}-radio-group__words">
115
+ <span id={`${id}-${index}`} class="{{prefix}}-radio-group__text">{option.label}</span>
116
+ {#if option.description}
117
+ <span id={`${id}-${index}-description`} class="{{prefix}}-radio-group__description"
118
+ >{option.description}</span
119
+ >
120
+ {/if}
121
+ </span>
122
+ </span>
123
+ </label>
124
+ {/each}
125
+ </div>
126
+ <!-- The region is there before the error is, so that the error is announced when it appears.
127
+ Empty, it takes no room. -->
128
+ <div aria-live="polite">
129
+ {#if invalid}
130
+ <span id={errorId} class="{{prefix}}-radio-group__error">{error}</span>
131
+ {/if}
132
+ </div>
133
+ </div>
@@ -0,0 +1,154 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A text field for a query: TextField's box as a pill, with a search icon in front and, while
8
+ there is a value, a control that clears it. Escape clears too. A read-only field has neither.
9
+
10
+ Use it to filter or search what is on the screen. For a value that is saved with a form, use a
11
+ TextField, which has a visible label. Without `value` it keeps its own query, from
12
+ `defaultValue`, and a reset of its form puts that back.
13
+
14
+ `focus()`, `blur()` and `element()` on the instance reach the native input.
15
+ -->
16
+ <script module lang="ts">
17
+ import type { RootProps } from "@xds/svelte/base";
18
+ import type { FocusEventHandler } from "svelte/elements";
19
+ import type { SearchFieldBaseProps } from "./text-field.ts";
20
+
21
+ export type SearchFieldProps = SearchFieldBaseProps &
22
+ RootProps & {
23
+ onChange?: (value: string) => void;
24
+ /** Called with the query on Enter, or on the search key of a software keyboard. */
25
+ onSubmit?: (value: string) => void;
26
+ onFocus?: FocusEventHandler<HTMLInputElement>;
27
+ onBlur?: FocusEventHandler<HTMLInputElement>;
28
+ };
29
+ </script>
30
+
31
+ <script lang="ts">
32
+ import {
33
+ controllable,
34
+ followFormReset,
35
+ keepValue,
36
+ rootAttributes,
37
+ useLabels,
38
+ } from "@xds/svelte/base";
39
+ import Icon from "./Icon.svelte";
40
+ import { classes, rootPart } from "./parts.ts";
41
+
42
+ // `value` stays in the rest, where whether it is given at all can be asked.
43
+ let {
44
+ defaultValue = "",
45
+ readOnly,
46
+ label,
47
+ placeholder,
48
+ disabled,
49
+ clearLabel,
50
+ onChange,
51
+ onSubmit,
52
+ onFocus,
53
+ onBlur,
54
+ class: className,
55
+ style,
56
+ ...rest
57
+ }: SearchFieldProps = $props();
58
+
59
+ const labels = useLabels();
60
+
61
+ const control = controllable(
62
+ () => rest,
63
+ "value",
64
+ () => rest.value ?? "",
65
+ () => defaultValue,
66
+ () => onChange,
67
+ );
68
+ let input = $state<HTMLInputElement>();
69
+ followFormReset(() => input, control);
70
+ // Nothing to clear in a field that cannot be changed.
71
+ const clearable = $derived(control.current !== "" && !disabled && !readOnly);
72
+
73
+ /** Moves the focus to the native input. */
74
+ export function focus(options?: FocusOptions) {
75
+ input?.focus(options);
76
+ }
77
+
78
+ /** Takes the focus from the native input. */
79
+ export function blur() {
80
+ input?.blur();
81
+ }
82
+
83
+ /** The native input, once it is on the page. */
84
+ export function element(): HTMLInputElement | undefined {
85
+ return input;
86
+ }
87
+ </script>
88
+
89
+ <!-- TextField's box, so its part as well as its own. -->
90
+ <div
91
+ {...rootAttributes(rest)}
92
+ class={classes("{{prefix}}-text-field", rootPart("SearchField"), className)}
93
+ {style}
94
+ >
95
+ <div
96
+ class="{{prefix}}-text-field__control {{prefix}}-text-field__control--pill {{prefix}}-text-field__group"
97
+ >
98
+ <span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading"
99
+ ><Icon name="search" size="sm" /></span
100
+ >
101
+ <!-- Escape clears only while there is something to clear; an empty field lets Escape
102
+ through to whatever it sits in, such as a dialog. -->
103
+ <input
104
+ bind:this={input}
105
+ type="text"
106
+ role="searchbox"
107
+ class="{{prefix}}-text-field__input"
108
+ aria-label={label}
109
+ enterkeyhint="search"
110
+ {placeholder}
111
+ value={control.current}
112
+ defaultValue={control.controlled ? control.current : defaultValue}
113
+ readonly={readOnly}
114
+ {disabled}
115
+ data-uses-escape={clearable ? "" : undefined}
116
+ oninput={(event) => {
117
+ control.set(event.currentTarget.value);
118
+ if (!(event instanceof InputEvent && event.isComposing))
119
+ keepValue(event.currentTarget, () => control.current);
120
+ }}
121
+ oncompositionend={(event) => keepValue(event.currentTarget, () => control.current)}
122
+ onkeydown={(event) => {
123
+ // While a composition is open, Enter and Escape belong to the input method.
124
+ if (event.isComposing) return;
125
+ if (event.key === "Enter" && onSubmit) {
126
+ event.preventDefault();
127
+ onSubmit(control.current);
128
+ }
129
+ if (event.key === "Escape" && clearable) {
130
+ event.stopPropagation();
131
+ control.set("");
132
+ }
133
+ }}
134
+ onfocus={onFocus}
135
+ onblur={onBlur}
136
+ />
137
+ {#if clearable}
138
+ <span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
139
+ <button
140
+ type="button"
141
+ aria-label={clearLabel ?? labels().clear}
142
+ onclick={() => {
143
+ control.set("");
144
+ // The control is about to disappear, and focus would be lost with it.
145
+ input?.focus();
146
+ }}
147
+ class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid"
148
+ >
149
+ <Icon name="circle-x" size="sm" />
150
+ </button>
151
+ </span>
152
+ {/if}
153
+ </div>
154
+ </div>
@@ -0,0 +1,67 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ The title row of a group of content. The title is a heading at `level`; the action is a quiet
8
+ button with a chevron at its end edge, which points the other way in a right-to-left layout.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { RootProps } from "@xds/svelte/base";
12
+ import type { SectionHeaderBaseProps } from "./section-header.ts";
13
+
14
+ export type SectionHeaderProps = SectionHeaderBaseProps &
15
+ RootProps & {
16
+ /** A link-like action at the end, such as "See all". */
17
+ action?: { label: string; onPress: () => void };
18
+ };
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { rootAttributes } from "@xds/svelte/base";
23
+ import Button from "./Button.svelte";
24
+ import Icon from "./Icon.svelte";
25
+ import { classes, rootPart } from "./parts.ts";
26
+ import { SECTION_HEADER_PARTS } from "./section-header.ts";
27
+
28
+ let {
29
+ title,
30
+ description,
31
+ icon,
32
+ level = 2,
33
+ action,
34
+ class: className,
35
+ style,
36
+ ...rest
37
+ }: SectionHeaderProps = $props();
38
+ </script>
39
+
40
+ <div
41
+ {...rootAttributes(rest)}
42
+ class={classes(rootPart("SectionHeader"), SECTION_HEADER_PARTS.root, className)}
43
+ {style}
44
+ >
45
+ <div class={SECTION_HEADER_PARTS.lead}>
46
+ {#if icon}
47
+ <span class={SECTION_HEADER_PARTS.icon}><Icon name={icon} size="md" /></span>
48
+ {/if}
49
+ <div class={SECTION_HEADER_PARTS.text}>
50
+ <svelte:element this={`h${level}`} class={SECTION_HEADER_PARTS.title}>{title}</svelte:element>
51
+ {#if description}
52
+ <p class={SECTION_HEADER_PARTS.description}>{description}</p>
53
+ {/if}
54
+ </div>
55
+ </div>
56
+ {#if action}
57
+ <span class={SECTION_HEADER_PARTS.action}>
58
+ <Button variant="ghost" size="sm" onPress={() => action.onPress()}
59
+ >{action.label}<Icon
60
+ name="chevron-right"
61
+ size="sm"
62
+ class={SECTION_HEADER_PARTS.chevron}
63
+ /></Button
64
+ >
65
+ </span>
66
+ {/if}
67
+ </div>
@@ -0,0 +1,85 @@
1
+ <!--
2
+ Ejected from `@xds/svelte` 1.2.0 by `xds eject`. This copy is the app's own: change it
3
+ as you need. `xds eject --list` says which ejected files differ from what was copied.
4
+ -->
5
+ <!--
6
+ @component
7
+ A choice between a few views or modes, all visible at once. The selected segment is outlined as
8
+ well as filled, so the choice does not depend on telling two greys apart.
9
+
10
+ It is a group of native radio buttons, so the arrow keys move between segments. Without
11
+ `value` it keeps its own choice, from `defaultValue` or else the first segment.
12
+ -->
13
+ <script module lang="ts">
14
+ import type { RootProps } from "@xds/svelte/base";
15
+ import type { SegmentedControlBaseProps } from "./segmented-control.ts";
16
+
17
+ export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> &
18
+ RootProps & {
19
+ onChange?: (value: Value) => void;
20
+ };
21
+ </script>
22
+
23
+ <script lang="ts" generics="Value extends string">
24
+ import { controllable, keepChecked, rootAttributes } from "@xds/svelte/base";
25
+ import { classes, rootPart } from "./parts.ts";
26
+ import {
27
+ segmentedControlClass,
28
+ segmentedControlOptionClass,
29
+ segmentedControlSegmentClass,
30
+ } from "./segmented-control.ts";
31
+
32
+ // `value` stays in the rest, where whether it is given at all can be asked.
33
+ let {
34
+ options,
35
+ defaultValue,
36
+ "aria-label": ariaLabel,
37
+ fullWidth,
38
+ onChange,
39
+ class: className,
40
+ style,
41
+ ...rest
42
+ }: SegmentedControlProps<Value> = $props();
43
+
44
+ const control = controllable<Value | undefined, Value>(
45
+ () => rest,
46
+ "value",
47
+ () => rest.value,
48
+ () => defaultValue ?? options[0]?.value,
49
+ () => onChange,
50
+ );
51
+
52
+ const name = $props.id();
53
+ let group = $state<HTMLDivElement>();
54
+ </script>
55
+
56
+ <div
57
+ {...rootAttributes(rest)}
58
+ bind:this={group}
59
+ aria-label={ariaLabel}
60
+ role="radiogroup"
61
+ class={classes(rootPart("SegmentedControl"), segmentedControlClass(fullWidth), className)}
62
+ {style}
63
+ >
64
+ {#each options as option (option.value)}
65
+ <label class={segmentedControlOptionClass(fullWidth)}>
66
+ <input
67
+ type="radio"
68
+ {name}
69
+ value={option.value}
70
+ class="peer sr-only"
71
+ checked={option.value === control.current}
72
+ defaultChecked={option.value === control.current}
73
+ onchange={() => {
74
+ control.set(option.value);
75
+ // The browser moved the dot already; where the owner kept the old value, it goes
76
+ // back, on every radio of the group.
77
+ for (const input of group?.querySelectorAll("input") ?? []) {
78
+ keepChecked(input, () => input.value === control.current);
79
+ }
80
+ }}
81
+ />
82
+ <span class={segmentedControlSegmentClass}>{option.label}</span>
83
+ </label>
84
+ {/each}
85
+ </div>