diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx')
| -rw-r--r-- | packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx b/packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx new file mode 100644 index 0000000..4faa41b --- /dev/null +++ b/packages/excalidraw/components/welcome-screen/WelcomeScreen.Center.tsx @@ -0,0 +1,195 @@ +import type { JSX } from "react"; +import { actionLoadScene, actionShortcuts } from "../../actions"; +import { getShortcutFromShortcutName } from "../../actions/shortcuts"; +import { t, useI18n } from "../../i18n"; +import { useDevice, useExcalidrawActionManager } from "../App"; +import { useTunnels } from "../../context/tunnels"; +import { HelpIcon, LoadIcon, usersIcon } from "../icons"; +import { useUIAppState } from "../../context/ui-appState"; +import { ExcalidrawLogo } from "../ExcalidrawLogo"; + +const WelcomeScreenMenuItemContent = ({ + icon, + shortcut, + children, +}: { + icon?: JSX.Element; + shortcut?: string | null; + children: React.ReactNode; +}) => { + const device = useDevice(); + return ( + <> + <div className="welcome-screen-menu-item__icon">{icon}</div> + <div className="welcome-screen-menu-item__text">{children}</div> + {shortcut && !device.editor.isMobile && ( + <div className="welcome-screen-menu-item__shortcut">{shortcut}</div> + )} + </> + ); +}; +WelcomeScreenMenuItemContent.displayName = "WelcomeScreenMenuItemContent"; + +const WelcomeScreenMenuItem = ({ + onSelect, + children, + icon, + shortcut, + className = "", + ...props +}: { + onSelect: () => void; + children: React.ReactNode; + icon?: JSX.Element; + shortcut?: string | null; +} & React.ButtonHTMLAttributes<HTMLButtonElement>) => { + return ( + <button + {...props} + type="button" + className={`welcome-screen-menu-item ${className}`} + onClick={onSelect} + > + <WelcomeScreenMenuItemContent icon={icon} shortcut={shortcut}> + {children} + </WelcomeScreenMenuItemContent> + </button> + ); +}; +WelcomeScreenMenuItem.displayName = "WelcomeScreenMenuItem"; + +const WelcomeScreenMenuItemLink = ({ + children, + href, + icon, + shortcut, + className = "", + ...props +}: { + children: React.ReactNode; + href: string; + icon?: JSX.Element; + shortcut?: string | null; +} & React.AnchorHTMLAttributes<HTMLAnchorElement>) => { + return ( + <a + {...props} + className={`welcome-screen-menu-item ${className}`} + href={href} + target="_blank" + rel="noreferrer" + > + <WelcomeScreenMenuItemContent icon={icon} shortcut={shortcut}> + {children} + </WelcomeScreenMenuItemContent> + </a> + ); +}; +WelcomeScreenMenuItemLink.displayName = "WelcomeScreenMenuItemLink"; + +const Center = ({ children }: { children?: React.ReactNode }) => { + const { WelcomeScreenCenterTunnel } = useTunnels(); + return ( + <WelcomeScreenCenterTunnel.In> + <div className="welcome-screen-center"> + {children || ( + <> + <Logo /> + <Heading>{t("welcomeScreen.defaults.center_heading")}</Heading> + <Menu> + <MenuItemLoadScene /> + <MenuItemHelp /> + </Menu> + </> + )} + </div> + </WelcomeScreenCenterTunnel.In> + ); +}; +Center.displayName = "Center"; + +const Logo = ({ children }: { children?: React.ReactNode }) => { + return ( + <div className="welcome-screen-center__logo excalifont welcome-screen-decor"> + {children || <ExcalidrawLogo withText />} + </div> + ); +}; +Logo.displayName = "Logo"; + +const Heading = ({ children }: { children: React.ReactNode }) => { + return ( + <div className="welcome-screen-center__heading welcome-screen-decor excalifont"> + {children} + </div> + ); +}; +Heading.displayName = "Heading"; + +const Menu = ({ children }: { children?: React.ReactNode }) => { + return <div className="welcome-screen-menu">{children}</div>; +}; +Menu.displayName = "Menu"; + +const MenuItemHelp = () => { + const actionManager = useExcalidrawActionManager(); + + return ( + <WelcomeScreenMenuItem + onSelect={() => actionManager.executeAction(actionShortcuts)} + shortcut="?" + icon={HelpIcon} + > + {t("helpDialog.title")} + </WelcomeScreenMenuItem> + ); +}; +MenuItemHelp.displayName = "MenuItemHelp"; + +const MenuItemLoadScene = () => { + const appState = useUIAppState(); + const actionManager = useExcalidrawActionManager(); + + if (appState.viewModeEnabled) { + return null; + } + + return ( + <WelcomeScreenMenuItem + onSelect={() => actionManager.executeAction(actionLoadScene)} + shortcut={getShortcutFromShortcutName("loadScene")} + icon={LoadIcon} + > + {t("buttons.load")} + </WelcomeScreenMenuItem> + ); +}; +MenuItemLoadScene.displayName = "MenuItemLoadScene"; + +const MenuItemLiveCollaborationTrigger = ({ + onSelect, +}: { + onSelect: () => any; +}) => { + const { t } = useI18n(); + return ( + <WelcomeScreenMenuItem shortcut={null} onSelect={onSelect} icon={usersIcon}> + {t("labels.liveCollaboration")} + </WelcomeScreenMenuItem> + ); +}; +MenuItemLiveCollaborationTrigger.displayName = + "MenuItemLiveCollaborationTrigger"; + +// ----------------------------------------------------------------------------- + +Center.Logo = Logo; +Center.Heading = Heading; +Center.Menu = Menu; +Center.MenuItem = WelcomeScreenMenuItem; +Center.MenuItemLink = WelcomeScreenMenuItemLink; +Center.MenuItemHelp = MenuItemHelp; +Center.MenuItemLoadScene = MenuItemLoadScene; +Center.MenuItemLiveCollaborationTrigger = MenuItemLiveCollaborationTrigger; + +export { Center }; |
