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.

toolbar.tsx 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import state, { useSelector } from 'state'
  2. import styled from 'styles'
  3. import { Lock, Menu, RotateCcw, RotateCw, Unlock } from 'react-feather'
  4. import { IconButton } from './shared'
  5. export default function Toolbar() {
  6. const activeTool = useSelector((state) =>
  7. state.whenIn({
  8. selecting: 'select',
  9. dot: 'dot',
  10. circle: 'circle',
  11. ellipse: 'ellipse',
  12. ray: 'ray',
  13. line: 'line',
  14. polyline: 'polyline',
  15. rectangle: 'rectangle',
  16. draw: 'draw',
  17. })
  18. )
  19. const isToolLocked = useSelector((s) => s.data.settings.isToolLocked)
  20. return (
  21. <ToolbarContainer>
  22. <Section>
  23. <Button>
  24. <Menu />
  25. </Button>
  26. <Button onClick={() => state.send('TOGGLED_TOOL_LOCK')}>
  27. {isToolLocked ? <Lock /> : <Unlock />}
  28. </Button>
  29. <Button
  30. isSelected={activeTool === 'select'}
  31. onClick={() => state.send('SELECTED_SELECT_TOOL')}
  32. >
  33. Select
  34. </Button>
  35. <Button
  36. isSelected={activeTool === 'draw'}
  37. onClick={() => state.send('SELECTED_DRAW_TOOL')}
  38. >
  39. Draw
  40. </Button>
  41. <Button
  42. isSelected={activeTool === 'dot'}
  43. onClick={() => state.send('SELECTED_DOT_TOOL')}
  44. >
  45. Dot
  46. </Button>
  47. <Button
  48. isSelected={activeTool === 'circle'}
  49. onClick={() => state.send('SELECTED_CIRCLE_TOOL')}
  50. >
  51. Circle
  52. </Button>
  53. <Button
  54. isSelected={activeTool === 'ellipse'}
  55. onClick={() => state.send('SELECTED_ELLIPSE_TOOL')}
  56. >
  57. Ellipse
  58. </Button>
  59. <Button
  60. isSelected={activeTool === 'ray'}
  61. onClick={() => state.send('SELECTED_RAY_TOOL')}
  62. >
  63. Ray
  64. </Button>
  65. <Button
  66. isSelected={activeTool === 'line'}
  67. onClick={() => state.send('SELECTED_LINE_TOOL')}
  68. >
  69. Line
  70. </Button>
  71. <Button
  72. isSelected={activeTool === 'polyline'}
  73. onClick={() => state.send('SELECTED_POLYLINE_TOOL')}
  74. >
  75. Polyline
  76. </Button>
  77. <Button
  78. isSelected={activeTool === 'rectangle'}
  79. onClick={() => state.send('SELECTED_RECTANGLE_TOOL')}
  80. >
  81. Rectangle
  82. </Button>
  83. <Button onClick={() => state.send('RESET_CAMERA')}>Reset Camera</Button>
  84. </Section>
  85. <Section>
  86. <Button title="Undo" onClick={() => state.send('UNDO')}>
  87. <RotateCcw />
  88. </Button>
  89. <Button title="Redo" onClick={() => state.send('REDO')}>
  90. <RotateCw />
  91. </Button>
  92. </Section>
  93. </ToolbarContainer>
  94. )
  95. }
  96. const ToolbarContainer = styled('div', {
  97. gridArea: 'toolbar',
  98. userSelect: 'none',
  99. borderBottom: '1px solid black',
  100. display: 'flex',
  101. alignItems: 'center',
  102. justifyContent: 'space-between',
  103. backgroundColor: '$panel',
  104. gap: 8,
  105. fontSize: '$1',
  106. zIndex: 200,
  107. })
  108. const Section = styled('div', {
  109. whiteSpace: 'nowrap',
  110. overflowY: 'hidden',
  111. overflowX: 'auto',
  112. display: 'flex',
  113. scrollbarWidth: 'none',
  114. '&::-webkit-scrollbar': {
  115. '-webkit-appearance': 'none',
  116. width: 0,
  117. height: 0,
  118. },
  119. })
  120. const Button = styled('button', {
  121. display: 'flex',
  122. alignItems: 'center',
  123. cursor: 'pointer',
  124. font: '$ui',
  125. fontSize: '$ui',
  126. height: '40px',
  127. outline: 'none',
  128. borderRadius: 0,
  129. border: 'none',
  130. padding: '0 12px',
  131. background: 'none',
  132. '&:hover': {
  133. backgroundColor: '$hint',
  134. },
  135. '& svg': {
  136. height: 16,
  137. width: 16,
  138. },
  139. variants: {
  140. isSelected: {
  141. true: {
  142. color: '$selected',
  143. },
  144. false: {},
  145. },
  146. },
  147. })