import { defineMessages, usePassThroughWheelEvents } from '@tldraw/editor' import { memo, useCallback, useRef } from 'react' import { PORTRAIT_BREAKPOINT } from '../../constants' import { unwrapLabel, useActions } from '../../context/actions' import { useBreakpoint } from '../../context/breakpoints' import { useTldrawUiComponents } from '../../context/components' import { useLocalStorageState } from '../../hooks/useLocalStorageState' import { useDirection, useTranslation } from '../../hooks/useTranslation/useTranslation' import { kbdStr } from '../../kbd-utils' import { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon' import { TldrawUiToolbar, TldrawUiToolbarButton } from '../primitives/TldrawUiToolbar' const messages = defineMessages({ navigationZoneTitle: { id: 'navigation-zone.title', defaultMessage: 'Navigation' }, navigationZoneToggleMinimap: { id: 'navigation-zone.toggle-minimap', defaultMessage: 'Toggle minimap', }, }) /** @public @react */ export const DefaultNavigationPanel = memo(function DefaultNavigationPanel() { const actions = useActions() const msg = useTranslation() const dir = useDirection() const breakpoint = useBreakpoint() const ref = useRef(null) usePassThroughWheelEvents(ref) const [collapsed, setCollapsed] = useLocalStorageState('minimap', true) const toggleMinimap = useCallback(() => { setCollapsed((s) => !s) }, [setCollapsed]) const { ZoomMenu, Minimap } = useTldrawUiComponents() if (breakpoint < PORTRAIT_BREAKPOINT.MOBILE) { return null } const isRtl = dir === 'rtl' const minimapToggle = Minimap && ( ) return (
{ZoomMenu && breakpoint < PORTRAIT_BREAKPOINT.TABLET ? ( ) : ( <> {isRtl && minimapToggle} {!collapsed && ( actions['zoom-out'].onSelect('navigation-zone')} > )} {ZoomMenu && } {!collapsed && ( actions['zoom-in'].onSelect('navigation-zone')} > )} {!isRtl && minimapToggle} )} {Minimap && breakpoint >= PORTRAIT_BREAKPOINT.TABLET && !collapsed && }
) })