@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
@@ -1,19 +1,37 @@
1
1
  import { space } from "@xds/tokens";
2
- import { classes, keepListKeys, readCssPx, selectOptionIds, underlayLayerStyle, } from "@xds/core";
2
+ import { classes, isControlled, keepListKeys, orderedValues, readCssPx, selectedLabels, selectOptionIds, underlayLayerStyle, } from "@xds/core";
3
3
  import * as select from "@zag-js/select";
4
4
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
5
5
  import { createMemo, createUniqueId, For, Show } from "solid-js";
6
+ import { createControllable } from "./controllable.js";
6
7
  import { Icon } from "./Icon.jsx";
7
8
  import { modalPopover } from "./modal-popover.js";
8
9
  import { Portal } from "./portal.jsx";
9
10
  import { createPresence } from "./presence.js";
10
- import { withStyle } from "./root.js";
11
+ import { rootAttributes, withStyle } from "./root.js";
12
+ import { createItemProps } from "./rows.js";
11
13
  export function Select(props) {
12
14
  const id = createUniqueId();
13
15
  const valueId = `${id}-value`;
14
16
  const descriptionId = `${id}-description`;
15
17
  const errorId = `${id}-error`;
16
18
  const invalid = () => props.error !== undefined;
19
+ const value = createControllable({
20
+ controlled: () => isControlled(props, "value"),
21
+ value: () => props.value,
22
+ defaultValue: () => props.defaultValue,
23
+ onChange: (next) => {
24
+ if (next !== undefined)
25
+ props.onChange?.(next);
26
+ },
27
+ });
28
+ const values = createControllable({
29
+ controlled: () => isControlled(props, "values"),
30
+ value: () => props.values ?? [],
31
+ defaultValue: () => props.defaultValues ?? [],
32
+ onChange: (next) => props.onValuesChange?.([...next]),
33
+ });
34
+ const multiple = () => props.multiple ?? false;
17
35
  const collection = createMemo(() => select.collection({
18
36
  items: [...props.options],
19
37
  itemToValue: (option) => option.value,
@@ -21,13 +39,24 @@ export function Select(props) {
21
39
  }));
22
40
  const service = useMachine(select.machine, () => ({
23
41
  id,
42
+ ids: { root: props.id },
24
43
  collection: collection(),
25
- value: props.value === undefined ? [] : [props.value],
44
+ value: multiple()
45
+ ? [...values.value()]
46
+ : value.value() === undefined
47
+ ? []
48
+ : [value.value()],
26
49
  onValueChange: (details) => {
50
+ if (multiple()) {
51
+ values.set(orderedValues(props.options, details.value));
52
+ return;
53
+ }
27
54
  const next = details.value[0];
28
55
  if (next !== undefined)
29
- props.onChange(next);
56
+ value.set(next);
30
57
  },
58
+ multiple: multiple(),
59
+ closeOnSelect: !multiple(),
31
60
  disabled: props.disabled,
32
61
  invalid: invalid(),
33
62
  name: props.name,
@@ -39,7 +68,7 @@ export function Select(props) {
39
68
  },
40
69
  }));
41
70
  const api = createMemo(() => select.connect(service, normalizeProps));
42
- const root = withStyle(() => api().getRootProps(), () => props.style);
71
+ const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
43
72
  const current = () => select.connect(service, normalizeProps);
44
73
  const labelProps = createMemo(() => {
45
74
  const { for: _, ...rest } = api().getLabelProps();
@@ -76,7 +105,8 @@ export function Select(props) {
76
105
  <button {...triggerProps()} aria-labelledby={`${valueId} ${labelProps().id}`} aria-describedby={invalid() ? errorId : props.description ? descriptionId : undefined} class="xds-select__trigger">
77
106
 
78
107
  <span {...api().getValueTextProps()} id={valueId} class="xds-select__value">
79
- {api().valueAsString || props.placeholder}
108
+ {(multiple() ? selectedLabels(props.options, values.value()) : api().valueAsString) ||
109
+ props.placeholder}
80
110
  </span>
81
111
  <Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder"/>
82
112
  </button>
@@ -93,8 +123,10 @@ export function Select(props) {
93
123
  </div>
94
124
 
95
125
  <select {...api().getHiddenSelectProps()}>
96
-
97
- <option value=""/>
126
+ <Show when={!multiple()}>
127
+
128
+ <option value=""/>
129
+ </Show>
98
130
  <For each={props.options}>
99
131
  {(option) => <option value={option.value}>{option.label}</option>}
100
132
  </For>
@@ -112,9 +144,12 @@ export function Select(props) {
112
144
  <For each={collection().items}>
113
145
  {(option, index) => {
114
146
  const ids = () => selectOptionIds(id, index());
115
- return (<div {...api().getItemProps({ item: option })} aria-labelledby={ids().label} aria-describedby={option.description ? ids().description : undefined} class="xds-select__item">
147
+ const itemProps = createItemProps(() => api().getItemProps({ item: option }));
148
+ const textProps = createItemProps(() => api().getItemTextProps({ item: option }));
149
+ const selected = createMemo(() => api().getItemState({ item: option }).selected);
150
+ return (<div {...itemProps()} aria-labelledby={ids().label} aria-describedby={option.description ? ids().description : undefined} class="xds-select__item">
116
151
  <span class="xds-select__item-words">
117
- <span {...api().getItemTextProps({ item: option })} id={ids().label} class="xds-select__item-label">
152
+ <span {...textProps()} id={ids().label} class="xds-select__item-label">
118
153
  {option.label}
119
154
  </span>
120
155
  <Show when={option.description}>
@@ -124,7 +159,7 @@ export function Select(props) {
124
159
  </Show>
125
160
  </span>
126
161
 
127
- <Show when={api().getItemState({ item: option }).selected}>
162
+ <Show when={selected()}>
128
163
  <Icon name="check" size="sm"/>
129
164
  </Show>
130
165
  </div>);
@@ -1,7 +1,7 @@
1
1
  import { type SidebarBaseProps } from "@xds/core";
2
2
  import type { JSX } from "@solidjs/web";
3
3
  import { type Element } from "solid-js";
4
- import type { RootProps } from "./root.ts";
4
+ import { type RootProps } from "./root.ts";
5
5
  export type { SidebarItem, SidebarSection } from "@xds/core";
6
6
  export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> & RootProps & {
7
7
  onChange: (value: Value) => void;
@@ -2,13 +2,14 @@ import { classes, rootPart, SIDEBAR_PARTS, sidebarClass, sidebarCount, sidebarIc
2
2
  import { createMemo, createUniqueId, For, Show } from "solid-js";
3
3
  import { Icon } from "./Icon.jsx";
4
4
  import { PlaceRow } from "./ListRow.jsx";
5
+ import { rootAttributes } from "./root.js";
5
6
  import { TooltipBeside } from "./Tooltip.jsx";
6
7
  import { withTrigger } from "./trigger.js";
7
8
  const ROOT = rootPart("Sidebar");
8
9
  export function Sidebar(props) {
9
10
  const id = createUniqueId();
10
11
  const collapsed = () => props.collapsed ?? false;
11
- return (<nav aria-label={props.label} class={classes(ROOT, sidebarClass(collapsed()), props.class)} style={props.style}>
12
+ return (<nav {...rootAttributes(props)} aria-label={props.label} class={classes(ROOT, sidebarClass(collapsed()), props.class)} style={props.style}>
12
13
  <Show when={props.header}>
13
14
  {(header) => <div class={SIDEBAR_PARTS.edge}>{header()}</div>}
14
15
  </Show>
@@ -1,9 +1,9 @@
1
1
  import { classes, rootPart, skeletonClass, skeletonSize, } from "@xds/core";
2
2
  import { useDefaults } from "./Defaults.jsx";
3
- import { layStyle } from "./root.js";
3
+ import { layStyle, rootAttributes } from "./root.js";
4
4
  const ROOT = rootPart("Skeleton");
5
5
  export function Skeleton(props) {
6
6
  const defaults = useDefaults("Skeleton");
7
7
  const shape = () => props.shape ?? defaults().shape;
8
- return (<span aria-hidden="true" class={classes(ROOT, skeletonClass(shape()), props.class)} style={layStyle(skeletonSize({ shape: shape(), width: props.width, height: props.height }), props.style)}/>);
8
+ return (<span {...rootAttributes(props)} aria-hidden="true" class={classes(ROOT, skeletonClass(shape()), props.class)} style={layStyle(skeletonSize({ shape: shape(), width: props.width, height: props.height }), props.style)}/>);
9
9
  }
@@ -1,13 +1,13 @@
1
1
  import { type SliderBaseProps } from "@xds/core";
2
2
  import { type RootProps } from "./root.ts";
3
3
  export type SliderProps = SliderBaseProps & RootProps & {
4
- onChange: (value: number) => void;
4
+ onChange?: (value: number) => void;
5
5
  };
6
6
  /**
7
7
  * Picks a number in a range by dragging the thumb, or by pressing the track where it should
8
8
  * go. The values snap to `step`.
9
9
  *
10
10
  * It is a slider named by its label with its value, minimum and maximum, and each arrow key
11
- * moves it one step.
11
+ * moves it one step. Without `value` it keeps its own, from `defaultValue`, or `min`.
12
12
  */
13
13
  export declare function Slider(props: SliderProps): import("@solidjs/web").JSX.Element;
@@ -1,19 +1,27 @@
1
- import { classes, focusThumbOnPress, sliderArrowValue, sliderPageSize, sliderValueText, } from "@xds/core";
1
+ import { classes, focusThumbOnPress, isControlled, sliderArrowValue, sliderPageSize, sliderValueText, } from "@xds/core";
2
2
  import * as slider from "@zag-js/slider";
3
3
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
4
4
  import { createMemo, createUniqueId, Show } from "solid-js";
5
- import { withStyle } from "./root.js";
5
+ import { createControllable } from "./controllable.js";
6
+ import { rootAttributes, withStyle } from "./root.js";
6
7
  export function Slider(props) {
7
8
  const id = createUniqueId();
8
9
  const min = () => props.min ?? 0;
9
10
  const max = () => props.max ?? 100;
10
11
  const step = () => props.step ?? 1;
11
12
  const pageSize = () => sliderPageSize({ min: min(), max: max(), step: step() });
13
+ const value = createControllable({
14
+ controlled: () => isControlled(props, "value"),
15
+ value: () => props.value ?? min(),
16
+ defaultValue: () => props.defaultValue ?? min(),
17
+ onChange: (next) => props.onChange?.(next),
18
+ });
12
19
  const service = useMachine(slider.machine, () => ({
13
20
  id,
21
+ ids: { root: props.id },
14
22
  name: props.name,
15
- value: [props.value],
16
- onValueChange: (details) => props.onChange(details.value[0] ?? min()),
23
+ value: [value.value()],
24
+ onValueChange: (details) => value.set(details.value[0] ?? min()),
17
25
  min: min(),
18
26
  max: max(),
19
27
  step: step(),
@@ -23,7 +31,7 @@ export function Slider(props) {
23
31
  getAriaValueText: (details) => sliderValueText(details.value, props.locale),
24
32
  }));
25
33
  const api = createMemo(() => slider.connect(service, normalizeProps));
26
- const root = withStyle(() => api().getRootProps(), () => props.style);
34
+ const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
27
35
  const thumb = mergeProps(() => api().getThumbProps({ index: 0 }), {
28
36
  draggable: "false",
29
37
  onKeyDown: (event) => {
@@ -57,7 +65,7 @@ export function Slider(props) {
57
65
  <Show when={props.showValue}>
58
66
 
59
67
  <output {...api().getValueTextProps()} aria-live="off" class="xds-slider__output">
60
- {sliderValueText(api().value[0] ?? props.value, props.locale)}
68
+ {sliderValueText(api().value[0] ?? value.value(), props.locale)}
61
69
  </output>
62
70
  </Show>
63
71
  <div {...control} class="xds-slider__control">
@@ -1,5 +1,5 @@
1
1
  import { type SpinnerBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type SpinnerProps = SpinnerBaseProps & RootProps;
4
4
  /**
5
5
  * Says that something is in progress and how long is unknown. Takes the color of the text around
@@ -1,9 +1,10 @@
1
1
  import { classes, rootPart, spinnerClass } from "@xds/core";
2
2
  import { useDefaults } from "./Defaults.jsx";
3
+ import { rootAttributes } from "./root.js";
3
4
  const ROOT = rootPart("Spinner");
4
5
  export function Spinner(props) {
5
6
  const defaults = useDefaults("Spinner");
6
- return (<span class={classes(ROOT, "inline-flex shrink-0", props.class)} style={props.style} role={props.label ? "status" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
7
+ return (<span {...rootAttributes(props)} class={classes(ROOT, "inline-flex shrink-0", props.class)} style={props.style} role={props.label ? "status" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
7
8
  <svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(props.size ?? defaults().size)}>
8
9
  <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25"/>
9
10
  <path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>
@@ -1,13 +1,19 @@
1
1
  import { type SwitchBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import type { JSX } from "@solidjs/web";
3
+ import { type RootProps } from "./root.ts";
3
4
  export type SwitchProps = SwitchBaseProps & RootProps & {
4
- onChange: (checked: boolean) => void;
5
+ onChange?: (checked: boolean) => void;
6
+ onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
7
+ onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
8
+ /** The native checkbox, which has the switch role. */
9
+ ref?: JSX.Ref<HTMLInputElement>;
5
10
  };
6
11
  /**
7
12
  * Turns a setting on or off, and takes effect at once. For a choice that is applied later,
8
13
  * with a form, use a Checkbox.
9
14
  *
10
15
  * It is a native checkbox with the switch role, so the keyboard, forms and screen readers
11
- * treat it as one. The input is hidden and the track is drawn beside it.
16
+ * treat it as one. The input is hidden and the track is drawn beside it. Without `checked` it
17
+ * keeps its own state, from `defaultChecked`.
12
18
  */
13
- export declare function Switch(props: SwitchProps): import("@solidjs/web").JSX.Element;
19
+ export declare function Switch(props: SwitchProps): JSX.Element;
@@ -1,13 +1,25 @@
1
- import { classes, rootPart, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "@xds/core";
1
+ import { classes, isControlled, rootPart, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "@xds/core";
2
2
  import { Show } from "solid-js";
3
+ import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
3
4
  import { keepChecked } from "./controlled.js";
5
+ import { rootAttributes } from "./root.js";
4
6
  const ROOT = rootPart("Switch");
5
7
  export function Switch(props) {
6
- return (<label class={classes(ROOT, switchClass, props.class)} style={props.style}>
7
- <input type="checkbox" role="switch" aria-checked={props.checked ? "true" : "false"} aria-label={props["aria-label"]} class="peer sr-only" checked={props.checked} defaultChecked={props.checked} disabled={props.disabled} onChange={(event) => {
8
- props.onChange(event.currentTarget.checked);
9
- keepChecked(event.currentTarget, () => props.checked);
10
- }}/>
8
+ const controlled = () => isControlled(props, "checked");
9
+ const defaultChecked = () => props.defaultChecked ?? false;
10
+ const checked = createControllable({
11
+ controlled,
12
+ value: () => props.checked ?? false,
13
+ defaultValue: defaultChecked,
14
+ onChange: (next) => props.onChange?.(next),
15
+ });
16
+ let input;
17
+ resetWithForm(() => input, controlled, checked.reset);
18
+ return (<label {...rootAttributes(props)} class={classes(ROOT, switchClass, props.class)} style={props.style}>
19
+ <input ref={composeRefs((element) => (input = element), () => props.ref)} type="checkbox" role="switch" aria-checked={checked.value() ? "true" : "false"} aria-label={props["aria-label"]} class="peer sr-only" checked={checked.value()} defaultChecked={controlled() ? checked.value() : defaultChecked()} disabled={props.disabled} onChange={(event) => {
20
+ checked.set(event.currentTarget.checked);
21
+ keepChecked(event.currentTarget, checked.value);
22
+ }} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)}/>
11
23
  <span class={switchTrackClass}>
12
24
  <span class={switchThumbClass}/>
13
25
  </span>
@@ -0,0 +1,17 @@
1
+ import { type TableBaseProps, type TableSort } from "@xds/core";
2
+ import { type RootProps } from "./root.ts";
3
+ export type { SortDirection, TableColumn, TableRow, TableSort } from "@xds/core";
4
+ export type TableProps = TableBaseProps & RootProps & {
5
+ /**
6
+ * Called with the sort a press on a sortable column's header asks for. The app sorts the
7
+ * rows and gives the table the new `sort`.
8
+ */
9
+ onSortChange?: (sort: TableSort) => void;
10
+ };
11
+ /**
12
+ * Rows of data under a row of column headers, to read and compare across. The header of a
13
+ * sortable column is a button that asks for the rows sorted by it, ascending first and then the
14
+ * other way, and the header they are sorted by says so with `aria-sort` and an arrow. The rows
15
+ * are shown in the order given. Where the columns do not fit, the table scrolls sideways.
16
+ */
17
+ export declare function Table(props: TableProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import { classes, columnSort, nextSort, rootPart, sortIcon, TABLE_PARTS, } from "@xds/core";
2
+ import { For, Show } from "solid-js";
3
+ import { Icon } from "./Icon.jsx";
4
+ import { rootAttributes } from "./root.js";
5
+ const ROOT = rootPart("Table");
6
+ export function Table(props) {
7
+ const end = (align) => align === "end" && TABLE_PARTS.end;
8
+ return (<div {...rootAttributes(props)} class={classes(ROOT, props.class)} style={props.style}>
9
+ <table class={TABLE_PARTS.table} aria-label={props.label}>
10
+ <thead>
11
+ <tr class={TABLE_PARTS.row}>
12
+ <For each={props.columns}>
13
+ {(column) => {
14
+ const direction = () => columnSort(props.sort, column.key);
15
+ return (<th scope="col" aria-sort={direction()} class={classes(TABLE_PARTS.header, end(column.align))}>
16
+ <Show when={column.sortable} fallback={column.label}>
17
+ <button type="button" class={TABLE_PARTS.sort} onClick={() => props.onSortChange?.(nextSort(props.sort, column.key))}>
18
+ {column.label}
19
+ <Icon name={sortIcon(direction())} size="xs"/>
20
+ </button>
21
+ </Show>
22
+ </th>);
23
+ }}
24
+ </For>
25
+ </tr>
26
+ </thead>
27
+ <tbody>
28
+ <Show when={props.rows.length > 0 || props.empty === undefined} fallback={<tr class={TABLE_PARTS.row}>
29
+ <td class={TABLE_PARTS.empty} colspan={props.columns.length}>
30
+ {props.empty}
31
+ </td>
32
+ </tr>}>
33
+ <For each={props.rows}>
34
+ {(row) => (<tr class={TABLE_PARTS.row}>
35
+ <For each={props.columns}>
36
+ {(column, index) => (<td class={classes(TABLE_PARTS.cell, end(column.align))}>
37
+ {row.cells[index()]}
38
+ </td>)}
39
+ </For>
40
+ </tr>)}
41
+ </For>
42
+ </Show>
43
+ </tbody>
44
+ </table>
45
+ </div>);
46
+ }
@@ -1,7 +1,7 @@
1
1
  import { type TabsBaseProps } from "@xds/core";
2
2
  import { type RootProps } from "./root.ts";
3
3
  export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps & {
4
- onChange: (value: Value) => void;
4
+ onChange?: (value: Value) => void;
5
5
  };
6
6
  /**
7
7
  * Switches between views inside one screen. For two to four short modes a SegmentedControl is
@@ -9,6 +9,6 @@ export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps &
9
9
  *
10
10
  * The selected tab is underlined as well as darker, so the choice does not depend on color.
11
11
  * This is only the row: the app shows the view that matches `value`. The arrow keys move
12
- * between tabs.
12
+ * between tabs. Without `value` they keep their own, from `defaultValue`, or the first tab.
13
13
  */
14
14
  export declare function Tabs<Value extends string>(props: TabsProps<Value>): import("@solidjs/web").JSX.Element;
@@ -1,18 +1,29 @@
1
- import { classes, tabStopIndex, tabsClass } from "@xds/core";
1
+ import { classes, isControlled, tabStopIndex, tabsClass } from "@xds/core";
2
2
  import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
3
3
  import * as tabs from "@zag-js/tabs";
4
4
  import { createMemo, createUniqueId, For, Show } from "solid-js";
5
+ import { createControllable } from "./controllable.js";
5
6
  import { Icon } from "./Icon.jsx";
6
- import { withStyle } from "./root.js";
7
+ import { rootAttributes, withStyle } from "./root.js";
7
8
  export function Tabs(props) {
8
9
  const id = createUniqueId();
10
+ const value = createControllable({
11
+ controlled: () => isControlled(props, "value"),
12
+ value: () => props.value,
13
+ defaultValue: () => props.defaultValue ?? props.items[0]?.value,
14
+ onChange: (next) => {
15
+ if (next !== undefined)
16
+ props.onChange?.(next);
17
+ },
18
+ });
9
19
  const service = useMachine(tabs.machine, () => ({
10
20
  id,
11
- value: props.value,
12
- onValueChange: (details) => props.onChange(details.value),
21
+ ids: { root: props.id },
22
+ value: value.value() ?? null,
23
+ onValueChange: (details) => value.set(details.value),
13
24
  }));
14
25
  const api = createMemo(() => tabs.connect(service, normalizeProps));
15
- const root = withStyle(() => api().getRootProps(), () => props.style);
26
+ const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
16
27
  return (<div {...root} class={classes(tabsClass(props.fullWidth), props.class)}>
17
28
  <div {...api().getListProps()} aria-label={props.label} class="xds-tabs__list">
18
29
  <For each={props.items}>
@@ -1,7 +1,7 @@
1
1
  import { type TextBaseProps } from "@xds/core";
2
2
  import { type ValidComponent } from "@solidjs/web";
3
3
  import type { Element } from "solid-js";
4
- import type { RootProps } from "./root.ts";
4
+ import { type RootProps } from "./root.ts";
5
5
  export type TextProps = TextBaseProps & RootProps & {
6
6
  /** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
7
7
  as?: ValidComponent;
@@ -1,11 +1,12 @@
1
1
  import { classes, rootPart, textClass } from "@xds/core";
2
2
  import { dynamic } from "@solidjs/web";
3
3
  import { useDefaults } from "./Defaults.jsx";
4
+ import { rootAttributes } from "./root.js";
4
5
  const ROOT = rootPart("Text");
5
6
  export function Text(props) {
6
7
  const Tag = dynamic(() => props.as ?? "p");
7
8
  const defaults = useDefaults("Text");
8
- return (<Tag class={classes(ROOT, textClass({
9
+ return (<Tag {...rootAttributes(props)} class={classes(ROOT, textClass({
9
10
  variant: props.variant ?? defaults().variant,
10
11
  tone: props.tone ?? defaults().tone,
11
12
  }), props.class)} style={props.style}>
@@ -1,8 +1,14 @@
1
1
  import { type TextFieldBaseProps } from "@xds/core";
2
+ import type { JSX } from "@solidjs/web";
2
3
  import { type Element } from "solid-js";
3
- import type { RootProps } from "./root.ts";
4
+ import { type RootProps } from "./root.ts";
5
+ type Field = HTMLInputElement | HTMLTextAreaElement;
4
6
  export type TextFieldProps = TextFieldBaseProps & RootProps & {
5
- onChange: (value: string) => void;
7
+ onChange?: (value: string) => void;
8
+ onFocus?: JSX.FocusEventHandler<Field, FocusEvent>;
9
+ onBlur?: JSX.FocusEventHandler<Field, FocusEvent>;
10
+ /** The native input, or the text area of a field of several lines. */
11
+ ref?: JSX.Ref<Field>;
6
12
  /**
7
13
  * Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
8
14
  * unless it sets its own.
@@ -18,5 +24,8 @@ export type TextFieldProps = TextFieldBaseProps & RootProps & {
18
24
  *
19
25
  * An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
20
26
  * the person edits the value.
27
+ *
28
+ * Without `value` it keeps its own text, from `defaultValue`.
21
29
  */
22
- export declare function TextField(props: TextFieldProps): import("@solidjs/web").JSX.Element;
30
+ export declare function TextField(props: TextFieldProps): JSX.Element;
31
+ export {};
@@ -1,6 +1,8 @@
1
- import { classes } from "@xds/core";
1
+ import { classes, isControlled } from "@xds/core";
2
2
  import { children, createEffect, createUniqueId, onSettled, Show } from "solid-js";
3
+ import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
3
4
  import { keepValue } from "./controlled.js";
5
+ import { rootAttributes } from "./root.js";
4
6
  export function TextField(props) {
5
7
  const id = createUniqueId();
6
8
  const descriptionId = `${id}-description`;
@@ -9,6 +11,15 @@ export function TextField(props) {
9
11
  const trailing = children(() => props.trailing);
10
12
  const invalid = () => props.error !== undefined;
11
13
  let input;
14
+ const controlled = () => isControlled(props, "value");
15
+ const defaultValue = () => props.defaultValue ?? "";
16
+ const value = createControllable({
17
+ controlled,
18
+ value: () => props.value ?? "",
19
+ defaultValue,
20
+ onChange: (next) => props.onChange?.(next),
21
+ });
22
+ resetWithForm(() => input, controlled, value.reset);
12
23
  onSettled(() => {
13
24
  if (input instanceof HTMLTextAreaElement)
14
25
  input.setSelectionRange(0, 0);
@@ -21,8 +32,8 @@ export function TextField(props) {
21
32
  const shared = (box) => ({
22
33
  id,
23
34
  class: box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input",
24
- value: props.value,
25
- defaultValue: props.value,
35
+ value: value.value(),
36
+ defaultValue: controlled() ? value.value() : defaultValue(),
26
37
  placeholder: props.placeholder,
27
38
  name: props.name,
28
39
  maxlength: props.maxLength,
@@ -30,18 +41,22 @@ export function TextField(props) {
30
41
  autocomplete: props.autoComplete,
31
42
  required: props.required,
32
43
  disabled: props.disabled,
44
+ readonly: props.readOnly,
33
45
  "aria-invalid": invalid() ? "true" : undefined,
34
46
  "aria-errormessage": invalid() ? errorId : undefined,
35
47
  "aria-describedby": invalid() ? errorId : props.description ? descriptionId : undefined,
36
48
  onInput: (event) => {
37
- props.onChange(event.currentTarget.value);
49
+ value.set(event.currentTarget.value);
38
50
  if (!event.isComposing)
39
- keepValue(event.currentTarget, () => props.value);
51
+ keepValue(event.currentTarget, value.value);
40
52
  },
41
- onCompositionEnd: (event) => keepValue(event.currentTarget, () => props.value),
53
+ onCompositionEnd: (event) => keepValue(event.currentTarget, value.value),
54
+ onFocus: (event) => props.onFocus?.(event),
55
+ onBlur: (event) => props.onBlur?.(event),
42
56
  });
43
- const field = (box) => props.multiline ? (<textarea ref={(element) => (input = element)} rows={props.rows ?? 3} {...shared(box)}/>) : (<input ref={(element) => (input = element)} type={props.type ?? "text"} {...shared(box)}/>);
44
- return (<div class={classes("xds-text-field", props.class)} style={props.style}>
57
+ const ref = composeRefs((element) => (input = element), () => props.ref);
58
+ const field = (box) => props.multiline ? (<textarea ref={ref} rows={props.rows ?? 3} {...shared(box)}/>) : (<input ref={ref} type={props.type ?? "text"} {...shared(box)}/>);
59
+ return (<div {...rootAttributes(props)} class={classes("xds-text-field", props.class)} style={props.style}>
45
60
  <label for={id} class="xds-text-field__label">
46
61
  {props.label}
47
62
  </label>
@@ -68,7 +83,7 @@ export function TextField(props) {
68
83
  </span>
69
84
  <Show when={props.maxLength !== undefined}>
70
85
  <span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">
71
- {props.value.length}/{props.maxLength}
86
+ {value.value().length}/{props.maxLength}
72
87
  </span>
73
88
  </Show>
74
89
  </div>
@@ -1,5 +1,5 @@
1
1
  import { type ThumbnailBaseProps } from "@xds/core";
2
- import type { RootProps } from "./root.ts";
2
+ import { type RootProps } from "./root.ts";
3
3
  export type { ThumbnailRatio } from "@xds/core";
4
4
  export type ThumbnailProps = ThumbnailBaseProps & RootProps;
5
5
  /**
@@ -4,12 +4,13 @@ import { Badge } from "./Badge.jsx";
4
4
  import { useDefaults } from "./Defaults.jsx";
5
5
  import { Icon } from "./Icon.jsx";
6
6
  import { createPicture } from "./picture.js";
7
+ import { rootAttributes } from "./root.js";
7
8
  const ROOT = rootPart("Thumbnail");
8
9
  export function Thumbnail(props) {
9
10
  const defaults = useDefaults("Thumbnail");
10
11
  const picture = createPicture(() => props.src);
11
12
  const watched = () => thumbnailWatched(props.progress);
12
- return (<span class={classes(ROOT, thumbnailClass(props.ratio ?? defaults().ratio), props.class)} style={props.style}>
13
+ return (<span {...rootAttributes(props)} class={classes(ROOT, thumbnailClass(props.ratio ?? defaults().ratio), props.class)} style={props.style}>
13
14
 
14
15
  <span class={THUMBNAIL_PARTS.placeholder} role={props.alt ? "img" : undefined} aria-label={props.alt || undefined} aria-hidden={props.alt ? undefined : "true"}>
15
16
  <Show when={picture.loaded() !== true}>
@@ -0,0 +1,19 @@
1
+ import { type IsoTime, type TimePickerBaseProps } from "@xds/core";
2
+ import type { JSX } from "@solidjs/web";
3
+ import { type RootProps } from "./root.ts";
4
+ export type { IsoTime } from "@xds/core";
5
+ export type TimePickerProps = TimePickerBaseProps & RootProps & {
6
+ /** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
7
+ onChange?: (value: IsoTime) => void;
8
+ };
9
+ /**
10
+ * A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen
11
+ * time on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to
12
+ * `max`, `step` minutes apart, under itself, with the chosen one in view; choosing one calls
13
+ * `onChange` with it as `HH:MM` and closes the list.
14
+ *
15
+ * The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
16
+ * typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
17
+ * `defaultValue`.
18
+ */
19
+ export declare function TimePicker(props: TimePickerProps): JSX.Element;