@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,237 @@
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
+ createItemProps,
7
+ createPresence,
8
+ isControlled,
9
+ keepListKeys,
10
+ modalPopover,
11
+ Portal,
12
+ type RootProps,
13
+ readCssPx,
14
+ resetWithForm,
15
+ rootAttributes,
16
+ space,
17
+ underlayLayerStyle,
18
+ withStyle,
19
+ } from "@xds/solid/base";
20
+ import type { JSX } from "@solidjs/web";
21
+ import * as select from "@zag-js/select";
22
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
23
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
24
+ import { Icon } from "./Icon.tsx";
25
+ import { classes } from "./parts.ts";
26
+ import type { SelectOption } from "./select.ts";
27
+ import {
28
+ type IsoTime,
29
+ type TimePickerBaseProps,
30
+ timeOptions,
31
+ timePickerIds,
32
+ timePickerLocale,
33
+ } from "./time-picker.ts";
34
+
35
+ export type { IsoTime } from "./time-picker.ts";
36
+
37
+ export type TimePickerProps = TimePickerBaseProps &
38
+ RootProps & {
39
+ /** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
40
+ onChange?: (value: IsoTime) => void;
41
+ };
42
+
43
+ type KeyHandler = (event: KeyboardEvent) => void;
44
+
45
+ /**
46
+ * A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen
47
+ * time on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to
48
+ * `max`, `step` minutes apart, under itself, with the chosen one in view; choosing one calls
49
+ * `onChange` with it as `HH:MM` and closes the list.
50
+ *
51
+ * The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
52
+ * typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
53
+ * `defaultValue`.
54
+ */
55
+ export function TimePicker(props: TimePickerProps) {
56
+ const id = createUniqueId();
57
+ const ids = timePickerIds(id);
58
+ const invalid = () => props.error !== undefined;
59
+ const controlled = () => isControlled(props, "value");
60
+ const value = createControllable<IsoTime | undefined>({
61
+ controlled,
62
+ value: () => props.value,
63
+ defaultValue: () => props.defaultValue,
64
+ onChange: (next) => {
65
+ if (next !== undefined) props.onChange?.(next);
66
+ },
67
+ });
68
+ let element: HTMLDivElement | undefined;
69
+ resetWithForm(() => element, controlled, value.reset);
70
+ const options = createMemo(() =>
71
+ timeOptions(
72
+ { min: props.min, max: props.max, step: props.step, value: value.value() },
73
+ timePickerLocale(props.locale),
74
+ ),
75
+ );
76
+ const collection = createMemo(() =>
77
+ select.collection<SelectOption<IsoTime>>({
78
+ items: options(),
79
+ itemToValue: (option) => option.value,
80
+ itemToString: (option) => option.label,
81
+ }),
82
+ );
83
+ const service = useMachine(select.machine, () => ({
84
+ id,
85
+ // The app's id goes on the root, where Zag looks for it by this one.
86
+ ids: { root: props.id },
87
+ collection: collection(),
88
+ value: value.value() === undefined ? [] : [value.value() as IsoTime],
89
+ onValueChange: (details: select.ValueChangeDetails<SelectOption<IsoTime>>) => {
90
+ const next = details.value[0];
91
+ if (next !== undefined) value.set(next);
92
+ },
93
+ disabled: props.disabled,
94
+ invalid: invalid(),
95
+ positioning: {
96
+ placement: "bottom-start" as const,
97
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
98
+ sameWidth: true,
99
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
100
+ },
101
+ }));
102
+ const api = createMemo(() => select.connect(service, normalizeProps));
103
+ const root = withStyle(
104
+ () => api().getRootProps(),
105
+ () => props.style,
106
+ rootAttributes(props),
107
+ );
108
+ // As in Select: a handler taken from the machine when the key comes reads whether a search
109
+ // by typing is still under way.
110
+ const current = () => select.connect(service, normalizeProps);
111
+ // A span: the field is a button, which a <label> cannot point at.
112
+ const labelProps = createMemo(() => {
113
+ const { for: _, ...rest } = api().getLabelProps() as JSX.LabelHTMLAttributes<HTMLElement>;
114
+ return rest as JSX.HTMLAttributes<HTMLSpanElement>;
115
+ });
116
+ const triggerProps = createMemo(() => {
117
+ const {
118
+ role: _role,
119
+ "aria-invalid": _invalid,
120
+ "aria-required": _required,
121
+ onKeyDown: _onKeyDown,
122
+ ...rest
123
+ } = api().getTriggerProps() as JSX.ButtonHTMLAttributes<HTMLButtonElement>;
124
+ return {
125
+ ...rest,
126
+ onKeyDown: (event: KeyboardEvent) => {
127
+ if (!api().open && (event.key === "Home" || event.key === "End")) return;
128
+ (current().getTriggerProps().onKeyDown as KeyHandler | undefined)?.(event);
129
+ },
130
+ };
131
+ });
132
+ let positioner: HTMLDivElement | undefined;
133
+ let surface: HTMLDivElement | undefined;
134
+ modalPopover(
135
+ () => api().open,
136
+ () => positioner,
137
+ );
138
+ const present = createPresence(
139
+ () => api().open,
140
+ () => [surface],
141
+ );
142
+ const content = mergeProps(
143
+ () => {
144
+ const { onKeyDown: _onKeyDown, ...rest } = api().getContentProps();
145
+ return rest;
146
+ },
147
+ {
148
+ onKeyDown: (event: KeyboardEvent) => {
149
+ keepListKeys(
150
+ event,
151
+ surface,
152
+ ".{{prefix}}-time-picker__item:not([data-disabled])",
153
+ (value) => api().setHighlightedValue(value),
154
+ );
155
+ (current().getContentProps().onKeyDown as KeyHandler | undefined)?.(event);
156
+ },
157
+ },
158
+ );
159
+ return (
160
+ <div
161
+ {...root}
162
+ ref={(node) => (element = node)}
163
+ class={classes("{{prefix}}-time-picker", props.class)}
164
+ >
165
+ <span {...labelProps()} class="{{prefix}}-time-picker__label">
166
+ {props.label}
167
+ </span>
168
+ <button
169
+ {...triggerProps()}
170
+ aria-labelledby={`${ids.value} ${labelProps().id}`}
171
+ aria-describedby={invalid() ? ids.error : props.description ? ids.description : undefined}
172
+ class="{{prefix}}-time-picker__trigger"
173
+ >
174
+ <span {...api().getValueTextProps()} id={ids.value} class="{{prefix}}-time-picker__value">
175
+ {api().valueAsString || props.placeholder}
176
+ </span>
177
+ <Icon name="clock" size="sm" class="text-xds-field-placeholder" />
178
+ </button>
179
+ <div class="{{prefix}}-time-picker__footer">
180
+ <Show when={!invalid() && props.description}>
181
+ <span id={ids.description} class="{{prefix}}-time-picker__description">
182
+ {props.description}
183
+ </span>
184
+ </Show>
185
+ <span id={ids.error} class="{{prefix}}-time-picker__error" aria-live="polite">
186
+ {props.error}
187
+ </span>
188
+ </div>
189
+ {/* What a form submits: the time as HH:MM, where the field shows it on the locale's clock. */}
190
+ <input type="hidden" name={props.name} value={value.value() ?? ""} />
191
+ <Portal>
192
+ <Show when={api().open}>
193
+ {/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
194
+ <div
195
+ class="{{prefix}}-time-picker__underlay"
196
+ style={underlayLayerStyle(api().getPositionerProps().style)}
197
+ onMouseDown={(event) => event.preventDefault()}
198
+ />
199
+ </Show>
200
+ <div
201
+ ref={(element) => (positioner = element)}
202
+ {...api().getPositionerProps()}
203
+ class="{{prefix}}-time-picker__positioner"
204
+ >
205
+ <div
206
+ {...content}
207
+ ref={(element) => (surface = element)}
208
+ hidden={!present()}
209
+ class="{{prefix}}-time-picker__content"
210
+ >
211
+ <div {...api().getListProps()} class="{{prefix}}-time-picker__list">
212
+ <For each={collection().items}>
213
+ {(option) => {
214
+ const itemProps = createItemProps(() => api().getItemProps({ item: option }));
215
+ const textProps = createItemProps(() => api().getItemTextProps({ item: option }));
216
+ const selected = createMemo(() => api().getItemState({ item: option }).selected);
217
+ return (
218
+ <div {...itemProps()} class="{{prefix}}-time-picker__item">
219
+ <span class="{{prefix}}-time-picker__item-words">
220
+ <span {...textProps()} class="{{prefix}}-time-picker__item-label">
221
+ {option.label}
222
+ </span>
223
+ </span>
224
+ <Show when={selected()}>
225
+ <Icon name="check" size="sm" />
226
+ </Show>
227
+ </div>
228
+ );
229
+ }}
230
+ </For>
231
+ </div>
232
+ </div>
233
+ </div>
234
+ </Portal>
235
+ </div>
236
+ );
237
+ }
@@ -0,0 +1,100 @@
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 { motion, type RootProps, readCssMs, rootAttributes } from "@xds/solid/base";
5
+ import { createEffect, createSignal, onSettled, Show } from "solid-js";
6
+ import { classes, rootPart } from "./parts.ts";
7
+ import { TOAST_PARTS, type ToastBaseProps } from "./toast.ts";
8
+
9
+ export type ToastProps = ToastBaseProps &
10
+ RootProps & {
11
+ /** Called when the time is up and after the action. Set `open` to false in it. */
12
+ onClose: () => void;
13
+ };
14
+
15
+ const ROOT = rootPart("Toast");
16
+
17
+ /**
18
+ * A short message about what just happened, which leaves on its own. It sits at the bottom
19
+ * center of the window, above everything else, and is announced politely without taking
20
+ * focus. The time does not run while the pointer is over it or focus is inside it.
21
+ *
22
+ * Do not put the only way to do something in a toast: it is gone in a few seconds.
23
+ *
24
+ * Its `class` and `style` are the toast's surface's, which is in the page only while it is open.
25
+ */
26
+ export function Toast(props: ToastProps) {
27
+ let region!: HTMLDivElement;
28
+ // The toast the pointer is over and the one focus is in. A toast that closed under the
29
+ // pointer gets no event to say that the pointer left, so only one still in the page counts.
30
+ const [hovered, setHovered] = createSignal<Element>();
31
+ const [focused, setFocused] = createSignal<Element>();
32
+ const inPage = (toast: Element | undefined) => toast?.isConnected === true;
33
+
34
+ // The region is in the top layer for as long as the component is mounted, empty or not: a
35
+ // screen reader only announces what is added to a region it already knows.
36
+ onSettled(() => {
37
+ if (!region.showPopover) return;
38
+ region.showPopover();
39
+ return () => {
40
+ if (region.isConnected && region.matches(":popover-open")) region.hidePopover();
41
+ };
42
+ });
43
+
44
+ createEffect(
45
+ () => ({
46
+ open: props.open,
47
+ held: inPage(hovered()) || inPage(focused()),
48
+ duration: props.duration,
49
+ message: props.message,
50
+ }),
51
+ ({ open, held, duration }) => {
52
+ const ms =
53
+ duration ?? readCssMs(region, "--xds-motion-duration-toast", motion.duration.toast);
54
+ if (!open || held || ms <= 0) return;
55
+ // `props.onClose` is read when the time is up, so a new function does not restart it.
56
+ const timer = setTimeout(() => props.onClose(), ms);
57
+ return () => clearTimeout(timer);
58
+ },
59
+ );
60
+
61
+ return (
62
+ <div
63
+ ref={(element) => (region = element)}
64
+ role="status"
65
+ popover="manual"
66
+ class={TOAST_PARTS.region}
67
+ >
68
+ <Show when={props.open}>
69
+ {/* Hover and focus only pause the timer; the action inside is a real button. */}
70
+ <div
71
+ {...rootAttributes(props)}
72
+ onPointerEnter={(event) => setHovered(event.currentTarget)}
73
+ onPointerLeave={() => setHovered(undefined)}
74
+ onFocusIn={(event) => setFocused(event.currentTarget)}
75
+ onFocusOut={() => setFocused(undefined)}
76
+ // The root is the toast, not the region around it: the region is see-through and
77
+ // spans the window, so a class or a style for the toast means the surface.
78
+ class={classes(ROOT, TOAST_PARTS.toast, props.class)}
79
+ style={props.style}
80
+ >
81
+ <span class={TOAST_PARTS.message}>{props.message}</span>
82
+ <Show when={props.action}>
83
+ {(action) => (
84
+ <button
85
+ type="button"
86
+ onClick={() => {
87
+ action().onPress();
88
+ props.onClose();
89
+ }}
90
+ class={TOAST_PARTS.action}
91
+ >
92
+ {action().label}
93
+ </button>
94
+ )}
95
+ </Show>
96
+ </div>
97
+ </Show>
98
+ </div>
99
+ );
100
+ }
@@ -0,0 +1,62 @@
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 { motion, type RootProps, readCssMs, rootAttributes } from "@xds/solid/base";
5
+ import { createEffect, createMemo, createSignal } from "solid-js";
6
+ import { type QueuedToast, type ToastQueueBaseProps, toastQueueStep } from "./toast-queue.ts";
7
+ import { Toast } from "./Toast.tsx";
8
+
9
+ export { type QueuedToast, queueToast } from "./toast-queue.ts";
10
+
11
+ /** `class`, `style`, `id` and `data-*` go on the toast shown, as Toast takes them. */
12
+ export type ToastQueueProps = ToastQueueBaseProps &
13
+ RootProps & {
14
+ /**
15
+ * Called with a toast's id when its time is up or its action was taken. Take it out of
16
+ * `toasts` in it.
17
+ */
18
+ onClose: (id: QueuedToast["id"]) => void;
19
+ };
20
+
21
+ /**
22
+ * Shows the app's toasts one at a time, in their order: the first of `toasts`, which stays for
23
+ * its own `duration` or until its action is taken, and then the next, `motion.duration.normal`
24
+ * after the one before has gone, so that each is read and announced as a message of its own.
25
+ * Add a toast with `queueToast`, which keeps at most three waiting, and take one out in
26
+ * `onClose`. Put one where a single Toast would go.
27
+ */
28
+ export function ToastQueue(props: ToastQueueProps) {
29
+ const [visible, setVisible] = createSignal<QueuedToast["id"] | undefined>(undefined);
30
+ const step = createMemo(() => toastQueueStep(props.toasts, visible()));
31
+ const shown = () => (step() === "keep" ? props.toasts[0] : undefined);
32
+
33
+ createEffect(
34
+ () => ({ step: step(), first: props.toasts[0] }),
35
+ ({ step, first }) => {
36
+ if (step === "close") {
37
+ setVisible(undefined);
38
+ return undefined;
39
+ }
40
+ if (step !== "wait" || first === undefined) return undefined;
41
+ const gap = readCssMs(null, "--xds-motion-duration-normal", motion.duration.normal);
42
+ const timer = setTimeout(() => setVisible(() => first.id), gap);
43
+ return () => clearTimeout(timer);
44
+ },
45
+ );
46
+
47
+ return (
48
+ <Toast
49
+ {...rootAttributes(props)}
50
+ class={props.class}
51
+ style={props.style}
52
+ open={shown() !== undefined}
53
+ message={shown()?.message ?? ""}
54
+ action={shown()?.action}
55
+ duration={shown()?.duration}
56
+ onClose={() => {
57
+ const toast = shown();
58
+ if (toast !== undefined) props.onClose(toast.id);
59
+ }}
60
+ />
61
+ );
62
+ }
@@ -0,0 +1,135 @@
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
+ createPresence,
6
+ motion,
7
+ Portal,
8
+ provideTrigger,
9
+ type RootProps,
10
+ readCssMs,
11
+ readCssPx,
12
+ rootAttributes,
13
+ space,
14
+ TriggerContext,
15
+ type TriggerProps,
16
+ withStyle,
17
+ } from "@xds/solid/base";
18
+ import { normalizeProps, useMachine } from "@zag-js/solid";
19
+ import * as tooltip from "@zag-js/tooltip";
20
+ import { createMemo, createUniqueId, type Element, Show } from "solid-js";
21
+ import { classes } from "./parts.ts";
22
+ import { type TooltipBaseProps, tooltipEndSide } from "./tooltip.ts";
23
+
24
+ export type TooltipProps = TooltipBaseProps &
25
+ RootProps & {
26
+ /** The control it describes: a Button or an IconButton. */
27
+ children: Element;
28
+ };
29
+
30
+ /**
31
+ * Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
32
+ * short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
33
+ * focus leaves, or Escape is pressed.
34
+ *
35
+ * It describes the control and is not its name: an IconButton still needs its `label`. It
36
+ * never holds anything pressable, and touch input has no hover, so nothing may depend on it.
37
+ *
38
+ * Its `class` and `style` are the tooltip's, not the control's, and it is in the page only
39
+ * while it shows.
40
+ */
41
+ export function Tooltip(props: TooltipProps) {
42
+ return (
43
+ <Overlay
44
+ label={props.label}
45
+ shortcut={props.shortcut}
46
+ placement={() => props.placement ?? "top"}
47
+ {...rootAttributes(props)}
48
+ class={props.class}
49
+ style={props.style}
50
+ >
51
+ {props.children}
52
+ </Overlay>
53
+ );
54
+ }
55
+
56
+ /**
57
+ * A Tooltip at the end edge of its control instead of above or below it: a collapsed Sidebar
58
+ * names its icons on the side of the content, where they do not cover their neighbours. Only
59
+ * for this package's own components: the index does not export it.
60
+ */
61
+ export function TooltipBeside(props: { label: string; children: Element }) {
62
+ return (
63
+ <Overlay label={props.label} placement={tooltipEndSide}>
64
+ {props.children}
65
+ </Overlay>
66
+ );
67
+ }
68
+
69
+ /** The root element is the tooltip itself, which is in the page only while it shows. */
70
+ function Overlay(
71
+ props: RootProps & {
72
+ label: string;
73
+ shortcut?: string | undefined;
74
+ placement: () => tooltip.Placement;
75
+ children: Element;
76
+ },
77
+ ) {
78
+ const id = createUniqueId();
79
+ const service = useMachine(tooltip.machine, () => ({
80
+ id,
81
+ // The app's id goes on the tooltip, where Zag looks for it by this one.
82
+ ids: { content: props.id },
83
+ openDelay: readCssMs(
84
+ null,
85
+ "--xds-motion-duration-tooltip-delay",
86
+ motion.duration.tooltipDelay,
87
+ ),
88
+ closeDelay: 0,
89
+ // It stays and follows its control when the page scrolls, for as long as the control keeps
90
+ // focus or the pointer. Tabbing to a control out of view scrolls the page, and a tooltip
91
+ // closed by that scroll would never show for it.
92
+ closeOnScroll: false,
93
+ positioning: {
94
+ placement: props.placement(),
95
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
96
+ },
97
+ }));
98
+ const api = createMemo(() => tooltip.connect(service, normalizeProps));
99
+ const trigger = provideTrigger(() => api().getTriggerProps() as TriggerProps);
100
+ const contentProps = withStyle(
101
+ () => api().getContentProps(),
102
+ () => props.style,
103
+ rootAttributes(props),
104
+ );
105
+ let content: HTMLDivElement | undefined;
106
+ const present = createPresence(
107
+ () => api().open,
108
+ () => [content],
109
+ );
110
+ return (
111
+ <>
112
+ <TriggerContext value={trigger}>{props.children}</TriggerContext>
113
+ <Show when={present()}>
114
+ <Portal>
115
+ <TriggerContext value={null}>
116
+ <div {...api().getPositionerProps()} class="{{prefix}}-tooltip__positioner">
117
+ {/* Shown until its exit animation ends; Zag would hide it as it closes. */}
118
+ <div
119
+ {...contentProps}
120
+ ref={(element) => (content = element)}
121
+ hidden={false}
122
+ class={classes("{{prefix}}-tooltip", props.class)}
123
+ >
124
+ {props.label}
125
+ <Show when={props.shortcut}>
126
+ {(shortcut) => <kbd class="{{prefix}}-tooltip__shortcut">{shortcut()}</kbd>}
127
+ </Show>
128
+ </div>
129
+ </div>
130
+ </TriggerContext>
131
+ </Portal>
132
+ </Show>
133
+ </>
134
+ );
135
+ }
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Ejected from `@xds/solid` 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
+ * Accordion: Zag's accordion machine.
7
+ *
8
+ * Parts: `.{{prefix}}-accordion`, `.{{prefix}}-accordion__item`, `.{{prefix}}-accordion__heading` (the h3),
9
+ * `.{{prefix}}-accordion__trigger` (the button; also a Tailwind `group` for the chevron),
10
+ * `.{{prefix}}-accordion__panel` (the body's box, whose height moves) and `.{{prefix}}-accordion__body`.
11
+ * States: `:hover`, `:active`, `:focus-visible` and `[aria-expanded]` on the trigger. The
12
+ * panel's height is `--accordion-panel-height`, which the component sets: a length while it
13
+ * moves, `auto` while open and `0px` while closed.
14
+ */
15
+ @layer components {
16
+ /* A hairline above the first item and one under every item, the last included. */
17
+ .{{prefix}}-accordion {
18
+ width: 100%;
19
+ border-top: var(--xds-border-width-thin) solid var(--xds-color-accordion-border);
20
+ contain: layout style;
21
+ }
22
+
23
+ .{{prefix}}-accordion__item {
24
+ position: relative;
25
+ border-style: none;
26
+ border-bottom: var(--xds-border-width-thin) solid var(--xds-color-accordion-border);
27
+ }
28
+
29
+ .{{prefix}}-accordion__heading {
30
+ display: flex;
31
+ }
32
+
33
+ .{{prefix}}-accordion__trigger {
34
+ display: flex;
35
+ flex: 1;
36
+ align-items: center;
37
+ justify-content: space-between;
38
+ gap: var(--xds-space-3);
39
+ min-height: var(--xds-size-list-row);
40
+ padding: var(--xds-space-2) var(--xds-space-4);
41
+ font-size: var(--xds-typography-label-size);
42
+ font-weight: var(--xds-typography-label-weight);
43
+ line-height: var(--xds-typography-label-line-height);
44
+ text-align: start;
45
+ cursor: pointer;
46
+ touch-action: manipulation;
47
+ -webkit-tap-highlight-color: transparent;
48
+ transition: background-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
49
+ }
50
+
51
+ /* Open or closed, the row takes its own fills under the pointer and while pressed. */
52
+ @media (hover: hover) {
53
+ .{{prefix}}-accordion__trigger:hover {
54
+ background: var(--xds-color-accordion-header-background-hover);
55
+ }
56
+ }
57
+
58
+ /* A press that drags does not select the title. */
59
+ .{{prefix}}-accordion__trigger:active {
60
+ background: var(--xds-color-accordion-header-background-pressed);
61
+ user-select: none;
62
+ }
63
+
64
+ /* Inside the row, so the hairlines next to it do not cut through the ring. */
65
+ .{{prefix}}-accordion__trigger:focus-visible {
66
+ outline: var(--xds-focus-width) solid var(--xds-color-border-focus);
67
+ outline-offset: calc(-1 * var(--xds-focus-offset));
68
+ }
69
+
70
+ /* Only the height moves. */
71
+ .{{prefix}}-accordion__panel {
72
+ height: var(--accordion-panel-height, auto);
73
+ overflow: clip;
74
+ transition: height var(--xds-motion-duration-normal) var(--xds-motion-easing-standard);
75
+ }
76
+
77
+ @media (prefers-reduced-motion: reduce) {
78
+ .{{prefix}}-accordion__panel {
79
+ transition: none;
80
+ }
81
+ }
82
+
83
+ .{{prefix}}-accordion__body {
84
+ padding: 0 var(--xds-space-4) var(--xds-space-4);
85
+ font-size: var(--xds-typography-body-size);
86
+ line-height: var(--xds-typography-body-line-height);
87
+ color: var(--xds-color-text-secondary);
88
+ }
89
+ }
@@ -0,0 +1,67 @@
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 { afterAnimations, focusWithoutRing } from "@xds/solid/base";
5
+
6
+ /** An item of an Accordion in every framework, short of its body. */
7
+ export type AccordionItemBase<Value extends string = string> = {
8
+ value: Value;
9
+ title: string;
10
+ /** A line under the title, shown whether the item is open or not. */
11
+ description?: string;
12
+ };
13
+
14
+ /** Accordion's props in every framework, short of its items and `onChange`. */
15
+ export type AccordionBaseProps<Value extends string = string> = {
16
+ /** The values of the open items. */
17
+ expanded: readonly Value[];
18
+ /** Lets several items be open at once. Without it, opening one closes the others. */
19
+ multiple?: boolean;
20
+ };
21
+
22
+ export const ACCORDION_PARTS = {
23
+ /** The title and the description, beside the chevron. */
24
+ text: "flex min-w-0 flex-1 flex-col gap-0.5",
25
+ title: "text-xds-body-strong text-xds-text-primary",
26
+ description: "text-xds-detail text-xds-text-secondary",
27
+ // The trigger is a `group`; the chevron turns over while it is expanded.
28
+ chevron:
29
+ "text-xds-accordion-icon transition-transform duration-(--xds-motion-duration-normal) ease-(--xds-motion-easing-standard) group-aria-expanded:rotate-180 motion-reduce:transition-none",
30
+ } as const;
31
+
32
+ /**
33
+ * Opens or closes an item's panel (`.{{prefix}}-accordion__panel`): its height moves between zero and the
34
+ * height of what it holds, and it is hidden only once it has finished closing, with
35
+ * `hidden="until-found"`, so the browser's find in page still opens it. Call it on every change
36
+ * of `open`, with `animate` false the first time, when there is nothing to move from. Returns
37
+ * the function that stops the change from settling: call it before the next change, which
38
+ * takes over.
39
+ */
40
+ export function setPanelOpen(panel: HTMLElement, open: boolean, animate: boolean): () => void {
41
+ const height = (value: string) => panel.style.setProperty("--accordion-panel-height", value);
42
+ if (!animate) {
43
+ if (open) panel.removeAttribute("hidden");
44
+ else panel.setAttribute("hidden", "until-found");
45
+ height(open ? "auto" : "0px");
46
+ return () => {};
47
+ }
48
+ if (open) {
49
+ panel.removeAttribute("hidden");
50
+ height(`${panel.scrollHeight}px`);
51
+ return afterAnimations([panel], () => height("auto"));
52
+ }
53
+ height(`${panel.scrollHeight}px`);
54
+ // Computes the style now, so the change to zero starts a transition.
55
+ void getComputedStyle(panel).height;
56
+ height("0px");
57
+ return afterAnimations([panel], () => panel.setAttribute("hidden", "until-found"));
58
+ }
59
+
60
+ /**
61
+ * For a click on an item's title, ahead of Zag's handler. Zag toggles the item only while its
62
+ * title has the focus, which a press gives it but a click from a script or from assistive
63
+ * technology does not. Focused here first, the title takes those clicks too.
64
+ */
65
+ export function focusTitleOnClick(event: { currentTarget: EventTarget | null }): void {
66
+ if (event.currentTarget instanceof HTMLElement) focusWithoutRing(event.currentTarget);
67
+ }