@xds/solid 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 (274) hide show
  1. package/dist/dom/Accordion.js +3 -2
  2. package/dist/dom/Avatar.js +17 -13
  3. package/dist/dom/AvatarStack.js +17 -13
  4. package/dist/dom/Badge.js +12 -10
  5. package/dist/dom/Banner.js +25 -15
  6. package/dist/dom/Breadcrumb.js +87 -0
  7. package/dist/dom/Button.js +10 -3
  8. package/dist/dom/Card.js +31 -26
  9. package/dist/dom/Checkbox.js +57 -26
  10. package/dist/dom/Chip.js +21 -17
  11. package/dist/dom/ChipBar.js +17 -13
  12. package/dist/dom/Combobox.js +295 -0
  13. package/dist/dom/CountBadge.js +28 -23
  14. package/dist/dom/DatePicker.js +13 -7
  15. package/dist/dom/DateRangePicker.js +16 -10
  16. package/dist/dom/Dialog.js +3 -2
  17. package/dist/dom/Divider.js +12 -10
  18. package/dist/dom/EmptyState.js +14 -11
  19. package/dist/dom/Icon.js +30 -19
  20. package/dist/dom/IconButton.js +10 -3
  21. package/dist/dom/Labels.js +26 -0
  22. package/dist/dom/Link.js +62 -0
  23. package/dist/dom/ListRow.js +34 -28
  24. package/dist/dom/MediaCard.js +32 -23
  25. package/dist/dom/Menu.js +18 -15
  26. package/dist/dom/Pagination.js +132 -0
  27. package/dist/dom/Popover.js +126 -0
  28. package/dist/dom/ProgressBar.js +27 -15
  29. package/dist/dom/RadioGroup.js +44 -23
  30. package/dist/dom/SearchField.js +58 -32
  31. package/dist/dom/SectionHeader.js +17 -10
  32. package/dist/dom/SegmentedControl.js +33 -19
  33. package/dist/dom/Select.js +91 -51
  34. package/dist/dom/Sidebar.js +17 -13
  35. package/dist/dom/Skeleton.js +15 -13
  36. package/dist/dom/Slider.js +15 -7
  37. package/dist/dom/Spinner.js +23 -17
  38. package/dist/dom/Switch.js +49 -24
  39. package/dist/dom/Table.js +150 -0
  40. package/dist/dom/Tabs.js +16 -6
  41. package/dist/dom/Text.js +6 -3
  42. package/dist/dom/TextField.js +37 -19
  43. package/dist/dom/Thumbnail.js +21 -14
  44. package/dist/dom/TimePicker.js +245 -0
  45. package/dist/dom/Toast.js +19 -20
  46. package/dist/dom/ToastQueue.js +59 -0
  47. package/dist/dom/Tooltip.js +10 -6
  48. package/dist/dom/base.js +16 -0
  49. package/dist/dom/controllable.js +44 -0
  50. package/dist/dom/index.js +10 -1
  51. package/dist/dom/modal-popover.js +2 -2
  52. package/dist/dom/presence.js +3 -2
  53. package/dist/dom/preview.js +20 -1
  54. package/dist/dom/root.js +16 -4
  55. package/dist/dom/rows.js +13 -0
  56. package/dist/dom/trigger.js +5 -3
  57. package/dist/source/Accordion.jsx +3 -2
  58. package/dist/source/Avatar.d.ts +1 -1
  59. package/dist/source/Avatar.jsx +2 -1
  60. package/dist/source/AvatarStack.d.ts +1 -1
  61. package/dist/source/AvatarStack.jsx +2 -1
  62. package/dist/source/Badge.d.ts +1 -1
  63. package/dist/source/Badge.jsx +2 -1
  64. package/dist/source/Banner.d.ts +1 -1
  65. package/dist/source/Banner.jsx +5 -2
  66. package/dist/source/Breadcrumb.d.ts +9 -0
  67. package/dist/source/Breadcrumb.jsx +26 -0
  68. package/dist/source/Button.d.ts +5 -1
  69. package/dist/source/Button.jsx +5 -2
  70. package/dist/source/Card.d.ts +1 -1
  71. package/dist/source/Card.jsx +3 -2
  72. package/dist/source/Checkbox.d.ts +10 -4
  73. package/dist/source/Checkbox.jsx +26 -8
  74. package/dist/source/Chip.d.ts +1 -1
  75. package/dist/source/Chip.jsx +2 -1
  76. package/dist/source/ChipBar.d.ts +1 -1
  77. package/dist/source/ChipBar.jsx +2 -1
  78. package/dist/source/Combobox.d.ts +16 -0
  79. package/dist/source/Combobox.jsx +137 -0
  80. package/dist/source/CountBadge.d.ts +1 -1
  81. package/dist/source/CountBadge.jsx +3 -2
  82. package/dist/source/DatePicker.jsx +13 -7
  83. package/dist/source/DateRangePicker.jsx +16 -10
  84. package/dist/source/Dialog.jsx +3 -2
  85. package/dist/source/Divider.d.ts +1 -1
  86. package/dist/source/Divider.jsx +2 -1
  87. package/dist/source/EmptyState.d.ts +1 -1
  88. package/dist/source/EmptyState.jsx +2 -1
  89. package/dist/source/Icon.d.ts +1 -1
  90. package/dist/source/Icon.jsx +2 -1
  91. package/dist/source/IconButton.d.ts +5 -1
  92. package/dist/source/IconButton.jsx +5 -2
  93. package/dist/source/Labels.d.ts +17 -0
  94. package/dist/source/Labels.jsx +11 -0
  95. package/dist/source/Link.d.ts +20 -0
  96. package/dist/source/Link.jsx +21 -0
  97. package/dist/source/ListRow.d.ts +1 -1
  98. package/dist/source/ListRow.jsx +3 -2
  99. package/dist/source/MediaCard.d.ts +1 -1
  100. package/dist/source/MediaCard.jsx +3 -2
  101. package/dist/source/Menu.d.ts +1 -1
  102. package/dist/source/Menu.jsx +11 -3
  103. package/dist/source/Pagination.d.ts +12 -0
  104. package/dist/source/Pagination.jsx +51 -0
  105. package/dist/source/Popover.d.ts +19 -0
  106. package/dist/source/Popover.jsx +65 -0
  107. package/dist/source/ProgressBar.d.ts +1 -1
  108. package/dist/source/ProgressBar.jsx +2 -1
  109. package/dist/source/RadioGroup.d.ts +5 -2
  110. package/dist/source/RadioGroup.jsx +18 -5
  111. package/dist/source/SearchField.d.ts +11 -3
  112. package/dist/source/SearchField.jsx +26 -12
  113. package/dist/source/SectionHeader.d.ts +1 -1
  114. package/dist/source/SectionHeader.jsx +2 -1
  115. package/dist/source/SegmentedControl.d.ts +4 -3
  116. package/dist/source/SegmentedControl.jsx +16 -5
  117. package/dist/source/Select.d.ts +10 -1
  118. package/dist/source/Select.jsx +46 -11
  119. package/dist/source/Sidebar.d.ts +1 -1
  120. package/dist/source/Sidebar.jsx +2 -1
  121. package/dist/source/Skeleton.jsx +2 -2
  122. package/dist/source/Slider.d.ts +2 -2
  123. package/dist/source/Slider.jsx +14 -6
  124. package/dist/source/Spinner.d.ts +1 -1
  125. package/dist/source/Spinner.jsx +2 -1
  126. package/dist/source/Switch.d.ts +10 -4
  127. package/dist/source/Switch.jsx +18 -6
  128. package/dist/source/Table.d.ts +17 -0
  129. package/dist/source/Table.jsx +46 -0
  130. package/dist/source/Tabs.d.ts +2 -2
  131. package/dist/source/Tabs.jsx +16 -5
  132. package/dist/source/Text.d.ts +1 -1
  133. package/dist/source/Text.jsx +2 -1
  134. package/dist/source/TextField.d.ts +12 -3
  135. package/dist/source/TextField.jsx +24 -9
  136. package/dist/source/Thumbnail.d.ts +1 -1
  137. package/dist/source/Thumbnail.jsx +2 -1
  138. package/dist/source/TimePicker.d.ts +19 -0
  139. package/dist/source/TimePicker.jsx +137 -0
  140. package/dist/source/Toast.d.ts +1 -1
  141. package/dist/source/Toast.jsx +2 -1
  142. package/dist/source/ToastQueue.d.ts +19 -0
  143. package/dist/source/ToastQueue.jsx +27 -0
  144. package/dist/source/Tooltip.jsx +4 -3
  145. package/dist/source/base.d.ts +15 -0
  146. package/dist/source/base.js +15 -0
  147. package/dist/source/controllable.d.ts +30 -0
  148. package/dist/source/controllable.js +30 -0
  149. package/dist/source/index.d.ts +10 -1
  150. package/dist/source/index.js +9 -0
  151. package/dist/source/modal-popover.js +2 -2
  152. package/dist/source/presence.js +3 -2
  153. package/dist/source/preview.d.ts +10 -2
  154. package/dist/source/preview.jsx +12 -2
  155. package/dist/source/root.d.ts +14 -4
  156. package/dist/source/root.js +7 -2
  157. package/dist/source/rows.d.ts +8 -0
  158. package/dist/source/rows.js +5 -0
  159. package/dist/source/trigger.d.ts +4 -2
  160. package/dist/source/trigger.js +2 -2
  161. package/eject/files/Accordion.tsx +138 -0
  162. package/eject/files/Avatar.tsx +48 -0
  163. package/eject/files/AvatarStack.tsx +51 -0
  164. package/eject/files/Badge.tsx +39 -0
  165. package/eject/files/Banner.tsx +80 -0
  166. package/eject/files/Breadcrumb.tsx +57 -0
  167. package/eject/files/Button.tsx +90 -0
  168. package/eject/files/Card.tsx +100 -0
  169. package/eject/files/Checkbox.tsx +100 -0
  170. package/eject/files/Chip.tsx +40 -0
  171. package/eject/files/ChipBar.tsx +34 -0
  172. package/eject/files/Combobox.tsx +200 -0
  173. package/eject/files/CountBadge.tsx +55 -0
  174. package/eject/files/DatePicker.tsx +225 -0
  175. package/eject/files/DateRangePicker.tsx +319 -0
  176. package/eject/files/Dialog.tsx +117 -0
  177. package/eject/files/Divider.tsx +21 -0
  178. package/eject/files/EmptyState.tsx +39 -0
  179. package/eject/files/Icon.tsx +37 -0
  180. package/eject/files/IconButton.tsx +76 -0
  181. package/eject/files/Link.tsx +61 -0
  182. package/eject/files/ListRow.tsx +94 -0
  183. package/eject/files/MediaCard.tsx +116 -0
  184. package/eject/files/Menu.tsx +190 -0
  185. package/eject/files/Pagination.tsx +109 -0
  186. package/eject/files/Popover.tsx +124 -0
  187. package/eject/files/ProgressBar.tsx +37 -0
  188. package/eject/files/RadioGroup.tsx +138 -0
  189. package/eject/files/SearchField.tsx +124 -0
  190. package/eject/files/SectionHeader.tsx +59 -0
  191. package/eject/files/SegmentedControl.tsx +79 -0
  192. package/eject/files/Select.tsx +290 -0
  193. package/eject/files/Sidebar.tsx +156 -0
  194. package/eject/files/Skeleton.tsx +33 -0
  195. package/eject/files/Slider.tsx +131 -0
  196. package/eject/files/Spinner.tsx +44 -0
  197. package/eject/files/Switch.tsx +88 -0
  198. package/eject/files/Table.tsx +98 -0
  199. package/eject/files/Tabs.tsx +87 -0
  200. package/eject/files/Text.tsx +38 -0
  201. package/eject/files/TextField.tsx +171 -0
  202. package/eject/files/Thumbnail.tsx +84 -0
  203. package/eject/files/TimePicker.tsx +237 -0
  204. package/eject/files/Toast.tsx +100 -0
  205. package/eject/files/ToastQueue.tsx +62 -0
  206. package/eject/files/Tooltip.tsx +135 -0
  207. package/eject/files/accordion.css +89 -0
  208. package/eject/files/accordion.ts +67 -0
  209. package/eject/files/avatar-stack.ts +57 -0
  210. package/eject/files/avatar.ts +42 -0
  211. package/eject/files/badge.ts +30 -0
  212. package/eject/files/banner.ts +71 -0
  213. package/eject/files/base.css +38 -0
  214. package/eject/files/breadcrumb.css +51 -0
  215. package/eject/files/breadcrumb.ts +42 -0
  216. package/eject/files/button.css +241 -0
  217. package/eject/files/button.ts +106 -0
  218. package/eject/files/card.ts +58 -0
  219. package/eject/files/checkbox.ts +52 -0
  220. package/eject/files/chip-bar.ts +16 -0
  221. package/eject/files/chip.ts +35 -0
  222. package/eject/files/combobox.css +269 -0
  223. package/eject/files/combobox.ts +85 -0
  224. package/eject/files/count-badge.ts +32 -0
  225. package/eject/files/date-picker.css +375 -0
  226. package/eject/files/date-picker.ts +280 -0
  227. package/eject/files/date-range-picker.ts +338 -0
  228. package/eject/files/dialog.css +139 -0
  229. package/eject/files/dialog.ts +15 -0
  230. package/eject/files/divider.ts +5 -0
  231. package/eject/files/empty-state.ts +22 -0
  232. package/eject/files/icon.ts +36 -0
  233. package/eject/files/link.css +64 -0
  234. package/eject/files/link.ts +63 -0
  235. package/eject/files/list-row.ts +66 -0
  236. package/eject/files/media-card.ts +66 -0
  237. package/eject/files/menu.css +192 -0
  238. package/eject/files/menu.ts +84 -0
  239. package/eject/files/overlay.css +40 -0
  240. package/eject/files/pagination.css +106 -0
  241. package/eject/files/pagination.ts +68 -0
  242. package/eject/files/parts.ts +17 -0
  243. package/eject/files/popover.css +101 -0
  244. package/eject/files/popover.ts +37 -0
  245. package/eject/files/progress-bar.ts +26 -0
  246. package/eject/files/radio-group.css +184 -0
  247. package/eject/files/radio-group.ts +30 -0
  248. package/eject/files/section-header.ts +32 -0
  249. package/eject/files/segmented-control.ts +33 -0
  250. package/eject/files/select.css +347 -0
  251. package/eject/files/select.ts +77 -0
  252. package/eject/files/sidebar.ts +75 -0
  253. package/eject/files/skeleton.ts +51 -0
  254. package/eject/files/slider.css +160 -0
  255. package/eject/files/slider.ts +80 -0
  256. package/eject/files/spinner.ts +22 -0
  257. package/eject/files/switch.ts +45 -0
  258. package/eject/files/table.css +107 -0
  259. package/eject/files/table.ts +84 -0
  260. package/eject/files/tabs.css +120 -0
  261. package/eject/files/tabs.ts +37 -0
  262. package/eject/files/text-field.css +225 -0
  263. package/eject/files/text-field.ts +64 -0
  264. package/eject/files/text.ts +38 -0
  265. package/eject/files/thumbnail.ts +51 -0
  266. package/eject/files/time-picker.ts +113 -0
  267. package/eject/files/toast-queue.ts +64 -0
  268. package/eject/files/toast.ts +31 -0
  269. package/eject/files/tooltip.css +111 -0
  270. package/eject/files/tooltip.ts +21 -0
  271. package/eject/manifest.json +1027 -0
  272. package/package.json +12 -4
  273. package/styles.css +1066 -167
  274. package/tailwind.css +1295 -218
@@ -0,0 +1,138 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import {
5
+ createControllable,
6
+ isControlled,
7
+ keepChecked,
8
+ type RootProps,
9
+ resetWithForm,
10
+ rootAttributes,
11
+ } from "@xds/solid/base";
12
+ import { createUniqueId, For, Show } from "solid-js";
13
+ import { classes } from "./parts.ts";
14
+ import type { RadioGroupBaseProps } from "./radio-group.ts";
15
+
16
+ export type { RadioOption } from "./radio-group.ts";
17
+
18
+ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> &
19
+ RootProps & {
20
+ onChange?: (value: Value) => void;
21
+ };
22
+
23
+ /**
24
+ * One choice among a few, applied later with the form it belongs to. For a choice that takes
25
+ * effect at once among two to four options, a SegmentedControl is the usual pick.
26
+ *
27
+ * The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
28
+ * options are native radio buttons, hidden and drawn beside, in a group named by the legend:
29
+ * the arrow keys move between them, and the error is tied to the group and announced.
30
+ *
31
+ * Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
32
+ * `undefined`, it shows that.
33
+ */
34
+ export function RadioGroup<Value extends string = string>(props: RadioGroupProps<Value>) {
35
+ const id = createUniqueId();
36
+ const labelId = `${id}-label`;
37
+ const errorId = `${id}-error`;
38
+ const invalid = () => props.error !== undefined;
39
+ let group!: HTMLDivElement;
40
+ const controlled = () => isControlled(props, "value");
41
+ const value = createControllable<Value | undefined>({
42
+ controlled,
43
+ value: () => props.value,
44
+ defaultValue: () => props.defaultValue,
45
+ onChange: (next) => {
46
+ if (next !== undefined) props.onChange?.(next);
47
+ },
48
+ });
49
+ resetWithForm(() => group, controlled, value.reset);
50
+ return (
51
+ <div
52
+ {...rootAttributes(props)}
53
+ ref={(element) => (group = element)}
54
+ role="radiogroup"
55
+ aria-labelledby={labelId}
56
+ aria-describedby={invalid() ? errorId : undefined}
57
+ aria-invalid={invalid() ? "true" : undefined}
58
+ aria-disabled={props.disabled ? "true" : undefined}
59
+ aria-orientation="vertical"
60
+ class={classes("{{prefix}}-radio-group", props.class)}
61
+ style={props.style}
62
+ >
63
+ <span id={labelId} class="{{prefix}}-radio-group__label">
64
+ {props.label}
65
+ </span>
66
+ <div class="{{prefix}}-radio-group__options">
67
+ <For each={props.options}>
68
+ {(option, index) => (
69
+ <label class="{{prefix}}-radio-group__option">
70
+ <input
71
+ type="radio"
72
+ class="{{prefix}}-radio-group__input sr-only"
73
+ // Radios group by name, which is what makes the arrow keys move between them.
74
+ name={props.name ?? id}
75
+ value={option.value}
76
+ checked={option.value === value.value()}
77
+ defaultChecked={
78
+ option.value === (controlled() ? value.value() : props.defaultValue)
79
+ }
80
+ disabled={props.disabled}
81
+ // The description is inside the pressable row, so the row's text would name the
82
+ // radio together with it. The label alone names it; the description describes it.
83
+ aria-labelledby={`${id}-${index()}`}
84
+ aria-describedby={
85
+ [
86
+ option.description ? `${id}-${index()}-description` : undefined,
87
+ invalid() ? errorId : undefined,
88
+ ]
89
+ .filter(Boolean)
90
+ .join(" ") || undefined
91
+ }
92
+ // oxlint-disable-next-line jsx-a11y/role-supports-aria-props -- on each radio as well as the group, so it is heard on the radio that has focus
93
+ aria-invalid={invalid() ? "true" : undefined}
94
+ onChange={() => {
95
+ value.set(option.value);
96
+ // The browser moved the dot already; where the parent kept the old value, it
97
+ // goes back, on every radio of the group.
98
+ for (const input of group.querySelectorAll("input")) {
99
+ keepChecked(input, () => input.value === value.value());
100
+ }
101
+ }}
102
+ />
103
+ <span class="{{prefix}}-radio-group__row">
104
+ <span class="{{prefix}}-radio-group__circle-line">
105
+ <span class="{{prefix}}-radio-group__circle">
106
+ <span class="{{prefix}}-radio-group__dot" />
107
+ </span>
108
+ </span>
109
+ <span class="{{prefix}}-radio-group__words">
110
+ <span id={`${id}-${index()}`} class="{{prefix}}-radio-group__text">
111
+ {option.label}
112
+ </span>
113
+ <Show when={option.description}>
114
+ <span
115
+ id={`${id}-${index()}-description`}
116
+ class="{{prefix}}-radio-group__description"
117
+ >
118
+ {option.description}
119
+ </span>
120
+ </Show>
121
+ </span>
122
+ </span>
123
+ </label>
124
+ )}
125
+ </For>
126
+ </div>
127
+ {/* The region is there before the error is, so that the error is announced when it
128
+ appears. Empty, it takes no room. */}
129
+ <div aria-live="polite">
130
+ <Show when={invalid()}>
131
+ <span id={errorId} class="{{prefix}}-radio-group__error">
132
+ {props.error}
133
+ </span>
134
+ </Show>
135
+ </div>
136
+ </div>
137
+ );
138
+ }
@@ -0,0 +1,124 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import {
5
+ composeRefs,
6
+ createControllable,
7
+ isControlled,
8
+ keepValue,
9
+ type RootProps,
10
+ resetWithForm,
11
+ rootAttributes,
12
+ useLabels,
13
+ } from "@xds/solid/base";
14
+ import type { JSX } from "@solidjs/web";
15
+ import { Show } from "solid-js";
16
+ import { Icon } from "./Icon.tsx";
17
+ import { classes, rootPart } from "./parts.ts";
18
+ import type { SearchFieldBaseProps } from "./text-field.ts";
19
+
20
+ export type SearchFieldProps = SearchFieldBaseProps &
21
+ RootProps & {
22
+ onChange?: (value: string) => void;
23
+ onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
24
+ onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
25
+ /** The native input. */
26
+ ref?: JSX.Ref<HTMLInputElement>;
27
+ /** Called with the query on Enter, or on the search key of a software keyboard. */
28
+ onSubmit?: (value: string) => void;
29
+ };
30
+
31
+ const ROOT = rootPart("SearchField");
32
+
33
+ /**
34
+ * A text field for a query: TextField's box as a pill, with a search icon in front and, while
35
+ * there is a value, a control that clears it. Escape clears too.
36
+ *
37
+ * Use it to filter or search what is on the screen. For a value that is saved with a form,
38
+ * use a TextField, which has a visible label.
39
+ *
40
+ * Without `value` it keeps its own query, from `defaultValue`. A read-only one has no control
41
+ * that clears it, and Escape leaves it as it is.
42
+ */
43
+ export function SearchField(props: SearchFieldProps) {
44
+ const labels = useLabels();
45
+ let input!: HTMLInputElement;
46
+ const controlled = () => isControlled(props, "value");
47
+ const defaultValue = () => props.defaultValue ?? "";
48
+ const value = createControllable({
49
+ controlled,
50
+ value: () => props.value ?? "",
51
+ defaultValue,
52
+ onChange: (next) => props.onChange?.(next),
53
+ });
54
+ resetWithForm(() => input, controlled, value.reset);
55
+ const clearable = () => value.value() !== "" && !props.disabled && !props.readOnly;
56
+ return (
57
+ // TextField's block, which draws the box, and its own root part beside it.
58
+ <div
59
+ {...rootAttributes(props)}
60
+ class={classes("{{prefix}}-text-field", ROOT, props.class)}
61
+ style={props.style}
62
+ >
63
+ <div class="{{prefix}}-text-field__control {{prefix}}-text-field__control--pill {{prefix}}-text-field__group">
64
+ <span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading">
65
+ <Icon name="search" size="sm" />
66
+ </span>
67
+ <input
68
+ ref={composeRefs(
69
+ (element) => (input = element),
70
+ () => props.ref,
71
+ )}
72
+ type="text"
73
+ role="searchbox"
74
+ class="{{prefix}}-text-field__input"
75
+ aria-label={props.label}
76
+ enterkeyhint="search"
77
+ placeholder={props.placeholder}
78
+ value={value.value()}
79
+ defaultValue={controlled() ? value.value() : defaultValue()}
80
+ disabled={props.disabled}
81
+ readonly={props.readOnly}
82
+ // Escape clears only while there is something to clear; an empty field lets Escape
83
+ // through to whatever it sits in, such as a dialog.
84
+ data-uses-escape={clearable() ? "" : undefined}
85
+ onInput={(event) => {
86
+ value.set(event.currentTarget.value);
87
+ if (!event.isComposing) keepValue(event.currentTarget, value.value);
88
+ }}
89
+ onCompositionEnd={(event) => keepValue(event.currentTarget, value.value)}
90
+ onFocus={(event) => props.onFocus?.(event)}
91
+ onBlur={(event) => props.onBlur?.(event)}
92
+ onKeyDown={(event) => {
93
+ // While a composition is open, Enter and Escape belong to the input method.
94
+ if (event.isComposing) return;
95
+ if (event.key === "Enter" && props.onSubmit) {
96
+ event.preventDefault();
97
+ props.onSubmit(value.value());
98
+ }
99
+ if (event.key === "Escape" && clearable()) {
100
+ event.stopPropagation();
101
+ value.set("");
102
+ }
103
+ }}
104
+ />
105
+ <Show when={clearable()}>
106
+ <span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
107
+ <button
108
+ type="button"
109
+ aria-label={props.clearLabel ?? labels().clear}
110
+ onClick={() => {
111
+ value.set("");
112
+ // The control is about to disappear, and focus would be lost with it.
113
+ input.focus();
114
+ }}
115
+ 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"
116
+ >
117
+ <Icon name="circle-x" size="sm" />
118
+ </button>
119
+ </span>
120
+ </Show>
121
+ </div>
122
+ </div>
123
+ );
124
+ }
@@ -0,0 +1,59 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import { type RootProps, rootAttributes } from "@xds/solid/base";
5
+ import { dynamic } from "@solidjs/web";
6
+ import { Show } from "solid-js";
7
+ import { Button } from "./Button.tsx";
8
+ import { Icon } from "./Icon.tsx";
9
+ import { classes, rootPart } from "./parts.ts";
10
+ import { SECTION_HEADER_PARTS, type SectionHeaderBaseProps } from "./section-header.ts";
11
+
12
+ export type SectionHeaderProps = SectionHeaderBaseProps &
13
+ RootProps & {
14
+ /** A link-like action at the end, such as "See all". */
15
+ action?: { label: string; onPress: () => void };
16
+ };
17
+
18
+ const ROOT = rootPart("SectionHeader");
19
+
20
+ /**
21
+ * The title row of a group of content. The title is a heading at `level`; the action is a quiet
22
+ * button with a chevron at its end edge, which points the other way in a right-to-left layout.
23
+ */
24
+ export function SectionHeader(props: SectionHeaderProps) {
25
+ const Heading = dynamic(() => `h${props.level ?? 2}` as const);
26
+ return (
27
+ <div
28
+ {...rootAttributes(props)}
29
+ class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)}
30
+ style={props.style}
31
+ >
32
+ <div class={SECTION_HEADER_PARTS.lead}>
33
+ <Show when={props.icon}>
34
+ {(icon) => (
35
+ <span class={SECTION_HEADER_PARTS.icon}>
36
+ <Icon name={icon()} size="md" />
37
+ </span>
38
+ )}
39
+ </Show>
40
+ <div class={SECTION_HEADER_PARTS.text}>
41
+ <Heading class={SECTION_HEADER_PARTS.title}>{props.title}</Heading>
42
+ <Show when={props.description}>
43
+ {(description) => <p class={SECTION_HEADER_PARTS.description}>{description()}</p>}
44
+ </Show>
45
+ </div>
46
+ </div>
47
+ <Show when={props.action}>
48
+ {(action) => (
49
+ <span class={SECTION_HEADER_PARTS.action}>
50
+ <Button variant="ghost" size="sm" onPress={() => action().onPress()}>
51
+ {action().label}
52
+ <Icon name="chevron-right" size="sm" class={SECTION_HEADER_PARTS.chevron} />
53
+ </Button>
54
+ </span>
55
+ )}
56
+ </Show>
57
+ </div>
58
+ );
59
+ }
@@ -0,0 +1,79 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import {
5
+ createControllable,
6
+ isControlled,
7
+ keepChecked,
8
+ type RootProps,
9
+ rootAttributes,
10
+ } from "@xds/solid/base";
11
+ import { createUniqueId, For } from "solid-js";
12
+ import { classes, rootPart } from "./parts.ts";
13
+ import {
14
+ type SegmentedControlBaseProps,
15
+ segmentedControlClass,
16
+ segmentedControlOptionClass,
17
+ segmentedControlSegmentClass,
18
+ } from "./segmented-control.ts";
19
+
20
+ export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> &
21
+ RootProps & {
22
+ onChange?: (value: Value) => void;
23
+ };
24
+
25
+ const ROOT = rootPart("SegmentedControl");
26
+
27
+ /**
28
+ * A choice between a few views or modes, all visible at once. The selected segment is outlined
29
+ * as well as filled, so the choice does not depend on telling two greys apart.
30
+ *
31
+ * It is a group of native radio buttons, so the arrow keys move between segments. Without
32
+ * `value` it keeps its own choice, from `defaultValue`, or the first segment.
33
+ */
34
+ export function SegmentedControl<Value extends string>(props: SegmentedControlProps<Value>) {
35
+ const name = createUniqueId();
36
+ let group!: HTMLDivElement;
37
+ const value = createControllable<Value | undefined>({
38
+ controlled: () => isControlled(props, "value"),
39
+ value: () => props.value,
40
+ defaultValue: () => props.defaultValue ?? props.options[0]?.value,
41
+ onChange: (next) => {
42
+ if (next !== undefined) props.onChange?.(next);
43
+ },
44
+ });
45
+ return (
46
+ <div
47
+ {...rootAttributes(props)}
48
+ ref={(element) => (group = element)}
49
+ aria-label={props["aria-label"]}
50
+ role="radiogroup"
51
+ class={classes(ROOT, segmentedControlClass(props.fullWidth), props.class)}
52
+ style={props.style}
53
+ >
54
+ <For each={props.options}>
55
+ {(option) => (
56
+ <label class={segmentedControlOptionClass(props.fullWidth)}>
57
+ <input
58
+ type="radio"
59
+ name={name}
60
+ value={option.value}
61
+ class="peer sr-only"
62
+ checked={option.value === value.value()}
63
+ defaultChecked={option.value === value.value()}
64
+ onChange={() => {
65
+ value.set(option.value);
66
+ // The browser moved the dot already; where the parent kept the old value, it
67
+ // goes back, on every radio of the group.
68
+ for (const input of group.querySelectorAll("input")) {
69
+ keepChecked(input, () => input.value === value.value());
70
+ }
71
+ }}
72
+ />
73
+ <span class={segmentedControlSegmentClass}>{option.label}</span>
74
+ </label>
75
+ )}
76
+ </For>
77
+ </div>
78
+ );
79
+ }