import React from "react"; import type { NonDeletedExcalidrawElement } from "@excalidraw/element/types"; import { useTunnels } from "../context/tunnels"; import { t } from "../i18n"; import { getScrollToContentState } from "../scene"; import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars"; import { ExitViewModeButton, MobileShapeActions } from "./Actions"; import { MobileToolbar } from "./MobileToolbar"; import { FixedSideContainer } from "./FixedSideContainer"; import { Island } from "./Island"; import { PenModeButton } from "./PenModeButton"; import { ViewportStatusBadge } from "./ViewportStatusFrame/ViewportStatusFrame"; import type { ActionManager } from "../actions/manager"; import type { AppClassProperties, AppState, UIAppState } from "../types"; import type { JSX } from "react"; type MobileMenuProps = { appState: UIAppState; actionManager: ActionManager; renderJSONExportDialog: () => React.ReactNode; renderImageExportDialog: () => React.ReactNode; setAppState: React.Component["setState"]; elements: readonly NonDeletedExcalidrawElement[]; onPenModeToggle: AppClassProperties["togglePenMode"]; renderTopRightUI?: ( isMobile: boolean, appState: UIAppState, ) => JSX.Element | null; renderTopLeftUI?: ( isMobile: boolean, appState: UIAppState, ) => JSX.Element | null; renderSidebars: () => JSX.Element | null; renderWelcomeScreen: boolean; defaultUIEnabled: boolean; scrollBackToContentUIEnabled: boolean; app: AppClassProperties; }; export const MobileMenu = ({ appState, elements, actionManager, setAppState, renderTopLeftUI, renderTopRightUI, renderSidebars, renderWelcomeScreen, defaultUIEnabled, scrollBackToContentUIEnabled, app, onPenModeToggle, }: MobileMenuProps) => { const { WelcomeScreenCenterTunnel, MainMenuTunnel, DefaultSidebarTriggerTunnel, } = useTunnels(); const renderAppTopBar = () => { if (appState.openDialog?.name === "elementLinkSelector") { return null; } const topRightUI = (
{renderTopRightUI?.(true, appState) ?? (!appState.viewModeEnabled && ( <> {defaultUIEnabled && ( onPenModeToggle(null)} title={t("toolBar.penMode")} isMobile penDetected={appState.penDetected} /> )} ))} {defaultUIEnabled && appState.viewModeEnabled && app.isInteractionEnabled() && ( )}
); const topLeftUI = (
{renderTopLeftUI?.(true, appState)}
); return (
{topLeftUI} {topRightUI}
); }; const renderToolbar = () => { return ; }; const shouldRenderScrollBackToContent = scrollBackToContentUIEnabled && appState.scrolledOutside; const shouldRenderDefaultBottomBar = defaultUIEnabled && !appState.viewModeEnabled; const scrollBackToContentButton = shouldRenderScrollBackToContent && !appState.openMenu && !appState.openSidebar ? ( ) : null; const viewportStatusLabel = app.props.viewportStatusFrame?.label; const viewportStatusBadge = viewportStatusLabel ? ( ) : null; return ( <> {renderSidebars()} {/* welcome screen, bottom bar, and top bar all have the same z-index */} {/* ordered in this reverse order so that top bar is on top */}
{renderWelcomeScreen && }
{shouldRenderDefaultBottomBar && (
{scrollBackToContentButton && (
{scrollBackToContentButton}
)} {appState.openDialog?.name !== "elementLinkSelector" && renderToolbar()}
)} {!shouldRenderDefaultBottomBar && scrollBackToContentButton && (
{scrollBackToContentButton}
)} {viewportStatusBadge && (
{viewportStatusBadge}
)} {renderAppTopBar()} ); };