set readonly on mobile devices

This commit is contained in:
Luck
2022-01-27 23:26:16 +00:00
parent 7d54be07d9
commit ed7f8e5bdd
5 changed files with 28 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
import { useState, useEffect } from 'react';
import { ThemeProvider, createGlobalStyle } from 'styled-components';
import { isMobile } from 'react-device-detect';
import ls from 'local-storage';
import EditorControls from './EditorControls';
@@ -13,7 +14,8 @@ export default function Editor({
setActualContent,
contentType,
}) {
const [language, setLanguage] = useState('plain');
const [language, setLanguage] = useState(isMobile);
const [readOnly, setReadOnly] = useState(true);
const [theme, setTheme] = usePreference(
'theme',
@@ -48,6 +50,8 @@ export default function Editor({
setForcedContent={setForcedContent}
language={language}
setLanguage={setLanguage}
readOnly={readOnly}
setReadOnly={setReadOnly}
theme={theme}
setTheme={setTheme}
zoom={zoom}
@@ -59,6 +63,7 @@ export default function Editor({
theme={themes[theme]}
language={language}
fontSize={fontSize}
readOnly={readOnly}
/>
</ThemeProvider>
</>

View File

@@ -14,6 +14,8 @@ export default function EditorControls({
setForcedContent,
language,
setLanguage,
readOnly,
setReadOnly,
theme,
setTheme,
zoom,
@@ -72,6 +74,10 @@ export default function EditorControls({
document.title = 'paste';
}
function unsetReadOnly() {
setReadOnly(false);
}
return (
<Header>
<Section>
@@ -85,6 +91,7 @@ export default function EditorControls({
setValue={setLanguage}
ids={languages}
/>
{readOnly && <Button onClick={unsetReadOnly}>[edit]</Button>}
</Section>
<Section>
<Button onClick={() => zoom(1)}>[+ </Button>

View File

@@ -11,6 +11,7 @@ export default function EditorTextArea({
theme,
language,
fontSize,
readOnly,
}) {
const [editor, setEditor] = useState();
const [monaco, setMonaco] = useState();
@@ -70,6 +71,7 @@ export default function EditorTextArea({
wordWrap: true,
renderLineHighlight: 'none',
renderValidationDecorations: false,
readOnly,
}}
beforeMount={beforeMount}
onMount={onMount}