Tools.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import React from "react";
  2. import {
  3. AiOutlineFullscreen,
  4. AiOutlineMinus,
  5. AiOutlinePlus,
  6. } from "react-icons/ai";
  7. import { FiDownload } from "react-icons/fi";
  8. import { HiOutlineSun, HiOutlineMoon } from "react-icons/hi";
  9. import { MdCenterFocusWeak } from "react-icons/md";
  10. import { SearchInput } from "src/components/SearchInput";
  11. import styled from "styled-components";
  12. import useConfig from "src/hooks/store/useConfig";
  13. import shallow from "zustand/shallow";
  14. import { DownloadModal } from "../Modals/DownloadModal";
  15. import useStored from "src/hooks/store/useStored";
  16. import { TbSettings } from "react-icons/tb";
  17. import { Settings } from "./Settings";
  18. export const StyledTools = styled.div`
  19. display: flex;
  20. align-items: center;
  21. gap: 4px;
  22. flex-direction: row-reverse;
  23. height: 28px;
  24. padding: 4px 16px;
  25. background: ${({ theme }) => theme.BACKGROUND_PRIMARY};
  26. color: ${({ theme }) => theme.SILVER};
  27. box-shadow: 0 1px 0px ${({ theme }) => theme.BACKGROUND_TERTIARY};
  28. @media only screen and (max-width: 768px) {
  29. display: none;
  30. }
  31. `;
  32. const StyledToolElement = styled.button`
  33. display: grid;
  34. place-content: center;
  35. font-size: 20px;
  36. background: none;
  37. color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
  38. &:hover {
  39. color: ${({ theme }) => theme.INTERACTIVE_HOVER};
  40. opacity: 1;
  41. box-shadow: none;
  42. }
  43. `;
  44. export const Tools: React.FC = () => {
  45. const [settingsVisible, setSettingsVisible] = React.useState(false);
  46. const [isDownloadVisible, setDownloadVisible] = React.useState(false);
  47. const lightmode = useStored((state) => state.lightmode);
  48. const setLightTheme = useStored((state) => state.setLightTheme);
  49. const hideEditor = useConfig((state) => state.hideEditor);
  50. const setConfig = useConfig((state) => state.setConfig);
  51. const zoomIn = useConfig((state) => state.zoomIn);
  52. const zoomOut = useConfig((state) => state.zoomOut);
  53. const centerView = useConfig((state) => state.centerView);
  54. const toggleEditor = () => setConfig("hideEditor", !hideEditor);
  55. const toggleTheme = () => setLightTheme(!lightmode);
  56. return (
  57. <StyledTools>
  58. <StyledToolElement aria-label="fullscreen" onClick={toggleEditor}>
  59. <AiOutlineFullscreen />
  60. </StyledToolElement>
  61. <StyledToolElement
  62. aria-label="settings"
  63. onClick={() => setSettingsVisible(true)}
  64. >
  65. <TbSettings />
  66. </StyledToolElement>
  67. <StyledToolElement aria-label="switch theme" onClick={toggleTheme}>
  68. {lightmode ? <HiOutlineMoon /> : <HiOutlineSun />}
  69. </StyledToolElement>
  70. <SearchInput />
  71. <StyledToolElement
  72. aria-label="save"
  73. onClick={() => setDownloadVisible(true)}
  74. >
  75. <FiDownload />
  76. </StyledToolElement>
  77. <StyledToolElement aria-label="center canvas" onClick={centerView}>
  78. <MdCenterFocusWeak />
  79. </StyledToolElement>
  80. <StyledToolElement aria-label="zoom out" onClick={zoomOut}>
  81. <AiOutlineMinus />
  82. </StyledToolElement>
  83. <StyledToolElement aria-label="zoom in" onClick={zoomIn}>
  84. <AiOutlinePlus />
  85. </StyledToolElement>
  86. <DownloadModal
  87. visible={isDownloadVisible}
  88. setVisible={setDownloadVisible}
  89. />
  90. <Settings visible={settingsVisible} setVisible={setSettingsVisible} />
  91. </StyledTools>
  92. );
  93. };