diff --git a/src/components/CodeMirror.js b/src/components/CodeMirror.js index 59edee6..a61baca 100644 --- a/src/components/CodeMirror.js +++ b/src/components/CodeMirror.js @@ -4,22 +4,13 @@ import { basicSetup, EditorView } from "codemirror"; import { keymap } from "@codemirror/view"; import { indentWithTab } from "@codemirror/commands"; import { EditorState } from "@codemirror/state"; -import styled, { css } from 'styled-components/macro'; +import styled from 'styled-components/macro'; import { yCollab } from "y-codemirror.next"; import useCollaboration from '../hooks/useCollaboration' import spellcheck from '../hooks/spellchecker'; +import { adjustToMode } from './Preview'; -const adjustToMode = (mode) => { - if (mode === "Both") { - return css` - display: block; - max-width: 50%;` - } else if (mode === "Source") { - return css`display: block;` - } else { - return css`display: none;` - } -} +const adjust = adjustToMode("Source") const CodeEditor = styled.div` border-radius: var(--border-radius); @@ -31,7 +22,7 @@ const CodeEditor = styled.div` padding: 20px; min-height: 500px; - ${props => adjustToMode(props.$mode)} + ${props => adjust(props.$mode)} flex: 1; border: 1px solid var(--gray-400); diff --git a/src/components/Preview.js b/src/components/Preview.js index ffeff99..0938458 100644 --- a/src/components/Preview.js +++ b/src/components/Preview.js @@ -1,15 +1,19 @@ import styled, { css } from 'styled-components/macro'; -const adjustToMode = (mode) => { +export const adjustToMode = (mainMode) => (mode) => { if (mode === "Both") { - return css`max-width: 50%;` - } else if (mode === "Preview") { + return css` + display: block; + max-width: 50%;` + } else if (mode === mainMode) { return css`` } else { return css`display: none;` } } +const adjust = adjustToMode("Preview"); + const Preview = styled.div` background-color: white; padding: 20px; @@ -23,7 +27,7 @@ const Preview = styled.div` vertical-align: top; color: var(--gray-900); word-break: unset; - ${props => adjustToMode(props.$mode)} + ${props => adjust(props.$mode)} @media print { & {