Tools.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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: 320px) {
  22. display: none;
  23. }
  24. `;
  25. const StyledToolElement = styled.button<{ hide?: boolean }>`
  26. display: ${({ hide }) => (hide ? "none" : "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<{ isWidget?: boolean }> = ({ isWidget = false }) => {
  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. <StyledTools>
  52. <StyledToolElement aria-label="fullscreen" hide={isWidget} onClick={toggleEditor}>
  53. <AiOutlineFullscreen />
  54. </StyledToolElement>
  55. <SearchInput />
  56. <StyledToolElement aria-label="save" onClick={() => setVisible("download")(true)}>
  57. <FiDownload />
  58. </StyledToolElement>
  59. <StyledToolElement aria-label="center canvas" onClick={centerView}>
  60. <MdCenterFocusWeak />
  61. </StyledToolElement>
  62. <StyledToolElement aria-label="zoom out" onClick={zoomOut}>
  63. <AiOutlineMinus />
  64. </StyledToolElement>
  65. <StyledToolElement aria-label="zoom in" onClick={zoomIn}>
  66. <AiOutlinePlus />
  67. </StyledToolElement>
  68. </StyledTools>
  69. );
  70. };