@xds/react 0.0.0-stage → 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 (190) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/Accordion.d.ts +20 -0
  4. package/dist/Accordion.js +197 -0
  5. package/dist/Avatar.d.ts +9 -0
  6. package/dist/Avatar.js +69 -0
  7. package/dist/AvatarStack.d.ts +8 -0
  8. package/dist/AvatarStack.js +105 -0
  9. package/dist/Badge.d.ts +13 -0
  10. package/dist/Badge.js +66 -0
  11. package/dist/Banner.d.ts +23 -0
  12. package/dist/Banner.js +166 -0
  13. package/dist/Button.d.ts +14 -0
  14. package/dist/Button.js +159 -0
  15. package/dist/Card.d.ts +18 -0
  16. package/dist/Card.js +173 -0
  17. package/dist/Checkbox.d.ts +10 -0
  18. package/dist/Checkbox.js +140 -0
  19. package/dist/Chip.d.ts +12 -0
  20. package/dist/Chip.js +74 -0
  21. package/dist/ChipBar.d.ts +12 -0
  22. package/dist/ChipBar.js +38 -0
  23. package/dist/CountBadge.d.ts +12 -0
  24. package/dist/CountBadge.js +64 -0
  25. package/dist/DatePicker.d.ts +20 -0
  26. package/dist/DatePicker.js +429 -0
  27. package/dist/DateRangePicker.d.ts +24 -0
  28. package/dist/DateRangePicker.js +370 -0
  29. package/dist/Defaults.d.ts +17 -0
  30. package/dist/Defaults.js +48 -0
  31. package/dist/Dialog.d.ts +20 -0
  32. package/dist/Dialog.js +137 -0
  33. package/dist/Divider.d.ts +4 -0
  34. package/dist/Divider.js +31 -0
  35. package/dist/EmptyState.d.ts +12 -0
  36. package/dist/EmptyState.js +86 -0
  37. package/dist/Icon.d.ts +9 -0
  38. package/dist/Icon.js +79 -0
  39. package/dist/IconButton.d.ts +12 -0
  40. package/dist/IconButton.js +119 -0
  41. package/dist/ListRow.d.ts +21 -0
  42. package/dist/ListRow.js +185 -0
  43. package/dist/MediaCard.d.ts +20 -0
  44. package/dist/MediaCard.js +279 -0
  45. package/dist/Menu.d.ts +18 -0
  46. package/dist/Menu.js +244 -0
  47. package/dist/ProgressBar.d.ts +8 -0
  48. package/dist/ProgressBar.js +65 -0
  49. package/dist/RadioGroup.d.ts +15 -0
  50. package/dist/RadioGroup.js +176 -0
  51. package/dist/SearchField.d.ts +15 -0
  52. package/dist/SearchField.js +152 -0
  53. package/dist/SectionHeader.d.ts +14 -0
  54. package/dist/SectionHeader.js +124 -0
  55. package/dist/SegmentedControl.d.ts +12 -0
  56. package/dist/SegmentedControl.js +106 -0
  57. package/dist/Select.d.ts +18 -0
  58. package/dist/Select.js +318 -0
  59. package/dist/Sidebar.d.ts +21 -0
  60. package/dist/Sidebar.js +220 -0
  61. package/dist/Skeleton.d.ts +11 -0
  62. package/dist/Skeleton.js +64 -0
  63. package/dist/Slider.d.ts +13 -0
  64. package/dist/Slider.js +151 -0
  65. package/dist/Spinner.d.ts +9 -0
  66. package/dist/Spinner.js +97 -0
  67. package/dist/Switch.d.ts +13 -0
  68. package/dist/Switch.js +116 -0
  69. package/dist/Tabs.d.ts +14 -0
  70. package/dist/Tabs.js +137 -0
  71. package/dist/Text.d.ts +10 -0
  72. package/dist/Text.js +46 -0
  73. package/dist/TextField.d.ts +22 -0
  74. package/dist/TextField.js +213 -0
  75. package/dist/Thumbnail.d.ts +9 -0
  76. package/dist/Thumbnail.js +152 -0
  77. package/dist/Toast.d.ts +14 -0
  78. package/dist/Toast.js +121 -0
  79. package/dist/Tooltip.d.ts +26 -0
  80. package/dist/Tooltip.js +166 -0
  81. package/dist/base.d.ts +11 -0
  82. package/dist/base.js +10 -0
  83. package/dist/index.d.ts +39 -0
  84. package/dist/index.js +39 -0
  85. package/dist/modal-popover.d.ts +7 -0
  86. package/dist/modal-popover.js +37 -0
  87. package/dist/picture.d.ts +13 -0
  88. package/dist/picture.js +76 -0
  89. package/dist/portal.d.ts +9 -0
  90. package/dist/portal.js +27 -0
  91. package/dist/presence.d.ts +6 -0
  92. package/dist/presence.js +34 -0
  93. package/dist/preview.d.ts +17 -0
  94. package/dist/preview.js +126 -0
  95. package/dist/root.d.ts +12 -0
  96. package/dist/root.js +1 -0
  97. package/dist/trigger.d.ts +24 -0
  98. package/dist/trigger.js +47 -0
  99. package/eject/files/Accordion.tsx +157 -0
  100. package/eject/files/Avatar.tsx +41 -0
  101. package/eject/files/AvatarStack.tsx +47 -0
  102. package/eject/files/Badge.tsx +33 -0
  103. package/eject/files/Banner.tsx +70 -0
  104. package/eject/files/Button.tsx +88 -0
  105. package/eject/files/Card.tsx +85 -0
  106. package/eject/files/Checkbox.tsx +59 -0
  107. package/eject/files/Chip.tsx +43 -0
  108. package/eject/files/ChipBar.tsx +31 -0
  109. package/eject/files/CountBadge.tsx +50 -0
  110. package/eject/files/DatePicker.tsx +192 -0
  111. package/eject/files/DateRangePicker.tsx +271 -0
  112. package/eject/files/Dialog.tsx +108 -0
  113. package/eject/files/Divider.tsx +13 -0
  114. package/eject/files/EmptyState.tsx +39 -0
  115. package/eject/files/Icon.tsx +38 -0
  116. package/eject/files/IconButton.tsx +62 -0
  117. package/eject/files/ListRow.tsx +86 -0
  118. package/eject/files/MediaCard.tsx +111 -0
  119. package/eject/files/Menu.tsx +168 -0
  120. package/eject/files/ProgressBar.tsx +34 -0
  121. package/eject/files/RadioGroup.tsx +112 -0
  122. package/eject/files/SearchField.tsx +88 -0
  123. package/eject/files/SectionHeader.tsx +56 -0
  124. package/eject/files/SegmentedControl.tsx +57 -0
  125. package/eject/files/Select.tsx +228 -0
  126. package/eject/files/Sidebar.tsx +149 -0
  127. package/eject/files/Skeleton.tsx +28 -0
  128. package/eject/files/Slider.tsx +109 -0
  129. package/eject/files/Spinner.tsx +36 -0
  130. package/eject/files/Switch.tsx +53 -0
  131. package/eject/files/Tabs.tsx +71 -0
  132. package/eject/files/Text.tsx +31 -0
  133. package/eject/files/TextField.tsx +122 -0
  134. package/eject/files/Thumbnail.tsx +66 -0
  135. package/eject/files/Toast.tsx +88 -0
  136. package/eject/files/Tooltip.tsx +120 -0
  137. package/eject/files/accordion.css +89 -0
  138. package/eject/files/accordion.ts +67 -0
  139. package/eject/files/avatar-stack.ts +57 -0
  140. package/eject/files/avatar.ts +42 -0
  141. package/eject/files/badge.ts +30 -0
  142. package/eject/files/banner.ts +68 -0
  143. package/eject/files/base.css +38 -0
  144. package/eject/files/button.css +241 -0
  145. package/eject/files/button.ts +106 -0
  146. package/eject/files/card.ts +58 -0
  147. package/eject/files/checkbox.ts +32 -0
  148. package/eject/files/chip-bar.ts +16 -0
  149. package/eject/files/chip.ts +35 -0
  150. package/eject/files/count-badge.ts +32 -0
  151. package/eject/files/date-picker.css +352 -0
  152. package/eject/files/date-picker.ts +250 -0
  153. package/eject/files/date-range-picker.ts +323 -0
  154. package/eject/files/dialog.css +139 -0
  155. package/eject/files/dialog.ts +15 -0
  156. package/eject/files/divider.ts +5 -0
  157. package/eject/files/empty-state.ts +22 -0
  158. package/eject/files/icon.ts +36 -0
  159. package/eject/files/list-row.ts +66 -0
  160. package/eject/files/media-card.ts +66 -0
  161. package/eject/files/menu.css +176 -0
  162. package/eject/files/menu.ts +84 -0
  163. package/eject/files/parts.ts +17 -0
  164. package/eject/files/progress-bar.ts +23 -0
  165. package/eject/files/radio-group.css +160 -0
  166. package/eject/files/radio-group.ts +24 -0
  167. package/eject/files/section-header.ts +32 -0
  168. package/eject/files/segmented-control.ts +30 -0
  169. package/eject/files/select.css +285 -0
  170. package/eject/files/select.ts +36 -0
  171. package/eject/files/sidebar.ts +75 -0
  172. package/eject/files/skeleton.ts +51 -0
  173. package/eject/files/slider.css +136 -0
  174. package/eject/files/slider.ts +65 -0
  175. package/eject/files/spinner.ts +22 -0
  176. package/eject/files/switch.ts +34 -0
  177. package/eject/files/tabs.css +112 -0
  178. package/eject/files/tabs.ts +35 -0
  179. package/eject/files/text-field.css +229 -0
  180. package/eject/files/text-field.ts +48 -0
  181. package/eject/files/text.ts +38 -0
  182. package/eject/files/thumbnail.ts +51 -0
  183. package/eject/files/toast.ts +31 -0
  184. package/eject/files/tooltip.css +104 -0
  185. package/eject/files/tooltip.ts +21 -0
  186. package/eject/manifest.json +814 -0
  187. package/package.json +66 -4
  188. package/page.css +20 -0
  189. package/styles.css +3252 -0
  190. package/tailwind.css +2665 -0
package/dist/base.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export { type IconName, icons, motion, space } from "@xds/tokens";
2
+ export { AVATAR_SIZE, type AvatarSize, afterAnimations, buttonClass, focusWithoutRing, type IconSize, initials, keepListKeys, leaveEscapeToFields, PEER_FOCUS, PRESSABLE_ROW, pictureClass, switchClass, switchLabelClass, type ThumbnailRatio, } from "@xds/core";
3
+ export { useDefaults } from "./Defaults.tsx";
4
+ export { PlaceRow } from "./ListRow.tsx";
5
+ export { useModalPopover } from "./modal-popover.ts";
6
+ export { usePicture } from "./picture.ts";
7
+ export { Portal } from "./portal.tsx";
8
+ export { usePresence } from "./presence.ts";
9
+ export type { RootProps } from "./root.ts";
10
+ export { TooltipBeside } from "./Tooltip.tsx";
11
+ export { TriggerContext, type TriggerProps, useMergedProps, useProvideTrigger, useTrigger, } from "./trigger.ts";
package/dist/base.js ADDED
@@ -0,0 +1,10 @@
1
+ export { icons, motion, space } from "@xds/tokens";
2
+ export { AVATAR_SIZE, afterAnimations, buttonClass, focusWithoutRing, initials, keepListKeys, leaveEscapeToFields, PEER_FOCUS, PRESSABLE_ROW, pictureClass, switchClass, switchLabelClass } from "@xds/core";
3
+ export { useDefaults } from "./Defaults.js";
4
+ export { PlaceRow } from "./ListRow.js";
5
+ export { useModalPopover } from "./modal-popover.js";
6
+ export { usePicture } from "./picture.js";
7
+ export { Portal } from "./portal.js";
8
+ export { usePresence } from "./presence.js";
9
+ export { TooltipBeside } from "./Tooltip.js";
10
+ export { TriggerContext, useMergedProps, useProvideTrigger, useTrigger } from "./trigger.js";
@@ -0,0 +1,39 @@
1
+ export { Accordion, type AccordionItem, type AccordionProps } from "./Accordion.tsx";
2
+ export { Avatar, type AvatarProps, type AvatarSize } from "./Avatar.tsx";
3
+ export { AvatarStack, type AvatarStackProps } from "./AvatarStack.tsx";
4
+ export { Badge, type BadgeProps, type BadgeTone } from "./Badge.tsx";
5
+ export { Banner, type BannerProps, type BannerTone } from "./Banner.tsx";
6
+ export { Button, type ButtonProps, type ButtonVariant, type ControlSize } from "./Button.tsx";
7
+ export { Card, type CardProps } from "./Card.tsx";
8
+ export { Checkbox, type CheckboxProps } from "./Checkbox.tsx";
9
+ export { Chip, type ChipProps } from "./Chip.tsx";
10
+ export { ChipBar, type ChipBarProps } from "./ChipBar.tsx";
11
+ export { CountBadge, type CountBadgeProps } from "./CountBadge.tsx";
12
+ export { DatePicker, type DatePickerProps, type IsoDate } from "./DatePicker.tsx";
13
+ export { type DateRange, DateRangePicker, type DateRangePickerProps } from "./DateRangePicker.tsx";
14
+ export { type ComponentDefaults, Defaults, type DefaultsProps } from "./Defaults.tsx";
15
+ export { Dialog, type DialogProps } from "./Dialog.tsx";
16
+ export { Divider, type DividerProps } from "./Divider.tsx";
17
+ export { EmptyState, type EmptyStateProps } from "./EmptyState.tsx";
18
+ export { Icon, type IconName, type IconProps, type IconSize } from "./Icon.tsx";
19
+ export { IconButton, type IconButtonProps } from "./IconButton.tsx";
20
+ export { ListRow, type ListRowProps } from "./ListRow.tsx";
21
+ export { MediaCard, type MediaCardProps } from "./MediaCard.tsx";
22
+ export { Menu, type MenuItem, type MenuProps } from "./Menu.tsx";
23
+ export { ProgressBar, type ProgressBarProps } from "./ProgressBar.tsx";
24
+ export { RadioGroup, type RadioGroupProps, type RadioOption } from "./RadioGroup.tsx";
25
+ export { SearchField, type SearchFieldProps } from "./SearchField.tsx";
26
+ export { SectionHeader, type SectionHeaderProps } from "./SectionHeader.tsx";
27
+ export { SegmentedControl, type SegmentedControlProps } from "./SegmentedControl.tsx";
28
+ export { Select, type SelectOption, type SelectProps } from "./Select.tsx";
29
+ export { Sidebar, type SidebarItem, type SidebarProps, type SidebarSection } from "./Sidebar.tsx";
30
+ export { Skeleton, type SkeletonProps } from "./Skeleton.tsx";
31
+ export { Slider, type SliderProps } from "./Slider.tsx";
32
+ export { Spinner, type SpinnerProps } from "./Spinner.tsx";
33
+ export { Switch, type SwitchProps } from "./Switch.tsx";
34
+ export { Tabs, type TabsProps } from "./Tabs.tsx";
35
+ export { Text, type TextProps, type TextTone, type TextVariant } from "./Text.tsx";
36
+ export { TextField, type TextFieldProps } from "./TextField.tsx";
37
+ export { Thumbnail, type ThumbnailProps, type ThumbnailRatio } from "./Thumbnail.tsx";
38
+ export { Toast, type ToastProps } from "./Toast.tsx";
39
+ export { Tooltip, type TooltipProps } from "./Tooltip.tsx";
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ export { Accordion } from "./Accordion.js";
2
+ export { Avatar } from "./Avatar.js";
3
+ export { AvatarStack } from "./AvatarStack.js";
4
+ export { Badge } from "./Badge.js";
5
+ export { Banner } from "./Banner.js";
6
+ export { Button } from "./Button.js";
7
+ export { Card } from "./Card.js";
8
+ export { Checkbox } from "./Checkbox.js";
9
+ export { Chip } from "./Chip.js";
10
+ export { ChipBar } from "./ChipBar.js";
11
+ export { CountBadge } from "./CountBadge.js";
12
+ export { DatePicker } from "./DatePicker.js";
13
+ export { DateRangePicker } from "./DateRangePicker.js";
14
+ export { Defaults } from "./Defaults.js";
15
+ export { Dialog } from "./Dialog.js";
16
+ export { Divider } from "./Divider.js";
17
+ export { EmptyState } from "./EmptyState.js";
18
+ export { Icon } from "./Icon.js";
19
+ export { IconButton } from "./IconButton.js";
20
+ export { ListRow } from "./ListRow.js";
21
+ export { MediaCard } from "./MediaCard.js";
22
+ export { Menu } from "./Menu.js";
23
+ export { ProgressBar } from "./ProgressBar.js";
24
+ export { RadioGroup } from "./RadioGroup.js";
25
+ export { SearchField } from "./SearchField.js";
26
+ export { SectionHeader } from "./SectionHeader.js";
27
+ export { SegmentedControl } from "./SegmentedControl.js";
28
+ export { Select } from "./Select.js";
29
+ export { Sidebar } from "./Sidebar.js";
30
+ export { Skeleton } from "./Skeleton.js";
31
+ export { Slider } from "./Slider.js";
32
+ export { Spinner } from "./Spinner.js";
33
+ export { Switch } from "./Switch.js";
34
+ export { Tabs } from "./Tabs.js";
35
+ export { Text } from "./Text.js";
36
+ export { TextField } from "./TextField.js";
37
+ export { Thumbnail } from "./Thumbnail.js";
38
+ export { Toast } from "./Toast.js";
39
+ export { Tooltip } from "./Tooltip.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Makes an open Menu or Select list modal while `open` is true: the rest of the page is hidden
3
+ * from assistive technology, so a screen reader's cursor stays in the popup, where the focus is
4
+ * held too, and the page does not scroll. The popup's underlay keeps the pointer off the page.
5
+ * Zag does all of this around a dialog, but not around a menu or a select.
6
+ */
7
+ export declare function useModalPopover(open: boolean, popup: () => HTMLElement | null): void;
@@ -0,0 +1,37 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { ariaHidden } from "@zag-js/aria-hidden";
3
+ import { preventBodyScroll } from "@zag-js/remove-scroll";
4
+ import { useEffect } from "react";
5
+ export function useModalPopover(open, popup) {
6
+ const $ = _c(5);
7
+ let t0;
8
+ if ($[0] !== open || $[1] !== popup) {
9
+ t0 = () => {
10
+ if (!open) {
11
+ return;
12
+ }
13
+ const unlock = preventBodyScroll(document);
14
+ const reveal = ariaHidden(() => [popup()], {
15
+ defer: true
16
+ });
17
+ return () => {
18
+ reveal();
19
+ unlock();
20
+ };
21
+ };
22
+ $[0] = open;
23
+ $[1] = popup;
24
+ $[2] = t0;
25
+ } else {
26
+ t0 = $[2];
27
+ }
28
+ let t1;
29
+ if ($[3] !== open) {
30
+ t1 = [open];
31
+ $[3] = open;
32
+ $[4] = t1;
33
+ } else {
34
+ t1 = $[4];
35
+ }
36
+ useEffect(t0, t1);
37
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Follows the loading of the picture at `src`. `loaded` is undefined while it loads, then true
3
+ * or false. The result is remembered with the address it belongs to, so a new `src` starts
4
+ * over without an effect. Spread `image` on the `<img>`.
5
+ */
6
+ export declare function usePicture(src: string | undefined): {
7
+ loaded: boolean | undefined;
8
+ image: {
9
+ ref: (image: HTMLImageElement | null) => void;
10
+ onLoad: () => void;
11
+ onError: () => void;
12
+ };
13
+ };
@@ -0,0 +1,76 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useState } from "react";
3
+ export function usePicture(src) {
4
+ const $ = _c(13);
5
+ const [picture, setPicture] = useState();
6
+ const loaded = picture !== undefined && picture.src === src ? picture.loaded : undefined;
7
+ let t0;
8
+ if ($[0] !== loaded || $[1] !== src) {
9
+ t0 = image => {
10
+ if (src && image?.complete && image.naturalWidth > 0 && loaded === undefined) {
11
+ setPicture({
12
+ src,
13
+ loaded: true
14
+ });
15
+ }
16
+ };
17
+ $[0] = loaded;
18
+ $[1] = src;
19
+ $[2] = t0;
20
+ } else {
21
+ t0 = $[2];
22
+ }
23
+ let t1;
24
+ let t2;
25
+ if ($[3] !== src) {
26
+ t1 = () => {
27
+ if (src) {
28
+ setPicture({
29
+ src,
30
+ loaded: true
31
+ });
32
+ }
33
+ };
34
+ t2 = () => {
35
+ if (src) {
36
+ setPicture({
37
+ src,
38
+ loaded: false
39
+ });
40
+ }
41
+ };
42
+ $[3] = src;
43
+ $[4] = t1;
44
+ $[5] = t2;
45
+ } else {
46
+ t1 = $[4];
47
+ t2 = $[5];
48
+ }
49
+ let t3;
50
+ if ($[6] !== t0 || $[7] !== t1 || $[8] !== t2) {
51
+ t3 = {
52
+ ref: t0,
53
+ onLoad: t1,
54
+ onError: t2
55
+ };
56
+ $[6] = t0;
57
+ $[7] = t1;
58
+ $[8] = t2;
59
+ $[9] = t3;
60
+ } else {
61
+ t3 = $[9];
62
+ }
63
+ let t4;
64
+ if ($[10] !== loaded || $[11] !== t3) {
65
+ t4 = {
66
+ loaded,
67
+ image: t3
68
+ };
69
+ $[10] = loaded;
70
+ $[11] = t3;
71
+ $[12] = t4;
72
+ } else {
73
+ t4 = $[12];
74
+ }
75
+ return t4;
76
+ }
@@ -0,0 +1,9 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * Renders `children` at the end of the body, where an overlay is above the page. A page
4
+ * rendered by a server has no body to render into, and the render that hydrates it must match
5
+ * the server's, so there the overlay comes in the render after.
6
+ */
7
+ export declare function Portal({ children }: {
8
+ children: ReactNode;
9
+ }): import("react").ReactPortal | null;
package/dist/portal.js ADDED
@@ -0,0 +1,27 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useSyncExternalStore } from "react";
3
+ import { createPortal } from "react-dom";
4
+ const subscribe = () => () => {};
5
+ export function Portal(t0) {
6
+ const $ = _c(3);
7
+ const {
8
+ children
9
+ } = t0;
10
+ const client = useSyncExternalStore(subscribe, _temp, _temp2);
11
+ let t1;
12
+ if ($[0] !== children || $[1] !== client) {
13
+ t1 = client ? createPortal(children, document.body) : null;
14
+ $[0] = children;
15
+ $[1] = client;
16
+ $[2] = t1;
17
+ } else {
18
+ t1 = $[2];
19
+ }
20
+ return t1;
21
+ }
22
+ function _temp2() {
23
+ return false;
24
+ }
25
+ function _temp() {
26
+ return true;
27
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether an overlay is on the page: from when it opens until the exit animation that its
3
+ * stylesheet starts on `[data-state="closed"]` has finished. Zag hides a closed part at once.
4
+ * `parts` returns the elements that animate; it is read once the closed state is rendered.
5
+ */
6
+ export declare function usePresence(open: boolean, parts: () => readonly (Element | null | undefined)[]): boolean;
@@ -0,0 +1,34 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { afterAnimations } from "@xds/core";
3
+ import { useEffect, useState } from "react";
4
+ export function usePresence(open, parts) {
5
+ const $ = _c(5);
6
+ const [exited, setExited] = useState(!open);
7
+ if (open && exited) {
8
+ setExited(false);
9
+ }
10
+ let t0;
11
+ if ($[0] !== open || $[1] !== parts) {
12
+ t0 = () => {
13
+ if (open) {
14
+ return;
15
+ }
16
+ return afterAnimations(parts(), () => setExited(true));
17
+ };
18
+ $[0] = open;
19
+ $[1] = parts;
20
+ $[2] = t0;
21
+ } else {
22
+ t0 = $[2];
23
+ }
24
+ let t1;
25
+ if ($[3] !== open) {
26
+ t1 = [open];
27
+ $[3] = open;
28
+ $[4] = t1;
29
+ } else {
30
+ t1 = $[4];
31
+ }
32
+ useEffect(t0, t1);
33
+ return open || !exited;
34
+ }
@@ -0,0 +1,17 @@
1
+ import { type ComponentName, type Components, type Screen } from "@xds/core/preview";
2
+ import { type ComponentType, type ReactNode } from "react";
3
+ export { designPreview } from "@xds/core/preview";
4
+ type Given<N extends ComponentName> = Omit<Components<ReactNode>[N], "class"> & ("class" extends keyof Components<ReactNode>[N] ? {
5
+ className?: Components<ReactNode>[N]["class"];
6
+ } : unknown);
7
+ /**
8
+ * Components to draw in place of the library's, by name: an app's ejected copies (`xds eject`),
9
+ * which the design preview then shows as it shows the library's.
10
+ */
11
+ export type PreviewComponents = {
12
+ [N in ComponentName]?: ComponentType<Given<N>>;
13
+ };
14
+ export declare function Preview({ screen, components, }: {
15
+ screen: Screen;
16
+ components?: PreviewComponents;
17
+ }): ReactNode;
@@ -0,0 +1,126 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { isNode, resolve } from "@xds/core/preview";
3
+ import { createElement, Fragment, useEffect, useState } from "react";
4
+ import { Accordion, Avatar, AvatarStack, Badge, Banner, Button, Card, Checkbox, Chip, ChipBar, CountBadge, DatePicker, DateRangePicker, Defaults, Dialog, Divider, EmptyState, Icon, IconButton, ListRow, MediaCard, Menu, ProgressBar, RadioGroup, SearchField, SectionHeader, SegmentedControl, Select, Sidebar, Skeleton, Slider, Spinner, Switch, Tabs, Text, TextField, Thumbnail, Toast, Tooltip } from "./index.js";
5
+ export { designPreview } from "@xds/core/preview";
6
+ const COMPONENTS = {
7
+ Accordion,
8
+ Avatar,
9
+ AvatarStack,
10
+ Badge,
11
+ Banner,
12
+ Button,
13
+ Card,
14
+ Checkbox,
15
+ Chip,
16
+ ChipBar,
17
+ CountBadge,
18
+ DatePicker,
19
+ DateRangePicker,
20
+ Defaults,
21
+ Dialog,
22
+ Divider,
23
+ EmptyState,
24
+ Icon,
25
+ IconButton,
26
+ ListRow,
27
+ MediaCard,
28
+ Menu,
29
+ ProgressBar,
30
+ RadioGroup,
31
+ SearchField,
32
+ SectionHeader,
33
+ SegmentedControl,
34
+ Select,
35
+ Sidebar,
36
+ Skeleton,
37
+ Slider,
38
+ Spinner,
39
+ Switch,
40
+ Tabs,
41
+ Text,
42
+ TextField,
43
+ Thumbnail,
44
+ Toast,
45
+ Tooltip
46
+ };
47
+ const _lacking = {};
48
+ const camel = name => name.startsWith("--") ? name : name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
49
+ export function Preview(t0) {
50
+ const $ = _c(8);
51
+ const {
52
+ screen,
53
+ components
54
+ } = t0;
55
+ const [state, setState] = useState(screen.state);
56
+ let t1;
57
+ let t2;
58
+ if ($[0] !== screen) {
59
+ t1 = () => screen.mount?.();
60
+ t2 = [screen];
61
+ $[0] = screen;
62
+ $[1] = t1;
63
+ $[2] = t2;
64
+ } else {
65
+ t1 = $[1];
66
+ t2 = $[2];
67
+ }
68
+ useEffect(t1, t2);
69
+ let t3;
70
+ if ($[3] !== components || $[4] !== screen.root || $[5] !== state) {
71
+ let t4;
72
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
73
+ t4 = patch => setState(current => ({
74
+ ...current,
75
+ ...patch
76
+ }));
77
+ $[7] = t4;
78
+ } else {
79
+ t4 = $[7];
80
+ }
81
+ const host = {
82
+ state,
83
+ set: t4,
84
+ draw: slot => {
85
+ if (Array.isArray(slot)) {
86
+ return createElement(Fragment, null, ...slot.map(host.draw));
87
+ }
88
+ if (typeof slot === "function") {
89
+ return slot(state);
90
+ }
91
+ if (!isNode(slot)) {
92
+ return slot;
93
+ }
94
+ if (slot.kind === "show") {
95
+ return host.draw(slot.when(state) ? slot.children : slot.fallback);
96
+ }
97
+ const props = {};
98
+ for (const [key, value] of Object.entries(slot.props)) {
99
+ if (key === "class") {
100
+ props.className = resolve(value, key, host);
101
+ } else {
102
+ if (key === "style") {
103
+ props.style = Object.fromEntries(Object.entries(value).map(_temp));
104
+ } else {
105
+ props[key] = resolve(value, key, host);
106
+ }
107
+ }
108
+ }
109
+ const type = slot.kind === "element" ? slot.tag : components?.[slot.name] ?? COMPONENTS[slot.name];
110
+ return createElement(type, props, ...slot.children.map(host.draw));
111
+ }
112
+ };
113
+ t3 = host.draw(screen.root);
114
+ $[3] = components;
115
+ $[4] = screen.root;
116
+ $[5] = state;
117
+ $[6] = t3;
118
+ } else {
119
+ t3 = $[6];
120
+ }
121
+ return t3;
122
+ }
123
+ function _temp(t0) {
124
+ const [name, css] = t0;
125
+ return [camel(name), css];
126
+ }
package/dist/root.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { CSSProperties } from "react";
2
+ /**
3
+ * What every component takes for its root element, its outermost one, or the surface of an
4
+ * overlay: the panel of a Dialog, a Menu, a Tooltip or a Toast. The element always has its root
5
+ * part `xds-<name>` as well, the stable handle for an app's own styles.
6
+ */
7
+ export type RootProps = {
8
+ /** Classes for the root element, after the component's own. */
9
+ className?: string;
10
+ /** An inline style for the root element. What it sets wins over the component's own. */
11
+ style?: CSSProperties;
12
+ };
package/dist/root.js ADDED
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,24 @@
1
+ import { mergeProps } from "@zag-js/react";
2
+ /** The props an overlay's machine has for the control that opens it. */
3
+ export type TriggerProps = Record<string, unknown>;
4
+ /** Not exported from the package: only this package's controls and overlays use it. */
5
+ export declare const TriggerContext: import("react").Context<TriggerProps | null>;
6
+ /**
7
+ * For an overlay: its trigger props, joined with those of any overlay around it, to provide as
8
+ * `<TriggerContext value={...}>` around the control. A Tooltip around a Menu's button gives the
9
+ * button both sets; the handlers of both run.
10
+ */
11
+ export declare function useProvideTrigger(own: TriggerProps): TriggerProps;
12
+ /**
13
+ * For a control that can open an overlay: its own props, after those of the overlays it opens.
14
+ * Its own attributes win, its own handlers run first, and its class is added to theirs. While
15
+ * `inert` is true, as for a loading button, the overlays get none of its events and so do not
16
+ * open. Spread the result on the element.
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;
@@ -0,0 +1,47 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { mergeProps } from "@zag-js/react";
3
+ import { createContext, useContext } from "react";
4
+ export const TriggerContext = createContext(null);
5
+ export function useProvideTrigger(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;
26
+ }
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;
42
+ }
43
+ function _temp(t0) {
44
+ const [key] = t0;
45
+ return !key.startsWith("on");
46
+ }
47
+ export const useMergedProps = (...sets) => mergeProps(...sets);