Panes.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from "react";
  2. import dynamic from "next/dynamic";
  3. import styled from "styled-components";
  4. import { Allotment } from "allotment";
  5. import "allotment/dist/style.css";
  6. import { JsonEditor } from "src/containers/Editor/JsonEditor";
  7. import useGraph from "src/store/useGraph";
  8. export const StyledEditor = styled(Allotment)`
  9. position: relative !important;
  10. display: flex;
  11. background: ${({ theme }) => theme.BACKGROUND_SECONDARY};
  12. `;
  13. const LiveEditor = dynamic(() => import("src/containers/Editor/LiveEditor"), {
  14. ssr: false,
  15. });
  16. const Panes: React.FC = () => {
  17. const fullscreen = useGraph(state => state.fullscreen);
  18. const toggleFullscreen = useGraph(state => state.toggleFullscreen);
  19. const isMobile = React.useMemo(() => window.innerWidth <= 768, []);
  20. React.useEffect(() => {
  21. if (isMobile) toggleFullscreen(true);
  22. }, [isMobile, toggleFullscreen]);
  23. return (
  24. <StyledEditor proportionalLayout={false} vertical={isMobile}>
  25. <Allotment.Pane
  26. preferredSize={isMobile ? "100%" : 400}
  27. minSize={fullscreen ? 0 : 300}
  28. maxSize={isMobile ? Infinity : 800}
  29. visible={!fullscreen}
  30. >
  31. <JsonEditor />
  32. </Allotment.Pane>
  33. <Allotment.Pane minSize={0} maxSize={isMobile && !fullscreen ? 0 : Infinity}>
  34. <LiveEditor />
  35. </Allotment.Pane>
  36. </StyledEditor>
  37. );
  38. };
  39. export default Panes;