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.

tools-panel.tsx 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {
  2. ArrowTopRightIcon,
  3. CircleIcon,
  4. CursorArrowIcon,
  5. DividerHorizontalIcon,
  6. DotIcon,
  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 UndoRedo from './undo-redo'
  20. import Zoom from './zoom'
  21. const selectArrowTool = () => state.send('SELECTED_ARROW_TOOL')
  22. const selectCircleTool = () => state.send('SELECTED_CIRCLE_TOOL')
  23. const selectDotTool = () => state.send('SELECTED_DOT_TOOL')
  24. const selectDrawTool = () => state.send('SELECTED_DRAW_TOOL')
  25. const selectEllipseTool = () => state.send('SELECTED_ELLIPSE_TOOL')
  26. const selectLineTool = () => state.send('SELECTED_LINE_TOOL')
  27. const selectPolylineTool = () => state.send('SELECTED_POLYLINE_TOOL')
  28. const selectRayTool = () => state.send('SELECTED_RAY_TOOL')
  29. const selectRectangleTool = () => state.send('SELECTED_RECTANGLE_TOOL')
  30. const selectSelectTool = () => state.send('SELECTED_SELECT_TOOL')
  31. const selectToolLock = () => state.send('TOGGLED_TOOL_LOCK')
  32. export default function ToolsPanel() {
  33. const activeTool = useSelector((state) =>
  34. state.whenIn({
  35. arrow: ShapeType.Arrow,
  36. circle: ShapeType.Circle,
  37. dot: ShapeType.Dot,
  38. draw: ShapeType.Draw,
  39. ellipse: ShapeType.Ellipse,
  40. line: ShapeType.Line,
  41. polyline: ShapeType.Polyline,
  42. ray: ShapeType.Ray,
  43. rectangle: ShapeType.Rectangle,
  44. selecting: 'select',
  45. })
  46. )
  47. const isToolLocked = useSelector((s) => s.data.settings.isToolLocked)
  48. const isPenLocked = useSelector((s) => s.data.settings.isPenLocked)
  49. return (
  50. <OuterContainer>
  51. <Zoom />
  52. <Flex size={{ '@sm': 'small' }}>
  53. <Container>
  54. <IconButton
  55. name="select"
  56. size={{ '@sm': 'small', '@md': 'large' }}
  57. onClick={selectSelectTool}
  58. isActive={activeTool === 'select'}
  59. >
  60. <CursorArrowIcon />
  61. </IconButton>
  62. </Container>
  63. <Container>
  64. <IconButton
  65. name={ShapeType.Draw}
  66. size={{ '@sm': 'small', '@md': 'large' }}
  67. onClick={selectDrawTool}
  68. isActive={activeTool === ShapeType.Draw}
  69. >
  70. <Pencil1Icon />
  71. </IconButton>
  72. <IconButton
  73. name={ShapeType.Rectangle}
  74. size={{ '@sm': 'small', '@md': 'large' }}
  75. onClick={selectRectangleTool}
  76. isActive={activeTool === ShapeType.Rectangle}
  77. >
  78. <SquareIcon />
  79. </IconButton>
  80. <IconButton
  81. name={ShapeType.Circle}
  82. size={{ '@sm': 'small', '@md': 'large' }}
  83. onClick={selectEllipseTool}
  84. isActive={activeTool === ShapeType.Ellipse}
  85. >
  86. <CircleIcon />
  87. </IconButton>
  88. <IconButton
  89. name={ShapeType.Arrow}
  90. size={{ '@sm': 'small', '@md': 'large' }}
  91. onClick={selectArrowTool}
  92. isActive={activeTool === ShapeType.Arrow}
  93. >
  94. <ArrowTopRightIcon />
  95. </IconButton>
  96. {/* <IconButton
  97. name={ShapeType.Circle}
  98. size={{ '@sm': 'small', '@md': 'large' }}
  99. onClick={selectCircleTool}
  100. isActive={activeTool === ShapeType.Circle}
  101. >
  102. <CircleIcon />
  103. </IconButton> */}
  104. {/* <IconButton
  105. name={ShapeType.Line}
  106. size={{ '@sm': 'small', '@md': 'large' }}
  107. onClick={selectLineTool}
  108. isActive={activeTool === ShapeType.Line}
  109. >
  110. <DividerHorizontalIcon transform="rotate(-45)" />
  111. </IconButton>
  112. <IconButton
  113. name={ShapeType.Ray}
  114. size={{ '@sm': 'small', '@md': 'large' }}
  115. onClick={selectRayTool}
  116. isActive={activeTool === ShapeType.Ray}
  117. >
  118. <SewingPinIcon transform="rotate(-135)" />
  119. </IconButton>
  120. <IconButton
  121. name={ShapeType.Dot}
  122. size={{ '@sm': 'small', '@md': 'large' }}
  123. onClick={selectDotTool}
  124. isActive={activeTool === ShapeType.Dot}
  125. >
  126. <DotIcon />
  127. </IconButton> */}
  128. </Container>
  129. <Container>
  130. <IconButton
  131. size={{ '@sm': 'small', '@md': 'large' }}
  132. onClick={selectToolLock}
  133. >
  134. {isToolLocked ? <LockClosedIcon /> : <LockOpen1Icon />}
  135. </IconButton>
  136. {isPenLocked && (
  137. <IconButton
  138. size={{ '@sm': 'small', '@md': 'large' }}
  139. onClick={selectToolLock}
  140. >
  141. <Pencil2Icon />
  142. </IconButton>
  143. )}
  144. </Container>
  145. </Flex>
  146. <UndoRedo />
  147. </OuterContainer>
  148. )
  149. }
  150. const OuterContainer = styled('div', {
  151. position: 'fixed',
  152. bottom: 40,
  153. left: 0,
  154. right: 0,
  155. padding: '0 8px 12px 8px',
  156. width: '100%',
  157. display: 'flex',
  158. alignItems: 'center',
  159. justifyContent: 'center',
  160. flexWrap: 'wrap',
  161. gap: 16,
  162. zIndex: 200,
  163. })
  164. const Flex = styled('div', {
  165. display: 'flex',
  166. justifyContent: 'space-between',
  167. width: '100%',
  168. padding: '0 4px',
  169. variants: {
  170. size: {
  171. small: {
  172. width: 'auto',
  173. padding: '0',
  174. '& > *:nth-child(n+2)': {
  175. marginLeft: 16,
  176. },
  177. },
  178. },
  179. },
  180. })
  181. const Container = styled('div', {
  182. position: 'relative',
  183. backgroundColor: '$panel',
  184. borderRadius: '4px',
  185. overflow: 'hidden',
  186. border: '1px solid $panel',
  187. pointerEvents: 'all',
  188. userSelect: 'none',
  189. height: '100%',
  190. display: 'flex',
  191. padding: 4,
  192. boxShadow: '0px 2px 4px rgba(0,0,0,.12)',
  193. '& svg': {
  194. strokeWidth: 0,
  195. },
  196. })