@xds/solid 0.0.0-stage → 0.1.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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/dom/Accordion.js +139 -0
  4. package/dist/dom/Avatar.js +59 -0
  5. package/dist/dom/AvatarStack.js +74 -0
  6. package/dist/dom/Badge.js +58 -0
  7. package/dist/dom/Banner.js +102 -0
  8. package/dist/dom/Button.js +107 -0
  9. package/dist/dom/Card.js +164 -0
  10. package/dist/dom/Checkbox.js +64 -0
  11. package/dist/dom/Chip.js +52 -0
  12. package/dist/dom/ChipBar.js +28 -0
  13. package/dist/dom/CountBadge.js +67 -0
  14. package/dist/dom/DatePicker.js +300 -0
  15. package/dist/dom/DateRangePicker.js +404 -0
  16. package/dist/dom/Defaults.js +29 -0
  17. package/dist/dom/Dialog.js +136 -0
  18. package/dist/dom/Divider.js +20 -0
  19. package/dist/dom/EmptyState.js +70 -0
  20. package/dist/dom/Icon.js +46 -0
  21. package/dist/dom/IconButton.js +72 -0
  22. package/dist/dom/ListRow.js +126 -0
  23. package/dist/dom/MediaCard.js +178 -0
  24. package/dist/dom/Menu.js +176 -0
  25. package/dist/dom/ProgressBar.js +33 -0
  26. package/dist/dom/RadioGroup.js +123 -0
  27. package/dist/dom/SearchField.js +94 -0
  28. package/dist/dom/SectionHeader.js +104 -0
  29. package/dist/dom/SegmentedControl.js +69 -0
  30. package/dist/dom/Select.js +271 -0
  31. package/dist/dom/Sidebar.js +233 -0
  32. package/dist/dom/Skeleton.js +34 -0
  33. package/dist/dom/Slider.js +115 -0
  34. package/dist/dom/Spinner.js +35 -0
  35. package/dist/dom/Switch.js +65 -0
  36. package/dist/dom/Tabs.js +80 -0
  37. package/dist/dom/Text.js +24 -0
  38. package/dist/dom/TextField.js +172 -0
  39. package/dist/dom/Thumbnail.js +119 -0
  40. package/dist/dom/Toast.js +99 -0
  41. package/dist/dom/Tooltip.js +128 -0
  42. package/dist/dom/controlled.js +13 -0
  43. package/dist/dom/index.js +40 -0
  44. package/dist/dom/modal-popover.js +22 -0
  45. package/dist/dom/picture.js +29 -0
  46. package/dist/dom/presence.js +20 -0
  47. package/dist/dom/preview.js +139 -0
  48. package/dist/dom/root.js +26 -0
  49. package/dist/dom/trigger.js +31 -0
  50. package/dist/source/Accordion.d.ts +21 -0
  51. package/dist/source/Accordion.jsx +57 -0
  52. package/dist/source/Avatar.d.ts +9 -0
  53. package/dist/source/Avatar.jsx +16 -0
  54. package/dist/source/AvatarStack.d.ts +8 -0
  55. package/dist/source/AvatarStack.jsx +22 -0
  56. package/dist/source/Badge.d.ts +13 -0
  57. package/dist/source/Badge.jsx +15 -0
  58. package/dist/source/Banner.d.ts +23 -0
  59. package/dist/source/Banner.jsx +32 -0
  60. package/dist/source/Button.d.ts +15 -0
  61. package/dist/source/Button.jsx +48 -0
  62. package/dist/source/Card.d.ts +18 -0
  63. package/dist/source/Card.jsx +46 -0
  64. package/dist/source/Checkbox.d.ts +10 -0
  65. package/dist/source/Checkbox.jsx +20 -0
  66. package/dist/source/Chip.d.ts +12 -0
  67. package/dist/source/Chip.jsx +12 -0
  68. package/dist/source/ChipBar.d.ts +12 -0
  69. package/dist/source/ChipBar.jsx +7 -0
  70. package/dist/source/CountBadge.d.ts +12 -0
  71. package/dist/source/CountBadge.jsx +17 -0
  72. package/dist/source/DatePicker.d.ts +20 -0
  73. package/dist/source/DatePicker.jsx +109 -0
  74. package/dist/source/DateRangePicker.d.ts +24 -0
  75. package/dist/source/DateRangePicker.jsx +150 -0
  76. package/dist/source/Defaults.d.ts +23 -0
  77. package/dist/source/Defaults.jsx +12 -0
  78. package/dist/source/Dialog.d.ts +21 -0
  79. package/dist/source/Dialog.jsx +58 -0
  80. package/dist/source/Divider.d.ts +4 -0
  81. package/dist/source/Divider.jsx +5 -0
  82. package/dist/source/EmptyState.d.ts +12 -0
  83. package/dist/source/EmptyState.jsx +16 -0
  84. package/dist/source/Icon.d.ts +8 -0
  85. package/dist/source/Icon.jsx +11 -0
  86. package/dist/source/IconButton.d.ts +13 -0
  87. package/dist/source/IconButton.jsx +36 -0
  88. package/dist/source/ListRow.d.ts +21 -0
  89. package/dist/source/ListRow.jsx +38 -0
  90. package/dist/source/MediaCard.d.ts +20 -0
  91. package/dist/source/MediaCard.jsx +47 -0
  92. package/dist/source/Menu.d.ts +19 -0
  93. package/dist/source/Menu.jsx +99 -0
  94. package/dist/source/ProgressBar.d.ts +8 -0
  95. package/dist/source/ProgressBar.jsx +8 -0
  96. package/dist/source/RadioGroup.d.ts +15 -0
  97. package/dist/source/RadioGroup.jsx +57 -0
  98. package/dist/source/SearchField.d.ts +15 -0
  99. package/dist/source/SearchField.jsx +39 -0
  100. package/dist/source/SectionHeader.d.ts +14 -0
  101. package/dist/source/SectionHeader.jsx +32 -0
  102. package/dist/source/SegmentedControl.d.ts +12 -0
  103. package/dist/source/SegmentedControl.jsx +21 -0
  104. package/dist/source/Select.d.ts +18 -0
  105. package/dist/source/Select.jsx +139 -0
  106. package/dist/source/Sidebar.d.ts +22 -0
  107. package/dist/source/Sidebar.jsx +65 -0
  108. package/dist/source/Skeleton.d.ts +11 -0
  109. package/dist/source/Skeleton.jsx +9 -0
  110. package/dist/source/Slider.d.ts +13 -0
  111. package/dist/source/Slider.jsx +69 -0
  112. package/dist/source/Spinner.d.ts +9 -0
  113. package/dist/source/Spinner.jsx +12 -0
  114. package/dist/source/Switch.d.ts +13 -0
  115. package/dist/source/Switch.jsx +18 -0
  116. package/dist/source/Tabs.d.ts +14 -0
  117. package/dist/source/Tabs.jsx +31 -0
  118. package/dist/source/Text.d.ts +10 -0
  119. package/dist/source/Text.jsx +14 -0
  120. package/dist/source/TextField.d.ts +22 -0
  121. package/dist/source/TextField.jsx +73 -0
  122. package/dist/source/Thumbnail.d.ts +9 -0
  123. package/dist/source/Thumbnail.jsx +34 -0
  124. package/dist/source/Toast.d.ts +16 -0
  125. package/dist/source/Toast.jsx +42 -0
  126. package/dist/source/Tooltip.d.ts +28 -0
  127. package/dist/source/Tooltip.jsx +52 -0
  128. package/dist/source/controlled.d.ts +4 -0
  129. package/dist/source/controlled.js +11 -0
  130. package/dist/source/index.d.ts +40 -0
  131. package/dist/source/index.js +39 -0
  132. package/dist/source/modal-popover.d.ts +7 -0
  133. package/dist/source/modal-popover.js +15 -0
  134. package/dist/source/picture.d.ts +20 -0
  135. package/dist/source/picture.js +13 -0
  136. package/dist/source/presence.d.ts +7 -0
  137. package/dist/source/presence.js +13 -0
  138. package/dist/source/preview.d.ts +6 -0
  139. package/dist/source/preview.jsx +110 -0
  140. package/dist/source/root.d.ts +25 -0
  141. package/dist/source/root.js +19 -0
  142. package/dist/source/trigger.d.ts +18 -0
  143. package/dist/source/trigger.js +18 -0
  144. package/package.json +63 -4
  145. package/page.css +20 -0
  146. package/styles.css +3353 -0
  147. package/tailwind.css +2665 -0
@@ -0,0 +1,20 @@
1
+ import { type MediaCardBaseProps } from "@xds/core";
2
+ import { type Element } from "solid-js";
3
+ import type { RootProps } from "./root.ts";
4
+ export type MediaCardProps = MediaCardBaseProps & RootProps & {
5
+ /** Before the text in the vertical layout, such as an Avatar. */
6
+ leading?: Element;
7
+ /** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
8
+ action?: Element;
9
+ /** Makes the whole card one button. */
10
+ onPress?: () => void;
11
+ };
12
+ /**
13
+ * A thumbnail with its title and details: a video in a feed, an article in a list.
14
+ *
15
+ * With `onPress` the whole card is one button with no surface at rest: under a pointer and
16
+ * while pressed it takes the card's fills, and it has a focus ring. The button is named by the
17
+ * title followed by the details. `action` is a separate control beside it, so pressing it does
18
+ * not press the card.
19
+ */
20
+ export declare function MediaCard(props: MediaCardProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import { classes, MEDIA_CARD_PARTS, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, rootPart, } from "@xds/core";
2
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
3
+ import { useDefaults } from "./Defaults.jsx";
4
+ import { Thumbnail } from "./Thumbnail.jsx";
5
+ const ROOT = rootPart("MediaCard");
6
+ export function MediaCard(props) {
7
+ const id = createUniqueId();
8
+ const ids = createMemo(() => mediaCardIds(id, props.meta));
9
+ const defaults = useDefaults("MediaCard");
10
+ const horizontal = () => (props.layout ?? defaults().layout) === "horizontal";
11
+ const pressable = () => props.onPress !== undefined;
12
+ const hidden = () => (pressable() ? "true" : undefined);
13
+ const content = () => (<div class={mediaCardContentClass({ horizontal: horizontal(), pressable: pressable() })}>
14
+ <span aria-hidden={hidden()} class={mediaCardThumbnailClass(horizontal())}>
15
+ <Thumbnail src={props.src} alt={props.alt ?? ""} ratio={props.ratio ?? "16:9"} badge={props.badge} progress={props.progress}/>
16
+ </span>
17
+ <div class={MEDIA_CARD_PARTS.body}>
18
+ <Show when={!horizontal() && props.leading}>
19
+ {(leading) => (<span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.leading}>
20
+ {leading()}
21
+ </span>)}
22
+ </Show>
23
+ <span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.text}>
24
+ <span id={ids().title} class={MEDIA_CARD_PARTS.title}>
25
+ {props.title}
26
+ </span>
27
+
28
+ <For each={props.meta ?? []} keyed={false}>
29
+ {(line, index) => (<span id={ids().details[index]} class={MEDIA_CARD_PARTS.meta}>
30
+ {line()}
31
+ </span>)}
32
+ </For>
33
+ </span>
34
+ <Show when={props.action}>
35
+ {(action) => <div class={MEDIA_CARD_PARTS.action}>{action()}</div>}
36
+ </Show>
37
+ </div>
38
+ </div>);
39
+ return (<Show when={pressable()} fallback={<div role="group" aria-labelledby={ids().names} class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)} style={props.style}>
40
+ {content()}
41
+ </div>}>
42
+ <div class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)} style={props.style}>
43
+ <button type="button" onClick={() => props.onPress?.()} aria-labelledby={ids().names} class={MEDIA_CARD_PARTS.button}/>
44
+ {content()}
45
+ </div>
46
+ </Show>);
47
+ }
@@ -0,0 +1,19 @@
1
+ import { type MenuBaseProps } from "@xds/core";
2
+ import { type Element } from "solid-js";
3
+ import type { RootProps } from "./root.ts";
4
+ export type { MenuItem } from "@xds/core";
5
+ export type MenuProps = MenuBaseProps & RootProps & {
6
+ /** The control that opens the menu: a Button or an IconButton. */
7
+ trigger: Element;
8
+ };
9
+ /**
10
+ * A list of actions that opens from a control. Choosing an item calls its `onSelect` and
11
+ * closes the menu; a press outside or Escape closes it too, and focus goes back to the
12
+ * trigger.
13
+ *
14
+ * The trigger reports that it opens a menu and whether the menu is open. The arrow keys move
15
+ * the highlight and Enter chooses.
16
+ *
17
+ * Its `class` and `style` are the menu's surface's, which is in the page only while it is open.
18
+ */
19
+ export declare function Menu(props: MenuProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,99 @@
1
+ import { space } from "@xds/tokens";
2
+ import { classes, firstMenuValue, keepListKeys, layoutRect, leaveEscapeToFields, menuItemClass, opensOnPress, } from "@xds/core";
3
+ import { Portal } from "@solidjs/web";
4
+ import * as menu from "@zag-js/menu";
5
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
6
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
7
+ import { Icon } from "./Icon.jsx";
8
+ import { modalPopover } from "./modal-popover.js";
9
+ import { createPresence } from "./presence.js";
10
+ import { provideTrigger, TriggerContext } from "./trigger.js";
11
+ export function Menu(props) {
12
+ const id = createUniqueId();
13
+ const service = useMachine(menu.machine, () => ({
14
+ id,
15
+ "aria-label": props.label,
16
+ positioning: {
17
+ placement: `bottom-${props.align ?? "start"}`,
18
+ gutter: space[1],
19
+ getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
20
+ },
21
+ onSelect: (details) => {
22
+ const item = props.items[Number(details.value)];
23
+ if (item && item !== "separator")
24
+ item.onSelect();
25
+ },
26
+ onEscapeKeyDown: leaveEscapeToFields,
27
+ loopFocus: true,
28
+ }));
29
+ const api = createMemo(() => menu.connect(service, normalizeProps));
30
+ let pressOpened = false;
31
+ const trigger = provideTrigger(() => {
32
+ const { onPointerDown: _onPointerDown, ...rest } = api().getTriggerProps();
33
+ return mergeProps(rest, {
34
+ class: "xds-menu__trigger",
35
+ onPointerDown: (event) => {
36
+ pressOpened = opensOnPress(event) && !api().open;
37
+ if (pressOpened)
38
+ api().setOpen(true);
39
+ },
40
+ onClick: (event) => {
41
+ const pointer = event.detail !== 0;
42
+ if (pressOpened && pointer) {
43
+ pressOpened = false;
44
+ event.preventDefault();
45
+ return;
46
+ }
47
+ if (pointer)
48
+ return;
49
+ requestAnimationFrame(() => {
50
+ if (!api().open)
51
+ return;
52
+ const first = firstMenuValue(props.items);
53
+ if (first !== undefined)
54
+ api().setHighlightedValue(first);
55
+ });
56
+ },
57
+ });
58
+ });
59
+ let positioner;
60
+ let surface;
61
+ modalPopover(() => api().open, () => positioner);
62
+ const present = createPresence(() => api().open, () => [surface]);
63
+ const content = mergeProps(() => api().getContentProps(), {
64
+ onKeyDown: (event) => keepListKeys(event, surface, ".xds-menu__item:not([data-disabled])", (value) => api().setHighlightedValue(value)),
65
+ get style() {
66
+ return props.style;
67
+ },
68
+ });
69
+ return (<>
70
+ <TriggerContext value={trigger}>{props.trigger}</TriggerContext>
71
+ <Portal>
72
+
73
+ <TriggerContext value={null}>
74
+ <Show when={api().open}>
75
+
76
+
77
+ <div class="xds-menu__underlay" onMouseDown={(event) => event.preventDefault()}/>
78
+ </Show>
79
+ <div ref={(element) => (positioner = element)} {...api().getPositionerProps()} class="xds-menu__positioner">
80
+
81
+ <div {...content} ref={(element) => (surface = element)} hidden={!present()} class={classes("xds-menu", props.class)}>
82
+ <For each={props.items}>
83
+ {(item, index) => item === "separator" ? (<div {...api().getSeparatorProps()} class="xds-menu__separator"/>) : (<div {...api().getItemProps({ value: String(index()), disabled: item.disabled })} class={menuItemClass(item.danger)}>
84
+ <Show when={item.icon}>
85
+ {(name) => <Icon name={name()} size="sm" class="xds-menu__item-icon"/>}
86
+ </Show>
87
+ <span class="flex-1">{item.label}</span>
88
+
89
+ <Show when={item.selected}>
90
+ <Icon name="check" size="sm" label="Selected"/>
91
+ </Show>
92
+ </div>)}
93
+ </For>
94
+ </div>
95
+ </div>
96
+ </TriggerContext>
97
+ </Portal>
98
+ </>);
99
+ }
@@ -0,0 +1,8 @@
1
+ import { type ProgressBarBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type ProgressBarProps = ProgressBarBaseProps & RootProps;
4
+ /**
5
+ * How far along something is, from 0 to 1. For work of unknown length use a Spinner.
6
+ * `label` says what is progressing; a screen reader reads it with the percentage.
7
+ */
8
+ export declare function ProgressBar(props: ProgressBarProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { classes, progressBarClass, progressBarFillClass, progressPercent, rootPart, } from "@xds/core";
2
+ const ROOT = rootPart("ProgressBar");
3
+ export function ProgressBar(props) {
4
+ const percent = () => progressPercent(props.value);
5
+ return (<div role="progressbar" aria-label={props.label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent()} class={classes(ROOT, progressBarClass, props.class)} style={props.style}>
6
+ <div class={progressBarFillClass} style={{ width: `${percent()}%` }}/>
7
+ </div>);
8
+ }
@@ -0,0 +1,15 @@
1
+ import { type RadioGroupBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type { RadioOption } from "@xds/core";
4
+ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> & RootProps & {
5
+ onChange: (value: Value) => void;
6
+ };
7
+ /**
8
+ * One choice among a few, applied later with the form it belongs to. For a choice that takes
9
+ * effect at once among two to four options, a SegmentedControl is the usual pick.
10
+ *
11
+ * The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
12
+ * options are native radio buttons, hidden and drawn beside, in a group named by the legend:
13
+ * the arrow keys move between them, and the error is tied to the group and announced.
14
+ */
15
+ export declare function RadioGroup<Value extends string = string>(props: RadioGroupProps<Value>): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,57 @@
1
+ import { classes } from "@xds/core";
2
+ import { createUniqueId, For, Show } from "solid-js";
3
+ import { keepChecked } from "./controlled.js";
4
+ export function RadioGroup(props) {
5
+ const id = createUniqueId();
6
+ const labelId = `${id}-label`;
7
+ const errorId = `${id}-error`;
8
+ const invalid = () => props.error !== undefined;
9
+ let group;
10
+ return (<div ref={(element) => (group = element)} role="radiogroup" aria-labelledby={labelId} aria-describedby={invalid() ? errorId : undefined} aria-invalid={invalid() ? "true" : undefined} aria-disabled={props.disabled ? "true" : undefined} aria-orientation="vertical" class={classes("xds-radio-group", props.class)} style={props.style}>
11
+ <span id={labelId} class="xds-radio-group__label">
12
+ {props.label}
13
+ </span>
14
+ <div class="xds-radio-group__options">
15
+ <For each={props.options}>
16
+ {(option, index) => (<label class="xds-radio-group__option">
17
+ <input type="radio" class="xds-radio-group__input sr-only" name={props.name ?? id} value={option.value} checked={option.value === props.value} defaultChecked={option.value === props.value} disabled={props.disabled} aria-labelledby={`${id}-${index()}`} aria-describedby={[
18
+ option.description ? `${id}-${index()}-description` : undefined,
19
+ invalid() ? errorId : undefined,
20
+ ]
21
+ .filter(Boolean)
22
+ .join(" ") || undefined} aria-invalid={invalid() ? "true" : undefined} onChange={() => {
23
+ props.onChange(option.value);
24
+ for (const input of group.querySelectorAll("input")) {
25
+ keepChecked(input, () => input.value === props.value);
26
+ }
27
+ }}/>
28
+ <span class="xds-radio-group__row">
29
+ <span class="xds-radio-group__circle-line">
30
+ <span class="xds-radio-group__circle">
31
+ <span class="xds-radio-group__dot"/>
32
+ </span>
33
+ </span>
34
+ <span class="xds-radio-group__words">
35
+ <span id={`${id}-${index()}`} class="xds-radio-group__text">
36
+ {option.label}
37
+ </span>
38
+ <Show when={option.description}>
39
+ <span id={`${id}-${index()}-description`} class="xds-radio-group__description">
40
+ {option.description}
41
+ </span>
42
+ </Show>
43
+ </span>
44
+ </span>
45
+ </label>)}
46
+ </For>
47
+ </div>
48
+
49
+ <div aria-live="polite">
50
+ <Show when={invalid()}>
51
+ <span id={errorId} class="xds-radio-group__error">
52
+ {props.error}
53
+ </span>
54
+ </Show>
55
+ </div>
56
+ </div>);
57
+ }
@@ -0,0 +1,15 @@
1
+ import { type SearchFieldBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
4
+ onChange: (value: string) => void;
5
+ /** Called with the query on Enter, or on the search key of a software keyboard. */
6
+ onSubmit?: (value: string) => void;
7
+ };
8
+ /**
9
+ * A text field for a query: TextField's box as a pill, with a search icon in front and, while
10
+ * there is a value, a control that clears it. Escape clears too.
11
+ *
12
+ * Use it to filter or search what is on the screen. For a value that is saved with a form,
13
+ * use a TextField, which has a visible label.
14
+ */
15
+ export declare function SearchField(props: SearchFieldProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { classes, rootPart } from "@xds/core";
2
+ import { Show } from "solid-js";
3
+ import { keepValue } from "./controlled.js";
4
+ import { Icon } from "./Icon.jsx";
5
+ const ROOT = rootPart("SearchField");
6
+ export function SearchField(props) {
7
+ let input;
8
+ return (<div class={classes("xds-text-field", ROOT, props.class)} style={props.style}>
9
+ <div class="xds-text-field__control xds-text-field__control--pill xds-text-field__group">
10
+ <span class="xds-text-field__slot xds-text-field__slot--leading">
11
+ <Icon name="search" size="sm"/>
12
+ </span>
13
+ <input ref={(element) => (input = element)} type="text" class="xds-text-field__input" aria-label={props.label} enterkeyhint="search" placeholder={props.placeholder} value={props.value} defaultValue={props.value} disabled={props.disabled} data-uses-escape={props.value !== "" ? "" : undefined} onInput={(event) => {
14
+ props.onChange(event.currentTarget.value);
15
+ if (!event.isComposing)
16
+ keepValue(event.currentTarget, () => props.value);
17
+ }} onCompositionEnd={(event) => keepValue(event.currentTarget, () => props.value)} onKeyDown={(event) => {
18
+ if (event.isComposing)
19
+ return;
20
+ if (event.key === "Enter")
21
+ props.onSubmit?.(props.value);
22
+ if (event.key === "Escape" && props.value !== "") {
23
+ event.stopPropagation();
24
+ props.onChange("");
25
+ }
26
+ }}/>
27
+ <Show when={props.value !== "" && !props.disabled}>
28
+ <span class="xds-text-field__slot xds-text-field__slot--trailing">
29
+ <button type="button" aria-label={props.clearLabel ?? "Clear"} onClick={() => {
30
+ props.onChange("");
31
+ input.focus();
32
+ }} class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid">
33
+ <Icon name="circle-x" size="sm"/>
34
+ </button>
35
+ </span>
36
+ </Show>
37
+ </div>
38
+ </div>);
39
+ }
@@ -0,0 +1,14 @@
1
+ import { type SectionHeaderBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type SectionHeaderProps = SectionHeaderBaseProps & RootProps & {
4
+ /** A link-like action at the end, such as "See all". */
5
+ action?: {
6
+ label: string;
7
+ onPress: () => void;
8
+ };
9
+ };
10
+ /**
11
+ * The title row of a group of content. The title is a heading at `level`; the action is a quiet
12
+ * button with a chevron at its end edge, which points the other way in a right-to-left layout.
13
+ */
14
+ export declare function SectionHeader(props: SectionHeaderProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import { classes, rootPart, SECTION_HEADER_PARTS, } from "@xds/core";
2
+ import { dynamic } from "@solidjs/web";
3
+ import { Show } from "solid-js";
4
+ import { Button } from "./Button.jsx";
5
+ import { Icon } from "./Icon.jsx";
6
+ const ROOT = rootPart("SectionHeader");
7
+ export function SectionHeader(props) {
8
+ const Heading = dynamic(() => `h${props.level ?? 2}`);
9
+ return (<div class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)} style={props.style}>
10
+ <div class={SECTION_HEADER_PARTS.lead}>
11
+ <Show when={props.icon}>
12
+ {(icon) => (<span class={SECTION_HEADER_PARTS.icon}>
13
+ <Icon name={icon()} size="md"/>
14
+ </span>)}
15
+ </Show>
16
+ <div class={SECTION_HEADER_PARTS.text}>
17
+ <Heading class={SECTION_HEADER_PARTS.title}>{props.title}</Heading>
18
+ <Show when={props.description}>
19
+ {(description) => <p class={SECTION_HEADER_PARTS.description}>{description()}</p>}
20
+ </Show>
21
+ </div>
22
+ </div>
23
+ <Show when={props.action}>
24
+ {(action) => (<span class={SECTION_HEADER_PARTS.action}>
25
+ <Button variant="ghost" size="sm" onPress={() => action().onPress()}>
26
+ {action().label}
27
+ <Icon name="chevron-right" size="sm" class={SECTION_HEADER_PARTS.chevron}/>
28
+ </Button>
29
+ </span>)}
30
+ </Show>
31
+ </div>);
32
+ }
@@ -0,0 +1,12 @@
1
+ import { type SegmentedControlBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> & RootProps & {
4
+ onChange: (value: Value) => void;
5
+ };
6
+ /**
7
+ * A choice between a few views or modes, all visible at once. The selected segment is outlined
8
+ * as well as filled, so the choice does not depend on telling two greys apart.
9
+ *
10
+ * It is a group of native radio buttons, so the arrow keys move between segments.
11
+ */
12
+ export declare function SegmentedControl<Value extends string>(props: SegmentedControlProps<Value>): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,21 @@
1
+ import { classes, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
2
+ import { createUniqueId, For } from "solid-js";
3
+ import { keepChecked } from "./controlled.js";
4
+ const ROOT = rootPart("SegmentedControl");
5
+ export function SegmentedControl(props) {
6
+ const name = createUniqueId();
7
+ let group;
8
+ return (<div ref={(element) => (group = element)} aria-label={props["aria-label"]} role="radiogroup" class={classes(ROOT, segmentedControlClass(props.fullWidth), props.class)} style={props.style}>
9
+ <For each={props.options}>
10
+ {(option) => (<label class={segmentedControlOptionClass(props.fullWidth)}>
11
+ <input type="radio" name={name} value={option.value} class="peer sr-only" checked={option.value === props.value} defaultChecked={option.value === props.value} onChange={() => {
12
+ props.onChange(option.value);
13
+ for (const input of group.querySelectorAll("input")) {
14
+ keepChecked(input, () => input.value === props.value);
15
+ }
16
+ }}/>
17
+ <span class={segmentedControlSegmentClass}>{option.label}</span>
18
+ </label>)}
19
+ </For>
20
+ </div>);
21
+ }
@@ -0,0 +1,18 @@
1
+ import { type SelectBaseProps } from "@xds/core";
2
+ import { type JSX } from "@solidjs/web";
3
+ import { type RootProps } from "./root.ts";
4
+ export type { SelectOption } from "@xds/core";
5
+ export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
6
+ onChange: (value: Value) => void;
7
+ };
8
+ /**
9
+ * A field for choosing one option from a list too long to show at once. Closed, it looks like a
10
+ * TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the
11
+ * field. Choosing an option calls `onChange` and closes the list; a press outside or Escape
12
+ * closes it too.
13
+ *
14
+ * The field is a button that says it opens a list box and whether the list is open. In the list
15
+ * the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
16
+ * selected for assistive technology and marked with a check.
17
+ */
18
+ export declare function Select<Value extends string = string>(props: SelectProps<Value>): JSX.Element;
@@ -0,0 +1,139 @@
1
+ import { space } from "@xds/tokens";
2
+ import { classes, keepListKeys, selectOptionIds, } from "@xds/core";
3
+ import { Portal } from "@solidjs/web";
4
+ import * as select from "@zag-js/select";
5
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
6
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
7
+ import { Icon } from "./Icon.jsx";
8
+ import { modalPopover } from "./modal-popover.js";
9
+ import { createPresence } from "./presence.js";
10
+ import { withStyle } from "./root.js";
11
+ export function Select(props) {
12
+ const id = createUniqueId();
13
+ const valueId = `${id}-value`;
14
+ const descriptionId = `${id}-description`;
15
+ const errorId = `${id}-error`;
16
+ const invalid = () => props.error !== undefined;
17
+ const collection = createMemo(() => select.collection({
18
+ items: [...props.options],
19
+ itemToValue: (option) => option.value,
20
+ itemToString: (option) => option.label,
21
+ }));
22
+ const service = useMachine(select.machine, () => ({
23
+ id,
24
+ collection: collection(),
25
+ value: props.value === undefined ? [] : [props.value],
26
+ onValueChange: (details) => {
27
+ const next = details.value[0];
28
+ if (next !== undefined)
29
+ props.onChange(next);
30
+ },
31
+ disabled: props.disabled,
32
+ invalid: invalid(),
33
+ name: props.name,
34
+ positioning: {
35
+ placement: "bottom-start",
36
+ gutter: space[1],
37
+ sameWidth: true,
38
+ overflowPadding: space[3],
39
+ },
40
+ }));
41
+ const api = createMemo(() => select.connect(service, normalizeProps));
42
+ const root = withStyle(() => api().getRootProps(), () => props.style);
43
+ const current = () => select.connect(service, normalizeProps);
44
+ const labelProps = createMemo(() => {
45
+ const { for: _, ...rest } = api().getLabelProps();
46
+ return rest;
47
+ });
48
+ const triggerProps = createMemo(() => {
49
+ const { role: _role, "aria-invalid": _invalid, "aria-required": _required, onKeyDown: _onKeyDown, ...rest } = api().getTriggerProps();
50
+ return {
51
+ ...rest,
52
+ onKeyDown: (event) => {
53
+ if (!api().open && (event.key === "Home" || event.key === "End"))
54
+ return;
55
+ current().getTriggerProps().onKeyDown?.(event);
56
+ },
57
+ };
58
+ });
59
+ let positioner;
60
+ let surface;
61
+ modalPopover(() => api().open, () => positioner);
62
+ const present = createPresence(() => api().open, () => [surface]);
63
+ const content = mergeProps(() => {
64
+ const { onKeyDown: _onKeyDown, ...rest } = api().getContentProps();
65
+ return rest;
66
+ }, {
67
+ onKeyDown: (event) => {
68
+ keepListKeys(event, surface, ".xds-select__item:not([data-disabled])", (value) => api().setHighlightedValue(value));
69
+ current().getContentProps().onKeyDown?.(event);
70
+ },
71
+ });
72
+ return (<div {...root} class={classes("xds-select", props.class)}>
73
+ <span {...labelProps()} class="xds-select__label">
74
+ {props.label}
75
+ </span>
76
+ <button {...triggerProps()} aria-labelledby={`${valueId} ${labelProps().id}`} aria-describedby={invalid() ? errorId : props.description ? descriptionId : undefined} class="xds-select__trigger">
77
+
78
+ <span {...api().getValueTextProps()} id={valueId} class="xds-select__value">
79
+ {api().valueAsString || props.placeholder}
80
+ </span>
81
+ <Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder"/>
82
+ </button>
83
+
84
+ <Show when={invalid() || props.description}>
85
+ <div class="xds-select__footer">
86
+ <Show when={invalid()} fallback={<span id={descriptionId} class="xds-select__description">
87
+ {props.description}
88
+ </span>}>
89
+ <span id={errorId} class="xds-select__error">
90
+ {props.error}
91
+ </span>
92
+ </Show>
93
+ </div>
94
+ </Show>
95
+
96
+ <select {...api().getHiddenSelectProps()}>
97
+
98
+ <option value=""/>
99
+ <For each={props.options}>
100
+ {(option) => <option value={option.value}>{option.label}</option>}
101
+ </For>
102
+ </select>
103
+ <Portal>
104
+ <Show when={api().open}>
105
+
106
+
107
+ <div class="xds-select__underlay" onMouseDown={(event) => event.preventDefault()}/>
108
+ </Show>
109
+ <div ref={(element) => (positioner = element)} {...api().getPositionerProps()} class="xds-select__positioner">
110
+
111
+ <div {...content} ref={(element) => (surface = element)} hidden={!present()} class="xds-select__content">
112
+ <div {...api().getListProps()} class="xds-select__list">
113
+ <For each={collection().items}>
114
+ {(option, index) => {
115
+ const ids = () => selectOptionIds(id, index());
116
+ return (<div {...api().getItemProps({ item: option })} aria-labelledby={ids().label} aria-describedby={option.description ? ids().description : undefined} class="xds-select__item">
117
+ <span class="xds-select__item-words">
118
+ <span {...api().getItemTextProps({ item: option })} id={ids().label} class="xds-select__item-label">
119
+ {option.label}
120
+ </span>
121
+ <Show when={option.description}>
122
+ <span id={ids().description} class="xds-select__item-description">
123
+ {option.description}
124
+ </span>
125
+ </Show>
126
+ </span>
127
+
128
+ <Show when={api().getItemState({ item: option }).selected}>
129
+ <Icon name="check" size="sm"/>
130
+ </Show>
131
+ </div>);
132
+ }}
133
+ </For>
134
+ </div>
135
+ </div>
136
+ </div>
137
+ </Portal>
138
+ </div>);
139
+ }
@@ -0,0 +1,22 @@
1
+ import { type SidebarBaseProps } from "@xds/core";
2
+ import type { JSX } from "@solidjs/web";
3
+ import { type Element } from "solid-js";
4
+ import type { RootProps } from "./root.ts";
5
+ export type { SidebarItem, SidebarSection } from "@xds/core";
6
+ export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> & RootProps & {
7
+ onChange: (value: Value) => void;
8
+ /** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
9
+ header?: Element;
10
+ /** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
11
+ footer?: Element;
12
+ };
13
+ /**
14
+ * The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each
15
+ * row is a compact list row; the current one is selected, its title heavier and its icon
16
+ * filled, so the place does not depend on the tint alone.
17
+ *
18
+ * It is navigation named by `label`, and the current row says it is the current page.
19
+ * Collapsed, the rows keep their names, and show them in a Tooltip under a pointer and on
20
+ * keyboard focus.
21
+ */
22
+ export declare function Sidebar<Value extends string = string>(props: SidebarProps<Value>): JSX.Element;