@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,83 @@
|
|
|
1
|
+
import { type TriggerMenuContentProps, type TriggerMenuContentState, type TriggerMenuData, type TriggerMenuEmptyState, type TriggerMenuHintState, type TriggerMenuItemProps, type TriggerMenuItemState, type TriggerMenuOptions, type TriggerMenuStatusState } from "@ui-sdk/core/trigger-menu";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type PartProps } from "./use-primitive.js";
|
|
4
|
+
type Clashing = "value" | "defaultValue" | "onChange" | "onSelect";
|
|
5
|
+
/**
|
|
6
|
+
* The props of `TriggerMenu`.
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
type TriggerMenuProps<T = string> = TriggerMenuOptions<T> & {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Suggestions opened by a trigger like `@` or `/` in text. Inside a TokenInput
|
|
14
|
+
* it uses that editor; otherwise render a TriggerMenuInput, or pass `editor`.
|
|
15
|
+
* @stable
|
|
16
|
+
*/
|
|
17
|
+
declare function TriggerMenu<T = string>({ children, container, editor, ...options }: TriggerMenuProps<T>): React.JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* The text field the menu suggests into: a `<textarea>`, or an `<input>` through `render`.
|
|
20
|
+
* @stable
|
|
21
|
+
*/
|
|
22
|
+
declare const TriggerMenuInput: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/trigger-menu").TriggerMenuPrimitive, "input", "textarea">;
|
|
23
|
+
/**
|
|
24
|
+
* The popup that holds the suggestions, anchored at the caret.
|
|
25
|
+
* @stable
|
|
26
|
+
*/
|
|
27
|
+
declare function TriggerMenuContent({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, keepMounted, container, children, ...props }: PartProps<"div", TriggerMenuContentState> & TriggerMenuContentProps): React.JSX.Element | null;
|
|
28
|
+
/**
|
|
29
|
+
* The listbox. Without children, it renders the current trigger's items, filtered.
|
|
30
|
+
* @stable
|
|
31
|
+
*/
|
|
32
|
+
declare function TriggerMenuList({ children, ...props }: PartProps<"div", TriggerMenuContentState>): React.JSX.Element | null;
|
|
33
|
+
/**
|
|
34
|
+
* A suggestion. Choosing it inserts it into the text.
|
|
35
|
+
* @stable
|
|
36
|
+
*/
|
|
37
|
+
declare const TriggerMenuItem: <T = string>(props: Omit<PartProps<"div", TriggerMenuItemState>, Clashing> & TriggerMenuItemProps<T>) => React.ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* An icon inside a suggestion. Screen readers, typeahead and filtering skip it, and `mirror` flips
|
|
40
|
+
* it in right-to-left text.
|
|
41
|
+
* @stable
|
|
42
|
+
*/
|
|
43
|
+
declare const TriggerMenuItemIcon: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/trigger-menu").TriggerMenuPrimitive, "item-icon", "span">;
|
|
44
|
+
/**
|
|
45
|
+
* A group of items, named by its `TriggerMenuGroupLabel`.
|
|
46
|
+
* @stable
|
|
47
|
+
*/
|
|
48
|
+
declare const TriggerMenuGroup: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/trigger-menu").TriggerMenuPrimitive, "group", "div">;
|
|
49
|
+
/**
|
|
50
|
+
* The group's heading, which names the group.
|
|
51
|
+
* @stable
|
|
52
|
+
*/
|
|
53
|
+
declare const TriggerMenuGroupLabel: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/trigger-menu").TriggerMenuPrimitive, "group-label", "div">;
|
|
54
|
+
/**
|
|
55
|
+
* A line between items or groups, hidden from screen readers.
|
|
56
|
+
* @stable
|
|
57
|
+
*/
|
|
58
|
+
declare const TriggerMenuSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/trigger-menu").TriggerMenuPrimitive, "separator", "div">;
|
|
59
|
+
/**
|
|
60
|
+
* Shown while no item matches. Rendering it keeps the menu open with no matches; without it, the menu closes until something matches.
|
|
61
|
+
* @stable
|
|
62
|
+
*/
|
|
63
|
+
declare function TriggerMenuEmpty({ children, ...props }: PartProps<"div", TriggerMenuEmptyState>): React.JSX.Element | null;
|
|
64
|
+
/**
|
|
65
|
+
* A polite status, outside the popup. Without children, it says the count and the keys once typing pauses.
|
|
66
|
+
* @stable
|
|
67
|
+
*/
|
|
68
|
+
declare function TriggerMenuStatus(props: PartProps<"div", TriggerMenuStatusState>): React.JSX.Element | null;
|
|
69
|
+
/**
|
|
70
|
+
* Ghost text at the caret for the arguments still to type, like `<name>`. Without children, the hints.
|
|
71
|
+
* @stable
|
|
72
|
+
*/
|
|
73
|
+
declare function TriggerMenuHint(props: PartProps<"span", TriggerMenuHintState>): React.JSX.Element | null;
|
|
74
|
+
/**
|
|
75
|
+
* Renders data items. Used by data menus, and available for custom layouts.
|
|
76
|
+
* @stable
|
|
77
|
+
*/
|
|
78
|
+
declare function TriggerMenuItems({ items }: {
|
|
79
|
+
items: TriggerMenuData<any>;
|
|
80
|
+
}): React.JSX.Element;
|
|
81
|
+
export { createTriggerMenuController, textFieldAdapter, } from "@ui-sdk/core/trigger-menu";
|
|
82
|
+
export type { EditorChange, EditorReplaceOptions, ListFilter, ListItem, ListSeparator, TextEditorAdapter, TextRange, TextRect, Token, TokenInsert, TriggerAfter, TriggerArgument, TriggerBoundary, TriggerDefinition, TriggerItemsLoader, TriggerMatch, TriggerMenuApi, TriggerMenuChangeOptions, TriggerMenuContentProps, TriggerMenuContentState, TriggerMenuController, TriggerMenuData, TriggerMenuDataGroup, TriggerMenuDataItem, TriggerMenuDismissReason, TriggerMenuEmptyState, TriggerMenuHintState, TriggerMenuInputState, TriggerMenuItemIconProps, TriggerMenuItemIconState, TriggerMenuItemProps, TriggerMenuItemState, TriggerMenuOpenChangeReason, TriggerMenuOptions, TriggerMenuPrimitive, TriggerMenuQueryChangeReason, TriggerMenuSelectDetails, TriggerMenuStatusState, TriggerRule, } from "@ui-sdk/core/trigger-menu";
|
|
83
|
+
export { TriggerMenu, TriggerMenuContent, TriggerMenuEmpty, TriggerMenuGroup, TriggerMenuGroupLabel, TriggerMenuHint, TriggerMenuInput, TriggerMenuItem, TriggerMenuItemIcon, TriggerMenuItems, TriggerMenuList, type TriggerMenuProps, TriggerMenuSeparator, TriggerMenuStatus, };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/trigger-menu.tsx
|
|
3
|
+
import {
|
|
4
|
+
triggerMenu as triggerMenuPrimitive
|
|
5
|
+
} from "@ui-sdk/core/trigger-menu";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { hasChild, Placed, usePlaceContent, usePlacedContent } from "./children.js";
|
|
8
|
+
import { EditorContext } from "./editor-context.js";
|
|
9
|
+
import {
|
|
10
|
+
renderPopup,
|
|
11
|
+
useControllerEntry,
|
|
12
|
+
useOwnContainer,
|
|
13
|
+
usePopupContainer
|
|
14
|
+
} from "./popup.js";
|
|
15
|
+
import { ListItems } from "./list-items.js";
|
|
16
|
+
import {
|
|
17
|
+
createParts,
|
|
18
|
+
HandleScope,
|
|
19
|
+
useHandle,
|
|
20
|
+
usePart,
|
|
21
|
+
usePrimitive
|
|
22
|
+
} from "./use-primitive.js";
|
|
23
|
+
import {
|
|
24
|
+
createTriggerMenuController,
|
|
25
|
+
textFieldAdapter
|
|
26
|
+
} from "@ui-sdk/core/trigger-menu";
|
|
27
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
28
|
+
var parts = createParts(triggerMenuPrimitive, {
|
|
29
|
+
input: "textarea",
|
|
30
|
+
item: "div",
|
|
31
|
+
"item-icon": "span",
|
|
32
|
+
group: "div",
|
|
33
|
+
"group-label": "div",
|
|
34
|
+
separator: "div"
|
|
35
|
+
});
|
|
36
|
+
var ContainerContext = React.createContext(void 0);
|
|
37
|
+
function useTriggerMenu() {
|
|
38
|
+
return useHandle(triggerMenuPrimitive);
|
|
39
|
+
}
|
|
40
|
+
function TriggerMenu({
|
|
41
|
+
children,
|
|
42
|
+
container,
|
|
43
|
+
editor,
|
|
44
|
+
...options
|
|
45
|
+
}) {
|
|
46
|
+
const inherited = React.useContext(EditorContext);
|
|
47
|
+
const menu = usePrimitive(triggerMenuPrimitive, {
|
|
48
|
+
...options,
|
|
49
|
+
editor: editor ?? inherited
|
|
50
|
+
});
|
|
51
|
+
useControllerEntry(options.controller, menu);
|
|
52
|
+
const found = hasChild(children, TriggerMenuContent);
|
|
53
|
+
const [placed, place] = usePlacedContent(!found);
|
|
54
|
+
const own = placed || found;
|
|
55
|
+
return /* @__PURE__ */ jsx(HandleScope, { handle: menu, children: /* @__PURE__ */ jsxs(ContainerContext.Provider, { value: container, children: [
|
|
56
|
+
/* @__PURE__ */ jsx(Placed, { value: place, children }),
|
|
57
|
+
/* @__PURE__ */ jsx(Placed, { value: null, children: !own && /* @__PURE__ */ jsx(TriggerMenuContent, {}) })
|
|
58
|
+
] }) });
|
|
59
|
+
}
|
|
60
|
+
var TriggerMenuInput = parts.Input;
|
|
61
|
+
function TriggerMenuContent({
|
|
62
|
+
side,
|
|
63
|
+
align,
|
|
64
|
+
sideOffset,
|
|
65
|
+
alignOffset,
|
|
66
|
+
collisionPadding,
|
|
67
|
+
arrowPadding,
|
|
68
|
+
anchor,
|
|
69
|
+
keepMounted,
|
|
70
|
+
container,
|
|
71
|
+
children,
|
|
72
|
+
...props
|
|
73
|
+
}) {
|
|
74
|
+
usePlaceContent();
|
|
75
|
+
const target = usePopupContainer(useOwnContainer(container, ContainerContext));
|
|
76
|
+
const content = {
|
|
77
|
+
side,
|
|
78
|
+
align,
|
|
79
|
+
sideOffset,
|
|
80
|
+
alignOffset,
|
|
81
|
+
collisionPadding,
|
|
82
|
+
arrowPadding,
|
|
83
|
+
anchor,
|
|
84
|
+
keepMounted
|
|
85
|
+
};
|
|
86
|
+
const body = children ?? /* @__PURE__ */ jsx(TriggerMenuList, {});
|
|
87
|
+
const element = usePart(triggerMenuPrimitive, "content", content, {
|
|
88
|
+
...props,
|
|
89
|
+
children: body
|
|
90
|
+
});
|
|
91
|
+
return element && renderPopup(element, target);
|
|
92
|
+
}
|
|
93
|
+
function TriggerMenuList({
|
|
94
|
+
children = listItems,
|
|
95
|
+
...props
|
|
96
|
+
}) {
|
|
97
|
+
return usePart(triggerMenuPrimitive, "list", {}, { ...props, children });
|
|
98
|
+
}
|
|
99
|
+
var listItems = (state) => /* @__PURE__ */ jsx(TriggerMenuItems, { items: state.items });
|
|
100
|
+
var TriggerMenuItem = parts.Item;
|
|
101
|
+
var TriggerMenuItemIcon = parts.ItemIcon;
|
|
102
|
+
var TriggerMenuGroup = parts.Group;
|
|
103
|
+
var TriggerMenuGroupLabel = parts.GroupLabel;
|
|
104
|
+
var TriggerMenuSeparator = parts.Separator;
|
|
105
|
+
function TriggerMenuEmpty({
|
|
106
|
+
children,
|
|
107
|
+
...props
|
|
108
|
+
}) {
|
|
109
|
+
const content = (state) => typeof children === "function" ? children(state) : state.empty ? children : null;
|
|
110
|
+
return usePart(
|
|
111
|
+
triggerMenuPrimitive,
|
|
112
|
+
"empty",
|
|
113
|
+
{},
|
|
114
|
+
{ ...props, children: content }
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function TriggerMenuStatus(props) {
|
|
118
|
+
return usePart(
|
|
119
|
+
triggerMenuPrimitive,
|
|
120
|
+
"status",
|
|
121
|
+
{ text: props.children === void 0 },
|
|
122
|
+
props
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
function TriggerMenuHint(props) {
|
|
126
|
+
return usePart(
|
|
127
|
+
triggerMenuPrimitive,
|
|
128
|
+
"hint",
|
|
129
|
+
{ text: props.children === void 0 },
|
|
130
|
+
props,
|
|
131
|
+
"span"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
function TriggerMenuItems({ items }) {
|
|
135
|
+
const menu = useTriggerMenu();
|
|
136
|
+
return /* @__PURE__ */ jsx(
|
|
137
|
+
ListItems,
|
|
138
|
+
{
|
|
139
|
+
items,
|
|
140
|
+
parts: listParts,
|
|
141
|
+
keyOf: menu.api.internal.keyOf
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
var listParts = {
|
|
146
|
+
Item: TriggerMenuItem,
|
|
147
|
+
Group: TriggerMenuGroup,
|
|
148
|
+
GroupLabel: TriggerMenuGroupLabel,
|
|
149
|
+
Separator: TriggerMenuSeparator
|
|
150
|
+
};
|
|
151
|
+
export {
|
|
152
|
+
TriggerMenu,
|
|
153
|
+
TriggerMenuContent,
|
|
154
|
+
TriggerMenuEmpty,
|
|
155
|
+
TriggerMenuGroup,
|
|
156
|
+
TriggerMenuGroupLabel,
|
|
157
|
+
TriggerMenuHint,
|
|
158
|
+
TriggerMenuInput,
|
|
159
|
+
TriggerMenuItem,
|
|
160
|
+
TriggerMenuItemIcon,
|
|
161
|
+
TriggerMenuItems,
|
|
162
|
+
TriggerMenuList,
|
|
163
|
+
TriggerMenuSeparator,
|
|
164
|
+
TriggerMenuStatus,
|
|
165
|
+
createTriggerMenuController,
|
|
166
|
+
textFieldAdapter
|
|
167
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { OptionsOf, Primitive, PrimitiveInstance, PropsOf, SlotName, StateOf, TypesOf } from "@ui-sdk/core";
|
|
2
|
+
import { type PrimitiveGeneric } from "@ui-sdk/core/renderer";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { mergeProps, mergeRefs, renderElement, type RenderProp } from "./render-element.js";
|
|
5
|
+
/**
|
|
6
|
+
* What `usePrimitive` returns, and what a component's context holds: one object for the instance's life.
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
type PrimitiveHandle<P extends Primitive> = {
|
|
10
|
+
/** The primitive it's an instance of. */
|
|
11
|
+
primitive: P;
|
|
12
|
+
/** The core instance `usePrimitive` made, with its `get()`, `part()` and `api`. In render, read `state` instead of its `get()`, which shows only what React has committed. */
|
|
13
|
+
instance: ReturnType<P>;
|
|
14
|
+
/** The state this render shows. Reading it doesn't subscribe; a part's `render` and class name functions get the state they render. */
|
|
15
|
+
readonly state: TypesOf<P>["state"];
|
|
16
|
+
/** The methods its definition declares, like Tabs' `setValue`. */
|
|
17
|
+
api: TypesOf<P>["api"];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of a primitive for this component, keeps its options
|
|
21
|
+
* current on every render, and destroys it when the component leaves. Render
|
|
22
|
+
* its root with `usePart`, which shares the instance with the parts inside.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* function ConfirmButton({ onConfirm, ...props }: PartProps<"button", ConfirmButtonState> & { onConfirm?: () => void }) {
|
|
26
|
+
* const button = usePrimitive(confirmButton, { onConfirm })
|
|
27
|
+
* return usePart(button, "root", {}, props, "button")
|
|
28
|
+
* }
|
|
29
|
+
* @stable
|
|
30
|
+
*/
|
|
31
|
+
declare function usePrimitive<P extends Primitive>(primitive: P, options: OptionsOf<P>): PrimitiveHandle<P>;
|
|
32
|
+
type Outer = {
|
|
33
|
+
instance: PrimitiveInstance;
|
|
34
|
+
};
|
|
35
|
+
declare function reading<F extends (...args: never[]) => unknown>(handle: Outer, read: F): F;
|
|
36
|
+
declare function extendHandle<H extends {
|
|
37
|
+
instance: PrimitiveInstance;
|
|
38
|
+
}, E extends object>(handle: H, extra: E): H & E;
|
|
39
|
+
declare function presentIn<P extends Primitive, S extends SlotName<P>>(handle: PrimitiveHandle<P>, name: S, props?: PropsOf<P, S>): boolean;
|
|
40
|
+
declare function slotIn<P extends Primitive, S extends SlotName<P>>(handle: PrimitiveHandle<P>, name: S, props?: PropsOf<P, S>, user?: Record<string, any>): Record<string, any>;
|
|
41
|
+
declare function readIn<I extends PrimitiveInstance, T>(handle: {
|
|
42
|
+
instance: I;
|
|
43
|
+
}, read: (state: I["types"]["state"]) => T, around?: Record<string, object>): T;
|
|
44
|
+
/**
|
|
45
|
+
* Props every part takes: its element's props, `render`, and class names and
|
|
46
|
+
* styles that may be functions of the part's state.
|
|
47
|
+
* @stable
|
|
48
|
+
*/
|
|
49
|
+
type PartProps<Tag extends keyof React.JSX.IntrinsicElements, State = {}> = Omit<React.ComponentProps<Tag>, "className" | "style" | "children"> & {
|
|
50
|
+
/** Class names, or a function of the part's state that returns them. */
|
|
51
|
+
className?: string | ((state: State) => string | undefined);
|
|
52
|
+
/** Styles, or a function of the part's state that returns them. */
|
|
53
|
+
style?: React.CSSProperties | ((state: State) => React.CSSProperties | undefined);
|
|
54
|
+
/** Renders your own element: one that receives the part's props, or a function of the props and the state. */
|
|
55
|
+
render?: RenderProp<State>;
|
|
56
|
+
/** Content, or a function of the part's state that returns it. */
|
|
57
|
+
children?: React.ReactNode | ((state: State) => React.ReactNode);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Shares an instance with the parts inside, for a root that renders no
|
|
61
|
+
* element of its own, like a popover's.
|
|
62
|
+
*/
|
|
63
|
+
declare function HandleScope({ handle, children, }: {
|
|
64
|
+
handle: PrimitiveHandle<Primitive>;
|
|
65
|
+
children?: React.ReactNode;
|
|
66
|
+
}): React.JSX.Element;
|
|
67
|
+
/** The nearest instance of a primitive, or undefined outside its root, like a toggle's group. */
|
|
68
|
+
declare function useNearest<P extends Primitive>(primitive: P): PrimitiveHandle<P> | undefined;
|
|
69
|
+
/** The nearest instance of a primitive, for a part written by hand that calls its api. */
|
|
70
|
+
declare function useHandle<P extends Primitive>(primitive: P): PrimitiveHandle<P>;
|
|
71
|
+
type PartState<P extends Primitive, S extends SlotName<P>> = unknown extends StateOf<P, S> ? {} : StateOf<P, S>;
|
|
72
|
+
/**
|
|
73
|
+
* Renders one part of a primitive written by hand: its element, with the
|
|
74
|
+
* slot's attributes and handlers merged into `props`, re-rendered when what
|
|
75
|
+
* it shows changes, or nothing while the slot says it isn't present.
|
|
76
|
+
* `handle` is `usePrimitive`'s, or the primitive, whose nearest instance it
|
|
77
|
+
* uses. Given `usePrimitive`'s handle, the parts inside the element find that
|
|
78
|
+
* instance.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* function RatingStar({ value, ...props }: PartProps<"button", RatingStarState> & { value: string }) {
|
|
82
|
+
* return usePart(rating, "star", { value }, props, "button")
|
|
83
|
+
* }
|
|
84
|
+
* @stable
|
|
85
|
+
*/
|
|
86
|
+
declare function usePart<P extends Primitive, S extends SlotName<P>, T extends Tag = "div">(handle: P | PrimitiveHandle<P>, slot: S, slotProps: PropsOf<P, S>, props?: PartProps<T, PartState<P, S>>, tag?: T): React.JSX.Element | null;
|
|
87
|
+
type Pascal<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Capitalize<Head>}${Pascal<Tail>}` : Capitalize<Name>;
|
|
88
|
+
type Tag = keyof React.JSX.IntrinsicElements;
|
|
89
|
+
type ElementProps<T extends Tag, State, Named> = Omit<PartProps<T, State>, keyof Named>;
|
|
90
|
+
type Props<Named, State, T extends Tag> = Named & ElementProps<T, State, Named>;
|
|
91
|
+
type RootSlot<P extends Primitive> = "root" & SlotName<P>;
|
|
92
|
+
type GenericOf<P> = P extends {
|
|
93
|
+
generic?: infer G extends PrimitiveGeneric;
|
|
94
|
+
} ? G : never;
|
|
95
|
+
type Applied<G, T, U> = G & {
|
|
96
|
+
T: T;
|
|
97
|
+
U: U;
|
|
98
|
+
};
|
|
99
|
+
type DefaultOf<G extends PrimitiveGeneric, K extends "T" | "U"> = G extends {
|
|
100
|
+
defaults: Record<K, infer D>;
|
|
101
|
+
} ? D & G[K] : G[K];
|
|
102
|
+
type OptionsIn<P extends Primitive, A> = [A] extends [never] ? OptionsOf<P> : A extends {
|
|
103
|
+
options: infer O;
|
|
104
|
+
} ? O : OptionsOf<P>;
|
|
105
|
+
type StateIn<P extends Primitive, S extends SlotName<P>, A> = [A] extends [
|
|
106
|
+
never
|
|
107
|
+
] ? StateOf<P, S> : A extends {
|
|
108
|
+
state: Record<S, infer State>;
|
|
109
|
+
} ? State : StateOf<P, S>;
|
|
110
|
+
type PropsIn<P extends Primitive, S extends SlotName<P>, A> = [A] extends [
|
|
111
|
+
never
|
|
112
|
+
] ? PropsOf<P, S> : A extends {
|
|
113
|
+
props: Record<S, infer Named>;
|
|
114
|
+
} ? Named : PropsOf<P, S>;
|
|
115
|
+
type RootOf<P extends Primitive, T extends Tag | undefined> = [
|
|
116
|
+
GenericOf<P>
|
|
117
|
+
] extends [never] ? (props: RootPropsIn<P, never, T>) => React.ReactElement | null : <A extends GenericOf<P>["T"] = DefaultOf<GenericOf<P>, "T">, B extends GenericOf<P>["U"] = DefaultOf<GenericOf<P>, "U">>(props: GenericRootProps<P, Applied<GenericOf<P>, A, B>, T>) => React.ReactElement | null;
|
|
118
|
+
type GenericRootProps<P extends Primitive, A extends PrimitiveGeneric, T extends Tag | undefined> = T extends Tag ? Props<A["options"] & PropsOf<P, RootSlot<P>>, StateIn<P, RootSlot<P>, A>, T> : A["options"] & {
|
|
119
|
+
children?: React.ReactNode;
|
|
120
|
+
};
|
|
121
|
+
type RootPropsIn<P extends Primitive, A, T extends Tag | undefined> = T extends Tag ? Props<OptionsIn<P, A> & PropsIn<P, RootSlot<P>, A>, StateIn<P, RootSlot<P>, A>, T> : OptionsIn<P, A> & {
|
|
122
|
+
children?: React.ReactNode;
|
|
123
|
+
};
|
|
124
|
+
type PartOf<P extends Primitive, S extends SlotName<P>, T extends Tag> = [
|
|
125
|
+
GenericOf<P>
|
|
126
|
+
] extends [never] ? PartComponent<P, S, T> : GenericOf<P> extends {
|
|
127
|
+
props: Record<S, unknown>;
|
|
128
|
+
} ? GenericPartComponent<P, S, T> : PartComponent<P, S, T>;
|
|
129
|
+
/**
|
|
130
|
+
* A part's component, from `createParts`: the props of slot `S` of primitive
|
|
131
|
+
* `P` rendered as a `T`.
|
|
132
|
+
* @stable
|
|
133
|
+
*/
|
|
134
|
+
interface PartComponent<P extends Primitive, S extends SlotName<P>, T extends Tag> {
|
|
135
|
+
(props: Props<PropsOf<P, S>, [
|
|
136
|
+
GenericOf<P>
|
|
137
|
+
] extends [never] ? StateOf<P, S> : StateIn<P, S, GenericOf<P>>, T>): React.ReactElement | null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A part's component whose props take the primitive's type parameter, like an
|
|
141
|
+
* item's `value`, from `createParts`.
|
|
142
|
+
* @stable
|
|
143
|
+
*/
|
|
144
|
+
interface GenericPartComponent<P extends Primitive, S extends SlotName<P>, T extends Tag> {
|
|
145
|
+
<A extends GenericOf<P>["T"] = DefaultOf<GenericOf<P>, "T">>(props: Props<(Applied<GenericOf<P>, A, unknown>["props"] & Record<S, unknown>)[S], StateIn<P, S, Applied<GenericOf<P>, A, unknown>>, T>): React.ReactElement | null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The components `createParts` makes: `Root`, and one per tagged slot, named in Pascal case.
|
|
149
|
+
* @stable
|
|
150
|
+
*/
|
|
151
|
+
type Parts<P extends Primitive, Tags extends {
|
|
152
|
+
[S in SlotName<P>]?: Tag;
|
|
153
|
+
}> = {
|
|
154
|
+
Root: RootOf<P, Tags extends {
|
|
155
|
+
root: Tag;
|
|
156
|
+
} ? Tags["root"] : undefined>;
|
|
157
|
+
} & {
|
|
158
|
+
[S in keyof TypesOf<P>["slots"] as S extends Exclude<keyof Tags, "root"> & string ? Pascal<S> : never]: PartOf<P, S & SlotName<P>, NonNullable<Tags[S & keyof Tags]> & Tag>;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Every part of a primitive as a component, typed from it. `Root` makes the
|
|
162
|
+
* instance from the primitive's options and shares it with the parts inside
|
|
163
|
+
* it. Each slot named in `tags` becomes a component that renders that tag,
|
|
164
|
+
* named in Pascal case, like `TabIcon` for `tab-icon`. Without a `root` tag,
|
|
165
|
+
* `Root` renders only its children. Every part takes `render`, and class
|
|
166
|
+
* names, styles and children that may be functions of its state.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* const { Root: Playlist, Track: PlaylistTrack } = createParts(playlist, { root: "ul", track: "li" })
|
|
170
|
+
* @stable
|
|
171
|
+
*/
|
|
172
|
+
declare function createParts<P extends Primitive, Tags extends {
|
|
173
|
+
[S in SlotName<P>]?: Tag;
|
|
174
|
+
}>(primitive: P, tags: Tags): Parts<P, Tags>;
|
|
175
|
+
/** The props of the part of `slot` around the one rendering, like an option's inside its group. */
|
|
176
|
+
declare function useAround<P extends Primitive>(primitive: P, slot: SlotName<P>): Record<string, unknown> | undefined;
|
|
177
|
+
declare function sharesProps(primitive: Primitive, slot: string): void;
|
|
178
|
+
export { createParts, extendHandle, HandleScope, mergeProps, mergeRefs, type GenericPartComponent, type PartComponent, type PartProps, type Parts, presentIn, type PrimitiveHandle, readIn, reading, renderElement, type RenderProp, sharesProps, slotIn, useHandle, useAround, useNearest, usePart, usePrimitive, };
|