You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zoom.tsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { ZoomInIcon, ZoomOutIcon } from '@radix-ui/react-icons'
  2. import { IconButton } from 'components/shared'
  3. import state, { useSelector } from 'state'
  4. import styled from 'styles'
  5. const zoomIn = () => state.send('ZOOMED_IN')
  6. const zoomOut = () => state.send('ZOOMED_OUT')
  7. const zoomToFit = () => state.send('ZOOMED_TO_FIT')
  8. const zoomToActual = () => state.send('ZOOMED_TO_ACTUAL')
  9. export default function Zoom() {
  10. return (
  11. <Container size={{ '@sm': 'small' }}>
  12. <IconButton onClick={zoomOut}>
  13. <ZoomOutIcon />
  14. </IconButton>
  15. <IconButton onClick={zoomIn}>
  16. <ZoomInIcon />
  17. </IconButton>
  18. <ZoomCounter />
  19. </Container>
  20. )
  21. }
  22. function ZoomCounter() {
  23. const camera = useSelector((s) => s.data.camera)
  24. return (
  25. <ZoomButton onClick={zoomToActual} onDoubleClick={zoomToFit}>
  26. {Math.round(camera.zoom * 100)}%
  27. </ZoomButton>
  28. )
  29. }
  30. const ZoomButton = styled(IconButton, {
  31. fontSize: '$0',
  32. padding: 8,
  33. })
  34. const Container = styled('div', {
  35. position: 'absolute',
  36. left: 12,
  37. bottom: 64,
  38. backgroundColor: '$panel',
  39. borderRadius: '4px',
  40. overflow: 'hidden',
  41. alignSelf: 'flex-end',
  42. pointerEvents: 'all',
  43. userSelect: 'none',
  44. zIndex: 200,
  45. border: '1px solid $panel',
  46. boxShadow: '0px 2px 4px rgba(0,0,0,.12)',
  47. display: 'flex',
  48. padding: 4,
  49. flexDirection: 'column',
  50. alignItems: 'center',
  51. '& svg': {
  52. strokeWidth: 0,
  53. },
  54. variants: {
  55. size: {
  56. small: {
  57. bottom: 12,
  58. flexDirection: 'row',
  59. alignItems: 'center',
  60. [`& ${ZoomButton}`]: {
  61. width: 44,
  62. },
  63. },
  64. },
  65. },
  66. })