Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

tools-panel.tsx 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. import {
  2. CircleIcon,
  3. CursorArrowIcon,
  4. DividerHorizontalIcon,
  5. DotIcon,
  6. LineHeightIcon,
  7. LockClosedIcon,
  8. LockOpen1Icon,
  9. Pencil1Icon,
  10. Pencil2Icon,
  11. SewingPinIcon,
  12. SquareIcon,
  13. } from '@radix-ui/react-icons'
  14. import { IconButton } from 'components/shared'
  15. import React from 'react'
  16. import state, { useSelector } from 'state'
  17. import styled from 'styles'
  18. import { ShapeType } from 'types'
  19. import Zoom from './zoom'
  20. const selectSelectTool = () => state.send('SELECTED_SELECT_TOOL')
  21. const selectDrawTool = () => state.send('SELECTED_DRAW_TOOL')
  22. const selectDotTool = () => state.send('SELECTED_DOT_TOOL')
  23. const selectCircleTool = () => state.send('SELECTED_CIRCLE_TOOL')
  24. const selectEllipseTool = () => state.send('SELECTED_ELLIPSE_TOOL')
  25. const selectRayTool = () => state.send('SELECTED_RAY_TOOL')
  26. const selectLineTool = () => state.send('SELECTED_LINE_TOOL')
  27. const selectPolylineTool = () => state.send('SELECTED_POLYLINE_TOOL')
  28. const selectRectangleTool = () => state.send('SELECTED_RECTANGLE_TOOL')
  29. const selectToolLock = () => state.send('TOGGLED_TOOL_LOCK')
  30. export default function ToolsPanel() {
  31. const activeTool = useSelector((state) =>
  32. state.whenIn({
  33. selecting: 'select',
  34. dot: ShapeType.Dot,
  35. circle: ShapeType.Circle,
  36. ellipse: ShapeType.Ellipse,
  37. ray: ShapeType.Ray,
  38. line: ShapeType.Line,
  39. polyline: ShapeType.Polyline,
  40. rectangle: ShapeType.Rectangle,
  41. draw: ShapeType.Draw,
  42. })
  43. )
  44. const isToolLocked = useSelector((s) => s.data.settings.isToolLocked)
  45. const isPenLocked = useSelector((s) => s.data.settings.isPenLocked)
  46. return (
  47. <OuterContainer>
  48. <Zoom />
  49. <Container>
  50. <IconButton
  51. name="select"
  52. size="large"
  53. onClick={selectSelectTool}
  54. isActive={activeTool === 'select'}
  55. >
  56. <CursorArrowIcon />
  57. </IconButton>
  58. </Container>
  59. <Container>
  60. <IconButton
  61. name={ShapeType.Draw}
  62. size="large"
  63. onClick={selectDrawTool}
  64. isActive={activeTool === ShapeType.Draw}
  65. >
  66. <Pencil1Icon />
  67. </IconButton>
  68. <IconButton
  69. name={ShapeType.Rectangle}
  70. size="large"
  71. onClick={selectRectangleTool}
  72. isActive={activeTool === ShapeType.Rectangle}
  73. >
  74. <SquareIcon />
  75. </IconButton>
  76. <IconButton
  77. name={ShapeType.Circle}
  78. size="large"
  79. onClick={selectCircleTool}
  80. isActive={activeTool === ShapeType.Circle}
  81. >
  82. <CircleIcon />
  83. </IconButton>
  84. <IconButton
  85. name={ShapeType.Ellipse}
  86. size="large"
  87. onClick={selectEllipseTool}
  88. isActive={activeTool === ShapeType.Ellipse}
  89. >
  90. <CircleIcon transform="rotate(-45) scale(1, .8)" />
  91. </IconButton>
  92. <IconButton
  93. name={ShapeType.Line}
  94. size="large"
  95. onClick={selectLineTool}
  96. isActive={activeTool === ShapeType.Line}
  97. >
  98. <DividerHorizontalIcon transform="rotate(-45)" />
  99. </IconButton>
  100. <IconButton
  101. name={ShapeType.Ray}
  102. size="large"
  103. onClick={selectRayTool}
  104. isActive={activeTool === ShapeType.Ray}
  105. >
  106. <SewingPinIcon transform="rotate(-135)" />
  107. </IconButton>
  108. <IconButton
  109. name={ShapeType.Dot}
  110. size="large"
  111. onClick={selectDotTool}
  112. isActive={activeTool === ShapeType.Dot}
  113. >
  114. <DotIcon />
  115. </IconButton>
  116. </Container>
  117. <Container>
  118. <IconButton size="medium" onClick={selectToolLock}>
  119. {isToolLocked ? <LockClosedIcon /> : <LockOpen1Icon />}
  120. </IconButton>
  121. {isPenLocked && (
  122. <IconButton size="medium" onClick={selectToolLock}>
  123. <Pencil2Icon />
  124. </IconButton>
  125. )}
  126. </Container>
  127. </OuterContainer>
  128. )
  129. }
  130. const Spacer = styled('div', { flexGrow: 2 })
  131. const OuterContainer = styled('div', {
  132. position: 'relative',
  133. gridArea: 'tools',
  134. padding: '0 8px 12px 8px',
  135. height: '100%',
  136. width: '100%',
  137. display: 'flex',
  138. alignItems: 'center',
  139. justifyContent: 'center',
  140. gap: 16,
  141. })
  142. const Container = styled('div', {
  143. position: 'relative',
  144. backgroundColor: '$panel',
  145. borderRadius: '4px',
  146. overflow: 'hidden',
  147. border: '1px solid $border',
  148. pointerEvents: 'all',
  149. userSelect: 'none',
  150. zIndex: 200,
  151. boxShadow: '0px 2px 25px rgba(0,0,0,.16)',
  152. height: '100%',
  153. display: 'flex',
  154. padding: 4,
  155. '& svg': {
  156. strokeWidth: 0,
  157. },
  158. })