選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

toolbar.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import state, { useSelector } from 'state'
  2. import styled from 'styles'
  3. import { Lock, Menu, 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 onClick={() => state.send('UNDO')}>Undo</Button>
  87. <Button onClick={() => state.send('REDO')}>Redo</Button>
  88. </Section>
  89. </ToolbarContainer>
  90. )
  91. }
  92. const ToolbarContainer = styled('div', {
  93. gridArea: 'toolbar',
  94. userSelect: 'none',
  95. borderBottom: '1px solid black',
  96. display: 'flex',
  97. alignItems: 'center',
  98. justifyContent: 'space-between',
  99. backgroundColor: '$panel',
  100. gap: 8,
  101. fontSize: '$1',
  102. zIndex: 200,
  103. })
  104. const Section = styled('div', {
  105. whiteSpace: 'nowrap',
  106. overflowY: 'hidden',
  107. overflowX: 'auto',
  108. display: 'flex',
  109. scrollbarWidth: 'none',
  110. '&::-webkit-scrollbar': {
  111. '-webkit-appearance': 'none',
  112. width: 0,
  113. height: 0,
  114. },
  115. })
  116. const Button = styled('button', {
  117. display: 'flex',
  118. alignItems: 'center',
  119. cursor: 'pointer',
  120. font: '$ui',
  121. fontSize: '$ui',
  122. height: '40px',
  123. outline: 'none',
  124. borderRadius: 0,
  125. border: 'none',
  126. padding: '0 12px',
  127. background: 'none',
  128. '&:hover': {
  129. backgroundColor: '$hint',
  130. },
  131. '& svg': {
  132. height: 16,
  133. width: 16,
  134. },
  135. variants: {
  136. isSelected: {
  137. true: {
  138. color: '$selected',
  139. },
  140. false: {},
  141. },
  142. },
  143. })