@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,51 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import { type RootProps, rootAttributes, useDefaults } from "@xds/solid/base";
5
+ import { createMemo, For, Show } from "solid-js";
6
+ import {
7
+ type AvatarStackBaseProps,
8
+ avatarStack,
9
+ avatarStackClass,
10
+ avatarStackItemClass,
11
+ avatarStackRestClass,
12
+ } from "./avatar-stack.ts";
13
+ import { Avatar } from "./Avatar.tsx";
14
+ import { classes, rootPart } from "./parts.ts";
15
+
16
+ export type AvatarStackProps = AvatarStackBaseProps & RootProps;
17
+
18
+ const ROOT = rootPart("AvatarStack");
19
+
20
+ /**
21
+ * Several people in the room of one. Assistive technology gets one image named after
22
+ * everyone in it, including those who did not fit.
23
+ */
24
+ export function AvatarStack(props: AvatarStackProps) {
25
+ const defaults = useDefaults("AvatarStack");
26
+ // Handed to every avatar, so that an Avatar default cannot make them a size the stack is not.
27
+ const size = () => props.size ?? defaults().size ?? "md";
28
+ const stack = createMemo(() => avatarStack(props.people, props.max, props.label));
29
+ return (
30
+ <span
31
+ {...rootAttributes(props)}
32
+ role="img"
33
+ aria-label={stack().name}
34
+ class={classes(ROOT, avatarStackClass, props.class)}
35
+ style={props.style}
36
+ >
37
+ <For each={stack().shown}>
38
+ {(person) => (
39
+ <span aria-hidden="true" class={avatarStackItemClass(size())}>
40
+ <Avatar name={person.name} src={person.src} size={size()} />
41
+ </span>
42
+ )}
43
+ </For>
44
+ <Show when={stack().rest > 0}>
45
+ <span aria-hidden="true" class={avatarStackRestClass(size())}>
46
+ +{stack().rest}
47
+ </span>
48
+ </Show>
49
+ </span>
50
+ );
51
+ }
@@ -0,0 +1,39 @@
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 { type Element, Show } from "solid-js";
6
+ import { type BadgeBaseProps, badgeClass, badgeDotClass } from "./badge.ts";
7
+ import { Icon } from "./Icon.tsx";
8
+ import { classes, rootPart } from "./parts.ts";
9
+
10
+ export type { BadgeTone } from "./badge.ts";
11
+
12
+ export type BadgeProps = BadgeBaseProps &
13
+ RootProps & {
14
+ children: Element;
15
+ };
16
+
17
+ const ROOT = rootPart("Badge");
18
+
19
+ /**
20
+ * A short status or category. The words carry the meaning; the color only reinforces it, so a
21
+ * badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for
22
+ * live states such as "connected", and `icon` a drawing in front of the words.
23
+ */
24
+ export function Badge(props: BadgeProps) {
25
+ const defaults = useDefaults("Badge");
26
+ return (
27
+ <span
28
+ {...rootAttributes(props)}
29
+ class={classes(ROOT, badgeClass(props.tone ?? defaults().tone), props.class)}
30
+ style={props.style}
31
+ >
32
+ <Show when={props.dot}>
33
+ <span aria-hidden="true" class={badgeDotClass} />
34
+ </Show>
35
+ <Show when={props.icon}>{(name) => <Icon name={name()} size="xs" />}</Show>
36
+ {props.children}
37
+ </span>
38
+ );
39
+ }
@@ -0,0 +1,80 @@
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, useLabels } from "@xds/solid/base";
5
+ import { type Element, Show } from "solid-js";
6
+ import {
7
+ BANNER_PARTS,
8
+ type BannerBaseProps,
9
+ bannerClass,
10
+ bannerIconClass,
11
+ bannerIconPath,
12
+ bannerRole,
13
+ } from "./banner.ts";
14
+ import { Button } from "./Button.tsx";
15
+ import { IconButton } from "./IconButton.tsx";
16
+ import { classes, rootPart } from "./parts.ts";
17
+
18
+ export type { BannerTone } from "./banner.ts";
19
+
20
+ export type BannerProps = BannerBaseProps &
21
+ RootProps & {
22
+ /** What the person can do about the message. Drawn under it as a small secondary button. */
23
+ action?: { label: string; onPress: () => void };
24
+ /**
25
+ * Shows a close control. The banner does not hide itself: the handler decides what happens
26
+ * to it.
27
+ */
28
+ onDismiss?: () => void;
29
+ children: Element;
30
+ };
31
+
32
+ const ROOT = rootPart("Banner");
33
+
34
+ /**
35
+ * A message about the whole view or a section of it. Each tone has its own icon shape, so the
36
+ * tone does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader;
37
+ * `info` and `success` wait their turn.
38
+ */
39
+ export function Banner(props: BannerProps) {
40
+ const defaults = useDefaults("Banner");
41
+ const labels = useLabels();
42
+ const tone = () => props.tone ?? defaults().tone;
43
+ return (
44
+ <div
45
+ {...rootAttributes(props)}
46
+ role={bannerRole(tone())}
47
+ class={classes(ROOT, bannerClass(tone()), props.class)}
48
+ style={props.style}
49
+ >
50
+ <svg viewBox="0 0 24 24" aria-hidden="true" class={bannerIconClass(tone())}>
51
+ <path fill="currentColor" d={bannerIconPath(tone())} />
52
+ </svg>
53
+ <div class={BANNER_PARTS.body}>
54
+ <Show when={props.title}>{(title) => <p class={BANNER_PARTS.title}>{title()}</p>}</Show>
55
+ <div>{props.children}</div>
56
+ <Show when={props.action}>
57
+ {(action) => (
58
+ <div class={BANNER_PARTS.action}>
59
+ {/* Its variant is the banner's, not one the app gives its own buttons. */}
60
+ <Button variant="secondary" size="sm" onPress={() => action().onPress()}>
61
+ {action().label}
62
+ </Button>
63
+ </div>
64
+ )}
65
+ </Show>
66
+ </div>
67
+ <Show when={props.onDismiss}>
68
+ <div class={BANNER_PARTS.dismiss}>
69
+ <IconButton
70
+ icon="x"
71
+ label={props.dismissLabel ?? labels().dismiss}
72
+ variant="ghost"
73
+ size="sm"
74
+ onPress={() => props.onDismiss?.()}
75
+ />
76
+ </div>
77
+ </Show>
78
+ </div>
79
+ );
80
+ }
@@ -0,0 +1,57 @@
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, useLabels } from "@xds/solid/base";
5
+ import { For, Show } from "solid-js";
6
+ import { BREADCRUMB_PARTS, BREADCRUMB_SEPARATOR, type BreadcrumbBaseProps } from "./breadcrumb.ts";
7
+ import { Icon } from "./Icon.tsx";
8
+ import { Link } from "./Link.tsx";
9
+ import { classes, rootPart } from "./parts.ts";
10
+
11
+ export type { BreadcrumbItem } from "./breadcrumb.ts";
12
+
13
+ export type BreadcrumbProps = BreadcrumbBaseProps & RootProps;
14
+
15
+ const ROOT = rootPart("Breadcrumb");
16
+
17
+ /**
18
+ * Where the current view sits in the app: the places above it, each a link, then the view
19
+ * itself. A navigation landmark; the current place is marked as the page.
20
+ */
21
+ export function Breadcrumb(props: BreadcrumbProps) {
22
+ const labels = useLabels();
23
+ return (
24
+ <nav
25
+ {...rootAttributes(props)}
26
+ aria-label={props.label ?? labels().breadcrumb}
27
+ class={classes(ROOT, props.class)}
28
+ style={props.style}
29
+ >
30
+ <ol class={BREADCRUMB_PARTS.list}>
31
+ <For each={props.items}>
32
+ {(item, index) => (
33
+ <li class={BREADCRUMB_PARTS.item}>
34
+ <Show
35
+ when={index() < props.items.length - 1}
36
+ fallback={
37
+ <span aria-current="page" class={BREADCRUMB_PARTS.current}>
38
+ {item.label}
39
+ </span>
40
+ }
41
+ >
42
+ <Link href={item.href} onPress={() => item.onPress?.()}>
43
+ {item.label}
44
+ </Link>
45
+ <Icon
46
+ name={BREADCRUMB_SEPARATOR.name}
47
+ size={BREADCRUMB_SEPARATOR.size}
48
+ class={BREADCRUMB_PARTS.separator}
49
+ />
50
+ </Show>
51
+ </li>
52
+ )}
53
+ </For>
54
+ </ol>
55
+ </nav>
56
+ );
57
+ }
@@ -0,0 +1,90 @@
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, withTrigger } from "@xds/solid/base";
5
+ import type { JSX } from "@solidjs/web";
6
+ import { children, createMemo, type Element, Show } from "solid-js";
7
+ import { BUTTON_ICON, type ButtonBaseProps, buttonClass, isHeld } from "./button.ts";
8
+ import { Icon } from "./Icon.tsx";
9
+ import { classes } from "./parts.ts";
10
+ import { Spinner } from "./Spinner.tsx";
11
+
12
+ export type { ButtonVariant, ControlSize } from "./button.ts";
13
+
14
+ export type ButtonProps = ButtonBaseProps &
15
+ RootProps & {
16
+ onPress?: () => void;
17
+ onFocus?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
18
+ onBlur?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
19
+ /** The native button. */
20
+ ref?: JSX.Ref<HTMLButtonElement>;
21
+ /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
22
+ children?: Element;
23
+ };
24
+
25
+ /**
26
+ * A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach
27
+ * it through context.
28
+ */
29
+ export function Button(props: ButtonProps) {
30
+ // Read once: each read of a JSX prop creates its nodes again.
31
+ const label = children(() => props.children);
32
+ const defaults = useDefaults("Button");
33
+ const variant = () => props.variant ?? defaults().variant ?? "secondary";
34
+ const size = () => props.size ?? defaults().size ?? "md";
35
+ const icon = () => BUTTON_ICON[size()];
36
+ const held = () =>
37
+ isHeld({ variant: variant(), selected: props.selected, disabled: props.disabled });
38
+ const attributes = withTrigger(
39
+ createMemo((): JSX.ButtonHTMLAttributes<HTMLButtonElement> => ({
40
+ type: props.type ?? "button",
41
+ // Its root part, `{{prefix}}-button`, is in the recipe.
42
+ class: classes(
43
+ buttonClass({
44
+ variant: variant(),
45
+ size: size(),
46
+ iconOnly:
47
+ label() == null && (props.iconStart !== undefined || props.iconEnd !== undefined),
48
+ fullWidth: props.fullWidth ?? false,
49
+ }),
50
+ props.class,
51
+ ),
52
+ style: props.style,
53
+ disabled: props.disabled,
54
+ // Loading keeps the button focusable, so focus is not lost while it waits.
55
+ "aria-disabled": props.loading ? "true" : undefined,
56
+ "data-pending": props.loading ? "" : undefined,
57
+ "aria-pressed": props.selected === undefined ? undefined : props.selected ? "true" : "false",
58
+ "aria-label": props["aria-label"],
59
+ onClick: (event) => {
60
+ // The press was taken already: block keyboard Enter/Space form submit or reset too.
61
+ if (props.loading) {
62
+ event.preventDefault();
63
+ return;
64
+ }
65
+ props.onPress?.();
66
+ },
67
+ onFocus: (event) => props.onFocus?.(event),
68
+ onBlur: (event) => props.onBlur?.(event),
69
+ })),
70
+ () => props.loading === true,
71
+ rootAttributes(props),
72
+ );
73
+ return (
74
+ <button ref={props.ref} {...attributes}>
75
+ <Show when={props.loading}>
76
+ <Show when={props.iconStart} fallback={<Spinner size="sm" />}>
77
+ {/* Where the icon was, so the button keeps its width. */}
78
+ <span class={icon().box}>
79
+ <Spinner size="sm" />
80
+ </span>
81
+ </Show>
82
+ </Show>
83
+ <Show when={!props.loading && props.iconStart}>
84
+ {(name) => <Icon name={name()} size={icon().size} filled={held()} />}
85
+ </Show>
86
+ {label()}
87
+ <Show when={props.iconEnd}>{(name) => <Icon name={name()} size={icon().size} />}</Show>
88
+ </button>
89
+ );
90
+ }
@@ -0,0 +1,100 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import { type RootProps, rootAttributes } from "@xds/solid/base";
5
+ import { dynamic } from "@solidjs/web";
6
+ import { children, type Element, Show } from "solid-js";
7
+ import { CARD_PARTS, type CardBaseProps, cardClass, cardMediaClass } from "./card.ts";
8
+ import { classes, rootPart } from "./parts.ts";
9
+
10
+ export type CardProps = CardBaseProps &
11
+ RootProps & {
12
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
13
+ actions?: Element;
14
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
15
+ media?: Element;
16
+ /** Makes the whole card one button. Put no other control inside it then. */
17
+ onPress?: () => void;
18
+ children?: Element;
19
+ };
20
+
21
+ const ROOT = rootPart("Card");
22
+
23
+ /**
24
+ * A surface that groups related content. A hairline outline and a trace of shadow lift it off
25
+ * the page; in dark mode, where shadows barely show, the lighter fill does that. `title`
26
+ * renders as a heading; `actions` sit across from it.
27
+ */
28
+ export function Card(props: CardProps) {
29
+ // Read once: each read of a JSX prop creates its nodes again.
30
+ const media = children(() => props.media);
31
+ const actions = children(() => props.actions);
32
+ const body = children(() => props.children);
33
+ const pressable = () => props.onPress !== undefined;
34
+ // A button may hold only phrasing content, so inside one the parts are spans. Its heading
35
+ // would not be reachable as a heading anyway: a button reads as its text.
36
+ const Header = dynamic(() => (pressable() ? "span" : "header"));
37
+ const Box = dynamic(() => (pressable() ? "span" : "div"));
38
+ const Title = dynamic(() => (pressable() ? "span" : "h2"));
39
+ const Line = dynamic(() => (pressable() ? "span" : "p"));
40
+ const surface = () =>
41
+ classes(
42
+ ROOT,
43
+ cardClass({ selected: props.selected, flush: props.flush, pressable: pressable() }),
44
+ props.class,
45
+ );
46
+ const parts = () => (
47
+ <>
48
+ <Show when={media() != null}>
49
+ <Box class={cardMediaClass(props.flush)}>{media()}</Box>
50
+ </Show>
51
+ <Show when={props.title || props.description || (actions() != null && !pressable())}>
52
+ <Header class={CARD_PARTS.header}>
53
+ <Box class={CARD_PARTS.heading}>
54
+ <Show when={props.title}>
55
+ {(title) => <Title class={CARD_PARTS.title}>{title()}</Title>}
56
+ </Show>
57
+ <Show when={props.description}>
58
+ {(description) => <Line class={CARD_PARTS.description}>{description()}</Line>}
59
+ </Show>
60
+ </Box>
61
+ <Show when={actions() != null && !pressable()}>
62
+ <div class={CARD_PARTS.actions}>{actions()}</div>
63
+ </Show>
64
+ </Header>
65
+ </Show>
66
+ {body()}
67
+ </>
68
+ );
69
+ const content = () => (
70
+ <Show when={props.flush} fallback={parts()}>
71
+ <Box class={CARD_PARTS.flush}>{parts()}</Box>
72
+ </Show>
73
+ );
74
+ return (
75
+ <Show
76
+ when={pressable()}
77
+ fallback={
78
+ <section
79
+ {...rootAttributes(props)}
80
+ aria-current={props.selected ? "true" : undefined}
81
+ class={surface()}
82
+ style={props.style}
83
+ >
84
+ {content()}
85
+ </section>
86
+ }
87
+ >
88
+ <button
89
+ {...rootAttributes(props)}
90
+ type="button"
91
+ onClick={() => props.onPress?.()}
92
+ aria-pressed={props.selected === undefined ? undefined : props.selected ? "true" : "false"}
93
+ class={surface()}
94
+ style={props.style}
95
+ >
96
+ {content()}
97
+ </button>
98
+ </Show>
99
+ );
100
+ }
@@ -0,0 +1,100 @@
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
+ composeRefs,
6
+ createControllable,
7
+ isControlled,
8
+ keepChecked,
9
+ type RootProps,
10
+ resetWithForm,
11
+ rootAttributes,
12
+ } from "@xds/solid/base";
13
+ import type { JSX } from "@solidjs/web";
14
+ import { createEffect, Show } from "solid-js";
15
+ import {
16
+ type CheckboxBaseProps,
17
+ checkboxBoxClass,
18
+ checkboxClass,
19
+ checkboxLabelClass,
20
+ checkboxMark,
21
+ checkboxMarkClass,
22
+ } from "./checkbox.ts";
23
+ import { classes, rootPart } from "./parts.ts";
24
+
25
+ export type CheckboxProps = CheckboxBaseProps &
26
+ RootProps & {
27
+ onChange?: (checked: boolean) => void;
28
+ onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
29
+ onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
30
+ /** The native checkbox. */
31
+ ref?: JSX.Ref<HTMLInputElement>;
32
+ };
33
+
34
+ const ROOT = rootPart("Checkbox");
35
+
36
+ /**
37
+ * A choice that is applied later, with the form it belongs to. A native checkbox: the input is
38
+ * hidden and the box is drawn beside it. Without `checked` it keeps its own state, from
39
+ * `defaultChecked`. With `indeterminate` it shows a dash and is reported as mixed.
40
+ */
41
+ export function Checkbox(props: CheckboxProps) {
42
+ const controlled = () => isControlled(props, "checked");
43
+ const defaultChecked = () => props.defaultChecked ?? false;
44
+ const checked = createControllable({
45
+ controlled,
46
+ value: () => props.checked ?? false,
47
+ defaultValue: defaultChecked,
48
+ onChange: (next) => props.onChange?.(next),
49
+ });
50
+ let input: HTMLInputElement | undefined;
51
+ resetWithForm(() => input, controlled, checked.reset);
52
+ const indeterminate = () => props.indeterminate ?? false;
53
+ // A property of the native input, with no attribute: it is what reports the box as mixed.
54
+ createEffect(indeterminate, (value) => {
55
+ if (input) input.indeterminate = value;
56
+ });
57
+ return (
58
+ <label
59
+ {...rootAttributes(props)}
60
+ class={classes(ROOT, checkboxClass, props.class)}
61
+ style={props.style}
62
+ >
63
+ <input
64
+ ref={composeRefs(
65
+ (element) => (input = element),
66
+ () => props.ref,
67
+ )}
68
+ type="checkbox"
69
+ aria-label={props["aria-label"]}
70
+ class="peer sr-only"
71
+ checked={checked.value()}
72
+ defaultChecked={controlled() ? checked.value() : defaultChecked()}
73
+ disabled={props.disabled}
74
+ name={props.name || undefined}
75
+ onChange={(event) => {
76
+ // A press clears it on the input; it stays until the app clears it.
77
+ event.currentTarget.indeterminate = indeterminate();
78
+ checked.set(event.currentTarget.checked);
79
+ keepChecked(event.currentTarget, checked.value);
80
+ }}
81
+ onFocus={(event) => props.onFocus?.(event)}
82
+ onBlur={(event) => props.onBlur?.(event)}
83
+ />
84
+ <span class={checkboxBoxClass}>
85
+ <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" class={checkboxMarkClass}>
86
+ <path
87
+ d={checkboxMark(indeterminate())}
88
+ stroke="currentColor"
89
+ stroke-width="2"
90
+ stroke-linecap="round"
91
+ stroke-linejoin="round"
92
+ />
93
+ </svg>
94
+ </span>
95
+ <Show when={props.label}>
96
+ <span class={checkboxLabelClass}>{props.label}</span>
97
+ </Show>
98
+ </label>
99
+ );
100
+ }
@@ -0,0 +1,40 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import { type RootProps, rootAttributes } from "@xds/solid/base";
5
+ import { Show } from "solid-js";
6
+ import { type ChipBaseProps, chipClass, chipIcon } from "./chip.ts";
7
+ import { Icon } from "./Icon.tsx";
8
+ import { classes, rootPart } from "./parts.ts";
9
+
10
+ export type ChipProps = ChipBaseProps &
11
+ RootProps & {
12
+ onPress?: () => void;
13
+ };
14
+
15
+ const ROOT = rootPart("Chip");
16
+
17
+ /**
18
+ * A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
19
+ * outlined and marked with a check, so the state does not depend on color.
20
+ *
21
+ * It is a toggle button: assistive technology hears whether it is pressed.
22
+ */
23
+ export function Chip(props: ChipProps) {
24
+ return (
25
+ <button
26
+ {...rootAttributes(props)}
27
+ type="button"
28
+ aria-pressed={props.selected ? "true" : "false"}
29
+ disabled={props.disabled}
30
+ onClick={() => props.onPress?.()}
31
+ class={classes(ROOT, chipClass(props.selected), props.class)}
32
+ style={props.style}
33
+ >
34
+ <Show when={chipIcon({ selected: props.selected, iconStart: props.iconStart })}>
35
+ {(name) => <Icon name={name()} size="sm" />}
36
+ </Show>
37
+ {props.label}
38
+ </button>
39
+ );
40
+ }
@@ -0,0 +1,34 @@
1
+ // Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
2
+ // as you need. `xds eject --list` says which ejected files differ from what was copied.
3
+
4
+ import { type RootProps, rootAttributes } from "@xds/solid/base";
5
+ import type { Element } from "solid-js";
6
+ import { type ChipBarBaseProps, chipBarClass } from "./chip-bar.ts";
7
+ import { classes, rootPart } from "./parts.ts";
8
+
9
+ export type ChipBarProps = ChipBarBaseProps &
10
+ RootProps & {
11
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
12
+ children: Element;
13
+ };
14
+
15
+ const ROOT = rootPart("ChipBar");
16
+
17
+ /**
18
+ * One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the
19
+ * content under it stays where it is.
20
+ */
21
+ export function ChipBar(props: ChipBarProps) {
22
+ return (
23
+ // A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser.
24
+ <div
25
+ {...rootAttributes(props)}
26
+ role="group"
27
+ aria-label={props.label}
28
+ class={classes(ROOT, chipBarClass, props.class)}
29
+ style={props.style}
30
+ >
31
+ {props.children}
32
+ </div>
33
+ );
34
+ }