@xds/svelte 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/Accordion.svelte +89 -0
  4. package/dist/Accordion.svelte.d.ts +43 -0
  5. package/dist/AccordionPanel.svelte +40 -0
  6. package/dist/AccordionPanel.svelte.d.ts +15 -0
  7. package/dist/Avatar.svelte +45 -0
  8. package/dist/Avatar.svelte.d.ts +11 -0
  9. package/dist/AvatarStack.svelte +49 -0
  10. package/dist/AvatarStack.svelte.d.ts +10 -0
  11. package/dist/Badge.svelte +36 -0
  12. package/dist/Badge.svelte.d.ts +15 -0
  13. package/dist/Banner.svelte +88 -0
  14. package/dist/Banner.svelte.d.ts +25 -0
  15. package/dist/Button.svelte +90 -0
  16. package/dist/Button.svelte.d.ts +16 -0
  17. package/dist/Card.svelte +99 -0
  18. package/dist/Card.svelte.d.ts +20 -0
  19. package/dist/Checkbox.svelte +68 -0
  20. package/dist/Checkbox.svelte.d.ts +12 -0
  21. package/dist/Chip.svelte +43 -0
  22. package/dist/Chip.svelte.d.ts +14 -0
  23. package/dist/ChipBar.svelte +32 -0
  24. package/dist/ChipBar.svelte.d.ts +14 -0
  25. package/dist/CountBadge.svelte +50 -0
  26. package/dist/CountBadge.svelte.d.ts +14 -0
  27. package/dist/DatePicker.svelte +178 -0
  28. package/dist/DatePicker.svelte.d.ts +22 -0
  29. package/dist/DateRangePicker.svelte +264 -0
  30. package/dist/DateRangePicker.svelte.d.ts +25 -0
  31. package/dist/Defaults.svelte +29 -0
  32. package/dist/Defaults.svelte.d.ts +17 -0
  33. package/dist/Dialog.svelte +104 -0
  34. package/dist/Dialog.svelte.d.ts +22 -0
  35. package/dist/Divider.svelte +17 -0
  36. package/dist/Divider.svelte.d.ts +6 -0
  37. package/dist/EmptyState.svelte +34 -0
  38. package/dist/EmptyState.svelte.d.ts +14 -0
  39. package/dist/Icon.svelte +38 -0
  40. package/dist/Icon.svelte.d.ts +10 -0
  41. package/dist/IconButton.svelte +67 -0
  42. package/dist/IconButton.svelte.d.ts +13 -0
  43. package/dist/ListRow.svelte +29 -0
  44. package/dist/ListRow.svelte.d.ts +15 -0
  45. package/dist/MediaCard.svelte +112 -0
  46. package/dist/MediaCard.svelte.d.ts +22 -0
  47. package/dist/Menu.svelte +156 -0
  48. package/dist/Menu.svelte.d.ts +19 -0
  49. package/dist/PlaceRow.svelte +66 -0
  50. package/dist/PlaceRow.svelte.d.ts +12 -0
  51. package/dist/Portal.svelte +27 -0
  52. package/dist/Portal.svelte.d.ts +15 -0
  53. package/dist/ProgressBar.svelte +37 -0
  54. package/dist/ProgressBar.svelte.d.ts +10 -0
  55. package/dist/RadioGroup.svelte +114 -0
  56. package/dist/RadioGroup.svelte.d.ts +38 -0
  57. package/dist/SearchField.svelte +93 -0
  58. package/dist/SearchField.svelte.d.ts +17 -0
  59. package/dist/SectionHeader.svelte +56 -0
  60. package/dist/SectionHeader.svelte.d.ts +16 -0
  61. package/dist/SegmentedControl.svelte +70 -0
  62. package/dist/SegmentedControl.svelte.d.ts +35 -0
  63. package/dist/Select.svelte +214 -0
  64. package/dist/Select.svelte.d.ts +40 -0
  65. package/dist/Sidebar.svelte +125 -0
  66. package/dist/Sidebar.svelte.d.ts +43 -0
  67. package/dist/SidebarRailButton.svelte +29 -0
  68. package/dist/SidebarRailButton.svelte.d.ts +14 -0
  69. package/dist/Skeleton.svelte +34 -0
  70. package/dist/Skeleton.svelte.d.ts +13 -0
  71. package/dist/Slider.svelte +111 -0
  72. package/dist/Slider.svelte.d.ts +15 -0
  73. package/dist/Spinner.svelte +35 -0
  74. package/dist/Spinner.svelte.d.ts +11 -0
  75. package/dist/Switch.svelte +60 -0
  76. package/dist/Switch.svelte.d.ts +15 -0
  77. package/dist/Tabs.svelte +65 -0
  78. package/dist/Tabs.svelte.d.ts +36 -0
  79. package/dist/Text.svelte +36 -0
  80. package/dist/Text.svelte.d.ts +11 -0
  81. package/dist/TextField.svelte +163 -0
  82. package/dist/TextField.svelte.d.ts +23 -0
  83. package/dist/Thumbnail.svelte +81 -0
  84. package/dist/Thumbnail.svelte.d.ts +11 -0
  85. package/dist/Toast.svelte +83 -0
  86. package/dist/Toast.svelte.d.ts +17 -0
  87. package/dist/Tooltip.svelte +40 -0
  88. package/dist/Tooltip.svelte.d.ts +19 -0
  89. package/dist/TooltipOverlay.svelte +66 -0
  90. package/dist/TooltipOverlay.svelte.d.ts +17 -0
  91. package/dist/controlled.d.ts +4 -0
  92. package/dist/controlled.js +23 -0
  93. package/dist/defaults.svelte.d.ts +12 -0
  94. package/dist/defaults.svelte.js +25 -0
  95. package/dist/index.d.ts +41 -0
  96. package/dist/index.js +47 -0
  97. package/dist/modal-popover.svelte.d.ts +8 -0
  98. package/dist/modal-popover.svelte.js +22 -0
  99. package/dist/picture.svelte.d.ts +19 -0
  100. package/dist/picture.svelte.js +18 -0
  101. package/dist/presence.svelte.d.ts +6 -0
  102. package/dist/presence.svelte.js +19 -0
  103. package/dist/preview/Component.svelte +56 -0
  104. package/dist/preview/Component.svelte.d.ts +15 -0
  105. package/dist/preview/Draw.svelte +65 -0
  106. package/dist/preview/Draw.svelte.d.ts +15 -0
  107. package/dist/preview/Preview.svelte +41 -0
  108. package/dist/preview/Preview.svelte.d.ts +13 -0
  109. package/dist/preview/Snippets.svelte +36 -0
  110. package/dist/preview/Snippets.svelte.d.ts +19 -0
  111. package/dist/preview/components.js +48 -0
  112. package/dist/preview/index.d.ts +2 -0
  113. package/dist/preview/index.js +4 -0
  114. package/dist/root.d.ts +11 -0
  115. package/dist/root.js +1 -0
  116. package/dist/styles/index.css +5 -0
  117. package/dist/trigger.svelte.d.ts +21 -0
  118. package/dist/trigger.svelte.js +48 -0
  119. package/package.json +62 -4
  120. package/page.css +20 -0
  121. package/styles.css +3354 -0
  122. package/tailwind.css +2665 -0
@@ -0,0 +1,29 @@
1
+ <!--
2
+ @component
3
+ One line of a list or a settings screen. Separate rows with a Divider.
4
+ -->
5
+ <script module lang="ts">
6
+ import type { ListRowBaseProps } from "@xds/core";
7
+ import type { Snippet } from "svelte";
8
+ import type { RootProps } from "./root.js";
9
+
10
+ export type ListRowProps = ListRowBaseProps &
11
+ RootProps & {
12
+ /** In front of the title: an avatar or an icon. */
13
+ leading?: Snippet;
14
+ /** At the far end: a value, a badge or a switch. */
15
+ trailing?: Snippet;
16
+ /** Makes the whole row a button. Do not put another control in `trailing` then. */
17
+ onPress?: () => void;
18
+ };
19
+ </script>
20
+
21
+ <script lang="ts">
22
+ import { classes, rootPart } from "@xds/core";
23
+ import PlaceRow from "./PlaceRow.svelte";
24
+
25
+ let { class: className, ...props }: ListRowProps = $props();
26
+ </script>
27
+
28
+ <!-- The root part is the ListRow's: a Sidebar's rows are PlaceRows, but not ListRows of the app. -->
29
+ <PlaceRow {...props} class={classes(rootPart("ListRow"), className)} current="true" />
@@ -0,0 +1,15 @@
1
+ import type { ListRowBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type ListRowProps = ListRowBaseProps & RootProps & {
5
+ /** In front of the title: an avatar or an icon. */
6
+ leading?: Snippet;
7
+ /** At the far end: a value, a badge or a switch. */
8
+ trailing?: Snippet;
9
+ /** Makes the whole row a button. Do not put another control in `trailing` then. */
10
+ onPress?: () => void;
11
+ };
12
+ /** One line of a list or a settings screen. Separate rows with a Divider. */
13
+ declare const ListRow: import("svelte").Component<ListRowProps, {}, "">;
14
+ type ListRow = ReturnType<typeof ListRow>;
15
+ export default ListRow;
@@ -0,0 +1,112 @@
1
+ <!--
2
+ @component
3
+ A thumbnail with its title and details: a video in a feed, an article in a list.
4
+
5
+ With `onPress` the whole card is one button with no surface at rest: under a pointer and while
6
+ pressed it takes the card's fills, and it has a focus ring. The button is named by the title
7
+ followed by the details. `action` is a separate control beside it, so pressing it does not
8
+ press the card.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { MediaCardBaseProps } from "@xds/core";
12
+ import type { Snippet } from "svelte";
13
+ import type { RootProps } from "./root.js";
14
+
15
+ export type MediaCardProps = MediaCardBaseProps &
16
+ RootProps & {
17
+ /** Before the text in the vertical layout, such as an Avatar. */
18
+ leading?: Snippet;
19
+ /** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
20
+ action?: Snippet;
21
+ /** Makes the whole card one button. */
22
+ onPress?: () => void;
23
+ };
24
+ </script>
25
+
26
+ <script lang="ts">
27
+ import {
28
+ classes,
29
+ MEDIA_CARD_PARTS,
30
+ mediaCardContentClass,
31
+ mediaCardIds,
32
+ mediaCardThumbnailClass,
33
+ rootPart,
34
+ } from "@xds/core";
35
+ import { useDefaults } from "./defaults.svelte.js";
36
+ import Thumbnail from "./Thumbnail.svelte";
37
+
38
+ let {
39
+ layout: ownLayout,
40
+ src,
41
+ alt,
42
+ // The card's own ratio, not one the app gives its other thumbnails.
43
+ ratio = "16:9",
44
+ badge,
45
+ progress,
46
+ title,
47
+ meta,
48
+ leading,
49
+ action,
50
+ onPress,
51
+ class: className,
52
+ style,
53
+ }: MediaCardProps = $props();
54
+
55
+ const defaults = useDefaults("MediaCard");
56
+ const layout = $derived(ownLayout ?? defaults().layout);
57
+ const root = $derived(classes(rootPart("MediaCard"), className));
58
+
59
+ const id = $props.id();
60
+ const ids = $derived(mediaCardIds(id, meta));
61
+ const horizontal = $derived(layout === "horizontal");
62
+ const pressable = $derived(onPress !== undefined);
63
+ // On a pressable card the button says all of this, so the parts are hidden from assistive
64
+ // technology and only the action is left beside it.
65
+ const hidden = $derived(pressable ? "true" : undefined);
66
+ </script>
67
+
68
+ {#snippet content()}
69
+ <div class={mediaCardContentClass({ horizontal, pressable })}>
70
+ <span aria-hidden={hidden} class={mediaCardThumbnailClass(horizontal)}>
71
+ <Thumbnail {src} alt={alt ?? ""} {ratio} {badge} {progress} />
72
+ </span>
73
+ <div class={MEDIA_CARD_PARTS.body}>
74
+ {#if !horizontal && leading}
75
+ <span aria-hidden={hidden} class={MEDIA_CARD_PARTS.leading}>{@render leading()}</span>
76
+ {/if}
77
+ <span aria-hidden={hidden} class={MEDIA_CARD_PARTS.text}>
78
+ <span id={ids.title} class={MEDIA_CARD_PARTS.title}>{title}</span>
79
+ <!-- Two details may read the same, so they are told apart by their position. -->
80
+ {#each meta ?? [] as line, index (index)}
81
+ <span id={ids.details[index]} class={MEDIA_CARD_PARTS.meta}>{line}</span>
82
+ {/each}
83
+ </span>
84
+ {#if action}
85
+ <div class={MEDIA_CARD_PARTS.action}>{@render action()}</div>
86
+ {/if}
87
+ </div>
88
+ </div>
89
+ {/snippet}
90
+
91
+ {#if pressable}
92
+ <div class={classes(MEDIA_CARD_PARTS.pressable, root)} {style}>
93
+ <button
94
+ type="button"
95
+ onclick={() => onPress?.()}
96
+ aria-labelledby={ids.names}
97
+ class={MEDIA_CARD_PARTS.button}
98
+ ></button>
99
+ {@render content()}
100
+ </div>
101
+ {:else}
102
+ <!-- A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
103
+ content, which would undo the ellipses. -->
104
+ <div
105
+ role="group"
106
+ aria-labelledby={ids.names}
107
+ class={classes(MEDIA_CARD_PARTS.group, root)}
108
+ {style}
109
+ >
110
+ {@render content()}
111
+ </div>
112
+ {/if}
@@ -0,0 +1,22 @@
1
+ import type { MediaCardBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type MediaCardProps = MediaCardBaseProps & RootProps & {
5
+ /** Before the text in the vertical layout, such as an Avatar. */
6
+ leading?: Snippet;
7
+ /** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
8
+ action?: Snippet;
9
+ /** Makes the whole card one button. */
10
+ onPress?: () => void;
11
+ };
12
+ /**
13
+ * A thumbnail with its title and details: a video in a feed, an article in a list.
14
+ *
15
+ * With `onPress` the whole card is one button with no surface at rest: under a pointer and while
16
+ * pressed it takes the card's fills, and it has a focus ring. The button is named by the title
17
+ * followed by the details. `action` is a separate control beside it, so pressing it does not
18
+ * press the card.
19
+ */
20
+ declare const MediaCard: import("svelte").Component<MediaCardProps, {}, "">;
21
+ type MediaCard = ReturnType<typeof MediaCard>;
22
+ export default MediaCard;
@@ -0,0 +1,156 @@
1
+ <!--
2
+ @component
3
+ A list of actions that opens from a control. Choosing an item calls its `onSelect` and closes
4
+ the menu; a press outside or Escape closes it too, and focus goes back to the trigger.
5
+
6
+ The trigger reports that it opens a menu and whether the menu is open. The arrow keys move the
7
+ highlight and Enter chooses.
8
+ -->
9
+ <script module lang="ts">
10
+ import type { MenuBaseProps } from "@xds/core";
11
+ import type { Snippet } from "svelte";
12
+ import type { RootProps } from "./root.js";
13
+
14
+ export type { MenuItem } from "@xds/core";
15
+
16
+ /** Its root is the menu, while it is open, not its trigger. */
17
+ export type MenuProps = MenuBaseProps &
18
+ RootProps & {
19
+ /** The control that opens the menu: a Button or an IconButton. */
20
+ trigger: Snippet;
21
+ };
22
+ </script>
23
+
24
+ <script lang="ts">
25
+ import { space } from "@xds/tokens";
26
+ import {
27
+ classes,
28
+ firstMenuValue,
29
+ keepListKeys,
30
+ layoutRect,
31
+ leaveEscapeToFields,
32
+ menuItemClass,
33
+ opensOnPress,
34
+ } from "@xds/core";
35
+ import * as menu from "@zag-js/menu";
36
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
37
+ import Icon from "./Icon.svelte";
38
+ import { modalPopover } from "./modal-popover.svelte.js";
39
+ import Portal from "./Portal.svelte";
40
+ import { createPresence } from "./presence.svelte.js";
41
+ import { provideTrigger, type TriggerProps } from "./trigger.svelte.js";
42
+
43
+ let { label, items, align = "start", trigger, class: className, style }: MenuProps = $props();
44
+
45
+ const id = $props.id();
46
+ const service = useMachine(menu.machine, () => ({
47
+ id,
48
+ "aria-label": label,
49
+ positioning: {
50
+ placement: `bottom-${align}` as const,
51
+ gutter: space[1],
52
+ getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
53
+ },
54
+ onSelect: (details: menu.SelectionDetails) => {
55
+ // The values are positions, because two items may have the same label.
56
+ const item = items[Number(details.value)];
57
+ if (item && item !== "separator") item.onSelect();
58
+ },
59
+ onEscapeKeyDown: leaveEscapeToFields,
60
+ // The arrow keys go round from the last item to the first, as in a native menu.
61
+ loopFocus: true,
62
+ }));
63
+ const api = $derived(menu.connect(service, normalizeProps));
64
+ // Whether the last press on the trigger opened the menu, which its click must then not do.
65
+ let pressOpened = false;
66
+ provideTrigger(() => {
67
+ // Zag's handler for a press is left out: it keeps the press from focusing the trigger, so
68
+ // the focus would reach the menu, and come back to the trigger as the menu closes, only
69
+ // from a script, which the browser marks with the keyboard ring.
70
+ const { onpointerdown: _onPointerDown, ...rest } = api.getTriggerProps() as TriggerProps;
71
+ return mergeProps(rest, {
72
+ // Added to the control's own class; the trigger looks pressed while its menu is open.
73
+ class: "xds-menu__trigger",
74
+ // A mouse opens the menu as its button goes down; touch and pen open it on the click, as
75
+ // Zag does.
76
+ onpointerdown: (event: PointerEvent & { currentTarget: HTMLElement }) => {
77
+ pressOpened = opensOnPress(event) && !api.open;
78
+ if (pressOpened) api.setOpen(true);
79
+ },
80
+ onclick: (event: MouseEvent) => {
81
+ // A click with no pointer behind it comes from a screen reader or a script.
82
+ const pointer = event.detail !== 0;
83
+ // The press opened the menu already. This handler runs before Zag's, which skips a
84
+ // handled click. Not told by the click's pointer type: a browser may send the click as
85
+ // a plain mouse event.
86
+ if (pressOpened && pointer) {
87
+ pressOpened = false;
88
+ event.preventDefault();
89
+ return;
90
+ }
91
+ if (pointer) return;
92
+ // After the machine has opened the menu.
93
+ requestAnimationFrame(() => {
94
+ if (!api.open) return;
95
+ const first = firstMenuValue(items);
96
+ if (first !== undefined) api.setHighlightedValue(first);
97
+ });
98
+ },
99
+ });
100
+ });
101
+ let positioner = $state<HTMLDivElement>();
102
+ let surface = $state<HTMLDivElement>();
103
+ modalPopover(
104
+ () => api.open,
105
+ () => positioner,
106
+ );
107
+ const present = createPresence(
108
+ () => api.open,
109
+ () => [surface],
110
+ );
111
+ const content = $derived(
112
+ mergeProps(api.getContentProps(), {
113
+ class: classes("xds-menu", className),
114
+ style,
115
+ // This handler runs before Zag's.
116
+ onkeydown: (event: KeyboardEvent) =>
117
+ keepListKeys(event, surface, ".xds-menu__item:not([data-disabled])", (value) =>
118
+ api.setHighlightedValue(value),
119
+ ),
120
+ }),
121
+ );
122
+ </script>
123
+
124
+ {@render trigger()}
125
+ <Portal>
126
+ {#if api.open}
127
+ <!-- Takes a press outside, which then only closes the menu. The focus stays in the menu until
128
+ the menu hands it back to the trigger. -->
129
+ <!-- svelte-ignore a11y_no_static_element_interactions -->
130
+ <div class="xds-menu__underlay" onmousedown={(event) => event.preventDefault()}></div>
131
+ {/if}
132
+ <div {...api.getPositionerProps()} bind:this={positioner} class="xds-menu__positioner">
133
+ <!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
134
+ <div {...content} bind:this={surface} hidden={!present()}>
135
+ {#each items as item, index (index)}
136
+ {#if item === "separator"}
137
+ <div {...api.getSeparatorProps()} class="xds-menu__separator"></div>
138
+ {:else}
139
+ <div
140
+ {...api.getItemProps({ value: String(index), disabled: item.disabled })}
141
+ class={menuItemClass(item.danger)}
142
+ >
143
+ {#if item.icon}
144
+ <Icon name={item.icon} size="sm" class="xds-menu__item-icon" />
145
+ {/if}
146
+ <span class="flex-1">{item.label}</span>
147
+ <!-- Named, so a screen reader hears the state that the check shows. -->
148
+ {#if item.selected}
149
+ <Icon name="check" size="sm" label="Selected" />
150
+ {/if}
151
+ </div>
152
+ {/if}
153
+ {/each}
154
+ </div>
155
+ </div>
156
+ </Portal>
@@ -0,0 +1,19 @@
1
+ import type { MenuBaseProps } from "@xds/core";
2
+ import type { Snippet } from "svelte";
3
+ import type { RootProps } from "./root.js";
4
+ export type { MenuItem } from "@xds/core";
5
+ /** Its root is the menu, while it is open, not its trigger. */
6
+ export type MenuProps = MenuBaseProps & RootProps & {
7
+ /** The control that opens the menu: a Button or an IconButton. */
8
+ trigger: Snippet;
9
+ };
10
+ /**
11
+ * A list of actions that opens from a control. Choosing an item calls its `onSelect` and closes
12
+ * the menu; a press outside or Escape closes it too, and focus goes back to the trigger.
13
+ *
14
+ * The trigger reports that it opens a menu and whether the menu is open. The arrow keys move the
15
+ * highlight and Enter chooses.
16
+ */
17
+ declare const Menu: import("svelte").Component<MenuProps, {}, "">;
18
+ type Menu = ReturnType<typeof Menu>;
19
+ export default Menu;
@@ -0,0 +1,66 @@
1
+ <!--
2
+ @component
3
+ A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
4
+ places of an app, so its selected row is the current page. Only for this package's own
5
+ components: the index does not export it.
6
+ -->
7
+ <script lang="ts">
8
+ import {
9
+ classes,
10
+ LIST_ROW_PARTS,
11
+ listRowClass,
12
+ listRowDescriptionClass,
13
+ listRowTitleClass,
14
+ } from "@xds/core";
15
+ import Icon from "./Icon.svelte";
16
+ import type { ListRowProps } from "./ListRow.svelte";
17
+
18
+ let {
19
+ title,
20
+ description,
21
+ chevron,
22
+ selected,
23
+ compact,
24
+ disabled,
25
+ leading,
26
+ trailing,
27
+ onPress,
28
+ class: className,
29
+ style,
30
+ current: kind,
31
+ }: ListRowProps & { current: "true" | "page" } = $props();
32
+
33
+ const current = $derived(selected ? kind : undefined);
34
+ const row = $derived(
35
+ classes(listRowClass({ compact, selected, pressable: onPress !== undefined }), className),
36
+ );
37
+ </script>
38
+
39
+ {#snippet content()}
40
+ {@render leading?.()}
41
+ <span class={LIST_ROW_PARTS.text}>
42
+ <span class={listRowTitleClass({ compact, selected, disabled })}>{title}</span>
43
+ {#if description}
44
+ <span class={listRowDescriptionClass(compact)}>{description}</span>
45
+ {/if}
46
+ </span>
47
+ {@render trailing?.()}
48
+ {#if chevron}
49
+ <Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron} />
50
+ {/if}
51
+ {/snippet}
52
+
53
+ {#if onPress}
54
+ <button
55
+ aria-current={current}
56
+ type="button"
57
+ {disabled}
58
+ onclick={() => onPress()}
59
+ class={row}
60
+ {style}
61
+ >
62
+ {@render content()}
63
+ </button>
64
+ {:else}
65
+ <div aria-current={current} class={row} {style}>{@render content()}</div>
66
+ {/if}
@@ -0,0 +1,12 @@
1
+ import type { ListRowProps } from "./ListRow.svelte";
2
+ type $$ComponentProps = ListRowProps & {
3
+ current: "true" | "page";
4
+ };
5
+ /**
6
+ * A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
7
+ * places of an app, so its selected row is the current page. Only for this package's own
8
+ * components: the index does not export it.
9
+ */
10
+ declare const PlaceRow: import("svelte").Component<$$ComponentProps, {}, "">;
11
+ type PlaceRow = ReturnType<typeof PlaceRow>;
12
+ export default PlaceRow;
@@ -0,0 +1,27 @@
1
+ <!--
2
+ @component
3
+ Draws its content at the end of the page's body, out of any box that would clip it or stack it
4
+ under the page, as the other web libraries' portals do, and takes it away with itself. The
5
+ content is a root of its own, which keeps the context it is drawn in: moving the elements
6
+ instead would leave the blocks around them to remove the page's elements in their place. Only
7
+ for this package's own overlays: the index does not export it.
8
+ -->
9
+ <script lang="ts">
10
+ import { getAllContexts, mount, onMount, type Snippet, unmount } from "svelte";
11
+ import Self from "./Portal.svelte";
12
+
13
+ let { children, here = false }: { children: Snippet; here?: boolean } = $props();
14
+
15
+ const context = getAllContexts();
16
+ onMount(() => {
17
+ if (here) return;
18
+ const content = mount(Self, {
19
+ target: document.body,
20
+ props: { children, here: true },
21
+ context,
22
+ });
23
+ return () => void unmount(content);
24
+ });
25
+ </script>
26
+
27
+ {#if here}{@render children()}{/if}
@@ -0,0 +1,15 @@
1
+ import { type Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ here?: boolean;
5
+ };
6
+ /**
7
+ * Draws its content at the end of the page's body, out of any box that would clip it or stack it
8
+ * under the page, as the other web libraries' portals do, and takes it away with itself. The
9
+ * content is a root of its own, which keeps the context it is drawn in: moving the elements
10
+ * instead would leave the blocks around them to remove the page's elements in their place. Only
11
+ * for this package's own overlays: the index does not export it.
12
+ */
13
+ declare const Portal: import("svelte").Component<$$ComponentProps, {}, "">;
14
+ type Portal = ReturnType<typeof Portal>;
15
+ export default Portal;
@@ -0,0 +1,37 @@
1
+ <!--
2
+ @component
3
+ How far along something is, from 0 to 1. For work of unknown length use a Spinner. `label` says
4
+ what is progressing; a screen reader reads it with the percentage.
5
+ -->
6
+ <script module lang="ts">
7
+ import type { ProgressBarBaseProps } from "@xds/core";
8
+ import type { RootProps } from "./root.js";
9
+
10
+ export type ProgressBarProps = ProgressBarBaseProps & RootProps;
11
+ </script>
12
+
13
+ <script lang="ts">
14
+ import {
15
+ classes,
16
+ progressBarClass,
17
+ progressBarFillClass,
18
+ progressPercent,
19
+ rootPart,
20
+ } from "@xds/core";
21
+
22
+ let { value, label, class: className, style }: ProgressBarProps = $props();
23
+
24
+ const percent = $derived(progressPercent(value));
25
+ </script>
26
+
27
+ <div
28
+ role="progressbar"
29
+ aria-label={label}
30
+ aria-valuemin={0}
31
+ aria-valuemax={100}
32
+ aria-valuenow={percent}
33
+ class={classes(rootPart("ProgressBar"), progressBarClass, className)}
34
+ {style}
35
+ >
36
+ <div class={progressBarFillClass} style:width="{percent}%"></div>
37
+ </div>
@@ -0,0 +1,10 @@
1
+ import type { ProgressBarBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.js";
3
+ export type ProgressBarProps = ProgressBarBaseProps & RootProps;
4
+ /**
5
+ * How far along something is, from 0 to 1. For work of unknown length use a Spinner. `label` says
6
+ * what is progressing; a screen reader reads it with the percentage.
7
+ */
8
+ declare const ProgressBar: import("svelte").Component<ProgressBarProps, {}, "">;
9
+ type ProgressBar = ReturnType<typeof ProgressBar>;
10
+ export default ProgressBar;
@@ -0,0 +1,114 @@
1
+ <!--
2
+ @component
3
+ One choice among a few, applied later with the form it belongs to. For a choice that takes
4
+ effect at once among two to four options, a SegmentedControl is the usual pick.
5
+
6
+ The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
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.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { RadioGroupBaseProps } from "@xds/core";
12
+ import type { RootProps } from "./root.js";
13
+
14
+ export type { RadioOption } from "@xds/core";
15
+
16
+ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
17
+ RootProps & {
18
+ onChange: (value: Value) => void;
19
+ };
20
+ </script>
21
+
22
+ <script lang="ts" generics="Value extends string = string">
23
+ import { classes } from "@xds/core";
24
+ import { keepChecked } from "./controlled.js";
25
+
26
+ let {
27
+ label,
28
+ options,
29
+ value,
30
+ disabled,
31
+ error,
32
+ name,
33
+ onChange,
34
+ class: className,
35
+ style,
36
+ }: RadioGroupProps<Value> = $props();
37
+
38
+ const id = $props.id();
39
+ const labelId = `${id}-label`;
40
+ const errorId = `${id}-error`;
41
+ const invalid = $derived(error !== undefined);
42
+ let group = $state<HTMLDivElement>();
43
+ </script>
44
+
45
+ <div
46
+ bind:this={group}
47
+ role="radiogroup"
48
+ aria-labelledby={labelId}
49
+ aria-describedby={invalid ? errorId : undefined}
50
+ aria-invalid={invalid ? "true" : undefined}
51
+ aria-disabled={disabled ? "true" : undefined}
52
+ aria-orientation="vertical"
53
+ class={classes("xds-radio-group", className)}
54
+ {style}
55
+ >
56
+ <span id={labelId} class="xds-radio-group__label">{label}</span>
57
+ <div class="xds-radio-group__options">
58
+ {#each options as option, index (option.value)}
59
+ <label class="xds-radio-group__option">
60
+ <!-- The description is inside the pressable row, so the row's text would name the radio
61
+ together with it. The label alone names it; the description describes it.
62
+ aria-invalid is on each radio as well as the group, so it is heard on the radio that
63
+ has focus. -->
64
+ <!-- svelte-ignore a11y_role_supports_aria_props_implicit -->
65
+ <input
66
+ type="radio"
67
+ class="xds-radio-group__input sr-only"
68
+ name={name ?? id}
69
+ value={option.value}
70
+ checked={option.value === value}
71
+ defaultChecked={option.value === value}
72
+ {disabled}
73
+ aria-labelledby={`${id}-${index}`}
74
+ aria-describedby={[
75
+ option.description ? `${id}-${index}-description` : undefined,
76
+ invalid ? errorId : undefined,
77
+ ]
78
+ .filter(Boolean)
79
+ .join(" ") || undefined}
80
+ aria-invalid={invalid ? "true" : undefined}
81
+ onchange={() => {
82
+ onChange(option.value);
83
+ // The browser moved the dot already; where the owner kept the old value, it goes
84
+ // back, on every radio of the group.
85
+ for (const input of group?.querySelectorAll("input") ?? []) {
86
+ keepChecked(input, () => input.value === value);
87
+ }
88
+ }}
89
+ />
90
+ <span class="xds-radio-group__row">
91
+ <span class="xds-radio-group__circle-line">
92
+ <span class="xds-radio-group__circle"><span class="xds-radio-group__dot"></span></span
93
+ >
94
+ </span>
95
+ <span class="xds-radio-group__words">
96
+ <span id={`${id}-${index}`} class="xds-radio-group__text">{option.label}</span>
97
+ {#if option.description}
98
+ <span id={`${id}-${index}-description`} class="xds-radio-group__description"
99
+ >{option.description}</span
100
+ >
101
+ {/if}
102
+ </span>
103
+ </span>
104
+ </label>
105
+ {/each}
106
+ </div>
107
+ <!-- The region is there before the error is, so that the error is announced when it appears.
108
+ Empty, it takes no room. -->
109
+ <div aria-live="polite">
110
+ {#if invalid}
111
+ <span id={errorId} class="xds-radio-group__error">{error}</span>
112
+ {/if}
113
+ </div>
114
+ </div>