@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/menu.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type MenuCheckboxItemProps, type MenuCheckboxItemState, type MenuContentProps, type MenuContentState, type MenuContextTriggerProps, type MenuContextTriggerState, type MenuData, type MenuItemIconProps, type MenuItemIconState, type MenuItemIndicatorProps, type MenuItemIndicatorState, type MenuItemProps, type MenuItemState, type MenuOptions, type MenuRadioGroupProps, type MenuRadioGroupState, type MenuRadioItemProps, type MenuRadioItemState, type MenuSubTriggerProps, type MenuTriggerProps, type MenuTriggerState } from "@ui-sdk/core/menu";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { type PartProps } from "./use-primitive.js";
|
|
4
|
+
type Clashing = "value" | "defaultValue" | "onChange" | "onSelect" | "defaultChecked";
|
|
5
|
+
/**
|
|
6
|
+
* The props of `Menu`.
|
|
7
|
+
* @stable
|
|
8
|
+
*/
|
|
9
|
+
type MenuProps = MenuOptions & {
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A list of actions and options, opened from a button or a right-click. Put its trigger and content inside.
|
|
14
|
+
* @stable
|
|
15
|
+
*/
|
|
16
|
+
declare function Menu({ children, items, container, ...options }: MenuProps): React.JSX.Element;
|
|
17
|
+
type TriggerProps = MenuTriggerProps;
|
|
18
|
+
/**
|
|
19
|
+
* The button that opens the menu. A trigger outside the menu connects through `controller`.
|
|
20
|
+
* @stable
|
|
21
|
+
*/
|
|
22
|
+
declare function MenuTrigger({ controller, ...props }: Omit<PartProps<"button", MenuTriggerState>, Clashing> & TriggerProps): React.JSX.Element;
|
|
23
|
+
/**
|
|
24
|
+
* An area that opens the menu at the pointer on a right-click or a long press, and on Shift+F10.
|
|
25
|
+
* @stable
|
|
26
|
+
*/
|
|
27
|
+
declare function MenuContextTrigger({ controller, ...props }: PartProps<"div", MenuContextTriggerState> & MenuContextTriggerProps): React.JSX.Element;
|
|
28
|
+
/**
|
|
29
|
+
* The popup that holds the items, positioned against the trigger that opened it.
|
|
30
|
+
* @stable
|
|
31
|
+
*/
|
|
32
|
+
declare function MenuContent<Payload = unknown>({ side, align, sideOffset, alignOffset, collisionPadding, arrowPadding, anchor, finalFocus, keepMounted, container, render, ...props }: PartProps<"div", MenuContentState<Payload>> & MenuContentProps): React.JSX.Element | null;
|
|
33
|
+
/**
|
|
34
|
+
* An action. Pressing it runs its `onSelect` and closes the menu, unless `closeOnSelect` is false.
|
|
35
|
+
* @stable
|
|
36
|
+
*/
|
|
37
|
+
declare function MenuItem({ value, label, disabled, shortcut, closeOnSelect, destructive, onSelect, render, children, ...props }: Omit<PartProps<"div", MenuItemState>, Clashing> & MenuItemProps): React.JSX.Element | null;
|
|
38
|
+
/**
|
|
39
|
+
* Shows the keys of an item's shortcut, like `⌘S`, inside the item. Hidden from screen readers.
|
|
40
|
+
* @stable
|
|
41
|
+
*/
|
|
42
|
+
declare const MenuShortcut: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/menu").MenuPrimitive, "shortcut", "span">;
|
|
43
|
+
/**
|
|
44
|
+
* An item that checks and unchecks an option.
|
|
45
|
+
* @stable
|
|
46
|
+
*/
|
|
47
|
+
declare function MenuCheckboxItem({ value, label, disabled, checked, defaultChecked, onCheckedChange, closeOnSelect, render, ...props }: Omit<PartProps<"div", MenuCheckboxItemState>, Clashing> & MenuCheckboxItemProps): React.JSX.Element;
|
|
48
|
+
/**
|
|
49
|
+
* Radio items that share one value. `T` is inferred from `value`, `defaultValue` or `onValueChange`.
|
|
50
|
+
* @stable
|
|
51
|
+
*/
|
|
52
|
+
declare function MenuRadioGroup<T extends string = string>({ name, value, defaultValue, onValueChange, render, ...props }: Omit<PartProps<"div", MenuRadioGroupState>, Clashing> & MenuRadioGroupProps<T>): React.JSX.Element | null;
|
|
53
|
+
/**
|
|
54
|
+
* An item in a `MenuRadioGroup`. Pressing it checks its value.
|
|
55
|
+
* @stable
|
|
56
|
+
*/
|
|
57
|
+
declare function MenuRadioItem({ value, label, disabled, closeOnSelect, render, ...props }: Omit<PartProps<"div", MenuRadioItemState>, Clashing> & MenuRadioItemProps): React.JSX.Element;
|
|
58
|
+
/**
|
|
59
|
+
* The check or dot inside a checkbox or radio item. Rendered while the item is checked, or always with `keepMounted`.
|
|
60
|
+
* @stable
|
|
61
|
+
*/
|
|
62
|
+
declare function MenuItemIndicator({ keepMounted, render, ...props }: PartProps<"span", MenuItemIndicatorState> & MenuItemIndicatorProps): React.JSX.Element | null;
|
|
63
|
+
/**
|
|
64
|
+
* An icon inside an item or a submenu trigger. Screen readers and typeahead skip it, and `mirror`
|
|
65
|
+
* flips it in right-to-left text.
|
|
66
|
+
* @stable
|
|
67
|
+
*/
|
|
68
|
+
declare function MenuItemIcon({ mirror, render, ...props }: PartProps<"span", MenuItemIconState> & MenuItemIconProps): React.JSX.Element | null;
|
|
69
|
+
/**
|
|
70
|
+
* A group of items, named by its `MenuGroupLabel`.
|
|
71
|
+
* @stable
|
|
72
|
+
*/
|
|
73
|
+
declare function MenuGroup(props: PartProps<"div">): React.JSX.Element;
|
|
74
|
+
/**
|
|
75
|
+
* The group's heading, which names the group.
|
|
76
|
+
* @stable
|
|
77
|
+
*/
|
|
78
|
+
declare function MenuGroupLabel({ render, ...props }: PartProps<"div">): React.JSX.Element | null;
|
|
79
|
+
/**
|
|
80
|
+
* A line between items or groups.
|
|
81
|
+
* @stable
|
|
82
|
+
*/
|
|
83
|
+
declare const MenuSeparator: import("./use-primitive.js").PartComponent<import("@ui-sdk/core/menu").MenuPrimitive, "separator", "div">;
|
|
84
|
+
/**
|
|
85
|
+
* The props of `MenuSub`.
|
|
86
|
+
* @stable
|
|
87
|
+
*/
|
|
88
|
+
type MenuSubProps = Pick<MenuOptions, "open" | "defaultOpen" | "onOpenChange" | "onOpenChangeComplete" | "loop" | "delay" | "controller" | "debug"> & {
|
|
89
|
+
children?: React.ReactNode;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* A submenu. Put its `MenuSubTrigger` and `MenuSubContent` inside, in a menu's content.
|
|
93
|
+
* @stable
|
|
94
|
+
*/
|
|
95
|
+
declare function MenuSub({ children, ...options }: MenuSubProps): React.JSX.Element;
|
|
96
|
+
/**
|
|
97
|
+
* The item that opens its submenu.
|
|
98
|
+
* @stable
|
|
99
|
+
*/
|
|
100
|
+
declare function MenuSubTrigger({ disabled, ...props }: Omit<PartProps<"div", MenuTriggerState>, Clashing> & MenuSubTriggerProps): React.JSX.Element | null;
|
|
101
|
+
/**
|
|
102
|
+
* The submenu's popup, positioned beside its trigger.
|
|
103
|
+
* @stable
|
|
104
|
+
*/
|
|
105
|
+
declare const MenuSubContent: typeof MenuContent;
|
|
106
|
+
/**
|
|
107
|
+
* Renders a data menu's items as bare parts. Used by `<Menu items>` when you place no `MenuContent`
|
|
108
|
+
* of your own, and available for custom layouts.
|
|
109
|
+
* @stable
|
|
110
|
+
*/
|
|
111
|
+
declare function MenuItems({ items }: {
|
|
112
|
+
items: MenuData;
|
|
113
|
+
}): React.JSX.Element[];
|
|
114
|
+
export { createMenuController } from "@ui-sdk/core/menu";
|
|
115
|
+
export type { MenuApi, MenuCheckboxItemProps, MenuCheckboxItemState, MenuActionDetails, MenuCheckedChangeDetails, MenuCheckedChangeReason, MenuContentProps, MenuContentState, MenuContextTriggerProps, MenuContextTriggerState, MenuController, MenuData, MenuDataItem, MenuDismissReason, MenuFinalFocus, MenuItemIconProps, MenuItemIconState, MenuItemIndicatorProps, MenuItemIndicatorState, MenuItemProps, MenuItemState, MenuOpenChangeReason, MenuOpenOptions, MenuOptions, MenuPayloadChangeReason, MenuPrimitive, MenuRadioGroupProps, MenuRadioGroupState, MenuRadioItemProps, MenuRadioItemState, MenuSubTriggerProps, MenuTriggerProps, MenuTriggerState, MenuValueChangeDetails, MenuValueChangeReason, } from "@ui-sdk/core/menu";
|
|
116
|
+
export { Menu, MenuCheckboxItem, MenuContent, MenuContextTrigger, MenuGroup, MenuGroupLabel, MenuItem, MenuItemIcon, MenuItemIndicator, MenuItems, type MenuProps, MenuRadioGroup, MenuRadioItem, MenuSeparator, MenuShortcut, MenuSub, MenuSubContent, type MenuSubProps, MenuSubTrigger, MenuTrigger, };
|
package/dist/menu.js
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/menu.tsx
|
|
3
|
+
import { formatShortcut } from "@ui-sdk/core";
|
|
4
|
+
import {
|
|
5
|
+
menu as menuPrimitive
|
|
6
|
+
} from "@ui-sdk/core/menu";
|
|
7
|
+
import {
|
|
8
|
+
menuCheckable,
|
|
9
|
+
menuContextTrigger,
|
|
10
|
+
menuItemIcons
|
|
11
|
+
} from "@ui-sdk/core/renderer";
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
import { hasChild, Placed, usePlaceContent, usePlacedContent } from "./children.js";
|
|
14
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
15
|
+
import {
|
|
16
|
+
Connected,
|
|
17
|
+
renderPopup,
|
|
18
|
+
sheetViewport,
|
|
19
|
+
useOwnContainer,
|
|
20
|
+
usePopupContainer,
|
|
21
|
+
useControllerEntry
|
|
22
|
+
} from "./popup.js";
|
|
23
|
+
import {
|
|
24
|
+
createParts,
|
|
25
|
+
HandleScope,
|
|
26
|
+
reading,
|
|
27
|
+
renderElement,
|
|
28
|
+
sharesProps,
|
|
29
|
+
useAround,
|
|
30
|
+
useHandle,
|
|
31
|
+
usePart,
|
|
32
|
+
usePrimitive
|
|
33
|
+
} from "./use-primitive.js";
|
|
34
|
+
import { createMenuController } from "@ui-sdk/core/menu";
|
|
35
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
36
|
+
var parts = createParts(menuPrimitive, {
|
|
37
|
+
trigger: "button",
|
|
38
|
+
shortcut: "span",
|
|
39
|
+
separator: "div"
|
|
40
|
+
});
|
|
41
|
+
sharesProps(menuPrimitive, "radio-group");
|
|
42
|
+
var ContainerContext = React.createContext(void 0);
|
|
43
|
+
var GroupContext = React.createContext(null);
|
|
44
|
+
var ItemContext = React.createContext(null);
|
|
45
|
+
function useMenu() {
|
|
46
|
+
return useHandle(menuPrimitive);
|
|
47
|
+
}
|
|
48
|
+
function useRadioGroup() {
|
|
49
|
+
return useAround(menuPrimitive, "radio-group")?.name;
|
|
50
|
+
}
|
|
51
|
+
function Menu({ children, items, container, ...options }) {
|
|
52
|
+
const menubar = React.useContext(MenubarContext);
|
|
53
|
+
const menu = usePrimitive(menuPrimitive, {
|
|
54
|
+
items,
|
|
55
|
+
...options,
|
|
56
|
+
menubar: menubar ? reading(menubar, () => menubar.api) : void 0
|
|
57
|
+
});
|
|
58
|
+
useControllerEntry(options.controller, menu);
|
|
59
|
+
const found = hasChild(children, MenuContent);
|
|
60
|
+
const [placed, place] = usePlacedContent(!!items && !found);
|
|
61
|
+
const own = placed || found;
|
|
62
|
+
return /* @__PURE__ */ jsx(HandleScope, { handle: menu, children: /* @__PURE__ */ jsxs(ContainerContext.Provider, { value: container, children: [
|
|
63
|
+
/* @__PURE__ */ jsx(MenubarContext.Provider, { value: null, children: /* @__PURE__ */ jsx(Placed, { value: place, children }) }),
|
|
64
|
+
/* @__PURE__ */ jsx(Placed, { value: null, children: items && !own && /* @__PURE__ */ jsx(MenuContent, { children: /* @__PURE__ */ jsx(MenuItems, { items }) }) })
|
|
65
|
+
] }) });
|
|
66
|
+
}
|
|
67
|
+
function MenuTrigger({
|
|
68
|
+
controller,
|
|
69
|
+
...props
|
|
70
|
+
}) {
|
|
71
|
+
const {
|
|
72
|
+
disabled,
|
|
73
|
+
focusableWhenDisabled,
|
|
74
|
+
payload: _,
|
|
75
|
+
shortcut: __,
|
|
76
|
+
render,
|
|
77
|
+
...rest
|
|
78
|
+
} = props;
|
|
79
|
+
const unconnected = () => renderElement(
|
|
80
|
+
"button",
|
|
81
|
+
{
|
|
82
|
+
type: "button",
|
|
83
|
+
disabled: disabled && !focusableWhenDisabled,
|
|
84
|
+
"aria-disabled": disabled && focusableWhenDisabled || void 0,
|
|
85
|
+
...rest
|
|
86
|
+
},
|
|
87
|
+
render,
|
|
88
|
+
{
|
|
89
|
+
open: false,
|
|
90
|
+
disabled: !!disabled
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
return /* @__PURE__ */ jsx(
|
|
94
|
+
Connected,
|
|
95
|
+
{
|
|
96
|
+
primitive: menuPrimitive,
|
|
97
|
+
controller,
|
|
98
|
+
fallback: unconnected,
|
|
99
|
+
children: /* @__PURE__ */ jsx(parts.Trigger, { ...props })
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function MenuContextTrigger({
|
|
104
|
+
controller,
|
|
105
|
+
...props
|
|
106
|
+
}) {
|
|
107
|
+
const { disabled, payload: _, render, ...rest } = props;
|
|
108
|
+
const unconnected = () => renderElement("div", rest, render, { open: false, disabled: !!disabled });
|
|
109
|
+
return /* @__PURE__ */ jsx(
|
|
110
|
+
Connected,
|
|
111
|
+
{
|
|
112
|
+
primitive: menuPrimitive,
|
|
113
|
+
controller,
|
|
114
|
+
fallback: unconnected,
|
|
115
|
+
children: /* @__PURE__ */ jsx(ContextTriggerPart, { ...props })
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
function ContextTriggerPart({
|
|
120
|
+
disabled,
|
|
121
|
+
payload,
|
|
122
|
+
...props
|
|
123
|
+
}) {
|
|
124
|
+
const menu = useMenu();
|
|
125
|
+
menu.instance.use(menuContextTrigger);
|
|
126
|
+
return usePart(
|
|
127
|
+
menu,
|
|
128
|
+
"context-trigger",
|
|
129
|
+
{ id: React.useId(), disabled, payload },
|
|
130
|
+
props
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function MenuContent({
|
|
134
|
+
side,
|
|
135
|
+
align,
|
|
136
|
+
sideOffset,
|
|
137
|
+
alignOffset,
|
|
138
|
+
collisionPadding,
|
|
139
|
+
arrowPadding,
|
|
140
|
+
anchor,
|
|
141
|
+
finalFocus,
|
|
142
|
+
keepMounted,
|
|
143
|
+
container,
|
|
144
|
+
render,
|
|
145
|
+
...props
|
|
146
|
+
}) {
|
|
147
|
+
usePlaceContent();
|
|
148
|
+
const menu = useMenu();
|
|
149
|
+
const target = usePopupContainer(useOwnContainer(container, ContainerContext));
|
|
150
|
+
const content = {
|
|
151
|
+
side,
|
|
152
|
+
align,
|
|
153
|
+
sideOffset,
|
|
154
|
+
alignOffset,
|
|
155
|
+
collisionPadding,
|
|
156
|
+
arrowPadding,
|
|
157
|
+
anchor,
|
|
158
|
+
finalFocus,
|
|
159
|
+
keepMounted
|
|
160
|
+
};
|
|
161
|
+
const nested = menu.api.root() !== menu.api;
|
|
162
|
+
const partProps = {
|
|
163
|
+
...props,
|
|
164
|
+
render: nested ? render : sheetViewport(menu, render)
|
|
165
|
+
};
|
|
166
|
+
const element = usePart(menu, "content", content, partProps);
|
|
167
|
+
return element && (nested ? element : renderPopup(element, target));
|
|
168
|
+
}
|
|
169
|
+
function MenuItem({
|
|
170
|
+
value,
|
|
171
|
+
label,
|
|
172
|
+
disabled,
|
|
173
|
+
shortcut,
|
|
174
|
+
closeOnSelect,
|
|
175
|
+
destructive,
|
|
176
|
+
onSelect,
|
|
177
|
+
render,
|
|
178
|
+
children,
|
|
179
|
+
...props
|
|
180
|
+
}) {
|
|
181
|
+
const menu = useMenu();
|
|
182
|
+
const id = React.useId();
|
|
183
|
+
const item = {
|
|
184
|
+
id,
|
|
185
|
+
value,
|
|
186
|
+
label,
|
|
187
|
+
disabled,
|
|
188
|
+
shortcut,
|
|
189
|
+
closeOnSelect,
|
|
190
|
+
destructive,
|
|
191
|
+
onSelect
|
|
192
|
+
};
|
|
193
|
+
const content = (state) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
194
|
+
typeof children === "function" ? children(state) : children,
|
|
195
|
+
shortcut && /* @__PURE__ */ jsx(MenuShortcut, { children: formatShortcut(shortcut, menu.state.apple) })
|
|
196
|
+
] });
|
|
197
|
+
return usePart(menu, "item", item, { ...props, children: content, render });
|
|
198
|
+
}
|
|
199
|
+
var MenuShortcut = parts.Shortcut;
|
|
200
|
+
function MenuCheckboxItem({
|
|
201
|
+
value,
|
|
202
|
+
label,
|
|
203
|
+
disabled,
|
|
204
|
+
checked,
|
|
205
|
+
defaultChecked,
|
|
206
|
+
onCheckedChange,
|
|
207
|
+
closeOnSelect,
|
|
208
|
+
render,
|
|
209
|
+
...props
|
|
210
|
+
}) {
|
|
211
|
+
const menu = useMenu();
|
|
212
|
+
menu.instance.use(menuCheckable);
|
|
213
|
+
const item = {
|
|
214
|
+
value,
|
|
215
|
+
label,
|
|
216
|
+
disabled,
|
|
217
|
+
checked,
|
|
218
|
+
defaultChecked,
|
|
219
|
+
onCheckedChange,
|
|
220
|
+
closeOnSelect
|
|
221
|
+
};
|
|
222
|
+
const indicator = React.useMemo(
|
|
223
|
+
() => ({ item: "checkbox-item", itemKey: value }),
|
|
224
|
+
[value]
|
|
225
|
+
);
|
|
226
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, { value: indicator, children: usePart(menu, "checkbox-item", item, { ...props, render }) });
|
|
227
|
+
}
|
|
228
|
+
function MenuRadioGroup({
|
|
229
|
+
name,
|
|
230
|
+
value,
|
|
231
|
+
defaultValue,
|
|
232
|
+
onValueChange,
|
|
233
|
+
render,
|
|
234
|
+
...props
|
|
235
|
+
}) {
|
|
236
|
+
const menu = useMenu();
|
|
237
|
+
menu.instance.use(menuCheckable);
|
|
238
|
+
const generated = React.useId();
|
|
239
|
+
const group = name ?? generated;
|
|
240
|
+
const part = {
|
|
241
|
+
id: group,
|
|
242
|
+
name: group,
|
|
243
|
+
value,
|
|
244
|
+
defaultValue,
|
|
245
|
+
onValueChange
|
|
246
|
+
};
|
|
247
|
+
return usePart(menu, "radio-group", part, { ...props, render });
|
|
248
|
+
}
|
|
249
|
+
function MenuRadioItem({
|
|
250
|
+
value,
|
|
251
|
+
label,
|
|
252
|
+
disabled,
|
|
253
|
+
closeOnSelect,
|
|
254
|
+
render,
|
|
255
|
+
...props
|
|
256
|
+
}) {
|
|
257
|
+
const menu = useMenu();
|
|
258
|
+
menu.instance.use(menuCheckable);
|
|
259
|
+
const group = useRadioGroup();
|
|
260
|
+
const item = { group: group ?? "", value, label, disabled, closeOnSelect };
|
|
261
|
+
const indicator = React.useMemo(
|
|
262
|
+
() => ({ item: "radio-item", itemKey: value, group: group ?? "" }),
|
|
263
|
+
[value, group]
|
|
264
|
+
);
|
|
265
|
+
if (!group) {
|
|
266
|
+
throw new Error("<MenuRadioItem> must be used inside <MenuRadioGroup>.");
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ jsx(ItemContext.Provider, { value: indicator, children: usePart(menu, "radio-item", item, { ...props, render }) });
|
|
269
|
+
}
|
|
270
|
+
function MenuItemIndicator({
|
|
271
|
+
keepMounted,
|
|
272
|
+
render,
|
|
273
|
+
...props
|
|
274
|
+
}) {
|
|
275
|
+
const menu = useMenu();
|
|
276
|
+
menu.instance.use(menuCheckable);
|
|
277
|
+
const id = React.useId();
|
|
278
|
+
const item = React.useContext(ItemContext);
|
|
279
|
+
if (!item) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
"<MenuItemIndicator> must be used inside a checkbox or radio item."
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
const indicator = { id, ...item, keepMounted };
|
|
285
|
+
return usePart(
|
|
286
|
+
menu,
|
|
287
|
+
"item-indicator",
|
|
288
|
+
indicator,
|
|
289
|
+
{ ...props, render },
|
|
290
|
+
"span"
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
function MenuItemIcon({
|
|
294
|
+
mirror,
|
|
295
|
+
render,
|
|
296
|
+
...props
|
|
297
|
+
}) {
|
|
298
|
+
const menu = useMenu();
|
|
299
|
+
menu.instance.use(menuItemIcons);
|
|
300
|
+
const part = { id: React.useId(), mirror };
|
|
301
|
+
return usePart(menu, "item-icon", part, { ...props, render }, "span");
|
|
302
|
+
}
|
|
303
|
+
function MenuGroup(props) {
|
|
304
|
+
const id = React.useId();
|
|
305
|
+
return /* @__PURE__ */ jsx(GroupContext.Provider, { value: id, children: usePart(useMenu(), "group", { id }, props) });
|
|
306
|
+
}
|
|
307
|
+
function MenuGroupLabel({ render, ...props }) {
|
|
308
|
+
const menu = useMenu();
|
|
309
|
+
const radioGroup = useRadioGroup();
|
|
310
|
+
const plainGroup = React.useContext(GroupContext);
|
|
311
|
+
const group = radioGroup ?? plainGroup;
|
|
312
|
+
if (!group) {
|
|
313
|
+
throw new Error(
|
|
314
|
+
"<MenuGroupLabel> must be used inside <MenuGroup> or <MenuRadioGroup>."
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return usePart(
|
|
318
|
+
menu,
|
|
319
|
+
"group-label",
|
|
320
|
+
{ id: group, group },
|
|
321
|
+
{ ...props, render },
|
|
322
|
+
"div"
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
var MenuSeparator = parts.Separator;
|
|
326
|
+
function MenuSub({ children, ...options }) {
|
|
327
|
+
const parent = useMenu();
|
|
328
|
+
const menu = usePrimitive(menuPrimitive, { ...options, parent: parent.api });
|
|
329
|
+
return /* @__PURE__ */ jsx(HandleScope, { handle: menu, children });
|
|
330
|
+
}
|
|
331
|
+
function MenuSubTrigger({
|
|
332
|
+
disabled,
|
|
333
|
+
...props
|
|
334
|
+
}) {
|
|
335
|
+
return usePart(useMenu(), "trigger", { disabled }, props);
|
|
336
|
+
}
|
|
337
|
+
var MenuSubContent = MenuContent;
|
|
338
|
+
function MenuItems({ items }) {
|
|
339
|
+
return items.map((entry, index) => {
|
|
340
|
+
const item = typeof entry === "string" ? { value: entry, label: entry } : entry;
|
|
341
|
+
switch (item.type) {
|
|
342
|
+
case void 0:
|
|
343
|
+
case "item":
|
|
344
|
+
return /* @__PURE__ */ jsx(
|
|
345
|
+
MenuItem,
|
|
346
|
+
{
|
|
347
|
+
value: item.value,
|
|
348
|
+
disabled: item.disabled,
|
|
349
|
+
shortcut: item.shortcut,
|
|
350
|
+
closeOnSelect: item.closeOnSelect,
|
|
351
|
+
destructive: item.destructive,
|
|
352
|
+
children: item.label
|
|
353
|
+
},
|
|
354
|
+
item.value
|
|
355
|
+
);
|
|
356
|
+
case "separator":
|
|
357
|
+
return /* @__PURE__ */ jsx(MenuSeparator, {}, `separator-${index}`);
|
|
358
|
+
case "group":
|
|
359
|
+
return /* @__PURE__ */ jsxs(MenuGroup, { children: [
|
|
360
|
+
item.label && /* @__PURE__ */ jsx(MenuGroupLabel, { children: item.label }),
|
|
361
|
+
/* @__PURE__ */ jsx(MenuItems, { items: item.items })
|
|
362
|
+
] }, `group-${index}`);
|
|
363
|
+
case "checkbox":
|
|
364
|
+
return /* @__PURE__ */ jsx(
|
|
365
|
+
MenuCheckboxItem,
|
|
366
|
+
{
|
|
367
|
+
value: item.value,
|
|
368
|
+
disabled: item.disabled,
|
|
369
|
+
checked: item.checked,
|
|
370
|
+
defaultChecked: item.defaultChecked,
|
|
371
|
+
closeOnSelect: item.closeOnSelect,
|
|
372
|
+
children: item.label
|
|
373
|
+
},
|
|
374
|
+
item.value
|
|
375
|
+
);
|
|
376
|
+
case "radio-group":
|
|
377
|
+
return /* @__PURE__ */ jsxs(
|
|
378
|
+
MenuRadioGroup,
|
|
379
|
+
{
|
|
380
|
+
name: item.name,
|
|
381
|
+
value: item.value,
|
|
382
|
+
defaultValue: item.defaultValue,
|
|
383
|
+
children: [
|
|
384
|
+
item.label && /* @__PURE__ */ jsx(MenuGroupLabel, { children: item.label }),
|
|
385
|
+
item.items.map((radio) => /* @__PURE__ */ jsx(
|
|
386
|
+
MenuRadioItem,
|
|
387
|
+
{
|
|
388
|
+
value: radio.value,
|
|
389
|
+
disabled: radio.disabled,
|
|
390
|
+
children: radio.label
|
|
391
|
+
},
|
|
392
|
+
radio.value
|
|
393
|
+
))
|
|
394
|
+
]
|
|
395
|
+
},
|
|
396
|
+
item.name
|
|
397
|
+
);
|
|
398
|
+
case "submenu":
|
|
399
|
+
return /* @__PURE__ */ jsxs(MenuSub, { children: [
|
|
400
|
+
/* @__PURE__ */ jsx(MenuSubTrigger, { disabled: item.disabled, children: item.label }),
|
|
401
|
+
/* @__PURE__ */ jsx(MenuSubContent, { children: /* @__PURE__ */ jsx(MenuItems, { items: item.items }) })
|
|
402
|
+
] }, `submenu-${index}`);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
export {
|
|
407
|
+
Menu,
|
|
408
|
+
MenuCheckboxItem,
|
|
409
|
+
MenuContent,
|
|
410
|
+
MenuContextTrigger,
|
|
411
|
+
MenuGroup,
|
|
412
|
+
MenuGroupLabel,
|
|
413
|
+
MenuItem,
|
|
414
|
+
MenuItemIcon,
|
|
415
|
+
MenuItemIndicator,
|
|
416
|
+
MenuItems,
|
|
417
|
+
MenuRadioGroup,
|
|
418
|
+
MenuRadioItem,
|
|
419
|
+
MenuSeparator,
|
|
420
|
+
MenuShortcut,
|
|
421
|
+
MenuSub,
|
|
422
|
+
MenuSubContent,
|
|
423
|
+
MenuSubTrigger,
|
|
424
|
+
MenuTrigger,
|
|
425
|
+
createMenuController
|
|
426
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type MenubarOptions, type MenubarState } from "@ui-sdk/core/menubar";
|
|
2
|
+
import { type PartProps } from "./use-primitive.js";
|
|
3
|
+
/**
|
|
4
|
+
* A row of menus, like a desktop app's: one tab stop, arrow keys between the
|
|
5
|
+
* triggers and between open menus. Each `Menu` inside joins it.
|
|
6
|
+
* @stable
|
|
7
|
+
*/
|
|
8
|
+
declare function Menubar({ orientation, loop, disabled, modal, controller, debug, ...props }: MenubarOptions & PartProps<"div", MenubarState>): import("react").JSX.Element;
|
|
9
|
+
export { createMenubarController } from "@ui-sdk/core/menubar";
|
|
10
|
+
export type { MenubarApi, MenubarController, MenubarMember, MenubarOptions, MenubarOrientation, MenubarPrimitive, MenubarState, } from "@ui-sdk/core/menubar";
|
|
11
|
+
export { Menubar };
|
package/dist/menubar.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// src/menubar.tsx
|
|
3
|
+
import {
|
|
4
|
+
menubar as menubarPrimitive
|
|
5
|
+
} from "@ui-sdk/core/menubar";
|
|
6
|
+
import { MenubarContext } from "./menubar-context.js";
|
|
7
|
+
import { usePart, usePrimitive } from "./use-primitive.js";
|
|
8
|
+
import { createMenubarController } from "@ui-sdk/core/menubar";
|
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
|
10
|
+
function Menubar({
|
|
11
|
+
orientation,
|
|
12
|
+
loop,
|
|
13
|
+
disabled,
|
|
14
|
+
modal,
|
|
15
|
+
controller,
|
|
16
|
+
debug,
|
|
17
|
+
...props
|
|
18
|
+
}) {
|
|
19
|
+
const menubar = usePrimitive(menubarPrimitive, {
|
|
20
|
+
orientation,
|
|
21
|
+
loop,
|
|
22
|
+
disabled,
|
|
23
|
+
modal,
|
|
24
|
+
controller,
|
|
25
|
+
debug
|
|
26
|
+
});
|
|
27
|
+
return /* @__PURE__ */ jsx(MenubarContext.Provider, { value: menubar, children: usePart(menubar, "root", {}, props) });
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
Menubar,
|
|
31
|
+
createMenubarController
|
|
32
|
+
};
|