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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. creatingDot: "dot",
  9. creatingCircle: "circle",
  10. creatingEllipse: "ellipse",
  11. creatingRay: "ray",
  12. creatingLine: "line",
  13. creatingPolyline: "polyline",
  14. creatingRectangle: "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. </Section>
  72. </ToolbarContainer>
  73. )
  74. }
  75. const ToolbarContainer = styled("div", {
  76. position: "absolute",
  77. top: 0,
  78. left: 0,
  79. width: "100%",
  80. height: 40,
  81. userSelect: "none",
  82. borderBottom: "1px solid black",
  83. gridArea: "status",
  84. display: "grid",
  85. gridTemplateColumns: "auto 1fr auto",
  86. alignItems: "center",
  87. backgroundColor: "white",
  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. borderRadius: 0,
  105. border: "none",
  106. padding: "0 12px",
  107. background: "none",
  108. "&:hover": {
  109. backgroundColor: "$hint",
  110. },
  111. "& svg": {
  112. height: 16,
  113. width: 16,
  114. },
  115. variants: {
  116. isSelected: {
  117. true: {
  118. color: "$selected",
  119. },
  120. false: {},
  121. },
  122. },
  123. })