@xds/react 0.1.0 → 0.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 (140) hide show
  1. package/dist/Accordion.js +191 -33
  2. package/dist/Avatar.js +65 -6
  3. package/dist/AvatarStack.js +101 -6
  4. package/dist/Badge.js +61 -4
  5. package/dist/Banner.js +161 -5
  6. package/dist/Button.js +152 -24
  7. package/dist/Card.js +171 -12
  8. package/dist/Checkbox.js +138 -3
  9. package/dist/Chip.js +71 -4
  10. package/dist/ChipBar.js +36 -3
  11. package/dist/CountBadge.js +62 -9
  12. package/dist/DatePicker.js +421 -25
  13. package/dist/DateRangePicker.js +362 -40
  14. package/dist/Defaults.js +42 -7
  15. package/dist/Dialog.js +128 -24
  16. package/dist/Divider.js +29 -3
  17. package/dist/EmptyState.js +83 -3
  18. package/dist/Icon.js +74 -4
  19. package/dist/IconButton.js +113 -18
  20. package/dist/ListRow.js +180 -10
  21. package/dist/MediaCard.js +273 -11
  22. package/dist/Menu.js +234 -58
  23. package/dist/ProgressBar.js +63 -4
  24. package/dist/RadioGroup.js +173 -12
  25. package/dist/SearchField.js +148 -16
  26. package/dist/SectionHeader.js +121 -5
  27. package/dist/SegmentedControl.js +104 -5
  28. package/dist/Select.js +307 -55
  29. package/dist/Sidebar.js +212 -19
  30. package/dist/Skeleton.js +61 -5
  31. package/dist/Slider.js +142 -35
  32. package/dist/Spinner.js +93 -4
  33. package/dist/Switch.js +114 -3
  34. package/dist/Tabs.js +130 -14
  35. package/dist/Text.js +42 -4
  36. package/dist/TextField.js +209 -26
  37. package/dist/Thumbnail.js +146 -7
  38. package/dist/Toast.js +118 -30
  39. package/dist/Tooltip.js +154 -20
  40. package/dist/base.d.ts +11 -0
  41. package/dist/base.js +10 -0
  42. package/dist/modal-popover.js +32 -10
  43. package/dist/picture.d.ts +6 -4
  44. package/dist/picture.js +72 -17
  45. package/dist/portal.js +24 -4
  46. package/dist/presence.js +30 -9
  47. package/dist/preview.d.ts +14 -3
  48. package/dist/preview.js +118 -74
  49. package/dist/root.js +1 -0
  50. package/dist/trigger.d.ts +7 -0
  51. package/dist/trigger.js +41 -8
  52. package/eject/files/Accordion.tsx +157 -0
  53. package/eject/files/Avatar.tsx +41 -0
  54. package/eject/files/AvatarStack.tsx +47 -0
  55. package/eject/files/Badge.tsx +33 -0
  56. package/eject/files/Banner.tsx +70 -0
  57. package/eject/files/Button.tsx +88 -0
  58. package/eject/files/Card.tsx +85 -0
  59. package/eject/files/Checkbox.tsx +59 -0
  60. package/eject/files/Chip.tsx +43 -0
  61. package/eject/files/ChipBar.tsx +31 -0
  62. package/eject/files/CountBadge.tsx +50 -0
  63. package/eject/files/DatePicker.tsx +192 -0
  64. package/eject/files/DateRangePicker.tsx +271 -0
  65. package/eject/files/Dialog.tsx +108 -0
  66. package/eject/files/Divider.tsx +13 -0
  67. package/eject/files/EmptyState.tsx +39 -0
  68. package/eject/files/Icon.tsx +38 -0
  69. package/eject/files/IconButton.tsx +62 -0
  70. package/eject/files/ListRow.tsx +86 -0
  71. package/eject/files/MediaCard.tsx +111 -0
  72. package/eject/files/Menu.tsx +168 -0
  73. package/eject/files/ProgressBar.tsx +34 -0
  74. package/eject/files/RadioGroup.tsx +112 -0
  75. package/eject/files/SearchField.tsx +88 -0
  76. package/eject/files/SectionHeader.tsx +56 -0
  77. package/eject/files/SegmentedControl.tsx +57 -0
  78. package/eject/files/Select.tsx +228 -0
  79. package/eject/files/Sidebar.tsx +149 -0
  80. package/eject/files/Skeleton.tsx +28 -0
  81. package/eject/files/Slider.tsx +109 -0
  82. package/eject/files/Spinner.tsx +36 -0
  83. package/eject/files/Switch.tsx +53 -0
  84. package/eject/files/Tabs.tsx +71 -0
  85. package/eject/files/Text.tsx +31 -0
  86. package/eject/files/TextField.tsx +122 -0
  87. package/eject/files/Thumbnail.tsx +66 -0
  88. package/eject/files/Toast.tsx +88 -0
  89. package/eject/files/Tooltip.tsx +120 -0
  90. package/eject/files/accordion.css +89 -0
  91. package/eject/files/accordion.ts +67 -0
  92. package/eject/files/avatar-stack.ts +57 -0
  93. package/eject/files/avatar.ts +42 -0
  94. package/eject/files/badge.ts +30 -0
  95. package/eject/files/banner.ts +68 -0
  96. package/eject/files/base.css +38 -0
  97. package/eject/files/button.css +241 -0
  98. package/eject/files/button.ts +106 -0
  99. package/eject/files/card.ts +58 -0
  100. package/eject/files/checkbox.ts +32 -0
  101. package/eject/files/chip-bar.ts +16 -0
  102. package/eject/files/chip.ts +35 -0
  103. package/eject/files/count-badge.ts +32 -0
  104. package/eject/files/date-picker.css +352 -0
  105. package/eject/files/date-picker.ts +250 -0
  106. package/eject/files/date-range-picker.ts +323 -0
  107. package/eject/files/dialog.css +139 -0
  108. package/eject/files/dialog.ts +15 -0
  109. package/eject/files/divider.ts +5 -0
  110. package/eject/files/empty-state.ts +22 -0
  111. package/eject/files/icon.ts +36 -0
  112. package/eject/files/list-row.ts +66 -0
  113. package/eject/files/media-card.ts +66 -0
  114. package/eject/files/menu.css +176 -0
  115. package/eject/files/menu.ts +84 -0
  116. package/eject/files/parts.ts +17 -0
  117. package/eject/files/progress-bar.ts +23 -0
  118. package/eject/files/radio-group.css +160 -0
  119. package/eject/files/radio-group.ts +24 -0
  120. package/eject/files/section-header.ts +32 -0
  121. package/eject/files/segmented-control.ts +30 -0
  122. package/eject/files/select.css +285 -0
  123. package/eject/files/select.ts +36 -0
  124. package/eject/files/sidebar.ts +75 -0
  125. package/eject/files/skeleton.ts +51 -0
  126. package/eject/files/slider.css +136 -0
  127. package/eject/files/slider.ts +65 -0
  128. package/eject/files/spinner.ts +22 -0
  129. package/eject/files/switch.ts +34 -0
  130. package/eject/files/tabs.css +112 -0
  131. package/eject/files/tabs.ts +35 -0
  132. package/eject/files/text-field.css +229 -0
  133. package/eject/files/text-field.ts +48 -0
  134. package/eject/files/text.ts +38 -0
  135. package/eject/files/thumbnail.ts +51 -0
  136. package/eject/files/toast.ts +31 -0
  137. package/eject/files/tooltip.css +104 -0
  138. package/eject/files/tooltip.ts +21 -0
  139. package/eject/manifest.json +814 -0
  140. package/package.json +9 -4
package/dist/trigger.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { mergeProps } from "@zag-js/react";
1
2
  /** The props an overlay's machine has for the control that opens it. */
2
3
  export type TriggerProps = Record<string, unknown>;
3
4
  /** Not exported from the package: only this package's controls and overlays use it. */
@@ -15,3 +16,9 @@ export declare function useProvideTrigger(own: TriggerProps): TriggerProps;
15
16
  * open. Spread the result on the element.
16
17
  */
17
18
  export declare function useTrigger<T extends object>(own: T, inert?: boolean): T;
19
+ /**
20
+ * Zag's `mergeProps` for props whose handlers read a ref. React Compiler lets such a handler be
21
+ * handed to a hook, which by React's rules does not call it while rendering, and to no other
22
+ * function a component calls as it renders.
23
+ */
24
+ export declare const useMergedProps: typeof mergeProps;
package/dist/trigger.js CHANGED
@@ -1,14 +1,47 @@
1
+ import { c as _c } from "react/compiler-runtime";
1
2
  import { mergeProps } from "@zag-js/react";
2
3
  import { createContext, useContext } from "react";
3
4
  export const TriggerContext = createContext(null);
4
5
  export function useProvideTrigger(own) {
5
- const outer = useContext(TriggerContext);
6
- return mergeProps(outer ?? {}, own);
6
+ const $ = _c(5);
7
+ const outer = useContext(TriggerContext);
8
+ let t0;
9
+ if ($[0] !== outer) {
10
+ t0 = outer ?? {};
11
+ $[0] = outer;
12
+ $[1] = t0;
13
+ } else {
14
+ t0 = $[1];
15
+ }
16
+ let t1;
17
+ if ($[2] !== own || $[3] !== t0) {
18
+ t1 = mergeProps(t0, own);
19
+ $[2] = own;
20
+ $[3] = t0;
21
+ $[4] = t1;
22
+ } else {
23
+ t1 = $[4];
24
+ }
25
+ return t1;
7
26
  }
8
- export function useTrigger(own, inert = false) {
9
- const trigger = useContext(TriggerContext) ?? {};
10
- const overlays = inert
11
- ? Object.fromEntries(Object.entries(trigger).filter(([key]) => !key.startsWith("on")))
12
- : trigger;
13
- return mergeProps(overlays, own);
27
+ export function useTrigger(own, t0) {
28
+ const $ = _c(3);
29
+ const inert = t0 === undefined ? false : t0;
30
+ const trigger = useContext(TriggerContext) ?? {};
31
+ const overlays = inert ? Object.fromEntries(Object.entries(trigger).filter(_temp)) : trigger;
32
+ let t1;
33
+ if ($[0] !== overlays || $[1] !== own) {
34
+ t1 = mergeProps(overlays, own);
35
+ $[0] = overlays;
36
+ $[1] = own;
37
+ $[2] = t1;
38
+ } else {
39
+ t1 = $[2];
40
+ }
41
+ return t1;
14
42
  }
43
+ function _temp(t0) {
44
+ const [key] = t0;
45
+ return !key.startsWith("on");
46
+ }
47
+ export const useMergedProps = (...sets) => mergeProps(...sets);
@@ -0,0 +1,157 @@
1
+ // Ejected from `@xds/react` 0.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 } from "@xds/react/base";
5
+ import * as accordion from "@zag-js/accordion";
6
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
7
+ import {
8
+ type HTMLAttributes,
9
+ type ReactNode,
10
+ useId,
11
+ useLayoutEffect,
12
+ useRef,
13
+ useState,
14
+ } from "react";
15
+ import {
16
+ ACCORDION_PARTS,
17
+ type AccordionBaseProps,
18
+ type AccordionItemBase,
19
+ focusTitleOnClick,
20
+ setPanelOpen,
21
+ } from "./accordion.ts";
22
+ import { Icon } from "./Icon.tsx";
23
+ import { classes } from "./parts.ts";
24
+
25
+ export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
26
+ /** The body, shown under the title while the item is open. */
27
+ content: ReactNode;
28
+ };
29
+
30
+ export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> &
31
+ RootProps & {
32
+ items: readonly AccordionItem<Value>[];
33
+ onChange: (expanded: Value[]) => void;
34
+ };
35
+
36
+ /**
37
+ * Items whose bodies open and close under their titles, separated by hairlines. The chevron
38
+ * turns over when an item is open, so the state does not depend on color. Opening and closing
39
+ * animate the height, and do not for people who ask for less motion.
40
+ *
41
+ * Each title is a heading holding a button that says whether its body is expanded and which
42
+ * body it controls. A closed body is hidden, but the browser's find in page still opens it.
43
+ */
44
+ export function Accordion<Value extends string = string>({
45
+ items,
46
+ expanded,
47
+ onChange,
48
+ multiple = false,
49
+ className,
50
+ style,
51
+ }: AccordionProps<Value>) {
52
+ const service = useMachine(accordion.machine, {
53
+ id: useId(),
54
+ value: [...expanded],
55
+ onValueChange: (details) => onChange(details.value as Value[]),
56
+ multiple,
57
+ collapsible: true,
58
+ hiddenUntilFound: true,
59
+ });
60
+ const api = accordion.connect(service, normalizeProps);
61
+ return (
62
+ <div
63
+ {...mergeProps(api.getRootProps(), {
64
+ className: classes("{{prefix}}-accordion", className),
65
+ style,
66
+ })}
67
+ >
68
+ {items.map((item) => {
69
+ // The panel hides itself once it has finished closing; see Panel.
70
+ const { hidden: _hidden, ...body } = api.getItemContentProps({ value: item.value });
71
+ return (
72
+ <div
73
+ key={item.value}
74
+ {...api.getItemProps({ value: item.value })}
75
+ className="{{prefix}}-accordion__item"
76
+ >
77
+ <h3
78
+ {...api.getItemHeaderProps({ value: item.value })}
79
+ className="{{prefix}}-accordion__heading"
80
+ >
81
+ <button
82
+ {...mergeProps(api.getItemTriggerProps({ value: item.value }), {
83
+ // Runs before Zag's handler.
84
+ onClick: focusTitleOnClick,
85
+ })}
86
+ type="button"
87
+ className="{{prefix}}-accordion__trigger group"
88
+ >
89
+ <span className={ACCORDION_PARTS.text}>
90
+ <span className={ACCORDION_PARTS.title}>{item.title}</span>
91
+ {item.description && (
92
+ <span className={ACCORDION_PARTS.description}>{item.description}</span>
93
+ )}
94
+ </span>
95
+ <Icon name="chevron-down" size="sm" className={ACCORDION_PARTS.chevron} />
96
+ </button>
97
+ </h3>
98
+ <Panel open={api.value.includes(item.value)} attributes={body}>
99
+ {item.content}
100
+ </Panel>
101
+ </div>
102
+ );
103
+ })}
104
+ </div>
105
+ );
106
+ }
107
+
108
+ /**
109
+ * An item's body. Its height moves between zero and the height of what it holds, and it is
110
+ * hidden only once it has finished closing.
111
+ */
112
+ function Panel({
113
+ open,
114
+ attributes,
115
+ children,
116
+ }: {
117
+ open: boolean;
118
+ attributes: HTMLAttributes<HTMLDivElement>;
119
+ children: ReactNode;
120
+ }) {
121
+ const panel = useRef<HTMLDivElement>(null);
122
+ // What the panel was last set to. A change animates; the first setting, and the same one
123
+ // again when StrictMode runs the effect twice, do not.
124
+ const shown = useRef<boolean>(undefined);
125
+ // A page rendered on the server shows the panel before the effect below can run, so a
126
+ // closed one starts hidden. The value never changes, so React leaves the attribute to the
127
+ // effect from then on.
128
+ const [closedAtFirst] = useState(!open);
129
+ // Before the browser paints, so a closed panel never shows for a frame.
130
+ useLayoutEffect(() => {
131
+ if (!panel.current) return;
132
+ const stop = setPanelOpen(
133
+ panel.current,
134
+ open,
135
+ shown.current !== undefined && shown.current !== open,
136
+ );
137
+ shown.current = open;
138
+ // The next toggle takes over from this one.
139
+ return stop;
140
+ }, [open]);
141
+ // A group: a region is a landmark, and a page of accordions would fill the list of
142
+ // landmarks. A closed one is left out of the accessibility tree as soon as it starts closing;
143
+ // `hidden="until-found"` alone leaves the empty group in it.
144
+ return (
145
+ // A group, not a fieldset: it is the body of a disclosure, not a set of form fields.
146
+ <div
147
+ {...attributes}
148
+ ref={panel}
149
+ hidden={closedAtFirst || undefined}
150
+ role="group"
151
+ aria-hidden={open ? undefined : true}
152
+ className="{{prefix}}-accordion__panel"
153
+ >
154
+ <div className="{{prefix}}-accordion__body">{children}</div>
155
+ </div>
156
+ );
157
+ }
@@ -0,0 +1,41 @@
1
+ // Ejected from `@xds/react` 0.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, useDefaults, usePicture } from "@xds/react/base";
5
+ import { type AvatarBaseProps, avatarClass, avatarInitials, pictureClass } from "./avatar.ts";
6
+ import { classes, rootPart } from "./parts.ts";
7
+
8
+ export type { AvatarSize } from "./avatar.ts";
9
+
10
+ export type AvatarProps = AvatarBaseProps & RootProps;
11
+
12
+ /**
13
+ * Stands for a person or a team by a picture, or by their initials when there is none.
14
+ * Assistive technology gets the full name either way. The small size has room for one letter.
15
+ */
16
+ export function Avatar(props: AvatarProps) {
17
+ const defaults = useDefaults("Avatar");
18
+ const { name, src, className, style } = props;
19
+ const size = props.size ?? defaults.size;
20
+ const picture = usePicture(src);
21
+ return (
22
+ <span
23
+ role="img"
24
+ aria-label={name}
25
+ className={classes(rootPart("Avatar"), avatarClass(size), className)}
26
+ style={style}
27
+ >
28
+ {avatarInitials(name, size)}
29
+ {src && picture.loaded !== false && (
30
+ <img
31
+ src={src}
32
+ // The name is on the avatar itself; a second one on the picture would be read twice.
33
+ alt=""
34
+ aria-hidden="true"
35
+ className={pictureClass(picture.loaded === true)}
36
+ {...picture.image}
37
+ />
38
+ )}
39
+ </span>
40
+ );
41
+ }
@@ -0,0 +1,47 @@
1
+ // Ejected from `@xds/react` 0.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, useDefaults } from "@xds/react/base";
5
+ import {
6
+ type AvatarStackBaseProps,
7
+ avatarStack,
8
+ avatarStackClass,
9
+ avatarStackItemClass,
10
+ avatarStackRestClass,
11
+ } from "./avatar-stack.ts";
12
+ import { Avatar } from "./Avatar.tsx";
13
+ import { classes, rootPart } from "./parts.ts";
14
+
15
+ export type AvatarStackProps = AvatarStackBaseProps & RootProps;
16
+
17
+ /**
18
+ * Several people in the room of one. Assistive technology gets one image named after
19
+ * everyone in it, including those who did not fit.
20
+ */
21
+ export function AvatarStack(props: AvatarStackProps) {
22
+ const defaults = useDefaults("AvatarStack");
23
+ const { people, max, label, className, style } = props;
24
+ // Settled here, so that the avatars take the stack's size and not an Avatar default.
25
+ const size = props.size ?? defaults.size ?? "md";
26
+ const stack = avatarStack(people, max, label);
27
+ return (
28
+ <span
29
+ role="img"
30
+ aria-label={stack.name}
31
+ className={classes(rootPart("AvatarStack"), avatarStackClass, className)}
32
+ style={style}
33
+ >
34
+ {stack.shown.map((person, index) => (
35
+ // By position, not by name: two people can share a name.
36
+ <span key={index} aria-hidden="true" className={avatarStackItemClass(size)}>
37
+ <Avatar name={person.name} src={person.src} size={size} />
38
+ </span>
39
+ ))}
40
+ {stack.rest > 0 && (
41
+ <span aria-hidden="true" className={avatarStackRestClass(size)}>
42
+ +{stack.rest}
43
+ </span>
44
+ )}
45
+ </span>
46
+ );
47
+ }
@@ -0,0 +1,33 @@
1
+ // Ejected from `@xds/react` 0.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, useDefaults } from "@xds/react/base";
5
+ import type { ReactNode } from "react";
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: ReactNode;
15
+ };
16
+
17
+ /**
18
+ * A short status or category. The words carry the meaning; the color only reinforces it, so a
19
+ * badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for
20
+ * live states such as "connected", and `icon` a drawing in front of the words.
21
+ */
22
+ export function Badge(props: BadgeProps) {
23
+ const defaults = useDefaults("Badge");
24
+ const { dot = false, icon, className, style, children } = props;
25
+ const tone = props.tone ?? defaults.tone;
26
+ return (
27
+ <span className={classes(rootPart("Badge"), badgeClass(tone), className)} style={style}>
28
+ {dot && <span aria-hidden className={badgeDotClass} />}
29
+ {icon && <Icon name={icon} size="xs" />}
30
+ {children}
31
+ </span>
32
+ );
33
+ }
@@ -0,0 +1,70 @@
1
+ // Ejected from `@xds/react` 0.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, useDefaults } from "@xds/react/base";
5
+ import type { ReactNode } from "react";
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: ReactNode;
30
+ };
31
+
32
+ /**
33
+ * A message about the whole view or a section of it. Each tone has its own icon shape, so the
34
+ * tone does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader;
35
+ * `info` and `success` wait their turn.
36
+ */
37
+ export function Banner(props: BannerProps) {
38
+ const defaults = useDefaults("Banner");
39
+ const { title, action, onDismiss, dismissLabel = "Dismiss", className, style, children } = props;
40
+ const tone = props.tone ?? defaults.tone;
41
+ return (
42
+ <div
43
+ role={bannerRole(tone)}
44
+ className={classes(rootPart("Banner"), bannerClass(tone), className)}
45
+ style={style}
46
+ >
47
+ <svg viewBox="0 0 24 24" aria-hidden="true" className={bannerIconClass(tone)}>
48
+ <path fill="currentColor" d={bannerIconPath(tone)} />
49
+ </svg>
50
+ <div className={BANNER_PARTS.body}>
51
+ {title && <p className={BANNER_PARTS.title}>{title}</p>}
52
+ <div>{children}</div>
53
+ {/* Its controls name their variant and size: a Button or IconButton default that the
54
+ app sets is for the app's own controls, not for the parts of a banner. */}
55
+ {action && (
56
+ <div className={BANNER_PARTS.action}>
57
+ <Button variant="secondary" size="sm" onPress={action.onPress}>
58
+ {action.label}
59
+ </Button>
60
+ </div>
61
+ )}
62
+ </div>
63
+ {onDismiss && (
64
+ <div className={BANNER_PARTS.dismiss}>
65
+ <IconButton icon="x" label={dismissLabel} variant="ghost" size="sm" onPress={onDismiss} />
66
+ </div>
67
+ )}
68
+ </div>
69
+ );
70
+ }
@@ -0,0 +1,88 @@
1
+ // Ejected from `@xds/react` 0.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, useDefaults, useTrigger } from "@xds/react/base";
5
+ import type { ReactNode } from "react";
6
+ import { BUTTON_ICON, type ButtonBaseProps, buttonClass, isHeld } from "./button.ts";
7
+ import { Icon } from "./Icon.tsx";
8
+ import { classes } from "./parts.ts";
9
+ import { Spinner } from "./Spinner.tsx";
10
+
11
+ export type { ButtonVariant, ControlSize } from "./button.ts";
12
+
13
+ export type ButtonProps = ButtonBaseProps &
14
+ RootProps & {
15
+ onPress?: () => void;
16
+ /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
17
+ children?: ReactNode;
18
+ };
19
+
20
+ /**
21
+ * A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach
22
+ * it through context.
23
+ */
24
+ export function Button(props: ButtonProps) {
25
+ const defaults = useDefaults("Button");
26
+ const {
27
+ iconStart,
28
+ iconEnd,
29
+ selected,
30
+ disabled = false,
31
+ loading = false,
32
+ fullWidth = false,
33
+ type = "button",
34
+ onPress,
35
+ "aria-label": label,
36
+ className,
37
+ style,
38
+ children,
39
+ } = props;
40
+ const variant = props.variant ?? defaults.variant ?? "secondary";
41
+ const size = props.size ?? defaults.size ?? "md";
42
+ const icon = BUTTON_ICON[size];
43
+ const attributes = useTrigger(
44
+ {
45
+ // The recipe's first class is the root part, `{{prefix}}-button`.
46
+ className: classes(
47
+ buttonClass({
48
+ variant,
49
+ size,
50
+ iconOnly: children == null && (iconStart !== undefined || iconEnd !== undefined),
51
+ fullWidth,
52
+ }),
53
+ className,
54
+ ),
55
+ style,
56
+ disabled,
57
+ // Loading keeps the button focusable, so focus is not lost while it waits.
58
+ "aria-disabled": loading || undefined,
59
+ "data-pending": loading ? "" : undefined,
60
+ "aria-pressed": selected,
61
+ "aria-label": label,
62
+ onClick: () => {
63
+ // The press was taken already.
64
+ if (!loading) onPress?.();
65
+ },
66
+ },
67
+ loading,
68
+ );
69
+ return (
70
+ // oxlint-disable-next-line react/button-has-type -- one of the three types, from the props
71
+ <button {...attributes} type={type}>
72
+ {loading &&
73
+ (iconStart ? (
74
+ // Where the icon was, so the button keeps its width.
75
+ <span className={icon.box}>
76
+ <Spinner size="sm" />
77
+ </span>
78
+ ) : (
79
+ <Spinner size="sm" />
80
+ ))}
81
+ {iconStart && !loading && (
82
+ <Icon name={iconStart} size={icon.size} filled={isHeld({ variant, selected, disabled })} />
83
+ )}
84
+ {children}
85
+ {iconEnd && <Icon name={iconEnd} size={icon.size} />}
86
+ </button>
87
+ );
88
+ }
@@ -0,0 +1,85 @@
1
+ // Ejected from `@xds/react` 0.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 } from "@xds/react/base";
5
+ import type { ReactNode } from "react";
6
+ import { CARD_PARTS, type CardBaseProps, cardClass, cardMediaClass } from "./card.ts";
7
+ import { classes, rootPart } from "./parts.ts";
8
+
9
+ export type CardProps = CardBaseProps &
10
+ RootProps & {
11
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
12
+ actions?: ReactNode;
13
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
14
+ media?: ReactNode;
15
+ /** Makes the whole card one button. Put no other control inside it then. */
16
+ onPress?: () => void;
17
+ children?: ReactNode;
18
+ };
19
+
20
+ /**
21
+ * A surface that groups related content. A hairline outline and a trace of shadow lift it off
22
+ * the page; in dark mode, where shadows barely show, the lighter fill does that. `title`
23
+ * renders as a heading; `actions` sit across from it.
24
+ */
25
+ export function Card({
26
+ title,
27
+ description,
28
+ actions,
29
+ media,
30
+ flush = false,
31
+ onPress,
32
+ selected,
33
+ className,
34
+ style,
35
+ children,
36
+ }: CardProps) {
37
+ const surface = classes(
38
+ rootPart("Card"),
39
+ cardClass({ selected, flush, pressable: onPress !== undefined }),
40
+ className,
41
+ );
42
+ // A button may hold only phrasing content, so inside one the parts are spans. Its heading
43
+ // would not be reachable as a heading anyway: a button reads as its text.
44
+ const [Header, Box, Title, Line] = onPress
45
+ ? (["span", "span", "span", "span"] as const)
46
+ : (["header", "div", "h2", "p"] as const);
47
+ const parts = (
48
+ <>
49
+ {media != null && <Box className={cardMediaClass(flush)}>{media}</Box>}
50
+ {(title || (actions && !onPress)) && (
51
+ <Header className={CARD_PARTS.header}>
52
+ <Box className={CARD_PARTS.heading}>
53
+ {title && <Title className={CARD_PARTS.title}>{title}</Title>}
54
+ {description && <Line className={CARD_PARTS.description}>{description}</Line>}
55
+ </Box>
56
+ {actions && !onPress && <div className={CARD_PARTS.actions}>{actions}</div>}
57
+ </Header>
58
+ )}
59
+ {children}
60
+ </>
61
+ );
62
+ const content = flush ? <Box className={CARD_PARTS.flush}>{parts}</Box> : parts;
63
+ if (!onPress) {
64
+ return (
65
+ <section
66
+ {...(selected ? { "aria-current": "true" as const } : {})}
67
+ className={surface}
68
+ style={style}
69
+ >
70
+ {content}
71
+ </section>
72
+ );
73
+ }
74
+ return (
75
+ <button
76
+ type="button"
77
+ onClick={onPress}
78
+ {...(selected === undefined ? {} : { "aria-pressed": selected })}
79
+ className={surface}
80
+ style={style}
81
+ >
82
+ {content}
83
+ </button>
84
+ );
85
+ }
@@ -0,0 +1,59 @@
1
+ // Ejected from `@xds/react` 0.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 } from "@xds/react/base";
5
+ import {
6
+ CHECKBOX_MARK,
7
+ type CheckboxBaseProps,
8
+ checkboxBoxClass,
9
+ checkboxClass,
10
+ checkboxLabelClass,
11
+ checkboxMarkClass,
12
+ } from "./checkbox.ts";
13
+ import { classes, rootPart } from "./parts.ts";
14
+
15
+ export type CheckboxProps = CheckboxBaseProps &
16
+ RootProps & {
17
+ onChange: (checked: boolean) => void;
18
+ };
19
+
20
+ /**
21
+ * A choice that is applied later, with the form it belongs to. A native checkbox: the input is
22
+ * hidden and the box is drawn beside it.
23
+ */
24
+ export function Checkbox({
25
+ checked,
26
+ onChange,
27
+ label,
28
+ name,
29
+ disabled = false,
30
+ className,
31
+ style,
32
+ ...aria
33
+ }: CheckboxProps) {
34
+ return (
35
+ <label className={classes(rootPart("Checkbox"), checkboxClass, className)} style={style}>
36
+ <input
37
+ {...aria}
38
+ type="checkbox"
39
+ className="peer sr-only"
40
+ checked={checked}
41
+ disabled={disabled}
42
+ onChange={(event) => onChange(event.target.checked)}
43
+ {...(name ? { name } : {})}
44
+ />
45
+ <span className={checkboxBoxClass}>
46
+ <svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className={checkboxMarkClass}>
47
+ <path
48
+ d={CHECKBOX_MARK}
49
+ stroke="currentColor"
50
+ strokeWidth="2"
51
+ strokeLinecap="round"
52
+ strokeLinejoin="round"
53
+ />
54
+ </svg>
55
+ </span>
56
+ {label && <span className={checkboxLabelClass}>{label}</span>}
57
+ </label>
58
+ );
59
+ }