@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,65 @@
1
+ import { classes, rootPart, SIDEBAR_PARTS, sidebarClass, sidebarCount, sidebarIconClass, sidebarRailButtonClass, sidebarSectionClass, sidebarTitleClass, } from "@xds/core";
2
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
3
+ import { Icon } from "./Icon.jsx";
4
+ import { PlaceRow } from "./ListRow.jsx";
5
+ import { TooltipBeside } from "./Tooltip.jsx";
6
+ import { withTrigger } from "./trigger.js";
7
+ const ROOT = rootPart("Sidebar");
8
+ export function Sidebar(props) {
9
+ const id = createUniqueId();
10
+ const collapsed = () => props.collapsed ?? false;
11
+ return (<nav aria-label={props.label} class={classes(ROOT, sidebarClass(collapsed()), props.class)} style={props.style}>
12
+ <Show when={props.header}>
13
+ {(header) => <div class={SIDEBAR_PARTS.edge}>{header()}</div>}
14
+ </Show>
15
+
16
+ <div class={SIDEBAR_PARTS.places}>
17
+ <For each={props.sections}>
18
+ {(section, index) => {
19
+ const title = () => `${id}-${index()}`;
20
+ return (<div class={sidebarSectionClass(index(), collapsed())}>
21
+ <Show when={section.title}>
22
+ {(text) => (<p id={title()} class={sidebarTitleClass(collapsed())}>
23
+ {text()}
24
+ </p>)}
25
+ </Show>
26
+ <Show when={collapsed() && index() > 0}>
27
+ <div aria-hidden="true" class={SIDEBAR_PARTS.rule}/>
28
+ </Show>
29
+ <ul aria-labelledby={section.title ? title() : undefined} class={SIDEBAR_PARTS.list}>
30
+ <For each={section.items}>
31
+ {(item) => {
32
+ const selected = () => item.value === props.value;
33
+ return (<li class={SIDEBAR_PARTS.item}>
34
+ <Show when={collapsed()} fallback={<PlaceRow compact current="page" selected={selected()} onPress={() => props.onChange(item.value)} title={item.label} leading={<Icon name={item.icon} size="md" filled={selected()} class={sidebarIconClass(selected())}/>} trailing={<Show when={sidebarCount(item.count)}>
35
+ {(count) => <span class={SIDEBAR_PARTS.count}>{count()}</span>}
36
+ </Show>}/>}>
37
+ <TooltipBeside label={item.label}>
38
+ <RailButton label={item.label} icon={item.icon} selected={selected()} onPress={() => props.onChange(item.value)}/>
39
+ </TooltipBeside>
40
+ </Show>
41
+ </li>);
42
+ }}
43
+ </For>
44
+ </ul>
45
+ </div>);
46
+ }}
47
+ </For>
48
+ </div>
49
+ <Show when={props.footer}>
50
+ {(footer) => <div class={SIDEBAR_PARTS.edge}>{footer()}</div>}
51
+ </Show>
52
+ </nav>);
53
+ }
54
+ function RailButton(props) {
55
+ const attributes = withTrigger(createMemo(() => ({
56
+ type: "button",
57
+ class: sidebarRailButtonClass(props.selected),
58
+ "aria-label": props.label,
59
+ "aria-current": props.selected ? "page" : undefined,
60
+ onClick: () => props.onPress(),
61
+ })));
62
+ return (<button {...attributes}>
63
+ <Icon name={props.icon} size="md" filled={props.selected}/>
64
+ </button>);
65
+ }
@@ -0,0 +1,11 @@
1
+ import { type SkeletonBaseProps } from "@xds/core";
2
+ import { type RootProps } from "./root.ts";
3
+ export type SkeletonProps = SkeletonBaseProps & RootProps;
4
+ /**
5
+ * Holds the place of content that is loading, in the shape the content will have. It pulses,
6
+ * and stands still for people who ask for less motion.
7
+ *
8
+ * It is hidden from assistive technology: the screen that shows skeletons says that it is
9
+ * loading, once, instead of every placeholder saying so.
10
+ */
11
+ export declare function Skeleton(props: SkeletonProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { classes, rootPart, skeletonClass, skeletonSize, } from "@xds/core";
2
+ import { useDefaults } from "./Defaults.jsx";
3
+ import { layStyle } from "./root.js";
4
+ const ROOT = rootPart("Skeleton");
5
+ export function Skeleton(props) {
6
+ const defaults = useDefaults("Skeleton");
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)}/>);
9
+ }
@@ -0,0 +1,13 @@
1
+ import { type SliderBaseProps } from "@xds/core";
2
+ import { type RootProps } from "./root.ts";
3
+ export type SliderProps = SliderBaseProps & RootProps & {
4
+ onChange: (value: number) => void;
5
+ };
6
+ /**
7
+ * Picks a number in a range by dragging the thumb, or by pressing the track where it should
8
+ * go. The values snap to `step`.
9
+ *
10
+ * It is a slider named by its label with its value, minimum and maximum, and each arrow key
11
+ * moves it one step.
12
+ */
13
+ export declare function Slider(props: SliderProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,69 @@
1
+ import { classes, focusThumbOnPress, sliderArrowValue, sliderPageSize, sliderValueText, } from "@xds/core";
2
+ import * as slider from "@zag-js/slider";
3
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
4
+ import { createMemo, createUniqueId, Show } from "solid-js";
5
+ import { withStyle } from "./root.js";
6
+ export function Slider(props) {
7
+ const id = createUniqueId();
8
+ const min = () => props.min ?? 0;
9
+ const max = () => props.max ?? 100;
10
+ const step = () => props.step ?? 1;
11
+ const pageSize = () => sliderPageSize({ min: min(), max: max(), step: step() });
12
+ const service = useMachine(slider.machine, () => ({
13
+ id,
14
+ value: [props.value],
15
+ onValueChange: (details) => props.onChange(details.value[0] ?? min()),
16
+ min: min(),
17
+ max: max(),
18
+ step: step(),
19
+ largeStep: pageSize(),
20
+ disabled: props.disabled,
21
+ thumbAlignment: "center",
22
+ getAriaValueText: (details) => sliderValueText(details.value),
23
+ }));
24
+ const api = createMemo(() => slider.connect(service, normalizeProps));
25
+ const root = withStyle(() => api().getRootProps(), () => props.style);
26
+ const thumb = mergeProps(() => api().getThumbProps({ index: 0 }), {
27
+ draggable: "false",
28
+ onKeyDown: (event) => {
29
+ if (props.disabled)
30
+ return;
31
+ const next = sliderArrowValue(event, {
32
+ value: api().value[0] ?? min(),
33
+ min: min(),
34
+ max: max(),
35
+ step: step(),
36
+ pageSize: pageSize(),
37
+ });
38
+ if (next !== undefined)
39
+ api().setThumbValue(0, next);
40
+ },
41
+ });
42
+ let thumbElement;
43
+ const control = mergeProps(() => api().getControlProps(), {
44
+ onPointerDown: (event) => {
45
+ if (!props.disabled)
46
+ focusThumbOnPress(event, thumbElement);
47
+ },
48
+ });
49
+ return (<div {...root} role="group" aria-labelledby={api().getLabelProps().id} class={classes("xds-slider", props.class)}>
50
+
51
+ <label {...api().getLabelProps()} class="xds-slider__label">
52
+ {props.label}
53
+ </label>
54
+ <Show when={props.showValue}>
55
+
56
+ <output {...api().getValueTextProps()} aria-live="off" class="xds-slider__output">
57
+ {sliderValueText(api().value[0] ?? props.value)}
58
+ </output>
59
+ </Show>
60
+ <div {...control} class="xds-slider__control">
61
+ <div {...api().getTrackProps()} class="xds-slider__track">
62
+ <div {...api().getRangeProps()} class="xds-slider__range"/>
63
+ </div>
64
+ <div {...thumb} ref={(element) => (thumbElement = element)} class="xds-slider__thumb">
65
+ <input {...api().getHiddenInputProps({ index: 0 })}/>
66
+ </div>
67
+ </div>
68
+ </div>);
69
+ }
@@ -0,0 +1,9 @@
1
+ import { type SpinnerBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type SpinnerProps = SpinnerBaseProps & RootProps;
4
+ /**
5
+ * Says that something is in progress and how long is unknown. Takes the color of the text around
6
+ * it. With `label` it is announced; without one it is decoration next to text that already says
7
+ * what is happening.
8
+ */
9
+ export declare function Spinner(props: SpinnerProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { classes, rootPart, spinnerClass } from "@xds/core";
2
+ import { useDefaults } from "./Defaults.jsx";
3
+ const ROOT = rootPart("Spinner");
4
+ export function Spinner(props) {
5
+ 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
+ <svg viewBox="0 0 24 24" fill="none" aria-hidden="true" class={spinnerClass(props.size ?? defaults().size)}>
8
+ <circle cx="12" cy="12" r="9" stroke="currentColor" stroke-width="3" opacity="0.25"/>
9
+ <path d="M21 12a9 9 0 0 0-9-9" stroke="currentColor" stroke-width="3" stroke-linecap="round"/>
10
+ </svg>
11
+ </span>);
12
+ }
@@ -0,0 +1,13 @@
1
+ import { type SwitchBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type SwitchProps = SwitchBaseProps & RootProps & {
4
+ onChange: (checked: boolean) => void;
5
+ };
6
+ /**
7
+ * Turns a setting on or off, and takes effect at once. For a choice that is applied later,
8
+ * with a form, use a Checkbox.
9
+ *
10
+ * 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.
12
+ */
13
+ export declare function Switch(props: SwitchProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { classes, rootPart, switchClass, switchLabelClass, switchThumbClass, switchTrackClass, } from "@xds/core";
2
+ import { Show } from "solid-js";
3
+ import { keepChecked } from "./controlled.js";
4
+ const ROOT = rootPart("Switch");
5
+ 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
+ }}/>
11
+ <span class={switchTrackClass}>
12
+ <span class={switchThumbClass}/>
13
+ </span>
14
+ <Show when={props.label}>
15
+ <span class={switchLabelClass}>{props.label}</span>
16
+ </Show>
17
+ </label>);
18
+ }
@@ -0,0 +1,14 @@
1
+ import { type TabsBaseProps } from "@xds/core";
2
+ import { type RootProps } from "./root.ts";
3
+ export type TabsProps<Value extends string> = TabsBaseProps<Value> & RootProps & {
4
+ onChange: (value: Value) => void;
5
+ };
6
+ /**
7
+ * Switches between views inside one screen. For two to four short modes a SegmentedControl is
8
+ * lighter; tabs are for more items, longer labels, or a row that may have to scroll.
9
+ *
10
+ * The selected tab is underlined as well as darker, so the choice does not depend on color.
11
+ * This is only the row: the app shows the view that matches `value`. The arrow keys move
12
+ * between tabs.
13
+ */
14
+ export declare function Tabs<Value extends string>(props: TabsProps<Value>): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { classes, tabStopIndex, tabsClass } from "@xds/core";
2
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
3
+ import * as tabs from "@zag-js/tabs";
4
+ import { createMemo, createUniqueId, For, Show } from "solid-js";
5
+ import { Icon } from "./Icon.jsx";
6
+ import { withStyle } from "./root.js";
7
+ export function Tabs(props) {
8
+ const id = createUniqueId();
9
+ const service = useMachine(tabs.machine, () => ({
10
+ id,
11
+ value: props.value,
12
+ onValueChange: (details) => props.onChange(details.value),
13
+ }));
14
+ const api = createMemo(() => tabs.connect(service, normalizeProps));
15
+ const root = withStyle(() => api().getRootProps(), () => props.style);
16
+ return (<div {...root} class={classes(tabsClass(props.fullWidth), props.class)}>
17
+ <div {...api().getListProps()} aria-label={props.label} class="xds-tabs__list">
18
+ <For each={props.items}>
19
+ {(item) => {
20
+ const trigger = () => api().getTriggerProps({ value: item.value });
21
+ const tabIndex = () => tabStopIndex(api().focusedValue, item.value, trigger().tabIndex);
22
+ return (<button {...mergeProps(trigger, () => ({ tabIndex: tabIndex() }))} aria-controls={undefined} class="xds-tabs__tab">
23
+ <Show when={item.icon}>{(name) => <Icon name={name()} size="sm"/>}</Show>
24
+ {item.label}
25
+ </button>);
26
+ }}
27
+ </For>
28
+ <div {...api().getIndicatorProps()} class="xds-tabs__indicator"/>
29
+ </div>
30
+ </div>);
31
+ }
@@ -0,0 +1,10 @@
1
+ import { type TextBaseProps } from "@xds/core";
2
+ import { type ValidComponent } from "@solidjs/web";
3
+ import type { Element } from "solid-js";
4
+ import type { RootProps } from "./root.ts";
5
+ export type TextProps = TextBaseProps & RootProps & {
6
+ /** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
7
+ as?: ValidComponent;
8
+ children: Element;
9
+ };
10
+ export declare function Text(props: TextProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import { classes, rootPart, textClass } from "@xds/core";
2
+ import { dynamic } from "@solidjs/web";
3
+ import { useDefaults } from "./Defaults.jsx";
4
+ const ROOT = rootPart("Text");
5
+ export function Text(props) {
6
+ const Tag = dynamic(() => props.as ?? "p");
7
+ const defaults = useDefaults("Text");
8
+ return (<Tag class={classes(ROOT, textClass({
9
+ variant: props.variant ?? defaults().variant,
10
+ tone: props.tone ?? defaults().tone,
11
+ }), props.class)} style={props.style}>
12
+ {props.children}
13
+ </Tag>);
14
+ }
@@ -0,0 +1,22 @@
1
+ import { type TextFieldBaseProps } from "@xds/core";
2
+ import { type Element } from "solid-js";
3
+ import type { RootProps } from "./root.ts";
4
+ export type TextFieldProps = TextFieldBaseProps & RootProps & {
5
+ onChange: (value: string) => void;
6
+ /**
7
+ * Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
8
+ * unless it sets its own.
9
+ */
10
+ leading?: Element;
11
+ /** Inside the box, after the text: an icon, a unit, a small button. */
12
+ trailing?: Element;
13
+ };
14
+ /**
15
+ * A labelled text field, of one line or several. The label, the description and the error
16
+ * message are tied to the input for assistive technology, and the error is announced when it
17
+ * appears.
18
+ *
19
+ * An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
20
+ * the person edits the value.
21
+ */
22
+ export declare function TextField(props: TextFieldProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,73 @@
1
+ import { classes } from "@xds/core";
2
+ import { children, createUniqueId, onSettled, Show } from "solid-js";
3
+ import { keepValue } from "./controlled.js";
4
+ export function TextField(props) {
5
+ const id = createUniqueId();
6
+ const descriptionId = `${id}-description`;
7
+ const errorId = `${id}-error`;
8
+ const leading = children(() => props.leading);
9
+ const trailing = children(() => props.trailing);
10
+ const invalid = () => props.error !== undefined;
11
+ let input;
12
+ onSettled(() => {
13
+ if (input instanceof HTMLTextAreaElement)
14
+ input.setSelectionRange(0, 0);
15
+ if (props.autoFocus)
16
+ input.focus();
17
+ });
18
+ const shared = (box) => ({
19
+ id,
20
+ class: box ? "xds-text-field__input xds-text-field__control" : "xds-text-field__input",
21
+ value: props.value,
22
+ defaultValue: props.value,
23
+ placeholder: props.placeholder,
24
+ name: props.name,
25
+ maxlength: props.maxLength,
26
+ inputmode: props.inputMode,
27
+ autocomplete: props.autoComplete,
28
+ required: props.required,
29
+ disabled: props.disabled,
30
+ "aria-invalid": invalid() ? "true" : undefined,
31
+ "aria-errormessage": invalid() ? errorId : undefined,
32
+ "aria-describedby": invalid() ? errorId : props.description ? descriptionId : undefined,
33
+ onInput: (event) => {
34
+ props.onChange(event.currentTarget.value);
35
+ if (!event.isComposing)
36
+ keepValue(event.currentTarget, () => props.value);
37
+ },
38
+ onCompositionEnd: (event) => keepValue(event.currentTarget, () => props.value),
39
+ });
40
+ 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)}/>);
41
+ return (<div class={classes("xds-text-field", props.class)} style={props.style}>
42
+ <label for={id} class="xds-text-field__label">
43
+ {props.label}
44
+ </label>
45
+ <Show when={leading() != null || trailing() != null} fallback={field(true)}>
46
+ <div class="xds-text-field__control xds-text-field__group">
47
+ <Show when={leading()}>
48
+ {(content) => (<span class="xds-text-field__slot xds-text-field__slot--leading">{content()}</span>)}
49
+ </Show>
50
+ {field(false)}
51
+ <Show when={trailing()}>
52
+ {(content) => (<span class="xds-text-field__slot xds-text-field__slot--trailing">{content()}</span>)}
53
+ </Show>
54
+ </div>
55
+ </Show>
56
+
57
+ <div class="xds-text-field__footer">
58
+ <Show when={!invalid() && props.description}>
59
+ <span id={descriptionId} class="xds-text-field__description">
60
+ {props.description}
61
+ </span>
62
+ </Show>
63
+ <span id={errorId} class="xds-text-field__error" aria-live="polite">
64
+ {props.error}
65
+ </span>
66
+ <Show when={props.maxLength !== undefined}>
67
+ <span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">
68
+ {props.value.length}/{props.maxLength}
69
+ </span>
70
+ </Show>
71
+ </div>
72
+ </div>);
73
+ }
@@ -0,0 +1,9 @@
1
+ import { type ThumbnailBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type { ThumbnailRatio } from "@xds/core";
4
+ export type ThumbnailProps = ThumbnailBaseProps & RootProps;
5
+ /**
6
+ * A picture in a fixed shape, for a video, an article or a product. It fills the width it is
7
+ * given and takes its height from `ratio`, and crops the picture to fill it.
8
+ */
9
+ export declare function Thumbnail(props: ThumbnailProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { classes, pictureClass, rootPart, THUMBNAIL_PARTS, thumbnailBadgeClass, thumbnailClass, thumbnailWatched, } from "@xds/core";
2
+ import { Show } from "solid-js";
3
+ import { Badge } from "./Badge.jsx";
4
+ import { useDefaults } from "./Defaults.jsx";
5
+ import { Icon } from "./Icon.jsx";
6
+ import { createPicture } from "./picture.js";
7
+ const ROOT = rootPart("Thumbnail");
8
+ export function Thumbnail(props) {
9
+ const defaults = useDefaults("Thumbnail");
10
+ const picture = createPicture(() => props.src);
11
+ const watched = () => thumbnailWatched(props.progress);
12
+ return (<span class={classes(ROOT, thumbnailClass(props.ratio ?? defaults().ratio), props.class)} style={props.style}>
13
+
14
+ <span class={THUMBNAIL_PARTS.placeholder} role={props.alt ? "img" : undefined} aria-label={props.alt || undefined} aria-hidden={props.alt ? undefined : "true"}>
15
+ <Show when={picture.loaded() !== true}>
16
+ <Icon name="image" size="lg"/>
17
+ </Show>
18
+ <Show when={picture.loaded() !== false && props.src}>
19
+ {(src) => (<img src={src()} alt="" aria-hidden="true" class={pictureClass(picture.loaded() === true)} onLoad={() => picture.onLoad(src())} onError={() => picture.onError(src())}/>)}
20
+ </Show>
21
+ </span>
22
+ <Show when={props.badge}>
23
+ {(badge) => (<span class={thumbnailBadgeClass(watched())}>
24
+ <Badge tone="overlay">{badge()}</Badge>
25
+ </span>)}
26
+ </Show>
27
+ <Show when={watched() > 0}>
28
+
29
+ <span aria-hidden="true" class={THUMBNAIL_PARTS.track}>
30
+ <span class={THUMBNAIL_PARTS.fill} style={{ width: `${watched() * 100}%` }}/>
31
+ </span>
32
+ </Show>
33
+ </span>);
34
+ }
@@ -0,0 +1,16 @@
1
+ import { type ToastBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type ToastProps = ToastBaseProps & RootProps & {
4
+ /** Called when the time is up and after the action. Set `open` to false in it. */
5
+ onClose: () => void;
6
+ };
7
+ /**
8
+ * A short message about what just happened, which leaves on its own. It sits at the bottom
9
+ * center of the window, above everything else, and is announced politely without taking
10
+ * focus. The time does not run while the pointer is over it or focus is inside it.
11
+ *
12
+ * Do not put the only way to do something in a toast: it is gone in a few seconds.
13
+ *
14
+ * Its `class` and `style` are the toast's surface's, which is in the page only while it is open.
15
+ */
16
+ export declare function Toast(props: ToastProps): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,42 @@
1
+ import { motion } from "@xds/tokens";
2
+ import { classes, rootPart, TOAST_PARTS } from "@xds/core";
3
+ import { createEffect, createSignal, onSettled, Show } from "solid-js";
4
+ const ROOT = rootPart("Toast");
5
+ export function Toast(props) {
6
+ let region;
7
+ const [hovered, setHovered] = createSignal();
8
+ const [focused, setFocused] = createSignal();
9
+ const inPage = (toast) => toast?.isConnected === true;
10
+ onSettled(() => {
11
+ if (!region.showPopover)
12
+ return;
13
+ region.showPopover();
14
+ return () => region.hidePopover();
15
+ });
16
+ createEffect(() => ({
17
+ open: props.open,
18
+ held: inPage(hovered()) || inPage(focused()),
19
+ duration: props.duration ?? motion.duration.toast,
20
+ }), ({ open, held, duration }) => {
21
+ if (!open || held || duration <= 0)
22
+ return;
23
+ const timer = setTimeout(() => props.onClose(), duration);
24
+ return () => clearTimeout(timer);
25
+ });
26
+ return (<div ref={(element) => (region = element)} role="status" popover="manual" class={TOAST_PARTS.region}>
27
+ <Show when={props.open}>
28
+
29
+ <div onPointerEnter={(event) => setHovered(event.currentTarget)} onPointerLeave={() => setHovered(undefined)} onFocusIn={(event) => setFocused(event.currentTarget)} onFocusOut={() => setFocused(undefined)} class={classes(ROOT, TOAST_PARTS.toast, props.class)} style={props.style}>
30
+ <span class={TOAST_PARTS.message}>{props.message}</span>
31
+ <Show when={props.action}>
32
+ {(action) => (<button type="button" onClick={() => {
33
+ action().onPress();
34
+ props.onClose();
35
+ }} class={TOAST_PARTS.action}>
36
+ {action().label}
37
+ </button>)}
38
+ </Show>
39
+ </div>
40
+ </Show>
41
+ </div>);
42
+ }
@@ -0,0 +1,28 @@
1
+ import { type TooltipBaseProps } from "@xds/core";
2
+ import { type Element } from "solid-js";
3
+ import { type RootProps } from "./root.ts";
4
+ export type TooltipProps = TooltipBaseProps & RootProps & {
5
+ /** The control it describes: a Button or an IconButton. */
6
+ children: Element;
7
+ };
8
+ /**
9
+ * Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
10
+ * short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
11
+ * focus leaves, or Escape is pressed.
12
+ *
13
+ * It describes the control and is not its name: an IconButton still needs its `label`. It
14
+ * never holds anything pressable, and touch input has no hover, so nothing may depend on it.
15
+ *
16
+ * Its `class` and `style` are the tooltip's, not the control's, and it is in the page only
17
+ * while it shows.
18
+ */
19
+ export declare function Tooltip(props: TooltipProps): import("@solidjs/web").JSX.Element;
20
+ /**
21
+ * A Tooltip at the end edge of its control instead of above or below it: a collapsed Sidebar
22
+ * names its icons on the side of the content, where they do not cover their neighbours. Only
23
+ * for this package's own components: the index does not export it.
24
+ */
25
+ export declare function TooltipBeside(props: {
26
+ label: string;
27
+ children: Element;
28
+ }): import("@solidjs/web").JSX.Element;
@@ -0,0 +1,52 @@
1
+ import { motion, space } from "@xds/tokens";
2
+ import { classes, tooltipEndSide } from "@xds/core";
3
+ import { Portal } from "@solidjs/web";
4
+ import { normalizeProps, useMachine } from "@zag-js/solid";
5
+ import * as tooltip from "@zag-js/tooltip";
6
+ import { createMemo, createUniqueId, Show } from "solid-js";
7
+ import { createPresence } from "./presence.js";
8
+ import { withStyle } from "./root.js";
9
+ import { provideTrigger, TriggerContext } from "./trigger.js";
10
+ export function Tooltip(props) {
11
+ return (<Overlay label={props.label} shortcut={props.shortcut} placement={() => props.placement ?? "top"} class={props.class} style={props.style}>
12
+ {props.children}
13
+ </Overlay>);
14
+ }
15
+ export function TooltipBeside(props) {
16
+ return (<Overlay label={props.label} placement={tooltipEndSide}>
17
+ {props.children}
18
+ </Overlay>);
19
+ }
20
+ function Overlay(props) {
21
+ const id = createUniqueId();
22
+ const service = useMachine(tooltip.machine, () => ({
23
+ id,
24
+ openDelay: motion.duration.tooltipDelay,
25
+ closeDelay: 0,
26
+ closeOnScroll: false,
27
+ positioning: { placement: props.placement(), gutter: space[1] },
28
+ }));
29
+ const api = createMemo(() => tooltip.connect(service, normalizeProps));
30
+ const trigger = provideTrigger(() => api().getTriggerProps());
31
+ const contentProps = withStyle(() => api().getContentProps(), () => props.style);
32
+ let content;
33
+ const present = createPresence(() => api().open, () => [content]);
34
+ return (<>
35
+ <TriggerContext value={trigger}>{props.children}</TriggerContext>
36
+ <Show when={present()}>
37
+ <Portal>
38
+ <TriggerContext value={null}>
39
+ <div {...api().getPositionerProps()} class="xds-tooltip__positioner">
40
+
41
+ <div {...contentProps} ref={(element) => (content = element)} hidden={false} class={classes("xds-tooltip", props.class)}>
42
+ {props.label}
43
+ <Show when={props.shortcut}>
44
+ {(shortcut) => <kbd class="xds-tooltip__shortcut">{shortcut()}</kbd>}
45
+ </Show>
46
+ </div>
47
+ </div>
48
+ </TriggerContext>
49
+ </Portal>
50
+ </Show>
51
+ </>);
52
+ }
@@ -0,0 +1,4 @@
1
+ /** After `onChange`: puts the parent's value back into a field that did not take the edit. */
2
+ export declare function keepValue(element: HTMLInputElement | HTMLTextAreaElement, value: () => string): void;
3
+ /** After `onChange`: puts the parent's state back into a checkbox or radio that did not take it. */
4
+ export declare function keepChecked(element: HTMLInputElement, checked: () => boolean): void;
@@ -0,0 +1,11 @@
1
+ import { flush } from "solid-js";
2
+ export function keepValue(element, value) {
3
+ flush();
4
+ if (element.value !== value())
5
+ element.value = value();
6
+ }
7
+ export function keepChecked(element, checked) {
8
+ flush();
9
+ if (element.checked !== checked())
10
+ element.checked = checked();
11
+ }