@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,370 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { classes, DATE_PICKER_NAV_CLASS, dateRangeMachineProps, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerTriggerAttrs, endRangeChoiceOnClose, focusOpeningDay, formatRange, keepCalendarFocus, keepDayFocused, keepRangePreview, rangeDayClick, rangeGridKeyDown, rangeMonths, rangeMonthViews, rangeSummary, shownRange } from "@xds/core";
3
+ import * as datePicker from "@zag-js/date-picker";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import { useEffect, useId, useRef, useState } from "react";
6
+ import { Icon } from "./Icon.js";
7
+ import { useModalPopover } from "./modal-popover.js";
8
+ import { Portal } from "./portal.js";
9
+ import { usePresence } from "./presence.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ export function DateRangePicker(t0) {
12
+ const $ = _c(39);
13
+ const {
14
+ onChange,
15
+ className,
16
+ style,
17
+ ...props
18
+ } = t0;
19
+ const {
20
+ label,
21
+ value,
22
+ placeholder,
23
+ description,
24
+ error,
25
+ startName,
26
+ endName
27
+ } = props;
28
+ const id = useId();
29
+ const ids = datePickerIds(id);
30
+ const locale = datePickerLocale();
31
+ const [draft, setDraft] = useState(null);
32
+ const [months, setMonths] = useState(1);
33
+ const shown = shownRange(value, draft);
34
+ const service = useMachine(datePicker.machine, dateRangeMachineProps(props, shown, {
35
+ id,
36
+ locale,
37
+ months,
38
+ onDraft: setDraft,
39
+ onChange
40
+ }));
41
+ const api = datePicker.connect(service, normalizeProps);
42
+ const trigger = api.getTriggerProps();
43
+ const positioner = useRef(null);
44
+ const surface = useRef(null);
45
+ let t1;
46
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
47
+ t1 = () => positioner.current;
48
+ $[0] = t1;
49
+ } else {
50
+ t1 = $[0];
51
+ }
52
+ useModalPopover(api.open, t1);
53
+ let t2;
54
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
55
+ t2 = () => [surface.current];
56
+ $[1] = t2;
57
+ } else {
58
+ t2 = $[1];
59
+ }
60
+ const present = usePresence(api.open, t2);
61
+ const focused = api.focusedValue.toString();
62
+ const month = api.visibleRange.start.toString();
63
+ useEffect(() => keepDayFocused(api.open, surface.current), [api.open, focused, month]);
64
+ let t3;
65
+ if ($[2] !== api) {
66
+ t3 = [api.open];
67
+ $[2] = api;
68
+ $[3] = t3;
69
+ } else {
70
+ t3 = $[3];
71
+ }
72
+ useEffect(() => endRangeChoiceOnClose(service, api.open), t3);
73
+ useEffect(() => keepRangePreview(service, shown, api.open), [focused]);
74
+ const summary = rangeSummary(shown, props, locale);
75
+ const invalid = error !== undefined;
76
+ const t4 = mergeProps(api.getRootProps(), {
77
+ className: classes("xds-date-picker xds-date-range-picker", className),
78
+ style
79
+ });
80
+ let t5;
81
+ if ($[4] !== api) {
82
+ t5 = api.getControlProps();
83
+ $[4] = api;
84
+ $[5] = t5;
85
+ } else {
86
+ t5 = $[5];
87
+ }
88
+ let t6;
89
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
90
+ t6 = /*#__PURE__*/_jsx(Icon, {
91
+ name: "calendar",
92
+ size: "sm",
93
+ className: "text-xds-field-placeholder"
94
+ });
95
+ $[6] = t6;
96
+ } else {
97
+ t6 = $[6];
98
+ }
99
+ const T0 = Portal;
100
+ const t7 = api.open && /*#__PURE__*/_jsx("div", {
101
+ className: "xds-date-picker__underlay",
102
+ onMouseDown: _temp
103
+ });
104
+ let t8;
105
+ if ($[7] !== api) {
106
+ t8 = api.getPositionerProps();
107
+ $[7] = api;
108
+ $[8] = t8;
109
+ } else {
110
+ t8 = $[8];
111
+ }
112
+ const t9 = "xds-date-picker__positioner";
113
+ let t10;
114
+ if ($[9] !== api) {
115
+ t10 = api.getContentProps();
116
+ $[9] = api;
117
+ $[10] = t10;
118
+ } else {
119
+ t10 = $[10];
120
+ }
121
+ const t11 = datePickerContentAttrs(ids);
122
+ const t12 = !present;
123
+ let t13;
124
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
125
+ t13 = event_1 => keepCalendarFocus(event_1, surface.current);
126
+ $[11] = t13;
127
+ } else {
128
+ t13 = $[11];
129
+ }
130
+ let t14;
131
+ if ($[12] !== summary.start) {
132
+ t14 = /*#__PURE__*/_jsx("span", {
133
+ children: summary.start
134
+ });
135
+ $[12] = summary.start;
136
+ $[13] = t14;
137
+ } else {
138
+ t14 = $[13];
139
+ }
140
+ let t15;
141
+ if ($[14] !== summary.end) {
142
+ t15 = /*#__PURE__*/_jsx("span", {
143
+ children: summary.end
144
+ });
145
+ $[14] = summary.end;
146
+ $[15] = t15;
147
+ } else {
148
+ t15 = $[15];
149
+ }
150
+ let t16;
151
+ if ($[16] !== t14 || $[17] !== t15) {
152
+ t16 = /*#__PURE__*/_jsxs("div", {
153
+ className: "xds-date-range-picker__summary",
154
+ "aria-live": "polite",
155
+ children: [t14, t15]
156
+ });
157
+ $[16] = t14;
158
+ $[17] = t15;
159
+ $[18] = t16;
160
+ } else {
161
+ t16 = $[18];
162
+ }
163
+ let t17;
164
+ if ($[19] !== api || $[20] !== months || $[21] !== props || $[22] !== shown) {
165
+ t17 = rangeMonthViews(api, months).map(view => {
166
+ const table = api.getTableProps({
167
+ view: "day",
168
+ id: view.table.id
169
+ });
170
+ return /*#__PURE__*/_jsxs("div", {
171
+ className: "xds-date-range-picker__month",
172
+ children: [/*#__PURE__*/_jsxs("div", {
173
+ className: "xds-date-picker__header",
174
+ children: [view.index === 0 ? /*#__PURE__*/_jsx("button", {
175
+ ...api.getPreviousTriggerProps(),
176
+ type: "button",
177
+ className: DATE_PICKER_NAV_CLASS,
178
+ children: /*#__PURE__*/_jsx(Icon, {
179
+ name: "chevron-left",
180
+ size: "sm"
181
+ })
182
+ }) : /*#__PURE__*/_jsx("span", {
183
+ className: "xds-date-range-picker__nav-space"
184
+ }), /*#__PURE__*/_jsx("span", {
185
+ ...api.getRangeTextProps(),
186
+ className: "xds-date-picker__heading",
187
+ children: view.name
188
+ }), view.index === months - 1 ? /*#__PURE__*/_jsx("button", {
189
+ ...api.getNextTriggerProps(),
190
+ type: "button",
191
+ className: DATE_PICKER_NAV_CLASS,
192
+ children: /*#__PURE__*/_jsx(Icon, {
193
+ name: "chevron-right",
194
+ size: "sm"
195
+ })
196
+ }) : /*#__PURE__*/_jsx("span", {
197
+ className: "xds-date-range-picker__nav-space"
198
+ })]
199
+ }), /*#__PURE__*/_jsxs("table", {
200
+ ...table,
201
+ ...view.table,
202
+ onKeyDown: event_2 => rangeGridKeyDown(event_2, api, shown, props, table.onKeyDown),
203
+ className: "xds-date-picker__grid",
204
+ children: [/*#__PURE__*/_jsx("thead", {
205
+ ...api.getTableHeadProps({
206
+ view: "day"
207
+ }),
208
+ children: /*#__PURE__*/_jsx("tr", {
209
+ ...api.getTableRowProps({
210
+ view: "day"
211
+ }),
212
+ children: api.weekDays.map(_temp2)
213
+ })
214
+ }), /*#__PURE__*/_jsx("tbody", {
215
+ ...api.getTableBodyProps({
216
+ view: "day"
217
+ }),
218
+ children: view.weeks.map(week => /*#__PURE__*/_jsx("tr", {
219
+ ...api.getTableRowProps({
220
+ view: "day"
221
+ }),
222
+ children: week.map(date => {
223
+ const cell = {
224
+ value: date,
225
+ visibleRange: view.visibleRange
226
+ };
227
+ const day = api.getDayTableCellTriggerProps(cell);
228
+ return /*#__PURE__*/_jsx("td", {
229
+ ...api.getDayTableCellProps(cell),
230
+ className: "xds-date-picker__cell",
231
+ children: /*#__PURE__*/_jsx("div", {
232
+ ...day,
233
+ onClick: event_3 => rangeDayClick(event_3, api, shown, props, date, view.visibleRange, day.onClick),
234
+ className: "xds-date-picker__day",
235
+ children: date.day
236
+ })
237
+ }, date.toString());
238
+ })
239
+ }, week[0]?.toString()))
240
+ })]
241
+ })]
242
+ }, view.index);
243
+ });
244
+ $[19] = api;
245
+ $[20] = months;
246
+ $[21] = props;
247
+ $[22] = shown;
248
+ $[23] = t17;
249
+ } else {
250
+ t17 = $[23];
251
+ }
252
+ let t18;
253
+ if ($[24] !== t17) {
254
+ t18 = /*#__PURE__*/_jsx("div", {
255
+ className: "xds-date-range-picker__months",
256
+ children: t17
257
+ });
258
+ $[24] = t17;
259
+ $[25] = t18;
260
+ } else {
261
+ t18 = $[25];
262
+ }
263
+ let t19;
264
+ if ($[26] !== t10 || $[27] !== t11 || $[28] !== t12 || $[29] !== t16 || $[30] !== t18) {
265
+ t19 = /*#__PURE__*/_jsxs("div", {
266
+ ...t10,
267
+ ...t11,
268
+ ref: surface,
269
+ hidden: t12,
270
+ onKeyDown: t13,
271
+ className: "xds-date-picker__content xds-date-range-picker__content",
272
+ children: [t16, t18]
273
+ });
274
+ $[26] = t10;
275
+ $[27] = t11;
276
+ $[28] = t12;
277
+ $[29] = t16;
278
+ $[30] = t18;
279
+ $[31] = t19;
280
+ } else {
281
+ t19 = $[31];
282
+ }
283
+ let t20;
284
+ if ($[32] !== t19 || $[33] !== t8) {
285
+ t20 = /*#__PURE__*/_jsx("div", {
286
+ ...t8,
287
+ ref: positioner,
288
+ className: t9,
289
+ children: t19
290
+ });
291
+ $[32] = t19;
292
+ $[33] = t8;
293
+ $[34] = t20;
294
+ } else {
295
+ t20 = $[34];
296
+ }
297
+ let t21;
298
+ if ($[35] !== T0 || $[36] !== t20 || $[37] !== t7) {
299
+ t21 = /*#__PURE__*/_jsxs(T0, {
300
+ children: [t7, t20]
301
+ });
302
+ $[35] = T0;
303
+ $[36] = t20;
304
+ $[37] = t7;
305
+ $[38] = t21;
306
+ } else {
307
+ t21 = $[38];
308
+ }
309
+ return /*#__PURE__*/_jsxs("div", {
310
+ ...t4,
311
+ children: [/*#__PURE__*/_jsx("span", {
312
+ id: ids.label,
313
+ className: "xds-date-picker__label",
314
+ children: label
315
+ }), /*#__PURE__*/_jsx("div", {
316
+ ...t5,
317
+ className: "xds-date-picker__control",
318
+ children: /*#__PURE__*/_jsxs("button", {
319
+ ...trigger,
320
+ ...datePickerTriggerAttrs(props, ids),
321
+ type: "button",
322
+ onClick: event => {
323
+ if (!api.open) {
324
+ setMonths(rangeMonths());
325
+ }
326
+ focusOpeningDay(api, {
327
+ ...props,
328
+ value: value?.start
329
+ });
330
+ trigger.onClick?.(event);
331
+ },
332
+ className: "xds-date-picker__trigger",
333
+ children: [/*#__PURE__*/_jsx("span", {
334
+ id: ids.value,
335
+ className: "xds-date-picker__value",
336
+ children: value === undefined ? placeholder : formatRange(value, locale)
337
+ }), t6]
338
+ })
339
+ }), (invalid || description) && /*#__PURE__*/_jsx("div", {
340
+ className: "xds-date-picker__footer",
341
+ children: invalid ? /*#__PURE__*/_jsx("span", {
342
+ id: ids.error,
343
+ className: "xds-date-picker__error",
344
+ children: error
345
+ }) : /*#__PURE__*/_jsx("span", {
346
+ id: ids.description,
347
+ className: "xds-date-picker__description",
348
+ children: description
349
+ })
350
+ }), startName !== undefined && /*#__PURE__*/_jsx("input", {
351
+ type: "hidden",
352
+ name: startName,
353
+ value: value?.start ?? ""
354
+ }), endName !== undefined && /*#__PURE__*/_jsx("input", {
355
+ type: "hidden",
356
+ name: endName,
357
+ value: value?.end ?? ""
358
+ }), t21]
359
+ });
360
+ }
361
+ function _temp2(weekDay) {
362
+ return /*#__PURE__*/_jsx("th", {
363
+ scope: "col",
364
+ className: "xds-date-picker__weekday",
365
+ children: weekDay.narrow
366
+ }, weekDay.long);
367
+ }
368
+ function _temp(event_0) {
369
+ return event_0.preventDefault();
370
+ }
@@ -0,0 +1,17 @@
1
+ import { type ComponentDefaults, type DefaultedComponent } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ export type { ComponentDefaults } from "@xds/core";
4
+ export type DefaultsProps = {
5
+ /** By component, what it takes for an option it is not given, such as Button's `variant`. */
6
+ value: ComponentDefaults;
7
+ children: ReactNode;
8
+ };
9
+ /**
10
+ * Gives the components inside it their defaults: a component takes the value for an option
11
+ * the app leaves out from the closest Defaults around it, and its own built-in default when no
12
+ * Defaults names one. A Defaults inside another keeps the outer one's values and replaces those
13
+ * it names, option by option.
14
+ */
15
+ export declare function Defaults({ value, children }: DefaultsProps): import("react").JSX.Element;
16
+ /** The defaults that the closest Defaults gives component `name`, or none. */
17
+ export declare function useDefaults<N extends DefaultedComponent>(name: N): NonNullable<ComponentDefaults[N]>;
@@ -0,0 +1,48 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { mergeDefaults } from "@xds/core";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ const DefaultsContext = createContext({});
6
+ export function Defaults(t0) {
7
+ const $ = _c(8);
8
+ const {
9
+ value,
10
+ children
11
+ } = t0;
12
+ const outer = useContext(DefaultsContext);
13
+ let t1;
14
+ if ($[0] !== value) {
15
+ t1 = JSON.stringify(value);
16
+ $[0] = value;
17
+ $[1] = t1;
18
+ } else {
19
+ t1 = $[1];
20
+ }
21
+ const key = t1;
22
+ let t2;
23
+ if ($[2] !== key || $[3] !== outer) {
24
+ t2 = mergeDefaults(outer, JSON.parse(key));
25
+ $[2] = key;
26
+ $[3] = outer;
27
+ $[4] = t2;
28
+ } else {
29
+ t2 = $[4];
30
+ }
31
+ const merged = t2;
32
+ let t3;
33
+ if ($[5] !== children || $[6] !== merged) {
34
+ t3 = /*#__PURE__*/_jsx(DefaultsContext, {
35
+ value: merged,
36
+ children: children
37
+ });
38
+ $[5] = children;
39
+ $[6] = merged;
40
+ $[7] = t3;
41
+ } else {
42
+ t3 = $[7];
43
+ }
44
+ return t3;
45
+ }
46
+ export function useDefaults(name) {
47
+ return useContext(DefaultsContext)[name] ?? {};
48
+ }
@@ -0,0 +1,20 @@
1
+ import { type DialogBaseProps } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ /** `className` and `style` are for the dialog's panel, not for the backdrop around it. */
5
+ export type DialogProps = DialogBaseProps & RootProps & {
6
+ /** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
7
+ onClose: () => void;
8
+ /** The body, between the description and the actions. It scrolls when it is too tall. */
9
+ children?: ReactNode;
10
+ /** Buttons, in a row at the end edge. Put the main action last. */
11
+ actions?: ReactNode;
12
+ };
13
+ /**
14
+ * A window that interrupts the screen for a confirmation or a short task. Everything behind it
15
+ * is dimmed and cannot be reached until it closes.
16
+ *
17
+ * It is a modal dialog named by its title and described by its description. Focus moves into
18
+ * it, stays inside it, and returns to where it was when it closes.
19
+ */
20
+ export declare function Dialog({ open, onClose, title, description, children, actions, dismissible, className, style, }: DialogProps): import("react").JSX.Element | null;
package/dist/Dialog.js ADDED
@@ -0,0 +1,137 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { classes, leaveEscapeToFields } from "@xds/core";
3
+ import * as dialog from "@zag-js/dialog";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import { useId, useRef } from "react";
6
+ import { Portal } from "./portal.js";
7
+ import { usePresence } from "./presence.js";
8
+ import { TriggerContext } from "./trigger.js";
9
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
10
+ export function Dialog(t0) {
11
+ const $ = _c(13);
12
+ const {
13
+ open,
14
+ onClose,
15
+ title,
16
+ description,
17
+ children,
18
+ actions,
19
+ dismissible: t1,
20
+ className,
21
+ style
22
+ } = t0;
23
+ const dismissible = t1 === undefined ? true : t1;
24
+ const backdrop = useRef(null);
25
+ const positioner = useRef(null);
26
+ const content = useRef(null);
27
+ const t2 = useId();
28
+ let t3;
29
+ if ($[0] !== onClose) {
30
+ t3 = details => {
31
+ if (!details.open) {
32
+ onClose();
33
+ }
34
+ };
35
+ $[0] = onClose;
36
+ $[1] = t3;
37
+ } else {
38
+ t3 = $[1];
39
+ }
40
+ let t4;
41
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
42
+ t4 = () => content.current;
43
+ $[2] = t4;
44
+ } else {
45
+ t4 = $[2];
46
+ }
47
+ let t5;
48
+ if ($[3] !== dismissible || $[4] !== open || $[5] !== t2 || $[6] !== t3) {
49
+ t5 = {
50
+ id: t2,
51
+ open,
52
+ onOpenChange: t3,
53
+ closeOnEscape: dismissible,
54
+ closeOnInteractOutside: dismissible,
55
+ onEscapeKeyDown: leaveEscapeToFields,
56
+ initialFocusEl: t4
57
+ };
58
+ $[3] = dismissible;
59
+ $[4] = open;
60
+ $[5] = t2;
61
+ $[6] = t3;
62
+ $[7] = t5;
63
+ } else {
64
+ t5 = $[7];
65
+ }
66
+ const service = useMachine(dialog.machine, t5);
67
+ const api = dialog.connect(service, normalizeProps);
68
+ let t6;
69
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
70
+ t6 = () => [backdrop.current, positioner.current];
71
+ $[8] = t6;
72
+ } else {
73
+ t6 = $[8];
74
+ }
75
+ const present = usePresence(api.open, t6);
76
+ if (!present) {
77
+ return null;
78
+ }
79
+ let t7;
80
+ if ($[9] !== children) {
81
+ t7 = children != null && /*#__PURE__*/_jsx("div", {
82
+ className: "xds-dialog__body",
83
+ children: children
84
+ });
85
+ $[9] = children;
86
+ $[10] = t7;
87
+ } else {
88
+ t7 = $[10];
89
+ }
90
+ let t8;
91
+ if ($[11] !== actions) {
92
+ t8 = actions != null && /*#__PURE__*/_jsx("div", {
93
+ className: "xds-dialog__actions",
94
+ children: actions
95
+ });
96
+ $[11] = actions;
97
+ $[12] = t8;
98
+ } else {
99
+ t8 = $[12];
100
+ }
101
+ return /*#__PURE__*/_jsx(Portal, {
102
+ children: /*#__PURE__*/_jsxs(TriggerContext, {
103
+ value: null,
104
+ children: [/*#__PURE__*/_jsx("div", {
105
+ ...api.getBackdropProps(),
106
+ ref: backdrop,
107
+ hidden: false,
108
+ onMouseDown: _temp,
109
+ className: "xds-dialog__backdrop"
110
+ }), /*#__PURE__*/_jsx("div", {
111
+ ...api.getPositionerProps(),
112
+ ref: positioner,
113
+ className: "xds-dialog__positioner",
114
+ children: /*#__PURE__*/_jsxs("section", {
115
+ ...mergeProps(api.getContentProps(), {
116
+ className: classes("xds-dialog", className),
117
+ style
118
+ }),
119
+ ref: content,
120
+ hidden: false,
121
+ children: [/*#__PURE__*/_jsx("h2", {
122
+ ...api.getTitleProps(),
123
+ className: "xds-dialog__title",
124
+ children: title
125
+ }), description && /*#__PURE__*/_jsx("p", {
126
+ ...api.getDescriptionProps(),
127
+ className: "xds-dialog__description",
128
+ children: description
129
+ }), t7, t8]
130
+ })
131
+ })]
132
+ })
133
+ });
134
+ }
135
+ function _temp(event) {
136
+ return event.preventDefault();
137
+ }
@@ -0,0 +1,4 @@
1
+ import type { RootProps } from "./root.ts";
2
+ export type DividerProps = RootProps;
3
+ /** A line between groups of content. Decorative lines use the low-contrast border color. */
4
+ export declare function Divider({ className, style }: DividerProps): import("react").JSX.Element;
@@ -0,0 +1,31 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { classes, dividerClass, rootPart } from "@xds/core";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export function Divider(t0) {
5
+ const $ = _c(5);
6
+ const {
7
+ className,
8
+ style
9
+ } = t0;
10
+ let t1;
11
+ if ($[0] !== className) {
12
+ t1 = classes(rootPart("Divider"), dividerClass, className);
13
+ $[0] = className;
14
+ $[1] = t1;
15
+ } else {
16
+ t1 = $[1];
17
+ }
18
+ let t2;
19
+ if ($[2] !== style || $[3] !== t1) {
20
+ t2 = /*#__PURE__*/_jsx("hr", {
21
+ className: t1,
22
+ style: style
23
+ });
24
+ $[2] = style;
25
+ $[3] = t1;
26
+ $[4] = t2;
27
+ } else {
28
+ t2 = $[4];
29
+ }
30
+ return t2;
31
+ }
@@ -0,0 +1,12 @@
1
+ import { type EmptyStateBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type EmptyStateProps = EmptyStateBaseProps & RootProps & {
5
+ /** The one thing to do about it, usually a Button. */
6
+ action?: ReactNode;
7
+ };
8
+ /**
9
+ * What a screen or a list says when it has nothing to show. It centers itself in its container,
10
+ * also vertically when the container is a flex box with room to spare.
11
+ */
12
+ export declare function EmptyState({ icon, title, description, action, className, style, }: EmptyStateProps): import("react").JSX.Element;