snapshot of https://github.com/excalidraw/excalidraw.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Tests / test (push) Failing after 15s
Some checks failed
Tests / test (push) Failing after 15s
This commit is contained in:
95
packages/excalidraw/components/main-menu/MainMenu.tsx
Normal file
95
packages/excalidraw/components/main-menu/MainMenu.tsx
Normal file
@@ -0,0 +1,95 @@
|
||||
import React from "react";
|
||||
|
||||
import { composeEventHandlers } from "@excalidraw/common";
|
||||
|
||||
import { useTunnels } from "../../context/tunnels";
|
||||
import { useUIAppState } from "../../context/ui-appState";
|
||||
import { t } from "../../i18n";
|
||||
import {
|
||||
useAppProps,
|
||||
useEditorInterface,
|
||||
useExcalidrawSetAppState,
|
||||
} from "../App";
|
||||
import { UserList } from "../UserList";
|
||||
import DropdownMenu from "../dropdownMenu/DropdownMenu";
|
||||
import DropdownMenuSub from "../dropdownMenu/DropdownMenuSub";
|
||||
import { withInternalFallback } from "../hoc/withInternalFallback";
|
||||
import { HamburgerMenuIcon } from "../icons";
|
||||
|
||||
import * as DefaultItems from "./DefaultItems";
|
||||
|
||||
const MainMenu = Object.assign(
|
||||
withInternalFallback(
|
||||
"MainMenu",
|
||||
({
|
||||
children,
|
||||
onSelect,
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
/**
|
||||
* Called when any menu item is selected (clicked on).
|
||||
*/
|
||||
onSelect?: (event: Event) => void;
|
||||
}) => {
|
||||
const { MainMenuTunnel } = useTunnels();
|
||||
const editorInterface = useEditorInterface();
|
||||
const appState = useUIAppState();
|
||||
const appProps = useAppProps();
|
||||
const setAppState = useExcalidrawSetAppState();
|
||||
|
||||
return (
|
||||
<MainMenuTunnel.In>
|
||||
<DropdownMenu open={appState.openMenu === "canvas"}>
|
||||
<DropdownMenu.Trigger
|
||||
onToggle={() => {
|
||||
setAppState({
|
||||
openMenu: appState.openMenu === "canvas" ? null : "canvas",
|
||||
openPopup: null,
|
||||
openDialog: null,
|
||||
});
|
||||
}}
|
||||
data-testid="main-menu-trigger"
|
||||
className="main-menu-trigger"
|
||||
>
|
||||
{HamburgerMenuIcon}
|
||||
</DropdownMenu.Trigger>
|
||||
<DropdownMenu.Content
|
||||
onClickOutside={() => setAppState({ openMenu: null })}
|
||||
onSelect={composeEventHandlers(onSelect, () => {
|
||||
setAppState({ openMenu: null });
|
||||
})}
|
||||
className="main-menu"
|
||||
align="start"
|
||||
>
|
||||
{children}
|
||||
{editorInterface.formFactor === "phone" &&
|
||||
appState.collaborators.size > 0 && (
|
||||
<fieldset className="UserList-Wrapper">
|
||||
<legend>{t("labels.collaborators")}</legend>
|
||||
<UserList
|
||||
mobile={true}
|
||||
collaborators={appState.collaborators}
|
||||
userToFollow={appProps.userToFollow?.socketId || null}
|
||||
currentUserControls={appProps.currentUserControls}
|
||||
/>
|
||||
</fieldset>
|
||||
)}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu>
|
||||
</MainMenuTunnel.In>
|
||||
);
|
||||
},
|
||||
),
|
||||
{
|
||||
Trigger: DropdownMenu.Trigger,
|
||||
Item: DropdownMenu.Item,
|
||||
ItemLink: DropdownMenu.ItemLink,
|
||||
ItemCustom: DropdownMenu.ItemCustom,
|
||||
Group: DropdownMenu.Group,
|
||||
Separator: DropdownMenu.Separator,
|
||||
Sub: DropdownMenuSub,
|
||||
DefaultItems,
|
||||
},
|
||||
);
|
||||
|
||||
export default MainMenu;
|
||||
Reference in New Issue
Block a user