@xds/solid 1.1.0 → 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 (163) hide show
  1. package/dist/dom/Breadcrumb.js +87 -0
  2. package/dist/dom/Checkbox.js +12 -6
  3. package/dist/dom/Combobox.js +295 -0
  4. package/dist/dom/Link.js +62 -0
  5. package/dist/dom/Menu.js +15 -14
  6. package/dist/dom/Pagination.js +132 -0
  7. package/dist/dom/Popover.js +126 -0
  8. package/dist/dom/Select.js +75 -48
  9. package/dist/dom/Table.js +150 -0
  10. package/dist/dom/TimePicker.js +245 -0
  11. package/dist/dom/ToastQueue.js +59 -0
  12. package/dist/dom/base.js +16 -0
  13. package/dist/dom/index.js +9 -1
  14. package/dist/dom/modal-popover.js +2 -2
  15. package/dist/dom/presence.js +3 -2
  16. package/dist/dom/preview.js +19 -2
  17. package/dist/dom/rows.js +13 -0
  18. package/dist/source/Breadcrumb.d.ts +9 -0
  19. package/dist/source/Breadcrumb.jsx +26 -0
  20. package/dist/source/Checkbox.d.ts +1 -1
  21. package/dist/source/Checkbox.jsx +9 -3
  22. package/dist/source/Combobox.d.ts +16 -0
  23. package/dist/source/Combobox.jsx +137 -0
  24. package/dist/source/Link.d.ts +20 -0
  25. package/dist/source/Link.jsx +21 -0
  26. package/dist/source/Menu.jsx +8 -2
  27. package/dist/source/Pagination.d.ts +12 -0
  28. package/dist/source/Pagination.jsx +51 -0
  29. package/dist/source/Popover.d.ts +19 -0
  30. package/dist/source/Popover.jsx +65 -0
  31. package/dist/source/Select.d.ts +6 -0
  32. package/dist/source/Select.jsx +32 -8
  33. package/dist/source/Table.d.ts +17 -0
  34. package/dist/source/Table.jsx +46 -0
  35. package/dist/source/TimePicker.d.ts +19 -0
  36. package/dist/source/TimePicker.jsx +137 -0
  37. package/dist/source/ToastQueue.d.ts +19 -0
  38. package/dist/source/ToastQueue.jsx +27 -0
  39. package/dist/source/base.d.ts +15 -0
  40. package/dist/source/base.js +15 -0
  41. package/dist/source/controllable.d.ts +1 -1
  42. package/dist/source/index.d.ts +9 -1
  43. package/dist/source/index.js +8 -0
  44. package/dist/source/modal-popover.js +2 -2
  45. package/dist/source/presence.js +3 -2
  46. package/dist/source/preview.d.ts +10 -2
  47. package/dist/source/preview.jsx +12 -3
  48. package/dist/source/rows.d.ts +8 -0
  49. package/dist/source/rows.js +5 -0
  50. package/eject/files/Accordion.tsx +138 -0
  51. package/eject/files/Avatar.tsx +48 -0
  52. package/eject/files/AvatarStack.tsx +51 -0
  53. package/eject/files/Badge.tsx +39 -0
  54. package/eject/files/Banner.tsx +80 -0
  55. package/eject/files/Breadcrumb.tsx +57 -0
  56. package/eject/files/Button.tsx +90 -0
  57. package/eject/files/Card.tsx +100 -0
  58. package/eject/files/Checkbox.tsx +100 -0
  59. package/eject/files/Chip.tsx +40 -0
  60. package/eject/files/ChipBar.tsx +34 -0
  61. package/eject/files/Combobox.tsx +200 -0
  62. package/eject/files/CountBadge.tsx +55 -0
  63. package/eject/files/DatePicker.tsx +225 -0
  64. package/eject/files/DateRangePicker.tsx +319 -0
  65. package/eject/files/Dialog.tsx +117 -0
  66. package/eject/files/Divider.tsx +21 -0
  67. package/eject/files/EmptyState.tsx +39 -0
  68. package/eject/files/Icon.tsx +37 -0
  69. package/eject/files/IconButton.tsx +76 -0
  70. package/eject/files/Link.tsx +61 -0
  71. package/eject/files/ListRow.tsx +94 -0
  72. package/eject/files/MediaCard.tsx +116 -0
  73. package/eject/files/Menu.tsx +190 -0
  74. package/eject/files/Pagination.tsx +109 -0
  75. package/eject/files/Popover.tsx +124 -0
  76. package/eject/files/ProgressBar.tsx +37 -0
  77. package/eject/files/RadioGroup.tsx +138 -0
  78. package/eject/files/SearchField.tsx +124 -0
  79. package/eject/files/SectionHeader.tsx +59 -0
  80. package/eject/files/SegmentedControl.tsx +79 -0
  81. package/eject/files/Select.tsx +290 -0
  82. package/eject/files/Sidebar.tsx +156 -0
  83. package/eject/files/Skeleton.tsx +33 -0
  84. package/eject/files/Slider.tsx +131 -0
  85. package/eject/files/Spinner.tsx +44 -0
  86. package/eject/files/Switch.tsx +88 -0
  87. package/eject/files/Table.tsx +98 -0
  88. package/eject/files/Tabs.tsx +87 -0
  89. package/eject/files/Text.tsx +38 -0
  90. package/eject/files/TextField.tsx +171 -0
  91. package/eject/files/Thumbnail.tsx +84 -0
  92. package/eject/files/TimePicker.tsx +237 -0
  93. package/eject/files/Toast.tsx +100 -0
  94. package/eject/files/ToastQueue.tsx +62 -0
  95. package/eject/files/Tooltip.tsx +135 -0
  96. package/eject/files/accordion.css +89 -0
  97. package/eject/files/accordion.ts +67 -0
  98. package/eject/files/avatar-stack.ts +57 -0
  99. package/eject/files/avatar.ts +42 -0
  100. package/eject/files/badge.ts +30 -0
  101. package/eject/files/banner.ts +71 -0
  102. package/eject/files/base.css +38 -0
  103. package/eject/files/breadcrumb.css +51 -0
  104. package/eject/files/breadcrumb.ts +42 -0
  105. package/eject/files/button.css +241 -0
  106. package/eject/files/button.ts +106 -0
  107. package/eject/files/card.ts +58 -0
  108. package/eject/files/checkbox.ts +52 -0
  109. package/eject/files/chip-bar.ts +16 -0
  110. package/eject/files/chip.ts +35 -0
  111. package/eject/files/combobox.css +269 -0
  112. package/eject/files/combobox.ts +85 -0
  113. package/eject/files/count-badge.ts +32 -0
  114. package/eject/files/date-picker.css +375 -0
  115. package/eject/files/date-picker.ts +280 -0
  116. package/eject/files/date-range-picker.ts +338 -0
  117. package/eject/files/dialog.css +139 -0
  118. package/eject/files/dialog.ts +15 -0
  119. package/eject/files/divider.ts +5 -0
  120. package/eject/files/empty-state.ts +22 -0
  121. package/eject/files/icon.ts +36 -0
  122. package/eject/files/link.css +64 -0
  123. package/eject/files/link.ts +63 -0
  124. package/eject/files/list-row.ts +66 -0
  125. package/eject/files/media-card.ts +66 -0
  126. package/eject/files/menu.css +192 -0
  127. package/eject/files/menu.ts +84 -0
  128. package/eject/files/overlay.css +40 -0
  129. package/eject/files/pagination.css +106 -0
  130. package/eject/files/pagination.ts +68 -0
  131. package/eject/files/parts.ts +17 -0
  132. package/eject/files/popover.css +101 -0
  133. package/eject/files/popover.ts +37 -0
  134. package/eject/files/progress-bar.ts +26 -0
  135. package/eject/files/radio-group.css +184 -0
  136. package/eject/files/radio-group.ts +30 -0
  137. package/eject/files/section-header.ts +32 -0
  138. package/eject/files/segmented-control.ts +33 -0
  139. package/eject/files/select.css +347 -0
  140. package/eject/files/select.ts +77 -0
  141. package/eject/files/sidebar.ts +75 -0
  142. package/eject/files/skeleton.ts +51 -0
  143. package/eject/files/slider.css +160 -0
  144. package/eject/files/slider.ts +80 -0
  145. package/eject/files/spinner.ts +22 -0
  146. package/eject/files/switch.ts +45 -0
  147. package/eject/files/table.css +107 -0
  148. package/eject/files/table.ts +84 -0
  149. package/eject/files/tabs.css +120 -0
  150. package/eject/files/tabs.ts +37 -0
  151. package/eject/files/text-field.css +225 -0
  152. package/eject/files/text-field.ts +64 -0
  153. package/eject/files/text.ts +38 -0
  154. package/eject/files/thumbnail.ts +51 -0
  155. package/eject/files/time-picker.ts +113 -0
  156. package/eject/files/toast-queue.ts +64 -0
  157. package/eject/files/toast.ts +31 -0
  158. package/eject/files/tooltip.css +111 -0
  159. package/eject/files/tooltip.ts +21 -0
  160. package/eject/manifest.json +1027 -0
  161. package/package.json +12 -4
  162. package/styles.css +1064 -169
  163. package/tailwind.css +1295 -218
@@ -0,0 +1,290 @@
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
+ rootAttributes,
15
+ space,
16
+ underlayLayerStyle,
17
+ withStyle,
18
+ } from "@xds/solid/base";
19
+ import type { JSX } from "@solidjs/web";
20
+ import * as select from "@zag-js/select";
21
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
22
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
23
+ import { Icon } from "./Icon.tsx";
24
+ import { classes } from "./parts.ts";
25
+ import {
26
+ orderedValues,
27
+ type SelectBaseProps,
28
+ type SelectOption,
29
+ selectedLabels,
30
+ selectOptionIds,
31
+ } from "./select.ts";
32
+
33
+ export type { SelectOption } from "./select.ts";
34
+
35
+ export type SelectProps<Value extends string = string> = SelectBaseProps<Value> &
36
+ RootProps & {
37
+ onChange?: (value: Value) => void;
38
+ /** Called with the chosen options of a select with `multiple`, in the options' order. */
39
+ onValuesChange?: (values: Value[]) => void;
40
+ };
41
+
42
+ type KeyHandler = (event: KeyboardEvent) => void;
43
+
44
+ /**
45
+ * A field for choosing one option from a list too long to show at once. Closed, it looks like a
46
+ * TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the
47
+ * field. Choosing an option calls `onChange` and closes the list; a press outside or Escape
48
+ * closes it too.
49
+ *
50
+ * The field is a button that says it opens a list box and whether the list is open. In the list
51
+ * the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
52
+ * selected for assistive technology and marked with a check.
53
+ *
54
+ * Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
55
+ * `undefined`, it shows that.
56
+ *
57
+ * With `multiple`, any number of options can be chosen: choosing one adds it or takes it away,
58
+ * the list stays open, and `onValuesChange` gets them all. The list box says that several can
59
+ * be chosen.
60
+ */
61
+ export function Select<Value extends string = string>(props: SelectProps<Value>) {
62
+ const id = createUniqueId();
63
+ const valueId = `${id}-value`;
64
+ const descriptionId = `${id}-description`;
65
+ const errorId = `${id}-error`;
66
+ const invalid = () => props.error !== undefined;
67
+ const value = createControllable<Value | undefined>({
68
+ controlled: () => isControlled(props, "value"),
69
+ value: () => props.value,
70
+ defaultValue: () => props.defaultValue,
71
+ onChange: (next) => {
72
+ if (next !== undefined) props.onChange?.(next);
73
+ },
74
+ });
75
+ const values = createControllable<readonly Value[]>({
76
+ controlled: () => isControlled(props, "values"),
77
+ value: () => props.values ?? [],
78
+ defaultValue: () => props.defaultValues ?? [],
79
+ onChange: (next) => props.onValuesChange?.([...next]),
80
+ });
81
+ const multiple = () => props.multiple ?? false;
82
+ const collection = createMemo(() =>
83
+ select.collection<SelectOption<Value>>({
84
+ items: [...props.options],
85
+ itemToValue: (option) => option.value,
86
+ itemToString: (option) => option.label,
87
+ }),
88
+ );
89
+ const service = useMachine(select.machine, () => ({
90
+ id,
91
+ // The app's id goes on the root, where Zag looks for it by this one.
92
+ ids: { root: props.id },
93
+ collection: collection(),
94
+ value: multiple()
95
+ ? [...values.value()]
96
+ : value.value() === undefined
97
+ ? []
98
+ : [value.value() as Value],
99
+ onValueChange: (details: select.ValueChangeDetails<SelectOption<Value>>) => {
100
+ if (multiple()) {
101
+ values.set(orderedValues(props.options, details.value as Value[]));
102
+ return;
103
+ }
104
+ const next = details.value[0];
105
+ if (next !== undefined) value.set(next as Value);
106
+ },
107
+ multiple: multiple(),
108
+ // Several are chosen one after another, so the list stays until the person closes it.
109
+ closeOnSelect: !multiple(),
110
+ disabled: props.disabled,
111
+ invalid: invalid(),
112
+ name: props.name,
113
+ positioning: {
114
+ placement: "bottom-start" as const,
115
+ gutter: readCssPx(null, "--xds-space-1", space[1]),
116
+ sameWidth: true,
117
+ // The list keeps this far from the window's edges.
118
+ overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
119
+ },
120
+ }));
121
+ const api = createMemo(() => select.connect(service, normalizeProps));
122
+ const root = withStyle(
123
+ () => api().getRootProps(),
124
+ () => props.style,
125
+ rootAttributes(props),
126
+ );
127
+ // Zag's key handlers read whether a search by typing is under way when the field renders,
128
+ // and a search ends on a timer, which renders nothing: long after a search, Space would
129
+ // still search for a space instead of opening the list or choosing. A handler taken from
130
+ // the machine when the key comes reads it then.
131
+ const current = () => select.connect(service, normalizeProps);
132
+ // A span: the field is a button, which a <label> cannot point at. A press on it still
133
+ // focuses the field.
134
+ const labelProps = createMemo(() => {
135
+ const { for: _, ...rest } = api().getLabelProps() as JSX.LabelHTMLAttributes<HTMLElement>;
136
+ return rest as JSX.HTMLAttributes<HTMLSpanElement>;
137
+ });
138
+ // A button that opens a list box, rather than Zag's combobox: named by the chosen option and
139
+ // then the label, and described by the help or the error. The error is said there, so the
140
+ // button itself does not claim to be invalid or required.
141
+ const triggerProps = createMemo(() => {
142
+ const {
143
+ role: _role,
144
+ "aria-invalid": _invalid,
145
+ "aria-required": _required,
146
+ onKeyDown: _onKeyDown,
147
+ ...rest
148
+ } = api().getTriggerProps() as JSX.ButtonHTMLAttributes<HTMLButtonElement>;
149
+ return {
150
+ ...rest,
151
+ // Home and End leave a closed field to the page; Zag would choose the first or the last
152
+ // option.
153
+ onKeyDown: (event: KeyboardEvent) => {
154
+ if (!api().open && (event.key === "Home" || event.key === "End")) return;
155
+ (current().getTriggerProps().onKeyDown as KeyHandler | undefined)?.(event);
156
+ },
157
+ };
158
+ });
159
+ let positioner: HTMLDivElement | undefined;
160
+ let surface: HTMLDivElement | undefined;
161
+ modalPopover(
162
+ () => api().open,
163
+ () => positioner,
164
+ );
165
+ const present = createPresence(
166
+ () => api().open,
167
+ () => [surface],
168
+ );
169
+ const content = mergeProps(
170
+ () => {
171
+ const { onKeyDown: _onKeyDown, ...rest } = api().getContentProps();
172
+ return rest;
173
+ },
174
+ {
175
+ onKeyDown: (event: KeyboardEvent) => {
176
+ keepListKeys(event, surface, ".{{prefix}}-select__item:not([data-disabled])", (value) =>
177
+ api().setHighlightedValue(value),
178
+ );
179
+ (current().getContentProps().onKeyDown as KeyHandler | undefined)?.(event);
180
+ },
181
+ },
182
+ );
183
+ return (
184
+ <div {...root} class={classes("{{prefix}}-select", props.class)}>
185
+ <span {...labelProps()} class="{{prefix}}-select__label">
186
+ {props.label}
187
+ </span>
188
+ <button
189
+ {...triggerProps()}
190
+ aria-labelledby={`${valueId} ${labelProps().id}`}
191
+ aria-describedby={invalid() ? errorId : props.description ? descriptionId : undefined}
192
+ class="{{prefix}}-select__trigger"
193
+ >
194
+ {/* The chosen option's label alone: the list's rows also hold a description and a
195
+ check, which do not belong in the field. */}
196
+ <span {...api().getValueTextProps()} id={valueId} class="{{prefix}}-select__value">
197
+ {(multiple() ? selectedLabels(props.options, values.value()) : api().valueAsString) ||
198
+ props.placeholder}
199
+ </span>
200
+ <Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder" />
201
+ </button>
202
+ {/* One line under the box: the help, or the error in its place. The error stays mounted as
203
+ a live region so assistive technology announces it when it appears. */}
204
+ <div class="{{prefix}}-select__footer">
205
+ <Show when={!invalid() && props.description}>
206
+ <span id={descriptionId} class="{{prefix}}-select__description">
207
+ {props.description}
208
+ </span>
209
+ </Show>
210
+ <span id={errorId} class="{{prefix}}-select__error" aria-live="polite">
211
+ {props.error}
212
+ </span>
213
+ </div>
214
+ {/* What a form submits; in a select of one, the first option stands for no choice. */}
215
+ <select {...api().getHiddenSelectProps()}>
216
+ <Show when={!multiple()}>
217
+ {/* oxlint-disable-next-line jsx-a11y/control-has-associated-label -- Zag's props hide the select from assistive technology, which uses the trigger */}
218
+ <option value="" />
219
+ </Show>
220
+ <For each={props.options}>
221
+ {(option) => <option value={option.value}>{option.label}</option>}
222
+ </For>
223
+ </select>
224
+ <Portal>
225
+ <Show when={api().open}>
226
+ {/* Takes a press outside, which then only closes the list. The focus stays in the
227
+ list until the list hands it back to the field. */}
228
+ {/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
229
+ <div
230
+ class="{{prefix}}-select__underlay"
231
+ style={underlayLayerStyle(api().getPositionerProps().style)}
232
+ onMouseDown={(event) => event.preventDefault()}
233
+ />
234
+ </Show>
235
+ <div
236
+ ref={(element) => (positioner = element)}
237
+ {...api().getPositionerProps()}
238
+ class="{{prefix}}-select__positioner"
239
+ >
240
+ {/* Shown until its exit animation ends; Zag would hide it as it closes. */}
241
+ <div
242
+ {...content}
243
+ ref={(element) => (surface = element)}
244
+ hidden={!present()}
245
+ class="{{prefix}}-select__content"
246
+ >
247
+ <div {...api().getListProps()} class="{{prefix}}-select__list">
248
+ <For each={collection().items}>
249
+ {(option, index) => {
250
+ const ids = () => selectOptionIds(id, index());
251
+ const itemProps = createItemProps(() => api().getItemProps({ item: option }));
252
+ const textProps = createItemProps(() => api().getItemTextProps({ item: option }));
253
+ const selected = createMemo(() => api().getItemState({ item: option }).selected);
254
+ return (
255
+ // Named by its label alone, as the field shows it; the help line describes it.
256
+ <div
257
+ {...itemProps()}
258
+ aria-labelledby={ids().label}
259
+ aria-describedby={option.description ? ids().description : undefined}
260
+ class="{{prefix}}-select__item"
261
+ >
262
+ <span class="{{prefix}}-select__item-words">
263
+ <span
264
+ {...textProps()}
265
+ id={ids().label}
266
+ class="{{prefix}}-select__item-label"
267
+ >
268
+ {option.label}
269
+ </span>
270
+ <Show when={option.description}>
271
+ <span id={ids().description} class="{{prefix}}-select__item-description">
272
+ {option.description}
273
+ </span>
274
+ </Show>
275
+ </span>
276
+ {/* Unnamed, unlike a Menu's: the option itself reports that it is selected. */}
277
+ <Show when={selected()}>
278
+ <Icon name="check" size="sm" />
279
+ </Show>
280
+ </div>
281
+ );
282
+ }}
283
+ </For>
284
+ </div>
285
+ </div>
286
+ </div>
287
+ </Portal>
288
+ </div>
289
+ );
290
+ }
@@ -0,0 +1,156 @@
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 IconName, type RootProps, rootAttributes, withTrigger } from "@xds/solid/base";
5
+ import type { JSX } from "@solidjs/web";
6
+ import { createMemo, createUniqueId, type Element, For, Show } from "solid-js";
7
+ import { Icon } from "./Icon.tsx";
8
+ import { PlaceRow } from "./ListRow.tsx";
9
+ import { classes, rootPart } from "./parts.ts";
10
+ import {
11
+ SIDEBAR_PARTS,
12
+ type SidebarBaseProps,
13
+ sidebarClass,
14
+ sidebarCount,
15
+ sidebarIconClass,
16
+ sidebarRailButtonClass,
17
+ sidebarSectionClass,
18
+ sidebarTitleClass,
19
+ } from "./sidebar.ts";
20
+ import { TooltipBeside } from "./Tooltip.tsx";
21
+
22
+ export type { SidebarItem, SidebarSection } from "./sidebar.ts";
23
+
24
+ export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> &
25
+ RootProps & {
26
+ onChange: (value: Value) => void;
27
+ /** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
28
+ header?: Element;
29
+ /** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
30
+ footer?: Element;
31
+ };
32
+
33
+ const ROOT = rootPart("Sidebar");
34
+
35
+ /**
36
+ * The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each
37
+ * row is a compact list row; the current one is selected, its title heavier and its icon
38
+ * filled, so the place does not depend on the tint alone.
39
+ *
40
+ * It is navigation named by `label`, and the current row says it is the current page.
41
+ * Collapsed, the rows keep their names, and show them in a Tooltip under a pointer and on
42
+ * keyboard focus.
43
+ */
44
+ export function Sidebar<Value extends string = string>(props: SidebarProps<Value>) {
45
+ const id = createUniqueId();
46
+ const collapsed = () => props.collapsed ?? false;
47
+ return (
48
+ <nav
49
+ {...rootAttributes(props)}
50
+ aria-label={props.label}
51
+ class={classes(ROOT, sidebarClass(collapsed()), props.class)}
52
+ style={props.style}
53
+ >
54
+ <Show when={props.header}>
55
+ {(header) => <div class={SIDEBAR_PARTS.edge}>{header()}</div>}
56
+ </Show>
57
+ {/* The places scroll when there are more than fit; the header and footer stay. */}
58
+ <div class={SIDEBAR_PARTS.places}>
59
+ <For each={props.sections}>
60
+ {(section, index) => {
61
+ // A section has nothing but its position to tell it apart: titles are optional.
62
+ const title = () => `${id}-${index()}`;
63
+ return (
64
+ <div class={sidebarSectionClass(index(), collapsed())}>
65
+ <Show when={section.title}>
66
+ {(text) => (
67
+ <p id={title()} class={sidebarTitleClass(collapsed())}>
68
+ {text()}
69
+ </p>
70
+ )}
71
+ </Show>
72
+ <Show when={collapsed() && index() > 0}>
73
+ <div aria-hidden="true" class={SIDEBAR_PARTS.rule} />
74
+ </Show>
75
+ <ul
76
+ aria-labelledby={section.title ? title() : undefined}
77
+ class={SIDEBAR_PARTS.list}
78
+ >
79
+ <For each={section.items}>
80
+ {(item) => {
81
+ const selected = () => item.value === props.value;
82
+ return (
83
+ <li class={SIDEBAR_PARTS.item}>
84
+ <Show
85
+ when={collapsed()}
86
+ fallback={
87
+ <PlaceRow
88
+ compact
89
+ current="page"
90
+ selected={selected()}
91
+ onPress={() => props.onChange(item.value)}
92
+ title={item.label}
93
+ leading={
94
+ <Icon
95
+ name={item.icon}
96
+ size="md"
97
+ filled={selected()}
98
+ class={sidebarIconClass(selected())}
99
+ />
100
+ }
101
+ trailing={
102
+ <Show when={sidebarCount(item.count)}>
103
+ {(count) => <span class={SIDEBAR_PARTS.count}>{count()}</span>}
104
+ </Show>
105
+ }
106
+ />
107
+ }
108
+ >
109
+ <TooltipBeside label={item.label}>
110
+ <RailButton
111
+ label={item.label}
112
+ icon={item.icon}
113
+ selected={selected()}
114
+ onPress={() => props.onChange(item.value)}
115
+ />
116
+ </TooltipBeside>
117
+ </Show>
118
+ </li>
119
+ );
120
+ }}
121
+ </For>
122
+ </ul>
123
+ </div>
124
+ );
125
+ }}
126
+ </For>
127
+ </div>
128
+ <Show when={props.footer}>
129
+ {(footer) => <div class={SIDEBAR_PARTS.edge}>{footer()}</div>}
130
+ </Show>
131
+ </nav>
132
+ );
133
+ }
134
+
135
+ /** A row of the collapsed rail. It is the trigger of the Tooltip that names it. */
136
+ function RailButton(props: {
137
+ label: string;
138
+ icon: IconName;
139
+ selected: boolean;
140
+ onPress: () => void;
141
+ }) {
142
+ const attributes = withTrigger(
143
+ createMemo((): JSX.ButtonHTMLAttributes<HTMLButtonElement> => ({
144
+ type: "button",
145
+ class: sidebarRailButtonClass(props.selected),
146
+ "aria-label": props.label,
147
+ "aria-current": props.selected ? "page" : undefined,
148
+ onClick: () => props.onPress(),
149
+ })),
150
+ );
151
+ return (
152
+ <button {...attributes}>
153
+ <Icon name={props.icon} size="md" filled={props.selected} />
154
+ </button>
155
+ );
156
+ }
@@ -0,0 +1,33 @@
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 { layStyle, type RootProps, rootAttributes, useDefaults } from "@xds/solid/base";
5
+ import { classes, rootPart } from "./parts.ts";
6
+ import { type SkeletonBaseProps, skeletonClass, skeletonSize } from "./skeleton.ts";
7
+
8
+ export type SkeletonProps = SkeletonBaseProps & RootProps;
9
+
10
+ const ROOT = rootPart("Skeleton");
11
+
12
+ /**
13
+ * Holds the place of content that is loading, in the shape the content will have. It pulses,
14
+ * and stands still for people who ask for less motion.
15
+ *
16
+ * It is hidden from assistive technology: the screen that shows skeletons says that it is
17
+ * loading, once, instead of every placeholder saying so.
18
+ */
19
+ export function Skeleton(props: SkeletonProps) {
20
+ const defaults = useDefaults("Skeleton");
21
+ const shape = () => props.shape ?? defaults().shape;
22
+ return (
23
+ <span
24
+ {...rootAttributes(props)}
25
+ aria-hidden="true"
26
+ class={classes(ROOT, skeletonClass(shape()), props.class)}
27
+ style={layStyle(
28
+ skeletonSize({ shape: shape(), width: props.width, height: props.height }),
29
+ props.style,
30
+ )}
31
+ />
32
+ );
33
+ }
@@ -0,0 +1,131 @@
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
+ withStyle,
10
+ } from "@xds/solid/base";
11
+ import * as slider from "@zag-js/slider";
12
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
13
+ import { createMemo, createUniqueId, Show } from "solid-js";
14
+ import { classes } from "./parts.ts";
15
+ import {
16
+ focusThumbOnPress,
17
+ type SliderBaseProps,
18
+ sliderArrowValue,
19
+ sliderPageSize,
20
+ sliderValueText,
21
+ } from "./slider.ts";
22
+
23
+ export type SliderProps = SliderBaseProps &
24
+ RootProps & {
25
+ onChange?: (value: number) => void;
26
+ };
27
+
28
+ /**
29
+ * Picks a number in a range by dragging the thumb, or by pressing the track where it should
30
+ * go. The values snap to `step`.
31
+ *
32
+ * It is a slider named by its label with its value, minimum and maximum, and each arrow key
33
+ * moves it one step. Without `value` it keeps its own, from `defaultValue`, or `min`.
34
+ */
35
+ export function Slider(props: SliderProps) {
36
+ const id = createUniqueId();
37
+ const min = () => props.min ?? 0;
38
+ const max = () => props.max ?? 100;
39
+ const step = () => props.step ?? 1;
40
+ const pageSize = () => sliderPageSize({ min: min(), max: max(), step: step() });
41
+ const value = createControllable({
42
+ controlled: () => isControlled(props, "value"),
43
+ value: () => props.value ?? min(),
44
+ defaultValue: () => props.defaultValue ?? min(),
45
+ onChange: (next) => props.onChange?.(next),
46
+ });
47
+ const service = useMachine(slider.machine, () => ({
48
+ id,
49
+ // The app's id goes on the root, where Zag looks for it by this one.
50
+ ids: { root: props.id },
51
+ name: props.name,
52
+ value: [value.value()],
53
+ // One thumb, so one number.
54
+ onValueChange: (details: slider.ValueChangeDetails) => value.set(details.value[0] ?? min()),
55
+ min: min(),
56
+ max: max(),
57
+ step: step(),
58
+ largeStep: pageSize(),
59
+ disabled: props.disabled,
60
+ // The thumb's center is on the value, at the ends too; the band is inset to make room.
61
+ thumbAlignment: "center" as const,
62
+ getAriaValueText: (details: { value: number }) => sliderValueText(details.value, props.locale),
63
+ }));
64
+ const api = createMemo(() => slider.connect(service, normalizeProps));
65
+ const root = withStyle(
66
+ () => api().getRootProps(),
67
+ () => props.style,
68
+ rootAttributes(props),
69
+ );
70
+ const thumb = mergeProps(() => api().getThumbProps({ index: 0 }), {
71
+ // Zag gives `draggable: false`, and Solid removes an attribute whose value is false.
72
+ // `draggable` is not a boolean attribute: without it the thumb is "auto", so "false" has
73
+ // to be written out, as the other web libraries write it.
74
+ draggable: "false" as const,
75
+ // Up and Down move a horizontal slider too, as they move a native range input.
76
+ onKeyDown: (event: KeyboardEvent) => {
77
+ if (props.disabled) return;
78
+ const next = sliderArrowValue(event, {
79
+ value: api().value[0] ?? min(),
80
+ min: min(),
81
+ max: max(),
82
+ step: step(),
83
+ pageSize: pageSize(),
84
+ });
85
+ if (next !== undefined) {
86
+ event.preventDefault();
87
+ api().setThumbValue(0, next);
88
+ }
89
+ },
90
+ });
91
+ let thumbElement: HTMLDivElement | undefined;
92
+ const control = mergeProps(() => api().getControlProps(), {
93
+ // No focus ring after a press. This handler runs before Zag's.
94
+ onPointerDown: (event: PointerEvent) => {
95
+ if (!props.disabled) focusThumbOnPress(event, thumbElement);
96
+ },
97
+ });
98
+ return (
99
+ // A group named by the label, around the label, the value and the slider. Not a fieldset:
100
+ // that is for a set of fields, and this is one slider and its label.
101
+ <div
102
+ {...root}
103
+ role="group"
104
+ aria-labelledby={api().getLabelProps().id}
105
+ class={classes("{{prefix}}-slider", props.class)}
106
+ >
107
+ {/* Zag's props give it `for`, the hidden input's id. */}
108
+ <label {...api().getLabelProps()} class="{{prefix}}-slider__label">
109
+ {props.label}
110
+ </label>
111
+ <Show when={props.showValue}>
112
+ {/* Read when asked for, not at every step: the slider itself announces its value. */}
113
+ <output {...api().getValueTextProps()} aria-live="off" class="{{prefix}}-slider__output">
114
+ {sliderValueText(api().value[0] ?? value.value(), props.locale)}
115
+ </output>
116
+ </Show>
117
+ <div {...control} class="{{prefix}}-slider__control">
118
+ <div {...api().getTrackProps()} class="{{prefix}}-slider__track">
119
+ <div {...api().getRangeProps()} class="{{prefix}}-slider__range" />
120
+ </div>
121
+ <div
122
+ {...thumb}
123
+ ref={(element) => (thumbElement = element)}
124
+ class="{{prefix}}-slider__thumb"
125
+ >
126
+ <input {...api().getHiddenInputProps({ index: 0 })} />
127
+ </div>
128
+ </div>
129
+ </div>
130
+ );
131
+ }
@@ -0,0 +1,44 @@
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 { classes, rootPart } from "./parts.ts";
6
+ import { type SpinnerBaseProps, spinnerClass } from "./spinner.ts";
7
+
8
+ export type SpinnerProps = SpinnerBaseProps & RootProps;
9
+
10
+ const ROOT = rootPart("Spinner");
11
+
12
+ /**
13
+ * Says that something is in progress and how long is unknown. Takes the color of the text around
14
+ * it. With `label` it is announced; without one it is decoration next to text that already says
15
+ * what is happening.
16
+ */
17
+ export function Spinner(props: SpinnerProps) {
18
+ const defaults = useDefaults("Spinner");
19
+ return (
20
+ <span
21
+ {...rootAttributes(props)}
22
+ class={classes(ROOT, "inline-flex shrink-0", props.class)}
23
+ style={props.style}
24
+ role={props.label ? "status" : undefined}
25
+ aria-label={props.label || undefined}
26
+ aria-hidden={props.label ? undefined : "true"}
27
+ >
28
+ <svg
29
+ viewBox="0 0 24 24"
30
+ fill="none"
31
+ aria-hidden="true"
32
+ class={spinnerClass(props.size ?? defaults().size)}
33
+ >
34
+ <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25" />
35
+ <path
36
+ d="M21 12a9 9 0 0 0-9-9"
37
+ stroke="currentColor"
38
+ stroke-width="3"
39
+ stroke-linecap="round"
40
+ />
41
+ </svg>
42
+ </span>
43
+ );
44
+ }