@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,52 @@
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
+ Where the current view sits in the app: the places above it, each a link, then the view
8
+ itself. A navigation landmark; the current place is marked as the page.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { RootProps } from "@xds/svelte/base";
12
+ import type { BreadcrumbBaseProps } from "./breadcrumb.ts";
13
+
14
+ export type { BreadcrumbItem } from "./breadcrumb.ts";
15
+ export type BreadcrumbProps = BreadcrumbBaseProps & RootProps;
16
+ </script>
17
+
18
+ <script lang="ts">
19
+ import { rootAttributes, useLabels } from "@xds/svelte/base";
20
+ import { BREADCRUMB_PARTS, BREADCRUMB_SEPARATOR } from "./breadcrumb.ts";
21
+ import Icon from "./Icon.svelte";
22
+ import Link from "./Link.svelte";
23
+ import { classes, rootPart } from "./parts.ts";
24
+
25
+ let { items, label, class: className, style, ...rest }: BreadcrumbProps = $props();
26
+ const labels = useLabels();
27
+ </script>
28
+
29
+ <nav
30
+ {...rootAttributes(rest)}
31
+ aria-label={label ?? labels().breadcrumb}
32
+ class={classes(rootPart("Breadcrumb"), className)}
33
+ {style}
34
+ >
35
+ <ol class={BREADCRUMB_PARTS.list}>
36
+ <!-- Two places of a trail can share a label, so a place is known by where it is. -->
37
+ {#each items as item, index (index)}
38
+ <li class={BREADCRUMB_PARTS.item}>
39
+ {#if index === items.length - 1}
40
+ <span aria-current="page" class={BREADCRUMB_PARTS.current}>{item.label}</span>
41
+ {:else}
42
+ <Link href={item.href} onPress={item.onPress}>{item.label}</Link>
43
+ <Icon
44
+ name={BREADCRUMB_SEPARATOR.name}
45
+ size={BREADCRUMB_SEPARATOR.size}
46
+ class={BREADCRUMB_PARTS.separator}
47
+ />
48
+ {/if}
49
+ </li>
50
+ {/each}
51
+ </ol>
52
+ </nav>
@@ -0,0 +1,126 @@
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 native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach it
8
+ through context.
9
+
10
+ `focus()`, `blur()` and `element()` on the instance reach the native button.
11
+ -->
12
+ <script module lang="ts">
13
+ import type { RootProps } from "@xds/svelte/base";
14
+ import type { Snippet } from "svelte";
15
+ import type { FocusEventHandler } from "svelte/elements";
16
+ import type { ButtonBaseProps } from "./button.ts";
17
+
18
+ export type { ButtonVariant, ControlSize } from "./button.ts";
19
+
20
+ export type ButtonProps = ButtonBaseProps &
21
+ RootProps & {
22
+ onPress?: () => void;
23
+ onFocus?: FocusEventHandler<HTMLButtonElement>;
24
+ onBlur?: FocusEventHandler<HTMLButtonElement>;
25
+ /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
26
+ children?: Snippet;
27
+ };
28
+ </script>
29
+
30
+ <script lang="ts">
31
+ import { rootAttributes, useDefaults, withTrigger } from "@xds/svelte/base";
32
+ import type { HTMLButtonAttributes } from "svelte/elements";
33
+ import { BUTTON_ICON, buttonClass, isHeld } from "./button.ts";
34
+ import Icon from "./Icon.svelte";
35
+ import { classes } from "./parts.ts";
36
+ import Spinner from "./Spinner.svelte";
37
+
38
+ let {
39
+ variant: ownVariant,
40
+ size: ownSize,
41
+ iconStart,
42
+ iconEnd,
43
+ selected,
44
+ disabled,
45
+ loading,
46
+ fullWidth = false,
47
+ type = "button",
48
+ onPress,
49
+ onFocus,
50
+ onBlur,
51
+ "aria-label": ariaLabel,
52
+ class: className,
53
+ style,
54
+ children,
55
+ ...rest
56
+ }: ButtonProps = $props();
57
+
58
+ const defaults = useDefaults("Button");
59
+ const variant = $derived(ownVariant ?? defaults().variant ?? "secondary");
60
+ const size = $derived(ownSize ?? defaults().size ?? "md");
61
+
62
+ const icon = $derived(BUTTON_ICON[size]);
63
+ const held = $derived(isHeld({ variant, selected, disabled }));
64
+ const attributes = withTrigger(
65
+ (): HTMLButtonAttributes => ({
66
+ type,
67
+ // The recipe gives the root part, `{{prefix}}-button`.
68
+ class: classes(
69
+ buttonClass({
70
+ variant,
71
+ size,
72
+ iconOnly: children === undefined && (iconStart !== undefined || iconEnd !== undefined),
73
+ fullWidth,
74
+ }),
75
+ className,
76
+ ),
77
+ style,
78
+ disabled,
79
+ // Loading keeps the button focusable, so focus is not lost while it waits.
80
+ "aria-disabled": loading ? "true" : undefined,
81
+ "data-pending": loading ? "" : undefined,
82
+ "aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
83
+ "aria-label": ariaLabel,
84
+ onclick: (event) => {
85
+ // The press was taken already: block keyboard Enter/Space form submit or reset too.
86
+ if (loading) {
87
+ event.preventDefault();
88
+ return;
89
+ }
90
+ onPress?.();
91
+ },
92
+ onfocus: onFocus,
93
+ onblur: onBlur,
94
+ }),
95
+ () => loading === true,
96
+ );
97
+ let button = $state<HTMLButtonElement>();
98
+
99
+ /** Moves the focus to the native button. */
100
+ export function focus(options?: FocusOptions) {
101
+ button?.focus(options);
102
+ }
103
+
104
+ /** Takes the focus from the native button. */
105
+ export function blur() {
106
+ button?.blur();
107
+ }
108
+
109
+ /** The native button, once it is on the page. */
110
+ export function element(): HTMLButtonElement | undefined {
111
+ return button;
112
+ }
113
+ </script>
114
+
115
+ <!-- The app's id gives way to the one an overlay gives its trigger, which the overlay's own
116
+ parts point at. -->
117
+ <button {...rootAttributes(rest)} {...attributes()} bind:this={button}
118
+ >{#if loading}{#if iconStart}
119
+ <!-- Where the icon was, so the button keeps its width. -->
120
+ <span class={icon.box}><Spinner size="sm" /></span>
121
+ {:else}<Spinner size="sm" />{/if}{:else if iconStart}<Icon
122
+ name={iconStart}
123
+ size={icon.size}
124
+ filled={held}
125
+ />{/if}{@render children?.()}{#if iconEnd}<Icon name={iconEnd} size={icon.size} />{/if}</button
126
+ >
@@ -0,0 +1,112 @@
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 groups related content. A hairline outline and a trace of shadow lift it off the
8
+ page; in dark mode, where shadows barely show, the lighter fill does that. `title` renders as a
9
+ heading; `actions` sit across from it.
10
+ -->
11
+ <script module lang="ts">
12
+ import type { RootProps } from "@xds/svelte/base";
13
+ import type { Snippet } from "svelte";
14
+ import type { CardBaseProps } from "./card.ts";
15
+
16
+ export type CardProps = CardBaseProps &
17
+ RootProps & {
18
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
19
+ actions?: Snippet;
20
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
21
+ media?: Snippet;
22
+ /** Makes the whole card one button. Put no other control inside it then. */
23
+ onPress?: () => void;
24
+ children?: Snippet;
25
+ };
26
+ </script>
27
+
28
+ <script lang="ts">
29
+ import { rootAttributes } from "@xds/svelte/base";
30
+ import { CARD_PARTS, cardClass, cardMediaClass } from "./card.ts";
31
+ import { classes, rootPart } from "./parts.ts";
32
+
33
+ let {
34
+ title,
35
+ description,
36
+ flush,
37
+ selected,
38
+ actions,
39
+ media,
40
+ onPress,
41
+ class: className,
42
+ style,
43
+ children,
44
+ ...rest
45
+ }: CardProps = $props();
46
+
47
+ const pressable = $derived(onPress !== undefined);
48
+ // A button may hold only phrasing content, so inside one the parts are spans. Its heading
49
+ // would not be reachable as a heading anyway: a button reads as its text.
50
+ const tags = $derived(
51
+ pressable
52
+ ? { header: "span", box: "span", title: "span", line: "span" }
53
+ : { header: "header", box: "div", title: "h2", line: "p" },
54
+ );
55
+ const surface = $derived(
56
+ classes(rootPart("Card"), cardClass({ selected, flush, pressable }), className),
57
+ );
58
+ </script>
59
+
60
+ {#snippet parts()}
61
+ {#if media}
62
+ <svelte:element this={tags.box} class={cardMediaClass(flush)}>{@render media()}</svelte:element>
63
+ {/if}
64
+ {#if title || description || (actions && !pressable)}
65
+ <svelte:element this={tags.header} class={CARD_PARTS.header}>
66
+ <svelte:element this={tags.box} class={CARD_PARTS.heading}>
67
+ {#if title}
68
+ <svelte:element this={tags.title} class={CARD_PARTS.title}>{title}</svelte:element>
69
+ {/if}
70
+ {#if description}
71
+ <svelte:element this={tags.line} class={CARD_PARTS.description}
72
+ >{description}</svelte:element
73
+ >
74
+ {/if}
75
+ </svelte:element>
76
+ {#if actions && !pressable}
77
+ <div class={CARD_PARTS.actions}>{@render actions()}</div>
78
+ {/if}
79
+ </svelte:element>
80
+ {/if}
81
+ {@render children?.()}
82
+ {/snippet}
83
+
84
+ {#snippet content()}
85
+ {#if flush}
86
+ <svelte:element this={tags.box} class={CARD_PARTS.flush}>{@render parts()}</svelte:element>
87
+ {:else}
88
+ {@render parts()}
89
+ {/if}
90
+ {/snippet}
91
+
92
+ {#if pressable}
93
+ <button
94
+ {...rootAttributes(rest)}
95
+ type="button"
96
+ onclick={() => onPress?.()}
97
+ aria-pressed={selected === undefined ? undefined : selected ? "true" : "false"}
98
+ class={surface}
99
+ {style}
100
+ >
101
+ {@render content()}
102
+ </button>
103
+ {:else}
104
+ <section
105
+ {...rootAttributes(rest)}
106
+ aria-current={selected ? "true" : undefined}
107
+ class={surface}
108
+ {style}
109
+ >
110
+ {@render content()}
111
+ </section>
112
+ {/if}
@@ -0,0 +1,121 @@
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 that is applied later, with the form it belongs to. A native checkbox: the input is
8
+ hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
9
+ `defaultChecked`, and a reset of its form puts that back. With `indeterminate` it shows a dash
10
+ and is reported as mixed.
11
+
12
+ `focus()`, `blur()` and `element()` on the instance reach the native checkbox.
13
+ -->
14
+ <script module lang="ts">
15
+ import type { RootProps } from "@xds/svelte/base";
16
+ import type { FocusEventHandler } from "svelte/elements";
17
+ import type { CheckboxBaseProps } from "./checkbox.ts";
18
+
19
+ export type CheckboxProps = CheckboxBaseProps &
20
+ RootProps & {
21
+ onChange?: (checked: boolean) => void;
22
+ onFocus?: FocusEventHandler<HTMLInputElement>;
23
+ onBlur?: FocusEventHandler<HTMLInputElement>;
24
+ };
25
+ </script>
26
+
27
+ <script lang="ts">
28
+ import { controllable, followFormReset, keepChecked, rootAttributes } from "@xds/svelte/base";
29
+ import {
30
+ checkboxBoxClass,
31
+ checkboxClass,
32
+ checkboxLabelClass,
33
+ checkboxMark,
34
+ checkboxMarkClass,
35
+ } from "./checkbox.ts";
36
+ import { classes, rootPart } from "./parts.ts";
37
+
38
+ // `checked` stays in the rest, where whether it is given at all can be asked.
39
+ let {
40
+ defaultChecked = false,
41
+ indeterminate = false,
42
+ label,
43
+ "aria-label": ariaLabel,
44
+ name,
45
+ disabled,
46
+ onChange,
47
+ onFocus,
48
+ onBlur,
49
+ class: className,
50
+ style,
51
+ ...rest
52
+ }: CheckboxProps = $props();
53
+
54
+ const control = controllable(
55
+ () => rest,
56
+ "checked",
57
+ () => rest.checked ?? false,
58
+ () => defaultChecked,
59
+ () => onChange,
60
+ );
61
+ let input = $state<HTMLInputElement>();
62
+ followFormReset(() => input, control);
63
+ // A property of the native input, with no attribute: it is what reports the box as mixed.
64
+ $effect(() => {
65
+ if (input) input.indeterminate = indeterminate;
66
+ });
67
+
68
+ /** Moves the focus to the native checkbox. */
69
+ export function focus(options?: FocusOptions) {
70
+ input?.focus(options);
71
+ }
72
+
73
+ /** Takes the focus from the native checkbox. */
74
+ export function blur() {
75
+ input?.blur();
76
+ }
77
+
78
+ /** The native checkbox, once it is on the page. */
79
+ export function element(): HTMLInputElement | undefined {
80
+ return input;
81
+ }
82
+ </script>
83
+
84
+ <label
85
+ {...rootAttributes(rest)}
86
+ class={classes(rootPart("Checkbox"), checkboxClass, className)}
87
+ {style}
88
+ >
89
+ <input
90
+ bind:this={input}
91
+ type="checkbox"
92
+ aria-label={ariaLabel}
93
+ class="peer sr-only"
94
+ checked={control.current}
95
+ defaultChecked={control.controlled ? control.current : defaultChecked}
96
+ {disabled}
97
+ name={name || undefined}
98
+ onchange={(event) => {
99
+ // A press clears it on the input; it stays until the app clears it.
100
+ event.currentTarget.indeterminate = indeterminate;
101
+ control.set(event.currentTarget.checked);
102
+ keepChecked(event.currentTarget, () => control.current);
103
+ }}
104
+ onfocus={onFocus}
105
+ onblur={onBlur}
106
+ />
107
+ <span class={checkboxBoxClass}>
108
+ <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
109
+ <path
110
+ d={checkboxMark(indeterminate)}
111
+ stroke="currentColor"
112
+ stroke-width="2"
113
+ stroke-linecap="round"
114
+ stroke-linejoin="round"
115
+ />
116
+ </svg>
117
+ </span>
118
+ {#if label}
119
+ <span class={checkboxLabelClass}>{label}</span>
120
+ {/if}
121
+ </label>
@@ -0,0 +1,51 @@
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 that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
8
+ outlined and marked with a check, so the state does not depend on color.
9
+
10
+ It is a toggle button: assistive technology hears whether it is pressed.
11
+ -->
12
+ <script module lang="ts">
13
+ import type { RootProps } from "@xds/svelte/base";
14
+ import type { ChipBaseProps } from "./chip.ts";
15
+
16
+ export type ChipProps = ChipBaseProps &
17
+ RootProps & {
18
+ onPress?: () => void;
19
+ };
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import { rootAttributes } from "@xds/svelte/base";
24
+ import { chipClass, chipIcon } from "./chip.ts";
25
+ import Icon from "./Icon.svelte";
26
+ import { classes, rootPart } from "./parts.ts";
27
+
28
+ let {
29
+ label,
30
+ selected,
31
+ iconStart,
32
+ disabled,
33
+ onPress,
34
+ class: className,
35
+ style,
36
+ ...rest
37
+ }: ChipProps = $props();
38
+
39
+ const icon = $derived(chipIcon({ selected, iconStart }));
40
+ </script>
41
+
42
+ <button
43
+ {...rootAttributes(rest)}
44
+ type="button"
45
+ aria-pressed={selected ? "true" : "false"}
46
+ {disabled}
47
+ onclick={() => onPress?.()}
48
+ class={classes(rootPart("Chip"), chipClass(selected), className)}
49
+ {style}
50
+ >{#if icon}<Icon name={icon} size="sm" />{/if}{label}</button
51
+ >
@@ -0,0 +1,39 @@
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 row of chips. It scrolls sideways when the chips do not fit and never wraps, so the content
8
+ under it stays where it is.
9
+ -->
10
+ <script module lang="ts">
11
+ import type { RootProps } from "@xds/svelte/base";
12
+ import type { Snippet } from "svelte";
13
+ import type { ChipBarBaseProps } from "./chip-bar.ts";
14
+
15
+ export type ChipBarProps = ChipBarBaseProps &
16
+ RootProps & {
17
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
18
+ children: Snippet;
19
+ };
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import { rootAttributes } from "@xds/svelte/base";
24
+ import { chipBarClass } from "./chip-bar.ts";
25
+ import { classes, rootPart } from "./parts.ts";
26
+
27
+ let { label, class: className, style, children, ...rest }: ChipBarProps = $props();
28
+ </script>
29
+
30
+ <!-- A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser. -->
31
+ <div
32
+ {...rootAttributes(rest)}
33
+ role="group"
34
+ aria-label={label}
35
+ class={classes(rootPart("ChipBar"), chipBarClass, className)}
36
+ {style}
37
+ >
38
+ {@render children()}
39
+ </div>