@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.
- package/LICENSE +202 -0
- package/README.md +10 -2
- package/dist/accordion.d.ts +331 -0
- package/dist/accordion.js +25 -0
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +8 -0
- package/dist/alert-dialog.d.ts +56 -0
- package/dist/alert-dialog.js +45 -0
- package/dist/async-options.d.ts +22 -0
- package/dist/async-options.js +56 -0
- package/dist/autocomplete.d.ts +102 -0
- package/dist/autocomplete.js +195 -0
- package/dist/avatar.d.ts +301 -0
- package/dist/avatar.js +17 -0
- package/dist/button.d.ts +21 -0
- package/dist/button.js +45 -0
- package/dist/calendar-context.d.ts +10 -0
- package/dist/calendar-context.js +9 -0
- package/dist/calendar.d.ts +80 -0
- package/dist/calendar.js +257 -0
- package/dist/carousel.d.ts +52 -0
- package/dist/carousel.js +151 -0
- package/dist/checkbox.d.ts +24 -0
- package/dist/checkbox.js +98 -0
- package/dist/children.d.ts +38 -0
- package/dist/children.js +63 -0
- package/dist/collapsible.d.ts +302 -0
- package/dist/collapsible.js +19 -0
- package/dist/color-picker.d.ts +72 -0
- package/dist/color-picker.js +133 -0
- package/dist/color.d.ts +2 -0
- package/dist/color.js +22 -0
- package/dist/combobox.d.ts +152 -0
- package/dist/combobox.js +338 -0
- package/dist/command.d.ts +88 -0
- package/dist/command.js +233 -0
- package/dist/controller-target.d.ts +3 -0
- package/dist/controller-target.js +59 -0
- package/dist/date-input.d.ts +19 -0
- package/dist/date-input.js +58 -0
- package/dist/date-picker.d.ts +47 -0
- package/dist/date-picker.js +310 -0
- package/dist/date.d.ts +2 -0
- package/dist/date.js +60 -0
- package/dist/dialog-parts.d.ts +23 -0
- package/dist/dialog-parts.js +142 -0
- package/dist/dialog.d.ts +57 -0
- package/dist/dialog.js +32 -0
- package/dist/drawer.d.ts +70 -0
- package/dist/drawer.js +158 -0
- package/dist/editor-context.d.ts +4 -0
- package/dist/editor-context.js +9 -0
- package/dist/field-context.d.ts +47 -0
- package/dist/field-context.js +87 -0
- package/dist/field.d.ts +49 -0
- package/dist/field.js +169 -0
- package/dist/file-input.d.ts +46 -0
- package/dist/file-input.js +170 -0
- package/dist/form-inputs.d.ts +5 -0
- package/dist/form-inputs.js +22 -0
- package/dist/gesture.d.ts +1 -0
- package/dist/gesture.js +16 -0
- package/dist/history.d.ts +2 -0
- package/dist/history.js +12 -0
- package/dist/hover-card.d.ts +33 -0
- package/dist/hover-card.js +84 -0
- package/dist/image-cropper.d.ts +333 -0
- package/dist/image-cropper.js +37 -0
- package/dist/image.d.ts +2 -0
- package/dist/image.js +6 -0
- package/dist/input.d.ts +22 -0
- package/dist/input.js +51 -0
- package/dist/label.d.ts +294 -0
- package/dist/label.js +9 -0
- package/dist/list-items.d.ts +15 -0
- package/dist/list-items.js +39 -0
- package/dist/list-text.d.ts +4 -0
- package/dist/list-text.js +15 -0
- package/dist/listbox.d.ts +56 -0
- package/dist/listbox.js +122 -0
- package/dist/menu.d.ts +116 -0
- package/dist/menu.js +426 -0
- package/dist/menubar-context.d.ts +4 -0
- package/dist/menubar-context.js +7 -0
- package/dist/menubar.d.ts +11 -0
- package/dist/menubar.js +32 -0
- package/dist/meter.d.ts +312 -0
- package/dist/meter.js +30 -0
- package/dist/navigation-menu.d.ts +61 -0
- package/dist/navigation-menu.js +169 -0
- package/dist/number-input.d.ts +44 -0
- package/dist/number-input.js +185 -0
- package/dist/number.d.ts +2 -0
- package/dist/number.js +40 -0
- package/dist/observe.d.ts +2 -0
- package/dist/observe.js +8 -0
- package/dist/otp-input.d.ts +29 -0
- package/dist/otp-input.js +94 -0
- package/dist/overlays.d.ts +26 -0
- package/dist/overlays.js +82 -0
- package/dist/pagination.d.ts +336 -0
- package/dist/pagination.js +71 -0
- package/dist/password-input.d.ts +23 -0
- package/dist/password-input.js +65 -0
- package/dist/popover.d.ts +54 -0
- package/dist/popover.js +151 -0
- package/dist/popup.d.ts +41 -0
- package/dist/popup.js +180 -0
- package/dist/preferences.d.ts +35 -0
- package/dist/preferences.js +93 -0
- package/dist/primitive.d.ts +2 -0
- package/dist/primitive.js +14 -0
- package/dist/progress.d.ts +312 -0
- package/dist/progress.js +30 -0
- package/dist/radio.d.ts +22 -0
- package/dist/radio.js +86 -0
- package/dist/rating.d.ts +20 -0
- package/dist/rating.js +94 -0
- package/dist/render-element.d.ts +35 -0
- package/dist/render-element.js +103 -0
- package/dist/resizable.d.ts +302 -0
- package/dist/resizable.js +23 -0
- package/dist/scroll-area.d.ts +324 -0
- package/dist/scroll-area.js +49 -0
- package/dist/segmented-control.d.ts +24 -0
- package/dist/segmented-control.js +78 -0
- package/dist/segmented-input.d.ts +15 -0
- package/dist/segmented-input.js +48 -0
- package/dist/select.d.ts +125 -0
- package/dist/select.js +330 -0
- package/dist/separator.d.ts +290 -0
- package/dist/separator.js +9 -0
- package/dist/shortcuts.d.ts +32 -0
- package/dist/shortcuts.js +61 -0
- package/dist/slider.d.ts +38 -0
- package/dist/slider.js +163 -0
- package/dist/switch.d.ts +15 -0
- package/dist/switch.js +39 -0
- package/dist/tabs.d.ts +331 -0
- package/dist/tabs.js +28 -0
- package/dist/text-control.d.ts +22 -0
- package/dist/text-control.js +24 -0
- package/dist/text-match.d.ts +2 -0
- package/dist/text-match.js +8 -0
- package/dist/textarea.d.ts +10 -0
- package/dist/textarea.js +48 -0
- package/dist/time-input.d.ts +19 -0
- package/dist/time-input.js +63 -0
- package/dist/timeline.d.ts +327 -0
- package/dist/timeline.js +31 -0
- package/dist/toast-parts.d.ts +63 -0
- package/dist/toast-parts.js +144 -0
- package/dist/toast.d.ts +2 -0
- package/dist/toast.js +22 -0
- package/dist/toggle.d.ts +23 -0
- package/dist/toggle.js +76 -0
- package/dist/token-input.d.ts +35 -0
- package/dist/token-input.js +100 -0
- package/dist/toolbar-context.d.ts +6 -0
- package/dist/toolbar-context.js +16 -0
- package/dist/toolbar.d.ts +38 -0
- package/dist/toolbar.js +63 -0
- package/dist/tooltip.d.ts +39 -0
- package/dist/tooltip.js +108 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +150 -0
- package/dist/trigger-menu.d.ts +83 -0
- package/dist/trigger-menu.js +167 -0
- package/dist/use-primitive.d.ts +178 -0
- package/dist/use-primitive.js +674 -0
- package/dist/waterfall.d.ts +80 -0
- package/dist/waterfall.js +108 -0
- package/docs/README.md +89 -0
- package/docs/agents.md +1523 -0
- package/docs/components/accordion.md +1391 -0
- package/docs/components/alert-dialog.md +850 -0
- package/docs/components/autocomplete.md +1963 -0
- package/docs/components/avatar.md +252 -0
- package/docs/components/button.md +444 -0
- package/docs/components/calendar.md +1687 -0
- package/docs/components/carousel.md +1244 -0
- package/docs/components/checkbox.md +1069 -0
- package/docs/components/collapsible.md +567 -0
- package/docs/components/color-picker.md +736 -0
- package/docs/components/combobox.md +3647 -0
- package/docs/components/command.md +1573 -0
- package/docs/components/date-input.md +608 -0
- package/docs/components/date-picker.md +1266 -0
- package/docs/components/dialog.md +1469 -0
- package/docs/components/drawer.md +1197 -0
- package/docs/components/field.md +549 -0
- package/docs/components/file-input.md +609 -0
- package/docs/components/hover-card.md +514 -0
- package/docs/components/image-cropper.md +579 -0
- package/docs/components/input.md +301 -0
- package/docs/components/label.md +217 -0
- package/docs/components/listbox.md +1130 -0
- package/docs/components/menu.md +1286 -0
- package/docs/components/menubar.md +455 -0
- package/docs/components/meter.md +304 -0
- package/docs/components/navigation-menu.md +1581 -0
- package/docs/components/number-input.md +1086 -0
- package/docs/components/otp-input.md +565 -0
- package/docs/components/pagination.md +648 -0
- package/docs/components/password-input.md +737 -0
- package/docs/components/popover.md +1552 -0
- package/docs/components/preferences.md +220 -0
- package/docs/components/progress.md +443 -0
- package/docs/components/radio.md +846 -0
- package/docs/components/rating.md +458 -0
- package/docs/components/resizable.md +982 -0
- package/docs/components/scroll-area.md +980 -0
- package/docs/components/segmented-control.md +465 -0
- package/docs/components/select.md +2133 -0
- package/docs/components/separator.md +243 -0
- package/docs/components/slider.md +1169 -0
- package/docs/components/switch.md +613 -0
- package/docs/components/tabs.md +1014 -0
- package/docs/components/textarea.md +318 -0
- package/docs/components/time-input.md +231 -0
- package/docs/components/timeline.md +677 -0
- package/docs/components/toast.md +1395 -0
- package/docs/components/toggle.md +541 -0
- package/docs/components/token-input.md +1007 -0
- package/docs/components/toolbar.md +787 -0
- package/docs/components/tooltip.md +884 -0
- package/docs/components/tree.md +1346 -0
- package/docs/components/trigger-menu.md +1257 -0
- package/docs/components/waterfall.md +754 -0
- package/docs/controllers.md +89 -0
- package/docs/core.md +8027 -0
- package/docs/custom-parts.md +120 -0
- package/docs/first-component.md +83 -0
- package/docs/forms.md +148 -0
- package/docs/hooks/async-options.md +366 -0
- package/docs/hooks/shortcuts.md +221 -0
- package/docs/installation.md +45 -0
- package/docs/introduction.md +32 -0
- package/docs/lists-and-menus.md +170 -0
- package/docs/llms.txt +1844 -0
- package/docs/parts-and-composition.md +93 -0
- package/docs/popups.md +117 -0
- package/docs/rendering.md +121 -0
- package/docs/server-rendering.md +253 -0
- package/docs/state-and-events.md +105 -0
- package/docs/styling-and-animation.md +176 -0
- 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
|
+
};
|
package/dist/number.d.ts
ADDED
|
@@ -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
|
+
};
|
package/dist/observe.js
ADDED
|
@@ -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 };
|
package/dist/overlays.js
ADDED
|
@@ -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
|
+
};
|