ZoomMenu.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
  2. import { useApp } from '@tldraw/react'
  3. import { MOD_KEY} from '@tldraw/core'
  4. import { observer } from 'mobx-react-lite'
  5. export const ZoomMenu = observer(function ZoomMenu(): JSX.Element {
  6. const app = useApp()
  7. const preventEvent = (e: Event) => {
  8. e.preventDefault()
  9. }
  10. return (
  11. <DropdownMenuPrimitive.Root>
  12. <DropdownMenuPrimitive.Trigger>
  13. {(app.viewport.camera.zoom * 100).toFixed(0) + '%'}
  14. </DropdownMenuPrimitive.Trigger>
  15. <DropdownMenuPrimitive.Content
  16. className="tl-zoom-menu-dropdown-menu-button"
  17. id="zoomPopup"
  18. sideOffset={12}
  19. >
  20. <DropdownMenuPrimitive.Arrow style={{ fill: 'white' }}></DropdownMenuPrimitive.Arrow>
  21. <DropdownMenuPrimitive.Item
  22. className="menu-link tl-zoom-menu-dropdown-item"
  23. onSelect={preventEvent}
  24. onClick={app.api.zoomToFit}
  25. >
  26. Zoom to Fit <div className="tl-zoom-menu-right-slot"></div>
  27. </DropdownMenuPrimitive.Item>
  28. <DropdownMenuPrimitive.Item
  29. className="menu-link tl-zoom-menu-dropdown-item"
  30. onSelect={preventEvent}
  31. onClick={app.api.zoomToSelection}
  32. >
  33. Zoom to Selection <div className="tl-zoom-menu-right-slot"><span className="keyboard-shortcut"><code>{MOD_KEY}</code> <code>-</code></span></div>
  34. </DropdownMenuPrimitive.Item>
  35. <DropdownMenuPrimitive.Item
  36. className="menu-link tl-zoom-menu-dropdown-item"
  37. onSelect={preventEvent}
  38. onClick={app.api.zoomIn}
  39. >
  40. Zoom In <div className="tl-zoom-menu-right-slot"><span className="keyboard-shortcut"><code>{MOD_KEY}</code> <code>+</code></span></div>
  41. </DropdownMenuPrimitive.Item>
  42. <DropdownMenuPrimitive.Item
  43. className="menu-link tl-zoom-menu-dropdown-item"
  44. onSelect={preventEvent}
  45. onClick={app.api.zoomOut}
  46. >
  47. Zoom Out <div className="tl-zoom-menu-right-slot"><span className="keyboard-shortcut"><code>{MOD_KEY}</code> <code>-</code></span></div>
  48. </DropdownMenuPrimitive.Item>
  49. <DropdownMenuPrimitive.Item
  50. className="menu-link tl-zoom-menu-dropdown-item"
  51. onSelect={preventEvent}
  52. onClick={app.api.resetZoom}
  53. >
  54. Reset Zoom <div className="tl-zoom-menu-right-slot"><span className="keyboard-shortcut"><code>⇧</code> <code>0</code></span></div>
  55. </DropdownMenuPrimitive.Item>
  56. </DropdownMenuPrimitive.Content>
  57. </DropdownMenuPrimitive.Root>
  58. )
  59. })
  60. export default ZoomMenu