@ui-sdk/react 0.0.0-stage → 0.1.0-beta.1

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 (247) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +331 -0
  4. package/dist/accordion.js +25 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +8 -0
  7. package/dist/alert-dialog.d.ts +56 -0
  8. package/dist/alert-dialog.js +45 -0
  9. package/dist/async-options.d.ts +22 -0
  10. package/dist/async-options.js +56 -0
  11. package/dist/autocomplete.d.ts +102 -0
  12. package/dist/autocomplete.js +195 -0
  13. package/dist/avatar.d.ts +301 -0
  14. package/dist/avatar.js +17 -0
  15. package/dist/button.d.ts +21 -0
  16. package/dist/button.js +45 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +9 -0
  19. package/dist/calendar.d.ts +80 -0
  20. package/dist/calendar.js +257 -0
  21. package/dist/carousel.d.ts +52 -0
  22. package/dist/carousel.js +151 -0
  23. package/dist/checkbox.d.ts +24 -0
  24. package/dist/checkbox.js +98 -0
  25. package/dist/children.d.ts +38 -0
  26. package/dist/children.js +63 -0
  27. package/dist/collapsible.d.ts +302 -0
  28. package/dist/collapsible.js +19 -0
  29. package/dist/color-picker.d.ts +72 -0
  30. package/dist/color-picker.js +133 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +22 -0
  33. package/dist/combobox.d.ts +152 -0
  34. package/dist/combobox.js +338 -0
  35. package/dist/command.d.ts +88 -0
  36. package/dist/command.js +233 -0
  37. package/dist/controller-target.d.ts +3 -0
  38. package/dist/controller-target.js +59 -0
  39. package/dist/date-input.d.ts +19 -0
  40. package/dist/date-input.js +58 -0
  41. package/dist/date-picker.d.ts +47 -0
  42. package/dist/date-picker.js +310 -0
  43. package/dist/date.d.ts +2 -0
  44. package/dist/date.js +60 -0
  45. package/dist/dialog-parts.d.ts +23 -0
  46. package/dist/dialog-parts.js +142 -0
  47. package/dist/dialog.d.ts +57 -0
  48. package/dist/dialog.js +32 -0
  49. package/dist/drawer.d.ts +70 -0
  50. package/dist/drawer.js +158 -0
  51. package/dist/editor-context.d.ts +4 -0
  52. package/dist/editor-context.js +9 -0
  53. package/dist/field-context.d.ts +47 -0
  54. package/dist/field-context.js +87 -0
  55. package/dist/field.d.ts +49 -0
  56. package/dist/field.js +169 -0
  57. package/dist/file-input.d.ts +46 -0
  58. package/dist/file-input.js +170 -0
  59. package/dist/form-inputs.d.ts +5 -0
  60. package/dist/form-inputs.js +22 -0
  61. package/dist/gesture.d.ts +1 -0
  62. package/dist/gesture.js +16 -0
  63. package/dist/history.d.ts +2 -0
  64. package/dist/history.js +12 -0
  65. package/dist/hover-card.d.ts +33 -0
  66. package/dist/hover-card.js +84 -0
  67. package/dist/image-cropper.d.ts +333 -0
  68. package/dist/image-cropper.js +37 -0
  69. package/dist/image.d.ts +2 -0
  70. package/dist/image.js +6 -0
  71. package/dist/input.d.ts +22 -0
  72. package/dist/input.js +51 -0
  73. package/dist/label.d.ts +294 -0
  74. package/dist/label.js +9 -0
  75. package/dist/list-items.d.ts +15 -0
  76. package/dist/list-items.js +39 -0
  77. package/dist/list-text.d.ts +4 -0
  78. package/dist/list-text.js +15 -0
  79. package/dist/listbox.d.ts +56 -0
  80. package/dist/listbox.js +122 -0
  81. package/dist/menu.d.ts +116 -0
  82. package/dist/menu.js +426 -0
  83. package/dist/menubar-context.d.ts +4 -0
  84. package/dist/menubar-context.js +7 -0
  85. package/dist/menubar.d.ts +11 -0
  86. package/dist/menubar.js +32 -0
  87. package/dist/meter.d.ts +312 -0
  88. package/dist/meter.js +30 -0
  89. package/dist/navigation-menu.d.ts +61 -0
  90. package/dist/navigation-menu.js +169 -0
  91. package/dist/number-input.d.ts +44 -0
  92. package/dist/number-input.js +185 -0
  93. package/dist/number.d.ts +2 -0
  94. package/dist/number.js +40 -0
  95. package/dist/observe.d.ts +2 -0
  96. package/dist/observe.js +8 -0
  97. package/dist/otp-input.d.ts +29 -0
  98. package/dist/otp-input.js +94 -0
  99. package/dist/overlays.d.ts +26 -0
  100. package/dist/overlays.js +82 -0
  101. package/dist/pagination.d.ts +336 -0
  102. package/dist/pagination.js +71 -0
  103. package/dist/password-input.d.ts +23 -0
  104. package/dist/password-input.js +65 -0
  105. package/dist/popover.d.ts +54 -0
  106. package/dist/popover.js +151 -0
  107. package/dist/popup.d.ts +41 -0
  108. package/dist/popup.js +180 -0
  109. package/dist/preferences.d.ts +35 -0
  110. package/dist/preferences.js +93 -0
  111. package/dist/primitive.d.ts +2 -0
  112. package/dist/primitive.js +14 -0
  113. package/dist/progress.d.ts +312 -0
  114. package/dist/progress.js +30 -0
  115. package/dist/radio.d.ts +22 -0
  116. package/dist/radio.js +86 -0
  117. package/dist/rating.d.ts +20 -0
  118. package/dist/rating.js +94 -0
  119. package/dist/render-element.d.ts +35 -0
  120. package/dist/render-element.js +103 -0
  121. package/dist/resizable.d.ts +302 -0
  122. package/dist/resizable.js +23 -0
  123. package/dist/scroll-area.d.ts +324 -0
  124. package/dist/scroll-area.js +49 -0
  125. package/dist/segmented-control.d.ts +24 -0
  126. package/dist/segmented-control.js +78 -0
  127. package/dist/segmented-input.d.ts +15 -0
  128. package/dist/segmented-input.js +48 -0
  129. package/dist/select.d.ts +125 -0
  130. package/dist/select.js +330 -0
  131. package/dist/separator.d.ts +290 -0
  132. package/dist/separator.js +9 -0
  133. package/dist/shortcuts.d.ts +32 -0
  134. package/dist/shortcuts.js +61 -0
  135. package/dist/slider.d.ts +38 -0
  136. package/dist/slider.js +163 -0
  137. package/dist/switch.d.ts +15 -0
  138. package/dist/switch.js +39 -0
  139. package/dist/tabs.d.ts +331 -0
  140. package/dist/tabs.js +28 -0
  141. package/dist/text-control.d.ts +22 -0
  142. package/dist/text-control.js +24 -0
  143. package/dist/text-match.d.ts +2 -0
  144. package/dist/text-match.js +8 -0
  145. package/dist/textarea.d.ts +10 -0
  146. package/dist/textarea.js +48 -0
  147. package/dist/time-input.d.ts +19 -0
  148. package/dist/time-input.js +63 -0
  149. package/dist/timeline.d.ts +327 -0
  150. package/dist/timeline.js +31 -0
  151. package/dist/toast-parts.d.ts +63 -0
  152. package/dist/toast-parts.js +144 -0
  153. package/dist/toast.d.ts +2 -0
  154. package/dist/toast.js +22 -0
  155. package/dist/toggle.d.ts +23 -0
  156. package/dist/toggle.js +76 -0
  157. package/dist/token-input.d.ts +35 -0
  158. package/dist/token-input.js +100 -0
  159. package/dist/toolbar-context.d.ts +6 -0
  160. package/dist/toolbar-context.js +16 -0
  161. package/dist/toolbar.d.ts +38 -0
  162. package/dist/toolbar.js +63 -0
  163. package/dist/tooltip.d.ts +39 -0
  164. package/dist/tooltip.js +108 -0
  165. package/dist/tree.d.ts +51 -0
  166. package/dist/tree.js +150 -0
  167. package/dist/trigger-menu.d.ts +83 -0
  168. package/dist/trigger-menu.js +167 -0
  169. package/dist/use-primitive.d.ts +178 -0
  170. package/dist/use-primitive.js +674 -0
  171. package/dist/waterfall.d.ts +80 -0
  172. package/dist/waterfall.js +108 -0
  173. package/docs/README.md +89 -0
  174. package/docs/agents.md +1523 -0
  175. package/docs/components/accordion.md +1391 -0
  176. package/docs/components/alert-dialog.md +850 -0
  177. package/docs/components/autocomplete.md +1963 -0
  178. package/docs/components/avatar.md +252 -0
  179. package/docs/components/button.md +444 -0
  180. package/docs/components/calendar.md +1687 -0
  181. package/docs/components/carousel.md +1244 -0
  182. package/docs/components/checkbox.md +1069 -0
  183. package/docs/components/collapsible.md +567 -0
  184. package/docs/components/color-picker.md +736 -0
  185. package/docs/components/combobox.md +3647 -0
  186. package/docs/components/command.md +1573 -0
  187. package/docs/components/date-input.md +608 -0
  188. package/docs/components/date-picker.md +1266 -0
  189. package/docs/components/dialog.md +1469 -0
  190. package/docs/components/drawer.md +1197 -0
  191. package/docs/components/field.md +549 -0
  192. package/docs/components/file-input.md +609 -0
  193. package/docs/components/hover-card.md +514 -0
  194. package/docs/components/image-cropper.md +579 -0
  195. package/docs/components/input.md +301 -0
  196. package/docs/components/label.md +217 -0
  197. package/docs/components/listbox.md +1130 -0
  198. package/docs/components/menu.md +1286 -0
  199. package/docs/components/menubar.md +455 -0
  200. package/docs/components/meter.md +304 -0
  201. package/docs/components/navigation-menu.md +1581 -0
  202. package/docs/components/number-input.md +1086 -0
  203. package/docs/components/otp-input.md +565 -0
  204. package/docs/components/pagination.md +648 -0
  205. package/docs/components/password-input.md +737 -0
  206. package/docs/components/popover.md +1552 -0
  207. package/docs/components/preferences.md +220 -0
  208. package/docs/components/progress.md +443 -0
  209. package/docs/components/radio.md +846 -0
  210. package/docs/components/rating.md +458 -0
  211. package/docs/components/resizable.md +982 -0
  212. package/docs/components/scroll-area.md +980 -0
  213. package/docs/components/segmented-control.md +465 -0
  214. package/docs/components/select.md +2133 -0
  215. package/docs/components/separator.md +243 -0
  216. package/docs/components/slider.md +1169 -0
  217. package/docs/components/switch.md +613 -0
  218. package/docs/components/tabs.md +1014 -0
  219. package/docs/components/textarea.md +318 -0
  220. package/docs/components/time-input.md +231 -0
  221. package/docs/components/timeline.md +677 -0
  222. package/docs/components/toast.md +1395 -0
  223. package/docs/components/toggle.md +541 -0
  224. package/docs/components/token-input.md +1007 -0
  225. package/docs/components/toolbar.md +787 -0
  226. package/docs/components/tooltip.md +884 -0
  227. package/docs/components/tree.md +1346 -0
  228. package/docs/components/trigger-menu.md +1257 -0
  229. package/docs/components/waterfall.md +754 -0
  230. package/docs/controllers.md +89 -0
  231. package/docs/core.md +8027 -0
  232. package/docs/custom-parts.md +120 -0
  233. package/docs/first-component.md +83 -0
  234. package/docs/forms.md +148 -0
  235. package/docs/hooks/async-options.md +366 -0
  236. package/docs/hooks/shortcuts.md +221 -0
  237. package/docs/installation.md +45 -0
  238. package/docs/introduction.md +32 -0
  239. package/docs/lists-and-menus.md +170 -0
  240. package/docs/llms.txt +1844 -0
  241. package/docs/parts-and-composition.md +93 -0
  242. package/docs/popups.md +117 -0
  243. package/docs/rendering.md +121 -0
  244. package/docs/server-rendering.md +253 -0
  245. package/docs/state-and-events.md +105 -0
  246. package/docs/styling-and-animation.md +176 -0
  247. package/package.json +333 -3
@@ -0,0 +1,185 @@
1
+ "use client";
2
+ // src/number-input.tsx
3
+ import {
4
+ numberInput as numberInputPrimitive
5
+ } from "@ui-sdk/core/number-input";
6
+ import * as React from "react";
7
+ import { createPortal } from "react-dom";
8
+ import { useControllerEntry, useControllerTarget } from "./controller-target.js";
9
+ import {
10
+ ownDescription,
11
+ useFieldControl,
12
+ useFieldControlId
13
+ } from "./field-context.js";
14
+ import {
15
+ createParts,
16
+ extendHandle,
17
+ renderElement,
18
+ usePart,
19
+ usePrimitive
20
+ } from "./use-primitive.js";
21
+ import { createNumberInputController } from "@ui-sdk/core/number-input";
22
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
23
+ var parts = createParts(numberInputPrimitive, {
24
+ group: "div",
25
+ increment: "button",
26
+ decrement: "button"
27
+ });
28
+ var NumberInputContext = React.createContext(
29
+ null
30
+ );
31
+ function useNumberInput(part) {
32
+ const context = React.useContext(NumberInputContext);
33
+ if (!context) {
34
+ throw new Error(`${part} must be used inside <NumberInput>.`);
35
+ }
36
+ return context;
37
+ }
38
+ function NumberInput({
39
+ value,
40
+ defaultValue,
41
+ onValueChange,
42
+ onValueCommit,
43
+ min,
44
+ max,
45
+ step,
46
+ largeStep,
47
+ smallStep,
48
+ format,
49
+ locale,
50
+ wheel,
51
+ disabled,
52
+ readOnly,
53
+ required,
54
+ name,
55
+ form,
56
+ controller,
57
+ debug,
58
+ children,
59
+ ...props
60
+ }) {
61
+ const field = useFieldControl();
62
+ const controlId = useFieldControlId();
63
+ const numberInput = usePrimitive(numberInputPrimitive, {
64
+ value,
65
+ defaultValue,
66
+ onValueChange,
67
+ onValueCommit,
68
+ min,
69
+ max,
70
+ step,
71
+ largeStep,
72
+ smallStep,
73
+ format,
74
+ locale,
75
+ wheel,
76
+ disabled: disabled || field?.disabled,
77
+ readOnly,
78
+ required,
79
+ name: name ?? field?.name,
80
+ form,
81
+ controller,
82
+ debug,
83
+ controlId
84
+ });
85
+ const context = React.useMemo(
86
+ () => extendHandle(numberInput, { field }),
87
+ [numberInput, field]
88
+ );
89
+ useControllerEntry(controller, context);
90
+ const content = (current) => /* @__PURE__ */ jsxs(Fragment, { children: [
91
+ typeof children === "function" ? children(current) : children,
92
+ /* @__PURE__ */ jsx(HiddenInput, {})
93
+ ] });
94
+ return /* @__PURE__ */ jsx(NumberInputContext.Provider, { value: context, children: usePart(numberInput, "root", {}, { ...props, children: content }) });
95
+ }
96
+ function HiddenInput() {
97
+ return usePart(numberInputPrimitive, "hidden-input", {}, {}, "input");
98
+ }
99
+ var NumberInputGroup = parts.Group;
100
+ function NumberInputControl({
101
+ render,
102
+ ...props
103
+ }) {
104
+ const numberInput = useNumberInput("NumberInputControl");
105
+ const control = (input, state) => {
106
+ const { field } = numberInput;
107
+ const [own, element] = field ? ownDescription(input, render) : [input, render];
108
+ const { value, ...rest } = field ? field.props(own) : own;
109
+ return renderElement(
110
+ "input",
111
+ { ...rest, defaultValue: value },
112
+ element,
113
+ state
114
+ );
115
+ };
116
+ return usePart(
117
+ numberInput,
118
+ "control",
119
+ {},
120
+ { ...props, render: control },
121
+ "input"
122
+ );
123
+ }
124
+ var NumberInputIncrement = parts.Increment;
125
+ var NumberInputDecrement = parts.Decrement;
126
+ var unconnected = {
127
+ value: null,
128
+ disabled: false,
129
+ readOnly: false,
130
+ required: false,
131
+ scrubbing: false
132
+ };
133
+ function NumberInputScrubArea({
134
+ orientation,
135
+ pixelsPerStep,
136
+ controller,
137
+ render,
138
+ ...props
139
+ }) {
140
+ const numberInput = useControllerTarget(
141
+ controller,
142
+ React.useContext(NumberInputContext)
143
+ );
144
+ if (!numberInput) {
145
+ return renderElement("span", props, render, unconnected);
146
+ }
147
+ return /* @__PURE__ */ jsx(NumberInputContext.Provider, { value: numberInput, children: /* @__PURE__ */ jsx(
148
+ ScrubAreaPart,
149
+ {
150
+ numberInput,
151
+ scrub: { orientation, pixelsPerStep },
152
+ props,
153
+ render
154
+ }
155
+ ) });
156
+ }
157
+ function ScrubAreaPart({
158
+ numberInput,
159
+ scrub,
160
+ props,
161
+ render
162
+ }) {
163
+ return usePart(numberInput, "scrub-area", scrub, { ...props, render }, "span");
164
+ }
165
+ function NumberInputScrubAreaCursor(props) {
166
+ const numberInput = React.useContext(NumberInputContext);
167
+ return numberInput ? /* @__PURE__ */ jsx(CursorPart, { numberInput, ...props }) : null;
168
+ }
169
+ function CursorPart({
170
+ numberInput,
171
+ ...props
172
+ }) {
173
+ const cursor = usePart(numberInput, "scrub-area-cursor", {}, props, "span");
174
+ return cursor && createPortal(cursor, document.body);
175
+ }
176
+ export {
177
+ NumberInput,
178
+ NumberInputControl,
179
+ NumberInputDecrement,
180
+ NumberInputGroup,
181
+ NumberInputIncrement,
182
+ NumberInputScrubArea,
183
+ NumberInputScrubAreaCursor,
184
+ createNumberInputController
185
+ };
@@ -0,0 +1,2 @@
1
+ export { clamp, decimalsOf, formatNumber, formatNumberRange, formatNumberToParts, fractionOf, isPartialNumber, maxOnGrid, numberFormatter, parseNumber, roundTo, scrubTo, stepBy, stepFromKey, stepValue, valueAt, wrap, } from "@ui-sdk/core/number";
2
+ export type { NumberFormat, NumberKeyOptions, NumberMove, NumberRange, NumberScale, NumberScrub, NumberSnap, StepRange, } from "@ui-sdk/core/number";
package/dist/number.js ADDED
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ // src/number.ts
3
+ import {
4
+ clamp,
5
+ decimalsOf,
6
+ formatNumber,
7
+ formatNumberRange,
8
+ formatNumberToParts,
9
+ fractionOf,
10
+ isPartialNumber,
11
+ maxOnGrid,
12
+ numberFormatter,
13
+ parseNumber,
14
+ roundTo,
15
+ scrubTo,
16
+ stepBy,
17
+ stepFromKey,
18
+ stepValue,
19
+ valueAt,
20
+ wrap
21
+ } from "@ui-sdk/core/number";
22
+ export {
23
+ clamp,
24
+ decimalsOf,
25
+ formatNumber,
26
+ formatNumberRange,
27
+ formatNumberToParts,
28
+ fractionOf,
29
+ isPartialNumber,
30
+ maxOnGrid,
31
+ numberFormatter,
32
+ parseNumber,
33
+ roundTo,
34
+ scrubTo,
35
+ stepBy,
36
+ stepFromKey,
37
+ stepValue,
38
+ valueAt,
39
+ wrap
40
+ };
@@ -0,0 +1,2 @@
1
+ export { elementOf, observe, withSource } from "@ui-sdk/core/observe";
2
+ export type { ObservedChange } from "@ui-sdk/core/observe";
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ // src/observe.ts
3
+ import { elementOf, observe, withSource } from "@ui-sdk/core/observe";
4
+ export {
5
+ elementOf,
6
+ observe,
7
+ withSource
8
+ };
@@ -0,0 +1,29 @@
1
+ import { type OTPInputOptions, type OTPInputSlotProps, type OTPInputSlotState, type OTPInputState } from "@ui-sdk/core/otp-input";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ type DivProps<State> = Omit<PartProps<"div", State>, "defaultValue" | "onChange" | "onSelect">;
5
+ type InputProps = Pick<React.ComponentProps<"input">, "id" | "autoFocus" | "aria-label" | "aria-labelledby" | "aria-describedby" | "aria-invalid">;
6
+ /**
7
+ * The root: the slots, and the one real input over them. `id`, `autoFocus`
8
+ * and the `aria-*` naming props go to that input.
9
+ * @stable
10
+ */
11
+ declare function OTPInput({ disabled, name, id, autoFocus, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, "aria-invalid": invalid, children, ...props }: OTPInputOptions & InputProps & DivProps<OTPInputState>): React.JSX.Element;
12
+ /**
13
+ * Lays out a run of slots.
14
+ * @stable
15
+ */
16
+ declare const OTPInputGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/otp-input").OtpInputPrimitive, "group", "div">;
17
+ /**
18
+ * One character of the code. Without children, it shows the character.
19
+ * @stable
20
+ */
21
+ declare function OTPInputSlot({ index, children, ...props }: OTPInputSlotProps & DivProps<OTPInputSlotState>): React.JSX.Element | null;
22
+ /**
23
+ * Drawn between groups, like a dash.
24
+ * @stable
25
+ */
26
+ declare const OTPInputSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/otp-input").OtpInputPrimitive, "separator", "div">;
27
+ export { createOTPInputController } from "@ui-sdk/core/otp-input";
28
+ export type { OTPInputApi, OTPInputChangeOptions, OTPInputController, OTPInputOptions, OTPInputPattern, OTPInputSlotData, OTPInputSlotProps, OTPInputSlotState, OTPInputState, OTPInputValueChangeReason, OtpInputPrimitive, } from "@ui-sdk/core/otp-input";
29
+ export { OTPInput, OTPInputGroup, OTPInputSeparator, OTPInputSlot };
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ // src/otp-input.tsx
3
+ import {
4
+ otpInput
5
+ } from "@ui-sdk/core/otp-input";
6
+ import * as React from "react";
7
+ import { useFieldControl } from "./field-context.js";
8
+ import {
9
+ createParts,
10
+ slotIn,
11
+ useHandle,
12
+ usePart
13
+ } from "./use-primitive.js";
14
+ import { createOTPInputController } from "@ui-sdk/core/otp-input";
15
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ var parts = createParts(otpInput, {
17
+ root: "div",
18
+ group: "div",
19
+ separator: "div"
20
+ });
21
+ function withInput(children, input) {
22
+ return (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
23
+ typeof children === "function" ? children(state) : children,
24
+ input
25
+ ] });
26
+ }
27
+ function OTPInputControl(props) {
28
+ const otp = useHandle(otpInput);
29
+ const field = useFieldControl();
30
+ const [initial] = React.useState(
31
+ () => slotIn(otp, "control").value
32
+ );
33
+ const render = (control) => {
34
+ const { value: _, ...input } = field ? field.props(control) : control;
35
+ return /* @__PURE__ */ jsx("input", { ...input, defaultValue: initial });
36
+ };
37
+ return usePart(otp, "control", {}, { ...props, render }, "input");
38
+ }
39
+ function OTPInput({
40
+ disabled,
41
+ name,
42
+ id,
43
+ autoFocus,
44
+ "aria-label": label,
45
+ "aria-labelledby": labelledBy,
46
+ "aria-describedby": describedBy,
47
+ "aria-invalid": invalid,
48
+ children,
49
+ ...props
50
+ }) {
51
+ const field = useFieldControl();
52
+ const input = /* @__PURE__ */ jsx(
53
+ OTPInputControl,
54
+ {
55
+ id,
56
+ autoFocus,
57
+ "aria-label": label,
58
+ "aria-labelledby": labelledBy,
59
+ "aria-describedby": describedBy,
60
+ "aria-invalid": invalid
61
+ }
62
+ );
63
+ return /* @__PURE__ */ jsx(
64
+ parts.Root,
65
+ {
66
+ ...props,
67
+ disabled: disabled || field?.disabled,
68
+ name: name ?? field?.name,
69
+ children: withInput(children, input)
70
+ }
71
+ );
72
+ }
73
+ var OTPInputGroup = parts.Group;
74
+ var char = (state) => state.char;
75
+ function OTPInputSlot({
76
+ index,
77
+ children = char,
78
+ ...props
79
+ }) {
80
+ return usePart(
81
+ otpInput,
82
+ "slot",
83
+ { index, id: String(index) },
84
+ { ...props, children }
85
+ );
86
+ }
87
+ var OTPInputSeparator = parts.Separator;
88
+ export {
89
+ OTPInput,
90
+ OTPInputGroup,
91
+ OTPInputSeparator,
92
+ OTPInputSlot,
93
+ createOTPInputController
94
+ };
@@ -0,0 +1,26 @@
1
+ import { type Overlays } from "@ui-sdk/core/overlays";
2
+ import * as React from "react";
3
+ import { type ToastRegionProps } from "./toast-parts.js";
4
+ /**
5
+ * Props for `OverlayHost`.
6
+ * @stable
7
+ */
8
+ type OverlayHostProps = {
9
+ /**
10
+ * The registry it renders.
11
+ * @defaultValue the shared `overlays`, which `toast()` and `confirm()` open into
12
+ */
13
+ overlays?: Overlays;
14
+ /** Props for the toast regions it renders, like `side`, `className` and `children`. */
15
+ toast?: Omit<ToastRegionProps, "toaster">;
16
+ };
17
+ /**
18
+ * Renders what `toast()` and `confirm()` open, from anywhere in the app.
19
+ * Mount it once, near the root. A `ToastRegion` you place yourself takes over
20
+ * its toaster.
21
+ * @stable
22
+ */
23
+ declare function OverlayHost({ overlays, toast }: OverlayHostProps): (React.JSX.Element | null)[];
24
+ export { createOverlays, overlays } from "@ui-sdk/core/overlays";
25
+ export type { OverlayEntry, Overlays } from "@ui-sdk/core/overlays";
26
+ export { OverlayHost, type OverlayHostProps };
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ // src/overlays.tsx
3
+ import {
4
+ overlays as sharedOverlays
5
+ } from "@ui-sdk/core/overlays";
6
+ import { toasterInternals } from "@ui-sdk/core/renderer";
7
+ import * as React from "react";
8
+ import {
9
+ AlertDialog,
10
+ AlertDialogClose,
11
+ AlertDialogContent,
12
+ AlertDialogDescription,
13
+ AlertDialogTitle
14
+ } from "./alert-dialog.js";
15
+ import { Region } from "./toast-parts.js";
16
+ import { createOverlays, overlays } from "@ui-sdk/core/overlays";
17
+ import { jsx, jsxs } from "react/jsx-runtime";
18
+ var noEntries = [];
19
+ function OverlayHost({ overlays: overlays2 = sharedOverlays, toast }) {
20
+ const entries = React.useSyncExternalStore(
21
+ overlays2.subscribe,
22
+ overlays2.entries,
23
+ () => noEntries
24
+ );
25
+ React.useLayoutEffect(() => overlays2.attachHost(), [overlays2]);
26
+ return entries.map((entry) => {
27
+ if (entry.type === "toaster") {
28
+ return /* @__PURE__ */ jsx(
29
+ HostedToaster,
30
+ {
31
+ ...entry.data,
32
+ props: toast
33
+ },
34
+ entry.id
35
+ );
36
+ }
37
+ if (entry.type === "confirm") {
38
+ return /* @__PURE__ */ jsx(HostedConfirm, { entry: entry.data }, entry.id);
39
+ }
40
+ return null;
41
+ });
42
+ }
43
+ function HostedToaster({
44
+ toaster,
45
+ props
46
+ }) {
47
+ const placed = React.useSyncExternalStore(
48
+ toaster.subscribe,
49
+ () => toasterInternals(toaster).hasPlacedRegion(),
50
+ () => false
51
+ );
52
+ if (placed) {
53
+ return null;
54
+ }
55
+ return /* @__PURE__ */ jsx(Region, { ...props, toaster, placed: false });
56
+ }
57
+ function HostedConfirm({ entry }) {
58
+ React.useEffect(() => {
59
+ entry.open();
60
+ }, [entry]);
61
+ const question = entry.payload ?? {};
62
+ return /* @__PURE__ */ jsx(
63
+ AlertDialog,
64
+ {
65
+ controller: entry.controller,
66
+ onOpenChangeComplete: (open) => !open && entry.done(),
67
+ children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
68
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: question.title }),
69
+ question.description && /* @__PURE__ */ jsx(AlertDialogDescription, { children: question.description }),
70
+ /* @__PURE__ */ jsxs("div", { children: [
71
+ /* @__PURE__ */ jsx(AlertDialogClose, { children: question.cancelLabel ?? "Cancel" }),
72
+ /* @__PURE__ */ jsx(AlertDialogClose, { value: "confirm", children: question.confirmLabel ?? "Continue" })
73
+ ] })
74
+ ] })
75
+ }
76
+ );
77
+ }
78
+ export {
79
+ OverlayHost,
80
+ createOverlays,
81
+ overlays
82
+ };