Tools.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. export const StyledTools = styled.div`
  17. display: flex;
  18. align-items: center;
  19. gap: 4px;
  20. flex-direction: row-reverse;
  21. height: 28px;
  22. padding: 4px 16px;
  23. background: ${({ theme }) => theme.BACKGROUND_PRIMARY};
  24. color: ${({ theme }) => theme.SILVER};
  25. box-shadow: 0 1px 0px ${({ theme }) => theme.BACKGROUND_TERTIARY};
  26. `;
  27. const StyledToolElement = styled.button`
  28. display: grid;
  29. place-content: center;
  30. font-size: 20px;
  31. background: none;
  32. color: ${({ theme }) => theme.INTERACTIVE_NORMAL};
  33. &:hover {
  34. color: ${({ theme }) => theme.INTERACTIVE_HOVER};
  35. opacity: 1;
  36. box-shadow: none;
  37. }
  38. `;
  39. export const Tools: React.FC = () => {
  40. const [isDownloadVisible, setDownloadVisible] = React.useState(false);
  41. const lightmode = useStored((state) => state.lightmode);
  42. const setLightTheme = useStored((state) => state.setLightTheme);
  43. const [performanceMode, hideEditor] = useConfig(
  44. (state) => [state.performanceMode, state.hideEditor],
  45. shallow
  46. );
  47. const setConfig = useConfig((state) => state.setConfig);
  48. const zoomIn = useConfig((state) => state.zoomIn);
  49. const zoomOut = useConfig((state) => state.zoomOut);
  50. const centerView = useConfig((state) => state.centerView);
  51. const toggleEditor = () => setConfig("hideEditor", !hideEditor);
  52. const toggleTheme = () => setLightTheme(!lightmode);
  53. return (
  54. <StyledTools>
  55. <StyledToolElement aria-label="fullscreen" onClick={toggleEditor}>
  56. <AiOutlineFullscreen />
  57. </StyledToolElement>
  58. <StyledToolElement aria-label="switch theme" onClick={toggleTheme}>
  59. {lightmode ? <HiOutlineMoon /> : <HiOutlineSun />}
  60. </StyledToolElement>
  61. {!performanceMode && <SearchInput />}
  62. {!performanceMode && (
  63. <StyledToolElement
  64. aria-label="save"
  65. onClick={() => setDownloadVisible(true)}
  66. >
  67. <FiDownload />
  68. </StyledToolElement>
  69. )}
  70. <StyledToolElement aria-label="center canvas" onClick={centerView}>
  71. <MdCenterFocusWeak />
  72. </StyledToolElement>
  73. <StyledToolElement aria-label="zoom out" onClick={zoomOut}>
  74. <AiOutlineMinus />
  75. </StyledToolElement>
  76. <StyledToolElement aria-label="zoom in" onClick={zoomIn}>
  77. <AiOutlinePlus />
  78. </StyledToolElement>
  79. <DownloadModal
  80. visible={isDownloadVisible}
  81. setVisible={setDownloadVisible}
  82. />
  83. </StyledTools>
  84. );
  85. };