@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
@@ -0,0 +1,213 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { classes } from "@xds/core";
3
+ import { useId } from "react";
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
+ export function TextField(t0) {
6
+ const $ = _c(51);
7
+ const {
8
+ label,
9
+ value,
10
+ onChange,
11
+ description,
12
+ error,
13
+ placeholder,
14
+ leading,
15
+ trailing,
16
+ multiline: t1,
17
+ rows: t2,
18
+ maxLength,
19
+ name,
20
+ type: t3,
21
+ inputMode,
22
+ autoComplete,
23
+ autoFocus: t4,
24
+ required: t5,
25
+ disabled: t6,
26
+ className,
27
+ style
28
+ } = t0;
29
+ const multiline = t1 === undefined ? false : t1;
30
+ const rows = t2 === undefined ? 3 : t2;
31
+ const type = t3 === undefined ? "text" : t3;
32
+ const autoFocus = t4 === undefined ? false : t4;
33
+ const required = t5 === undefined ? false : t5;
34
+ const disabled = t6 === undefined ? false : t6;
35
+ const id = useId();
36
+ const descriptionId = `${id}-description`;
37
+ const errorId = `${id}-error`;
38
+ const invalid = error !== undefined;
39
+ const grouped = leading != null || trailing != null;
40
+ const t7 = grouped ? "xds-text-field__input" : "xds-text-field__input xds-text-field__control";
41
+ const t8 = invalid || undefined;
42
+ const t9 = invalid ? errorId : undefined;
43
+ const t10 = invalid ? errorId : description ? descriptionId : undefined;
44
+ let t11;
45
+ if ($[0] !== autoComplete || $[1] !== autoFocus || $[2] !== disabled || $[3] !== id || $[4] !== inputMode || $[5] !== maxLength || $[6] !== name || $[7] !== placeholder || $[8] !== required || $[9] !== t10 || $[10] !== t7 || $[11] !== t8 || $[12] !== t9 || $[13] !== value) {
46
+ t11 = {
47
+ id,
48
+ className: t7,
49
+ value,
50
+ placeholder,
51
+ name,
52
+ maxLength,
53
+ inputMode,
54
+ autoComplete,
55
+ autoFocus,
56
+ required,
57
+ disabled,
58
+ "aria-invalid": t8,
59
+ "aria-errormessage": t9,
60
+ "aria-describedby": t10
61
+ };
62
+ $[0] = autoComplete;
63
+ $[1] = autoFocus;
64
+ $[2] = disabled;
65
+ $[3] = id;
66
+ $[4] = inputMode;
67
+ $[5] = maxLength;
68
+ $[6] = name;
69
+ $[7] = placeholder;
70
+ $[8] = required;
71
+ $[9] = t10;
72
+ $[10] = t7;
73
+ $[11] = t8;
74
+ $[12] = t9;
75
+ $[13] = value;
76
+ $[14] = t11;
77
+ } else {
78
+ t11 = $[14];
79
+ }
80
+ const shared = t11;
81
+ let t12;
82
+ if ($[15] !== multiline || $[16] !== onChange || $[17] !== rows || $[18] !== shared || $[19] !== type) {
83
+ t12 = multiline ? /*#__PURE__*/_jsx("textarea", {
84
+ ...shared,
85
+ rows: rows,
86
+ onChange: event => onChange(event.currentTarget.value)
87
+ }) : /*#__PURE__*/_jsx("input", {
88
+ ...shared,
89
+ type: type,
90
+ onChange: event_0 => onChange(event_0.currentTarget.value)
91
+ });
92
+ $[15] = multiline;
93
+ $[16] = onChange;
94
+ $[17] = rows;
95
+ $[18] = shared;
96
+ $[19] = type;
97
+ $[20] = t12;
98
+ } else {
99
+ t12 = $[20];
100
+ }
101
+ const field = t12;
102
+ let t13;
103
+ if ($[21] !== className) {
104
+ t13 = classes("xds-text-field", className);
105
+ $[21] = className;
106
+ $[22] = t13;
107
+ } else {
108
+ t13 = $[22];
109
+ }
110
+ let t14;
111
+ if ($[23] !== id || $[24] !== label) {
112
+ t14 = /*#__PURE__*/_jsx("label", {
113
+ htmlFor: id,
114
+ className: "xds-text-field__label",
115
+ children: label
116
+ });
117
+ $[23] = id;
118
+ $[24] = label;
119
+ $[25] = t14;
120
+ } else {
121
+ t14 = $[25];
122
+ }
123
+ let t15;
124
+ if ($[26] !== field || $[27] !== grouped || $[28] !== leading || $[29] !== trailing) {
125
+ t15 = grouped ? /*#__PURE__*/_jsxs("div", {
126
+ className: "xds-text-field__control xds-text-field__group",
127
+ children: [leading != null && /*#__PURE__*/_jsx("span", {
128
+ className: "xds-text-field__slot xds-text-field__slot--leading",
129
+ children: leading
130
+ }), field, trailing != null && /*#__PURE__*/_jsx("span", {
131
+ className: "xds-text-field__slot xds-text-field__slot--trailing",
132
+ children: trailing
133
+ })]
134
+ }) : field;
135
+ $[26] = field;
136
+ $[27] = grouped;
137
+ $[28] = leading;
138
+ $[29] = trailing;
139
+ $[30] = t15;
140
+ } else {
141
+ t15 = $[30];
142
+ }
143
+ let t16;
144
+ if ($[31] !== description || $[32] !== descriptionId || $[33] !== invalid) {
145
+ t16 = !invalid && description && /*#__PURE__*/_jsx("span", {
146
+ id: descriptionId,
147
+ className: "xds-text-field__description",
148
+ children: description
149
+ });
150
+ $[31] = description;
151
+ $[32] = descriptionId;
152
+ $[33] = invalid;
153
+ $[34] = t16;
154
+ } else {
155
+ t16 = $[34];
156
+ }
157
+ let t17;
158
+ if ($[35] !== error || $[36] !== errorId) {
159
+ t17 = /*#__PURE__*/_jsx("span", {
160
+ id: errorId,
161
+ className: "xds-text-field__error",
162
+ "aria-live": "polite",
163
+ children: error
164
+ });
165
+ $[35] = error;
166
+ $[36] = errorId;
167
+ $[37] = t17;
168
+ } else {
169
+ t17 = $[37];
170
+ }
171
+ let t18;
172
+ if ($[38] !== maxLength || $[39] !== value) {
173
+ t18 = maxLength !== undefined && /*#__PURE__*/_jsxs("span", {
174
+ className: "ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums",
175
+ children: [value.length, "/", maxLength]
176
+ });
177
+ $[38] = maxLength;
178
+ $[39] = value;
179
+ $[40] = t18;
180
+ } else {
181
+ t18 = $[40];
182
+ }
183
+ let t19;
184
+ if ($[41] !== t16 || $[42] !== t17 || $[43] !== t18) {
185
+ t19 = /*#__PURE__*/_jsxs("div", {
186
+ className: "xds-text-field__footer",
187
+ children: [t16, t17, t18]
188
+ });
189
+ $[41] = t16;
190
+ $[42] = t17;
191
+ $[43] = t18;
192
+ $[44] = t19;
193
+ } else {
194
+ t19 = $[44];
195
+ }
196
+ let t20;
197
+ if ($[45] !== style || $[46] !== t13 || $[47] !== t14 || $[48] !== t15 || $[49] !== t19) {
198
+ t20 = /*#__PURE__*/_jsxs("div", {
199
+ className: t13,
200
+ style: style,
201
+ children: [t14, t15, t19]
202
+ });
203
+ $[45] = style;
204
+ $[46] = t13;
205
+ $[47] = t14;
206
+ $[48] = t15;
207
+ $[49] = t19;
208
+ $[50] = t20;
209
+ } else {
210
+ t20 = $[50];
211
+ }
212
+ return t20;
213
+ }
@@ -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("react").JSX.Element;
@@ -0,0 +1,152 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { classes, pictureClass, rootPart, THUMBNAIL_PARTS, thumbnailBadgeClass, thumbnailClass, thumbnailWatched } from "@xds/core";
3
+ import { Badge } from "./Badge.js";
4
+ import { useDefaults } from "./Defaults.js";
5
+ import { Icon } from "./Icon.js";
6
+ import { usePicture } from "./picture.js";
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
+ export function Thumbnail(props) {
9
+ const $ = _c(37);
10
+ const defaults = useDefaults("Thumbnail");
11
+ const {
12
+ src,
13
+ alt,
14
+ badge,
15
+ progress,
16
+ className,
17
+ style
18
+ } = props;
19
+ const ratio = props.ratio ?? defaults.ratio;
20
+ const picture = usePicture(src);
21
+ let t0;
22
+ let t1;
23
+ let t2;
24
+ let t3;
25
+ let watched;
26
+ if ($[0] !== alt || $[1] !== badge || $[2] !== className || $[3] !== picture.image || $[4] !== picture.loaded || $[5] !== progress || $[6] !== ratio || $[7] !== src || $[8] !== style) {
27
+ watched = thumbnailWatched(progress);
28
+ if ($[14] !== className || $[15] !== ratio) {
29
+ t0 = classes(rootPart("Thumbnail"), thumbnailClass(ratio), className);
30
+ $[14] = className;
31
+ $[15] = ratio;
32
+ $[16] = t0;
33
+ } else {
34
+ t0 = $[16];
35
+ }
36
+ t1 = style;
37
+ let t4;
38
+ if ($[17] !== alt) {
39
+ t4 = alt ? {
40
+ role: "img",
41
+ "aria-label": alt
42
+ } : {
43
+ "aria-hidden": true
44
+ };
45
+ $[17] = alt;
46
+ $[18] = t4;
47
+ } else {
48
+ t4 = $[18];
49
+ }
50
+ let t5;
51
+ if ($[19] !== picture.loaded) {
52
+ t5 = picture.loaded !== true && /*#__PURE__*/_jsx(Icon, {
53
+ name: "image",
54
+ size: "lg"
55
+ });
56
+ $[19] = picture.loaded;
57
+ $[20] = t5;
58
+ } else {
59
+ t5 = $[20];
60
+ }
61
+ let t6;
62
+ if ($[21] !== picture.image || $[22] !== picture.loaded || $[23] !== src) {
63
+ t6 = src && picture.loaded !== false && /*#__PURE__*/_jsx("img", {
64
+ src: src,
65
+ alt: "",
66
+ "aria-hidden": "true",
67
+ className: pictureClass(picture.loaded === true),
68
+ ...picture.image
69
+ });
70
+ $[21] = picture.image;
71
+ $[22] = picture.loaded;
72
+ $[23] = src;
73
+ $[24] = t6;
74
+ } else {
75
+ t6 = $[24];
76
+ }
77
+ if ($[25] !== t4 || $[26] !== t5 || $[27] !== t6) {
78
+ t2 = /*#__PURE__*/_jsxs("span", {
79
+ className: THUMBNAIL_PARTS.placeholder,
80
+ ...t4,
81
+ children: [t5, t6]
82
+ });
83
+ $[25] = t4;
84
+ $[26] = t5;
85
+ $[27] = t6;
86
+ $[28] = t2;
87
+ } else {
88
+ t2 = $[28];
89
+ }
90
+ t3 = badge && /*#__PURE__*/_jsx("span", {
91
+ className: thumbnailBadgeClass(watched),
92
+ children: /*#__PURE__*/_jsx(Badge, {
93
+ tone: "overlay",
94
+ children: badge
95
+ })
96
+ });
97
+ $[0] = alt;
98
+ $[1] = badge;
99
+ $[2] = className;
100
+ $[3] = picture.image;
101
+ $[4] = picture.loaded;
102
+ $[5] = progress;
103
+ $[6] = ratio;
104
+ $[7] = src;
105
+ $[8] = style;
106
+ $[9] = t0;
107
+ $[10] = t1;
108
+ $[11] = t2;
109
+ $[12] = t3;
110
+ $[13] = watched;
111
+ } else {
112
+ t0 = $[9];
113
+ t1 = $[10];
114
+ t2 = $[11];
115
+ t3 = $[12];
116
+ watched = $[13];
117
+ }
118
+ let t4;
119
+ if ($[29] !== watched) {
120
+ t4 = watched > 0 && /*#__PURE__*/_jsx("span", {
121
+ "aria-hidden": "true",
122
+ className: THUMBNAIL_PARTS.track,
123
+ children: /*#__PURE__*/_jsx("span", {
124
+ className: THUMBNAIL_PARTS.fill,
125
+ style: {
126
+ width: `${watched * 100}%`
127
+ }
128
+ })
129
+ });
130
+ $[29] = watched;
131
+ $[30] = t4;
132
+ } else {
133
+ t4 = $[30];
134
+ }
135
+ let t5;
136
+ if ($[31] !== t0 || $[32] !== t1 || $[33] !== t2 || $[34] !== t3 || $[35] !== t4) {
137
+ t5 = /*#__PURE__*/_jsxs("span", {
138
+ className: t0,
139
+ style: t1,
140
+ children: [t2, t3, t4]
141
+ });
142
+ $[31] = t0;
143
+ $[32] = t1;
144
+ $[33] = t2;
145
+ $[34] = t3;
146
+ $[35] = t4;
147
+ $[36] = t5;
148
+ } else {
149
+ t5 = $[36];
150
+ }
151
+ return t5;
152
+ }
@@ -0,0 +1,14 @@
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
+ export declare function Toast({ open, onClose, message, action, duration, className, style, }: ToastProps): import("react").JSX.Element;
package/dist/Toast.js ADDED
@@ -0,0 +1,121 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { motion } from "@xds/tokens";
3
+ import { classes, rootPart, TOAST_PARTS } from "@xds/core";
4
+ import { useEffect, useEffectEvent, useRef, useState } from "react";
5
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
+ export function Toast(t0) {
7
+ const $ = _c(20);
8
+ const {
9
+ open,
10
+ onClose,
11
+ message,
12
+ action,
13
+ duration: t1,
14
+ className,
15
+ style
16
+ } = t0;
17
+ const duration = t1 === undefined ? motion.duration.toast : t1;
18
+ const region = useRef(null);
19
+ const [hovered, setHovered] = useState(false);
20
+ const [focused, setFocused] = useState(false);
21
+ const held = hovered || focused;
22
+ const close = useEffectEvent(onClose);
23
+ let t2;
24
+ let t3;
25
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
26
+ t2 = () => {
27
+ const element = region.current;
28
+ if (!element?.showPopover) {
29
+ return;
30
+ }
31
+ element.showPopover();
32
+ return () => element.hidePopover();
33
+ };
34
+ t3 = [];
35
+ $[0] = t2;
36
+ $[1] = t3;
37
+ } else {
38
+ t2 = $[0];
39
+ t3 = $[1];
40
+ }
41
+ useEffect(t2, t3);
42
+ let t4;
43
+ if ($[2] !== close || $[3] !== duration || $[4] !== held || $[5] !== open) {
44
+ t4 = () => {
45
+ if (!open) {
46
+ setHovered(false);
47
+ setFocused(false);
48
+ }
49
+ if (!open || held || duration <= 0) {
50
+ return;
51
+ }
52
+ const timer = setTimeout(() => close(), duration);
53
+ return () => clearTimeout(timer);
54
+ };
55
+ $[2] = close;
56
+ $[3] = duration;
57
+ $[4] = held;
58
+ $[5] = open;
59
+ $[6] = t4;
60
+ } else {
61
+ t4 = $[6];
62
+ }
63
+ let t5;
64
+ if ($[7] !== duration || $[8] !== held || $[9] !== open) {
65
+ t5 = [open, held, duration];
66
+ $[7] = duration;
67
+ $[8] = held;
68
+ $[9] = open;
69
+ $[10] = t5;
70
+ } else {
71
+ t5 = $[10];
72
+ }
73
+ useEffect(t4, t5);
74
+ let t6;
75
+ if ($[11] !== action || $[12] !== className || $[13] !== message || $[14] !== onClose || $[15] !== open || $[16] !== style) {
76
+ t6 = open && /*#__PURE__*/_jsxs("div", {
77
+ onPointerEnter: () => setHovered(true),
78
+ onPointerLeave: () => setHovered(false),
79
+ onFocus: () => setFocused(true),
80
+ onBlur: () => setFocused(false),
81
+ className: classes(rootPart("Toast"), TOAST_PARTS.toast, className),
82
+ style: style,
83
+ children: [/*#__PURE__*/_jsx("span", {
84
+ className: TOAST_PARTS.message,
85
+ children: message
86
+ }), action && /*#__PURE__*/_jsx("button", {
87
+ type: "button",
88
+ onClick: () => {
89
+ action.onPress();
90
+ onClose();
91
+ },
92
+ className: TOAST_PARTS.action,
93
+ children: action.label
94
+ })]
95
+ });
96
+ $[11] = action;
97
+ $[12] = className;
98
+ $[13] = message;
99
+ $[14] = onClose;
100
+ $[15] = open;
101
+ $[16] = style;
102
+ $[17] = t6;
103
+ } else {
104
+ t6 = $[17];
105
+ }
106
+ let t7;
107
+ if ($[18] !== t6) {
108
+ t7 = /*#__PURE__*/_jsx("div", {
109
+ ref: region,
110
+ role: "status",
111
+ popover: "manual",
112
+ className: TOAST_PARTS.region,
113
+ children: t6
114
+ });
115
+ $[18] = t6;
116
+ $[19] = t7;
117
+ } else {
118
+ t7 = $[19];
119
+ }
120
+ return t7;
121
+ }
@@ -0,0 +1,26 @@
1
+ import { type TooltipBaseProps } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ /** `className` and `style` are for the tooltip, not for the control it describes. */
5
+ export type TooltipProps = TooltipBaseProps & RootProps & {
6
+ /** The control it describes: a Button or an IconButton. */
7
+ children: ReactNode;
8
+ };
9
+ /**
10
+ * Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
11
+ * short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
12
+ * focus leaves, or Escape is pressed.
13
+ *
14
+ * It describes the control and is not its name: an IconButton still needs its `label`. It
15
+ * never holds anything pressable, and touch input has no hover, so nothing may depend on it.
16
+ */
17
+ export declare function Tooltip({ label, shortcut, placement, className, style, children, }: TooltipProps): import("react").JSX.Element;
18
+ /**
19
+ * A Tooltip at the end edge of its control instead of above or below it: a collapsed Sidebar
20
+ * names its icons on the side of the content, where they do not cover their neighbours. Only
21
+ * for this package's own components: the index does not export it.
22
+ */
23
+ export declare function TooltipBeside({ label, children }: {
24
+ label: string;
25
+ children: ReactNode;
26
+ }): import("react").JSX.Element;
@@ -0,0 +1,166 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { motion, space } from "@xds/tokens";
3
+ import { classes, tooltipEndSide } from "@xds/core";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import * as tooltip from "@zag-js/tooltip";
6
+ import { useId, useRef } from "react";
7
+ import { Portal } from "./portal.js";
8
+ import { usePresence } from "./presence.js";
9
+ import { TriggerContext, useProvideTrigger } from "./trigger.js";
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ export function Tooltip(t0) {
12
+ const $ = _c(7);
13
+ const {
14
+ label,
15
+ shortcut,
16
+ placement: t1,
17
+ className,
18
+ style,
19
+ children
20
+ } = t0;
21
+ const placement = t1 === undefined ? "top" : t1;
22
+ let t2;
23
+ if ($[0] !== children || $[1] !== className || $[2] !== label || $[3] !== placement || $[4] !== shortcut || $[5] !== style) {
24
+ t2 = /*#__PURE__*/_jsx(Overlay, {
25
+ label: label,
26
+ shortcut: shortcut,
27
+ placement: placement,
28
+ className: className,
29
+ style: style,
30
+ children: children
31
+ });
32
+ $[0] = children;
33
+ $[1] = className;
34
+ $[2] = label;
35
+ $[3] = placement;
36
+ $[4] = shortcut;
37
+ $[5] = style;
38
+ $[6] = t2;
39
+ } else {
40
+ t2 = $[6];
41
+ }
42
+ return t2;
43
+ }
44
+ export function TooltipBeside(t0) {
45
+ const $ = _c(4);
46
+ const {
47
+ label,
48
+ children
49
+ } = t0;
50
+ let t1;
51
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
52
+ t1 = tooltipEndSide();
53
+ $[0] = t1;
54
+ } else {
55
+ t1 = $[0];
56
+ }
57
+ let t2;
58
+ if ($[1] !== children || $[2] !== label) {
59
+ t2 = /*#__PURE__*/_jsx(Overlay, {
60
+ label: label,
61
+ placement: t1,
62
+ children: children
63
+ });
64
+ $[1] = children;
65
+ $[2] = label;
66
+ $[3] = t2;
67
+ } else {
68
+ t2 = $[3];
69
+ }
70
+ return t2;
71
+ }
72
+ function Overlay(t0) {
73
+ const $ = _c(12);
74
+ const {
75
+ label,
76
+ shortcut,
77
+ placement,
78
+ className,
79
+ style,
80
+ children
81
+ } = t0;
82
+ const t1 = useId();
83
+ let t2;
84
+ if ($[0] !== placement) {
85
+ t2 = {
86
+ placement,
87
+ gutter: space[1]
88
+ };
89
+ $[0] = placement;
90
+ $[1] = t2;
91
+ } else {
92
+ t2 = $[1];
93
+ }
94
+ let t3;
95
+ if ($[2] !== t1 || $[3] !== t2) {
96
+ t3 = {
97
+ id: t1,
98
+ openDelay: motion.duration.tooltipDelay,
99
+ closeDelay: 0,
100
+ closeOnScroll: false,
101
+ positioning: t2
102
+ };
103
+ $[2] = t1;
104
+ $[3] = t2;
105
+ $[4] = t3;
106
+ } else {
107
+ t3 = $[4];
108
+ }
109
+ const service = useMachine(tooltip.machine, t3);
110
+ const api = tooltip.connect(service, normalizeProps);
111
+ const trigger = useProvideTrigger(api.getTriggerProps());
112
+ const content = useRef(null);
113
+ let t4;
114
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
115
+ t4 = () => [content.current];
116
+ $[5] = t4;
117
+ } else {
118
+ t4 = $[5];
119
+ }
120
+ const present = usePresence(api.open, t4);
121
+ let t5;
122
+ if ($[6] !== children || $[7] !== trigger) {
123
+ t5 = /*#__PURE__*/_jsx(TriggerContext, {
124
+ value: trigger,
125
+ children: children
126
+ });
127
+ $[6] = children;
128
+ $[7] = trigger;
129
+ $[8] = t5;
130
+ } else {
131
+ t5 = $[8];
132
+ }
133
+ const t6 = present && /*#__PURE__*/_jsx(Portal, {
134
+ children: /*#__PURE__*/_jsx(TriggerContext, {
135
+ value: null,
136
+ children: /*#__PURE__*/_jsx("div", {
137
+ ...api.getPositionerProps(),
138
+ className: "xds-tooltip__positioner",
139
+ children: /*#__PURE__*/_jsxs("div", {
140
+ ...mergeProps(api.getContentProps(), {
141
+ className: classes("xds-tooltip", className),
142
+ style
143
+ }),
144
+ ref: content,
145
+ hidden: false,
146
+ children: [label, shortcut && /*#__PURE__*/_jsx("kbd", {
147
+ className: "xds-tooltip__shortcut",
148
+ children: shortcut
149
+ })]
150
+ })
151
+ })
152
+ })
153
+ });
154
+ let t7;
155
+ if ($[9] !== t5 || $[10] !== t6) {
156
+ t7 = /*#__PURE__*/_jsxs(_Fragment, {
157
+ children: [t5, t6]
158
+ });
159
+ $[9] = t5;
160
+ $[10] = t6;
161
+ $[11] = t7;
162
+ } else {
163
+ t7 = $[11];
164
+ }
165
+ return t7;
166
+ }