您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

toolbar.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. </ToolbarContainer>
  74. )
  75. }
  76. const ToolbarContainer = styled("div", {
  77. gridArea: "toolbar",
  78. userSelect: "none",
  79. borderBottom: "1px solid black",
  80. display: "grid",
  81. gridTemplateColumns: "auto 1fr auto",
  82. alignItems: "center",
  83. backgroundColor: "white",
  84. gap: 8,
  85. fontSize: "$1",
  86. zIndex: 200,
  87. })
  88. const Section = styled("div", {
  89. whiteSpace: "nowrap",
  90. overflow: "hidden",
  91. display: "flex",
  92. })
  93. const Button = styled("button", {
  94. display: "flex",
  95. alignItems: "center",
  96. cursor: "pointer",
  97. font: "$ui",
  98. fontSize: "$ui",
  99. height: "40px",
  100. borderRadius: 0,
  101. border: "none",
  102. padding: "0 12px",
  103. background: "none",
  104. "&:hover": {
  105. backgroundColor: "$hint",
  106. },
  107. "& svg": {
  108. height: 16,
  109. width: 16,
  110. },
  111. variants: {
  112. isSelected: {
  113. true: {
  114. color: "$selected",
  115. },
  116. false: {},
  117. },
  118. },
  119. })