diff --git a/playground/src/Editor/index.tsx b/playground/src/Editor/index.tsx index 27356f5..ad7d755 100644 --- a/playground/src/Editor/index.tsx +++ b/playground/src/Editor/index.tsx @@ -1,6 +1,5 @@ import React, { FC, useMemo } from "react"; import styled from "styled-components"; - import { IEditorTabs, ISnippet } from "../types"; import EditorSetup from "./EditorSetup"; import { ITabConfig } from "../types"; @@ -17,12 +16,13 @@ const TabContainer = styled(StyledTabs)` `; interface IProps { + width: number; code: ISnippet; defaultTab: IEditorTabs; onChange: (changed: string, type: IEditorTabs) => void; } -const Editor: FC = ({ code, defaultTab, onChange }) => { +const Editor: FC = ({ code, defaultTab, onChange, width }) => { const tabs: Readonly[]> = useMemo( () => [ { name: "HTML", value: "markup" }, @@ -34,6 +34,7 @@ const Editor: FC = ({ code, defaultTab, onChange }) => { return ( tab.value === defaultTab)} + style={{ width: width }} > {tabs.map(tab => ( diff --git a/playground/src/Playground.tsx b/playground/src/Playground.tsx index a193dfc..79f5126 100644 --- a/playground/src/Playground.tsx +++ b/playground/src/Playground.tsx @@ -1,4 +1,4 @@ -import React, { FC, useState } from "react"; +import React, { FC, useState, useCallback, useEffect, useRef } from "react"; import styled, { ThemeProvider, DefaultTheme } from "styled-components"; import { useId } from "@reach/auto-id"; @@ -16,6 +16,11 @@ const Container = styled.div` ${media.phone` flex-direction: column; `} + + .divider { + border: 1px solid transparent; + cursor: col-resize; + } `; interface IProps { @@ -38,8 +43,10 @@ const Playground: FC = ({ theme = ourTheme, }) => { const [snippet, setSnippet] = useState(initialSnippet); - + const [width, setWidth] = useState(0); + const [containerWidth, setContainerWidth] = useState(0); const id = useId(userId); + const ref = useRef(null); const onSnippetChange = (changed: string, type: IEditorTabs) => { setSnippet(snippet => ({ @@ -48,22 +55,54 @@ const Playground: FC = ({ })); }; + useEffect(() => { + if (ref.current) { + setContainerWidth(ref.current.clientWidth); + setWidth(ref.current.clientWidth / 2); + } + }, []); + + const resize = useCallback( + (e: any) => { + const movedInPx = e.clientX - 10; + setWidth(movedInPx); + }, + [setWidth] + ); + + const handleAddListener = useCallback(() => { + document.addEventListener("mousemove", resize, false); + }, []); + + const handleRemoveListener = useCallback(() => { + document.removeEventListener("mousemove", resize, false); + }, []); + return ( - + {id && ( - + <> +
+ + )}
diff --git a/playground/src/Result/index.tsx b/playground/src/Result/index.tsx index ef1a29d..60231c8 100644 --- a/playground/src/Result/index.tsx +++ b/playground/src/Result/index.tsx @@ -17,6 +17,7 @@ interface IProps { defaultTab: IResultTabs; transformJs: boolean; presets: string[]; + width: number; } const Result: FC = ({ @@ -25,6 +26,7 @@ const Result: FC = ({ presets, defaultTab, transformJs, + width, }) => { const [logs, setLogs] = useState([]); const tabs: Readonly[]> = useMemo( @@ -50,7 +52,10 @@ const Result: FC = ({ waitForMessage(); }, [id]); return ( - tab.value === defaultTab)}> + tab.value === defaultTab)} + style={{ width: width }} + > {tabs.map(tab => ( {tab.name}