@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
package/dist/command.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/command.tsx
|
|
3
|
+
import {
|
|
4
|
+
command as commandPrimitive
|
|
5
|
+
} from "@ui-sdk/core/command";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { hasChild, Placed, usePlaceContent, usePlacedContent } from "./children.js";
|
|
8
|
+
import { useControllerEntry } from "./controller-target.js";
|
|
9
|
+
import { markSegments, textToMark } from "./list-text.js";
|
|
10
|
+
import {
|
|
11
|
+
createParts,
|
|
12
|
+
useAround,
|
|
13
|
+
useHandle,
|
|
14
|
+
usePart,
|
|
15
|
+
usePrimitive
|
|
16
|
+
} from "./use-primitive.js";
|
|
17
|
+
import { createCommandController } from "@ui-sdk/core/command";
|
|
18
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
+
var parts = createParts(commandPrimitive, {
|
|
20
|
+
input: "input",
|
|
21
|
+
"item-icon": "span",
|
|
22
|
+
group: "div",
|
|
23
|
+
"group-label": "div",
|
|
24
|
+
separator: "div",
|
|
25
|
+
status: "div"
|
|
26
|
+
});
|
|
27
|
+
var PageContext = React.createContext(void 0);
|
|
28
|
+
var DataContext = React.createContext(false);
|
|
29
|
+
function useCommand() {
|
|
30
|
+
return useHandle(commandPrimitive);
|
|
31
|
+
}
|
|
32
|
+
function Command({
|
|
33
|
+
value,
|
|
34
|
+
defaultValue,
|
|
35
|
+
onValueChange,
|
|
36
|
+
query,
|
|
37
|
+
defaultQuery,
|
|
38
|
+
onQueryChange,
|
|
39
|
+
pages,
|
|
40
|
+
defaultPages,
|
|
41
|
+
onPagesChange,
|
|
42
|
+
onAction,
|
|
43
|
+
pendingAnnouncement,
|
|
44
|
+
items,
|
|
45
|
+
emptyItems,
|
|
46
|
+
filter,
|
|
47
|
+
autoHighlight,
|
|
48
|
+
loop,
|
|
49
|
+
status,
|
|
50
|
+
onLoadMore,
|
|
51
|
+
announcement,
|
|
52
|
+
controller,
|
|
53
|
+
debug,
|
|
54
|
+
children,
|
|
55
|
+
...props
|
|
56
|
+
}) {
|
|
57
|
+
const command = usePrimitive(commandPrimitive, {
|
|
58
|
+
value,
|
|
59
|
+
defaultValue,
|
|
60
|
+
onValueChange,
|
|
61
|
+
query,
|
|
62
|
+
defaultQuery,
|
|
63
|
+
onQueryChange,
|
|
64
|
+
pages,
|
|
65
|
+
defaultPages,
|
|
66
|
+
onPagesChange,
|
|
67
|
+
onAction,
|
|
68
|
+
pendingAnnouncement,
|
|
69
|
+
items,
|
|
70
|
+
emptyItems,
|
|
71
|
+
filter,
|
|
72
|
+
autoHighlight,
|
|
73
|
+
loop,
|
|
74
|
+
status,
|
|
75
|
+
onLoadMore,
|
|
76
|
+
announcement,
|
|
77
|
+
controller,
|
|
78
|
+
debug
|
|
79
|
+
});
|
|
80
|
+
useControllerEntry(controller, command);
|
|
81
|
+
const found = typeof children !== "function" && hasChild(children, CommandList);
|
|
82
|
+
const [placed, place] = usePlacedContent(
|
|
83
|
+
typeof children !== "function" && !!items && !found
|
|
84
|
+
);
|
|
85
|
+
const own = placed || found;
|
|
86
|
+
const content = (state) => typeof children === "function" ? /* @__PURE__ */ jsx(Placed, { value: place, children: children(state) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
87
|
+
/* @__PURE__ */ jsx(Placed, { value: place, children }),
|
|
88
|
+
/* @__PURE__ */ jsx(Placed, { value: null, children: items && !own && /* @__PURE__ */ jsx(CommandList, {}) })
|
|
89
|
+
] });
|
|
90
|
+
return usePart(command, "root", {}, { ...props, children: content });
|
|
91
|
+
}
|
|
92
|
+
var CommandInput = parts.Input;
|
|
93
|
+
function CommandList({
|
|
94
|
+
children,
|
|
95
|
+
...props
|
|
96
|
+
}) {
|
|
97
|
+
usePlaceContent();
|
|
98
|
+
const command = useCommand();
|
|
99
|
+
const content = (state) => typeof children === "function" ? children(state) : children ?? (command.state.items ? /* @__PURE__ */ jsx(CommandItems, { items: state.items }) : null);
|
|
100
|
+
return usePart(command, "list", {}, { ...props, children: content });
|
|
101
|
+
}
|
|
102
|
+
function CommandItem({
|
|
103
|
+
value,
|
|
104
|
+
label,
|
|
105
|
+
keywords,
|
|
106
|
+
disabled,
|
|
107
|
+
shortcut,
|
|
108
|
+
page,
|
|
109
|
+
index,
|
|
110
|
+
onSelect,
|
|
111
|
+
render,
|
|
112
|
+
...props
|
|
113
|
+
}) {
|
|
114
|
+
const command = useCommand();
|
|
115
|
+
const generated = React.useId();
|
|
116
|
+
const group = useAround(commandPrimitive, "group")?.id;
|
|
117
|
+
const inPage = React.useContext(PageContext);
|
|
118
|
+
const data = React.useContext(DataContext);
|
|
119
|
+
const key = value ?? generated;
|
|
120
|
+
const item = {
|
|
121
|
+
id: key,
|
|
122
|
+
value: key,
|
|
123
|
+
label,
|
|
124
|
+
keywords,
|
|
125
|
+
disabled,
|
|
126
|
+
shortcut,
|
|
127
|
+
page,
|
|
128
|
+
index,
|
|
129
|
+
onSelect,
|
|
130
|
+
group,
|
|
131
|
+
inPage,
|
|
132
|
+
data
|
|
133
|
+
};
|
|
134
|
+
return usePart(command, "item", item, { ...props, render });
|
|
135
|
+
}
|
|
136
|
+
function CommandItemText({
|
|
137
|
+
children,
|
|
138
|
+
...props
|
|
139
|
+
}) {
|
|
140
|
+
const item = useAround(commandPrimitive, "item");
|
|
141
|
+
if (!item) {
|
|
142
|
+
throw new Error("<CommandItemText> must be used inside <CommandItem>.");
|
|
143
|
+
}
|
|
144
|
+
const label = item.label ?? item.value;
|
|
145
|
+
const part = { id: item.value, text: textToMark(children, label) };
|
|
146
|
+
const content = typeof children === "function" ? children : (state) => markSegments(state.segments);
|
|
147
|
+
return usePart(
|
|
148
|
+
commandPrimitive,
|
|
149
|
+
"item-text",
|
|
150
|
+
part,
|
|
151
|
+
{ ...props, children: content },
|
|
152
|
+
"span"
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
var CommandItemIcon = parts.ItemIcon;
|
|
156
|
+
function CommandShortcut({
|
|
157
|
+
shortcut,
|
|
158
|
+
children = text,
|
|
159
|
+
...props
|
|
160
|
+
}) {
|
|
161
|
+
const inherited = useAround(commandPrimitive, "item")?.shortcut;
|
|
162
|
+
return usePart(
|
|
163
|
+
commandPrimitive,
|
|
164
|
+
"shortcut",
|
|
165
|
+
{ shortcut: shortcut ?? inherited },
|
|
166
|
+
{ ...props, children },
|
|
167
|
+
"span"
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
var text = (state) => state.text;
|
|
171
|
+
function CommandPage({
|
|
172
|
+
value,
|
|
173
|
+
children
|
|
174
|
+
}) {
|
|
175
|
+
const page = () => /* @__PURE__ */ jsx(PageContext.Provider, { value: value ?? null, children });
|
|
176
|
+
return usePart(commandPrimitive, "page", { value }, { render: page });
|
|
177
|
+
}
|
|
178
|
+
var CommandGroup = parts.Group;
|
|
179
|
+
var CommandGroupLabel = parts.GroupLabel;
|
|
180
|
+
var CommandSeparator = parts.Separator;
|
|
181
|
+
function CommandEmpty({
|
|
182
|
+
children,
|
|
183
|
+
...props
|
|
184
|
+
}) {
|
|
185
|
+
const content = (state) => typeof children === "function" ? children(state) : state.empty ? children : null;
|
|
186
|
+
return usePart(commandPrimitive, "empty", {}, { ...props, children: content });
|
|
187
|
+
}
|
|
188
|
+
var CommandStatus = parts.Status;
|
|
189
|
+
function CommandItems({ items }) {
|
|
190
|
+
return /* @__PURE__ */ jsx(DataContext.Provider, { value: true, children: items.map((entry, index) => {
|
|
191
|
+
if (typeof entry === "string") {
|
|
192
|
+
return /* @__PURE__ */ jsx(CommandItem, { value: entry, children: entry }, entry);
|
|
193
|
+
}
|
|
194
|
+
if ("type" in entry && entry.type === "separator") {
|
|
195
|
+
return /* @__PURE__ */ jsx(CommandSeparator, {}, `separator-${index}`);
|
|
196
|
+
}
|
|
197
|
+
if ("type" in entry && entry.type === "group") {
|
|
198
|
+
return /* @__PURE__ */ jsxs(CommandGroup, { children: [
|
|
199
|
+
entry.label && /* @__PURE__ */ jsx(CommandGroupLabel, { children: entry.label }),
|
|
200
|
+
/* @__PURE__ */ jsx(CommandItems, { items: entry.items })
|
|
201
|
+
] }, `group-${entry.label ?? index}`);
|
|
202
|
+
}
|
|
203
|
+
return /* @__PURE__ */ jsx(
|
|
204
|
+
CommandItem,
|
|
205
|
+
{
|
|
206
|
+
value: entry.value,
|
|
207
|
+
label: entry.label,
|
|
208
|
+
keywords: entry.keywords,
|
|
209
|
+
disabled: entry.disabled,
|
|
210
|
+
shortcut: entry.shortcut,
|
|
211
|
+
children: entry.label
|
|
212
|
+
},
|
|
213
|
+
entry.value
|
|
214
|
+
);
|
|
215
|
+
}) });
|
|
216
|
+
}
|
|
217
|
+
export {
|
|
218
|
+
Command,
|
|
219
|
+
CommandEmpty,
|
|
220
|
+
CommandGroup,
|
|
221
|
+
CommandGroupLabel,
|
|
222
|
+
CommandInput,
|
|
223
|
+
CommandItem,
|
|
224
|
+
CommandItemIcon,
|
|
225
|
+
CommandItemText,
|
|
226
|
+
CommandItems,
|
|
227
|
+
CommandList,
|
|
228
|
+
CommandPage,
|
|
229
|
+
CommandSeparator,
|
|
230
|
+
CommandShortcut,
|
|
231
|
+
CommandStatus,
|
|
232
|
+
createCommandController
|
|
233
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/controller-target.ts
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
var controlled = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
function controlledEntry(controller) {
|
|
6
|
+
let entry = controlled.get(controller);
|
|
7
|
+
if (!entry) {
|
|
8
|
+
controlled.set(
|
|
9
|
+
controller,
|
|
10
|
+
entry = { value: void 0, listeners: /* @__PURE__ */ new Set() }
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return entry;
|
|
14
|
+
}
|
|
15
|
+
var noController = () => () => {
|
|
16
|
+
};
|
|
17
|
+
function useControllerTarget(controller, nearest) {
|
|
18
|
+
const subscribe = React.useCallback(
|
|
19
|
+
(listener) => {
|
|
20
|
+
if (!controller) {
|
|
21
|
+
return () => {
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const { listeners } = controlledEntry(controller);
|
|
25
|
+
listeners.add(listener);
|
|
26
|
+
return () => {
|
|
27
|
+
listeners.delete(listener);
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
[controller]
|
|
31
|
+
);
|
|
32
|
+
const read = () => controller ? controlled.get(controller)?.value : void 0;
|
|
33
|
+
return React.useSyncExternalStore(
|
|
34
|
+
controller ? subscribe : noController,
|
|
35
|
+
read,
|
|
36
|
+
() => void 0
|
|
37
|
+
) ?? nearest;
|
|
38
|
+
}
|
|
39
|
+
function useControllerEntry(controller, value) {
|
|
40
|
+
React.useLayoutEffect(() => {
|
|
41
|
+
if (!controller) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const entry = controlledEntry(controller);
|
|
45
|
+
entry.value = value;
|
|
46
|
+
entry.listeners.forEach((listener) => listener());
|
|
47
|
+
return () => {
|
|
48
|
+
if (entry.value !== value) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
entry.value = void 0;
|
|
52
|
+
entry.listeners.forEach((listener) => listener());
|
|
53
|
+
};
|
|
54
|
+
}, [controller, value]);
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
useControllerEntry,
|
|
58
|
+
useControllerTarget
|
|
59
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type DateInputOptions } from "@ui-sdk/core/date-input";
|
|
2
|
+
import { type RootProps, type SegmentProps } from "./segmented-input.js";
|
|
3
|
+
/**
|
|
4
|
+
* The root: a group of segments the locale orders, like month, day and year,
|
|
5
|
+
* and the hidden input the ISO value submits with. Without children it renders
|
|
6
|
+
* every segment; its children can be a function of its state that renders
|
|
7
|
+
* `state.segments`.
|
|
8
|
+
* @stable
|
|
9
|
+
*/
|
|
10
|
+
declare function DateInput({ value, defaultValue, onValueChange, granularity, hourCycle, min, max, unavailable, locale, disabled, readOnly, required, name, form, controller, debug, ...props }: DateInputOptions & RootProps): import("react").JSX.Element | null;
|
|
11
|
+
/**
|
|
12
|
+
* A segment, like the month: an input arrow keys step and digits fill, named
|
|
13
|
+
* by its unit. The text between segments renders as a span.
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
declare function DateInputSegment(props: SegmentProps): import("react").JSX.Element | null;
|
|
17
|
+
export { createDateInputController } from "@ui-sdk/core/date-input";
|
|
18
|
+
export type { DateInputApi, DateInputChangeOptions, DateInputController, DateInputGranularity, DateInputOptions, DateInputPrimitive, DateInputSegmentData, DateInputSegmentProps, DateInputSegmentState, DateInputSegmentType, DateInputState, DateInputValueChangeReason, DateMatcher, DateMatchers, HourCycle, } from "@ui-sdk/core/date-input";
|
|
19
|
+
export { DateInput, DateInputSegment };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/date-input.tsx
|
|
3
|
+
import { dateInput } from "@ui-sdk/core/date-input";
|
|
4
|
+
import { useFieldControl } from "./field-context.js";
|
|
5
|
+
import {
|
|
6
|
+
useSegmentedRoot,
|
|
7
|
+
useSegment
|
|
8
|
+
} from "./segmented-input.js";
|
|
9
|
+
import { usePrimitive } from "./use-primitive.js";
|
|
10
|
+
import { createDateInputController } from "@ui-sdk/core/date-input";
|
|
11
|
+
function DateInput({
|
|
12
|
+
value,
|
|
13
|
+
defaultValue,
|
|
14
|
+
onValueChange,
|
|
15
|
+
granularity,
|
|
16
|
+
hourCycle,
|
|
17
|
+
min,
|
|
18
|
+
max,
|
|
19
|
+
unavailable,
|
|
20
|
+
locale,
|
|
21
|
+
disabled,
|
|
22
|
+
readOnly,
|
|
23
|
+
required,
|
|
24
|
+
name,
|
|
25
|
+
form,
|
|
26
|
+
controller,
|
|
27
|
+
debug,
|
|
28
|
+
...props
|
|
29
|
+
}) {
|
|
30
|
+
const field = useFieldControl();
|
|
31
|
+
const instance = usePrimitive(dateInput, {
|
|
32
|
+
value,
|
|
33
|
+
defaultValue,
|
|
34
|
+
onValueChange,
|
|
35
|
+
granularity,
|
|
36
|
+
hourCycle,
|
|
37
|
+
min,
|
|
38
|
+
max,
|
|
39
|
+
unavailable,
|
|
40
|
+
locale,
|
|
41
|
+
disabled: disabled || field?.disabled,
|
|
42
|
+
readOnly,
|
|
43
|
+
required,
|
|
44
|
+
name: name ?? field?.name,
|
|
45
|
+
form,
|
|
46
|
+
controller,
|
|
47
|
+
debug
|
|
48
|
+
});
|
|
49
|
+
return useSegmentedRoot(dateInput, instance, field, props, DateInputSegment);
|
|
50
|
+
}
|
|
51
|
+
function DateInputSegment(props) {
|
|
52
|
+
return useSegment(dateInput, props);
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
DateInput,
|
|
56
|
+
DateInputSegment,
|
|
57
|
+
createDateInputController
|
|
58
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type DatePickerContentProps, type DatePickerContentState, type DatePickerHintState, type DatePickerInputProps, type DatePickerInputState, type DatePickerOptions, type DatePickerPresetState, type DatePickerState, type DatePickerTriggerState, type DatePickerValue } from "@ui-sdk/core/date-picker";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type PartProps } from "./use-primitive.js";
|
|
4
|
+
/**
|
|
5
|
+
* The root, and the hidden inputs that submit ISO dates. Without children it
|
|
6
|
+
* renders an input, or two in range mode, the trigger and the popup.
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
declare function DatePicker({ mode, value, defaultValue, onValueChange, month, defaultMonth, onMonthChange, open, defaultOpen, onOpenChange, onOpenChangeComplete, closeOnSelect, presentation, dismissible, onDismissAttempt, min, max, unavailable, disabled, readOnly, months, pageBy, locale, weekStartsOn, weekdayFormat, monthFormat, fixedWeeks, showOutsideDays, today, timeZone, minDays, maxDays, allowUnavailable, name, startName, endName, form, required, container, controller, debug, children, ...props }: DatePickerOptions & Omit<PartProps<"div", DatePickerState>, "defaultValue" | "onChange">): React.JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* A text input that reads a date typed in the page's language on Enter or
|
|
12
|
+
* blur. `end` makes it a range's end.
|
|
13
|
+
* @stable
|
|
14
|
+
*/
|
|
15
|
+
declare function DatePickerInput({ end, render, ...props }: Omit<PartProps<"input", DatePickerInputState>, "value" | "defaultValue" | "children" | "readOnly"> & DatePickerInputProps): React.JSX.Element | null;
|
|
16
|
+
/**
|
|
17
|
+
* Opens the calendar. Named "Choose date" and the date chosen; pass `aria-label` in another language.
|
|
18
|
+
* @stable
|
|
19
|
+
*/
|
|
20
|
+
declare function DatePickerTrigger({ children, ...props }: Omit<PartProps<"button", DatePickerTriggerState>, "value" | "defaultValue" | "onChange">): React.JSX.Element | null;
|
|
21
|
+
/**
|
|
22
|
+
* The popup. Without children it renders Previous, the heading, Next and a
|
|
23
|
+
* grid for each month; every Calendar part works inside it.
|
|
24
|
+
* @stable
|
|
25
|
+
*/
|
|
26
|
+
declare function DatePickerContent({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, finalFocus, keepMounted, container, render, children, ...props }: PartProps<"div", DatePickerContentState> & DatePickerContentProps): React.JSX.Element | null;
|
|
27
|
+
/**
|
|
28
|
+
* The format to type, like "MM/DD/YYYY". The inputs are described by it.
|
|
29
|
+
* @stable
|
|
30
|
+
*/
|
|
31
|
+
declare function DatePickerHint({ children, ...props }: PartProps<"span", DatePickerHintState>): React.JSX.Element | null;
|
|
32
|
+
/**
|
|
33
|
+
* Clears the value and focuses the input.
|
|
34
|
+
* @stable
|
|
35
|
+
*/
|
|
36
|
+
declare const DatePickerClear: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/date-picker").DatePickerPrimitive, "clear", "button">;
|
|
37
|
+
/**
|
|
38
|
+
* Selects the value it holds, like the last 7 days.
|
|
39
|
+
* @stable
|
|
40
|
+
*/
|
|
41
|
+
declare function DatePickerPreset({ value, ...props }: Omit<PartProps<"button", DatePickerPresetState>, "value" | "defaultValue" | "onChange"> & {
|
|
42
|
+
value: DatePickerValue;
|
|
43
|
+
}): React.JSX.Element | null;
|
|
44
|
+
export { CalendarDay, CalendarGrid, CalendarHeading, CalendarMonthSelect, CalendarNext, CalendarPrevious, CalendarWeekday, CalendarWeekdays, CalendarWeeks, CalendarYearSelect, } from "./calendar.js";
|
|
45
|
+
export { createDatePickerController } from "@ui-sdk/core/date-picker";
|
|
46
|
+
export type { CalendarDayState, CalendarGridCell, CalendarGridState, CalendarHeadingState, CalendarSelectOption, CalendarSelectState, CalendarStepState, CalendarWeekdayState, DateMatcher, DateMatchers, DatePickerApi, DatePickerChangeOptions, DatePickerClearState, DatePickerContentProps, DatePickerContentState, DatePickerController, DatePickerDismissReason, DatePickerHintState, DatePickerInputProps, DatePickerInputState, DatePickerMode, DatePickerMonthChangeReason, DatePickerOpenChangeReason, DatePickerOptions, DatePickerPresetProps, DatePickerPresetState, DatePickerPrimitive, DatePickerState, DatePickerTriggerState, DatePickerValue, DatePickerValueChangeReason, ISOMonth, } from "@ui-sdk/core/date-picker";
|
|
47
|
+
export { DatePicker, DatePickerClear, DatePickerContent, DatePickerHint, DatePickerInput, DatePickerPreset, DatePickerTrigger, };
|