@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,94 @@
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 { type Element, Show } from "solid-js";
6
+ import { Icon } from "./Icon.tsx";
7
+ import {
8
+ LIST_ROW_PARTS,
9
+ type ListRowBaseProps,
10
+ listRowClass,
11
+ listRowDescriptionClass,
12
+ listRowTitleClass,
13
+ } from "./list-row.ts";
14
+ import { classes, rootPart } from "./parts.ts";
15
+
16
+ export type ListRowProps = ListRowBaseProps &
17
+ RootProps & {
18
+ /** In front of the title: an avatar or an icon. */
19
+ leading?: Element;
20
+ /** At the far end: a value, a badge or a switch. */
21
+ trailing?: Element;
22
+ /** Makes the whole row a button. Do not put another control in `trailing` then. */
23
+ onPress?: () => void;
24
+ };
25
+
26
+ const ROOT = rootPart("ListRow");
27
+
28
+ /** One line of a list or a settings screen. Separate rows with a Divider. */
29
+ export function ListRow(props: ListRowProps) {
30
+ return <PlaceRow {...props} current="true" />;
31
+ }
32
+
33
+ /**
34
+ * A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
35
+ * places of an app, so its selected row is the current page. Only for this package's own
36
+ * components: the index does not export it.
37
+ */
38
+ export function PlaceRow(props: ListRowProps & { current: "true" | "page" }) {
39
+ const pressable = () => props.onPress !== undefined;
40
+ const current = () => (props.selected ? props.current : undefined);
41
+ const row = () =>
42
+ classes(
43
+ ROOT,
44
+ listRowClass({ compact: props.compact, selected: props.selected, pressable: pressable() }),
45
+ props.class,
46
+ );
47
+ const content = () => (
48
+ <>
49
+ {props.leading}
50
+ <span class={LIST_ROW_PARTS.text}>
51
+ <span
52
+ class={listRowTitleClass({
53
+ compact: props.compact,
54
+ selected: props.selected,
55
+ disabled: props.disabled,
56
+ })}
57
+ >
58
+ {props.title}
59
+ </span>
60
+ <Show when={props.description}>
61
+ {(description) => (
62
+ <span class={listRowDescriptionClass(props.compact)}>{description()}</span>
63
+ )}
64
+ </Show>
65
+ </span>
66
+ {props.trailing}
67
+ <Show when={props.chevron}>
68
+ <Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron} />
69
+ </Show>
70
+ </>
71
+ );
72
+ return (
73
+ <Show
74
+ when={pressable()}
75
+ fallback={
76
+ <div {...rootAttributes(props)} aria-current={current()} class={row()} style={props.style}>
77
+ {content()}
78
+ </div>
79
+ }
80
+ >
81
+ <button
82
+ {...rootAttributes(props)}
83
+ aria-current={current()}
84
+ type="button"
85
+ disabled={props.disabled}
86
+ onClick={() => props.onPress?.()}
87
+ class={row()}
88
+ style={props.style}
89
+ >
90
+ {content()}
91
+ </button>
92
+ </Show>
93
+ );
94
+ }
@@ -0,0 +1,116 @@
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, useDefaults } from "@xds/solid/base";
5
+ import { createMemo, createUniqueId, type Element, For, Show } from "solid-js";
6
+ import {
7
+ MEDIA_CARD_PARTS,
8
+ type MediaCardBaseProps,
9
+ mediaCardContentClass,
10
+ mediaCardIds,
11
+ mediaCardThumbnailClass,
12
+ } from "./media-card.ts";
13
+ import { classes, rootPart } from "./parts.ts";
14
+ import { Thumbnail } from "./Thumbnail.tsx";
15
+
16
+ export type MediaCardProps = MediaCardBaseProps &
17
+ RootProps & {
18
+ /** Before the text in the vertical layout, such as an Avatar. */
19
+ leading?: Element;
20
+ /** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
21
+ action?: Element;
22
+ /** Makes the whole card one button. */
23
+ onPress?: () => void;
24
+ };
25
+
26
+ const ROOT = rootPart("MediaCard");
27
+
28
+ /**
29
+ * A thumbnail with its title and details: a video in a feed, an article in a list.
30
+ *
31
+ * With `onPress` the whole card is one button with no surface at rest: under a pointer and
32
+ * while pressed it takes the card's fills, and it has a focus ring. The button is named by the
33
+ * title followed by the details. `action` is a separate control beside it, so pressing it does
34
+ * not press the card.
35
+ */
36
+ export function MediaCard(props: MediaCardProps) {
37
+ const id = createUniqueId();
38
+ const ids = createMemo(() => mediaCardIds(id, props.meta));
39
+ const defaults = useDefaults("MediaCard");
40
+ const horizontal = () => (props.layout ?? defaults().layout) === "horizontal";
41
+ const pressable = () => props.onPress !== undefined;
42
+ // On a pressable card the button says all of this, so the parts are hidden from assistive
43
+ // technology and only the action is left beside it.
44
+ const hidden = () => (pressable() ? "true" : undefined);
45
+ const content = () => (
46
+ <div class={mediaCardContentClass({ horizontal: horizontal(), pressable: pressable() })}>
47
+ <span aria-hidden={hidden()} class={mediaCardThumbnailClass(horizontal())}>
48
+ <Thumbnail
49
+ src={props.src}
50
+ alt={props.alt ?? ""}
51
+ // The card's own ratio, not one the app gives its other thumbnails.
52
+ ratio={props.ratio ?? "16:9"}
53
+ badge={props.badge}
54
+ progress={props.progress}
55
+ />
56
+ </span>
57
+ <div class={MEDIA_CARD_PARTS.body}>
58
+ <Show when={!horizontal() && props.leading}>
59
+ {(leading) => (
60
+ <span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.leading}>
61
+ {leading()}
62
+ </span>
63
+ )}
64
+ </Show>
65
+ <span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.text}>
66
+ <span id={ids().title} class={MEDIA_CARD_PARTS.title}>
67
+ {props.title}
68
+ </span>
69
+ {/* Two details may read the same, so they are told apart by their position. */}
70
+ <For each={props.meta ?? []} keyed={false}>
71
+ {(line, index) => (
72
+ <span id={ids().details[index]} class={MEDIA_CARD_PARTS.meta}>
73
+ {line()}
74
+ </span>
75
+ )}
76
+ </For>
77
+ </span>
78
+ <Show when={props.action}>
79
+ {(action) => <div class={MEDIA_CARD_PARTS.action}>{action()}</div>}
80
+ </Show>
81
+ </div>
82
+ </div>
83
+ );
84
+ return (
85
+ <Show
86
+ when={pressable()}
87
+ fallback={
88
+ // A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
89
+ // content, which would undo the ellipses.
90
+ <div
91
+ {...rootAttributes(props)}
92
+ role="group"
93
+ aria-labelledby={ids().names}
94
+ class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)}
95
+ style={props.style}
96
+ >
97
+ {content()}
98
+ </div>
99
+ }
100
+ >
101
+ <div
102
+ {...rootAttributes(props)}
103
+ class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)}
104
+ style={props.style}
105
+ >
106
+ <button
107
+ type="button"
108
+ onClick={() => props.onPress?.()}
109
+ aria-labelledby={ids().names}
110
+ class={MEDIA_CARD_PARTS.button}
111
+ />
112
+ {content()}
113
+ </div>
114
+ </Show>
115
+ );
116
+ }
@@ -0,0 +1,190 @@
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
+ createItemProps,
6
+ createPresence,
7
+ keepListKeys,
8
+ leaveEscapeToFields,
9
+ modalPopover,
10
+ Portal,
11
+ provideTrigger,
12
+ type RootProps,
13
+ readCssPx,
14
+ rootAttributes,
15
+ space,
16
+ TriggerContext,
17
+ type TriggerProps,
18
+ underlayLayerStyle,
19
+ } from "@xds/solid/base";
20
+ import * as menu from "@zag-js/menu";
21
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
22
+ import { createMemo, createUniqueId, type Element, For, Show } from "solid-js";
23
+ import { Icon } from "./Icon.tsx";
24
+ import {
25
+ firstMenuValue,
26
+ layoutRect,
27
+ type MenuBaseProps,
28
+ menuItemClass,
29
+ opensOnPress,
30
+ } from "./menu.ts";
31
+ import { classes } from "./parts.ts";
32
+
33
+ export type { MenuItem } from "./menu.ts";
34
+
35
+ export type MenuProps = MenuBaseProps &
36
+ RootProps & {
37
+ /** The control that opens the menu: a Button or an IconButton. */
38
+ trigger: Element;
39
+ };
40
+
41
+ /**
42
+ * A list of actions that opens from a control. Choosing an item calls its `onSelect` and
43
+ * closes the menu; a press outside or Escape closes it too, and focus goes back to the
44
+ * trigger.
45
+ *
46
+ * The trigger reports that it opens a menu and whether the menu is open. The arrow keys move
47
+ * the highlight and Enter chooses.
48
+ *
49
+ * Its `class` and `style` are the menu's surface's, which is in the page only while it is open.
50
+ */
51
+ export function Menu(props: MenuProps) {
52
+ const id = createUniqueId();
53
+ const service = useMachine(menu.machine, () => ({
54
+ id,
55
+ // The app's id goes on the surface, where Zag looks for it by this one.
56
+ ids: { content: props.id },
57
+ "aria-label": props.label,
58
+ positioning: {
59
+ placement: `bottom-${props.align ?? "start"}` as const,
60
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
61
+ getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
62
+ },
63
+ onSelect: (details: menu.SelectionDetails) => {
64
+ // The values are positions, because two items may have the same label.
65
+ const item = props.items[Number(details.value)];
66
+ if (item && item !== "separator") item.onSelect();
67
+ },
68
+ onEscapeKeyDown: leaveEscapeToFields,
69
+ // The arrow keys go round from the last item to the first, as in a native menu.
70
+ loopFocus: true,
71
+ }));
72
+ const api = createMemo(() => menu.connect(service, normalizeProps));
73
+ // Whether the last press on the trigger opened the menu, which its click must then not do.
74
+ let pressOpened = false;
75
+ const trigger = provideTrigger(() => {
76
+ // Zag's handler for a press is left out: it keeps the press from focusing the trigger, so
77
+ // the focus would reach the menu, and come back to the trigger as the menu closes, only
78
+ // from a script, which the browser marks with the keyboard ring.
79
+ const { onPointerDown: _onPointerDown, ...rest } = api().getTriggerProps() as TriggerProps;
80
+ return mergeProps(rest, {
81
+ // Added to the control's own class; the trigger looks pressed while its menu is open.
82
+ class: "{{prefix}}-menu__trigger",
83
+ // A mouse opens the menu as its button goes down; touch and pen open it on the click,
84
+ // as Zag does.
85
+ onPointerDown: (event: PointerEvent & { currentTarget: HTMLElement }) => {
86
+ pressOpened = opensOnPress(event) && !api().open;
87
+ if (pressOpened) api().setOpen(true);
88
+ },
89
+ onClick: (event: MouseEvent) => {
90
+ // A click with no pointer behind it comes from a screen reader or a script.
91
+ const pointer = event.detail !== 0;
92
+ // The press opened the menu already. This handler runs before Zag's, which skips a
93
+ // handled click. Not told by the click's pointer type: a browser may send the click
94
+ // as a plain mouse event.
95
+ if (pressOpened && pointer) {
96
+ pressOpened = false;
97
+ event.preventDefault();
98
+ return;
99
+ }
100
+ if (pointer) return;
101
+ // After the machine has opened the menu.
102
+ requestAnimationFrame(() => {
103
+ if (!api().open) return;
104
+ const first = firstMenuValue(props.items);
105
+ if (first !== undefined) api().setHighlightedValue(first);
106
+ });
107
+ },
108
+ });
109
+ });
110
+ let positioner: HTMLDivElement | undefined;
111
+ let surface: HTMLDivElement | undefined;
112
+ modalPopover(
113
+ () => api().open,
114
+ () => positioner,
115
+ );
116
+ const present = createPresence(
117
+ () => api().open,
118
+ () => [surface],
119
+ );
120
+ const content = mergeProps(() => api().getContentProps(), rootAttributes(props), {
121
+ // This handler runs before Zag's.
122
+ onKeyDown: (event: KeyboardEvent) =>
123
+ keepListKeys(event, surface, ".{{prefix}}-menu__item:not([data-disabled])", (value) =>
124
+ api().setHighlightedValue(value),
125
+ ),
126
+ // The app's, laid over Zag's.
127
+ get style() {
128
+ return props.style;
129
+ },
130
+ });
131
+ return (
132
+ <>
133
+ <TriggerContext value={trigger}>{props.trigger}</TriggerContext>
134
+ <Portal>
135
+ {/* Nothing inside opens an overlay from a control outside it. */}
136
+ <TriggerContext value={null}>
137
+ <Show when={api().open}>
138
+ {/* Takes a press outside, which then only closes the menu. The focus stays in the
139
+ menu until the menu hands it back to the trigger. */}
140
+ {/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
141
+ <div
142
+ class="{{prefix}}-menu__underlay"
143
+ style={underlayLayerStyle(api().getPositionerProps().style)}
144
+ onMouseDown={(event) => event.preventDefault()}
145
+ />
146
+ </Show>
147
+ <div
148
+ ref={(element) => (positioner = element)}
149
+ {...api().getPositionerProps()}
150
+ class="{{prefix}}-menu__positioner"
151
+ >
152
+ {/* Shown until its exit animation ends; Zag would hide it as it closes. */}
153
+ <div
154
+ {...content}
155
+ ref={(element) => (surface = element)}
156
+ hidden={!present()}
157
+ class={classes("{{prefix}}-menu", props.class)}
158
+ >
159
+ <For each={props.items}>
160
+ {(item, index) => {
161
+ if (item === "separator")
162
+ return (
163
+ <div {...api().getSeparatorProps()} class="{{prefix}}-menu__separator" />
164
+ );
165
+ const itemProps = createItemProps(() =>
166
+ api().getItemProps({ value: String(index()), disabled: item.disabled }),
167
+ );
168
+ return (
169
+ <div {...itemProps()} class={menuItemClass(item.danger)}>
170
+ <Show when={item.icon}>
171
+ {(name) => (
172
+ <Icon name={name()} size="sm" class="{{prefix}}-menu__item-icon" />
173
+ )}
174
+ </Show>
175
+ <span class="flex-1">{item.label}</span>
176
+ {/* Named, so a screen reader hears the state that the check shows. */}
177
+ <Show when={item.selected}>
178
+ <Icon name="check" size="sm" label="Selected" />
179
+ </Show>
180
+ </div>
181
+ );
182
+ }}
183
+ </For>
184
+ </div>
185
+ </div>
186
+ </TriggerContext>
187
+ </Portal>
188
+ </>
189
+ );
190
+ }
@@ -0,0 +1,109 @@
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
+ type RootProps,
8
+ rootAttributes,
9
+ useLabels,
10
+ } from "@xds/solid/base";
11
+ import { For, Show } from "solid-js";
12
+ import { Icon } from "./Icon.tsx";
13
+ import {
14
+ clampPage,
15
+ PAGINATION_PARTS,
16
+ PAGINATION_STEPS,
17
+ type PaginationBaseProps,
18
+ paginationEntries,
19
+ } from "./pagination.ts";
20
+ import { classes, rootPart } from "./parts.ts";
21
+
22
+ export type PaginationProps = PaginationBaseProps &
23
+ RootProps & {
24
+ /** Called with the page to show, from 1. */
25
+ onChange?: (value: number) => void;
26
+ };
27
+
28
+ const ROOT = rootPart("Pagination");
29
+
30
+ /**
31
+ * Moves through a list split into pages: a step back, the first and the last pages, the page
32
+ * shown with an ellipsis for those left out, and a step on. A navigation landmark; the page
33
+ * shown is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
34
+ */
35
+ export function Pagination(props: PaginationProps) {
36
+ const labels = useLabels();
37
+ const value = createControllable<number | undefined>({
38
+ controlled: () => isControlled(props, "value"),
39
+ value: () => props.value,
40
+ defaultValue: () => props.defaultValue ?? 1,
41
+ onChange: (next) => {
42
+ if (next !== undefined) props.onChange?.(next);
43
+ },
44
+ });
45
+ const page = () => clampPage(value.value() ?? 1, props.count);
46
+ const last = () => Math.max(1, Math.floor(props.count));
47
+ const go = (next: number) => {
48
+ if (next !== page() && next >= 1 && next <= last()) value.set(next);
49
+ };
50
+ return (
51
+ <nav
52
+ {...rootAttributes(props)}
53
+ aria-label={props.label ?? labels().pagination}
54
+ class={classes(ROOT, props.class)}
55
+ style={props.style}
56
+ >
57
+ <ul class={PAGINATION_PARTS.list}>
58
+ <li>
59
+ <button
60
+ type="button"
61
+ class={PAGINATION_PARTS.step}
62
+ aria-label={props.previousLabel ?? labels().previousPage}
63
+ aria-disabled={page() <= 1 ? "true" : undefined}
64
+ onClick={() => go(page() - 1)}
65
+ >
66
+ <Icon name={PAGINATION_STEPS.previous} size={PAGINATION_STEPS.size} />
67
+ </button>
68
+ </li>
69
+ {/* By place: the two gaps are equal, and a page moves from place to place. */}
70
+ <For each={paginationEntries(page(), props.count)} keyed={false}>
71
+ {(entry) => (
72
+ <li>
73
+ <Show
74
+ when={entry() !== "gap" && (entry() as number)}
75
+ fallback={
76
+ <span class={PAGINATION_PARTS.gap} aria-hidden="true">
77
+ …
78
+ </span>
79
+ }
80
+ >
81
+ {(number) => (
82
+ <button
83
+ type="button"
84
+ class={PAGINATION_PARTS.page}
85
+ aria-current={number() === page() ? "page" : undefined}
86
+ onClick={() => go(number())}
87
+ >
88
+ {number()}
89
+ </button>
90
+ )}
91
+ </Show>
92
+ </li>
93
+ )}
94
+ </For>
95
+ <li>
96
+ <button
97
+ type="button"
98
+ class={PAGINATION_PARTS.step}
99
+ aria-label={props.nextLabel ?? labels().nextPage}
100
+ aria-disabled={page() >= last() ? "true" : undefined}
101
+ onClick={() => go(page() + 1)}
102
+ >
103
+ <Icon name={PAGINATION_STEPS.next} size={PAGINATION_STEPS.size} />
104
+ </button>
105
+ </li>
106
+ </ul>
107
+ </nav>
108
+ );
109
+ }
@@ -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
+ createControllable,
6
+ createPresence,
7
+ isControlled,
8
+ leaveEscapeToFields,
9
+ Portal,
10
+ provideTrigger,
11
+ type RootProps,
12
+ readCssPx,
13
+ rootAttributes,
14
+ space,
15
+ TriggerContext,
16
+ type TriggerProps,
17
+ useLabels,
18
+ withStyle,
19
+ } from "@xds/solid/base";
20
+ import * as popover from "@zag-js/popover";
21
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
22
+ import { createMemo, createUniqueId, type Element, Show } from "solid-js";
23
+ import { IconButton } from "./IconButton.tsx";
24
+ import { classes } from "./parts.ts";
25
+ import { POPOVER_PARTS, type PopoverBaseProps } from "./popover.ts";
26
+
27
+ /** `class` and `style` are for the popover's surface, not for its trigger. */
28
+ export type PopoverProps = PopoverBaseProps &
29
+ RootProps & {
30
+ /** The control that opens it: a Button or an IconButton. */
31
+ trigger: Element;
32
+ /** Called with whether it is open, as it opens and closes. */
33
+ onOpenChange?: (open: boolean) => void;
34
+ /** What it holds: a few lines of text, a short form, actions. */
35
+ children?: Element;
36
+ };
37
+
38
+ /**
39
+ * A surface that opens beside the control that opens it, for details or a short task that do
40
+ * not need the whole screen: a press outside, Escape or its close button closes it, and the
41
+ * focus goes back to the trigger. It is a dialog named by its title, and not modal: the page
42
+ * stays as it is behind it. Without `open` it keeps its own, from `defaultOpen`.
43
+ */
44
+ export function Popover(props: PopoverProps) {
45
+ const id = createUniqueId();
46
+ const labels = useLabels();
47
+ const open = createControllable<boolean | undefined>({
48
+ controlled: () => isControlled(props, "open"),
49
+ value: () => props.open,
50
+ defaultValue: () => props.defaultOpen ?? false,
51
+ onChange: (next) => props.onOpenChange?.(next ?? false),
52
+ });
53
+ let content: HTMLElement | undefined;
54
+ const service = useMachine(popover.machine, () => ({
55
+ id,
56
+ // The app's id goes on the surface, where Zag looks for it by this one.
57
+ ids: { content: props.id },
58
+ open: open.value() ?? false,
59
+ onOpenChange: (details: popover.OpenChangeDetails) => open.set(details.open),
60
+ positioning: {
61
+ placement: props.placement ?? "bottom",
62
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
63
+ },
64
+ onEscapeKeyDown: leaveEscapeToFields,
65
+ // The surface itself rather than its first control: a screen reader then reads the title
66
+ // first, and the close button is the next stop.
67
+ initialFocusEl: () => content ?? null,
68
+ }));
69
+ const api = createMemo(() => popover.connect(service, normalizeProps));
70
+ const trigger = provideTrigger(
71
+ // Added to the control's own class; the trigger looks pressed while it is open.
72
+ () =>
73
+ mergeProps(api().getTriggerProps() as TriggerProps, {
74
+ class: POPOVER_PARTS.trigger,
75
+ }) as TriggerProps,
76
+ );
77
+ const contentProps = withStyle(
78
+ () => api().getContentProps(),
79
+ () => props.style,
80
+ rootAttributes(props),
81
+ );
82
+ const present = createPresence(
83
+ () => api().open,
84
+ () => [content],
85
+ );
86
+ return (
87
+ <>
88
+ <TriggerContext value={trigger}>{props.trigger}</TriggerContext>
89
+ <Show when={present()}>
90
+ <Portal>
91
+ {/* Nothing inside opens an overlay from a control outside it. */}
92
+ <TriggerContext value={null}>
93
+ <div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
94
+ {/* Shown until its exit animation ends; Zag would hide it as it closes. */}
95
+ <section
96
+ {...contentProps}
97
+ ref={(element) => (content = element)}
98
+ hidden={false}
99
+ class={classes("{{prefix}}-popover", props.class)}
100
+ >
101
+ <div class={POPOVER_PARTS.header}>
102
+ <h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>
103
+ {props.title}
104
+ </h2>
105
+ <IconButton
106
+ icon="x"
107
+ label={props.closeLabel ?? labels().close}
108
+ variant="ghost"
109
+ size="sm"
110
+ class={POPOVER_PARTS.close}
111
+ onPress={() => api().setOpen(false)}
112
+ />
113
+ </div>
114
+ <Show when={props.children != null}>
115
+ <div class={POPOVER_PARTS.body}>{props.children}</div>
116
+ </Show>
117
+ </section>
118
+ </div>
119
+ </TriggerContext>
120
+ </Portal>
121
+ </Show>
122
+ </>
123
+ );
124
+ }
@@ -0,0 +1,37 @@
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 { classes, rootPart } from "./parts.ts";
6
+ import {
7
+ type ProgressBarBaseProps,
8
+ progressBarClass,
9
+ progressBarFillClass,
10
+ progressPercent,
11
+ } from "./progress-bar.ts";
12
+
13
+ export type ProgressBarProps = ProgressBarBaseProps & RootProps;
14
+
15
+ const ROOT = rootPart("ProgressBar");
16
+
17
+ /**
18
+ * How far along something is, from 0 to 1. For work of unknown length use a Spinner.
19
+ * `label` says what is progressing; a screen reader reads it with the percentage.
20
+ */
21
+ export function ProgressBar(props: ProgressBarProps) {
22
+ const percent = () => progressPercent(props.value);
23
+ return (
24
+ <div
25
+ {...rootAttributes(props)}
26
+ role="progressbar"
27
+ aria-label={props.label}
28
+ aria-valuemin={0}
29
+ aria-valuemax={100}
30
+ aria-valuenow={percent()}
31
+ class={classes(ROOT, progressBarClass, props.class)}
32
+ style={props.style}
33
+ >
34
+ <div class={progressBarFillClass} style={{ width: `${percent()}%` }} />
35
+ </div>
36
+ );
37
+ }