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 2.9KB

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