Tools.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React from "react";
  2. import { AiOutlineFullscreen, AiOutlineMinus, AiOutlinePlus } from "react-icons/ai";
  3. import { FiDownload } from "react-icons/fi";
  4. import { MdCenterFocusWeak } from "react-icons/md";
  5. import { SearchInput } from "src/components/SearchInput";
  6. import useGraph from "src/store/useGraph";
  7. import useModal from "src/store/useModal";
  8. import styled from "styled-components";
  9. export const StyledTools = styled.div`
  10. position: relative;
  11. display: flex;
  12. align-items: center;
  13. gap: 4px;
  14. flex-direction: row-reverse;
  15. height: 28px;
  16. padding: 4px 16px;
  17. background: ${({ theme }) => theme.BACKGROUND_PRIMARY};
  18. color: ${({ theme }) => theme.SILVER};
  19. box-shadow: 0 1px 0px ${({ theme }) => theme.BACKGROUND_TERTIARY};
  20. z-index: 1;
  21. @media only screen and (max-width: 768px) {
  22. display: none;
  23. }
  24. `;
  25. const StyledToolElement = styled.button`
  26. display: grid;
  27. place-content: center;
  28. font-size: 20px;
  29. background: none;
  30. color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
  31. padding: 6px;
  32. border-radius: 3px;
  33. &:hover {
  34. background-image: linear-gradient(rgba(0, 0, 0, 0.1) 0 0);
  35. }
  36. &:hover {
  37. color: ${({ theme }) => theme.INTERACTIVE_HOVER};
  38. opacity: 1;
  39. box-shadow: none;
  40. }
  41. `;
  42. export const Tools: React.FC = () => {
  43. const setVisible = useModal(state => state.setVisible);
  44. const fullscreen = useGraph(state => state.fullscreen);
  45. const toggleFullscreen = useGraph(state => state.toggleFullscreen);
  46. const zoomIn = useGraph(state => state.zoomIn);
  47. const zoomOut = useGraph(state => state.zoomOut);
  48. const centerView = useGraph(state => state.centerView);
  49. const toggleEditor = () => toggleFullscreen(!fullscreen);
  50. return (
  51. <>
  52. <StyledTools>
  53. <StyledToolElement aria-label="fullscreen" onClick={toggleEditor}>
  54. <AiOutlineFullscreen />
  55. </StyledToolElement>
  56. <SearchInput />
  57. <StyledToolElement aria-label="save" onClick={() => setVisible("download")(true)}>
  58. <FiDownload />
  59. </StyledToolElement>
  60. <StyledToolElement aria-label="center canvas" onClick={centerView}>
  61. <MdCenterFocusWeak />
  62. </StyledToolElement>
  63. <StyledToolElement aria-label="zoom out" onClick={zoomOut}>
  64. <AiOutlineMinus />
  65. </StyledToolElement>
  66. <StyledToolElement aria-label="zoom in" onClick={zoomIn}>
  67. <AiOutlinePlus />
  68. </StyledToolElement>
  69. </StyledTools>
  70. </>
  71. );
  72. };