Tools.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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<{ isWidget: boolean }>`
  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: ${({ isWidget }) => !isWidget && "none"};
  23. }
  24. @media only screen and (max-width: 480px) {
  25. display: none;
  26. }
  27. `;
  28. const StyledToolElement = styled.button<{ hide?: boolean }>`
  29. display: ${({ hide }) => (hide ? "none" : "grid")};
  30. place-content: center;
  31. font-size: 20px;
  32. background: none;
  33. color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
  34. padding: 6px;
  35. border-radius: 3px;
  36. &:hover {
  37. background-image: linear-gradient(rgba(0, 0, 0, 0.1) 0 0);
  38. }
  39. &:hover {
  40. color: ${({ theme }) => theme.INTERACTIVE_HOVER};
  41. opacity: 1;
  42. box-shadow: none;
  43. }
  44. `;
  45. export const Tools: React.FC<{ isWidget?: boolean }> = ({ isWidget = false }) => {
  46. const setVisible = useModal(state => state.setVisible);
  47. const fullscreen = useGraph(state => state.fullscreen);
  48. const toggleFullscreen = useGraph(state => state.toggleFullscreen);
  49. const zoomIn = useGraph(state => state.zoomIn);
  50. const zoomOut = useGraph(state => state.zoomOut);
  51. const centerView = useGraph(state => state.centerView);
  52. const toggleEditor = () => toggleFullscreen(!fullscreen);
  53. return (
  54. <>
  55. <StyledTools isWidget={isWidget}>
  56. <StyledToolElement aria-label="fullscreen" hide={isWidget} onClick={toggleEditor}>
  57. <AiOutlineFullscreen />
  58. </StyledToolElement>
  59. <SearchInput />
  60. <StyledToolElement aria-label="save" onClick={() => setVisible("download")(true)}>
  61. <FiDownload />
  62. </StyledToolElement>
  63. <StyledToolElement aria-label="center canvas" onClick={centerView}>
  64. <MdCenterFocusWeak />
  65. </StyledToolElement>
  66. <StyledToolElement aria-label="zoom out" onClick={zoomOut}>
  67. <AiOutlineMinus />
  68. </StyledToolElement>
  69. <StyledToolElement aria-label="zoom in" onClick={zoomIn}>
  70. <AiOutlinePlus />
  71. </StyledToolElement>
  72. </StyledTools>
  73. </>
  74. );
  75. };