aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/Inputs/Code.js
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2021-03-06 17:57:24 -0800
committerGitHub <[email protected]>2021-03-06 17:57:24 -0800
commit5dd02b5c2acd7a4c408ce9ffa1d95e208d20bbc8 (patch)
tree5a09bea364331dd0f41510153924065b815b702e /frontend/src/components/Inputs/Code.js
parentfix(typo): public api docs endpoint (diff)
parentfix password modal (diff)
downloadctrl-v-5dd02b5c2acd7a4c408ce9ffa1d95e208d20bbc8.tar.xz
ctrl-v-5dd02b5c2acd7a4c408ce9ffa1d95e208d20bbc8.zip
Merge pull request #70 from jackyzha0/visual-overhaul
Diffstat (limited to 'frontend/src/components/Inputs/Code.js')
-rw-r--r--frontend/src/components/Inputs/Code.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/frontend/src/components/Inputs/Code.js b/frontend/src/components/Inputs/Code.js
new file mode 100644
index 0000000..adb1536
--- /dev/null
+++ b/frontend/src/components/Inputs/Code.js
@@ -0,0 +1,54 @@
+import React from "react";
+import styled from 'styled-components'
+import CharLimit from "../decorators/CharLimit";
+import Editor from 'react-simple-code-editor';
+import {Highlighter} from "../renderers/Code";
+import {CodeLike, Hover} from "../Common/mixins";
+
+const Wrapper = styled.div`
+ position: relative;
+`
+const EditorWrapper = styled(Editor)`
+ overflow: visible !important;
+
+ & > * {
+ padding: 0 !important;
+ width: 100%;
+ }
+
+ & pre, & code, & > textarea {
+ ${CodeLike}
+ min-height: 40vh;
+ }
+
+ & pre {
+ z-index: -1 !important;
+ }
+
+ & > textarea {
+ ${Hover}
+ padding: 0.6em !important;
+ outline: none !important;
+ }
+`
+
+export const Code = ({content, id, readOnly, setContentCallback, ...props}) => {
+ return (
+ <Wrapper>
+ <EditorWrapper
+ name="content"
+ readOnly={readOnly}
+ placeholder="Paste your text here"
+ value={content}
+ id={id}
+ required
+ highlight={code => <Highlighter theme="atom">{code}</Highlighter> }
+ onValueChange={code => setContentCallback(code)}
+ padding={15}
+ />
+ <CharLimit
+ content={content}
+ maxLength={props.maxLength} />
+ </Wrapper>
+ );
+} \ No newline at end of file