@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
package/dist/toggle.js ADDED
@@ -0,0 +1,76 @@
1
+ "use client";
2
+ // src/toggle.tsx
3
+ import {
4
+ toggle,
5
+ toggleGroup
6
+ } from "@ui-sdk/core/toggle";
7
+ import * as React from "react";
8
+ import { useToolbarScope } from "./toolbar-context.js";
9
+ import {
10
+ createParts,
11
+ reading,
12
+ usePart,
13
+ usePrimitive
14
+ } from "./use-primitive.js";
15
+ import {
16
+ createToggleController,
17
+ createToggleGroupController
18
+ } from "@ui-sdk/core/toggle";
19
+ import { jsx } from "react/jsx-runtime";
20
+ var parts = createParts(toggle, { root: "button", icon: "span" });
21
+ var ToggleGroupContext = React.createContext(null);
22
+ function Toggle(props) {
23
+ const group = React.useContext(ToggleGroupContext);
24
+ const toolbar = useToolbarScope();
25
+ return /* @__PURE__ */ jsx(
26
+ parts.Root,
27
+ {
28
+ ...props,
29
+ group: group ? reading(group, () => group.api) : void 0,
30
+ toolbar
31
+ }
32
+ );
33
+ }
34
+ var ToggleIcon = parts.Icon;
35
+ function ToggleGroup({
36
+ value,
37
+ defaultValue,
38
+ onValueChange,
39
+ multiple,
40
+ deselectable,
41
+ disabled,
42
+ orientation,
43
+ loop,
44
+ controller,
45
+ debug,
46
+ ...props
47
+ }) {
48
+ const toolbar = useToolbarScope();
49
+ const group = usePrimitive(toggleGroup, {
50
+ value,
51
+ defaultValue,
52
+ onValueChange,
53
+ multiple,
54
+ deselectable,
55
+ disabled,
56
+ orientation,
57
+ loop,
58
+ controller,
59
+ debug,
60
+ toolbar
61
+ });
62
+ return /* @__PURE__ */ jsx(ToggleGroupContext, { value: group, children: usePart(
63
+ group,
64
+ "group",
65
+ {},
66
+ props,
67
+ "div"
68
+ ) });
69
+ }
70
+ export {
71
+ Toggle,
72
+ ToggleGroup,
73
+ ToggleIcon,
74
+ createToggleController,
75
+ createToggleGroupController
76
+ };
@@ -0,0 +1,35 @@
1
+ import { type Token, type TokenInputEditorProps, type TokenInputEditorState, type TokenInputOptions, type TokenInputTokenState } from "@ui-sdk/core/token-input";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ /**
5
+ * The props of `TokenInput`.
6
+ * @stable
7
+ */
8
+ type TokenInputProps = TokenInputOptions & {
9
+ children?: React.ReactNode;
10
+ /** Renders a token's content, usually a TokenInputToken. Without it, tokens show their label. */
11
+ renderToken?: (token: Token) => React.ReactNode;
12
+ };
13
+ /**
14
+ * A text field with atomic tokens. A TriggerMenu inside it suggests into it.
15
+ * @stable
16
+ */
17
+ declare function TokenInput({ children, renderToken, ...options }: TokenInputProps): React.JSX.Element;
18
+ /**
19
+ * The editable text. The core owns its content; style it, and show the placeholder with `data-empty`.
20
+ * @stable
21
+ */
22
+ declare function TokenInputEditor({ placeholder, render, ...props }: Omit<PartProps<"div", TokenInputEditorState>, "children"> & TokenInputEditorProps): React.JSX.Element | null;
23
+ /**
24
+ * A token's content, inside `renderToken`, with its state for styling.
25
+ * @stable
26
+ */
27
+ declare function TokenInputToken(props: PartProps<"span", TokenInputTokenState>): React.JSX.Element | null;
28
+ /**
29
+ * Removes its token when pressed. Hidden from assistive technology: the keyboard's way is Backspace.
30
+ * @stable
31
+ */
32
+ declare function TokenInputTokenRemove(props: PartProps<"span">): React.JSX.Element | null;
33
+ export { createTokenInputController, defaultCodec, fromText, toLabel, toText, } from "@ui-sdk/core/token-input";
34
+ export type { UndoStackOptions, TextEditorAdapter, TextRange, Token, TokenCodec, TokenDeletion, TokenInputApi, TokenInputChangeOptions, TokenInputController, TokenInputEditorProps, TokenInputEditorState, TokenInputOptions, TokenInputPrimitive, TokenInputTokenProps, TokenInputTokenState, TokenInputValue, TokenInputSubmitDetails, TokenInputValueChangeDetails, TokenInputValueChangeReason, TokenInsert, } from "@ui-sdk/core/token-input";
35
+ export { TokenInput, TokenInputEditor, type TokenInputProps, TokenInputToken, TokenInputTokenRemove, };
@@ -0,0 +1,100 @@
1
+ "use client";
2
+ // src/token-input.tsx
3
+ import {
4
+ tokenInput
5
+ } from "@ui-sdk/core/token-input";
6
+ import { renderStaticHtml, renderVersion } from "@ui-sdk/core/renderer";
7
+ import * as React from "react";
8
+ import { createPortal } from "react-dom";
9
+ import { EditorContext } from "./editor-context.js";
10
+ import { controlRender, useFieldControl } from "./field-context.js";
11
+ import {
12
+ HandleScope,
13
+ useHandle,
14
+ usePart,
15
+ usePrimitive
16
+ } from "./use-primitive.js";
17
+ import {
18
+ createTokenInputController,
19
+ defaultCodec,
20
+ fromText,
21
+ toLabel,
22
+ toText
23
+ } from "@ui-sdk/core/token-input";
24
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
25
+ var TokenContext = React.createContext(null);
26
+ function useTokenId(part) {
27
+ const id = React.useContext(TokenContext);
28
+ if (!id) {
29
+ throw new Error(`<${part}> must be used inside renderToken.`);
30
+ }
31
+ return id;
32
+ }
33
+ function TokenInput({ children, renderToken, ...options }) {
34
+ const field = useFieldControl();
35
+ const input = usePrimitive(tokenInput, {
36
+ ...options,
37
+ name: options.name ?? field?.name,
38
+ disabled: options.disabled || field?.disabled
39
+ });
40
+ const custom = !!renderToken;
41
+ React.useLayoutEffect(() => input.api.internal.setCustom(custom), [custom]);
42
+ return /* @__PURE__ */ jsx(HandleScope, { handle: input, children: /* @__PURE__ */ jsxs(EditorContext.Provider, { value: input.api.editor, children: [
43
+ children,
44
+ renderToken && /* @__PURE__ */ jsx(Tokens, { input, renderToken }),
45
+ /* @__PURE__ */ jsx(FormInput, {})
46
+ ] }) });
47
+ }
48
+ function Tokens({
49
+ input,
50
+ renderToken
51
+ }) {
52
+ const version = () => renderVersion(input.instance);
53
+ React.useSyncExternalStore(input.instance.subscribe, version, version);
54
+ return input.api.internal.hosts().map(
55
+ ({ id, token, host }) => createPortal(
56
+ /* @__PURE__ */ jsx(TokenContext.Provider, { value: id, children: renderToken(token) }),
57
+ host,
58
+ id
59
+ )
60
+ );
61
+ }
62
+ function FormInput() {
63
+ const render = ({ value, ...props }) => props.name ? /* @__PURE__ */ jsx("textarea", { ...props, defaultValue: value }) : /* @__PURE__ */ jsx(Fragment, {});
64
+ return usePart(tokenInput, "form-input", {}, { render }, "textarea");
65
+ }
66
+ function TokenInputEditor({
67
+ placeholder,
68
+ render,
69
+ ...props
70
+ }) {
71
+ const input = useHandle(tokenInput);
72
+ const [html] = React.useState(() => ({
73
+ __html: renderStaticHtml(input.state.value, input.api.internal.describe)
74
+ }));
75
+ const element = {
76
+ ...props,
77
+ dangerouslySetInnerHTML: html,
78
+ render: controlRender(useFieldControl(props), "div", render)
79
+ };
80
+ return usePart(input, "editor", { placeholder }, element);
81
+ }
82
+ function TokenInputToken(props) {
83
+ const id = useTokenId("TokenInputToken");
84
+ return usePart(tokenInput, "token", { id, token: id }, props, "span");
85
+ }
86
+ function TokenInputTokenRemove(props) {
87
+ const id = useTokenId("TokenInputTokenRemove");
88
+ return usePart(tokenInput, "token-remove", { id, token: id }, props, "span");
89
+ }
90
+ export {
91
+ TokenInput,
92
+ TokenInputEditor,
93
+ TokenInputToken,
94
+ TokenInputTokenRemove,
95
+ createTokenInputController,
96
+ defaultCodec,
97
+ fromText,
98
+ toLabel,
99
+ toText
100
+ };
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import { type PrimitiveHandle } from "./use-primitive.js";
3
+ declare const ToolbarContext: React.Context<PrimitiveHandle<import("@ui-sdk/core/toolbar").ToolbarPrimitive> | null>;
4
+ declare const ToolbarGroupContext: React.Context<boolean>;
5
+ declare function useToolbarScope(): (() => import("@ui-sdk/core/renderer").RovingScope) | undefined;
6
+ export { ToolbarContext, ToolbarGroupContext, useToolbarScope };
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ // src/toolbar-context.ts
3
+ import * as React from "react";
4
+ import { reading } from "./use-primitive.js";
5
+ var ToolbarContext = React.createContext(null);
6
+ var ToolbarGroupContext = React.createContext(false);
7
+ function useToolbarScope() {
8
+ const toolbar = React.useContext(ToolbarContext);
9
+ const groupDisabled = React.useContext(ToolbarGroupContext);
10
+ return toolbar ? reading(toolbar, () => toolbar.api.internal.scopeIn(groupDisabled)) : void 0;
11
+ }
12
+ export {
13
+ ToolbarContext,
14
+ ToolbarGroupContext,
15
+ useToolbarScope
16
+ };
@@ -0,0 +1,38 @@
1
+ import { type ToolbarGroupProps, type ToolbarGroupState, type ToolbarOptions, type ToolbarState } from "@ui-sdk/core/toolbar";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ /**
5
+ * A row of controls with one tab stop and arrow keys between them. Toggles and
6
+ * toggle groups inside join it. Render menu and select triggers through
7
+ * `ToolbarButton`, and fields through `ToolbarInput`.
8
+ * @stable
9
+ */
10
+ declare function Toolbar({ orientation, loop, disabled, controller, debug, ...props }: ToolbarOptions & PartProps<"div", ToolbarState>): React.JSX.Element;
11
+ /**
12
+ * A button in the toolbar. Arrow keys move between it and the toolbar's other items.
13
+ * @stable
14
+ */
15
+ declare const ToolbarButton: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/toolbar").ToolbarPrimitive, "button", "button">;
16
+ /**
17
+ * A link in the toolbar. Arrow keys move between it and the toolbar's other items.
18
+ * @stable
19
+ */
20
+ declare const ToolbarLink: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/toolbar").ToolbarPrimitive, "link", "a">;
21
+ /**
22
+ * A text field. Arrows move its caret, and leave it only from the end they point at.
23
+ * @stable
24
+ */
25
+ declare const ToolbarInput: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/toolbar").ToolbarPrimitive, "input", "input">;
26
+ /**
27
+ * A group of related items in the toolbar. `disabled` disables every item in it.
28
+ * @stable
29
+ */
30
+ declare function ToolbarGroup({ disabled, children, ...props }: ToolbarGroupProps & Omit<PartProps<"div", ToolbarGroupState>, "disabled">): React.JSX.Element | null;
31
+ /**
32
+ * A line between groups of items.
33
+ * @stable
34
+ */
35
+ declare const ToolbarSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/toolbar").ToolbarPrimitive, "separator", "div">;
36
+ export { createToolbarController } from "@ui-sdk/core/toolbar";
37
+ export type { ToolbarApi, ToolbarButtonProps, ToolbarButtonState, ToolbarController, ToolbarGroupProps, ToolbarGroupState, ToolbarInputProps, ToolbarInputState, ToolbarLinkState, ToolbarOptions, ToolbarOrientation, ToolbarPrimitive, ToolbarState, ToolbarSeparatorState, } from "@ui-sdk/core/toolbar";
38
+ export { Toolbar, ToolbarButton, ToolbarGroup, ToolbarInput, ToolbarLink, ToolbarSeparator, };
@@ -0,0 +1,63 @@
1
+ "use client";
2
+ // src/toolbar.tsx
3
+ import {
4
+ toolbar
5
+ } from "@ui-sdk/core/toolbar";
6
+ import * as React from "react";
7
+ import { ToolbarContext, ToolbarGroupContext } from "./toolbar-context.js";
8
+ import {
9
+ createParts,
10
+ usePart,
11
+ usePrimitive
12
+ } from "./use-primitive.js";
13
+ import { createToolbarController } from "@ui-sdk/core/toolbar";
14
+ import { jsx } from "react/jsx-runtime";
15
+ var parts = createParts(toolbar, {
16
+ button: "button",
17
+ link: "a",
18
+ input: "input",
19
+ separator: "div"
20
+ });
21
+ function Toolbar({
22
+ orientation,
23
+ loop,
24
+ disabled,
25
+ controller,
26
+ debug,
27
+ ...props
28
+ }) {
29
+ const handle = usePrimitive(toolbar, {
30
+ orientation,
31
+ loop,
32
+ disabled,
33
+ controller,
34
+ debug
35
+ });
36
+ return /* @__PURE__ */ jsx(ToolbarContext.Provider, { value: handle, children: usePart(handle, "root", {}, props) });
37
+ }
38
+ var ToolbarButton = parts.Button;
39
+ var ToolbarLink = parts.Link;
40
+ var ToolbarInput = parts.Input;
41
+ function ToolbarGroup({
42
+ disabled,
43
+ children,
44
+ ...props
45
+ }) {
46
+ const content = (state) => /* @__PURE__ */ jsx(ToolbarGroupContext.Provider, { value: state.disabled, children: typeof children === "function" ? children(state) : children });
47
+ return usePart(
48
+ toolbar,
49
+ "group",
50
+ { id: React.useId(), disabled },
51
+ { ...props, children: content }
52
+ );
53
+ }
54
+ var ToolbarSeparator = parts.Separator;
55
+ export {
56
+ Toolbar,
57
+ ToolbarButton,
58
+ ToolbarGroup,
59
+ ToolbarInput,
60
+ ToolbarLink,
61
+ ToolbarSeparator,
62
+ createToolbarController
63
+ };
@@ -0,0 +1,39 @@
1
+ import { type TooltipContentProps, type TooltipContentState, type TooltipOptions, type TooltipShortcutProps, type TooltipShortcutState, type TooltipTriggerProps, type TooltipTriggerState } from "@ui-sdk/core/tooltip";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ /**
5
+ * The props of `Tooltip`.
6
+ * @stable
7
+ */
8
+ type TooltipProps = TooltipOptions & {
9
+ children?: React.ReactNode;
10
+ };
11
+ /**
12
+ * A short label or hint that appears when the pointer rests on its trigger or keyboard focus reaches it.
13
+ * @stable
14
+ */
15
+ declare function Tooltip({ children, container, ...options }: TooltipProps): React.JSX.Element;
16
+ type TriggerPartProps = Omit<PartProps<"button", TooltipTriggerState>, "value" | "defaultValue" | "onChange"> & TooltipTriggerProps;
17
+ /**
18
+ * The element the tooltip names or describes, usually a button.
19
+ * @stable
20
+ */
21
+ declare function TooltipTrigger({ controller, ...props }: TriggerPartProps): React.JSX.Element;
22
+ /**
23
+ * The tooltip itself, positioned against its trigger.
24
+ * @stable
25
+ */
26
+ declare function TooltipContent<Payload = unknown>({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, container, ...props }: PartProps<"div", TooltipContentState<Payload>> & TooltipContentProps): React.JSX.Element | null;
27
+ /**
28
+ * An arrow on the tooltip's edge that points at its trigger.
29
+ * @stable
30
+ */
31
+ declare const TooltipArrow: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/tooltip").TooltipPrimitive, "arrow", "div">;
32
+ /**
33
+ * Shows the tooltip's shortcut, like `⌘S`, formatted for the platform.
34
+ * @stable
35
+ */
36
+ declare function TooltipShortcut(props: PartProps<"span", TooltipShortcutState> & TooltipShortcutProps): React.JSX.Element | null;
37
+ export { createTooltipController } from "@ui-sdk/core/tooltip";
38
+ export type { TooltipApi, TooltipArrowState, TooltipContentProps, TooltipContentState, TooltipController, TooltipOpenChangeReason, TooltipOptions, TooltipPayloadChangeReason, TooltipPrimitive, TooltipShortcutProps, TooltipShortcutState, TooltipTriggerProps, TooltipTriggerState, } from "@ui-sdk/core/tooltip";
39
+ export { Tooltip, TooltipArrow, TooltipContent, type TooltipProps, TooltipShortcut, TooltipTrigger, };
@@ -0,0 +1,108 @@
1
+ "use client";
2
+ // src/tooltip.tsx
3
+ import {
4
+ tooltip
5
+ } from "@ui-sdk/core/tooltip";
6
+ import * as React from "react";
7
+ import {
8
+ Connected,
9
+ renderPopup,
10
+ useControllerEntry,
11
+ useOwnContainer,
12
+ usePopupContainer
13
+ } from "./popup.js";
14
+ import {
15
+ createParts,
16
+ HandleScope,
17
+ renderElement,
18
+ useNearest,
19
+ usePart,
20
+ usePrimitive
21
+ } from "./use-primitive.js";
22
+ import { createTooltipController } from "@ui-sdk/core/tooltip";
23
+ import { jsx } from "react/jsx-runtime";
24
+ var parts = createParts(tooltip, { trigger: "button", arrow: "div" });
25
+ var ContainerContext = React.createContext(void 0);
26
+ var InTriggerContext = React.createContext(false);
27
+ function Tooltip({ children, container, ...options }) {
28
+ const handle = usePrimitive(tooltip, options);
29
+ useControllerEntry(options.controller, handle);
30
+ return /* @__PURE__ */ jsx(HandleScope, { handle, children: /* @__PURE__ */ jsx(ContainerContext.Provider, { value: container, children }) });
31
+ }
32
+ function TooltipTrigger({ controller, ...props }) {
33
+ const { payload: _, render, ...rest } = props;
34
+ const unconnected = () => renderElement("button", { type: "button", ...rest }, render, {
35
+ open: false
36
+ });
37
+ return /* @__PURE__ */ jsx(InTriggerContext.Provider, { value: true, children: /* @__PURE__ */ jsx(
38
+ Connected,
39
+ {
40
+ primitive: tooltip,
41
+ controller,
42
+ fallback: unconnected,
43
+ children: /* @__PURE__ */ jsx(parts.Trigger, { ...props })
44
+ }
45
+ ) });
46
+ }
47
+ function TooltipContent({
48
+ side,
49
+ align,
50
+ sideOffset,
51
+ alignOffset,
52
+ collisionPadding,
53
+ arrowPadding,
54
+ anchor,
55
+ container,
56
+ ...props
57
+ }) {
58
+ const target = usePopupContainer(useOwnContainer(container, ContainerContext));
59
+ const content = {
60
+ side,
61
+ align,
62
+ sideOffset,
63
+ alignOffset,
64
+ collisionPadding,
65
+ arrowPadding,
66
+ anchor
67
+ };
68
+ const element = usePart(
69
+ tooltip,
70
+ "content",
71
+ content,
72
+ props
73
+ );
74
+ return element && renderPopup(element, target);
75
+ }
76
+ var TooltipArrow = parts.Arrow;
77
+ var text = (state) => state.text;
78
+ function TooltipShortcut(props) {
79
+ const inTrigger = React.useContext(InTriggerContext);
80
+ if (useNearest(tooltip)) {
81
+ return /* @__PURE__ */ jsx(ShortcutPart, { ...props });
82
+ }
83
+ if (inTrigger) {
84
+ return null;
85
+ }
86
+ throw new Error("Tooltip parts must be used inside <Tooltip>.");
87
+ }
88
+ function ShortcutPart({
89
+ shortcut,
90
+ children = text,
91
+ ...props
92
+ }) {
93
+ return usePart(
94
+ tooltip,
95
+ "shortcut",
96
+ { shortcut },
97
+ { ...props, children },
98
+ "span"
99
+ );
100
+ }
101
+ export {
102
+ Tooltip,
103
+ TooltipArrow,
104
+ TooltipContent,
105
+ TooltipShortcut,
106
+ TooltipTrigger,
107
+ createTooltipController
108
+ };
package/dist/tree.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ import { type TreeItemData, type TreeItemProps, type TreeItemState, type TreeOptions, type TreeState, type TreeMode } from "@ui-sdk/core/tree";
2
+ import * as React from "react";
3
+ import { type PartProps } from "./use-primitive.js";
4
+ type Clashing = "value" | "defaultValue" | "defaultChecked" | "onChange" | "onSelect";
5
+ /**
6
+ * The props of `Tree`.
7
+ * @stable
8
+ */
9
+ type TreeProps<Mode extends TreeMode = "single"> = Omit<PartProps<"div", TreeState>, Clashing | keyof TreeOptions> & TreeOptions<Mode> & {};
10
+ /**
11
+ * A tree of items that expand and collapse, with one tab stop and arrow keys between its items.
12
+ * @stable
13
+ */
14
+ declare function Tree<Mode extends TreeMode = "single">({ items, paths, mode, value, defaultValue, onValueChange, activation, expanded, defaultExpanded, onExpandedChange, expandOnPress, checkable, checked, defaultChecked, onCheckedChange, checkStrategy, onAction, pendingAnnouncement, loadChildren, current, onHighlight, disabled, focusableWhenDisabled, keepMounted, hiddenUntilFound, announcement, controller, debug, children, ...props }: TreeProps<Mode>): React.JSX.Element;
15
+ /**
16
+ * An item. Put its text in a `TreeItemLabel` and its children in a
17
+ * `TreeGroup`, which makes it a branch. Set `branch` for one whose children
18
+ * load later, or whose group is inside a component of your own.
19
+ * @stable
20
+ */
21
+ declare function TreeItem({ value, branch, disabled, label, children, ...props }: Omit<PartProps<"div", TreeItemState>, Clashing> & Omit<TreeItemProps, "parent">): React.JSX.Element;
22
+ /**
23
+ * The item's text, which names it. Render it as a link to make the item one.
24
+ * @stable
25
+ */
26
+ declare const TreeItemLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/tree").TreePrimitive, "label", "span">;
27
+ /**
28
+ * The arrow that expands and collapses a branch. Alt or Option expands everything in it.
29
+ * @stable
30
+ */
31
+ declare const TreeItemIndicator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/tree").TreePrimitive, "indicator", "span">;
32
+ /**
33
+ * The item's checkbox, with `checkable`. Screen readers hear the item's checked state instead.
34
+ * @stable
35
+ */
36
+ declare const TreeItemCheckbox: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/tree").TreePrimitive, "checkbox", "span">;
37
+ /**
38
+ * A branch's children. Rendered while the branch is expanded or animating closed.
39
+ * @stable
40
+ */
41
+ declare const TreeGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/tree").TreePrimitive, "group", "div">;
42
+ /**
43
+ * Renders data items. Used by data trees, and available for custom layouts.
44
+ * @stable
45
+ */
46
+ declare function TreeItems({ items }: {
47
+ items: TreeItemData[];
48
+ }): React.JSX.Element[];
49
+ export { createTreeController, toggleTreeChecked, treeCheckedStates, treeFromPaths, visibleTreeRows, } from "@ui-sdk/core/tree";
50
+ export type { ListHighlightDetails, TreeActionDetails, TreeAnnouncement, TreeApi, TreeChangeOptions, TreeCheckStrategy, TreeCheckedChangeReason, TreeCheckedState, TreeCollection, TreeCollectionNode, TreeController, TreeExpandedChangeReason, TreeGroupProps, TreeGroupState, TreeItemData, TreeItemPartProps, TreeItemProps, TreeItemState, TreeOptions, TreePrimitive, TreeState, TreeRow, TreeMode, TreeValue, TreeValueChangeReason, } from "@ui-sdk/core/tree";
51
+ export { Tree, TreeGroup, TreeItem, TreeItemCheckbox, TreeItemIndicator, TreeItemLabel, TreeItems, type TreeProps, };
package/dist/tree.js ADDED
@@ -0,0 +1,150 @@
1
+ "use client";
2
+ // src/tree.tsx
3
+ import {
4
+ tree as treePrimitive
5
+ } from "@ui-sdk/core/tree";
6
+ import * as React from "react";
7
+ import { hasChild } from "./children.js";
8
+ import {
9
+ createParts,
10
+ readIn,
11
+ useHandle,
12
+ usePart,
13
+ usePrimitive
14
+ } from "./use-primitive.js";
15
+ import {
16
+ createTreeController,
17
+ toggleTreeChecked,
18
+ treeCheckedStates,
19
+ treeFromPaths,
20
+ visibleTreeRows
21
+ } from "@ui-sdk/core/tree";
22
+ import { jsx, jsxs } from "react/jsx-runtime";
23
+ var parts = createParts(treePrimitive, {
24
+ label: "span",
25
+ indicator: "span",
26
+ checkbox: "span",
27
+ group: "div"
28
+ });
29
+ var ItemContext = React.createContext(null);
30
+ function Tree({
31
+ items,
32
+ paths,
33
+ mode,
34
+ value,
35
+ defaultValue,
36
+ onValueChange,
37
+ activation,
38
+ expanded,
39
+ defaultExpanded,
40
+ onExpandedChange,
41
+ expandOnPress,
42
+ checkable,
43
+ checked,
44
+ defaultChecked,
45
+ onCheckedChange,
46
+ checkStrategy,
47
+ onAction,
48
+ pendingAnnouncement,
49
+ loadChildren,
50
+ current,
51
+ onHighlight,
52
+ disabled,
53
+ focusableWhenDisabled,
54
+ keepMounted,
55
+ hiddenUntilFound,
56
+ announcement,
57
+ controller,
58
+ debug,
59
+ children,
60
+ ...props
61
+ }) {
62
+ const tree = usePrimitive(treePrimitive, {
63
+ items,
64
+ paths,
65
+ mode,
66
+ value,
67
+ defaultValue,
68
+ onValueChange,
69
+ activation,
70
+ expanded,
71
+ defaultExpanded,
72
+ onExpandedChange,
73
+ expandOnPress,
74
+ checkable,
75
+ checked,
76
+ defaultChecked,
77
+ onCheckedChange,
78
+ checkStrategy,
79
+ onAction,
80
+ pendingAnnouncement,
81
+ loadChildren,
82
+ current,
83
+ onHighlight,
84
+ disabled,
85
+ focusableWhenDisabled,
86
+ keepMounted,
87
+ hiddenUntilFound,
88
+ announcement,
89
+ controller,
90
+ debug
91
+ });
92
+ const data = readIn(tree, () => tree.api.internal.items());
93
+ const content = children ?? (data && /* @__PURE__ */ jsx(TreeItems, { items: data }));
94
+ return /* @__PURE__ */ jsx(ItemContext.Provider, { value: null, children: usePart(tree, "root", {}, { ...props, children: content }) });
95
+ }
96
+ function TreeItem({
97
+ value,
98
+ branch,
99
+ disabled,
100
+ label,
101
+ children,
102
+ ...props
103
+ }) {
104
+ const parent = React.useContext(ItemContext);
105
+ const item = {
106
+ value,
107
+ parent,
108
+ // A branch is one with a group among its children.
109
+ branch: branch ?? (typeof children === "function" ? void 0 : hasChild(children, TreeGroup) || void 0),
110
+ disabled,
111
+ label
112
+ };
113
+ return /* @__PURE__ */ jsx(ItemContext.Provider, { value, children: usePart(treePrimitive, "item", item, { ...props, children }) });
114
+ }
115
+ var TreeItemLabel = parts.Label;
116
+ var TreeItemIndicator = parts.Indicator;
117
+ var TreeItemCheckbox = parts.Checkbox;
118
+ var TreeGroup = parts.Group;
119
+ function TreeItems({ items }) {
120
+ const tree = useHandle(treePrimitive);
121
+ const checkable = tree.state.checkable;
122
+ return items.map((item) => /* @__PURE__ */ jsxs(
123
+ TreeItem,
124
+ {
125
+ value: item.value,
126
+ branch: item.children !== void 0,
127
+ disabled: item.disabled,
128
+ children: [
129
+ checkable && /* @__PURE__ */ jsx(TreeItemCheckbox, {}),
130
+ /* @__PURE__ */ jsx(TreeItemLabel, { render: item.href ? /* @__PURE__ */ jsx("a", { href: item.href }) : void 0, children: item.label }),
131
+ item.children && /* @__PURE__ */ jsx(TreeGroup, { children: /* @__PURE__ */ jsx(TreeItems, { items: item.children }) })
132
+ ]
133
+ },
134
+ item.value
135
+ ));
136
+ }
137
+ export {
138
+ Tree,
139
+ TreeGroup,
140
+ TreeItem,
141
+ TreeItemCheckbox,
142
+ TreeItemIndicator,
143
+ TreeItemLabel,
144
+ TreeItems,
145
+ createTreeController,
146
+ toggleTreeChecked,
147
+ treeCheckedStates,
148
+ treeFromPaths,
149
+ visibleTreeRows
150
+ };